realtek: Cleanup setting inner/outer PVID and Ingress/Egres VLAN filtering
[openwrt/staging/chunkeey.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 (0x3A7C)
70 #define RTL838X_VLAN_PORT_TAG_STS_CTRL (0xA530)
71
72 #define RTL839X_VLAN_PROFILE(idx) (0x25C0 + (((idx) << 3)))
73 #define RTL839X_VLAN_CTRL (0x26D4)
74 #define RTL839X_VLAN_PORT_PB_VLAN (0x26D8)
75 #define RTL839X_VLAN_PORT_IGR_FLTR (0x27B4)
76 #define RTL839X_VLAN_PORT_EGR_FLTR (0x27C4)
77 #define RTL839X_VLAN_PORT_TAG_STS_CTRL (0x6828)
78 #define RTL839X_VLAN_PORT_TAG_STS_CTRL (0x6828)
79
80 #define RTL930X_VLAN_PROFILE_SET(idx) (0x9c60 + (((idx) * 20)))
81 #define RTL930X_VLAN_CTRL (0x82D4)
82 #define RTL930X_VLAN_PORT_PB_VLAN (0x82D8)
83 #define RTL930X_VLAN_PORT_IGR_FLTR (0x83C0)
84 #define RTL930X_VLAN_PORT_EGR_FLTR (0x83C8)
85 #define RTL930X_VLAN_PORT_TAG_STS_CTRL (0xCE24)
86
87 #define RTL931X_VLAN_PROFILE_SET(idx) (0x9800 + (((idx) * 28)))
88 #define RTL931X_VLAN_CTRL (0x94E4)
89 #define RTL931X_VLAN_PORT_IGR_CTRL (0x94E8)
90 #define RTL931X_VLAN_PORT_IGR_FLTR (0x96B4)
91 #define RTL931X_VLAN_PORT_EGR_FLTR (0x96C4)
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 #define RTL930X_MAC_LINK_MEDIA_STS (0xCB14)
149
150 /* MAC link state bits */
151 #define RTL838X_FORCE_EN (1 << 0)
152 #define RTL838X_FORCE_LINK_EN (1 << 1)
153 #define RTL838X_NWAY_EN (1 << 2)
154 #define RTL838X_DUPLEX_MODE (1 << 3)
155 #define RTL838X_TX_PAUSE_EN (1 << 6)
156 #define RTL838X_RX_PAUSE_EN (1 << 7)
157 #define RTL838X_MAC_FORCE_FC_EN (1 << 8)
158
159 #define RTL839X_FORCE_EN (1 << 0)
160 #define RTL839X_FORCE_LINK_EN (1 << 1)
161 #define RTL839X_DUPLEX_MODE (1 << 2)
162 #define RTL839X_TX_PAUSE_EN (1 << 5)
163 #define RTL839X_RX_PAUSE_EN (1 << 6)
164 #define RTL839X_MAC_FORCE_FC_EN (1 << 7)
165
166 #define RTL930X_FORCE_EN (1 << 0)
167 #define RTL930X_FORCE_LINK_EN (1 << 1)
168 #define RTL930X_DUPLEX_MODE (1 << 2)
169 #define RTL930X_TX_PAUSE_EN (1 << 7)
170 #define RTL930X_RX_PAUSE_EN (1 << 8)
171 #define RTL930X_MAC_FORCE_FC_EN (1 << 9)
172
173 #define RTL931X_FORCE_EN (1 << 9)
174 #define RTL931X_FORCE_LINK_EN (1 << 0)
175 #define RTL931X_DUPLEX_MODE (1 << 2)
176 #define RTL931X_MAC_FORCE_FC_EN (1 << 4)
177 #define RTL931X_TX_PAUSE_EN (1 << 16)
178 #define RTL931X_RX_PAUSE_EN (1 << 17)
179
180 /* EEE */
181 #define RTL838X_MAC_EEE_ABLTY (0xa1a8)
182 #define RTL838X_EEE_PORT_TX_EN (0x014c)
183 #define RTL838X_EEE_PORT_RX_EN (0x0150)
184 #define RTL838X_EEE_CLK_STOP_CTRL (0x0148)
185 #define RTL838X_EEE_TX_TIMER_GIGA_CTRL (0xaa04)
186 #define RTL838X_EEE_TX_TIMER_GELITE_CTRL (0xaa08)
187
188 #define RTL839X_EEE_TX_TIMER_GELITE_CTRL (0x042C)
189 #define RTL839X_EEE_TX_TIMER_GIGA_CTRL (0x0430)
190 #define RTL839X_EEE_TX_TIMER_10G_CTRL (0x0434)
191 #define RTL839X_EEE_CTRL(p) (0x8008 + ((p) << 7))
192 #define RTL839X_MAC_EEE_ABLTY (0x03C8)
193
194 #define RTL930X_MAC_EEE_ABLTY (0xCB34)
195 #define RTL930X_EEE_CTRL(p) (0x3274 + ((p) << 6))
196 #define RTL930X_EEEP_PORT_CTRL(p) (0x3278 + ((p) << 6))
197
198 /* L2 functionality */
199 #define RTL838X_L2_CTRL_0 (0x3200)
200 #define RTL839X_L2_CTRL_0 (0x3800)
201 #define RTL930X_L2_CTRL (0x8FD8)
202 #define RTL931X_L2_CTRL (0xC800)
203 #define RTL838X_L2_CTRL_1 (0x3204)
204 #define RTL839X_L2_CTRL_1 (0x3804)
205 #define RTL930X_L2_AGE_CTRL (0x8FDC)
206 #define RTL931X_L2_AGE_CTRL (0xC804)
207 #define RTL838X_L2_PORT_AGING_OUT (0x3358)
208 #define RTL839X_L2_PORT_AGING_OUT (0x3b74)
209 #define RTL930X_L2_PORT_AGE_CTRL (0x8FE0)
210 #define RTL931X_L2_PORT_AGE_CTRL (0xc808)
211 #define RTL838X_TBL_ACCESS_L2_CTRL (0x6900)
212 #define RTL839X_TBL_ACCESS_L2_CTRL (0x1180)
213 #define RTL930X_TBL_ACCESS_L2_CTRL (0xB320)
214 #define RTL930X_TBL_ACCESS_L2_METHOD_CTRL (0xB324)
215 #define RTL838X_TBL_ACCESS_L2_DATA(idx) (0x6908 + ((idx) << 2))
216 #define RTL839X_TBL_ACCESS_L2_DATA(idx) (0x1184 + ((idx) << 2))
217 #define RTL930X_TBL_ACCESS_L2_DATA(idx) (0xab08 + ((idx) << 2))
218 #define RTL838X_L2_TBL_FLUSH_CTRL (0x3370)
219 #define RTL839X_L2_TBL_FLUSH_CTRL (0x3ba0)
220 #define RTL930X_L2_TBL_FLUSH_CTRL (0x9404)
221 #define RTL931X_L2_TBL_FLUSH_CTRL (0xCD9C)
222
223 #define RTL838X_L2_LRN_CONSTRT (0x329C)
224 #define RTL839X_L2_LRN_CONSTRT (0x3910)
225 #define RTL930X_L2_LRN_CONSTRT_CTRL (0x909c)
226 #define RTL838X_L2_FLD_PMSK (0x3288)
227 #define RTL839X_L2_FLD_PMSK (0x38EC)
228 #define RTL930X_L2_BC_FLD_PMSK (0x9068)
229 #define RTL930X_L2_UNKN_UC_FLD_PMSK (0x9064)
230 #define RTL838X_L2_LRN_CONSTRT_EN (0x3368)
231
232 #define RTL838X_L2_PORT_NEW_SALRN(p) (0x328c + (((p >> 4) << 2)))
233 #define RTL839X_L2_PORT_NEW_SALRN(p) (0x38F0 + (((p >> 4) << 2)))
234 #define RTL930X_L2_PORT_SALRN(p) (0x8FEC + (((p >> 4) << 2)))
235 #define RTL931X_L2_PORT_NEW_SALRN(p) (0xC820 + (((p >> 4) << 2)))
236 #define RTL838X_L2_PORT_NEW_SA_FWD(p) (0x3294 + (((p >> 4) << 2)))
237 #define RTL839X_L2_PORT_NEW_SA_FWD(p) (0x3900 + (((p >> 4) << 2)))
238 #define RTL930X_L2_PORT_NEW_SA_FWD(p) (0x8FF4 + (((p / 10) << 2)))
239 #define RTL931X_L2_PORT_NEW_SA_FWD(p) (0xC830 + (((p / 10) << 2)))
240
241 #define RTL930X_ST_CTRL (0x8798)
242
243 #define RTL930X_L2_PORT_SABLK_CTRL (0x905c)
244 #define RTL930X_L2_PORT_DABLK_CTRL (0x9060)
245
246 #define RTL838X_RMA_BPDU_FLD_PMSK (0x4348)
247 #define RTL930X_RMA_BPDU_FLD_PMSK (0x9F18)
248 #define RTL931X_RMA_BPDU_FLD_PMSK (0x8950)
249 #define RTL839X_RMA_BPDU_FLD_PMSK (0x125C)
250
251 #define RTL838X_L2_PORT_LM_ACT(p) (0x3208 + ((p) << 2))
252 #define RTL838X_VLAN_PORT_FWD (0x3A78)
253 #define RTL839X_VLAN_PORT_FWD (0x27AC)
254 #define RTL930X_VLAN_PORT_FWD (0x834C)
255 #define RTL838X_VLAN_FID_CTRL (0x3aa8)
256
257 /* Port Mirroring */
258 #define RTL838X_MIR_CTRL (0x5D00)
259 #define RTL838X_MIR_DPM_CTRL (0x5D20)
260 #define RTL838X_MIR_SPM_CTRL (0x5D10)
261
262 #define RTL839X_MIR_CTRL (0x2500)
263 #define RTL839X_MIR_DPM_CTRL (0x2530)
264 #define RTL839X_MIR_SPM_CTRL (0x2510)
265
266 #define RTL930X_MIR_CTRL (0xA2A0)
267 #define RTL930X_MIR_DPM_CTRL (0xA2C0)
268 #define RTL930X_MIR_SPM_CTRL (0xA2B0)
269
270 #define RTL931X_MIR_CTRL (0xAF00)
271 #define RTL931X_MIR_DPM_CTRL (0xAF30)
272 #define RTL931X_MIR_SPM_CTRL (0xAF10)
273
274 /* Storm/rate control and scheduling */
275 #define RTL838X_STORM_CTRL (0x4700)
276 #define RTL839X_STORM_CTRL (0x1800)
277 #define RTL838X_STORM_CTRL_LB_CTRL(p) (0x4884 + (((p) << 2)))
278 #define RTL838X_STORM_CTRL_BURST_PPS_0 (0x4874)
279 #define RTL838X_STORM_CTRL_BURST_PPS_1 (0x4878)
280 #define RTL838X_STORM_CTRL_BURST_0 (0x487c)
281 #define RTL838X_STORM_CTRL_BURST_1 (0x4880)
282 #define RTL839X_STORM_CTRL_LB_TICK_TKN_CTRL_0 (0x1804)
283 #define RTL839X_STORM_CTRL_LB_TICK_TKN_CTRL_1 (0x1808)
284 #define RTL838X_SCHED_CTRL (0xB980)
285 #define RTL839X_SCHED_CTRL (0x60F4)
286 #define RTL838X_SCHED_LB_TICK_TKN_CTRL_0 (0xAD58)
287 #define RTL838X_SCHED_LB_TICK_TKN_CTRL_1 (0xAD5C)
288 #define RTL839X_SCHED_LB_TICK_TKN_CTRL_0 (0x1804)
289 #define RTL839X_SCHED_LB_TICK_TKN_CTRL_1 (0x1808)
290 #define RTL839X_STORM_CTRL_SPCL_LB_TICK_TKN_CTRL (0x2000)
291 #define RTL839X_IGR_BWCTRL_LB_TICK_TKN_CTRL_0 (0x1604)
292 #define RTL839X_IGR_BWCTRL_LB_TICK_TKN_CTRL_1 (0x1608)
293 #define RTL839X_SCHED_LB_TICK_TKN_CTRL (0x60F8)
294 #define RTL839X_SCHED_LB_TICK_TKN_PPS_CTRL (0x6200)
295 #define RTL838X_SCHED_LB_THR (0xB984)
296 #define RTL839X_SCHED_LB_THR (0x60FC)
297 #define RTL838X_SCHED_P_EGR_RATE_CTRL(p) (0xC008 + (((p) << 7)))
298 #define RTL838X_SCHED_Q_EGR_RATE_CTRL(p, q) (0xC00C + (p << 7) + (((q) << 2)))
299 #define RTL838X_STORM_CTRL_PORT_BC_EXCEED (0x470C)
300 #define RTL838X_STORM_CTRL_PORT_MC_EXCEED (0x4710)
301 #define RTL838X_STORM_CTRL_PORT_UC_EXCEED (0x4714)
302 #define RTL839X_STORM_CTRL_PORT_BC_EXCEED(p) (0x180c + (((p >> 5) << 2)))
303 #define RTL839X_STORM_CTRL_PORT_MC_EXCEED(p) (0x1814 + (((p >> 5) << 2)))
304 #define RTL839X_STORM_CTRL_PORT_UC_EXCEED(p) (0x181c + (((p >> 5) << 2)))
305 #define RTL838X_STORM_CTRL_PORT_UC(p) (0x4718 + (((p) << 2)))
306 #define RTL838X_STORM_CTRL_PORT_MC(p) (0x478c + (((p) << 2)))
307 #define RTL838X_STORM_CTRL_PORT_BC(p) (0x4800 + (((p) << 2)))
308 #define RTL839X_STORM_CTRL_PORT_UC_0(p) (0x185C + (((p) << 3)))
309 #define RTL839X_STORM_CTRL_PORT_UC_1(p) (0x1860 + (((p) << 3)))
310 #define RTL839X_STORM_CTRL_PORT_MC_0(p) (0x19FC + (((p) << 3)))
311 #define RTL839X_STORM_CTRL_PORT_MC_1(p) (0x1a00 + (((p) << 3)))
312 #define RTL839X_STORM_CTRL_PORT_BC_0(p) (0x1B9C + (((p) << 3)))
313 #define RTL839X_STORM_CTRL_PORT_BC_1(p) (0x1BA0 + (((p) << 3)))
314 #define RTL839X_TBL_ACCESS_CTRL_2 (0x611C)
315 #define RTL839X_TBL_ACCESS_DATA_2(i) (0x6120 + (((i) << 2)))
316 #define RTL839X_IGR_BWCTRL_PORT_CTRL_10G_0(p) (0x1618 + (((p) << 3)))
317 #define RTL839X_IGR_BWCTRL_PORT_CTRL_10G_1(p) (0x161C + (((p) << 3)))
318 #define RTL839X_IGR_BWCTRL_PORT_CTRL_0(p) (0x1640 + (((p) << 3)))
319 #define RTL839X_IGR_BWCTRL_PORT_CTRL_1(p) (0x1644 + (((p) << 3)))
320 #define RTL839X_IGR_BWCTRL_CTRL_LB_THR (0x1614)
321
322 /* Link aggregation (Trunking) */
323 #define RTL839X_TRK_MBR_CTR (0x2200)
324 #define RTL838X_TRK_MBR_CTR (0x3E00)
325 #define RTL930X_TRK_MBR_CTRL (0xA41C)
326 #define RTL931X_TRK_MBR_CTRL (0xB8D0)
327
328 /* Attack prevention */
329 #define RTL838X_ATK_PRVNT_PORT_EN (0x5B00)
330 #define RTL838X_ATK_PRVNT_CTRL (0x5B04)
331 #define RTL838X_ATK_PRVNT_ACT (0x5B08)
332 #define RTL838X_ATK_PRVNT_STS (0x5B1C)
333
334 /* 802.1X */
335 #define RTL838X_SPCL_TRAP_EAPOL_CTRL (0x6988)
336 #define RTL839X_SPCL_TRAP_EAPOL_CTRL (0x105C)
337 #define RTL838X_SPCL_TRAP_ARP_CTRL (0x698C)
338 #define RTL839X_SPCL_TRAP_ARP_CTRL (0x1060)
339
340 /* QoS */
341 #define RTL838X_QM_INTPRI2QID_CTRL (0x5F00)
342 #define RTL839X_QM_INTPRI2QID_CTRL(q) (0x1110 + (q << 2))
343 #define RTL839X_QM_PORT_QNUM(p) (0x1130 + (((p / 10) << 2)))
344 #define RTL838X_PRI_SEL_PORT_PRI(p) (0x5FB8 + (((p / 10) << 2)))
345 #define RTL839X_PRI_SEL_PORT_PRI(p) (0x10A8 + (((p / 10) << 2)))
346 #define RTL838X_QM_PKT2CPU_INTPRI_MAP (0x5F10)
347 #define RTL839X_QM_PKT2CPU_INTPRI_MAP (0x1154)
348 #define RTL838X_PRI_SEL_CTRL (0x10E0)
349 #define RTL839X_PRI_SEL_CTRL (0x10E0)
350 #define RTL838X_PRI_SEL_TBL_CTRL(i) (0x5FD8 + (((i) << 2)))
351 #define RTL839X_PRI_SEL_TBL_CTRL(i) (0x10D0 + (((i) << 2)))
352 #define RTL838X_QM_PKT2CPU_INTPRI_0 (0x5F04)
353 #define RTL838X_QM_PKT2CPU_INTPRI_1 (0x5F08)
354 #define RTL838X_QM_PKT2CPU_INTPRI_2 (0x5F0C)
355 #define RTL839X_OAM_CTRL (0x2100)
356 #define RTL839X_OAM_PORT_ACT_CTRL(p) (0x2104 + (((p) << 2)))
357 #define RTL839X_RMK_PORT_DEI_TAG_CTRL(p) (0x6A9C + (((p >> 5) << 2)))
358 #define RTL839X_PRI_SEL_IPRI_REMAP (0x1080)
359 #define RTL838X_PRI_SEL_IPRI_REMAP (0x5F8C)
360 #define RTL839X_PRI_SEL_DEI2DP_REMAP (0x10EC)
361 #define RTL839X_PRI_SEL_DSCP2DP_REMAP_ADDR(i) (0x10F0 + (((i >> 4) << 2)))
362 #define RTL839X_RMK_DEI_CTRL (0x6AA4)
363 #define RTL839X_WRED_PORT_THR_CTRL(i) (0x6084 + ((i) << 2))
364 #define RTL839X_WRED_QUEUE_THR_CTRL(q, i) (0x6090 + ((q) * 12) + ((i) << 2))
365 #define RTL838X_PRI_DSCP_INVLD_CTRL0 (0x5FE8)
366 #define RTL838X_RMK_IPRI_CTRL (0xA460)
367 #define RTL838X_RMK_OPRI_CTRL (0xA464)
368 #define RTL838X_SCHED_P_TYPE_CTRL(p) (0xC04C + (((p) << 7)))
369 #define RTL838X_SCHED_LB_CTRL(p) (0xC004 + (((p) << 7)))
370 #define RTL838X_FC_P_EGR_DROP_CTRL(p) (0x6B1C + (((p) << 2)))
371
372 /* Debug features */
373 #define RTL930X_STAT_PRVTE_DROP_COUNTER0 (0xB5B8)
374
375 /* Packet Inspection Engine */
376 #define RTL838X_METER_GLB_CTRL (0x4B08)
377 #define RTL839X_METER_GLB_CTRL (0x1300)
378 #define RTL930X_METER_GLB_CTRL (0xa0a0)
379 #define RTL839X_ACL_CTRL (0x1288)
380 #define RTL838X_ACL_BLK_LOOKUP_CTRL (0x6100)
381 #define RTL839X_ACL_BLK_LOOKUP_CTRL (0x1280)
382 #define RTL930X_PIE_BLK_LOOKUP_CTRL (0xa5a0)
383 #define RTL838X_ACL_BLK_PWR_CTRL (0x6104)
384 #define RTL839X_PS_ACL_PWR_CTRL (0x049c)
385 #define RTL838X_ACL_BLK_TMPLTE_CTRL(block) (0x6108 + ((block) << 2))
386 #define RTL839X_ACL_BLK_TMPLTE_CTRL(block) (0x128c + ((block) << 2))
387 #define RTL930X_PIE_BLK_TMPLTE_CTRL(block) (0xa624 + ((block) << 2))
388 #define RTL838X_ACL_BLK_GROUP_CTRL (0x615C)
389 #define RTL839X_ACL_BLK_GROUP_CTRL (0x12ec)
390 #define RTL838X_ACL_CLR_CTRL (0x6168)
391 #define RTL839X_ACL_CLR_CTRL (0x12fc)
392 #define RTL930X_PIE_CLR_CTRL (0xa66c)
393 #define RTL838X_DMY_REG27 (0x3378)
394 #define RTL838X_ACL_PORT_LOOKUP_CTRL(p) (0x616C + (((p) << 2)))
395 #define RTL930X_ACL_PORT_LOOKUP_CTRL(p) (0xA784 + (((p) << 2)))
396 #define RTL930X_PIE_BLK_PHASE_CTRL (0xA5A4)
397
398 // PIE actions
399 #define PIE_ACT_COPY_TO_PORT 2
400 #define PIE_ACT_REDIRECT_TO_PORT 4
401 #define PIE_ACT_ROUTE_UC 6
402 #define PIE_ACT_VID_ASSIGN 0
403
404 // L3 actions
405 #define L3_FORWARD 0
406 #define L3_DROP 1
407 #define L3_TRAP2CPU 2
408 #define L3_COPY2CPU 3
409 #define L3_TRAP2MASTERCPU 4
410 #define L3_COPY2MASTERCPU 5
411 #define L3_HARDDROP 6
412
413 // Route actions
414 #define ROUTE_ACT_FORWARD 0
415 #define ROUTE_ACT_TRAP2CPU 1
416 #define ROUTE_ACT_COPY2CPU 2
417 #define ROUTE_ACT_DROP 3
418
419 /* L3 Routing */
420 #define RTL839X_ROUTING_SA_CTRL 0x6afc
421 #define RTL930X_L3_HOST_TBL_CTRL (0xAB48)
422 #define RTL930X_L3_IPUC_ROUTE_CTRL (0xAB4C)
423 #define RTL930X_L3_IP6UC_ROUTE_CTRL (0xAB50)
424 #define RTL930X_L3_IPMC_ROUTE_CTRL (0xAB54)
425 #define RTL930X_L3_IP6MC_ROUTE_CTRL (0xAB58)
426 #define RTL930X_L3_IP_MTU_CTRL(i) (0xAB5C + ((i >> 1) << 2))
427 #define RTL930X_L3_IP6_MTU_CTRL(i) (0xAB6C + ((i >> 1) << 2))
428 #define RTL930X_L3_HW_LU_KEY_CTRL (0xAC9C)
429 #define RTL930X_L3_HW_LU_KEY_IP_CTRL (0xACA0)
430 #define RTL930X_L3_HW_LU_CTRL (0xACC0)
431 #define RTL930X_L3_IP_ROUTE_CTRL 0xab44
432
433 #define MAX_VLANS 4096
434 #define MAX_LAGS 16
435 #define MAX_PRIOS 8
436 #define RTL930X_PORT_IGNORE 0x3f
437 #define MAX_MC_GROUPS 512
438 #define UNKNOWN_MC_PMASK (MAX_MC_GROUPS - 1)
439 #define PIE_BLOCK_SIZE 128
440 #define MAX_PIE_ENTRIES (18 * PIE_BLOCK_SIZE)
441 #define N_FIXED_FIELDS 12
442 #define MAX_COUNTERS 2048
443 #define MAX_ROUTES 512
444 #define MAX_HOST_ROUTES 1536
445 #define MAX_INTF_MTUS 8
446 #define DEFAULT_MTU 1536
447 #define MAX_INTERFACES 100
448 #define MAX_ROUTER_MACS 64
449 #define L3_EGRESS_DMACS 2048
450 #define MAX_SMACS 64
451
452 enum phy_type {
453 PHY_NONE = 0,
454 PHY_RTL838X_SDS = 1,
455 PHY_RTL8218B_INT = 2,
456 PHY_RTL8218B_EXT = 3,
457 PHY_RTL8214FC = 4,
458 PHY_RTL839X_SDS = 5,
459 PHY_RTL930X_SDS = 6,
460 };
461
462 enum pbvlan_type {
463 PBVLAN_TYPE_INNER = 0,
464 PBVLAN_TYPE_OUTER,
465 };
466
467 enum pbvlan_mode {
468 PBVLAN_MODE_UNTAG_AND_PRITAG = 0,
469 PBVLAN_MODE_UNTAG_ONLY,
470 PBVLAN_MODE_ALL_PKT,
471 };
472
473 struct rtl838x_port {
474 bool enable;
475 u64 pm;
476 u16 pvid;
477 bool eee_enabled;
478 enum phy_type phy;
479 bool phy_is_integrated;
480 bool is10G;
481 bool is2G5;
482 int sds_num;
483 const struct dsa_port *dp;
484 };
485
486 struct rtl838x_vlan_info {
487 u64 untagged_ports;
488 u64 tagged_ports;
489 u8 profile_id;
490 bool hash_mc_fid;
491 bool hash_uc_fid;
492 u8 fid; // AKA MSTI
493
494 // The following fields are used only by the RTL931X
495 int if_id; // Interface (index in L3_EGR_INTF_IDX)
496 u16 multicast_grp_mask;
497 int l2_tunnel_list_id;
498 };
499
500 enum l2_entry_type {
501 L2_INVALID = 0,
502 L2_UNICAST = 1,
503 L2_MULTICAST = 2,
504 IP4_MULTICAST = 3,
505 IP6_MULTICAST = 4,
506 };
507
508 struct rtl838x_l2_entry {
509 u8 mac[6];
510 u16 vid;
511 u16 rvid;
512 u8 port;
513 bool valid;
514 enum l2_entry_type type;
515 bool is_static;
516 bool is_ip_mc;
517 bool is_ipv6_mc;
518 bool block_da;
519 bool block_sa;
520 bool suspended;
521 bool next_hop;
522 int age;
523 u8 trunk;
524 bool is_trunk;
525 u8 stack_dev;
526 u16 mc_portmask_index;
527 u32 mc_gip;
528 u32 mc_sip;
529 u16 mc_mac_index;
530 u16 nh_route_id;
531 bool nh_vlan_target; // Only RTL83xx: VLAN used for next hop
532
533 // The following is only valid on RTL931x
534 bool is_open_flow;
535 bool is_pe_forward;
536 bool is_local_forward;
537 bool is_remote_forward;
538 bool is_l2_tunnel;
539 int l2_tunnel_id;
540 int l2_tunnel_list_id;
541 };
542
543 enum fwd_rule_action {
544 FWD_RULE_ACTION_NONE = 0,
545 FWD_RULE_ACTION_FWD = 1,
546 };
547
548 enum pie_phase {
549 PHASE_VACL = 0,
550 PHASE_IACL = 1,
551 };
552
553 enum igr_filter {
554 IGR_FORWARD = 0,
555 IGR_DROP = 1,
556 IGR_TRAP = 2,
557 };
558
559 enum egr_filter {
560 EGR_DISABLE = 0,
561 EGR_ENABLE = 1,
562 };
563
564 /* Intermediate representation of a Packet Inspection Engine Rule
565 * as suggested by the Kernel's tc flower offload subsystem
566 * Field meaning is universal across SoC families, but data content is specific
567 * to SoC family (e.g. because of different port ranges) */
568 struct pie_rule {
569 int id;
570 enum pie_phase phase; // Phase in which this template is applied
571 int packet_cntr; // ID of a packet counter assigned to this rule
572 int octet_cntr; // ID of a byte counter assigned to this rule
573 u32 last_packet_cnt;
574 u64 last_octet_cnt;
575
576 // The following are requirements for the pie template
577 bool is_egress;
578 bool is_ipv6; // This is a rule with IPv6 fields
579
580 // Fixed fields that are always matched against on RTL8380
581 u8 spmmask_fix;
582 u8 spn; // Source port number
583 bool stacking_port; // Source port is stacking port
584 bool mgnt_vlan; // Packet arrived on management VLAN
585 bool dmac_hit_sw; // The packet's destination MAC matches one of the device's
586 bool content_too_deep; // The content of the packet cannot be parsed: too many layers
587 bool not_first_frag; // Not the first IP fragment
588 u8 frame_type_l4; // 0: UDP, 1: TCP, 2: ICMP/ICMPv6, 3: IGMP
589 u8 frame_type; // 0: ARP, 1: L2 only, 2: IPv4, 3: IPv6
590 bool otag_fmt; // 0: outer tag packet, 1: outer priority tag or untagged
591 bool itag_fmt; // 0: inner tag packet, 1: inner priority tag or untagged
592 bool otag_exist; // packet with outer tag
593 bool itag_exist; // packet with inner tag
594 bool frame_type_l2; // 0: Ethernet, 1: LLC_SNAP, 2: LLC_Other, 3: Reserved
595 bool igr_normal_port; // Ingress port is not cpu or stacking port
596 u8 tid; // The template ID defining the what the templated fields mean
597
598 // Masks for the fields that are always matched against on RTL8380
599 u8 spmmask_fix_m;
600 u8 spn_m;
601 bool stacking_port_m;
602 bool mgnt_vlan_m;
603 bool dmac_hit_sw_m;
604 bool content_too_deep_m;
605 bool not_first_frag_m;
606 u8 frame_type_l4_m;
607 u8 frame_type_m;
608 bool otag_fmt_m;
609 bool itag_fmt_m;
610 bool otag_exist_m;
611 bool itag_exist_m;
612 bool frame_type_l2_m;
613 bool igr_normal_port_m;
614 u8 tid_m;
615
616 // Logical operations between rules, special rules for rule numbers apply
617 bool valid;
618 bool cond_not; // Matches when conditions not match
619 bool cond_and1; // And this rule 2n with the next rule 2n+1 in same block
620 bool cond_and2; // And this rule m in block 2n with rule m in block 2n+1
621 bool ivalid;
622
623 // Actions to be performed
624 bool drop; // Drop the packet
625 bool fwd_sel; // Forward packet: to port, portmask, dest route, next rule, drop
626 bool ovid_sel; // So something to outer vlan-id: shift, re-assign
627 bool ivid_sel; // Do something to inner vlan-id: shift, re-assign
628 bool flt_sel; // Filter the packet when sending to certain ports
629 bool log_sel; // Log the packet in one of the LOG-table counters
630 bool rmk_sel; // Re-mark the packet, i.e. change the priority-tag
631 bool meter_sel; // Meter the packet, i.e. limit rate of this type of packet
632 bool tagst_sel; // Change the ergress tag
633 bool mir_sel; // Mirror the packet to a Link Aggregation Group
634 bool nopri_sel; // Change the normal priority
635 bool cpupri_sel; // Change the CPU priority
636 bool otpid_sel; // Change Outer Tag Protocol Identifier (802.1q)
637 bool itpid_sel; // Change Inner Tag Protocol Identifier (802.1q)
638 bool shaper_sel; // Apply traffic shaper
639 bool mpls_sel; // MPLS actions
640 bool bypass_sel; // Bypass actions
641 bool fwd_sa_lrn; // Learn the source address when forwarding
642 bool fwd_mod_to_cpu; // Forward the modified VLAN tag format to CPU-port
643
644 // Fields used in predefined templates 0-2 on RTL8380 / 90 / 9300
645 u64 spm; // Source Port Matrix
646 u16 otag; // Outer VLAN-ID
647 u8 smac[ETH_ALEN]; // Source MAC address
648 u8 dmac[ETH_ALEN]; // Destination MAC address
649 u16 ethertype; // Ethernet frame type field in ethernet header
650 u16 itag; // Inner VLAN-ID
651 u16 field_range_check;
652 u32 sip; // Source IP
653 struct in6_addr sip6; // IPv6 Source IP
654 u32 dip; // Destination IP
655 struct in6_addr dip6; // IPv6 Destination IP
656 u16 tos_proto; // IPv4: TOS + Protocol fields, IPv6: Traffic class + next header
657 u16 sport; // TCP/UDP source port
658 u16 dport; // TCP/UDP destination port
659 u16 icmp_igmp;
660 u16 tcp_info;
661 u16 dsap_ssap; // Destination / Source Service Access Point bytes (802.3)
662
663 u64 spm_m;
664 u16 otag_m;
665 u8 smac_m[ETH_ALEN];
666 u8 dmac_m[ETH_ALEN];
667 u8 ethertype_m;
668 u16 itag_m;
669 u16 field_range_check_m;
670 u32 sip_m;
671 struct in6_addr sip6_m; // IPv6 Source IP mask
672 u32 dip_m;
673 struct in6_addr dip6_m; // IPv6 Destination IP mask
674 u16 tos_proto_m;
675 u16 sport_m;
676 u16 dport_m;
677 u16 icmp_igmp_m;
678 u16 tcp_info_m;
679 u16 dsap_ssap_m;
680
681 // Data associated with actions
682 u8 fwd_act; // Type of forwarding action
683 // 0: permit, 1: drop, 2: copy to port id, 4: copy to portmask
684 // 4: redirect to portid, 5: redirect to portmask
685 // 6: route, 7: vlan leaky (only 8380)
686 u16 fwd_data; // Additional data for forwarding action, e.g. destination port
687 u8 ovid_act;
688 u16 ovid_data; // Outer VLAN ID
689 u8 ivid_act;
690 u16 ivid_data; // Inner VLAN ID
691 u16 flt_data; // Filtering data
692 u16 log_data; // ID of packet or octet counter in LOG table, on RTL93xx
693 // unnecessary since PIE-Rule-ID == LOG-counter-ID
694 bool log_octets;
695 u8 mpls_act; // MPLS action type
696 u16 mpls_lib_idx; // MPLS action data
697
698 u16 rmk_data; // Data for remarking
699 u16 meter_data; // ID of meter for bandwidth control
700 u16 tagst_data;
701 u16 mir_data;
702 u16 nopri_data;
703 u16 cpupri_data;
704 u16 otpid_data;
705 u16 itpid_data;
706 u16 shaper_data;
707
708 // Bypass actions, ignored on RTL8380
709 bool bypass_all; // Not clear
710 bool bypass_igr_stp; // Bypass Ingress STP state
711 bool bypass_ibc_sc; // Bypass Ingress Bandwidth Control and Storm Control
712 };
713
714 struct rtl838x_l3_intf {
715 u16 vid;
716 u8 smac_idx;
717 u8 ip4_mtu_id;
718 u8 ip6_mtu_id;
719 u16 ip4_mtu;
720 u16 ip6_mtu;
721 u8 ttl_scope;
722 u8 hl_scope;
723 u8 ip4_icmp_redirect;
724 u8 ip6_icmp_redirect;
725 u8 ip4_pbr_icmp_redirect;
726 u8 ip6_pbr_icmp_redirect;
727 };
728
729 /*
730 * An entry in the RTL93XX SoC's ROUTER_MAC tables setting up a termination point
731 * for the L3 routing system. Packets arriving and matching an entry in this table
732 * will be considered for routing.
733 * Mask fields state whether the corresponding data fields matter for matching
734 */
735 struct rtl93xx_rt_mac {
736 bool valid; // Valid or not
737 bool p_type; // Individual (0) or trunk (1) port
738 bool p_mask; // Whether the port type is used
739 u8 p_id;
740 u8 p_id_mask; // Mask for the port
741 u8 action; // Routing action performed: 0: FORWARD, 1: DROP, 2: TRAP2CPU
742 // 3: COPY2CPU, 4: TRAP2MASTERCPU, 5: COPY2MASTERCPU, 6: HARDDROP
743 u16 vid;
744 u16 vid_mask;
745 u64 mac; // MAC address used as source MAC in the routed packet
746 u64 mac_mask;
747 };
748
749 struct rtl83xx_nexthop {
750 u16 id; // ID: L3_NEXT_HOP table-index or route-index set in L2_NEXT_HOP
751 u32 dev_id;
752 u16 port;
753 u16 vid; // VLAN-ID for L2 table entry (saved from L2-UC entry)
754 u16 rvid; // Relay VID/FID for the L2 table entry
755 u64 mac; // The MAC address of the entry in the L2_NEXT_HOP table
756 u16 mac_id;
757 u16 l2_id; // Index of this next hop forwarding entry in L2 FIB table
758 u64 gw; // The gateway MAC address packets are forwarded to
759 int if_id; // Interface (into L3_EGR_INTF_IDX)
760 };
761
762 struct rtl838x_switch_priv;
763
764 struct rtl83xx_flow {
765 unsigned long cookie;
766 struct rhash_head node;
767 struct rcu_head rcu_head;
768 struct rtl838x_switch_priv *priv;
769 struct pie_rule rule;
770 u32 flags;
771 };
772
773 struct rtl93xx_route_attr {
774 bool valid;
775 bool hit;
776 bool ttl_dec;
777 bool ttl_check;
778 bool dst_null;
779 bool qos_as;
780 u8 qos_prio;
781 u8 type;
782 u8 action;
783 };
784
785 struct rtl83xx_route {
786 u32 gw_ip; // IP of the route's gateway
787 u32 dst_ip; // IP of the destination net
788 struct in6_addr dst_ip6;
789 int prefix_len; // Network prefix len of the destination net
790 bool is_host_route;
791 int id; // ID number of this route
792 struct rhlist_head linkage;
793 u16 switch_mac_id; // Index into switch's own MACs, RTL839X only
794 struct rtl83xx_nexthop nh;
795 struct pie_rule pr;
796 struct rtl93xx_route_attr attr;
797 };
798
799 struct rtl838x_reg {
800 void (*mask_port_reg_be)(u64 clear, u64 set, int reg);
801 void (*set_port_reg_be)(u64 set, int reg);
802 u64 (*get_port_reg_be)(int reg);
803 void (*mask_port_reg_le)(u64 clear, u64 set, int reg);
804 void (*set_port_reg_le)(u64 set, int reg);
805 u64 (*get_port_reg_le)(int reg);
806 int stat_port_rst;
807 int stat_rst;
808 int stat_port_std_mib;
809 int (*port_iso_ctrl)(int p);
810 void (*traffic_enable)(int source, int dest);
811 void (*traffic_disable)(int source, int dest);
812 void (*traffic_set)(int source, u64 dest_matrix);
813 u64 (*traffic_get)(int source);
814 int l2_ctrl_0;
815 int l2_ctrl_1;
816 int l2_port_aging_out;
817 int smi_poll_ctrl;
818 int l2_tbl_flush_ctrl;
819 void (*exec_tbl0_cmd)(u32 cmd);
820 void (*exec_tbl1_cmd)(u32 cmd);
821 int (*tbl_access_data_0)(int i);
822 int isr_glb_src;
823 int isr_port_link_sts_chg;
824 int imr_port_link_sts_chg;
825 int imr_glb;
826 void (*vlan_tables_read)(u32 vlan, struct rtl838x_vlan_info *info);
827 void (*vlan_set_tagged)(u32 vlan, struct rtl838x_vlan_info *info);
828 void (*vlan_set_untagged)(u32 vlan, u64 portmask);
829 void (*vlan_profile_dump)(int index);
830 void (*vlan_profile_setup)(int profile);
831 void (*vlan_port_pvidmode_set)(int port, enum pbvlan_type type, enum pbvlan_mode mode);
832 void (*vlan_port_pvid_set)(int port, enum pbvlan_type type, int pvid);
833 void (*set_vlan_igr_filter)(int port, enum igr_filter state);
834 void (*set_vlan_egr_filter)(int port, enum egr_filter state);
835 void (*stp_get)(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]);
836 void (*stp_set)(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]);
837 int (*mac_force_mode_ctrl)(int port);
838 int (*mac_port_ctrl)(int port);
839 int (*l2_port_new_salrn)(int port);
840 int (*l2_port_new_sa_fwd)(int port);
841 int mir_ctrl;
842 int mir_dpm;
843 int mir_spm;
844 int mac_link_sts;
845 int mac_link_dup_sts;
846 int (*mac_link_spd_sts)(int port);
847 int mac_rx_pause_sts;
848 int mac_tx_pause_sts;
849 u64 (*read_l2_entry_using_hash)(u32 hash, u32 position, struct rtl838x_l2_entry *e);
850 void (*write_l2_entry_using_hash)(u32 hash, u32 pos, struct rtl838x_l2_entry *e);
851 u64 (*read_cam)(int idx, struct rtl838x_l2_entry *e);
852 void (*write_cam)(int idx, struct rtl838x_l2_entry *e);
853 int vlan_port_tag_sts_ctrl;
854 int (*rtl838x_vlan_port_tag_sts_ctrl)(int port);
855 int (*trk_mbr_ctr)(int group);
856 int rma_bpdu_fld_pmask;
857 int spcl_trap_eapol_ctrl;
858 void (*init_eee)(struct rtl838x_switch_priv *priv, bool enable);
859 void (*port_eee_set)(struct rtl838x_switch_priv *priv, int port, bool enable);
860 int (*eee_port_ability)(struct rtl838x_switch_priv *priv,
861 struct ethtool_eee *e, int port);
862 u64 (*l2_hash_seed)(u64 mac, u32 vid);
863 u32 (*l2_hash_key)(struct rtl838x_switch_priv *priv, u64 seed);
864 u64 (*read_mcast_pmask)(int idx);
865 void (*write_mcast_pmask)(int idx, u64 portmask);
866 void (*vlan_fwd_on_inner)(int port, bool is_set);
867 void (*pie_init)(struct rtl838x_switch_priv *priv);
868 int (*pie_rule_read)(struct rtl838x_switch_priv *priv, int idx, struct pie_rule *pr);
869 int (*pie_rule_write)(struct rtl838x_switch_priv *priv, int idx, struct pie_rule *pr);
870 int (*pie_rule_add)(struct rtl838x_switch_priv *priv, struct pie_rule *rule);
871 void (*pie_rule_rm)(struct rtl838x_switch_priv *priv, struct pie_rule *rule);
872 void (*l2_learning_setup)(void);
873 u32 (*packet_cntr_read)(int counter);
874 void (*packet_cntr_clear)(int counter);
875 void (*route_read)(int idx, struct rtl83xx_route *rt);
876 void (*route_write)(int idx, struct rtl83xx_route *rt);
877 void (*host_route_write)(int idx, struct rtl83xx_route *rt);
878 int (*l3_setup)(struct rtl838x_switch_priv *priv);
879 void (*set_l3_nexthop)(int idx, u16 dmac_id, u16 interface);
880 void (*get_l3_nexthop)(int idx, u16 *dmac_id, u16 *interface);
881 u64 (*get_l3_egress_mac)(u32 idx);
882 void (*set_l3_egress_mac)(u32 idx, u64 mac);
883 int (*find_l3_slot)(struct rtl83xx_route *rt, bool must_exist);
884 int (*route_lookup_hw)(struct rtl83xx_route *rt);
885 void (*get_l3_router_mac)(u32 idx, struct rtl93xx_rt_mac *m);
886 void (*set_l3_router_mac)(u32 idx, struct rtl93xx_rt_mac *m);
887 void (*set_l3_egress_intf)(int idx, struct rtl838x_l3_intf *intf);
888 };
889
890 struct rtl838x_switch_priv {
891 /* Switch operation */
892 struct dsa_switch *ds;
893 struct device *dev;
894 u16 id;
895 u16 family_id;
896 char version;
897 struct rtl838x_port ports[57];
898 struct mutex reg_mutex; // Mutex for individual register manipulations
899 struct mutex pie_mutex; // Mutex for Packet Inspection Engine
900 int link_state_irq;
901 int mirror_group_ports[4];
902 struct mii_bus *mii_bus;
903 const struct rtl838x_reg *r;
904 u8 cpu_port;
905 u8 port_mask;
906 u8 port_width;
907 u8 port_ignore;
908 u64 irq_mask;
909 u32 fib_entries;
910 int l2_bucket_size;
911 struct dentry *dbgfs_dir;
912 int n_lags;
913 u64 lags_port_members[MAX_LAGS];
914 struct net_device *lag_devs[MAX_LAGS];
915 struct notifier_block nb; // TODO: change to different name
916 struct notifier_block ne_nb;
917 struct notifier_block fib_nb;
918 bool eee_enabled;
919 unsigned long int mc_group_bm[MAX_MC_GROUPS >> 5];
920 int n_pie_blocks;
921 struct rhashtable tc_ht;
922 unsigned long int pie_use_bm[MAX_PIE_ENTRIES >> 5];
923 int n_counters;
924 unsigned long int octet_cntr_use_bm[MAX_COUNTERS >> 5];
925 unsigned long int packet_cntr_use_bm[MAX_COUNTERS >> 4];
926 struct rhltable routes;
927 unsigned long int route_use_bm[MAX_ROUTES >> 5];
928 unsigned long int host_route_use_bm[MAX_HOST_ROUTES >> 5];
929 struct rtl838x_l3_intf *interfaces[MAX_INTERFACES];
930 u16 intf_mtus[MAX_INTF_MTUS];
931 int intf_mtu_count[MAX_INTF_MTUS];
932 };
933
934 void rtl838x_dbgfs_init(struct rtl838x_switch_priv *priv);
935 void rtl930x_dbgfs_init(struct rtl838x_switch_priv *priv);
936
937 #endif /* _RTL838X_H */