Skip to contentSkip to conversation

Add more commands for VSC9953 L2 Switch

PATCH Superseded Codrin Ciubotariu 2 participants 49 messages Jun 23, 2015 – Jul 8, 2015 Network drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add more commands for VSC9953 L2 Switch

This patch set adds several features for VSC9953 L2 Switch:
- VLAN configuration;
- port statistics;
- FDB table operations;
- enable/disable HW learning;
- private/shared VLAN learning.

Also, the parser needed to be changed to allow commands with optional parameters and to allow developers to easily add new commands.

Since new features are added, the default configuration
had to be changed to:
- HW learning enabled on all ports; (HW default)
- All ports are in VLAN 1;
- All ports are VLAN aware;
- All ports have POP_COUNT 1;
- All ports have PVID 1;
- All ports have TPID 0x8100; (HW default)
- All ports tag frames classified to all VLANs that are not PVID;

If the user decides to compile the VSC9953 driver without the support for commands, the above default configuration should be sufficient to make the L2 Switch work in unmanaged mode.

New supported commands:
- show a port's statistics;
- enable/disable/show learning configuration on a port;
- add/delete a MAC entry in FDB; show the FDB table;
- add/remove a VLAN to/from a port (VLAN members);
- set/show PVID (ingress and egress VLAN tagging) for a port;
- set egress tagging mod for a port;
- configure VID source for egress tag;
- make VLAN learning shared or private;
- enable/disable VLAN ingress filtering on a port.

Changes for v2:
- removed Change-id field;
- Added the patch that changes the License at the end of the patch set for an easier integration;

Codrin Ciubotariu (11):
drivers/net/vsc9953: Cleanup patch
drivers/net/vsc9953: Fix missing reserved register drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch drivers/net/vsc9953: Refractor the parser for VSC9953 commands drivers/net/vsc9953: Add command to show/clear port counters drivers/net/vsc9953: Add commands to enable/disable HW learning drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953 drivers/net/vsc9953: Add VLAN commands for VSC9953 drivers/net/vsc9953: Add command for shared/private VLAN learning drivers/net/vsc9953: Add commands for VLAN ingress filtering drivers/net/vsc9953: Add GPL-2.0+ SPDX-License-Identifier

 drivers/net/vsc9953.c | 2816 ++++++++++++++++++++++++++++++++++++++++++++++---
 include/vsc9953.h     |  274 ++++-
 2 files changed, 2948 insertions(+), 142 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH v2 1/11 drivers/net/vsc9953: Cleanup patch

This patch groups some macros defined for registers and replaces some magic numbers from vsc9953 with macros. Also, "port" and "port_nr" keywords are replaced with "port_no".

Also, in some places, this patch replaces in_le32 and out_le32 with clrbits_le32 and setbits_le32 to reduce the number of code lines and to assure that only intended bits of a register are changed.

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 100 +++++++++++++++++++++++++-------------------------
 include/vsc9953.h     |  47 ++++++++++++++++++++----
 2 files changed, 88 insertions(+), 59 deletions(-)
drivers/net/vsc9953.c +49 -51
index fed7358..720ae47 100644
@@ -25,44 +25,44 @@ static struct vsc9953_info vsc9953_l2sw = {
 		.port[9] = VSC9953_PORT_INFO_INITIALIZER(9),
 };
 
-void vsc9953_port_info_set_mdio(int port, struct mii_dev *bus)
+void vsc9953_port_info_set_mdio(int port_no, struct mii_dev *bus)
 {
-	if (!VSC9953_PORT_CHECK(port))
+	if (!VSC9953_PORT_CHECK(port_no))
 		return;
 
-	vsc9953_l2sw.port[port].bus = bus;
+	vsc9953_l2sw.port[port_no].bus = bus;
 }
 
-void vsc9953_port_info_set_phy_address(int port, int address)
+void vsc9953_port_info_set_phy_address(int port_no, int address)
 {
-	if (!VSC9953_PORT_CHECK(port))
+	if (!VSC9953_PORT_CHECK(port_no))
 		return;
 
-	vsc9953_l2sw.port[port].phyaddr = address;
+	vsc9953_l2sw.port[port_no].phyaddr = address;
 }
 
-void vsc9953_port_info_set_phy_int(int port, phy_interface_t phy_int)
+void vsc9953_port_info_set_phy_int(int port_no, phy_interface_t phy_int)
 {
-	if (!VSC9953_PORT_CHECK(port))
+	if (!VSC9953_PORT_CHECK(port_no))
 		return;
 
-	vsc9953_l2sw.port[port].enet_if = phy_int;
+	vsc9953_l2sw.port[port_no].enet_if = phy_int;
 }
 
-void vsc9953_port_enable(int port)
+void vsc9953_port_enable(int port_no)
 {
-	if (!VSC9953_PORT_CHECK(port))
+	if (!VSC9953_PORT_CHECK(port_no))
 		return;
 
-	vsc9953_l2sw.port[port].enabled = 1;
+	vsc9953_l2sw.port[port_no].enabled = 1;
 }
 
-void vsc9953_port_disable(int port)
+void vsc9953_port_disable(int port_no)
 {
-	if (!VSC9953_PORT_CHECK(port))
+	if (!VSC9953_PORT_CHECK(port_no))
 		return;
 
-	vsc9953_l2sw.port[port].enabled = 0;
+	vsc9953_l2sw.port[port_no].enabled = 0;
 }
 
 static void vsc9953_mdio_write(struct vsc9953_mii_mng *phyregs, int port_addr,
@@ -148,21 +148,21 @@ static int init_phy(struct eth_device *dev)
 	return 0;
 }
 
-static int vsc9953_port_init(int port)
+static int vsc9953_port_init(int port_no)
 {
 	struct eth_device		*dev;
 
 	/* Internal ports never have a PHY */
-	if (VSC9953_INTERNAL_PORT_CHECK(port))
+	if (VSC9953_INTERNAL_PORT_CHECK(port_no))
 		return 0;
 
 	/* alloc eth device */
 	dev = (struct eth_device *)calloc(1, sizeof(struct eth_device));
 	if (!dev)
-		return 1;
+		return -1;
 
-	sprintf(dev->name, "SW at PORT%d", port);
-	dev->priv = &vsc9953_l2sw.port[port];
+	sprintf(dev->name, "SW at PORT%d", port_no);
+	dev->priv = &vsc9953_l2sw.port[port_no];
 	dev->init = NULL;
 	dev->halt = NULL;
 	dev->send = NULL;
@@ -170,7 +170,7 @@ static int vsc9953_port_init(int port)
 
 	if (init_phy(dev)) {
 		free(dev);
-		return 1;
+		return -1;
 	}
 
 	return 0;
@@ -255,8 +255,8 @@ void vsc9953_init(bd_t *bis)
 		out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_hdx_cfg, hdx_cfg);
 		out_le32(&l2sys_reg->sys.front_port_mode[i],
 			 CONFIG_VSC9953_FRONT_PORT_MODE);
-		out_le32(&l2qsys_reg->sys.switch_port_mode[i],
-			 CONFIG_VSC9953_PORT_ENA);
+		setbits_le32(&l2qsys_reg->sys.switch_port_mode[i],
+			     CONFIG_VSC9953_PORT_ENA);
 		out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_maxlen_cfg,
 			 CONFIG_VSC9953_MAC_MAX_LEN);
 		out_le32(&l2sys_reg->pause_cfg.pause_cfg[i],
@@ -312,25 +312,23 @@ void vsc9953_init(bd_t *bis)
 
 #ifdef CONFIG_VSC9953_CMD
 /* Enable/disable status of a VSC9953 port */
-static void vsc9953_port_status_set(int port_nr, u8 enabled)
+static void vsc9953_port_status_set(int port_no, u8 enabled)
 {
-	u32			val;
 	struct vsc9953_qsys_reg	*l2qsys_reg;
 
 	/* Administrative down */
-	if (vsc9953_l2sw.port[port_nr].enabled == 0)
+	if (!vsc9953_l2sw.port[port_no].enabled)
 		return;
 
 	l2qsys_reg = (struct vsc9953_qsys_reg *)(VSC9953_OFFSET +
 			VSC9953_QSYS_OFFSET);
 
-	val = in_le32(&l2qsys_reg->sys.switch_port_mode[port_nr]);
-	if (enabled == 1)
-		val |= (1 << 13);
+	if (enabled)
+		setbits_le32(&l2qsys_reg->sys.switch_port_mode[port_no],
+			     CONFIG_VSC9953_PORT_ENA);
 	else
-		val &= ~(1 << 13);
-
-	out_le32(&l2qsys_reg->sys.switch_port_mode[port_nr], val);
+		clrbits_le32(&l2qsys_reg->sys.switch_port_mode[port_no],
+			     CONFIG_VSC9953_PORT_ENA);
 }
 
 /* Set all VSC9953 ports' status */
@@ -343,14 +341,14 @@ static void vsc9953_port_all_status_set(u8 enabled)
 }
 
 /* Start autonegotiation for a VSC9953 PHY */
-static void vsc9953_phy_autoneg(int port_nr)
+static void vsc9953_phy_autoneg(int port_no)
 {
-	if (!vsc9953_l2sw.port[port_nr].phydev)
+	if (!vsc9953_l2sw.port[port_no].phydev)
 		return;
 
-	if (vsc9953_l2sw.port[port_nr].phydev->drv->startup(
-			vsc9953_l2sw.port[port_nr].phydev))
-		printf("Failed to start PHY for port %d\n", port_nr);
+	if (vsc9953_l2sw.port[port_no].phydev->drv->startup(
+			vsc9953_l2sw.port[port_no].phydev))
+		printf("Failed to start PHY for port %d\n", port_no);
 }
 
 /* Start autonegotiation for all VSC9953 PHYs */
@@ -363,7 +361,7 @@ static void vsc9953_phy_all_autoneg(void)
 }
 
 /* Print a VSC9953 port's configuration */
-static void vsc9953_port_config_show(int port)
+static void vsc9953_port_config_show(int port_no)
 {
 	int			speed;
 	int			duplex;
@@ -375,20 +373,20 @@ static void vsc9953_port_config_show(int port)
 	l2qsys_reg = (struct vsc9953_qsys_reg *)(VSC9953_OFFSET +
 			VSC9953_QSYS_OFFSET);
 
-	val = in_le32(&l2qsys_reg->sys.switch_port_mode[port]);
-	enabled = vsc9953_l2sw.port[port].enabled &
-			((val & 0x00002000) >> 13);
+	val = in_le32(&l2qsys_reg->sys.switch_port_mode[port_no]);
+	enabled = !!(vsc9953_l2sw.port[port_no].enabled &
+		     val & CONFIG_VSC9953_PORT_ENA);
 
 	/* internal ports (8 and 9) are fixed */
-	if (VSC9953_INTERNAL_PORT_CHECK(port)) {
+	if (VSC9953_INTERNAL_PORT_CHECK(port_no)) {
 		link = 1;
 		speed = SPEED_2500;
 		duplex = DUPLEX_FULL;
 	} else {
-		if (vsc9953_l2sw.port[port].phydev) {
-			link = vsc9953_l2sw.port[port].phydev->link;
-			speed = vsc9953_l2sw.port[port].phydev->speed;
-			duplex = vsc9953_l2sw.port[port].phydev->duplex;
+		if (vsc9953_l2sw.port[port_no].phydev) {
+			link = vsc9953_l2sw.port[port_no].phydev->link;
+			speed = vsc9953_l2sw.port[port_no].phydev->speed;
+			duplex = vsc9953_l2sw.port[port_no].phydev->duplex;
 		} else {
 			link = -1;
 			speed = -1;
@@ -396,7 +394,7 @@ static void vsc9953_port_config_show(int port)
 		}
 	}
 
-	printf("%8d ", port);
+	printf("%8d ", port_no);
 	printf("%8s ", enabled == 1 ? "enabled" : "disabled");
 	printf("%8s ", link == 1 ? "up" : "down");
 
@@ -487,11 +485,11 @@ static int do_ethsw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 U_BOOT_CMD(ethsw, 5, 0, do_ethsw,
 	   "vsc9953 l2 switch commands",
-	   "port <port_nr> enable|disable\n"
+	   "port <port_no> enable|disable\n"
 	   "    - enable/disable an l2 switch port\n"
-	   "      port_nr=0..9; use \"all\" for all ports\n"
-	   "ethsw port <port_nr> show\n"
+	   "      port_no=0..9; use \"all\" for all ports\n"
+	   "ethsw port <port_no> show\n"
 	   "    - show an l2 switch port's configuration\n"
-	   "      port_nr=0..9; use \"all\" for all ports\n"
+	   "      port_no=0..9; use \"all\" for all ports\n"
 );
 #endif /* CONFIG_VSC9953_CMD */
include/vsc9953.h +39 -8

78 lines not on this page · raw message

Signature · 1 line
1.9.3
#2 lore raw

PATCH v2 1/11 drivers/net/vsc9953: Cleanup patch

Hi Codrin,

Quoted 91 lines · Codrin Ciubotariu

This patch groups some macros defined for registers and replaces some magic numbers from vsc9953 with macros. Also, "port" and "port_nr" keywords are replaced with "port_no".

Also, in some places, this patch replaces in_le32 and out_le32 with clrbits_le32 and setbits_le32 to reduce the number of code lines and to assure that only intended bits of a register are changed.

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 100 +++++++++++++++++++++++++-------------------------
 include/vsc9953.h     |  47 ++++++++++++++++++++----
 2 files changed, 88 insertions(+), 59 deletions(-)
drivers/net/vsc9953.c +16 -16
index fed7358..720ae47 100644
@@ -25,44 +25,44 @@ static struct vsc9953_info vsc9953_l2sw = {
                .port[9] = VSC9953_PORT_INFO_INITIALIZER(9),
 };
 
-void vsc9953_port_info_set_mdio(int port, struct mii_dev *bus)
+void vsc9953_port_info_set_mdio(int port_no, struct mii_dev *bus)
 {
-       if (!VSC9953_PORT_CHECK(port))
+       if (!VSC9953_PORT_CHECK(port_no))
                return;
 
-       vsc9953_l2sw.port[port].bus = bus;
+       vsc9953_l2sw.port[port_no].bus = bus;
 }
 
-void vsc9953_port_info_set_phy_address(int port, int address)
+void vsc9953_port_info_set_phy_address(int port_no, int address)
 {
-       if (!VSC9953_PORT_CHECK(port))
+       if (!VSC9953_PORT_CHECK(port_no))
                return;
 
-       vsc9953_l2sw.port[port].phyaddr = address;
+       vsc9953_l2sw.port[port_no].phyaddr = address;
 }
 
-void vsc9953_port_info_set_phy_int(int port, phy_interface_t phy_int)
+void vsc9953_port_info_set_phy_int(int port_no, phy_interface_t phy_int)
 {
-       if (!VSC9953_PORT_CHECK(port))
+       if (!VSC9953_PORT_CHECK(port_no))
                return;
 
-       vsc9953_l2sw.port[port].enet_if = phy_int;
+       vsc9953_l2sw.port[port_no].enet_if = phy_int;
 }
 
-void vsc9953_port_enable(int port)
+void vsc9953_port_enable(int port_no)
 {
-       if (!VSC9953_PORT_CHECK(port))
+       if (!VSC9953_PORT_CHECK(port_no))
                return;
 
-       vsc9953_l2sw.port[port].enabled = 1;
+       vsc9953_l2sw.port[port_no].enabled = 1;
 }
 
-void vsc9953_port_disable(int port)
+void vsc9953_port_disable(int port_no)
 {
-       if (!VSC9953_PORT_CHECK(port))
+       if (!VSC9953_PORT_CHECK(port_no))
                return;
 
-       vsc9953_l2sw.port[port].enabled = 0;
+       vsc9953_l2sw.port[port_no].enabled = 0;
 }
 
 static void vsc9953_mdio_write(struct vsc9953_mii_mng *phyregs, int port_addr,
@@ -148,21 +148,21 @@ static int init_phy(struct eth_device *dev)
        return 0;
 }
 
-static int vsc9953_port_init(int port)
+static int vsc9953_port_init(int port_no)
 {
        struct eth_device               *dev;
 

drivers/net/vsc9953.c static int init_phy(struct eth_device *dev) · line 162

Quoted 10 lines
drivers/net/vsc9953.c +2 -2
        /* Internal ports never have a PHY */
-       if (VSC9953_INTERNAL_PORT_CHECK(port))
+       if (VSC9953_INTERNAL_PORT_CHECK(port_no))
                return 0;
 
        /* alloc eth device */
        dev = (struct eth_device *)calloc(1, sizeof(struct eth_device));
        if (!dev)
-               return 1;
+               return -1;

Is it reasonable to use values from asm/errno.h here and elsewhere in the driver? This seems like it should return -ENODEV instead of -EPERM.

Quoted 90 lines
drivers/net/vsc9953.c +18 -20
-       sprintf(dev->name, "SW at PORT%d", port);
-       dev->priv = &vsc9953_l2sw.port[port];
+       sprintf(dev->name, "SW at PORT%d", port_no);
+       dev->priv = &vsc9953_l2sw.port[port_no];
        dev->init = NULL;
        dev->halt = NULL;
        dev->send = NULL;
@@ -170,7 +170,7 @@ static int vsc9953_port_init(int port)
 
        if (init_phy(dev)) {
                free(dev);
-               return 1;
+               return -1;
        }
 
        return 0;
@@ -255,8 +255,8 @@ void vsc9953_init(bd_t *bis)
                out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_hdx_cfg, hdx_cfg);
                out_le32(&l2sys_reg->sys.front_port_mode[i],
                         CONFIG_VSC9953_FRONT_PORT_MODE);
-               out_le32(&l2qsys_reg->sys.switch_port_mode[i],
-                        CONFIG_VSC9953_PORT_ENA);
+               setbits_le32(&l2qsys_reg->sys.switch_port_mode[i],
+                            CONFIG_VSC9953_PORT_ENA);
                out_le32(&l2dev_gmii_reg->mac_cfg_status.mac_maxlen_cfg,
                         CONFIG_VSC9953_MAC_MAX_LEN);
                out_le32(&l2sys_reg->pause_cfg.pause_cfg[i],
@@ -312,25 +312,23 @@ void vsc9953_init(bd_t *bis)
 
 #ifdef CONFIG_VSC9953_CMD
 /* Enable/disable status of a VSC9953 port */
-static void vsc9953_port_status_set(int port_nr, u8 enabled)
+static void vsc9953_port_status_set(int port_no, u8 enabled)
 {
-       u32                     val;
        struct vsc9953_qsys_reg *l2qsys_reg;
 
        /* Administrative down */
-       if (vsc9953_l2sw.port[port_nr].enabled == 0)
+       if (!vsc9953_l2sw.port[port_no].enabled)
                return;
 
        l2qsys_reg = (struct vsc9953_qsys_reg *)(VSC9953_OFFSET +
                        VSC9953_QSYS_OFFSET);
 
-       val = in_le32(&l2qsys_reg->sys.switch_port_mode[port_nr]);
-       if (enabled == 1)
-               val |= (1 << 13);
+       if (enabled)
+               setbits_le32(&l2qsys_reg->sys.switch_port_mode[port_no],
+                            CONFIG_VSC9953_PORT_ENA);
        else
-               val &= ~(1 << 13);
-
-       out_le32(&l2qsys_reg->sys.switch_port_mode[port_nr], val);
+               clrbits_le32(&l2qsys_reg->sys.switch_port_mode[port_no],
+                            CONFIG_VSC9953_PORT_ENA);
 }
 
 /* Set all VSC9953 ports' status */
@@ -343,14 +341,14 @@ static void vsc9953_port_all_status_set(u8 enabled)
 }
 
 /* Start autonegotiation for a VSC9953 PHY */
-static void vsc9953_phy_autoneg(int port_nr)
+static void vsc9953_phy_autoneg(int port_no)
 {
-       if (!vsc9953_l2sw.port[port_nr].phydev)
+       if (!vsc9953_l2sw.port[port_no].phydev)
                return;
 
-       if (vsc9953_l2sw.port[port_nr].phydev->drv->startup(
-                       vsc9953_l2sw.port[port_nr].phydev))
-               printf("Failed to start PHY for port %d\n", port_nr);
+       if (vsc9953_l2sw.port[port_no].phydev->drv->startup(
+                       vsc9953_l2sw.port[port_no].phydev))
+               printf("Failed to start PHY for port %d\n", port_no);
 }
 
 /* Start autonegotiation for all VSC9953 PHYs */
@@ -363,7 +361,7 @@ static void vsc9953_phy_all_autoneg(void)
 }
 
 /* Print a VSC9953 port's configuration */
-static void vsc9953_port_config_show(int port)
+static void vsc9953_port_config_show(int port_no)
 {
        int                     speed;
        int                     duplex;

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port) · line 378

Quoted 9 lines
drivers/net/vsc9953.c +3 -3
@@ -375,20 +373,20 @@ static void vsc9953_port_config_show(int port)
        l2qsys_reg = (struct vsc9953_qsys_reg *)(VSC9953_OFFSET +
                        VSC9953_QSYS_OFFSET);
 
-       val = in_le32(&l2qsys_reg->sys.switch_port_mode[port]);
-       enabled = vsc9953_l2sw.port[port].enabled &
-                       ((val & 0x00002000) >> 13);
+       val = in_le32(&l2qsys_reg->sys.switch_port_mode[port_no]);
+       enabled = !!(vsc9953_l2sw.port[port_no].enabled &
+                    val & CONFIG_VSC9953_PORT_ENA);

This is incorrect... Should be:

+ enabled = vsc9953_l2sw.port[port_no].enabled &&
+ (val & CONFIG_VSC9953_PORT_ENA);

Quoted 49 lines
drivers/net/vsc9953.c +10 -10
        /* internal ports (8 and 9) are fixed */
-       if (VSC9953_INTERNAL_PORT_CHECK(port)) {
+       if (VSC9953_INTERNAL_PORT_CHECK(port_no)) {
                link = 1;
                speed = SPEED_2500;
                duplex = DUPLEX_FULL;
        } else {
-               if (vsc9953_l2sw.port[port].phydev) {
-                       link = vsc9953_l2sw.port[port].phydev->link;
-                       speed = vsc9953_l2sw.port[port].phydev->speed;
-                       duplex = vsc9953_l2sw.port[port].phydev->duplex;
+               if (vsc9953_l2sw.port[port_no].phydev) {
+                       link = vsc9953_l2sw.port[port_no].phydev->link;
+                       speed = vsc9953_l2sw.port[port_no].phydev->speed;
+                       duplex = vsc9953_l2sw.port[port_no].phydev->duplex;
                } else {
                        link = -1;
                        speed = -1;
@@ -396,7 +394,7 @@ static void vsc9953_port_config_show(int port)
                }
        }
 
-       printf("%8d ", port);
+       printf("%8d ", port_no);
        printf("%8s ", enabled == 1 ? "enabled" : "disabled");
        printf("%8s ", link == 1 ? "up" : "down");
 
@@ -487,11 +485,11 @@ static int do_ethsw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 U_BOOT_CMD(ethsw, 5, 0, do_ethsw,
           "vsc9953 l2 switch commands",
-          "port <port_nr> enable|disable\n"
+          "port <port_no> enable|disable\n"
           "    - enable/disable an l2 switch port\n"
-          "      port_nr=0..9; use \"all\" for all ports\n"
-          "ethsw port <port_nr> show\n"
+          "      port_no=0..9; use \"all\" for all ports\n"
+          "ethsw port <port_no> show\n"
           "    - show an l2 switch port's configuration\n"
-          "      port_nr=0..9; use \"all\" for all ports\n"
+          "      port_no=0..9; use \"all\" for all ports\n"
 );
 #endif /* CONFIG_VSC9953_CMD */
include/vsc9953.h +0 -0
index 3d11b87..920402f 100644

include/vsc9953.h line 37

Quoted 5 lines
include/vsc9953.h +1 -0
@@ -33,29 +33,60 @@
 #define T1040_SWITCH_GMII_DEV_OFFSET   0x010000
 #define VSC9953_PHY_REGS_OFFST         0x0000AC
 
+/* Macros for vsc9953_chip_regs.soft_rst register */
 #define CONFIG_VSC9953_SOFT_SWC_RST_ENA        0x00000001

All of there that are register constants should not have "CONFIG_" prepended to them. That should only be for constants that configure something, eventually only from Kconfig. Please add another patch before this one that removes that.

include/vsc9953.h line 41

Quoted 7 lines
include/vsc9953.h +2 -1
+
+/* Macros for vsc9953_sys_sys.reset_cfg register */
 #define CONFIG_VSC9953_CORE_ENABLE     0x80
 #define CONFIG_VSC9953_MEM_ENABLE      0x40
 #define CONFIG_VSC9953_MEM_INIT                0x20
 
-#define CONFIG_VSC9953_PORT_ENA                0x00003a00

Why is this value changing? Was it just wrong before?

Quoted 25 lines
include/vsc9953.h +17 -0
+/* Macros for vsc9953_dev_gmii_mac_cfg_status.mac_ena_cfg register */
 #define CONFIG_VSC9953_MAC_ENA_CFG     0x00000011
+
+/* Macros for vsc9953_dev_gmii_mac_cfg_status.mac_mode_cfg register */
 #define CONFIG_VSC9953_MAC_MODE_CFG    0x00000011
+
+/* Macros for vsc9953_dev_gmii_mac_cfg_status.mac_ifg_cfg register */
 #define CONFIG_VSC9953_MAC_IFG_CFG     0x00000515
+
+/* Macros for vsc9953_dev_gmii_mac_cfg_status.mac_hdx_cfg register */
 #define CONFIG_VSC9953_MAC_HDX_CFG     0x00001043
+
+/* Macros for vsc9953_dev_gmii_mac_cfg_status.mac_maxlen_cfg register */
+#define CONFIG_VSC9953_MAC_MAX_LEN     0x000005ee
+
+/* Macros for vsc9953_dev_gmii_port_mode.clock_cfg register */
 #define CONFIG_VSC9953_CLOCK_CFG       0x00000001
 #define CONFIG_VSC9953_CLOCK_CFG_1000M 0x00000001
+
+/* Macros for vsc9953_sys_sys.front_port_mode register */
+#define CONFIG_VSC9953_FRONT_PORT_MODE 0x00000000
+
+/* Macros for vsc9953_ana_pfc.pfc_cfg register */
 #define CONFIG_VSC9953_PFC_FC          0x00000001
 #define CONFIG_VSC9953_PFC_FC_QSGMII   0x00000000

include/vsc9953.h line 78

Quoted 10 lines
include/vsc9953.h +7 -0
+
+/* Macros for vsc9953_sys_pause_cfg.mac_fc_cfg register */
 #define CONFIG_VSC9953_MAC_FC_CFG      0x04700000
 #define CONFIG_VSC9953_MAC_FC_CFG_QSGMII       0x00700000
+
+/* Macros for vsc9953_sys_pause_cfg.pause_cfg register */
 #define CONFIG_VSC9953_PAUSE_CFG       0x001ffffe
+
+/* Macros for vsc9953_sys_pause_cfg.pause_cfg register */
+#define CONFIG_VSC9953_PAUSE_CFG       0x001ffffe

This adds a duplicate of the define above it.

include/vsc9953.h line 85

Quoted 8 lines
include/vsc9953.h +2 -2
+/* Macros for vsc9953_sys_pause_cfgtot_tail_drop_lvl register */
 #define CONFIG_VSC9953_TOT_TAIL_DROP_LVL       0x000003ff
-#define CONFIG_VSC9953_FRONT_PORT_MODE 0x00000000
-#define CONFIG_VSC9953_MAC_MAX_LEN     0x000005ee
 
+/* Macros for vsc9953_vcap_core_cfg.vcap_mv_cfg register */
 #define        CONFIG_VSC9953_VCAP_MV_CFG      0x0000ffff
 #define        CONFIG_VSC9953_VCAP_UPDATE_CTRL 0x01000004

May as well get rid of the tabs here after the defines.

Quoted 30 lines
include/vsc9953.h +9 -6
+
+/* Macros for vsc9953_qsys_sys.switch_port_mode register */
+#define CONFIG_VSC9953_PORT_ENA                0x00002000
+
 #define VSC9953_MAX_PORTS              10
 #define VSC9953_PORT_CHECK(port)       \
        (((port) < 0 || (port) >= VSC9953_MAX_PORTS) ? 0 : 1)
@@ -393,10 +424,10 @@ struct vsc9953_info {
 
 void vsc9953_init(bd_t *bis);
 
-void vsc9953_port_info_set_mdio(int port, struct mii_dev *bus);
-void vsc9953_port_info_set_phy_address(int port, int address);
-void vsc9953_port_enable(int port);
-void vsc9953_port_disable(int port);
-void vsc9953_port_info_set_phy_int(int port, phy_interface_t phy_int);
+void vsc9953_port_info_set_mdio(int port_no, struct mii_dev *bus);
+void vsc9953_port_info_set_phy_address(int port_no, int address);
+void vsc9953_port_enable(int port_no);
+void vsc9953_port_disable(int port_no);
+void vsc9953_port_info_set_phy_int(int port_no, phy_interface_t phy_int);
 
 #endif /* _VSC9953_H_ */
--

1.9.3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#3 lore raw

PATCH v2 1/11 drivers/net/vsc9953: Cleanup patch

Hi Joe,

Quoted 10 lines

Review

Quoted 6 lines
        /* alloc eth device */
        dev = (struct eth_device *)calloc(1, sizeof(struct eth_device));
        if (!dev)
(quoted diff) +1 -1
-               return 1;
+               return -1;

Is it reasonable to use values from asm/errno.h here and elsewhere in the driver? This seems like it should return -ENODEV instead of -EPERM.

Yes, I should use values from errno.h . -ENOMEM seems more appropriate to me. What do you think?

Review

Quoted 7 lines

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port) · line 378

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+       enabled = !!(vsc9953_l2sw.port[port_no].enabled &
+                    val & CONFIG_VSC9953_PORT_ENA);

This is incorrect... Should be:

(quoted diff) +2 -0
+       enabled = vsc9953_l2sw.port[port_no].enabled &&
+                    (val & CONFIG_VSC9953_PORT_ENA);

Ok.

Quoted 8 lines
Quoted 8 lines
include/vsc9953.h +0 -0
index 3d11b87..920402f 100644
@@ -33,29 +33,60 @@
 #define T1040_SWITCH_GMII_DEV_OFFSET   0x010000
 #define VSC9953_PHY_REGS_OFFST         0x0000AC
 
Quoted 7 lines

include/vsc9953.h line 37

Quoted 2 lines
include/vsc9953.h +1 -0
+/* Macros for vsc9953_chip_regs.soft_rst register */
 #define CONFIG_VSC9953_SOFT_SWC_RST_ENA        0x00000001

All of there that are register constants should not have "CONFIG_" prepended to them. That should only be for constants that configure something, eventually only from Kconfig. Please add another patch before this one that removes that.

Ok, I will add another patch before this one.

Quoted 7 lines

include/vsc9953.h line 78

Quoted 5 lines
include/vsc9953.h +4 -0
+/* Macros for vsc9953_sys_pause_cfg.pause_cfg register */
 #define CONFIG_VSC9953_PAUSE_CFG       0x001ffffe
+
+/* Macros for vsc9953_sys_pause_cfg.pause_cfg register */
+#define CONFIG_VSC9953_PAUSE_CFG       0x001ffffe

This adds a duplicate of the define above it.

I will remove one of them.

Quoted 6 lines

include/vsc9953.h line 85

Quoted 4 lines
include/vsc9953.h +1 -0
+/* Macros for vsc9953_vcap_core_cfg.vcap_mv_cfg register */
 #define        CONFIG_VSC9953_VCAP_MV_CFG      0x0000ffff
 #define        CONFIG_VSC9953_VCAP_UPDATE_CTRL 0x01000004

May as well get rid of the tabs here after the defines.

Ok.

Thank you for your review. I will make v3.

Best regards,
Codrin

#4 lore raw

PATCH v2 1/11 drivers/net/vsc9953: Cleanup patch

Hi Codrin,

Quoted 9 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 7 lines
Quoted 6 lines
        /* alloc eth device */
        dev = (struct eth_device *)calloc(1, sizeof(struct eth_device));
        if (!dev)
(quoted diff) +1 -1
-               return 1;
+               return -1;
Quoted 5 lines
Quoted 3 lines

Is it reasonable to use values from asm/errno.h here and elsewhere in the driver? This seems like it should return -ENODEV instead of -EPERM.

Yes, I should use values from errno.h . -ENOMEM seems more appropriate to me. What do you think?

Yes, sorry. I didn't look at the line above! :/

Quoted 43 lines

Review

Quoted 7 lines

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port) · line 378

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+       enabled = !!(vsc9953_l2sw.port[port_no].enabled &
+                    val & CONFIG_VSC9953_PORT_ENA);

This is incorrect... Should be:

(quoted diff) +2 -0
+       enabled = vsc9953_l2sw.port[port_no].enabled &&
+                    (val & CONFIG_VSC9953_PORT_ENA);

Ok.

Quoted 8 lines
Quoted 8 lines
include/vsc9953.h +0 -0
index 3d11b87..920402f 100644
@@ -33,29 +33,60 @@
 #define T1040_SWITCH_GMII_DEV_OFFSET   0x010000
 #define VSC9953_PHY_REGS_OFFST         0x0000AC
 
Quoted 7 lines

include/vsc9953.h line 37

Quoted 2 lines
include/vsc9953.h +1 -0
+/* Macros for vsc9953_chip_regs.soft_rst register */
 #define CONFIG_VSC9953_SOFT_SWC_RST_ENA        0x00000001

All of there that are register constants should not have "CONFIG_" prepended to them. That should only be for constants that configure something, eventually only from Kconfig. Please add another patch before this one that removes that.

Ok, I will add another patch before this one.

Quoted 7 lines

include/vsc9953.h line 78

Quoted 5 lines
include/vsc9953.h +4 -0
+/* Macros for vsc9953_sys_pause_cfg.pause_cfg register */
 #define CONFIG_VSC9953_PAUSE_CFG       0x001ffffe
+
+/* Macros for vsc9953_sys_pause_cfg.pause_cfg register */
+#define CONFIG_VSC9953_PAUSE_CFG       0x001ffffe

This adds a duplicate of the define above it.

I will remove one of them.

Quoted 5 lines
Quoted 4 lines
include/vsc9953.h +1 -0
+/* Macros for vsc9953_vcap_core_cfg.vcap_mv_cfg register */
 #define        CONFIG_VSC9953_VCAP_MV_CFG      0x0000ffff
 #define        CONFIG_VSC9953_VCAP_UPDATE_CTRL 0x01000004
Quoted 5 lines
Quoted 1 line

May as well get rid of the tabs here after the defines.

Ok.

Thank you for your review. I will make v3.

Sure thing. I'll try to get through the rest of them today.

Cheers,
-Joe

#5 lore raw

PATCH v2 1/11 drivers/net/vsc9953: Cleanup patch

In reply to Joe Hershberger

Hi Joe,

Quoted 3 lines
Quoted 1 line

-#define CONFIG_VSC9953_PORT_ENA 0x00003a00

Why is this value changing? Was it just wrong before?

Sorry, I missed this comment. Yes, the correct value that only enables the port is 0x00002000. The rest of the bits are set to 1 because they are reserved and default values. Since this patch changes the way l2qsys_reg->sys.switch_port_mode[i] is set (out_le32() replaced by setbits_le32()), the other bits are no longer touched when enabling the port:
- out_le32(&l2qsys_reg->sys.switch_port_mode[i],
- CONFIG_VSC9953_PORT_ENA);
+ setbits_le32(&l2qsys_reg->sys.switch_port_mode[i],
+ CONFIG_VSC9953_PORT_ENA)

Should I make a different patch for this change?

Best regards,
Codrin

#6 lore raw

PATCH v2 1/11 drivers/net/vsc9953: Cleanup patch

Hi Codrin,

Quoted 6 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 3 lines
Quoted 1 line

-#define CONFIG_VSC9953_PORT_ENA 0x00003a00

Why is this value changing? Was it just wrong before?

Sorry, I missed this comment. Yes, the correct value that only enables the port is 0x00002000. The rest of the bits are set to 1 because they are reserved and default values. Since this patch changes the way l2qsys_reg->sys.switch_port_mode[i] is set (out_le32() replaced by setbits_le32()), the other bits are no longer touched when enabling the port:

OK. This is (obviously) unclear as is.

Quoted 6 lines
drivers/net/vsc9953.c +2 -2
-               out_le32(&l2qsys_reg->sys.switch_port_mode[i],
-                        CONFIG_VSC9953_PORT_ENA);
+               setbits_le32(&l2qsys_reg->sys.switch_port_mode[i],
+                            CONFIG_VSC9953_PORT_ENA)

Should I make a different patch for this change?

For sure. Include the comment you made above in the log.

Thanks,
-Joe

#7 lore raw

PATCH v2 2/11 drivers/net/vsc9953: Fix missing reserved register

In reply to Codrin Ciubotariu

The VSC9953 DS reserves a register between vlan_mask and anag_efil registers.

---
Changes for v2:
- removed Change-id field;

 include/vsc9953.h | 1 +
 1 file changed, 1 insertion(+)
include/vsc9953.h +1 -0
index 920402f..2b88c5c 100644
@@ -147,6 +147,7 @@ struct vsc9953_ana_ana_tables {
 struct vsc9953_ana_ana {
 	u32	adv_learn;
 	u32	vlan_mask;
+	u32	reserved;
 	u32	anag_efil;
 	u32	an_events;
 	u32	storm_limit_burst;
Signature · 1 line
1.9.3
#8 lore raw

PATCH v2 2/11 drivers/net/vsc9953: Fix missing reserved register

Hi Codrin,

Quoted 5 lines · Codrin Ciubotariu

The VSC9953 DS reserves a register between vlan_mask and anag_efil registers.

---

Where is your Signed-off-by: ? Please either update the "Author" in the commit to Johnson Leung or add your Signed-off-by.

-Joe

#9 lore raw

PATCH v2 2/11 drivers/net/vsc9953: Fix missing reserved register

Hi Joe,

Quoted 10 lines
Quoted 5 lines

The VSC9953 DS reserves a register between vlan_mask and anag_efil registers.

---

Where is your Signed-off-by: ? Please either update the "Author" in the commit to Johnson Leung or add your Signed-off-by.

-Joe

Johnson found the issue, but I made a separate patch for it. I will add my signature in v3.

Best regards,
Codrin

#10 lore raw

PATCH v2 3/11 drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

In reply to Codrin Ciubotariu

At startup, the default configuration should be:
- enable HW learning on all ports (HW default);
- all ports are VLAN aware;
- all ports are members of VLAN 1;
- all ports have Port-based VLAN 1;
- on all ports, the switch is allowed to remove maximum one VLAN tag,
- on egress, the switch should add a VLAN tag if the frame is classified to a different VLAN than the port's Port-based VLAN;

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 266 +++++++++++++++++++++++++++++++++++++++++++++++++-
 include/vsc9953.h     |  61 +++++++++++-
 2 files changed, 325 insertions(+), 2 deletions(-)
drivers/net/vsc9953.c +265 -1
index 720ae47..9dec683 100644
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2014 Freescale Semiconductor, Inc.
+ *  Copyright 2014-2015 Freescale Semiconductor, Inc.
  *
  *  SPDX-License-Identifier:      GPL-2.0+
  *
@@ -176,6 +176,268 @@ static int vsc9953_port_init(int port_no)
 	return 0;
 }
 
+static int vsc9953_vlan_table_poll_idle(void)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+	int				timeout;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	timeout = 50000;
+	while (((in_le32(&l2ana_reg->ana_tables.vlan_access) &
+			CONFIG_VSC9953_VLAN_CMD_MASK) !=
+		CONFIG_VSC9953_VLAN_CMD_IDLE) && --timeout)
+		udelay(1);
+
+	return !!timeout;
+}
+
+/* vlan table set/clear all membership of vid */
+static void vsc9953_vlan_table_membership_all_set(int vid, int set)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	if (!vsc9953_vlan_table_poll_idle()) {
+		debug("VLAN table timeout\n");
+		return;
+	}
+
+	/* read current vlan configuration */
+	clrsetbits_le32(&l2ana_reg->ana_tables.vlan_tidx,
+			CONFIG_VSC9953_ANA_TBL_VID_MASK,
+			field_set(vid, CONFIG_VSC9953_ANA_TBL_VID_MASK));
+
+	clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+			CONFIG_VSC9953_VLAN_CMD_MASK,
+			field_set(CONFIG_VSC9953_VLAN_CMD_READ,
+				  CONFIG_VSC9953_VLAN_CMD_MASK));
+
+	if (!vsc9953_vlan_table_poll_idle()) {
+		debug("VLAN table timeout\n");
+		return;
+	}
+
+	clrsetbits_le32(&l2ana_reg->ana_tables.vlan_tidx,
+			CONFIG_VSC9953_ANA_TBL_VID_MASK,
+			field_set(vid, CONFIG_VSC9953_ANA_TBL_VID_MASK));
+
+	if (!set)
+		clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+				CONFIG_VSC9953_VLAN_PORT_MASK |
+				CONFIG_VSC9953_VLAN_CMD_MASK,
+				field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+					  CONFIG_VSC9953_VLAN_CMD_MASK));
+	else
+		clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+				CONFIG_VSC9953_VLAN_PORT_MASK |
+				CONFIG_VSC9953_VLAN_CMD_MASK,
+				field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+					  CONFIG_VSC9953_VLAN_CMD_MASK) |
+				CONFIG_VSC9953_VLAN_PORT_MASK);
+}
+
+/* Set PVID for a VSC9953 port */
+static void vsc9953_port_vlan_pvid_set(int port_no, int pvid)
+{
+	struct vsc9953_analyzer	*l2ana_reg;
+	struct vsc9953_rew_reg	*l2rew_reg;
+
+	/* Administrative down */
+	if ((!vsc9953_l2sw.port[port_no].enabled)) {
+		printf("Port %d is administrative down\n", port_no);
+		return;
+	}
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+	l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
+			VSC9953_REW_OFFSET);
+
+	/* Set PVID on ingress */
+	clrsetbits_le32(&l2ana_reg->port[port_no].vlan_cfg,
+			CONFIG_VSC9953_VLAN_CFG_VID_MASK,
+			field_set(pvid, CONFIG_VSC9953_VLAN_CFG_VID_MASK));
+
+	/* Set PVID on egress */
+	clrsetbits_le32(&l2rew_reg->port[port_no].port_vlan_cfg,
+			CONFIG_VSC9953_PORT_VLAN_CFG_VID_MASK,
+			field_set(pvid, CONFIG_VSC9953_PORT_VLAN_CFG_VID_MASK));
+}
+
+static void vsc9953_port_all_vlan_pvid_set(int pvid)
+{
+	int		i;
+
+	for (i = 0; i < VSC9953_MAX_PORTS; i++)
+		vsc9953_port_vlan_pvid_set(i, pvid);
+}
+
+/* Enable/disable vlan aware of a VSC9953 port */
+static void vsc9953_port_vlan_aware_set(int port_no, int enabled)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	/* Administrative down */
+	if (!vsc9953_l2sw.port[port_no].enabled) {
+		printf("Port %d is administrative down\n", port_no);
+		return;
+	}
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	if (enabled)
+		setbits_le32(&l2ana_reg->port[port_no].vlan_cfg,
+			     CONFIG_VSC9953_VLAN_CFG_AWARE_ENA);
+	else
+		clrbits_le32(&l2ana_reg->port[port_no].vlan_cfg,
+			     CONFIG_VSC9953_VLAN_CFG_AWARE_ENA);
+}
+
+/* Set all VSC9953 ports' vlan aware  */
+static void vsc9953_port_all_vlan_aware_set(int enabled)
+{
+	int		i;
+
+	for (i = 0; i < VSC9953_MAX_PORTS; i++)
+		vsc9953_port_vlan_aware_set(i, enabled);
+}
+
+/* Enable/disable vlan pop count of a VSC9953 port */
+static void vsc9953_port_vlan_popcnt_set(int port_no, int popcnt)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	/* Administrative down */
+	if (!vsc9953_l2sw.port[port_no].enabled) {
+		printf("Port %d is administrative down\n", port_no);
+		return;
+	}
+
+	if (popcnt > 3 || popcnt < 0) {
+		printf("Invalid pop count value: %d\n", port_no);
+		return;
+	}
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	clrsetbits_le32(&l2ana_reg->port[port_no].vlan_cfg,
+			CONFIG_VSC9953_VLAN_CFG_POP_CNT_MASK,
+			field_set(popcnt,
+				  CONFIG_VSC9953_VLAN_CFG_POP_CNT_MASK));
+}
+
+/* Set all VSC9953 ports' pop count  */
+static void vsc9953_port_all_vlan_poncnt_set(int popcnt)
+{
+	int		i;
+
+	for (i = 0; i < VSC9953_MAX_PORTS; i++)
+		vsc9953_port_vlan_popcnt_set(i, popcnt);
+}
+
+/* Enable/disable learning for frames dropped due to ingress filtering */
+static void vsc9953_vlan_ingr_fltr_learn_drop(int enable)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	if (enable)
+		setbits_le32(&l2ana_reg->ana.adv_learn,
+			     CONFIG_VSC9953_VLAN_CHK);
+	else
+		clrbits_le32(&l2ana_reg->ana.adv_learn,
+			     CONFIG_VSC9953_VLAN_CHK);
+}
+
+/* Egress untag modes of a VSC9953 port */
+enum egress_untag_mode {
+	EGRESS_UNTAG_ALL = 0,
+	EGRESS_UNTAG_PVID_AND_ZERO,
+	EGRESS_UNTAG_ZERO,
+	EGRESS_UNTAG_NONE,
+};
+
+static void vsc9953_port_vlan_egr_untag_set(int port_no,
+					    enum egress_untag_mode mode)
+{
+	struct vsc9953_rew_reg	*l2rew_reg;
+
+	/* Administrative down */
+	if (!vsc9953_l2sw.port[port_no].enabled) {
+		printf("Port %d is administrative down\n", port_no);
+		return;
+	}
+
+	l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
+			VSC9953_REW_OFFSET);
+
+	switch (mode) {
+	case EGRESS_UNTAG_ALL:
+		clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+				CONFIG_VSC9953_TAG_CFG_MASK,
+				CONFIG_VSC9953_TAG_CFG_NONE);
+		break;
+	case EGRESS_UNTAG_PVID_AND_ZERO:
+		clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+				CONFIG_VSC9953_TAG_CFG_MASK,
+				CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO);
+		break;
+	case EGRESS_UNTAG_ZERO:
+		clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+				CONFIG_VSC9953_TAG_CFG_MASK,
+				CONFIG_VSC9953_TAG_CFG_ALL_ZERO);
+		break;
+	case EGRESS_UNTAG_NONE:
+		clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+				CONFIG_VSC9953_TAG_CFG_MASK,
+				CONFIG_VSC9953_TAG_CFG_ALL);
+		break;
+	default:
+		printf("Unknown untag mode for port %d\n", port_no);
+	}
+}
+
+static void vsc9953_port_all_vlan_egress_untagged_set(
+		enum egress_untag_mode mode)
+{
+	int		i;
+
+	for (i = 0; i < VSC9953_MAX_PORTS; i++)
+		vsc9953_port_vlan_egr_untag_set(i, mode);
+}
+
+/*****************************************************************************
+At startup, the default configuration would be:
+	- HW learning enabled on all ports; (HW default)
+	- All ports are in VLAN 1;
+	- All ports are VLAN aware;
+	- All ports have POP_COUNT 1;
+	- All ports have PVID 1;
+	- All ports have TPID 0x8100; (HW default)
+	- All ports tag frames classified to all VLANs that are not PVID;
+*****************************************************************************/
+void vsc9953_default_configuration(void)
+{
+	int i;
+
+	for (i = 0; i < VSC9953_MAX_VLAN; i++)
+		vsc9953_vlan_table_membership_all_set(i, 0);
+	vsc9953_port_all_vlan_aware_set(1);
+	vsc9953_port_all_vlan_pvid_set(1);
+	vsc9953_port_all_vlan_poncnt_set(1);
+	vsc9953_vlan_table_membership_all_set(1, 1);
+	vsc9953_vlan_ingr_fltr_learn_drop(1);
+	vsc9953_port_all_vlan_egress_untagged_set(EGRESS_UNTAG_PVID_AND_ZERO);
+}
+
 void vsc9953_init(bd_t *bis)
 {
 	u32				i, hdx_cfg = 0, phy_addr = 0;
@@ -306,6 +568,8 @@ void vsc9953_init(bd_t *bis)
 		}
 	}
 
+	vsc9953_default_configuration();
+
 	printf("VSC9953 L2 switch initialized\n");
 	return;
 }
include/vsc9953.h +60 -1

97 lines not on this page · raw message

Signature · 1 line
1.9.3
#11 lore raw

PATCH v2 3/11 drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

Hi Codrin,

Quoted 41 lines · Codrin Ciubotariu

At startup, the default configuration should be:
- enable HW learning on all ports (HW default);
- all ports are VLAN aware;
- all ports are members of VLAN 1;
- all ports have Port-based VLAN 1;
- on all ports, the switch is allowed to remove maximum one VLAN tag,
- on egress, the switch should add a VLAN tag if the frame is classified to a different VLAN than the port's Port-based VLAN;

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 266 +++++++++++++++++++++++++++++++++++++++++++++++++-
 include/vsc9953.h     |  61 +++++++++++-
 2 files changed, 325 insertions(+), 2 deletions(-)
drivers/net/vsc9953.c +6 -1
index 720ae47..9dec683 100644
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2014 Freescale Semiconductor, Inc.
+ *  Copyright 2014-2015 Freescale Semiconductor, Inc.
  *
  *  SPDX-License-Identifier:      GPL-2.0+
  *
@@ -176,6 +176,268 @@ static int vsc9953_port_init(int port_no)
        return 0;
 }
 
+static int vsc9953_vlan_table_poll_idle(void)
+{
+       struct vsc9953_analyzer         *l2ana_reg;
+       int                             timeout;
+

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 193

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       timeout = 50000;
+       while (((in_le32(&l2ana_reg->ana_tables.vlan_access) &
+                       CONFIG_VSC9953_VLAN_CMD_MASK) !=
+               CONFIG_VSC9953_VLAN_CMD_IDLE) && --timeout)
+               udelay(1);
+
+       return !!timeout;

Maybe this:

+ return timeout ? 0 : -EBUSY;

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 204

Quoted 11 lines
drivers/net/vsc9953.c +11 -0
+}
+
+/* vlan table set/clear all membership of vid */
+static void vsc9953_vlan_table_membership_all_set(int vid, int set)
+{
+       struct vsc9953_analyzer         *l2ana_reg;
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       if (!vsc9953_vlan_table_poll_idle()) {

If you accept the above, you need to change these to:
+ if (vsc9953_vlan_table_poll_idle() < 0) {

or

+ if (vsc9953_vlan_table_poll_idle() == -EBUSY) {

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+               debug("VLAN table timeout\n");
+               return;
+       }
+
+       /* read current vlan configuration */

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 219

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       clrsetbits_le32(&l2ana_reg->ana_tables.vlan_tidx,
+                       CONFIG_VSC9953_ANA_TBL_VID_MASK,
+                       field_set(vid, CONFIG_VSC9953_ANA_TBL_VID_MASK));
+
+       clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                       CONFIG_VSC9953_VLAN_CMD_MASK,
+                       field_set(CONFIG_VSC9953_VLAN_CMD_READ,
+                                 CONFIG_VSC9953_VLAN_CMD_MASK));
+
+       if (!vsc9953_vlan_table_poll_idle()) {

Here too.

Quoted 12 lines
drivers/net/vsc9953.c +11 -0
+               debug("VLAN table timeout\n");
+               return;
+       }
+
+       clrsetbits_le32(&l2ana_reg->ana_tables.vlan_tidx,
+                       CONFIG_VSC9953_ANA_TBL_VID_MASK,
+                       field_set(vid, CONFIG_VSC9953_ANA_TBL_VID_MASK));
+
 
+       if (!set)
+               clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                               CONFIG_VSC9953_VLAN_PORT_MASK |

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 240

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                               CONFIG_VSC9953_VLAN_CMD_MASK,
+                               field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+                                         CONFIG_VSC9953_VLAN_CMD_MASK));
+       else
+               clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                               CONFIG_VSC9953_VLAN_PORT_MASK |
+                               CONFIG_VSC9953_VLAN_CMD_MASK,
+                               field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+                                         CONFIG_VSC9953_VLAN_CMD_MASK) |
+                               CONFIG_VSC9953_VLAN_PORT_MASK);

It seems this could if statement could all be simplified as:
+ clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,

+                       CONFIG_VSC9953_VLAN_PORT_MASK |
+                       CONFIG_VSC9953_VLAN_CMD_MASK,
+                       field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,

+ CONFIG_VSC9953_VLAN_CMD_MASK) |
+ (set ? CONFIG_VSC9953_VLAN_PORT_MASK : 0));

It may also help to rename the parameter from "set" to something like "set_member".

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 250

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+}
+
+/* Set PVID for a VSC9953 port */
+static void vsc9953_port_vlan_pvid_set(int port_no, int pvid)
+{
+       struct vsc9953_analyzer *l2ana_reg;
+       struct vsc9953_rew_reg  *l2rew_reg;
+
+       /* Administrative down */
+       if ((!vsc9953_l2sw.port[port_no].enabled)) {

Why do you have double "((" and "))"?

Quoted 13 lines
drivers/net/vsc9953.c +13 -0
+               printf("Port %d is administrative down\n", port_no);
+               return;
+       }
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+       l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
+                       VSC9953_REW_OFFSET);
+
+       /* Set PVID on ingress */
+       clrsetbits_le32(&l2ana_reg->port[port_no].vlan_cfg,
+                       CONFIG_VSC9953_VLAN_CFG_VID_MASK,
+                       field_set(pvid, CONFIG_VSC9953_VLAN_CFG_VID_MASK));

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 273

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+
+       /* Set PVID on egress */
+       clrsetbits_le32(&l2rew_reg->port[port_no].port_vlan_cfg,
+                       CONFIG_VSC9953_PORT_VLAN_CFG_VID_MASK,
+                       field_set(pvid, CONFIG_VSC9953_PORT_VLAN_CFG_VID_MASK));
+}
+
+static void vsc9953_port_all_vlan_pvid_set(int pvid)
+{
+       int             i;

Use a single space.

Quoted 21 lines
drivers/net/vsc9953.c +21 -0
+
+       for (i = 0; i < VSC9953_MAX_PORTS; i++)
+               vsc9953_port_vlan_pvid_set(i, pvid);
+}
+
+/* Enable/disable vlan aware of a VSC9953 port */
+static void vsc9953_port_vlan_aware_set(int port_no, int enabled)
+{
+       struct vsc9953_analyzer         *l2ana_reg;
+
+       /* Administrative down */
+       if (!vsc9953_l2sw.port[port_no].enabled) {
+               printf("Port %d is administrative down\n", port_no);
+               return;
+       }
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       if (enabled)
+               setbits_le32(&l2ana_reg->port[port_no].vlan_cfg,

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 304

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                            CONFIG_VSC9953_VLAN_CFG_AWARE_ENA);
+       else
+               clrbits_le32(&l2ana_reg->port[port_no].vlan_cfg,
+                            CONFIG_VSC9953_VLAN_CFG_AWARE_ENA);
+}
+
+/* Set all VSC9953 ports' vlan aware  */
+static void vsc9953_port_all_vlan_aware_set(int enabled)
+{
+       int             i;

Use a single space.

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 313

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+
+       for (i = 0; i < VSC9953_MAX_PORTS; i++)
+               vsc9953_port_vlan_aware_set(i, enabled);
+}
+
+/* Enable/disable vlan pop count of a VSC9953 port */
+static void vsc9953_port_vlan_popcnt_set(int port_no, int popcnt)
+{
+       struct vsc9953_analyzer         *l2ana_reg;

Use a single space.

Quoted 15 lines
drivers/net/vsc9953.c +15 -0
+
+       /* Administrative down */
+       if (!vsc9953_l2sw.port[port_no].enabled) {
+               printf("Port %d is administrative down\n", port_no);
+               return;
+       }
+
+       if (popcnt > 3 || popcnt < 0) {
+               printf("Invalid pop count value: %d\n", port_no);
+               return;
+       }
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 338

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       clrsetbits_le32(&l2ana_reg->port[port_no].vlan_cfg,
+                       CONFIG_VSC9953_VLAN_CFG_POP_CNT_MASK,
+                       field_set(popcnt,
+                                 CONFIG_VSC9953_VLAN_CFG_POP_CNT_MASK));
+}
+
+/* Set all VSC9953 ports' pop count  */
+static void vsc9953_port_all_vlan_poncnt_set(int popcnt)
+{
+       int             i;

Use a single space.

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 347

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+
+       for (i = 0; i < VSC9953_MAX_PORTS; i++)
+               vsc9953_port_vlan_popcnt_set(i, popcnt);
+}
+
+/* Enable/disable learning for frames dropped due to ingress filtering */
+static void vsc9953_vlan_ingr_fltr_learn_drop(int enable)
+{
+       struct vsc9953_analyzer         *l2ana_reg;

Use a single space.

Quoted 14 lines
drivers/net/vsc9953.c +14 -0
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       if (enable)
+               setbits_le32(&l2ana_reg->ana.adv_learn,
+                            CONFIG_VSC9953_VLAN_CHK);
+       else
+               clrbits_le32(&l2ana_reg->ana.adv_learn,
+                            CONFIG_VSC9953_VLAN_CHK);
+}
+
+/* Egress untag modes of a VSC9953 port */
+enum egress_untag_mode {

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 371

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       EGRESS_UNTAG_ALL = 0,
+       EGRESS_UNTAG_PVID_AND_ZERO,
+       EGRESS_UNTAG_ZERO,
+       EGRESS_UNTAG_NONE,
+};
+
+static void vsc9953_port_vlan_egr_untag_set(int port_no,
+                                           enum egress_untag_mode mode)
+{
+       struct vsc9953_rew_reg  *l2rew_reg;

Use a single space.

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+
+       /* Administrative down */
+       if (!vsc9953_l2sw.port[port_no].enabled) {
+               printf("Port %d is administrative down\n", port_no);
+               return;
+       }
+
+       l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
+                       VSC9953_REW_OFFSET);
+

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 391

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       switch (mode) {
+       case EGRESS_UNTAG_ALL:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_NONE);
+               break;
+       case EGRESS_UNTAG_PVID_AND_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO);

This seems like the naming is inverted. The enum value is called "untag" pvid and zero, but the config is called "tag" all pvid and zero. Is this a bug or just poorly named constants / enum values?

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 396

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+               break;
+       case EGRESS_UNTAG_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL_ZERO);

Also here.

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+               break;
+       case EGRESS_UNTAG_NONE:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL);

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 411

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+               break;
+       default:
+               printf("Unknown untag mode for port %d\n", port_no);
+       }
+}
+
+static void vsc9953_port_all_vlan_egress_untagged_set(
+               enum egress_untag_mode mode)
+{
+       int             i;

Use a single space.

Quoted 55 lines
drivers/net/vsc9953.c +29 -0
+
+       for (i = 0; i < VSC9953_MAX_PORTS; i++)
+               vsc9953_port_vlan_egr_untag_set(i, mode);
+}
+
+/*****************************************************************************
+At startup, the default configuration would be:
+       - HW learning enabled on all ports; (HW default)
+       - All ports are in VLAN 1;
+       - All ports are VLAN aware;
+       - All ports have POP_COUNT 1;
+       - All ports have PVID 1;
+       - All ports have TPID 0x8100; (HW default)
+       - All ports tag frames classified to all VLANs that are not PVID;
+*****************************************************************************/
+void vsc9953_default_configuration(void)
+{
+       int i;
+
+       for (i = 0; i < VSC9953_MAX_VLAN; i++)
+               vsc9953_vlan_table_membership_all_set(i, 0);
+       vsc9953_port_all_vlan_aware_set(1);
+       vsc9953_port_all_vlan_pvid_set(1);
+       vsc9953_port_all_vlan_poncnt_set(1);
+       vsc9953_vlan_table_membership_all_set(1, 1);
+       vsc9953_vlan_ingr_fltr_learn_drop(1);
+       vsc9953_port_all_vlan_egress_untagged_set(EGRESS_UNTAG_PVID_AND_ZERO);
+}
+
 void vsc9953_init(bd_t *bis)
 {
        u32                             i, hdx_cfg = 0, phy_addr = 0;
drivers/net/vsc9953.c +2 -0
@@ -306,6 +568,8 @@ void vsc9953_init(bd_t *bis)
                }
        }
 
+       vsc9953_default_configuration();
+
        printf("VSC9953 L2 switch initialized\n");
        return;
 }
include/vsc9953.h +1 -1
index 2b88c5c..bf81623 100644
@@ -7,7 +7,7 @@
  *  terms of the GNU Public License, Version 2, incorporated
  *  herein by reference.
  *
- * Copyright 2013  Freescale Semiconductor, Inc.
+ * Copyright 2013, 2015 Freescale Semiconductor, Inc.
  *
  */
 

include/vsc9953.h line 23

Quoted 5 lines
include/vsc9953.h +2 -0
@@ -19,9 +19,13 @@
 #include <asm/types.h>
 #include <malloc.h>
 
+#define field_set(val, mask)           ((val) * ((mask) & ~((mask) << 1)))
+#define field_get(val, mask)           ((val) / ((mask) & ~((mask) << 1)))

I don't follow why this is unique to this chip? Also, get is never used. Is it just for completeness, I assume.

I think you should either be using the functions in include/bitfield.h or you should be adding these there instead of here. If you decide to add them there, then naturally do it as a separate patch and with good comments and naming consistent with that file and as functions not macros. This method is nice in that you use the mask to define the shift instead of requiring it as a separate constant.

Quoted 59 lines
include/vsc9953.h +34 -0
+
 #define VSC9953_OFFSET                 (CONFIG_SYS_CCSRBAR_DEFAULT + 0x800000)
 
 #define VSC9953_SYS_OFFSET             0x010000
+#define VSC9953_REW_OFFSET             0x030000
 #define VSC9953_DEV_GMII_OFFSET                0x100000
 #define VSC9953_QSYS_OFFSET            0x200000
 #define VSC9953_ANA_OFFSET             0x280000
@@ -84,9 +88,38 @@
 #define        CONFIG_VSC9953_VCAP_MV_CFG      0x0000ffff
 #define        CONFIG_VSC9953_VCAP_UPDATE_CTRL 0x01000004
 
+/* Macros for vsc9953_ana_port.vlan_cfg register */
+#define CONFIG_VSC9953_VLAN_CFG_AWARE_ENA              0x00100000
+#define CONFIG_VSC9953_VLAN_CFG_POP_CNT_MASK           0x000c0000
+#define CONFIG_VSC9953_VLAN_CFG_VID_MASK               0x00000fff
+
+/* Macros for vsc9953_rew_port.port_vlan_cfg register */
+#define CONFIG_VSC9953_PORT_VLAN_CFG_VID_MASK  0x00000fff
+
+/* Macros for vsc9953_ana_ana_tables.vlan_tidx register */
+#define CONFIG_VSC9953_ANA_TBL_VID_MASK                0x00000fff
+
+/* Macros for vsc9953_ana_ana_tables.vlan_access register */
+#define CONFIG_VSC9953_VLAN_PORT_MASK  0x00001ffc
+#define CONFIG_VSC9953_VLAN_CMD_MASK   0x00000003
+#define CONFIG_VSC9953_VLAN_CMD_IDLE   0x00000000
+#define CONFIG_VSC9953_VLAN_CMD_READ   0x00000001
+#define CONFIG_VSC9953_VLAN_CMD_WRITE  0x00000002
+#define CONFIG_VSC9953_VLAN_CMD_INIT   0x00000003
+
 /* Macros for vsc9953_qsys_sys.switch_port_mode register */
 #define CONFIG_VSC9953_PORT_ENA                0x00002000
 
+/* Macros for vsc9953_ana_ana.adv_learn register */
+#define CONFIG_VSC9953_VLAN_CHK                0x00000400
+
+/* Macros for vsc9953_rew_port.port_tag_cfg register */
+#define CONFIG_VSC9953_TAG_CFG_MASK    0x00000180
+#define CONFIG_VSC9953_TAG_CFG_NONE    0x00000000
+#define CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO   0x00000080
+#define CONFIG_VSC9953_TAG_CFG_ALL_ZERO                0x00000100
+#define CONFIG_VSC9953_TAG_CFG_ALL     0x00000180
+
 #define VSC9953_MAX_PORTS              10
 #define VSC9953_PORT_CHECK(port)       \
        (((port) < 0 || (port) >= VSC9953_MAX_PORTS) ? 0 : 1)
@@ -95,6 +128,9 @@
                (port) < VSC9953_MAX_PORTS - 2 || (port) >= VSC9953_MAX_PORTS \
        ) ? 0 : 1 \
 )
+#define VSC9953_MAX_VLAN               4096
+#define VSC9953_VLAN_CHECK(vid)        \
+       (((vid) < 0 || (vid) >= VSC9953_MAX_VLAN) ? 0 : 1)
 
 #define DEFAULT_VSC9953_MDIO_NAME      "VSC9953_MDIO0"
 
@@ -342,6 +378,29 @@ struct     vsc9953_system_reg {
 

include/vsc9953.h struct vsc9953_system_reg { · line 388

Quoted 10 lines
include/vsc9953.h +8 -0
 /* END VSC9953 SYS structure for T1040 U-boot*/
 
+/* VSC9953 REW structure for T1040 U-boot*/
+
+struct vsc9953_rew_port {
+       u32     port_vlan_cfg;
+       u32     port_tag_cfg;
+       u32     port_port_cfg;
+       u32     port_dscp_cfg;
+       u32     port_pcp_dei_qos_map_cfg[16];

Seems like you should drop the "port_" from all of these member names.

Quoted 5 lines
include/vsc9953.h +5 -0
+       u32     reserved[12];
+};
+
+struct vsc9953_rew_common {
+       u32     reserve[4];

include/vsc9953.h struct vsc9953_system_reg { · line 403

Quoted 10 lines
include/vsc9953.h +10 -0
+       u32     dscp_remap_dp1_cfg[64];
+       u32     dscp_remap_cfg[64];
+};
+
+struct vsc9953_rew_reg {
+       struct vsc9953_rew_port port[12];
+       struct vsc9953_rew_common common;
+};
+
+/* END VSC9953 REW structure for T1040 U-boot*/

These comments seem gratuitous and not particularly relevant (begin and end). Perhaps either remove them throughout the file or at least don't add more. At the very least, drop the " structure for T1040 U-boot" which isn't helpful or accurate.

Quoted 10 lines
include/vsc9953.h +0 -1
 /* VSC9953 DEVCPU_GCB structure for T1040 U-boot*/
 
--

1.9.3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#12 lore raw

PATCH v2 3/11 drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

Hi Joe,

Quoted 5 lines
Quoted 1 line

+ return !!timeout;

Maybe this:

+ return timeout ? 0 : -EBUSY;

Ok.

Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+       if (!vsc9953_vlan_table_poll_idle()) {

If you accept the above, you need to change these to:
+ if (vsc9953_vlan_table_poll_idle() < 0) {

or

+ if (vsc9953_vlan_table_poll_idle() == -EBUSY) {

Ok, I think I will go with the first choice.

Quoted 3 lines
Quoted 1 line

+ if (!vsc9953_vlan_table_poll_idle()) {

Here too.

Ok.

Quoted 22 lines

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 240

Quoted 13 lines
drivers/net/vsc9953.c +13 -0
+       if (!set)
+               clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                               CONFIG_VSC9953_VLAN_PORT_MASK |
+                               CONFIG_VSC9953_VLAN_CMD_MASK,
+                               field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+                                         CONFIG_VSC9953_VLAN_CMD_MASK));
+       else
+               clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                               CONFIG_VSC9953_VLAN_PORT_MASK |
+                               CONFIG_VSC9953_VLAN_CMD_MASK,
+                               field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+                                         CONFIG_VSC9953_VLAN_CMD_MASK) |
+                               CONFIG_VSC9953_VLAN_PORT_MASK);

It seems this could if statement could all be simplified as:

drivers/net/vsc9953.c +6 -0
+       clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                       CONFIG_VSC9953_VLAN_PORT_MASK |
+                       CONFIG_VSC9953_VLAN_CMD_MASK,
+                       field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+                                 CONFIG_VSC9953_VLAN_CMD_MASK) |
+                       (set ? CONFIG_VSC9953_VLAN_PORT_MASK : 0));
Quoted 2 lines

It may also help to rename the parameter from "set" to something like "set_member".

Ok.

Quoted 4 lines

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 250

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+       /* Administrative down */
+       if ((!vsc9953_l2sw.port[port_no].enabled)) {

Why do you have double "((" and "))"?

By mistake. I will remove the extra pair.

Quoted 3 lines
Quoted 1 line

+ int i;

Use a single space.

Ok, I will make sure there are no tabs after a variable's type, in all these patches.

Quoted 15 lines

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 391

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       switch (mode) {
+       case EGRESS_UNTAG_ALL:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_NONE);
+               break;
+       case EGRESS_UNTAG_PVID_AND_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO);

This seems like the naming is inverted. The enum value is called "untag" pvid and zero, but the config is called "tag" all pvid and zero. Is this a bug or just poorly named constants / enum values?

Quoted 17 lines

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 396

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+               break;
+       case EGRESS_UNTAG_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL_ZERO);

Also here.

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+               break;
+       case EGRESS_UNTAG_NONE:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL);
+               break;
+       default:
+               printf("Unknown untag mode for port %d\n", port_no);
+       }

Yes, the naming is inverted. The main reason for this is that I couldn't find a short and easy to use command to configure a port's egress to send all frames VLAN tagged except when the VLAN ID equals the Port VLAN ID. I decided to make a command to tell the switch for which VLAN ID's not to tag a frame (untag) instead of making a command to tell the switch for which VLAN IDs to tag the frame (tag). So, for example, the command "ethsw [port <port_no>] tag all except pvid" or
"ethsw [port <port_no>] tag !pvid" became
"ethsw [port <port_no>] untagged pvid". If you think this is not intuitive for both users and developers, I will try to find something more appropriate.

Quoted 6 lines

include/vsc9953.h line 23

Quoted 2 lines
include/vsc9953.h +2 -0
+#define field_set(val, mask)           ((val) * ((mask) & ~((mask) << 1)))
+#define field_get(val, mask)           ((val) / ((mask) & ~((mask) << 1)))

I don't follow why this is unique to this chip? Also, get is never used. Is it just for completeness, I assume.

Quoted 6 lines

I think you should either be using the functions in include/bitfield.h or you should be adding these there instead of here. If you decide to add them there, then naturally do it as a separate patch and with good comments and naming consistent with that file and as functions not macros. This method is nice in that you use the mask to define the shift instead of requiring it as a separate constant.

These are not unique to this chip. If you consider them useful, I will make a separate patch and add them (or something similar) to include/bitfield.h . I could also use those from bitfield.h, but then I should create new macros or use some sort of magic numbers for the "shift" parameter. Changing the already defined bitfiled_*() functions doesn't look like an option since it would require changes all over u-boot.

Quoted 8 lines

include/vsc9953.h struct vsc9953_system_reg { · line 388

Quoted 6 lines
include/vsc9953.h +6 -0
+struct vsc9953_rew_port {
+       u32     port_vlan_cfg;
+       u32     port_tag_cfg;
+       u32     port_port_cfg;
+       u32     port_dscp_cfg;
+       u32     port_pcp_dei_qos_map_cfg[16];

Seems like you should drop the "port_" from all of these member names.

Yes, I will remove the "port_".

Quoted 9 lines
Quoted 9 lines
include/vsc9953.h +9 -0
+struct vsc9953_rew_common {
+       u32     reserve[4];
+       u32     dscp_remap_dp1_cfg[64];
+       u32     dscp_remap_cfg[64];
+};
+
+struct vsc9953_rew_reg {
+       struct vsc9953_rew_port port[12];
+       struct vsc9953_rew_common common;
Quoted 9 lines

include/vsc9953.h struct vsc9953_system_reg { · line 403

Quoted 3 lines
include/vsc9953.h +3 -0
+};
+
+/* END VSC9953 REW structure for T1040 U-boot*/

These comments seem gratuitous and not particularly relevant (begin and end). Perhaps either remove them throughout the file or at least don't add more. At the very least, drop the " structure for T1040 U-boot" which isn't helpful or accurate.

Yes, the " structure for T1040 U-boot" seems irrelevant indeed. I will also remove the other comments if you consider them unnecessary. To me it looks like it groups the structures a bit and might help developers look for a specific register. I will remove them in the patch with the clean-up.

Thanks and best regards,
Codrin

#13 lore raw

PATCH v2 3/11 drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

Hi Codrin,

Quoted 102 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 5 lines
Quoted 1 line

+ return !!timeout;

Maybe this:

+ return timeout ? 0 : -EBUSY;

Ok.

Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+       if (!vsc9953_vlan_table_poll_idle()) {

If you accept the above, you need to change these to:
+ if (vsc9953_vlan_table_poll_idle() < 0) {

or

+ if (vsc9953_vlan_table_poll_idle() == -EBUSY) {

Ok, I think I will go with the first choice.

Quoted 3 lines
Quoted 1 line

+ if (!vsc9953_vlan_table_poll_idle()) {

Here too.

Ok.

Quoted 22 lines

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 240

Quoted 13 lines
drivers/net/vsc9953.c +13 -0
+       if (!set)
+               clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                               CONFIG_VSC9953_VLAN_PORT_MASK |
+                               CONFIG_VSC9953_VLAN_CMD_MASK,
+                               field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+                                         CONFIG_VSC9953_VLAN_CMD_MASK));
+       else
+               clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                               CONFIG_VSC9953_VLAN_PORT_MASK |
+                               CONFIG_VSC9953_VLAN_CMD_MASK,
+                               field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+                                         CONFIG_VSC9953_VLAN_CMD_MASK) |
+                               CONFIG_VSC9953_VLAN_PORT_MASK);

It seems this could if statement could all be simplified as:

drivers/net/vsc9953.c +6 -0
+       clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                       CONFIG_VSC9953_VLAN_PORT_MASK |
+                       CONFIG_VSC9953_VLAN_CMD_MASK,
+                       field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+                                 CONFIG_VSC9953_VLAN_CMD_MASK) |
+                       (set ? CONFIG_VSC9953_VLAN_PORT_MASK : 0));
Quoted 2 lines

It may also help to rename the parameter from "set" to something like "set_member".

Ok.

Quoted 4 lines

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 250

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+       /* Administrative down */
+       if ((!vsc9953_l2sw.port[port_no].enabled)) {

Why do you have double "((" and "))"?

By mistake. I will remove the extra pair.

Quoted 3 lines
Quoted 1 line

+ int i;

Use a single space.

Ok, I will make sure there are no tabs after a variable's type, in all these patches.

Quoted 15 lines

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 391

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       switch (mode) {
+       case EGRESS_UNTAG_ALL:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_NONE);
+               break;
+       case EGRESS_UNTAG_PVID_AND_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO);

This seems like the naming is inverted. The enum value is called "untag" pvid and zero, but the config is called "tag" all pvid and zero. Is this a bug or just poorly named constants / enum values?

Quoted 17 lines

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 396

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+               break;
+       case EGRESS_UNTAG_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL_ZERO);

Also here.

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+               break;
+       case EGRESS_UNTAG_NONE:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL);
+               break;
+       default:
+               printf("Unknown untag mode for port %d\n", port_no);
+       }
Quoted 10 lines

Yes, the naming is inverted. The main reason for this is that I couldn't find a short and easy to use command to configure a port's egress to send all frames VLAN tagged except when the VLAN ID equals the Port VLAN ID. I decided to make a command to tell the switch for which VLAN ID's not to tag a frame (untag) instead of making a command to tell the switch for which VLAN IDs to tag the frame (tag). So, for example, the command "ethsw [port <port_no>] tag all except pvid" or
"ethsw [port <port_no>] tag !pvid" became
"ethsw [port <port_no>] untagged pvid". If you think this is not intuitive for both users and developers, I will try to find something more appropriate.

I don't have a problem with using the inverted logic if that's what typical use-cases call for, what I was referring to was those two specific examples. The "all" and "none" seem correctly inverted.

In the other 2 cases, the "tag" vs "untag" is inverted, but the subject is not "PVID_AND_ZERO" vs "ALL_PVID_ZERO"

"EGRESS_UNTAG_PVID_AND_ZERO" -> "CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO", for example. That's the discrepancy I'm concerned about.

Quoted 13 lines
Quoted 6 lines

include/vsc9953.h line 23

Quoted 2 lines
include/vsc9953.h +2 -0
+#define field_set(val, mask)           ((val) * ((mask) & ~((mask) << 1)))
+#define field_get(val, mask)           ((val) / ((mask) & ~((mask) << 1)))

I don't follow why this is unique to this chip? Also, get is never used. Is it just for completeness, I assume.

Quoted 6 lines

I think you should either be using the functions in include/bitfield.h or you should be adding these there instead of here. If you decide to add them there, then naturally do it as a separate patch and with good comments and naming consistent with that file and as functions not macros. This method is nice in that you use the mask to define the shift instead of requiring it as a separate constant.

Quoted 3 lines

These are not unique to this chip. If you consider them useful, I will make a separate patch and add them (or something similar) to include/bitfield.h .

I think this would be the best approach.

Quoted 3 lines

I could also use those from bitfield.h, but then I should create new macros or use some sort of magic numbers for the "shift" parameter.

That could be done, but if you do create macros for the shift parameter, they should go in bitfield.h.

Please do not add magic numbers.

Quoted 3 lines

Changing the already defined bitfiled_*() functions doesn't look like an option since it would require changes all over u-boot.

Yes, certainly do not do this. Use them as is or add new versions. Do no change the existing functions.

Quoted 30 lines
Quoted 8 lines

include/vsc9953.h struct vsc9953_system_reg { · line 388

Quoted 6 lines
include/vsc9953.h +6 -0
+struct vsc9953_rew_port {
+       u32     port_vlan_cfg;
+       u32     port_tag_cfg;
+       u32     port_port_cfg;
+       u32     port_dscp_cfg;
+       u32     port_pcp_dei_qos_map_cfg[16];

Seems like you should drop the "port_" from all of these member names.

Yes, I will remove the "port_".

Quoted 9 lines
Quoted 9 lines
include/vsc9953.h +9 -0
+struct vsc9953_rew_common {
+       u32     reserve[4];
+       u32     dscp_remap_dp1_cfg[64];
+       u32     dscp_remap_cfg[64];
+};
+
+struct vsc9953_rew_reg {
+       struct vsc9953_rew_port port[12];
+       struct vsc9953_rew_common common;
Quoted 9 lines

include/vsc9953.h struct vsc9953_system_reg { · line 403

Quoted 3 lines
include/vsc9953.h +3 -0
+};
+
+/* END VSC9953 REW structure for T1040 U-boot*/

These comments seem gratuitous and not particularly relevant (begin and end). Perhaps either remove them throughout the file or at least don't add more. At the very least, drop the " structure for T1040 U-boot" which isn't helpful or accurate.

Quoted 5 lines

Yes, the " structure for T1040 U-boot" seems irrelevant indeed. I will also remove the other comments if you consider them unnecessary. To me it looks like it groups the structures a bit and might help developers look for a specific register. I will remove them in the patch with the clean-up.

If you think the bracketing of these structs adds clarity, then only remove the trailing text. Otherwise remove all of them completely. Up to you; I'm fine with either way.

Thanks,
-Joe

#14 lore raw

PATCH v2 3/11 drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

Hi Joe,

I removed the lines on which we agreed on...

Quoted 50 lines
Quoted 34 lines
Quoted 16 lines

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no)

Quoted 11 lines
drivers/net/vsc9953.c +11 -0
+       switch (mode) {
+       case EGRESS_UNTAG_ALL:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_NONE);
+               break;
+       case EGRESS_UNTAG_PVID_AND_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+
+ CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO);

This seems like the naming is inverted. The enum value is called "untag" pvid and zero, but the config is called "tag" all pvid and zero. Is this a bug or just poorly named constants / enum values?

Quoted 17 lines

drivers/net/vsc9953.c static int vsc9953_port_init(int port_no) · line 396

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+               break;
+       case EGRESS_UNTAG_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL_ZERO);

Also here.

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+               break;
+       case EGRESS_UNTAG_NONE:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL);
+               break;
+       default:
+               printf("Unknown untag mode for port %d\n", port_no);
+       }
Quoted 3 lines

Yes, the naming is inverted. The main reason for this is that I couldn't find a short and easy to use command to configure a port's egress to send all frames VLAN tagged except when the VLAN ID equals the Port

VLAN ID.

Quoted 7 lines

I decided to make a command to tell the switch for which VLAN ID's not to tag a frame (untag) instead of making a command to tell the switch for which VLAN IDs to tag the frame (tag). So, for example, the command "ethsw [port <port_no>] tag all except pvid" or "ethsw [port <port_no>] tag !pvid" became "ethsw [port <port_no>] untagged pvid". If you think this is not intuitive for both users and developers, I will try to find something more appropriate.

I don't have a problem with using the inverted logic if that's what typical use- cases call for, what I was referring to was those two specific examples. The "all" and "none" seem correctly inverted.

Quoted 6 lines

In the other 2 cases, the "tag" vs "untag" is inverted, but the subject is not "PVID_AND_ZERO" vs "ALL_PVID_ZERO"

"EGRESS_UNTAG_PVID_AND_ZERO" -> "CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO", for example. That's the discrepancy I'm concerned about.

Ok, should I rename the constants to something like VSC9953_TAG_CFG_ALL_BUT_PRIV_ZERO instead of CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO and VSC9953_TAG_CFG_ALL_BUT_ZERO instead of CONFIG_VSC9953_TAG_CFG_ALL_ZERO?

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

include/vsc9953.h line 23

Quoted 3 lines
include/vsc9953.h +2 -0
+#define field_set(val, mask)           ((val) * ((mask) & ~((mask) << 1)))
+#define field_get(val, mask)           ((val) / ((mask) & ~((mask) << 1)))

I don't follow why this is unique to this chip? Also, get is never used. Is it just for completeness, I assume.

I think you should either be using the functions in include/bitfield.h or you should be adding these there instead of here. If you decide to add them there, then naturally do it as a separate patch and with good comments and naming consistent with that file and as functions not macros. This method is nice in that you use the mask to define the shift instead of requiring it as a separate constant.

Quoted 5 lines
Quoted 3 lines

These are not unique to this chip. If you consider them useful, I will make a separate patch and add them (or something similar) to include/bitfield.h .

I think this would be the best approach.

Ok, I will make another patch and add bitfield_set/get() inline functions in include/bitfield.h .

Quoted 24 lines
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
include/vsc9953.h +8 -0
+struct vsc9953_rew_common {
+       u32     reserve[4];
+       u32     dscp_remap_dp1_cfg[64];
+       u32     dscp_remap_cfg[64];
+};
+
+struct vsc9953_rew_reg {
+       struct vsc9953_rew_port port[12];
Quoted 9 lines

include/vsc9953.h struct vsc9953_system_reg { · line 403

Quoted 3 lines
include/vsc9953.h +3 -0
+       struct vsc9953_rew_common common; };
+
+/* END VSC9953 REW structure for T1040 U-boot*/

These comments seem gratuitous and not particularly relevant (begin and end). Perhaps either remove them throughout the file or at least don't add more. At the very least, drop the " structure for T1040 U-boot" which isn't helpful or accurate.

Quoted 5 lines

Yes, the " structure for T1040 U-boot" seems irrelevant indeed. I will also remove the other comments if you consider them unnecessary. To me it looks like it groups the structures a bit and might help developers look for a specific register. I will remove them in the patch with the clean-up.

Quoted 3 lines

If you think the bracketing of these structs adds clarity, then only remove the trailing text. Otherwise remove all of them completely. Up to you; I'm fine with either way.

Ok, I will remove the trailing text and I will see if the remaining comments make sense.

Quoted 3 lines

Thanks,
-Joe

Thanks and best regards,
Codrin

#15 lore raw

PATCH v2 3/11 drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

Hi Codrin,

Quoted 61 lines · Codrin Constantin Ciubotariu

Hi Joe,

I removed the lines on which we agreed on...

Quoted 50 lines
Quoted 34 lines
Quoted 16 lines

Review

Quoted 11 lines
(quoted diff) +11 -0
+       switch (mode) {
+       case EGRESS_UNTAG_ALL:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_NONE);
+               break;
+       case EGRESS_UNTAG_PVID_AND_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+
+ CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO);

This seems like the naming is inverted. The enum value is called "untag" pvid and zero, but the config is called "tag" all pvid and zero. Is this a bug or just poorly named constants / enum values?

Quoted 17 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+               break;
+       case EGRESS_UNTAG_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL_ZERO);

Also here.

Quoted 9 lines
(quoted diff) +9 -0
+               break;
+       case EGRESS_UNTAG_NONE:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL);
+               break;
+       default:
+               printf("Unknown untag mode for port %d\n", port_no);
+       }
Quoted 3 lines

Yes, the naming is inverted. The main reason for this is that I couldn't find a short and easy to use command to configure a port's egress to send all frames VLAN tagged except when the VLAN ID equals the Port

VLAN ID.

Quoted 7 lines

I decided to make a command to tell the switch for which VLAN ID's not to tag a frame (untag) instead of making a command to tell the switch for which VLAN IDs to tag the frame (tag). So, for example, the command "ethsw [port <port_no>] tag all except pvid" or "ethsw [port <port_no>] tag !pvid" became "ethsw [port <port_no>] untagged pvid". If you think this is not intuitive for both users and developers, I will try to find something more appropriate.

I don't have a problem with using the inverted logic if that's what typical use- cases call for, what I was referring to was those two specific examples. The "all" and "none" seem correctly inverted.

Quoted 6 lines

In the other 2 cases, the "tag" vs "untag" is inverted, but the subject is not "PVID_AND_ZERO" vs "ALL_PVID_ZERO"

"EGRESS_UNTAG_PVID_AND_ZERO" -> "CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO", for example. That's the discrepancy I'm concerned about.

Quoted 6 lines

Ok, should I rename the constants to something like VSC9953_TAG_CFG_ALL_BUT_PRIV_ZERO instead of CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO and VSC9953_TAG_CFG_ALL_BUT_ZERO instead of CONFIG_VSC9953_TAG_CFG_ALL_ZERO?

I assume you meant to say VSC9953_TAG_CFG_ALL_BUT_*PVID*_ZERO here.

If so, I think that's clear enough.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+#define field_set(val, mask)           ((val) * ((mask) & ~((mask) << 1)))
+#define field_get(val, mask)           ((val) / ((mask) & ~((mask) << 1)))

I don't follow why this is unique to this chip? Also, get is never used. Is it just for completeness, I assume.

I think you should either be using the functions in include/bitfield.h or you should be adding these there instead of here. If you decide to add them there, then naturally do it as a separate patch and with good comments and naming consistent with that file and as functions not macros. This method is nice in that you use the mask to define the shift instead of requiring it as a separate constant.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

These are not unique to this chip. If you consider them useful, I will make a separate patch and add them (or something similar) to include/bitfield.h .

I think this would be the best approach.

Ok, I will make another patch and add bitfield_set/get() inline functions in include/bitfield.h .

I would recommend you structure it as 3 new functions.

include/bitfield.h +6 -0
index ec4815c..b685804 100644
@@ -39,6 +39,12 @@ static inline uint bitfield_mask(uint shift, uint width)
        return ((1 << width) - 1) << shift;
 }
 
+/* Produces a shift of the bitfield given a mask */
+static inline uint bitfield_shift(uint mask)
+{
+       return ffs(mask) - 1;
+}
+
 /* Extract the value of a bitfield found within a given register value */
 static inline uint bitfield_extract(uint reg_val, uint shift, uint width)
 {
@@ -56,3 +62,23 @@ static inline uint bitfield_replace(uint reg_val,

uint shift, uint width,

        return (reg_val & ~mask) | (bitfield_val << shift);

}
+
+/* Extract the value of a bitfield found within a given register value */ +static inline uint bitfield_extract_by_mask(uint reg_val, uint mask) +{
+ uint shift = bitfield_shift(mask);
+
+ return (reg_val & mask) >> shift;
+}
+
+/*
+ * Replace the value of a bitfield found within a given register value
+ * Returns the newly modified uint value with the replaced field.
+ */
+static inline uint bitfield_replace_by_mask(uint reg_val, uint mask,
+ uint bitfield_val)
+{
+ uint shift = bitfield_shift(mask);
+
+ return (reg_val & ~mask) | ((bitfield_val << shift) & mask);
+}

Quoted 28 lines
Quoted 24 lines
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
(quoted diff) +8 -0
+struct vsc9953_rew_common {
+       u32     reserve[4];
+       u32     dscp_remap_dp1_cfg[64];
+       u32     dscp_remap_cfg[64];
+};
+
+struct vsc9953_rew_reg {
+       struct vsc9953_rew_port port[12];
Quoted 9 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+       struct vsc9953_rew_common common; };
+
+/* END VSC9953 REW structure for T1040 U-boot*/

These comments seem gratuitous and not particularly relevant (begin and end). Perhaps either remove them throughout the file or at least don't add more. At the very least, drop the " structure for T1040 U-boot" which isn't helpful or accurate.

Quoted 5 lines

Yes, the " structure for T1040 U-boot" seems irrelevant indeed. I will also remove the other comments if you consider them unnecessary. To me it looks like it groups the structures a bit and might help developers look for a specific register. I will remove them in the patch with the clean-up.

Quoted 3 lines

If you think the bracketing of these structs adds clarity, then only remove the trailing text. Otherwise remove all of them completely. Up to you; I'm fine with either way.

Quoted 8 lines

Ok, I will remove the trailing text and I will see if the remaining comments make sense.

Quoted 3 lines

Thanks,
-Joe

Thanks and best regards,
Codrin

Cheers,
-Joe

#16 lore raw

PATCH v2 3/11 drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

Hi Joe,

Quoted 84 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Wednesday, July 01, 2015 1:26 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 03/11 v2] drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

Hi Codrin,

Quoted 41 lines · Codrin Constantin Ciubotariu

Hi Joe,

I removed the lines on which we agreed on...

Quoted 37 lines
Quoted 37 lines
Quoted 16 lines

Review

Quoted 11 lines
(quoted diff) +11 -0
+       switch (mode) {
+       case EGRESS_UNTAG_ALL:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_NONE);
+               break;
+       case EGRESS_UNTAG_PVID_AND_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+
+ CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO);

This seems like the naming is inverted. The enum value is called "untag" pvid and zero, but the config is called "tag" all pvid and zero. Is this a bug or just poorly named constants / enum values?

Quoted 17 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+               break;
+       case EGRESS_UNTAG_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL_ZERO);

Also here.

Quoted 9 lines
(quoted diff) +9 -0
+               break;
+       case EGRESS_UNTAG_NONE:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL);
+               break;
+       default:
+               printf("Unknown untag mode for port %d\n", port_no);
+       }

Yes, the naming is inverted. The main reason for this is that I couldn't find a short and easy to use command to configure a port's egress to send all frames VLAN tagged except when the VLAN ID equals the

Port

Quoted 10 lines
Quoted 10 lines

VLAN ID.

Quoted 7 lines

I decided to make a command to tell the switch for which VLAN ID's not to tag a frame (untag) instead of making a command to tell the switch for which VLAN IDs to tag the frame (tag). So, for example, the command "ethsw [port <port_no>] tag all except pvid" or "ethsw [port <port_no>] tag !pvid" became "ethsw [port <port_no>] untagged pvid". If you think this is not intuitive for both users and developers, I will try to find something more appropriate.

I don't have a problem with using the inverted logic if that's what typical

use-

Quoted 4 lines
Quoted 4 lines

cases call for, what I was referring to was those two specific examples. The "all" and "none" seem correctly inverted.

In the other 2 cases, the "tag" vs "untag" is inverted, but the subject is

not

Quoted 4 lines
Quoted 4 lines

"PVID_AND_ZERO" vs "ALL_PVID_ZERO"

"EGRESS_UNTAG_PVID_AND_ZERO" -> "CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO", for example. That's the discrepancy

I'm

Quoted 8 lines
Quoted 1 line

concerned about.

Ok, should I rename the constants to something like VSC9953_TAG_CFG_ALL_BUT_PRIV_ZERO instead of CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO and VSC9953_TAG_CFG_ALL_BUT_ZERO instead of CONFIG_VSC9953_TAG_CFG_ALL_ZERO?

Quoted 3 lines

I assume you meant to say VSC9953_TAG_CFG_ALL_BUT_*PVID*_ZERO here.

If so, I think that's clear enough.

Yes, VSC9953_TAG_CFG_ALL_BUT_PVID_ZERO and VSC9953_TAG_CFG_ALL_BUT_ZERO.

Quoted 34 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

+#define field_set(val, mask) ((val) * ((mask) & ~((mask) <<

1)))

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+#define field_get(val, mask) ((val) / ((mask) & ~((mask) <<

1)))

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

I don't follow why this is unique to this chip? Also, get is never used. Is it just for completeness, I assume.

I think you should either be using the functions in include/bitfield.h or you should be adding these there instead of here. If you decide to add them there, then naturally do it as a separate patch and with good comments and naming consistent with that file and as functions not macros. This method is nice in that you use the mask to define the shift instead of requiring it as a separate

constant.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

These are not unique to this chip. If you consider them useful, I will make a separate patch and add them (or something similar) to include/bitfield.h .

I think this would be the best approach.

Ok, I will make another patch and add bitfield_set/get() inline functions in

include/bitfield.h .

I would recommend you structure it as 3 new functions.

include/bitfield.h +0 -0
index ec4815c..b685804 100644

include/bitfield.h static inline uint bitfield_mask(uint shift, uint width) · line 46

Quoted 8 lines
include/bitfield.h +5 -0
@@ -39,6 +39,12 @@ static inline uint bitfield_mask(uint shift, uint width)
        return ((1 << width) - 1) << shift;
 }
 
+/* Produces a shift of the bitfield given a mask */
+static inline uint bitfield_shift(uint mask)
+{
+       return ffs(mask) - 1;
+}

Ok, should we assure we return 0 if mask is 0? Something like return mask : ffs(mask) - 1 ? 0;

Quoted 19 lines
include/bitfield.h +11 -0
+
 /* Extract the value of a bitfield found within a given register value */
 static inline uint bitfield_extract(uint reg_val, uint shift, uint width)
 {
@@ -56,3 +62,23 @@ static inline uint bitfield_replace(uint reg_val,
 uint shift, uint width,
 
        return (reg_val & ~mask) | (bitfield_val << shift);
 }
+
+/* Extract the value of a bitfield found within a given register value */
+static inline uint bitfield_extract_by_mask(uint reg_val, uint mask)
+{
+       uint shift = bitfield_shift(mask);
+
+       return (reg_val & mask) >> shift;
+}
+
+/*

include/bitfield.h static inline uint bitfield_replace(uint reg_val,

Quoted 10 lines
include/bitfield.h +10 -0
+ * Replace the value of a bitfield found within a given register value
+ * Returns the newly modified uint value with the replaced field.
+ */
+static inline uint bitfield_replace_by_mask(uint reg_val, uint mask,
+                                           uint bitfield_val)
+{
+       uint shift = bitfield_shift(mask);
+
+       return (reg_val & ~mask) | ((bitfield_val << shift) & mask);
+}

Ok.

Best regards,
Codrin

#17 lore raw

PATCH v2 3/11 drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

Hi Codrin,

Quoted 86 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 84 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Wednesday, July 01, 2015 1:26 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 03/11 v2] drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

Hi Codrin,

Quoted 41 lines · Codrin Constantin Ciubotariu

Hi Joe,

I removed the lines on which we agreed on...

Quoted 37 lines
Quoted 37 lines
Quoted 16 lines

Review

Quoted 11 lines
(quoted diff) +11 -0
+       switch (mode) {
+       case EGRESS_UNTAG_ALL:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_NONE);
+               break;
+       case EGRESS_UNTAG_PVID_AND_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+
+ CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO);

This seems like the naming is inverted. The enum value is called "untag" pvid and zero, but the config is called "tag" all pvid and zero. Is this a bug or just poorly named constants / enum values?

Quoted 17 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+               break;
+       case EGRESS_UNTAG_ZERO:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL_ZERO);

Also here.

Quoted 9 lines
(quoted diff) +9 -0
+               break;
+       case EGRESS_UNTAG_NONE:
+               clrsetbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                               CONFIG_VSC9953_TAG_CFG_MASK,
+                               CONFIG_VSC9953_TAG_CFG_ALL);
+               break;
+       default:
+               printf("Unknown untag mode for port %d\n", port_no);
+       }

Yes, the naming is inverted. The main reason for this is that I couldn't find a short and easy to use command to configure a port's egress to send all frames VLAN tagged except when the VLAN ID equals the

Port

Quoted 10 lines
Quoted 10 lines

VLAN ID.

Quoted 7 lines

I decided to make a command to tell the switch for which VLAN ID's not to tag a frame (untag) instead of making a command to tell the switch for which VLAN IDs to tag the frame (tag). So, for example, the command "ethsw [port <port_no>] tag all except pvid" or "ethsw [port <port_no>] tag !pvid" became "ethsw [port <port_no>] untagged pvid". If you think this is not intuitive for both users and developers, I will try to find something more appropriate.

I don't have a problem with using the inverted logic if that's what typical

use-

Quoted 4 lines
Quoted 4 lines

cases call for, what I was referring to was those two specific examples. The "all" and "none" seem correctly inverted.

In the other 2 cases, the "tag" vs "untag" is inverted, but the subject is

not

Quoted 4 lines
Quoted 4 lines

"PVID_AND_ZERO" vs "ALL_PVID_ZERO"

"EGRESS_UNTAG_PVID_AND_ZERO" -> "CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO", for example. That's the discrepancy

I'm

Quoted 8 lines
Quoted 1 line

concerned about.

Ok, should I rename the constants to something like VSC9953_TAG_CFG_ALL_BUT_PRIV_ZERO instead of CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO and VSC9953_TAG_CFG_ALL_BUT_ZERO instead of CONFIG_VSC9953_TAG_CFG_ALL_ZERO?

Quoted 5 lines
Quoted 3 lines

I assume you meant to say VSC9953_TAG_CFG_ALL_BUT_*PVID*_ZERO here.

If so, I think that's clear enough.

Yes, VSC9953_TAG_CFG_ALL_BUT_PVID_ZERO and VSC9953_TAG_CFG_ALL_BUT_ZERO.

Sounds good.

Quoted 35 lines
Quoted 35 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+#define field_set(val, mask) ((val) * ((mask) & ~((mask) <<

1)))

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+#define field_get(val, mask) ((val) / ((mask) & ~((mask) <<

1)))

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

I don't follow why this is unique to this chip? Also, get is never used. Is it just for completeness, I assume.

I think you should either be using the functions in include/bitfield.h or you should be adding these there instead of here. If you decide to add them there, then naturally do it as a separate patch and with good comments and naming consistent with that file and as functions not macros. This method is nice in that you use the mask to define the shift instead of requiring it as a separate

constant.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

These are not unique to this chip. If you consider them useful, I will make a separate patch and add them (or something similar) to include/bitfield.h .

I think this would be the best approach.

Ok, I will make another patch and add bitfield_set/get() inline functions in

include/bitfield.h .

I would recommend you structure it as 3 new functions.

include/bitfield.h +0 -0
index ec4815c..b685804 100644
@@ -39,6 +39,12 @@ static inline uint bitfield_mask(uint shift, uint width)
        return ((1 << width) - 1) << shift;
 }
 
Quoted 7 lines

include/bitfield.h static inline uint bitfield_mask(uint shift, uint width) · line 46

Quoted 5 lines
include/bitfield.h +5 -0
+/* Produces a shift of the bitfield given a mask */
+static inline uint bitfield_shift(uint mask)
+{
+       return ffs(mask) - 1;
+}

Ok, should we assure we return 0 if mask is 0? Something like return mask : ffs(mask) - 1 ? 0;

Sounds like a good idea.

Quoted 32 lines
Quoted 19 lines
include/bitfield.h +11 -0
+
 /* Extract the value of a bitfield found within a given register value */
 static inline uint bitfield_extract(uint reg_val, uint shift, uint width)
 {
@@ -56,3 +62,23 @@ static inline uint bitfield_replace(uint reg_val,
 uint shift, uint width,
 
        return (reg_val & ~mask) | (bitfield_val << shift);
 }
+
+/* Extract the value of a bitfield found within a given register value */
+static inline uint bitfield_extract_by_mask(uint reg_val, uint mask)
+{
+       uint shift = bitfield_shift(mask);
+
+       return (reg_val & mask) >> shift;
+}
+
+/*

include/bitfield.h static inline uint bitfield_replace(uint reg_val,

Quoted 10 lines
include/bitfield.h +10 -0
+ * Replace the value of a bitfield found within a given register value
+ * Returns the newly modified uint value with the replaced field.
+ */
+static inline uint bitfield_replace_by_mask(uint reg_val, uint mask,
+                                           uint bitfield_val)
+{
+       uint shift = bitfield_shift(mask);
+
+       return (reg_val & ~mask) | ((bitfield_val << shift) & mask);
+}

Ok.

Quoted 2 lines

Best regards,
Codrin

Cheers,
-Joe

#18 lore raw

PATCH v2 3/11 drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

In reply to Codrin Ciubotariu

Hi Codrin,

Quoted 26 lines · Codrin Ciubotariu

At startup, the default configuration should be:
- enable HW learning on all ports (HW default);
- all ports are VLAN aware;
- all ports are members of VLAN 1;
- all ports have Port-based VLAN 1;
- on all ports, the switch is allowed to remove maximum one VLAN tag,
- on egress, the switch should add a VLAN tag if the frame is classified to a different VLAN than the port's Port-based VLAN;

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 266 +++++++++++++++++++++++++++++++++++++++++++++++++-
 include/vsc9953.h     |  61 +++++++++++-
 2 files changed, 325 insertions(+), 2 deletions(-)
drivers/net/vsc9953.c +0 -0
index 720ae47..9dec683 100644

drivers/net/vsc9953.c line 2

Quoted 3 lines
drivers/net/vsc9953.c +1 -1
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2014 Freescale Semiconductor, Inc.
+ *  Copyright 2014-2015 Freescale Semiconductor, Inc.

This change should be moved to the last patch.

Quoted 3 lines
drivers/net/vsc9953.c +0 -0
  *
  *  SPDX-License-Identifier:      GPL-2.0+
  *

<snip>

include/vsc9953.h line 10

Quoted 10 lines
include/vsc9953.h +1 -1
index 2b88c5c..bf81623 100644
@@ -7,7 +7,7 @@
  *  terms of the GNU Public License, Version 2, incorporated
  *  herein by reference.
  *
- * Copyright 2013  Freescale Semiconductor, Inc.
+ * Copyright 2013, 2015 Freescale Semiconductor, Inc.

This change should be moved to the last patch.

include/vsc9953.h line 13

Quoted 3 lines
include/vsc9953.h +0 -0
  *
  */
 

<snip>

Thanks,
-Joe

#19 lore raw

PATCH v2 3/11 drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

Hi Joe,

Quoted 38 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:26 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 03/11 v2] drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch

drivers/net/vsc9953.c line 2

Quoted 8 lines
drivers/net/vsc9953.c index renamed from drivers/net/vsc9953.c +0 -0

720ae47..9dec683 100644

drivers/net/vsc9953.c +1 -1
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2014 Freescale Semiconductor, Inc.
+ *  Copyright 2014-2015 Freescale Semiconductor, Inc.

This change should be moved to the last patch.

Quoted 3 lines
drivers/net/vsc9953.c +0 -0
  *
  *  SPDX-License-Identifier:      GPL-2.0+
  *

<snip>

include/vsc9953.h line 10

Quoted 10 lines
include/vsc9953.h index renamed from include/vsc9953.h +0 -0

2b88c5c..bf81623 100644

include/vsc9953.h +1 -1
@@ -7,7 +7,7 @@
  *  terms of the GNU Public License, Version 2, incorporated
  *  herein by reference.
  *
- * Copyright 2013  Freescale Semiconductor, Inc.
+ * Copyright 2013, 2015 Freescale Semiconductor, Inc.

This change should be moved to the last patch.

Quoted 5 lines
Quoted 3 lines
include/vsc9953.h +0 -0
  *
  */
 

<snip>

Ok, I will move these two changes in the last patch.

Best regards,
Codrin

#20 lore raw

PATCH v2 4/11 drivers/net/vsc9953: Refractor the parser for VSC9953 commands

In reply to Codrin Ciubotariu

In order to support multiple commands to configure the VSC9953 L2 Switch, the parser needs to be changed to be more flexible and to support more complex commands. This patch adds a parser that searches for defined keywords in the command and calls the proper function when a match is found. Also, the parser allows for optional keywords, such as "port", to apply the command on a port or on all ports. The already defined commands are also changed a bit to:
ethsw [port <port_no>] { enable | disable | show }

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 381 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 310 insertions(+), 71 deletions(-)
drivers/net/vsc9953.c +310 -71
index 9dec683..4df751a 100644
@@ -10,6 +10,7 @@
 #include <asm/fsl_serdes.h>
 #include <fm_eth.h>
 #include <fsl_memac.h>
+#include <errno.h>
 #include <vsc9953.h>
 
 static struct vsc9953_info vsc9953_l2sw = {
@@ -575,6 +576,10 @@ void vsc9953_init(bd_t *bis)
 }
 
 #ifdef CONFIG_VSC9953_CMD
+
+#define VSC9953_MAX_CMD_PARAMS	20
+#define VSC9953_CMD_PORT_ALL	-1
+
 /* Enable/disable status of a VSC9953 port */
 static void vsc9953_port_status_set(int port_no, u8 enabled)
 {
@@ -595,15 +600,6 @@ static void vsc9953_port_status_set(int port_no, u8 enabled)
 			     CONFIG_VSC9953_PORT_ENA);
 }
 
-/* Set all VSC9953 ports' status */
-static void vsc9953_port_all_status_set(u8 enabled)
-{
-	int		i;
-
-	for (i = 0; i < VSC9953_MAX_PORTS; i++)
-		vsc9953_port_status_set(i, enabled);
-}
-
 /* Start autonegotiation for a VSC9953 PHY */
 static void vsc9953_phy_autoneg(int port_no)
 {
@@ -615,15 +611,6 @@ static void vsc9953_phy_autoneg(int port_no)
 		printf("Failed to start PHY for port %d\n", port_no);
 }
 
-/* Start autonegotiation for all VSC9953 PHYs */
-static void vsc9953_phy_all_autoneg(void)
-{
-	int		i;
-
-	for (i = 0; i < VSC9953_MAX_PORTS; i++)
-		vsc9953_phy_autoneg(i);
-}
-
 /* Print a VSC9953 port's configuration */
 static void vsc9953_port_config_show(int port_no)
 {
@@ -685,75 +672,327 @@ static void vsc9953_port_config_show(int port_no)
 	printf("%8s\n", duplex == DUPLEX_FULL ? "full" : "half");
 }
 
-/* Print VSC9953 ports' configuration */
-static void vsc9953_port_all_config_show(void)
-{
-	int		i;
+/* IDs used to track keywords in a command */
+enum keyword_id {
+	id_key_end = -1,
+	id_help,
+	id_show,
+	id_port,
+	id_enable,
+	id_disable,
+	id_count,	/* keep last */
+};
 
-	for (i = 0; i < VSC9953_MAX_PORTS; i++)
-		vsc9953_port_config_show(i);
-}
+enum keyword_opt_id {
+	id_port_no = id_count + 1,
+	id_count_all,	/* keep last */
+};
 
-/* function to interpret commands starting with "ethsw " */
-static int do_ethsw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+struct command_def {
+	int cmd_to_keywords[VSC9953_MAX_CMD_PARAMS];
+	int cmd_keywords_nr;
+	int port;
+	int err;
+	int (*cmd_function)(struct command_def *parsed_cmd);
+};
+
+#define VSC9953_PORT_CONF_HELP "[port <port_no>] { enable | disable | show } " \
+"- enable/disable a port; show shows a port's configuration"
+
+static int vsc9953_port_status_key_func(struct command_def *parsed_cmd)
 {
-	u8 enable;
-	u32 port;
+	int			i;
+	u8			enabled;
 
-	if (argc < 4)
+	/* Last keyword should tell us if we should enable/disable the port */
+	if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+	    id_enable)
+		enabled = 1;
+	else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+		 id_disable)
+		enabled = 0;
+	else {
+		parsed_cmd->err = 1;
 		return -1;
+	}
 
-	if (strcmp(argv[1], "port"))
-		return -1;
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_port_status_set(parsed_cmd->port, enabled);
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_port_status_set(i, enabled);
+	}
+
+	return 0;
+}
+
+static int vsc9953_port_config_key_func(struct command_def *parsed_cmd)
+{
+	int			i;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_phy_autoneg(parsed_cmd->port);
+		printf("%8s %8s %8s %8s %8s\n",
+		       "Port", "Status", "Link", "Speed",
+		       "Duplex");
+		vsc9953_port_config_show(parsed_cmd->port);
 
-	if (!strcmp(argv[3], "show")) {
-		if (!strcmp(argv[2], "all")) {
-			vsc9953_phy_all_autoneg();
-			printf("%8s %8s %8s %8s %8s\n",
-			       "Port", "Status", "Link", "Speed",
-			       "Duplex");
-			vsc9953_port_all_config_show();
-			return 0;
-		} else {
-			port = simple_strtoul(argv[2], NULL, 10);
-			if (!VSC9953_PORT_CHECK(port))
-				return -1;
-			vsc9953_phy_autoneg(port);
-			printf("%8s %8s %8s %8s %8s\n",
-			       "Port", "Status", "Link", "Speed",
-			       "Duplex");
-			vsc9953_port_config_show(port);
-			return 0;
-		}
-	} else if (!strcmp(argv[3], "enable")) {
-		enable = 1;
-	} else if (!strcmp(argv[3], "disable")) {
-		enable = 0;
 	} else {
-		return -1;
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_phy_autoneg(i);
+		printf("%8s %8s %8s %8s %8s\n",
+		       "Port", "Status", "Link", "Speed", "Duplex");
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_port_config_show(i);
 	}
 
-	if (!strcmp(argv[2], "all")) {
-		vsc9953_port_all_status_set(enable);
+	return 0;
+}
+
+struct keywords_to_function {
+	enum keyword_id cmd_keyword[VSC9953_MAX_CMD_PARAMS];
+	int (*keyword_function)(struct command_def *parsed_cmd);
+} cmd_def[] = {
+		{
+			.cmd_keyword = {
+					id_enable,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_port_status_key_func,
+		}, {
+			.cmd_keyword = {
+					id_disable,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_port_status_key_func,
+		}, {
+			.cmd_keyword = {
+					id_show,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_port_config_key_func,
+		},
+};
+
+struct keywords_optional {
+	enum keyword_id cmd_keyword[VSC9953_MAX_CMD_PARAMS];
+} cmd_opt_def[] = {
+		{
+				.cmd_keyword = {
+						id_port,
+						id_port_no,
+						id_key_end,
+				},
+		},
+};
+
+static int keyword_match_gen(enum keyword_id key_id, int argc,
+			     char *const argv[], int *argc_nr,
+			     struct command_def *parsed_cmd);
+static int keyword_match_port(enum keyword_id key_id, int argc,
+			      char *const argv[], int *argc_nr,
+			      struct command_def *parsed_cmd);
+
+/* Define properties for each keyword;
+ * keep the order synced with enum keyword_id
+ */
+struct keyword_def {
+	const char *keyword_name;
+	int (*match)(enum keyword_id key_id, int argc, char *const argv[],
+		     int *argc_nr, struct command_def *parsed_cmd);
+} keyword[] = {
+		{
+				.keyword_name = "help",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "show",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "port",
+				.match = &keyword_match_port
+		},  {
+				.keyword_name = "enable",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "disable",
+				.match = &keyword_match_gen,
+		},
+};
+
+/* Generic function used to match a keyword only by a string */
+static int keyword_match_gen(enum keyword_id key_id, int argc,
+			     char *const argv[], int *argc_nr,
+			     struct command_def *parsed_cmd)
+{
+	if (strcmp(argv[*argc_nr], keyword[key_id].keyword_name) == 0) {
+		parsed_cmd->cmd_to_keywords[*argc_nr] = key_id;
+
+		return 1;
+	}
+	return 0;
+}
+
+/* Function used to match the command's port */
+static int keyword_match_port(enum keyword_id key_id, int argc,
+			      char *const argv[], int *argc_nr,
+			      struct command_def *parsed_cmd)
+{
+	unsigned long			val;
+
+	if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
 		return 0;
-	} else {
-		port = simple_strtoul(argv[2], NULL, 10);
-		if (!VSC9953_PORT_CHECK(port))
-			return -1;
-		vsc9953_port_status_set(port, enable);
+
+	if (*argc_nr + 1 >= argc)
 		return 0;
+
+	if (strict_strtoul(argv[*argc_nr + 1], 10, &val) != -EINVAL) {
+		if (!VSC9953_PORT_CHECK(val)) {
+			printf("Invalid port number: %lu\n", val);
+			return 0;
+		}
+		parsed_cmd->port = val;
+		(*argc_nr)++;
+		parsed_cmd->cmd_to_keywords[*argc_nr] = id_port_no;
+		return 1;
+	}
+
+	return 0;
+}
+
+/* match optional keywords */
+static void cmd_keywords_opt_check(struct command_def *parsed_cmd,
+				   int *argc_val)
+{
+	int			i, keyw_opt_id, argc_val_max;
+
+	/* remember the best match */
+	argc_val_max = *argc_val;
+
+	for (i = 0; i < ARRAY_SIZE(cmd_opt_def); i++) {
+		keyw_opt_id = 0;
+		while (keyw_opt_id + *argc_val <
+				parsed_cmd->cmd_keywords_nr &&
+		       cmd_opt_def[i].cmd_keyword[keyw_opt_id] != id_key_end &&
+		       parsed_cmd->cmd_to_keywords[keyw_opt_id + *argc_val] ==
+		       cmd_opt_def[i].cmd_keyword[keyw_opt_id])
+			keyw_opt_id++;
+		if (keyw_opt_id && keyw_opt_id + *argc_val <=
+				   parsed_cmd->cmd_keywords_nr &&
+		    cmd_opt_def[i].cmd_keyword[keyw_opt_id] == id_key_end &&
+		    (*argc_val + keyw_opt_id > argc_val_max))
+				argc_val_max = *argc_val + keyw_opt_id;
 	}
 
-	return -1;
+	*argc_val = argc_val_max;
 }
 
-U_BOOT_CMD(ethsw, 5, 0, do_ethsw,
+/* get the function to call based on keywords */
+static void cmd_keywords_check(struct command_def *parsed_cmd, int *argc_val)
+{
+	int			i, keyword_id;
+
+	for (i = 0; i < ARRAY_SIZE(cmd_def); i++) {
+		keyword_id = 0;
+		while (keyword_id + *argc_val < parsed_cmd->cmd_keywords_nr &&
+		       cmd_def[i].cmd_keyword[keyword_id] != id_key_end &&
+		       parsed_cmd->cmd_to_keywords[keyword_id + *argc_val] ==
+				      cmd_def[i].cmd_keyword[keyword_id])
+			keyword_id++;
+		if (keyword_id && keyword_id + *argc_val ==
+				  parsed_cmd->cmd_keywords_nr &&
+		    cmd_def[i].cmd_keyword[keyword_id] == id_key_end) {
+			*argc_val += keyword_id;
+			parsed_cmd->cmd_function = cmd_def[i].keyword_function;
+			return;
+		}
+	}
+}
+
+/* find all the keywords in the command */
+static void keywords_find(int argc, char * const argv[],
+			  struct command_def *parsed_cmd)
+{
+	int			i, j, argc_val;
+
+	for (i = 1; i < argc; i++) {
+		for (j = 0; j < id_count; j++) {
+			if (keyword[j].match(j, argc, argv, &i,
+					     parsed_cmd))
+				break;
+		}
+	}
+
+	for (i = 1; i < argc; i++)
+		if (parsed_cmd->cmd_to_keywords[i] == -1)
+			parsed_cmd->err = 1;
+
+	parsed_cmd->cmd_keywords_nr = argc;
+	argc_val = 1;
+
+	/* get optional parameters first */
+	cmd_keywords_opt_check(parsed_cmd, &argc_val);
+
+	cmd_keywords_check(parsed_cmd, &argc_val);
+
+	/* error if not all commands' parameters were matched */
+	if (argc_val != parsed_cmd->cmd_keywords_nr ||
+	    !parsed_cmd->cmd_function)
+		parsed_cmd->err = 1;
+}
+
+static void command_def_init(struct command_def *parsed_cmd)
+{
+	int			i;
+
+	for (i = 0; i < VSC9953_MAX_CMD_PARAMS; i++)
+		parsed_cmd->cmd_to_keywords[i] = -1;
+
+	parsed_cmd->port = VSC9953_CMD_PORT_ALL;
+	parsed_cmd->err = 0;
+	parsed_cmd->cmd_function = NULL;
+}
+
+static void command_def_cleanup(struct command_def *parsed_cmd)
+{
+	/* Nothing to do for now */
+}
+
+/* function to interpret commands starting with "ethsw " */
+static int do_ethsw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	struct command_def		parsed_cmd;
+	int				rc = 0;
+
+	if (argc >= VSC9953_MAX_CMD_PARAMS) {
+		rc = -1;
+		goto __ret;
+	}
+
+	command_def_init(&parsed_cmd);
+
+	keywords_find(argc, argv, &parsed_cmd);
+
+	if (!parsed_cmd.cmd_function) {
+		rc = -1;
+		goto __ret_cmd_cleanup;
+	}
+
+	rc = parsed_cmd.cmd_function(&parsed_cmd);
+
+	if (parsed_cmd.err) {
+		rc = -1;
+		goto __ret_cmd_cleanup;
+	}
+
+__ret_cmd_cleanup:
+	command_def_cleanup(&parsed_cmd);
+__ret:
+	return rc;
+}
+
+U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
 	   "vsc9953 l2 switch commands",
-	   "port <port_no> enable|disable\n"
-	   "    - enable/disable an l2 switch port\n"
-	   "      port_no=0..9; use \"all\" for all ports\n"
-	   "ethsw port <port_no> show\n"
-	   "    - show an l2 switch port's configuration\n"
-	   "      port_no=0..9; use \"all\" for all ports\n"
+	   VSC9953_PORT_CONF_HELP"\n"
 );
+
 #endif /* CONFIG_VSC9953_CMD */
Signature · 1 line
1.9.3
#21 lore raw

PATCH v2 4/11 drivers/net/vsc9953: Refractor the parser for VSC9953 commands

Hi Codrin,

Quoted 31 lines · Codrin Ciubotariu

In order to support multiple commands to configure the VSC9953 L2 Switch, the parser needs to be changed to be more flexible and to support more complex commands. This patch adds a parser that searches for defined keywords in the command and calls the proper function when a match is found. Also, the parser allows for optional keywords, such as "port", to apply the command on a port or on all ports. The already defined commands are also changed a bit to:
ethsw [port <port_no>] { enable | disable | show }

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 381 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 310 insertions(+), 71 deletions(-)
drivers/net/vsc9953.c +1 -0
index 9dec683..4df751a 100644
@@ -10,6 +10,7 @@
 #include <asm/fsl_serdes.h>
 #include <fm_eth.h>
 #include <fsl_memac.h>
+#include <errno.h>
 #include <vsc9953.h>
 
 static struct vsc9953_info vsc9953_l2sw = {

drivers/net/vsc9953.c void vsc9953_init(bd_t *bis) · line 578

Quoted 3 lines
drivers/net/vsc9953.c +0 -0
@@ -575,6 +576,10 @@ void vsc9953_init(bd_t *bis)
 }
 
 #ifdef CONFIG_VSC9953_CMD

I'd like to see this moved to its own file in common... maybe "common/cmd_ethsw.c". I'd also like to see this #define change to something like "CONFIG_CMD_ETHSW".

These changes don't necessarily need to be part of this series, since it already got in as is, but if you feel motivated, I would recommend you add a patch before this one that moves it.

Quoted 63 lines
drivers/net/vsc9953.c +16 -25
+
+#define VSC9953_MAX_CMD_PARAMS 20
+#define VSC9953_CMD_PORT_ALL   -1
+
 /* Enable/disable status of a VSC9953 port */
 static void vsc9953_port_status_set(int port_no, u8 enabled)
 {
@@ -595,15 +600,6 @@ static void vsc9953_port_status_set(int port_no, u8 enabled)
                             CONFIG_VSC9953_PORT_ENA);
 }
 
-/* Set all VSC9953 ports' status */
-static void vsc9953_port_all_status_set(u8 enabled)
-{
-       int             i;
-
-       for (i = 0; i < VSC9953_MAX_PORTS; i++)
-               vsc9953_port_status_set(i, enabled);
-}
-
 /* Start autonegotiation for a VSC9953 PHY */
 static void vsc9953_phy_autoneg(int port_no)
 {
@@ -615,15 +611,6 @@ static void vsc9953_phy_autoneg(int port_no)
                printf("Failed to start PHY for port %d\n", port_no);
 }
 
-/* Start autonegotiation for all VSC9953 PHYs */
-static void vsc9953_phy_all_autoneg(void)
-{
-       int             i;
-
-       for (i = 0; i < VSC9953_MAX_PORTS; i++)
-               vsc9953_phy_autoneg(i);
-}
-
 /* Print a VSC9953 port's configuration */
 static void vsc9953_port_config_show(int port_no)
 {
@@ -685,75 +672,327 @@ static void vsc9953_port_config_show(int port_no)
        printf("%8s\n", duplex == DUPLEX_FULL ? "full" : "half");
 }
 
-/* Print VSC9953 ports' configuration */
-static void vsc9953_port_all_config_show(void)
-{
-       int             i;
+/* IDs used to track keywords in a command */
+enum keyword_id {
+       id_key_end = -1,
+       id_help,
+       id_show,
+       id_port,
+       id_enable,
+       id_disable,
+       id_count,       /* keep last */
+};
 
-       for (i = 0; i < VSC9953_MAX_PORTS; i++)
-               vsc9953_port_config_show(i);
-}
+enum keyword_opt_id {
+       id_port_no = id_count + 1,

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 695

Quoted 10 lines
drivers/net/vsc9953.c +7 -2
+       id_count_all,   /* keep last */
+};
 
-/* function to interpret commands starting with "ethsw " */
-static int do_ethsw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+struct command_def {
+       int cmd_to_keywords[VSC9953_MAX_CMD_PARAMS];
+       int cmd_keywords_nr;
+       int port;
+       int err;

Remove this. Just use a return value.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 700

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+       int (*cmd_function)(struct command_def *parsed_cmd);
+};
+
+#define VSC9953_PORT_CONF_HELP "[port <port_no>] { enable | disable | show } " \
+"- enable/disable a port; show shows a port's configuration"

Probably better to define this down by the use.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 705

Quoted 7 lines
drivers/net/vsc9953.c +4 -2
+
+static int vsc9953_port_status_key_func(struct command_def *parsed_cmd)
 {
-       u8 enable;
-       u32 port;
+       int                     i;
+       u8                      enabled;

Use a single space.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 715

Quoted 11 lines
drivers/net/vsc9953.c +9 -1
-       if (argc < 4)
+       /* Last keyword should tell us if we should enable/disable the port */
+       if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+           id_enable)
+               enabled = 1;
+       else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+                id_disable)
+               enabled = 0;
+       else {
+               parsed_cmd->err = 1;

Remove this.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 716

Quoted 1 line
drivers/net/vsc9953.c +0 -0
                return -1;

Please use "return CMD_RET_USAGE;" from include/command.h.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 726

Quoted 12 lines
drivers/net/vsc9953.c +9 -2
+       }
 
-       if (strcmp(argv[1], "port"))
-               return -1;
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               vsc9953_port_status_set(parsed_cmd->port, enabled);
+       } else {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++)
+                       vsc9953_port_status_set(i, enabled);
+       }
+
+       return 0;

Please use "return CMD_RET_SUCCESS;"

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 731

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+}
+
+static int vsc9953_port_config_key_func(struct command_def *parsed_cmd)
+{
+       int                     i;

Use a single space.

Quoted 34 lines
drivers/net/vsc9953.c +8 -24
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               vsc9953_phy_autoneg(parsed_cmd->port);
+               printf("%8s %8s %8s %8s %8s\n",
+                      "Port", "Status", "Link", "Speed",
+                      "Duplex");
+               vsc9953_port_config_show(parsed_cmd->port);
 
-       if (!strcmp(argv[3], "show")) {
-               if (!strcmp(argv[2], "all")) {
-                       vsc9953_phy_all_autoneg();
-                       printf("%8s %8s %8s %8s %8s\n",
-                              "Port", "Status", "Link", "Speed",
-                              "Duplex");
-                       vsc9953_port_all_config_show();
-                       return 0;
-               } else {
-                       port = simple_strtoul(argv[2], NULL, 10);
-                       if (!VSC9953_PORT_CHECK(port))
-                               return -1;
-                       vsc9953_phy_autoneg(port);
-                       printf("%8s %8s %8s %8s %8s\n",
-                              "Port", "Status", "Link", "Speed",
-                              "Duplex");
-                       vsc9953_port_config_show(port);
-                       return 0;
-               }
-       } else if (!strcmp(argv[3], "enable")) {
-               enable = 1;
-       } else if (!strcmp(argv[3], "disable")) {
-               enable = 0;
        } else {
-               return -1;
+               for (i = 0; i < VSC9953_MAX_PORTS; i++)

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 749

Quoted 10 lines
drivers/net/vsc9953.c +6 -2
+                       vsc9953_phy_autoneg(i);
+               printf("%8s %8s %8s %8s %8s\n",
+                      "Port", "Status", "Link", "Speed", "Duplex");
+               for (i = 0; i < VSC9953_MAX_PORTS; i++)
+                       vsc9953_port_config_show(i);
        }
 
-       if (!strcmp(argv[2], "all")) {
-               vsc9953_port_all_status_set(enable);
+       return 0;

Please use "return CMD_RET_SUCCESS;"

Quoted 81 lines
drivers/net/vsc9953.c +81 -0
+}
+
+struct keywords_to_function {
+       enum keyword_id cmd_keyword[VSC9953_MAX_CMD_PARAMS];
+       int (*keyword_function)(struct command_def *parsed_cmd);
+} cmd_def[] = {
+               {
+                       .cmd_keyword = {
+                                       id_enable,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_port_status_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_disable,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_port_status_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_show,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_port_config_key_func,
+               },
+};
+
+struct keywords_optional {
+       enum keyword_id cmd_keyword[VSC9953_MAX_CMD_PARAMS];
+} cmd_opt_def[] = {
+               {
+                               .cmd_keyword = {
+                                               id_port,
+                                               id_port_no,
+                                               id_key_end,
+                               },
+               },
+};
+
+static int keyword_match_gen(enum keyword_id key_id, int argc,
+                            char *const argv[], int *argc_nr,
+                            struct command_def *parsed_cmd);
+static int keyword_match_port(enum keyword_id key_id, int argc,
+                             char *const argv[], int *argc_nr,
+                             struct command_def *parsed_cmd);
+
+/* Define properties for each keyword;
+ * keep the order synced with enum keyword_id
+ */
+struct keyword_def {
+       const char *keyword_name;
+       int (*match)(enum keyword_id key_id, int argc, char *const argv[],
+                    int *argc_nr, struct command_def *parsed_cmd);
+} keyword[] = {
+               {
+                               .keyword_name = "help",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "show",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "port",
+                               .match = &keyword_match_port
+               },  {
+                               .keyword_name = "enable",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "disable",
+                               .match = &keyword_match_gen,
+               },
+};
+
+/* Generic function used to match a keyword only by a string */
+static int keyword_match_gen(enum keyword_id key_id, int argc,
+                            char *const argv[], int *argc_nr,
+                            struct command_def *parsed_cmd)
+{
+       if (strcmp(argv[*argc_nr], keyword[key_id].keyword_name) == 0) {
+               parsed_cmd->cmd_to_keywords[*argc_nr] = key_id;
+
+               return 1;

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 840

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       }
+       return 0;
+}
+
+/* Function used to match the command's port */
+static int keyword_match_port(enum keyword_id key_id, int argc,
+                             char *const argv[], int *argc_nr,
+                             struct command_def *parsed_cmd)
+{
+       unsigned long                   val;

Use a single space.

Quoted 21 lines
drivers/net/vsc9953.c +14 -5
+
+       if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
                return 0;
-       } else {
-               port = simple_strtoul(argv[2], NULL, 10);
-               if (!VSC9953_PORT_CHECK(port))
-                       return -1;
-               vsc9953_port_status_set(port, enable);
+
+       if (*argc_nr + 1 >= argc)
                return 0;
+
+       if (strict_strtoul(argv[*argc_nr + 1], 10, &val) != -EINVAL) {
+               if (!VSC9953_PORT_CHECK(val)) {
+                       printf("Invalid port number: %lu\n", val);
+                       return 0;
+               }
+               parsed_cmd->port = val;
+               (*argc_nr)++;
+               parsed_cmd->cmd_to_keywords[*argc_nr] = id_port_no;
+               return 1;

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 866

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       }
+
+       return 0;
+}
+
+/* match optional keywords */
+static void cmd_keywords_opt_check(struct command_def *parsed_cmd,
+                                  int *argc_val)
+{
+       int                     i, keyw_opt_id, argc_val_max;

Use a single space. Put each var on a separate line.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 878

Quoted 12 lines
drivers/net/vsc9953.c +12 -0
+
+       /* remember the best match */
+       argc_val_max = *argc_val;
+
+       for (i = 0; i < ARRAY_SIZE(cmd_opt_def); i++) {
+               keyw_opt_id = 0;
+               while (keyw_opt_id + *argc_val <
+                               parsed_cmd->cmd_keywords_nr &&
+                      cmd_opt_def[i].cmd_keyword[keyw_opt_id] != id_key_end &&
+                      parsed_cmd->cmd_to_keywords[keyw_opt_id + *argc_val] ==
+                      cmd_opt_def[i].cmd_keyword[keyw_opt_id])
+                       keyw_opt_id++;

It might help to break this up a bit and use some intermediate variables to make the code more readable.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 882

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+               if (keyw_opt_id && keyw_opt_id + *argc_val <=
+                                  parsed_cmd->cmd_keywords_nr &&
+                   cmd_opt_def[i].cmd_keyword[keyw_opt_id] == id_key_end &&
+                   (*argc_val + keyw_opt_id > argc_val_max))

This could benefit from a comment describing what you expect to be verified.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 892

Quoted 12 lines
drivers/net/vsc9953.c +6 -2
+                               argc_val_max = *argc_val + keyw_opt_id;
        }
 
-       return -1;
+       *argc_val = argc_val_max;
 }
 
-U_BOOT_CMD(ethsw, 5, 0, do_ethsw,
+/* get the function to call based on keywords */
+static void cmd_keywords_check(struct command_def *parsed_cmd, int *argc_val)
+{
+       int                     i, keyword_id;

Use a single space. Put each var on a separate line.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 900

Quoted 8 lines
drivers/net/vsc9953.c +8 -0
+
+       for (i = 0; i < ARRAY_SIZE(cmd_def); i++) {
+               keyword_id = 0;
+               while (keyword_id + *argc_val < parsed_cmd->cmd_keywords_nr &&
+                      cmd_def[i].cmd_keyword[keyword_id] != id_key_end &&
+                      parsed_cmd->cmd_to_keywords[keyword_id + *argc_val] ==
+                                     cmd_def[i].cmd_keyword[keyword_id])
+                       keyword_id++;

It might help to break this up a bit and use some intermediate variables to make the code more readable.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 903

Quoted 3 lines
drivers/net/vsc9953.c +3 -0
+               if (keyword_id && keyword_id + *argc_val ==
+                                 parsed_cmd->cmd_keywords_nr &&
+                   cmd_def[i].cmd_keyword[keyword_id] == id_key_end) {

This could benefit from a comment describing what you expect to be verified.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 912

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+                       *argc_val += keyword_id;
+                       parsed_cmd->cmd_function = cmd_def[i].keyword_function;
+                       return;
+               }
+       }
+}
+
+/* find all the keywords in the command */
+static void keywords_find(int argc, char * const argv[],

Make this function return an int.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 915

Quoted 3 lines
drivers/net/vsc9953.c +3 -0
+                         struct command_def *parsed_cmd)
+{
+       int                     i, j, argc_val;

Use a single space. Put each var on a separate line.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 927

Quoted 12 lines
drivers/net/vsc9953.c +12 -0
+
+       for (i = 1; i < argc; i++) {
+               for (j = 0; j < id_count; j++) {
+                       if (keyword[j].match(j, argc, argv, &i,
+                                            parsed_cmd))
+                               break;
+               }
+       }
+
+       for (i = 1; i < argc; i++)
+               if (parsed_cmd->cmd_to_keywords[i] == -1)
+                       parsed_cmd->err = 1;

Instead return CMD_RET_USAGE;

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 940

Quoted 13 lines
drivers/net/vsc9953.c +13 -0
+
+       parsed_cmd->cmd_keywords_nr = argc;
+       argc_val = 1;
+
+       /* get optional parameters first */
+       cmd_keywords_opt_check(parsed_cmd, &argc_val);
+
+       cmd_keywords_check(parsed_cmd, &argc_val);
+
+       /* error if not all commands' parameters were matched */
+       if (argc_val != parsed_cmd->cmd_keywords_nr ||
+           !parsed_cmd->cmd_function)
+               parsed_cmd->err = 1;

Instead return CMD_RET_USAGE;

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 951

Quoted 11 lines
drivers/net/vsc9953.c +11 -0
+}
+
+static void command_def_init(struct command_def *parsed_cmd)
+{
+       int                     i;
+
+       for (i = 0; i < VSC9953_MAX_CMD_PARAMS; i++)
+               parsed_cmd->cmd_to_keywords[i] = -1;
+
+       parsed_cmd->port = VSC9953_CMD_PORT_ALL;
+       parsed_cmd->err = 0;

Remove this.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 957

Quoted 6 lines
drivers/net/vsc9953.c +6 -0
+       parsed_cmd->cmd_function = NULL;
+}
+
+static void command_def_cleanup(struct command_def *parsed_cmd)
+{
+       /* Nothing to do for now */

Then why define it?

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 964

Quoted 7 lines
drivers/net/vsc9953.c +7 -0
+}
+
+/* function to interpret commands starting with "ethsw " */
+static int do_ethsw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct command_def              parsed_cmd;
+       int                             rc = 0;

Use a single space.

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 967

Quoted 3 lines
drivers/net/vsc9953.c +3 -0
+
+       if (argc >= VSC9953_MAX_CMD_PARAMS) {
+               rc = -1;

Use this:
+ rc = CMD_RET_USAGE;

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 973

Quoted 6 lines
drivers/net/vsc9953.c +6 -0
+               goto __ret;
+       }
+
+       command_def_init(&parsed_cmd);
+
+       keywords_find(argc, argv, &parsed_cmd);

Use this:
+ rc = keywords_find(argc, argv, &parsed_cmd);
+ if (rc)
+ goto __ret_cmd_cleanup;

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 978

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+
+       if (!parsed_cmd.cmd_function) {
+               rc = -1;
+               goto __ret_cmd_cleanup;
+       }

I think this whole if statement is unneeded since this same test already exists in keywords_find().

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 985

Quoted 7 lines
drivers/net/vsc9953.c +7 -0
+
+       rc = parsed_cmd.cmd_function(&parsed_cmd);
+
+       if (parsed_cmd.err) {
+               rc = -1;
+               goto __ret_cmd_cleanup;
+       }

Remove this if statement along with parsed_cmd.err.

Quoted 26 lines
drivers/net/vsc9953.c +10 -7
+
+__ret_cmd_cleanup:
+       command_def_cleanup(&parsed_cmd);
+__ret:
+       return rc;
+}
+
+U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
           "vsc9953 l2 switch commands",
-          "port <port_no> enable|disable\n"
-          "    - enable/disable an l2 switch port\n"
-          "      port_no=0..9; use \"all\" for all ports\n"
-          "ethsw port <port_no> show\n"
-          "    - show an l2 switch port's configuration\n"
-          "      port_no=0..9; use \"all\" for all ports\n"
+          VSC9953_PORT_CONF_HELP"\n"
 );
+
 #endif /* CONFIG_VSC9953_CMD */
--

1.9.3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#22 lore raw

PATCH v2 4/11 drivers/net/vsc9953: Refractor the parser for VSC9953 commands

Hi Joe,

Quoted 13 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:31 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 04/11 v2] drivers/net/vsc9953: Refractor the parser for VSC9953 commands

Quoted 4 lines

static struct vsc9953_info vsc9953_l2sw = { @@ -575,6 +576,10 @@ void
vsc9953_init(bd_t *bis) }

#ifdef CONFIG_VSC9953_CMD

Quoted 7 lines

I'd like to see this moved to its own file in common... maybe "common/cmd_ethsw.c". I'd also like to see this #define change to something like "CONFIG_CMD_ETHSW".

These changes don't necessarily need to be part of this series, since it already got in as is, but if you feel motivated, I would recommend you add a patch before this one that moves it.

I could move this parser in common/do_ethsw.c and rename the define. I guess this would imply that upcoming drivers for Ethernet L2 Switches could use the same commands while calling their specific functions.

Quoted 10 lines

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 695

Quoted 8 lines

-/* function to interpret commands starting with "ethsw " */ -static int do_ethsw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])

drivers/net/vsc9953.c +5 -0
+struct command_def {
+       int cmd_to_keywords[VSC9953_MAX_CMD_PARAMS];
+       int cmd_keywords_nr;
+       int port;
+       int err;

Remove this. Just use a return value.

Ok, I will remove "err" and all the other references to it.

Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+#define VSC9953_PORT_CONF_HELP "[port <port_no>] { enable | disable |
+show } " \
+"- enable/disable a port; show shows a port's configuration"

Probably better to define this down by the use.

Ok.

Quoted 3 lines
Quoted 1 line
                return -1;

Please use "return CMD_RET_USAGE;" from include/command.h.

Ok, I wasn't aware of these macros. I will make use them in this patch set when it's appropriate.

Quoted 6 lines

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 866

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+/* match optional keywords */
+static void cmd_keywords_opt_check(struct command_def *parsed_cmd,
+                                  int *argc_val) {
+       int                     i, keyw_opt_id, argc_val_max;

Use a single space. Put each var on a separate line.

Ok, I will make sure this applies throughout the whole patch set.

Quoted 11 lines

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no)

Quoted 10 lines
drivers/net/vsc9953.c +9 -0
+
+       /* remember the best match */
+       argc_val_max = *argc_val;
+
+       for (i = 0; i < ARRAY_SIZE(cmd_opt_def); i++) {
+               keyw_opt_id = 0;
+               while (keyw_opt_id + *argc_val <
+                               parsed_cmd->cmd_keywords_nr &&
+                      cmd_opt_def[i].cmd_keyword[keyw_opt_id] != id_key_end

&&

Quoted 6 lines

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 878

Quoted 3 lines
drivers/net/vsc9953.c +3 -0
+                      parsed_cmd->cmd_to_keywords[keyw_opt_id + *argc_val] ==
+                      cmd_opt_def[i].cmd_keyword[keyw_opt_id])
+                       keyw_opt_id++;

It might help to break this up a bit and use some intermediate variables to make the code more readable.

Ok.

Quoted 7 lines

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 882

Quoted 5 lines
drivers/net/vsc9953.c +4 -0
+               if (keyw_opt_id && keyw_opt_id + *argc_val <=
+                                  parsed_cmd->cmd_keywords_nr &&
+                   cmd_opt_def[i].cmd_keyword[keyw_opt_id] == id_key_end &&
+                   (*argc_val + keyw_opt_id > argc_val_max))

This could benefit from a comment describing what you expect to be verified.

Ok.

Quoted 11 lines

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 900

Quoted 8 lines
drivers/net/vsc9953.c +8 -0
+
+       for (i = 0; i < ARRAY_SIZE(cmd_def); i++) {
+               keyword_id = 0;
+               while (keyword_id + *argc_val < parsed_cmd->cmd_keywords_nr &&
+                      cmd_def[i].cmd_keyword[keyword_id] != id_key_end &&
+                      parsed_cmd->cmd_to_keywords[keyword_id + *argc_val] ==
+                                     cmd_def[i].cmd_keyword[keyword_id])
+                       keyword_id++;

It might help to break this up a bit and use some intermediate variables to make the code more readable.

Ok.

Quoted 7 lines

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 914

Quoted 5 lines
drivers/net/vsc9953.c +4 -0
+               if (keyword_id && keyword_id + *argc_val ==
+                                 parsed_cmd->cmd_keywords_nr &&
+                   cmd_def[i].cmd_keyword[keyword_id] == id_key_end)
+ {

This could benefit from a comment describing what you expect to be verified.

Ok.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+/* find all the keywords in the command */ static void
+keywords_find(int argc, char * const argv[],

Make this function return an int.

Ok. I will also make the changes along this patch to check it?s return code.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+static void command_def_cleanup(struct command_def *parsed_cmd) {
+       /* Nothing to do for now */

Then why define it?

This function is populated later by another patch and it frees a dynamically allocated buffer. You suggested to use a static buffer instead, so I guess I will remove this functions since it's no longer needed.

Quoted 7 lines

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 978

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+       if (!parsed_cmd.cmd_function) {
+               rc = -1;
+               goto __ret_cmd_cleanup;
+       }

I think this whole if statement is unneeded since this same test already exists in keywords_find().

Ok.

Thanks and best regards,
Codrin

#23 lore raw

PATCH v2 4/11 drivers/net/vsc9953: Refractor the parser for VSC9953 commands

Hi Codrin,

Quoted 19 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 17 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:31 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 04/11 v2] drivers/net/vsc9953: Refractor the parser for VSC9953 commands

Quoted 4 lines

static struct vsc9953_info vsc9953_l2sw = { @@ -575,6 +576,10 @@ void
vsc9953_init(bd_t *bis) }

#ifdef CONFIG_VSC9953_CMD

I'd like to see this moved to its own file in common... maybe "common/cmd_ethsw.c". I'd also like to see this #define change to something like "CONFIG_CMD_ETHSW".

Quoted 5 lines
Quoted 3 lines

These changes don't necessarily need to be part of this series, since it already got in as is, but if you feel motivated, I would recommend you add a patch before this one that moves it.

I could move this parser in common/do_ethsw.c and rename the define. I guess this would imply that upcoming drivers for Ethernet L2 Switches could use the same commands while calling their specific functions.

That's the idea. It would be great to keep it semi-generic.

Thanks,
-Joe

#24 lore raw

PATCH v2 4/11 drivers/net/vsc9953: Refractor the parser for VSC9953 commands

Hi Joe,

Quoted 35 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Wednesday, July 01, 2015 1:31 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 04/11 v2] drivers/net/vsc9953: Refractor the parser for VSC9953 commands

Hi Codrin,

Quoted 23 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 20 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:31 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 04/11 v2] drivers/net/vsc9953: Refractor the parser for VSC9953 commands

Quoted 4 lines

static struct vsc9953_info vsc9953_l2sw = { @@ -575,6 +576,10 @@
void vsc9953_init(bd_t *bis) }

#ifdef CONFIG_VSC9953_CMD

I'd like to see this moved to its own file in common... maybe "common/cmd_ethsw.c". I'd also like to see this #define change to something like "CONFIG_CMD_ETHSW".

These changes don't necessarily need to be part of this series, since it already got in as is, but if you feel motivated, I would recommend you add a patch before this one that moves it.

Quoted 5 lines
Quoted 1 line

I could move this parser in common/do_ethsw.c and rename the define. I guess

this would imply that upcoming drivers for Ethernet L2 Switches could use the same commands while calling their specific functions.

That's the idea. It would be great to keep it semi-generic.

I also need to create a do_ethsw.h that should contain at least struct keywords_to_function. I need this so that any driver could set its implementation in .keyword_function. Where should I put this header?

Best regards,
Codrin

#25 lore raw

PATCH v2 4/11 drivers/net/vsc9953: Refractor the parser for VSC9953 commands

Hi Codrin,

Quoted 37 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 35 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Wednesday, July 01, 2015 1:31 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 04/11 v2] drivers/net/vsc9953: Refractor the parser for VSC9953 commands

Hi Codrin,

Quoted 23 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 20 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:31 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 04/11 v2] drivers/net/vsc9953: Refractor the parser for VSC9953 commands

Quoted 4 lines

static struct vsc9953_info vsc9953_l2sw = { @@ -575,6 +576,10 @@
void vsc9953_init(bd_t *bis) }

#ifdef CONFIG_VSC9953_CMD

I'd like to see this moved to its own file in common... maybe "common/cmd_ethsw.c". I'd also like to see this #define change to something like "CONFIG_CMD_ETHSW".

These changes don't necessarily need to be part of this series, since it already got in as is, but if you feel motivated, I would recommend you add a patch before this one that moves it.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I could move this parser in common/do_ethsw.c and rename the define. I guess

this would imply that upcoming drivers for Ethernet L2 Switches could use the same commands while calling their specific functions.

That's the idea. It would be great to keep it semi-generic.

I also need to create a do_ethsw.h that should contain at least struct keywords_to_function. I need this so that any driver could set its implementation in .keyword_function. Where should I put this header?

I think you should add a file simply called "include/ethsw.h"

Cheers,
-Joe

#26 lore raw

PATCH v2 5/11 drivers/net/vsc9953: Add command to show/clear port counters

In reply to Codrin Ciubotariu

The new added command:
ethsw [port <port_no>] statistics { [help] | [clear] }

will print counters like the number of Rx/Tx frames, number of Rx/Tx bytes, number of Rx/Tx unicast frames, etc.

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 280 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/vsc9953.h     | 116 ++++++++++++++++++++-
 2 files changed, 393 insertions(+), 3 deletions(-)
drivers/net/vsc9953.c +280 -0
index 4df751a..62ab0eb 100644
@@ -672,6 +672,219 @@ static void vsc9953_port_config_show(int port_no)
 	printf("%8s\n", duplex == DUPLEX_FULL ? "full" : "half");
 }
 
+/* Show VSC9953 ports' statistics */
+static void vsc9953_port_statistics_show(int port_no)
+{
+	u32				rx_val, tx_val;
+	struct vsc9953_system_reg	*l2sys_reg;
+
+	/* Administrative down */
+	if (!vsc9953_l2sw.port[port_no].enabled) {
+		printf("Port %d is administrative down\n", port_no);
+		return;
+	}
+
+	l2sys_reg = (struct vsc9953_system_reg *)(VSC9953_OFFSET +
+			VSC9953_SYS_OFFSET);
+
+	printf("Statistics for L2 Switch port %d:\n", port_no);
+
+	/* Set counter view for our port */
+	out_le32(&l2sys_reg->sys.stat_cfg, port_no);
+
+#define VSC9953_STATS_PRINTF "%-15s %10u"
+
+	/* Get number of Rx and Tx frames */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_short) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_frag) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_jabber) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_long) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_64) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_65_127) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_128_255) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_256_511) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_512_1023) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_1024_1526) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_jumbo);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_64) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_65_127) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_128_255) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_256_511) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_512_1023) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_1024_1526) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_jumbo);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx frames:", rx_val, "Tx frames:", tx_val);
+
+	/* Get number of Rx and Tx bytes */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_oct);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_oct);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx bytes:", rx_val, "Tx bytes:", tx_val);
+
+	/* Get number of Rx frames received ok and Tx frames sent ok */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_0) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_1) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_2) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_3) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_4) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_5) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_6) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_7) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_0) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_1) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_2) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_3) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_4) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_5) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_6) +
+		 in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_7);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_64) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_65_127) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_128_255) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_256_511) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_512_1023) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_1024_1526) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_jumbo);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx frames ok:", rx_val, "Tx frames ok:", tx_val);
+
+	/* Get number of Rx and Tx unicast frames */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_uc);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_uc);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx unicast:", rx_val, "Tx unicast:", tx_val);
+
+	/* Get number of Rx and Tx broadcast frames */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_bc);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_bc);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx broadcast:", rx_val, "Tx broadcast:", tx_val);
+
+	/* Get number of Rx and Tx frames of 64B */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_64);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_64);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx 64B:", rx_val, "Tx 64B:", tx_val);
+
+	/* Get number of Rx and Tx frames with sizes between 65B and 127B */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_65_127);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_65_127);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx 65B-127B:", rx_val, "Tx 65B-127B:", tx_val);
+
+	/* Get number of Rx and Tx frames with sizes between 128B and 255B */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_128_255);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_128_255);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx 128B-255B:", rx_val, "Tx 128B-255B:", tx_val);
+
+	/* Get number of Rx and Tx frames with sizes between 256B and 511B */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_256_511);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_256_511);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx 256B-511B:", rx_val, "Tx 256B-511B:", tx_val);
+
+	/* Get number of Rx and Tx frames with sizes between 512B and 1023B */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_512_1023);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_512_1023);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx 512B-1023B:", rx_val, "Tx 512B-1023B:", tx_val);
+
+	/* Get number of Rx and Tx frames with sizes between 1024B and 1526B */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_1024_1526);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_1024_1526);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx 1024B-1526B:", rx_val, "Tx 1024B-1526B:", tx_val);
+
+	/* Get number of Rx and Tx jumbo frames */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_jumbo);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_jumbo);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx jumbo:", rx_val, "Tx jumbo:", tx_val);
+
+	/* Get number of Rx and Tx dropped frames */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_cat_drop) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_tail) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_0) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_1) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_2) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_3) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_4) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_5) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_6) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_7) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_0) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_1) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_2) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_3) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_4) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_5) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_6) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_7);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_drop) +
+		 in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_aged);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx drops:", rx_val, "Tx drops:", tx_val);
+
+	/* Get number of Rx frames with CRC or alignment errors
+	 * and number of detected Tx collisions
+	 */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_crc);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_col);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx CRC&align:", rx_val, "Tx coll:", tx_val);
+
+	/* Get number of Rx undersized frames and
+	 * number of Tx aged frames
+	 */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_short);
+	tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_aged);
+	printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+	       "Rx undersize:", rx_val, "Tx aged:", tx_val);
+
+	/* Get number of Rx oversized frames */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_long);
+	printf(VSC9953_STATS_PRINTF"\n", "Rx oversized:", rx_val);
+
+	/* Get number of Rx fragmented frames */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_frag);
+	printf(VSC9953_STATS_PRINTF"\n", "Rx fragments:", rx_val);
+
+	/* Get number of Rx jabber errors */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_jabber);
+	printf(VSC9953_STATS_PRINTF"\n", "Rx jabbers:", rx_val);
+
+	/* Get number of Rx frames filtered due to classification rules or
+	 * no destination ports
+	 */
+	rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_cat_drop) +
+		 in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_local);
+	printf(VSC9953_STATS_PRINTF"\n", "Rx filtered:", rx_val);
+
+	printf("\n");
+}
+
+/* Clear statistics for a VSC9953 port */
+static void vsc9953_port_statistics_clear(int port_no)
+{
+	struct vsc9953_system_reg	*l2sys_reg;
+
+	/* Administrative down */
+	if (!vsc9953_l2sw.port[port_no].enabled) {
+		printf("Port %d is administrative down\n", port_no);
+		return;
+	}
+
+	l2sys_reg = (struct vsc9953_system_reg *)(VSC9953_OFFSET +
+				VSC9953_SYS_OFFSET);
+
+	/* Clear all counter groups for our ports */
+	out_le32(&l2sys_reg->sys.stat_cfg, port_no |
+		 CONFIG_VSC9953_STAT_CLEAR_RX | CONFIG_VSC9953_STAT_CLEAR_TX |
+		 CONFIG_VSC9953_STAT_CLEAR_DR);
+}
+
 /* IDs used to track keywords in a command */
 enum keyword_id {
 	id_key_end = -1,
@@ -680,6 +893,8 @@ enum keyword_id {
 	id_port,
 	id_enable,
 	id_disable,
+	id_statistics,
+	id_clear,
 	id_count,	/* keep last */
 };
 
@@ -749,6 +964,44 @@ static int vsc9953_port_config_key_func(struct command_def *parsed_cmd)
 	return 0;
 }
 
+#define VSC9953_PORT_STATS_HELP "ethsw [port <port_no>] statistics " \
+"{ [help] | [clear] } - show an l2 switch port's statistics"
+
+static int vsc9953_port_stats_help_key_func(struct command_def *parsed_cmd)
+{
+	printf(VSC9953_PORT_STATS_HELP"\n");
+
+	return 0;
+}
+
+static int vsc9953_port_stats_key_func(struct command_def *parsed_cmd)
+{
+	int i;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_port_statistics_show(parsed_cmd->port);
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_port_statistics_show(i);
+	}
+
+	return 0;
+}
+
+static int vsc9953_port_stats_clear_key_func(struct command_def *parsed_cmd)
+{
+	int i;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_port_statistics_clear(parsed_cmd->port);
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_port_statistics_clear(i);
+	}
+
+	return 0;
+}
+
 struct keywords_to_function {
 	enum keyword_id cmd_keyword[VSC9953_MAX_CMD_PARAMS];
 	int (*keyword_function)(struct command_def *parsed_cmd);
@@ -771,6 +1024,26 @@ struct keywords_to_function {
 					id_key_end,
 			},
 			.keyword_function = &vsc9953_port_config_key_func,
+		}, {
+			.cmd_keyword = {
+					id_statistics,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_port_stats_key_func,
+		}, {
+			.cmd_keyword = {
+					id_statistics,
+					id_help,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_port_stats_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_statistics,
+					id_clear,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_port_stats_clear_key_func,
 		},
 };
 
@@ -816,6 +1089,12 @@ struct keyword_def {
 		}, {
 				.keyword_name = "disable",
 				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "statistics",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "clear",
+				.match = &keyword_match_gen,
 		},
 };
 
@@ -993,6 +1272,7 @@ __ret:
 U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
 	   "vsc9953 l2 switch commands",
 	   VSC9953_PORT_CONF_HELP"\n"
+	   VSC9953_PORT_STATS_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
include/vsc9953.h +113 -3

129 lines not on this page · raw message

Signature · 1 line
1.9.3
#27 lore raw

PATCH v2 5/11 drivers/net/vsc9953: Add command to show/clear port counters

Hi Codrin,

Quoted 20 lines · Codrin Ciubotariu

The new added command:
ethsw [port <port_no>] statistics { [help] | [clear] }

will print counters like the number of Rx/Tx frames, number of Rx/Tx bytes, number of Rx/Tx unicast frames, etc.

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 280 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/vsc9953.h     | 116 ++++++++++++++++++++-
 2 files changed, 393 insertions(+), 3 deletions(-)
drivers/net/vsc9953.c +0 -0
index 4df751a..62ab0eb 100644

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 679

Quoted 8 lines
drivers/net/vsc9953.c +5 -0
@@ -672,6 +672,219 @@ static void vsc9953_port_config_show(int port_no)
        printf("%8s\n", duplex == DUPLEX_FULL ? "full" : "half");
 }
 
+/* Show VSC9953 ports' statistics */
+static void vsc9953_port_statistics_show(int port_no)
+{
+       u32                             rx_val, tx_val;
+       struct vsc9953_system_reg       *l2sys_reg;

Use a single space. Place each variable on its own line.

Quoted 182 lines
drivers/net/vsc9953.c +182 -0
+
+       /* Administrative down */
+       if (!vsc9953_l2sw.port[port_no].enabled) {
+               printf("Port %d is administrative down\n", port_no);
+               return;
+       }
+
+       l2sys_reg = (struct vsc9953_system_reg *)(VSC9953_OFFSET +
+                       VSC9953_SYS_OFFSET);
+
+       printf("Statistics for L2 Switch port %d:\n", port_no);
+
+       /* Set counter view for our port */
+       out_le32(&l2sys_reg->sys.stat_cfg, port_no);
+
+#define VSC9953_STATS_PRINTF "%-15s %10u"
+
+       /* Get number of Rx and Tx frames */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_short) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_frag) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_jabber) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_long) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_64) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_65_127) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_128_255) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_256_511) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_512_1023) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_1024_1526) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_jumbo);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_64) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_65_127) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_128_255) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_256_511) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_512_1023) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_1024_1526) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_jumbo);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx frames:", rx_val, "Tx frames:", tx_val);
+
+       /* Get number of Rx and Tx bytes */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_oct);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_oct);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx bytes:", rx_val, "Tx bytes:", tx_val);
+
+       /* Get number of Rx frames received ok and Tx frames sent ok */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_0) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_1) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_2) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_3) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_4) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_5) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_6) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_yellow_prio_7) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_0) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_1) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_2) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_3) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_4) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_5) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_6) +
+                in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_green_prio_7);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_64) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_65_127) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_128_255) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_256_511) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_512_1023) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_1024_1526) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_jumbo);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx frames ok:", rx_val, "Tx frames ok:", tx_val);
+
+       /* Get number of Rx and Tx unicast frames */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_uc);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_uc);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx unicast:", rx_val, "Tx unicast:", tx_val);
+
+       /* Get number of Rx and Tx broadcast frames */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_bc);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_bc);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx broadcast:", rx_val, "Tx broadcast:", tx_val);
+
+       /* Get number of Rx and Tx frames of 64B */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_64);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_64);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx 64B:", rx_val, "Tx 64B:", tx_val);
+
+       /* Get number of Rx and Tx frames with sizes between 65B and 127B */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_65_127);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_65_127);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx 65B-127B:", rx_val, "Tx 65B-127B:", tx_val);
+
+       /* Get number of Rx and Tx frames with sizes between 128B and 255B */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_128_255);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_128_255);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx 128B-255B:", rx_val, "Tx 128B-255B:", tx_val);
+
+       /* Get number of Rx and Tx frames with sizes between 256B and 511B */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_256_511);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_256_511);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx 256B-511B:", rx_val, "Tx 256B-511B:", tx_val);
+
+       /* Get number of Rx and Tx frames with sizes between 512B and 1023B */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_512_1023);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_512_1023);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx 512B-1023B:", rx_val, "Tx 512B-1023B:", tx_val);
+
+       /* Get number of Rx and Tx frames with sizes between 1024B and 1526B */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_1024_1526);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_1024_1526);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx 1024B-1526B:", rx_val, "Tx 1024B-1526B:", tx_val);
+
+       /* Get number of Rx and Tx jumbo frames */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_sz_jumbo);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_sz_jumbo);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx jumbo:", rx_val, "Tx jumbo:", tx_val);
+
+       /* Get number of Rx and Tx dropped frames */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_cat_drop) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_tail) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_0) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_1) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_2) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_3) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_4) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_5) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_6) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_yellow_prio_7) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_0) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_1) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_2) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_3) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_4) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_5) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_6) +
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_green_prio_7);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_drop) +
+                in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_aged);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx drops:", rx_val, "Tx drops:", tx_val);
+
+       /* Get number of Rx frames with CRC or alignment errors
+        * and number of detected Tx collisions
+        */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_crc);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_col);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx CRC&align:", rx_val, "Tx coll:", tx_val);
+
+       /* Get number of Rx undersized frames and
+        * number of Tx aged frames
+        */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_short);
+       tx_val = in_le32(&l2sys_reg->stat.tx_cntrs.c_tx_aged);
+       printf(VSC9953_STATS_PRINTF"\t\t"VSC9953_STATS_PRINTF"\n",
+              "Rx undersize:", rx_val, "Tx aged:", tx_val);
+
+       /* Get number of Rx oversized frames */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_long);
+       printf(VSC9953_STATS_PRINTF"\n", "Rx oversized:", rx_val);
+
+       /* Get number of Rx fragmented frames */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_frag);
+       printf(VSC9953_STATS_PRINTF"\n", "Rx fragments:", rx_val);
+
+       /* Get number of Rx jabber errors */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_jabber);
+       printf(VSC9953_STATS_PRINTF"\n", "Rx jabbers:", rx_val);
+
+       /* Get number of Rx frames filtered due to classification rules or
+        * no destination ports
+        */
+       rx_val = in_le32(&l2sys_reg->stat.rx_cntrs.c_rx_cat_drop) +

drivers/net/vsc9953.c static void vsc9953_port_config_show(int port_no) · line 871

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                in_le32(&l2sys_reg->stat.drop_cntrs.c_dr_local);
+       printf(VSC9953_STATS_PRINTF"\n", "Rx filtered:", rx_val);
+
+       printf("\n");
+}
+
+/* Clear statistics for a VSC9953 port */
+static void vsc9953_port_statistics_clear(int port_no)
+{
+       struct vsc9953_system_reg       *l2sys_reg;

Use a single space.

Quoted 30 lines
drivers/net/vsc9953.c +18 -0
+
+       /* Administrative down */
+       if (!vsc9953_l2sw.port[port_no].enabled) {
+               printf("Port %d is administrative down\n", port_no);
+               return;
+       }
+
+       l2sys_reg = (struct vsc9953_system_reg *)(VSC9953_OFFSET +
+                               VSC9953_SYS_OFFSET);
+
+       /* Clear all counter groups for our ports */
+       out_le32(&l2sys_reg->sys.stat_cfg, port_no |
+                CONFIG_VSC9953_STAT_CLEAR_RX | CONFIG_VSC9953_STAT_CLEAR_TX |
+                CONFIG_VSC9953_STAT_CLEAR_DR);
+}
+
 /* IDs used to track keywords in a command */
 enum keyword_id {
        id_key_end = -1,
@@ -680,6 +893,8 @@ enum keyword_id {
        id_port,
        id_enable,
        id_disable,
+       id_statistics,
+       id_clear,
        id_count,       /* keep last */
 };
 
@@ -749,6 +964,44 @@ static int vsc9953_port_config_key_func(struct command_def *parsed_cmd)
        return 0;

drivers/net/vsc9953.c static int vsc9953_port_config_key_func(struct command_def *parsed_cmd) · line 974

Quoted 10 lines
drivers/net/vsc9953.c +8 -0
 }
 
+#define VSC9953_PORT_STATS_HELP "ethsw [port <port_no>] statistics " \
+"{ [help] | [clear] } - show an l2 switch port's statistics"
+
+static int vsc9953_port_stats_help_key_func(struct command_def *parsed_cmd)
+{
+       printf(VSC9953_PORT_STATS_HELP"\n");
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+}
+
+static int vsc9953_port_stats_key_func(struct command_def *parsed_cmd)
+{

drivers/net/vsc9953.c static int vsc9953_port_config_key_func(struct command_def *parsed_cmd) · line 988

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       int i;
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               vsc9953_port_statistics_show(parsed_cmd->port);
+       } else {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++)
+                       vsc9953_port_statistics_show(i);
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+}
+
+static int vsc9953_port_stats_clear_key_func(struct command_def *parsed_cmd)
+{

drivers/net/vsc9953.c static int vsc9953_port_config_key_func(struct command_def *parsed_cmd) · line 1002

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       int i;
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               vsc9953_port_statistics_clear(parsed_cmd->port);
+       } else {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++)
+                       vsc9953_port_statistics_clear(i);
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 12 lines
drivers/net/vsc9953.c +5 -0
+}
+
 struct keywords_to_function {
        enum keyword_id cmd_keyword[VSC9953_MAX_CMD_PARAMS];
        int (*keyword_function)(struct command_def *parsed_cmd);
@@ -771,6 +1024,26 @@ struct keywords_to_function {
                                        id_key_end,
                        },
                        .keyword_function = &vsc9953_port_config_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_statistics,

drivers/net/vsc9953.c struct keywords_to_function { · line 1039

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_port_stats_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_statistics,
+                                       id_help,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_port_stats_help_key_func,

If you're going to add this, shouldn't you also add one that prints "VSC9953_PORT_CONF_HELP" individually?

Quoted 173 lines
drivers/net/vsc9953.c +14 -0
+               }, {
+                       .cmd_keyword = {
+                                       id_statistics,
+                                       id_clear,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_port_stats_clear_key_func,
                },
 };
 
@@ -816,6 +1089,12 @@ struct keyword_def {
                }, {
                                .keyword_name = "disable",
                                .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "statistics",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "clear",
+                               .match = &keyword_match_gen,
                },
 };
 
@@ -993,6 +1272,7 @@ __ret:
 U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
           "vsc9953 l2 switch commands",
           VSC9953_PORT_CONF_HELP"\n"
+          VSC9953_PORT_STATS_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
include/vsc9953.h +113 -4
index bf81623..482acac 100644
@@ -84,6 +84,11 @@
 /* Macros for vsc9953_sys_pause_cfgtot_tail_drop_lvl register */
 #define CONFIG_VSC9953_TOT_TAIL_DROP_LVL       0x000003ff
 
+/* Macros for vsc9953_sys_sys.stat_cfg register */
+#define CONFIG_VSC9953_STAT_CLEAR_RX   0x00000400
+#define CONFIG_VSC9953_STAT_CLEAR_TX   0x00000800
+#define CONFIG_VSC9953_STAT_CLEAR_DR   0x00001000
+
 /* Macros for vsc9953_vcap_core_cfg.vcap_mv_cfg register */
 #define        CONFIG_VSC9953_VCAP_MV_CFG      0x0000ffff
 #define        CONFIG_VSC9953_VCAP_UPDATE_CTRL 0x01000004
@@ -339,10 +344,115 @@ struct   vsc9953_qsys_reg {
 
 /* VSC9953 SYS structure for T1040 U-boot*/
 
+struct vsc9953_rx_cntrs {
+       u32     c_rx_oct;
+       u32     c_rx_uc;
+       u32     c_rx_mc;
+       u32     c_rx_bc;
+       u32     c_rx_short;
+       u32     c_rx_frag;
+       u32     c_rx_jabber;
+       u32     c_rx_crc;
+       u32     c_rx_symbol_err;
+       u32     c_rx_sz_64;
+       u32     c_rx_sz_65_127;
+       u32     c_rx_sz_128_255;
+       u32     c_rx_sz_256_511;
+       u32     c_rx_sz_512_1023;
+       u32     c_rx_sz_1024_1526;
+       u32     c_rx_sz_jumbo;
+       u32     c_rx_pause;
+       u32     c_rx_control;
+       u32     c_rx_long;
+       u32     c_rx_cat_drop;
+       u32     c_rx_red_prio_0;
+       u32     c_rx_red_prio_1;
+       u32     c_rx_red_prio_2;
+       u32     c_rx_red_prio_3;
+       u32     c_rx_red_prio_4;
+       u32     c_rx_red_prio_5;
+       u32     c_rx_red_prio_6;
+       u32     c_rx_red_prio_7;
+       u32     c_rx_yellow_prio_0;
+       u32     c_rx_yellow_prio_1;
+       u32     c_rx_yellow_prio_2;
+       u32     c_rx_yellow_prio_3;
+       u32     c_rx_yellow_prio_4;
+       u32     c_rx_yellow_prio_5;
+       u32     c_rx_yellow_prio_6;
+       u32     c_rx_yellow_prio_7;
+       u32     c_rx_green_prio_0;
+       u32     c_rx_green_prio_1;
+       u32     c_rx_green_prio_2;
+       u32     c_rx_green_prio_3;
+       u32     c_rx_green_prio_4;
+       u32     c_rx_green_prio_5;
+       u32     c_rx_green_prio_6;
+       u32     c_rx_green_prio_7;
+       u32     reserved[20];
+};
+
+struct vsc9953_tx_cntrs {
+       u32     c_tx_oct;
+       u32     c_tx_uc;
+       u32     c_tx_mc;
+       u32     c_tx_bc;
+       u32     c_tx_col;
+       u32     c_tx_drop;
+       u32     c_tx_pause;
+       u32     c_tx_sz_64;
+       u32     c_tx_sz_65_127;
+       u32     c_tx_sz_128_255;
+       u32     c_tx_sz_256_511;
+       u32     c_tx_sz_512_1023;
+       u32     c_tx_sz_1024_1526;
+       u32     c_tx_sz_jumbo;
+       u32     c_tx_yellow_prio_0;
+       u32     c_tx_yellow_prio_1;
+       u32     c_tx_yellow_prio_2;
+       u32     c_tx_yellow_prio_3;
+       u32     c_tx_yellow_prio_4;
+       u32     c_tx_yellow_prio_5;
+       u32     c_tx_yellow_prio_6;
+       u32     c_tx_yellow_prio_7;
+       u32     c_tx_green_prio_0;
+       u32     c_tx_green_prio_1;
+       u32     c_tx_green_prio_2;
+       u32     c_tx_green_prio_3;
+       u32     c_tx_green_prio_4;
+       u32     c_tx_green_prio_5;
+       u32     c_tx_green_prio_6;
+       u32     c_tx_green_prio_7;
+       u32     c_tx_aged;
+       u32     reserved[33];
+};
+
+struct vsc9953_drop_cntrs {
+       u32     c_dr_local;
+       u32     c_dr_tail;
+       u32     c_dr_yellow_prio_0;
+       u32     c_dr_yellow_prio_1;
+       u32     c_dr_yellow_prio_2;
+       u32     c_dr_yellow_prio_3;
+       u32     c_dr_yellow_prio_4;
+       u32     c_dr_yellow_prio_5;
+       u32     c_dr_yellow_prio_6;
+       u32     c_dr_yellow_prio_7;
+       u32     c_dr_green_prio_0;
+       u32     c_dr_green_prio_1;
+       u32     c_dr_green_prio_2;
+       u32     c_dr_green_prio_3;
+       u32     c_dr_green_prio_4;
+       u32     c_dr_green_prio_5;
+       u32     c_dr_green_prio_6;
+       u32     c_dr_green_prio_7;
+       u32     reserved[46];
+};
+
 struct vsc9953_sys_stat {
-       u32     rx_cntrs[64];
-       u32     tx_cntrs[64];
-       u32     drop_cntrs[64];
+       struct vsc9953_rx_cntrs         rx_cntrs;
+       struct vsc9953_tx_cntrs         tx_cntrs;
+       struct vsc9953_drop_cntrs       drop_cntrs;
        u32     reserved1[6];
 };
 
--

1.9.3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#28 lore raw

PATCH v2 5/11 drivers/net/vsc9953: Add command to show/clear port counters

Hi Joe,

I will make the changes you requested.

Thanks and best regards,
Codrin

Quoted 7 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:34 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 05/11 v2] drivers/net/vsc9953: Add command to show/clear port counters

#29 lore raw

PATCH v2 6/11 drivers/net/vsc9953: Add commands to enable/disable HW learning

In reply to Codrin Ciubotariu

The command:
ethsw [port <port_no>] learning { [help] | show | auto | disable }

can be used to enable/disable HW learning on a port.

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/vsc9953.h     |   6 ++
 2 files changed, 194 insertions(+)
drivers/net/vsc9953.c +188 -0
index 62ab0eb..1936c4a 100644
@@ -672,6 +672,73 @@ static void vsc9953_port_config_show(int port_no)
 	printf("%8s\n", duplex == DUPLEX_FULL ? "full" : "half");
 }
 
+enum port_learn_mode {
+	PORT_LEARN_NONE,
+	PORT_LEARN_AUTO
+};
+
+/* Set learning configuration for a VSC9953 port */
+static void vsc9953_port_learn_mode_set(int port_no, enum port_learn_mode mode)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	/* Administrative down */
+	if (!vsc9953_l2sw.port[port_no].enabled) {
+		printf("Port %d is administrative down\n", port_no);
+		return;
+	}
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	switch (mode) {
+	case PORT_LEARN_NONE:
+		clrbits_le32(&l2ana_reg->port[port_no].port_cfg,
+			     CONFIG_VSC9953_PORT_CFG_LEARN_DROP |
+			     CONFIG_VSC9953_PORT_CFG_LEARN_CPU |
+			     CONFIG_VSC9953_PORT_CFG_LEARN_AUTO |
+			     CONFIG_VSC9953_PORT_CFG_LEARN_ENA);
+		break;
+	case PORT_LEARN_AUTO:
+		clrsetbits_le32(&l2ana_reg->port[port_no].port_cfg,
+				CONFIG_VSC9953_PORT_CFG_LEARN_DROP |
+				CONFIG_VSC9953_PORT_CFG_LEARN_CPU,
+				CONFIG_VSC9953_PORT_CFG_LEARN_ENA |
+				CONFIG_VSC9953_PORT_CFG_LEARN_AUTO);
+		break;
+	default:
+		printf("Unknown learn mode for port %d\n", port_no);
+	}
+}
+
+/* Get learning configuration for a VSC9953 port */
+static int vsc9953_port_learn_mode_get(int port_no, enum port_learn_mode *mode)
+{
+	u32				val;
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	/* Administrative down */
+	if (!vsc9953_l2sw.port[port_no].enabled) {
+		printf("Port %d is administrative down\n", port_no);
+		return -1;
+	}
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	/* For now we only support HW learning (auto) and no learning */
+	val = in_le32(&l2ana_reg->port[port_no].port_cfg);
+	if ((val & (CONFIG_VSC9953_PORT_CFG_LEARN_ENA |
+		   CONFIG_VSC9953_PORT_CFG_LEARN_AUTO)) ==
+	    (CONFIG_VSC9953_PORT_CFG_LEARN_ENA |
+	     CONFIG_VSC9953_PORT_CFG_LEARN_AUTO))
+		*mode = PORT_LEARN_AUTO;
+	else
+		*mode = PORT_LEARN_NONE;
+
+	return 0;
+}
+
 /* Show VSC9953 ports' statistics */
 static void vsc9953_port_statistics_show(int port_no)
 {
@@ -895,6 +962,8 @@ enum keyword_id {
 	id_disable,
 	id_statistics,
 	id_clear,
+	id_learning,
+	id_auto,
 	id_count,	/* keep last */
 };
 
@@ -1002,6 +1071,84 @@ static int vsc9953_port_stats_clear_key_func(struct command_def *parsed_cmd)
 	return 0;
 }
 
+#define VSC9953_LEARN_HELP "ethsw [port <port_no>] learning " \
+"{ [help] | show | auto | disable } " \
+"- enable/disable/show learning configuration on a port"
+
+static int vsc9953_learn_help_key_func(struct command_def *parsed_cmd)
+{
+	printf(VSC9953_LEARN_HELP"\n");
+
+	return 0;
+}
+
+static int vsc9953_learn_show_key_func(struct command_def *parsed_cmd)
+{
+	int				i;
+	enum port_learn_mode		mode;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		if (vsc9953_port_learn_mode_get(parsed_cmd->port, &mode))
+			return -1;
+		printf("%7s %11s\n", "Port", "Learn mode");
+		switch (mode) {
+		case PORT_LEARN_NONE:
+			printf("%7d %11s\n", parsed_cmd->port, "disable");
+			break;
+		case PORT_LEARN_AUTO:
+			printf("%7d %11s\n", parsed_cmd->port, "auto");
+			break;
+		default:
+			printf("%7d %11s\n", parsed_cmd->port, "-");
+		}
+	} else {
+		printf("%7s %11s\n", "Port", "Learn mode");
+		for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+			if (vsc9953_port_learn_mode_get(i, &mode))
+				continue;
+			switch (mode) {
+			case PORT_LEARN_NONE:
+				printf("%7d %11s\n", i, "disable");
+				break;
+			case PORT_LEARN_AUTO:
+				printf("%7d %11s\n", i, "auto");
+				break;
+			default:
+				printf("%7d %11s\n", i, "-");
+			}
+		}
+	}
+
+	return 0;
+}
+
+static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd)
+{
+	int				i;
+	enum port_learn_mode		mode;
+
+	/* Last keyword should tell us the learn mode */
+	if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+			id_auto)
+		mode = PORT_LEARN_AUTO;
+	else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+			id_disable)
+		mode = PORT_LEARN_NONE;
+	else {
+		parsed_cmd->err = 1;
+		return -1;
+	}
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_port_learn_mode_set(parsed_cmd->port, mode);
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_port_learn_mode_set(i, mode);
+	}
+
+	return 0;
+}
+
 struct keywords_to_function {
 	enum keyword_id cmd_keyword[VSC9953_MAX_CMD_PARAMS];
 	int (*keyword_function)(struct command_def *parsed_cmd);
@@ -1044,6 +1191,40 @@ struct keywords_to_function {
 					id_key_end,
 			},
 			.keyword_function = &vsc9953_port_stats_clear_key_func,
+		}, {
+			.cmd_keyword = {
+					id_learning,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_learn_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_learning,
+					id_help,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_learn_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_learning,
+					id_show,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_learn_show_key_func,
+		}, {
+			.cmd_keyword = {
+					id_learning,
+					id_auto,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_learn_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_learning,
+					id_disable,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_learn_set_key_func,
 		},
 };
 
@@ -1095,6 +1276,12 @@ struct keyword_def {
 		}, {
 				.keyword_name = "clear",
 				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "learning",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "auto",
+				.match = &keyword_match_gen,
 		},
 };
 
@@ -1273,6 +1460,7 @@ U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
 	   "vsc9953 l2 switch commands",
 	   VSC9953_PORT_CONF_HELP"\n"
 	   VSC9953_PORT_STATS_HELP"\n"
+	   VSC9953_LEARN_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
include/vsc9953.h +6 -0
index 482acac..59c85c3 100644
@@ -112,6 +112,12 @@
 #define CONFIG_VSC9953_VLAN_CMD_WRITE	0x00000002
 #define CONFIG_VSC9953_VLAN_CMD_INIT	0x00000003
 
+/* Macros for vsc9953_ana_port.port_cfg register */
+#define CONFIG_VSC9953_PORT_CFG_LEARN_ENA	0x00000080
+#define CONFIG_VSC9953_PORT_CFG_LEARN_AUTO	0x00000100
+#define CONFIG_VSC9953_PORT_CFG_LEARN_CPU	0x00000200
+#define CONFIG_VSC9953_PORT_CFG_LEARN_DROP	0x00000400
+
 /* Macros for vsc9953_qsys_sys.switch_port_mode register */
 #define CONFIG_VSC9953_PORT_ENA		0x00002000
 
Signature · 1 line
1.9.3
#30 lore raw

PATCH v2 6/11 drivers/net/vsc9953: Add commands to enable/disable HW learning

Hi Codrin,

Quoted 105 lines · Codrin Ciubotariu

The command:
ethsw [port <port_no>] learning { [help] | show | auto | disable }

can be used to enable/disable HW learning on a port.

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/vsc9953.h     |   6 ++
 2 files changed, 194 insertions(+)
drivers/net/vsc9953.c +69 -0
index 62ab0eb..1936c4a 100644
@@ -672,6 +672,73 @@ static void vsc9953_port_config_show(int port_no)
        printf("%8s\n", duplex == DUPLEX_FULL ? "full" : "half");
 }
 
+enum port_learn_mode {
+       PORT_LEARN_NONE,
+       PORT_LEARN_AUTO
+};
+
+/* Set learning configuration for a VSC9953 port */
+static void vsc9953_port_learn_mode_set(int port_no, enum port_learn_mode mode)
+{
+       struct vsc9953_analyzer         *l2ana_reg;
+
+       /* Administrative down */
+       if (!vsc9953_l2sw.port[port_no].enabled) {
+               printf("Port %d is administrative down\n", port_no);
+               return;
+       }
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       switch (mode) {
+       case PORT_LEARN_NONE:
+               clrbits_le32(&l2ana_reg->port[port_no].port_cfg,
+                            CONFIG_VSC9953_PORT_CFG_LEARN_DROP |
+                            CONFIG_VSC9953_PORT_CFG_LEARN_CPU |
+                            CONFIG_VSC9953_PORT_CFG_LEARN_AUTO |
+                            CONFIG_VSC9953_PORT_CFG_LEARN_ENA);
+               break;
+       case PORT_LEARN_AUTO:
+               clrsetbits_le32(&l2ana_reg->port[port_no].port_cfg,
+                               CONFIG_VSC9953_PORT_CFG_LEARN_DROP |
+                               CONFIG_VSC9953_PORT_CFG_LEARN_CPU,
+                               CONFIG_VSC9953_PORT_CFG_LEARN_ENA |
+                               CONFIG_VSC9953_PORT_CFG_LEARN_AUTO);
+               break;
+       default:
+               printf("Unknown learn mode for port %d\n", port_no);
+       }
+}
+
+/* Get learning configuration for a VSC9953 port */
+static int vsc9953_port_learn_mode_get(int port_no, enum port_learn_mode *mode)
+{
+       u32                             val;
+       struct vsc9953_analyzer         *l2ana_reg;
+
+       /* Administrative down */
+       if (!vsc9953_l2sw.port[port_no].enabled) {
+               printf("Port %d is administrative down\n", port_no);
+               return -1;
+       }
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       /* For now we only support HW learning (auto) and no learning */
+       val = in_le32(&l2ana_reg->port[port_no].port_cfg);
+       if ((val & (CONFIG_VSC9953_PORT_CFG_LEARN_ENA |
+                  CONFIG_VSC9953_PORT_CFG_LEARN_AUTO)) ==
+           (CONFIG_VSC9953_PORT_CFG_LEARN_ENA |
+            CONFIG_VSC9953_PORT_CFG_LEARN_AUTO))
+               *mode = PORT_LEARN_AUTO;
+       else
+               *mode = PORT_LEARN_NONE;
+
+       return 0;
+}
+
 /* Show VSC9953 ports' statistics */
 static void vsc9953_port_statistics_show(int port_no)
 {
@@ -895,6 +962,8 @@ enum keyword_id {
        id_disable,
        id_statistics,
        id_clear,
+       id_learning,
+       id_auto,
        id_count,       /* keep last */
 };
 
@@ -1002,6 +1071,84 @@ static int vsc9953_port_stats_clear_key_func(struct command_def *parsed_cmd)
        return 0;
 }

drivers/net/vsc9953.c static int vsc9953_port_stats_clear_key_func(struct command_def *parsed_cmd) · line 1082

Quoted 10 lines
drivers/net/vsc9953.c +9 -0
 
+#define VSC9953_LEARN_HELP "ethsw [port <port_no>] learning " \
+"{ [help] | show | auto | disable } " \
+"- enable/disable/show learning configuration on a port"
+
+static int vsc9953_learn_help_key_func(struct command_def *parsed_cmd)
+{
+       printf(VSC9953_LEARN_HELP"\n");
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_port_stats_clear_key_func(struct command_def *parsed_cmd) · line 1092

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+}
+
+static int vsc9953_learn_show_key_func(struct command_def *parsed_cmd)
+{
+       int                             i;
+       enum port_learn_mode            mode;
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               if (vsc9953_port_learn_mode_get(parsed_cmd->port, &mode))
+                       return -1;

Please use:
+ return CMD_RET_FAILURE;

Quoted 20 lines
drivers/net/vsc9953.c +20 -0
+               printf("%7s %11s\n", "Port", "Learn mode");
+               switch (mode) {
+               case PORT_LEARN_NONE:
+                       printf("%7d %11s\n", parsed_cmd->port, "disable");
+                       break;
+               case PORT_LEARN_AUTO:
+                       printf("%7d %11s\n", parsed_cmd->port, "auto");
+                       break;
+               default:
+                       printf("%7d %11s\n", parsed_cmd->port, "-");
+               }
+       } else {
+               printf("%7s %11s\n", "Port", "Learn mode");
+               for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+                       if (vsc9953_port_learn_mode_get(i, &mode))
+                               continue;
+                       switch (mode) {
+                       case PORT_LEARN_NONE:
+                               printf("%7d %11s\n", i, "disable");
+                               break;

drivers/net/vsc9953.c static int vsc9953_port_stats_clear_key_func(struct command_def *parsed_cmd) · line 1122

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                       case PORT_LEARN_AUTO:
+                               printf("%7d %11s\n", i, "auto");
+                               break;
+                       default:
+                               printf("%7d %11s\n", i, "-");
+                       }
+               }
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 7 lines
drivers/net/vsc9953.c +7 -0
+}
+
+static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd)
+{
+       int                             i;
+       enum port_learn_mode            mode;
+

drivers/net/vsc9953.c static int vsc9953_port_stats_clear_key_func(struct command_def *parsed_cmd) · line 1139

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       /* Last keyword should tell us the learn mode */
+       if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+                       id_auto)
+               mode = PORT_LEARN_AUTO;
+       else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+                       id_disable)
+               mode = PORT_LEARN_NONE;
+       else {
+               parsed_cmd->err = 1;
+               return -1;

Please use:
+ return CMD_RET_USAGE;

drivers/net/vsc9953.c static int vsc9953_port_stats_clear_key_func(struct command_def *parsed_cmd) · line 1149

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       }
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               vsc9953_port_learn_mode_set(parsed_cmd->port, mode);
+       } else {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++)
+                       vsc9953_port_learn_mode_set(i, mode);
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 72 lines
drivers/net/vsc9953.c +43 -0
+}
+
 struct keywords_to_function {
        enum keyword_id cmd_keyword[VSC9953_MAX_CMD_PARAMS];
        int (*keyword_function)(struct command_def *parsed_cmd);
@@ -1044,6 +1191,40 @@ struct keywords_to_function {
                                        id_key_end,
                        },
                        .keyword_function = &vsc9953_port_stats_clear_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_learning,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_learn_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_learning,
+                                       id_help,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_learn_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_learning,
+                                       id_show,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_learn_show_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_learning,
+                                       id_auto,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_learn_set_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_learning,
+                                       id_disable,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_learn_set_key_func,
                },
 };
 
@@ -1095,6 +1276,12 @@ struct keyword_def {
                }, {
                                .keyword_name = "clear",
                                .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "learning",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "auto",
+                               .match = &keyword_match_gen,
                },
 };
 
@@ -1273,6 +1460,7 @@ U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
           "vsc9953 l2 switch commands",
           VSC9953_PORT_CONF_HELP"\n"
           VSC9953_PORT_STATS_HELP"\n"
+          VSC9953_LEARN_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
include/vsc9953.h +0 -0
index 482acac..59c85c3 100644

include/vsc9953.h line 119

Quoted 8 lines
include/vsc9953.h +5 -0
@@ -112,6 +112,12 @@
 #define CONFIG_VSC9953_VLAN_CMD_WRITE  0x00000002
 #define CONFIG_VSC9953_VLAN_CMD_INIT   0x00000003
 
+/* Macros for vsc9953_ana_port.port_cfg register */
+#define CONFIG_VSC9953_PORT_CFG_LEARN_ENA      0x00000080
+#define CONFIG_VSC9953_PORT_CFG_LEARN_AUTO     0x00000100
+#define CONFIG_VSC9953_PORT_CFG_LEARN_CPU      0x00000200
+#define CONFIG_VSC9953_PORT_CFG_LEARN_DROP     0x00000400

Drop "CONFIG_" from these.

Quoted 11 lines
include/vsc9953.h +1 -1
+
 /* Macros for vsc9953_qsys_sys.switch_port_mode register */
 #define CONFIG_VSC9953_PORT_ENA                0x00002000
 
--

1.9.3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#31 lore raw

PATCH v2 6/11 drivers/net/vsc9953: Add commands to enable/disable HW learning

Hi Joe,

I will make the changes you requested.

Thanks and best regards,
Codrin

Quoted 7 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:38 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 06/11 v2] drivers/net/vsc9953: Add commands to enable/disable HW learning

#32 lore raw

PATCH v2 7/11 drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953

In reply to Codrin Ciubotariu

The new command:
ethsw [port <port_no>] [vlan <vid>] fdb

	{ [help] | show | flush | { add | del } <mac> }

Can be used to add and delete FDB entries. Also, the command can be used to show entries from the FDB tables. When used with [port <port_no>] and [vlan <vid>], only the matching the FDB entries can be seen or flushed.

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 635 +++++++++++++++++++++++++++++++++++++++++++++++++-
 include/vsc9953.h     |  28 +++
 2 files changed, 662 insertions(+), 1 deletion(-)
drivers/net/vsc9953.c +634 -1
index 1936c4a..ef7b50c 100644
@@ -12,6 +12,7 @@
 #include <fsl_memac.h>
 #include <errno.h>
 #include <vsc9953.h>
+#include <linux/ctype.h>
 
 static struct vsc9953_info vsc9953_l2sw = {
 		.port[0] = VSC9953_PORT_INFO_INITIALIZER(0),
@@ -579,6 +580,7 @@ void vsc9953_init(bd_t *bis)
 
 #define VSC9953_MAX_CMD_PARAMS	20
 #define VSC9953_CMD_PORT_ALL	-1
+#define VSC9953_CMD_VLAN_ALL	-1
 
 /* Enable/disable status of a VSC9953 port */
 static void vsc9953_port_status_set(int port_no, u8 enabled)
@@ -952,6 +954,365 @@ static void vsc9953_port_statistics_clear(int port_no)
 		 CONFIG_VSC9953_STAT_CLEAR_DR);
 }
 
+/* wait for FDB to become available */
+static int vsc9953_mac_table_poll_idle(void)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+	u32				timeout;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	timeout = 50000;
+	while (((in_le32(&l2ana_reg->ana_tables.mac_access) &
+			CONFIG_VSC9953_MAC_CMD_MASK) !=
+		 CONFIG_VSC9953_MAC_CMD_IDLE) && --timeout)
+		udelay(1);
+
+	return !!timeout;
+}
+
+/* enum describing available commands for the MAC table */
+enum mac_table_cmd {
+	MAC_TABLE_READ_DIRECT,
+	MAC_TABLE_READ_INDIRECT,
+	MAC_TABLE_WRITE,
+	MAC_TABLE_LEARN,
+	MAC_TABLE_FORGET,
+	MAC_TABLE_GET_NEXT,
+	MAC_TABLE_AGE,
+};
+
+/* Issues a command to the FDB table */
+static int vsc9953_mac_table_cmd(enum mac_table_cmd cmd)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	switch (cmd) {
+	case MAC_TABLE_READ_DIRECT:
+		clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+				CONFIG_VSC9953_MAC_CMD_MASK |
+				CONFIG_VSC9953_MAC_CMD_VALID,
+				CONFIG_VSC9953_MAC_CMD_READ);
+		break;
+	case MAC_TABLE_READ_INDIRECT:
+		clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+				CONFIG_VSC9953_MAC_CMD_MASK,
+				CONFIG_VSC9953_MAC_CMD_READ |
+				CONFIG_VSC9953_MAC_CMD_VALID);
+		break;
+	case MAC_TABLE_WRITE:
+		clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+				CONFIG_VSC9953_MAC_CMD_MASK |
+				CONFIG_VSC9953_MAC_ENTRYTYPE_MASK,
+				CONFIG_VSC9953_MAC_CMD_WRITE |
+				CONFIG_VSC9953_MAC_ENTRYTYPE_LOCKED);
+		break;
+	case MAC_TABLE_LEARN:
+		clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+				CONFIG_VSC9953_MAC_CMD_MASK |
+				CONFIG_VSC9953_MAC_ENTRYTYPE_MASK,
+				CONFIG_VSC9953_MAC_CMD_LEARN |
+				CONFIG_VSC9953_MAC_ENTRYTYPE_LOCKED |
+				CONFIG_VSC9953_MAC_CMD_VALID);
+		break;
+	case MAC_TABLE_FORGET:
+		clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+				CONFIG_VSC9953_MAC_CMD_MASK |
+				CONFIG_VSC9953_MAC_ENTRYTYPE_MASK,
+				CONFIG_VSC9953_MAC_CMD_FORGET);
+		break;
+	case MAC_TABLE_GET_NEXT:
+		clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+				CONFIG_VSC9953_MAC_CMD_MASK |
+				CONFIG_VSC9953_MAC_ENTRYTYPE_MASK,
+				CONFIG_VSC9953_MAC_CMD_NEXT);
+		break;
+	case MAC_TABLE_AGE:
+		clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+				CONFIG_VSC9953_MAC_CMD_MASK |
+				CONFIG_VSC9953_MAC_ENTRYTYPE_MASK,
+				CONFIG_VSC9953_MAC_CMD_AGE);
+		break;
+	default:
+		printf("Unknown MAC table command\n");
+	}
+
+	if (!vsc9953_mac_table_poll_idle()) {
+		debug("MAC table timeout\n");
+		return -1;
+	}
+
+	/* For some commands we might have a way to
+	 * detect if the command succeeded
+	 */
+	if ((cmd == MAC_TABLE_GET_NEXT || cmd == MAC_TABLE_READ_DIRECT ||
+	     MAC_TABLE_READ_INDIRECT) &&
+	    !(in_le32(&l2ana_reg->ana_tables.mac_access) &
+	     CONFIG_VSC9953_MAC_CMD_VALID))
+		return -1;
+
+	return 0;
+}
+
+/* show the FDB entries that correspond to a port and a VLAN */
+static void vsc9953_mac_table_show(int port_no, int vid)
+{
+	int				i, rc[VSC9953_MAX_PORTS];
+	u32				val, vlan, mach, macl, dest_indx;
+	enum port_learn_mode		mode[VSC9953_MAX_PORTS];
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	/* disable auto learning */
+	if (port_no == VSC9953_CMD_PORT_ALL) {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+			rc[i] = vsc9953_port_learn_mode_get(i, &mode[i]);
+			if (!rc[i] && mode[i] != PORT_LEARN_NONE)
+				vsc9953_port_learn_mode_set(i,
+							    PORT_LEARN_NONE);
+		}
+	} else {
+		rc[port_no] = vsc9953_port_learn_mode_get(port_no,
+							  &mode[port_no]);
+		if (!rc[port_no] && mode[port_no] != PORT_LEARN_NONE)
+			vsc9953_port_learn_mode_set(port_no, PORT_LEARN_NONE);
+	}
+
+	/* write port and vid to get selected FDB entries */
+	val = in_le32(&l2ana_reg->ana.anag_efil);
+	if (port_no != VSC9953_CMD_PORT_ALL) {
+		val = (val & ~CONFIG_VSC9953_AGE_PORT_MASK) |
+				CONFIG_VSC9953_AGE_PORT_EN |
+				field_set(port_no,
+					  CONFIG_VSC9953_AGE_PORT_MASK);
+	}
+	if (vid != VSC9953_CMD_VLAN_ALL) {
+		val = (val & ~CONFIG_VSC9953_AGE_VID_MASK) |
+				CONFIG_VSC9953_AGE_VID_EN |
+				field_set(vid, CONFIG_VSC9953_AGE_VID_MASK);
+	}
+	out_le32(&l2ana_reg->ana.anag_efil, val);
+
+	/* set MAC and VLAN to 0 to look from beginning */
+	clrbits_le32(&l2ana_reg->ana_tables.mach_data,
+		     CONFIG_VSC9953_MAC_VID_MASK |
+		     CONFIG_VSC9953_MAC_MACH_MASK);
+	out_le32(&l2ana_reg->ana_tables.macl_data, 0);
+
+	/* get entries */
+	printf("%10s %17s %5s %4s\n", "EntryType", "MAC", "PORT", "VID");
+	do {
+		/* get out when an invalid entry is found */
+		if (vsc9953_mac_table_cmd(MAC_TABLE_GET_NEXT))
+			break;
+
+		val = in_le32(&l2ana_reg->ana_tables.mac_access);
+
+		switch (val & CONFIG_VSC9953_MAC_ENTRYTYPE_MASK) {
+		case CONFIG_VSC9953_MAC_ENTRYTYPE_NORMAL:
+			printf("%10s ", "Dynamic");
+			break;
+		case CONFIG_VSC9953_MAC_ENTRYTYPE_LOCKED:
+			printf("%10s ", "Static");
+			break;
+		case CONFIG_VSC9953_MAC_ENTRYTYPE_IPV4MCAST:
+			printf("%10s ", "IPv4 Mcast");
+			break;
+		case CONFIG_VSC9953_MAC_ENTRYTYPE_IPV6MCAST:
+			printf("%10s ", "IPv6 Mcast");
+			break;
+		default:
+			printf("%10s ", "Unknown");
+		}
+
+		dest_indx = field_get(val & CONFIG_VSC9953_MAC_DESTIDX_MASK,
+				      CONFIG_VSC9953_MAC_DESTIDX_MASK);
+
+		val = in_le32(&l2ana_reg->ana_tables.mach_data);
+		vlan = field_get(val & CONFIG_VSC9953_MAC_VID_MASK,
+				 CONFIG_VSC9953_MAC_VID_MASK);
+		mach = field_get(val & CONFIG_VSC9953_MAC_MACH_MASK,
+				 CONFIG_VSC9953_MAC_MACH_MASK);
+		macl = in_le32(&l2ana_reg->ana_tables.macl_data);
+
+		printf("%02x:%02x:%02x:%02x:%02x:%02x ", (mach >> 8) & 0xff,
+		       mach & 0xff, (macl >> 24) & 0xff, (macl >> 16) & 0xff,
+		       (macl >> 8) & 0xff, macl & 0xff);
+		printf("%5d ", dest_indx);
+		printf("%4d\n", vlan);
+	} while (1);
+
+	/* set learning mode to previous value */
+	if (port_no == VSC9953_CMD_PORT_ALL) {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+			if (!rc[i] && mode[i] != PORT_LEARN_NONE)
+				vsc9953_port_learn_mode_set(i, mode[i]);
+		}
+	} else {
+		/* If administrative down, skip */
+		if (!rc[port_no] && mode[port_no] != PORT_LEARN_NONE)
+			vsc9953_port_learn_mode_set(port_no, mode[port_no]);
+	}
+
+	/* reset FDB port and VLAN FDB selection */
+	clrbits_le32(&l2ana_reg->ana.anag_efil, CONFIG_VSC9953_AGE_PORT_EN |
+		     CONFIG_VSC9953_AGE_PORT_MASK | CONFIG_VSC9953_AGE_VID_EN |
+		     CONFIG_VSC9953_AGE_VID_MASK);
+}
+
+/* Add a static FDB entry */
+static int vsc9953_mac_table_add(u8 port_no, uchar mac[6], int vid)
+{
+	u32				val;
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	out_le32(&l2ana_reg->ana_tables.mach_data,
+		 (mac[0] << 8) | (mac[1] << 0) |
+		 (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+				 CONFIG_VSC9953_MACHDATA_VID_MASK));
+	out_le32(&l2ana_reg->ana_tables.macl_data,
+		 (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) |
+		 (mac[5] << 0));
+
+	/* set on which port is the MAC address added */
+	clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+			CONFIG_VSC9953_MAC_DESTIDX_MASK,
+			field_set(port_no, CONFIG_VSC9953_MAC_DESTIDX_MASK));
+	if (vsc9953_mac_table_cmd(MAC_TABLE_LEARN))
+		return -1;
+
+	/* check if the MAC address was indeed added */
+	out_le32(&l2ana_reg->ana_tables.mach_data,
+		 (mac[0] << 8) | (mac[1] << 0) |
+		 (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+				CONFIG_VSC9953_MACHDATA_VID_MASK));
+	out_le32(&l2ana_reg->ana_tables.macl_data,
+		 (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) |
+		 (mac[5] << 0));
+
+	if (vsc9953_mac_table_cmd(MAC_TABLE_READ_DIRECT))
+		return -1;
+
+	val = in_le32(&l2ana_reg->ana_tables.mac_access);
+
+	if ((port_no != field_get(val & CONFIG_VSC9953_MAC_DESTIDX_MASK,
+				  CONFIG_VSC9953_MAC_DESTIDX_MASK))) {
+		printf("Failed to add MAC address\n");
+		return -1;
+	}
+	return 0;
+}
+
+/* Delete a FDB entry */
+static int vsc9953_mac_table_del(uchar mac[6], u16 vid)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	/* check first if MAC entry is present */
+	out_le32(&l2ana_reg->ana_tables.mach_data,
+		 (mac[0] << 8) | (mac[1] << 0) |
+		 (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+		  CONFIG_VSC9953_MACHDATA_VID_MASK));
+	out_le32(&l2ana_reg->ana_tables.macl_data,
+		 (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) |
+		 (mac[5] << 0));
+
+	if (vsc9953_mac_table_cmd(MAC_TABLE_READ_INDIRECT)) {
+		printf("The MAC address: %02x:%02x:%02x:%02x:%02x:%02x ",
+		       mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+			printf("VLAN: %d does not exist.\n", vid);
+		return -1;
+	}
+
+	/* FDB entry found, proceed to delete */
+	out_le32(&l2ana_reg->ana_tables.mach_data, (mac[0] << 8) |
+		 (mac[1] << 0) |
+		 (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+		  CONFIG_VSC9953_MACHDATA_VID_MASK));
+	out_le32(&l2ana_reg->ana_tables.macl_data, (mac[2] << 24) |
+		 (mac[3] << 16) | (mac[4] << 8) | (mac[5] << 0));
+
+	if (vsc9953_mac_table_cmd(MAC_TABLE_FORGET))
+		return -1;
+
+	/* check if the MAC entry is still in FDB */
+	out_le32(&l2ana_reg->ana_tables.mach_data, (mac[0] << 8) |
+		 (mac[1] << 0) |
+		 (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+		  CONFIG_VSC9953_MACHDATA_VID_MASK));
+	out_le32(&l2ana_reg->ana_tables.macl_data, (mac[2] << 24) |
+		 (mac[3] << 16) | (mac[4] << 8) | (mac[5] << 0));
+
+	if (vsc9953_mac_table_cmd(MAC_TABLE_READ_INDIRECT)) {
+		printf("Failed to delete MAC address\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+/* age the unlocked entries in FDB */
+static void vsc9953_mac_table_age(int port_no, int vid)
+{
+	int				rc;
+	u32				val;
+	struct vsc9953_analyzer		*l2ana_reg;
+	enum port_learn_mode		mode;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	/* disable auto learning */
+	rc = vsc9953_port_learn_mode_get(port_no, &mode);
+	if (!rc && mode != PORT_LEARN_NONE)
+		vsc9953_port_learn_mode_set(port_no, PORT_LEARN_NONE);
+
+	/* set port and VID for selective aging */
+	val = in_le32(&l2ana_reg->ana.anag_efil);
+	if (port_no != VSC9953_CMD_PORT_ALL) {
+		val = (val & ~CONFIG_VSC9953_AGE_PORT_MASK) |
+		      CONFIG_VSC9953_AGE_PORT_EN |
+		      field_set(port_no, CONFIG_VSC9953_AGE_PORT_MASK);
+	}
+
+	if (vid != VSC9953_CMD_VLAN_ALL) {
+		val = (val & ~CONFIG_VSC9953_AGE_VID_MASK) |
+		      CONFIG_VSC9953_AGE_VID_EN |
+		      field_set(vid, CONFIG_VSC9953_AGE_VID_MASK);
+	}
+	out_le32(&l2ana_reg->ana.anag_efil, val);
+
+	/* age the dynamic FDB entries */
+	vsc9953_mac_table_cmd(MAC_TABLE_AGE);
+
+	/* clear previously set port and VID */
+	clrbits_le32(&l2ana_reg->ana.anag_efil, CONFIG_VSC9953_AGE_PORT_EN |
+		     CONFIG_VSC9953_AGE_PORT_MASK | CONFIG_VSC9953_AGE_VID_EN |
+		     CONFIG_VSC9953_AGE_VID_MASK);
+
+	if (!rc && mode != PORT_LEARN_NONE)
+		vsc9953_port_learn_mode_set(port_no, mode);
+}
+
+/* Delete all the dynamic FDB entries */
+static void vsc9953_mac_table_flush(int port, int vid)
+{
+	vsc9953_mac_table_age(port, vid);
+	vsc9953_mac_table_age(port, vid);
+}
+
 /* IDs used to track keywords in a command */
 enum keyword_id {
 	id_key_end = -1,
@@ -964,11 +1325,19 @@ enum keyword_id {
 	id_clear,
 	id_learning,
 	id_auto,
+	id_vlan,
+	id_fdb,
+	id_add,
+	id_del,
+	id_flush,
 	id_count,	/* keep last */
 };
 
 enum keyword_opt_id {
 	id_port_no = id_count + 1,
+	id_vlan_no,
+	id_add_del_no,
+	id_add_del_mac,
 	id_count_all,	/* keep last */
 };
 
@@ -977,6 +1346,8 @@ struct command_def {
 	int cmd_keywords_nr;
 	int port;
 	int err;
+	int vid;
+	uchar *mac_addr;
 	int (*cmd_function)(struct command_def *parsed_cmd);
 };
 
@@ -1149,6 +1520,77 @@ static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd)
 	return 0;
 }
 
+#define VSC9953_FDB_HELP "ethsw [port <port_no>] [vlan <vid>] fdb " \
+"{ [help] | show | flush | { add | del } <mac> } " \
+"- Add/delete a mac entry in FDB; use show to see FDB entries; " \
+"if vlan <vid> is missing, will be used VID 1"
+
+static int vsc9953_fdb_help_key_func(struct command_def *parsed_cmd)
+{
+	printf(VSC9953_FDB_HELP"\n");
+
+	return 0;
+}
+
+static int vsc9953_fdb_show_key_func(struct command_def *parsed_cmd)
+{
+	vsc9953_mac_table_show(parsed_cmd->port, parsed_cmd->vid);
+
+	return 0;
+}
+
+static int vsc9953_fdb_flush_key_func(struct command_def *parsed_cmd)
+{
+	vsc9953_mac_table_flush(parsed_cmd->port, parsed_cmd->vid);
+
+	return 0;
+}
+
+static int vsc9953_fdb_entry_add_key_func(struct command_def *parsed_cmd)
+{
+	int			vid;
+
+	/* check if MAC address is present */
+	if (!parsed_cmd->mac_addr) {
+		printf("Please use a valid MAC address\n");
+		return -EINVAL;
+	}
+
+	/* a port number must be present */
+	if (parsed_cmd->port == VSC9953_CMD_PORT_ALL) {
+		printf("Please specify a port\n");
+		return -EINVAL;
+	}
+
+	/* Use VLAN 1 if VID is not set */
+	vid = (parsed_cmd->vid == VSC9953_CMD_VLAN_ALL ? 1 : parsed_cmd->vid);
+
+	if (vsc9953_mac_table_add(parsed_cmd->port, parsed_cmd->mac_addr, vid))
+		return -1;
+
+	return 0;
+}
+
+static int vsc9953_fdb_entry_del_key_func(struct command_def *parsed_cmd)
+{
+	int			vid;
+
+	/* check if MAC address is present */
+	if (!parsed_cmd->mac_addr) {
+		printf("Please use a valid MAC address\n");
+		return -EINVAL;
+	}
+
+	/* Use VLAN 1 if VID is not set */
+	vid = (parsed_cmd->vid == VSC9953_CMD_VLAN_ALL ?
+	       1 : parsed_cmd->vid);
+
+	if (vsc9953_mac_table_del(parsed_cmd->mac_addr, vid))
+		return -1;
+
+	return 0;
+}
+
 struct keywords_to_function {
 	enum keyword_id cmd_keyword[VSC9953_MAX_CMD_PARAMS];
 	int (*keyword_function)(struct command_def *parsed_cmd);
@@ -1225,6 +1667,49 @@ struct keywords_to_function {
 					id_key_end,
 			},
 			.keyword_function = &vsc9953_learn_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_fdb,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_fdb_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_fdb,
+					id_help,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_fdb_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_fdb,
+					id_show,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_fdb_show_key_func,
+		}, {
+			.cmd_keyword = {
+					id_fdb,
+					id_flush,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_fdb_flush_key_func,
+		}, {
+			.cmd_keyword = {
+					id_fdb,
+					id_add,
+					id_add_del_mac,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_fdb_entry_add_key_func,
+		}, {
+			.cmd_keyword = {
+					id_fdb,
+					id_del,
+					id_add_del_mac,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_fdb_entry_del_key_func,
 		},
 };
 
@@ -1237,6 +1722,20 @@ struct keywords_optional {
 						id_port_no,
 						id_key_end,
 				},
+		}, {
+				.cmd_keyword = {
+						id_vlan,
+						id_vlan_no,
+						id_key_end,
+				},
+		}, {
+				.cmd_keyword = {
+						id_port,
+						id_port_no,
+						id_vlan,
+						id_vlan_no,
+						id_key_end,
+				},
 		},
 };
 
@@ -1246,6 +1745,12 @@ static int keyword_match_gen(enum keyword_id key_id, int argc,
 static int keyword_match_port(enum keyword_id key_id, int argc,
 			      char *const argv[], int *argc_nr,
 			      struct command_def *parsed_cmd);
+static int keyword_match_vlan(enum keyword_id key_id, int argc,
+			      char *const argv[], int *argc_nr,
+			      struct command_def *parsed_cmd);
+static int keyword_match_mac_addr(enum keyword_id key_id, int argc,
+				  char *const argv[], int *argc_nr,
+				  struct command_def *parsed_cmd);
 
 /* Define properties for each keyword;
  * keep the order synced with enum keyword_id
@@ -1282,6 +1787,21 @@ struct keyword_def {
 		}, {
 				.keyword_name = "auto",
 				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "vlan",
+				 .match = &keyword_match_vlan,
+		}, {
+				.keyword_name = "fdb",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "add",
+				.match = &keyword_match_mac_addr,
+		}, {
+				.keyword_name = "del",
+				.match = &keyword_match_mac_addr,
+		}, {
+				.keyword_name = "flush",
+				.match = &keyword_match_gen,
 		},
 };
 
@@ -1325,6 +1845,112 @@ static int keyword_match_port(enum keyword_id key_id, int argc,
 	return 0;
 }
 
+/* Function used to match the command's vlan */
+static int keyword_match_vlan(enum keyword_id key_id, int argc,
+			      char *const argv[], int *argc_nr,
+			      struct command_def *parsed_cmd)
+{
+	unsigned long			val;
+	int				aux;
+
+	if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
+		return 0;
+
+	if (*argc_nr + 1 >= argc)
+		return 0;
+
+	if (strict_strtoul(argv[*argc_nr + 1], 10, &val) != -EINVAL) {
+		if (!VSC9953_VLAN_CHECK(val)) {
+			printf("Invalid vlan number: %lu\n", val);
+			return 0;
+		}
+		parsed_cmd->vid = val;
+		(*argc_nr)++;
+		parsed_cmd->cmd_to_keywords[*argc_nr] = id_vlan_no;
+		return 1;
+	}
+
+	aux = *argc_nr + 1;
+
+	if (keyword_match_gen(id_add, argc, argv, &aux, parsed_cmd))
+		parsed_cmd->cmd_to_keywords[*argc_nr + 1] = id_add;
+	else if (keyword_match_gen(id_del, argc, argv, &aux, parsed_cmd))
+		parsed_cmd->cmd_to_keywords[*argc_nr + 1] = id_del;
+	else
+		return 0;
+
+	if (*argc_nr + 2 >= argc)
+		return 0;
+
+	if (strict_strtoul(argv[*argc_nr + 2], 10, &val) != -EINVAL) {
+		if (!VSC9953_VLAN_CHECK(val)) {
+			printf("Invalid vlan number: %lu\n", val);
+			return 0;
+		}
+		parsed_cmd->vid = val;
+		(*argc_nr) += 2;
+		parsed_cmd->cmd_to_keywords[*argc_nr] = id_add_del_no;
+		return 1;
+	}
+
+	return 0;
+}
+
+/* check if the string has the format for a MAC address */
+static int string_is_mac_addr(const char *mac)
+{
+	int			i;
+
+	if (!mac)
+		return 0;
+
+	for (i = 0; i < 6; i++) {
+		if (!isxdigit(*mac) || !isxdigit(*(mac + 1)))
+			return 0;
+		mac += 2;
+		if (i != 5) {
+			if (*mac != ':' && *mac != '-')
+				return 0;
+			mac++;
+		}
+	}
+
+	if (*mac != '\0')
+		return 0;
+
+	return 1;
+}
+
+/* Function used to match the command's MAC address */
+static int keyword_match_mac_addr(enum keyword_id key_id, int argc,
+				  char *const argv[], int *argc_nr,
+				  struct command_def *parsed_cmd)
+{
+	if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
+		return 0;
+
+	if ((*argc_nr + 1 >= argc) || parsed_cmd->mac_addr)
+		return 1;
+
+	if (!string_is_mac_addr(argv[*argc_nr + 1])) {
+		printf("Invalid mac address: %s\n", argv[*argc_nr + 1]);
+		return 0;
+	}
+
+	parsed_cmd->mac_addr = malloc(6);
+	eth_parse_enetaddr(argv[*argc_nr + 1], parsed_cmd->mac_addr);
+
+	if (is_broadcast_ethaddr(parsed_cmd->mac_addr)) {
+		free(parsed_cmd->mac_addr);
+		parsed_cmd->mac_addr = NULL;
+		return 0;
+	}
+
+	parsed_cmd->cmd_to_keywords[*argc_nr + 1] = id_add_del_mac;
+
+	return 1;
+}
+
 /* match optional keywords */
 static void cmd_keywords_opt_check(struct command_def *parsed_cmd,
 				   int *argc_val)
@@ -1414,13 +2040,19 @@ static void command_def_init(struct command_def *parsed_cmd)
 		parsed_cmd->cmd_to_keywords[i] = -1;
 
 	parsed_cmd->port = VSC9953_CMD_PORT_ALL;
+	parsed_cmd->vid = VSC9953_CMD_VLAN_ALL;
 	parsed_cmd->err = 0;
+	parsed_cmd->mac_addr = NULL;
 	parsed_cmd->cmd_function = NULL;
 }
 
 static void command_def_cleanup(struct command_def *parsed_cmd)
 {
-	/* Nothing to do for now */
+	/* free MAC address */
+	if (parsed_cmd->mac_addr) {
+		free(parsed_cmd->mac_addr);
+		parsed_cmd->mac_addr = NULL;
+	}
 }
 
 /* function to interpret commands starting with "ethsw " */
@@ -1461,6 +2093,7 @@ U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
 	   VSC9953_PORT_CONF_HELP"\n"
 	   VSC9953_PORT_STATS_HELP"\n"
 	   VSC9953_LEARN_HELP"\n"
+	   VSC9953_FDB_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
include/vsc9953.h +28 -0
index 59c85c3..051c24e 100644
@@ -93,6 +93,25 @@
 #define	CONFIG_VSC9953_VCAP_MV_CFG	0x0000ffff
 #define	CONFIG_VSC9953_VCAP_UPDATE_CTRL	0x01000004
 
+/* Macros for register vsc9953_ana_ana_tables.mac_access register */
+#define CONFIG_VSC9953_MAC_CMD_IDLE	0x00000000
+#define CONFIG_VSC9953_MAC_CMD_LEARN	0x00000001
+#define CONFIG_VSC9953_MAC_CMD_FORGET	0x00000002
+#define CONFIG_VSC9953_MAC_CMD_AGE	0x00000003
+#define CONFIG_VSC9953_MAC_CMD_NEXT	0x00000004
+#define CONFIG_VSC9953_MAC_CMD_READ	0x00000006
+#define CONFIG_VSC9953_MAC_CMD_WRITE	0x00000007
+#define CONFIG_VSC9953_MAC_CMD_MASK	0x00000007
+#define CONFIG_VSC9953_MAC_CMD_VALID	0x00000800
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_NORMAL	0x00000000
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_LOCKED	0x00000200
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_IPV4MCAST	0x00000400
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_IPV6MCAST	0x00000600
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_MASK	0x00000600
+#define CONFIG_VSC9953_MAC_DESTIDX_MASK	0x000001f8
+#define CONFIG_VSC9953_MAC_VID_MASK	0x1fff0000
+#define CONFIG_VSC9953_MAC_MACH_MASK	0x0000ffff
+
 /* Macros for vsc9953_ana_port.vlan_cfg register */
 #define CONFIG_VSC9953_VLAN_CFG_AWARE_ENA		0x00100000
 #define CONFIG_VSC9953_VLAN_CFG_POP_CNT_MASK		0x000c0000
@@ -131,6 +150,15 @@
 #define CONFIG_VSC9953_TAG_CFG_ALL_ZERO		0x00000100
 #define CONFIG_VSC9953_TAG_CFG_ALL	0x00000180
 
+/* Macros for vsc9953_ana_ana.anag_efil register */
+#define CONFIG_VSC9953_AGE_PORT_EN	0x00080000
+#define CONFIG_VSC9953_AGE_PORT_MASK	0x0007c000
+#define CONFIG_VSC9953_AGE_VID_EN	0x00002000
+#define CONFIG_VSC9953_AGE_VID_MASK	0x00001fff
+
+/* Macros for vsc9953_ana_ana_tables.mach_data register */
+#define CONFIG_VSC9953_MACHDATA_VID_MASK	0x1fff0000
+
 #define VSC9953_MAX_PORTS		10
 #define VSC9953_PORT_CHECK(port)	\
 	(((port) < 0 || (port) >= VSC9953_MAX_PORTS) ? 0 : 1)
Signature · 1 line
1.9.3
#33 lore raw

PATCH v2 7/11 drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953

Hi Codrin,

Quoted 40 lines · Codrin Ciubotariu

The new command:
ethsw [port <port_no>] [vlan <vid>] fdb

        { [help] | show | flush | { add | del } <mac> }

Can be used to add and delete FDB entries. Also, the command can be used to show entries from the FDB tables. When used with [port <port_no>] and [vlan <vid>], only the matching the FDB entries can be seen or flushed.

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 635 +++++++++++++++++++++++++++++++++++++++++++++++++-
 include/vsc9953.h     |  28 +++
 2 files changed, 662 insertions(+), 1 deletion(-)
drivers/net/vsc9953.c +2 -0
index 1936c4a..ef7b50c 100644
@@ -12,6 +12,7 @@
 #include <fsl_memac.h>
 #include <errno.h>
 #include <vsc9953.h>
+#include <linux/ctype.h>
 
 static struct vsc9953_info vsc9953_l2sw = {
                .port[0] = VSC9953_PORT_INFO_INITIALIZER(0),
@@ -579,6 +580,7 @@ void vsc9953_init(bd_t *bis)
 
 #define VSC9953_MAX_CMD_PARAMS 20
 #define VSC9953_CMD_PORT_ALL   -1
+#define VSC9953_CMD_VLAN_ALL   -1
 
 /* Enable/disable status of a VSC9953 port */
 static void vsc9953_port_status_set(int port_no, u8 enabled)

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 961

Quoted 8 lines
drivers/net/vsc9953.c +5 -0
@@ -952,6 +954,365 @@ static void vsc9953_port_statistics_clear(int port_no)
                 CONFIG_VSC9953_STAT_CLEAR_DR);
 }
 
+/* wait for FDB to become available */
+static int vsc9953_mac_table_poll_idle(void)
+{
+       struct vsc9953_analyzer         *l2ana_reg;
+       u32                             timeout;

Use a single space.

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 972

Quoted 11 lines
drivers/net/vsc9953.c +11 -0
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       timeout = 50000;
+       while (((in_le32(&l2ana_reg->ana_tables.mac_access) &
+                       CONFIG_VSC9953_MAC_CMD_MASK) !=
+                CONFIG_VSC9953_MAC_CMD_IDLE) && --timeout)
+               udelay(1);
+
+       return !!timeout;

Maybe return -EBUSY like suggested in previous patch.

Quoted 7 lines
drivers/net/vsc9953.c +7 -0
+}
+
+/* enum describing available commands for the MAC table */
+enum mac_table_cmd {
+       MAC_TABLE_READ_DIRECT,
+       MAC_TABLE_READ_INDIRECT,
+       MAC_TABLE_WRITE,

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 989

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       MAC_TABLE_LEARN,
+       MAC_TABLE_FORGET,
+       MAC_TABLE_GET_NEXT,
+       MAC_TABLE_AGE,
+};
+
+/* Issues a command to the FDB table */
+static int vsc9953_mac_table_cmd(enum mac_table_cmd cmd)
+{
+       struct vsc9953_analyzer         *l2ana_reg;

Use a single space.

Quoted 66 lines
drivers/net/vsc9953.c +66 -0
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       switch (cmd) {
+       case MAC_TABLE_READ_DIRECT:
+               clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+                               CONFIG_VSC9953_MAC_CMD_MASK |
+                               CONFIG_VSC9953_MAC_CMD_VALID,
+                               CONFIG_VSC9953_MAC_CMD_READ);
+               break;
+       case MAC_TABLE_READ_INDIRECT:
+               clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+                               CONFIG_VSC9953_MAC_CMD_MASK,
+                               CONFIG_VSC9953_MAC_CMD_READ |
+                               CONFIG_VSC9953_MAC_CMD_VALID);
+               break;
+       case MAC_TABLE_WRITE:
+               clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+                               CONFIG_VSC9953_MAC_CMD_MASK |
+                               CONFIG_VSC9953_MAC_ENTRYTYPE_MASK,
+                               CONFIG_VSC9953_MAC_CMD_WRITE |
+                               CONFIG_VSC9953_MAC_ENTRYTYPE_LOCKED);
+               break;
+       case MAC_TABLE_LEARN:
+               clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+                               CONFIG_VSC9953_MAC_CMD_MASK |
+                               CONFIG_VSC9953_MAC_ENTRYTYPE_MASK,
+                               CONFIG_VSC9953_MAC_CMD_LEARN |
+                               CONFIG_VSC9953_MAC_ENTRYTYPE_LOCKED |
+                               CONFIG_VSC9953_MAC_CMD_VALID);
+               break;
+       case MAC_TABLE_FORGET:
+               clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+                               CONFIG_VSC9953_MAC_CMD_MASK |
+                               CONFIG_VSC9953_MAC_ENTRYTYPE_MASK,
+                               CONFIG_VSC9953_MAC_CMD_FORGET);
+               break;
+       case MAC_TABLE_GET_NEXT:
+               clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+                               CONFIG_VSC9953_MAC_CMD_MASK |
+                               CONFIG_VSC9953_MAC_ENTRYTYPE_MASK,
+                               CONFIG_VSC9953_MAC_CMD_NEXT);
+               break;
+       case MAC_TABLE_AGE:
+               clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,
+                               CONFIG_VSC9953_MAC_CMD_MASK |
+                               CONFIG_VSC9953_MAC_ENTRYTYPE_MASK,
+                               CONFIG_VSC9953_MAC_CMD_AGE);
+               break;
+       default:
+               printf("Unknown MAC table command\n");
+       }
+
+       if (!vsc9953_mac_table_poll_idle()) {
+               debug("MAC table timeout\n");
+               return -1;
+       }
+
+       /* For some commands we might have a way to
+        * detect if the command succeeded
+        */
+       if ((cmd == MAC_TABLE_GET_NEXT || cmd == MAC_TABLE_READ_DIRECT ||
+            MAC_TABLE_READ_INDIRECT) &&
+           !(in_le32(&l2ana_reg->ana_tables.mac_access) &
+            CONFIG_VSC9953_MAC_CMD_VALID))

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1065

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+               return -1;
+
+       return 0;
+}
+
+/* show the FDB entries that correspond to a port and a VLAN */
+static void vsc9953_mac_table_show(int port_no, int vid)
+{
+       int                             i, rc[VSC9953_MAX_PORTS];
+       u32                             val, vlan, mach, macl, dest_indx;

Use a separate line for each variable.

Quoted 18 lines
drivers/net/vsc9953.c +18 -0
+       enum port_learn_mode            mode[VSC9953_MAX_PORTS];
+       struct vsc9953_analyzer         *l2ana_reg;
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       /* disable auto learning */
+       if (port_no == VSC9953_CMD_PORT_ALL) {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+                       rc[i] = vsc9953_port_learn_mode_get(i, &mode[i]);
+                       if (!rc[i] && mode[i] != PORT_LEARN_NONE)
+                               vsc9953_port_learn_mode_set(i,
+                                                           PORT_LEARN_NONE);
+               }
+       } else {
+               rc[port_no] = vsc9953_port_learn_mode_get(port_no,
+                                                         &mode[port_no]);
+               if (!rc[port_no] && mode[port_no] != PORT_LEARN_NONE)

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1093

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                       vsc9953_port_learn_mode_set(port_no, PORT_LEARN_NONE);
+       }
+
+       /* write port and vid to get selected FDB entries */
+       val = in_le32(&l2ana_reg->ana.anag_efil);
+       if (port_no != VSC9953_CMD_PORT_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_PORT_MASK) |
+                               CONFIG_VSC9953_AGE_PORT_EN |
+                               field_set(port_no,
+                                         CONFIG_VSC9953_AGE_PORT_MASK);

Seems like a good place to use bitfield_replace() from include/bitfield.h (or a new one that you add that uses the mask for the shift).

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1098

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+       }
+       if (vid != VSC9953_CMD_VLAN_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_VID_MASK) |
+                               CONFIG_VSC9953_AGE_VID_EN |
+                               field_set(vid, CONFIG_VSC9953_AGE_VID_MASK);

Same here.

Quoted 31 lines
drivers/net/vsc9953.c +31 -0
+       }
+       out_le32(&l2ana_reg->ana.anag_efil, val);
+
+       /* set MAC and VLAN to 0 to look from beginning */
+       clrbits_le32(&l2ana_reg->ana_tables.mach_data,
+                    CONFIG_VSC9953_MAC_VID_MASK |
+                    CONFIG_VSC9953_MAC_MACH_MASK);
+       out_le32(&l2ana_reg->ana_tables.macl_data, 0);
+
+       /* get entries */
+       printf("%10s %17s %5s %4s\n", "EntryType", "MAC", "PORT", "VID");
+       do {
+               /* get out when an invalid entry is found */
+               if (vsc9953_mac_table_cmd(MAC_TABLE_GET_NEXT))
+                       break;
+
+               val = in_le32(&l2ana_reg->ana_tables.mac_access);
+
+               switch (val & CONFIG_VSC9953_MAC_ENTRYTYPE_MASK) {
+               case CONFIG_VSC9953_MAC_ENTRYTYPE_NORMAL:
+                       printf("%10s ", "Dynamic");
+                       break;
+               case CONFIG_VSC9953_MAC_ENTRYTYPE_LOCKED:
+                       printf("%10s ", "Static");
+                       break;
+               case CONFIG_VSC9953_MAC_ENTRYTYPE_IPV4MCAST:
+                       printf("%10s ", "IPv4 Mcast");
+                       break;
+               case CONFIG_VSC9953_MAC_ENTRYTYPE_IPV6MCAST:
+                       printf("%10s ", "IPv6 Mcast");
+                       break;

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1139

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+               default:
+                       printf("%10s ", "Unknown");
+               }
+
+               dest_indx = field_get(val & CONFIG_VSC9953_MAC_DESTIDX_MASK,
+                                     CONFIG_VSC9953_MAC_DESTIDX_MASK);
+
+               val = in_le32(&l2ana_reg->ana_tables.mach_data);
+               vlan = field_get(val & CONFIG_VSC9953_MAC_VID_MASK,
+                                CONFIG_VSC9953_MAC_VID_MASK);

It seems like masking off the val before shifting it would be better implemented inside the field_get function (renamed and moved to include/bitfield.h) instead of on each use.

Quoted 32 lines
drivers/net/vsc9953.c +32 -0
+               mach = field_get(val & CONFIG_VSC9953_MAC_MACH_MASK,
+                                CONFIG_VSC9953_MAC_MACH_MASK);
+               macl = in_le32(&l2ana_reg->ana_tables.macl_data);
+
+               printf("%02x:%02x:%02x:%02x:%02x:%02x ", (mach >> 8) & 0xff,
+                      mach & 0xff, (macl >> 24) & 0xff, (macl >> 16) & 0xff,
+                      (macl >> 8) & 0xff, macl & 0xff);
+               printf("%5d ", dest_indx);
+               printf("%4d\n", vlan);
+       } while (1);
+
+       /* set learning mode to previous value */
+       if (port_no == VSC9953_CMD_PORT_ALL) {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+                       if (!rc[i] && mode[i] != PORT_LEARN_NONE)
+                               vsc9953_port_learn_mode_set(i, mode[i]);
+               }
+       } else {
+               /* If administrative down, skip */
+               if (!rc[port_no] && mode[port_no] != PORT_LEARN_NONE)
+                       vsc9953_port_learn_mode_set(port_no, mode[port_no]);
+       }
+
+       /* reset FDB port and VLAN FDB selection */
+       clrbits_le32(&l2ana_reg->ana.anag_efil, CONFIG_VSC9953_AGE_PORT_EN |
+                    CONFIG_VSC9953_AGE_PORT_MASK | CONFIG_VSC9953_AGE_VID_EN |
+                    CONFIG_VSC9953_AGE_VID_MASK);
+}
+
+/* Add a static FDB entry */
+static int vsc9953_mac_table_add(u8 port_no, uchar mac[6], int vid)
+{

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1181

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       u32                             val;
+       struct vsc9953_analyzer         *l2ana_reg;
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       out_le32(&l2ana_reg->ana_tables.mach_data,
+                (mac[0] << 8) | (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                                CONFIG_VSC9953_MACHDATA_VID_MASK));

Why do you need to & with the mask again after field_set()?

Quoted 6 lines
drivers/net/vsc9953.c +6 -0
+       out_le32(&l2ana_reg->ana_tables.macl_data,
+                (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) |
+                (mac[5] << 0));
+
+       /* set on which port is the MAC address added */
+       clrsetbits_le32(&l2ana_reg->ana_tables.mac_access,

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1197

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                       CONFIG_VSC9953_MAC_DESTIDX_MASK,
+                       field_set(port_no, CONFIG_VSC9953_MAC_DESTIDX_MASK));
+       if (vsc9953_mac_table_cmd(MAC_TABLE_LEARN))
+               return -1;
+
+       /* check if the MAC address was indeed added */
+       out_le32(&l2ana_reg->ana_tables.mach_data,
+                (mac[0] << 8) | (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                               CONFIG_VSC9953_MACHDATA_VID_MASK));

Why do you need to & with the mask again after field_set()?

Quoted 11 lines
drivers/net/vsc9953.c +11 -0
+       out_le32(&l2ana_reg->ana_tables.macl_data,
+                (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) |
+                (mac[5] << 0));
+
+       if (vsc9953_mac_table_cmd(MAC_TABLE_READ_DIRECT))
+               return -1;
+
+       val = in_le32(&l2ana_reg->ana_tables.mac_access);
+
+       if ((port_no != field_get(val & CONFIG_VSC9953_MAC_DESTIDX_MASK,
+                                 CONFIG_VSC9953_MAC_DESTIDX_MASK))) {

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1218

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+               printf("Failed to add MAC address\n");
+               return -1;
+       }
+       return 0;
+}
+
+/* Delete a FDB entry */
+static int vsc9953_mac_table_del(uchar mac[6], u16 vid)
+{
+       struct vsc9953_analyzer         *l2ana_reg;

Use a single space.

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1227

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       /* check first if MAC entry is present */
+       out_le32(&l2ana_reg->ana_tables.mach_data,
+                (mac[0] << 8) | (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                 CONFIG_VSC9953_MACHDATA_VID_MASK));

Why do you need to & with the mask again after field_set()?

Quoted 6 lines
drivers/net/vsc9953.c +6 -0
+       out_le32(&l2ana_reg->ana_tables.macl_data,
+                (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) |
+                (mac[5] << 0));
+
+       if (vsc9953_mac_table_cmd(MAC_TABLE_READ_INDIRECT)) {
+               printf("The MAC address: %02x:%02x:%02x:%02x:%02x:%02x ",

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1243

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                      mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+                       printf("VLAN: %d does not exist.\n", vid);
+               return -1;
+       }
+
+       /* FDB entry found, proceed to delete */
+       out_le32(&l2ana_reg->ana_tables.mach_data, (mac[0] << 8) |
+                (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                 CONFIG_VSC9953_MACHDATA_VID_MASK));

Why do you need to & with the mask again after field_set()?

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1254

Quoted 11 lines
drivers/net/vsc9953.c +11 -0
+       out_le32(&l2ana_reg->ana_tables.macl_data, (mac[2] << 24) |
+                (mac[3] << 16) | (mac[4] << 8) | (mac[5] << 0));
+
+       if (vsc9953_mac_table_cmd(MAC_TABLE_FORGET))
+               return -1;
+
+       /* check if the MAC entry is still in FDB */
+       out_le32(&l2ana_reg->ana_tables.mach_data, (mac[0] << 8) |
+                (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                 CONFIG_VSC9953_MACHDATA_VID_MASK));

Why do you need to & with the mask again after field_set()?

Quoted 23 lines
drivers/net/vsc9953.c +23 -0
+       out_le32(&l2ana_reg->ana_tables.macl_data, (mac[2] << 24) |
+                (mac[3] << 16) | (mac[4] << 8) | (mac[5] << 0));
+
+       if (vsc9953_mac_table_cmd(MAC_TABLE_READ_INDIRECT)) {
+               printf("Failed to delete MAC address\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+/* age the unlocked entries in FDB */
+static void vsc9953_mac_table_age(int port_no, int vid)
+{
+       int                             rc;
+       u32                             val;
+       struct vsc9953_analyzer         *l2ana_reg;
+       enum port_learn_mode            mode;
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       /* disable auto learning */

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1287

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       rc = vsc9953_port_learn_mode_get(port_no, &mode);
+       if (!rc && mode != PORT_LEARN_NONE)
+               vsc9953_port_learn_mode_set(port_no, PORT_LEARN_NONE);
+
+       /* set port and VID for selective aging */
+       val = in_le32(&l2ana_reg->ana.anag_efil);
+       if (port_no != VSC9953_CMD_PORT_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_PORT_MASK) |
+                     CONFIG_VSC9953_AGE_PORT_EN |
+                     field_set(port_no, CONFIG_VSC9953_AGE_PORT_MASK);

Seems like a good place to use bitfield_replace() from include/bitfield.h (or a new one that you add that uses the mask for the shift).

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1098

Quoted 6 lines
drivers/net/vsc9953.c +6 -0
+       }
+
+       if (vid != VSC9953_CMD_VLAN_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_VID_MASK) |
+                     CONFIG_VSC9953_AGE_VID_EN |
+                     field_set(vid, CONFIG_VSC9953_AGE_VID_MASK);

Same here.

Quoted 46 lines
drivers/net/vsc9953.c +30 -0
+       }
+       out_le32(&l2ana_reg->ana.anag_efil, val);
+
+       /* age the dynamic FDB entries */
+       vsc9953_mac_table_cmd(MAC_TABLE_AGE);
+
+       /* clear previously set port and VID */
+       clrbits_le32(&l2ana_reg->ana.anag_efil, CONFIG_VSC9953_AGE_PORT_EN |
+                    CONFIG_VSC9953_AGE_PORT_MASK | CONFIG_VSC9953_AGE_VID_EN |
+                    CONFIG_VSC9953_AGE_VID_MASK);
+
+       if (!rc && mode != PORT_LEARN_NONE)
+               vsc9953_port_learn_mode_set(port_no, mode);
+}
+
+/* Delete all the dynamic FDB entries */
+static void vsc9953_mac_table_flush(int port, int vid)
+{
+       vsc9953_mac_table_age(port, vid);
+       vsc9953_mac_table_age(port, vid);
+}
+
 /* IDs used to track keywords in a command */
 enum keyword_id {
        id_key_end = -1,
@@ -964,11 +1325,19 @@ enum keyword_id {
        id_clear,
        id_learning,
        id_auto,
+       id_vlan,
+       id_fdb,
+       id_add,
+       id_del,
+       id_flush,
        id_count,       /* keep last */
 };
 
 enum keyword_opt_id {
        id_port_no = id_count + 1,
+       id_vlan_no,
+       id_add_del_no,
+       id_add_del_mac,
        id_count_all,   /* keep last */
 };
 

drivers/net/vsc9953.c struct command_def { · line 1350

Quoted 5 lines
drivers/net/vsc9953.c +2 -0
@@ -977,6 +1346,8 @@ struct command_def {
        int cmd_keywords_nr;
        int port;
        int err;
+       int vid;
+       uchar *mac_addr;

Use this:
+ uchar ethaddr[6];
I recently made a pass through U-Boot trying to standardize on that naming. Also, don't make it a pointer that has to be allocated. It is small and of known size.

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1526

Quoted 11 lines
drivers/net/vsc9953.c +4 -0
        int (*cmd_function)(struct command_def *parsed_cmd);
 };
 
@@ -1149,6 +1520,77 @@ static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd)
        return 0;
 }
 
+#define VSC9953_FDB_HELP "ethsw [port <port_no>] [vlan <vid>] fdb " \
+"{ [help] | show | flush | { add | del } <mac> } " \
+"- Add/delete a mac entry in FDB; use show to see FDB entries; " \
+"if vlan <vid> is missing, will be used VID 1"

Please use this:
+"if vlan <vid> is missing, VID 1 will be used"

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1532

Quoted 6 lines
drivers/net/vsc9953.c +6 -0
+
+static int vsc9953_fdb_help_key_func(struct command_def *parsed_cmd)
+{
+       printf(VSC9953_FDB_HELP"\n");
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1539

Quoted 7 lines
drivers/net/vsc9953.c +7 -0
+}
+
+static int vsc9953_fdb_show_key_func(struct command_def *parsed_cmd)
+{
+       vsc9953_mac_table_show(parsed_cmd->port, parsed_cmd->vid);
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1546

Quoted 7 lines
drivers/net/vsc9953.c +7 -0
+}
+
+static int vsc9953_fdb_flush_key_func(struct command_def *parsed_cmd)
+{
+       vsc9953_mac_table_flush(parsed_cmd->port, parsed_cmd->vid);
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1554

Quoted 8 lines
drivers/net/vsc9953.c +8 -0
+}
+
+static int vsc9953_fdb_entry_add_key_func(struct command_def *parsed_cmd)
+{
+       int                     vid;
+
+       /* check if MAC address is present */
+       if (!parsed_cmd->mac_addr) {

Use this:
+ if (is_valid_ethaddr(parsed_cmd->mac_addr)) {

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1556

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+               printf("Please use a valid MAC address\n");
+               return -EINVAL;

Please use:
+ return CMD_RET_USAGE;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1562

Quoted 6 lines
drivers/net/vsc9953.c +6 -0
+       }
+
+       /* a port number must be present */
+       if (parsed_cmd->port == VSC9953_CMD_PORT_ALL) {
+               printf("Please specify a port\n");
+               return -EINVAL;

Please use:
+ return CMD_RET_USAGE;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1569

Quoted 7 lines
drivers/net/vsc9953.c +7 -0
+       }
+
+       /* Use VLAN 1 if VID is not set */
+       vid = (parsed_cmd->vid == VSC9953_CMD_VLAN_ALL ? 1 : parsed_cmd->vid);
+
+       if (vsc9953_mac_table_add(parsed_cmd->port, parsed_cmd->mac_addr, vid))
+               return -1;

Please use:
+ return CMD_RET_FAILURE;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1571

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1579

Quoted 8 lines
drivers/net/vsc9953.c +8 -0
+}
+
+static int vsc9953_fdb_entry_del_key_func(struct command_def *parsed_cmd)
+{
+       int                     vid;
+
+       /* check if MAC address is present */
+       if (!parsed_cmd->mac_addr) {

Use this:
+ if (is_valid_ethaddr(parsed_cmd->mac_addr)) {

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1581

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+               printf("Please use a valid MAC address\n");
+               return -EINVAL;

Please use:
+ return CMD_RET_USAGE;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1589

Quoted 8 lines
drivers/net/vsc9953.c +8 -0
+       }
+
+       /* Use VLAN 1 if VID is not set */
+       vid = (parsed_cmd->vid == VSC9953_CMD_VLAN_ALL ?
+              1 : parsed_cmd->vid);
+
+       if (vsc9953_mac_table_del(parsed_cmd->mac_addr, vid))
+               return -1;

Please use:
+ return CMD_RET_FAILURE;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1591

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 112 lines
drivers/net/vsc9953.c +80 -0
+}
+
 struct keywords_to_function {
        enum keyword_id cmd_keyword[VSC9953_MAX_CMD_PARAMS];
        int (*keyword_function)(struct command_def *parsed_cmd);
@@ -1225,6 +1667,49 @@ struct keywords_to_function {
                                        id_key_end,
                        },
                        .keyword_function = &vsc9953_learn_set_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_fdb,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_fdb_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_fdb,
+                                       id_help,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_fdb_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_fdb,
+                                       id_show,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_fdb_show_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_fdb,
+                                       id_flush,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_fdb_flush_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_fdb,
+                                       id_add,
+                                       id_add_del_mac,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_fdb_entry_add_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_fdb,
+                                       id_del,
+                                       id_add_del_mac,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_fdb_entry_del_key_func,
                },
 };
 
@@ -1237,6 +1722,20 @@ struct keywords_optional {
                                                id_port_no,
                                                id_key_end,
                                },
+               }, {
+                               .cmd_keyword = {
+                                               id_vlan,
+                                               id_vlan_no,
+                                               id_key_end,
+                               },
+               }, {
+                               .cmd_keyword = {
+                                               id_port,
+                                               id_port_no,
+                                               id_vlan,
+                                               id_vlan_no,
+                                               id_key_end,
+                               },
                },
 };
 
@@ -1246,6 +1745,12 @@ static int keyword_match_gen(enum keyword_id key_id, int argc,
 static int keyword_match_port(enum keyword_id key_id, int argc,
                              char *const argv[], int *argc_nr,
                              struct command_def *parsed_cmd);
+static int keyword_match_vlan(enum keyword_id key_id, int argc,
+                             char *const argv[], int *argc_nr,
+                             struct command_def *parsed_cmd);
+static int keyword_match_mac_addr(enum keyword_id key_id, int argc,
+                                 char *const argv[], int *argc_nr,
+                                 struct command_def *parsed_cmd);
 
 /* Define properties for each keyword;
  * keep the order synced with enum keyword_id
@@ -1282,6 +1787,21 @@ struct keyword_def {
                }, {
                                .keyword_name = "auto",
                                .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "vlan",
+                                .match = &keyword_match_vlan,
+               }, {
+                               .keyword_name = "fdb",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "add",
+                               .match = &keyword_match_mac_addr,
+               }, {
+                               .keyword_name = "del",
+                               .match = &keyword_match_mac_addr,
+               }, {
+                               .keyword_name = "flush",
+                               .match = &keyword_match_gen,
                },
 };
 

drivers/net/vsc9953.c static int keyword_match_port(enum keyword_id key_id, int argc, · line 1854

Quoted 10 lines
drivers/net/vsc9953.c +7 -0
@@ -1325,6 +1845,112 @@ static int keyword_match_port(enum keyword_id key_id, int argc,
        return 0;
 }
 
+/* Function used to match the command's vlan */
+static int keyword_match_vlan(enum keyword_id key_id, int argc,
+                             char *const argv[], int *argc_nr,
+                             struct command_def *parsed_cmd)
+{
+       unsigned long                   val;
+       int                             aux;

Use a single space.

Quoted 57 lines
drivers/net/vsc9953.c +57 -0
+
+       if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
+               return 0;
+
+       if (*argc_nr + 1 >= argc)
+               return 0;
+
+       if (strict_strtoul(argv[*argc_nr + 1], 10, &val) != -EINVAL) {
+               if (!VSC9953_VLAN_CHECK(val)) {
+                       printf("Invalid vlan number: %lu\n", val);
+                       return 0;
+               }
+               parsed_cmd->vid = val;
+               (*argc_nr)++;
+               parsed_cmd->cmd_to_keywords[*argc_nr] = id_vlan_no;
+               return 1;
+       }
+
+       aux = *argc_nr + 1;
+
+       if (keyword_match_gen(id_add, argc, argv, &aux, parsed_cmd))
+               parsed_cmd->cmd_to_keywords[*argc_nr + 1] = id_add;
+       else if (keyword_match_gen(id_del, argc, argv, &aux, parsed_cmd))
+               parsed_cmd->cmd_to_keywords[*argc_nr + 1] = id_del;
+       else
+               return 0;
+
+       if (*argc_nr + 2 >= argc)
+               return 0;
+
+       if (strict_strtoul(argv[*argc_nr + 2], 10, &val) != -EINVAL) {
+               if (!VSC9953_VLAN_CHECK(val)) {
+                       printf("Invalid vlan number: %lu\n", val);
+                       return 0;
+               }
+               parsed_cmd->vid = val;
+               (*argc_nr) += 2;
+               parsed_cmd->cmd_to_keywords[*argc_nr] = id_add_del_no;
+               return 1;
+       }
+
+       return 0;
+}
+
+/* check if the string has the format for a MAC address */
+static int string_is_mac_addr(const char *mac)
+{
+       int                     i;
+
+       if (!mac)
+               return 0;
+
+       for (i = 0; i < 6; i++) {
+               if (!isxdigit(*mac) || !isxdigit(*(mac + 1)))
+                       return 0;
+               mac += 2;
+               if (i != 5) {

drivers/net/vsc9953.c static int keyword_match_port(enum keyword_id key_id, int argc, · line 1921

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                       if (*mac != ':' && *mac != '-')
+                               return 0;
+                       mac++;
+               }
+       }
+
+       if (*mac != '\0')
+               return 0;
+
+       return 1;

This functionality is already implemented in common/env_flags.c in the _env_flags_validate_type() function. Maybe that implementation should be extracted. Another option is to make the eth_parse_enetaddr() in net/eth.c return a status and then it can be used. Either way I don't think it should be re-implemented here.

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+}
+
+/* Function used to match the command's MAC address */
+static int keyword_match_mac_addr(enum keyword_id key_id, int argc,
+                                 char *const argv[], int *argc_nr,
+                                 struct command_def *parsed_cmd)
+{
+       if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
+               return 0;

drivers/net/vsc9953.c static int keyword_match_port(enum keyword_id key_id, int argc, · line 1940

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+
+       if ((*argc_nr + 1 >= argc) || parsed_cmd->mac_addr)
+               return 1;
+
+       if (!string_is_mac_addr(argv[*argc_nr + 1])) {
+               printf("Invalid mac address: %s\n", argv[*argc_nr + 1]);
+               return 0;
+       }
+
+       parsed_cmd->mac_addr = malloc(6);

Why malloc this? It is small and known size.

drivers/net/vsc9953.c static int keyword_match_port(enum keyword_id key_id, int argc, · line 1945

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+       eth_parse_enetaddr(argv[*argc_nr + 1], parsed_cmd->mac_addr);
+
+       if (is_broadcast_ethaddr(parsed_cmd->mac_addr)) {
+               free(parsed_cmd->mac_addr);
+               parsed_cmd->mac_addr = NULL;

Drop these two lines.

Quoted 12 lines
drivers/net/vsc9953.c +8 -0
+               return 0;
+       }
+
+       parsed_cmd->cmd_to_keywords[*argc_nr + 1] = id_add_del_mac;
+
+       return 1;
+}
+
 /* match optional keywords */
 static void cmd_keywords_opt_check(struct command_def *parsed_cmd,
                                   int *argc_val)

drivers/net/vsc9953.c static void command_def_init(struct command_def *parsed_cmd) · line 2045

Quoted 6 lines
drivers/net/vsc9953.c +2 -0
@@ -1414,13 +2040,19 @@ static void command_def_init(struct command_def *parsed_cmd)
                parsed_cmd->cmd_to_keywords[i] = -1;
 
        parsed_cmd->port = VSC9953_CMD_PORT_ALL;
+       parsed_cmd->vid = VSC9953_CMD_VLAN_ALL;
        parsed_cmd->err = 0;
+       parsed_cmd->mac_addr = NULL;

Drop this.

drivers/net/vsc9953.c static void command_def_init(struct command_def *parsed_cmd) · line 2055

Quoted 11 lines
drivers/net/vsc9953.c +5 -1
        parsed_cmd->cmd_function = NULL;
 }
 
 static void command_def_cleanup(struct command_def *parsed_cmd)
 {
-       /* Nothing to do for now */
+       /* free MAC address */
+       if (parsed_cmd->mac_addr) {
+               free(parsed_cmd->mac_addr);
+               parsed_cmd->mac_addr = NULL;
+       }

Don't malloc, and you don't need free.

Quoted 43 lines
drivers/net/vsc9953.c +1 -0
 }
 
 /* function to interpret commands starting with "ethsw " */
@@ -1461,6 +2093,7 @@ U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
           VSC9953_PORT_CONF_HELP"\n"
           VSC9953_PORT_STATS_HELP"\n"
           VSC9953_LEARN_HELP"\n"
+          VSC9953_FDB_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
include/vsc9953.h +19 -0
index 59c85c3..051c24e 100644
@@ -93,6 +93,25 @@
 #define        CONFIG_VSC9953_VCAP_MV_CFG      0x0000ffff
 #define        CONFIG_VSC9953_VCAP_UPDATE_CTRL 0x01000004
 
+/* Macros for register vsc9953_ana_ana_tables.mac_access register */
+#define CONFIG_VSC9953_MAC_CMD_IDLE    0x00000000
+#define CONFIG_VSC9953_MAC_CMD_LEARN   0x00000001
+#define CONFIG_VSC9953_MAC_CMD_FORGET  0x00000002
+#define CONFIG_VSC9953_MAC_CMD_AGE     0x00000003
+#define CONFIG_VSC9953_MAC_CMD_NEXT    0x00000004
+#define CONFIG_VSC9953_MAC_CMD_READ    0x00000006
+#define CONFIG_VSC9953_MAC_CMD_WRITE   0x00000007
+#define CONFIG_VSC9953_MAC_CMD_MASK    0x00000007
+#define CONFIG_VSC9953_MAC_CMD_VALID   0x00000800
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_NORMAL    0x00000000
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_LOCKED    0x00000200
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_IPV4MCAST 0x00000400
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_IPV6MCAST 0x00000600
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_MASK      0x00000600
+#define CONFIG_VSC9953_MAC_DESTIDX_MASK        0x000001f8
+#define CONFIG_VSC9953_MAC_VID_MASK    0x1fff0000
+#define CONFIG_VSC9953_MAC_MACH_MASK   0x0000ffff
+
 /* Macros for vsc9953_ana_port.vlan_cfg register */
 #define CONFIG_VSC9953_VLAN_CFG_AWARE_ENA              0x00100000
 #define CONFIG_VSC9953_VLAN_CFG_POP_CNT_MASK           0x000c0000
@@ -131,6 +150,15 @@
 #define CONFIG_VSC9953_TAG_CFG_ALL_ZERO                0x00000100

include/vsc9953.h line 160

Quoted 10 lines
include/vsc9953.h +8 -0
 #define CONFIG_VSC9953_TAG_CFG_ALL     0x00000180
 
+/* Macros for vsc9953_ana_ana.anag_efil register */
+#define CONFIG_VSC9953_AGE_PORT_EN     0x00080000
+#define CONFIG_VSC9953_AGE_PORT_MASK   0x0007c000
+#define CONFIG_VSC9953_AGE_VID_EN      0x00002000
+#define CONFIG_VSC9953_AGE_VID_MASK    0x00001fff
+
+/* Macros for vsc9953_ana_ana_tables.mach_data register */
+#define CONFIG_VSC9953_MACHDATA_VID_MASK       0x1fff0000

Drop "CONFIG_" from all these.

Quoted 11 lines
include/vsc9953.h +1 -1
+
 #define VSC9953_MAX_PORTS              10
 #define VSC9953_PORT_CHECK(port)       \
        (((port) < 0 || (port) >= VSC9953_MAX_PORTS) ? 0 : 1)
--

1.9.3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#34 lore raw

PATCH v2 7/11 drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953

Hi Joe,

Quoted 11 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:39 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 07/11 v2] drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953

Quoted 1 line

+ return !!timeout;

Maybe return -EBUSY like suggested in previous patch.

Ok.

Quoted 12 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1093

Quoted 7 lines
drivers/net/vsc9953.c +7 -0
+       /* write port and vid to get selected FDB entries */
+       val = in_le32(&l2ana_reg->ana.anag_efil);
+       if (port_no != VSC9953_CMD_PORT_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_PORT_MASK) |
+                               CONFIG_VSC9953_AGE_PORT_EN |
+                               field_set(port_no,
+                                         CONFIG_VSC9953_AGE_PORT_MASK);

Seems like a good place to use bitfield_replace() from include/bitfield.h (or a new one that you add that uses the mask for the shift).

Quoted 7 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1098

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+       }
+       if (vid != VSC9953_CMD_VLAN_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_VID_MASK) |
+                               CONFIG_VSC9953_AGE_VID_EN |
+                               field_set(vid, CONFIG_VSC9953_AGE_VID_MASK);

Same here.

Ok.

Quoted 6 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1139

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+               vlan = field_get(val & CONFIG_VSC9953_MAC_VID_MASK,
+                                CONFIG_VSC9953_MAC_VID_MASK);

It seems like masking off the val before shifting it would be better implemented inside the field_get function (renamed and moved to include/bitfield.h) instead of on each use.

Yes, something like #define field_set(val, mask) (((val) * ((mask) & ~((mask) << 1))) & mask) and
#define field_get(val, mask) ((val & mask) / ((mask) & ~((mask) << 1))).

Quoted 6 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1181

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+       out_le32(&l2ana_reg->ana_tables.mach_data,
+                (mac[0] << 8) | (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                                CONFIG_VSC9953_MACHDATA_VID_MASK));

Why do you need to & with the mask again after field_set()?

To assure that the shifted vid value is not higher than its mask. Adding the mask to the macro/inline function as described above should assure this.

Quoted 7 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1197

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+       /* check if the MAC address was indeed added */
+       out_le32(&l2ana_reg->ana_tables.mach_data,
+                (mac[0] << 8) | (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                               CONFIG_VSC9953_MACHDATA_VID_MASK));

Why do you need to & with the mask again after field_set()?

Same here.

Quoted 6 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1181

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+       out_le32(&l2ana_reg->ana_tables.mach_data,
+                (mac[0] << 8) | (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                 CONFIG_VSC9953_MACHDATA_VID_MASK));

Why do you need to & with the mask again after field_set()?

Same here.

Quoted 6 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1243

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+       out_le32(&l2ana_reg->ana_tables.mach_data, (mac[0] << 8) |
+                (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                 CONFIG_VSC9953_MACHDATA_VID_MASK));

Why do you need to & with the mask again after field_set()?

Same here.

Quoted 6 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1243

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+       out_le32(&l2ana_reg->ana_tables.mach_data, (mac[0] << 8) |
+                (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                 CONFIG_VSC9953_MACHDATA_VID_MASK));

Why do you need to & with the mask again after field_set()?

Same here.

Quoted 9 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1287

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+       val = in_le32(&l2ana_reg->ana.anag_efil);
+       if (port_no != VSC9953_CMD_PORT_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_PORT_MASK) |
+                     CONFIG_VSC9953_AGE_PORT_EN |
+                     field_set(port_no, CONFIG_VSC9953_AGE_PORT_MASK);

Seems like a good place to use bitfield_replace() from include/bitfield.h (or a new one that you add that uses the mask for the shift).

Ok.

Quoted 9 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1098

Quoted 7 lines
drivers/net/vsc9953.c +6 -0
+       }
+
+       if (vid != VSC9953_CMD_VLAN_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_VID_MASK) |
+                     CONFIG_VSC9953_AGE_VID_EN |
+                     field_set(vid, CONFIG_VSC9953_AGE_VID_MASK);

Same here.

Ok.

Quoted 7 lines
Quoted 1 line

+ uchar *mac_addr;

Use this:
+ uchar ethaddr[6];
I recently made a pass through U-Boot trying to standardize on that naming. Also, don't make it a pointer that has to be allocated. It is small and of known size.

Ok.

Quoted 7 lines
Quoted 4 lines

+#define VSC9953_FDB_HELP "ethsw [port <port_no>] [vlan <vid>] fdb " \
+"{ [help] | show | flush | { add | del } <mac> } " \
+"- Add/delete a mac entry in FDB; use show to see FDB entries; " \
+"if vlan <vid> is missing, will be used VID 1"

Please use this:
+"if vlan <vid> is missing, VID 1 will be used"

Ok.

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+       /* check if MAC address is present */
+       if (!parsed_cmd->mac_addr) {

Use this:
+ if (is_valid_ethaddr(parsed_cmd->mac_addr)) {

is_valid_ethaddr() returns false if the mac address is 00:00:00:00:00:00, but for the L2 Switch, this mac address is valid. Maybe is_broadcast_ethaddr()?

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+       /* check if MAC address is present */
+       if (!parsed_cmd->mac_addr) {

Use this:
+ if (is_valid_ethaddr(parsed_cmd->mac_addr)) {

Same as above.

Quoted 21 lines
Quoted 21 lines
drivers/net/vsc9953.c +21 -0
+/* check if the string has the format for a MAC address */
+static int string_is_mac_addr(const char *mac)
+{
+       int                     i;
+
+       if (!mac)
+               return 0;
+
+       for (i = 0; i < 6; i++) {
+               if (!isxdigit(*mac) || !isxdigit(*(mac + 1)))
+                       return 0;
+               mac += 2;
+               if (i != 5) {
+                       if (*mac != ':' && *mac != '-')
+                               return 0;
+                       mac++;
+               }
+       }
+
+       if (*mac != '\0')
+               return 0;
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+       return 1;

This functionality is already implemented in common/env_flags.c in the _env_flags_validate_type() function. Maybe that implementation should be extracted. Another option is to make the eth_parse_enetaddr() in net/eth.c return a status and then it can be used. Either way I don't think it should be re-implemented here.

Yes, I noticed that this function is already implemented, but with no access to it. I will see how I can use the one available.

Quoted 3 lines
Quoted 1 line

+ parsed_cmd->mac_addr = malloc(6);

Why malloc this? It is small and known size.

I will declare the array statically.

Quoted 5 lines

drivers/net/vsc9953.c static int keyword_match_port(enum keyword_id key_id, int argc, · line 1945

Quoted 3 lines
drivers/net/vsc9953.c +3 -0
+       if (is_broadcast_ethaddr(parsed_cmd->mac_addr)) {
+               free(parsed_cmd->mac_addr);
+               parsed_cmd->mac_addr = NULL;

Drop these two lines.

Ok.

Quoted 8 lines

drivers/net/vsc9953.c static void command_def_init(struct command_def *parsed_cmd) · line 2055

Quoted 6 lines
drivers/net/vsc9953.c +5 -1
-       /* Nothing to do for now */
+       /* free MAC address */
+       if (parsed_cmd->mac_addr) {
+               free(parsed_cmd->mac_addr);
+               parsed_cmd->mac_addr = NULL;
+       }

Don't malloc, and you don't need free.

Ok.

Quoted 29 lines
Quoted 29 lines

#define CONFIG_VSC9953_VCAP_MV_CFG 0x0000ffff
#define CONFIG_VSC9953_VCAP_UPDATE_CTRL 0x01000004

include/vsc9953.h +19 -0
+/* Macros for register vsc9953_ana_ana_tables.mac_access register */
+#define CONFIG_VSC9953_MAC_CMD_IDLE    0x00000000
+#define CONFIG_VSC9953_MAC_CMD_LEARN   0x00000001
+#define CONFIG_VSC9953_MAC_CMD_FORGET  0x00000002
+#define CONFIG_VSC9953_MAC_CMD_AGE     0x00000003
+#define CONFIG_VSC9953_MAC_CMD_NEXT    0x00000004
+#define CONFIG_VSC9953_MAC_CMD_READ    0x00000006
+#define CONFIG_VSC9953_MAC_CMD_WRITE   0x00000007
+#define CONFIG_VSC9953_MAC_CMD_MASK    0x00000007
+#define CONFIG_VSC9953_MAC_CMD_VALID   0x00000800
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_NORMAL    0x00000000
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_LOCKED    0x00000200
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_IPV4MCAST 0x00000400
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_IPV6MCAST 0x00000600
+#define CONFIG_VSC9953_MAC_ENTRYTYPE_MASK      0x00000600
+#define CONFIG_VSC9953_MAC_DESTIDX_MASK        0x000001f8
+#define CONFIG_VSC9953_MAC_VID_MASK    0x1fff0000
+#define CONFIG_VSC9953_MAC_MACH_MASK   0x0000ffff
+
 /* Macros for vsc9953_ana_port.vlan_cfg register */
 #define CONFIG_VSC9953_VLAN_CFG_AWARE_ENA              0x00100000
 #define CONFIG_VSC9953_VLAN_CFG_POP_CNT_MASK           0x000c0000
@@ -131,6 +150,15 @@
 #define CONFIG_VSC9953_TAG_CFG_ALL_ZERO                0x00000100
 #define CONFIG_VSC9953_TAG_CFG_ALL     0x00000180
 
Quoted 10 lines

include/vsc9953.h line 160

Quoted 8 lines
include/vsc9953.h +8 -0
+/* Macros for vsc9953_ana_ana.anag_efil register */
+#define CONFIG_VSC9953_AGE_PORT_EN     0x00080000
+#define CONFIG_VSC9953_AGE_PORT_MASK   0x0007c000
+#define CONFIG_VSC9953_AGE_VID_EN      0x00002000
+#define CONFIG_VSC9953_AGE_VID_MASK    0x00001fff
+
+/* Macros for vsc9953_ana_ana_tables.mach_data register */
+#define CONFIG_VSC9953_MACHDATA_VID_MASK       0x1fff0000

Drop "CONFIG_" from all these.

Ok.

Thanks and best regards,
Codrin

#35 lore raw

PATCH v2 7/11 drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953

Hi Codrin,

Quoted 41 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 11 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:39 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 07/11 v2] drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953

Quoted 1 line

+ return !!timeout;

Maybe return -EBUSY like suggested in previous patch.

Ok.

Quoted 12 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1093

Quoted 7 lines
drivers/net/vsc9953.c +7 -0
+       /* write port and vid to get selected FDB entries */
+       val = in_le32(&l2ana_reg->ana.anag_efil);
+       if (port_no != VSC9953_CMD_PORT_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_PORT_MASK) |
+                               CONFIG_VSC9953_AGE_PORT_EN |
+                               field_set(port_no,
+                                         CONFIG_VSC9953_AGE_PORT_MASK);

Seems like a good place to use bitfield_replace() from include/bitfield.h (or a new one that you add that uses the mask for the shift).

Quoted 7 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1098

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+       }
+       if (vid != VSC9953_CMD_VLAN_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_VID_MASK) |
+                               CONFIG_VSC9953_AGE_VID_EN |
+                               field_set(vid, CONFIG_VSC9953_AGE_VID_MASK);

Same here.

Ok.

Quoted 3 lines
Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+               vlan = field_get(val & CONFIG_VSC9953_MAC_VID_MASK,
+                                CONFIG_VSC9953_MAC_VID_MASK);
Quoted 6 lines
Quoted 3 lines

It seems like masking off the val before shifting it would be better implemented inside the field_get function (renamed and moved to include/bitfield.h) instead of on each use.

Yes, something like #define field_set(val, mask) (((val) * ((mask) & ~((mask) << 1))) & mask) and
#define field_get(val, mask) ((val & mask) / ((mask) & ~((mask) << 1))).

The set seems the same as replace, just without any other bitfields to preserve. You could just use replace and pass in 0 as the reg_val.

Quoted 8 lines
Quoted 6 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1181

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+       out_le32(&l2ana_reg->ana_tables.mach_data,
+                (mac[0] << 8) | (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                                CONFIG_VSC9953_MACHDATA_VID_MASK));

Why do you need to & with the mask again after field_set()?

To assure that the shifted vid value is not higher than its mask. Adding the mask to the macro/inline function as described above should assure this.

OK. Maybe the existing bitfield_replace() should be updated to also mask off the bitfield_val.

Quoted 7 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+       /* check if MAC address is present */
+       if (!parsed_cmd->mac_addr) {

Use this:
+ if (is_valid_ethaddr(parsed_cmd->mac_addr)) {

is_valid_ethaddr() returns false if the mac address is 00:00:00:00:00:00, but for the L2 Switch, this mac address is valid. Maybe is_broadcast_ethaddr()?

I'm not sure what criteria you intend to check for here, so I'm not sure if that is appropriate.

Quoted 38 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+       /* check if MAC address is present */
+       if (!parsed_cmd->mac_addr) {

Use this:
+ if (is_valid_ethaddr(parsed_cmd->mac_addr)) {

Same as above.

Quoted 21 lines
Quoted 21 lines
drivers/net/vsc9953.c +21 -0
+/* check if the string has the format for a MAC address */
+static int string_is_mac_addr(const char *mac)
+{
+       int                     i;
+
+       if (!mac)
+               return 0;
+
+       for (i = 0; i < 6; i++) {
+               if (!isxdigit(*mac) || !isxdigit(*(mac + 1)))
+                       return 0;
+               mac += 2;
+               if (i != 5) {
+                       if (*mac != ':' && *mac != '-')
+                               return 0;
+                       mac++;
+               }
+       }
+
+       if (*mac != '\0')
+               return 0;
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+       return 1;

This functionality is already implemented in common/env_flags.c in the _env_flags_validate_type() function. Maybe that implementation should be extracted. Another option is to make the eth_parse_enetaddr() in net/eth.c return a status and then it can be used. Either way I don't think it should be re-implemented here.

Quoted 1 line

Yes, I noticed that this function is already implemented, but with no access to it. I will see how I can use the one available.

Which path do you plan to take?

Thanks,
-Joe

#36 lore raw

PATCH v2 7/11 drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953

Hi Joe,

Quoted 58 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Wednesday, July 01, 2015 1:50 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 07/11 v2] drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953

Hi Codrin,

Quoted 10 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 8 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:39 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 07/11 v2] drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953

Quoted 23 lines
Quoted 3 lines
Quoted 1 line

+ return !!timeout;

Maybe return -EBUSY like suggested in previous patch.

Ok.

Quoted 17 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1093

Quoted 7 lines
drivers/net/vsc9953.c +7 -0
+       /* write port and vid to get selected FDB entries */
+       val = in_le32(&l2ana_reg->ana.anag_efil);
+       if (port_no != VSC9953_CMD_PORT_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_PORT_MASK) |
+                               CONFIG_VSC9953_AGE_PORT_EN |
+                               field_set(port_no,
+                                         CONFIG_VSC9953_AGE_PORT_MASK);

Seems like a good place to use bitfield_replace() from include/bitfield.h (or a new one that you add that uses the mask for the shift).

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+       }
+       if (vid != VSC9953_CMD_VLAN_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_VID_MASK) |
+                               CONFIG_VSC9953_AGE_VID_EN |
+                               field_set(vid,

CONFIG_VSC9953_AGE_VID_MASK);

Quoted 12 lines
Quoted 2 lines

Same here.

Ok.

Quoted 6 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1139

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+               vlan = field_get(val & CONFIG_VSC9953_MAC_VID_MASK,
+                                CONFIG_VSC9953_MAC_VID_MASK);

It seems like masking off the val before shifting it would be better implemented inside the field_get function (renamed and moved to include/bitfield.h) instead of on each use.

Quoted 7 lines
Quoted 1 line

Yes, something like #define field_set(val, mask) (((val) * ((mask) &

~((mask) << 1))) & mask) and

Quoted 1 line

#define field_get(val, mask) ((val & mask) / ((mask) & ~((mask) <<

1))).

The set seems the same as replace, just without any other bitfields to preserve. You could just use replace and pass in 0 as the reg_val.

Yes, although I still have to pass the "shift" parameter.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/net/vsc9953.c +4 -0
+       out_le32(&l2ana_reg->ana_tables.mach_data,
+                (mac[0] << 8) | (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                                CONFIG_VSC9953_MACHDATA_VID_MASK));
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Why do you need to & with the mask again after field_set()?

To assure that the shifted vid value is not higher than its mask. Adding the

mask to the macro/inline function as described above should assure this.

OK. Maybe the existing bitfield_replace() should be updated to also mask off the bitfield_val.

Yes, I think it should be updated. Should I make a separate patch for it? It should be out of this patch set since it has nothing to do with VSC9953.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
(quoted diff) +2 -0
+       /* check if MAC address is present */
+       if (!parsed_cmd->mac_addr) {
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Use this:
+ if (is_valid_ethaddr(parsed_cmd->mac_addr)) {

is_valid_ethaddr() returns false if the mac address is 00:00:00:00:00:00, but

for the L2 Switch, this mac address is valid. Maybe is_broadcast_ethaddr()?

I'm not sure what criteria you intend to check for here, so I'm not sure if that is appropriate.

When a command for adding/removing a mac address is issued, we should check if there is a valid mac address in parsed_cmd->mac_addr. I guess that this could be checked only in keyword_match_mac_addr(). Also, since mac_addr will become a static array, I should initialize this array with an invalid mac address. Since 0 mac address is a valid address for the L2 Switch, I was thinking to initialize it with L2 Broadcast address. What do you think?

Quoted 39 lines
Quoted 39 lines
Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+       /* check if MAC address is present */
+       if (!parsed_cmd->mac_addr) {

Use this:
+ if (is_valid_ethaddr(parsed_cmd->mac_addr)) {

Same as above.

Quoted 29 lines
Quoted 13 lines
drivers/net/vsc9953.c +13 -0
+/* check if the string has the format for a MAC address */
+static int string_is_mac_addr(const char *mac)
+{
+       int                     i;
+
+       if (!mac)
+               return 0;
+
+       for (i = 0; i < 6; i++) {
+               if (!isxdigit(*mac) || !isxdigit(*(mac + 1)))
+                       return 0;
+               mac += 2;
+               if (i != 5) {

drivers/net/vsc9953.c static int keyword_match_port(enum keyword_id key_id, int argc, · line 1921

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                       if (*mac != ':' && *mac != '-')
+                               return 0;
+                       mac++;
+               }
+       }
+
+       if (*mac != '\0')
+               return 0;
+
+       return 1;

This functionality is already implemented in common/env_flags.c in the _env_flags_validate_type() function. Maybe that implementation should be extracted. Another option is to make the eth_parse_enetaddr() in net/eth.c return a status and then it can be used. Either way I don't think it should be re-implemented here.

Quoted 4 lines
Quoted 1 line

Yes, I noticed that this function is already implemented, but with no access

to it. I will see how I can use the one available.

Which path do you plan to take?

I looked through both eth_parse_enetaddr() and _env_flags_validate_type() and I prefer the implementation from the latter function, since eth_parse_enetaddr() doesn't check for ':' or if the value returned by simple_strtoul() is <= 0xFF. I could move the code from "case env_flags_vartype_macaddr:" to a separate function (something like eth_check_enetaddr()? ) and add its prototype somewhere in include/net.h. What do you think?

Best regards,
Codrin

#37 lore raw

PATCH v2 7/11 drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953

Hi Codrin,

Quoted 61 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 59 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Wednesday, July 01, 2015 1:50 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 07/11 v2] drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953

Hi Codrin,

Quoted 10 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 8 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:39 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 07/11 v2] drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953

Quoted 23 lines
Quoted 3 lines
Quoted 1 line

+ return !!timeout;

Maybe return -EBUSY like suggested in previous patch.

Ok.

Quoted 17 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1093

Quoted 7 lines
drivers/net/vsc9953.c +7 -0
+       /* write port and vid to get selected FDB entries */
+       val = in_le32(&l2ana_reg->ana.anag_efil);
+       if (port_no != VSC9953_CMD_PORT_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_PORT_MASK) |
+                               CONFIG_VSC9953_AGE_PORT_EN |
+                               field_set(port_no,
+                                         CONFIG_VSC9953_AGE_PORT_MASK);

Seems like a good place to use bitfield_replace() from include/bitfield.h (or a new one that you add that uses the mask for the shift).

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+       }
+       if (vid != VSC9953_CMD_VLAN_ALL) {
+               val = (val & ~CONFIG_VSC9953_AGE_VID_MASK) |
+                               CONFIG_VSC9953_AGE_VID_EN |
+                               field_set(vid,

CONFIG_VSC9953_AGE_VID_MASK);

Quoted 13 lines
Quoted 2 lines

Same here.

Ok.

Quoted 6 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1139

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+               vlan = field_get(val & CONFIG_VSC9953_MAC_VID_MASK,
+                                CONFIG_VSC9953_MAC_VID_MASK);

It seems like masking off the val before shifting it would be better implemented inside the field_get function (renamed and moved to include/bitfield.h) instead of on each use.

Yes, something like #define field_set(val, mask) (((val) * ((mask) &

Quoted 8 lines
Quoted 6 lines

~((mask) << 1))) & mask) and

Quoted 1 line

#define field_get(val, mask) ((val & mask) / ((mask) & ~((mask) <<

1))).

The set seems the same as replace, just without any other bitfields to preserve. You could just use replace and pass in 0 as the reg_val.

Yes, although I still have to pass the "shift" parameter.

Not if you use the new bitfield_replace_by_mask().

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1181

Quoted 5 lines
drivers/net/vsc9953.c +4 -0
+       out_le32(&l2ana_reg->ana_tables.mach_data,
+                (mac[0] << 8) | (mac[1] << 0) |
+                (field_set(vid, CONFIG_VSC9953_MACHDATA_VID_MASK) &
+                                CONFIG_VSC9953_MACHDATA_VID_MASK));

Why do you need to & with the mask again after field_set()?

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

To assure that the shifted vid value is not higher than its mask. Adding the

mask to the macro/inline function as described above should assure this.

OK. Maybe the existing bitfield_replace() should be updated to also mask off the bitfield_val.

Yes, I think it should be updated. Should I make a separate patch for it? It should be out of this patch set since it has nothing to do with VSC9953.

Definitely a separate patch.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+       /* check if MAC address is present */
+       if (!parsed_cmd->mac_addr) {

Use this:
+ if (is_valid_ethaddr(parsed_cmd->mac_addr)) {

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

is_valid_ethaddr() returns false if the mac address is 00:00:00:00:00:00, but

for the L2 Switch, this mac address is valid. Maybe is_broadcast_ethaddr()?

I'm not sure what criteria you intend to check for here, so I'm not sure if that is appropriate.

When a command for adding/removing a mac address is issued, we should check if there is a valid mac address in parsed_cmd->mac_addr. I guess that this could be checked only in keyword_match_mac_addr(). Also, since mac_addr will become a static array, I should initialize this array with an invalid mac address. Since 0 mac address is a valid address for the L2 Switch, I was thinking to initialize it with L2 Broadcast address. What do you think?

Sounds good.

Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+       /* check if MAC address is present */
+       if (!parsed_cmd->mac_addr) {

Use this:
+ if (is_valid_ethaddr(parsed_cmd->mac_addr)) {

Same as above.

Quoted 29 lines
Quoted 13 lines
drivers/net/vsc9953.c +13 -0
+/* check if the string has the format for a MAC address */
+static int string_is_mac_addr(const char *mac)
+{
+       int                     i;
+
+       if (!mac)
+               return 0;
+
+       for (i = 0; i < 6; i++) {
+               if (!isxdigit(*mac) || !isxdigit(*(mac + 1)))
+                       return 0;
+               mac += 2;
+               if (i != 5) {

drivers/net/vsc9953.c static int keyword_match_port(enum keyword_id key_id, int argc, · line 1921

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                       if (*mac != ':' && *mac != '-')
+                               return 0;
+                       mac++;
+               }
+       }
+
+       if (*mac != '\0')
+               return 0;
+
+       return 1;

This functionality is already implemented in common/env_flags.c in the _env_flags_validate_type() function. Maybe that implementation should be extracted. Another option is to make the eth_parse_enetaddr() in net/eth.c return a status and then it can be used. Either way I don't think it should be re-implemented here.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Yes, I noticed that this function is already implemented, but with no access

to it. I will see how I can use the one available.

Which path do you plan to take?

I looked through both eth_parse_enetaddr() and _env_flags_validate_type() and I prefer the implementation from the latter function, since eth_parse_enetaddr() doesn't check for ':' or if the value returned by simple_strtoul() is <= 0xFF. I could move the code from "case env_flags_vartype_macaddr:" to a separate function (something like eth_check_enetaddr()? ) and add its prototype somewhere in include/net.h. What do you think?

I think it should be called eth_validate_ethaddr_str(). You can add it to include/net.h and the top of net/eth.c

Cheers,
-Joe

#38 lore raw

PATCH v2 8/11 drivers/net/vsc9953: Add VLAN commands for VSC9953

In reply to Codrin Ciubotariu

The new added commands can be used to configure VLANs for a port on both ingress and egress.

The new commands are:
ethsw [port <port_no>] pvid { [help] | show | <pvid> }
- set/show PVID (ingress and egress VLAN tagging) for a port;
ethsw [port <port_no>] vlan { [help] | show | add <vid> | del <vid> }
- add a VLAN to a port (VLAN members);
ethsw [port <port_no>] untagged { [help] | show | all | none | pvid }
- set egress tagging mod for a port"
ethsw [port <port_no>] egress tag { [help] | show | pvid | classified }
- Configure VID source for egress tag. Tag's VID could be the frame's classified VID or the PVID of the port

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 678 +++++++++++++++++++++++++++++++++++++++++++++++++-
 include/vsc9953.h     |   3 +
 2 files changed, 680 insertions(+), 1 deletion(-)
drivers/net/vsc9953.c +677 -1
index ef7b50c..b78a941 100644
@@ -270,6 +270,31 @@ static void vsc9953_port_vlan_pvid_set(int port_no, int pvid)
 			field_set(pvid, CONFIG_VSC9953_PORT_VLAN_CFG_VID_MASK));
 }
 
+#ifdef CONFIG_VSC9953_CMD
+/* Set PVID for a VSC9953 port */
+static int vsc9953_port_vlan_pvid_get(int port_nr, int *pvid)
+{
+	u32			val;
+	struct vsc9953_analyzer	*l2ana_reg;
+
+	/* Administrative down */
+	if ((!vsc9953_l2sw.port[port_nr].enabled)) {
+		printf("Port %d is administrative down\n", port_nr);
+		return -1;
+	}
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+				VSC9953_ANA_OFFSET);
+
+	/* Get ingress PVID */
+	val = in_le32(&l2ana_reg->port[port_nr].vlan_cfg);
+	*pvid = field_get(val & CONFIG_VSC9953_VLAN_CFG_VID_MASK,
+			  CONFIG_VSC9953_VLAN_CFG_VID_MASK);
+
+	return 0;
+}
+#endif
+
 static void vsc9953_port_all_vlan_pvid_set(int pvid)
 {
 	int		i;
@@ -407,6 +432,75 @@ static void vsc9953_port_vlan_egr_untag_set(int port_no,
 	}
 }
 
+#ifdef CONFIG_VSC9953_CMD
+/* Get egress tagging configuration for a VSC9953 port */
+static int vsc9953_port_vlan_egr_untag_get(int port_no,
+					   enum egress_untag_mode *mode)
+{
+	u32			val;
+	struct vsc9953_rew_reg	*l2rew_reg;
+
+	/* Administrative down */
+	if ((!vsc9953_l2sw.port[port_no].enabled)) {
+		printf("Port %d is administrative down\n", port_no);
+		return -1;
+	}
+
+	l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
+			VSC9953_REW_OFFSET);
+
+	val = in_le32(&l2rew_reg->port[port_no].port_tag_cfg);
+
+	switch (val & CONFIG_VSC9953_TAG_CFG_MASK) {
+	case CONFIG_VSC9953_TAG_CFG_NONE:
+		*mode = EGRESS_UNTAG_ALL;
+		return 0;
+	case CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO:
+		*mode = EGRESS_UNTAG_PVID_AND_ZERO;
+		return 0;
+	case CONFIG_VSC9953_TAG_CFG_ALL_ZERO:
+		*mode = EGRESS_UNTAG_ZERO;
+		return 0;
+	case CONFIG_VSC9953_TAG_CFG_ALL:
+		*mode = EGRESS_UNTAG_NONE;
+		return 0;
+	default:
+		printf("Unknown egress tagging configuration for port %d\n",
+		       port_no);
+		return -1;
+	}
+}
+
+/* Shiw egress tagging configuration for a VSC9953 port */
+static void vsc9953_port_vlan_egr_untag_show(int port_no)
+{
+	enum egress_untag_mode mode;
+
+	if (vsc9953_port_vlan_egr_untag_get(port_no, &mode)) {
+		printf("%7d\t%17s\n", port_no, "-");
+		return;
+	}
+
+	printf("%7d\t", port_no);
+	switch (mode) {
+	case EGRESS_UNTAG_ALL:
+		printf("%17s\n", "none");
+		break;
+	case EGRESS_UNTAG_NONE:
+		printf("%17s\n", "all");
+		break;
+	case EGRESS_UNTAG_PVID_AND_ZERO:
+		printf("%17s\n", "all but PVID and 0");
+		break;
+	case EGRESS_UNTAG_ZERO:
+		printf("%17s\n", "all but 0");
+		break;
+	default:
+		printf("%17s\n", "-");
+	}
+}
+#endif
+
 static void vsc9953_port_all_vlan_egress_untagged_set(
 		enum egress_untag_mode mode)
 {
@@ -954,6 +1048,102 @@ static void vsc9953_port_statistics_clear(int port_no)
 		 CONFIG_VSC9953_STAT_CLEAR_DR);
 }
 
+/* Add/remove a port to/from a VLAN */
+static void vsc9953_vlan_table_membership_set(int vid, u32 port_no, u8 add)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	if (!vsc9953_vlan_table_poll_idle()) {
+		debug("VLAN table timeout\n");
+		return;
+	}
+
+	clrsetbits_le32(&l2ana_reg->ana_tables.vlan_tidx,
+			CONFIG_VSC9953_ANA_TBL_VID_MASK,
+			field_set(vid, CONFIG_VSC9953_ANA_TBL_VID_MASK));
+	clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+			CONFIG_VSC9953_VLAN_CMD_MASK,
+			field_set(CONFIG_VSC9953_VLAN_CMD_READ,
+				  CONFIG_VSC9953_VLAN_CMD_MASK));
+
+	if (!vsc9953_vlan_table_poll_idle()) {
+		debug("VLAN table timeout\n");
+		return;
+	}
+
+	clrsetbits_le32(&l2ana_reg->ana_tables.vlan_tidx,
+			CONFIG_VSC9953_ANA_TBL_VID_MASK,
+			field_set(vid, CONFIG_VSC9953_ANA_TBL_VID_MASK));
+
+	if (!add) {
+		clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+				CONFIG_VSC9953_VLAN_CMD_MASK |
+				(field_set((1 << port_no),
+					   CONFIG_VSC9953_VLAN_PORT_MASK) &
+				CONFIG_VSC9953_VLAN_PORT_MASK),
+				field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+					  CONFIG_VSC9953_VLAN_CMD_MASK));
+	} else {
+		clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+				CONFIG_VSC9953_VLAN_CMD_MASK,
+				field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+					  CONFIG_VSC9953_VLAN_CMD_MASK) |
+				(field_set((1 << port_no),
+					   CONFIG_VSC9953_VLAN_PORT_MASK) &
+				 CONFIG_VSC9953_VLAN_PORT_MASK));
+	}
+
+	/* wait for VLAN table command to flush */
+	if (!vsc9953_vlan_table_poll_idle()) {
+		debug("VLAN table timeout\n");
+		return;
+	}
+}
+
+/* show VLAN membership for a port */
+static void vsc9953_vlan_membership_show(int port_no)
+{
+	u32				val;
+	struct vsc9953_analyzer		*l2ana_reg;
+	u32				vid;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	printf("Port %d VLAN membership: ", port_no);
+
+	for (vid = 0; vid < VSC9953_MAX_VLAN; vid++) {
+		if (!vsc9953_vlan_table_poll_idle()) {
+			debug("VLAN table timeout\n");
+			return;
+		}
+
+		clrsetbits_le32(&l2ana_reg->ana_tables.vlan_tidx,
+				CONFIG_VSC9953_ANA_TBL_VID_MASK,
+				field_set(vid,
+					  CONFIG_VSC9953_ANA_TBL_VID_MASK));
+		clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+				CONFIG_VSC9953_VLAN_CMD_MASK,
+				field_set(CONFIG_VSC9953_VLAN_CMD_READ,
+					  CONFIG_VSC9953_VLAN_CMD_MASK));
+
+		if (!vsc9953_vlan_table_poll_idle()) {
+			debug("VLAN table timeout\n");
+			return;
+		}
+
+		val = in_le32(&l2ana_reg->ana_tables.vlan_access);
+
+		if (!!(val & (field_set((1 << port_no),
+					CONFIG_VSC9953_VLAN_PORT_MASK))))
+			printf("%d ", vid);
+	}
+	printf("\n");
+}
+
 /* wait for FDB to become available */
 static int vsc9953_mac_table_poll_idle(void)
 {
@@ -965,7 +1155,7 @@ static int vsc9953_mac_table_poll_idle(void)
 
 	timeout = 50000;
 	while (((in_le32(&l2ana_reg->ana_tables.mac_access) &
-			CONFIG_VSC9953_MAC_CMD_MASK) !=
+		 CONFIG_VSC9953_MAC_CMD_MASK) !=
 		 CONFIG_VSC9953_MAC_CMD_IDLE) && --timeout)
 		udelay(1);
 
@@ -1313,6 +1503,51 @@ static void vsc9953_mac_table_flush(int port, int vid)
 	vsc9953_mac_table_age(port, vid);
 }
 
+enum egress_vlan_tag {
+	EGR_TAG_CLASS = 0,
+	EGR_TAG_PVID,
+};
+
+/* Set egress tag mode for a VSC9953 port */
+static void vsc9953_port_vlan_egress_tag_set(int port_no,
+					     enum egress_vlan_tag mode)
+{
+	struct vsc9953_rew_reg		*l2rew_reg;
+
+	l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
+			VSC9953_REW_OFFSET);
+
+	switch (mode) {
+	case EGR_TAG_CLASS:
+		clrbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+			     CONFIG_VSC9953_TAG_VID_PVID);
+		break;
+	case EGR_TAG_PVID:
+		setbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+			     CONFIG_VSC9953_TAG_VID_PVID);
+		break;
+	default:
+		printf("Unknown egress VLAN tag mode for port %d\n", port_no);
+	}
+}
+
+/* Get egress tag mode for a VSC9953 port */
+static void vsc9953_port_vlan_egress_tag_get(int port_no,
+					     enum egress_vlan_tag *mode)
+{
+	u32				val;
+	struct vsc9953_rew_reg		*l2rew_reg;
+
+	l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
+			VSC9953_REW_OFFSET);
+
+	val = in_le32(&l2rew_reg->port[port_no].port_tag_cfg);
+	if (val & CONFIG_VSC9953_TAG_VID_PVID)
+		*mode = EGR_TAG_PVID;
+	else
+		*mode = EGR_TAG_CLASS;
+}
+
 /* IDs used to track keywords in a command */
 enum keyword_id {
 	id_key_end = -1,
@@ -1330,12 +1565,20 @@ enum keyword_id {
 	id_add,
 	id_del,
 	id_flush,
+	id_pvid,
+	id_untagged,
+	id_all,
+	id_none,
+	id_egress,
+	id_tag,
+	id_classified,
 	id_count,	/* keep last */
 };
 
 enum keyword_opt_id {
 	id_port_no = id_count + 1,
 	id_vlan_no,
+	id_pvid_no,
 	id_add_del_no,
 	id_add_del_mac,
 	id_count_all,	/* keep last */
@@ -1520,6 +1763,241 @@ static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd)
 	return 0;
 }
 
+#define VSC9953_PVID_HELP "ethsw [port <port_no>] " \
+"pvid { [help] | show | <pvid> } " \
+"- set/show PVID (ingress and egress VLAN tagging) for a port"
+
+static int vsc9953_pvid_help_key_func(struct command_def *parsed_cmd)
+{
+	printf(VSC9953_PVID_HELP"\n");
+
+	return 0;
+}
+
+static int vsc9953_pvid_show_key_func(struct command_def *parsed_cmd)
+{
+	int			i, pvid;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		if (vsc9953_port_vlan_pvid_get(parsed_cmd->port, &pvid))
+			return -1;
+		printf("%7s %7s\n", "Port", "PVID");
+		printf("%7d %7d\n", parsed_cmd->port, pvid);
+	} else {
+		printf("%7s %7s\n", "Port", "PVID");
+		for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+			if (vsc9953_port_vlan_pvid_get(i, &pvid))
+				continue;
+			printf("%7d %7d\n", i, pvid);
+		}
+	}
+
+	return 0;
+}
+
+static int vsc9953_pvid_set_key_func(struct command_def *parsed_cmd)
+{
+	/* PVID number should be set in parsed_cmd->vid */
+	if (parsed_cmd->vid == VSC9953_CMD_VLAN_ALL) {
+		printf("Please set a vlan value\n");
+		return -1;
+	}
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL)
+		vsc9953_port_vlan_pvid_set(parsed_cmd->port, parsed_cmd->vid);
+	else
+		vsc9953_port_all_vlan_pvid_set(parsed_cmd->vid);
+
+	return 0;
+}
+
+#define VSC9953_VLAN_HELP "ethsw [port <port_no>] vlan " \
+"{ [help] | show | add <vid> | del <vid> } " \
+"- add a VLAN to a port (VLAN members)"
+
+static int vsc9953_vlan_help_key_func(struct command_def *parsed_cmd)
+{
+	printf(VSC9953_VLAN_HELP"\n");
+
+	return 0;
+}
+
+static int vsc9953_vlan_show_key_func(struct command_def *parsed_cmd)
+{
+	int			i;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_vlan_membership_show(parsed_cmd->port);
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_vlan_membership_show(i);
+	}
+
+	return 0;
+}
+
+static int vsc9953_vlan_set_key_func(struct command_def *parsed_cmd)
+{
+	int			i, add;
+
+	/* VLAN should be set in parsed_cmd->vid */
+	if (parsed_cmd->vid == VSC9953_CMD_VLAN_ALL) {
+		printf("Please set a vlan value\n");
+		return -1;
+	}
+
+	/* keywords add/delete should be the last but one in array */
+	if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 2] ==
+	    id_add)
+		add = 1;
+	else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 2] ==
+		 id_del)
+		add = 0;
+	else
+		return -1;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_vlan_table_membership_set(parsed_cmd->vid,
+						  parsed_cmd->port, add);
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_vlan_table_membership_set(parsed_cmd->vid, i,
+							  add);
+	}
+
+	return 0;
+}
+
+#define VSC9953_PORT_UNTAG_HELP "ethsw [port <port_no>] untagged " \
+"{ [help] | show | all | none | pvid } " \
+" - set egress tagging mod for a port"
+
+static int vsc9953_port_untag_help_key_func(struct command_def *parsed_cmd)
+{
+	printf(VSC9953_PORT_UNTAG_HELP"\n");
+
+	return 0;
+}
+
+static int vsc9953_port_untag_show_key_func(struct command_def *parsed_cmd)
+{
+	int				i;
+
+	printf("%7s\t%17s\n", "Port", "Egress VLAN tag");
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_port_vlan_egr_untag_show(parsed_cmd->port);
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_port_vlan_egr_untag_show(i);
+	}
+
+	return 0;
+}
+
+static int vsc9953_port_untag_set_key_func(struct command_def *parsed_cmd)
+{
+	int				i;
+	enum egress_untag_mode		mode;
+
+	/* keywords for the untagged mode are the last in the array */
+	if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+	    id_all)
+		mode = EGRESS_UNTAG_ALL;
+	else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+		 id_none)
+		mode = EGRESS_UNTAG_NONE;
+	else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+		 id_pvid)
+		mode = EGRESS_UNTAG_PVID_AND_ZERO;
+	else
+		return -1;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_port_vlan_egr_untag_set(parsed_cmd->port, mode);
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_port_vlan_egr_untag_set(i, mode);
+	}
+
+	return 0;
+}
+
+#define VSC9953_EGR_VLAN_TAG_HELP "ethsw [port <port_no>] egress tag " \
+"{ [help] | show | pvid | classified } " \
+"- Configure VID source for egress tag. " \
+"Tag's VID could be the frame's classified VID or the PVID of the port"
+
+static int vsc9953_egr_tag_help_key_func(struct command_def *parsed_cmd)
+{
+	printf(VSC9953_EGR_VLAN_TAG_HELP"\n");
+
+	return 0;
+}
+
+static int vsc9953_egr_vlan_tag_show_key_func(struct command_def *parsed_cmd)
+{
+	int				i;
+	enum egress_vlan_tag	mode;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_port_vlan_egress_tag_get(parsed_cmd->port, &mode);
+		printf("%7s\t%12s\n", "Port", "Egress VID");
+		printf("%7d\t", parsed_cmd->port);
+		switch (mode) {
+		case EGR_TAG_CLASS:
+			printf("%12s\n", "classified");
+			break;
+		case EGR_TAG_PVID:
+			printf("%12s\n", "pvid");
+			break;
+		default:
+			printf("%12s\n", "-");
+		}
+	} else {
+		printf("%7s\t%12s\n", "Port", "Egress VID");
+		for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+			vsc9953_port_vlan_egress_tag_get(i, &mode);
+			switch (mode) {
+			case EGR_TAG_CLASS:
+				printf("%7d\t%12s\n", i, "classified");
+				break;
+			case EGR_TAG_PVID:
+				printf("%7d\t%12s\n", i, "pvid");
+				break;
+			default:
+				printf("%7d\t%12s\n", i, "-");
+			}
+		}
+	}
+
+	return 0;
+}
+
+static int vsc9953_egr_vlan_tag_set_key_func(struct command_def *parsed_cmd)
+{
+	int				i;
+	enum egress_vlan_tag	mode;
+
+	/* keywords for the egress vlan tag mode are the last in the array */
+	if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+	    id_pvid)
+		mode = EGR_TAG_PVID;
+	else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+		 id_classified)
+		mode = EGR_TAG_CLASS;
+	else
+		return -1;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_port_vlan_egress_tag_set(parsed_cmd->port, mode);
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_port_vlan_egress_tag_set(i, mode);
+	}
+
+	return 0;
+}
+
 #define VSC9953_FDB_HELP "ethsw [port <port_no>] [vlan <vid>] fdb " \
 "{ [help] | show | flush | { add | del } <mac> } " \
 "- Add/delete a mac entry in FDB; use show to see FDB entries; " \
@@ -1669,6 +2147,149 @@ struct keywords_to_function {
 			.keyword_function = &vsc9953_learn_set_key_func,
 		}, {
 			.cmd_keyword = {
+					id_pvid,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_pvid_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_pvid,
+					id_help,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_pvid_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_pvid,
+					id_show,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_pvid_show_key_func,
+		}, {
+			.cmd_keyword = {
+					id_pvid,
+					id_pvid_no,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_pvid_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_vlan,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_vlan_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_vlan,
+					id_help,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_vlan_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_vlan,
+					id_show,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_vlan_show_key_func,
+		}, {
+			.cmd_keyword = {
+					id_vlan,
+					id_add,
+					id_add_del_no,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_vlan_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_vlan,
+					id_del,
+					id_add_del_no,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_vlan_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_untagged,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_port_untag_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_untagged,
+					id_help,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_port_untag_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_untagged,
+					id_show,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_port_untag_show_key_func,
+		}, {
+			.cmd_keyword = {
+					id_untagged,
+					id_all,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_port_untag_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_untagged,
+					id_none,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_port_untag_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_untagged,
+					id_pvid,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_port_untag_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_egress,
+					id_tag,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_egr_tag_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_egress,
+					id_tag,
+					id_help,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_egr_tag_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_egress,
+					id_tag,
+					id_show,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_egr_vlan_tag_show_key_func,
+		}, {
+			.cmd_keyword = {
+					id_egress,
+					id_tag,
+					id_pvid,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_egr_vlan_tag_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_egress,
+					id_tag,
+					id_classified,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_egr_vlan_tag_set_key_func,
+		}, {
+			.cmd_keyword = {
 					id_fdb,
 					id_key_end,
 			},
@@ -1748,6 +2369,9 @@ static int keyword_match_port(enum keyword_id key_id, int argc,
 static int keyword_match_vlan(enum keyword_id key_id, int argc,
 			      char *const argv[], int *argc_nr,
 			      struct command_def *parsed_cmd);
+static int keyword_match_pvid(enum keyword_id key_id, int argc,
+			      char *const argv[], int *argc_nr,
+			      struct command_def *parsed_cmd);
 static int keyword_match_mac_addr(enum keyword_id key_id, int argc,
 				  char *const argv[], int *argc_nr,
 				  struct command_def *parsed_cmd);
@@ -1802,6 +2426,27 @@ struct keyword_def {
 		}, {
 				.keyword_name = "flush",
 				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "pvid",
+				.match = &keyword_match_pvid,
+		}, {
+				.keyword_name = "untagged",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "all",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "none",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "egress",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "tag",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "classified",
+				.match = &keyword_match_gen,
 		},
 };
 
@@ -1896,6 +2541,33 @@ static int keyword_match_vlan(enum keyword_id key_id, int argc,
 	return 0;
 }
 
+/* Function used to match the command's pvid */
+static int keyword_match_pvid(enum keyword_id key_id, int argc,
+			      char *const argv[], int *argc_nr,
+			      struct command_def *parsed_cmd)
+{
+	unsigned long			val;
+
+	if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
+		return 0;
+
+	if (*argc_nr + 1 >= argc)
+		return 1;
+
+	if (strict_strtoul(argv[*argc_nr + 1], 10, &val) != -EINVAL) {
+		if (!VSC9953_VLAN_CHECK(val)) {
+			printf("Invalid pvid number: %lu\n", val);
+			return 0;
+		}
+		parsed_cmd->vid = val;
+		(*argc_nr)++;
+		parsed_cmd->cmd_to_keywords[*argc_nr] = id_pvid_no;
+		return 1;
+	}
+
+	return 1;
+}
+
 /* check if the string has the format for a MAC address */
 static int string_is_mac_addr(const char *mac)
 {
@@ -2094,6 +2766,10 @@ U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
 	   VSC9953_PORT_STATS_HELP"\n"
 	   VSC9953_LEARN_HELP"\n"
 	   VSC9953_FDB_HELP"\n"
+	   VSC9953_VLAN_HELP"\n"
+	   VSC9953_PVID_HELP"\n"
+	   VSC9953_PORT_UNTAG_HELP"\n"
+	   VSC9953_EGR_VLAN_TAG_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
include/vsc9953.h +3 -0
index 051c24e..6eb22a9 100644
@@ -115,6 +115,8 @@
 /* Macros for vsc9953_ana_port.vlan_cfg register */
 #define CONFIG_VSC9953_VLAN_CFG_AWARE_ENA		0x00100000
 #define CONFIG_VSC9953_VLAN_CFG_POP_CNT_MASK		0x000c0000
+#define CONFIG_VSC9953_VLAN_CFG_POP_CNT_NONE		0x00000000
+#define CONFIG_VSC9953_VLAN_CFG_POP_CNT_ONE		0x00040000
 #define CONFIG_VSC9953_VLAN_CFG_VID_MASK		0x00000fff
 
 /* Macros for vsc9953_rew_port.port_vlan_cfg register */
@@ -149,6 +151,7 @@
 #define CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO	0x00000080
 #define CONFIG_VSC9953_TAG_CFG_ALL_ZERO		0x00000100
 #define CONFIG_VSC9953_TAG_CFG_ALL	0x00000180
+#define CONFIG_VSC9953_TAG_VID_PVID	0x00000010
 
 /* Macros for vsc9953_ana_ana.anag_efil register */
 #define CONFIG_VSC9953_AGE_PORT_EN	0x00080000
Signature · 1 line
1.9.3
#39 lore raw

PATCH v2 8/11 drivers/net/vsc9953: Add VLAN commands for VSC9953

Hi Codrin,

Quoted 29 lines · Codrin Ciubotariu

The new added commands can be used to configure VLANs for a port on both ingress and egress.

The new commands are:
ethsw [port <port_no>] pvid { [help] | show | <pvid> }
- set/show PVID (ingress and egress VLAN tagging) for a port;
ethsw [port <port_no>] vlan { [help] | show | add <vid> | del <vid> }
- add a VLAN to a port (VLAN members);
ethsw [port <port_no>] untagged { [help] | show | all | none | pvid }
- set egress tagging mod for a port"
ethsw [port <port_no>] egress tag { [help] | show | pvid | classified }
- Configure VID source for egress tag. Tag's VID could be the frame's classified VID or the PVID of the port

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 678 +++++++++++++++++++++++++++++++++++++++++++++++++-
 include/vsc9953.h     |   3 +
 2 files changed, 680 insertions(+), 1 deletion(-)
drivers/net/vsc9953.c +0 -0
index ef7b50c..b78a941 100644

drivers/net/vsc9953.c static void vsc9953_port_vlan_pvid_set(int port_no, int pvid) · line 273

Quoted 4 lines
drivers/net/vsc9953.c +1 -0
@@ -270,6 +270,31 @@ static void vsc9953_port_vlan_pvid_set(int port_no, int pvid)
                        field_set(pvid, CONFIG_VSC9953_PORT_VLAN_CFG_VID_MASK));
 }
 
+#ifdef CONFIG_VSC9953_CMD

Why does this need to be defined outside of the #ifdef already at the bottom of the file?

drivers/net/vsc9953.c static void vsc9953_port_vlan_pvid_set(int port_no, int pvid) · line 277

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+/* Set PVID for a VSC9953 port */
+static int vsc9953_port_vlan_pvid_get(int port_nr, int *pvid)
+{
+       u32                     val;

Use a single space.

drivers/net/vsc9953.c static void vsc9953_port_vlan_pvid_set(int port_no, int pvid) · line 281

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+       struct vsc9953_analyzer *l2ana_reg;
+
+       /* Administrative down */
+       if ((!vsc9953_l2sw.port[port_nr].enabled)) {

Why do you have double "((" and "))"?

Quoted 20 lines
drivers/net/vsc9953.c +16 -0
+               printf("Port %d is administrative down\n", port_nr);
+               return -1;
+       }
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                               VSC9953_ANA_OFFSET);
+
+       /* Get ingress PVID */
+       val = in_le32(&l2ana_reg->port[port_nr].vlan_cfg);
+       *pvid = field_get(val & CONFIG_VSC9953_VLAN_CFG_VID_MASK,
+                         CONFIG_VSC9953_VLAN_CFG_VID_MASK);
+
+       return 0;
+}
+#endif
+
 static void vsc9953_port_all_vlan_pvid_set(int pvid)
 {
        int             i;

drivers/net/vsc9953.c static void vsc9953_port_vlan_egr_untag_set(int port_no, · line 435

Quoted 4 lines
drivers/net/vsc9953.c +1 -0
@@ -407,6 +432,75 @@ static void vsc9953_port_vlan_egr_untag_set(int port_no,
        }
 }
 
+#ifdef CONFIG_VSC9953_CMD

Why does this need to be defined outside of the #ifdef already at the bottom of the file?

drivers/net/vsc9953.c static void vsc9953_port_vlan_egr_untag_set(int port_no, · line 444

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+/* Get egress tagging configuration for a VSC9953 port */
+static int vsc9953_port_vlan_egr_untag_get(int port_no,
+                                          enum egress_untag_mode *mode)
+{
+       u32                     val;
+       struct vsc9953_rew_reg  *l2rew_reg;
+
+       /* Administrative down */
+       if ((!vsc9953_l2sw.port[port_no].enabled)) {

Why do you have double "((" and "))"?

Quoted 20 lines
drivers/net/vsc9953.c +20 -0
+               printf("Port %d is administrative down\n", port_no);
+               return -1;
+       }
+
+       l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
+                       VSC9953_REW_OFFSET);
+
+       val = in_le32(&l2rew_reg->port[port_no].port_tag_cfg);
+
+       switch (val & CONFIG_VSC9953_TAG_CFG_MASK) {
+       case CONFIG_VSC9953_TAG_CFG_NONE:
+               *mode = EGRESS_UNTAG_ALL;
+               return 0;
+       case CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO:
+               *mode = EGRESS_UNTAG_PVID_AND_ZERO;
+               return 0;
+       case CONFIG_VSC9953_TAG_CFG_ALL_ZERO:
+               *mode = EGRESS_UNTAG_ZERO;
+               return 0;
+       case CONFIG_VSC9953_TAG_CFG_ALL:

drivers/net/vsc9953.c static void vsc9953_port_vlan_egr_untag_set(int port_no, · line 474

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+               *mode = EGRESS_UNTAG_NONE;
+               return 0;
+       default:
+               printf("Unknown egress tagging configuration for port %d\n",
+                      port_no);
+               return -1;
+       }
+}
+
+/* Shiw egress tagging configuration for a VSC9953 port */

Shiw -> Show

Quoted 117 lines
drivers/net/vsc9953.c +110 -0
+static void vsc9953_port_vlan_egr_untag_show(int port_no)
+{
+       enum egress_untag_mode mode;
+
+       if (vsc9953_port_vlan_egr_untag_get(port_no, &mode)) {
+               printf("%7d\t%17s\n", port_no, "-");
+               return;
+       }
+
+       printf("%7d\t", port_no);
+       switch (mode) {
+       case EGRESS_UNTAG_ALL:
+               printf("%17s\n", "none");
+               break;
+       case EGRESS_UNTAG_NONE:
+               printf("%17s\n", "all");
+               break;
+       case EGRESS_UNTAG_PVID_AND_ZERO:
+               printf("%17s\n", "all but PVID and 0");
+               break;
+       case EGRESS_UNTAG_ZERO:
+               printf("%17s\n", "all but 0");
+               break;
+       default:
+               printf("%17s\n", "-");
+       }
+}
+#endif
+
 static void vsc9953_port_all_vlan_egress_untagged_set(
                enum egress_untag_mode mode)
 {
@@ -954,6 +1048,102 @@ static void vsc9953_port_statistics_clear(int port_no)
                 CONFIG_VSC9953_STAT_CLEAR_DR);
 }
 
+/* Add/remove a port to/from a VLAN */
+static void vsc9953_vlan_table_membership_set(int vid, u32 port_no, u8 add)
+{
+       struct vsc9953_analyzer         *l2ana_reg;
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       if (!vsc9953_vlan_table_poll_idle()) {
+               debug("VLAN table timeout\n");
+               return;
+       }
+
+       clrsetbits_le32(&l2ana_reg->ana_tables.vlan_tidx,
+                       CONFIG_VSC9953_ANA_TBL_VID_MASK,
+                       field_set(vid, CONFIG_VSC9953_ANA_TBL_VID_MASK));
+       clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                       CONFIG_VSC9953_VLAN_CMD_MASK,
+                       field_set(CONFIG_VSC9953_VLAN_CMD_READ,
+                                 CONFIG_VSC9953_VLAN_CMD_MASK));
+
+       if (!vsc9953_vlan_table_poll_idle()) {
+               debug("VLAN table timeout\n");
+               return;
+       }
+
+       clrsetbits_le32(&l2ana_reg->ana_tables.vlan_tidx,
+                       CONFIG_VSC9953_ANA_TBL_VID_MASK,
+                       field_set(vid, CONFIG_VSC9953_ANA_TBL_VID_MASK));
+
+       if (!add) {
+               clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                               CONFIG_VSC9953_VLAN_CMD_MASK |
+                               (field_set((1 << port_no),
+                                          CONFIG_VSC9953_VLAN_PORT_MASK) &
+                               CONFIG_VSC9953_VLAN_PORT_MASK),
+                               field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+                                         CONFIG_VSC9953_VLAN_CMD_MASK));
+       } else {
+               clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                               CONFIG_VSC9953_VLAN_CMD_MASK,
+                               field_set(CONFIG_VSC9953_VLAN_CMD_WRITE,
+                                         CONFIG_VSC9953_VLAN_CMD_MASK) |
+                               (field_set((1 << port_no),
+                                          CONFIG_VSC9953_VLAN_PORT_MASK) &
+                                CONFIG_VSC9953_VLAN_PORT_MASK));
+       }
+
+       /* wait for VLAN table command to flush */
+       if (!vsc9953_vlan_table_poll_idle()) {
+               debug("VLAN table timeout\n");
+               return;
+       }
+}
+
+/* show VLAN membership for a port */
+static void vsc9953_vlan_membership_show(int port_no)
+{
+       u32                             val;
+       struct vsc9953_analyzer         *l2ana_reg;
+       u32                             vid;
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       printf("Port %d VLAN membership: ", port_no);
+
+       for (vid = 0; vid < VSC9953_MAX_VLAN; vid++) {
+               if (!vsc9953_vlan_table_poll_idle()) {
+                       debug("VLAN table timeout\n");
+                       return;
+               }
+
+               clrsetbits_le32(&l2ana_reg->ana_tables.vlan_tidx,
+                               CONFIG_VSC9953_ANA_TBL_VID_MASK,
+                               field_set(vid,
+                                         CONFIG_VSC9953_ANA_TBL_VID_MASK));
+               clrsetbits_le32(&l2ana_reg->ana_tables.vlan_access,
+                               CONFIG_VSC9953_VLAN_CMD_MASK,
+                               field_set(CONFIG_VSC9953_VLAN_CMD_READ,
+                                         CONFIG_VSC9953_VLAN_CMD_MASK));

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1141

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+
+               if (!vsc9953_vlan_table_poll_idle()) {
+                       debug("VLAN table timeout\n");
+                       return;
+               }
+
+               val = in_le32(&l2ana_reg->ana_tables.vlan_access);
+
+               if (!!(val & (field_set((1 << port_no),
+                                       CONFIG_VSC9953_VLAN_PORT_MASK))))

There is no need for "!!" in an if statement. Drop it and the extra parenthesis.

Quoted 21 lines
drivers/net/vsc9953.c +6 -1
+                       printf("%d ", vid);
+       }
+       printf("\n");
+}
+
 /* wait for FDB to become available */
 static int vsc9953_mac_table_poll_idle(void)
 {
@@ -965,7 +1155,7 @@ static int vsc9953_mac_table_poll_idle(void)
 
        timeout = 50000;
        while (((in_le32(&l2ana_reg->ana_tables.mac_access) &
-                       CONFIG_VSC9953_MAC_CMD_MASK) !=
+                CONFIG_VSC9953_MAC_CMD_MASK) !=
                 CONFIG_VSC9953_MAC_CMD_IDLE) && --timeout)
                udelay(1);
 
@@ -1313,6 +1503,51 @@ static void vsc9953_mac_table_flush(int port, int vid)
        vsc9953_mac_table_age(port, vid);
 }
 

drivers/net/vsc9953.c static void vsc9953_mac_table_flush(int port, int vid) · line 1515

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+enum egress_vlan_tag {
+       EGR_TAG_CLASS = 0,
+       EGR_TAG_PVID,
+};
+
+/* Set egress tag mode for a VSC9953 port */
+static void vsc9953_port_vlan_egress_tag_set(int port_no,
+                                            enum egress_vlan_tag mode)
+{
+       struct vsc9953_rew_reg          *l2rew_reg;

Use a single space.

Quoted 62 lines
drivers/net/vsc9953.c +43 -0
+
+       l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
+                       VSC9953_REW_OFFSET);
+
+       switch (mode) {
+       case EGR_TAG_CLASS:
+               clrbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                            CONFIG_VSC9953_TAG_VID_PVID);
+               break;
+       case EGR_TAG_PVID:
+               setbits_le32(&l2rew_reg->port[port_no].port_tag_cfg,
+                            CONFIG_VSC9953_TAG_VID_PVID);
+               break;
+       default:
+               printf("Unknown egress VLAN tag mode for port %d\n", port_no);
+       }
+}
+
+/* Get egress tag mode for a VSC9953 port */
+static void vsc9953_port_vlan_egress_tag_get(int port_no,
+                                            enum egress_vlan_tag *mode)
+{
+       u32                             val;
+       struct vsc9953_rew_reg          *l2rew_reg;
+
+       l2rew_reg = (struct vsc9953_rew_reg *)(VSC9953_OFFSET +
+                       VSC9953_REW_OFFSET);
+
+       val = in_le32(&l2rew_reg->port[port_no].port_tag_cfg);
+       if (val & CONFIG_VSC9953_TAG_VID_PVID)
+               *mode = EGR_TAG_PVID;
+       else
+               *mode = EGR_TAG_CLASS;
+}
+
 /* IDs used to track keywords in a command */
 enum keyword_id {
        id_key_end = -1,
@@ -1330,12 +1565,20 @@ enum keyword_id {
        id_add,
        id_del,
        id_flush,
+       id_pvid,
+       id_untagged,
+       id_all,
+       id_none,
+       id_egress,
+       id_tag,
+       id_classified,
        id_count,       /* keep last */
 };
 
 enum keyword_opt_id {
        id_port_no = id_count + 1,
        id_vlan_no,
+       id_pvid_no,
        id_add_del_no,
        id_add_del_mac,
        id_count_all,   /* keep last */
@@ -1520,6 +1763,241 @@ static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd)
        return 0;
 }

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1774

Quoted 10 lines
drivers/net/vsc9953.c +9 -0
 
+#define VSC9953_PVID_HELP "ethsw [port <port_no>] " \
+"pvid { [help] | show | <pvid> } " \
+"- set/show PVID (ingress and egress VLAN tagging) for a port"
+
+static int vsc9953_pvid_help_key_func(struct command_def *parsed_cmd)
+{
+       printf(VSC9953_PVID_HELP"\n");
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1783

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+}
+
+static int vsc9953_pvid_show_key_func(struct command_def *parsed_cmd)
+{
+       int                     i, pvid;
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               if (vsc9953_port_vlan_pvid_get(parsed_cmd->port, &pvid))
+                       return -1;

Please use:
+ return CMD_RET_FAILURE;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1795

Quoted 12 lines
drivers/net/vsc9953.c +12 -0
+               printf("%7s %7s\n", "Port", "PVID");
+               printf("%7d %7d\n", parsed_cmd->port, pvid);
+       } else {
+               printf("%7s %7s\n", "Port", "PVID");
+               for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+                       if (vsc9953_port_vlan_pvid_get(i, &pvid))
+                               continue;
+                       printf("%7d %7d\n", i, pvid);
+               }
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1803

Quoted 8 lines
drivers/net/vsc9953.c +8 -0
+}
+
+static int vsc9953_pvid_set_key_func(struct command_def *parsed_cmd)
+{
+       /* PVID number should be set in parsed_cmd->vid */
+       if (parsed_cmd->vid == VSC9953_CMD_VLAN_ALL) {
+               printf("Please set a vlan value\n");
+               return -1;

Please use:
+ return CMD_RET_USAGE;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1811

Quoted 8 lines
drivers/net/vsc9953.c +8 -0
+       }
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL)
+               vsc9953_port_vlan_pvid_set(parsed_cmd->port, parsed_cmd->vid);
+       else
+               vsc9953_port_all_vlan_pvid_set(parsed_cmd->vid);
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1822

Quoted 11 lines
drivers/net/vsc9953.c +11 -0
+}
+
+#define VSC9953_VLAN_HELP "ethsw [port <port_no>] vlan " \
+"{ [help] | show | add <vid> | del <vid> } " \
+"- add a VLAN to a port (VLAN members)"
+
+static int vsc9953_vlan_help_key_func(struct command_def *parsed_cmd)
+{
+       printf(VSC9953_VLAN_HELP"\n");
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1827

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+}
+
+static int vsc9953_vlan_show_key_func(struct command_def *parsed_cmd)
+{
+       int                     i;

Use a single space.

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1836

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               vsc9953_vlan_membership_show(parsed_cmd->port);
+       } else {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++)
+                       vsc9953_vlan_membership_show(i);
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1846

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+}
+
+static int vsc9953_vlan_set_key_func(struct command_def *parsed_cmd)
+{
+       int                     i, add;
+
+       /* VLAN should be set in parsed_cmd->vid */
+       if (parsed_cmd->vid == VSC9953_CMD_VLAN_ALL) {
+               printf("Please set a vlan value\n");
+               return -1;

Please use:
+ return CMD_RET_USAGE;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1857

Quoted 11 lines
drivers/net/vsc9953.c +11 -0
+       }
+
+       /* keywords add/delete should be the last but one in array */
+       if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 2] ==
+           id_add)
+               add = 1;
+       else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 2] ==
+                id_del)
+               add = 0;
+       else
+               return -1;

Please use:
+ return CMD_RET_USAGE;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1868

Quoted 11 lines
drivers/net/vsc9953.c +11 -0
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               vsc9953_vlan_table_membership_set(parsed_cmd->vid,
+                                                 parsed_cmd->port, add);
+       } else {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++)
+                       vsc9953_vlan_table_membership_set(parsed_cmd->vid, i,
+                                                         add);
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1879

Quoted 11 lines
drivers/net/vsc9953.c +11 -0
+}
+
+#define VSC9953_PORT_UNTAG_HELP "ethsw [port <port_no>] untagged " \
+"{ [help] | show | all | none | pvid } " \
+" - set egress tagging mod for a port"
+
+static int vsc9953_port_untag_help_key_func(struct command_def *parsed_cmd)
+{
+       printf(VSC9953_PORT_UNTAG_HELP"\n");
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1884

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+}
+
+static int vsc9953_port_untag_show_key_func(struct command_def *parsed_cmd)
+{
+       int                             i;

Use a single space.

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1894

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+
+       printf("%7s\t%17s\n", "Port", "Egress VLAN tag");
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               vsc9953_port_vlan_egr_untag_show(parsed_cmd->port);
+       } else {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++)
+                       vsc9953_port_vlan_egr_untag_show(i);
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1900

Quoted 6 lines
drivers/net/vsc9953.c +6 -0
+}
+
+static int vsc9953_port_untag_set_key_func(struct command_def *parsed_cmd)
+{
+       int                             i;
+       enum egress_untag_mode          mode;

Use a single space.

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1913

Quoted 13 lines
drivers/net/vsc9953.c +13 -0
+
+       /* keywords for the untagged mode are the last in the array */
+       if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+           id_all)
+               mode = EGRESS_UNTAG_ALL;
+       else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+                id_none)
+               mode = EGRESS_UNTAG_NONE;
+       else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+                id_pvid)
+               mode = EGRESS_UNTAG_PVID_AND_ZERO;
+       else
+               return -1;

Please use:
+ return CMD_RET_USAGE;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1922

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               vsc9953_port_vlan_egr_untag_set(parsed_cmd->port, mode);
+       } else {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++)
+                       vsc9953_port_vlan_egr_untag_set(i, mode);
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1934

Quoted 12 lines
drivers/net/vsc9953.c +12 -0
+}
+
+#define VSC9953_EGR_VLAN_TAG_HELP "ethsw [port <port_no>] egress tag " \
+"{ [help] | show | pvid | classified } " \
+"- Configure VID source for egress tag. " \
+"Tag's VID could be the frame's classified VID or the PVID of the port"
+
+static int vsc9953_egr_tag_help_key_func(struct command_def *parsed_cmd)
+{
+       printf(VSC9953_EGR_VLAN_TAG_HELP"\n");
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 29 lines
drivers/net/vsc9953.c +29 -0
+}
+
+static int vsc9953_egr_vlan_tag_show_key_func(struct command_def *parsed_cmd)
+{
+       int                             i;
+       enum egress_vlan_tag    mode;
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               vsc9953_port_vlan_egress_tag_get(parsed_cmd->port, &mode);
+               printf("%7s\t%12s\n", "Port", "Egress VID");
+               printf("%7d\t", parsed_cmd->port);
+               switch (mode) {
+               case EGR_TAG_CLASS:
+                       printf("%12s\n", "classified");
+                       break;
+               case EGR_TAG_PVID:
+                       printf("%12s\n", "pvid");
+                       break;
+               default:
+                       printf("%12s\n", "-");
+               }
+       } else {
+               printf("%7s\t%12s\n", "Port", "Egress VID");
+               for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+                       vsc9953_port_vlan_egress_tag_get(i, &mode);
+                       switch (mode) {
+                       case EGR_TAG_CLASS:
+                               printf("%7d\t%12s\n", i, "classified");
+                               break;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1973

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                       case EGR_TAG_PVID:
+                               printf("%7d\t%12s\n", i, "pvid");
+                               break;
+                       default:
+                               printf("%7d\t%12s\n", i, "-");
+                       }
+               }
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 6 lines
drivers/net/vsc9953.c +6 -0
+}
+
+static int vsc9953_egr_vlan_tag_set_key_func(struct command_def *parsed_cmd)
+{
+       int                             i;
+       enum egress_vlan_tag    mode;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1989

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+
+       /* keywords for the egress vlan tag mode are the last in the array */
+       if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+           id_pvid)
+               mode = EGR_TAG_PVID;
+       else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+                id_classified)
+               mode = EGR_TAG_CLASS;
+       else
+               return -1;

Please use:
+ return CMD_RET_USAGE;

drivers/net/vsc9953.c static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd) · line 1998

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               vsc9953_port_vlan_egress_tag_set(parsed_cmd->port, mode);
+       } else {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++)
+                       vsc9953_port_vlan_egress_tag_set(i, mode);
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 266 lines
drivers/net/vsc9953.c +200 -0
+}
+
 #define VSC9953_FDB_HELP "ethsw [port <port_no>] [vlan <vid>] fdb " \
 "{ [help] | show | flush | { add | del } <mac> } " \
 "- Add/delete a mac entry in FDB; use show to see FDB entries; " \
@@ -1669,6 +2147,149 @@ struct keywords_to_function {
                        .keyword_function = &vsc9953_learn_set_key_func,
                }, {
                        .cmd_keyword = {
+                                       id_pvid,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_pvid_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_pvid,
+                                       id_help,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_pvid_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_pvid,
+                                       id_show,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_pvid_show_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_pvid,
+                                       id_pvid_no,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_pvid_set_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_vlan,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_vlan_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_vlan,
+                                       id_help,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_vlan_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_vlan,
+                                       id_show,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_vlan_show_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_vlan,
+                                       id_add,
+                                       id_add_del_no,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_vlan_set_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_vlan,
+                                       id_del,
+                                       id_add_del_no,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_vlan_set_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_untagged,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_port_untag_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_untagged,
+                                       id_help,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_port_untag_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_untagged,
+                                       id_show,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_port_untag_show_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_untagged,
+                                       id_all,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_port_untag_set_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_untagged,
+                                       id_none,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_port_untag_set_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_untagged,
+                                       id_pvid,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_port_untag_set_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_egress,
+                                       id_tag,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_egr_tag_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_egress,
+                                       id_tag,
+                                       id_help,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_egr_tag_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_egress,
+                                       id_tag,
+                                       id_show,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_egr_vlan_tag_show_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_egress,
+                                       id_tag,
+                                       id_pvid,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_egr_vlan_tag_set_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_egress,
+                                       id_tag,
+                                       id_classified,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_egr_vlan_tag_set_key_func,
+               }, {
+                       .cmd_keyword = {
                                        id_fdb,
                                        id_key_end,
                        },
@@ -1748,6 +2369,9 @@ static int keyword_match_port(enum keyword_id key_id, int argc,
 static int keyword_match_vlan(enum keyword_id key_id, int argc,
                              char *const argv[], int *argc_nr,
                              struct command_def *parsed_cmd);
+static int keyword_match_pvid(enum keyword_id key_id, int argc,
+                             char *const argv[], int *argc_nr,
+                             struct command_def *parsed_cmd);
 static int keyword_match_mac_addr(enum keyword_id key_id, int argc,
                                  char *const argv[], int *argc_nr,
                                  struct command_def *parsed_cmd);
@@ -1802,6 +2426,27 @@ struct keyword_def {
                }, {
                                .keyword_name = "flush",
                                .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "pvid",
+                               .match = &keyword_match_pvid,
+               }, {
+                               .keyword_name = "untagged",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "all",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "none",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "egress",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "tag",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "classified",
+                               .match = &keyword_match_gen,
                },
 };
 
@@ -1896,6 +2541,33 @@ static int keyword_match_vlan(enum keyword_id key_id, int argc,
        return 0;
 }
 
+/* Function used to match the command's pvid */
+static int keyword_match_pvid(enum keyword_id key_id, int argc,
+                             char *const argv[], int *argc_nr,
+                             struct command_def *parsed_cmd)
+{
+       unsigned long                   val;
+
+       if (!keyword_match_gen(key_id, argc, argv, argc_nr, parsed_cmd))
+               return 0;
+
+       if (*argc_nr + 1 >= argc)
+               return 1;
+
+       if (strict_strtoul(argv[*argc_nr + 1], 10, &val) != -EINVAL) {
+               if (!VSC9953_VLAN_CHECK(val)) {
+                       printf("Invalid pvid number: %lu\n", val);
+                       return 0;
+               }
+               parsed_cmd->vid = val;
+               (*argc_nr)++;
+               parsed_cmd->cmd_to_keywords[*argc_nr] = id_pvid_no;
+               return 1;
+       }
+
+       return 1;
+}
+
 /* check if the string has the format for a MAC address */
 static int string_is_mac_addr(const char *mac)
 {
@@ -2094,6 +2766,10 @@ U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
           VSC9953_PORT_STATS_HELP"\n"
           VSC9953_LEARN_HELP"\n"
           VSC9953_FDB_HELP"\n"
+          VSC9953_VLAN_HELP"\n"
+          VSC9953_PVID_HELP"\n"
+          VSC9953_PORT_UNTAG_HELP"\n"
+          VSC9953_EGR_VLAN_TAG_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
include/vsc9953.h +3 -1
index 051c24e..6eb22a9 100644
@@ -115,6 +115,8 @@
 /* Macros for vsc9953_ana_port.vlan_cfg register */
 #define CONFIG_VSC9953_VLAN_CFG_AWARE_ENA              0x00100000
 #define CONFIG_VSC9953_VLAN_CFG_POP_CNT_MASK           0x000c0000
+#define CONFIG_VSC9953_VLAN_CFG_POP_CNT_NONE           0x00000000
+#define CONFIG_VSC9953_VLAN_CFG_POP_CNT_ONE            0x00040000
 #define CONFIG_VSC9953_VLAN_CFG_VID_MASK               0x00000fff
 
 /* Macros for vsc9953_rew_port.port_vlan_cfg register */
@@ -149,6 +151,7 @@
 #define CONFIG_VSC9953_TAG_CFG_ALL_PVID_ZERO   0x00000080
 #define CONFIG_VSC9953_TAG_CFG_ALL_ZERO                0x00000100
 #define CONFIG_VSC9953_TAG_CFG_ALL     0x00000180
+#define CONFIG_VSC9953_TAG_VID_PVID    0x00000010
 
 /* Macros for vsc9953_ana_ana.anag_efil register */
 #define CONFIG_VSC9953_AGE_PORT_EN     0x00080000
--

1.9.3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#40 lore raw

PATCH v2 8/11 drivers/net/vsc9953: Add VLAN commands for VSC9953

Hi Joe,

Quoted 10 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:41 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 08/11 v2] drivers/net/vsc9953: Add VLAN commands for VSC9953

Review static void vsc9953_port_vlan_pvid_set(int port_no, int

Quoted 1 line
(quoted diff) +0 -0
@@ -270,6 +270,31 @@ static void vsc9953_port_vlan_pvid_set(int port_no, int

pvid)

Quoted 8 lines

Review static void vsc9953_port_vlan_pvid_set(int port_no, int · line 270

Quoted 1 line
(quoted diff) +0 -0
                        field_set(pvid,

CONFIG_VSC9953_PORT_VLAN_CFG_VID_MASK));

drivers/net/vsc9953.c static void vsc9953_port_vlan_pvid_set(int port_no, int pvid) · line 273

Quoted 3 lines
drivers/net/vsc9953.c +1 -0
 }
 
+#ifdef CONFIG_VSC9953_CMD

Why does this need to be defined outside of the #ifdef already at the bottom of the file?

I added it here so that vsc9953_port_vlan_pvid_get() could be next to its pair, vsc9953_port_vlan_pvid_set(). If you think that it should be at the bottom of the file I can move it.

Quoted 4 lines

drivers/net/vsc9953.c static void vsc9953_port_vlan_pvid_set(int port_no, int pvid) · line 281

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+       /* Administrative down */
+       if ((!vsc9953_l2sw.port[port_nr].enabled)) {

Why do you have double "((" and "))"?

By mistake, I will remove one pair.

Quoted 4 lines

Review static void vsc9953_port_vlan_pvid_set(int port_no, int · line 276

Quoted 1 line
(quoted diff) +1 -0
+#ifdef CONFIG_VSC9953_CMD

Why does this need to be defined outside of the #ifdef already at the bottom of the file?

I did this so that similar get/set() functions to be close to one another. Also, the functions guarded by CONFIG_VSC9953_CMD are used only when the ethsw commands are enabled (CONFIG_VSC9953_CMD defined). If a user decides to use the driver for VSC9953, with the switch working in unmanaged state and he doesn't need the commands to configure the switch, he could compile u-boot with CONFIG_VSC9953_CMD undefined. In this case, some warnings will appear at compile time suggesting that functions like vsc9953_port_vlan_egr_untag_get() are defined but not used.

Quoted 4 lines

drivers/net/vsc9953.c static void vsc9953_port_vlan_egr_untag_set(int port_no, · line 444

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+       /* Administrative down */
+       if ((!vsc9953_l2sw.port[port_no].enabled)) {

Why do you have double "((" and "))"?

By mistake, I will remove one pair.

Quoted 3 lines

drivers/net/vsc9953.c static void vsc9953_port_vlan_egr_untag_set(int port_no, · line 474

Quoted 1 line
drivers/net/vsc9953.c +1 -0
+/* Shiw egress tagging configuration for a VSC9953 port */

Shiw -> Show

Yes, it's a typo.

Quoted 4 lines

drivers/net/vsc9953.c static void vsc9953_port_statistics_clear(int port_no) · line 1141

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+               if (!!(val & (field_set((1 << port_no),
+                                       CONFIG_VSC9953_VLAN_PORT_MASK))))

There is no need for "!!" in an if statement. Drop it and the extra parenthesis.

Ok.

Thanks and best regards,
Codrin

#41 lore raw

PATCH v2 8/11 drivers/net/vsc9953: Add VLAN commands for VSC9953

Hi Codrin,

Quoted 14 lines · Codrin Constantin Ciubotariu

Hi Joe,

Quoted 12 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:41 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 08/11 v2] drivers/net/vsc9953: Add VLAN commands for VSC9953

Review static void vsc9953_port_vlan_pvid_set(int port_no, int

Quoted 1 line
(quoted diff) +0 -0
@@ -270,6 +270,31 @@ static void vsc9953_port_vlan_pvid_set(int port_no, int

pvid)

Review static void vsc9953_port_vlan_pvid_set(int port_no, int · line 270

Quoted 1 line
(quoted diff) +0 -0
                        field_set(pvid,

CONFIG_VSC9953_PORT_VLAN_CFG_VID_MASK));

Quoted 8 lines
Quoted 6 lines

drivers/net/vsc9953.c static void vsc9953_port_vlan_pvid_set(int port_no, int pvid) · line 273

Quoted 3 lines
drivers/net/vsc9953.c +1 -0
 }
 
+#ifdef CONFIG_VSC9953_CMD

Why does this need to be defined outside of the #ifdef already at the bottom of the file?

I added it here so that vsc9953_port_vlan_pvid_get() could be next to its pair, vsc9953_port_vlan_pvid_set(). If you think that it should be at the bottom of the file I can move it.

OK, I think that makes sense the way you had it. Also, it wouldn't make sense to move out of drivers/net/vsc9953.c, so leave it here.

Quoted 5 lines
Quoted 4 lines

drivers/net/vsc9953.c static void vsc9953_port_vlan_pvid_set(int port_no, int pvid) · line 281

Quoted 2 lines
drivers/net/vsc9953.c +2 -0
+       /* Administrative down */
+       if ((!vsc9953_l2sw.port[port_nr].enabled)) {

Why do you have double "((" and "))"?

Quoted 8 lines

By mistake, I will remove one pair.

Quoted 4 lines

Review static void vsc9953_port_vlan_pvid_set(int port_no, int · line 276

Quoted 1 line
(quoted diff) +1 -0
+#ifdef CONFIG_VSC9953_CMD

Why does this need to be defined outside of the #ifdef already at the bottom of the file?

I did this so that similar get/set() functions to be close to one another. Also, the functions guarded by CONFIG_VSC9953_CMD are used only when the ethsw commands are enabled (CONFIG_VSC9953_CMD defined). If a user decides to use the driver for VSC9953, with the switch working in unmanaged state and he doesn't need the commands to configure the switch, he could compile u-boot with CONFIG_VSC9953_CMD undefined. In this case, some warnings will appear at compile time suggesting that functions like vsc9953_port_vlan_egr_untag_get() are defined but not used.

Sounds good. You can leave this here.

Thanks,
-Joe

#42 lore raw

PATCH v2 9/11 drivers/net/vsc9953: Add command for shared/private VLAN learning

In reply to Codrin Ciubotariu

The command:
ethsw vlan fdb { [help] | show | shared | private }
- make VLAN learning shared or private"

configures the FDB to share the FDB entries learned on multiple VLANs or to keep them separated. By default, the FBD uses private VLAN learning.

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/vsc9953.h     |   3 +
 2 files changed, 158 insertions(+)
drivers/net/vsc9953.c +155 -0
index b78a941..3129b03 100644
@@ -1503,6 +1503,58 @@ static void vsc9953_mac_table_flush(int port, int vid)
 	vsc9953_mac_table_age(port, vid);
 }
 
+/* VSC9953 VLAN learning modes */
+enum vlan_learning_mode {
+	SHARED_VLAN_LEARNING,
+	PRIVATE_VLAN_LEARNING,
+};
+
+/* Set VLAN learning mode for VSC9953 */
+static void vsc9953_vlan_learning_set(enum vlan_learning_mode lrn_mode)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	switch (lrn_mode) {
+	case SHARED_VLAN_LEARNING:
+		setbits_le32(&l2ana_reg->ana.agen_ctrl,
+			     CONFIG_VSC9953_FID_MASK_ALL);
+		break;
+	case PRIVATE_VLAN_LEARNING:
+		clrbits_le32(&l2ana_reg->ana.agen_ctrl,
+			     CONFIG_VSC9953_FID_MASK_ALL);
+		break;
+	default:
+		printf("Unknown VLAN learn mode\n");
+	}
+}
+
+/* Get VLAN learning mode for VSC9953 */
+static int vsc9953_vlan_learning_get(enum vlan_learning_mode *lrn_mode)
+{
+	u32				val;
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	val = in_le32(&l2ana_reg->ana.agen_ctrl);
+
+	if (!(val & CONFIG_VSC9953_FID_MASK_ALL)) {
+		*lrn_mode = PRIVATE_VLAN_LEARNING;
+	} else if ((val & CONFIG_VSC9953_FID_MASK_ALL) ==
+			CONFIG_VSC9953_FID_MASK_ALL) {
+		*lrn_mode = SHARED_VLAN_LEARNING;
+	} else {
+		printf("Unknown VLAN learning mode\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 enum egress_vlan_tag {
 	EGR_TAG_CLASS = 0,
 	EGR_TAG_PVID,
@@ -1572,6 +1624,8 @@ enum keyword_id {
 	id_egress,
 	id_tag,
 	id_classified,
+	id_shared,
+	id_private,
 	id_count,	/* keep last */
 };
 
@@ -1868,6 +1922,61 @@ static int vsc9953_vlan_set_key_func(struct command_def *parsed_cmd)
 	return 0;
 }
 
+#define VSC9953_VLAN_FDB_HELP "ethsw vlan fdb " \
+"{ [help] | show | shared | private } " \
+"- make VLAN learning shared or private"
+
+static int vsc9953_vlan_learn_help_key_func(struct command_def *parsed_cmd)
+{
+	printf(VSC9953_VLAN_FDB_HELP"\n");
+
+	return 0;
+}
+
+static int vsc9953_vlan_learn_show_key_func(struct command_def *parsed_cmd)
+{
+	int				rc;
+	enum vlan_learning_mode		mode;
+
+	rc = vsc9953_vlan_learning_get(&mode);
+	if (rc)
+		goto __out_return;
+
+	switch (mode) {
+	case SHARED_VLAN_LEARNING:
+		printf("VLAN learning mode: shared\n");
+		break;
+	case PRIVATE_VLAN_LEARNING:
+		printf("VLAN learning mode: private\n");
+		break;
+	default:
+		printf("Unknown VLAN learning mode\n");
+		rc = -EINVAL;
+	}
+
+__out_return:
+	return rc;
+}
+
+static int vsc9953_vlan_learn_set_key_func(struct command_def *parsed_cmd)
+{
+	enum vlan_learning_mode		mode;
+
+	/* keywords for shared/private are the last in the array */
+	if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+	    id_shared)
+		mode = SHARED_VLAN_LEARNING;
+	else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+		 id_private)
+		mode = PRIVATE_VLAN_LEARNING;
+	else
+		return -1;
+
+	vsc9953_vlan_learning_set(mode);
+
+	return 0;
+}
+
 #define VSC9953_PORT_UNTAG_HELP "ethsw [port <port_no>] untagged " \
 "{ [help] | show | all | none | pvid } " \
 " - set egress tagging mod for a port"
@@ -2331,6 +2440,45 @@ struct keywords_to_function {
 					id_key_end,
 			},
 			.keyword_function = &vsc9953_fdb_entry_del_key_func,
+		}, {
+			.cmd_keyword = {
+					id_vlan,
+					id_fdb,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_vlan_learn_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_vlan,
+					id_fdb,
+					id_help,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_vlan_learn_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_vlan,
+					id_fdb,
+					id_show,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_vlan_learn_show_key_func,
+		}, {
+			.cmd_keyword = {
+					id_vlan,
+					id_fdb,
+					id_shared,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_vlan_learn_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_vlan,
+					id_fdb,
+					id_private,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_vlan_learn_set_key_func,
 		},
 };
 
@@ -2447,6 +2595,12 @@ struct keyword_def {
 		}, {
 				.keyword_name = "classified",
 				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "shared",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "private",
+				.match = &keyword_match_gen,
 		},
 };
 
@@ -2770,6 +2924,7 @@ U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
 	   VSC9953_PVID_HELP"\n"
 	   VSC9953_PORT_UNTAG_HELP"\n"
 	   VSC9953_EGR_VLAN_TAG_HELP"\n"
+	   VSC9953_VLAN_FDB_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
include/vsc9953.h +3 -0
index 6eb22a9..26a08aa 100644
@@ -142,6 +142,9 @@
 /* Macros for vsc9953_qsys_sys.switch_port_mode register */
 #define CONFIG_VSC9953_PORT_ENA		0x00002000
 
+/* Macros for vsc9953_ana_ana.agen_ctrl register */
+#define CONFIG_VSC9953_FID_MASK_ALL	0x00fff000
+
 /* Macros for vsc9953_ana_ana.adv_learn register */
 #define CONFIG_VSC9953_VLAN_CHK		0x00000400
 
Signature · 1 line
1.9.3
#43 lore raw

PATCH v2 9/11 drivers/net/vsc9953: Add command for shared/private VLAN learning

Hi Codrin,

Quoted 26 lines · Codrin Ciubotariu

The command:
ethsw vlan fdb { [help] | show | shared | private }
- make VLAN learning shared or private"

configures the FDB to share the FDB entries learned on multiple VLANs or to keep them separated. By default, the FBD uses private VLAN learning.

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/vsc9953.h     |   3 +
 2 files changed, 158 insertions(+)
drivers/net/vsc9953.c +0 -0
index b78a941..3129b03 100644
@@ -1503,6 +1503,58 @@ static void vsc9953_mac_table_flush(int port, int vid)
        vsc9953_mac_table_age(port, vid);
 }
 

drivers/net/vsc9953.c static void vsc9953_mac_table_flush(int port, int vid) · line 1515

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+/* VSC9953 VLAN learning modes */
+enum vlan_learning_mode {
+       SHARED_VLAN_LEARNING,
+       PRIVATE_VLAN_LEARNING,
+};
+
+/* Set VLAN learning mode for VSC9953 */
+static void vsc9953_vlan_learning_set(enum vlan_learning_mode lrn_mode)
+{
+       struct vsc9953_analyzer         *l2ana_reg;

Use a single space.

Quoted 27 lines
drivers/net/vsc9953.c +27 -0
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+
+       switch (lrn_mode) {
+       case SHARED_VLAN_LEARNING:
+               setbits_le32(&l2ana_reg->ana.agen_ctrl,
+                            CONFIG_VSC9953_FID_MASK_ALL);
+               break;
+       case PRIVATE_VLAN_LEARNING:
+               clrbits_le32(&l2ana_reg->ana.agen_ctrl,
+                            CONFIG_VSC9953_FID_MASK_ALL);
+               break;
+       default:
+               printf("Unknown VLAN learn mode\n");
+       }
+}
+
+/* Get VLAN learning mode for VSC9953 */
+static int vsc9953_vlan_learning_get(enum vlan_learning_mode *lrn_mode)
+{
+       u32                             val;
+       struct vsc9953_analyzer         *l2ana_reg;
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                       VSC9953_ANA_OFFSET);
+

drivers/net/vsc9953.c static void vsc9953_mac_table_flush(int port, int vid) · line 1552

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       val = in_le32(&l2ana_reg->ana.agen_ctrl);
+
+       if (!(val & CONFIG_VSC9953_FID_MASK_ALL)) {
+               *lrn_mode = PRIVATE_VLAN_LEARNING;
+       } else if ((val & CONFIG_VSC9953_FID_MASK_ALL) ==
+                       CONFIG_VSC9953_FID_MASK_ALL) {
+               *lrn_mode = SHARED_VLAN_LEARNING;
+       } else {
+               printf("Unknown VLAN learning mode\n");
+               return -EINVAL;

Please use:
+ return CMD_RET_FAILURE;

drivers/net/vsc9953.c static void vsc9953_mac_table_flush(int port, int vid) · line 1555

Quoted 3 lines
drivers/net/vsc9953.c +3 -0
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 17 lines
drivers/net/vsc9953.c +4 -0
+}
+
 enum egress_vlan_tag {
        EGR_TAG_CLASS = 0,
        EGR_TAG_PVID,
@@ -1572,6 +1624,8 @@ enum keyword_id {
        id_egress,
        id_tag,
        id_classified,
+       id_shared,
+       id_private,
        id_count,       /* keep last */
 };
 
@@ -1868,6 +1922,61 @@ static int vsc9953_vlan_set_key_func(struct command_def *parsed_cmd)
        return 0;
 }

drivers/net/vsc9953.c static int vsc9953_vlan_set_key_func(struct command_def *parsed_cmd) · line 1933

Quoted 10 lines
drivers/net/vsc9953.c +9 -0
 
+#define VSC9953_VLAN_FDB_HELP "ethsw vlan fdb " \
+"{ [help] | show | shared | private } " \
+"- make VLAN learning shared or private"
+
+static int vsc9953_vlan_learn_help_key_func(struct command_def *parsed_cmd)
+{
+       printf(VSC9953_VLAN_FDB_HELP"\n");
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 11 lines
drivers/net/vsc9953.c +11 -0
+}
+
+static int vsc9953_vlan_learn_show_key_func(struct command_def *parsed_cmd)
+{
+       int                             rc;
+       enum vlan_learning_mode         mode;
+
+       rc = vsc9953_vlan_learning_get(&mode);
+       if (rc)
+               goto __out_return;
+

drivers/net/vsc9953.c static int vsc9953_vlan_set_key_func(struct command_def *parsed_cmd) · line 1954

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       switch (mode) {
+       case SHARED_VLAN_LEARNING:
+               printf("VLAN learning mode: shared\n");
+               break;
+       case PRIVATE_VLAN_LEARNING:
+               printf("VLAN learning mode: private\n");
+               break;
+       default:
+               printf("Unknown VLAN learning mode\n");
+               rc = -EINVAL;

Please use:
+ rc =CMD_RET_FAILURE;

Quoted 9 lines
drivers/net/vsc9953.c +9 -0
+       }
+
+__out_return:
+       return rc;
+}
+
+static int vsc9953_vlan_learn_set_key_func(struct command_def *parsed_cmd)
+{
+       enum vlan_learning_mode         mode;

drivers/net/vsc9953.c static int vsc9953_vlan_set_key_func(struct command_def *parsed_cmd) · line 1973

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+
+       /* keywords for shared/private are the last in the array */
+       if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+           id_shared)
+               mode = SHARED_VLAN_LEARNING;
+       else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+                id_private)
+               mode = PRIVATE_VLAN_LEARNING;
+       else
+               return -1;

Please use:
+ return CMD_RET_USAGE;

drivers/net/vsc9953.c static int vsc9953_vlan_set_key_func(struct command_def *parsed_cmd) · line 1977

Quoted 4 lines
drivers/net/vsc9953.c +4 -0
+
+       vsc9953_vlan_learning_set(mode);
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 93 lines
drivers/net/vsc9953.c +48 -0
+}
+
 #define VSC9953_PORT_UNTAG_HELP "ethsw [port <port_no>] untagged " \
 "{ [help] | show | all | none | pvid } " \
 " - set egress tagging mod for a port"
@@ -2331,6 +2440,45 @@ struct keywords_to_function {
                                        id_key_end,
                        },
                        .keyword_function = &vsc9953_fdb_entry_del_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_vlan,
+                                       id_fdb,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_vlan_learn_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_vlan,
+                                       id_fdb,
+                                       id_help,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_vlan_learn_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_vlan,
+                                       id_fdb,
+                                       id_show,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_vlan_learn_show_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_vlan,
+                                       id_fdb,
+                                       id_shared,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_vlan_learn_set_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_vlan,
+                                       id_fdb,
+                                       id_private,
+                                       id_key_end,
+                       },
+                       .keyword_function = &vsc9953_vlan_learn_set_key_func,
                },
 };
 
@@ -2447,6 +2595,12 @@ struct keyword_def {
                }, {
                                .keyword_name = "classified",
                                .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "shared",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "private",
+                               .match = &keyword_match_gen,
                },
 };
 
@@ -2770,6 +2924,7 @@ U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
           VSC9953_PVID_HELP"\n"
           VSC9953_PORT_UNTAG_HELP"\n"
           VSC9953_EGR_VLAN_TAG_HELP"\n"
+          VSC9953_VLAN_FDB_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
include/vsc9953.h +3 -1
index 6eb22a9..26a08aa 100644
@@ -142,6 +142,9 @@
 /* Macros for vsc9953_qsys_sys.switch_port_mode register */
 #define CONFIG_VSC9953_PORT_ENA                0x00002000
 
+/* Macros for vsc9953_ana_ana.agen_ctrl register */
+#define CONFIG_VSC9953_FID_MASK_ALL    0x00fff000
+
 /* Macros for vsc9953_ana_ana.adv_learn register */
 #define CONFIG_VSC9953_VLAN_CHK                0x00000400
 
--

1.9.3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#44 lore raw

PATCH v2 9/11 drivers/net/vsc9953: Add command for shared/private VLAN learning

Hi Joe,

I will make a v3 with your suggestions.

Thanks and best regards,
Codrin

Quoted 7 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:41 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 09/11 v2] drivers/net/vsc9953: Add command for shared/private VLAN learning

#45 lore raw

PATCH v2 10/11 drivers/net/vsc9953: Add commands for VLAN ingress filtering

In reply to Codrin Ciubotariu

The command:
ethsw [port <port_no>] ingress filtering

     { [help] | show | enable | disable }

- enable/disable VLAN ingress filtering on port

can be used to enable/disable/show VLAN ingress filtering on a port.

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 137 insertions(+)
drivers/net/vsc9953.c +137 -0
index 3129b03..d5520d9 100644
@@ -1555,6 +1555,33 @@ static int vsc9953_vlan_learning_get(enum vlan_learning_mode *lrn_mode)
 	return 0;
 }
 
+/* Enable/disable VLAN ingress filtering on a VSC9953 port */
+static void vsc9953_port_ingress_filtering_set(int port_no, int enabled)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	if (enabled)
+		setbits_le32(&l2ana_reg->ana.vlan_mask, 1 << port_no);
+	else
+		clrbits_le32(&l2ana_reg->ana.vlan_mask, 1 << port_no);
+}
+
+/* Show VLAN ingress filtering on a VSC9953 port */
+static void vsc9953_port_ingress_filtering_get(int port_no, int *enabled)
+{
+	u32				val;
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+				VSC9953_ANA_OFFSET);
+
+	val = in_le32(&l2ana_reg->ana.vlan_mask);
+	*enabled = !!(val & (1 << port_no));
+}
+
 enum egress_vlan_tag {
 	EGR_TAG_CLASS = 0,
 	EGR_TAG_PVID,
@@ -1626,6 +1653,8 @@ enum keyword_id {
 	id_classified,
 	id_shared,
 	id_private,
+	id_ingress,
+	id_filtering,
 	id_count,	/* keep last */
 };
 
@@ -2031,6 +2060,68 @@ static int vsc9953_port_untag_set_key_func(struct command_def *parsed_cmd)
 	return 0;
 }
 
+#define VSC9953_PORT_INGR_FLTR_HELP "ethsw [port <port_no>] ingress filtering" \
+" { [help] | show | enable | disable } " \
+"- enable/disable VLAN ingress filtering on port"
+
+static int vsc9953_ingr_fltr_help_key_func(struct command_def *parsed_cmd)
+{
+	printf(VSC9953_PORT_INGR_FLTR_HELP"\n");
+
+	return 0;
+}
+
+static int vsc9953_ingr_fltr_show_key_func(struct command_def *parsed_cmd)
+{
+	int			i, enabled;
+
+	printf("%7s\t%18s\n", "Port", "Ingress filtering");
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_port_ingress_filtering_get(parsed_cmd->port, &enabled);
+		printf("%7d\t%18s\n", parsed_cmd->port, enabled ? "enable" :
+								  "disable");
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+			vsc9953_port_ingress_filtering_get(i, &enabled);
+			printf("%7d\t%18s\n", parsed_cmd->port, enabled ?
+								"enable" :
+								"disable");
+		}
+	}
+
+	return 0;
+}
+
+static int vsc9953_ingr_fltr_set_key_func(struct command_def *parsed_cmd)
+{
+	int				i, enable;
+
+	/* keywords for enabling/disabling ingress filtering
+	 * are the last in the array
+	 */
+	if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+	    id_enable)
+		enable = 1;
+	else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+		 id_disable)
+		enable = 0;
+	else
+		return -1;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
+			printf("Invalid port number: %d\n", parsed_cmd->port);
+			return -1;
+		}
+		vsc9953_port_ingress_filtering_set(parsed_cmd->port, enable);
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_port_ingress_filtering_set(i, enable);
+	}
+
+	return 0;
+}
+
 #define VSC9953_EGR_VLAN_TAG_HELP "ethsw [port <port_no>] egress tag " \
 "{ [help] | show | pvid | classified } " \
 "- Configure VID source for egress tag. " \
@@ -2479,6 +2570,45 @@ struct keywords_to_function {
 					id_key_end,
 			},
 			.keyword_function = &vsc9953_vlan_learn_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_ingress,
+					id_filtering,
+					-1,
+			},
+			.keyword_function = &vsc9953_ingr_fltr_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_ingress,
+					id_filtering,
+					id_help,
+					-1,
+			},
+			.keyword_function = &vsc9953_ingr_fltr_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_ingress,
+					id_filtering,
+					id_show,
+					-1,
+			},
+			.keyword_function = &vsc9953_ingr_fltr_show_key_func,
+		}, {
+			.cmd_keyword = {
+					id_ingress,
+					id_filtering,
+					id_enable,
+					-1,
+			},
+			.keyword_function = &vsc9953_ingr_fltr_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_ingress,
+					id_filtering,
+					id_disable,
+					-1,
+			},
+			.keyword_function = &vsc9953_ingr_fltr_set_key_func,
 		},
 };
 
@@ -2601,6 +2731,12 @@ struct keyword_def {
 		}, {
 				.keyword_name = "private",
 				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "ingress",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "filtering",
+				.match = &keyword_match_gen,
 		},
 };
 
@@ -2925,6 +3061,7 @@ U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
 	   VSC9953_PORT_UNTAG_HELP"\n"
 	   VSC9953_EGR_VLAN_TAG_HELP"\n"
 	   VSC9953_VLAN_FDB_HELP"\n"
+	   VSC9953_PORT_INGR_FLTR_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
Signature · 1 line
1.9.3
#46 lore raw

PATCH v2 10/11 drivers/net/vsc9953: Add commands for VLAN ingress filtering

Hi Codrin,

Quoted 30 lines · Codrin Ciubotariu

The command:
ethsw [port <port_no>] ingress filtering

     { [help] | show | enable | disable }

- enable/disable VLAN ingress filtering on port

can be used to enable/disable/show VLAN ingress filtering on a port.

---
Changes for v2:
- removed Change-id field;

 drivers/net/vsc9953.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 137 insertions(+)
drivers/net/vsc9953.c +6 -0
index 3129b03..d5520d9 100644
@@ -1555,6 +1555,33 @@ static int vsc9953_vlan_learning_get(enum vlan_learning_mode *lrn_mode)
        return 0;
 }
 
+/* Enable/disable VLAN ingress filtering on a VSC9953 port */
+static void vsc9953_port_ingress_filtering_set(int port_no, int enabled)
+{
+       struct vsc9953_analyzer         *l2ana_reg;
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +

drivers/net/vsc9953.c static int vsc9953_vlan_learning_get(enum vlan_learning_mode *lrn_mode) · line 1573

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+                       VSC9953_ANA_OFFSET);
+
+       if (enabled)
+               setbits_le32(&l2ana_reg->ana.vlan_mask, 1 << port_no);
+       else
+               clrbits_le32(&l2ana_reg->ana.vlan_mask, 1 << port_no);
+}
+
+/* Show VLAN ingress filtering on a VSC9953 port */
+static void vsc9953_port_ingress_filtering_get(int port_no, int *enabled)

Why not just return the enabled status instead of a pointer?

Quoted 26 lines
drivers/net/vsc9953.c +13 -0
+{
+       u32                             val;
+       struct vsc9953_analyzer         *l2ana_reg;
+
+       l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+                               VSC9953_ANA_OFFSET);
+
+       val = in_le32(&l2ana_reg->ana.vlan_mask);
+       *enabled = !!(val & (1 << port_no));
+}
+
 enum egress_vlan_tag {
        EGR_TAG_CLASS = 0,
        EGR_TAG_PVID,
@@ -1626,6 +1653,8 @@ enum keyword_id {
        id_classified,
        id_shared,
        id_private,
+       id_ingress,
+       id_filtering,
        id_count,       /* keep last */
 };
 
@@ -2031,6 +2060,68 @@ static int vsc9953_port_untag_set_key_func(struct command_def *parsed_cmd)
        return 0;
 }

drivers/net/vsc9953.c static int vsc9953_port_untag_set_key_func(struct command_def *parsed_cmd) · line 2071

Quoted 10 lines
drivers/net/vsc9953.c +9 -0
 
+#define VSC9953_PORT_INGR_FLTR_HELP "ethsw [port <port_no>] ingress filtering" \
+" { [help] | show | enable | disable } " \
+"- enable/disable VLAN ingress filtering on port"
+
+static int vsc9953_ingr_fltr_help_key_func(struct command_def *parsed_cmd)
+{
+       printf(VSC9953_PORT_INGR_FLTR_HELP"\n");
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_port_untag_set_key_func(struct command_def *parsed_cmd) · line 2076

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+}
+
+static int vsc9953_ingr_fltr_show_key_func(struct command_def *parsed_cmd)
+{
+       int                     i, enabled;

Use one space and put each variable on a separate line.

Quoted 6 lines
drivers/net/vsc9953.c +6 -0
+
+       printf("%7s\t%18s\n", "Port", "Ingress filtering");
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               vsc9953_port_ingress_filtering_get(parsed_cmd->port, &enabled);
+               printf("%7d\t%18s\n", parsed_cmd->port, enabled ? "enable" :
+                                                                 "disable");

drivers/net/vsc9953.c static int vsc9953_port_untag_set_key_func(struct command_def *parsed_cmd) · line 2092

Quoted 10 lines
drivers/net/vsc9953.c +10 -0
+       } else {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+                       vsc9953_port_ingress_filtering_get(i, &enabled);
+                       printf("%7d\t%18s\n", parsed_cmd->port, enabled ?
+                                                               "enable" :
+                                                               "disable");
+               }
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

drivers/net/vsc9953.c static int vsc9953_port_untag_set_key_func(struct command_def *parsed_cmd) · line 2097

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+}
+
+static int vsc9953_ingr_fltr_set_key_func(struct command_def *parsed_cmd)
+{
+       int                             i, enable;

Use one space and put each variable on a separate line.

drivers/net/vsc9953.c static int vsc9953_port_untag_set_key_func(struct command_def *parsed_cmd) · line 2109

Quoted 12 lines
drivers/net/vsc9953.c +12 -0
+
+       /* keywords for enabling/disabling ingress filtering
+        * are the last in the array
+        */
+       if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+           id_enable)
+               enable = 1;
+       else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+                id_disable)
+               enable = 0;
+       else
+               return -1;

Please use:
+ return CMD_RET_USAGE;

drivers/net/vsc9953.c static int vsc9953_port_untag_set_key_func(struct command_def *parsed_cmd) · line 2114

Quoted 5 lines
drivers/net/vsc9953.c +5 -0
+
+       if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+               if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
+                       printf("Invalid port number: %d\n", parsed_cmd->port);
+                       return -1;

Please use:
+ return CMD_RET_USAGE;

drivers/net/vsc9953.c static int vsc9953_port_untag_set_key_func(struct command_def *parsed_cmd) · line 2122

Quoted 8 lines
drivers/net/vsc9953.c +8 -0
+               }
+               vsc9953_port_ingress_filtering_set(parsed_cmd->port, enable);
+       } else {
+               for (i = 0; i < VSC9953_MAX_PORTS; i++)
+                       vsc9953_port_ingress_filtering_set(i, enable);
+       }
+
+       return 0;

Please use:
+ return CMD_RET_SUCCESS;

Quoted 6 lines
drivers/net/vsc9953.c +2 -0
+}
+
 #define VSC9953_EGR_VLAN_TAG_HELP "ethsw [port <port_no>] egress tag " \
 "{ [help] | show | pvid | classified } " \
 "- Configure VID source for egress tag. " \

drivers/net/vsc9953.c struct keywords_to_function { · line 2577

Quoted 8 lines
drivers/net/vsc9953.c +5 -0
@@ -2479,6 +2570,45 @@ struct keywords_to_function {
                                        id_key_end,
                        },
                        .keyword_function = &vsc9953_vlan_learn_set_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_ingress,
+                                       id_filtering,
+                                       -1,

id_key_end

drivers/net/vsc9953.c struct keywords_to_function { · line 2585

Quoted 8 lines
drivers/net/vsc9953.c +8 -0
+                       },
+                       .keyword_function = &vsc9953_ingr_fltr_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_ingress,
+                                       id_filtering,
+                                       id_help,
+                                       -1,

id_key_end

drivers/net/vsc9953.c struct keywords_to_function { · line 2593

Quoted 8 lines
drivers/net/vsc9953.c +8 -0
+                       },
+                       .keyword_function = &vsc9953_ingr_fltr_help_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_ingress,
+                                       id_filtering,
+                                       id_show,
+                                       -1,

id_key_end

drivers/net/vsc9953.c struct keywords_to_function { · line 2601

Quoted 8 lines
drivers/net/vsc9953.c +8 -0
+                       },
+                       .keyword_function = &vsc9953_ingr_fltr_show_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_ingress,
+                                       id_filtering,
+                                       id_enable,
+                                       -1,

id_key_end

drivers/net/vsc9953.c struct keywords_to_function { · line 2609

Quoted 8 lines
drivers/net/vsc9953.c +8 -0
+                       },
+                       .keyword_function = &vsc9953_ingr_fltr_set_key_func,
+               }, {
+                       .cmd_keyword = {
+                                       id_ingress,
+                                       id_filtering,
+                                       id_disable,
+                                       -1,

id_key_end

Quoted 33 lines
drivers/net/vsc9953.c +9 -1
+                       },
+                       .keyword_function = &vsc9953_ingr_fltr_set_key_func,
                },
 };
 
@@ -2601,6 +2731,12 @@ struct keyword_def {
                }, {
                                .keyword_name = "private",
                                .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "ingress",
+                               .match = &keyword_match_gen,
+               }, {
+                               .keyword_name = "filtering",
+                               .match = &keyword_match_gen,
                },
 };
 
@@ -2925,6 +3061,7 @@ U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
           VSC9953_PORT_UNTAG_HELP"\n"
           VSC9953_EGR_VLAN_TAG_HELP"\n"
           VSC9953_VLAN_FDB_HELP"\n"
+          VSC9953_PORT_INGR_FLTR_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
--

1.9.3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#47 lore raw

PATCH v2 10/11 drivers/net/vsc9953: Add commands for VLAN ingress filtering

Hi Joe,

I will make a v3 with your suggestions.

Thanks and best regards,
Codrin

Quoted 7 lines

-----Original Message-----
From: Joe Hershberger [mailto:joe.hershberger at gmail.com]
Sent: Friday, June 26, 2015 1:42 AM
To: Ciubotariu Codrin Constantin-B43658
Cc: u-boot; Joe Hershberger; Sun York-R58495
Subject: Re: [U-Boot] [PATCH 10/11 v2] drivers/net/vsc9953: Add commands for VLAN ingress filtering

#48 lore raw

PATCH v2 11/11 drivers/net/vsc9953: Add GPL-2.0+ SPDX-License-Identifier

In reply to Codrin Ciubotariu

---
Changes for v2:
- fixed the Copyright years from 2014-2015 to 2013, 2015;
- removed Change-id field;

 include/vsc9953.h | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
include/vsc9953.h +3 -8
index 26a08aa..c3d5ae4 100644
@@ -1,14 +1,9 @@
 /*
- *  vsc9953.h
+ *  Copyright 2013, 2015 Freescale Semiconductor, Inc.
  *
- *  Driver for the Vitesse VSC9953 L2 Switch
- *
- *  This software may be used and distributed according to the
- *  terms of the GNU Public License, Version 2, incorporated
- *  herein by reference.
- *
- * Copyright 2013, 2015 Freescale Semiconductor, Inc.
+ *  SPDX-License-Identifier:      GPL-2.0+
  *
+ *  Driver for the Vitesse VSC9953 L2 Switch
  */
 
 #ifndef _VSC9953_H_
Signature · 1 line
1.9.3