Skip to contentSkip to conversation

net: phy: Add Broadcom BCM53xx switch driver

PATCH Superseded Florian Fainelli 2 participants 8 messages Dec 9, 2017

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover net: phy: Add Broadcom BCM53xx switch driver

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)
=>

Changes in v3:
- dropped redundant phydev->priv assignment in b53_probe(), spotted by Joe

Changes in v2:

- collected Sefan's Reviewed-by and Joe's Acked-by tags
- use max() in drivers/net/designware.c as suggested by Joe

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    |   5 +
 drivers/net/phy/Kconfig     |  14 +
 drivers/net/phy/Makefile    |   1 +
 drivers/net/phy/b53.c       | 765 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/phy/phy.c       |   3 +
 include/phy.h               |   1 +
 7 files changed, 792 insertions(+)
 create mode 100644 drivers/net/phy/b53.c
Signature · 1 line
2.14.1
#1 lore raw

PATCH v3 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    | 627 +++++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/phy/phy.c    |   3 +
 include/phy.h            |   1 +
 5 files changed, 646 insertions(+)
 create mode 100644 drivers/net/phy/b53.c
drivers/net/phy/Kconfig +14 -0
index e32f1eb1c047..609305b8ebf8 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 1e264b2f2b03..f1980371c366 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 +627 -0

627 lines not on this page · raw message

drivers/net/phy/phy.c +3 -0
index fd3dd556c879..e31f3aa3a989 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 50f1e12f8c2c..0543ec10c28c 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.14.1
#2 lore raw

PATCH v3 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 | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/designware.c +5 -0
index 036d231071ca..56fa0ebd8f31 100644
@@ -17,6 +17,7 @@
 #include <pci.h>
 #include <linux/compiler.h>
 #include <linux/err.h>
+#include <linux/kernel.h>
 #include <asm/io.h>
 #include <power/regulator.h>
 #include "designware.h"
@@ -343,6 +344,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 +372,8 @@ static int _dw_eth_send(struct dw_eth_dev *priv, void *packet, int length)
 		return -EPERM;
 	}
 
+	length = max(length, ETH_ZLEN);
+
 	memcpy((void *)data_start, packet, length);
 
 	/* Flush data to be sent */
Signature · 1 line
2.14.1
#4 lore raw

PATCH v3 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 167ae0077eea..6fc8d5df1801 100644
@@ -625,3 +625,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.14.1
#5 lore raw

PATCH v3 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.14.1
#6 lore raw

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

Quoted 6 lines · Florian Fainelli

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

Usually you want to put your Signed-off-by: first, but not worth a respin. Just FYI.

Cheers,
-Joe

Quoted 22 lines
---
 configs/Lamobo_R1_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/Lamobo_R1_defconfig +3 -1
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
--

2.14.1

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

#7 lore raw

v3 cover net: phy: Add Broadcom BCM53xx switch driver

In reply to Florian Fainelli
Quoted 39 lines · Florian Fainelli

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)
=>

Changes in v3:
- dropped redundant phydev->priv assignment in b53_probe(), spotted by Joe

Changes in v2:

- collected Sefan's Reviewed-by and Joe's Acked-by tags
- use max() in drivers/net/designware.c as suggested by Joe

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

Quoted 9 lines
 configs/Lamobo_R1_defconfig |   3 +
 drivers/net/designware.c    |   5 +
 drivers/net/phy/Kconfig     |  14 +
 drivers/net/phy/Makefile    |   1 +
 drivers/net/phy/b53.c       | 765 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/phy/phy.c       |   3 +
 include/phy.h               |   1 +
 7 files changed, 792 insertions(+)
 create mode 100644 drivers/net/phy/b53.c

I tried to apply this and it has checkpatch.pl issues. Please address and send a v4.

Thanks,
-Joe