realtek: Add L2 aging configuration functions for all SoC families
[openwrt/staging/ldir.git] / target / linux / realtek / files-5.10 / drivers / net / dsa / rtl83xx / rtl930x.c
1 // SPDX-License-Identifier: GPL-2.0-only
2
3 #include <asm/mach-rtl838x/mach-rtl83xx.h>
4 #include <linux/inetdevice.h>
5
6 #include "rtl83xx.h"
7
8 extern struct mutex smi_lock;
9 extern struct rtl83xx_soc_info soc_info;
10
11 /* Definition of the RTL930X-specific template field IDs as used in the PIE */
12 enum template_field_id {
13 TEMPLATE_FIELD_SPM0 = 0, // Source portmask ports 0-15
14 TEMPLATE_FIELD_SPM1 = 1, // Source portmask ports 16-31
15 TEMPLATE_FIELD_DMAC0 = 2, // Destination MAC [15:0]
16 TEMPLATE_FIELD_DMAC1 = 3, // Destination MAC [31:16]
17 TEMPLATE_FIELD_DMAC2 = 4, // Destination MAC [47:32]
18 TEMPLATE_FIELD_SMAC0 = 5, // Source MAC [15:0]
19 TEMPLATE_FIELD_SMAC1 = 6, // Source MAC [31:16]
20 TEMPLATE_FIELD_SMAC2 = 7, // Source MAC [47:32]
21 TEMPLATE_FIELD_ETHERTYPE = 8, // Ethernet frame type field
22 TEMPLATE_FIELD_OTAG = 9,
23 TEMPLATE_FIELD_ITAG = 10,
24 TEMPLATE_FIELD_SIP0 = 11,
25 TEMPLATE_FIELD_SIP1 = 12,
26 TEMPLATE_FIELD_DIP0 = 13,
27 TEMPLATE_FIELD_DIP1 = 14,
28 TEMPLATE_FIELD_IP_TOS_PROTO = 15,
29 TEMPLATE_FIELD_L4_SPORT = 16,
30 TEMPLATE_FIELD_L4_DPORT = 17,
31 TEMPLATE_FIELD_L34_HEADER = 18,
32 TEMPLATE_FIELD_TCP_INFO = 19,
33 TEMPLATE_FIELD_FIELD_SELECTOR_VALID = 20,
34 TEMPLATE_FIELD_FIELD_SELECTOR_0 = 21,
35 TEMPLATE_FIELD_FIELD_SELECTOR_1 = 22,
36 TEMPLATE_FIELD_FIELD_SELECTOR_2 = 23,
37 TEMPLATE_FIELD_FIELD_SELECTOR_3 = 24,
38 TEMPLATE_FIELD_FIELD_SELECTOR_4 = 25,
39 TEMPLATE_FIELD_FIELD_SELECTOR_5 = 26,
40 TEMPLATE_FIELD_SIP2 = 27,
41 TEMPLATE_FIELD_SIP3 = 28,
42 TEMPLATE_FIELD_SIP4 = 29,
43 TEMPLATE_FIELD_SIP5 = 30,
44 TEMPLATE_FIELD_SIP6 = 31,
45 TEMPLATE_FIELD_SIP7 = 32,
46 TEMPLATE_FIELD_DIP2 = 33,
47 TEMPLATE_FIELD_DIP3 = 34,
48 TEMPLATE_FIELD_DIP4 = 35,
49 TEMPLATE_FIELD_DIP5 = 36,
50 TEMPLATE_FIELD_DIP6 = 37,
51 TEMPLATE_FIELD_DIP7 = 38,
52 TEMPLATE_FIELD_PKT_INFO = 39,
53 TEMPLATE_FIELD_FLOW_LABEL = 40,
54 TEMPLATE_FIELD_DSAP_SSAP = 41,
55 TEMPLATE_FIELD_SNAP_OUI = 42,
56 TEMPLATE_FIELD_FWD_VID = 43,
57 TEMPLATE_FIELD_RANGE_CHK = 44,
58 TEMPLATE_FIELD_VLAN_GMSK = 45, // VLAN Group Mask/IP range check
59 TEMPLATE_FIELD_DLP = 46,
60 TEMPLATE_FIELD_META_DATA = 47,
61 TEMPLATE_FIELD_SRC_FWD_VID = 48,
62 TEMPLATE_FIELD_SLP = 49,
63 };
64
65 /* The meaning of TEMPLATE_FIELD_VLAN depends on phase and the configuration in
66 * RTL930X_PIE_CTRL. We use always the same definition and map to the inner VLAN tag:
67 */
68 #define TEMPLATE_FIELD_VLAN TEMPLATE_FIELD_ITAG
69
70 // Number of fixed templates predefined in the RTL9300 SoC
71 #define N_FIXED_TEMPLATES 5
72 // RTL9300 specific predefined templates
73 static enum template_field_id fixed_templates[N_FIXED_TEMPLATES][N_FIXED_FIELDS] =
74 {
75 {
76 TEMPLATE_FIELD_DMAC0, TEMPLATE_FIELD_DMAC1, TEMPLATE_FIELD_DMAC2,
77 TEMPLATE_FIELD_SMAC0, TEMPLATE_FIELD_SMAC1, TEMPLATE_FIELD_SMAC2,
78 TEMPLATE_FIELD_VLAN, TEMPLATE_FIELD_IP_TOS_PROTO, TEMPLATE_FIELD_DSAP_SSAP,
79 TEMPLATE_FIELD_ETHERTYPE, TEMPLATE_FIELD_SPM0, TEMPLATE_FIELD_SPM1
80 }, {
81 TEMPLATE_FIELD_SIP0, TEMPLATE_FIELD_SIP1, TEMPLATE_FIELD_DIP0,
82 TEMPLATE_FIELD_DIP1, TEMPLATE_FIELD_IP_TOS_PROTO, TEMPLATE_FIELD_TCP_INFO,
83 TEMPLATE_FIELD_L4_SPORT, TEMPLATE_FIELD_L4_DPORT, TEMPLATE_FIELD_VLAN,
84 TEMPLATE_FIELD_RANGE_CHK, TEMPLATE_FIELD_SPM0, TEMPLATE_FIELD_SPM1
85 }, {
86 TEMPLATE_FIELD_DMAC0, TEMPLATE_FIELD_DMAC1, TEMPLATE_FIELD_DMAC2,
87 TEMPLATE_FIELD_VLAN, TEMPLATE_FIELD_ETHERTYPE, TEMPLATE_FIELD_IP_TOS_PROTO,
88 TEMPLATE_FIELD_SIP0, TEMPLATE_FIELD_SIP1, TEMPLATE_FIELD_DIP0,
89 TEMPLATE_FIELD_DIP1, TEMPLATE_FIELD_L4_SPORT, TEMPLATE_FIELD_L4_DPORT
90 }, {
91 TEMPLATE_FIELD_DIP0, TEMPLATE_FIELD_DIP1, TEMPLATE_FIELD_DIP2,
92 TEMPLATE_FIELD_DIP3, TEMPLATE_FIELD_DIP4, TEMPLATE_FIELD_DIP5,
93 TEMPLATE_FIELD_DIP6, TEMPLATE_FIELD_DIP7, TEMPLATE_FIELD_IP_TOS_PROTO,
94 TEMPLATE_FIELD_TCP_INFO, TEMPLATE_FIELD_L4_SPORT, TEMPLATE_FIELD_L4_DPORT
95 }, {
96 TEMPLATE_FIELD_SIP0, TEMPLATE_FIELD_SIP1, TEMPLATE_FIELD_SIP2,
97 TEMPLATE_FIELD_SIP3, TEMPLATE_FIELD_SIP4, TEMPLATE_FIELD_SIP5,
98 TEMPLATE_FIELD_SIP6, TEMPLATE_FIELD_SIP7, TEMPLATE_FIELD_VLAN,
99 TEMPLATE_FIELD_RANGE_CHK, TEMPLATE_FIELD_SPM1, TEMPLATE_FIELD_SPM1
100 },
101 };
102
103 void rtl930x_print_matrix(void)
104 {
105 int i;
106 struct table_reg *r = rtl_table_get(RTL9300_TBL_0, 6);
107
108 for (i = 0; i < 29; i++) {
109 rtl_table_read(r, i);
110 pr_debug("> %08x\n", sw_r32(rtl_table_data(r, 0)));
111 }
112 rtl_table_release(r);
113 }
114
115 inline void rtl930x_exec_tbl0_cmd(u32 cmd)
116 {
117 sw_w32(cmd, RTL930X_TBL_ACCESS_CTRL_0);
118 do { } while (sw_r32(RTL930X_TBL_ACCESS_CTRL_0) & (1 << 17));
119 }
120
121 inline void rtl930x_exec_tbl1_cmd(u32 cmd)
122 {
123 sw_w32(cmd, RTL930X_TBL_ACCESS_CTRL_1);
124 do { } while (sw_r32(RTL930X_TBL_ACCESS_CTRL_1) & (1 << 17));
125 }
126
127 inline int rtl930x_tbl_access_data_0(int i)
128 {
129 return RTL930X_TBL_ACCESS_DATA_0(i);
130 }
131
132 static inline int rtl930x_l2_port_new_salrn(int p)
133 {
134 return RTL930X_L2_PORT_SALRN(p);
135 }
136
137 static inline int rtl930x_l2_port_new_sa_fwd(int p)
138 {
139 // TODO: The definition of the fields changed, because of the master-cpu in a stack
140 return RTL930X_L2_PORT_NEW_SA_FWD(p);
141 }
142
143 inline static int rtl930x_trk_mbr_ctr(int group)
144 {
145 return RTL930X_TRK_MBR_CTRL + (group << 2);
146 }
147
148 static void rtl930x_vlan_tables_read(u32 vlan, struct rtl838x_vlan_info *info)
149 {
150 u32 v, w;
151 // Read VLAN table (1) via register 0
152 struct table_reg *r = rtl_table_get(RTL9300_TBL_0, 1);
153
154 rtl_table_read(r, vlan);
155 v = sw_r32(rtl_table_data(r, 0));
156 w = sw_r32(rtl_table_data(r, 1));
157 pr_debug("VLAN_READ %d: %08x %08x\n", vlan, v, w);
158 rtl_table_release(r);
159
160 info->tagged_ports = v >> 3;
161 info->profile_id = (w >> 24) & 7;
162 info->hash_mc_fid = !!(w & BIT(27));
163 info->hash_uc_fid = !!(w & BIT(28));
164 info->fid = ((v & 0x7) << 3) | ((w >> 29) & 0x7);
165
166 // Read UNTAG table via table register 2
167 r = rtl_table_get(RTL9300_TBL_2, 0);
168 rtl_table_read(r, vlan);
169 v = sw_r32(rtl_table_data(r, 0));
170 rtl_table_release(r);
171
172 info->untagged_ports = v >> 3;
173 }
174
175 static void rtl930x_vlan_set_tagged(u32 vlan, struct rtl838x_vlan_info *info)
176 {
177 u32 v, w;
178 // Access VLAN table (1) via register 0
179 struct table_reg *r = rtl_table_get(RTL9300_TBL_0, 1);
180
181 v = info->tagged_ports << 3;
182 v |= ((u32)info->fid) >> 3;
183
184 w = ((u32)info->fid) << 29;
185 w |= info->hash_mc_fid ? BIT(27) : 0;
186 w |= info->hash_uc_fid ? BIT(28) : 0;
187 w |= info->profile_id << 24;
188
189 sw_w32(v, rtl_table_data(r, 0));
190 sw_w32(w, rtl_table_data(r, 1));
191
192 rtl_table_write(r, vlan);
193 rtl_table_release(r);
194 }
195
196 void rtl930x_vlan_profile_dump(int profile)
197 {
198 u32 p[5];
199
200 if (profile < 0 || profile > 7)
201 return;
202
203 p[0] = sw_r32(RTL930X_VLAN_PROFILE_SET(profile));
204 p[1] = sw_r32(RTL930X_VLAN_PROFILE_SET(profile) + 4);
205 p[2] = sw_r32(RTL930X_VLAN_PROFILE_SET(profile) + 8) & 0x1FFFFFFF;
206 p[3] = sw_r32(RTL930X_VLAN_PROFILE_SET(profile) + 12) & 0x1FFFFFFF;
207 p[4] = sw_r32(RTL930X_VLAN_PROFILE_SET(profile) + 16) & 0x1FFFFFFF;
208
209 pr_info("VLAN %d: L2 learn: %d; Unknown MC PMasks: L2 %0x, IPv4 %0x, IPv6: %0x",
210 profile, p[0] & (3 << 21), p[2], p[3], p[4]);
211 pr_info(" Routing enabled: IPv4 UC %c, IPv6 UC %c, IPv4 MC %c, IPv6 MC %c\n",
212 p[0] & BIT(17) ? 'y' : 'n', p[0] & BIT(16) ? 'y' : 'n',
213 p[0] & BIT(13) ? 'y' : 'n', p[0] & BIT(12) ? 'y' : 'n');
214 pr_info(" Bridge enabled: IPv4 MC %c, IPv6 MC %c,\n",
215 p[0] & BIT(15) ? 'y' : 'n', p[0] & BIT(14) ? 'y' : 'n');
216 pr_info("VLAN profile %d: raw %08x %08x %08x %08x %08x\n",
217 profile, p[0], p[1], p[2], p[3], p[4]);
218 }
219
220 static void rtl930x_vlan_set_untagged(u32 vlan, u64 portmask)
221 {
222 struct table_reg *r = rtl_table_get(RTL9300_TBL_2, 0);
223
224 sw_w32(portmask << 3, rtl_table_data(r, 0));
225 rtl_table_write(r, vlan);
226 rtl_table_release(r);
227 }
228
229 /* Sets the L2 forwarding to be based on either the inner VLAN tag or the outer
230 */
231 static void rtl930x_vlan_fwd_on_inner(int port, bool is_set)
232 {
233 // Always set all tag modes to fwd based on either inner or outer tag
234 if (is_set)
235 sw_w32_mask(0, 0xf, RTL930X_VLAN_PORT_FWD + (port << 2));
236 else
237 sw_w32_mask(0xf, 0, RTL930X_VLAN_PORT_FWD + (port << 2));
238 }
239
240 static void rtl930x_vlan_profile_setup(int profile)
241 {
242 u32 p[5];
243
244 pr_info("In %s\n", __func__);
245 p[0] = sw_r32(RTL930X_VLAN_PROFILE_SET(profile));
246 p[1] = sw_r32(RTL930X_VLAN_PROFILE_SET(profile) + 4);
247
248 // Enable routing of Ipv4/6 Unicast and IPv4/6 Multicast traffic
249 p[0] |= BIT(17) | BIT(16) | BIT(13) | BIT(12);
250 p[2] = 0x1fffffff; // L2 unknown MC flooding portmask all ports, including the CPU-port
251 p[3] = 0x1fffffff; // IPv4 unknown MC flooding portmask
252 p[4] = 0x1fffffff; // IPv6 unknown MC flooding portmask
253
254 sw_w32(p[0], RTL930X_VLAN_PROFILE_SET(profile));
255 sw_w32(p[1], RTL930X_VLAN_PROFILE_SET(profile) + 4);
256 sw_w32(p[2], RTL930X_VLAN_PROFILE_SET(profile) + 8);
257 sw_w32(p[3], RTL930X_VLAN_PROFILE_SET(profile) + 12);
258 sw_w32(p[4], RTL930X_VLAN_PROFILE_SET(profile) + 16);
259 }
260
261 static void rtl930x_l2_learning_setup(void)
262 {
263 // Portmask for flooding broadcast traffic
264 sw_w32(0x1fffffff, RTL930X_L2_BC_FLD_PMSK);
265
266 // Portmask for flooding unicast traffic with unknown destination
267 sw_w32(0x1fffffff, RTL930X_L2_UNKN_UC_FLD_PMSK);
268
269 // Limit learning to maximum: 32k entries, after that just flood (bits 0-1)
270 sw_w32((0x7fff << 2) | 0, RTL930X_L2_LRN_CONSTRT_CTRL);
271 }
272
273 static void rtl930x_stp_get(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[])
274 {
275 int i;
276 u32 cmd = 1 << 17 /* Execute cmd */
277 | 0 << 16 /* Read */
278 | 4 << 12 /* Table type 0b10 */
279 | (msti & 0xfff);
280 priv->r->exec_tbl0_cmd(cmd);
281
282 for (i = 0; i < 2; i++)
283 port_state[i] = sw_r32(RTL930X_TBL_ACCESS_DATA_0(i));
284 pr_debug("MSTI: %d STATE: %08x, %08x\n", msti, port_state[0], port_state[1]);
285 }
286
287 static void rtl930x_stp_set(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[])
288 {
289 int i;
290 u32 cmd = 1 << 17 /* Execute cmd */
291 | 1 << 16 /* Write */
292 | 4 << 12 /* Table type 4 */
293 | (msti & 0xfff);
294
295 for (i = 0; i < 2; i++)
296 sw_w32(port_state[i], RTL930X_TBL_ACCESS_DATA_0(i));
297 priv->r->exec_tbl0_cmd(cmd);
298 }
299
300 static inline int rtl930x_mac_force_mode_ctrl(int p)
301 {
302 return RTL930X_MAC_FORCE_MODE_CTRL + (p << 2);
303 }
304
305 static inline int rtl930x_mac_port_ctrl(int p)
306 {
307 return RTL930X_MAC_L2_PORT_CTRL(p);
308 }
309
310 static inline int rtl930x_mac_link_spd_sts(int p)
311 {
312 return RTL930X_MAC_LINK_SPD_STS(p);
313 }
314
315 static u64 rtl930x_l2_hash_seed(u64 mac, u32 vid)
316 {
317 u64 v = vid;
318
319 v <<= 48;
320 v |= mac;
321
322 return v;
323 }
324
325 /*
326 * Calculate both the block 0 and the block 1 hash by applyingthe same hash
327 * algorithm as the one used currently by the ASIC to the seed, and return
328 * both hashes in the lower and higher word of the return value since only 12 bit of
329 * the hash are significant
330 */
331 static u32 rtl930x_l2_hash_key(struct rtl838x_switch_priv *priv, u64 seed)
332 {
333 u32 k0, k1, h1, h2, h;
334
335 k0 = (u32) (((seed >> 55) & 0x1f) ^ ((seed >> 44) & 0x7ff)
336 ^ ((seed >> 33) & 0x7ff) ^ ((seed >> 22) & 0x7ff)
337 ^ ((seed >> 11) & 0x7ff) ^ (seed & 0x7ff));
338
339 h1 = (seed >> 11) & 0x7ff;
340 h1 = ((h1 & 0x1f) << 6) | ((h1 >> 5) & 0x3f);
341
342 h2 = (seed >> 33) & 0x7ff;
343 h2 = ((h2 & 0x3f) << 5)| ((h2 >> 6) & 0x3f);
344
345 k1 = (u32) (((seed << 55) & 0x1f) ^ ((seed >> 44) & 0x7ff) ^ h2
346 ^ ((seed >> 22) & 0x7ff) ^ h1
347 ^ (seed & 0x7ff));
348
349 // Algorithm choice for block 0
350 if (sw_r32(RTL930X_L2_CTRL) & BIT(0))
351 h = k1;
352 else
353 h = k0;
354
355 /* Algorithm choice for block 1
356 * Since k0 and k1 are < 2048, adding 2048 will offset the hash into the second
357 * half of hash-space
358 * 2048 is in fact the hash-table size 16384 divided by 4 hashes per bucket
359 * divided by 2 to divide the hash space in 2
360 */
361 if (sw_r32(RTL930X_L2_CTRL) & BIT(1))
362 h |= (k1 + 2048) << 16;
363 else
364 h |= (k0 + 2048) << 16;
365
366 return h;
367 }
368
369 /*
370 * Fills an L2 entry structure from the SoC registers
371 */
372 static void rtl930x_fill_l2_entry(u32 r[], struct rtl838x_l2_entry *e)
373 {
374 pr_debug("In %s valid?\n", __func__);
375 e->valid = !!(r[2] & BIT(31));
376 if (!e->valid)
377 return;
378
379 pr_debug("In %s is valid\n", __func__);
380 e->is_ip_mc = false;
381 e->is_ipv6_mc = false;
382
383 // TODO: Is there not a function to copy directly MAC memory?
384 e->mac[0] = (r[0] >> 24);
385 e->mac[1] = (r[0] >> 16);
386 e->mac[2] = (r[0] >> 8);
387 e->mac[3] = r[0];
388 e->mac[4] = (r[1] >> 24);
389 e->mac[5] = (r[1] >> 16);
390
391 e->next_hop = !!(r[2] & BIT(12));
392 e->rvid = r[1] & 0xfff;
393
394 /* Is it a unicast entry? check multicast bit */
395 if (!(e->mac[0] & 1)) {
396 e->type = L2_UNICAST;
397 e->is_static = !!(r[2] & BIT(14));
398 e->port = (r[2] >> 20) & 0x3ff;
399 // Check for trunk port
400 if (r[2] & BIT(30)) {
401 e->is_trunk = true;
402 e->stack_dev = (e->port >> 9) & 1;
403 e->trunk = e->port & 0x3f;
404 } else {
405 e->is_trunk = false;
406 e->stack_dev = (e->port >> 6) & 0xf;
407 e->port = e->port & 0x3f;
408 }
409
410 e->block_da = !!(r[2] & BIT(15));
411 e->block_sa = !!(r[2] & BIT(16));
412 e->suspended = !!(r[2] & BIT(13));
413 e->age = (r[2] >> 17) & 3;
414 e->valid = true;
415 // the UC_VID field in hardware is used for the VID or for the route id
416 if (e->next_hop) {
417 e->nh_route_id = r[2] & 0x7ff;
418 e->vid = 0;
419 } else {
420 e->vid = r[2] & 0xfff;
421 e->nh_route_id = 0;
422 }
423 } else {
424 e->valid = true;
425 e->type = L2_MULTICAST;
426 e->mc_portmask_index = (r[2] >> 16) & 0x3ff;
427 }
428 }
429
430 /*
431 * Fills the 3 SoC table registers r[] with the information of in the rtl838x_l2_entry
432 */
433 static void rtl930x_fill_l2_row(u32 r[], struct rtl838x_l2_entry *e)
434 {
435 u32 port;
436
437 if (!e->valid) {
438 r[0] = r[1] = r[2] = 0;
439 return;
440 }
441
442 r[2] = BIT(31); // Set valid bit
443
444 r[0] = ((u32)e->mac[0]) << 24 | ((u32)e->mac[1]) << 16
445 | ((u32)e->mac[2]) << 8 | ((u32)e->mac[3]);
446 r[1] = ((u32)e->mac[4]) << 24 | ((u32)e->mac[5]) << 16;
447
448 r[2] |= e->next_hop ? BIT(12) : 0;
449
450 if (e->type == L2_UNICAST) {
451 r[2] |= e->is_static ? BIT(14) : 0;
452 r[1] |= e->rvid & 0xfff;
453 r[2] |= (e->port & 0x3ff) << 20;
454 if (e->is_trunk) {
455 r[2] |= BIT(30);
456 port = e->stack_dev << 9 | (e->port & 0x3f);
457 } else {
458 port = (e->stack_dev & 0xf) << 6;
459 port |= e->port & 0x3f;
460 }
461 r[2] |= port << 20;
462 r[2] |= e->block_da ? BIT(15) : 0;
463 r[2] |= e->block_sa ? BIT(17) : 0;
464 r[2] |= e->suspended ? BIT(13) : 0;
465 r[2] |= (e->age & 0x3) << 17;
466 // the UC_VID field in hardware is used for the VID or for the route id
467 if (e->next_hop)
468 r[2] |= e->nh_route_id & 0x7ff;
469 else
470 r[2] |= e->vid & 0xfff;
471 } else { // L2_MULTICAST
472 r[2] |= (e->mc_portmask_index & 0x3ff) << 16;
473 r[2] |= e->mc_mac_index & 0x7ff;
474 }
475 }
476
477 /*
478 * Read an L2 UC or MC entry out of a hash bucket of the L2 forwarding table
479 * hash is the id of the bucket and pos is the position of the entry in that bucket
480 * The data read from the SoC is filled into rtl838x_l2_entry
481 */
482 static u64 rtl930x_read_l2_entry_using_hash(u32 hash, u32 pos, struct rtl838x_l2_entry *e)
483 {
484 u32 r[3];
485 struct table_reg *q = rtl_table_get(RTL9300_TBL_L2, 0);
486 u32 idx;
487 int i;
488 u64 mac;
489 u64 seed;
490
491 pr_debug("%s: hash %08x, pos: %d\n", __func__, hash, pos);
492
493 /* On the RTL93xx, 2 different hash algorithms are used making it a total of
494 * 8 buckets that need to be searched, 4 for each hash-half
495 * Use second hash space when bucket is between 4 and 8 */
496 if (pos >= 4) {
497 pos -= 4;
498 hash >>= 16;
499 } else {
500 hash &= 0xffff;
501 }
502
503 idx = (0 << 14) | (hash << 2) | pos; // Search SRAM, with hash and at pos in bucket
504 pr_debug("%s: NOW hash %08x, pos: %d\n", __func__, hash, pos);
505
506 rtl_table_read(q, idx);
507 for (i = 0; i < 3; i++)
508 r[i] = sw_r32(rtl_table_data(q, i));
509
510 rtl_table_release(q);
511
512 rtl930x_fill_l2_entry(r, e);
513
514 pr_debug("%s: valid: %d, nh: %d\n", __func__, e->valid, e->next_hop);
515 if (!e->valid)
516 return 0;
517
518 mac = ((u64)e->mac[0]) << 40 | ((u64)e->mac[1]) << 32 | ((u64)e->mac[2]) << 24
519 | ((u64)e->mac[3]) << 16 | ((u64)e->mac[4]) << 8 | ((u64)e->mac[5]);
520
521 seed = rtl930x_l2_hash_seed(mac, e->rvid);
522 pr_debug("%s: mac %016llx, seed %016llx\n", __func__, mac, seed);
523 // return vid with concatenated mac as unique id
524 return seed;
525 }
526
527 static void rtl930x_write_l2_entry_using_hash(u32 hash, u32 pos, struct rtl838x_l2_entry *e)
528 {
529 u32 r[3];
530 struct table_reg *q = rtl_table_get(RTL9300_TBL_L2, 0);
531 u32 idx = (0 << 14) | (hash << 2) | pos; // Access SRAM, with hash and at pos in bucket
532 int i;
533
534 pr_debug("%s: hash %d, pos %d\n", __func__, hash, pos);
535 pr_debug("%s: index %d -> mac %02x:%02x:%02x:%02x:%02x:%02x\n", __func__, idx,
536 e->mac[0], e->mac[1], e->mac[2], e->mac[3],e->mac[4],e->mac[5]);
537
538 rtl930x_fill_l2_row(r, e);
539
540 for (i= 0; i < 3; i++)
541 sw_w32(r[i], rtl_table_data(q, i));
542
543 rtl_table_write(q, idx);
544 rtl_table_release(q);
545 }
546
547 static u64 rtl930x_read_cam(int idx, struct rtl838x_l2_entry *e)
548 {
549 u32 r[3];
550 struct table_reg *q = rtl_table_get(RTL9300_TBL_L2, 1);
551 int i;
552
553 rtl_table_read(q, idx);
554 for (i= 0; i < 3; i++)
555 r[i] = sw_r32(rtl_table_data(q, i));
556
557 rtl_table_release(q);
558
559 rtl930x_fill_l2_entry(r, e);
560 if (!e->valid)
561 return 0;
562
563 // return mac with concatenated vid as unique id
564 return ((u64)r[0] << 28) | ((r[1] & 0xffff0000) >> 4) | e->vid;
565 }
566
567 static void rtl930x_write_cam(int idx, struct rtl838x_l2_entry *e)
568 {
569 u32 r[3];
570 struct table_reg *q = rtl_table_get(RTL9300_TBL_L2, 1); // Access L2 Table 1
571 int i;
572
573 rtl930x_fill_l2_row(r, e);
574
575 for (i= 0; i < 3; i++)
576 sw_w32(r[i], rtl_table_data(q, i));
577
578 rtl_table_write(q, idx);
579 rtl_table_release(q);
580 }
581
582 static void dump_l2_entry(struct rtl838x_l2_entry *e)
583 {
584 pr_info("MAC: %02x:%02x:%02x:%02x:%02x:%02x vid: %d, rvid: %d, port: %d, valid: %d\n",
585 e->mac[0], e->mac[1], e->mac[2], e->mac[3], e->mac[4], e->mac[5],
586 e->vid, e->rvid, e->port, e->valid);
587 pr_info("Type: %d, is_static: %d, is_ip_mc: %d, is_ipv6_mc: %d, block_da: %d\n",
588 e->type, e->is_static, e->is_ip_mc, e->is_ipv6_mc, e->block_da);
589 pr_info(" block_sa: %d, suspended: %d, next_hop: %d, age: %d, is_trunk: %d, trunk: %d\n",
590 e->block_sa, e->suspended, e->next_hop, e->age, e->is_trunk, e->trunk);
591 if (e->is_ip_mc || e->is_ipv6_mc)
592 pr_info(" mc_portmask_index: %d, mc_gip: %d, mc_sip: %d\n",
593 e->mc_portmask_index, e->mc_gip, e->mc_sip);
594 pr_info(" stac_dev: %d, nh_route_id: %d, port: %d, dev_id\n",
595 e->stack_dev, e->nh_route_id, e->port);
596 }
597
598 static u64 rtl930x_read_mcast_pmask(int idx)
599 {
600 u32 portmask;
601 // Read MC_PORTMASK (2) via register RTL9300_TBL_L2
602 struct table_reg *q = rtl_table_get(RTL9300_TBL_L2, 2);
603
604 rtl_table_read(q, idx);
605 portmask = sw_r32(rtl_table_data(q, 0));
606 portmask >>= 3;
607 rtl_table_release(q);
608
609 pr_debug("%s: Index idx %d has portmask %08x\n", __func__, idx, portmask);
610 return portmask;
611 }
612
613 static void rtl930x_write_mcast_pmask(int idx, u64 portmask)
614 {
615 u32 pm = portmask;
616
617 // Access MC_PORTMASK (2) via register RTL9300_TBL_L2
618 struct table_reg *q = rtl_table_get(RTL9300_TBL_L2, 2);
619
620 pr_debug("%s: Index idx %d has portmask %08x\n", __func__, idx, pm);
621 pm <<= 3;
622 sw_w32(pm, rtl_table_data(q, 0));
623 rtl_table_write(q, idx);
624 rtl_table_release(q);
625 }
626
627 u64 rtl930x_traffic_get(int source)
628 {
629 u32 v;
630 struct table_reg *r = rtl_table_get(RTL9300_TBL_0, 6);
631
632 rtl_table_read(r, source);
633 v = sw_r32(rtl_table_data(r, 0));
634 rtl_table_release(r);
635 return v >> 3;
636 }
637
638 /*
639 * Enable traffic between a source port and a destination port matrix
640 */
641 void rtl930x_traffic_set(int source, u64 dest_matrix)
642 {
643 struct table_reg *r = rtl_table_get(RTL9300_TBL_0, 6);
644
645 sw_w32((dest_matrix << 3), rtl_table_data(r, 0));
646 rtl_table_write(r, source);
647 rtl_table_release(r);
648 }
649
650 void rtl930x_traffic_enable(int source, int dest)
651 {
652 struct table_reg *r = rtl_table_get(RTL9300_TBL_0, 6);
653 rtl_table_read(r, source);
654 sw_w32_mask(0, BIT(dest + 3), rtl_table_data(r, 0));
655 rtl_table_write(r, source);
656 rtl_table_release(r);
657 }
658
659 void rtl930x_traffic_disable(int source, int dest)
660 {
661 struct table_reg *r = rtl_table_get(RTL9300_TBL_0, 6);
662 rtl_table_read(r, source);
663 sw_w32_mask(BIT(dest + 3), 0, rtl_table_data(r, 0));
664 rtl_table_write(r, source);
665 rtl_table_release(r);
666 }
667
668 void rtl9300_dump_debug(void)
669 {
670 int i;
671 u16 r = RTL930X_STAT_PRVTE_DROP_COUNTER0;
672
673 for (i = 0; i < 10; i ++) {
674 pr_info("# %d %08x %08x %08x %08x %08x %08x %08x %08x\n", i * 8,
675 sw_r32(r), sw_r32(r + 4), sw_r32(r + 8), sw_r32(r + 12),
676 sw_r32(r + 16), sw_r32(r + 20), sw_r32(r + 24), sw_r32(r + 28));
677 r += 32;
678 }
679 pr_info("# %08x %08x %08x %08x %08x\n",
680 sw_r32(r), sw_r32(r + 4), sw_r32(r + 8), sw_r32(r + 12), sw_r32(r + 16));
681 rtl930x_print_matrix();
682 pr_info("RTL930X_L2_PORT_SABLK_CTRL: %08x, RTL930X_L2_PORT_DABLK_CTRL %08x\n",
683 sw_r32(RTL930X_L2_PORT_SABLK_CTRL), sw_r32(RTL930X_L2_PORT_DABLK_CTRL)
684
685 );
686 }
687
688 irqreturn_t rtl930x_switch_irq(int irq, void *dev_id)
689 {
690 struct dsa_switch *ds = dev_id;
691 u32 ports = sw_r32(RTL930X_ISR_PORT_LINK_STS_CHG);
692 u32 link;
693 int i;
694
695 /* Clear status */
696 sw_w32(ports, RTL930X_ISR_PORT_LINK_STS_CHG);
697
698 for (i = 0; i < 28; i++) {
699 if (ports & BIT(i)) {
700 /* Read the register twice because of issues with latency at least
701 * with the external RTL8226 PHY on the XGS1210 */
702 link = sw_r32(RTL930X_MAC_LINK_STS);
703 link = sw_r32(RTL930X_MAC_LINK_STS);
704 if (link & BIT(i))
705 dsa_port_phylink_mac_change(ds, i, true);
706 else
707 dsa_port_phylink_mac_change(ds, i, false);
708 }
709 }
710
711 return IRQ_HANDLED;
712 }
713
714 int rtl930x_write_phy(u32 port, u32 page, u32 reg, u32 val)
715 {
716 u32 v;
717 int err = 0;
718
719 pr_debug("%s: port %d, page: %d, reg: %x, val: %x\n", __func__, port, page, reg, val);
720
721 if (port > 63 || page > 4095 || reg > 31)
722 return -ENOTSUPP;
723
724 val &= 0xffff;
725 mutex_lock(&smi_lock);
726
727 sw_w32(BIT(port), RTL930X_SMI_ACCESS_PHY_CTRL_0);
728 sw_w32_mask(0xffff << 16, val << 16, RTL930X_SMI_ACCESS_PHY_CTRL_2);
729 v = reg << 20 | page << 3 | 0x1f << 15 | BIT(2) | BIT(0);
730 sw_w32(v, RTL930X_SMI_ACCESS_PHY_CTRL_1);
731
732 do {
733 v = sw_r32(RTL930X_SMI_ACCESS_PHY_CTRL_1);
734 } while (v & 0x1);
735
736 if (v & 0x2)
737 err = -EIO;
738
739 mutex_unlock(&smi_lock);
740
741 return err;
742 }
743
744 int rtl930x_read_phy(u32 port, u32 page, u32 reg, u32 *val)
745 {
746 u32 v;
747 int err = 0;
748
749 if (port > 63 || page > 4095 || reg > 31)
750 return -ENOTSUPP;
751
752 mutex_lock(&smi_lock);
753
754 sw_w32_mask(0xffff << 16, port << 16, RTL930X_SMI_ACCESS_PHY_CTRL_2);
755 v = reg << 20 | page << 3 | 0x1f << 15 | 1;
756 sw_w32(v, RTL930X_SMI_ACCESS_PHY_CTRL_1);
757
758 do {
759 v = sw_r32(RTL930X_SMI_ACCESS_PHY_CTRL_1);
760 } while ( v & 0x1);
761
762 if (v & BIT(25)) {
763 pr_debug("Error reading phy %d, register %d\n", port, reg);
764 err = -EIO;
765 }
766 *val = (sw_r32(RTL930X_SMI_ACCESS_PHY_CTRL_2) & 0xffff);
767
768 pr_debug("%s: port %d, page: %d, reg: %x, val: %x\n", __func__, port, page, reg, *val);
769
770 mutex_unlock(&smi_lock);
771
772 return err;
773 }
774
775 /*
776 * Write to an mmd register of the PHY
777 */
778 int rtl930x_write_mmd_phy(u32 port, u32 devnum, u32 regnum, u32 val)
779 {
780 int err = 0;
781 u32 v;
782
783 mutex_lock(&smi_lock);
784
785 // Set PHY to access
786 sw_w32(BIT(port), RTL930X_SMI_ACCESS_PHY_CTRL_0);
787
788 // Set data to write
789 sw_w32_mask(0xffff << 16, val << 16, RTL930X_SMI_ACCESS_PHY_CTRL_2);
790
791 // Set MMD device number and register to write to
792 sw_w32(devnum << 16 | (regnum & 0xffff), RTL930X_SMI_ACCESS_PHY_CTRL_3);
793
794 v = BIT(2) | BIT(1) | BIT(0); // WRITE | MMD-access | EXEC
795 sw_w32(v, RTL930X_SMI_ACCESS_PHY_CTRL_1);
796
797 do {
798 v = sw_r32(RTL930X_SMI_ACCESS_PHY_CTRL_1);
799 } while (v & BIT(0));
800
801 pr_debug("%s: port %d, regnum: %x, val: %x (err %d)\n", __func__, port, regnum, val, err);
802 mutex_unlock(&smi_lock);
803 return err;
804 }
805
806 /*
807 * Read an mmd register of the PHY
808 */
809 int rtl930x_read_mmd_phy(u32 port, u32 devnum, u32 regnum, u32 *val)
810 {
811 int err = 0;
812 u32 v;
813
814 mutex_lock(&smi_lock);
815
816 // Set PHY to access
817 sw_w32_mask(0xffff << 16, port << 16, RTL930X_SMI_ACCESS_PHY_CTRL_2);
818
819 // Set MMD device number and register to write to
820 sw_w32(devnum << 16 | (regnum & 0xffff), RTL930X_SMI_ACCESS_PHY_CTRL_3);
821
822 v = BIT(1) | BIT(0); // MMD-access | EXEC
823 sw_w32(v, RTL930X_SMI_ACCESS_PHY_CTRL_1);
824
825 do {
826 v = sw_r32(RTL930X_SMI_ACCESS_PHY_CTRL_1);
827 } while (v & BIT(0));
828 // There is no error-checking via BIT 25 of v, as it does not seem to be set correctly
829 *val = (sw_r32(RTL930X_SMI_ACCESS_PHY_CTRL_2) & 0xffff);
830 pr_debug("%s: port %d, regnum: %x, val: %x (err %d)\n", __func__, port, regnum, *val, err);
831
832 mutex_unlock(&smi_lock);
833
834 return err;
835 }
836
837 /*
838 * Calculate both the block 0 and the block 1 hash, and return in
839 * lower and higher word of the return value since only 12 bit of
840 * the hash are significant
841 */
842 u32 rtl930x_hash(struct rtl838x_switch_priv *priv, u64 seed)
843 {
844 u32 k0, k1, h1, h2, h;
845
846 k0 = (u32) (((seed >> 55) & 0x1f) ^ ((seed >> 44) & 0x7ff)
847 ^ ((seed >> 33) & 0x7ff) ^ ((seed >> 22) & 0x7ff)
848 ^ ((seed >> 11) & 0x7ff) ^ (seed & 0x7ff));
849
850 h1 = (seed >> 11) & 0x7ff;
851 h1 = ((h1 & 0x1f) << 6) | ((h1 >> 5) & 0x3f);
852
853 h2 = (seed >> 33) & 0x7ff;
854 h2 = ((h2 & 0x3f) << 5)| ((h2 >> 6) & 0x3f);
855
856 k1 = (u32) (((seed << 55) & 0x1f) ^ ((seed >> 44) & 0x7ff) ^ h2
857 ^ ((seed >> 22) & 0x7ff) ^ h1
858 ^ (seed & 0x7ff));
859
860 // Algorithm choice for block 0
861 if (sw_r32(RTL930X_L2_CTRL) & BIT(0))
862 h = k1;
863 else
864 h = k0;
865
866 /* Algorithm choice for block 1
867 * Since k0 and k1 are < 2048, adding 2048 will offset the hash into the second
868 * half of hash-space
869 * 2048 is in fact the hash-table size 16384 divided by 4 hashes per bucket
870 * divided by 2 to divide the hash space in 2
871 */
872 if (sw_r32(RTL930X_L2_CTRL) & BIT(1))
873 h |= (k1 + 2048) << 16;
874 else
875 h |= (k0 + 2048) << 16;
876
877 return h;
878 }
879
880 /*
881 * Enables or disables the EEE/EEEP capability of a port
882 */
883 void rtl930x_port_eee_set(struct rtl838x_switch_priv *priv, int port, bool enable)
884 {
885 u32 v;
886
887 // This works only for Ethernet ports, and on the RTL930X, ports from 26 are SFP
888 if (port >= 26)
889 return;
890
891 pr_debug("In %s: setting port %d to %d\n", __func__, port, enable);
892 v = enable ? 0x3f : 0x0;
893
894 // Set EEE/EEEP state for 100, 500, 1000MBit and 2.5, 5 and 10GBit
895 sw_w32_mask(0, v << 10, rtl930x_mac_force_mode_ctrl(port));
896
897 // Set TX/RX EEE state
898 v = enable ? 0x3 : 0x0;
899 sw_w32(v, RTL930X_EEE_CTRL(port));
900
901 priv->ports[port].eee_enabled = enable;
902 }
903
904 /*
905 * Get EEE own capabilities and negotiation result
906 */
907 int rtl930x_eee_port_ability(struct rtl838x_switch_priv *priv, struct ethtool_eee *e, int port)
908 {
909 u32 link, a;
910
911 if (port >= 26)
912 return -ENOTSUPP;
913
914 pr_info("In %s, port %d\n", __func__, port);
915 link = sw_r32(RTL930X_MAC_LINK_STS);
916 link = sw_r32(RTL930X_MAC_LINK_STS);
917 if (!(link & BIT(port)))
918 return 0;
919
920 pr_info("Setting advertised\n");
921 if (sw_r32(rtl930x_mac_force_mode_ctrl(port)) & BIT(10))
922 e->advertised |= ADVERTISED_100baseT_Full;
923
924 if (sw_r32(rtl930x_mac_force_mode_ctrl(port)) & BIT(12))
925 e->advertised |= ADVERTISED_1000baseT_Full;
926
927 if (priv->ports[port].is2G5 && sw_r32(rtl930x_mac_force_mode_ctrl(port)) & BIT(13)) {
928 pr_info("ADVERTISING 2.5G EEE\n");
929 e->advertised |= ADVERTISED_2500baseX_Full;
930 }
931
932 if (priv->ports[port].is10G && sw_r32(rtl930x_mac_force_mode_ctrl(port)) & BIT(15))
933 e->advertised |= ADVERTISED_10000baseT_Full;
934
935 a = sw_r32(RTL930X_MAC_EEE_ABLTY);
936 a = sw_r32(RTL930X_MAC_EEE_ABLTY);
937 pr_info("Link partner: %08x\n", a);
938 if (a & BIT(port)) {
939 e->lp_advertised = ADVERTISED_100baseT_Full;
940 e->lp_advertised |= ADVERTISED_1000baseT_Full;
941 if (priv->ports[port].is2G5)
942 e->lp_advertised |= ADVERTISED_2500baseX_Full;
943 if (priv->ports[port].is10G)
944 e->lp_advertised |= ADVERTISED_10000baseT_Full;
945 }
946
947 // Read 2x to clear latched state
948 a = sw_r32(RTL930X_EEEP_PORT_CTRL(port));
949 a = sw_r32(RTL930X_EEEP_PORT_CTRL(port));
950 pr_info("%s RTL930X_EEEP_PORT_CTRL: %08x\n", __func__, a);
951
952 return 0;
953 }
954
955 static void rtl930x_init_eee(struct rtl838x_switch_priv *priv, bool enable)
956 {
957 int i;
958
959 pr_info("Setting up EEE, state: %d\n", enable);
960
961 // Setup EEE on all ports
962 for (i = 0; i < priv->cpu_port; i++) {
963 if (priv->ports[i].phy)
964 rtl930x_port_eee_set(priv, i, enable);
965 }
966
967 priv->eee_enabled = enable;
968 }
969 #define HASH_PICK(val, lsb, len) ((val & (((1 << len) - 1) << lsb)) >> lsb)
970
971 static u32 rtl930x_l3_hash4(u32 ip, int algorithm, bool move_dip)
972 {
973 u32 rows[4];
974 u32 hash;
975 u32 s0, s1, pH;
976
977 memset(rows, 0, sizeof(rows));
978
979 rows[0] = HASH_PICK(ip, 27, 5);
980 rows[1] = HASH_PICK(ip, 18, 9);
981 rows[2] = HASH_PICK(ip, 9, 9);
982
983 if (!move_dip)
984 rows[3] = HASH_PICK(ip, 0, 9);
985
986 if (!algorithm) {
987 hash = rows[0] ^ rows[1] ^ rows[2] ^ rows[3];
988 } else {
989 s0 = rows[0] + rows[1] + rows[2];
990 s1 = (s0 & 0x1ff) + ((s0 & (0x1ff << 9)) >> 9);
991 pH = (s1 & 0x1ff) + ((s1 & (0x1ff << 9)) >> 9);
992 hash = pH ^ rows[3];
993 }
994 return hash;
995 }
996
997 static u32 rtl930x_l3_hash6(struct in6_addr *ip6, int algorithm, bool move_dip)
998 {
999 u32 rows[16];
1000 u32 hash;
1001 u32 s0, s1, pH;
1002
1003 rows[0] = (HASH_PICK(ip6->s6_addr[0], 6, 2) << 0);
1004 rows[1] = (HASH_PICK(ip6->s6_addr[0], 0, 6) << 3) | HASH_PICK(ip6->s6_addr[1], 5, 3);
1005 rows[2] = (HASH_PICK(ip6->s6_addr[1], 0, 5) << 4) | HASH_PICK(ip6->s6_addr[2], 4, 4);
1006 rows[3] = (HASH_PICK(ip6->s6_addr[2], 0, 4) << 5) | HASH_PICK(ip6->s6_addr[3], 3, 5);
1007 rows[4] = (HASH_PICK(ip6->s6_addr[3], 0, 3) << 6) | HASH_PICK(ip6->s6_addr[4], 2, 6);
1008 rows[5] = (HASH_PICK(ip6->s6_addr[4], 0, 2) << 7) | HASH_PICK(ip6->s6_addr[5], 1, 7);
1009 rows[6] = (HASH_PICK(ip6->s6_addr[5], 0, 1) << 8) | HASH_PICK(ip6->s6_addr[6], 0, 8);
1010 rows[7] = (HASH_PICK(ip6->s6_addr[7], 0, 8) << 1) | HASH_PICK(ip6->s6_addr[8], 7, 1);
1011 rows[8] = (HASH_PICK(ip6->s6_addr[8], 0, 7) << 2) | HASH_PICK(ip6->s6_addr[9], 6, 2);
1012 rows[9] = (HASH_PICK(ip6->s6_addr[9], 0, 6) << 3) | HASH_PICK(ip6->s6_addr[10], 5, 3);
1013 rows[10] = (HASH_PICK(ip6->s6_addr[10], 0, 5) << 4) | HASH_PICK(ip6->s6_addr[11], 4, 4);
1014 if (!algorithm) {
1015 rows[11] = (HASH_PICK(ip6->s6_addr[11], 0, 4) << 5)
1016 | (HASH_PICK(ip6->s6_addr[12], 3, 5) << 0);
1017 rows[12] = (HASH_PICK(ip6->s6_addr[12], 0, 3) << 6)
1018 | (HASH_PICK(ip6->s6_addr[13], 2, 6) << 0);
1019 rows[13] = (HASH_PICK(ip6->s6_addr[13], 0, 2) << 7)
1020 | (HASH_PICK(ip6->s6_addr[14], 1, 7) << 0);
1021 if (!move_dip) {
1022 rows[14] = (HASH_PICK(ip6->s6_addr[14], 0, 1) << 8)
1023 | (HASH_PICK(ip6->s6_addr[15], 0, 8) << 0);
1024 }
1025 hash = rows[0] ^ rows[1] ^ rows[2] ^ rows[3] ^ rows[4] ^ rows[5] ^ rows[6]
1026 ^ rows[7] ^ rows[8] ^ rows[9] ^ rows[10] ^ rows[11] ^ rows[12]
1027 ^ rows[13] ^ rows[14];
1028 } else {
1029 rows[11] = (HASH_PICK(ip6->s6_addr[11], 0, 4) << 5);
1030 rows[12] = (HASH_PICK(ip6->s6_addr[12], 3, 5) << 0);
1031 rows[13] = (HASH_PICK(ip6->s6_addr[12], 0, 3) << 6)
1032 | HASH_PICK(ip6->s6_addr[13], 2, 6);
1033 rows[14] = (HASH_PICK(ip6->s6_addr[13], 0, 2) << 7)
1034 | HASH_PICK(ip6->s6_addr[14], 1, 7);
1035 if (!move_dip) {
1036 rows[15] = (HASH_PICK(ip6->s6_addr[14], 0, 1) << 8)
1037 | (HASH_PICK(ip6->s6_addr[15], 0, 8) << 0);
1038 }
1039 s0 = rows[12] + rows[13] + rows[14];
1040 s1 = (s0 & 0x1ff) + ((s0 & (0x1ff << 9)) >> 9);
1041 pH = (s1 & 0x1ff) + ((s1 & (0x1ff << 9)) >> 9);
1042 hash = rows[0] ^ rows[1] ^ rows[2] ^ rows[3] ^ rows[4] ^ rows[5] ^ rows[6]
1043 ^ rows[7] ^ rows[8] ^ rows[9] ^ rows[10] ^ rows[11] ^ pH ^ rows[15];
1044 }
1045 return hash;
1046 }
1047
1048 /*
1049 * Read a prefix route entry from the L3_PREFIX_ROUTE_IPUC table
1050 * We currently only support IPv4 and IPv6 unicast route
1051 */
1052 static void rtl930x_route_read(int idx, struct rtl83xx_route *rt)
1053 {
1054 u32 v, ip4_m;
1055 bool host_route, default_route;
1056 struct in6_addr ip6_m;
1057
1058 // Read L3_PREFIX_ROUTE_IPUC table (2) via register RTL9300_TBL_1
1059 struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 2);
1060
1061 rtl_table_read(r, idx);
1062 // The table has a size of 11 registers
1063 rt->attr.valid = !!(sw_r32(rtl_table_data(r, 0)) & BIT(31));
1064 if (!rt->attr.valid)
1065 goto out;
1066
1067 rt->attr.type = (sw_r32(rtl_table_data(r, 0)) >> 29) & 0x3;
1068
1069 v = sw_r32(rtl_table_data(r, 10));
1070 host_route = !!(v & BIT(21));
1071 default_route = !!(v & BIT(20));
1072 rt->prefix_len = -1;
1073 pr_info("%s: host route %d, default_route %d\n", __func__, host_route, default_route);
1074
1075 switch (rt->attr.type) {
1076 case 0: // IPv4 Unicast route
1077 rt->dst_ip = sw_r32(rtl_table_data(r, 4));
1078 ip4_m = sw_r32(rtl_table_data(r, 9));
1079 pr_info("%s: Read ip4 mask: %08x\n", __func__, ip4_m);
1080 rt->prefix_len = host_route ? 32 : -1;
1081 rt->prefix_len = (rt->prefix_len < 0 && default_route) ? 0 : -1;
1082 if (rt->prefix_len < 0)
1083 rt->prefix_len = inet_mask_len(ip4_m);
1084 break;
1085 case 2: // IPv6 Unicast route
1086 ipv6_addr_set(&rt->dst_ip6,
1087 sw_r32(rtl_table_data(r, 1)), sw_r32(rtl_table_data(r, 2)),
1088 sw_r32(rtl_table_data(r, 3)), sw_r32(rtl_table_data(r, 4)));
1089 ipv6_addr_set(&ip6_m,
1090 sw_r32(rtl_table_data(r, 6)), sw_r32(rtl_table_data(r, 7)),
1091 sw_r32(rtl_table_data(r, 8)), sw_r32(rtl_table_data(r, 9)));
1092 rt->prefix_len = host_route ? 128 : 0;
1093 rt->prefix_len = (rt->prefix_len < 0 && default_route) ? 0 : -1;
1094 if (rt->prefix_len < 0)
1095 rt->prefix_len = find_last_bit((unsigned long int *)&ip6_m.s6_addr32,
1096 128);
1097 break;
1098 case 1: // IPv4 Multicast route
1099 case 3: // IPv6 Multicast route
1100 pr_warn("%s: route type not supported\n", __func__);
1101 goto out;
1102 }
1103
1104 rt->attr.hit = !!(v & BIT(22));
1105 rt->attr.action = (v >> 18) & 3;
1106 rt->nh.id = (v >> 7) & 0x7ff;
1107 rt->attr.ttl_dec = !!(v & BIT(6));
1108 rt->attr.ttl_check = !!(v & BIT(5));
1109 rt->attr.dst_null = !!(v & BIT(4));
1110 rt->attr.qos_as = !!(v & BIT(3));
1111 rt->attr.qos_prio = v & 0x7;
1112 pr_info("%s: index %d is valid: %d\n", __func__, idx, rt->attr.valid);
1113 pr_info("%s: next_hop: %d, hit: %d, action :%d, ttl_dec %d, ttl_check %d, dst_null %d\n",
1114 __func__, rt->nh.id, rt->attr.hit, rt->attr.action,
1115 rt->attr.ttl_dec, rt->attr.ttl_check, rt->attr.dst_null);
1116 pr_info("%s: GW: %pI4, prefix_len: %d\n", __func__, &rt->dst_ip, rt->prefix_len);
1117 out:
1118 rtl_table_release(r);
1119 }
1120
1121 static void rtl930x_net6_mask(int prefix_len, struct in6_addr *ip6_m)
1122 {
1123 int o, b;
1124 // Define network mask
1125 o = prefix_len >> 3;
1126 b = prefix_len & 0x7;
1127 memset(ip6_m->s6_addr, 0xff, o);
1128 ip6_m->s6_addr[o] |= b ? 0xff00 >> b : 0x00;
1129 }
1130
1131 /*
1132 * Read a host route entry from the table using its index
1133 * We currently only support IPv4 and IPv6 unicast route
1134 */
1135 static void rtl930x_host_route_read(int idx, struct rtl83xx_route *rt)
1136 {
1137 u32 v;
1138 // Read L3_HOST_ROUTE_IPUC table (1) via register RTL9300_TBL_1
1139 struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 1);
1140
1141 idx = ((idx / 6) * 8) + (idx % 6);
1142
1143 pr_debug("In %s, physical index %d\n", __func__, idx);
1144 rtl_table_read(r, idx);
1145 // The table has a size of 5 (for UC, 11 for MC) registers
1146 v = sw_r32(rtl_table_data(r, 0));
1147 rt->attr.valid = !!(v & BIT(31));
1148 if (!rt->attr.valid)
1149 goto out;
1150 rt->attr.type = (v >> 29) & 0x3;
1151 switch (rt->attr.type) {
1152 case 0: // IPv4 Unicast route
1153 rt->dst_ip = sw_r32(rtl_table_data(r, 4));
1154 break;
1155 case 2: // IPv6 Unicast route
1156 ipv6_addr_set(&rt->dst_ip6,
1157 sw_r32(rtl_table_data(r, 3)), sw_r32(rtl_table_data(r, 2)),
1158 sw_r32(rtl_table_data(r, 1)), sw_r32(rtl_table_data(r, 0)));
1159 break;
1160 case 1: // IPv4 Multicast route
1161 case 3: // IPv6 Multicast route
1162 pr_warn("%s: route type not supported\n", __func__);
1163 goto out;
1164 }
1165
1166 rt->attr.hit = !!(v & BIT(20));
1167 rt->attr.dst_null = !!(v & BIT(19));
1168 rt->attr.action = (v >> 17) & 3;
1169 rt->nh.id = (v >> 6) & 0x7ff;
1170 rt->attr.ttl_dec = !!(v & BIT(5));
1171 rt->attr.ttl_check = !!(v & BIT(4));
1172 rt->attr.qos_as = !!(v & BIT(3));
1173 rt->attr.qos_prio = v & 0x7;
1174 pr_debug("%s: index %d is valid: %d\n", __func__, idx, rt->attr.valid);
1175 pr_debug("%s: next_hop: %d, hit: %d, action :%d, ttl_dec %d, ttl_check %d, dst_null %d\n",
1176 __func__, rt->nh.id, rt->attr.hit, rt->attr.action, rt->attr.ttl_dec, rt->attr.ttl_check,
1177 rt->attr.dst_null);
1178 pr_debug("%s: Destination: %pI4\n", __func__, &rt->dst_ip);
1179
1180 out:
1181 rtl_table_release(r);
1182 }
1183
1184 /*
1185 * Write a host route entry from the table using its index
1186 * We currently only support IPv4 and IPv6 unicast route
1187 */
1188 static void rtl930x_host_route_write(int idx, struct rtl83xx_route *rt)
1189 {
1190 u32 v;
1191 // Access L3_HOST_ROUTE_IPUC table (1) via register RTL9300_TBL_1
1192 struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 1);
1193 // The table has a size of 5 (for UC, 11 for MC) registers
1194
1195 idx = ((idx / 6) * 8) + (idx % 6);
1196
1197 pr_debug("%s: index %d is valid: %d\n", __func__, idx, rt->attr.valid);
1198 pr_debug("%s: next_hop: %d, hit: %d, action :%d, ttl_dec %d, ttl_check %d, dst_null %d\n",
1199 __func__, rt->nh.id, rt->attr.hit, rt->attr.action, rt->attr.ttl_dec, rt->attr.ttl_check,
1200 rt->attr.dst_null);
1201 pr_debug("%s: GW: %pI4, prefix_len: %d\n", __func__, &rt->dst_ip, rt->prefix_len);
1202
1203 v = BIT(31); // Entry is valid
1204 v |= (rt->attr.type & 0x3) << 29;
1205 v |= rt->attr.hit ? BIT(20) : 0;
1206 v |= rt->attr.dst_null ? BIT(19) : 0;
1207 v |= (rt->attr.action & 0x3) << 17;
1208 v |= (rt->nh.id & 0x7ff) << 6;
1209 v |= rt->attr.ttl_dec ? BIT(5) : 0;
1210 v |= rt->attr.ttl_check ? BIT(4) : 0;
1211 v |= rt->attr.qos_as ? BIT(3) : 0;
1212 v |= rt->attr.qos_prio & 0x7;
1213
1214 sw_w32(v, rtl_table_data(r, 0));
1215 switch (rt->attr.type) {
1216 case 0: // IPv4 Unicast route
1217 sw_w32(0, rtl_table_data(r, 1));
1218 sw_w32(0, rtl_table_data(r, 2));
1219 sw_w32(0, rtl_table_data(r, 3));
1220 sw_w32(rt->dst_ip, rtl_table_data(r, 4));
1221 break;
1222 case 2: // IPv6 Unicast route
1223 sw_w32(rt->dst_ip6.s6_addr32[0], rtl_table_data(r, 1));
1224 sw_w32(rt->dst_ip6.s6_addr32[1], rtl_table_data(r, 2));
1225 sw_w32(rt->dst_ip6.s6_addr32[2], rtl_table_data(r, 3));
1226 sw_w32(rt->dst_ip6.s6_addr32[3], rtl_table_data(r, 4));
1227 break;
1228 case 1: // IPv4 Multicast route
1229 case 3: // IPv6 Multicast route
1230 pr_warn("%s: route type not supported\n", __func__);
1231 goto out;
1232 }
1233
1234 rtl_table_write(r, idx);
1235
1236 out:
1237 rtl_table_release(r);
1238 }
1239
1240 /*
1241 * Look up the index of a prefix route in the routing table CAM for unicast IPv4/6 routes
1242 * using hardware offload.
1243 */
1244 static int rtl930x_route_lookup_hw(struct rtl83xx_route *rt)
1245 {
1246 u32 ip4_m, v;
1247 struct in6_addr ip6_m;
1248 int i;
1249
1250 if (rt->attr.type == 1 || rt->attr.type == 3) // Hardware only supports UC routes
1251 return -1;
1252
1253 sw_w32_mask(0x3 << 19, rt->attr.type, RTL930X_L3_HW_LU_KEY_CTRL);
1254 if (rt->attr.type) { // IPv6
1255 rtl930x_net6_mask(rt->prefix_len, &ip6_m);
1256 for (i = 0; i < 4; i++)
1257 sw_w32(rt->dst_ip6.s6_addr32[0] & ip6_m.s6_addr32[0],
1258 RTL930X_L3_HW_LU_KEY_IP_CTRL + (i << 2));
1259 } else { // IPv4
1260 ip4_m = inet_make_mask(rt->prefix_len);
1261 sw_w32(0, RTL930X_L3_HW_LU_KEY_IP_CTRL);
1262 sw_w32(0, RTL930X_L3_HW_LU_KEY_IP_CTRL + 4);
1263 sw_w32(0, RTL930X_L3_HW_LU_KEY_IP_CTRL + 8);
1264 v = rt->dst_ip & ip4_m;
1265 pr_info("%s: searching for %pI4\n", __func__, &v);
1266 sw_w32(v, RTL930X_L3_HW_LU_KEY_IP_CTRL + 12);
1267 }
1268
1269 // Execute CAM lookup in SoC
1270 sw_w32(BIT(15), RTL930X_L3_HW_LU_CTRL);
1271
1272 // Wait until execute bit clears and result is ready
1273 do {
1274 v = sw_r32(RTL930X_L3_HW_LU_CTRL);
1275 } while (v & BIT(15));
1276
1277 pr_info("%s: found: %d, index: %d\n", __func__, !!(v & BIT(14)), v & 0x1ff);
1278
1279 // Test if search successful (BIT 14 set)
1280 if (v & BIT(14))
1281 return v & 0x1ff;
1282
1283 return -1;
1284 }
1285
1286 static int rtl930x_find_l3_slot(struct rtl83xx_route *rt, bool must_exist)
1287 {
1288 int t, s, slot_width, algorithm, addr, idx;
1289 u32 hash;
1290 struct rtl83xx_route route_entry;
1291
1292 // IPv6 entries take up 3 slots
1293 slot_width = (rt->attr.type == 0) || (rt->attr.type == 2) ? 1 : 3;
1294
1295 for (t = 0; t < 2; t++) {
1296 algorithm = (sw_r32(RTL930X_L3_HOST_TBL_CTRL) >> (2 + t)) & 0x1;
1297 hash = rtl930x_l3_hash4(rt->dst_ip, algorithm, false);
1298
1299 pr_debug("%s: table %d, algorithm %d, hash %04x\n", __func__, t, algorithm, hash);
1300
1301 for (s = 0; s < 6; s += slot_width) {
1302 addr = (t << 12) | ((hash & 0x1ff) << 3) | s;
1303 pr_debug("%s physical address %d\n", __func__, addr);
1304 idx = ((addr / 8) * 6) + (addr % 8);
1305 pr_debug("%s logical address %d\n", __func__, idx);
1306
1307 rtl930x_host_route_read(idx, &route_entry);
1308 pr_debug("%s route valid %d, route dest: %pI4, hit %d\n", __func__,
1309 rt->attr.valid, &rt->dst_ip, rt->attr.hit);
1310 if (!must_exist && rt->attr.valid)
1311 return idx;
1312 if (must_exist && route_entry.dst_ip == rt->dst_ip)
1313 return idx;
1314 }
1315 }
1316
1317 return -1;
1318 }
1319
1320 /*
1321 * Write a prefix route into the routing table CAM at position idx
1322 * Currently only IPv4 and IPv6 unicast routes are supported
1323 */
1324 static void rtl930x_route_write(int idx, struct rtl83xx_route *rt)
1325 {
1326 u32 v, ip4_m;
1327 struct in6_addr ip6_m;
1328 // Access L3_PREFIX_ROUTE_IPUC table (2) via register RTL9300_TBL_1
1329 // The table has a size of 11 registers (20 for MC)
1330 struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 2);
1331
1332 pr_debug("%s: index %d is valid: %d\n", __func__, idx, rt->attr.valid);
1333 pr_debug("%s: nexthop: %d, hit: %d, action :%d, ttl_dec %d, ttl_check %d, dst_null %d\n",
1334 __func__, rt->nh.id, rt->attr.hit, rt->attr.action,
1335 rt->attr.ttl_dec, rt->attr.ttl_check, rt->attr.dst_null);
1336 pr_debug("%s: GW: %pI4, prefix_len: %d\n", __func__, &rt->dst_ip, rt->prefix_len);
1337
1338 v = rt->attr.valid ? BIT(31) : 0;
1339 v |= (rt->attr.type & 0x3) << 29;
1340 sw_w32(v, rtl_table_data(r, 0));
1341
1342 v = rt->attr.hit ? BIT(22) : 0;
1343 v |= (rt->attr.action & 0x3) << 18;
1344 v |= (rt->nh.id & 0x7ff) << 7;
1345 v |= rt->attr.ttl_dec ? BIT(6) : 0;
1346 v |= rt->attr.ttl_check ? BIT(5) : 0;
1347 v |= rt->attr.dst_null ? BIT(6) : 0;
1348 v |= rt->attr.qos_as ? BIT(6) : 0;
1349 v |= rt->attr.qos_prio & 0x7;
1350 v |= rt->prefix_len == 0 ? BIT(20) : 0; // set default route bit
1351
1352 // set bit mask for entry type always to 0x3
1353 sw_w32(0x3 << 29, rtl_table_data(r, 5));
1354
1355 switch (rt->attr.type) {
1356 case 0: // IPv4 Unicast route
1357 sw_w32(0, rtl_table_data(r, 1));
1358 sw_w32(0, rtl_table_data(r, 2));
1359 sw_w32(0, rtl_table_data(r, 3));
1360 sw_w32(rt->dst_ip, rtl_table_data(r, 4));
1361
1362 v |= rt->prefix_len == 32 ? BIT(21) : 0; // set host-route bit
1363 ip4_m = inet_make_mask(rt->prefix_len);
1364 sw_w32(0, rtl_table_data(r, 6));
1365 sw_w32(0, rtl_table_data(r, 7));
1366 sw_w32(0, rtl_table_data(r, 8));
1367 sw_w32(ip4_m, rtl_table_data(r, 9));
1368 break;
1369 case 2: // IPv6 Unicast route
1370 sw_w32(rt->dst_ip6.s6_addr32[0], rtl_table_data(r, 1));
1371 sw_w32(rt->dst_ip6.s6_addr32[1], rtl_table_data(r, 2));
1372 sw_w32(rt->dst_ip6.s6_addr32[2], rtl_table_data(r, 3));
1373 sw_w32(rt->dst_ip6.s6_addr32[3], rtl_table_data(r, 4));
1374
1375 v |= rt->prefix_len == 128 ? BIT(21) : 0; // set host-route bit
1376
1377 rtl930x_net6_mask(rt->prefix_len, &ip6_m);
1378
1379 sw_w32(ip6_m.s6_addr32[0], rtl_table_data(r, 6));
1380 sw_w32(ip6_m.s6_addr32[1], rtl_table_data(r, 7));
1381 sw_w32(ip6_m.s6_addr32[2], rtl_table_data(r, 8));
1382 sw_w32(ip6_m.s6_addr32[3], rtl_table_data(r, 9));
1383 break;
1384 case 1: // IPv4 Multicast route
1385 case 3: // IPv6 Multicast route
1386 pr_warn("%s: route type not supported\n", __func__);
1387 rtl_table_release(r);
1388 return;
1389 }
1390 sw_w32(v, rtl_table_data(r, 10));
1391
1392 pr_debug("%s: %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", __func__,
1393 sw_r32(rtl_table_data(r, 0)), sw_r32(rtl_table_data(r, 1)), sw_r32(rtl_table_data(r, 2)),
1394 sw_r32(rtl_table_data(r, 3)), sw_r32(rtl_table_data(r, 4)), sw_r32(rtl_table_data(r, 5)),
1395 sw_r32(rtl_table_data(r, 6)), sw_r32(rtl_table_data(r, 7)), sw_r32(rtl_table_data(r, 8)),
1396 sw_r32(rtl_table_data(r, 9)), sw_r32(rtl_table_data(r, 10)));
1397
1398 rtl_table_write(r, idx);
1399 rtl_table_release(r);
1400 }
1401
1402
1403 /*
1404 * Get the destination MAC and L3 egress interface ID of a nexthop entry from
1405 * the SoC's L3_NEXTHOP table
1406 */
1407 static void rtl930x_get_l3_nexthop(int idx, u16 *dmac_id, u16 *interface)
1408 {
1409 u32 v;
1410 // Read L3_NEXTHOP table (3) via register RTL9300_TBL_1
1411 struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 3);
1412
1413 rtl_table_read(r, idx);
1414 // The table has a size of 1 register
1415 v = sw_r32(rtl_table_data(r, 0));
1416 rtl_table_release(r);
1417
1418 *dmac_id = (v >> 7) & 0x7fff;
1419 *interface = v & 0x7f;
1420 }
1421
1422 static int rtl930x_l3_mtu_del(struct rtl838x_switch_priv *priv, int mtu)
1423 {
1424 int i;
1425
1426 for (i = 0; i < MAX_INTF_MTUS; i++) {
1427 if (mtu == priv->intf_mtus[i])
1428 break;
1429 }
1430 if (i >= MAX_INTF_MTUS || !priv->intf_mtu_count[i]) {
1431 pr_err("%s: No MTU slot found for MTU: %d\n", __func__, mtu);
1432 return -EINVAL;
1433 }
1434
1435 priv->intf_mtu_count[i]--;
1436 }
1437
1438 static int rtl930x_l3_mtu_add(struct rtl838x_switch_priv *priv, int mtu)
1439 {
1440 int i, free_mtu;
1441 int mtu_id;
1442
1443 // Try to find an existing mtu-value or a free slot
1444 free_mtu = MAX_INTF_MTUS;
1445 for (i = 0; i < MAX_INTF_MTUS && priv->intf_mtus[i] != mtu; i++) {
1446 if ((!priv->intf_mtu_count[i]) && (free_mtu == MAX_INTF_MTUS))
1447 free_mtu = i;
1448 }
1449 i = (i < MAX_INTF_MTUS) ? i : free_mtu;
1450 if (i < MAX_INTF_MTUS) {
1451 mtu_id = i;
1452 } else {
1453 pr_err("%s: No free MTU slot available!\n", __func__);
1454 return -EINVAL;
1455 }
1456
1457 priv->intf_mtus[i] = mtu;
1458 pr_info("Writing MTU %d to slot %d\n", priv->intf_mtus[i], i);
1459 // Set MTU-value of the slot TODO: distinguish between IPv4/IPv6 routes / slots
1460 sw_w32_mask(0xffff << ((i % 2) * 16), priv->intf_mtus[i] << ((i % 2) * 16),
1461 RTL930X_L3_IP_MTU_CTRL(i));
1462 sw_w32_mask(0xffff << ((i % 2) * 16), priv->intf_mtus[i] << ((i % 2) * 16),
1463 RTL930X_L3_IP6_MTU_CTRL(i));
1464
1465 priv->intf_mtu_count[i]++;
1466
1467 return mtu_id;
1468 }
1469
1470 /*
1471 * Creates an interface for a route by setting up the HW tables in the SoC
1472 */
1473 static int rtl930x_l3_intf_add(struct rtl838x_switch_priv *priv, struct rtl838x_l3_intf *intf)
1474 {
1475 int i, intf_id, mtu_id;
1476 // number of MTU-values < 16384
1477
1478 // Use the same IPv6 mtu as the ip4 mtu for this route if unset
1479 intf->ip6_mtu = intf->ip6_mtu ? intf->ip6_mtu : intf->ip4_mtu;
1480
1481 mtu_id = rtl930x_l3_mtu_add(priv, intf->ip4_mtu);
1482 pr_info("%s: added mtu %d with mtu-id %d\n", __func__, intf->ip4_mtu, mtu_id);
1483 if (mtu_id < 0)
1484 return -ENOSPC;
1485 intf->ip4_mtu_id = mtu_id;
1486 intf->ip6_mtu_id = mtu_id;
1487
1488 for (i = 0; i < MAX_INTERFACES; i++) {
1489 if (!priv->interfaces[i])
1490 break;
1491 }
1492 if (i >= MAX_INTERFACES) {
1493 pr_err("%s: cannot find free interface entry\n", __func__);
1494 return -EINVAL;
1495 }
1496 intf_id = i;
1497 priv->interfaces[i] = kzalloc(sizeof(struct rtl838x_l3_intf), GFP_KERNEL);
1498 if (!priv->interfaces[i]) {
1499 pr_err("%s: no memory to allocate new interface\n", __func__);
1500 return -ENOMEM;
1501 }
1502 }
1503
1504 /*
1505 * Set the destination MAC and L3 egress interface ID for a nexthop entry in the SoC's
1506 * L3_NEXTHOP table. The nexthop entry is identified by idx.
1507 * dmac_id is the reference to the L2 entry in the L2 forwarding table, special values are
1508 * 0x7ffe: TRAP2CPU
1509 * 0x7ffd: TRAP2MASTERCPU
1510 * 0x7fff: DMAC_ID_DROP
1511 */
1512 static void rtl930x_set_l3_nexthop(int idx, u16 dmac_id, u16 interface)
1513 {
1514 // Access L3_NEXTHOP table (3) via register RTL9300_TBL_1
1515 struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 3);
1516
1517 pr_info("%s: Writing to L3_NEXTHOP table, index %d, dmac_id %d, interface %d\n",
1518 __func__, idx, dmac_id, interface);
1519 sw_w32(((dmac_id & 0x7fff) << 7) | (interface & 0x7f), rtl_table_data(r, 0));
1520
1521 pr_info("%s: %08x\n", __func__, sw_r32(rtl_table_data(r,0)));
1522 rtl_table_write(r, idx);
1523 rtl_table_release(r);
1524 }
1525
1526 static void rtl930x_pie_lookup_enable(struct rtl838x_switch_priv *priv, int index)
1527 {
1528 int block = index / PIE_BLOCK_SIZE;
1529
1530 sw_w32_mask(0, BIT(block), RTL930X_PIE_BLK_LOOKUP_CTRL);
1531 }
1532
1533 /*
1534 * Reads the intermediate representation of the templated match-fields of the
1535 * PIE rule in the pie_rule structure and fills in the raw data fields in the
1536 * raw register space r[].
1537 * The register space configuration size is identical for the RTL8380/90 and RTL9300,
1538 * however the RTL9310 has 2 more registers / fields and the physical field-ids are different
1539 * on all SoCs
1540 * On the RTL9300 the mask fields are not word-aligend!
1541 */
1542 static void rtl930x_write_pie_templated(u32 r[], struct pie_rule *pr, enum template_field_id t[])
1543 {
1544 int i;
1545 enum template_field_id field_type;
1546 u16 data, data_m;
1547
1548 for (i = 0; i < N_FIXED_FIELDS; i++) {
1549 field_type = t[i];
1550 data = data_m = 0;
1551
1552 switch (field_type) {
1553 case TEMPLATE_FIELD_SPM0:
1554 data = pr->spm;
1555 data_m = pr->spm_m;
1556 break;
1557 case TEMPLATE_FIELD_SPM1:
1558 data = pr->spm >> 16;
1559 data_m = pr->spm_m >> 16;
1560 break;
1561 case TEMPLATE_FIELD_OTAG:
1562 data = pr->otag;
1563 data_m = pr->otag_m;
1564 break;
1565 case TEMPLATE_FIELD_SMAC0:
1566 data = pr->smac[4];
1567 data = (data << 8) | pr->smac[5];
1568 data_m = pr->smac_m[4];
1569 data_m = (data_m << 8) | pr->smac_m[5];
1570 break;
1571 case TEMPLATE_FIELD_SMAC1:
1572 data = pr->smac[2];
1573 data = (data << 8) | pr->smac[3];
1574 data_m = pr->smac_m[2];
1575 data_m = (data_m << 8) | pr->smac_m[3];
1576 break;
1577 case TEMPLATE_FIELD_SMAC2:
1578 data = pr->smac[0];
1579 data = (data << 8) | pr->smac[1];
1580 data_m = pr->smac_m[0];
1581 data_m = (data_m << 8) | pr->smac_m[1];
1582 break;
1583 case TEMPLATE_FIELD_DMAC0:
1584 data = pr->dmac[4];
1585 data = (data << 8) | pr->dmac[5];
1586 data_m = pr->dmac_m[4];
1587 data_m = (data_m << 8) | pr->dmac_m[5];
1588 break;
1589 case TEMPLATE_FIELD_DMAC1:
1590 data = pr->dmac[2];
1591 data = (data << 8) | pr->dmac[3];
1592 data_m = pr->dmac_m[2];
1593 data_m = (data_m << 8) | pr->dmac_m[3];
1594 break;
1595 case TEMPLATE_FIELD_DMAC2:
1596 data = pr->dmac[0];
1597 data = (data << 8) | pr->dmac[1];
1598 data_m = pr->dmac_m[0];
1599 data_m = (data_m << 8) | pr->dmac_m[1];
1600 break;
1601 case TEMPLATE_FIELD_ETHERTYPE:
1602 data = pr->ethertype;
1603 data_m = pr->ethertype_m;
1604 break;
1605 case TEMPLATE_FIELD_ITAG:
1606 data = pr->itag;
1607 data_m = pr->itag_m;
1608 break;
1609 case TEMPLATE_FIELD_SIP0:
1610 if (pr->is_ipv6) {
1611 data = pr->sip6.s6_addr16[7];
1612 data_m = pr->sip6_m.s6_addr16[7];
1613 } else {
1614 data = pr->sip;
1615 data_m = pr->sip_m;
1616 }
1617 break;
1618 case TEMPLATE_FIELD_SIP1:
1619 if (pr->is_ipv6) {
1620 data = pr->sip6.s6_addr16[6];
1621 data_m = pr->sip6_m.s6_addr16[6];
1622 } else {
1623 data = pr->sip >> 16;
1624 data_m = pr->sip_m >> 16;
1625 }
1626 break;
1627
1628 case TEMPLATE_FIELD_SIP2:
1629 case TEMPLATE_FIELD_SIP3:
1630 case TEMPLATE_FIELD_SIP4:
1631 case TEMPLATE_FIELD_SIP5:
1632 case TEMPLATE_FIELD_SIP6:
1633 case TEMPLATE_FIELD_SIP7:
1634 data = pr->sip6.s6_addr16[5 - (field_type - TEMPLATE_FIELD_SIP2)];
1635 data_m = pr->sip6_m.s6_addr16[5 - (field_type - TEMPLATE_FIELD_SIP2)];
1636 break;
1637
1638 case TEMPLATE_FIELD_DIP0:
1639 if (pr->is_ipv6) {
1640 data = pr->dip6.s6_addr16[7];
1641 data_m = pr->dip6_m.s6_addr16[7];
1642 } else {
1643 data = pr->dip;
1644 data_m = pr->dip_m;
1645 }
1646 break;
1647
1648 case TEMPLATE_FIELD_DIP1:
1649 if (pr->is_ipv6) {
1650 data = pr->dip6.s6_addr16[6];
1651 data_m = pr->dip6_m.s6_addr16[6];
1652 } else {
1653 data = pr->dip >> 16;
1654 data_m = pr->dip_m >> 16;
1655 }
1656 break;
1657
1658 case TEMPLATE_FIELD_DIP2:
1659 case TEMPLATE_FIELD_DIP3:
1660 case TEMPLATE_FIELD_DIP4:
1661 case TEMPLATE_FIELD_DIP5:
1662 case TEMPLATE_FIELD_DIP6:
1663 case TEMPLATE_FIELD_DIP7:
1664 data = pr->dip6.s6_addr16[5 - (field_type - TEMPLATE_FIELD_DIP2)];
1665 data_m = pr->dip6_m.s6_addr16[5 - (field_type - TEMPLATE_FIELD_DIP2)];
1666 break;
1667
1668 case TEMPLATE_FIELD_IP_TOS_PROTO:
1669 data = pr->tos_proto;
1670 data_m = pr->tos_proto_m;
1671 break;
1672 case TEMPLATE_FIELD_L4_SPORT:
1673 data = pr->sport;
1674 data_m = pr->sport_m;
1675 break;
1676 case TEMPLATE_FIELD_L4_DPORT:
1677 data = pr->dport;
1678 data_m = pr->dport_m;
1679 break;
1680 case TEMPLATE_FIELD_DSAP_SSAP:
1681 data = pr->dsap_ssap;
1682 data_m = pr->dsap_ssap_m;
1683 break;
1684 case TEMPLATE_FIELD_TCP_INFO:
1685 data = pr->tcp_info;
1686 data_m = pr->tcp_info_m;
1687 break;
1688 case TEMPLATE_FIELD_RANGE_CHK:
1689 pr_warn("Warning: TEMPLATE_FIELD_RANGE_CHK: not configured\n");
1690 break;
1691 default:
1692 pr_info("%s: unknown field %d\n", __func__, field_type);
1693 }
1694
1695 // On the RTL9300, the mask fields are not word aligned!
1696 if (!(i % 2)) {
1697 r[5 - i / 2] = data;
1698 r[12 - i / 2] |= ((u32)data_m << 8);
1699 } else {
1700 r[5 - i / 2] |= ((u32)data) << 16;
1701 r[12 - i / 2] |= ((u32)data_m) << 24;
1702 r[11 - i / 2] |= ((u32)data_m) >> 8;
1703 }
1704 }
1705 }
1706
1707 static void rtl930x_read_pie_fixed_fields(u32 r[], struct pie_rule *pr)
1708 {
1709 pr->stacking_port = r[6] & BIT(31);
1710 pr->spn = (r[6] >> 24) & 0x7f;
1711 pr->mgnt_vlan = r[6] & BIT(23);
1712 if (pr->phase == PHASE_IACL)
1713 pr->dmac_hit_sw = r[6] & BIT(22);
1714 else
1715 pr->content_too_deep = r[6] & BIT(22);
1716 pr->not_first_frag = r[6] & BIT(21);
1717 pr->frame_type_l4 = (r[6] >> 18) & 7;
1718 pr->frame_type = (r[6] >> 16) & 3;
1719 pr->otag_fmt = (r[6] >> 15) & 1;
1720 pr->itag_fmt = (r[6] >> 14) & 1;
1721 pr->otag_exist = (r[6] >> 13) & 1;
1722 pr->itag_exist = (r[6] >> 12) & 1;
1723 pr->frame_type_l2 = (r[6] >> 10) & 3;
1724 pr->igr_normal_port = (r[6] >> 9) & 1;
1725 pr->tid = (r[6] >> 8) & 1;
1726
1727 pr->stacking_port_m = r[12] & BIT(7);
1728 pr->spn_m = r[12] & 0x7f;
1729 pr->mgnt_vlan_m = r[13] & BIT(31);
1730 if (pr->phase == PHASE_IACL)
1731 pr->dmac_hit_sw_m = r[13] & BIT(30);
1732 else
1733 pr->content_too_deep_m = r[13] & BIT(30);
1734 pr->not_first_frag_m = r[13] & BIT(29);
1735 pr->frame_type_l4_m = (r[13] >> 26) & 7;
1736 pr->frame_type_m = (r[13] >> 24) & 3;
1737 pr->otag_fmt_m = r[13] & BIT(23);
1738 pr->itag_fmt_m = r[13] & BIT(22);
1739 pr->otag_exist_m = r[13] & BIT(21);
1740 pr->itag_exist_m = r[13] & BIT (20);
1741 pr->frame_type_l2_m = (r[13] >> 18) & 3;
1742 pr->igr_normal_port_m = r[13] & BIT(17);
1743 pr->tid_m = (r[13] >> 16) & 1;
1744
1745 pr->valid = r[13] & BIT(15);
1746 pr->cond_not = r[13] & BIT(14);
1747 pr->cond_and1 = r[13] & BIT(13);
1748 pr->cond_and2 = r[13] & BIT(12);
1749 }
1750
1751 static void rtl930x_write_pie_fixed_fields(u32 r[], struct pie_rule *pr)
1752 {
1753 r[6] = pr->stacking_port ? BIT(31) : 0;
1754 r[6] |= ((u32) (pr->spn & 0x7f)) << 24;
1755 r[6] |= pr->mgnt_vlan ? BIT(23) : 0;
1756 if (pr->phase == PHASE_IACL)
1757 r[6] |= pr->dmac_hit_sw ? BIT(22) : 0;
1758 else
1759 r[6] |= pr->content_too_deep ? BIT(22) : 0;
1760 r[6] |= pr->not_first_frag ? BIT(21) : 0;
1761 r[6] |= ((u32) (pr->frame_type_l4 & 0x7)) << 18;
1762 r[6] |= ((u32) (pr->frame_type & 0x3)) << 16;
1763 r[6] |= pr->otag_fmt ? BIT(15) : 0;
1764 r[6] |= pr->itag_fmt ? BIT(14) : 0;
1765 r[6] |= pr->otag_exist ? BIT(13) : 0;
1766 r[6] |= pr->itag_exist ? BIT(12) : 0;
1767 r[6] |= ((u32) (pr->frame_type_l2 & 0x3)) << 10;
1768 r[6] |= pr->igr_normal_port ? BIT(9) : 0;
1769 r[6] |= ((u32) (pr->tid & 0x1)) << 8;
1770
1771 r[12] |= pr->stacking_port_m ? BIT(7) : 0;
1772 r[12] |= (u32) (pr->spn_m & 0x7f);
1773 r[13] |= pr->mgnt_vlan_m ? BIT(31) : 0;
1774 if (pr->phase == PHASE_IACL)
1775 r[13] |= pr->dmac_hit_sw_m ? BIT(30) : 0;
1776 else
1777 r[13] |= pr->content_too_deep_m ? BIT(30) : 0;
1778 r[13] |= pr->not_first_frag_m ? BIT(29) : 0;
1779 r[13] |= ((u32) (pr->frame_type_l4_m & 0x7)) << 26;
1780 r[13] |= ((u32) (pr->frame_type_m & 0x3)) << 24;
1781 r[13] |= pr->otag_fmt_m ? BIT(23) : 0;
1782 r[13] |= pr->itag_fmt_m ? BIT(22) : 0;
1783 r[13] |= pr->otag_exist_m ? BIT(21) : 0;
1784 r[13] |= pr->itag_exist_m ? BIT(20) : 0;
1785 r[13] |= ((u32) (pr->frame_type_l2_m & 0x3)) << 18;
1786 r[13] |= pr->igr_normal_port_m ? BIT(17) : 0;
1787 r[13] |= ((u32) (pr->tid_m & 0x1)) << 16;
1788
1789 r[13] |= pr->valid ? BIT(15) : 0;
1790 r[13] |= pr->cond_not ? BIT(14) : 0;
1791 r[13] |= pr->cond_and1 ? BIT(13) : 0;
1792 r[13] |= pr->cond_and2 ? BIT(12) : 0;
1793 }
1794
1795 static void rtl930x_write_pie_action(u32 r[], struct pie_rule *pr)
1796 {
1797 // Either drop or forward
1798 if (pr->drop) {
1799 r[14] |= BIT(24) | BIT(25) | BIT(26); // Do Green, Yellow and Red drops
1800 // Actually DROP, not PERMIT in Green / Yellow / Red
1801 r[14] |= BIT(23) | BIT(22) | BIT(20);
1802 } else {
1803 r[14] |= pr->fwd_sel ? BIT(27) : 0;
1804 r[14] |= pr->fwd_act << 18;
1805 r[14] |= BIT(14); // We overwrite any drop
1806 }
1807 if (pr->phase == PHASE_VACL)
1808 r[14] |= pr->fwd_sa_lrn ? BIT(15) : 0;
1809 r[13] |= pr->bypass_sel ? BIT(5) : 0;
1810 r[13] |= pr->nopri_sel ? BIT(4) : 0;
1811 r[13] |= pr->tagst_sel ? BIT(3) : 0;
1812 r[13] |= pr->ovid_sel ? BIT(1) : 0;
1813 r[14] |= pr->ivid_sel ? BIT(31) : 0;
1814 r[14] |= pr->meter_sel ? BIT(30) : 0;
1815 r[14] |= pr->mir_sel ? BIT(29) : 0;
1816 r[14] |= pr->log_sel ? BIT(28) : 0;
1817
1818 r[14] |= ((u32)(pr->fwd_data & 0x3fff)) << 3;
1819 r[15] |= pr->log_octets ? BIT(31) : 0;
1820 r[15] |= (u32)(pr->meter_data) << 23;
1821
1822 r[15] |= ((u32)(pr->ivid_act) << 21) & 0x3;
1823 r[15] |= ((u32)(pr->ivid_data) << 9) & 0xfff;
1824 r[16] |= ((u32)(pr->ovid_act) << 30) & 0x3;
1825 r[16] |= ((u32)(pr->ovid_data) & 0xfff) << 16;
1826 r[16] |= (pr->mir_data & 0x3) << 6;
1827 r[17] |= ((u32)(pr->tagst_data) & 0xf) << 28;
1828 r[17] |= ((u32)(pr->nopri_data) & 0x7) << 25;
1829 r[17] |= pr->bypass_ibc_sc ? BIT(16) : 0;
1830 }
1831
1832 void rtl930x_pie_rule_dump_raw(u32 r[])
1833 {
1834 pr_info("Raw IACL table entry:\n");
1835 pr_info("r 0 - 7: %08x %08x %08x %08x %08x %08x %08x %08x\n",
1836 r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7]);
1837 pr_info("r 8 - 15: %08x %08x %08x %08x %08x %08x %08x %08x\n",
1838 r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15]);
1839 pr_info("r 16 - 18: %08x %08x %08x\n", r[16], r[17], r[18]);
1840 pr_info("Match : %08x %08x %08x %08x %08x %08x\n", r[0], r[1], r[2], r[3], r[4], r[5]);
1841 pr_info("Fixed : %06x\n", r[6] >> 8);
1842 pr_info("Match M: %08x %08x %08x %08x %08x %08x\n",
1843 (r[6] << 24) | (r[7] >> 8), (r[7] << 24) | (r[8] >> 8), (r[8] << 24) | (r[9] >> 8),
1844 (r[9] << 24) | (r[10] >> 8), (r[10] << 24) | (r[11] >> 8),
1845 (r[11] << 24) | (r[12] >> 8));
1846 pr_info("R[13]: %08x\n", r[13]);
1847 pr_info("Fixed M: %06x\n", ((r[12] << 16) | (r[13] >> 16)) & 0xffffff);
1848 pr_info("Valid / not / and1 / and2 : %1x\n", (r[13] >> 12) & 0xf);
1849 pr_info("r 13-16: %08x %08x %08x %08x\n", r[13], r[14], r[15], r[16]);
1850 }
1851
1852 static int rtl930x_pie_rule_write(struct rtl838x_switch_priv *priv, int idx, struct pie_rule *pr)
1853 {
1854 // Access IACL table (2) via register 0
1855 struct table_reg *q = rtl_table_get(RTL9300_TBL_0, 2);
1856 u32 r[19];
1857 int i;
1858 int block = idx / PIE_BLOCK_SIZE;
1859 u32 t_select = sw_r32(RTL930X_PIE_BLK_TMPLTE_CTRL(block));
1860
1861 pr_debug("%s: %d, t_select: %08x\n", __func__, idx, t_select);
1862
1863 for (i = 0; i < 19; i++)
1864 r[i] = 0;
1865
1866 if (!pr->valid) {
1867 rtl_table_write(q, idx);
1868 rtl_table_release(q);
1869 return 0;
1870 }
1871 rtl930x_write_pie_fixed_fields(r, pr);
1872
1873 pr_debug("%s: template %d\n", __func__, (t_select >> (pr->tid * 4)) & 0xf);
1874 rtl930x_write_pie_templated(r, pr, fixed_templates[(t_select >> (pr->tid * 4)) & 0xf]);
1875
1876 rtl930x_write_pie_action(r, pr);
1877
1878 // rtl930x_pie_rule_dump_raw(r);
1879
1880 for (i = 0; i < 19; i++)
1881 sw_w32(r[i], rtl_table_data(q, i));
1882
1883 rtl_table_write(q, idx);
1884 rtl_table_release(q);
1885
1886 return 0;
1887 }
1888
1889 static bool rtl930x_pie_templ_has(int t, enum template_field_id field_type)
1890 {
1891 int i;
1892 enum template_field_id ft;
1893
1894 for (i = 0; i < N_FIXED_FIELDS; i++) {
1895 ft = fixed_templates[t][i];
1896 if (field_type == ft)
1897 return true;
1898 }
1899
1900 return false;
1901 }
1902
1903 /*
1904 * Verify that the rule pr is compatible with a given template t in block block
1905 * Note that this function is SoC specific since the values of e.g. TEMPLATE_FIELD_SIP0
1906 * depend on the SoC
1907 */
1908 static int rtl930x_pie_verify_template(struct rtl838x_switch_priv *priv,
1909 struct pie_rule *pr, int t, int block)
1910 {
1911 int i;
1912
1913 if (!pr->is_ipv6 && pr->sip_m && !rtl930x_pie_templ_has(t, TEMPLATE_FIELD_SIP0))
1914 return -1;
1915
1916 if (!pr->is_ipv6 && pr->dip_m && !rtl930x_pie_templ_has(t, TEMPLATE_FIELD_DIP0))
1917 return -1;
1918
1919 if (pr->is_ipv6) {
1920 if ((pr->sip6_m.s6_addr32[0] || pr->sip6_m.s6_addr32[1]
1921 || pr->sip6_m.s6_addr32[2] || pr->sip6_m.s6_addr32[3])
1922 && !rtl930x_pie_templ_has(t, TEMPLATE_FIELD_SIP2))
1923 return -1;
1924 if ((pr->dip6_m.s6_addr32[0] || pr->dip6_m.s6_addr32[1]
1925 || pr->dip6_m.s6_addr32[2] || pr->dip6_m.s6_addr32[3])
1926 && !rtl930x_pie_templ_has(t, TEMPLATE_FIELD_DIP2))
1927 return -1;
1928 }
1929
1930 if (ether_addr_to_u64(pr->smac) && !rtl930x_pie_templ_has(t, TEMPLATE_FIELD_SMAC0))
1931 return -1;
1932
1933 if (ether_addr_to_u64(pr->dmac) && !rtl930x_pie_templ_has(t, TEMPLATE_FIELD_DMAC0))
1934 return -1;
1935
1936 // TODO: Check more
1937
1938 i = find_first_zero_bit(&priv->pie_use_bm[block * 4], PIE_BLOCK_SIZE);
1939
1940 if (i >= PIE_BLOCK_SIZE)
1941 return -1;
1942
1943 return i + PIE_BLOCK_SIZE * block;
1944 }
1945
1946 static int rtl930x_pie_rule_add(struct rtl838x_switch_priv *priv, struct pie_rule *pr)
1947 {
1948 int idx, block, j, t;
1949 int min_block = 0;
1950 int max_block = priv->n_pie_blocks / 2;
1951
1952 if (pr->is_egress) {
1953 min_block = max_block;
1954 max_block = priv->n_pie_blocks;
1955 }
1956 pr_debug("In %s\n", __func__);
1957
1958 mutex_lock(&priv->pie_mutex);
1959
1960 for (block = min_block; block < max_block; block++) {
1961 for (j = 0; j < 2; j++) {
1962 t = (sw_r32(RTL930X_PIE_BLK_TMPLTE_CTRL(block)) >> (j * 4)) & 0xf;
1963 pr_debug("Testing block %d, template %d, template id %d\n", block, j, t);
1964 pr_debug("%s: %08x\n",
1965 __func__, sw_r32(RTL930X_PIE_BLK_TMPLTE_CTRL(block)));
1966 idx = rtl930x_pie_verify_template(priv, pr, t, block);
1967 if (idx >= 0)
1968 break;
1969 }
1970 if (j < 2)
1971 break;
1972 }
1973
1974 if (block >= priv->n_pie_blocks) {
1975 mutex_unlock(&priv->pie_mutex);
1976 return -EOPNOTSUPP;
1977 }
1978
1979 pr_debug("Using block: %d, index %d, template-id %d\n", block, idx, j);
1980 set_bit(idx, priv->pie_use_bm);
1981
1982 pr->valid = true;
1983 pr->tid = j; // Mapped to template number
1984 pr->tid_m = 0x1;
1985 pr->id = idx;
1986
1987 rtl930x_pie_lookup_enable(priv, idx);
1988 rtl930x_pie_rule_write(priv, idx, pr);
1989
1990 mutex_unlock(&priv->pie_mutex);
1991 return 0;
1992 }
1993
1994 /*
1995 * Delete a range of Packet Inspection Engine rules
1996 */
1997 static int rtl930x_pie_rule_del(struct rtl838x_switch_priv *priv, int index_from, int index_to)
1998 {
1999 u32 v = (index_from << 1)| (index_to << 12 ) | BIT(0);
2000
2001 pr_debug("%s: from %d to %d\n", __func__, index_from, index_to);
2002 mutex_lock(&priv->reg_mutex);
2003
2004 // Write from-to and execute bit into control register
2005 sw_w32(v, RTL930X_PIE_CLR_CTRL);
2006
2007 // Wait until command has completed
2008 do {
2009 } while (sw_r32(RTL930X_PIE_CLR_CTRL) & BIT(0));
2010
2011 mutex_unlock(&priv->reg_mutex);
2012 return 0;
2013 }
2014
2015 static void rtl930x_pie_rule_rm(struct rtl838x_switch_priv *priv, struct pie_rule *pr)
2016 {
2017 int idx = pr->id;
2018
2019 rtl930x_pie_rule_del(priv, idx, idx);
2020 clear_bit(idx, priv->pie_use_bm);
2021 }
2022
2023 static void rtl930x_pie_init(struct rtl838x_switch_priv *priv)
2024 {
2025 int i;
2026 u32 template_selectors;
2027
2028 mutex_init(&priv->pie_mutex);
2029
2030 pr_info("%s\n", __func__);
2031 // Enable ACL lookup on all ports, including CPU_PORT
2032 for (i = 0; i <= priv->cpu_port; i++)
2033 sw_w32(1, RTL930X_ACL_PORT_LOOKUP_CTRL(i));
2034
2035 // Include IPG in metering
2036 sw_w32_mask(0, 1, RTL930X_METER_GLB_CTRL);
2037
2038 // Delete all present rules, block size is 128 on all SoC families
2039 rtl930x_pie_rule_del(priv, 0, priv->n_pie_blocks * 128 - 1);
2040
2041 // Assign blocks 0-7 to VACL phase (bit = 0), blocks 8-15 to IACL (bit = 1)
2042 sw_w32(0xff00, RTL930X_PIE_BLK_PHASE_CTRL);
2043
2044 // Enable predefined templates 0, 1 for first quarter of all blocks
2045 template_selectors = 0 | (1 << 4);
2046 for (i = 0; i < priv->n_pie_blocks / 4; i++)
2047 sw_w32(template_selectors, RTL930X_PIE_BLK_TMPLTE_CTRL(i));
2048
2049 // Enable predefined templates 2, 3 for second quarter of all blocks
2050 template_selectors = 2 | (3 << 4);
2051 for (i = priv->n_pie_blocks / 4; i < priv->n_pie_blocks / 2; i++)
2052 sw_w32(template_selectors, RTL930X_PIE_BLK_TMPLTE_CTRL(i));
2053
2054 // Enable predefined templates 0, 1 for third half of all blocks
2055 template_selectors = 0 | (1 << 4);
2056 for (i = priv->n_pie_blocks / 2; i < priv->n_pie_blocks * 3 / 4; i++)
2057 sw_w32(template_selectors, RTL930X_PIE_BLK_TMPLTE_CTRL(i));
2058
2059 // Enable predefined templates 2, 3 for fourth quater of all blocks
2060 template_selectors = 2 | (3 << 4);
2061 for (i = priv->n_pie_blocks * 3 / 4; i < priv->n_pie_blocks; i++)
2062 sw_w32(template_selectors, RTL930X_PIE_BLK_TMPLTE_CTRL(i));
2063
2064 }
2065
2066 /*
2067 * Sets up an egress interface for L3 actions
2068 * Actions for ip4/6_icmp_redirect, ip4/6_pbr_icmp_redirect are:
2069 * 0: FORWARD, 1: DROP, 2: TRAP2CPU, 3: COPY2CPU, 4: TRAP2MASTERCPU 5: COPY2MASTERCPU
2070 * 6: HARDDROP
2071 * idx is the index in the HW interface table: idx < 0x80
2072 */
2073 static void rtl930x_set_l3_egress_intf(int idx, struct rtl838x_l3_intf *intf)
2074 {
2075 u32 u, v;
2076 // Read L3_EGR_INTF table (4) via register RTL9300_TBL_1
2077 struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 4);
2078
2079 // The table has 2 registers
2080 u = (intf->vid & 0xfff) << 9;
2081 u |= (intf->smac_idx & 0x3f) << 3;
2082 u |= (intf->ip4_mtu_id & 0x7);
2083
2084 v = (intf->ip6_mtu_id & 0x7) << 28;
2085 v |= (intf->ttl_scope & 0xff) << 20;
2086 v |= (intf->hl_scope & 0xff) << 12;
2087 v |= (intf->ip4_icmp_redirect & 0x7) << 9;
2088 v |= (intf->ip6_icmp_redirect & 0x7)<< 6;
2089 v |= (intf->ip4_pbr_icmp_redirect & 0x7) << 3;
2090 v |= (intf->ip6_pbr_icmp_redirect & 0x7);
2091
2092 sw_w32(u, rtl_table_data(r, 0));
2093 sw_w32(v, rtl_table_data(r, 1));
2094
2095 pr_info("%s writing to index %d: %08x %08x\n", __func__, idx, u, v);
2096 rtl_table_write(r, idx & 0x7f);
2097 rtl_table_release(r);
2098 }
2099
2100 /*
2101 * Reads a MAC entry for L3 termination as entry point for routing
2102 * from the hardware table
2103 * idx is the index into the L3_ROUTER_MAC table
2104 */
2105 static void rtl930x_get_l3_router_mac(u32 idx, struct rtl93xx_rt_mac *m)
2106 {
2107 u32 v, w;
2108 // Read L3_ROUTER_MAC table (0) via register RTL9300_TBL_1
2109 struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 0);
2110
2111 rtl_table_read(r, idx);
2112 // The table has a size of 7 registers, 64 entries
2113 v = sw_r32(rtl_table_data(r, 0));
2114 w = sw_r32(rtl_table_data(r, 3));
2115 m->valid = !!(v & BIT(20));
2116 if (!m->valid)
2117 goto out;
2118
2119 m->p_type = !!(v & BIT(19));
2120 m->p_id = (v >> 13) & 0x3f; // trunk id of port
2121 m->vid = v & 0xfff;
2122 m->vid_mask = w & 0xfff;
2123 m->action = sw_r32(rtl_table_data(r, 6)) & 0x7;
2124 m->mac_mask = ((((u64)sw_r32(rtl_table_data(r, 5))) << 32) & 0xffffffffffffULL)
2125 | (sw_r32(rtl_table_data(r, 4)));
2126 m->mac = ((((u64)sw_r32(rtl_table_data(r, 1))) << 32) & 0xffffffffffffULL)
2127 | (sw_r32(rtl_table_data(r, 2)));
2128 // Bits L3_INTF and BMSK_L3_INTF are 0
2129
2130 out:
2131 rtl_table_release(r);
2132 }
2133
2134 /*
2135 * Writes a MAC entry for L3 termination as entry point for routing
2136 * into the hardware table
2137 * idx is the index into the L3_ROUTER_MAC table
2138 */
2139 static void rtl930x_set_l3_router_mac(u32 idx, struct rtl93xx_rt_mac *m)
2140 {
2141 u32 v, w;
2142 // Read L3_ROUTER_MAC table (0) via register RTL9300_TBL_1
2143 struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 0);
2144
2145 // The table has a size of 7 registers, 64 entries
2146 v = BIT(20); // mac entry valid, port type is 0: individual
2147 v |= (m->p_id & 0x3f) << 13;
2148 v |= (m->vid & 0xfff); // Set the interface_id to the vlan id
2149
2150 w = m->vid_mask;
2151 w |= (m->p_id_mask & 0x3f) << 13;
2152
2153 sw_w32(v, rtl_table_data(r, 0));
2154 sw_w32(w, rtl_table_data(r, 3));
2155
2156 // Set MAC address, L3_INTF (bit 12 in register 1) needs to be 0
2157 sw_w32((u32)(m->mac), rtl_table_data(r, 2));
2158 sw_w32(m->mac >> 32, rtl_table_data(r, 1));
2159
2160 // Set MAC address mask, BMSK_L3_INTF (bit 12 in register 5) needs to be 0
2161 sw_w32((u32)(m->mac_mask >> 32), rtl_table_data(r, 4));
2162 sw_w32((u32)m->mac_mask, rtl_table_data(r, 5));
2163
2164 sw_w32(m->action & 0x7, rtl_table_data(r, 6));
2165
2166 pr_debug("%s writing index %d: %08x %08x %08x %08x %08x %08x %08x\n", __func__, idx,
2167 sw_r32(rtl_table_data(r, 0)), sw_r32(rtl_table_data(r, 1)), sw_r32(rtl_table_data(r, 2)),
2168 sw_r32(rtl_table_data(r, 3)), sw_r32(rtl_table_data(r, 4)), sw_r32(rtl_table_data(r, 5)),
2169 sw_r32(rtl_table_data(r, 6))
2170 );
2171 rtl_table_write(r, idx);
2172 rtl_table_release(r);
2173 }
2174
2175 /*
2176 * Get the Destination-MAC of an L3 egress interface or the Source MAC for routed packets
2177 * from the SoC's L3_EGR_INTF_MAC table
2178 * Indexes 0-2047 are DMACs, 2048+ are SMACs
2179 */
2180 static u64 rtl930x_get_l3_egress_mac(u32 idx)
2181 {
2182 u64 mac;
2183 // Read L3_EGR_INTF_MAC table (2) via register RTL9300_TBL_2
2184 struct table_reg *r = rtl_table_get(RTL9300_TBL_2, 2);
2185
2186 rtl_table_read(r, idx);
2187 // The table has a size of 2 registers
2188 mac = sw_r32(rtl_table_data(r, 0));
2189 mac <<= 32;
2190 mac |= sw_r32(rtl_table_data(r, 1));
2191 rtl_table_release(r);
2192
2193 return mac;
2194 }
2195 /*
2196 * Set the Destination-MAC of a route or the Source MAC of an L3 egress interface
2197 * in the SoC's L3_EGR_INTF_MAC table
2198 * Indexes 0-2047 are DMACs, 2048+ are SMACs
2199 */
2200 static void rtl930x_set_l3_egress_mac(u32 idx, u64 mac)
2201 {
2202 // Access L3_EGR_INTF_MAC table (2) via register RTL9300_TBL_2
2203 struct table_reg *r = rtl_table_get(RTL9300_TBL_2, 2);
2204
2205 // The table has a size of 2 registers
2206 sw_w32(mac >> 32, rtl_table_data(r, 0));
2207 sw_w32(mac, rtl_table_data(r, 1));
2208
2209 pr_debug("%s: setting index %d to %016llx\n", __func__, idx, mac);
2210 rtl_table_write(r, idx);
2211 rtl_table_release(r);
2212 }
2213
2214 /*
2215 * Configure L3 routing settings of the device:
2216 * - MTUs
2217 * - Egress interface
2218 * - The router's MAC address on which routed packets are expected
2219 * - MAC addresses used as source macs of routed packets
2220 */
2221 int rtl930x_l3_setup(struct rtl838x_switch_priv *priv)
2222 {
2223 int i;
2224
2225 // Setup MTU with id 0 for default interface
2226 for (i = 0; i < MAX_INTF_MTUS; i++)
2227 priv->intf_mtu_count[i] = priv->intf_mtus[i] = 0;
2228
2229 priv->intf_mtu_count[0] = 0; // Needs to stay forever
2230 priv->intf_mtus[0] = DEFAULT_MTU;
2231 sw_w32_mask(0xffff, DEFAULT_MTU, RTL930X_L3_IP_MTU_CTRL(0));
2232 sw_w32_mask(0xffff, DEFAULT_MTU, RTL930X_L3_IP6_MTU_CTRL(0));
2233 priv->intf_mtus[1] = DEFAULT_MTU;
2234 sw_w32_mask(0xffff0000, DEFAULT_MTU << 16, RTL930X_L3_IP_MTU_CTRL(0));
2235 sw_w32_mask(0xffff0000, DEFAULT_MTU << 16, RTL930X_L3_IP6_MTU_CTRL(0));
2236
2237 sw_w32_mask(0xffff, DEFAULT_MTU, RTL930X_L3_IP_MTU_CTRL(1));
2238 sw_w32_mask(0xffff, DEFAULT_MTU, RTL930X_L3_IP6_MTU_CTRL(1));
2239 sw_w32_mask(0xffff0000, DEFAULT_MTU << 16, RTL930X_L3_IP_MTU_CTRL(1));
2240 sw_w32_mask(0xffff0000, DEFAULT_MTU << 16, RTL930X_L3_IP6_MTU_CTRL(1));
2241
2242 // Clear all source port MACs
2243 for (i = 0; i < MAX_SMACS; i++)
2244 rtl930x_set_l3_egress_mac(L3_EGRESS_DMACS + i, 0ULL);
2245
2246 // Configure the default L3 hash algorithm
2247 sw_w32_mask(BIT(2), 0, RTL930X_L3_HOST_TBL_CTRL); // Algorithm selection 0 = 0
2248 sw_w32_mask(0, BIT(3), RTL930X_L3_HOST_TBL_CTRL); // Algorithm selection 1 = 1
2249
2250 pr_info("L3_IPUC_ROUTE_CTRL %08x, IPMC_ROUTE %08x, IP6UC_ROUTE %08x, IP6MC_ROUTE %08x\n",
2251 sw_r32(RTL930X_L3_IPUC_ROUTE_CTRL), sw_r32(RTL930X_L3_IPMC_ROUTE_CTRL),
2252 sw_r32(RTL930X_L3_IP6UC_ROUTE_CTRL), sw_r32(RTL930X_L3_IP6MC_ROUTE_CTRL));
2253 sw_w32_mask(0, 1, RTL930X_L3_IPUC_ROUTE_CTRL);
2254 sw_w32_mask(0, 1, RTL930X_L3_IP6UC_ROUTE_CTRL);
2255 sw_w32_mask(0, 1, RTL930X_L3_IPMC_ROUTE_CTRL);
2256 sw_w32_mask(0, 1, RTL930X_L3_IP6MC_ROUTE_CTRL);
2257
2258 sw_w32(0x00002001, RTL930X_L3_IPUC_ROUTE_CTRL);
2259 sw_w32(0x00014581, RTL930X_L3_IP6UC_ROUTE_CTRL);
2260 sw_w32(0x00000501, RTL930X_L3_IPMC_ROUTE_CTRL);
2261 sw_w32(0x00012881, RTL930X_L3_IP6MC_ROUTE_CTRL);
2262
2263 pr_info("L3_IPUC_ROUTE_CTRL %08x, IPMC_ROUTE %08x, IP6UC_ROUTE %08x, IP6MC_ROUTE %08x\n",
2264 sw_r32(RTL930X_L3_IPUC_ROUTE_CTRL), sw_r32(RTL930X_L3_IPMC_ROUTE_CTRL),
2265 sw_r32(RTL930X_L3_IP6UC_ROUTE_CTRL), sw_r32(RTL930X_L3_IP6MC_ROUTE_CTRL));
2266
2267 // Trap non-ip traffic to the CPU-port (e.g. ARP so we stay reachable)
2268 sw_w32_mask(0x3 << 8, 0x1 << 8, RTL930X_L3_IP_ROUTE_CTRL);
2269 pr_info("L3_IP_ROUTE_CTRL %08x\n", sw_r32(RTL930X_L3_IP_ROUTE_CTRL));
2270
2271 // PORT_ISO_RESTRICT_ROUTE_CTRL ?
2272
2273 // Do not use prefix route 0 because of HW limitations
2274 set_bit(0, priv->route_use_bm);
2275
2276 return 0;
2277 }
2278
2279 static u32 rtl930x_packet_cntr_read(int counter)
2280 {
2281 u32 v;
2282
2283 // Read LOG table (3) via register RTL9300_TBL_0
2284 struct table_reg *r = rtl_table_get(RTL9300_TBL_0, 3);
2285
2286 pr_debug("In %s, id %d\n", __func__, counter);
2287 rtl_table_read(r, counter / 2);
2288
2289 pr_debug("Registers: %08x %08x\n",
2290 sw_r32(rtl_table_data(r, 0)), sw_r32(rtl_table_data(r, 1)));
2291 // The table has a size of 2 registers
2292 if (counter % 2)
2293 v = sw_r32(rtl_table_data(r, 0));
2294 else
2295 v = sw_r32(rtl_table_data(r, 1));
2296
2297 rtl_table_release(r);
2298
2299 return v;
2300 }
2301
2302 static void rtl930x_packet_cntr_clear(int counter)
2303 {
2304 // Access LOG table (3) via register RTL9300_TBL_0
2305 struct table_reg *r = rtl_table_get(RTL9300_TBL_0, 3);
2306
2307 pr_info("In %s, id %d\n", __func__, counter);
2308 // The table has a size of 2 registers
2309 if (counter % 2)
2310 sw_w32(0, rtl_table_data(r, 0));
2311 else
2312 sw_w32(0, rtl_table_data(r, 1));
2313
2314 rtl_table_write(r, counter / 2);
2315
2316 rtl_table_release(r);
2317 }
2318
2319 void rtl930x_vlan_port_pvidmode_set(int port, enum pbvlan_type type, enum pbvlan_mode mode)
2320 {
2321 if (type == PBVLAN_TYPE_INNER)
2322 sw_w32_mask(0x3, mode, RTL930X_VLAN_PORT_PB_VLAN + (port << 2));
2323 else
2324 sw_w32_mask(0x3 << 14, mode << 14 ,RTL930X_VLAN_PORT_PB_VLAN + (port << 2));
2325 }
2326
2327 void rtl930x_vlan_port_pvid_set(int port, enum pbvlan_type type, int pvid)
2328 {
2329 if (type == PBVLAN_TYPE_INNER)
2330 sw_w32_mask(0xfff << 2, pvid << 2, RTL930X_VLAN_PORT_PB_VLAN + (port << 2));
2331 else
2332 sw_w32_mask(0xfff << 16, pvid << 16, RTL930X_VLAN_PORT_PB_VLAN + (port << 2));
2333 }
2334
2335 static int rtl930x_set_ageing_time(unsigned long msec)
2336 {
2337 int t = sw_r32(RTL930X_L2_AGE_CTRL);
2338
2339 t &= 0x1FFFFF;
2340 t = (t * 7) / 10;
2341 pr_debug("L2 AGING time: %d sec\n", t);
2342
2343 t = (msec / 100 + 6) / 7;
2344 t = t > 0x1FFFFF ? 0x1FFFFF : t;
2345 sw_w32_mask(0x1FFFFF, t, RTL930X_L2_AGE_CTRL);
2346 pr_debug("Dynamic aging for ports: %x\n", sw_r32(RTL930X_L2_PORT_AGE_CTRL));
2347
2348 return 0;
2349 }
2350
2351 static void rtl930x_set_igr_filter(int port, enum igr_filter state)
2352 {
2353 sw_w32_mask(0x3 << ((port & 0xf)<<1), state << ((port & 0xf)<<1),
2354 RTL930X_VLAN_PORT_IGR_FLTR + (((port >> 4) << 2)));
2355 }
2356
2357 static void rtl930x_set_egr_filter(int port, enum egr_filter state)
2358 {
2359 sw_w32_mask(0x1 << (port % 0x1D), state << (port % 0x1D),
2360 RTL930X_VLAN_PORT_EGR_FLTR + (((port / 29) << 2)));
2361 }
2362
2363 void rtl930x_set_distribution_algorithm(int group, int algoidx, u32 algomsk)
2364 {
2365 u32 l3shift = 0;
2366 u32 newmask = 0;
2367
2368 /* TODO: for now we set algoidx to 0 */
2369 algoidx = 0;
2370 if (algomsk & TRUNK_DISTRIBUTION_ALGO_SIP_BIT) {
2371 l3shift = 4;
2372 newmask |= TRUNK_DISTRIBUTION_ALGO_L3_SIP_BIT;
2373 }
2374 if (algomsk & TRUNK_DISTRIBUTION_ALGO_DIP_BIT) {
2375 l3shift = 4;
2376 newmask |= TRUNK_DISTRIBUTION_ALGO_L3_DIP_BIT;
2377 }
2378 if (algomsk & TRUNK_DISTRIBUTION_ALGO_SRC_L4PORT_BIT) {
2379 l3shift = 4;
2380 newmask |= TRUNK_DISTRIBUTION_ALGO_L3_SRC_L4PORT_BIT;
2381 }
2382 if (algomsk & TRUNK_DISTRIBUTION_ALGO_SRC_L4PORT_BIT) {
2383 l3shift = 4;
2384 newmask |= TRUNK_DISTRIBUTION_ALGO_L3_SRC_L4PORT_BIT;
2385 }
2386
2387 if (l3shift == 4) {
2388 if (algomsk & TRUNK_DISTRIBUTION_ALGO_SMAC_BIT)
2389 newmask |= TRUNK_DISTRIBUTION_ALGO_L3_SMAC_BIT;
2390
2391 if (algomsk & TRUNK_DISTRIBUTION_ALGO_DMAC_BIT)
2392 newmask |= TRUNK_DISTRIBUTION_ALGO_L3_DMAC_BIT;
2393 } else {
2394 if (algomsk & TRUNK_DISTRIBUTION_ALGO_SMAC_BIT)
2395 newmask |= TRUNK_DISTRIBUTION_ALGO_L2_SMAC_BIT;
2396 if (algomsk & TRUNK_DISTRIBUTION_ALGO_DMAC_BIT)
2397 newmask |= TRUNK_DISTRIBUTION_ALGO_L2_DMAC_BIT;
2398 }
2399
2400 sw_w32(newmask << l3shift, RTL930X_TRK_HASH_CTRL + (algoidx << 2));
2401 }
2402
2403 const struct rtl838x_reg rtl930x_reg = {
2404 .mask_port_reg_be = rtl838x_mask_port_reg,
2405 .set_port_reg_be = rtl838x_set_port_reg,
2406 .get_port_reg_be = rtl838x_get_port_reg,
2407 .mask_port_reg_le = rtl838x_mask_port_reg,
2408 .set_port_reg_le = rtl838x_set_port_reg,
2409 .get_port_reg_le = rtl838x_get_port_reg,
2410 .stat_port_rst = RTL930X_STAT_PORT_RST,
2411 .stat_rst = RTL930X_STAT_RST,
2412 .stat_port_std_mib = RTL930X_STAT_PORT_MIB_CNTR,
2413 .traffic_enable = rtl930x_traffic_enable,
2414 .traffic_disable = rtl930x_traffic_disable,
2415 .traffic_get = rtl930x_traffic_get,
2416 .traffic_set = rtl930x_traffic_set,
2417 .l2_ctrl_0 = RTL930X_L2_CTRL,
2418 .l2_ctrl_1 = RTL930X_L2_AGE_CTRL,
2419 .l2_port_aging_out = RTL930X_L2_PORT_AGE_CTRL,
2420 .set_ageing_time = rtl930x_set_ageing_time,
2421 .smi_poll_ctrl = RTL930X_SMI_POLL_CTRL, // TODO: Difference to RTL9300_SMI_PRVTE_POLLING_CTRL
2422 .l2_tbl_flush_ctrl = RTL930X_L2_TBL_FLUSH_CTRL,
2423 .exec_tbl0_cmd = rtl930x_exec_tbl0_cmd,
2424 .exec_tbl1_cmd = rtl930x_exec_tbl1_cmd,
2425 .tbl_access_data_0 = rtl930x_tbl_access_data_0,
2426 .isr_glb_src = RTL930X_ISR_GLB,
2427 .isr_port_link_sts_chg = RTL930X_ISR_PORT_LINK_STS_CHG,
2428 .imr_port_link_sts_chg = RTL930X_IMR_PORT_LINK_STS_CHG,
2429 .imr_glb = RTL930X_IMR_GLB,
2430 .vlan_tables_read = rtl930x_vlan_tables_read,
2431 .vlan_set_tagged = rtl930x_vlan_set_tagged,
2432 .vlan_set_untagged = rtl930x_vlan_set_untagged,
2433 .vlan_profile_dump = rtl930x_vlan_profile_dump,
2434 .vlan_profile_setup = rtl930x_vlan_profile_setup,
2435 .vlan_fwd_on_inner = rtl930x_vlan_fwd_on_inner,
2436 .set_vlan_igr_filter = rtl930x_set_igr_filter,
2437 .set_vlan_egr_filter = rtl930x_set_egr_filter,
2438 .stp_get = rtl930x_stp_get,
2439 .stp_set = rtl930x_stp_set,
2440 .mac_force_mode_ctrl = rtl930x_mac_force_mode_ctrl,
2441 .mac_port_ctrl = rtl930x_mac_port_ctrl,
2442 .l2_port_new_salrn = rtl930x_l2_port_new_salrn,
2443 .l2_port_new_sa_fwd = rtl930x_l2_port_new_sa_fwd,
2444 .mir_ctrl = RTL930X_MIR_CTRL,
2445 .mir_dpm = RTL930X_MIR_DPM_CTRL,
2446 .mir_spm = RTL930X_MIR_SPM_CTRL,
2447 .mac_link_sts = RTL930X_MAC_LINK_STS,
2448 .mac_link_dup_sts = RTL930X_MAC_LINK_DUP_STS,
2449 .mac_link_spd_sts = rtl930x_mac_link_spd_sts,
2450 .mac_rx_pause_sts = RTL930X_MAC_RX_PAUSE_STS,
2451 .mac_tx_pause_sts = RTL930X_MAC_TX_PAUSE_STS,
2452 .read_l2_entry_using_hash = rtl930x_read_l2_entry_using_hash,
2453 .write_l2_entry_using_hash = rtl930x_write_l2_entry_using_hash,
2454 .read_cam = rtl930x_read_cam,
2455 .write_cam = rtl930x_write_cam,
2456 .vlan_port_tag_sts_ctrl = RTL930X_VLAN_PORT_TAG_STS_CTRL,
2457 .vlan_port_pvidmode_set = rtl930x_vlan_port_pvidmode_set,
2458 .vlan_port_pvid_set = rtl930x_vlan_port_pvid_set,
2459 .trk_mbr_ctr = rtl930x_trk_mbr_ctr,
2460 .rma_bpdu_fld_pmask = RTL930X_RMA_BPDU_FLD_PMSK,
2461 .init_eee = rtl930x_init_eee,
2462 .port_eee_set = rtl930x_port_eee_set,
2463 .eee_port_ability = rtl930x_eee_port_ability,
2464 .l2_hash_seed = rtl930x_l2_hash_seed,
2465 .l2_hash_key = rtl930x_l2_hash_key,
2466 .read_mcast_pmask = rtl930x_read_mcast_pmask,
2467 .write_mcast_pmask = rtl930x_write_mcast_pmask,
2468 .pie_init = rtl930x_pie_init,
2469 .pie_rule_write = rtl930x_pie_rule_write,
2470 .pie_rule_add = rtl930x_pie_rule_add,
2471 .pie_rule_rm = rtl930x_pie_rule_rm,
2472 .l2_learning_setup = rtl930x_l2_learning_setup,
2473 .packet_cntr_read = rtl930x_packet_cntr_read,
2474 .packet_cntr_clear = rtl930x_packet_cntr_clear,
2475 .route_read = rtl930x_route_read,
2476 .route_write = rtl930x_route_write,
2477 .host_route_write = rtl930x_host_route_write,
2478 .l3_setup = rtl930x_l3_setup,
2479 .set_l3_nexthop = rtl930x_set_l3_nexthop,
2480 .get_l3_nexthop = rtl930x_get_l3_nexthop,
2481 .get_l3_egress_mac = rtl930x_get_l3_egress_mac,
2482 .set_l3_egress_mac = rtl930x_set_l3_egress_mac,
2483 .find_l3_slot = rtl930x_find_l3_slot,
2484 .route_lookup_hw = rtl930x_route_lookup_hw,
2485 .get_l3_router_mac = rtl930x_get_l3_router_mac,
2486 .set_l3_router_mac = rtl930x_set_l3_router_mac,
2487 .set_l3_egress_intf = rtl930x_set_l3_egress_intf,
2488 .set_distribution_algorithm = rtl930x_set_distribution_algorithm,
2489 };