2 * Copyright 2014 - 2015 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
6 * Driver for the Vitesse VSC9953 L2 Switch
10 #include <asm/fsl_serdes.h>
12 #include <fsl_memac.h>
19 static struct vsc9953_info vsc9953_l2sw = {
20 .port[0] = VSC9953_PORT_INFO_INITIALIZER(0),
21 .port[1] = VSC9953_PORT_INFO_INITIALIZER(1),
22 .port[2] = VSC9953_PORT_INFO_INITIALIZER(2),
23 .port[3] = VSC9953_PORT_INFO_INITIALIZER(3),
24 .port[4] = VSC9953_PORT_INFO_INITIALIZER(4),
25 .port[5] = VSC9953_PORT_INFO_INITIALIZER(5),
26 .port[6] = VSC9953_PORT_INFO_INITIALIZER(6),
27 .port[7] = VSC9953_PORT_INFO_INITIALIZER(7),
28 .port[8] = VSC9953_PORT_INFO_INITIALIZER(8),
29 .port[9] = VSC9953_PORT_INFO_INITIALIZER(9),
32 void vsc9953_port_info_set_mdio(int port_no, struct mii_dev *bus)
34 if (!VSC9953_PORT_CHECK(port_no))
37 vsc9953_l2sw.port[port_no].bus = bus;
40 void vsc9953_port_info_set_phy_address(int port_no, int address)
42 if (!VSC9953_PORT_CHECK(port_no))
45 vsc9953_l2sw.port[port_no].phyaddr = address;
48 void vsc9953_port_info_set_phy_int(int port_no, phy_interface_t phy_int)
50 if (!VSC9953_PORT_CHECK(port_no))
53 vsc9953_l2sw.port[port_no].enet_if = phy_int;
56 void vsc9953_port_enable(int port_no)
58 if (!VSC9953_PORT_CHECK(port_no))
61 vsc9953_l2sw.port[port_no].enabled = 1;
64 void vsc9953_port_disable(int port_no)
66 if (!VSC9953_PORT_CHECK(port_no))
69 vsc9953_l2sw.port[port_no].enabled = 0;
72 static void vsc9953_mdio_write(struct vsc9953_mii_mng *phyregs, int port_addr,
73 int regnum, int value)
77 out_le32(&phyregs->miimcmd, (0x1 << 31) | ((port_addr & 0x1f) << 25) |
78 ((regnum & 0x1f) << 20) | ((value & 0xffff) << 4) |
82 while ((in_le32(&phyregs->miimstatus) & 0x8) && --timeout)
86 debug("Timeout waiting for MDIO write\n");
89 static int vsc9953_mdio_read(struct vsc9953_mii_mng *phyregs, int port_addr,
95 while ((in_le32(&phyregs->miimstatus) & MIIMIND_OPR_PEND) && --timeout)
98 debug("Timeout waiting for MDIO operation to finish\n");
102 /* Put the address of the phy, and the register
105 out_le32(&phyregs->miimcmd, (0x1 << 31) | ((port_addr & 0x1f) << 25) |
106 ((regnum & 0x1f) << 20) | ((value & 0xffff) << 4) |
110 /* Wait for the the indication that the read is done */
111 while ((in_le32(&phyregs->miimstatus) & 0x8) && --timeout)
114 debug("Timeout waiting for MDIO read\n");
116 /* Grab the value read from the PHY */
117 value = in_le32(&phyregs->miimdata);
119 if ((value & 0x00030000) == 0)
120 return value & 0x0000ffff;
125 static int init_phy(struct eth_device *dev)
127 struct vsc9953_port_info *l2sw_port = dev->priv;
128 struct phy_device *phydev = NULL;
133 phydev = phy_connect(l2sw_port->bus, l2sw_port->phyaddr, dev,
136 printf("Failed to connect\n");
140 phydev->supported &= SUPPORTED_10baseT_Half |
141 SUPPORTED_10baseT_Full |
142 SUPPORTED_100baseT_Half |
143 SUPPORTED_100baseT_Full |
144 SUPPORTED_1000baseT_Full;
145 phydev->advertising = phydev->supported;
147 l2sw_port->phydev = phydev;
155 static int vsc9953_port_init(int port_no)
157 struct eth_device *dev;
159 /* Internal ports never have a PHY */
160 if (VSC9953_INTERNAL_PORT_CHECK(port_no))
163 /* alloc eth device */
164 dev = (struct eth_device *)calloc(1, sizeof(struct eth_device));
168 sprintf(dev->name, "SW@PORT%d", port_no);
169 dev->priv = &vsc9953_l2sw.port[port_no];
183 static int vsc9953_vlan_table_poll_idle(void)
185 struct vsc9953_analyzer *l2ana_reg;
188 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
192 while (((in_le32(&l2ana_reg->ana_tables.vlan_access) &
193 VSC9953_VLAN_CMD_MASK) != VSC9953_VLAN_CMD_IDLE) && --timeout)
196 return timeout ? 0 : -EBUSY;
199 #ifdef CONFIG_CMD_ETHSW
200 /* Add/remove a port to/from a VLAN */
201 static void vsc9953_vlan_table_membership_set(int vid, u32 port_no, u8 add)
204 struct vsc9953_analyzer *l2ana_reg;
206 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
209 if (vsc9953_vlan_table_poll_idle() < 0) {
210 debug("VLAN table timeout\n");
214 val = in_le32(&l2ana_reg->ana_tables.vlan_tidx);
215 val = bitfield_replace_by_mask(val, VSC9953_ANA_TBL_VID_MASK, vid);
216 out_le32(&l2ana_reg->ana_tables.vlan_tidx, val);
218 clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
219 VSC9953_VLAN_CMD_MASK, VSC9953_VLAN_CMD_READ);
221 if (vsc9953_vlan_table_poll_idle() < 0) {
222 debug("VLAN table timeout\n");
226 val = in_le32(&l2ana_reg->ana_tables.vlan_tidx);
227 val = bitfield_replace_by_mask(val, VSC9953_ANA_TBL_VID_MASK, vid);
228 out_le32(&l2ana_reg->ana_tables.vlan_tidx, val);
230 val = in_le32(&l2ana_reg->ana_tables.vlan_access);
232 val = bitfield_replace_by_mask(val, VSC9953_VLAN_CMD_MASK,
233 VSC9953_VLAN_CMD_WRITE) &
234 ~(bitfield_replace_by_mask(0, VSC9953_VLAN_PORT_MASK,
238 val = bitfield_replace_by_mask(val, VSC9953_VLAN_CMD_MASK,
239 VSC9953_VLAN_CMD_WRITE) |
240 bitfield_replace_by_mask(0, VSC9953_VLAN_PORT_MASK,
243 out_le32(&l2ana_reg->ana_tables.vlan_access, val);
245 /* wait for VLAN table command to flush */
246 if (vsc9953_vlan_table_poll_idle() < 0) {
247 debug("VLAN table timeout\n");
252 /* show VLAN membership for a port */
253 static void vsc9953_vlan_membership_show(int port_no)
256 struct vsc9953_analyzer *l2ana_reg;
259 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
262 printf("Port %d VLAN membership: ", port_no);
264 for (vid = 0; vid < VSC9953_MAX_VLAN; vid++) {
265 if (vsc9953_vlan_table_poll_idle() < 0) {
266 debug("VLAN table timeout\n");
270 val = in_le32(&l2ana_reg->ana_tables.vlan_tidx);
271 val = bitfield_replace_by_mask(val, VSC9953_ANA_TBL_VID_MASK,
273 out_le32(&l2ana_reg->ana_tables.vlan_tidx, val);
275 clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
276 VSC9953_VLAN_CMD_MASK, VSC9953_VLAN_CMD_READ);
278 if (vsc9953_vlan_table_poll_idle() < 0) {
279 debug("VLAN table timeout\n");
283 val = in_le32(&l2ana_reg->ana_tables.vlan_access);
285 if (bitfield_extract_by_mask(val, VSC9953_VLAN_PORT_MASK) &
293 /* vlan table set/clear all membership of vid */
294 static void vsc9953_vlan_table_membership_all_set(int vid, int set_member)
297 struct vsc9953_analyzer *l2ana_reg;
299 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
302 if (vsc9953_vlan_table_poll_idle() < 0) {
303 debug("VLAN table timeout\n");
307 /* read current vlan configuration */
308 val = in_le32(&l2ana_reg->ana_tables.vlan_tidx);
309 out_le32(&l2ana_reg->ana_tables.vlan_tidx,
310 bitfield_replace_by_mask(val, VSC9953_ANA_TBL_VID_MASK, vid));
312 clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
313 VSC9953_VLAN_CMD_MASK, VSC9953_VLAN_CMD_READ);
315 if (vsc9953_vlan_table_poll_idle() < 0) {
316 debug("VLAN table timeout\n");
320 val = in_le32(&l2ana_reg->ana_tables.vlan_tidx);
321 out_le32(&l2ana_reg->ana_tables.vlan_tidx,
322 bitfield_replace_by_mask(val, VSC9953_ANA_TBL_VID_MASK, vid));
324 clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
325 VSC9953_VLAN_PORT_MASK | VSC9953_VLAN_CMD_MASK,
326 VSC9953_VLAN_CMD_WRITE |
327 (set_member ? VSC9953_VLAN_PORT_MASK : 0));
330 #ifdef CONFIG_CMD_ETHSW
331 /* Get PVID of a VSC9953 port */
332 static int vsc9953_port_vlan_pvid_get(int port_nr, int *pvid)
335 struct vsc9953_analyzer *l2ana_reg;
337 /* Administrative down */
338 if (vsc9953_l2sw.port[port_nr].enabled) {
339 printf("Port %d is administrative down\n", port_nr);
343 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
346 /* Get ingress PVID */
347 val = in_le32(&l2ana_reg->port[port_nr].vlan_cfg);
348 *pvid = bitfield_extract_by_mask(val, VSC9953_VLAN_CFG_VID_MASK);
354 /* Set PVID for a VSC9953 port */
355 static void vsc9953_port_vlan_pvid_set(int port_no, int pvid)
358 struct vsc9953_analyzer *l2ana_reg;
359 struct vsc9953_rew_reg *l2rew_reg;
361 /* Administrative down */
362 if (!vsc9953_l2sw.port[port_no].enabled) {
363 printf("Port %d is administrative down\n", port_no);
367 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
369 l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
372 /* Set PVID on ingress */
373 val = in_le32(&l2ana_reg->port[port_no].vlan_cfg);
374 val = bitfield_replace_by_mask(val, VSC9953_VLAN_CFG_VID_MASK, pvid);
375 out_le32(&l2ana_reg->port[port_no].vlan_cfg, val);
377 /* Set PVID on egress */
378 val = in_le32(&l2rew_reg->port[port_no].port_vlan_cfg);
379 val = bitfield_replace_by_mask(val, VSC9953_PORT_VLAN_CFG_VID_MASK,
381 out_le32(&l2rew_reg->port[port_no].port_vlan_cfg, val);
384 static void vsc9953_port_all_vlan_pvid_set(int pvid)
388 for (i = 0; i < VSC9953_MAX_PORTS; i++)
389 vsc9953_port_vlan_pvid_set(i, pvid);
392 /* Enable/disable vlan aware of a VSC9953 port */
393 static void vsc9953_port_vlan_aware_set(int port_no, int enabled)
395 struct vsc9953_analyzer *l2ana_reg;
397 /* Administrative down */
398 if (!vsc9953_l2sw.port[port_no].enabled) {
399 printf("Port %d is administrative down\n", port_no);
403 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
407 setbits_le32(&l2ana_reg->port[port_no].vlan_cfg,
408 VSC9953_VLAN_CFG_AWARE_ENA);
410 clrbits_le32(&l2ana_reg->port[port_no].vlan_cfg,
411 VSC9953_VLAN_CFG_AWARE_ENA);
414 /* Set all VSC9953 ports' vlan aware */
415 static void vsc9953_port_all_vlan_aware_set(int enabled)
419 for (i = 0; i < VSC9953_MAX_PORTS; i++)
420 vsc9953_port_vlan_aware_set(i, enabled);
423 /* Enable/disable vlan pop count of a VSC9953 port */
424 static void vsc9953_port_vlan_popcnt_set(int port_no, int popcnt)
427 struct vsc9953_analyzer *l2ana_reg;
429 /* Administrative down */
430 if (!vsc9953_l2sw.port[port_no].enabled) {
431 printf("Port %d is administrative down\n", port_no);
435 if (popcnt > 3 || popcnt < 0) {
436 printf("Invalid pop count value: %d\n", port_no);
440 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
443 val = in_le32(&l2ana_reg->port[port_no].vlan_cfg);
444 val = bitfield_replace_by_mask(val, VSC9953_VLAN_CFG_POP_CNT_MASK,
446 out_le32(&l2ana_reg->port[port_no].vlan_cfg, val);
449 /* Set all VSC9953 ports' pop count */
450 static void vsc9953_port_all_vlan_poncnt_set(int popcnt)
454 for (i = 0; i < VSC9953_MAX_PORTS; i++)
455 vsc9953_port_vlan_popcnt_set(i, popcnt);
458 /* Enable/disable learning for frames dropped due to ingress filtering */
459 static void vsc9953_vlan_ingr_fltr_learn_drop(int enable)
461 struct vsc9953_analyzer *l2ana_reg;
463 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
467 setbits_le32(&l2ana_reg->ana.adv_learn, VSC9953_VLAN_CHK);
469 clrbits_le32(&l2ana_reg->ana.adv_learn, VSC9953_VLAN_CHK);
472 /* Egress untag modes of a VSC9953 port */
473 enum egress_untag_mode {
474 EGRESS_UNTAG_ALL = 0,
475 EGRESS_UNTAG_PVID_AND_ZERO,
480 #ifdef CONFIG_CMD_ETHSW
481 /* Get egress tagging configuration for a VSC9953 port */
482 static int vsc9953_port_vlan_egr_untag_get(int port_no,
483 enum egress_untag_mode *mode)
486 struct vsc9953_rew_reg *l2rew_reg;
488 /* Administrative down */
489 if (!vsc9953_l2sw.port[port_no].enabled) {
490 printf("Port %d is administrative down\n", port_no);
494 l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
497 val = in_le32(&l2rew_reg->port[port_no].port_tag_cfg);
499 switch (val & VSC9953_TAG_CFG_MASK) {
500 case VSC9953_TAG_CFG_NONE:
501 *mode = EGRESS_UNTAG_ALL;
503 case VSC9953_TAG_CFG_ALL_BUT_PVID_ZERO:
504 *mode = EGRESS_UNTAG_PVID_AND_ZERO;
506 case VSC9953_TAG_CFG_ALL_BUT_ZERO:
507 *mode = EGRESS_UNTAG_ZERO;
509 case VSC9953_TAG_CFG_ALL:
510 *mode = EGRESS_UNTAG_NONE;
513 printf("Unknown egress tagging configuration for port %d\n",
519 /* Show egress tagging configuration for a VSC9953 port */
520 static void vsc9953_port_vlan_egr_untag_show(int port_no)
522 enum egress_untag_mode mode;
524 if (vsc9953_port_vlan_egr_untag_get(port_no, &mode)) {
525 printf("%7d\t%17s\n", port_no, "-");
529 printf("%7d\t", port_no);
531 case EGRESS_UNTAG_ALL:
532 printf("%17s\n", "all");
534 case EGRESS_UNTAG_NONE:
535 printf("%17s\n", "none");
537 case EGRESS_UNTAG_PVID_AND_ZERO:
538 printf("%17s\n", "PVID and 0");
540 case EGRESS_UNTAG_ZERO:
541 printf("%17s\n", "0");
544 printf("%17s\n", "-");
549 static void vsc9953_port_vlan_egr_untag_set(int port_no,
550 enum egress_untag_mode mode)
552 struct vsc9953_rew_reg *l2rew_reg;
554 /* Administrative down */
555 if (!vsc9953_l2sw.port[port_no].enabled) {
556 printf("Port %d is administrative down\n", port_no);
560 l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
564 case EGRESS_UNTAG_ALL:
565 clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
566 VSC9953_TAG_CFG_MASK, VSC9953_TAG_CFG_NONE);
568 case EGRESS_UNTAG_PVID_AND_ZERO:
569 clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
570 VSC9953_TAG_CFG_MASK,
571 VSC9953_TAG_CFG_ALL_BUT_PVID_ZERO);
573 case EGRESS_UNTAG_ZERO:
574 clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
575 VSC9953_TAG_CFG_MASK,
576 VSC9953_TAG_CFG_ALL_BUT_ZERO);
578 case EGRESS_UNTAG_NONE:
579 clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
580 VSC9953_TAG_CFG_MASK, VSC9953_TAG_CFG_ALL);
583 printf("Unknown untag mode for port %d\n", port_no);
587 static void vsc9953_port_all_vlan_egress_untagged_set(
588 enum egress_untag_mode mode)
592 for (i = 0; i < VSC9953_MAX_PORTS; i++)
593 vsc9953_port_vlan_egr_untag_set(i, mode);
596 static int vsc9953_autoage_time_set(int age_period)
599 struct vsc9953_analyzer *l2ana_reg;
601 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
604 if (age_period < 0 || age_period > VSC9953_AUTOAGE_PERIOD_MASK)
607 autoage = bitfield_replace_by_mask(in_le32(&l2ana_reg->ana.auto_age),
608 VSC9953_AUTOAGE_PERIOD_MASK,
610 out_le32(&l2ana_reg->ana.auto_age, autoage);
615 #ifdef CONFIG_CMD_ETHSW
617 /* Enable/disable status of a VSC9953 port */
618 static void vsc9953_port_status_set(int port_no, u8 enabled)
620 struct vsc9953_qsys_reg *l2qsys_reg;
622 /* Administrative down */
623 if (!vsc9953_l2sw.port[port_no].enabled)
626 l2qsys_reg = (struct vsc9953_qsys_reg *)(VSC9953_OFFSET +
627 VSC9953_QSYS_OFFSET);
630 setbits_le32(&l2qsys_reg->sys.switch_port_mode[port_no],
633 clrbits_le32(&l2qsys_reg->sys.switch_port_mode[port_no],
637 /* Start autonegotiation for a VSC9953 PHY */
638 static void vsc9953_phy_autoneg(int port_no)
640 if (!vsc9953_l2sw.port[port_no].phydev)
643 if (vsc9953_l2sw.port[port_no].phydev->drv->startup(
644 vsc9953_l2sw.port[port_no].phydev))
645 printf("Failed to start PHY for port %d\n", port_no);
648 /* Print a VSC9953 port's configuration */
649 static void vsc9953_port_config_show(int port_no)
656 struct vsc9953_qsys_reg *l2qsys_reg;
658 l2qsys_reg = (struct vsc9953_qsys_reg *)(VSC9953_OFFSET +
659 VSC9953_QSYS_OFFSET);
661 val = in_le32(&l2qsys_reg->sys.switch_port_mode[port_no]);
662 enabled = vsc9953_l2sw.port[port_no].enabled &&
663 (val & VSC9953_PORT_ENA);
665 /* internal ports (8 and 9) are fixed */
666 if (VSC9953_INTERNAL_PORT_CHECK(port_no)) {
669 duplex = DUPLEX_FULL;
671 if (vsc9953_l2sw.port[port_no].phydev) {
672 link = vsc9953_l2sw.port[port_no].phydev->link;
673 speed = vsc9953_l2sw.port[port_no].phydev->speed;
674 duplex = vsc9953_l2sw.port[port_no].phydev->duplex;
682 printf("%8d ", port_no);
683 printf("%8s ", enabled == 1 ? "enabled" : "disabled");
684 printf("%8s ", link == 1 ? "up" : "down");
694 printf("%8d ", 1000);
697 printf("%8d ", 2500);
700 printf("%8d ", 10000);
706 printf("%8s\n", duplex == DUPLEX_FULL ? "full" : "half");
709 /* Show VSC9953 ports' statistics */
710 static void vsc9953_port_statistics_show(int port_no)
714 struct vsc9953_system_reg *l2sys_reg;
716 /* Administrative down */
717 if (!vsc9953_l2sw.port[port_no].enabled) {
718 printf("Port %d is administrative down\n", port_no);
722 l2sys_reg = (struct vsc9953_system_reg *)(VSC9953_OFFSET +
725 printf("Statistics for L2 Switch port %d:\n", port_no);
727 /* Set counter view for our port */
728 out_le32(&l2sys_reg->sys.stat_cfg, port_no);
730 #define VSC9953_STATS_PRINTF "%-15s %10u"
732 /* Get number of Rx and Tx frames */
733 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_short) +
734 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_frag) +
735 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_jabber) +
736 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_long) +
737 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_64) +
738 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_65_127) +
739 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_128_255) +
740 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_256_511) +
741 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_512_1023) +
742 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_1024_1526) +
743 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_jumbo);
744 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_64) +
745 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_65_127) +
746 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_128_255) +
747 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_256_511) +
748 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_512_1023) +
749 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_1024_1526) +
750 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_jumbo);
751 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
752 "Rx frames:", rx_val, "Tx frames:", tx_val);
754 /* Get number of Rx and Tx bytes */
755 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_oct);
756 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_oct);
757 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
758 "Rx bytes:", rx_val, "Tx bytes:", tx_val);
760 /* Get number of Rx frames received ok and Tx frames sent ok */
761 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_0) +
762 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_1) +
763 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_2) +
764 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_3) +
765 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_4) +
766 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_5) +
767 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_6) +
768 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_7) +
769 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_0) +
770 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_1) +
771 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_2) +
772 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_3) +
773 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_4) +
774 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_5) +
775 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_6) +
776 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_7);
777 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_64) +
778 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_65_127) +
779 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_128_255) +
780 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_256_511) +
781 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_512_1023) +
782 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_1024_1526) +
783 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_jumbo);
784 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
785 "Rx frames ok:", rx_val, "Tx frames ok:", tx_val);
787 /* Get number of Rx and Tx unicast frames */
788 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_uc);
789 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_uc);
790 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
791 "Rx unicast:", rx_val, "Tx unicast:", tx_val);
793 /* Get number of Rx and Tx broadcast frames */
794 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_bc);
795 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_bc);
796 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
797 "Rx broadcast:", rx_val, "Tx broadcast:", tx_val);
799 /* Get number of Rx and Tx frames of 64B */
800 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_64);
801 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_64);
802 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
803 "Rx 64B:", rx_val, "Tx 64B:", tx_val);
805 /* Get number of Rx and Tx frames with sizes between 65B and 127B */
806 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_65_127);
807 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_65_127);
808 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
809 "Rx 65B-127B:", rx_val, "Tx 65B-127B:", tx_val);
811 /* Get number of Rx and Tx frames with sizes between 128B and 255B */
812 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_128_255);
813 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_128_255);
814 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
815 "Rx 128B-255B:", rx_val, "Tx 128B-255B:", tx_val);
817 /* Get number of Rx and Tx frames with sizes between 256B and 511B */
818 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_256_511);
819 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_256_511);
820 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
821 "Rx 256B-511B:", rx_val, "Tx 256B-511B:", tx_val);
823 /* Get number of Rx and Tx frames with sizes between 512B and 1023B */
824 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_512_1023);
825 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_512_1023);
826 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
827 "Rx 512B-1023B:", rx_val, "Tx 512B-1023B:", tx_val);
829 /* Get number of Rx and Tx frames with sizes between 1024B and 1526B */
830 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_1024_1526);
831 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_1024_1526);
832 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
833 "Rx 1024B-1526B:", rx_val, "Tx 1024B-1526B:", tx_val);
835 /* Get number of Rx and Tx jumbo frames */
836 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_jumbo);
837 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_jumbo);
838 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
839 "Rx jumbo:", rx_val, "Tx jumbo:", tx_val);
841 /* Get number of Rx and Tx dropped frames */
842 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_cat_drop) +
843 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_tail) +
844 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_0) +
845 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_1) +
846 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_2) +
847 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_3) +
848 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_4) +
849 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_5) +
850 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_6) +
851 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_7) +
852 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_0) +
853 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_1) +
854 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_2) +
855 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_3) +
856 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_4) +
857 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_5) +
858 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_6) +
859 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_7);
860 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_drop) +
861 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_aged);
862 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
863 "Rx drops:", rx_val, "Tx drops:", tx_val);
866 * Get number of Rx frames with CRC or alignment errors
867 * and number of detected Tx collisions
869 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_crc);
870 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_col);
871 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
872 "Rx CRC&align:", rx_val, "Tx coll:", tx_val);
875 * Get number of Rx undersized frames and
876 * number of Tx aged frames
878 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_short);
879 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_aged);
880 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
881 "Rx undersize:", rx_val, "Tx aged:", tx_val);
883 /* Get number of Rx oversized frames */
884 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_long);
885 printf(VSC9953_STATS_PRINTF"\n", "Rx oversized:", rx_val);
887 /* Get number of Rx fragmented frames */
888 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_frag);
889 printf(VSC9953_STATS_PRINTF"\n", "Rx fragments:", rx_val);
891 /* Get number of Rx jabber errors */
892 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_jabber);
893 printf(VSC9953_STATS_PRINTF"\n", "Rx jabbers:", rx_val);
896 * Get number of Rx frames filtered due to classification rules or
897 * no destination ports
899 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_cat_drop) +
900 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_local);
901 printf(VSC9953_STATS_PRINTF"\n", "Rx filtered:", rx_val);
906 /* Clear statistics for a VSC9953 port */
907 static void vsc9953_port_statistics_clear(int port_no)
909 struct vsc9953_system_reg *l2sys_reg;
911 /* Administrative down */
912 if (!vsc9953_l2sw.port[port_no].enabled) {
913 printf("Port %d is administrative down\n", port_no);
917 l2sys_reg = (struct vsc9953_system_reg *)(VSC9953_OFFSET +
920 /* Clear all counter groups for our ports */
921 out_le32(&l2sys_reg->sys.stat_cfg, port_no |
922 VSC9953_STAT_CLEAR_RX | VSC9953_STAT_CLEAR_TX |
923 VSC9953_STAT_CLEAR_DR);
926 enum port_learn_mode {
931 /* Set learning configuration for a VSC9953 port */
932 static void vsc9953_port_learn_mode_set(int port_no, enum port_learn_mode mode)
934 struct vsc9953_analyzer *l2ana_reg;
936 /* Administrative down */
937 if (!vsc9953_l2sw.port[port_no].enabled) {
938 printf("Port %d is administrative down\n", port_no);
942 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
946 case PORT_LEARN_NONE:
947 clrbits_le32(&l2ana_reg->port[port_no].port_cfg,
948 VSC9953_PORT_CFG_LEARN_DROP |
949 VSC9953_PORT_CFG_LEARN_CPU |
950 VSC9953_PORT_CFG_LEARN_AUTO |
951 VSC9953_PORT_CFG_LEARN_ENA);
953 case PORT_LEARN_AUTO:
954 clrsetbits_le32(&l2ana_reg->port[port_no].port_cfg,
955 VSC9953_PORT_CFG_LEARN_DROP |
956 VSC9953_PORT_CFG_LEARN_CPU,
957 VSC9953_PORT_CFG_LEARN_ENA |
958 VSC9953_PORT_CFG_LEARN_AUTO);
961 printf("Unknown learn mode for port %d\n", port_no);
965 /* Get learning configuration for a VSC9953 port */
966 static int vsc9953_port_learn_mode_get(int port_no, enum port_learn_mode *mode)
969 struct vsc9953_analyzer *l2ana_reg;
971 /* Administrative down */
972 if (!vsc9953_l2sw.port[port_no].enabled) {
973 printf("Port %d is administrative down\n", port_no);
977 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
980 /* For now we only support HW learning (auto) and no learning */
981 val = in_le32(&l2ana_reg->port[port_no].port_cfg);
982 if ((val & (VSC9953_PORT_CFG_LEARN_ENA |
983 VSC9953_PORT_CFG_LEARN_AUTO)) ==
984 (VSC9953_PORT_CFG_LEARN_ENA | VSC9953_PORT_CFG_LEARN_AUTO))
985 *mode = PORT_LEARN_AUTO;
987 *mode = PORT_LEARN_NONE;
992 /* wait for FDB to become available */
993 static int vsc9953_mac_table_poll_idle(void)
995 struct vsc9953_analyzer *l2ana_reg;
998 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1002 while (((in_le32(&l2ana_reg->ana_tables.mac_access) &
1003 VSC9953_MAC_CMD_MASK) !=
1004 VSC9953_MAC_CMD_IDLE) && --timeout)
1007 return timeout ? 0 : -EBUSY;
1010 /* enum describing available commands for the MAC table */
1011 enum mac_table_cmd {
1021 /* Issues a command to the FDB table */
1022 static int vsc9953_mac_table_cmd(enum mac_table_cmd cmd)
1024 struct vsc9953_analyzer *l2ana_reg;
1026 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1027 VSC9953_ANA_OFFSET);
1030 case MAC_TABLE_READ:
1031 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1032 VSC9953_MAC_CMD_MASK | VSC9953_MAC_CMD_VALID,
1033 VSC9953_MAC_CMD_READ);
1035 case MAC_TABLE_LOOKUP:
1036 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1037 VSC9953_MAC_CMD_MASK, VSC9953_MAC_CMD_READ |
1038 VSC9953_MAC_CMD_VALID);
1040 case MAC_TABLE_WRITE:
1041 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1042 VSC9953_MAC_CMD_MASK |
1043 VSC9953_MAC_ENTRYTYPE_MASK,
1044 VSC9953_MAC_CMD_WRITE |
1045 VSC9953_MAC_ENTRYTYPE_LOCKED);
1047 case MAC_TABLE_LEARN:
1048 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1049 VSC9953_MAC_CMD_MASK |
1050 VSC9953_MAC_ENTRYTYPE_MASK,
1051 VSC9953_MAC_CMD_LEARN |
1052 VSC9953_MAC_ENTRYTYPE_LOCKED |
1053 VSC9953_MAC_CMD_VALID);
1055 case MAC_TABLE_FORGET:
1056 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1057 VSC9953_MAC_CMD_MASK |
1058 VSC9953_MAC_ENTRYTYPE_MASK,
1059 VSC9953_MAC_CMD_FORGET);
1061 case MAC_TABLE_GET_NEXT:
1062 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1063 VSC9953_MAC_CMD_MASK |
1064 VSC9953_MAC_ENTRYTYPE_MASK,
1065 VSC9953_MAC_CMD_NEXT);
1068 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1069 VSC9953_MAC_CMD_MASK |
1070 VSC9953_MAC_ENTRYTYPE_MASK,
1071 VSC9953_MAC_CMD_AGE);
1074 printf("Unknown MAC table command\n");
1077 if (vsc9953_mac_table_poll_idle() < 0) {
1078 debug("MAC table timeout\n");
1085 /* show the FDB entries that correspond to a port and a VLAN */
1086 static void vsc9953_mac_table_show(int port_no, int vid)
1088 int rc[VSC9953_MAX_PORTS];
1089 enum port_learn_mode mode[VSC9953_MAX_PORTS];
1096 struct vsc9953_analyzer *l2ana_reg;
1098 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1099 VSC9953_ANA_OFFSET);
1101 /* disable auto learning */
1102 if (port_no == ETHSW_CMD_PORT_ALL) {
1103 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1104 rc[i] = vsc9953_port_learn_mode_get(i, &mode[i]);
1105 if (!rc[i] && mode[i] != PORT_LEARN_NONE)
1106 vsc9953_port_learn_mode_set(i, PORT_LEARN_NONE);
1109 rc[port_no] = vsc9953_port_learn_mode_get(port_no,
1111 if (!rc[port_no] && mode[port_no] != PORT_LEARN_NONE)
1112 vsc9953_port_learn_mode_set(port_no, PORT_LEARN_NONE);
1115 /* write port and vid to get selected FDB entries */
1116 val = in_le32(&l2ana_reg->ana.anag_efil);
1117 if (port_no != ETHSW_CMD_PORT_ALL) {
1118 val = bitfield_replace_by_mask(val, VSC9953_AGE_PORT_MASK,
1119 port_no) | VSC9953_AGE_PORT_EN;
1121 if (vid != ETHSW_CMD_VLAN_ALL) {
1122 val = bitfield_replace_by_mask(val, VSC9953_AGE_VID_MASK,
1123 vid) | VSC9953_AGE_VID_EN;
1125 out_le32(&l2ana_reg->ana.anag_efil, val);
1127 /* set MAC and VLAN to 0 to look from beginning */
1128 clrbits_le32(&l2ana_reg->ana_tables.mach_data,
1129 VSC9953_MAC_VID_MASK | VSC9953_MAC_MACH_MASK);
1130 out_le32(&l2ana_reg->ana_tables.macl_data, 0);
1133 printf("%10s %17s %5s %4s\n", "EntryType", "MAC", "PORT", "VID");
1135 if (vsc9953_mac_table_cmd(MAC_TABLE_GET_NEXT) < 0) {
1136 debug("GET NEXT MAC table command failed\n");
1140 val = in_le32(&l2ana_reg->ana_tables.mac_access);
1142 /* get out when an invalid entry is found */
1143 if (!(val & VSC9953_MAC_CMD_VALID))
1146 switch (val & VSC9953_MAC_ENTRYTYPE_MASK) {
1147 case VSC9953_MAC_ENTRYTYPE_NORMAL:
1148 printf("%10s ", "Dynamic");
1150 case VSC9953_MAC_ENTRYTYPE_LOCKED:
1151 printf("%10s ", "Static");
1153 case VSC9953_MAC_ENTRYTYPE_IPV4MCAST:
1154 printf("%10s ", "IPv4 Mcast");
1156 case VSC9953_MAC_ENTRYTYPE_IPV6MCAST:
1157 printf("%10s ", "IPv6 Mcast");
1160 printf("%10s ", "Unknown");
1163 dest_indx = bitfield_extract_by_mask(val,
1164 VSC9953_MAC_DESTIDX_MASK);
1166 val = in_le32(&l2ana_reg->ana_tables.mach_data);
1167 vlan = bitfield_extract_by_mask(val, VSC9953_MAC_VID_MASK);
1168 mach = bitfield_extract_by_mask(val, VSC9953_MAC_MACH_MASK);
1169 macl = in_le32(&l2ana_reg->ana_tables.macl_data);
1171 printf("%02x:%02x:%02x:%02x:%02x:%02x ", (mach >> 8) & 0xff,
1172 mach & 0xff, (macl >> 24) & 0xff, (macl >> 16) & 0xff,
1173 (macl >> 8) & 0xff, macl & 0xff);
1174 printf("%5d ", dest_indx);
1175 printf("%4d\n", vlan);
1178 /* set learning mode to previous value */
1179 if (port_no == ETHSW_CMD_PORT_ALL) {
1180 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1181 if (!rc[i] && mode[i] != PORT_LEARN_NONE)
1182 vsc9953_port_learn_mode_set(i, mode[i]);
1185 /* If administrative down, skip */
1186 if (!rc[port_no] && mode[port_no] != PORT_LEARN_NONE)
1187 vsc9953_port_learn_mode_set(port_no, mode[port_no]);
1190 /* reset FDB port and VLAN FDB selection */
1191 clrbits_le32(&l2ana_reg->ana.anag_efil, VSC9953_AGE_PORT_EN |
1192 VSC9953_AGE_PORT_MASK | VSC9953_AGE_VID_EN |
1193 VSC9953_AGE_VID_MASK);
1196 /* Add a static FDB entry */
1197 static int vsc9953_mac_table_add(u8 port_no, uchar mac[6], int vid)
1200 struct vsc9953_analyzer *l2ana_reg;
1202 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1203 VSC9953_ANA_OFFSET);
1205 val = in_le32(&l2ana_reg->ana_tables.mach_data);
1206 val = bitfield_replace_by_mask(val, VSC9953_MACHDATA_VID_MASK, vid) |
1207 (mac[0] << 8) | (mac[1] << 0);
1208 out_le32(&l2ana_reg->ana_tables.mach_data, val);
1210 out_le32(&l2ana_reg->ana_tables.macl_data,
1211 (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) |
1214 /* set on which port is the MAC address added */
1215 val = in_le32(&l2ana_reg->ana_tables.mac_access);
1216 val = bitfield_replace_by_mask(val, VSC9953_MAC_DESTIDX_MASK, port_no);
1217 out_le32(&l2ana_reg->ana_tables.mac_access, val);
1219 if (vsc9953_mac_table_cmd(MAC_TABLE_LEARN) < 0)
1222 /* check if the MAC address was indeed added */
1223 val = in_le32(&l2ana_reg->ana_tables.mach_data);
1224 val = bitfield_replace_by_mask(val, VSC9953_MACHDATA_VID_MASK, vid) |
1225 (mac[0] << 8) | (mac[1] << 0);
1226 out_le32(&l2ana_reg->ana_tables.mach_data, val);
1228 out_le32(&l2ana_reg->ana_tables.macl_data,
1229 (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) |
1232 if (vsc9953_mac_table_cmd(MAC_TABLE_READ) < 0)
1235 val = in_le32(&l2ana_reg->ana_tables.mac_access);
1237 if ((port_no != bitfield_extract_by_mask(val,
1238 VSC9953_MAC_DESTIDX_MASK))) {
1239 printf("Failed to add MAC address\n");
1245 /* Delete a FDB entry */
1246 static int vsc9953_mac_table_del(uchar mac[6], u16 vid)
1249 struct vsc9953_analyzer *l2ana_reg;
1251 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1252 VSC9953_ANA_OFFSET);
1254 /* check first if MAC entry is present */
1255 val = in_le32(&l2ana_reg->ana_tables.mach_data);
1256 val = bitfield_replace_by_mask(val, VSC9953_MACHDATA_VID_MASK, vid) |
1257 (mac[0] << 8) | (mac[1] << 0);
1258 out_le32(&l2ana_reg->ana_tables.mach_data, val);
1260 out_le32(&l2ana_reg->ana_tables.macl_data,
1261 (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) |
1264 if (vsc9953_mac_table_cmd(MAC_TABLE_LOOKUP) < 0) {
1265 debug("Lookup in the MAC table failed\n");
1269 if (!(in_le32(&l2ana_reg->ana_tables.mac_access) &
1270 VSC9953_MAC_CMD_VALID)) {
1271 printf("The MAC address: %02x:%02x:%02x:%02x:%02x:%02x ",
1272 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
1273 printf("VLAN: %d does not exist.\n", vid);
1277 /* FDB entry found, proceed to delete */
1278 val = in_le32(&l2ana_reg->ana_tables.mach_data);
1279 val = bitfield_replace_by_mask(val, VSC9953_MACHDATA_VID_MASK, vid) |
1280 (mac[0] << 8) | (mac[1] << 0);
1281 out_le32(&l2ana_reg->ana_tables.mach_data, val);
1283 out_le32(&l2ana_reg->ana_tables.macl_data, (mac[2] << 24) |
1284 (mac[3] << 16) | (mac[4] << 8) | (mac[5] << 0));
1286 if (vsc9953_mac_table_cmd(MAC_TABLE_FORGET) < 0)
1289 /* check if the MAC entry is still in FDB */
1290 val = in_le32(&l2ana_reg->ana_tables.mach_data);
1291 val = bitfield_replace_by_mask(val, VSC9953_MACHDATA_VID_MASK, vid) |
1292 (mac[0] << 8) | (mac[1] << 0);
1293 out_le32(&l2ana_reg->ana_tables.mach_data, val);
1295 out_le32(&l2ana_reg->ana_tables.macl_data, (mac[2] << 24) |
1296 (mac[3] << 16) | (mac[4] << 8) | (mac[5] << 0));
1298 if (vsc9953_mac_table_cmd(MAC_TABLE_LOOKUP) < 0) {
1299 debug("Lookup in the MAC table failed\n");
1302 if (in_le32(&l2ana_reg->ana_tables.mac_access) &
1303 VSC9953_MAC_CMD_VALID) {
1304 printf("Failed to delete MAC address\n");
1311 /* age the unlocked entries in FDB */
1312 static void vsc9953_mac_table_age(int port_no, int vid)
1314 int rc[VSC9953_MAX_PORTS];
1315 enum port_learn_mode mode[VSC9953_MAX_PORTS];
1318 struct vsc9953_analyzer *l2ana_reg;
1320 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1321 VSC9953_ANA_OFFSET);
1323 /* set port and VID for selective aging */
1324 val = in_le32(&l2ana_reg->ana.anag_efil);
1325 if (port_no != ETHSW_CMD_PORT_ALL) {
1326 /* disable auto learning */
1327 rc[port_no] = vsc9953_port_learn_mode_get(port_no,
1329 if (!rc[port_no] && mode[port_no] != PORT_LEARN_NONE)
1330 vsc9953_port_learn_mode_set(port_no, PORT_LEARN_NONE);
1332 val = bitfield_replace_by_mask(val, VSC9953_AGE_PORT_MASK,
1333 port_no) | VSC9953_AGE_PORT_EN;
1335 /* disable auto learning on all ports */
1336 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1337 rc[i] = vsc9953_port_learn_mode_get(i, &mode[i]);
1338 if (!rc[i] && mode[i] != PORT_LEARN_NONE)
1339 vsc9953_port_learn_mode_set(i, PORT_LEARN_NONE);
1343 if (vid != ETHSW_CMD_VLAN_ALL) {
1344 val = bitfield_replace_by_mask(val, VSC9953_AGE_VID_MASK, vid) |
1347 out_le32(&l2ana_reg->ana.anag_efil, val);
1349 /* age the dynamic FDB entries */
1350 vsc9953_mac_table_cmd(MAC_TABLE_AGE);
1352 /* clear previously set port and VID */
1353 clrbits_le32(&l2ana_reg->ana.anag_efil, VSC9953_AGE_PORT_EN |
1354 VSC9953_AGE_PORT_MASK | VSC9953_AGE_VID_EN |
1355 VSC9953_AGE_VID_MASK);
1357 if (port_no != ETHSW_CMD_PORT_ALL) {
1358 if (!rc[port_no] && mode[port_no] != PORT_LEARN_NONE)
1359 vsc9953_port_learn_mode_set(port_no, mode[port_no]);
1361 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1362 if (!rc[i] && mode[i] != PORT_LEARN_NONE)
1363 vsc9953_port_learn_mode_set(i, mode[i]);
1368 /* Delete all the dynamic FDB entries */
1369 static void vsc9953_mac_table_flush(int port, int vid)
1371 vsc9953_mac_table_age(port, vid);
1372 vsc9953_mac_table_age(port, vid);
1375 enum egress_vlan_tag {
1380 /* Set egress tag mode for a VSC9953 port */
1381 static void vsc9953_port_vlan_egress_tag_set(int port_no,
1382 enum egress_vlan_tag mode)
1384 struct vsc9953_rew_reg *l2rew_reg;
1386 l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
1387 VSC9953_REW_OFFSET);
1391 clrbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
1392 VSC9953_TAG_VID_PVID);
1395 setbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
1396 VSC9953_TAG_VID_PVID);
1399 printf("Unknown egress VLAN tag mode for port %d\n", port_no);
1403 /* Get egress tag mode for a VSC9953 port */
1404 static void vsc9953_port_vlan_egress_tag_get(int port_no,
1405 enum egress_vlan_tag *mode)
1408 struct vsc9953_rew_reg *l2rew_reg;
1410 l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
1411 VSC9953_REW_OFFSET);
1413 val = in_le32(&l2rew_reg->port[port_no].port_tag_cfg);
1414 if (val & VSC9953_TAG_VID_PVID)
1415 *mode = EGR_TAG_PVID;
1417 *mode = EGR_TAG_CLASS;
1420 /* VSC9953 VLAN learning modes */
1421 enum vlan_learning_mode {
1422 SHARED_VLAN_LEARNING,
1423 PRIVATE_VLAN_LEARNING,
1426 /* Set VLAN learning mode for VSC9953 */
1427 static void vsc9953_vlan_learning_set(enum vlan_learning_mode lrn_mode)
1429 struct vsc9953_analyzer *l2ana_reg;
1431 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1432 VSC9953_ANA_OFFSET);
1435 case SHARED_VLAN_LEARNING:
1436 setbits_le32(&l2ana_reg->ana.agen_ctrl, VSC9953_FID_MASK_ALL);
1438 case PRIVATE_VLAN_LEARNING:
1439 clrbits_le32(&l2ana_reg->ana.agen_ctrl, VSC9953_FID_MASK_ALL);
1442 printf("Unknown VLAN learn mode\n");
1446 /* Get VLAN learning mode for VSC9953 */
1447 static int vsc9953_vlan_learning_get(enum vlan_learning_mode *lrn_mode)
1450 struct vsc9953_analyzer *l2ana_reg;
1452 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1453 VSC9953_ANA_OFFSET);
1455 val = in_le32(&l2ana_reg->ana.agen_ctrl);
1457 if (!(val & VSC9953_FID_MASK_ALL)) {
1458 *lrn_mode = PRIVATE_VLAN_LEARNING;
1459 } else if ((val & VSC9953_FID_MASK_ALL) == VSC9953_FID_MASK_ALL) {
1460 *lrn_mode = SHARED_VLAN_LEARNING;
1462 printf("Unknown VLAN learning mode\n");
1469 /* Enable/disable VLAN ingress filtering on a VSC9953 port */
1470 static void vsc9953_port_ingress_filtering_set(int port_no, int enabled)
1472 struct vsc9953_analyzer *l2ana_reg;
1474 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1475 VSC9953_ANA_OFFSET);
1478 setbits_le32(&l2ana_reg->ana.vlan_mask, 1 << port_no);
1480 clrbits_le32(&l2ana_reg->ana.vlan_mask, 1 << port_no);
1483 /* Return VLAN ingress filtering on a VSC9953 port */
1484 static int vsc9953_port_ingress_filtering_get(int port_no)
1487 struct vsc9953_analyzer *l2ana_reg;
1489 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1490 VSC9953_ANA_OFFSET);
1492 val = in_le32(&l2ana_reg->ana.vlan_mask);
1493 return !!(val & (1 << port_no));
1496 static int vsc9953_port_status_key_func(struct ethsw_command_def *parsed_cmd)
1501 /* Last keyword should tell us if we should enable/disable the port */
1502 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1505 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1509 return CMD_RET_USAGE;
1511 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1512 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1513 printf("Invalid port number: %d\n", parsed_cmd->port);
1514 return CMD_RET_FAILURE;
1516 vsc9953_port_status_set(parsed_cmd->port, enabled);
1518 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1519 vsc9953_port_status_set(i, enabled);
1522 return CMD_RET_SUCCESS;
1525 static int vsc9953_port_config_key_func(struct ethsw_command_def *parsed_cmd)
1529 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1530 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1531 printf("Invalid port number: %d\n", parsed_cmd->port);
1532 return CMD_RET_FAILURE;
1534 vsc9953_phy_autoneg(parsed_cmd->port);
1535 printf("%8s %8s %8s %8s %8s\n",
1536 "Port", "Status", "Link", "Speed",
1538 vsc9953_port_config_show(parsed_cmd->port);
1541 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1542 vsc9953_phy_autoneg(i);
1543 printf("%8s %8s %8s %8s %8s\n",
1544 "Port", "Status", "Link", "Speed", "Duplex");
1545 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1546 vsc9953_port_config_show(i);
1549 return CMD_RET_SUCCESS;
1552 static int vsc9953_port_stats_key_func(struct ethsw_command_def *parsed_cmd)
1556 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1557 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1558 printf("Invalid port number: %d\n", parsed_cmd->port);
1559 return CMD_RET_FAILURE;
1561 vsc9953_port_statistics_show(parsed_cmd->port);
1563 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1564 vsc9953_port_statistics_show(i);
1567 return CMD_RET_SUCCESS;
1570 static int vsc9953_port_stats_clear_key_func(struct ethsw_command_def
1575 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1576 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1577 printf("Invalid port number: %d\n", parsed_cmd->port);
1578 return CMD_RET_FAILURE;
1580 vsc9953_port_statistics_clear(parsed_cmd->port);
1582 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1583 vsc9953_port_statistics_clear(i);
1586 return CMD_RET_SUCCESS;
1589 static int vsc9953_learn_show_key_func(struct ethsw_command_def *parsed_cmd)
1592 enum port_learn_mode mode;
1594 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1595 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1596 printf("Invalid port number: %d\n", parsed_cmd->port);
1597 return CMD_RET_FAILURE;
1599 if (vsc9953_port_learn_mode_get(parsed_cmd->port, &mode))
1600 return CMD_RET_FAILURE;
1601 printf("%7s %11s\n", "Port", "Learn mode");
1603 case PORT_LEARN_NONE:
1604 printf("%7d %11s\n", parsed_cmd->port, "disable");
1606 case PORT_LEARN_AUTO:
1607 printf("%7d %11s\n", parsed_cmd->port, "auto");
1610 printf("%7d %11s\n", parsed_cmd->port, "-");
1613 printf("%7s %11s\n", "Port", "Learn mode");
1614 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1615 if (vsc9953_port_learn_mode_get(i, &mode))
1618 case PORT_LEARN_NONE:
1619 printf("%7d %11s\n", i, "disable");
1621 case PORT_LEARN_AUTO:
1622 printf("%7d %11s\n", i, "auto");
1625 printf("%7d %11s\n", i, "-");
1630 return CMD_RET_SUCCESS;
1633 static int vsc9953_learn_set_key_func(struct ethsw_command_def *parsed_cmd)
1636 enum port_learn_mode mode;
1638 /* Last keyword should tell us the learn mode */
1639 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1641 mode = PORT_LEARN_AUTO;
1642 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1644 mode = PORT_LEARN_NONE;
1646 return CMD_RET_USAGE;
1648 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1649 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1650 printf("Invalid port number: %d\n", parsed_cmd->port);
1651 return CMD_RET_FAILURE;
1653 vsc9953_port_learn_mode_set(parsed_cmd->port, mode);
1655 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1656 vsc9953_port_learn_mode_set(i, mode);
1659 return CMD_RET_SUCCESS;
1662 static int vsc9953_fdb_show_key_func(struct ethsw_command_def *parsed_cmd)
1664 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL &&
1665 !VSC9953_PORT_CHECK(parsed_cmd->port)) {
1666 printf("Invalid port number: %d\n", parsed_cmd->port);
1667 return CMD_RET_FAILURE;
1670 if (parsed_cmd->vid != ETHSW_CMD_VLAN_ALL &&
1671 !VSC9953_VLAN_CHECK(parsed_cmd->vid)) {
1672 printf("Invalid VID number: %d\n", parsed_cmd->vid);
1673 return CMD_RET_FAILURE;
1676 vsc9953_mac_table_show(parsed_cmd->port, parsed_cmd->vid);
1678 return CMD_RET_SUCCESS;
1681 static int vsc9953_fdb_flush_key_func(struct ethsw_command_def *parsed_cmd)
1683 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL &&
1684 !VSC9953_PORT_CHECK(parsed_cmd->port)) {
1685 printf("Invalid port number: %d\n", parsed_cmd->port);
1686 return CMD_RET_FAILURE;
1689 if (parsed_cmd->vid != ETHSW_CMD_VLAN_ALL &&
1690 !VSC9953_VLAN_CHECK(parsed_cmd->vid)) {
1691 printf("Invalid VID number: %d\n", parsed_cmd->vid);
1692 return CMD_RET_FAILURE;
1695 vsc9953_mac_table_flush(parsed_cmd->port, parsed_cmd->vid);
1697 return CMD_RET_SUCCESS;
1700 static int vsc9953_fdb_entry_add_key_func(struct ethsw_command_def *parsed_cmd)
1704 /* a port number must be present */
1705 if (parsed_cmd->port == ETHSW_CMD_PORT_ALL) {
1706 printf("Please specify a port\n");
1707 return CMD_RET_FAILURE;
1710 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1711 printf("Invalid port number: %d\n", parsed_cmd->port);
1712 return CMD_RET_FAILURE;
1715 /* Use VLAN 1 if VID is not set */
1716 vid = (parsed_cmd->vid == ETHSW_CMD_VLAN_ALL ? 1 : parsed_cmd->vid);
1718 if (!VSC9953_VLAN_CHECK(vid)) {
1719 printf("Invalid VID number: %d\n", vid);
1720 return CMD_RET_FAILURE;
1723 if (vsc9953_mac_table_add(parsed_cmd->port, parsed_cmd->ethaddr, vid))
1724 return CMD_RET_FAILURE;
1726 return CMD_RET_SUCCESS;
1729 static int vsc9953_fdb_entry_del_key_func(struct ethsw_command_def *parsed_cmd)
1733 /* Use VLAN 1 if VID is not set */
1734 vid = (parsed_cmd->vid == ETHSW_CMD_VLAN_ALL ? 1 : parsed_cmd->vid);
1736 if (!VSC9953_VLAN_CHECK(vid)) {
1737 printf("Invalid VID number: %d\n", vid);
1738 return CMD_RET_FAILURE;
1741 if (vsc9953_mac_table_del(parsed_cmd->ethaddr, vid))
1742 return CMD_RET_FAILURE;
1744 return CMD_RET_SUCCESS;
1747 static int vsc9953_pvid_show_key_func(struct ethsw_command_def *parsed_cmd)
1752 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1753 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1754 printf("Invalid port number: %d\n", parsed_cmd->port);
1755 return CMD_RET_FAILURE;
1758 if (vsc9953_port_vlan_pvid_get(parsed_cmd->port, &pvid))
1759 return CMD_RET_FAILURE;
1760 printf("%7s %7s\n", "Port", "PVID");
1761 printf("%7d %7d\n", parsed_cmd->port, pvid);
1763 printf("%7s %7s\n", "Port", "PVID");
1764 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1765 if (vsc9953_port_vlan_pvid_get(i, &pvid))
1767 printf("%7d %7d\n", i, pvid);
1771 return CMD_RET_SUCCESS;
1774 static int vsc9953_pvid_set_key_func(struct ethsw_command_def *parsed_cmd)
1776 /* PVID number should be set in parsed_cmd->vid */
1777 if (parsed_cmd->vid == ETHSW_CMD_VLAN_ALL) {
1778 printf("Please set a pvid value\n");
1779 return CMD_RET_FAILURE;
1782 if (!VSC9953_VLAN_CHECK(parsed_cmd->vid)) {
1783 printf("Invalid VID number: %d\n", parsed_cmd->vid);
1784 return CMD_RET_FAILURE;
1787 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1788 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1789 printf("Invalid port number: %d\n", parsed_cmd->port);
1790 return CMD_RET_FAILURE;
1792 vsc9953_port_vlan_pvid_set(parsed_cmd->port, parsed_cmd->vid);
1794 vsc9953_port_all_vlan_pvid_set(parsed_cmd->vid);
1797 return CMD_RET_SUCCESS;
1800 static int vsc9953_vlan_show_key_func(struct ethsw_command_def *parsed_cmd)
1804 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1805 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1806 printf("Invalid port number: %d\n", parsed_cmd->port);
1807 return CMD_RET_FAILURE;
1809 vsc9953_vlan_membership_show(parsed_cmd->port);
1811 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1812 vsc9953_vlan_membership_show(i);
1815 return CMD_RET_SUCCESS;
1818 static int vsc9953_vlan_set_key_func(struct ethsw_command_def *parsed_cmd)
1823 /* VLAN should be set in parsed_cmd->vid */
1824 if (parsed_cmd->vid == ETHSW_CMD_VLAN_ALL) {
1825 printf("Please set a vlan value\n");
1826 return CMD_RET_FAILURE;
1829 if (!VSC9953_VLAN_CHECK(parsed_cmd->vid)) {
1830 printf("Invalid VID number: %d\n", parsed_cmd->vid);
1831 return CMD_RET_FAILURE;
1834 /* keywords add/delete should be the last but one in array */
1835 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 2] ==
1838 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 2] ==
1842 return CMD_RET_USAGE;
1844 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1845 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1846 printf("Invalid port number: %d\n", parsed_cmd->port);
1847 return CMD_RET_FAILURE;
1849 vsc9953_vlan_table_membership_set(parsed_cmd->vid,
1850 parsed_cmd->port, add);
1852 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1853 vsc9953_vlan_table_membership_set(parsed_cmd->vid, i,
1857 return CMD_RET_SUCCESS;
1859 static int vsc9953_port_untag_show_key_func(
1860 struct ethsw_command_def *parsed_cmd)
1864 printf("%7s\t%17s\n", "Port", "Untag");
1865 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1866 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1867 printf("Invalid port number: %d\n", parsed_cmd->port);
1868 return CMD_RET_FAILURE;
1870 vsc9953_port_vlan_egr_untag_show(parsed_cmd->port);
1872 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1873 vsc9953_port_vlan_egr_untag_show(i);
1876 return CMD_RET_SUCCESS;
1879 static int vsc9953_port_untag_set_key_func(struct ethsw_command_def *parsed_cmd)
1882 enum egress_untag_mode mode;
1884 /* keywords for the untagged mode are the last in the array */
1885 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1887 mode = EGRESS_UNTAG_ALL;
1888 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1890 mode = EGRESS_UNTAG_NONE;
1891 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1893 mode = EGRESS_UNTAG_PVID_AND_ZERO;
1895 return CMD_RET_USAGE;
1897 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1898 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1899 printf("Invalid port number: %d\n", parsed_cmd->port);
1900 return CMD_RET_FAILURE;
1902 vsc9953_port_vlan_egr_untag_set(parsed_cmd->port, mode);
1904 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1905 vsc9953_port_vlan_egr_untag_set(i, mode);
1908 return CMD_RET_SUCCESS;
1911 static int vsc9953_egr_vlan_tag_show_key_func(
1912 struct ethsw_command_def *parsed_cmd)
1915 enum egress_vlan_tag mode;
1917 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1918 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1919 printf("Invalid port number: %d\n", parsed_cmd->port);
1920 return CMD_RET_FAILURE;
1922 vsc9953_port_vlan_egress_tag_get(parsed_cmd->port, &mode);
1923 printf("%7s\t%12s\n", "Port", "Egress VID");
1924 printf("%7d\t", parsed_cmd->port);
1927 printf("%12s\n", "classified");
1930 printf("%12s\n", "pvid");
1933 printf("%12s\n", "-");
1936 printf("%7s\t%12s\n", "Port", "Egress VID");
1937 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1938 vsc9953_port_vlan_egress_tag_get(i, &mode);
1941 printf("%7d\t%12s\n", i, "classified");
1944 printf("%7d\t%12s\n", i, "pvid");
1947 printf("%7d\t%12s\n", i, "-");
1952 return CMD_RET_SUCCESS;
1955 static int vsc9953_egr_vlan_tag_set_key_func(
1956 struct ethsw_command_def *parsed_cmd)
1959 enum egress_vlan_tag mode;
1961 /* keywords for the egress vlan tag mode are the last in the array */
1962 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1964 mode = EGR_TAG_PVID;
1965 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1966 ethsw_id_classified)
1967 mode = EGR_TAG_CLASS;
1969 return CMD_RET_USAGE;
1971 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1972 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1973 printf("Invalid port number: %d\n", parsed_cmd->port);
1974 return CMD_RET_FAILURE;
1976 vsc9953_port_vlan_egress_tag_set(parsed_cmd->port, mode);
1978 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1979 vsc9953_port_vlan_egress_tag_set(i, mode);
1982 return CMD_RET_SUCCESS;
1985 static int vsc9953_vlan_learn_show_key_func(
1986 struct ethsw_command_def *parsed_cmd)
1989 enum vlan_learning_mode mode;
1991 rc = vsc9953_vlan_learning_get(&mode);
1993 return CMD_RET_FAILURE;
1996 case SHARED_VLAN_LEARNING:
1997 printf("VLAN learning mode: shared\n");
1999 case PRIVATE_VLAN_LEARNING:
2000 printf("VLAN learning mode: private\n");
2003 printf("Unknown VLAN learning mode\n");
2004 rc = CMD_RET_FAILURE;
2007 return CMD_RET_SUCCESS;
2010 static int vsc9953_vlan_learn_set_key_func(struct ethsw_command_def *parsed_cmd)
2012 enum vlan_learning_mode mode;
2014 /* keywords for shared/private are the last in the array */
2015 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2017 mode = SHARED_VLAN_LEARNING;
2018 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2020 mode = PRIVATE_VLAN_LEARNING;
2022 return CMD_RET_USAGE;
2024 vsc9953_vlan_learning_set(mode);
2026 return CMD_RET_SUCCESS;
2029 static int vsc9953_ingr_fltr_show_key_func(struct ethsw_command_def *parsed_cmd)
2034 printf("%7s\t%18s\n", "Port", "Ingress filtering");
2035 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2036 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2037 printf("Invalid port number: %d\n", parsed_cmd->port);
2038 return CMD_RET_FAILURE;
2040 enabled = vsc9953_port_ingress_filtering_get(parsed_cmd->port);
2041 printf("%7d\t%18s\n", parsed_cmd->port, enabled ? "enable" :
2044 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
2045 enabled = vsc9953_port_ingress_filtering_get(i);
2046 printf("%7d\t%18s\n", parsed_cmd->port, enabled ?
2052 return CMD_RET_SUCCESS;
2055 static int vsc9953_ingr_fltr_set_key_func(struct ethsw_command_def *parsed_cmd)
2060 /* keywords for enabling/disabling ingress filtering
2061 * are the last in the array
2063 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2066 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2070 return CMD_RET_USAGE;
2072 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2073 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2074 printf("Invalid port number: %d\n", parsed_cmd->port);
2075 return CMD_RET_FAILURE;
2077 vsc9953_port_ingress_filtering_set(parsed_cmd->port, enable);
2079 for (i = 0; i < VSC9953_MAX_PORTS; i++)
2080 vsc9953_port_ingress_filtering_set(i, enable);
2083 return CMD_RET_SUCCESS;
2086 static struct ethsw_command_func vsc9953_cmd_func = {
2087 .ethsw_name = "L2 Switch VSC9953",
2088 .port_enable = &vsc9953_port_status_key_func,
2089 .port_disable = &vsc9953_port_status_key_func,
2090 .port_show = &vsc9953_port_config_key_func,
2091 .port_stats = &vsc9953_port_stats_key_func,
2092 .port_stats_clear = &vsc9953_port_stats_clear_key_func,
2093 .port_learn = &vsc9953_learn_set_key_func,
2094 .port_learn_show = &vsc9953_learn_show_key_func,
2095 .fdb_show = &vsc9953_fdb_show_key_func,
2096 .fdb_flush = &vsc9953_fdb_flush_key_func,
2097 .fdb_entry_add = &vsc9953_fdb_entry_add_key_func,
2098 .fdb_entry_del = &vsc9953_fdb_entry_del_key_func,
2099 .pvid_show = &vsc9953_pvid_show_key_func,
2100 .pvid_set = &vsc9953_pvid_set_key_func,
2101 .vlan_show = &vsc9953_vlan_show_key_func,
2102 .vlan_set = &vsc9953_vlan_set_key_func,
2103 .port_untag_show = &vsc9953_port_untag_show_key_func,
2104 .port_untag_set = &vsc9953_port_untag_set_key_func,
2105 .port_egr_vlan_show = &vsc9953_egr_vlan_tag_show_key_func,
2106 .port_egr_vlan_set = &vsc9953_egr_vlan_tag_set_key_func,
2107 .vlan_learn_show = &vsc9953_vlan_learn_show_key_func,
2108 .vlan_learn_set = &vsc9953_vlan_learn_set_key_func,
2109 .port_ingr_filt_show = &vsc9953_ingr_fltr_show_key_func,
2110 .port_ingr_filt_set = &vsc9953_ingr_fltr_set_key_func
2113 #endif /* CONFIG_CMD_ETHSW */
2115 /*****************************************************************************
2116 At startup, the default configuration would be:
2117 - HW learning enabled on all ports; (HW default)
2118 - All ports are in VLAN 1;
2119 - All ports are VLAN aware;
2120 - All ports have POP_COUNT 1;
2121 - All ports have PVID 1;
2122 - All ports have TPID 0x8100; (HW default)
2123 - All ports tag frames classified to all VLANs that are not PVID;
2124 *****************************************************************************/
2125 void vsc9953_default_configuration(void)
2129 if (vsc9953_autoage_time_set(VSC9953_DEFAULT_AGE_TIME))
2130 debug("VSC9953: failed to set AGE time to %d\n",
2131 VSC9953_DEFAULT_AGE_TIME);
2133 for (i = 0; i < VSC9953_MAX_VLAN; i++)
2134 vsc9953_vlan_table_membership_all_set(i, 0);
2135 vsc9953_port_all_vlan_aware_set(1);
2136 vsc9953_port_all_vlan_pvid_set(1);
2137 vsc9953_port_all_vlan_poncnt_set(1);
2138 vsc9953_vlan_table_membership_all_set(1, 1);
2139 vsc9953_vlan_ingr_fltr_learn_drop(1);
2140 vsc9953_port_all_vlan_egress_untagged_set(EGRESS_UNTAG_PVID_AND_ZERO);
2143 void vsc9953_init(bd_t *bis)
2149 struct vsc9953_system_reg *l2sys_reg;
2150 struct vsc9953_qsys_reg *l2qsys_reg;
2151 struct vsc9953_dev_gmii *l2dev_gmii_reg;
2152 struct vsc9953_analyzer *l2ana_reg;
2153 struct vsc9953_devcpu_gcb *l2dev_gcb;
2155 l2dev_gmii_reg = (struct vsc9953_dev_gmii *)(VSC9953_OFFSET +
2156 VSC9953_DEV_GMII_OFFSET);
2158 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
2159 VSC9953_ANA_OFFSET);
2161 l2sys_reg = (struct vsc9953_system_reg *)(VSC9953_OFFSET +
2162 VSC9953_SYS_OFFSET);
2164 l2qsys_reg = (struct vsc9953_qsys_reg *)(VSC9953_OFFSET +
2165 VSC9953_QSYS_OFFSET);
2167 l2dev_gcb = (struct vsc9953_devcpu_gcb *)(VSC9953_OFFSET +
2168 VSC9953_DEVCPU_GCB);
2170 out_le32(&l2dev_gcb->chip_regs.soft_rst,
2171 VSC9953_SOFT_SWC_RST_ENA);
2173 while ((in_le32(&l2dev_gcb->chip_regs.soft_rst) &
2174 VSC9953_SOFT_SWC_RST_ENA) && --timeout)
2175 udelay(1); /* busy wait for vsc9953 soft reset */
2177 debug("Timeout waiting for VSC9953 to reset\n");
2179 out_le32(&l2sys_reg->sys.reset_cfg, VSC9953_MEM_ENABLE |
2183 while ((in_le32(&l2sys_reg->sys.reset_cfg) &
2184 VSC9953_MEM_INIT) && --timeout)
2185 udelay(1); /* busy wait for vsc9953 memory init */
2187 debug("Timeout waiting for VSC9953 memory to initialize\n");
2189 out_le32(&l2sys_reg->sys.reset_cfg, (in_le32(&l2sys_reg->sys.reset_cfg)
2190 | VSC9953_CORE_ENABLE));
2192 /* VSC9953 Setting to be done once only */
2193 out_le32(&l2qsys_reg->sys.ext_cpu_cfg, 0x00000b00);
2195 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
2196 if (vsc9953_port_init(i))
2197 printf("Failed to initialize l2switch port %d\n", i);
2199 /* Enable VSC9953 GMII Ports Port ID 0 - 7 */
2200 if (VSC9953_INTERNAL_PORT_CHECK(i)) {
2201 out_le32(&l2ana_reg->pfc[i].pfc_cfg,
2202 VSC9953_PFC_FC_QSGMII);
2203 out_le32(&l2sys_reg->pause_cfg.mac_fc_cfg[i],
2204 VSC9953_MAC_FC_CFG_QSGMII);
2206 out_le32(&l2ana_reg->pfc[i].pfc_cfg,
2208 out_le32(&l2sys_reg->pause_cfg.mac_fc_cfg[i],
2209 VSC9953_MAC_FC_CFG);
2211 out_le32(&l2dev_gmii_reg->port_mode.clock_cfg,
2213 out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_ena_cfg,
2214 VSC9953_MAC_ENA_CFG);
2215 out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_mode_cfg,
2216 VSC9953_MAC_MODE_CFG);
2217 out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_ifg_cfg,
2218 VSC9953_MAC_IFG_CFG);
2219 /* mac_hdx_cfg varies with port id*/
2220 hdx_cfg = VSC9953_MAC_HDX_CFG | (i << 16);
2221 out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_hdx_cfg, hdx_cfg);
2222 out_le32(&l2sys_reg->sys.front_port_mode[i],
2223 VSC9953_FRONT_PORT_MODE);
2224 setbits_le32(&l2qsys_reg->sys.switch_port_mode[i],
2226 out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_maxlen_cfg,
2227 VSC9953_MAC_MAX_LEN);
2228 out_le32(&l2sys_reg->pause_cfg.pause_cfg[i],
2233 l2dev_gmii_reg = (struct vsc9953_dev_gmii *)(
2234 (char *)l2dev_gmii_reg
2235 + T1040_SWITCH_GMII_DEV_OFFSET);
2237 /* Initialize Lynx PHY Wrappers */
2239 if (vsc9953_l2sw.port[i].enet_if ==
2240 PHY_INTERFACE_MODE_QSGMII)
2241 phy_addr = (i + 0x4) & 0x1F;
2242 else if (vsc9953_l2sw.port[i].enet_if ==
2243 PHY_INTERFACE_MODE_SGMII)
2244 phy_addr = (i + 1) & 0x1F;
2247 /* SGMII IF mode + AN enable */
2248 vsc9953_mdio_write(&l2dev_gcb->mii_mng[0], phy_addr,
2249 0x14, PHY_SGMII_IF_MODE_AN |
2250 PHY_SGMII_IF_MODE_SGMII);
2251 /* Dev ability according to SGMII specification */
2252 vsc9953_mdio_write(&l2dev_gcb->mii_mng[0], phy_addr,
2253 0x4, PHY_SGMII_DEV_ABILITY_SGMII);
2254 /* Adjust link timer for SGMII
2255 * 1.6 ms in units of 8 ns = 2 * 10^5 = 0x30d40
2257 vsc9953_mdio_write(&l2dev_gcb->mii_mng[0], phy_addr,
2259 vsc9953_mdio_write(&l2dev_gcb->mii_mng[0], phy_addr,
2262 vsc9953_mdio_write(&l2dev_gcb->mii_mng[0], phy_addr,
2263 0x0, PHY_SGMII_CR_DEF_VAL |
2264 PHY_SGMII_CR_RESET_AN);
2267 while ((vsc9953_mdio_read(&l2dev_gcb->mii_mng[0],
2268 phy_addr, 0x01) & 0x0020) && --timeout)
2269 udelay(1); /* wait for AN to complete */
2271 debug("Timeout waiting for AN to complete\n");
2275 vsc9953_default_configuration();
2277 #ifdef CONFIG_CMD_ETHSW
2278 if (ethsw_define_functions(&vsc9953_cmd_func) < 0)
2279 debug("Unable to use \"ethsw\" commands\n");
2282 printf("VSC9953 L2 switch initialized\n");