net: phy: Add Broadcom BCM53xx switch driver
Subsystems (2)
v2 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:
=> dhcpdw_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/sdone
Bytes transferred = 2371552 (242fe0 hex)
=>
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 | 767 ++++++++++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 3 + include/phy.h | 1 + 7 files changed, 794 insertions(+) create mode 100644 drivers/net/phy/b53.c
Signature · 1 line
2.14.1
PATCH v2 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 1/4 net: phy: Add Broadcom BCM53xx switch driver
Quoted 12 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.
Reviewed-by Stefan Roese <[email protected]>Signed-off-by Florian Fainelli <[email protected]>---
[snip]
Quoted 10 lines
drivers/net/phy/b53.c new file +10
-0+static int b53_probe (struct phy_device *phydev) +{ +struct b53_device *dev; +int ret; + + dev =malloc (sizeof (*dev)); +if (!dev) +return -ENOMEM ; + +memset (dev,0 ,sizeof (*dev));
drivers/net/phy/b53.c line 547
Quoted 10 lines
drivers/net/phy/b53.c new file +10
-0+ + phydev->priv = dev; + dev->bus = phydev->bus; + dev->cpu_port =CONFIG_B53_CPU_PORT ; + + ret =b53_switch_reset (phydev); +if (ret <0 ) +return ret; + + phydev->priv = dev;
Looks like I missed Joe's comment here about the redundant assignment, let me resubmit a v3 with this corrected.
Signature · 1 line
Florian
PATCH v2 2/4 net: designware: Pad small packets
In reply to Florian FainelliMake 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
@@ -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
PATCH v2 3/4 net: phy: b53: Add b53_reg read/write commands
In reply to Florian FainelliAdd 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
@@ -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.14.1
PATCH v2 4/4 configs: Update Lamobo_R1 with B53 switch options
In reply to Florian FainelliEnable 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
@@ -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