realtek: Add driver support for TC offloading
[openwrt/staging/dedeckeh.git] / target / linux / realtek / files-5.10 / drivers / net / dsa / rtl83xx / rtl838x.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #ifndef _RTL838X_H
4 #define _RTL838X_H
5
6 #include <net/dsa.h>
7
8 /*
9 * Register definition
10 */
11 #define RTL838X_MAC_PORT_CTRL(port) (0xd560 + (((port) << 7)))
12 #define RTL839X_MAC_PORT_CTRL(port) (0x8004 + (((port) << 7)))
13 #define RTL930X_MAC_PORT_CTRL(port) (0x3260 + (((port) << 6)))
14 #define RTL930X_MAC_L2_PORT_CTRL(port) (0x3268 + (((port) << 6)))
15 #define RTL931X_MAC_PORT_CTRL(port) (0x6004 + (((port) << 7)))
16
17 #define RTL838X_RST_GLB_CTRL_0 (0x003c)
18
19 #define RTL838X_MAC_FORCE_MODE_CTRL (0xa104)
20 #define RTL839X_MAC_FORCE_MODE_CTRL (0x02bc)
21 #define RTL930X_MAC_FORCE_MODE_CTRL (0xCA1C)
22 #define RTL931X_MAC_FORCE_MODE_CTRL (0x0DCC)
23
24 #define RTL838X_DMY_REG31 (0x3b28)
25 #define RTL838X_SDS_MODE_SEL (0x0028)
26 #define RTL838X_SDS_CFG_REG (0x0034)
27 #define RTL838X_INT_MODE_CTRL (0x005c)
28 #define RTL838X_CHIP_INFO (0x00d8)
29 #define RTL839X_CHIP_INFO (0x0ff4)
30 #define RTL838X_PORT_ISO_CTRL(port) (0x4100 + ((port) << 2))
31 #define RTL839X_PORT_ISO_CTRL(port) (0x1400 + ((port) << 3))
32
33 /* Packet statistics */
34 #define RTL838X_STAT_PORT_STD_MIB (0x1200)
35 #define RTL839X_STAT_PORT_STD_MIB (0xC000)
36 #define RTL930X_STAT_PORT_MIB_CNTR (0x0664)
37 #define RTL838X_STAT_RST (0x3100)
38 #define RTL839X_STAT_RST (0xF504)
39 #define RTL930X_STAT_RST (0x3240)
40 #define RTL931X_STAT_RST (0x7ef4)
41 #define RTL838X_STAT_PORT_RST (0x3104)
42 #define RTL839X_STAT_PORT_RST (0xF508)
43 #define RTL930X_STAT_PORT_RST (0x3244)
44 #define RTL931X_STAT_PORT_RST (0x7ef8)
45 #define RTL838X_STAT_CTRL (0x3108)
46 #define RTL839X_STAT_CTRL (0x04cc)
47 #define RTL930X_STAT_CTRL (0x3248)
48 #define RTL931X_STAT_CTRL (0x5720)
49
50 /* Registers of the internal Serdes of the 8390 */
51 #define RTL8390_SDS0_1_XSG0 (0xA000)
52 #define RTL8390_SDS0_1_XSG1 (0xA100)
53 #define RTL839X_SDS12_13_XSG0 (0xB800)
54 #define RTL839X_SDS12_13_XSG1 (0xB900)
55 #define RTL839X_SDS12_13_PWR0 (0xb880)
56 #define RTL839X_SDS12_13_PWR1 (0xb980)
57
58 /* Registers of the internal Serdes of the 8380 */
59 #define RTL838X_SDS4_FIB_REG0 (0xF800)
60 #define RTL838X_SDS4_REG28 (0xef80)
61 #define RTL838X_SDS4_DUMMY0 (0xef8c)
62 #define RTL838X_SDS5_EXT_REG6 (0xf18c)
63
64 /* VLAN registers */
65 #define RTL838X_VLAN_CTRL (0x3A74)
66 #define RTL838X_VLAN_PROFILE(idx) (0x3A88 + ((idx) << 2))
67 #define RTL838X_VLAN_PORT_EGR_FLTR (0x3A84)
68 #define RTL838X_VLAN_PORT_PB_VLAN (0x3C00)
69 #define RTL838X_VLAN_PORT_IGR_FLTR(port) (0x3A7C + (((port >> 4) << 2)))
70 #define RTL838X_VLAN_PORT_IGR_FLTR_0 (0x3A7C)
71 #define RTL838X_VLAN_PORT_IGR_FLTR_1 (0x3A7C + 4)
72 #define RTL838X_VLAN_PORT_TAG_STS_CTRL (0xA530)
73
74 #define RTL839X_VLAN_PROFILE(idx) (0x25C0 + (((idx) << 3)))
75 #define RTL839X_VLAN_CTRL (0x26D4)
76 #define RTL839X_VLAN_PORT_PB_VLAN (0x26D8)
77 #define RTL839X_VLAN_PORT_IGR_FLTR(port) (0x27B4 + (((port >> 4) << 2)))
78 #define RTL839X_VLAN_PORT_EGR_FLTR(port) (0x27C4 + (((port >> 5) << 2)))
79 #define RTL839X_VLAN_PORT_TAG_STS_CTRL (0x6828)
80
81 #define RTL930X_VLAN_PROFILE_SET(idx) (0x9c60 + (((idx) * 20)))
82 #define RTL930X_VLAN_CTRL (0x82D4)
83 #define RTL930X_VLAN_PORT_PB_VLAN (0x82D8)
84 #define RTL930X_VLAN_PORT_IGR_FLTR(port) (0x83C0 + (((port >> 4) << 2)))
85 #define RTL930X_VLAN_PORT_EGR_FLTR (0x83C8)
86 #define RTL930X_VLAN_PORT_TAG_STS_CTRL (0xCE24)
87
88 #define RTL931X_VLAN_PROFILE_SET(idx) (0x9800 + (((idx) * 28)))
89 #define RTL931X_VLAN_CTRL (0x94E4)
90 #define RTL931X_VLAN_PORT_IGR_FLTR(port) (0x96B4 + (((port >> 4) << 2)))
91 #define RTL931X_VLAN_PORT_EGR_FLTR(port) (0x96C4 + (((port >> 5) << 2)))
92 #define RTL931X_VLAN_PORT_TAG_CTRL (0x4860)
93
94 /* Table access registers */
95 #define RTL838X_TBL_ACCESS_CTRL_0 (0x6914)
96 #define RTL838X_TBL_ACCESS_DATA_0(idx) (0x6918 + ((idx) << 2))
97 #define RTL838X_TBL_ACCESS_CTRL_1 (0xA4C8)
98 #define RTL838X_TBL_ACCESS_DATA_1(idx) (0xA4CC + ((idx) << 2))
99
100 #define RTL839X_TBL_ACCESS_CTRL_0 (0x1190)
101 #define RTL839X_TBL_ACCESS_DATA_0(idx) (0x1194 + ((idx) << 2))
102 #define RTL839X_TBL_ACCESS_CTRL_1 (0x6b80)
103 #define RTL839X_TBL_ACCESS_DATA_1(idx) (0x6b84 + ((idx) << 2))
104 #define RTL839X_TBL_ACCESS_CTRL_2 (0x611C)
105 #define RTL839X_TBL_ACCESS_DATA_2(i) (0x6120 + (((i) << 2)))
106
107 #define RTL930X_TBL_ACCESS_CTRL_0 (0xB340)
108 #define RTL930X_TBL_ACCESS_DATA_0(idx) (0xB344 + ((idx) << 2))
109 #define RTL930X_TBL_ACCESS_CTRL_1 (0xB3A0)
110 #define RTL930X_TBL_ACCESS_DATA_1(idx) (0xB3A4 + ((idx) << 2))
111 #define RTL930X_TBL_ACCESS_CTRL_2 (0xCE04)
112 #define RTL930X_TBL_ACCESS_DATA_2(i) (0xCE08 + (((i) << 2)))
113
114 #define RTL931X_TBL_ACCESS_CTRL_0 (0x8500)
115 #define RTL931X_TBL_ACCESS_DATA_0(idx) (0x8508 + ((idx) << 2))
116 #define RTL931X_TBL_ACCESS_CTRL_1 (0x40C0)
117 #define RTL931X_TBL_ACCESS_DATA_1(idx) (0x40C4 + ((idx) << 2))
118 #define RTL931X_TBL_ACCESS_CTRL_2 (0x8528)
119 #define RTL931X_TBL_ACCESS_DATA_2(i) (0x852C + (((i) << 2)))
120 #define RTL931X_TBL_ACCESS_CTRL_3 (0x0200)
121 #define RTL931X_TBL_ACCESS_DATA_3(i) (0x0204 + (((i) << 2)))
122 #define RTL931X_TBL_ACCESS_CTRL_4 (0x20DC)
123 #define RTL931X_TBL_ACCESS_DATA_4(i) (0x20E0 + (((i) << 2)))
124 #define RTL931X_TBL_ACCESS_CTRL_5 (0x7E1C)
125 #define RTL931X_TBL_ACCESS_DATA_5(i) (0x7E20 + (((i) << 2)))
126
127 /* MAC handling */
128 #define RTL838X_MAC_LINK_STS (0xa188)
129 #define RTL839X_MAC_LINK_STS (0x0390)
130 #define RTL930X_MAC_LINK_STS (0xCB10)
131 #define RTL931X_MAC_LINK_STS (0x0EC0)
132 #define RTL838X_MAC_LINK_SPD_STS(p) (0xa190 + (((p >> 4) << 2)))
133 #define RTL839X_MAC_LINK_SPD_STS(p) (0x03a0 + (((p >> 4) << 2)))
134 #define RTL930X_MAC_LINK_SPD_STS(p) (0xCB18 + (((p >> 3) << 2)))
135 #define RTL931X_MAC_LINK_SPD_STS(p) (0x0ED0 + (((p >> 3) << 2)))
136 #define RTL838X_MAC_LINK_DUP_STS (0xa19c)
137 #define RTL839X_MAC_LINK_DUP_STS (0x03b0)
138 #define RTL930X_MAC_LINK_DUP_STS (0xCB28)
139 #define RTL931X_MAC_LINK_DUP_STS (0x0EF0)
140 #define RTL838X_MAC_TX_PAUSE_STS (0xa1a0)
141 #define RTL839X_MAC_TX_PAUSE_STS (0x03b8)
142 #define RTL930X_MAC_TX_PAUSE_STS (0xCB2C)
143 #define RTL931X_MAC_TX_PAUSE_STS (0x0EF8)
144 #define RTL838X_MAC_RX_PAUSE_STS (0xa1a4)
145 #define RTL839X_MAC_RX_PAUSE_STS (0x03c0)
146 #define RTL930X_MAC_RX_PAUSE_STS (0xCB30)
147 #define RTL931X_MAC_RX_PAUSE_STS (0x0F00)
148
149 /* MAC link state bits */
150 #define FORCE_EN (1 << 0)
151 #define FORCE_LINK_EN (1 << 1)
152 #define NWAY_EN (1 << 2)
153 #define DUPLX_MODE (1 << 3)
154 #define TX_PAUSE_EN (1 << 6)
155 #define RX_PAUSE_EN (1 << 7)
156
157 /* EEE */
158 #define RTL838X_MAC_EEE_ABLTY (0xa1a8)
159 #define RTL838X_EEE_PORT_TX_EN (0x014c)
160 #define RTL838X_EEE_PORT_RX_EN (0x0150)
161 #define RTL838X_EEE_CLK_STOP_CTRL (0x0148)
162 #define RTL838X_EEE_TX_TIMER_GIGA_CTRL (0xaa04)
163 #define RTL838X_EEE_TX_TIMER_GELITE_CTRL (0xaa08)
164
165 #define RTL839X_EEE_TX_TIMER_GELITE_CTRL (0x042C)
166 #define RTL839X_EEE_TX_TIMER_GIGA_CTRL (0x0430)
167 #define RTL839X_EEE_TX_TIMER_10G_CTRL (0x0434)
168 #define RTL839X_EEE_CTRL(p) (0x8008 + ((p) << 7))
169 #define RTL839X_MAC_EEE_ABLTY (0x03C8)
170
171 #define RTL930X_MAC_EEE_ABLTY (0xCB34)
172 #define RTL930X_EEE_CTRL(p) (0x3274 + ((p) << 6))
173 #define RTL930X_EEEP_PORT_CTRL(p) (0x3278 + ((p) << 6))
174
175 /* L2 functionality */
176 #define RTL838X_L2_CTRL_0 (0x3200)
177 #define RTL839X_L2_CTRL_0 (0x3800)
178 #define RTL930X_L2_CTRL (0x8FD8)
179 #define RTL931X_L2_CTRL (0xC800)
180 #define RTL838X_L2_CTRL_1 (0x3204)
181 #define RTL839X_L2_CTRL_1 (0x3804)
182 #define RTL930X_L2_AGE_CTRL (0x8FDC)
183 #define RTL931X_L2_AGE_CTRL (0xC804)
184 #define RTL838X_L2_PORT_AGING_OUT (0x3358)
185 #define RTL839X_L2_PORT_AGING_OUT (0x3b74)
186 #define RTL930X_L2_PORT_AGE_CTRL (0x8FE0)
187 #define RTL931X_L2_PORT_AGE_CTRL (0xc808)
188 #define RTL838X_TBL_ACCESS_L2_CTRL (0x6900)
189 #define RTL839X_TBL_ACCESS_L2_CTRL (0x1180)
190 #define RTL930X_TBL_ACCESS_L2_CTRL (0xB320)
191 #define RTL930X_TBL_ACCESS_L2_METHOD_CTRL (0xB324)
192 #define RTL838X_TBL_ACCESS_L2_DATA(idx) (0x6908 + ((idx) << 2))
193 #define RTL839X_TBL_ACCESS_L2_DATA(idx) (0x1184 + ((idx) << 2))
194 #define RTL930X_TBL_ACCESS_L2_DATA(idx) (0xab08 + ((idx) << 2))
195 #define RTL838X_L2_TBL_FLUSH_CTRL (0x3370)
196 #define RTL839X_L2_TBL_FLUSH_CTRL (0x3ba0)
197 #define RTL930X_L2_TBL_FLUSH_CTRL (0x9404)
198 #define RTL931X_L2_TBL_FLUSH_CTRL (0xCD9C)
199
200 #define RTL838X_L2_PORT_NEW_SALRN(p) (0x328c + (((p >> 4) << 2)))
201 #define RTL839X_L2_PORT_NEW_SALRN(p) (0x38F0 + (((p >> 4) << 2)))
202 #define RTL930X_L2_PORT_SALRN(p) (0x8FEC + (((p >> 4) << 2)))
203 #define RTL931X_L2_PORT_NEW_SALRN(p) (0xC820 + (((p >> 4) << 2)))
204 #define RTL838X_L2_PORT_NEW_SA_FWD(p) (0x3294 + (((p >> 4) << 2)))
205 #define RTL839X_L2_PORT_NEW_SA_FWD(p) (0x3900 + (((p >> 4) << 2)))
206 #define RTL930X_L2_PORT_NEW_SA_FWD(p) (0x8FF4 + (((p / 10) << 2)))
207 #define RTL931X_L2_PORT_NEW_SA_FWD(p) (0xC830 + (((p / 10) << 2)))
208
209 #define RTL930X_ST_CTRL (0x8798)
210
211 #define RTL930X_L2_PORT_SABLK_CTRL (0x905c)
212 #define RTL930X_L2_PORT_DABLK_CTRL (0x9060)
213
214 #define RTL838X_RMA_BPDU_FLD_PMSK (0x4348)
215 #define RTL930X_RMA_BPDU_FLD_PMSK (0x9F18)
216 #define RTL931X_RMA_BPDU_FLD_PMSK (0x8950)
217 #define RTL839X_RMA_BPDU_FLD_PMSK (0x125C)
218
219 #define RTL838X_L2_PORT_LM_ACT(p) (0x3208 + ((p) << 2))
220 #define RTL838X_VLAN_PORT_FWD (0x3A78)
221 #define RTL839X_VLAN_PORT_FWD (0x27AC)
222 #define RTL930X_VLAN_PORT_FWD (0x834C)
223 #define RTL838X_VLAN_FID_CTRL (0x3aa8)
224
225 /* Port Mirroring */
226 #define RTL838X_MIR_CTRL (0x5D00)
227 #define RTL838X_MIR_DPM_CTRL (0x5D20)
228 #define RTL838X_MIR_SPM_CTRL (0x5D10)
229
230 #define RTL839X_MIR_CTRL (0x2500)
231 #define RTL839X_MIR_DPM_CTRL (0x2530)
232 #define RTL839X_MIR_SPM_CTRL (0x2510)
233
234 #define RTL930X_MIR_CTRL (0xA2A0)
235 #define RTL930X_MIR_DPM_CTRL (0xA2C0)
236 #define RTL930X_MIR_SPM_CTRL (0xA2B0)
237
238 #define RTL931X_MIR_CTRL (0xAF00)
239 #define RTL931X_MIR_DPM_CTRL (0xAF30)
240 #define RTL931X_MIR_SPM_CTRL (0xAF10)
241
242 /* Storm/rate control and scheduling */
243 #define RTL838X_STORM_CTRL (0x4700)
244 #define RTL839X_STORM_CTRL (0x1800)
245 #define RTL838X_STORM_CTRL_LB_CTRL(p) (0x4884 + (((p) << 2)))
246 #define RTL838X_STORM_CTRL_BURST_PPS_0 (0x4874)
247 #define RTL838X_STORM_CTRL_BURST_PPS_1 (0x4878)
248 #define RTL838X_STORM_CTRL_BURST_0 (0x487c)
249 #define RTL838X_STORM_CTRL_BURST_1 (0x4880)
250 #define RTL839X_STORM_CTRL_LB_TICK_TKN_CTRL_0 (0x1804)
251 #define RTL839X_STORM_CTRL_LB_TICK_TKN_CTRL_1 (0x1808)
252 #define RTL838X_SCHED_CTRL (0xB980)
253 #define RTL839X_SCHED_CTRL (0x60F4)
254 #define RTL838X_SCHED_LB_TICK_TKN_CTRL_0 (0xAD58)
255 #define RTL838X_SCHED_LB_TICK_TKN_CTRL_1 (0xAD5C)
256 #define RTL839X_SCHED_LB_TICK_TKN_CTRL_0 (0x1804)
257 #define RTL839X_SCHED_LB_TICK_TKN_CTRL_1 (0x1808)
258 #define RTL839X_STORM_CTRL_SPCL_LB_TICK_TKN_CTRL (0x2000)
259 #define RTL839X_IGR_BWCTRL_LB_TICK_TKN_CTRL_0 (0x1604)
260 #define RTL839X_IGR_BWCTRL_LB_TICK_TKN_CTRL_1 (0x1608)
261 #define RTL839X_SCHED_LB_TICK_TKN_CTRL (0x60F8)
262 #define RTL839X_SCHED_LB_TICK_TKN_PPS_CTRL (0x6200)
263 #define RTL838X_SCHED_LB_THR (0xB984)
264 #define RTL839X_SCHED_LB_THR (0x60FC)
265 #define RTL838X_SCHED_P_EGR_RATE_CTRL(p) (0xC008 + (((p) << 7)))
266 #define RTL838X_SCHED_Q_EGR_RATE_CTRL(p, q) (0xC00C + (p << 7) + (((q) << 2)))
267 #define RTL838X_STORM_CTRL_PORT_BC_EXCEED (0x470C)
268 #define RTL838X_STORM_CTRL_PORT_MC_EXCEED (0x4710)
269 #define RTL838X_STORM_CTRL_PORT_UC_EXCEED (0x4714)
270 #define RTL839X_STORM_CTRL_PORT_BC_EXCEED(p) (0x180c + (((p >> 5) << 2)))
271 #define RTL839X_STORM_CTRL_PORT_MC_EXCEED(p) (0x1814 + (((p >> 5) << 2)))
272 #define RTL839X_STORM_CTRL_PORT_UC_EXCEED(p) (0x181c + (((p >> 5) << 2)))
273 #define RTL838X_STORM_CTRL_PORT_UC(p) (0x4718 + (((p) << 2)))
274 #define RTL838X_STORM_CTRL_PORT_MC(p) (0x478c + (((p) << 2)))
275 #define RTL838X_STORM_CTRL_PORT_BC(p) (0x4800 + (((p) << 2)))
276 #define RTL839X_STORM_CTRL_PORT_UC_0(p) (0x185C + (((p) << 3)))
277 #define RTL839X_STORM_CTRL_PORT_UC_1(p) (0x1860 + (((p) << 3)))
278 #define RTL839X_STORM_CTRL_PORT_MC_0(p) (0x19FC + (((p) << 3)))
279 #define RTL839X_STORM_CTRL_PORT_MC_1(p) (0x1a00 + (((p) << 3)))
280 #define RTL839X_STORM_CTRL_PORT_BC_0(p) (0x1B9C + (((p) << 3)))
281 #define RTL839X_STORM_CTRL_PORT_BC_1(p) (0x1BA0 + (((p) << 3)))
282 #define RTL839X_TBL_ACCESS_CTRL_2 (0x611C)
283 #define RTL839X_TBL_ACCESS_DATA_2(i) (0x6120 + (((i) << 2)))
284 #define RTL839X_IGR_BWCTRL_PORT_CTRL_10G_0(p) (0x1618 + (((p) << 3)))
285 #define RTL839X_IGR_BWCTRL_PORT_CTRL_10G_1(p) (0x161C + (((p) << 3)))
286 #define RTL839X_IGR_BWCTRL_PORT_CTRL_0(p) (0x1640 + (((p) << 3)))
287 #define RTL839X_IGR_BWCTRL_PORT_CTRL_1(p) (0x1644 + (((p) << 3)))
288 #define RTL839X_IGR_BWCTRL_CTRL_LB_THR (0x1614)
289
290 /* Link aggregation (Trunking) */
291 #define RTL839X_TRK_MBR_CTR (0x2200)
292 #define RTL838X_TRK_MBR_CTR (0x3E00)
293 #define RTL930X_TRK_MBR_CTRL (0xA41C)
294 #define RTL931X_TRK_MBR_CTRL (0xB8D0)
295
296 /* Attack prevention */
297 #define RTL838X_ATK_PRVNT_PORT_EN (0x5B00)
298 #define RTL838X_ATK_PRVNT_CTRL (0x5B04)
299 #define RTL838X_ATK_PRVNT_ACT (0x5B08)
300 #define RTL838X_ATK_PRVNT_STS (0x5B1C)
301
302 /* 802.1X */
303 #define RTL838X_SPCL_TRAP_EAPOL_CTRL (0x6988)
304 #define RTL839X_SPCL_TRAP_EAPOL_CTRL (0x105C)
305
306 /* QoS */
307 #define RTL838X_QM_INTPRI2QID_CTRL (0x5F00)
308 #define RTL839X_QM_INTPRI2QID_CTRL(q) (0x1110 + (q << 2))
309 #define RTL839X_QM_PORT_QNUM(p) (0x1130 + (((p / 10) << 2)))
310 #define RTL838X_PRI_SEL_PORT_PRI(p) (0x5FB8 + (((p / 10) << 2)))
311 #define RTL839X_PRI_SEL_PORT_PRI(p) (0x10A8 + (((p / 10) << 2)))
312 #define RTL838X_QM_PKT2CPU_INTPRI_MAP (0x5F10)
313 #define RTL839X_QM_PKT2CPU_INTPRI_MAP (0x1154)
314 #define RTL838X_PRI_SEL_CTRL (0x10E0)
315 #define RTL839X_PRI_SEL_CTRL (0x10E0)
316 #define RTL838X_PRI_SEL_TBL_CTRL(i) (0x5FD8 + (((i) << 2)))
317 #define RTL839X_PRI_SEL_TBL_CTRL(i) (0x10D0 + (((i) << 2)))
318 #define RTL838X_QM_PKT2CPU_INTPRI_0 (0x5F04)
319 #define RTL838X_QM_PKT2CPU_INTPRI_1 (0x5F08)
320 #define RTL838X_QM_PKT2CPU_INTPRI_2 (0x5F0C)
321 #define RTL839X_OAM_CTRL (0x2100)
322 #define RTL839X_OAM_PORT_ACT_CTRL(p) (0x2104 + (((p) << 2)))
323 #define RTL839X_RMK_PORT_DEI_TAG_CTRL(p) (0x6A9C + (((p >> 5) << 2)))
324 #define RTL839X_PRI_SEL_IPRI_REMAP (0x1080)
325 #define RTL838X_PRI_SEL_IPRI_REMAP (0x5F8C)
326 #define RTL839X_PRI_SEL_DEI2DP_REMAP (0x10EC)
327 #define RTL839X_PRI_SEL_DSCP2DP_REMAP_ADDR(i) (0x10F0 + (((i >> 4) << 2)))
328 #define RTL839X_RMK_DEI_CTRL (0x6AA4)
329 #define RTL839X_WRED_PORT_THR_CTRL(i) (0x6084 + ((i) << 2))
330 #define RTL839X_WRED_QUEUE_THR_CTRL(q, i) (0x6090 + ((q) * 12) + ((i) << 2))
331 #define RTL838X_PRI_DSCP_INVLD_CTRL0 (0x5FE8)
332 #define RTL838X_RMK_IPRI_CTRL (0xA460)
333 #define RTL838X_RMK_OPRI_CTRL (0xA464)
334 #define RTL838X_SCHED_P_TYPE_CTRL(p) (0xC04C + (((p) << 7)))
335 #define RTL838X_SCHED_LB_CTRL(p) (0xC004 + (((p) << 7)))
336 #define RTL838X_FC_P_EGR_DROP_CTRL(p) (0x6B1C + (((p) << 2)))
337
338 /* Debug features */
339 #define RTL930X_STAT_PRVTE_DROP_COUNTER0 (0xB5B8)
340
341 /* Packet Inspection Engine */
342 #define RTL838X_METER_GLB_CTRL (0x4B08)
343 #define RTL839X_METER_GLB_CTRL (0x1300)
344 #define RTL930X_METER_GLB_CTRL (0xa0a0)
345 #define RTL839X_ACL_CTRL (0x1288)
346 #define RTL838X_ACL_BLK_LOOKUP_CTRL (0x6100)
347 #define RTL839X_ACL_BLK_LOOKUP_CTRL (0x1280)
348 #define RTL930X_PIE_BLK_LOOKUP_CTRL (0xa5a0)
349 #define RTL838X_ACL_BLK_PWR_CTRL (0x6104)
350 #define RTL839X_PS_ACL_PWR_CTRL (0x049c)
351 #define RTL838X_ACL_BLK_TMPLTE_CTRL(block) (0x6108 + ((block) << 2))
352 #define RTL839X_ACL_BLK_TMPLTE_CTRL(block) (0x128c + ((block) << 2))
353 #define RTL930X_PIE_BLK_TMPLTE_CTRL(block) (0xa624 + ((block) << 2))
354 #define RTL838X_ACL_BLK_GROUP_CTRL (0x615C)
355 #define RTL839X_ACL_BLK_GROUP_CTRL (0x12ec)
356 #define RTL838X_ACL_CLR_CTRL (0x6168)
357 #define RTL839X_ACL_CLR_CTRL (0x12fc)
358 #define RTL930X_PIE_CLR_CTRL (0xa66c)
359 #define RTL838X_DMY_REG27 (0x3378)
360 #define RTL838X_ACL_PORT_LOOKUP_CTRL(p) (0x616C + (((p) << 2)))
361 #define RTL930X_ACL_PORT_LOOKUP_CTRL(p) (0xA784 + (((p) << 2)))
362 #define RTL930X_PIE_BLK_PHASE_CTRL (0xA5A4)
363
364 // PIE actions
365 #define PIE_ACT_COPY_TO_PORT 2
366 #define PIE_ACT_REDIRECT_TO_PORT 4
367 #define PIE_ACT_ROUTE_UC 6
368 #define PIE_ACT_VID_ASSIGN 0
369
370 #define MAX_VLANS 4096
371 #define MAX_LAGS 16
372 #define MAX_PRIOS 8
373 #define RTL930X_PORT_IGNORE 0x3f
374 #define MAX_MC_GROUPS 512
375 #define UNKNOWN_MC_PMASK (MAX_MC_GROUPS - 1)
376 #define PIE_BLOCK_SIZE 128
377 #define MAX_PIE_ENTRIES (18 * PIE_BLOCK_SIZE)
378 #define N_FIXED_FIELDS 12
379 #define MAX_COUNTERS 2048
380
381 enum phy_type {
382 PHY_NONE = 0,
383 PHY_RTL838X_SDS = 1,
384 PHY_RTL8218B_INT = 2,
385 PHY_RTL8218B_EXT = 3,
386 PHY_RTL8214FC = 4,
387 PHY_RTL839X_SDS = 5,
388 };
389
390 struct rtl838x_port {
391 bool enable;
392 u64 pm;
393 u16 pvid;
394 bool eee_enabled;
395 enum phy_type phy;
396 bool is10G;
397 bool is2G5;
398 u8 sds_num;
399 const struct dsa_port *dp;
400 };
401
402 struct rtl838x_vlan_info {
403 u64 untagged_ports;
404 u64 tagged_ports;
405 u8 profile_id;
406 bool hash_mc_fid;
407 bool hash_uc_fid;
408 u8 fid;
409 };
410
411 enum l2_entry_type {
412 L2_INVALID = 0,
413 L2_UNICAST = 1,
414 L2_MULTICAST = 2,
415 IP4_MULTICAST = 3,
416 IP6_MULTICAST = 4,
417 };
418
419 struct rtl838x_l2_entry {
420 u8 mac[6];
421 u16 vid;
422 u16 rvid;
423 u8 port;
424 bool valid;
425 enum l2_entry_type type;
426 bool is_static;
427 bool is_ip_mc;
428 bool is_ipv6_mc;
429 bool block_da;
430 bool block_sa;
431 bool suspended;
432 bool next_hop;
433 int age;
434 u8 trunk;
435 bool is_trunk;
436 u8 stack_dev;
437 u16 mc_portmask_index;
438 u32 mc_gip;
439 u32 mc_sip;
440 u16 mc_mac_index;
441 u16 nh_route_id;
442 bool nh_vlan_target; // Only RTL83xx: VLAN used for next hop
443 };
444
445 enum fwd_rule_action {
446 FWD_RULE_ACTION_NONE = 0,
447 FWD_RULE_ACTION_FWD = 1,
448 };
449
450 enum pie_phase {
451 PHASE_VACL = 0,
452 PHASE_IACL = 1,
453 };
454
455 /* Intermediate representation of a Packet Inspection Engine Rule
456 * as suggested by the Kernel's tc flower offload subsystem
457 * Field meaning is universal across SoC families, but data content is specific
458 * to SoC family (e.g. because of different port ranges) */
459 struct pie_rule {
460 int id;
461 enum pie_phase phase; // Phase in which this template is applied
462 int packet_cntr; // ID of a packet counter assigned to this rule
463 int octet_cntr; // ID of a byte counter assigned to this rule
464 u32 last_packet_cnt;
465 u64 last_octet_cnt;
466
467 // The following are requirements for the pie template
468 bool is_egress;
469 bool is_ipv6; // This is a rule with IPv6 fields
470
471 // Fixed fields that are always matched against on RTL8380
472 u8 spmmask_fix;
473 u8 spn; // Source port number
474 bool stacking_port; // Source port is stacking port
475 bool mgnt_vlan; // Packet arrived on management VLAN
476 bool dmac_hit_sw; // The packet's destination MAC matches one of the device's
477 bool content_too_deep; // The content of the packet cannot be parsed: too many layers
478 bool not_first_frag; // Not the first IP fragment
479 u8 frame_type_l4; // 0: UDP, 1: TCP, 2: ICMP/ICMPv6, 3: IGMP
480 u8 frame_type; // 0: ARP, 1: L2 only, 2: IPv4, 3: IPv6
481 bool otag_fmt; // 0: outer tag packet, 1: outer priority tag or untagged
482 bool itag_fmt; // 0: inner tag packet, 1: inner priority tag or untagged
483 bool otag_exist; // packet with outer tag
484 bool itag_exist; // packet with inner tag
485 bool frame_type_l2; // 0: Ethernet, 1: LLC_SNAP, 2: LLC_Other, 3: Reserved
486 bool igr_normal_port; // Ingress port is not cpu or stacking port
487 u8 tid; // The template ID defining the what the templated fields mean
488
489 // Masks for the fields that are always matched against on RTL8380
490 u8 spmmask_fix_m;
491 u8 spn_m;
492 bool stacking_port_m;
493 bool mgnt_vlan_m;
494 bool dmac_hit_sw_m;
495 bool content_too_deep_m;
496 bool not_first_frag_m;
497 u8 frame_type_l4_m;
498 u8 frame_type_m;
499 bool otag_fmt_m;
500 bool itag_fmt_m;
501 bool otag_exist_m;
502 bool itag_exist_m;
503 bool frame_type_l2_m;
504 bool igr_normal_port_m;
505 u8 tid_m;
506
507 // Logical operations between rules, special rules for rule numbers apply
508 bool valid;
509 bool cond_not; // Matches when conditions not match
510 bool cond_and1; // And this rule 2n with the next rule 2n+1 in same block
511 bool cond_and2; // And this rule m in block 2n with rule m in block 2n+1
512 bool ivalid;
513
514 // Actions to be performed
515 bool drop; // Drop the packet
516 bool fwd_sel; // Forward packet: to port, portmask, dest route, next rule, drop
517 bool ovid_sel; // So something to outer vlan-id: shift, re-assign
518 bool ivid_sel; // Do something to inner vlan-id: shift, re-assign
519 bool flt_sel; // Filter the packet when sending to certain ports
520 bool log_sel; // Log the packet in one of the LOG-table counters
521 bool rmk_sel; // Re-mark the packet, i.e. change the priority-tag
522 bool meter_sel; // Meter the packet, i.e. limit rate of this type of packet
523 bool tagst_sel; // Change the ergress tag
524 bool mir_sel; // Mirror the packet to a Link Aggregation Group
525 bool nopri_sel; // Change the normal priority
526 bool cpupri_sel; // Change the CPU priority
527 bool otpid_sel; // Change Outer Tag Protocol Identifier (802.1q)
528 bool itpid_sel; // Change Inner Tag Protocol Identifier (802.1q)
529 bool shaper_sel; // Apply traffic shaper
530 bool mpls_sel; // MPLS actions
531 bool bypass_sel; // Bypass actions
532 bool fwd_sa_lrn; // Learn the source address when forwarding
533 bool fwd_mod_to_cpu; // Forward the modified VLAN tag format to CPU-port
534
535 // Fields used in predefined templates 0-2 on RTL8380 / 90 / 9300
536 u64 spm; // Source Port Matrix
537 u16 otag; // Outer VLAN-ID
538 u8 smac[ETH_ALEN]; // Source MAC address
539 u8 dmac[ETH_ALEN]; // Destination MAC address
540 u16 ethertype; // Ethernet frame type field in ethernet header
541 u16 itag; // Inner VLAN-ID
542 u16 field_range_check;
543 u32 sip; // Source IP
544 struct in6_addr sip6; // IPv6 Source IP
545 u32 dip; // Destination IP
546 struct in6_addr dip6; // IPv6 Destination IP
547 u16 tos_proto; // IPv4: TOS + Protocol fields, IPv6: Traffic class + next header
548 u16 sport; // TCP/UDP source port
549 u16 dport; // TCP/UDP destination port
550 u16 icmp_igmp;
551 u16 tcp_info;
552 u16 dsap_ssap; // Destination / Source Service Access Point bytes (802.3)
553
554 u64 spm_m;
555 u16 otag_m;
556 u8 smac_m[ETH_ALEN];
557 u8 dmac_m[ETH_ALEN];
558 u8 ethertype_m;
559 u16 itag_m;
560 u16 field_range_check_m;
561 u32 sip_m;
562 struct in6_addr sip6_m; // IPv6 Source IP mask
563 u32 dip_m;
564 struct in6_addr dip6_m; // IPv6 Destination IP mask
565 u16 tos_proto_m;
566 u16 sport_m;
567 u16 dport_m;
568 u16 icmp_igmp_m;
569 u16 tcp_info_m;
570 u16 dsap_ssap_m;
571
572 // Data associated with actions
573 u8 fwd_act; // Type of forwarding action
574 // 0: permit, 1: drop, 2: copy to port id, 4: copy to portmask
575 // 4: redirect to portid, 5: redirect to portmask
576 // 6: route, 7: vlan leaky (only 8380)
577 u16 fwd_data; // Additional data for forwarding action, e.g. destination port
578 u8 ovid_act;
579 u16 ovid_data; // Outer VLAN ID
580 u8 ivid_act;
581 u16 ivid_data; // Inner VLAN ID
582 u16 flt_data; // Filtering data
583 u16 log_data; // ID of packet or octet counter in LOG table, on RTL93xx
584 // unnecessary since PIE-Rule-ID == LOG-counter-ID
585 bool log_octets;
586 u8 mpls_act; // MPLS action type
587 u16 mpls_lib_idx; // MPLS action data
588
589 u16 rmk_data; // Data for remarking
590 u16 meter_data; // ID of meter for bandwidth control
591 u16 tagst_data;
592 u16 mir_data;
593 u16 nopri_data;
594 u16 cpupri_data;
595 u16 otpid_data;
596 u16 itpid_data;
597 u16 shaper_data;
598
599 // Bypass actions, ignored on RTL8380
600 bool bypass_all; // Not clear
601 bool bypass_igr_stp; // Bypass Ingress STP state
602 bool bypass_ibc_sc; // Bypass Ingress Bandwidth Control and Storm Control
603 };
604
605 struct rtl838x_nexthop {
606 u16 id; // ID in HW Nexthop table
607 u32 ip; // IP Addres of nexthop
608 u32 dev_id;
609 u16 port;
610 u16 vid;
611 u16 fid;
612 u64 mac;
613 u16 mac_id;
614 u16 l2_id; // Index of this next hop forwarding entry in L2 FIB table
615 u16 if_id;
616 };
617
618 struct rtl838x_switch_priv;
619
620 struct rtl83xx_flow {
621 unsigned long cookie;
622 struct rhash_head node;
623 struct rcu_head rcu_head;
624 struct rtl838x_switch_priv *priv;
625 struct pie_rule rule;
626 u32 flags;
627 };
628
629 struct rtl838x_reg {
630 void (*mask_port_reg_be)(u64 clear, u64 set, int reg);
631 void (*set_port_reg_be)(u64 set, int reg);
632 u64 (*get_port_reg_be)(int reg);
633 void (*mask_port_reg_le)(u64 clear, u64 set, int reg);
634 void (*set_port_reg_le)(u64 set, int reg);
635 u64 (*get_port_reg_le)(int reg);
636 int stat_port_rst;
637 int stat_rst;
638 int stat_port_std_mib;
639 int (*port_iso_ctrl)(int p);
640 void (*traffic_enable)(int source, int dest);
641 void (*traffic_disable)(int source, int dest);
642 void (*traffic_set)(int source, u64 dest_matrix);
643 u64 (*traffic_get)(int source);
644 int l2_ctrl_0;
645 int l2_ctrl_1;
646 int l2_port_aging_out;
647 int smi_poll_ctrl;
648 int l2_tbl_flush_ctrl;
649 void (*exec_tbl0_cmd)(u32 cmd);
650 void (*exec_tbl1_cmd)(u32 cmd);
651 int (*tbl_access_data_0)(int i);
652 int isr_glb_src;
653 int isr_port_link_sts_chg;
654 int imr_port_link_sts_chg;
655 int imr_glb;
656 void (*vlan_tables_read)(u32 vlan, struct rtl838x_vlan_info *info);
657 void (*vlan_set_tagged)(u32 vlan, struct rtl838x_vlan_info *info);
658 void (*vlan_set_untagged)(u32 vlan, u64 portmask);
659 void (*vlan_profile_dump)(int index);
660 void (*vlan_profile_setup)(int profile);
661 void (*stp_get)(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]);
662 void (*stp_set)(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]);
663 int (*mac_force_mode_ctrl)(int port);
664 int (*mac_port_ctrl)(int port);
665 int (*l2_port_new_salrn)(int port);
666 int (*l2_port_new_sa_fwd)(int port);
667 int mir_ctrl;
668 int mir_dpm;
669 int mir_spm;
670 int mac_link_sts;
671 int mac_link_dup_sts;
672 int (*mac_link_spd_sts)(int port);
673 int mac_rx_pause_sts;
674 int mac_tx_pause_sts;
675 u64 (*read_l2_entry_using_hash)(u32 hash, u32 position, struct rtl838x_l2_entry *e);
676 void (*write_l2_entry_using_hash)(u32 hash, u32 pos, struct rtl838x_l2_entry *e);
677 u64 (*read_cam)(int idx, struct rtl838x_l2_entry *e);
678 void (*write_cam)(int idx, struct rtl838x_l2_entry *e);
679 int vlan_port_egr_filter;
680 int vlan_port_igr_filter;
681 int vlan_port_pb;
682 int vlan_port_tag_sts_ctrl;
683 int (*rtl838x_vlan_port_tag_sts_ctrl)(int port);
684 int (*trk_mbr_ctr)(int group);
685 int rma_bpdu_fld_pmask;
686 int spcl_trap_eapol_ctrl;
687 void (*init_eee)(struct rtl838x_switch_priv *priv, bool enable);
688 void (*port_eee_set)(struct rtl838x_switch_priv *priv, int port, bool enable);
689 int (*eee_port_ability)(struct rtl838x_switch_priv *priv,
690 struct ethtool_eee *e, int port);
691 u64 (*l2_hash_seed)(u64 mac, u32 vid);
692 u32 (*l2_hash_key)(struct rtl838x_switch_priv *priv, u64 seed);
693 u64 (*read_mcast_pmask)(int idx);
694 void (*write_mcast_pmask)(int idx, u64 portmask);
695 void (*vlan_fwd_on_inner)(int port, bool is_set);
696 void (*pie_init)(struct rtl838x_switch_priv *priv);
697 int (*pie_rule_read)(struct rtl838x_switch_priv *priv, int idx, struct pie_rule *pr);
698 int (*pie_rule_write)(struct rtl838x_switch_priv *priv, int idx, struct pie_rule *pr);
699 int (*pie_rule_add)(struct rtl838x_switch_priv *priv, struct pie_rule *rule);
700 void (*pie_rule_rm)(struct rtl838x_switch_priv *priv, struct pie_rule *rule);
701 u32 (*packet_cntr_read)(int counter);
702 void (*packet_cntr_clear)(int counter);
703 };
704
705 struct rtl838x_switch_priv {
706 /* Switch operation */
707 struct dsa_switch *ds;
708 struct device *dev;
709 u16 id;
710 u16 family_id;
711 char version;
712 struct rtl838x_port ports[57];
713 struct mutex reg_mutex; // Mutex for individual register manipulations
714 struct mutex pie_mutex; // Mutex for Packet Inspection Engine
715 int link_state_irq;
716 int mirror_group_ports[4];
717 struct mii_bus *mii_bus;
718 const struct rtl838x_reg *r;
719 u8 cpu_port;
720 u8 port_mask;
721 u8 port_width;
722 u8 port_ignore;
723 u64 irq_mask;
724 u32 fib_entries;
725 int l2_bucket_size;
726 struct dentry *dbgfs_dir;
727 int n_lags;
728 u64 lags_port_members[MAX_LAGS];
729 struct net_device *lag_devs[MAX_LAGS];
730 struct notifier_block nb;
731 bool eee_enabled;
732 unsigned long int mc_group_bm[MAX_MC_GROUPS >> 5];
733 int n_pie_blocks;
734 struct rhashtable tc_ht;
735 unsigned long int pie_use_bm[MAX_PIE_ENTRIES >> 5];
736 int n_counters;
737 unsigned long int octet_cntr_use_bm[MAX_COUNTERS >> 5];
738 unsigned long int packet_cntr_use_bm[MAX_COUNTERS >> 4];
739 };
740
741 void rtl838x_dbgfs_init(struct rtl838x_switch_priv *priv);
742
743 #endif /* _RTL838X_H */