realtek: fix standalone ports in presence of static fdb entries
[openwrt/staging/wigyori.git] / target / linux / realtek / files-5.15 / 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 /* Register definition */
9 #define RTL838X_MAC_PORT_CTRL(port) (0xd560 + (((port) << 7)))
10 #define RTL839X_MAC_PORT_CTRL(port) (0x8004 + (((port) << 7)))
11 #define RTL930X_MAC_PORT_CTRL(port) (0x3260 + (((port) << 6)))
12 #define RTL931X_MAC_PORT_CTRL (0x6004)
13
14 #define RTL930X_MAC_L2_PORT_CTRL(port) (0x3268 + (((port) << 6)))
15 #define RTL931X_MAC_L2_PORT_CTRL (0x6000)
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 (0x3A7C)
70
71 #define RTL839X_VLAN_PROFILE(idx) (0x25C0 + (((idx) << 3)))
72 #define RTL839X_VLAN_CTRL (0x26D4)
73 #define RTL839X_VLAN_PORT_PB_VLAN (0x26D8)
74 #define RTL839X_VLAN_PORT_IGR_FLTR (0x27B4)
75 #define RTL839X_VLAN_PORT_EGR_FLTR (0x27C4)
76
77 #define RTL930X_VLAN_PROFILE_SET(idx) (0x9c60 + (((idx) * 20)))
78 #define RTL930X_VLAN_CTRL (0x82D4)
79 #define RTL930X_VLAN_PORT_PB_VLAN (0x82D8)
80 #define RTL930X_VLAN_PORT_IGR_FLTR (0x83C0)
81 #define RTL930X_VLAN_PORT_EGR_FLTR (0x83C8)
82
83 #define RTL931X_VLAN_PROFILE_SET(idx) (0x9800 + (((idx) * 28)))
84 #define RTL931X_VLAN_CTRL (0x94E4)
85 #define RTL931X_VLAN_PORT_IGR_CTRL (0x94E8)
86 #define RTL931X_VLAN_PORT_IGR_FLTR (0x96B4)
87 #define RTL931X_VLAN_PORT_EGR_FLTR (0x96C4)
88
89 /* Table access registers */
90 #define RTL838X_TBL_ACCESS_CTRL_0 (0x6914)
91 #define RTL838X_TBL_ACCESS_DATA_0(idx) (0x6918 + ((idx) << 2))
92 #define RTL838X_TBL_ACCESS_CTRL_1 (0xA4C8)
93 #define RTL838X_TBL_ACCESS_DATA_1(idx) (0xA4CC + ((idx) << 2))
94
95 #define RTL839X_TBL_ACCESS_CTRL_0 (0x1190)
96 #define RTL839X_TBL_ACCESS_DATA_0(idx) (0x1194 + ((idx) << 2))
97 #define RTL839X_TBL_ACCESS_CTRL_1 (0x6b80)
98 #define RTL839X_TBL_ACCESS_DATA_1(idx) (0x6b84 + ((idx) << 2))
99 #define RTL839X_TBL_ACCESS_CTRL_2 (0x611C)
100 #define RTL839X_TBL_ACCESS_DATA_2(i) (0x6120 + (((i) << 2)))
101
102 #define RTL930X_TBL_ACCESS_CTRL_0 (0xB340)
103 #define RTL930X_TBL_ACCESS_DATA_0(idx) (0xB344 + ((idx) << 2))
104 #define RTL930X_TBL_ACCESS_CTRL_1 (0xB3A0)
105 #define RTL930X_TBL_ACCESS_DATA_1(idx) (0xB3A4 + ((idx) << 2))
106 #define RTL930X_TBL_ACCESS_CTRL_2 (0xCE04)
107 #define RTL930X_TBL_ACCESS_DATA_2(i) (0xCE08 + (((i) << 2)))
108
109 #define RTL931X_TBL_ACCESS_CTRL_0 (0x8500)
110 #define RTL931X_TBL_ACCESS_DATA_0(idx) (0x8508 + ((idx) << 2))
111 #define RTL931X_TBL_ACCESS_CTRL_1 (0x40C0)
112 #define RTL931X_TBL_ACCESS_DATA_1(idx) (0x40C4 + ((idx) << 2))
113 #define RTL931X_TBL_ACCESS_CTRL_2 (0x8528)
114 #define RTL931X_TBL_ACCESS_DATA_2(i) (0x852C + (((i) << 2)))
115 #define RTL931X_TBL_ACCESS_CTRL_3 (0x0200)
116 #define RTL931X_TBL_ACCESS_DATA_3(i) (0x0204 + (((i) << 2)))
117 #define RTL931X_TBL_ACCESS_CTRL_4 (0x20DC)
118 #define RTL931X_TBL_ACCESS_DATA_4(i) (0x20E0 + (((i) << 2)))
119 #define RTL931X_TBL_ACCESS_CTRL_5 (0x7E1C)
120 #define RTL931X_TBL_ACCESS_DATA_5(i) (0x7E20 + (((i) << 2)))
121
122 /* MAC handling */
123 #define RTL838X_MAC_LINK_STS (0xa188)
124 #define RTL839X_MAC_LINK_STS (0x0390)
125 #define RTL930X_MAC_LINK_STS (0xCB10)
126 #define RTL931X_MAC_LINK_STS (0x0EC0)
127 #define RTL838X_MAC_LINK_SPD_STS(p) (0xa190 + (((p >> 4) << 2)))
128 #define RTL839X_MAC_LINK_SPD_STS(p) (0x03a0 + (((p >> 4) << 2)))
129 #define RTL930X_MAC_LINK_SPD_STS(p) (0xCB18 + (((p >> 3) << 2)))
130 #define RTL931X_MAC_LINK_SPD_STS (0x0ED0)
131 #define RTL838X_MAC_LINK_DUP_STS (0xa19c)
132 #define RTL839X_MAC_LINK_DUP_STS (0x03b0)
133 #define RTL930X_MAC_LINK_DUP_STS (0xCB28)
134 #define RTL931X_MAC_LINK_DUP_STS (0x0EF0)
135 #define RTL838X_MAC_TX_PAUSE_STS (0xa1a0)
136 #define RTL839X_MAC_TX_PAUSE_STS (0x03b8)
137 #define RTL930X_MAC_TX_PAUSE_STS (0xCB2C)
138 #define RTL931X_MAC_TX_PAUSE_STS (0x0EF8)
139 #define RTL838X_MAC_RX_PAUSE_STS (0xa1a4)
140 #define RTL839X_MAC_RX_PAUSE_STS (0x03c0)
141 #define RTL930X_MAC_RX_PAUSE_STS (0xCB30)
142 #define RTL931X_MAC_RX_PAUSE_STS (0x0F00)
143 #define RTL930X_MAC_LINK_MEDIA_STS (0xCB14)
144 #define RTL931X_MAC_LINK_MEDIA_STS (0x0EC8)
145
146 /* MAC link state bits */
147 #define RTL838X_FORCE_EN (1 << 0)
148 #define RTL838X_FORCE_LINK_EN (1 << 1)
149 #define RTL838X_NWAY_EN (1 << 2)
150 #define RTL838X_DUPLEX_MODE (1 << 3)
151 #define RTL838X_TX_PAUSE_EN (1 << 6)
152 #define RTL838X_RX_PAUSE_EN (1 << 7)
153 #define RTL838X_MAC_FORCE_FC_EN (1 << 8)
154
155 #define RTL839X_FORCE_EN (1 << 0)
156 #define RTL839X_FORCE_LINK_EN (1 << 1)
157 #define RTL839X_DUPLEX_MODE (1 << 2)
158 #define RTL839X_TX_PAUSE_EN (1 << 5)
159 #define RTL839X_RX_PAUSE_EN (1 << 6)
160 #define RTL839X_MAC_FORCE_FC_EN (1 << 7)
161
162 #define RTL930X_FORCE_EN (1 << 0)
163 #define RTL930X_FORCE_LINK_EN (1 << 1)
164 #define RTL930X_DUPLEX_MODE (1 << 2)
165 #define RTL930X_TX_PAUSE_EN (1 << 7)
166 #define RTL930X_RX_PAUSE_EN (1 << 8)
167 #define RTL930X_MAC_FORCE_FC_EN (1 << 9)
168
169 #define RTL931X_FORCE_EN (1 << 9)
170 #define RTL931X_FORCE_LINK_EN (1 << 0)
171 #define RTL931X_DUPLEX_MODE (1 << 2)
172 #define RTL931X_MAC_FORCE_FC_EN (1 << 4)
173 #define RTL931X_TX_PAUSE_EN (1 << 16)
174 #define RTL931X_RX_PAUSE_EN (1 << 17)
175
176 /* EEE */
177 #define RTL838X_MAC_EEE_ABLTY (0xa1a8)
178 #define RTL838X_EEE_PORT_TX_EN (0x014c)
179 #define RTL838X_EEE_PORT_RX_EN (0x0150)
180 #define RTL838X_EEE_CLK_STOP_CTRL (0x0148)
181 #define RTL838X_EEE_TX_TIMER_GIGA_CTRL (0xaa04)
182 #define RTL838X_EEE_TX_TIMER_GELITE_CTRL (0xaa08)
183
184 #define RTL839X_EEE_TX_TIMER_GELITE_CTRL (0x042C)
185 #define RTL839X_EEE_TX_TIMER_GIGA_CTRL (0x0430)
186 #define RTL839X_EEE_TX_TIMER_10G_CTRL (0x0434)
187 #define RTL839X_EEE_CTRL(p) (0x8008 + ((p) << 7))
188 #define RTL839X_MAC_EEE_ABLTY (0x03C8)
189
190 #define RTL930X_MAC_EEE_ABLTY (0xCB34)
191 #define RTL930X_EEE_CTRL(p) (0x3274 + ((p) << 6))
192 #define RTL930X_EEEP_PORT_CTRL(p) (0x3278 + ((p) << 6))
193
194 /* L2 functionality */
195 #define RTL838X_L2_CTRL_0 (0x3200)
196 #define RTL839X_L2_CTRL_0 (0x3800)
197 #define RTL930X_L2_CTRL (0x8FD8)
198 #define RTL931X_L2_CTRL (0xC800)
199 #define RTL838X_L2_CTRL_1 (0x3204)
200 #define RTL839X_L2_CTRL_1 (0x3804)
201 #define RTL930X_L2_AGE_CTRL (0x8FDC)
202 #define RTL931X_L2_AGE_CTRL (0xC804)
203 #define RTL838X_L2_PORT_AGING_OUT (0x3358)
204 #define RTL839X_L2_PORT_AGING_OUT (0x3b74)
205 #define RTL930X_L2_PORT_AGE_CTRL (0x8FE0)
206 #define RTL931X_L2_PORT_AGE_CTRL (0xc808)
207 #define RTL838X_TBL_ACCESS_L2_CTRL (0x6900)
208 #define RTL839X_TBL_ACCESS_L2_CTRL (0x1180)
209 #define RTL930X_TBL_ACCESS_L2_CTRL (0xB320)
210 #define RTL930X_TBL_ACCESS_L2_METHOD_CTRL (0xB324)
211 #define RTL838X_TBL_ACCESS_L2_DATA(idx) (0x6908 + ((idx) << 2))
212 #define RTL839X_TBL_ACCESS_L2_DATA(idx) (0x1184 + ((idx) << 2))
213 #define RTL930X_TBL_ACCESS_L2_DATA(idx) (0xab08 + ((idx) << 2))
214
215 #define RTL838X_L2_TBL_FLUSH_CTRL (0x3370)
216 #define RTL839X_L2_TBL_FLUSH_CTRL (0x3ba0)
217 #define RTL930X_L2_TBL_FLUSH_CTRL (0x9404)
218 #define RTL931X_L2_TBL_FLUSH_CTRL (0xCD9C)
219
220 #define RTL838X_L2_LRN_CONSTRT (0x329C)
221 #define RTL839X_L2_LRN_CONSTRT (0x3910)
222 #define RTL930X_L2_LRN_CONSTRT_CTRL (0x909c)
223 #define RTL931X_L2_LRN_CONSTRT_CTRL (0xC964)
224
225 #define RTL838X_L2_FLD_PMSK (0x3288)
226 #define RTL839X_L2_FLD_PMSK (0x38EC)
227 #define RTL930X_L2_BC_FLD_PMSK (0x9068)
228 #define RTL931X_L2_BC_FLD_PMSK (0xC8FC)
229
230 #define RTL930X_L2_UNKN_UC_FLD_PMSK (0x9064)
231 #define RTL931X_L2_UNKN_UC_FLD_PMSK (0xC8F4)
232
233 #define RTL838X_L2_LRN_CONSTRT_EN (0x3368)
234 #define RTL838X_L2_PORT_LRN_CONSTRT (0x32A0)
235 #define RTL839X_L2_PORT_LRN_CONSTRT (0x3914)
236
237 #define RTL838X_L2_PORT_NEW_SALRN(p) (0x328c + (((p >> 4) << 2)))
238 #define RTL839X_L2_PORT_NEW_SALRN(p) (0x38F0 + (((p >> 4) << 2)))
239 #define RTL930X_L2_PORT_SALRN(p) (0x8FEC + (((p >> 4) << 2)))
240 #define RTL931X_L2_PORT_NEW_SALRN(p) (0xC820 + (((p >> 4) << 2)))
241
242 #define SALRN_PORT_SHIFT(p) ((p % 16) * 2)
243 #define SALRN_MODE_MASK 0x3
244 #define SALRN_MODE_HARDWARE 0
245 #define SALRN_MODE_DISABLED 2
246
247 #define RTL838X_L2_PORT_NEW_SA_FWD(p) (0x3294 + (((p >> 4) << 2)))
248 #define RTL839X_L2_PORT_NEW_SA_FWD(p) (0x3900 + (((p >> 4) << 2)))
249 #define RTL930X_L2_PORT_NEW_SA_FWD(p) (0x8FF4 + (((p / 10) << 2)))
250 #define RTL931X_L2_PORT_NEW_SA_FWD(p) (0xC830 + (((p / 10) << 2)))
251
252 #define RTL838X_L2_PORT_MV_ACT(p) (0x335c + (((p >> 4) << 2)))
253 #define RTL839X_L2_PORT_MV_ACT(p) (0x3b80 + (((p >> 4) << 2)))
254
255 #define RTL838X_L2_PORT_STATIC_MV_ACT(p) (0x327c + (((p >> 4) << 2)))
256 #define RTL839X_L2_PORT_STATIC_MV_ACT(p) (0x38dc + (((p >> 4) << 2)))
257
258 #define MV_ACT_PORT_SHIFT(p) ((p % 16) * 2)
259 #define MV_ACT_MASK 0x3
260 #define MV_ACT_FORWARD 0
261 #define MV_ACT_DROP 1
262 #define MV_ACT_TRAP2CPU 2
263 #define MV_ACT_COPY2CPU 3
264
265 #define RTL930X_ST_CTRL (0x8798)
266
267 #define RTL930X_L2_PORT_SABLK_CTRL (0x905c)
268 #define RTL930X_L2_PORT_DABLK_CTRL (0x9060)
269
270 #define RTL838X_L2_PORT_LM_ACT(p) (0x3208 + ((p) << 2))
271 #define RTL838X_VLAN_PORT_FWD (0x3A78)
272 #define RTL839X_VLAN_PORT_FWD (0x27AC)
273 #define RTL930X_VLAN_PORT_FWD (0x834C)
274 #define RTL931X_VLAN_PORT_FWD (0x95CC)
275 #define RTL838X_VLAN_FID_CTRL (0x3aa8)
276
277 /* Port Mirroring */
278 #define RTL838X_MIR_CTRL (0x5D00)
279 #define RTL838X_MIR_DPM_CTRL (0x5D20)
280 #define RTL838X_MIR_SPM_CTRL (0x5D10)
281
282 #define RTL839X_MIR_CTRL (0x2500)
283 #define RTL839X_MIR_DPM_CTRL (0x2530)
284 #define RTL839X_MIR_SPM_CTRL (0x2510)
285
286 #define RTL930X_MIR_CTRL (0xA2A0)
287 #define RTL930X_MIR_DPM_CTRL (0xA2C0)
288 #define RTL930X_MIR_SPM_CTRL (0xA2B0)
289
290 #define RTL931X_MIR_CTRL (0xAF00)
291 #define RTL931X_MIR_DPM_CTRL (0xAF30)
292 #define RTL931X_MIR_SPM_CTRL (0xAF10)
293
294 /* Storm/rate control and scheduling */
295 #define RTL838X_STORM_CTRL (0x4700)
296 #define RTL839X_STORM_CTRL (0x1800)
297 #define RTL838X_STORM_CTRL_LB_CTRL(p) (0x4884 + (((p) << 2)))
298 #define RTL838X_STORM_CTRL_BURST_PPS_0 (0x4874)
299 #define RTL838X_STORM_CTRL_BURST_PPS_1 (0x4878)
300 #define RTL838X_STORM_CTRL_BURST_0 (0x487c)
301 #define RTL838X_STORM_CTRL_BURST_1 (0x4880)
302 #define RTL839X_STORM_CTRL_LB_TICK_TKN_CTRL_0 (0x1804)
303 #define RTL839X_STORM_CTRL_LB_TICK_TKN_CTRL_1 (0x1808)
304 #define RTL838X_SCHED_CTRL (0xB980)
305 #define RTL839X_SCHED_CTRL (0x60F4)
306 #define RTL838X_SCHED_LB_TICK_TKN_CTRL_0 (0xAD58)
307 #define RTL838X_SCHED_LB_TICK_TKN_CTRL_1 (0xAD5C)
308 #define RTL839X_SCHED_LB_TICK_TKN_CTRL_0 (0x1804)
309 #define RTL839X_SCHED_LB_TICK_TKN_CTRL_1 (0x1808)
310 #define RTL839X_STORM_CTRL_SPCL_LB_TICK_TKN_CTRL (0x2000)
311 #define RTL839X_IGR_BWCTRL_LB_TICK_TKN_CTRL_0 (0x1604)
312 #define RTL839X_IGR_BWCTRL_LB_TICK_TKN_CTRL_1 (0x1608)
313 #define RTL839X_SCHED_LB_TICK_TKN_CTRL (0x60F8)
314 #define RTL839X_SCHED_LB_TICK_TKN_PPS_CTRL (0x6200)
315 #define RTL838X_SCHED_LB_THR (0xB984)
316 #define RTL839X_SCHED_LB_THR (0x60FC)
317 #define RTL838X_SCHED_P_EGR_RATE_CTRL(p) (0xC008 + (((p) << 7)))
318 #define RTL838X_SCHED_Q_EGR_RATE_CTRL(p, q) (0xC00C + (p << 7) + (((q) << 2)))
319 #define RTL838X_STORM_CTRL_PORT_BC_EXCEED (0x470C)
320 #define RTL838X_STORM_CTRL_PORT_MC_EXCEED (0x4710)
321 #define RTL838X_STORM_CTRL_PORT_UC_EXCEED (0x4714)
322 #define RTL839X_STORM_CTRL_PORT_BC_EXCEED(p) (0x180c + (((p >> 5) << 2)))
323 #define RTL839X_STORM_CTRL_PORT_MC_EXCEED(p) (0x1814 + (((p >> 5) << 2)))
324 #define RTL839X_STORM_CTRL_PORT_UC_EXCEED(p) (0x181c + (((p >> 5) << 2)))
325 #define RTL838X_STORM_CTRL_PORT_UC(p) (0x4718 + (((p) << 2)))
326 #define RTL838X_STORM_CTRL_PORT_MC(p) (0x478c + (((p) << 2)))
327 #define RTL838X_STORM_CTRL_PORT_BC(p) (0x4800 + (((p) << 2)))
328 #define RTL839X_STORM_CTRL_PORT_UC_0(p) (0x185C + (((p) << 3)))
329 #define RTL839X_STORM_CTRL_PORT_UC_1(p) (0x1860 + (((p) << 3)))
330 #define RTL839X_STORM_CTRL_PORT_MC_0(p) (0x19FC + (((p) << 3)))
331 #define RTL839X_STORM_CTRL_PORT_MC_1(p) (0x1a00 + (((p) << 3)))
332 #define RTL839X_STORM_CTRL_PORT_BC_0(p) (0x1B9C + (((p) << 3)))
333 #define RTL839X_STORM_CTRL_PORT_BC_1(p) (0x1BA0 + (((p) << 3)))
334 #define RTL839X_TBL_ACCESS_CTRL_2 (0x611C)
335 #define RTL839X_TBL_ACCESS_DATA_2(i) (0x6120 + (((i) << 2)))
336 #define RTL839X_IGR_BWCTRL_PORT_CTRL_10G_0(p) (0x1618 + (((p) << 3)))
337 #define RTL839X_IGR_BWCTRL_PORT_CTRL_10G_1(p) (0x161C + (((p) << 3)))
338 #define RTL839X_IGR_BWCTRL_PORT_CTRL_0(p) (0x1640 + (((p) << 3)))
339 #define RTL839X_IGR_BWCTRL_PORT_CTRL_1(p) (0x1644 + (((p) << 3)))
340 #define RTL839X_IGR_BWCTRL_CTRL_LB_THR (0x1614)
341
342 /* Link aggregation (Trunking) */
343 #define TRUNK_DISTRIBUTION_ALGO_SPA_BIT 0x01
344 #define TRUNK_DISTRIBUTION_ALGO_SMAC_BIT 0x02
345 #define TRUNK_DISTRIBUTION_ALGO_DMAC_BIT 0x04
346 #define TRUNK_DISTRIBUTION_ALGO_SIP_BIT 0x08
347 #define TRUNK_DISTRIBUTION_ALGO_DIP_BIT 0x10
348 #define TRUNK_DISTRIBUTION_ALGO_SRC_L4PORT_BIT 0x20
349 #define TRUNK_DISTRIBUTION_ALGO_DST_L4PORT_BIT 0x40
350 #define TRUNK_DISTRIBUTION_ALGO_MASKALL 0x7F
351
352 #define TRUNK_DISTRIBUTION_ALGO_L2_SPA_BIT 0x01
353 #define TRUNK_DISTRIBUTION_ALGO_L2_SMAC_BIT 0x02
354 #define TRUNK_DISTRIBUTION_ALGO_L2_DMAC_BIT 0x04
355 #define TRUNK_DISTRIBUTION_ALGO_L2_VLAN_BIT 0x08
356 #define TRUNK_DISTRIBUTION_ALGO_L2_MASKALL 0xF
357
358 #define TRUNK_DISTRIBUTION_ALGO_L3_SPA_BIT 0x01
359 #define TRUNK_DISTRIBUTION_ALGO_L3_SMAC_BIT 0x02
360 #define TRUNK_DISTRIBUTION_ALGO_L3_DMAC_BIT 0x04
361 #define TRUNK_DISTRIBUTION_ALGO_L3_VLAN_BIT 0x08
362 #define TRUNK_DISTRIBUTION_ALGO_L3_SIP_BIT 0x10
363 #define TRUNK_DISTRIBUTION_ALGO_L3_DIP_BIT 0x20
364 #define TRUNK_DISTRIBUTION_ALGO_L3_SRC_L4PORT_BIT 0x40
365 #define TRUNK_DISTRIBUTION_ALGO_L3_DST_L4PORT_BIT 0x80
366 #define TRUNK_DISTRIBUTION_ALGO_L3_PROTO_BIT 0x100
367 #define TRUNK_DISTRIBUTION_ALGO_L3_FLOW_LABEL_BIT 0x200
368 #define TRUNK_DISTRIBUTION_ALGO_L3_MASKALL 0x3FF
369
370 #define RTL838X_TRK_MBR_CTR (0x3E00)
371 #define RTL838X_TRK_HASH_IDX_CTRL (0x3E20)
372 #define RTL838X_TRK_HASH_CTRL (0x3E24)
373
374 #define RTL839X_TRK_MBR_CTR (0x2200)
375 #define RTL839X_TRK_HASH_IDX_CTRL (0x2280)
376 #define RTL839X_TRK_HASH_CTRL (0x2284)
377
378 #define RTL930X_TRK_MBR_CTRL (0xA41C)
379 #define RTL930X_TRK_HASH_CTRL (0x9F80)
380
381 #define RTL931X_TRK_MBR_CTRL (0xB8D0)
382 #define RTL931X_TRK_HASH_CTRL (0xBA70)
383
384 /* Attack prevention */
385 #define RTL838X_ATK_PRVNT_PORT_EN (0x5B00)
386 #define RTL838X_ATK_PRVNT_CTRL (0x5B04)
387 #define RTL838X_ATK_PRVNT_ACT (0x5B08)
388 #define RTL838X_ATK_PRVNT_STS (0x5B1C)
389
390 /* 802.1X */
391 #define RTL838X_RMA_BPDU_FLD_PMSK (0x4348)
392 #define RTL930X_RMA_BPDU_FLD_PMSK (0x9F18)
393 #define RTL931X_RMA_BPDU_FLD_PMSK (0x8950)
394 #define RTL839X_RMA_BPDU_FLD_PMSK (0x125C)
395
396 #define RTL838X_SPCL_TRAP_CTRL (0x6980)
397 #define RTL838X_SPCL_TRAP_EAPOL_CTRL (0x6988)
398 #define RTL838X_SPCL_TRAP_ARP_CTRL (0x698C)
399 #define RTL838X_SPCL_TRAP_IGMP_CTRL (0x6984)
400 #define RTL838X_SPCL_TRAP_IPV6_CTRL (0x6994)
401 #define RTL838X_SPCL_TRAP_SWITCH_MAC_CTRL (0x6998)
402
403 #define RTL839X_SPCL_TRAP_CTRL (0x1054)
404 #define RTL839X_SPCL_TRAP_EAPOL_CTRL (0x105C)
405 #define RTL839X_SPCL_TRAP_ARP_CTRL (0x1060)
406 #define RTL839X_SPCL_TRAP_IGMP_CTRL (0x1058)
407 #define RTL839X_SPCL_TRAP_IPV6_CTRL (0x1064)
408 #define RTL839X_SPCL_TRAP_SWITCH_MAC_CTRL (0x1068)
409 #define RTL839X_SPCL_TRAP_SWITCH_IPV4_ADDR_CTRL (0x106C)
410 #define RTL839X_SPCL_TRAP_CRC_CTRL (0x1070)
411 /* special port action controls */
412 /* values:
413 * 0 = FORWARD (default)
414 * 1 = DROP
415 * 2 = TRAP2CPU
416 * 3 = FLOOD IN ALL PORT
417 *
418 * Register encoding.
419 * offset = CTRL + (port >> 4) << 2
420 * value/mask = 3 << ((port & 0xF) << 1)
421 */
422
423 typedef enum {
424 BPDU = 0,
425 PTP,
426 PTP_UDP,
427 PTP_ETH2,
428 LLTP,
429 EAPOL,
430 GRATARP,
431 } rma_ctrl_t;
432
433 typedef enum {
434 FORWARD = 0,
435 DROP,
436 TRAP2CPU,
437 FLOODALL,
438 TRAP2MASTERCPU,
439 COPY2CPU,
440 } action_type_t;
441
442 #define RTL838X_RMA_BPDU_CTRL (0x4330)
443 #define RTL839X_RMA_BPDU_CTRL (0x122C)
444 #define RTL930X_RMA_BPDU_CTRL (0x9E7C)
445 #define RTL931X_RMA_BPDU_CTRL (0x881C)
446
447 #define RTL838X_RMA_PTP_CTRL (0x4338)
448 #define RTL839X_RMA_PTP_CTRL (0x123C)
449 #define RTL930X_RMA_PTP_CTRL (0x9E88)
450 #define RTL931X_RMA_PTP_CTRL (0x8834)
451
452 #define RTL838X_RMA_LLTP_CTRL (0x4340)
453 #define RTL839X_RMA_LLTP_CTRL (0x124C)
454 #define RTL930X_RMA_LLTP_CTRL (0x9EFC)
455 #define RTL931X_RMA_LLTP_CTRL (0x8918)
456
457 #define RTL930X_RMA_EAPOL_CTRL (0x9F08)
458 #define RTL931X_RMA_EAPOL_CTRL (0x8930)
459 #define RTL931X_TRAP_ARP_GRAT_PORT_ACT (0x8C04)
460
461 /* QoS */
462 #define RTL838X_QM_INTPRI2QID_CTRL (0x5F00)
463 #define RTL839X_QM_INTPRI2QID_CTRL(q) (0x1110 + (q << 2))
464 #define RTL839X_QM_PORT_QNUM(p) (0x1130 + (((p / 10) << 2)))
465 #define RTL838X_PRI_SEL_PORT_PRI(p) (0x5FB8 + (((p / 10) << 2)))
466 #define RTL839X_PRI_SEL_PORT_PRI(p) (0x10A8 + (((p / 10) << 2)))
467 #define RTL838X_QM_PKT2CPU_INTPRI_MAP (0x5F10)
468 #define RTL839X_QM_PKT2CPU_INTPRI_MAP (0x1154)
469 #define RTL838X_PRI_SEL_CTRL (0x10E0)
470 #define RTL839X_PRI_SEL_CTRL (0x10E0)
471 #define RTL838X_PRI_SEL_TBL_CTRL(i) (0x5FD8 + (((i) << 2)))
472 #define RTL839X_PRI_SEL_TBL_CTRL(i) (0x10D0 + (((i) << 2)))
473 #define RTL838X_QM_PKT2CPU_INTPRI_0 (0x5F04)
474 #define RTL838X_QM_PKT2CPU_INTPRI_1 (0x5F08)
475 #define RTL838X_QM_PKT2CPU_INTPRI_2 (0x5F0C)
476 #define RTL839X_OAM_CTRL (0x2100)
477 #define RTL839X_OAM_PORT_ACT_CTRL(p) (0x2104 + (((p) << 2)))
478 #define RTL839X_RMK_PORT_DEI_TAG_CTRL(p) (0x6A9C + (((p >> 5) << 2)))
479 #define RTL839X_PRI_SEL_IPRI_REMAP (0x1080)
480 #define RTL838X_PRI_SEL_IPRI_REMAP (0x5F8C)
481 #define RTL839X_PRI_SEL_DEI2DP_REMAP (0x10EC)
482 #define RTL839X_PRI_SEL_DSCP2DP_REMAP_ADDR(i) (0x10F0 + (((i >> 4) << 2)))
483 #define RTL839X_RMK_DEI_CTRL (0x6AA4)
484 #define RTL839X_WRED_PORT_THR_CTRL(i) (0x6084 + ((i) << 2))
485 #define RTL839X_WRED_QUEUE_THR_CTRL(q, i) (0x6090 + ((q) * 12) + ((i) << 2))
486 #define RTL838X_PRI_DSCP_INVLD_CTRL0 (0x5FE8)
487 #define RTL838X_RMK_IPRI_CTRL (0xA460)
488 #define RTL838X_RMK_OPRI_CTRL (0xA464)
489 #define RTL838X_SCHED_P_TYPE_CTRL(p) (0xC04C + (((p) << 7)))
490 #define RTL838X_SCHED_LB_CTRL(p) (0xC004 + (((p) << 7)))
491 #define RTL838X_FC_P_EGR_DROP_CTRL(p) (0x6B1C + (((p) << 2)))
492
493 /* Debug features */
494 #define RTL930X_STAT_PRVTE_DROP_COUNTER0 (0xB5B8)
495
496 /* Packet Inspection Engine */
497 #define RTL838X_METER_GLB_CTRL (0x4B08)
498 #define RTL839X_METER_GLB_CTRL (0x1300)
499 #define RTL930X_METER_GLB_CTRL (0xa0a0)
500 #define RTL931X_METER_GLB_CTRL (0x411C)
501
502 #define RTL839X_ACL_CTRL (0x1288)
503
504 #define RTL838X_ACL_BLK_LOOKUP_CTRL (0x6100)
505 #define RTL839X_ACL_BLK_LOOKUP_CTRL (0x1280)
506 #define RTL930X_PIE_BLK_LOOKUP_CTRL (0xa5a0)
507 #define RTL931X_PIE_BLK_LOOKUP_CTRL (0x4180)
508
509 #define RTL838X_ACL_BLK_PWR_CTRL (0x6104)
510 #define RTL839X_PS_ACL_PWR_CTRL (0x049c)
511
512 #define RTL838X_ACL_BLK_TMPLTE_CTRL(block) (0x6108 + ((block) << 2))
513 #define RTL839X_ACL_BLK_TMPLTE_CTRL(block) (0x128c + ((block) << 2))
514 #define RTL930X_PIE_BLK_TMPLTE_CTRL(block) (0xa624 + ((block) << 2))
515 #define RTL931X_PIE_BLK_TMPLTE_CTRL(block) (0x4214 + ((block) << 2))
516
517 #define RTL838X_ACL_BLK_GROUP_CTRL (0x615C)
518 #define RTL839X_ACL_BLK_GROUP_CTRL (0x12ec)
519
520 #define RTL838X_ACL_CLR_CTRL (0x6168)
521 #define RTL839X_ACL_CLR_CTRL (0x12fc)
522 #define RTL930X_PIE_CLR_CTRL (0xa66c)
523 #define RTL931X_PIE_CLR_CTRL (0x42D8)
524
525 #define RTL838X_DMY_REG27 (0x3378)
526
527 #define RTL838X_ACL_PORT_LOOKUP_CTRL(p) (0x616C + (((p) << 2)))
528 #define RTL930X_ACL_PORT_LOOKUP_CTRL(p) (0xA784 + (((p) << 2)))
529 #define RTL931X_ACL_PORT_LOOKUP_CTRL(p) (0x44F8 + (((p) << 2)))
530
531 #define RTL930X_PIE_BLK_PHASE_CTRL (0xA5A4)
532 #define RTL931X_PIE_BLK_PHASE_CTRL (0x4184)
533
534 /* PIE actions */
535 #define PIE_ACT_COPY_TO_PORT 2
536 #define PIE_ACT_REDIRECT_TO_PORT 4
537 #define PIE_ACT_ROUTE_UC 6
538 #define PIE_ACT_VID_ASSIGN 0
539
540 /* L3 actions */
541 #define L3_FORWARD 0
542 #define L3_DROP 1
543 #define L3_TRAP2CPU 2
544 #define L3_COPY2CPU 3
545 #define L3_TRAP2MASTERCPU 4
546 #define L3_COPY2MASTERCPU 5
547 #define L3_HARDDROP 6
548
549 /* Route actions */
550 #define ROUTE_ACT_FORWARD 0
551 #define ROUTE_ACT_TRAP2CPU 1
552 #define ROUTE_ACT_COPY2CPU 2
553 #define ROUTE_ACT_DROP 3
554
555 /* L3 Routing */
556 #define RTL839X_ROUTING_SA_CTRL 0x6afc
557 #define RTL930X_L3_HOST_TBL_CTRL (0xAB48)
558 #define RTL930X_L3_IPUC_ROUTE_CTRL (0xAB4C)
559 #define RTL930X_L3_IP6UC_ROUTE_CTRL (0xAB50)
560 #define RTL930X_L3_IPMC_ROUTE_CTRL (0xAB54)
561 #define RTL930X_L3_IP6MC_ROUTE_CTRL (0xAB58)
562 #define RTL930X_L3_IP_MTU_CTRL(i) (0xAB5C + ((i >> 1) << 2))
563 #define RTL930X_L3_IP6_MTU_CTRL(i) (0xAB6C + ((i >> 1) << 2))
564 #define RTL930X_L3_HW_LU_KEY_CTRL (0xAC9C)
565 #define RTL930X_L3_HW_LU_KEY_IP_CTRL (0xACA0)
566 #define RTL930X_L3_HW_LU_CTRL (0xACC0)
567 #define RTL930X_L3_IP_ROUTE_CTRL 0xab44
568
569 /* Port LED Control */
570 #define RTL930X_LED_PORT_NUM_CTRL(p) (0xCC04 + (((p >> 4) << 2)))
571 #define RTL930X_LED_SET0_0_CTRL (0xCC28)
572 #define RTL930X_LED_PORT_COPR_SET_SEL_CTRL(p) (0xCC2C + (((p >> 4) << 2)))
573 #define RTL930X_LED_PORT_FIB_SET_SEL_CTRL(p) (0xCC34 + (((p >> 4) << 2)))
574 #define RTL930X_LED_PORT_COPR_MASK_CTRL (0xCC3C)
575 #define RTL930X_LED_PORT_FIB_MASK_CTRL (0xCC40)
576 #define RTL930X_LED_PORT_COMBO_MASK_CTRL (0xCC44)
577
578 #define RTL931X_LED_PORT_NUM_CTRL(p) (0x0604 + (((p >> 4) << 2)))
579 #define RTL931X_LED_SET0_0_CTRL (0x0630)
580 #define RTL931X_LED_PORT_COPR_SET_SEL_CTRL(p) (0x0634 + (((p >> 4) << 2)))
581 #define RTL931X_LED_PORT_FIB_SET_SEL_CTRL(p) (0x0644 + (((p >> 4) << 2)))
582 #define RTL931X_LED_PORT_COPR_MASK_CTRL (0x0654)
583 #define RTL931X_LED_PORT_FIB_MASK_CTRL (0x065c)
584 #define RTL931X_LED_PORT_COMBO_MASK_CTRL (0x0664)
585
586 #define MAX_VLANS 4096
587 #define MAX_LAGS 16
588 #define MAX_PRIOS 8
589 #define RTL930X_PORT_IGNORE 0x3f
590 #define MAX_MC_GROUPS 512
591 #define UNKNOWN_MC_PMASK (MAX_MC_GROUPS - 1)
592 #define PIE_BLOCK_SIZE 128
593 #define MAX_PIE_ENTRIES (18 * PIE_BLOCK_SIZE)
594 #define N_FIXED_FIELDS 12
595 #define N_FIXED_FIELDS_RTL931X 14
596 #define MAX_COUNTERS 2048
597 #define MAX_ROUTES 512
598 #define MAX_HOST_ROUTES 1536
599 #define MAX_INTF_MTUS 8
600 #define DEFAULT_MTU 1536
601 #define MAX_INTERFACES 100
602 #define MAX_ROUTER_MACS 64
603 #define L3_EGRESS_DMACS 2048
604 #define MAX_SMACS 64
605
606 enum phy_type {
607 PHY_NONE = 0,
608 PHY_RTL838X_SDS = 1,
609 PHY_RTL8218B_INT = 2,
610 PHY_RTL8218B_EXT = 3,
611 PHY_RTL8214FC = 4,
612 PHY_RTL839X_SDS = 5,
613 PHY_RTL930X_SDS = 6,
614 };
615
616 enum pbvlan_type {
617 PBVLAN_TYPE_INNER = 0,
618 PBVLAN_TYPE_OUTER,
619 };
620
621 enum pbvlan_mode {
622 PBVLAN_MODE_UNTAG_AND_PRITAG = 0,
623 PBVLAN_MODE_UNTAG_ONLY,
624 PBVLAN_MODE_ALL_PKT,
625 };
626
627 struct rtl838x_port {
628 bool enable;
629 u64 pm;
630 u16 pvid;
631 bool eee_enabled;
632 enum phy_type phy;
633 bool phy_is_integrated;
634 bool is10G;
635 bool is2G5;
636 int sds_num;
637 int led_set;
638 const struct dsa_port *dp;
639 };
640
641 struct rtl838x_vlan_info {
642 u64 untagged_ports;
643 u64 tagged_ports;
644 u8 profile_id;
645 bool hash_mc_fid;
646 bool hash_uc_fid;
647 u8 fid; /* AKA MSTI */
648
649 /* The following fields are used only by the RTL931X */
650 int if_id; /* Interface (index in L3_EGR_INTF_IDX) */
651 u16 multicast_grp_mask;
652 int l2_tunnel_list_id;
653 };
654
655 enum l2_entry_type {
656 L2_INVALID = 0,
657 L2_UNICAST = 1,
658 L2_MULTICAST = 2,
659 IP4_MULTICAST = 3,
660 IP6_MULTICAST = 4,
661 };
662
663 struct rtl838x_l2_entry {
664 u8 mac[6];
665 u16 vid;
666 u16 rvid;
667 u8 port;
668 bool valid;
669 enum l2_entry_type type;
670 bool is_static;
671 bool is_ip_mc;
672 bool is_ipv6_mc;
673 bool block_da;
674 bool block_sa;
675 bool suspended;
676 bool next_hop;
677 int age;
678 u8 trunk;
679 bool is_trunk;
680 u8 stack_dev;
681 u16 mc_portmask_index;
682 u32 mc_gip;
683 u32 mc_sip;
684 u16 mc_mac_index;
685 u16 nh_route_id;
686 bool nh_vlan_target; /* Only RTL83xx: VLAN used for next hop */
687
688 /* The following is only valid on RTL931x */
689 bool is_open_flow;
690 bool is_pe_forward;
691 bool is_local_forward;
692 bool is_remote_forward;
693 bool is_l2_tunnel;
694 int l2_tunnel_id;
695 int l2_tunnel_list_id;
696 };
697
698 enum fwd_rule_action {
699 FWD_RULE_ACTION_NONE = 0,
700 FWD_RULE_ACTION_FWD = 1,
701 };
702
703 enum pie_phase {
704 PHASE_VACL = 0,
705 PHASE_IACL = 1,
706 };
707
708 enum igr_filter {
709 IGR_FORWARD = 0,
710 IGR_DROP = 1,
711 IGR_TRAP = 2,
712 };
713
714 enum egr_filter {
715 EGR_DISABLE = 0,
716 EGR_ENABLE = 1,
717 };
718
719 /* Intermediate representation of a Packet Inspection Engine Rule
720 * as suggested by the Kernel's tc flower offload subsystem
721 * Field meaning is universal across SoC families, but data content is specific
722 * to SoC family (e.g. because of different port ranges) */
723 struct pie_rule {
724 int id;
725 enum pie_phase phase; /* Phase in which this template is applied */
726 int packet_cntr; /* ID of a packet counter assigned to this rule */
727 int octet_cntr; /* ID of a byte counter assigned to this rule */
728 u32 last_packet_cnt;
729 u64 last_octet_cnt;
730
731 /* The following are requirements for the pie template */
732 bool is_egress;
733 bool is_ipv6; /* This is a rule with IPv6 fields */
734
735 /* Fixed fields that are always matched against on RTL8380 */
736 u8 spmmask_fix;
737 u8 spn; /* Source port number */
738 bool stacking_port; /* Source port is stacking port */
739 bool mgnt_vlan; /* Packet arrived on management VLAN */
740 bool dmac_hit_sw; /* The packet's destination MAC matches one of the device's */
741 bool content_too_deep; /* The content of the packet cannot be parsed: too many layers */
742 bool not_first_frag; /* Not the first IP fragment */
743 u8 frame_type_l4; /* 0: UDP, 1: TCP, 2: ICMP/ICMPv6, 3: IGMP */
744 u8 frame_type; /* 0: ARP, 1: L2 only, 2: IPv4, 3: IPv6 */
745 bool otag_fmt; /* 0: outer tag packet, 1: outer priority tag or untagged */
746 bool itag_fmt; /* 0: inner tag packet, 1: inner priority tag or untagged */
747 bool otag_exist; /* packet with outer tag */
748 bool itag_exist; /* packet with inner tag */
749 bool frame_type_l2; /* 0: Ethernet, 1: LLC_SNAP, 2: LLC_Other, 3: Reserved */
750 bool igr_normal_port; /* Ingress port is not cpu or stacking port */
751 u8 tid; /* The template ID defining the what the templated fields mean */
752
753 /* Masks for the fields that are always matched against on RTL8380 */
754 u8 spmmask_fix_m;
755 u8 spn_m;
756 bool stacking_port_m;
757 bool mgnt_vlan_m;
758 bool dmac_hit_sw_m;
759 bool content_too_deep_m;
760 bool not_first_frag_m;
761 u8 frame_type_l4_m;
762 u8 frame_type_m;
763 bool otag_fmt_m;
764 bool itag_fmt_m;
765 bool otag_exist_m;
766 bool itag_exist_m;
767 bool frame_type_l2_m;
768 bool igr_normal_port_m;
769 u8 tid_m;
770
771 /* Logical operations between rules, special rules for rule numbers apply */
772 bool valid;
773 bool cond_not; /* Matches when conditions not match */
774 bool cond_and1; /* And this rule 2n with the next rule 2n+1 in same block */
775 bool cond_and2; /* And this rule m in block 2n with rule m in block 2n+1 */
776 bool ivalid;
777
778 /* Actions to be performed */
779 bool drop; /* Drop the packet */
780 bool fwd_sel; /* Forward packet: to port, portmask, dest route, next rule, drop */
781 bool ovid_sel; /* So something to outer vlan-id: shift, re-assign */
782 bool ivid_sel; /* Do something to inner vlan-id: shift, re-assign */
783 bool flt_sel; /* Filter the packet when sending to certain ports */
784 bool log_sel; /* Log the packet in one of the LOG-table counters */
785 bool rmk_sel; /* Re-mark the packet, i.e. change the priority-tag */
786 bool meter_sel; /* Meter the packet, i.e. limit rate of this type of packet */
787 bool tagst_sel; /* Change the ergress tag */
788 bool mir_sel; /* Mirror the packet to a Link Aggregation Group */
789 bool nopri_sel; /* Change the normal priority */
790 bool cpupri_sel; /* Change the CPU priority */
791 bool otpid_sel; /* Change Outer Tag Protocol Identifier (802.1q) */
792 bool itpid_sel; /* Change Inner Tag Protocol Identifier (802.1q) */
793 bool shaper_sel; /* Apply traffic shaper */
794 bool mpls_sel; /* MPLS actions */
795 bool bypass_sel; /* Bypass actions */
796 bool fwd_sa_lrn; /* Learn the source address when forwarding */
797 bool fwd_mod_to_cpu; /* Forward the modified VLAN tag format to CPU-port */
798
799 /* Fields used in predefined templates 0-2 on RTL8380 / 90 / 9300 */
800 u64 spm; /* Source Port Matrix */
801 u16 otag; /* Outer VLAN-ID */
802 u8 smac[ETH_ALEN]; /* Source MAC address */
803 u8 dmac[ETH_ALEN]; /* Destination MAC address */
804 u16 ethertype; /* Ethernet frame type field in ethernet header */
805 u16 itag; /* Inner VLAN-ID */
806 u16 field_range_check;
807 u32 sip; /* Source IP */
808 struct in6_addr sip6; /* IPv6 Source IP */
809 u32 dip; /* Destination IP */
810 struct in6_addr dip6; /* IPv6 Destination IP */
811 u16 tos_proto; /* IPv4: TOS + Protocol fields, IPv6: Traffic class + next header */
812 u16 sport; /* TCP/UDP source port */
813 u16 dport; /* TCP/UDP destination port */
814 u16 icmp_igmp;
815 u16 tcp_info;
816 u16 dsap_ssap; /* Destination / Source Service Access Point bytes (802.3) */
817
818 u64 spm_m;
819 u16 otag_m;
820 u8 smac_m[ETH_ALEN];
821 u8 dmac_m[ETH_ALEN];
822 u8 ethertype_m;
823 u16 itag_m;
824 u16 field_range_check_m;
825 u32 sip_m;
826 struct in6_addr sip6_m; /* IPv6 Source IP mask */
827 u32 dip_m;
828 struct in6_addr dip6_m; /* IPv6 Destination IP mask */
829 u16 tos_proto_m;
830 u16 sport_m;
831 u16 dport_m;
832 u16 icmp_igmp_m;
833 u16 tcp_info_m;
834 u16 dsap_ssap_m;
835
836 /* Data associated with actions */
837 u8 fwd_act; /* Type of forwarding action */
838 /* 0: permit, 1: drop, 2: copy to port id, 4: copy to portmask */
839 /* 4: redirect to portid, 5: redirect to portmask */
840 /* 6: route, 7: vlan leaky (only 8380) */
841 u16 fwd_data; /* Additional data for forwarding action, e.g. destination port */
842 u8 ovid_act;
843 u16 ovid_data; /* Outer VLAN ID */
844 u8 ivid_act;
845 u16 ivid_data; /* Inner VLAN ID */
846 u16 flt_data; /* Filtering data */
847 u16 log_data; /* ID of packet or octet counter in LOG table, on RTL93xx */
848 /* unnecessary since PIE-Rule-ID == LOG-counter-ID */
849 bool log_octets;
850 u8 mpls_act; /* MPLS action type */
851 u16 mpls_lib_idx; /* MPLS action data */
852
853 u16 rmk_data; /* Data for remarking */
854 u16 meter_data; /* ID of meter for bandwidth control */
855 u16 tagst_data;
856 u16 mir_data;
857 u16 nopri_data;
858 u16 cpupri_data;
859 u16 otpid_data;
860 u16 itpid_data;
861 u16 shaper_data;
862
863 /* Bypass actions, ignored on RTL8380 */
864 bool bypass_all; /* Not clear */
865 bool bypass_igr_stp; /* Bypass Ingress STP state */
866 bool bypass_ibc_sc; /* Bypass Ingress Bandwidth Control and Storm Control */
867 };
868
869 struct rtl838x_l3_intf {
870 u16 vid;
871 u8 smac_idx;
872 u8 ip4_mtu_id;
873 u8 ip6_mtu_id;
874 u16 ip4_mtu;
875 u16 ip6_mtu;
876 u8 ttl_scope;
877 u8 hl_scope;
878 u8 ip4_icmp_redirect;
879 u8 ip6_icmp_redirect;
880 u8 ip4_pbr_icmp_redirect;
881 u8 ip6_pbr_icmp_redirect;
882 };
883
884 /* An entry in the RTL93XX SoC's ROUTER_MAC tables setting up a termination point
885 * for the L3 routing system. Packets arriving and matching an entry in this table
886 * will be considered for routing.
887 * Mask fields state whether the corresponding data fields matter for matching
888 */
889 struct rtl93xx_rt_mac {
890 bool valid; /* Valid or not */
891 bool p_type; /* Individual (0) or trunk (1) port */
892 bool p_mask; /* Whether the port type is used */
893 u8 p_id;
894 u8 p_id_mask; /* Mask for the port */
895 u8 action; /* Routing action performed: 0: FORWARD, 1: DROP, 2: TRAP2CPU */
896 /* 3: COPY2CPU, 4: TRAP2MASTERCPU, 5: COPY2MASTERCPU, 6: HARDDROP */
897 u16 vid;
898 u16 vid_mask;
899 u64 mac; /* MAC address used as source MAC in the routed packet */
900 u64 mac_mask;
901 };
902
903 struct rtl83xx_nexthop {
904 u16 id; /* ID: L3_NEXT_HOP table-index or route-index set in L2_NEXT_HOP */
905 u32 dev_id;
906 u16 port;
907 u16 vid; /* VLAN-ID for L2 table entry (saved from L2-UC entry) */
908 u16 rvid; /* Relay VID/FID for the L2 table entry */
909 u64 mac; /* The MAC address of the entry in the L2_NEXT_HOP table */
910 u16 mac_id;
911 u16 l2_id; /* Index of this next hop forwarding entry in L2 FIB table */
912 u64 gw; /* The gateway MAC address packets are forwarded to */
913 int if_id; /* Interface (into L3_EGR_INTF_IDX) */
914 };
915
916 struct rtl838x_switch_priv;
917
918 struct rtl83xx_flow {
919 unsigned long cookie;
920 struct rhash_head node;
921 struct rcu_head rcu_head;
922 struct rtl838x_switch_priv *priv;
923 struct pie_rule rule;
924 u32 flags;
925 };
926
927 struct rtl93xx_route_attr {
928 bool valid;
929 bool hit;
930 bool ttl_dec;
931 bool ttl_check;
932 bool dst_null;
933 bool qos_as;
934 u8 qos_prio;
935 u8 type;
936 u8 action;
937 };
938
939 struct rtl83xx_route {
940 u32 gw_ip; /* IP of the route's gateway */
941 u32 dst_ip; /* IP of the destination net */
942 struct in6_addr dst_ip6;
943 int prefix_len; /* Network prefix len of the destination net */
944 bool is_host_route;
945 int id; /* ID number of this route */
946 struct rhlist_head linkage;
947 u16 switch_mac_id; /* Index into switch's own MACs, RTL839X only */
948 struct rtl83xx_nexthop nh;
949 struct pie_rule pr;
950 struct rtl93xx_route_attr attr;
951 };
952
953 struct rtl838x_reg {
954 void (*mask_port_reg_be)(u64 clear, u64 set, int reg);
955 void (*set_port_reg_be)(u64 set, int reg);
956 u64 (*get_port_reg_be)(int reg);
957 void (*mask_port_reg_le)(u64 clear, u64 set, int reg);
958 void (*set_port_reg_le)(u64 set, int reg);
959 u64 (*get_port_reg_le)(int reg);
960 int stat_port_rst;
961 int stat_rst;
962 int stat_port_std_mib;
963 int (*port_iso_ctrl)(int p);
964 void (*traffic_enable)(int source, int dest);
965 void (*traffic_disable)(int source, int dest);
966 void (*traffic_set)(int source, u64 dest_matrix);
967 u64 (*traffic_get)(int source);
968 int l2_ctrl_0;
969 int l2_ctrl_1;
970 int smi_poll_ctrl;
971 u32 l2_port_aging_out;
972 int l2_tbl_flush_ctrl;
973 void (*exec_tbl0_cmd)(u32 cmd);
974 void (*exec_tbl1_cmd)(u32 cmd);
975 int (*tbl_access_data_0)(int i);
976 int isr_glb_src;
977 int isr_port_link_sts_chg;
978 int imr_port_link_sts_chg;
979 int imr_glb;
980 void (*vlan_tables_read)(u32 vlan, struct rtl838x_vlan_info *info);
981 void (*vlan_set_tagged)(u32 vlan, struct rtl838x_vlan_info *info);
982 void (*vlan_set_untagged)(u32 vlan, u64 portmask);
983 void (*vlan_profile_dump)(int index);
984 void (*vlan_profile_setup)(int profile);
985 void (*vlan_port_pvidmode_set)(int port, enum pbvlan_type type, enum pbvlan_mode mode);
986 void (*vlan_port_pvid_set)(int port, enum pbvlan_type type, int pvid);
987 void (*vlan_port_keep_tag_set)(int port, bool keep_outer, bool keep_inner);
988 void (*set_vlan_igr_filter)(int port, enum igr_filter state);
989 void (*set_vlan_egr_filter)(int port, enum egr_filter state);
990 void (*enable_learning)(int port, bool enable);
991 void (*enable_flood)(int port, bool enable);
992 void (*enable_mcast_flood)(int port, bool enable);
993 void (*enable_bcast_flood)(int port, bool enable);
994 void (*set_static_move_action)(int port, bool forward);
995 void (*stp_get)(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]);
996 void (*stp_set)(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]);
997 int (*mac_force_mode_ctrl)(int port);
998 int (*mac_port_ctrl)(int port);
999 int (*l2_port_new_salrn)(int port);
1000 int (*l2_port_new_sa_fwd)(int port);
1001 int (*set_ageing_time)(unsigned long msec);
1002 int mir_ctrl;
1003 int mir_dpm;
1004 int mir_spm;
1005 int mac_link_sts;
1006 int mac_link_dup_sts;
1007 int (*mac_link_spd_sts)(int port);
1008 int mac_rx_pause_sts;
1009 int mac_tx_pause_sts;
1010 u64 (*read_l2_entry_using_hash)(u32 hash, u32 position, struct rtl838x_l2_entry *e);
1011 void (*write_l2_entry_using_hash)(u32 hash, u32 pos, struct rtl838x_l2_entry *e);
1012 u64 (*read_cam)(int idx, struct rtl838x_l2_entry *e);
1013 void (*write_cam)(int idx, struct rtl838x_l2_entry *e);
1014 int (*trk_mbr_ctr)(int group);
1015 int rma_bpdu_fld_pmask;
1016 int spcl_trap_eapol_ctrl;
1017 void (*init_eee)(struct rtl838x_switch_priv *priv, bool enable);
1018 void (*port_eee_set)(struct rtl838x_switch_priv *priv, int port, bool enable);
1019 int (*eee_port_ability)(struct rtl838x_switch_priv *priv,
1020 struct ethtool_eee *e, int port);
1021 u64 (*l2_hash_seed)(u64 mac, u32 vid);
1022 u32 (*l2_hash_key)(struct rtl838x_switch_priv *priv, u64 seed);
1023 u64 (*read_mcast_pmask)(int idx);
1024 void (*write_mcast_pmask)(int idx, u64 portmask);
1025 void (*vlan_fwd_on_inner)(int port, bool is_set);
1026 void (*pie_init)(struct rtl838x_switch_priv *priv);
1027 int (*pie_rule_read)(struct rtl838x_switch_priv *priv, int idx, struct pie_rule *pr);
1028 int (*pie_rule_write)(struct rtl838x_switch_priv *priv, int idx, struct pie_rule *pr);
1029 int (*pie_rule_add)(struct rtl838x_switch_priv *priv, struct pie_rule *rule);
1030 void (*pie_rule_rm)(struct rtl838x_switch_priv *priv, struct pie_rule *rule);
1031 void (*l2_learning_setup)(void);
1032 u32 (*packet_cntr_read)(int counter);
1033 void (*packet_cntr_clear)(int counter);
1034 void (*route_read)(int idx, struct rtl83xx_route *rt);
1035 void (*route_write)(int idx, struct rtl83xx_route *rt);
1036 void (*host_route_write)(int idx, struct rtl83xx_route *rt);
1037 int (*l3_setup)(struct rtl838x_switch_priv *priv);
1038 void (*set_l3_nexthop)(int idx, u16 dmac_id, u16 interface);
1039 void (*get_l3_nexthop)(int idx, u16 *dmac_id, u16 *interface);
1040 u64 (*get_l3_egress_mac)(u32 idx);
1041 void (*set_l3_egress_mac)(u32 idx, u64 mac);
1042 int (*find_l3_slot)(struct rtl83xx_route *rt, bool must_exist);
1043 int (*route_lookup_hw)(struct rtl83xx_route *rt);
1044 void (*get_l3_router_mac)(u32 idx, struct rtl93xx_rt_mac *m);
1045 void (*set_l3_router_mac)(u32 idx, struct rtl93xx_rt_mac *m);
1046 void (*set_l3_egress_intf)(int idx, struct rtl838x_l3_intf *intf);
1047 void (*set_distribution_algorithm)(int group, int algoidx, u32 algomask);
1048 void (*set_receive_management_action)(int port, rma_ctrl_t type, action_type_t action);
1049 void (*led_init)(struct rtl838x_switch_priv *priv);
1050 };
1051
1052 struct rtl838x_switch_priv {
1053 /* Switch operation */
1054 struct dsa_switch *ds;
1055 struct device *dev;
1056 u16 id;
1057 u16 family_id;
1058 char version;
1059 struct rtl838x_port ports[57];
1060 struct mutex reg_mutex; /* Mutex for individual register manipulations */
1061 struct mutex pie_mutex; /* Mutex for Packet Inspection Engine */
1062 int link_state_irq;
1063 int mirror_group_ports[4];
1064 struct mii_bus *mii_bus;
1065 const struct rtl838x_reg *r;
1066 u8 cpu_port;
1067 u8 port_mask;
1068 u8 port_width;
1069 u8 port_ignore;
1070 u64 irq_mask;
1071 u32 fib_entries;
1072 int l2_bucket_size;
1073 struct dentry *dbgfs_dir;
1074 int n_lags;
1075 u64 lags_port_members[MAX_LAGS];
1076 struct net_device *lag_devs[MAX_LAGS];
1077 u32 lag_primary[MAX_LAGS];
1078 u32 is_lagmember[57];
1079 u64 lagmembers;
1080 struct notifier_block nb; /* TODO: change to different name */
1081 struct notifier_block ne_nb;
1082 struct notifier_block fib_nb;
1083 bool eee_enabled;
1084 unsigned long int mc_group_bm[MAX_MC_GROUPS >> 5];
1085 int mc_group_saves[MAX_MC_GROUPS];
1086 int n_pie_blocks;
1087 struct rhashtable tc_ht;
1088 unsigned long int pie_use_bm[MAX_PIE_ENTRIES >> 5];
1089 int n_counters;
1090 unsigned long int octet_cntr_use_bm[MAX_COUNTERS >> 5];
1091 unsigned long int packet_cntr_use_bm[MAX_COUNTERS >> 4];
1092 struct rhltable routes;
1093 unsigned long int route_use_bm[MAX_ROUTES >> 5];
1094 unsigned long int host_route_use_bm[MAX_HOST_ROUTES >> 5];
1095 struct rtl838x_l3_intf *interfaces[MAX_INTERFACES];
1096 u16 intf_mtus[MAX_INTF_MTUS];
1097 int intf_mtu_count[MAX_INTF_MTUS];
1098 };
1099
1100 void rtl838x_dbgfs_init(struct rtl838x_switch_priv *priv);
1101 void rtl930x_dbgfs_init(struct rtl838x_switch_priv *priv);
1102
1103 #endif /* _RTL838X_H */