Skip to contentSkip to conversation

net: phy: Add Broadcom BCM53xx switch driver

PATCH New Florian Fainelli 3 participants 16 messages Oct 15, 2017 – Dec 5, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover net: phy: Add Broadcom BCM53xx switch driver

(this time after subscribing to the list)

Hi all,

This patch series adds support for the Broadcom BCM53xx switches, in particular BCM53125 which is found no the Lamobo R1 board.

The driver is largely based on the DSA/b53 driver Linux driver and only incorporates what is necessary to succesfully bring-up all ports (including the management port) for boot over the network:

=> dhcp
dw_adjust_link: Speed: 1000, full duplex
BOOTP broadcast 1
DHCP client bound to address 192.168.0.11 (3 ms)
Using ethernet at 01c50000 device
TFTP from server 192.168.0.1; our IP address is 192.168.0.11 Filename 'sun7i-a20-lamobo-r1-kernel.bin'.
Load address: 0x42000000
Loading: #################################################################

         #################################################################
         ################################
         11.6 MiB/s

done
Bytes transferred = 2371552 (242fe0 hex)
=>

Florian Fainelli (4):
net: phy: Add Broadcom BCM53xx switch driver
net: designware: Pad small packets
net: phy: b53: Add b53_reg read/write commands
configs: Update Lamobo_R1 with B53 switch options

 configs/Lamobo_R1_defconfig |   3 +
 drivers/net/designware.c    |   4 +
 drivers/net/phy/Kconfig     |  14 +
 drivers/net/phy/Makefile    |   1 +
 drivers/net/phy/b53.c       | 767 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/phy/phy.c       |   3 +
 include/phy.h               |   1 +
 7 files changed, 793 insertions(+)
 create mode 100644 drivers/net/phy/b53.c
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/4 net: phy: Add Broadcom BCM53xx switch driver

Add a minimalistic Broadcom BCM53xx (roboswitch) switch driver similar to the Marvell MV88E617x. This takes care of configuring the minimum amount out of the switch hardware such that each user visible port (configurable) and the CPU port can forward packets between each other while preserving isolation with other ports.

This is useful for e.g: the Lamobo R1 board featuring a Broadcom BCM53125 switch.

---
 drivers/net/phy/Kconfig  |  14 ++
 drivers/net/phy/Makefile |   1 +
 drivers/net/phy/b53.c    | 629 +++++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/phy/phy.c    |   3 +
 include/phy.h            |   1 +
 5 files changed, 648 insertions(+)
 create mode 100644 drivers/net/phy/b53.c
drivers/net/phy/Kconfig +14 -0
index 4d02d8bb19a9..e4c4039ff0a4 100644
@@ -12,6 +12,20 @@ menuconfig PHYLIB
 
 if PHYLIB
 
+config B53_SWITCH
+	bool "Broadcom BCM53xx (roboswitch) Ethernet switch PHY support."
+
+if B53_SWITCH
+
+config B53_CPU_PORT
+	int "CPU port"
+	default 8
+
+config B53_PHY_PORTS
+	hex "Bitmask of PHY ports"
+
+endif # B53_SWITCH
+
 config MV88E61XX_SWITCH
 	bool "Marvel MV88E61xx Ethernet switch PHY support."
 
drivers/net/phy/Makefile +1 -0
index 54f32f606be3..b30e6496063a 100644
@@ -6,6 +6,7 @@
 #
 
 obj-$(CONFIG_BITBANGMII) += miiphybb.o
+obj-$(CONFIG_B53_SWITCH) += b53.o
 obj-$(CONFIG_MV88E61XX_SWITCH) += mv88e61xx.o
 obj-$(CONFIG_MV88E6352_SWITCH) += mv88e6352.o
 
drivers/net/phy/b53.c new file +629 -0

629 lines not on this page · raw message

drivers/net/phy/phy.c +3 -0
index 5be51d73ce62..60bce7694f3d 100644
@@ -461,6 +461,9 @@ static LIST_HEAD(phy_drivers);
 
 int phy_init(void)
 {
+#ifdef CONFIG_B53_SWITCH
+	phy_b53_init();
+#endif
 #ifdef CONFIG_MV88E61XX_SWITCH
 	phy_mv88e61xx_init();
 #endif
include/phy.h +1 -0
index a0b1f12317f3..6881e5fa39d7 100644
@@ -257,6 +257,7 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
+int phy_b53_init(void);
 int phy_mv88e61xx_init(void);
 int phy_aquantia_init(void);
 int phy_atheros_init(void);
Signature · 1 line
2.11.0
#2 lore raw

PATCH 1/4 net: phy: Add Broadcom BCM53xx switch driver

Quoted 10 lines · Florian Fainelli

Add a minimalistic Broadcom BCM53xx (roboswitch) switch driver similar to the Marvell MV88E617x. This takes care of configuring the minimum amount out of the switch hardware such that each user visible port (configurable) and the CPU port can forward packets between each other while preserving isolation with other ports.

This is useful for e.g: the Lamobo R1 board featuring a Broadcom BCM53125 switch.

Thanks,
Stefan

#3 lore raw

PATCH 2/4 net: designware: Pad small packets

In reply to Florian Fainelli

Make sure that we pad small packets to a minimum length of 60 bytes (without FCS). This is necessary to interface with Ethernet switches that will reject RUNT frames unless padded correctly.

---
 drivers/net/designware.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/designware.c +4 -0
index 036d231071ca..10356a9abd0e 100644
@@ -343,6 +343,8 @@ int designware_eth_enable(struct dw_eth_dev *priv)
 	return 0;
 }
 
+#define ETH_ZLEN	60
+
 static int _dw_eth_send(struct dw_eth_dev *priv, void *packet, int length)
 {
 	struct eth_dma_regs *dma_p = priv->dma_regs_p;
@@ -369,6 +371,8 @@ static int _dw_eth_send(struct dw_eth_dev *priv, void *packet, int length)
 		return -EPERM;
 	}
 
+	length = (length < ETH_ZLEN) ? ETH_ZLEN : length;
+
 	memcpy((void *)data_start, packet, length);
 
 	/* Flush data to be sent */
Signature · 1 line
2.11.0
#5 lore raw

PATCH 2/4 net: designware: Pad small packets

In reply to Florian Fainelli
Quoted 23 lines · Florian Fainelli

Make sure that we pad small packets to a minimum length of 60 bytes (without FCS). This is necessary to interface with Ethernet switches that will reject RUNT frames unless padded correctly.

---
 drivers/net/designware.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/designware.c +2 -0
index 036d231071ca..10356a9abd0e 100644
@@ -343,6 +343,8 @@ int designware_eth_enable(struct dw_eth_dev *priv)
        return 0;
 }
 
+#define ETH_ZLEN       60
+
 static int _dw_eth_send(struct dw_eth_dev *priv, void *packet, int length)
 {
        struct eth_dma_regs *dma_p = priv->dma_regs_p;

drivers/net/designware.c static int _dw_eth_send(struct dw_eth_dev *priv, void *packet, int length) · line 374

Quoted 4 lines
drivers/net/designware.c +1 -0
@@ -369,6 +371,8 @@ static int _dw_eth_send(struct dw_eth_dev *priv, void *packet, int length)
                return -EPERM;
        }
 
+       length = (length < ETH_ZLEN) ? ETH_ZLEN : length;

Why not use max() from include/linux/kernel.h here?

Quoted 6 lines
drivers/net/designware.c +1 -1
+
        memcpy((void *)data_start, packet, length);
 
        /* Flush data to be sent */
--

2.11.0

#6 lore raw

PATCH 3/4 net: phy: b53: Add b53_reg read/write commands

In reply to Florian Fainelli

Add a b53_reg read/write command which allows inspecting the switch registers. Because the Broadcom BCM53xx registers have different sizes, we need to split the accesses in 8, 16, 32, 48 or 64 bits to obtain expected results.

---
 drivers/net/phy/b53.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 138 insertions(+)
drivers/net/phy/b53.c +138 -0
index fa37d051130b..a68d2ae39fa9 100644
@@ -627,3 +627,141 @@ int phy_b53_init(void)
 
 	return 0;
 }
+
+int do_b53_reg_read(const char *name, int argc, char * const argv[])
+{
+	u8 page, offset, width;
+	struct mii_dev *bus;
+	int ret = -EINVAL;
+	u64 value64 = 0;
+	u32 value32 = 0;
+	u16 value16 = 0;
+	u8 value8 = 0;
+
+	bus = miiphy_get_dev_by_name(name);
+	if (!bus) {
+		printf("unable to find MDIO bus: %s\n", name);
+		return ret;
+	}
+
+	page = simple_strtoul(argv[1], NULL, 16);
+	offset = simple_strtoul(argv[2], NULL, 16);
+	width = simple_strtoul(argv[3], NULL, 10);
+
+	switch (width) {
+	case 8:
+		ret = b53_mdio_read8(bus, page, offset, &value8);
+		printf("page=0x%02x, offset=0x%02x, value=0x%02x\n",
+			page, offset, value8);
+		break;
+	case 16:
+		ret = b53_mdio_read16(bus, page, offset, &value16);
+		printf("page=0x%02x, offset=0x%02x, value=0x%04x\n",
+			page, offset, value16);
+		break;
+	case 32:
+		ret = b53_mdio_read32(bus, page, offset, &value32);
+		printf("page=0x%02x, offset=0x%02x, value=0x%08x\n",
+			page, offset, value32);
+		break;
+	case 48:
+		ret = b53_mdio_read48(bus, page, offset, &value64);
+		printf("page=0x%02x, offset=0x%02x, value=0x%012llx\n",
+			page, offset, value64);
+		break;
+	case 64:
+		ret = b53_mdio_read48(bus, page, offset, &value64);
+		printf("page=0x%02x, offset=0x%02x, value=0x%016llx\n",
+			page, offset, value64);
+		break;
+	default:
+		printf("Unsupported width: %d\n", width);
+		break;
+	}
+
+	return ret;
+}
+
+int do_b53_reg_write(const char *name, int argc, char * const argv[])
+{
+	u8 page, offset, width;
+	struct mii_dev *bus;
+	int ret = -EINVAL;
+	u64 value64 = 0;
+	u32 value = 0;
+
+	bus = miiphy_get_dev_by_name(name);
+	if (!bus) {
+		printf("unable to find MDIO bus: %s\n", name);
+		return ret;
+	}
+
+	page = simple_strtoul(argv[1], NULL, 16);
+	offset = simple_strtoul(argv[2], NULL, 16);
+	width = simple_strtoul(argv[3], NULL, 10);
+	if (width == 48 || width == 64)
+		value64 = simple_strtoull(argv[4], NULL, 16);
+	else
+		value = simple_strtoul(argv[4], NULL, 16);
+
+	switch (width) {
+	case 8:
+		ret = b53_mdio_write8(bus, page, offset, value & 0xff);
+		break;
+	case 16:
+		ret = b53_mdio_write16(bus, page, offset, value);
+		break;
+	case 32:
+		ret = b53_mdio_write32(bus, page, offset, value);
+		break;
+	case 48:
+		ret = b53_mdio_write48(bus, page, offset, value64);
+		break;
+	case 64:
+		ret = b53_mdio_write64(bus, page, offset, value64);
+		break;
+	default:
+		printf("Unsupported width: %d\n", width);
+		break;
+	}
+
+	return ret;
+}
+
+int do_b53_reg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	const char *cmd, *mdioname;
+	int ret = 0;
+
+	if (argc < 2)
+		return cmd_usage(cmdtp);
+
+	cmd = argv[1];
+	--argc;
+	++argv;
+
+	if (!strcmp(cmd, "write")) {
+		if (argc < 4)
+			return cmd_usage(cmdtp);
+		mdioname = argv[1];
+		--argc;
+		++argv;
+		ret = do_b53_reg_write(mdioname, argc, argv);
+	} else if (!strcmp(cmd, "read")) {
+		if (argc < 5)
+			return cmd_usage(cmdtp);
+		mdioname = argv[1];
+		--argc;
+		++argv;
+		ret = do_b53_reg_read(mdioname, argc, argv);
+	} else
+		return cmd_usage(cmdtp);
+
+	return ret;
+}
+
+U_BOOT_CMD(b53_reg, 7, 1, do_b53_reg,
+	   "Broadcom B53 switch register access",
+	   "write mdioname page (hex) offset (hex) width (dec) value (hex)\n"
+	   "read mdioname page (hex) offset (hex) width (dec)\n"
+	  );
Signature · 1 line
2.11.0
#7 lore raw

PATCH 3/4 net: phy: b53: Add b53_reg read/write commands

Quoted 6 lines · Florian Fainelli

Add a b53_reg read/write command which allows inspecting the switch registers. Because the Broadcom BCM53xx registers have different sizes, we need to split the accesses in 8, 16, 32, 48 or 64 bits to obtain expected results.

Thanks,
Stefan

#9 lore raw

PATCH 4/4 configs: Update Lamobo_R1 with B53 switch options

In reply to Florian Fainelli

Enable CONFIG_B53_SWITCH, define the CPU/management port number (8) and enable all 5 ports of the switch to be usable.

---
 configs/Lamobo_R1_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/Lamobo_R1_defconfig +3 -0
index 84007ad374b8..19c977ef42ee 100644
@@ -22,3 +22,6 @@ CONFIG_SUN7I_GMAC=y
 CONFIG_SCSI=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y
+CONFIG_B53_SWITCH=y
+CONFIG_B53_CPU_PORT=8
+CONFIG_B53_PHY_PORTS=0x1f
Signature · 1 line
2.11.0
#12 lore raw

cover net: phy: Add Broadcom BCM53xx switch driver

In reply to Florian Fainelli
Quoted 6 lines · Florian Fainelli

(this time after subscribing to the list)

Hi all,

This patch series adds support for the Broadcom BCM53xx switches, in particular BCM53125 which is found no the Lamobo R1 board.

Thanks Stefan for the review. I suppose Joe should now queue those up, provided that he is happy with the patches and then submit a pull request?

Quoted 38 lines

The driver is largely based on the DSA/b53 driver Linux driver and only incorporates what is necessary to succesfully bring-up all ports (including the management port) for boot over the network:

=> dhcp
dw_adjust_link: Speed: 1000, full duplex
BOOTP broadcast 1
DHCP client bound to address 192.168.0.11 (3 ms)
Using ethernet at 01c50000 device
TFTP from server 192.168.0.1; our IP address is 192.168.0.11 Filename 'sun7i-a20-lamobo-r1-kernel.bin'.
Load address: 0x42000000
Loading: #################################################################

         #################################################################
         ################################
         11.6 MiB/s

done
Bytes transferred = 2371552 (242fe0 hex)
=>

Florian Fainelli (4):
net: phy: Add Broadcom BCM53xx switch driver
net: designware: Pad small packets
net: phy: b53: Add b53_reg read/write commands
configs: Update Lamobo_R1 with B53 switch options

 configs/Lamobo_R1_defconfig |   3 +
 drivers/net/designware.c    |   4 +
 drivers/net/phy/Kconfig     |  14 +
 drivers/net/phy/Makefile    |   1 +
 drivers/net/phy/b53.c       | 767 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/phy/phy.c       |   3 +
 include/phy.h               |   1 +
 7 files changed, 793 insertions(+)
 create mode 100644 drivers/net/phy/b53.c
Signature · 1 line
Florian
#13 lore raw

cover net: phy: Add Broadcom BCM53xx switch driver

Quoted 10 lines · Florian Fainelli
Quoted 6 lines · Florian Fainelli

(this time after subscribing to the list)

Hi all,

This patch series adds support for the Broadcom BCM53xx switches, in particular BCM53125 which is found no the Lamobo R1 board.

Thanks Stefan for the review. I suppose Joe should now queue those up, provided that he is happy with the patches and then submit a pull request?

Yes, this is how it usually works.

Thanks,
Stefan

#14 lore raw

cover net: phy: Add Broadcom BCM53xx switch driver

Le 10/19/17 à 21:45, Stefan Roese a écrit :

Quoted 10 lines · Florian Fainelli
Quoted 9 lines · Florian Fainelli
Quoted 7 lines

(this time after subscribing to the list)

Hi all,

This patch series adds support for the Broadcom BCM53xx switches, in particular
BCM53125 which is found no the Lamobo R1 board.

Quoted 5 lines
Quoted 3 lines

Thanks Stefan for the review. I suppose Joe should now queue those up, provided that he is happy with the patches and then submit a pull request?

Yes, this is how it usually works.

Joe, should I do anything, are you happy with how the patches look like?

Signature · 1 line
Florian
#15 lore raw

cover net: phy: Add Broadcom BCM53xx switch driver

Quoted 11 lines · Florian Fainelli

Le 10/19/17 à 21:45, Stefan Roese a écrit :

Quoted 10 lines · Florian Fainelli
Quoted 9 lines · Florian Fainelli
Quoted 7 lines

(this time after subscribing to the list)

Hi all,

This patch series adds support for the Broadcom BCM53xx switches, in particular
BCM53125 which is found no the Lamobo R1 board.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Thanks Stefan for the review. I suppose Joe should now queue those up, provided that he is happy with the patches and then submit a pull request?

Yes, this is how it usually works.

Joe, should I do anything, are you happy with how the patches look like?

Ping? How do we get these moving?

Signature · 1 line
Florian