1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014 - 2015 Freescale Semiconductor, Inc.
5 * Driver for the Vitesse VSC9953 L2 Switch
9 #include <asm/fsl_serdes.h>
11 #include <fsl_memac.h>
18 static struct vsc9953_info vsc9953_l2sw = {
19 .port[0] = VSC9953_PORT_INFO_INITIALIZER(0),
20 .port[1] = VSC9953_PORT_INFO_INITIALIZER(1),
21 .port[2] = VSC9953_PORT_INFO_INITIALIZER(2),
22 .port[3] = VSC9953_PORT_INFO_INITIALIZER(3),
23 .port[4] = VSC9953_PORT_INFO_INITIALIZER(4),
24 .port[5] = VSC9953_PORT_INFO_INITIALIZER(5),
25 .port[6] = VSC9953_PORT_INFO_INITIALIZER(6),
26 .port[7] = VSC9953_PORT_INFO_INITIALIZER(7),
27 .port[8] = VSC9953_PORT_INFO_INITIALIZER(8),
28 .port[9] = VSC9953_PORT_INFO_INITIALIZER(9),
31 void vsc9953_port_info_set_mdio(int port_no, struct mii_dev *bus)
33 if (!VSC9953_PORT_CHECK(port_no))
36 vsc9953_l2sw.port[port_no].bus = bus;
39 void vsc9953_port_info_set_phy_address(int port_no, int address)
41 if (!VSC9953_PORT_CHECK(port_no))
44 vsc9953_l2sw.port[port_no].phyaddr = address;
47 void vsc9953_port_info_set_phy_int(int port_no, phy_interface_t phy_int)
49 if (!VSC9953_PORT_CHECK(port_no))
52 vsc9953_l2sw.port[port_no].enet_if = phy_int;
55 void vsc9953_port_enable(int port_no)
57 if (!VSC9953_PORT_CHECK(port_no))
60 vsc9953_l2sw.port[port_no].enabled = 1;
63 void vsc9953_port_disable(int port_no)
65 if (!VSC9953_PORT_CHECK(port_no))
68 vsc9953_l2sw.port[port_no].enabled = 0;
71 static void vsc9953_mdio_write(struct vsc9953_mii_mng *phyregs, int port_addr,
72 int regnum, int value)
76 out_le32(&phyregs->miimcmd, (0x1 << 31) | ((port_addr & 0x1f) << 25) |
77 ((regnum & 0x1f) << 20) | ((value & 0xffff) << 4) |
81 while ((in_le32(&phyregs->miimstatus) & 0x8) && --timeout)
85 debug("Timeout waiting for MDIO write\n");
88 static int vsc9953_mdio_read(struct vsc9953_mii_mng *phyregs, int port_addr,
94 while ((in_le32(&phyregs->miimstatus) & MIIMIND_OPR_PEND) && --timeout)
97 debug("Timeout waiting for MDIO operation to finish\n");
101 /* Put the address of the phy, and the register
104 out_le32(&phyregs->miimcmd, (0x1 << 31) | ((port_addr & 0x1f) << 25) |
105 ((regnum & 0x1f) << 20) | ((value & 0xffff) << 4) |
109 /* Wait for the the indication that the read is done */
110 while ((in_le32(&phyregs->miimstatus) & 0x8) && --timeout)
113 debug("Timeout waiting for MDIO read\n");
115 /* Grab the value read from the PHY */
116 value = in_le32(&phyregs->miimdata);
118 if ((value & 0x00030000) == 0)
119 return value & 0x0000ffff;
124 static int init_phy(struct eth_device *dev)
126 struct vsc9953_port_info *l2sw_port = dev->priv;
127 struct phy_device *phydev = NULL;
132 phydev = phy_connect(l2sw_port->bus, l2sw_port->phyaddr, dev,
135 printf("Failed to connect\n");
139 phydev->supported &= SUPPORTED_10baseT_Half |
140 SUPPORTED_10baseT_Full |
141 SUPPORTED_100baseT_Half |
142 SUPPORTED_100baseT_Full |
143 SUPPORTED_1000baseT_Full;
144 phydev->advertising = phydev->supported;
146 l2sw_port->phydev = phydev;
154 static int vsc9953_port_init(int port_no)
156 struct eth_device *dev;
158 /* Internal ports never have a PHY */
159 if (VSC9953_INTERNAL_PORT_CHECK(port_no))
162 /* alloc eth device */
163 dev = (struct eth_device *)calloc(1, sizeof(struct eth_device));
167 sprintf(dev->name, "SW@PORT%d", port_no);
168 dev->priv = &vsc9953_l2sw.port[port_no];
182 static int vsc9953_vlan_table_poll_idle(void)
184 struct vsc9953_analyzer *l2ana_reg;
187 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
191 while (((in_le32(&l2ana_reg->ana_tables.vlan_access) &
192 VSC9953_VLAN_CMD_MASK) != VSC9953_VLAN_CMD_IDLE) && --timeout)
195 return timeout ? 0 : -EBUSY;
198 #ifdef CONFIG_CMD_ETHSW
199 /* Add/remove a port to/from a VLAN */
200 static void vsc9953_vlan_table_membership_set(int vid, u32 port_no, u8 add)
203 struct vsc9953_analyzer *l2ana_reg;
205 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
208 if (vsc9953_vlan_table_poll_idle() < 0) {
209 debug("VLAN table timeout\n");
213 val = in_le32(&l2ana_reg->ana_tables.vlan_tidx);
214 val = bitfield_replace_by_mask(val, VSC9953_ANA_TBL_VID_MASK, vid);
215 out_le32(&l2ana_reg->ana_tables.vlan_tidx, val);
217 clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
218 VSC9953_VLAN_CMD_MASK, VSC9953_VLAN_CMD_READ);
220 if (vsc9953_vlan_table_poll_idle() < 0) {
221 debug("VLAN table timeout\n");
225 val = in_le32(&l2ana_reg->ana_tables.vlan_tidx);
226 val = bitfield_replace_by_mask(val, VSC9953_ANA_TBL_VID_MASK, vid);
227 out_le32(&l2ana_reg->ana_tables.vlan_tidx, val);
229 val = in_le32(&l2ana_reg->ana_tables.vlan_access);
231 val = bitfield_replace_by_mask(val, VSC9953_VLAN_CMD_MASK,
232 VSC9953_VLAN_CMD_WRITE) &
233 ~(bitfield_replace_by_mask(0, VSC9953_VLAN_PORT_MASK,
237 val = bitfield_replace_by_mask(val, VSC9953_VLAN_CMD_MASK,
238 VSC9953_VLAN_CMD_WRITE) |
239 bitfield_replace_by_mask(0, VSC9953_VLAN_PORT_MASK,
242 out_le32(&l2ana_reg->ana_tables.vlan_access, val);
244 /* wait for VLAN table command to flush */
245 if (vsc9953_vlan_table_poll_idle() < 0) {
246 debug("VLAN table timeout\n");
251 /* show VLAN membership for a port */
252 static void vsc9953_vlan_membership_show(int port_no)
255 struct vsc9953_analyzer *l2ana_reg;
258 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
261 printf("Port %d VLAN membership: ", port_no);
263 for (vid = 0; vid < VSC9953_MAX_VLAN; vid++) {
264 if (vsc9953_vlan_table_poll_idle() < 0) {
265 debug("VLAN table timeout\n");
269 val = in_le32(&l2ana_reg->ana_tables.vlan_tidx);
270 val = bitfield_replace_by_mask(val, VSC9953_ANA_TBL_VID_MASK,
272 out_le32(&l2ana_reg->ana_tables.vlan_tidx, val);
274 clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
275 VSC9953_VLAN_CMD_MASK, VSC9953_VLAN_CMD_READ);
277 if (vsc9953_vlan_table_poll_idle() < 0) {
278 debug("VLAN table timeout\n");
282 val = in_le32(&l2ana_reg->ana_tables.vlan_access);
284 if (bitfield_extract_by_mask(val, VSC9953_VLAN_PORT_MASK) &
292 /* vlan table set/clear all membership of vid */
293 static void vsc9953_vlan_table_membership_all_set(int vid, int set_member)
296 struct vsc9953_analyzer *l2ana_reg;
298 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
301 if (vsc9953_vlan_table_poll_idle() < 0) {
302 debug("VLAN table timeout\n");
306 /* read current vlan configuration */
307 val = in_le32(&l2ana_reg->ana_tables.vlan_tidx);
308 out_le32(&l2ana_reg->ana_tables.vlan_tidx,
309 bitfield_replace_by_mask(val, VSC9953_ANA_TBL_VID_MASK, vid));
311 clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
312 VSC9953_VLAN_CMD_MASK, VSC9953_VLAN_CMD_READ);
314 if (vsc9953_vlan_table_poll_idle() < 0) {
315 debug("VLAN table timeout\n");
319 val = in_le32(&l2ana_reg->ana_tables.vlan_tidx);
320 out_le32(&l2ana_reg->ana_tables.vlan_tidx,
321 bitfield_replace_by_mask(val, VSC9953_ANA_TBL_VID_MASK, vid));
323 clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
324 VSC9953_VLAN_PORT_MASK | VSC9953_VLAN_CMD_MASK,
325 VSC9953_VLAN_CMD_WRITE |
326 (set_member ? VSC9953_VLAN_PORT_MASK : 0));
329 #ifdef CONFIG_CMD_ETHSW
330 /* Get PVID of a VSC9953 port */
331 static int vsc9953_port_vlan_pvid_get(int port_nr, int *pvid)
334 struct vsc9953_analyzer *l2ana_reg;
336 /* Administrative down */
337 if (!vsc9953_l2sw.port[port_nr].enabled) {
338 printf("Port %d is administrative down\n", port_nr);
342 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
345 /* Get ingress PVID */
346 val = in_le32(&l2ana_reg->port[port_nr].vlan_cfg);
347 *pvid = bitfield_extract_by_mask(val, VSC9953_VLAN_CFG_VID_MASK);
353 /* Set PVID for a VSC9953 port */
354 static void vsc9953_port_vlan_pvid_set(int port_no, int pvid)
357 struct vsc9953_analyzer *l2ana_reg;
358 struct vsc9953_rew_reg *l2rew_reg;
360 /* Administrative down */
361 if (!vsc9953_l2sw.port[port_no].enabled) {
362 printf("Port %d is administrative down\n", port_no);
366 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
368 l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
371 /* Set PVID on ingress */
372 val = in_le32(&l2ana_reg->port[port_no].vlan_cfg);
373 val = bitfield_replace_by_mask(val, VSC9953_VLAN_CFG_VID_MASK, pvid);
374 out_le32(&l2ana_reg->port[port_no].vlan_cfg, val);
376 /* Set PVID on egress */
377 val = in_le32(&l2rew_reg->port[port_no].port_vlan_cfg);
378 val = bitfield_replace_by_mask(val, VSC9953_PORT_VLAN_CFG_VID_MASK,
380 out_le32(&l2rew_reg->port[port_no].port_vlan_cfg, val);
383 static void vsc9953_port_all_vlan_pvid_set(int pvid)
387 for (i = 0; i < VSC9953_MAX_PORTS; i++)
388 vsc9953_port_vlan_pvid_set(i, pvid);
391 /* Enable/disable vlan aware of a VSC9953 port */
392 static void vsc9953_port_vlan_aware_set(int port_no, int enabled)
394 struct vsc9953_analyzer *l2ana_reg;
396 /* Administrative down */
397 if (!vsc9953_l2sw.port[port_no].enabled) {
398 printf("Port %d is administrative down\n", port_no);
402 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
406 setbits_le32(&l2ana_reg->port[port_no].vlan_cfg,
407 VSC9953_VLAN_CFG_AWARE_ENA);
409 clrbits_le32(&l2ana_reg->port[port_no].vlan_cfg,
410 VSC9953_VLAN_CFG_AWARE_ENA);
413 /* Set all VSC9953 ports' vlan aware */
414 static void vsc9953_port_all_vlan_aware_set(int enabled)
418 for (i = 0; i < VSC9953_MAX_PORTS; i++)
419 vsc9953_port_vlan_aware_set(i, enabled);
422 /* Enable/disable vlan pop count of a VSC9953 port */
423 static void vsc9953_port_vlan_popcnt_set(int port_no, int popcnt)
426 struct vsc9953_analyzer *l2ana_reg;
428 /* Administrative down */
429 if (!vsc9953_l2sw.port[port_no].enabled) {
430 printf("Port %d is administrative down\n", port_no);
434 if (popcnt > 3 || popcnt < 0) {
435 printf("Invalid pop count value: %d\n", port_no);
439 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
442 val = in_le32(&l2ana_reg->port[port_no].vlan_cfg);
443 val = bitfield_replace_by_mask(val, VSC9953_VLAN_CFG_POP_CNT_MASK,
445 out_le32(&l2ana_reg->port[port_no].vlan_cfg, val);
448 /* Set all VSC9953 ports' pop count */
449 static void vsc9953_port_all_vlan_poncnt_set(int popcnt)
453 for (i = 0; i < VSC9953_MAX_PORTS; i++)
454 vsc9953_port_vlan_popcnt_set(i, popcnt);
457 /* Enable/disable learning for frames dropped due to ingress filtering */
458 static void vsc9953_vlan_ingr_fltr_learn_drop(int enable)
460 struct vsc9953_analyzer *l2ana_reg;
462 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
466 setbits_le32(&l2ana_reg->ana.adv_learn, VSC9953_VLAN_CHK);
468 clrbits_le32(&l2ana_reg->ana.adv_learn, VSC9953_VLAN_CHK);
471 enum aggr_code_mode {
473 AGGR_CODE_ALL, /* S/D MAC, IPv4 S/D IP, IPv6 Flow Label, S/D PORT */
476 /* Set aggregation code generation mode */
477 static int vsc9953_aggr_code_set(enum aggr_code_mode ac)
480 struct vsc9953_analyzer *l2ana_reg;
482 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
487 clrsetbits_le32(&l2ana_reg->common.aggr_cfg,
488 VSC9953_AC_DMAC_ENA | VSC9953_AC_SMAC_ENA |
489 VSC9953_AC_IP6_LBL_ENA |
490 VSC9953_AC_IP6_TCPUDP_ENA |
491 VSC9953_AC_IP4_SIPDIP_ENA |
492 VSC9953_AC_IP4_TCPUDP_ENA, VSC9953_AC_RND_ENA);
496 clrsetbits_le32(&l2ana_reg->common.aggr_cfg, VSC9953_AC_RND_ENA,
497 VSC9953_AC_DMAC_ENA | VSC9953_AC_SMAC_ENA |
498 VSC9953_AC_IP6_LBL_ENA |
499 VSC9953_AC_IP6_TCPUDP_ENA |
500 VSC9953_AC_IP4_SIPDIP_ENA |
501 VSC9953_AC_IP4_TCPUDP_ENA);
505 /* unknown mode for aggregation code */
512 /* Egress untag modes of a VSC9953 port */
513 enum egress_untag_mode {
514 EGRESS_UNTAG_ALL = 0,
515 EGRESS_UNTAG_PVID_AND_ZERO,
520 #ifdef CONFIG_CMD_ETHSW
521 /* Get egress tagging configuration for a VSC9953 port */
522 static int vsc9953_port_vlan_egr_untag_get(int port_no,
523 enum egress_untag_mode *mode)
526 struct vsc9953_rew_reg *l2rew_reg;
528 /* Administrative down */
529 if (!vsc9953_l2sw.port[port_no].enabled) {
530 printf("Port %d is administrative down\n", port_no);
534 l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
537 val = in_le32(&l2rew_reg->port[port_no].port_tag_cfg);
539 switch (val & VSC9953_TAG_CFG_MASK) {
540 case VSC9953_TAG_CFG_NONE:
541 *mode = EGRESS_UNTAG_ALL;
543 case VSC9953_TAG_CFG_ALL_BUT_PVID_ZERO:
544 *mode = EGRESS_UNTAG_PVID_AND_ZERO;
546 case VSC9953_TAG_CFG_ALL_BUT_ZERO:
547 *mode = EGRESS_UNTAG_ZERO;
549 case VSC9953_TAG_CFG_ALL:
550 *mode = EGRESS_UNTAG_NONE;
553 printf("Unknown egress tagging configuration for port %d\n",
559 /* Show egress tagging configuration for a VSC9953 port */
560 static void vsc9953_port_vlan_egr_untag_show(int port_no)
562 enum egress_untag_mode mode;
564 if (vsc9953_port_vlan_egr_untag_get(port_no, &mode)) {
565 printf("%7d\t%17s\n", port_no, "-");
569 printf("%7d\t", port_no);
571 case EGRESS_UNTAG_ALL:
572 printf("%17s\n", "all");
574 case EGRESS_UNTAG_NONE:
575 printf("%17s\n", "none");
577 case EGRESS_UNTAG_PVID_AND_ZERO:
578 printf("%17s\n", "PVID and 0");
580 case EGRESS_UNTAG_ZERO:
581 printf("%17s\n", "0");
584 printf("%17s\n", "-");
589 static void vsc9953_port_vlan_egr_untag_set(int port_no,
590 enum egress_untag_mode mode)
592 struct vsc9953_rew_reg *l2rew_reg;
594 /* Administrative down */
595 if (!vsc9953_l2sw.port[port_no].enabled) {
596 printf("Port %d is administrative down\n", port_no);
600 l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
604 case EGRESS_UNTAG_ALL:
605 clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
606 VSC9953_TAG_CFG_MASK, VSC9953_TAG_CFG_NONE);
608 case EGRESS_UNTAG_PVID_AND_ZERO:
609 clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
610 VSC9953_TAG_CFG_MASK,
611 VSC9953_TAG_CFG_ALL_BUT_PVID_ZERO);
613 case EGRESS_UNTAG_ZERO:
614 clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
615 VSC9953_TAG_CFG_MASK,
616 VSC9953_TAG_CFG_ALL_BUT_ZERO);
618 case EGRESS_UNTAG_NONE:
619 clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
620 VSC9953_TAG_CFG_MASK, VSC9953_TAG_CFG_ALL);
623 printf("Unknown untag mode for port %d\n", port_no);
627 static void vsc9953_port_all_vlan_egress_untagged_set(
628 enum egress_untag_mode mode)
632 for (i = 0; i < VSC9953_MAX_PORTS; i++)
633 vsc9953_port_vlan_egr_untag_set(i, mode);
636 static int vsc9953_autoage_time_set(int age_period)
639 struct vsc9953_analyzer *l2ana_reg;
641 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
644 if (age_period < 0 || age_period > VSC9953_AUTOAGE_PERIOD_MASK)
647 autoage = bitfield_replace_by_mask(in_le32(&l2ana_reg->ana.auto_age),
648 VSC9953_AUTOAGE_PERIOD_MASK,
650 out_le32(&l2ana_reg->ana.auto_age, autoage);
655 #ifdef CONFIG_CMD_ETHSW
657 /* Enable/disable status of a VSC9953 port */
658 static void vsc9953_port_status_set(int port_no, u8 enabled)
660 struct vsc9953_qsys_reg *l2qsys_reg;
662 /* Administrative down */
663 if (!vsc9953_l2sw.port[port_no].enabled)
666 l2qsys_reg = (struct vsc9953_qsys_reg *)(VSC9953_OFFSET +
667 VSC9953_QSYS_OFFSET);
670 setbits_le32(&l2qsys_reg->sys.switch_port_mode[port_no],
673 clrbits_le32(&l2qsys_reg->sys.switch_port_mode[port_no],
677 /* Start autonegotiation for a VSC9953 PHY */
678 static void vsc9953_phy_autoneg(int port_no)
680 if (!vsc9953_l2sw.port[port_no].phydev)
683 if (vsc9953_l2sw.port[port_no].phydev->drv->startup(
684 vsc9953_l2sw.port[port_no].phydev))
685 printf("Failed to start PHY for port %d\n", port_no);
688 /* Print a VSC9953 port's configuration */
689 static void vsc9953_port_config_show(int port_no)
696 struct vsc9953_qsys_reg *l2qsys_reg;
698 l2qsys_reg = (struct vsc9953_qsys_reg *)(VSC9953_OFFSET +
699 VSC9953_QSYS_OFFSET);
701 val = in_le32(&l2qsys_reg->sys.switch_port_mode[port_no]);
702 enabled = vsc9953_l2sw.port[port_no].enabled &&
703 (val & VSC9953_PORT_ENA);
705 /* internal ports (8 and 9) are fixed */
706 if (VSC9953_INTERNAL_PORT_CHECK(port_no)) {
709 duplex = DUPLEX_FULL;
711 if (vsc9953_l2sw.port[port_no].phydev) {
712 link = vsc9953_l2sw.port[port_no].phydev->link;
713 speed = vsc9953_l2sw.port[port_no].phydev->speed;
714 duplex = vsc9953_l2sw.port[port_no].phydev->duplex;
722 printf("%8d ", port_no);
723 printf("%8s ", enabled == 1 ? "enabled" : "disabled");
724 printf("%8s ", link == 1 ? "up" : "down");
734 printf("%8d ", 1000);
737 printf("%8d ", 2500);
740 printf("%8d ", 10000);
746 printf("%8s\n", duplex == DUPLEX_FULL ? "full" : "half");
749 /* Show VSC9953 ports' statistics */
750 static void vsc9953_port_statistics_show(int port_no)
754 struct vsc9953_system_reg *l2sys_reg;
756 /* Administrative down */
757 if (!vsc9953_l2sw.port[port_no].enabled) {
758 printf("Port %d is administrative down\n", port_no);
762 l2sys_reg = (struct vsc9953_system_reg *)(VSC9953_OFFSET +
765 printf("Statistics for L2 Switch port %d:\n", port_no);
767 /* Set counter view for our port */
768 out_le32(&l2sys_reg->sys.stat_cfg, port_no);
770 #define VSC9953_STATS_PRINTF "%-15s %10u"
772 /* Get number of Rx and Tx frames */
773 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_short) +
774 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_frag) +
775 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_jabber) +
776 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_long) +
777 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_64) +
778 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_65_127) +
779 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_128_255) +
780 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_256_511) +
781 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_512_1023) +
782 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_1024_1526) +
783 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_jumbo);
784 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_64) +
785 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_65_127) +
786 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_128_255) +
787 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_256_511) +
788 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_512_1023) +
789 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_1024_1526) +
790 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_jumbo);
791 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
792 "Rx frames:", rx_val, "Tx frames:", tx_val);
794 /* Get number of Rx and Tx bytes */
795 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_oct);
796 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_oct);
797 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
798 "Rx bytes:", rx_val, "Tx bytes:", tx_val);
800 /* Get number of Rx frames received ok and Tx frames sent ok */
801 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_0) +
802 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_1) +
803 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_2) +
804 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_3) +
805 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_4) +
806 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_5) +
807 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_6) +
808 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_7) +
809 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_0) +
810 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_1) +
811 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_2) +
812 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_3) +
813 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_4) +
814 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_5) +
815 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_6) +
816 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_7);
817 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_64) +
818 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_65_127) +
819 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_128_255) +
820 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_256_511) +
821 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_512_1023) +
822 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_1024_1526) +
823 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_jumbo);
824 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
825 "Rx frames ok:", rx_val, "Tx frames ok:", tx_val);
827 /* Get number of Rx and Tx unicast frames */
828 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_uc);
829 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_uc);
830 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
831 "Rx unicast:", rx_val, "Tx unicast:", tx_val);
833 /* Get number of Rx and Tx broadcast frames */
834 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_bc);
835 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_bc);
836 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
837 "Rx broadcast:", rx_val, "Tx broadcast:", tx_val);
839 /* Get number of Rx and Tx frames of 64B */
840 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_64);
841 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_64);
842 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
843 "Rx 64B:", rx_val, "Tx 64B:", tx_val);
845 /* Get number of Rx and Tx frames with sizes between 65B and 127B */
846 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_65_127);
847 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_65_127);
848 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
849 "Rx 65B-127B:", rx_val, "Tx 65B-127B:", tx_val);
851 /* Get number of Rx and Tx frames with sizes between 128B and 255B */
852 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_128_255);
853 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_128_255);
854 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
855 "Rx 128B-255B:", rx_val, "Tx 128B-255B:", tx_val);
857 /* Get number of Rx and Tx frames with sizes between 256B and 511B */
858 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_256_511);
859 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_256_511);
860 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
861 "Rx 256B-511B:", rx_val, "Tx 256B-511B:", tx_val);
863 /* Get number of Rx and Tx frames with sizes between 512B and 1023B */
864 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_512_1023);
865 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_512_1023);
866 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
867 "Rx 512B-1023B:", rx_val, "Tx 512B-1023B:", tx_val);
869 /* Get number of Rx and Tx frames with sizes between 1024B and 1526B */
870 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_1024_1526);
871 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_1024_1526);
872 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
873 "Rx 1024B-1526B:", rx_val, "Tx 1024B-1526B:", tx_val);
875 /* Get number of Rx and Tx jumbo frames */
876 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_jumbo);
877 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_jumbo);
878 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
879 "Rx jumbo:", rx_val, "Tx jumbo:", tx_val);
881 /* Get number of Rx and Tx dropped frames */
882 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_cat_drop) +
883 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_tail) +
884 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_0) +
885 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_1) +
886 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_2) +
887 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_3) +
888 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_4) +
889 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_5) +
890 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_6) +
891 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_7) +
892 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_0) +
893 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_1) +
894 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_2) +
895 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_3) +
896 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_4) +
897 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_5) +
898 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_6) +
899 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_7);
900 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_drop) +
901 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_aged);
902 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
903 "Rx drops:", rx_val, "Tx drops:", tx_val);
906 * Get number of Rx frames with CRC or alignment errors
907 * and number of detected Tx collisions
909 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_crc);
910 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_col);
911 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
912 "Rx CRC&align:", rx_val, "Tx coll:", tx_val);
915 * Get number of Rx undersized frames and
916 * number of Tx aged frames
918 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_short);
919 tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_aged);
920 printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
921 "Rx undersize:", rx_val, "Tx aged:", tx_val);
923 /* Get number of Rx oversized frames */
924 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_long);
925 printf(VSC9953_STATS_PRINTF"\n", "Rx oversized:", rx_val);
927 /* Get number of Rx fragmented frames */
928 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_frag);
929 printf(VSC9953_STATS_PRINTF"\n", "Rx fragments:", rx_val);
931 /* Get number of Rx jabber errors */
932 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_jabber);
933 printf(VSC9953_STATS_PRINTF"\n", "Rx jabbers:", rx_val);
936 * Get number of Rx frames filtered due to classification rules or
937 * no destination ports
939 rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_cat_drop) +
940 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_local);
941 printf(VSC9953_STATS_PRINTF"\n", "Rx filtered:", rx_val);
946 /* Clear statistics for a VSC9953 port */
947 static void vsc9953_port_statistics_clear(int port_no)
949 struct vsc9953_system_reg *l2sys_reg;
951 /* Administrative down */
952 if (!vsc9953_l2sw.port[port_no].enabled) {
953 printf("Port %d is administrative down\n", port_no);
957 l2sys_reg = (struct vsc9953_system_reg *)(VSC9953_OFFSET +
960 /* Clear all counter groups for our ports */
961 out_le32(&l2sys_reg->sys.stat_cfg, port_no |
962 VSC9953_STAT_CLEAR_RX | VSC9953_STAT_CLEAR_TX |
963 VSC9953_STAT_CLEAR_DR);
966 enum port_learn_mode {
971 /* Set learning configuration for a VSC9953 port */
972 static void vsc9953_port_learn_mode_set(int port_no, enum port_learn_mode mode)
974 struct vsc9953_analyzer *l2ana_reg;
976 /* Administrative down */
977 if (!vsc9953_l2sw.port[port_no].enabled) {
978 printf("Port %d is administrative down\n", port_no);
982 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
986 case PORT_LEARN_NONE:
987 clrbits_le32(&l2ana_reg->port[port_no].port_cfg,
988 VSC9953_PORT_CFG_LEARN_DROP |
989 VSC9953_PORT_CFG_LEARN_CPU |
990 VSC9953_PORT_CFG_LEARN_AUTO |
991 VSC9953_PORT_CFG_LEARN_ENA);
993 case PORT_LEARN_AUTO:
994 clrsetbits_le32(&l2ana_reg->port[port_no].port_cfg,
995 VSC9953_PORT_CFG_LEARN_DROP |
996 VSC9953_PORT_CFG_LEARN_CPU,
997 VSC9953_PORT_CFG_LEARN_ENA |
998 VSC9953_PORT_CFG_LEARN_AUTO);
1001 printf("Unknown learn mode for port %d\n", port_no);
1005 /* Get learning configuration for a VSC9953 port */
1006 static int vsc9953_port_learn_mode_get(int port_no, enum port_learn_mode *mode)
1009 struct vsc9953_analyzer *l2ana_reg;
1011 /* Administrative down */
1012 if (!vsc9953_l2sw.port[port_no].enabled) {
1013 printf("Port %d is administrative down\n", port_no);
1017 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1018 VSC9953_ANA_OFFSET);
1020 /* For now we only support HW learning (auto) and no learning */
1021 val = in_le32(&l2ana_reg->port[port_no].port_cfg);
1022 if ((val & (VSC9953_PORT_CFG_LEARN_ENA |
1023 VSC9953_PORT_CFG_LEARN_AUTO)) ==
1024 (VSC9953_PORT_CFG_LEARN_ENA | VSC9953_PORT_CFG_LEARN_AUTO))
1025 *mode = PORT_LEARN_AUTO;
1027 *mode = PORT_LEARN_NONE;
1032 /* wait for FDB to become available */
1033 static int vsc9953_mac_table_poll_idle(void)
1035 struct vsc9953_analyzer *l2ana_reg;
1038 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1039 VSC9953_ANA_OFFSET);
1042 while (((in_le32(&l2ana_reg->ana_tables.mac_access) &
1043 VSC9953_MAC_CMD_MASK) !=
1044 VSC9953_MAC_CMD_IDLE) && --timeout)
1047 return timeout ? 0 : -EBUSY;
1050 /* enum describing available commands for the MAC table */
1051 enum mac_table_cmd {
1061 /* Issues a command to the FDB table */
1062 static int vsc9953_mac_table_cmd(enum mac_table_cmd cmd)
1064 struct vsc9953_analyzer *l2ana_reg;
1066 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1067 VSC9953_ANA_OFFSET);
1070 case MAC_TABLE_READ:
1071 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1072 VSC9953_MAC_CMD_MASK | VSC9953_MAC_CMD_VALID,
1073 VSC9953_MAC_CMD_READ);
1075 case MAC_TABLE_LOOKUP:
1076 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1077 VSC9953_MAC_CMD_MASK, VSC9953_MAC_CMD_READ |
1078 VSC9953_MAC_CMD_VALID);
1080 case MAC_TABLE_WRITE:
1081 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1082 VSC9953_MAC_CMD_MASK |
1083 VSC9953_MAC_ENTRYTYPE_MASK,
1084 VSC9953_MAC_CMD_WRITE |
1085 VSC9953_MAC_ENTRYTYPE_LOCKED);
1087 case MAC_TABLE_LEARN:
1088 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1089 VSC9953_MAC_CMD_MASK |
1090 VSC9953_MAC_ENTRYTYPE_MASK,
1091 VSC9953_MAC_CMD_LEARN |
1092 VSC9953_MAC_ENTRYTYPE_LOCKED |
1093 VSC9953_MAC_CMD_VALID);
1095 case MAC_TABLE_FORGET:
1096 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1097 VSC9953_MAC_CMD_MASK |
1098 VSC9953_MAC_ENTRYTYPE_MASK,
1099 VSC9953_MAC_CMD_FORGET);
1101 case MAC_TABLE_GET_NEXT:
1102 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1103 VSC9953_MAC_CMD_MASK |
1104 VSC9953_MAC_ENTRYTYPE_MASK,
1105 VSC9953_MAC_CMD_NEXT);
1108 clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
1109 VSC9953_MAC_CMD_MASK |
1110 VSC9953_MAC_ENTRYTYPE_MASK,
1111 VSC9953_MAC_CMD_AGE);
1114 printf("Unknown MAC table command\n");
1117 if (vsc9953_mac_table_poll_idle() < 0) {
1118 debug("MAC table timeout\n");
1125 /* show the FDB entries that correspond to a port and a VLAN */
1126 static void vsc9953_mac_table_show(int port_no, int vid)
1128 int rc[VSC9953_MAX_PORTS];
1129 enum port_learn_mode mode[VSC9953_MAX_PORTS];
1136 struct vsc9953_analyzer *l2ana_reg;
1138 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1139 VSC9953_ANA_OFFSET);
1141 /* disable auto learning */
1142 if (port_no == ETHSW_CMD_PORT_ALL) {
1143 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1144 rc[i] = vsc9953_port_learn_mode_get(i, &mode[i]);
1145 if (!rc[i] && mode[i] != PORT_LEARN_NONE)
1146 vsc9953_port_learn_mode_set(i, PORT_LEARN_NONE);
1149 rc[port_no] = vsc9953_port_learn_mode_get(port_no,
1151 if (!rc[port_no] && mode[port_no] != PORT_LEARN_NONE)
1152 vsc9953_port_learn_mode_set(port_no, PORT_LEARN_NONE);
1155 /* write port and vid to get selected FDB entries */
1156 val = in_le32(&l2ana_reg->ana.anag_efil);
1157 if (port_no != ETHSW_CMD_PORT_ALL) {
1158 val = bitfield_replace_by_mask(val, VSC9953_AGE_PORT_MASK,
1159 port_no) | VSC9953_AGE_PORT_EN;
1161 if (vid != ETHSW_CMD_VLAN_ALL) {
1162 val = bitfield_replace_by_mask(val, VSC9953_AGE_VID_MASK,
1163 vid) | VSC9953_AGE_VID_EN;
1165 out_le32(&l2ana_reg->ana.anag_efil, val);
1167 /* set MAC and VLAN to 0 to look from beginning */
1168 clrbits_le32(&l2ana_reg->ana_tables.mach_data,
1169 VSC9953_MAC_VID_MASK | VSC9953_MAC_MACH_MASK);
1170 out_le32(&l2ana_reg->ana_tables.macl_data, 0);
1173 printf("%10s %17s %5s %4s\n", "EntryType", "MAC", "PORT", "VID");
1175 if (vsc9953_mac_table_cmd(MAC_TABLE_GET_NEXT) < 0) {
1176 debug("GET NEXT MAC table command failed\n");
1180 val = in_le32(&l2ana_reg->ana_tables.mac_access);
1182 /* get out when an invalid entry is found */
1183 if (!(val & VSC9953_MAC_CMD_VALID))
1186 switch (val & VSC9953_MAC_ENTRYTYPE_MASK) {
1187 case VSC9953_MAC_ENTRYTYPE_NORMAL:
1188 printf("%10s ", "Dynamic");
1190 case VSC9953_MAC_ENTRYTYPE_LOCKED:
1191 printf("%10s ", "Static");
1193 case VSC9953_MAC_ENTRYTYPE_IPV4MCAST:
1194 printf("%10s ", "IPv4 Mcast");
1196 case VSC9953_MAC_ENTRYTYPE_IPV6MCAST:
1197 printf("%10s ", "IPv6 Mcast");
1200 printf("%10s ", "Unknown");
1203 dest_indx = bitfield_extract_by_mask(val,
1204 VSC9953_MAC_DESTIDX_MASK);
1206 val = in_le32(&l2ana_reg->ana_tables.mach_data);
1207 vlan = bitfield_extract_by_mask(val, VSC9953_MAC_VID_MASK);
1208 mach = bitfield_extract_by_mask(val, VSC9953_MAC_MACH_MASK);
1209 macl = in_le32(&l2ana_reg->ana_tables.macl_data);
1211 printf("%02x:%02x:%02x:%02x:%02x:%02x ", (mach >> 8) & 0xff,
1212 mach & 0xff, (macl >> 24) & 0xff, (macl >> 16) & 0xff,
1213 (macl >> 8) & 0xff, macl & 0xff);
1214 printf("%5d ", dest_indx);
1215 printf("%4d\n", vlan);
1218 /* set learning mode to previous value */
1219 if (port_no == ETHSW_CMD_PORT_ALL) {
1220 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1221 if (!rc[i] && mode[i] != PORT_LEARN_NONE)
1222 vsc9953_port_learn_mode_set(i, mode[i]);
1225 /* If administrative down, skip */
1226 if (!rc[port_no] && mode[port_no] != PORT_LEARN_NONE)
1227 vsc9953_port_learn_mode_set(port_no, mode[port_no]);
1230 /* reset FDB port and VLAN FDB selection */
1231 clrbits_le32(&l2ana_reg->ana.anag_efil, VSC9953_AGE_PORT_EN |
1232 VSC9953_AGE_PORT_MASK | VSC9953_AGE_VID_EN |
1233 VSC9953_AGE_VID_MASK);
1236 /* Add a static FDB entry */
1237 static int vsc9953_mac_table_add(u8 port_no, uchar mac[6], int vid)
1240 struct vsc9953_analyzer *l2ana_reg;
1242 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1243 VSC9953_ANA_OFFSET);
1245 val = in_le32(&l2ana_reg->ana_tables.mach_data);
1246 val = bitfield_replace_by_mask(val, VSC9953_MACHDATA_VID_MASK, vid) |
1247 (mac[0] << 8) | (mac[1] << 0);
1248 out_le32(&l2ana_reg->ana_tables.mach_data, val);
1250 out_le32(&l2ana_reg->ana_tables.macl_data,
1251 (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) |
1254 /* set on which port is the MAC address added */
1255 val = in_le32(&l2ana_reg->ana_tables.mac_access);
1256 val = bitfield_replace_by_mask(val, VSC9953_MAC_DESTIDX_MASK, port_no);
1257 out_le32(&l2ana_reg->ana_tables.mac_access, val);
1259 if (vsc9953_mac_table_cmd(MAC_TABLE_LEARN) < 0)
1262 /* check if the MAC address was indeed added */
1263 val = in_le32(&l2ana_reg->ana_tables.mach_data);
1264 val = bitfield_replace_by_mask(val, VSC9953_MACHDATA_VID_MASK, vid) |
1265 (mac[0] << 8) | (mac[1] << 0);
1266 out_le32(&l2ana_reg->ana_tables.mach_data, val);
1268 out_le32(&l2ana_reg->ana_tables.macl_data,
1269 (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) |
1272 if (vsc9953_mac_table_cmd(MAC_TABLE_READ) < 0)
1275 val = in_le32(&l2ana_reg->ana_tables.mac_access);
1277 if ((port_no != bitfield_extract_by_mask(val,
1278 VSC9953_MAC_DESTIDX_MASK))) {
1279 printf("Failed to add MAC address\n");
1285 /* Delete a FDB entry */
1286 static int vsc9953_mac_table_del(uchar mac[6], u16 vid)
1289 struct vsc9953_analyzer *l2ana_reg;
1291 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1292 VSC9953_ANA_OFFSET);
1294 /* check first if MAC entry is present */
1295 val = in_le32(&l2ana_reg->ana_tables.mach_data);
1296 val = bitfield_replace_by_mask(val, VSC9953_MACHDATA_VID_MASK, vid) |
1297 (mac[0] << 8) | (mac[1] << 0);
1298 out_le32(&l2ana_reg->ana_tables.mach_data, val);
1300 out_le32(&l2ana_reg->ana_tables.macl_data,
1301 (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) |
1304 if (vsc9953_mac_table_cmd(MAC_TABLE_LOOKUP) < 0) {
1305 debug("Lookup in the MAC table failed\n");
1309 if (!(in_le32(&l2ana_reg->ana_tables.mac_access) &
1310 VSC9953_MAC_CMD_VALID)) {
1311 printf("The MAC address: %02x:%02x:%02x:%02x:%02x:%02x ",
1312 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
1313 printf("VLAN: %d does not exist.\n", vid);
1317 /* FDB entry found, proceed to delete */
1318 val = in_le32(&l2ana_reg->ana_tables.mach_data);
1319 val = bitfield_replace_by_mask(val, VSC9953_MACHDATA_VID_MASK, vid) |
1320 (mac[0] << 8) | (mac[1] << 0);
1321 out_le32(&l2ana_reg->ana_tables.mach_data, val);
1323 out_le32(&l2ana_reg->ana_tables.macl_data, (mac[2] << 24) |
1324 (mac[3] << 16) | (mac[4] << 8) | (mac[5] << 0));
1326 if (vsc9953_mac_table_cmd(MAC_TABLE_FORGET) < 0)
1329 /* check if the MAC entry is still in FDB */
1330 val = in_le32(&l2ana_reg->ana_tables.mach_data);
1331 val = bitfield_replace_by_mask(val, VSC9953_MACHDATA_VID_MASK, vid) |
1332 (mac[0] << 8) | (mac[1] << 0);
1333 out_le32(&l2ana_reg->ana_tables.mach_data, val);
1335 out_le32(&l2ana_reg->ana_tables.macl_data, (mac[2] << 24) |
1336 (mac[3] << 16) | (mac[4] << 8) | (mac[5] << 0));
1338 if (vsc9953_mac_table_cmd(MAC_TABLE_LOOKUP) < 0) {
1339 debug("Lookup in the MAC table failed\n");
1342 if (in_le32(&l2ana_reg->ana_tables.mac_access) &
1343 VSC9953_MAC_CMD_VALID) {
1344 printf("Failed to delete MAC address\n");
1351 /* age the unlocked entries in FDB */
1352 static void vsc9953_mac_table_age(int port_no, int vid)
1354 int rc[VSC9953_MAX_PORTS];
1355 enum port_learn_mode mode[VSC9953_MAX_PORTS];
1358 struct vsc9953_analyzer *l2ana_reg;
1360 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1361 VSC9953_ANA_OFFSET);
1363 /* set port and VID for selective aging */
1364 val = in_le32(&l2ana_reg->ana.anag_efil);
1365 if (port_no != ETHSW_CMD_PORT_ALL) {
1366 /* disable auto learning */
1367 rc[port_no] = vsc9953_port_learn_mode_get(port_no,
1369 if (!rc[port_no] && mode[port_no] != PORT_LEARN_NONE)
1370 vsc9953_port_learn_mode_set(port_no, PORT_LEARN_NONE);
1372 val = bitfield_replace_by_mask(val, VSC9953_AGE_PORT_MASK,
1373 port_no) | VSC9953_AGE_PORT_EN;
1375 /* disable auto learning on all ports */
1376 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1377 rc[i] = vsc9953_port_learn_mode_get(i, &mode[i]);
1378 if (!rc[i] && mode[i] != PORT_LEARN_NONE)
1379 vsc9953_port_learn_mode_set(i, PORT_LEARN_NONE);
1383 if (vid != ETHSW_CMD_VLAN_ALL) {
1384 val = bitfield_replace_by_mask(val, VSC9953_AGE_VID_MASK, vid) |
1387 out_le32(&l2ana_reg->ana.anag_efil, val);
1389 /* age the dynamic FDB entries */
1390 vsc9953_mac_table_cmd(MAC_TABLE_AGE);
1392 /* clear previously set port and VID */
1393 clrbits_le32(&l2ana_reg->ana.anag_efil, VSC9953_AGE_PORT_EN |
1394 VSC9953_AGE_PORT_MASK | VSC9953_AGE_VID_EN |
1395 VSC9953_AGE_VID_MASK);
1397 if (port_no != ETHSW_CMD_PORT_ALL) {
1398 if (!rc[port_no] && mode[port_no] != PORT_LEARN_NONE)
1399 vsc9953_port_learn_mode_set(port_no, mode[port_no]);
1401 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1402 if (!rc[i] && mode[i] != PORT_LEARN_NONE)
1403 vsc9953_port_learn_mode_set(i, mode[i]);
1408 /* Delete all the dynamic FDB entries */
1409 static void vsc9953_mac_table_flush(int port, int vid)
1411 vsc9953_mac_table_age(port, vid);
1412 vsc9953_mac_table_age(port, vid);
1415 enum egress_vlan_tag {
1420 /* Set egress tag mode for a VSC9953 port */
1421 static void vsc9953_port_vlan_egress_tag_set(int port_no,
1422 enum egress_vlan_tag mode)
1424 struct vsc9953_rew_reg *l2rew_reg;
1426 l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
1427 VSC9953_REW_OFFSET);
1431 clrbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
1432 VSC9953_TAG_VID_PVID);
1435 setbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
1436 VSC9953_TAG_VID_PVID);
1439 printf("Unknown egress VLAN tag mode for port %d\n", port_no);
1443 /* Get egress tag mode for a VSC9953 port */
1444 static void vsc9953_port_vlan_egress_tag_get(int port_no,
1445 enum egress_vlan_tag *mode)
1448 struct vsc9953_rew_reg *l2rew_reg;
1450 l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
1451 VSC9953_REW_OFFSET);
1453 val = in_le32(&l2rew_reg->port[port_no].port_tag_cfg);
1454 if (val & VSC9953_TAG_VID_PVID)
1455 *mode = EGR_TAG_PVID;
1457 *mode = EGR_TAG_CLASS;
1460 /* VSC9953 VLAN learning modes */
1461 enum vlan_learning_mode {
1462 SHARED_VLAN_LEARNING,
1463 PRIVATE_VLAN_LEARNING,
1466 /* Set VLAN learning mode for VSC9953 */
1467 static void vsc9953_vlan_learning_set(enum vlan_learning_mode lrn_mode)
1469 struct vsc9953_analyzer *l2ana_reg;
1471 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1472 VSC9953_ANA_OFFSET);
1475 case SHARED_VLAN_LEARNING:
1476 setbits_le32(&l2ana_reg->ana.agen_ctrl, VSC9953_FID_MASK_ALL);
1478 case PRIVATE_VLAN_LEARNING:
1479 clrbits_le32(&l2ana_reg->ana.agen_ctrl, VSC9953_FID_MASK_ALL);
1482 printf("Unknown VLAN learn mode\n");
1486 /* Get VLAN learning mode for VSC9953 */
1487 static int vsc9953_vlan_learning_get(enum vlan_learning_mode *lrn_mode)
1490 struct vsc9953_analyzer *l2ana_reg;
1492 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1493 VSC9953_ANA_OFFSET);
1495 val = in_le32(&l2ana_reg->ana.agen_ctrl);
1497 if (!(val & VSC9953_FID_MASK_ALL)) {
1498 *lrn_mode = PRIVATE_VLAN_LEARNING;
1499 } else if ((val & VSC9953_FID_MASK_ALL) == VSC9953_FID_MASK_ALL) {
1500 *lrn_mode = SHARED_VLAN_LEARNING;
1502 printf("Unknown VLAN learning mode\n");
1509 /* Enable/disable VLAN ingress filtering on a VSC9953 port */
1510 static void vsc9953_port_ingress_filtering_set(int port_no, int enabled)
1512 struct vsc9953_analyzer *l2ana_reg;
1514 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1515 VSC9953_ANA_OFFSET);
1518 setbits_le32(&l2ana_reg->ana.vlan_mask, 1 << port_no);
1520 clrbits_le32(&l2ana_reg->ana.vlan_mask, 1 << port_no);
1523 /* Return VLAN ingress filtering on a VSC9953 port */
1524 static int vsc9953_port_ingress_filtering_get(int port_no)
1527 struct vsc9953_analyzer *l2ana_reg;
1529 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1530 VSC9953_ANA_OFFSET);
1532 val = in_le32(&l2ana_reg->ana.vlan_mask);
1533 return !!(val & (1 << port_no));
1536 /* Get the aggregation group of a port */
1537 static int vsc9953_port_aggr_grp_get(int port_no, int *aggr_grp)
1540 struct vsc9953_analyzer *l2ana_reg;
1542 if (!VSC9953_PORT_CHECK(port_no))
1545 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1546 VSC9953_ANA_OFFSET);
1548 val = in_le32(&l2ana_reg->port[port_no].port_cfg);
1549 *aggr_grp = bitfield_extract_by_mask(val,
1550 VSC9953_PORT_CFG_PORTID_MASK);
1555 static void vsc9953_aggr_grp_members_get(int aggr_grp,
1556 u8 aggr_membr[VSC9953_MAX_PORTS])
1561 for (port_no = 0; port_no < VSC9953_MAX_PORTS; port_no++) {
1562 aggr_membr[port_no] = 0;
1564 if (vsc9953_port_aggr_grp_get(port_no, &aggr_membr_grp))
1567 if (aggr_grp == aggr_membr_grp)
1568 aggr_membr[port_no] = 1;
1572 static void vsc9953_update_dest_members_masks(int port_no, u32 membr_bitfld_old,
1573 u32 membr_bitfld_new)
1577 struct vsc9953_analyzer *l2ana_reg;
1579 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1580 VSC9953_ANA_OFFSET);
1583 * NOTE: Only the unicast destination masks are updated, since
1584 * we do not support for now Layer-2 multicast entries
1586 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1588 clrsetbits_le32(&l2ana_reg->port_id_tbl.port_grp_id[i],
1589 VSC9953_PGID_PORT_MASK,
1594 pgid = in_le32(&l2ana_reg->port_id_tbl.port_grp_id[i]);
1595 if ((u32)(1 << i) & membr_bitfld_old & VSC9953_PGID_PORT_MASK)
1596 pgid &= ~((u32)(1 << port_no));
1597 if ((u32)(1 << i) & membr_bitfld_new & VSC9953_PGID_PORT_MASK)
1598 pgid |= ((u32)(1 << port_no));
1600 out_le32(&l2ana_reg->port_id_tbl.port_grp_id[i], pgid);
1604 static void vsc9953_update_source_members_masks(int port_no,
1605 u32 membr_bitfld_old,
1606 u32 membr_bitfld_new)
1611 struct vsc9953_analyzer *l2ana_reg;
1613 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1614 VSC9953_ANA_OFFSET);
1616 for (i = 0; i < VSC9953_MAX_PORTS + 1; i++) {
1617 index = PGID_SRC_START + i;
1618 pgid = in_le32(&l2ana_reg->port_id_tbl.port_grp_id[index]);
1620 pgid = (pgid | VSC9953_PGID_PORT_MASK) &
1622 out_le32(&l2ana_reg->port_id_tbl.port_grp_id[index],
1627 if ((u32)(1 << i) & membr_bitfld_old & VSC9953_PGID_PORT_MASK)
1628 pgid |= (u32)(1 << port_no);
1630 if ((u32)(1 << i) & membr_bitfld_new & VSC9953_PGID_PORT_MASK)
1631 pgid &= ~(u32)(1 << port_no);
1632 out_le32(&l2ana_reg->port_id_tbl.port_grp_id[index], pgid);
1636 static u32 vsc9953_aggr_mask_get_next(u32 aggr_mask, u32 member_bitfield)
1638 if (!member_bitfield)
1641 if (!(aggr_mask & VSC9953_PGID_PORT_MASK))
1646 while (!(aggr_mask & member_bitfield)) {
1648 if (!(aggr_mask & VSC9953_PGID_PORT_MASK))
1655 static void vsc9953_update_aggr_members_masks(int port_no, u32 membr_bitfld_old,
1656 u32 membr_bitfld_new)
1660 u32 aggr_mask_old = 0;
1661 u32 aggr_mask_new = 0;
1662 struct vsc9953_analyzer *l2ana_reg;
1664 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1665 VSC9953_ANA_OFFSET);
1667 /* Update all the PGID aggregation masks */
1668 for (i = PGID_AGGR_START; i < PGID_SRC_START; i++) {
1669 pgid = in_le32(&l2ana_reg->port_id_tbl.port_grp_id[i]);
1671 aggr_mask_old = vsc9953_aggr_mask_get_next(aggr_mask_old,
1673 pgid = (pgid & ~membr_bitfld_old) | aggr_mask_old;
1675 aggr_mask_new = vsc9953_aggr_mask_get_next(aggr_mask_new,
1677 pgid = (pgid & ~membr_bitfld_new) | aggr_mask_new;
1679 out_le32(&l2ana_reg->port_id_tbl.port_grp_id[i], pgid);
1683 static u32 vsc9953_aggr_membr_bitfield_get(u8 member[VSC9953_MAX_PORTS])
1686 u32 member_bitfield = 0;
1688 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1690 member_bitfield |= 1 << i;
1692 member_bitfield &= VSC9953_PGID_PORT_MASK;
1694 return member_bitfield;
1697 static void vsc9953_update_members_masks(int port_no,
1698 u8 member_old[VSC9953_MAX_PORTS],
1699 u8 member_new[VSC9953_MAX_PORTS])
1701 u32 membr_bitfld_old = vsc9953_aggr_membr_bitfield_get(member_old);
1702 u32 membr_bitfld_new = vsc9953_aggr_membr_bitfield_get(member_new);
1704 vsc9953_update_dest_members_masks(port_no, membr_bitfld_old,
1706 vsc9953_update_source_members_masks(port_no, membr_bitfld_old,
1708 vsc9953_update_aggr_members_masks(port_no, membr_bitfld_old,
1712 /* Set the aggregation group of a port */
1713 static int vsc9953_port_aggr_grp_set(int port_no, int aggr_grp)
1715 u8 aggr_membr_old[VSC9953_MAX_PORTS];
1716 u8 aggr_membr_new[VSC9953_MAX_PORTS];
1720 struct vsc9953_analyzer *l2ana_reg;
1722 if (!VSC9953_PORT_CHECK(port_no) || !VSC9953_PORT_CHECK(aggr_grp))
1725 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
1726 VSC9953_ANA_OFFSET);
1728 rc = vsc9953_port_aggr_grp_get(port_no, &aggr_grp_old);
1732 /* get all the members of the old aggregation group */
1733 vsc9953_aggr_grp_members_get(aggr_grp_old, aggr_membr_old);
1735 /* get all the members of the same aggregation group */
1736 vsc9953_aggr_grp_members_get(aggr_grp, aggr_membr_new);
1738 /* add current port as member to the new aggregation group */
1739 aggr_membr_old[port_no] = 0;
1740 aggr_membr_new[port_no] = 1;
1743 vsc9953_update_members_masks(port_no, aggr_membr_old, aggr_membr_new);
1745 /* Change logical port number */
1746 val = in_le32(&l2ana_reg->port[port_no].port_cfg);
1747 val = bitfield_replace_by_mask(val,
1748 VSC9953_PORT_CFG_PORTID_MASK, aggr_grp);
1749 out_le32(&l2ana_reg->port[port_no].port_cfg, val);
1754 static int vsc9953_port_status_key_func(struct ethsw_command_def *parsed_cmd)
1759 /* Last keyword should tell us if we should enable/disable the port */
1760 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1763 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1767 return CMD_RET_USAGE;
1769 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1770 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1771 printf("Invalid port number: %d\n", parsed_cmd->port);
1772 return CMD_RET_FAILURE;
1774 vsc9953_port_status_set(parsed_cmd->port, enabled);
1776 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1777 vsc9953_port_status_set(i, enabled);
1780 return CMD_RET_SUCCESS;
1783 static int vsc9953_port_config_key_func(struct ethsw_command_def *parsed_cmd)
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_phy_autoneg(parsed_cmd->port);
1793 printf("%8s %8s %8s %8s %8s\n",
1794 "Port", "Status", "Link", "Speed",
1796 vsc9953_port_config_show(parsed_cmd->port);
1799 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1800 vsc9953_phy_autoneg(i);
1801 printf("%8s %8s %8s %8s %8s\n",
1802 "Port", "Status", "Link", "Speed", "Duplex");
1803 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1804 vsc9953_port_config_show(i);
1807 return CMD_RET_SUCCESS;
1810 static int vsc9953_port_stats_key_func(struct ethsw_command_def *parsed_cmd)
1814 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1815 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1816 printf("Invalid port number: %d\n", parsed_cmd->port);
1817 return CMD_RET_FAILURE;
1819 vsc9953_port_statistics_show(parsed_cmd->port);
1821 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1822 vsc9953_port_statistics_show(i);
1825 return CMD_RET_SUCCESS;
1828 static int vsc9953_port_stats_clear_key_func(struct ethsw_command_def
1833 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1834 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1835 printf("Invalid port number: %d\n", parsed_cmd->port);
1836 return CMD_RET_FAILURE;
1838 vsc9953_port_statistics_clear(parsed_cmd->port);
1840 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1841 vsc9953_port_statistics_clear(i);
1844 return CMD_RET_SUCCESS;
1847 static int vsc9953_learn_show_key_func(struct ethsw_command_def *parsed_cmd)
1850 enum port_learn_mode mode;
1852 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1853 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1854 printf("Invalid port number: %d\n", parsed_cmd->port);
1855 return CMD_RET_FAILURE;
1857 if (vsc9953_port_learn_mode_get(parsed_cmd->port, &mode))
1858 return CMD_RET_FAILURE;
1859 printf("%7s %11s\n", "Port", "Learn mode");
1861 case PORT_LEARN_NONE:
1862 printf("%7d %11s\n", parsed_cmd->port, "disable");
1864 case PORT_LEARN_AUTO:
1865 printf("%7d %11s\n", parsed_cmd->port, "auto");
1868 printf("%7d %11s\n", parsed_cmd->port, "-");
1871 printf("%7s %11s\n", "Port", "Learn mode");
1872 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
1873 if (vsc9953_port_learn_mode_get(i, &mode))
1876 case PORT_LEARN_NONE:
1877 printf("%7d %11s\n", i, "disable");
1879 case PORT_LEARN_AUTO:
1880 printf("%7d %11s\n", i, "auto");
1883 printf("%7d %11s\n", i, "-");
1888 return CMD_RET_SUCCESS;
1891 static int vsc9953_learn_set_key_func(struct ethsw_command_def *parsed_cmd)
1894 enum port_learn_mode mode;
1896 /* Last keyword should tell us the learn mode */
1897 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1899 mode = PORT_LEARN_AUTO;
1900 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
1902 mode = PORT_LEARN_NONE;
1904 return CMD_RET_USAGE;
1906 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
1907 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1908 printf("Invalid port number: %d\n", parsed_cmd->port);
1909 return CMD_RET_FAILURE;
1911 vsc9953_port_learn_mode_set(parsed_cmd->port, mode);
1913 for (i = 0; i < VSC9953_MAX_PORTS; i++)
1914 vsc9953_port_learn_mode_set(i, mode);
1917 return CMD_RET_SUCCESS;
1920 static int vsc9953_fdb_show_key_func(struct ethsw_command_def *parsed_cmd)
1922 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL &&
1923 !VSC9953_PORT_CHECK(parsed_cmd->port)) {
1924 printf("Invalid port number: %d\n", parsed_cmd->port);
1925 return CMD_RET_FAILURE;
1928 if (parsed_cmd->vid != ETHSW_CMD_VLAN_ALL &&
1929 !VSC9953_VLAN_CHECK(parsed_cmd->vid)) {
1930 printf("Invalid VID number: %d\n", parsed_cmd->vid);
1931 return CMD_RET_FAILURE;
1934 vsc9953_mac_table_show(parsed_cmd->port, parsed_cmd->vid);
1936 return CMD_RET_SUCCESS;
1939 static int vsc9953_fdb_flush_key_func(struct ethsw_command_def *parsed_cmd)
1941 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL &&
1942 !VSC9953_PORT_CHECK(parsed_cmd->port)) {
1943 printf("Invalid port number: %d\n", parsed_cmd->port);
1944 return CMD_RET_FAILURE;
1947 if (parsed_cmd->vid != ETHSW_CMD_VLAN_ALL &&
1948 !VSC9953_VLAN_CHECK(parsed_cmd->vid)) {
1949 printf("Invalid VID number: %d\n", parsed_cmd->vid);
1950 return CMD_RET_FAILURE;
1953 vsc9953_mac_table_flush(parsed_cmd->port, parsed_cmd->vid);
1955 return CMD_RET_SUCCESS;
1958 static int vsc9953_fdb_entry_add_key_func(struct ethsw_command_def *parsed_cmd)
1962 /* a port number must be present */
1963 if (parsed_cmd->port == ETHSW_CMD_PORT_ALL) {
1964 printf("Please specify a port\n");
1965 return CMD_RET_FAILURE;
1968 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
1969 printf("Invalid port number: %d\n", parsed_cmd->port);
1970 return CMD_RET_FAILURE;
1973 /* Use VLAN 1 if VID is not set */
1974 vid = (parsed_cmd->vid == ETHSW_CMD_VLAN_ALL ? 1 : parsed_cmd->vid);
1976 if (!VSC9953_VLAN_CHECK(vid)) {
1977 printf("Invalid VID number: %d\n", vid);
1978 return CMD_RET_FAILURE;
1981 if (vsc9953_mac_table_add(parsed_cmd->port, parsed_cmd->ethaddr, vid))
1982 return CMD_RET_FAILURE;
1984 return CMD_RET_SUCCESS;
1987 static int vsc9953_fdb_entry_del_key_func(struct ethsw_command_def *parsed_cmd)
1991 /* Use VLAN 1 if VID is not set */
1992 vid = (parsed_cmd->vid == ETHSW_CMD_VLAN_ALL ? 1 : parsed_cmd->vid);
1994 if (!VSC9953_VLAN_CHECK(vid)) {
1995 printf("Invalid VID number: %d\n", vid);
1996 return CMD_RET_FAILURE;
1999 if (vsc9953_mac_table_del(parsed_cmd->ethaddr, vid))
2000 return CMD_RET_FAILURE;
2002 return CMD_RET_SUCCESS;
2005 static int vsc9953_pvid_show_key_func(struct ethsw_command_def *parsed_cmd)
2010 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2011 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2012 printf("Invalid port number: %d\n", parsed_cmd->port);
2013 return CMD_RET_FAILURE;
2016 if (vsc9953_port_vlan_pvid_get(parsed_cmd->port, &pvid))
2017 return CMD_RET_FAILURE;
2018 printf("%7s %7s\n", "Port", "PVID");
2019 printf("%7d %7d\n", parsed_cmd->port, pvid);
2021 printf("%7s %7s\n", "Port", "PVID");
2022 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
2023 if (vsc9953_port_vlan_pvid_get(i, &pvid))
2025 printf("%7d %7d\n", i, pvid);
2029 return CMD_RET_SUCCESS;
2032 static int vsc9953_pvid_set_key_func(struct ethsw_command_def *parsed_cmd)
2034 /* PVID number should be set in parsed_cmd->vid */
2035 if (parsed_cmd->vid == ETHSW_CMD_VLAN_ALL) {
2036 printf("Please set a pvid value\n");
2037 return CMD_RET_FAILURE;
2040 if (!VSC9953_VLAN_CHECK(parsed_cmd->vid)) {
2041 printf("Invalid VID number: %d\n", parsed_cmd->vid);
2042 return CMD_RET_FAILURE;
2045 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2046 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2047 printf("Invalid port number: %d\n", parsed_cmd->port);
2048 return CMD_RET_FAILURE;
2050 vsc9953_port_vlan_pvid_set(parsed_cmd->port, parsed_cmd->vid);
2052 vsc9953_port_all_vlan_pvid_set(parsed_cmd->vid);
2055 return CMD_RET_SUCCESS;
2058 static int vsc9953_vlan_show_key_func(struct ethsw_command_def *parsed_cmd)
2062 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2063 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2064 printf("Invalid port number: %d\n", parsed_cmd->port);
2065 return CMD_RET_FAILURE;
2067 vsc9953_vlan_membership_show(parsed_cmd->port);
2069 for (i = 0; i < VSC9953_MAX_PORTS; i++)
2070 vsc9953_vlan_membership_show(i);
2073 return CMD_RET_SUCCESS;
2076 static int vsc9953_vlan_set_key_func(struct ethsw_command_def *parsed_cmd)
2081 /* VLAN should be set in parsed_cmd->vid */
2082 if (parsed_cmd->vid == ETHSW_CMD_VLAN_ALL) {
2083 printf("Please set a vlan value\n");
2084 return CMD_RET_FAILURE;
2087 if (!VSC9953_VLAN_CHECK(parsed_cmd->vid)) {
2088 printf("Invalid VID number: %d\n", parsed_cmd->vid);
2089 return CMD_RET_FAILURE;
2092 /* keywords add/delete should be the last but one in array */
2093 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 2] ==
2096 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 2] ==
2100 return CMD_RET_USAGE;
2102 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2103 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2104 printf("Invalid port number: %d\n", parsed_cmd->port);
2105 return CMD_RET_FAILURE;
2107 vsc9953_vlan_table_membership_set(parsed_cmd->vid,
2108 parsed_cmd->port, add);
2110 for (i = 0; i < VSC9953_MAX_PORTS; i++)
2111 vsc9953_vlan_table_membership_set(parsed_cmd->vid, i,
2115 return CMD_RET_SUCCESS;
2117 static int vsc9953_port_untag_show_key_func(
2118 struct ethsw_command_def *parsed_cmd)
2122 printf("%7s\t%17s\n", "Port", "Untag");
2123 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2124 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2125 printf("Invalid port number: %d\n", parsed_cmd->port);
2126 return CMD_RET_FAILURE;
2128 vsc9953_port_vlan_egr_untag_show(parsed_cmd->port);
2130 for (i = 0; i < VSC9953_MAX_PORTS; i++)
2131 vsc9953_port_vlan_egr_untag_show(i);
2134 return CMD_RET_SUCCESS;
2137 static int vsc9953_port_untag_set_key_func(struct ethsw_command_def *parsed_cmd)
2140 enum egress_untag_mode mode;
2142 /* keywords for the untagged mode are the last in the array */
2143 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2145 mode = EGRESS_UNTAG_ALL;
2146 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2148 mode = EGRESS_UNTAG_NONE;
2149 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2151 mode = EGRESS_UNTAG_PVID_AND_ZERO;
2153 return CMD_RET_USAGE;
2155 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2156 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2157 printf("Invalid port number: %d\n", parsed_cmd->port);
2158 return CMD_RET_FAILURE;
2160 vsc9953_port_vlan_egr_untag_set(parsed_cmd->port, mode);
2162 for (i = 0; i < VSC9953_MAX_PORTS; i++)
2163 vsc9953_port_vlan_egr_untag_set(i, mode);
2166 return CMD_RET_SUCCESS;
2169 static int vsc9953_egr_vlan_tag_show_key_func(
2170 struct ethsw_command_def *parsed_cmd)
2173 enum egress_vlan_tag mode;
2175 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2176 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2177 printf("Invalid port number: %d\n", parsed_cmd->port);
2178 return CMD_RET_FAILURE;
2180 vsc9953_port_vlan_egress_tag_get(parsed_cmd->port, &mode);
2181 printf("%7s\t%12s\n", "Port", "Egress VID");
2182 printf("%7d\t", parsed_cmd->port);
2185 printf("%12s\n", "classified");
2188 printf("%12s\n", "pvid");
2191 printf("%12s\n", "-");
2194 printf("%7s\t%12s\n", "Port", "Egress VID");
2195 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
2196 vsc9953_port_vlan_egress_tag_get(i, &mode);
2199 printf("%7d\t%12s\n", i, "classified");
2202 printf("%7d\t%12s\n", i, "pvid");
2205 printf("%7d\t%12s\n", i, "-");
2210 return CMD_RET_SUCCESS;
2213 static int vsc9953_egr_vlan_tag_set_key_func(
2214 struct ethsw_command_def *parsed_cmd)
2217 enum egress_vlan_tag mode;
2219 /* keywords for the egress vlan tag mode are the last in the array */
2220 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2222 mode = EGR_TAG_PVID;
2223 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2224 ethsw_id_classified)
2225 mode = EGR_TAG_CLASS;
2227 return CMD_RET_USAGE;
2229 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2230 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2231 printf("Invalid port number: %d\n", parsed_cmd->port);
2232 return CMD_RET_FAILURE;
2234 vsc9953_port_vlan_egress_tag_set(parsed_cmd->port, mode);
2236 for (i = 0; i < VSC9953_MAX_PORTS; i++)
2237 vsc9953_port_vlan_egress_tag_set(i, mode);
2240 return CMD_RET_SUCCESS;
2243 static int vsc9953_vlan_learn_show_key_func(
2244 struct ethsw_command_def *parsed_cmd)
2247 enum vlan_learning_mode mode;
2249 rc = vsc9953_vlan_learning_get(&mode);
2251 return CMD_RET_FAILURE;
2254 case SHARED_VLAN_LEARNING:
2255 printf("VLAN learning mode: shared\n");
2257 case PRIVATE_VLAN_LEARNING:
2258 printf("VLAN learning mode: private\n");
2261 printf("Unknown VLAN learning mode\n");
2262 rc = CMD_RET_FAILURE;
2265 return CMD_RET_SUCCESS;
2268 static int vsc9953_vlan_learn_set_key_func(struct ethsw_command_def *parsed_cmd)
2270 enum vlan_learning_mode mode;
2272 /* keywords for shared/private are the last in the array */
2273 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2275 mode = SHARED_VLAN_LEARNING;
2276 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2278 mode = PRIVATE_VLAN_LEARNING;
2280 return CMD_RET_USAGE;
2282 vsc9953_vlan_learning_set(mode);
2284 return CMD_RET_SUCCESS;
2287 static int vsc9953_ingr_fltr_show_key_func(struct ethsw_command_def *parsed_cmd)
2292 printf("%7s\t%18s\n", "Port", "Ingress filtering");
2293 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2294 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2295 printf("Invalid port number: %d\n", parsed_cmd->port);
2296 return CMD_RET_FAILURE;
2298 enabled = vsc9953_port_ingress_filtering_get(parsed_cmd->port);
2299 printf("%7d\t%18s\n", parsed_cmd->port, enabled ? "enable" :
2302 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
2303 enabled = vsc9953_port_ingress_filtering_get(i);
2304 printf("%7d\t%18s\n", parsed_cmd->port, enabled ?
2310 return CMD_RET_SUCCESS;
2313 static int vsc9953_ingr_fltr_set_key_func(struct ethsw_command_def *parsed_cmd)
2318 /* keywords for enabling/disabling ingress filtering
2319 * are the last in the array
2321 if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2324 else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
2328 return CMD_RET_USAGE;
2330 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2331 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2332 printf("Invalid port number: %d\n", parsed_cmd->port);
2333 return CMD_RET_FAILURE;
2335 vsc9953_port_ingress_filtering_set(parsed_cmd->port, enable);
2337 for (i = 0; i < VSC9953_MAX_PORTS; i++)
2338 vsc9953_port_ingress_filtering_set(i, enable);
2341 return CMD_RET_SUCCESS;
2344 static int vsc9953_port_aggr_show_key_func(struct ethsw_command_def *parsed_cmd)
2349 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2350 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2351 printf("Invalid port number: %d\n", parsed_cmd->port);
2352 return CMD_RET_FAILURE;
2355 if (vsc9953_port_aggr_grp_get(parsed_cmd->port, &aggr_grp))
2356 return CMD_RET_FAILURE;
2357 printf("%7s %10s\n", "Port", "Aggr grp");
2358 printf("%7d %10d\n", parsed_cmd->port, aggr_grp);
2360 printf("%7s %10s\n", "Port", "Aggr grp");
2361 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
2362 if (vsc9953_port_aggr_grp_get(i, &aggr_grp))
2364 printf("%7d %10d\n", i, aggr_grp);
2368 return CMD_RET_SUCCESS;
2371 static int vsc9953_port_aggr_set_key_func(struct ethsw_command_def *parsed_cmd)
2375 /* Aggregation group number should be set in parsed_cmd->aggr_grp */
2376 if (parsed_cmd->aggr_grp == ETHSW_CMD_AGGR_GRP_NONE) {
2377 printf("Please set an aggregation group value\n");
2378 return CMD_RET_FAILURE;
2381 if (!VSC9953_PORT_CHECK(parsed_cmd->aggr_grp)) {
2382 printf("Invalid aggregation group number: %d\n",
2383 parsed_cmd->aggr_grp);
2384 return CMD_RET_FAILURE;
2387 if (parsed_cmd->port != ETHSW_CMD_PORT_ALL) {
2388 if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
2389 printf("Invalid port number: %d\n", parsed_cmd->port);
2390 return CMD_RET_FAILURE;
2392 if (vsc9953_port_aggr_grp_set(parsed_cmd->port,
2393 parsed_cmd->aggr_grp)) {
2394 printf("Port %d: failed to set aggr group %d\n",
2395 parsed_cmd->port, parsed_cmd->aggr_grp);
2398 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
2399 if (vsc9953_port_aggr_grp_set(i,
2400 parsed_cmd->aggr_grp)) {
2401 printf("Port %d: failed to set aggr group %d\n",
2402 i, parsed_cmd->aggr_grp);
2407 return CMD_RET_SUCCESS;
2410 static struct ethsw_command_func vsc9953_cmd_func = {
2411 .ethsw_name = "L2 Switch VSC9953",
2412 .port_enable = &vsc9953_port_status_key_func,
2413 .port_disable = &vsc9953_port_status_key_func,
2414 .port_show = &vsc9953_port_config_key_func,
2415 .port_stats = &vsc9953_port_stats_key_func,
2416 .port_stats_clear = &vsc9953_port_stats_clear_key_func,
2417 .port_learn = &vsc9953_learn_set_key_func,
2418 .port_learn_show = &vsc9953_learn_show_key_func,
2419 .fdb_show = &vsc9953_fdb_show_key_func,
2420 .fdb_flush = &vsc9953_fdb_flush_key_func,
2421 .fdb_entry_add = &vsc9953_fdb_entry_add_key_func,
2422 .fdb_entry_del = &vsc9953_fdb_entry_del_key_func,
2423 .pvid_show = &vsc9953_pvid_show_key_func,
2424 .pvid_set = &vsc9953_pvid_set_key_func,
2425 .vlan_show = &vsc9953_vlan_show_key_func,
2426 .vlan_set = &vsc9953_vlan_set_key_func,
2427 .port_untag_show = &vsc9953_port_untag_show_key_func,
2428 .port_untag_set = &vsc9953_port_untag_set_key_func,
2429 .port_egr_vlan_show = &vsc9953_egr_vlan_tag_show_key_func,
2430 .port_egr_vlan_set = &vsc9953_egr_vlan_tag_set_key_func,
2431 .vlan_learn_show = &vsc9953_vlan_learn_show_key_func,
2432 .vlan_learn_set = &vsc9953_vlan_learn_set_key_func,
2433 .port_ingr_filt_show = &vsc9953_ingr_fltr_show_key_func,
2434 .port_ingr_filt_set = &vsc9953_ingr_fltr_set_key_func,
2435 .port_aggr_show = &vsc9953_port_aggr_show_key_func,
2436 .port_aggr_set = &vsc9953_port_aggr_set_key_func,
2439 #endif /* CONFIG_CMD_ETHSW */
2441 /*****************************************************************************
2442 At startup, the default configuration would be:
2443 - HW learning enabled on all ports; (HW default)
2444 - All ports are in VLAN 1;
2445 - All ports are VLAN aware;
2446 - All ports have POP_COUNT 1;
2447 - All ports have PVID 1;
2448 - All ports have TPID 0x8100; (HW default)
2449 - All ports tag frames classified to all VLANs that are not PVID;
2450 *****************************************************************************/
2451 void vsc9953_default_configuration(void)
2455 if (vsc9953_autoage_time_set(VSC9953_DEFAULT_AGE_TIME))
2456 debug("VSC9953: failed to set AGE time to %d\n",
2457 VSC9953_DEFAULT_AGE_TIME);
2459 for (i = 0; i < VSC9953_MAX_VLAN; i++)
2460 vsc9953_vlan_table_membership_all_set(i, 0);
2461 vsc9953_port_all_vlan_aware_set(1);
2462 vsc9953_port_all_vlan_pvid_set(1);
2463 vsc9953_port_all_vlan_poncnt_set(1);
2464 vsc9953_vlan_table_membership_all_set(1, 1);
2465 vsc9953_vlan_ingr_fltr_learn_drop(1);
2466 vsc9953_port_all_vlan_egress_untagged_set(EGRESS_UNTAG_PVID_AND_ZERO);
2467 if (vsc9953_aggr_code_set(AGGR_CODE_ALL))
2468 debug("VSC9953: failed to set default aggregation code mode\n");
2471 static void vcap_entry2cache_init(u32 target, u32 entry_words)
2475 for (i = 0; i < entry_words; i++) {
2476 out_le32((unsigned int *)(VSC9953_OFFSET +
2477 VSC9953_VCAP_CACHE_ENTRY_DAT(target, i)), 0x00);
2478 out_le32((unsigned int *)(VSC9953_OFFSET +
2479 VSC9953_VCAP_CACHE_MASK_DAT(target, i)), 0xFF);
2482 out_le32((unsigned int *)(VSC9953_OFFSET +
2483 VSC9953_VCAP_CACHE_TG_DAT(target)), 0x00);
2484 out_le32((unsigned int *)(VSC9953_OFFSET +
2485 VSC9953_VCAP_CFG_MV_CFG(target)),
2486 VSC9953_VCAP_CFG_MV_CFG_SIZE(entry_words));
2489 static void vcap_action2cache_init(u32 target, u32 action_words,
2494 for (i = 0; i < action_words; i++)
2495 out_le32((unsigned int *)(VSC9953_OFFSET +
2496 VSC9953_VCAP_CACHE_ACTION_DAT(target, i)), 0x00);
2498 for (i = 0; i < counter_words; i++)
2499 out_le32((unsigned int *)(VSC9953_OFFSET +
2500 VSC9953_VCAP_CACHE_CNT_DAT(target, i)), 0x00);
2503 static int vcap_cmd(u32 target, u16 ix, int cmd, int sel, int entry_count)
2506 u32 value = (VSC9953_VCAP_UPDATE_CTRL_UPDATE_CMD(cmd) |
2507 VSC9953_VCAP_UPDATE_CTRL_UPDATE_ADDR(ix) |
2508 VSC9953_VCAP_UPDATE_CTRL_UPDATE_SHOT);
2510 if ((sel & TCAM_SEL_ENTRY) && ix >= entry_count)
2511 return CMD_RET_FAILURE;
2513 if (!(sel & TCAM_SEL_ENTRY))
2514 value |= VSC9953_VCAP_UPDATE_CTRL_UPDATE_ENTRY_DIS;
2516 if (!(sel & TCAM_SEL_ACTION))
2517 value |= VSC9953_VCAP_UPDATE_CTRL_UPDATE_ACTION_DIS;
2519 if (!(sel & TCAM_SEL_COUNTER))
2520 value |= VSC9953_VCAP_UPDATE_CTRL_UPDATE_CNT_DIS;
2522 out_le32((unsigned int *)(VSC9953_OFFSET +
2523 VSC9953_VCAP_CFG_UPDATE_CTRL(tgt)), value);
2526 value = in_le32((unsigned int *)(VSC9953_OFFSET +
2527 VSC9953_VCAP_CFG_UPDATE_CTRL(tgt)));
2529 } while (value & VSC9953_VCAP_UPDATE_CTRL_UPDATE_SHOT);
2531 return CMD_RET_SUCCESS;
2534 static void vsc9953_vcap_init(void)
2536 u32 tgt = VSC9953_ES0;
2540 vcap_entry2cache_init(tgt, ENTRY_WORDS_ES0);
2541 cmd_ret = vcap_cmd(tgt, 0, TCAM_CMD_INITIALIZE, TCAM_SEL_ENTRY,
2543 if (cmd_ret != CMD_RET_SUCCESS)
2544 debug("VSC9953:%d invalid TCAM_SEL_ENTRY\n",
2547 /* write actions and counters */
2548 vcap_action2cache_init(tgt, BITS_TO_DWORD(ES0_ACT_WIDTH),
2549 BITS_TO_DWORD(ES0_CNT_WIDTH));
2550 out_le32((unsigned int *)(VSC9953_OFFSET +
2551 VSC9953_VCAP_CFG_MV_CFG(tgt)),
2552 VSC9953_VCAP_CFG_MV_CFG_SIZE(ES0_ACT_COUNT));
2553 cmd_ret = vcap_cmd(tgt, 0, TCAM_CMD_INITIALIZE,
2554 TCAM_SEL_ACTION | TCAM_SEL_COUNTER, ENTRY_WORDS_ES0);
2555 if (cmd_ret != CMD_RET_SUCCESS)
2556 debug("VSC9953:%d invalid TCAM_SEL_ACTION | TCAM_SEL_COUNTER\n",
2562 vcap_entry2cache_init(tgt, ENTRY_WORDS_IS1);
2563 cmd_ret = vcap_cmd(tgt, 0, TCAM_CMD_INITIALIZE, TCAM_SEL_ENTRY,
2565 if (cmd_ret != CMD_RET_SUCCESS)
2566 debug("VSC9953:%d invalid TCAM_SEL_ENTRY\n",
2569 /* write actions and counters */
2570 vcap_action2cache_init(tgt, BITS_TO_DWORD(IS1_ACT_WIDTH),
2571 BITS_TO_DWORD(IS1_CNT_WIDTH));
2572 out_le32((unsigned int *)(VSC9953_OFFSET +
2573 VSC9953_VCAP_CFG_MV_CFG(tgt)),
2574 VSC9953_VCAP_CFG_MV_CFG_SIZE(IS1_ACT_COUNT));
2575 cmd_ret = vcap_cmd(tgt, 0, TCAM_CMD_INITIALIZE,
2576 TCAM_SEL_ACTION | TCAM_SEL_COUNTER, ENTRY_WORDS_IS1);
2577 if (cmd_ret != CMD_RET_SUCCESS)
2578 debug("VSC9953:%d invalid TCAM_SEL_ACTION | TCAM_SEL_COUNTER\n",
2584 vcap_entry2cache_init(tgt, ENTRY_WORDS_IS2);
2585 cmd_ret = vcap_cmd(tgt, 0, TCAM_CMD_INITIALIZE, TCAM_SEL_ENTRY,
2587 if (cmd_ret != CMD_RET_SUCCESS)
2588 debug("VSC9953:%d invalid selection: TCAM_SEL_ENTRY\n",
2591 /* write actions and counters */
2592 vcap_action2cache_init(tgt, BITS_TO_DWORD(IS2_ACT_WIDTH),
2593 BITS_TO_DWORD(IS2_CNT_WIDTH));
2594 out_le32((unsigned int *)(VSC9953_OFFSET +
2595 VSC9953_VCAP_CFG_MV_CFG(tgt)),
2596 VSC9953_VCAP_CFG_MV_CFG_SIZE(IS2_ACT_COUNT));
2597 cmd_ret = vcap_cmd(tgt, 0, TCAM_CMD_INITIALIZE,
2598 TCAM_SEL_ACTION | TCAM_SEL_COUNTER, ENTRY_WORDS_IS2);
2599 if (cmd_ret != CMD_RET_SUCCESS)
2600 debug("VSC9953:%d invalid TCAM_SEL_ACTION | TCAM_SEL_COUNTER\n",
2604 void vsc9953_init(bd_t *bis)
2610 struct vsc9953_system_reg *l2sys_reg;
2611 struct vsc9953_qsys_reg *l2qsys_reg;
2612 struct vsc9953_dev_gmii *l2dev_gmii_reg;
2613 struct vsc9953_analyzer *l2ana_reg;
2614 struct vsc9953_devcpu_gcb *l2dev_gcb;
2616 l2dev_gmii_reg = (struct vsc9953_dev_gmii *)(VSC9953_OFFSET +
2617 VSC9953_DEV_GMII_OFFSET);
2619 l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
2620 VSC9953_ANA_OFFSET);
2622 l2sys_reg = (struct vsc9953_system_reg *)(VSC9953_OFFSET +
2623 VSC9953_SYS_OFFSET);
2625 l2qsys_reg = (struct vsc9953_qsys_reg *)(VSC9953_OFFSET +
2626 VSC9953_QSYS_OFFSET);
2628 l2dev_gcb = (struct vsc9953_devcpu_gcb *)(VSC9953_OFFSET +
2629 VSC9953_DEVCPU_GCB);
2631 out_le32(&l2dev_gcb->chip_regs.soft_rst,
2632 VSC9953_SOFT_SWC_RST_ENA);
2634 while ((in_le32(&l2dev_gcb->chip_regs.soft_rst) &
2635 VSC9953_SOFT_SWC_RST_ENA) && --timeout)
2636 udelay(1); /* busy wait for vsc9953 soft reset */
2638 debug("Timeout waiting for VSC9953 to reset\n");
2640 out_le32(&l2sys_reg->sys.reset_cfg, VSC9953_MEM_ENABLE |
2644 while ((in_le32(&l2sys_reg->sys.reset_cfg) &
2645 VSC9953_MEM_INIT) && --timeout)
2646 udelay(1); /* busy wait for vsc9953 memory init */
2648 debug("Timeout waiting for VSC9953 memory to initialize\n");
2650 out_le32(&l2sys_reg->sys.reset_cfg, (in_le32(&l2sys_reg->sys.reset_cfg)
2651 | VSC9953_CORE_ENABLE));
2653 /* VSC9953 Setting to be done once only */
2654 out_le32(&l2qsys_reg->sys.ext_cpu_cfg, 0x00000b00);
2656 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
2657 if (vsc9953_port_init(i))
2658 printf("Failed to initialize l2switch port %d\n", i);
2660 if (!vsc9953_l2sw.port[i].enabled)
2663 /* Enable VSC9953 GMII Ports Port ID 0 - 7 */
2664 if (VSC9953_INTERNAL_PORT_CHECK(i)) {
2665 out_le32(&l2ana_reg->pfc[i].pfc_cfg,
2666 VSC9953_PFC_FC_QSGMII);
2667 out_le32(&l2sys_reg->pause_cfg.mac_fc_cfg[i],
2668 VSC9953_MAC_FC_CFG_QSGMII);
2670 out_le32(&l2ana_reg->pfc[i].pfc_cfg,
2672 out_le32(&l2sys_reg->pause_cfg.mac_fc_cfg[i],
2673 VSC9953_MAC_FC_CFG);
2676 l2dev_gmii_reg = (struct vsc9953_dev_gmii *)
2677 (VSC9953_OFFSET + VSC9953_DEV_GMII_OFFSET +
2678 T1040_SWITCH_GMII_DEV_OFFSET * i);
2680 out_le32(&l2dev_gmii_reg->port_mode.clock_cfg,
2682 out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_ena_cfg,
2683 VSC9953_MAC_ENA_CFG);
2684 out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_mode_cfg,
2685 VSC9953_MAC_MODE_CFG);
2686 out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_ifg_cfg,
2687 VSC9953_MAC_IFG_CFG);
2688 /* mac_hdx_cfg varies with port id*/
2689 hdx_cfg = VSC9953_MAC_HDX_CFG | (i << 16);
2690 out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_hdx_cfg, hdx_cfg);
2691 out_le32(&l2sys_reg->sys.front_port_mode[i],
2692 VSC9953_FRONT_PORT_MODE);
2693 setbits_le32(&l2qsys_reg->sys.switch_port_mode[i],
2695 out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_maxlen_cfg,
2696 VSC9953_MAC_MAX_LEN);
2697 out_le32(&l2sys_reg->pause_cfg.pause_cfg[i],
2702 /* Initialize Lynx PHY Wrappers */
2704 if (vsc9953_l2sw.port[i].enet_if ==
2705 PHY_INTERFACE_MODE_QSGMII)
2706 phy_addr = (i + 0x4) & 0x1F;
2707 else if (vsc9953_l2sw.port[i].enet_if ==
2708 PHY_INTERFACE_MODE_SGMII)
2709 phy_addr = (i + 1) & 0x1F;
2712 /* SGMII IF mode + AN enable */
2713 vsc9953_mdio_write(&l2dev_gcb->mii_mng[0], phy_addr,
2714 0x14, PHY_SGMII_IF_MODE_AN |
2715 PHY_SGMII_IF_MODE_SGMII);
2716 /* Dev ability according to SGMII specification */
2717 vsc9953_mdio_write(&l2dev_gcb->mii_mng[0], phy_addr,
2718 0x4, PHY_SGMII_DEV_ABILITY_SGMII);
2719 /* Adjust link timer for SGMII
2720 * 1.6 ms in units of 8 ns = 2 * 10^5 = 0x30d40
2722 vsc9953_mdio_write(&l2dev_gcb->mii_mng[0], phy_addr,
2724 vsc9953_mdio_write(&l2dev_gcb->mii_mng[0], phy_addr,
2727 vsc9953_mdio_write(&l2dev_gcb->mii_mng[0], phy_addr,
2728 0x0, PHY_SGMII_CR_DEF_VAL |
2729 PHY_SGMII_CR_RESET_AN);
2732 while ((vsc9953_mdio_read(&l2dev_gcb->mii_mng[0],
2733 phy_addr, 0x01) & 0x0020) && --timeout)
2734 udelay(1); /* wait for AN to complete */
2736 debug("Timeout waiting for AN to complete\n");
2740 vsc9953_vcap_init();
2741 vsc9953_default_configuration();
2743 #ifdef CONFIG_CMD_ETHSW
2744 if (ethsw_define_functions(&vsc9953_cmd_func) < 0)
2745 debug("Unable to use \"ethsw\" commands\n");
2748 printf("VSC9953 L2 switch initialized\n");