Microsemi Ocelot switch support
Subsystems (8)
Alexandre Belloni
maintainercover Microsemi Ocelot switch support
Hi,
This series adds initial support for the Microsemi Ethernet switch present on Ocelot SoCs.
This only has bridging (and STP) support for now and it uses the switchdev framework.
Coming features are VLAN filtering, link aggregation, IGMP snooping.
The switch can also be connected to an external CPU using PCIe. I have a PoC for that but it is still a bit clunky.
Also, support for integration on other SoCs will be submitted.
The ocelot dts changes are here for reference and should probably go through the MIPS tree once the bindings are accepted.
Alexandre Belloni (8):
net: phy: Add initial support for Microsemi Ocelot internal PHYs.
dt-bindings: net: add DT bindings for Microsemi MIIM
net: mscc: Add MDIO driver
dt-bindings: net: add DT bindings for Microsemi Ocelot Switch
net: mscc: Add initial Ocelot switch support
MIPS: mscc: Add switch to ocelot
MIPS: mscc: connect phys to ports on ocelot_pcb123
MAINTAINERS: Add entry for Microsemi Ethernet switches
.../devicetree/bindings/net/mscc-miim.txt | 25 + .../devicetree/bindings/net/mscc-ocelot.txt | 62 + MAINTAINERS | 6 + arch/mips/boot/dts/mscc/ocelot.dtsi | 84 ++ arch/mips/boot/dts/mscc/ocelot_pcb123.dts | 16 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/mscc/Kconfig | 36 + drivers/net/ethernet/mscc/Makefile | 6 + drivers/net/ethernet/mscc/mscc_miim.c | 210 +++ drivers/net/ethernet/mscc/ocelot.c | 1346 ++++++++++++++++++++ drivers/net/ethernet/mscc/ocelot.h | 554 ++++++++ drivers/net/ethernet/mscc/ocelot_ana.h | 625 +++++++++ drivers/net/ethernet/mscc/ocelot_board.c | 329 +++++ drivers/net/ethernet/mscc/ocelot_dev.h | 275 ++++ drivers/net/ethernet/mscc/ocelot_dev_gmii.h | 154 +++ drivers/net/ethernet/mscc/ocelot_hsio.h | 785 ++++++++++++ drivers/net/ethernet/mscc/ocelot_io.c | 116 ++ drivers/net/ethernet/mscc/ocelot_qs.h | 78 ++ drivers/net/ethernet/mscc/ocelot_qsys.h | 270 ++++ drivers/net/ethernet/mscc/ocelot_regs.c | 399 ++++++ drivers/net/ethernet/mscc/ocelot_rew.h | 81 ++ drivers/net/ethernet/mscc/ocelot_sys.h | 140 ++ drivers/net/phy/mscc.c | 15 + 24 files changed, 5614 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/mscc-miim.txt create mode 100644 Documentation/devicetree/bindings/net/mscc-ocelot.txt create mode 100644 drivers/net/ethernet/mscc/Kconfig create mode 100644 drivers/net/ethernet/mscc/Makefile create mode 100644 drivers/net/ethernet/mscc/mscc_miim.c create mode 100644 drivers/net/ethernet/mscc/ocelot.c create mode 100644 drivers/net/ethernet/mscc/ocelot.h create mode 100644 drivers/net/ethernet/mscc/ocelot_ana.h create mode 100644 drivers/net/ethernet/mscc/ocelot_board.c create mode 100644 drivers/net/ethernet/mscc/ocelot_dev.h create mode 100644 drivers/net/ethernet/mscc/ocelot_dev_gmii.h create mode 100644 drivers/net/ethernet/mscc/ocelot_hsio.h create mode 100644 drivers/net/ethernet/mscc/ocelot_io.c create mode 100644 drivers/net/ethernet/mscc/ocelot_qs.h create mode 100644 drivers/net/ethernet/mscc/ocelot_qsys.h create mode 100644 drivers/net/ethernet/mscc/ocelot_regs.c create mode 100644 drivers/net/ethernet/mscc/ocelot_rew.h create mode 100644 drivers/net/ethernet/mscc/ocelot_sys.h
Signature · 1 line
2.16.2
Alexandre Belloni
maintainerPATCH 1/8 net: phy: Add initial support for Microsemi Ocelot internal PHYs.
Add Microsemi Ocelot internal PHY ids. For now, simply use the genphy functions but more features are available.
--- drivers/net/phy/mscc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/net/phy/mscc.c +15 -0
@@ -91,6 +91,7 @@ enum rgmii_rx_clock_delay {#define SECURE_ON_PASSWD_LEN_4 0x4000/* Microsemi PHY ID's */ +#define PHY_ID_OCELOT 0x00070540#define PHY_ID_VSC8530 0x00070560#define PHY_ID_VSC8531 0x00070570#define PHY_ID_VSC8540 0x00070760
@@ -658,6 +659,19 @@ static int vsc85xx_probe(struct phy_device *phydev)/* Microsemi VSC85xx PHYs */ static struct phy_driver vsc85xx_driver[] = { +{ + .phy_id =PHY_ID_OCELOT , + .name ="Microsemi OCELOT" , + .phy_id_mask =0xfffffff0 , + .features =PHY_GBIT_FEATURES , + .soft_reset = &genphy_soft_reset, + .config_init = &genphy_config_init, + .config_aneg = &genphy_config_aneg, + .aneg_done = &genphy_aneg_done, + .read_status = &genphy_read_status, + .suspend = &genphy_suspend, + .resume = &genphy_resume, +}, { .phy_id =PHY_ID_VSC8530 , .name ="Microsemi FE VSC8530" ,
@@ -748,6 +762,7 @@ static struct phy_driver vsc85xx_driver[] = {module_phy_driver (vsc85xx_driver);static struct mdio_device_id __maybe_unused vsc85xx_tbl[] = { + {PHY_ID_OCELOT ,0xfffffff0 , }, {PHY_ID_VSC8530 ,0xfffffff0 , }, {PHY_ID_VSC8531 ,0xfffffff0 , }, {PHY_ID_VSC8540 ,0xfffffff0 , },
Signature · 1 line
2.16.2
Alexandre Belloni
maintainerPATCH 2/8 dt-bindings: net: add DT bindings for Microsemi MIIM
In reply to Alexandre BelloniDT bindings for the Microsemi MII Management Controller found on Microsemi SoCs
--- .../devicetree/bindings/net/mscc-miim.txt | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/mscc-miim.txt
Documentation/devicetree/bindings/net/mscc-miim.txt new file +25 -0
@@ -0,0 +1,25 @@ +Microsemi MII Management Controller (MIIM) / MDIO +================================================= + +Properties: +- compatible: must be "mscc,ocelot-miim" +- reg: The base address of the MDIO bus controller register bank. Optionally, a + second register bank can be defined if there is an associated reset register + for internal PHYs +- #address-cells: Must be <1>. +- #size-cells: Must be <0>. MDIO addresses have no size component. + +Typically an MDIO bus might have several children. + +Example: + mdio@107009c { + #address-cells = <1>; + #size-cells = <0>; + compatible = "mscc,ocelot-miim"; + reg = <0x107009c 0x36>, <0x10700f0 0x8>; + interrupts = <14>; + + phy0: ethernet-phy@0 { + reg = <0>; + }; + };
Signature · 1 line
2.16.2
Alexandre Belloni
maintainerPATCH 3/8 net: mscc: Add MDIO driver
In reply to Alexandre BelloniAdd a driver for the Microsemi MII Management controller (MIIM) found on Microsemi SoCs.
On Ocelot, there are two controllers, one is connected to the internal PHYs, the other one can communicate with external PHYs.
--- drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/mscc/Kconfig | 22 ++++ drivers/net/ethernet/mscc/Makefile | 2 + drivers/net/ethernet/mscc/mscc_miim.c | 210 ++++++++++++++++++++++++++++++++++ 5 files changed, 236 insertions(+) create mode 100644 drivers/net/ethernet/mscc/Kconfig create mode 100644 drivers/net/ethernet/mscc/Makefile create mode 100644 drivers/net/ethernet/mscc/mscc_miim.c
drivers/net/ethernet/Kconfig +1 -0
@@ -115,6 +115,7 @@ source "drivers/net/ethernet/mediatek/Kconfig" source "drivers/net/ethernet/mellanox/Kconfig" source "drivers/net/ethernet/micrel/Kconfig" source "drivers/net/ethernet/microchip/Kconfig" +source "drivers/net/ethernet/mscc/Kconfig" source "drivers/net/ethernet/moxa/Kconfig" source "drivers/net/ethernet/myricom/Kconfig"
drivers/net/ethernet/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_NET_VENDOR_MEDIATEK) += mediatek/ obj-$(CONFIG_NET_VENDOR_MELLANOX) += mellanox/ obj-$(CONFIG_NET_VENDOR_MICREL) += micrel/ obj-$(CONFIG_NET_VENDOR_MICROCHIP) += microchip/ +obj-$(CONFIG_NET_VENDOR_MICROSEMI) += mscc/ obj-$(CONFIG_NET_VENDOR_MOXART) += moxa/ obj-$(CONFIG_NET_VENDOR_MYRI) += myricom/ obj-$(CONFIG_FEALNX) += fealnx.o
drivers/net/ethernet/mscc/Kconfig new file +22 -0
@@ -0,0 +1,22 @@ +# SPDX-License-Identifier: (GPL-2.0 OR MIT) +config NET_VENDOR_MICROSEMI + bool "Microsemi devices" + default y + help + If you have a network (Ethernet) card belonging to this class, say Y. + + Note that the answer to this question doesn't directly affect the + kernel: saying N will just cause the configurator to skip all + the questions about Microsemi devices. + +if NET_VENDOR_MICROSEMI + +config MSCC_MIIM + tristate "Microsemi MIIM interface support" + depends on HAS_IOMEM + select PHYLIB + help + This driver supports the MIIM (MDIO) interface found in the network + switches of the Microsemi SoCs + +endif # NET_VENDOR_MICROSEMI
drivers/net/ethernet/mscc/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: (GPL-2.0 OR MIT) +obj-$(CONFIG_MSCC_MIIM) += mscc_miim.o
drivers/net/ethernet/mscc/mscc_miim.c new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.16.2
Alexandre Belloni
maintainerPATCH 4/8 dt-bindings: net: add DT bindings for Microsemi Ocelot Switch
In reply to Alexandre BelloniDT bindings for the Ethernet switch found on Microsemi Ocelot platforms.
--- .../devicetree/bindings/net/mscc-ocelot.txt | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/mscc-ocelot.txt
Documentation/devicetree/bindings/net/mscc-ocelot.txt new file +62 -0
@@ -0,0 +1,62 @@ +Microsemi Ocelot network Switch +=============================== + +The Microsemi Ocelot network switch can be found on Microsemi SoCs (VSC7513, +VSC7514) + +Required properties: +- compatible: Should be "mscc,ocelot-switch" +- reg: Must contain an (offset, length) pair of the register set for each + entry in reg-names. +- reg-names: Must include the following entries: + - "sys" + - "rew" + - "qs" + - "hsio" + - "qsys" + - "ana" + - "portX" with X from 0 to the number of last port index available on that + switch +- interrupts: Should contain the switch interrupts for frame extraction and + frame injection +- interrupt-names: should contain the interrupt names: "xtr", "inj" + +Example: + + switch@1010000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "mscc,ocelot-switch"; + reg = <0x1010000 0x10000>, + <0x1030000 0x10000>, + <0x1080000 0x100>, + <0x10d0000 0x10000>, + <0x11e0000 0x100>, + <0x11f0000 0x100>, + <0x1200000 0x100>, + <0x1210000 0x100>, + <0x1220000 0x100>, + <0x1230000 0x100>, + <0x1240000 0x100>, + <0x1250000 0x100>, + <0x1260000 0x100>, + <0x1270000 0x100>, + <0x1280000 0x100>, + <0x1800000 0x80000>, + <0x1880000 0x10000>; + reg-names = "sys", "rew", "qs", "hsio", "port0", + "port1", "port2", "port3", "port4", "port5", + "port6", "port7", "port8", "port9", "port10", + "qsys", "ana"; + interrupts = <21 22>; + interrupt-names = "xtr", "inj"; + + port0: port@0 { + reg = <0>; + phy-handle = <&phy0>; + }; + port1: port@1 { + reg = <1>; + phy-handle = <&phy1>; + }; + };
Signature · 1 line
2.16.2
Alexandre Belloni
maintainerPATCH 5/8 net: mscc: Add initial Ocelot switch support
In reply to Alexandre BelloniAdd a driver for Microsemi Ocelot Ethernet switch support.
This makes two modules:mscc_ocelot_common handles all the common features that doesn't depend on how the switch is integrated in the SoC. Currently, it handles offloading bridging to the hardware. ocelot_io.c handles register accesses. This is unfortunately needed because the register layout is packed and then depends on the number of ports available on the switch. The register definition files are automatically generated.
ocelot_board handles the switch integration on the SoC and on the board.
Frame injection and extraction to/from the CPU port is currently done using register accesses which is quite slow. DMA is possible but the port is not able to absorb the whole switch bandwidth.
--- drivers/net/ethernet/mscc/Kconfig | 14 + drivers/net/ethernet/mscc/Makefile | 4 + drivers/net/ethernet/mscc/ocelot.c | 1346 +++++++++++++++++++++++++++ drivers/net/ethernet/mscc/ocelot.h | 554 +++++++++++ drivers/net/ethernet/mscc/ocelot_ana.h | 625 +++++++++++++ drivers/net/ethernet/mscc/ocelot_board.c | 329 +++++++ drivers/net/ethernet/mscc/ocelot_dev.h | 275 ++++++ drivers/net/ethernet/mscc/ocelot_dev_gmii.h | 154 +++ drivers/net/ethernet/mscc/ocelot_hsio.h | 785 ++++++++++++++++ drivers/net/ethernet/mscc/ocelot_io.c | 116 +++ drivers/net/ethernet/mscc/ocelot_qs.h | 78 ++ drivers/net/ethernet/mscc/ocelot_qsys.h | 270 ++++++ drivers/net/ethernet/mscc/ocelot_regs.c | 399 ++++++++ drivers/net/ethernet/mscc/ocelot_rew.h | 81 ++ drivers/net/ethernet/mscc/ocelot_sys.h | 140 +++ 15 files changed, 5170 insertions(+) create mode 100644 drivers/net/ethernet/mscc/ocelot.c create mode 100644 drivers/net/ethernet/mscc/ocelot.h create mode 100644 drivers/net/ethernet/mscc/ocelot_ana.h create mode 100644 drivers/net/ethernet/mscc/ocelot_board.c create mode 100644 drivers/net/ethernet/mscc/ocelot_dev.h create mode 100644 drivers/net/ethernet/mscc/ocelot_dev_gmii.h create mode 100644 drivers/net/ethernet/mscc/ocelot_hsio.h create mode 100644 drivers/net/ethernet/mscc/ocelot_io.c create mode 100644 drivers/net/ethernet/mscc/ocelot_qs.h create mode 100644 drivers/net/ethernet/mscc/ocelot_qsys.h create mode 100644 drivers/net/ethernet/mscc/ocelot_regs.c create mode 100644 drivers/net/ethernet/mscc/ocelot_rew.h create mode 100644 drivers/net/ethernet/mscc/ocelot_sys.h
drivers/net/ethernet/mscc/Kconfig +14 -0
@@ -19,4 +19,18 @@ config MSCC_MIIM This driver supports the MIIM (MDIO) interface found in the network switches of the Microsemi SoCs +config MSCC_OCELOT_SWITCH + tristate "Ocelot switch driver" + depends on NET_SWITCHDEV + select REGMAP_MMIO + help + This driver supports the Ocelot network switch device. + +config MSCC_OCELOT_SWITCH_OCELOT + tristate "Ocelot switch driver on Ocelot" + depends on MSCC_OCELOT_SWITCH + help + This driver supports the Ocelot network switch device as present on + the Ocelot SoCs. + endif # NET_VENDOR_MICROSEMI
drivers/net/ethernet/mscc/Makefile +4 -0
@@ -1,2 +1,6 @@ # SPDX-License-Identifier: (GPL-2.0 OR MIT) obj-$(CONFIG_MSCC_MIIM) += mscc_miim.o +obj-$(CONFIG_MSCC_OCELOT_SWITCH) += mscc_ocelot_common.o +mscc_ocelot_common-y := ocelot.o ocelot_io.o +mscc_ocelot_common-y += ocelot_regs.o +obj-$(CONFIG_MSCC_OCELOT_SWITCH_OCELOT) += ocelot_board.o
drivers/net/ethernet/mscc/ocelot.c new file +1346 -0
1,346 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot.h new file +554 -0
554 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_ana.h new file +625 -0
625 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_board.c new file +329 -0
329 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_dev.h new file +275 -0
122 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_dev_gmii.h new file +154 -0
154 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_hsio.h new file +785 -0
785 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_io.c new file +116 -0
116 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_qs.h new file +78 -0
78 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_qsys.h new file +270 -0
270 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_regs.c new file +399 -0
399 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_rew.h new file +81 -0
81 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_sys.h new file +140 -0
140 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.16.2
Part of the diff is not shown here. View the raw message.
Alexandre Belloni
maintainerPATCH 6/8 MIPS: mscc: Add switch to ocelot
In reply to Alexandre BelloniOcelot has an integrated switch, add support for it.
--- arch/mips/boot/dts/mscc/ocelot.dtsi | 84 +++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+)
arch/mips/boot/dts/mscc/ocelot.dtsi +84 -0
@@ -91,6 +91,69 @@ status = "disabled"; }; + switch@1010000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "mscc,ocelot-switch"; + reg = <0x1010000 0x10000>, + <0x1030000 0x10000>, + <0x1080000 0x100>, + <0x10d0000 0x10000>, + <0x11e0000 0x100>, + <0x11f0000 0x100>, + <0x1200000 0x100>, + <0x1210000 0x100>, + <0x1220000 0x100>, + <0x1230000 0x100>, + <0x1240000 0x100>, + <0x1250000 0x100>, + <0x1260000 0x100>, + <0x1270000 0x100>, + <0x1280000 0x100>, + <0x1800000 0x80000>, + <0x1880000 0x10000>; + reg-names = "sys", "rew", "qs", "hsio", "port0", + "port1", "port2", "port3", "port4", "port5", + "port6", "port7", "port8", "port9", "port10", + "qsys", "ana"; + interrupts = <21 22>; + interrupt-names = "xtr", "inj"; + + port0: port@0 { + reg = <0>; + }; + port1: port@1 { + reg = <1>; + }; + port2: port@2 { + reg = <2>; + }; + port3: port@3 { + reg = <3>; + }; + port4: port@4 { + reg = <4>; + }; + port5: port@5 { + reg = <5>; + }; + port6: port@6 { + reg = <6>; + }; + port7: port@7 { + reg = <7>; + }; + port8: port@8 { + reg = <8>; + }; + port9: port@9 { + reg = <9>; + }; + port10: port@10 { + reg = <10>; + }; + }; + reset@1070008 { compatible = "mscc,ocelot-chip-reset"; reg = <0x1070008 0x4>;
@@ -113,5 +176,26 @@ function = "uart2"; }; }; + + mdio0: mdio@107009c { + #address-cells = <1>; + #size-cells = <0>; + compatible = "mscc,ocelot-miim"; + reg = <0x107009c 0x36>, <0x10700f0 0x8>; + interrupts = <14>; + + phy0: ethernet-phy@0 { + reg = <0>; + }; + phy1: ethernet-phy@1 { + reg = <1>; + }; + phy2: ethernet-phy@2 { + reg = <2>; + }; + phy3: ethernet-phy@3 { + reg = <3>; + }; + }; }; };
Signature · 1 line
2.16.2
Alexandre Belloni
maintainerPATCH 7/8 MIPS: mscc: connect phys to ports on ocelot_pcb123
In reply to Alexandre BelloniAdd phy to switch port connections for PCB123 for internal PHYs.
--- arch/mips/boot/dts/mscc/ocelot_pcb123.dts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/mips/boot/dts/mscc/ocelot_pcb123.dts +16 -0
@@ -25,3 +25,19 @@ &uart2 { status = "okay"; }; + +&port0 { + phy-handle = <&phy0>; +}; + +&port1 { + phy-handle = <&phy1>; +}; + +&port2 { + phy-handle = <&phy2>; +}; + +&port3 { + phy-handle = <&phy3>; +};
Signature · 1 line
2.16.2
Alexandre Belloni
maintainerPATCH 8/8 MAINTAINERS: Add entry for Microsemi Ethernet switches
In reply to Alexandre BelloniAdd myself as a maintainer for the Microsemi Ethernet switches.
--- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -9177,6 +9177,12 @@ F: include/linux/cciss*.h F: include/uapi/linux/cciss*.h F: Documentation/scsi/smartpqi.txt +MICROSEMI ETHERNET SWITCH DRIVER +M: Alexandre Belloni <[email protected]> +L: [email protected] +S: Supported +F: drivers/net/ethernet/mscc/ + MICROSOFT SURFACE PRO 3 BUTTON DRIVER M: Chen Yu <[email protected]> L: [email protected]
Signature · 1 line
2.16.2
Andrew Lunn
maintainerRe: [PATCH net-next 1/8] net: phy: Add initial support for Microsemi Ocelot internal PHYs.
In reply to Alexandre BelloniQuoted 22 lines · Alexandre Belloni
Add Microsemi Ocelot internal PHY ids. For now, simply use the genphy functions but more features are available.
Cc Raju Lakkaraju <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>--- drivers/net/phy/mscc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)drivers/net/phy/mscc.c +1
-0@@ -91,6 +91,7 @@ enum rgmii_rx_clock_delay {#define SECURE_ON_PASSWD_LEN_4 0x4000/* Microsemi PHY ID's */ +#define PHY_ID_OCELOT 0x00070540#define PHY_ID_VSC8530 0x00070560#define PHY_ID_VSC8531 0x00070570#define PHY_ID_VSC8540 0x00070760
drivers/net/phy/mscc.c static int vsc85xx_probe(struct phy_device *phydev) · line 666
Quoted 8 lines
drivers/net/phy/mscc.c +5
-0@@ -658,6 +659,19 @@ static int vsc85xx_probe(struct phy_device *phydev)/* Microsemi VSC85xx PHYs */ static struct phy_driver vsc85xx_driver[] = { +{ + .phy_id =PHY_ID_OCELOT , + .name ="Microsemi OCELOT" , + .phy_id_mask =0xfffffff0 , + .features =PHY_GBIT_FEATURES ,
No interrupt support? In fact, the only advantage i see this brings over the generic driver is that the name Microsemi OCELOT is printed.
Andrew
Quoted 8 lines
drivers/net/phy/mscc.c +8
-0+ .soft_reset = &genphy_soft_reset, + .config_init = &genphy_config_init, + .config_aneg = &genphy_config_aneg, + .aneg_done = &genphy_aneg_done, + .read_status = &genphy_read_status, + .suspend = &genphy_suspend, + .resume = &genphy_resume, +},
Andrew Lunn
maintainerRe: [PATCH net-next 3/8] net: mscc: Add MDIO driver
In reply to Alexandre BelloniQuoted 4 lines · Alexandre Belloni
Add a driver for the Microsemi MII Management controller (MIIM) found on Microsemi SoCs.
On Ocelot, there are two controllers, one is connected to the internal PHYs, the other one can communicate with external PHYs.
Hi Alexandre
This looks to be standalone. Such drivers we try to put in drivers/net/phy.
drivers/net/ethernet/mscc/mscc_miim.c line 61
Quoted 7 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +7
-0+static int mscc_miim_read (struct mii_bus *bus,int mii_id,int regnum) +{ +struct mscc_miim_dev *miim = bus->priv; +u32 val; +int ret; + +mutex_lock (&miim->lock);
What are you locking against here?
And you don't appear to initialize the mutex anywhere.
Quoted 5 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +5
-0+static int mscc_miim_reset (struct mii_bus *bus) +{ +struct mscc_miim_dev *miim = bus->priv; +int i; +
drivers/net/ethernet/mscc/mscc_miim.c line 124
Quoted 10 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +10
-0+if (miim->phy_regs) { +writel (0 , miim->phy_regs +MSCC_PHY_REG_PHY_CFG ); +writel (0x1ff , miim->phy_regs +MSCC_PHY_REG_PHY_CFG ); +mdelay (500 ); + } + +for (i =0 ; i <PHY_MAX_ADDR ; i++) { +if (mscc_miim_read (bus, i,MII_PHYSID1 ) <0 ) + bus->phy_mask |=BIT (i); + }
Why do this? Especially so for the external bus, where the PHYs might have a GPIO reset line, and won't respond until the gpio is released. The core code does that just before it scans the bus, or just before it scans the particular address on the bus, depending on the scope of the GPIO.
Otherwise, pretty good :-)
Andrew
Andrew Lunn
maintainerRe: [PATCH net-next 4/8] dt-bindings: net: add DT bindings for Microsemi Ocelot Switch
In reply to Alexandre BelloniQuoted 66 lines · Alexandre Belloni
DT bindings for the Ethernet switch found on Microsemi Ocelot platforms.
Cc Rob Herring <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>--- .../devicetree/bindings/net/mscc-ocelot.txt | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/mscc-ocelot.txtDocumentation/devicetree/bindings/net/mscc-ocelot.txt new file +51
-0@@ -0,0 +1,62 @@ +Microsemi Ocelot network Switch +=============================== + +The Microsemi Ocelot network switch can be found on Microsemi SoCs (VSC7513, +VSC7514) + +Required properties: +- compatible: Should be "mscc,ocelot-switch" +- reg: Must contain an (offset, length) pair of the register set for each + entry in reg-names. +- reg-names: Must include the following entries: + - "sys" + - "rew" + - "qs" + - "hsio" + - "qsys" + - "ana" + - "portX" with X from 0 to the number of last port index available on that + switch +- interrupts: Should contain the switch interrupts for frame extraction and + frame injection +- interrupt-names: should contain the interrupt names: "xtr", "inj" + +Example: + + switch@1010000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "mscc,ocelot-switch"; + reg = <0x1010000 0x10000>, + <0x1030000 0x10000>, + <0x1080000 0x100>, + <0x10d0000 0x10000>, + <0x11e0000 0x100>, + <0x11f0000 0x100>, + <0x1200000 0x100>, + <0x1210000 0x100>, + <0x1220000 0x100>, + <0x1230000 0x100>, + <0x1240000 0x100>, + <0x1250000 0x100>, + <0x1260000 0x100>, + <0x1270000 0x100>, + <0x1280000 0x100>, + <0x1800000 0x80000>, + <0x1880000 0x10000>; + reg-names = "sys", "rew", "qs", "hsio", "port0", + "port1", "port2", "port3", "port4", "port5", + "port6", "port7", "port8", "port9", "port10", + "qsys", "ana"; + interrupts = <21 22>;
Documentation/devicetree/bindings/net/mscc-ocelot.txt line 61
Quoted 10 lines
Documentation/devicetree/bindings/net/mscc-ocelot.txt new file +10
-0+ interrupt-names = "xtr", "inj"; + + port0: port@0 { + reg = <0>; + phy-handle = <&phy0>; + }; + port1: port@1 { + reg = <1>; + phy-handle = <&phy1>; + };
Hi Alexandre
Is there anything else in the switch which in the future might need child nodes? At the moment, you can do for_each_available_child_of_node() and walk the ports. But if you do need to add some other sorts of children in the future it gets messy. With DSA, we have a ports {} container.
Andrew
Re: [PATCH net-next 1/8] net: phy: Add initial support for Microsemi Ocelot internal PHYs.
In reply to Alexandre BelloniQuoted 27 lines · Alexandre Belloni
Add Microsemi Ocelot internal PHY ids. For now, simply use the genphy functions but more features are available.
Cc Raju Lakkaraju <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>--- drivers/net/phy/mscc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)drivers/net/phy/mscc.c +3
-0@@ -91,6 +91,7 @@ enum rgmii_rx_clock_delay {#define SECURE_ON_PASSWD_LEN_4 0x4000/* Microsemi PHY ID's */ +#define PHY_ID_OCELOT 0x00070540#define PHY_ID_VSC8530 0x00070560#define PHY_ID_VSC8531 0x00070570#define PHY_ID_VSC8540 0x00070760@@ -658,6 +659,19 @@ static int vsc85xx_probe(struct phy_device *phydev)/* Microsemi VSC85xx PHYs */ static struct phy_driver vsc85xx_driver[] = { +{ + .phy_id =PHY_ID_OCELOT ,
drivers/net/phy/mscc.c static int vsc85xx_probe(struct phy_device *phydev) · line 673
Quoted 10 lines
drivers/net/phy/mscc.c +10
-0+ .name = "Microsemi OCELOT", + .phy_id_mask = 0xfffffff0, + .features = PHY_GBIT_FEATURES, + .soft_reset = &genphy_soft_reset, + .config_init = &genphy_config_init, + .config_aneg = &genphy_config_aneg, + .aneg_done = &genphy_aneg_done, + .read_status = &genphy_read_status, + .suspend = &genphy_suspend, + .resume = &genphy_resume,
With the exception of config_init(), suspend and resume, everything else is already the default when you don't provide a callback. To echo to what Andrew wrote already, if the purpose is just to show a nice name, and do nothing else, consider using the Generic PHY driver (default).
Signature · 1 line
Florian
Re: [PATCH net-next 4/8] dt-bindings: net: add DT bindings for Microsemi Ocelot Switch
In reply to Alexandre BelloniQuoted 27 lines · Alexandre Belloni
DT bindings for the Ethernet switch found on Microsemi Ocelot platforms.
Cc Rob Herring <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>--- .../devicetree/bindings/net/mscc-ocelot.txt | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/mscc-ocelot.txtDocumentation/devicetree/bindings/net/mscc-ocelot.txt new file +12
-0@@ -0,0 +1,62 @@ +Microsemi Ocelot network Switch +=============================== + +The Microsemi Ocelot network switch can be found on Microsemi SoCs (VSC7513, +VSC7514) + +Required properties: +- compatible: Should be "mscc,ocelot-switch" +- reg: Must contain an (offset, length) pair of the register set for each + entry in reg-names. +- reg-names: Must include the following entries: + - "sys"
Documentation/devicetree/bindings/net/mscc-ocelot.txt line 22
Quoted 10 lines
Documentation/devicetree/bindings/net/mscc-ocelot.txt new file +10
-0+ - "rew" + - "qs" + - "hsio" + - "qsys" + - "ana" + - "portX" with X from 0 to the number of last port index available on that + switch +- interrupts: Should contain the switch interrupts for frame extraction and + frame injection +- interrupt-names: should contain the interrupt names: "xtr", "inj"
You are not documenting the "ports" subnode(s).Please move the individual ports definition under a ports subnode, mainly for two reasons:
- it makes it easy at the .dtsi level to have all ports disabled by default
- this makes you strictly conforming to the DSA binding for Ethernet switches and this is good for consistency (both parsing code and just representation).
Signature · 1 line
Florian
Re: [PATCH net-next 6/8] MIPS: mscc: Add switch to ocelot
In reply to Alexandre BelloniQuoted 33 lines · Alexandre Belloni
Ocelot has an integrated switch, add support for it.
Cc James Hogan <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>--- arch/mips/boot/dts/mscc/ocelot.dtsi | 84 +++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+)arch/mips/boot/dts/mscc/ocelot.dtsi +17
-0@@ -91,6 +91,69 @@ status = "disabled"; }; + switch@1010000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "mscc,ocelot-switch"; + reg = <0x1010000 0x10000>, + <0x1030000 0x10000>, + <0x1080000 0x100>, + <0x10d0000 0x10000>, + <0x11e0000 0x100>, + <0x11f0000 0x100>, + <0x1200000 0x100>, + <0x1210000 0x100>, + <0x1220000 0x100>, + <0x1230000 0x100>, + <0x1240000 0x100>, + <0x1250000 0x100>, + <0x1260000 0x100>,
arch/mips/boot/dts/mscc/ocelot.dtsi line 120
Quoted 10 lines
arch/mips/boot/dts/mscc/ocelot.dtsi +10
-0+ <0x1270000 0x100>, + <0x1280000 0x100>, + <0x1800000 0x80000>, + <0x1880000 0x10000>; + reg-names = "sys", "rew", "qs", "hsio", "port0", + "port1", "port2", "port3", "port4", "port5", + "port6", "port7", "port8", "port9", "port10", + "qsys", "ana"; + interrupts = <21 22>; + interrupt-names = "xtr", "inj";
See my comment about the binding patch, this should be moved to a ports subnode so it is conforming to the existing DSA binding and makes it a lot easier to have all ports disabled by default at the .dsti level by not defini
Quoted 40 lines
arch/mips/boot/dts/mscc/ocelot.dtsi +36
-0+ + port0: port@0 { + reg = <0>; + }; + port1: port@1 { + reg = <1>; + }; + port2: port@2 { + reg = <2>; + }; + port3: port@3 { + reg = <3>; + }; + port4: port@4 { + reg = <4>; + }; + port5: port@5 { + reg = <5>; + }; + port6: port@6 { + reg = <6>; + }; + port7: port@7 { + reg = <7>; + }; + port8: port@8 { + reg = <8>; + }; + port9: port@9 { + reg = <9>; + }; + port10: port@10 { + reg = <10>; + }; + }; + reset@1070008 { compatible = "mscc,ocelot-chip-reset"; reg = <0x1070008 0x4>;
arch/mips/boot/dts/mscc/ocelot.dtsi line 185
Quoted 10 lines
arch/mips/boot/dts/mscc/ocelot.dtsi +7
-0@@ -113,5 +176,26 @@ function = "uart2"; }; }; + + mdio0: mdio@107009c { + #address-cells = <1>; + #size-cells = <0>; + compatible = "mscc,ocelot-miim"; + reg = <0x107009c 0x36>, <0x10700f0 0x8>; + interrupts = <14>;
status = "disabled" by default?
arch/mips/boot/dts/mscc/ocelot.dtsi line 198
Quoted 13 lines
arch/mips/boot/dts/mscc/ocelot.dtsi +13
-0+ + phy0: ethernet-phy@0 { + reg = <0>; + }; + phy1: ethernet-phy@1 { + reg = <1>; + }; + phy2: ethernet-phy@2 { + reg = <2>; + }; + phy3: ethernet-phy@3 { + reg = <3>; + };
These PHYs should be defined at the board DTS level.
Signature · 1 line
Florian
Alexandre Belloni
maintainerRe: [PATCH net-next 6/8] MIPS: mscc: Add switch to ocelot
Quoted 16 lines · Florian Fainelli
arch/mips/boot/dts/mscc/ocelot.dtsi line 198
Quoted 13 lines · Alexandre Belloni
arch/mips/boot/dts/mscc/ocelot.dtsi +13
-0+ + phy0: ethernet-phy@0 { + reg = <0>; + }; + phy1: ethernet-phy@1 { + reg = <1>; + }; + phy2: ethernet-phy@2 { + reg = <2>; + }; + phy3: ethernet-phy@3 { + reg = <3>; + };These PHYs should be defined at the board DTS level.
Those are internal PHYs, present on the SoC, I doubt anyone will have anything different while using the same SoC.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Andrew Lunn
maintainerRe: [PATCH net-next 5/8] net: mscc: Add initial Ocelot switch support
In reply to Alexandre BelloniHi Alexandre
Quoted 6 lines
drivers/net/ethernet/mscc/ocelot.c new file +6
-0+static int ocelot_port_bridge_join (struct ocelot_port *ocelot_port, +struct net_device *bridge) +{ +struct ocelot *ocelot = ocelot_port->ocelot; + +if (!ocelot->bridge_mask) {
drivers/net/ethernet/mscc/ocelot.c line 1114
Quoted 10 lines
drivers/net/ethernet/mscc/ocelot.c new file +10
-0+ ocelot->hw_bridge_dev = bridge; + }else { +if (ocelot->hw_bridge_dev != bridge) +return -ENODEV ;//TODO: do something clever here + } + + ocelot->bridge_mask |=BIT (ocelot_port->chip_port); + +return 0 ; +}
I could be missing something here, but this looks way too simple.
By default, you have individual ports. They can just forward frames between the host CPU and the port. There is no port-to-port traffic allowed.
You then create a bridge, and add ports to the bridge. When you add a port, you need to program the hardware that it can now forward frames from this port to other parts in the same bridge. You also need to tell other parts in the same bridge it can forward frames to it. You might also need to tell the port which forwarding database it should use, since each bridge might have its own.
Andrew
Andrew Lunn
maintainerRe: [PATCH net-next 6/8] MIPS: mscc: Add switch to ocelot
In reply to Alexandre BelloniQuoted 18 lines · Alexandre Belloni
Quoted 16 lines · Florian Fainelli
arch/mips/boot/dts/mscc/ocelot.dtsi line 198
Quoted 13 lines · Alexandre Belloni
arch/mips/boot/dts/mscc/ocelot.dtsi +13
-0+ + phy0: ethernet-phy@0 { + reg = <0>; + }; + phy1: ethernet-phy@1 { + reg = <1>; + }; + phy2: ethernet-phy@2 { + reg = <2>; + }; + phy3: ethernet-phy@3 { + reg = <3>; + };These PHYs should be defined at the board DTS level.
Quoted 2 lines
Those are internal PHYs, present on the SoC, I doubt anyone will have anything different while using the same SoC.
With DSA, there is no need to list internal PHYs.
That is the trade off of having a standalone MDIO bus driver. Maybe add a phandle to the internal MDIO bus? The switch driver could then follow the phandle, and direct connect the internal PHYs?
Andrew
Re: [PATCH net-next 5/8] net: mscc: Add initial Ocelot switch support
In reply to Alexandre BelloniQuoted 10 lines · Alexandre Belloni
Add a driver for Microsemi Ocelot Ethernet switch support.
This makes two modules:
mscc_ocelot_commonhandles all the common features that doesn't depend on how the switch is integrated in the SoC. Currently, it handles offloading bridging to the hardware.ocelot_io.chandles register accesses. This is unfortunately needed because the register layout is packed and then depends on the number of ports available on the switch. The register definition files are automatically generated.
Quoted 7 lines
ocelot_boardhandles the switch integration on the SoC and on the board.Frame injection and extraction to/from the CPU port is currently done using register accesses which is quite slow. DMA is possible but the port is not able to absorb the whole switch bandwidth.
Signed-off-by Alexandre Belloni <[email protected]>
Random drive by comments because this is quite a number of lines to review!
Overall, looks quite good for a first version. Out of curiosity, is there a particular switch test you ran this driver against? LNST?
Quoted 10 lines
drivers/net/ethernet/mscc/ocelot.c new file +10
-0+static int ocelot_mact_learn (struct ocelot *ocelot,int port, +const unsigned char mac[ETH_ALEN ], +unsigned int vid, +enum macaccess_entry_type type) +{ +u32 macl =0 , mach =0 ; + +/* Set the MAC address to learn and the vlan associated in a format +* understood by the hardware. +*/
drivers/net/ethernet/mscc/ocelot.c line 92
Quoted 10 lines
drivers/net/ethernet/mscc/ocelot.c new file +10
-0+ mach |= vid <<16 ; + mach |= mac[0 ] <<8 ; + mach |= mac[1 ] <<0 ; + macl |= mac[2 ] <<24 ; + macl |= mac[3 ] <<16 ; + macl |= mac[4 ] <<8 ; + macl |= mac[5 ] <<0 ; + +ocelot_write (ocelot, macl,ANA_TABLES_MACLDATA ); +ocelot_write (ocelot, mach,ANA_TABLES_MACHDATA );
You are repeating this in the function right below, can you factor it somehow into a common function that this one, and the one right below could call?
[snip]
drivers/net/ethernet/mscc/ocelot.c line 188
Quoted 2 lines
drivers/net/ethernet/mscc/ocelot.c new file +2
-0+static void ocelot_port_adjust_link (struct net_device *dev) +{
This is fine for now, but I would suggest implementing PHYLINK to be future proof.
[snip]
drivers/net/ethernet/mscc/ocelot.c line 342
Quoted 7 lines
drivers/net/ethernet/mscc/ocelot.c new file +7
-0+static int ocelot_port_stop (struct net_device *dev) +{ +struct ocelot_port *port =netdev_priv (dev); + +phy_disconnect (port->phy); + + dev->phydev =NULL ;
You don't have anything else to do, like disabling the port so it possibly saves power or anything, aside from the PHY which will be suspended here.
[snip]
drivers/net/ethernet/mscc/ocelot.c line 375
Quoted 8 lines
drivers/net/ethernet/mscc/ocelot.c new file +8
-0+static int ocelot_port_xmit (struct sk_buff *skb,struct net_device *dev) +{ +struct ocelot_port *port =netdev_priv (dev); +struct ocelot *ocelot = port->ocelot; +u32 val, ifh[IFH_LEN ]; +struct frame_info info = {}; +u8 grp =0 ;/* Send everything on CPU group 0 */ +int i, count, last;
unsigned int for these types.
Quoted 32 lines
drivers/net/ethernet/mscc/ocelot.c new file +32
-0+ + val =ocelot_read (ocelot,QS_INJ_STATUS ); +if (!(val &QS_INJ_STATUS_FIFO_RDY (BIT (grp))) || + (val &QS_INJ_STATUS_WMARK_REACHED (BIT (grp)))) +return NETDEV_TX_BUSY ; + +ocelot_write_rix (ocelot,QS_INJ_CTRL_GAP_SIZE (1 ) | +QS_INJ_CTRL_SOF ,QS_INJ_CTRL , grp); + + info.port =BIT (port->chip_port); + info.cpuq =0xff ; +ocelot_gen_ifh (ifh, &info); + +for (i =0 ; i <IFH_LEN ; i++) +ocelot_write_rix (ocelot, ifh[i],QS_INJ_WR , grp); + + count = (skb->len +3 ) /4 ; + last = skb->len %4 ; +for (i =0 ; i < count; i++) { +ocelot_write_rix (ocelot,cpu_to_le32 (((u32 *)skb->data)[i]), +QS_INJ_WR , grp); + } + +/* Add padding */ +while (i < (OCELOT_BUFFER_CELL_SZ /4 )) { +ocelot_write_rix (ocelot,0 ,QS_INJ_WR , grp); + i++; + } + +/* Indicate EOF and valid bytes in last word */ + ocelot_write_rix(ocelot, QS_INJ_CTRL_GAP_SIZE(1) | + QS_INJ_CTRL_VLD_BYTES(skb->len < OCELOT_BUFFER_CELL_SZ ? 0 : last) |
drivers/net/ethernet/mscc/ocelot.c line 417
Quoted 10 lines
drivers/net/ethernet/mscc/ocelot.c new file +10
-0+QS_INJ_CTRL_EOF , + QS_INJ_CTRL, grp); + +/* Add dummy CRC */ +ocelot_write_rix (ocelot,0 ,QS_INJ_WR , grp); +skb_tx_timestamp (skb); + + dev->stats.tx_packets++; + dev->stats.tx_bytes += skb->len; +dev_kfree_skb_any (skb);
No interrupt to indicate transmit completion?
Quoted 11 lines
drivers/net/ethernet/mscc/ocelot.c new file +11
-0+static int ocelot_fdb_add (struct ndmsg *ndm,struct nlattr *tb[], +struct net_device *dev,const unsigned char *addr, +u16 vid,u16 flags) +{ +struct ocelot_port *port =netdev_priv (dev); +struct ocelot *ocelot = port->ocelot; + +if (!vid) { +if (!port->vlan_aware) +/* If the bridge is not VLAN aware and no VID was +* provided, set it to 1 as bridges have a default VID
drivers/net/ethernet/mscc/ocelot.c line 568
Quoted 10 lines
drivers/net/ethernet/mscc/ocelot.c new file +10
-0+* of 1. Otherwise the MAC entry wouldn't match incoming +* packets as the VID would differ (0 != 1). +*/ + vid =1 ; + else +/* If the bridge is VLAN aware a VID must be provided as +* otherwise the learnt entry wouldn't match any frame. +*/ + return -EINVAL; + }
So if we are targeting vid = 0 we end-up with vid = 1 possibly?
[snip]
Quoted 18 lines
drivers/net/ethernet/mscc/ocelot.c new file +18
-0+static int ocelot_port_attr_stp_state_set (struct ocelot_port *ocelot_port, +struct switchdev_trans *trans, +u8 state) +{ +struct ocelot *ocelot = ocelot_port->ocelot; +u32 port_cfg; +int port, i; + +if (switchdev_trans_ph_prepare (trans)) +return 0 ; + +if (!(BIT (ocelot_port->chip_port) & ocelot->bridge_mask)) +return 0 ; + + port_cfg =ocelot_read_gix (ocelot,ANA_PORT_PORT_CFG , + ocelot_port->chip_port); + +switch (state) {
drivers/net/ethernet/mscc/ocelot.c line 866
Quoted 10 lines
drivers/net/ethernet/mscc/ocelot.c new file +10
-0+case BR_STATE_FORWARDING : + ocelot->bridge_fwd_mask |=BIT (ocelot_port->chip_port); +/* Fallthrough */ +case BR_STATE_LEARNING : + port_cfg |=ANA_PORT_PORT_CFG_LEARN_ENA ; +break ; + +default : + port_cfg &= ~ANA_PORT_PORT_CFG_LEARN_ENA ; + ocelot->bridge_fwd_mask &= ~BIT (ocelot_port->chip_port);
Missing break, even if this is the default case.
Quoted 25 lines
drivers/net/ethernet/mscc/ocelot.c new file +25
-0+ } + +ocelot_write_gix (ocelot, port_cfg,ANA_PORT_PORT_CFG , + ocelot_port->chip_port); + +/* Apply FWD mask. The loop is needed to add/remove the current port as +* a source for the other ports. +*/ +for (port =0 ; port < ocelot->num_phys_ports; port++) { +if (ocelot->bridge_fwd_mask &BIT (port)) { +unsigned long mask = ocelot->bridge_fwd_mask & ~BIT (port); + +for (i =0 ; i < ocelot->num_phys_ports; i++) { +unsigned long bond_mask = ocelot->lags[i]; + +if (!bond_mask) +continue ; + +if (bond_mask &BIT (port)) { + mask &= ~bond_mask; +break ; + } + } + + ocelot_write_rix(ocelot,
drivers/net/ethernet/mscc/ocelot.c line 901
Quoted 10 lines
drivers/net/ethernet/mscc/ocelot.c new file +10
-0+BIT (ocelot->num_phys_ports) | mask, + ANA_PGID_PGID, PGID_SRC + port); + }else { +/* Only the CPU port, this is compatible with link +* aggregation. +*/ +ocelot_write_rix (ocelot, +BIT (ocelot->num_phys_ports), +ANA_PGID_PGID ,PGID_SRC + port); + }
All of this sounds like it should be moved into the br_join/leave, this does not appear to be the right place to do that.
[snip]
drivers/net/ethernet/mscc/ocelot.c line 941
Quoted 6 lines
drivers/net/ethernet/mscc/ocelot.c new file +6
-0+static int ocelot_port_attr_set (struct net_device *dev, +const struct switchdev_attr *attr, +struct switchdev_trans *trans) +{ +struct ocelot_port *ocelot_port =netdev_priv (dev); +int err =0 ;
Should not this be EOPNOTSUPP by default so your cases below are properly handled, like BRIDGE_FLAGS, MROUTER etc.
Quoted 52 lines
drivers/net/ethernet/mscc/ocelot.c new file +50
-0+ +switch (attr->id) { +case SWITCHDEV_ATTR_ID_PORT_STP_STATE : +ocelot_port_attr_stp_state_set (ocelot_port, trans, + attr->u.stp_state); +break ; +case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS : +break ; +case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME : +ocelot_port_attr_ageing_set (ocelot_port, attr->u.ageing_time); +break ; +case SWITCHDEV_ATTR_ID_PORT_MROUTER : +break ; +case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED : +ocelot_port_attr_mc_set (ocelot_port, !attr->u.mc_disabled); +break ; +default : + err = -EOPNOTSUPP ; +break ; + } + +return err; +} + +static struct ocelot_multicast *ocelot_multicast_get (struct ocelot *ocelot, +const unsigned char *addr, +u16 vid) +{ +struct ocelot_multicast *mc; + +list_for_each_entry (mc, &ocelot->multicast, list) { +if (ether_addr_equal (mc->addr, addr) && mc->vid == vid) +return mc; + } + +return NULL ; +} +static irqreturn_t ocelot_xtr_irq_handler (int irq,void *arg) +{ +struct ocelot *ocelot = arg; +int i =0 , grp =0 ; +int err =0 ; + +if (!(ocelot_read (ocelot,QS_XTR_DATA_PRESENT ) &BIT (grp))) +return IRQ_NONE ; + + do { + struct sk_buff *skb; + struct net_device *dev; + u32 *buf;
drivers/net/ethernet/mscc/ocelot.c line 1005
Quoted 10 lines
drivers/net/ethernet/mscc/ocelot.c new file +10
-0+int sz, len; +u32 ifh[4 ]; +u32 val; +struct frame_info info; + +for (i =0 ; i <IFH_LEN ; i++) { + err =ocelot_rx_frame_word (ocelot, grp, true, &ifh[i]); +if (err !=4 ) +break ; + }
NAPI maybe?
[snip]
drivers/net/ethernet/mscc/ocelot_board.c line 196
Quoted 3 lines
drivers/net/ethernet/mscc/ocelot_board.c new file +3
-0+ ocelot->targets[SYS ] =ocelot_io_platform_init (ocelot, pdev,"sys" ); +if (IS_ERR (ocelot->targets[SYS ])) +return PTR_ERR (ocelot->targets[SYS ]);
You can clearly make this in a loop instead of repeating this section, you just need an array of register names to be looking for.
[snip]
drivers/net/ethernet/mscc/ocelot_board.c line 263
Quoted 1 line
drivers/net/ethernet/mscc/ocelot_board.c new file +1
-0+if (np) {
Please rework the indentation here, check for !np
drivers/net/ethernet/mscc/ocelot_board.c line 264
Quoted 1 line
drivers/net/ethernet/mscc/ocelot_board.c new file +1
-0+for_each_child_of_node (np, portnp) {
for_each_available_child_of_node() you should be able to mark specific ports as being disabled and skip over these accordingly.
[snip]
drivers/net/ethernet/mscc/ocelot_io.c line 65
Quoted 4 lines
drivers/net/ethernet/mscc/ocelot_io.c new file +4
-0+int ocelot_regfields_init (struct ocelot *ocelot, +const struct reg_field *const regfields) +{ +int i;
unsigned int i
Signature · 1 line
Florian
Re: [PATCH net-next 6/8] MIPS: mscc: Add switch to ocelot
In reply to Andrew LunnQuoted 19 lines · Andrew Lunn
Quoted 18 lines · Alexandre Belloni
Quoted 16 lines · Florian Fainelli
arch/mips/boot/dts/mscc/ocelot.dtsi line 198
Quoted 13 lines · Alexandre Belloni
arch/mips/boot/dts/mscc/ocelot.dtsi +13
-0+ + phy0: ethernet-phy@0 { + reg = <0>; + }; + phy1: ethernet-phy@1 { + reg = <1>; + }; + phy2: ethernet-phy@2 { + reg = <2>; + }; + phy3: ethernet-phy@3 { + reg = <3>; + };These PHYs should be defined at the board DTS level.
Quoted 8 lines
Quoted 2 lines
Those are internal PHYs, present on the SoC, I doubt anyone will have anything different while using the same SoC.
With DSA, there is no need to list internal PHYs.
That is the trade off of having a standalone MDIO bus driver. Maybe add a phandle to the internal MDIO bus? The switch driver could then follow the phandle, and direct connect the internal PHYs?
This is more or less what patch 7 does, right?
Signature · 1 line
Florian
Re: [PATCH net-next 2/8] dt-bindings: net: add DT bindings for Microsemi MIIM
In reply to Alexandre BelloniQuoted 16 lines · Alexandre Belloni
DT bindings for the Microsemi MII Management Controller found on Microsemi SoCs
Cc Rob Herring <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>--- .../devicetree/bindings/net/mscc-miim.txt | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/mscc-miim.txtDocumentation/devicetree/bindings/net/mscc-miim.txt new file +0
-0
Documentation/devicetree/bindings/net/mscc-miim.txt line 10
Quoted 10 lines
Documentation/devicetree/bindings/net/mscc-miim.txt new file +10
-0@@ -0,0 +1,25 @@ +Microsemi MII Management Controller (MIIM) / MDIO +================================================= + +Properties: +- compatible: must be "mscc,ocelot-miim" +- reg: The base address of the MDIO bus controller register bank. Optionally, a + second register bank can be defined if there is an associated reset register + for internal PHYs +- #address-cells: Must be <1>. +- #size-cells: Must be <0>. MDIO addresses have no size component.
Missing interrupt property documentation (sorry), other than that:
Signature · 1 line
Florian
Re: [PATCH net-next 3/8] net: mscc: Add MDIO driver
In reply to Alexandre BelloniQuoted 134 lines · Alexandre Belloni
Add a driver for the Microsemi MII Management controller (MIIM) found on Microsemi SoCs.
On Ocelot, there are two controllers, one is connected to the internal PHYs, the other one can communicate with external PHYs.Signed-off-by Alexandre Belloni <[email protected]>--- drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/mscc/Kconfig | 22 ++++ drivers/net/ethernet/mscc/Makefile | 2 + drivers/net/ethernet/mscc/mscc_miim.c | 210 ++++++++++++++++++++++++++++++++++ 5 files changed, 236 insertions(+) create mode 100644 drivers/net/ethernet/mscc/Kconfig create mode 100644 drivers/net/ethernet/mscc/Makefile create mode 100644 drivers/net/ethernet/mscc/mscc_miim.cdrivers/net/ethernet/Kconfig +1
-0@@ -115,6 +115,7 @@ source "drivers/net/ethernet/mediatek/Kconfig" source "drivers/net/ethernet/mellanox/Kconfig" source "drivers/net/ethernet/micrel/Kconfig" source "drivers/net/ethernet/microchip/Kconfig" +source "drivers/net/ethernet/mscc/Kconfig" source "drivers/net/ethernet/moxa/Kconfig" source "drivers/net/ethernet/myricom/Kconfig"drivers/net/ethernet/Makefile +1
-0@@ -56,6 +56,7 @@ obj-$(CONFIG_NET_VENDOR_MEDIATEK) += mediatek/ obj-$(CONFIG_NET_VENDOR_MELLANOX) += mellanox/ obj-$(CONFIG_NET_VENDOR_MICREL) += micrel/ obj-$(CONFIG_NET_VENDOR_MICROCHIP) += microchip/ +obj-$(CONFIG_NET_VENDOR_MICROSEMI) += mscc/ obj-$(CONFIG_NET_VENDOR_MOXART) += moxa/ obj-$(CONFIG_NET_VENDOR_MYRI) += myricom/ obj-$(CONFIG_FEALNX) += fealnx.odrivers/net/ethernet/mscc/Kconfig new file +22
-0@@ -0,0 +1,22 @@ +# SPDX-License-Identifier: (GPL-2.0 OR MIT) +config NET_VENDOR_MICROSEMI + bool "Microsemi devices" + default y + help + If you have a network (Ethernet) card belonging to this class, say Y. + + Note that the answer to this question doesn't directly affect the + kernel: saying N will just cause the configurator to skip all + the questions about Microsemi devices. + +if NET_VENDOR_MICROSEMI + +config MSCC_MIIM + tristate "Microsemi MIIM interface support" + depends on HAS_IOMEM + select PHYLIB + help + This driver supports the MIIM (MDIO) interface found in the network + switches of the Microsemi SoCs + +endif # NET_VENDOR_MICROSEMIdrivers/net/ethernet/mscc/Makefile new file +2
-0@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: (GPL-2.0 OR MIT) +obj-$(CONFIG_MSCC_MIIM) += mscc_miim.odrivers/net/ethernet/mscc/mscc_miim.c new file +51
-0@@ -0,0 +1,210 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) +/* +* Driver for the MDIO interface of Microsemi network switches. +* +* Author: Alexandre Belloni <[email protected]> +* Copyright (c) 2017 Microsemi Corporation +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/phy.h> +#include <linux/platform_device.h> +#include <linux/bitops.h> +#include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/of_mdio.h> + +#define MSCC_MIIM_REG_STATUS 0x0 +#define MSCC_MIIM_STATUS_STAT_BUSY BIT(3) +#define MSCC_MIIM_REG_CMD 0x8 +#define MSCC_MIIM_CMD_OPR_WRITE BIT(1) +#define MSCC_MIIM_CMD_OPR_READ BIT(2) +#define MSCC_MIIM_CMD_WRDATA_SHIFT 4 +#define MSCC_MIIM_CMD_REGAD_SHIFT 20 +#define MSCC_MIIM_CMD_PHYAD_SHIFT 25 +#define MSCC_MIIM_CMD_VLD BIT(31) +#define MSCC_MIIM_REG_DATA 0xC +#define MSCC_MIIM_DATA_ERROR (BIT(16) | BIT(17)) + +#define MSCC_PHY_REG_PHY_CFG 0x0 +#define PHY_CFG_PHY_ENA (BIT(0) | BIT(1) | BIT(2) | BIT(3)) +#define PHY_CFG_PHY_COMMON_RESET BIT(4) +#define PHY_CFG_PHY_RESET (BIT(5) | BIT(6) | BIT(7) | BIT(8)) +#define MSCC_PHY_REG_PHY_STATUS 0x4 + +struct mscc_miim_dev { +struct mutex lock; +void __iomem *regs; +void __iomem *phy_regs; +}; + +static int mscc_miim_wait_ready (struct mii_bus *bus) +{ +struct mscc_miim_dev *miim = bus->priv; +u32 val; + +readl_poll_timeout (miim->regs +MSCC_MIIM_REG_STATUS , val, + !(val &MSCC_MIIM_STATUS_STAT_BUSY ),100 ,250000 ); +if (val &MSCC_MIIM_STATUS_STAT_BUSY ) +return -ETIMEDOUT ; +
drivers/net/ethernet/mscc/mscc_miim.c line 61
Quoted 10 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +10
-0+return 0 ; +} + +static int mscc_miim_read (struct mii_bus *bus,int mii_id,int regnum) +{ +struct mscc_miim_dev *miim = bus->priv; +u32 val; +int ret; + +mutex_lock (&miim->lock);
What is this lock for considering that bus->lock should always be acquired when doing these operations? As Andrew pointed out, needs to be initialized with mutex_init(), but likely you would drop it.
drivers/net/ethernet/mscc/mscc_miim.c line 73
Quoted 12 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +12
-0+ + ret =mscc_miim_wait_ready (bus); +if (ret) + goto out; + +writel (MSCC_MIIM_CMD_VLD | (mii_id <<MSCC_MIIM_CMD_PHYAD_SHIFT ) | + (regnum <<MSCC_MIIM_CMD_REGAD_SHIFT ) |MSCC_MIIM_CMD_OPR_READ , + miim->regs +MSCC_MIIM_REG_CMD ); + + ret =mscc_miim_wait_ready (bus); +if (ret) + goto out;
Your example had an interrupt specified, can't you use that instead of polling?
Quoted 30 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +30
-0+ + val =readl (miim->regs +MSCC_MIIM_REG_DATA ); +if (val &MSCC_MIIM_DATA_ERROR ) { + ret = -EIO ; + goto out; + } + + ret = val &0xFFFF ; +out: +mutex_unlock (&miim->lock); +return ret; +} + +static int mscc_miim_write (struct mii_bus *bus,int mii_id, +int regnum,u16 value) +{ +struct mscc_miim_dev *miim = bus->priv; +int ret; + +mutex_lock (&miim->lock); + + ret =mscc_miim_wait_ready (bus); +if (ret <0 ) + goto out; + +writel (MSCC_MIIM_CMD_VLD | (mii_id <<MSCC_MIIM_CMD_PHYAD_SHIFT ) | + (regnum <<MSCC_MIIM_CMD_REGAD_SHIFT ) | + (value <<MSCC_MIIM_CMD_WRDATA_SHIFT ) | +MSCC_MIIM_CMD_OPR_WRITE , + miim->regs +MSCC_MIIM_REG_CMD );
drivers/net/ethernet/mscc/mscc_miim.c line 113
Quoted 10 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +10
-0+ +out: +mutex_unlock (&miim->lock); +return ret; +} + +static int mscc_miim_reset (struct mii_bus *bus) +{ +struct mscc_miim_dev *miim = bus->priv; +int i;
unsigned int i
drivers/net/ethernet/mscc/mscc_miim.c line 124
Quoted 11 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +11
-0+ +if (miim->phy_regs) { +writel (0 , miim->phy_regs +MSCC_PHY_REG_PHY_CFG ); +writel (0x1ff , miim->phy_regs +MSCC_PHY_REG_PHY_CFG ); +mdelay (500 ); + } + +for (i =0 ; i <PHY_MAX_ADDR ; i++) { +if (mscc_miim_read (bus, i,MII_PHYSID1 ) <0 ) + bus->phy_mask |=BIT (i); + }
What is this used for? You have an OF MDIO bus which would create a phy_device for each node specified, is this a similar workaround to what drivers/net/phy/mdio-bcm-unimac.c has to do? If so, please document it as such.
Other than that, this looks quite good!
Signature · 1 line
Florian
Andrew Lunn
maintainerRe: [PATCH net-next 6/8] MIPS: mscc: Add switch to ocelot
In reply to Florian FainelliQuoted 5 lines
Quoted 3 lines
That is the trade off of having a standalone MDIO bus driver. Maybe add a phandle to the internal MDIO bus? The switch driver could then follow the phandle, and direct connect the internal PHYs?
This is more or less what patch 7 does, right?
Patch 7 does it in DT. I'm suggesting it could be done in C. It is hard wired, so there is no need to describe it in DT. Use the phandle to get the mdio bus, mdiobus_get_phy(, port) to get the phydev and then use phy_connect().
Andrew
Re: [PATCH net-next 6/8] MIPS: mscc: Add switch to ocelot
Quoted 10 lines · Andrew Lunn
Quoted 5 lines
Quoted 3 lines
That is the trade off of having a standalone MDIO bus driver. Maybe add a phandle to the internal MDIO bus? The switch driver could then follow the phandle, and direct connect the internal PHYs?
This is more or less what patch 7 does, right?
Patch 7 does it in DT. I'm suggesting it could be done in C. It is hard wired, so there is no need to describe it in DT. Use the phandle to get the mdio bus,
mdiobus_get_phy(, port)to get the phydev and then usephy_connect().
That does not sound like a great idea. And to go back to your example about DSA, it is partially true, you will see some switch bindings defining the internal PHYs (e.g: qca8k), and most not doing it (b53, mv88e6xxx, etc.). In either case, this resolves to the same thing though. Being able to parse a phy-handle property is a lot more flexible, and if it does matter that the PHY truly is internal, then the 'phy-mode' property can help reflect that.
Signature · 1 line
Florian
Andrew Lunn
maintainerRe: [PATCH net-next 6/8] MIPS: mscc: Add switch to ocelot
Quoted 12 lines · Florian Fainelli
Quoted 10 lines · Andrew Lunn
Quoted 5 lines
Quoted 3 lines
That is the trade off of having a standalone MDIO bus driver. Maybe add a phandle to the internal MDIO bus? The switch driver could then follow the phandle, and direct connect the internal PHYs?
This is more or less what patch 7 does, right?
Patch 7 does it in DT. I'm suggesting it could be done in C. It is hard wired, so there is no need to describe it in DT. Use the phandle to get the mdio bus,
mdiobus_get_phy(, port)to get the phydev and then usephy_connect().
Quoted 7 lines
That does not sound like a great idea. And to go back to your example about DSA, it is partially true, you will see some switch bindings defining the internal PHYs (e.g: qca8k), and most not doing it (b53, mv88e6xxx, etc.). In either case, this resolves to the same thing though. Being able to parse a phy-handle property is a lot more flexible, and if it does matter that the PHY truly is internal, then the 'phy-mode' property can help reflect that.
Hi Florian
With DSA, you can always provide a phy-handle. It is only when there is nothing specified that the fallback case is used to map internal PHYs to ports.
Putting internal PHYs in DT is fine, but it is a nice simplification if it is not needed.
Andrew
kbuild test robot
build botRe: [PATCH net-next 5/8] net: mscc: Add initial Ocelot switch support
In reply to Alexandre BelloniI love your patch! Perhaps something to improve:
Hi Alexandre,
I love your patch! Perhaps something to improve:
[auto build test WARNING on next-20180323]
[also build test WARNING on v4.16-rc7]
[cannot apply to net-next/master net/master robh/for-next v4.16-rc6 v4.16-rc5 v4.16-rc4] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Alexandre-Belloni/Microsemi-Ocelot-switch-support/20180325-234932
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__sparse warnings: (new ones prefixed by >>)
>> drivers/net/ethernet/mscc/ocelot.c:395:17: sparse: incorrect type in argument 2 (different base types) @@ expected unsigned int [unsigned] [usertype] val @@ got ed int [unsigned] [usertype] val @@ drivers/net/ethernet/mscc/ocelot.c:395:17: expected unsigned int [unsigned] [usertype] val drivers/net/ethernet/mscc/ocelot.c:395:17: got restricted __le32 [usertype] <noident> -- >> drivers/net/ethernet/mscc/ocelot_io.c:110:24: sparse: incorrect type in return expression (different address spaces) @@ expected struct regmap * @@ got void [noderef] <asnstruct regmap * @@ drivers/net/ethernet/mscc/ocelot_io.c:110:24: expected struct regmap * drivers/net/ethernet/mscc/ocelot_io.c:110:24: got void [noderef] <asn:2>*[assigned] regs -- >> drivers/net/ethernet/mscc/ocelot_board.c:41:26: sparse: cast to restricted __be32 >> drivers/net/ethernet/mscc/ocelot_board.c:41:26: sparse: cast to restricted __be32 >> drivers/net/ethernet/mscc/ocelot_board.c:41:26: sparse: cast to restricted __be32 >> drivers/net/ethernet/mscc/ocelot_board.c:41:26: sparse: cast to restricted __be32 >> drivers/net/ethernet/mscc/ocelot_board.c:41:26: sparse: cast to restricted __be32 >> drivers/net/ethernet/mscc/ocelot_board.c:41:26: sparse: cast to restricted __be32 >> drivers/net/ethernet/mscc/ocelot_board.c:142:34: sparse: cast to restricted __le32
vim +395 drivers/net/ethernet/mscc/ocelot.c
367
368 static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)
369 {
370 struct ocelot_port *port = netdev_priv(dev);
371 struct ocelot *ocelot = port->ocelot;
372 u32 val, ifh[IFH_LEN];
373 struct frame_info info = {};
374 u8 grp = 0; /* Send everything on CPU group 0 */
375 int i, count, last;
376
377 val = ocelot_read(ocelot, QS_INJ_STATUS);
378 if (!(val & QS_INJ_STATUS_FIFO_RDY(BIT(grp))) ||
379 (val & QS_INJ_STATUS_WMARK_REACHED(BIT(grp))))
380 return NETDEV_TX_BUSY;
381
382 ocelot_write_rix(ocelot, QS_INJ_CTRL_GAP_SIZE(1) |
383 QS_INJ_CTRL_SOF, QS_INJ_CTRL, grp);
384
385 info.port = BIT(port->chip_port);
386 info.cpuq = 0xff;
387 ocelot_gen_ifh(ifh, &info);
388
389 for (i = 0; i < IFH_LEN; i++)
390 ocelot_write_rix(ocelot, ifh[i], QS_INJ_WR, grp);
391
392 count = (skb->len + 3) / 4;
393 last = skb->len % 4;
394 for (i = 0; i < count; i++) {
> 395 ocelot_write_rix(ocelot, cpu_to_le32(((u32 *)skb->data)[i]),
396 QS_INJ_WR, grp);
397 }
398
399 /* Add padding */
400 while (i < (OCELOT_BUFFER_CELL_SZ / 4)) {
401 ocelot_write_rix(ocelot, 0, QS_INJ_WR, grp);
402 i++;
403 }
404
405 /* Indicate EOF and valid bytes in last word */
406 ocelot_write_rix(ocelot, QS_INJ_CTRL_GAP_SIZE(1) |
407 QS_INJ_CTRL_VLD_BYTES(skb->len < OCELOT_BUFFER_CELL_SZ ? 0 : last) |
408 QS_INJ_CTRL_EOF,
409 QS_INJ_CTRL, grp);
410
411 /* Add dummy CRC */
412 ocelot_write_rix(ocelot, 0, QS_INJ_WR, grp);
413 skb_tx_timestamp(skb);
414
415 dev->stats.tx_packets++;
416 dev->stats.tx_bytes += skb->len;
417 dev_kfree_skb_any(skb);
418
419 return NETDEV_TX_OK;
420 }
421
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Rob Herring
maintainerRe: [PATCH net-next 4/8] dt-bindings: net: add DT bindings for Microsemi Ocelot Switch
In reply to Florian FainelliQuoted 42 lines · Florian Fainelli
Quoted 27 lines · Alexandre Belloni
DT bindings for the Ethernet switch found on Microsemi Ocelot platforms.
Cc Rob Herring <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>--- .../devicetree/bindings/net/mscc-ocelot.txt | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/mscc-ocelot.txtDocumentation/devicetree/bindings/net/mscc-ocelot.txt new file +12
-0@@ -0,0 +1,62 @@ +Microsemi Ocelot network Switch +=============================== + +The Microsemi Ocelot network switch can be found on Microsemi SoCs (VSC7513, +VSC7514) + +Required properties: +- compatible: Should be "mscc,ocelot-switch" +- reg: Must contain an (offset, length) pair of the register set for each + entry in reg-names. +- reg-names: Must include the following entries: + - "sys"Documentation/devicetree/bindings/net/mscc-ocelot.txt line 22
Quoted 10 lines
Documentation/devicetree/bindings/net/mscc-ocelot.txt new file +10
-0+ - "rew" + - "qs" + - "hsio" + - "qsys" + - "ana" + - "portX" with X from 0 to the number of last port index available on that + switch +- interrupts: Should contain the switch interrupts for frame extraction and + frame injection +- interrupt-names: should contain the interrupt names: "xtr", "inj"You are not documenting the "ports" subnode(s).Please move the individual ports definition under a ports subnode, mainly for two reasons:
Quoted 5 lines
- it makes it easy at the .dtsi level to have all ports disabled by default
- this makes you strictly conforming to the DSA binding for Ethernet switches and this is good for consistency (both parsing code and just representation).
ports and port collide with the OF graph binding. It would be good if this moved to ethernet-port(s) or similar.
Rob
Rob Herring
maintainerRe: [PATCH net-next 4/8] dt-bindings: net: add DT bindings for Microsemi Ocelot Switch
In reply to Alexandre BelloniQuoted 15 lines · Alexandre Belloni
DT bindings for the Ethernet switch found on Microsemi Ocelot platforms.
Cc Rob Herring <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>--- .../devicetree/bindings/net/mscc-ocelot.txt | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/mscc-ocelot.txtDocumentation/devicetree/bindings/net/mscc-ocelot.txt new file +0
-0
Documentation/devicetree/bindings/net/mscc-ocelot.txt line 5
Quoted 5 lines
Documentation/devicetree/bindings/net/mscc-ocelot.txt new file +5
-0@@ -0,0 +1,62 @@ +Microsemi Ocelot network Switch +=============================== + +The Microsemi Ocelot network switch can be found on Microsemi SoCs (VSC7513, +VSC7514)
What's the difference in these SoCs? You should probably have the part#'s in the compatible string.
Quoted 60 lines
Documentation/devicetree/bindings/net/mscc-ocelot.txt new file +57
-0+ +Required properties: +- compatible: Should be "mscc,ocelot-switch" +- reg: Must contain an (offset, length) pair of the register set for each + entry in reg-names. +- reg-names: Must include the following entries: + - "sys" + - "rew" + - "qs" + - "hsio" + - "qsys" + - "ana" + - "portX" with X from 0 to the number of last port index available on that + switch +- interrupts: Should contain the switch interrupts for frame extraction and + frame injection +- interrupt-names: should contain the interrupt names: "xtr", "inj" + +Example: + + switch@1010000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "mscc,ocelot-switch"; + reg = <0x1010000 0x10000>, + <0x1030000 0x10000>, + <0x1080000 0x100>, + <0x10d0000 0x10000>, + <0x11e0000 0x100>, + <0x11f0000 0x100>, + <0x1200000 0x100>, + <0x1210000 0x100>, + <0x1220000 0x100>, + <0x1230000 0x100>, + <0x1240000 0x100>, + <0x1250000 0x100>, + <0x1260000 0x100>, + <0x1270000 0x100>, + <0x1280000 0x100>, + <0x1800000 0x80000>, + <0x1880000 0x10000>; + reg-names = "sys", "rew", "qs", "hsio", "port0", + "port1", "port2", "port3", "port4", "port5", + "port6", "port7", "port8", "port9", "port10", + "qsys", "ana"; + interrupts = <21 22>; + interrupt-names = "xtr", "inj"; + + port0: port@0 { + reg = <0>; + phy-handle = <&phy0>; + }; + port1: port@1 { + reg = <1>; + phy-handle = <&phy1>; + }; + };Signature · 1 line
2.16.2
Andrew Lunn
maintainerRe: [PATCH net-next 4/8] dt-bindings: net: add DT bindings for Microsemi Ocelot Switch
In reply to Rob HerringQuoted 2 lines
ports and port collide with the OF graph binding. It would be good if this moved to ethernet-port(s) or similar.
Hi Rob
Well, we have been using port in DSA since March 2013. ports is a bit newer, June 2016.
Changing DSA is not going to happen. But new switch bindings could use ethernet-port(s). It just makes them inconsistent with existing switch drivers.
Andrew
Rob Herring
maintainerRe: [PATCH net-next 4/8] dt-bindings: net: add DT bindings for Microsemi Ocelot Switch
Quoted 7 lines · Andrew Lunn
Quoted 2 lines
ports and port collide with the OF graph binding. It would be good if this moved to ethernet-port(s) or similar.
Hi Rob
Well, we have been using port in DSA since March 2013. ports is a bit newer, June 2016.
Yes, understood.
Quoted 4 lines
Changing DSA is not going to happen. But new switch bindings could use ethernet-port(s). It just makes them inconsistent with existing switch drivers.
I'm not saying to change existing bindings, but evolve to something that doesn't collide on new bindings if you don't have dependencies on what the node names are. It's mainly so we can have something to key off of to validate bindings better.
Rob
Alexandre Belloni
maintainerRe: [PATCH net-next 1/8] net: phy: Add initial support for Microsemi Ocelot internal PHYs.
In reply to Florian FainelliQuoted 35 lines · Florian Fainelli
Quoted 34 lines · Alexandre Belloni
Add Microsemi Ocelot internal PHY ids. For now, simply use the genphy functions but more features are available.
Cc Raju Lakkaraju <[email protected]>Signed-off-by Alexandre Belloni <[email protected]>--- drivers/net/phy/mscc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)drivers/net/phy/mscc.c +10
-0@@ -91,6 +91,7 @@ enum rgmii_rx_clock_delay {#define SECURE_ON_PASSWD_LEN_4 0x4000/* Microsemi PHY ID's */ +#define PHY_ID_OCELOT 0x00070540#define PHY_ID_VSC8530 0x00070560#define PHY_ID_VSC8531 0x00070570#define PHY_ID_VSC8540 0x00070760@@ -658,6 +659,19 @@ static int vsc85xx_probe(struct phy_device *phydev)/* Microsemi VSC85xx PHYs */ static struct phy_driver vsc85xx_driver[] = { +{ + .phy_id =PHY_ID_OCELOT , + .name ="Microsemi OCELOT" , + .phy_id_mask =0xfffffff0 , + .features =PHY_GBIT_FEATURES , + .soft_reset = &genphy_soft_reset, + .config_init = &genphy_config_init, + .config_aneg = &genphy_config_aneg, + .aneg_done = &genphy_aneg_done,
Quoted 8 lines
drivers/net/phy/mscc.c static int vsc85xx_probe(struct phy_device *phydev) · line 673
Quoted 3 lines
drivers/net/phy/mscc.c +3
-0+ .read_status = &genphy_read_status, + .suspend = &genphy_suspend, + .resume = &genphy_resume,With the exception of
config_init(), suspend and resume, everything else is already the default when you don't provide a callback. To echo to what Andrew wrote already, if the purpose is just to show a nice name, and do nothing else, consider using the Generic PHY driver (default).
Ok, I'll drop this patch for now, until we handle more features for that PHY.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Alexandre Belloni
maintainerRe: [PATCH net-next 3/8] net: mscc: Add MDIO driver
In reply to Andrew LunnQuoted 36 lines · Andrew Lunn
Quoted 4 lines · Alexandre Belloni
Add a driver for the Microsemi MII Management controller (MIIM) found on Microsemi SoCs.
On Ocelot, there are two controllers, one is connected to the internal PHYs, the other one can communicate with external PHYs.Hi Alexandre
This looks to be standalone. Such drivers we try to put in
drivers/net/phy.drivers/net/ethernet/mscc/mscc_miim.c line 61
Quoted 7 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +7
-0+static int mscc_miim_read (struct mii_bus *bus,int mii_id,int regnum) +{ +struct mscc_miim_dev *miim = bus->priv; +u32 val; +int ret; + +mutex_lock (&miim->lock);What are you locking against here?
And you don't appear to initialize the mutex anywhere.
Quoted 13 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +13
-0+static int mscc_miim_reset (struct mii_bus *bus) +{ +struct mscc_miim_dev *miim = bus->priv; +int i; + +if (miim->phy_regs) { +writel (0 , miim->phy_regs +MSCC_PHY_REG_PHY_CFG ); +writel (0x1ff , miim->phy_regs +MSCC_PHY_REG_PHY_CFG ); +mdelay (500 ); + } + +for (i =0 ; i <PHY_MAX_ADDR ; i++) { +if (mscc_miim_read (bus, i,MII_PHYSID1 ) <0 )
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ bus->phy_mask |= BIT(i); + }Why do this? Especially so for the external bus, where the PHYs might have a GPIO reset line, and won't respond until the gpio is released. The core code does that just before it scans the bus, or just before it scans the particular address on the bus, depending on the scope of the GPIO.
IIRC, this was needed when probing the bus without DT, in that case, the mdiobus_scan loop of __mdiobus_register() will fail when doing the get_phy_id for phys 0 to 31 because get_phy_id() transforms any error in -EIO and so it is impossible to register the bus. Other drivers have a similar code to handle that case.
Anyway, I'll remove that loop for now because I'm only supporting DT. I'll get back to that later.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Alexandre Belloni
maintainerRe: [PATCH net-next 3/8] net: mscc: Add MDIO driver
In reply to Florian FainelliQuoted 11 lines · Florian Fainelli
drivers/net/ethernet/mscc/mscc_miim.c line 73
Quoted 7 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +7
-0+writel (MSCC_MIIM_CMD_VLD | (mii_id <<MSCC_MIIM_CMD_PHYAD_SHIFT ) | + (regnum <<MSCC_MIIM_CMD_REGAD_SHIFT ) |MSCC_MIIM_CMD_OPR_READ , + miim->regs +MSCC_MIIM_REG_CMD ); + + ret =mscc_miim_wait_ready (bus); +if (ret) + goto out;Your example had an interrupt specified, can't you use that instead of polling?
the interrupt doesn't handle that. It is used to detect when a PHY register has changed once the MIIM controller is configured to poll the phys. At some point, this could be used to replace the PHY interrupts but it doesn't correspond to the linux model so I didn't investigate too much.
Quoted 10 lines
drivers/net/ethernet/mscc/mscc_miim.c line 124
Quoted 4 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +4
-0+for (i =0 ; i <PHY_MAX_ADDR ; i++) { +if (mscc_miim_read (bus, i,MII_PHYSID1 ) <0 ) + bus->phy_mask |=BIT (i); + }What is this used for? You have an OF MDIO bus which would create a
phy_devicefor each node specified, is this a similar workaround to whatdrivers/net/phy/mdio-bcm-unimac.chas to do? If so, please document it as such.
I replied to Andrew who had the same question.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Andrew Lunn
maintainerRe: [PATCH net-next 3/8] net: mscc: Add MDIO driver
In reply to Alexandre BelloniQuoted 47 lines · Alexandre Belloni
Quoted 36 lines · Andrew Lunn
Quoted 4 lines · Alexandre Belloni
Add a driver for the Microsemi MII Management controller (MIIM) found on Microsemi SoCs.
On Ocelot, there are two controllers, one is connected to the internal PHYs, the other one can communicate with external PHYs.Hi Alexandre
This looks to be standalone. Such drivers we try to put in
drivers/net/phy.drivers/net/ethernet/mscc/mscc_miim.c line 61
Quoted 7 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +7
-0+static int mscc_miim_read (struct mii_bus *bus,int mii_id,int regnum) +{ +struct mscc_miim_dev *miim = bus->priv; +u32 val; +int ret; + +mutex_lock (&miim->lock);What are you locking against here?
And you don't appear to initialize the mutex anywhere.
Quoted 13 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +13
-0+static int mscc_miim_reset (struct mii_bus *bus) +{ +struct mscc_miim_dev *miim = bus->priv; +int i; + +if (miim->phy_regs) { +writel (0 , miim->phy_regs +MSCC_PHY_REG_PHY_CFG ); +writel (0x1ff , miim->phy_regs +MSCC_PHY_REG_PHY_CFG ); +mdelay (500 ); + } + +for (i =0 ; i <PHY_MAX_ADDR ; i++) { +if (mscc_miim_read (bus, i,MII_PHYSID1 ) <0 )Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ bus->phy_mask |= BIT(i); + }Why do this? Especially so for the external bus, where the PHYs might have a GPIO reset line, and won't respond until the gpio is released. The core code does that just before it scans the bus, or just before it scans the particular address on the bus, depending on the scope of the GPIO.
Quoted 5 lines
IIRC, this was needed when probing the bus without DT, in that case, the
mdiobus_scanloop of__mdiobus_register()will fail when doing theget_phy_idfor phys 0 to 31 becauseget_phy_id()transforms any error in-EIOand so it is impossible to register the bus. Other drivers have a similar code to handle that case.
Hi Alexandre
Do you mean mscc_miim_read() will return -EIO if there is no device on the bus at the address trying to be read? Most devices just return 0xffff because there is a pull up on the data line, nothing is driving it, so all 1's are read.
It sounds like the correct fix is for get_phy_id() to look at the error code for mdiobus_read(bus, addr, MII_PHYSID1). If it is EIO and maybe ENODEV, set *phy_id to 0xffffffff and return. The scan code should then do the correct thing.
Andrew
Alexandre Belloni
maintainerRe: [PATCH net-next 3/8] net: mscc: Add MDIO driver
Quoted 18 lines · Andrew Lunn
Quoted 12 lines
Quoted 11 lines
drivers/net/ethernet/mscc/mscc_miim.c line 124
Quoted 4 lines
drivers/net/ethernet/mscc/mscc_miim.c new file +4
-0+for (i =0 ; i <PHY_MAX_ADDR ; i++) { +if (mscc_miim_read (bus, i,MII_PHYSID1 ) <0 ) + bus->phy_mask |=BIT (i); + }Why do this? Especially so for the external bus, where the PHYs might have a GPIO reset line, and won't respond until the gpio is released. The core code does that just before it scans the bus, or just before it scans the particular address on the bus, depending on the scope of the GPIO.
Quoted 5 lines
IIRC, this was needed when probing the bus without DT, in that case, the
mdiobus_scanloop of__mdiobus_register()will fail when doing theget_phy_idfor phys 0 to 31 becauseget_phy_id()transforms any error in-EIOand so it is impossible to register the bus. Other drivers have a similar code to handle that case.
Quoted 7 lines
Hi Alexandre
Do you mean
mscc_miim_read()will return-EIOif there is no device on the bus at the address trying to be read? Most devices just return0xffffbecause there is a pull up on the data line, nothing is driving it, so all 1's are read.
It will return -EIO but I tried to be clever and return -ENODEV but this gets changed to -EIO by get_phy_id.
Quoted 5 lines
It sounds like the correct fix is for
get_phy_id()to look at the error code formdiobus_read(bus, addr, MII_PHYSID1). If it is EIO and maybe ENODEV, set*phy_idto0xffffffffand return. The scan code should then do the correct thing.
That could work indeed. Do you want me to test and send a patch?
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Andrew Lunn
maintainerRe: [PATCH net-next 3/8] net: mscc: Add MDIO driver
Quoted 7 lines
Quoted 5 lines
It sounds like the correct fix is for
get_phy_id()to look at the error code formdiobus_read(bus, addr, MII_PHYSID1). If it is EIO and maybe ENODEV, set*phy_idto0xffffffffand return. The scan code should then do the correct thing.That could work indeed. Do you want me to test and send a patch?
Yes please.
Thanks
Andrew
RE: [PATCH net-next 5/8] net: mscc: Add initial Ocelot switch support
In reply to Alexandre BelloniHello Alexandre,
Quoted 4 lines
drivers/net/ethernet/mscc/ocelot_board.c new file +4
-0+ +register_netdevice_notifier (&ocelot_netdevice_nb); + +dev_info (&pdev->dev,"Ocelot switch probed\n" );
drivers/net/ethernet/mscc/ocelot_board.c line 311
Quoted 10 lines
drivers/net/ethernet/mscc/ocelot_board.c new file +10
-0+ +return 0 ; + +err_probe_ports: +return err; +} + +static int mscc_ocelot_remove (struct platform_device *pdev) +{ +unregister_netevent_notifier (&ocelot_netdevice_nb);
This should be replaced with a call to unregister_netdevice_notifier(). And also makes the inclusion of net/netevent.h not necessary.
Best regards,
Razvan
Alexandre Belloni
maintainerRe: [PATCH net-next 5/8] net: mscc: Add initial Ocelot switch support
In reply to Florian FainelliQuoted 17 lines · Florian Fainelli
Quoted 16 lines · Alexandre Belloni
Add a driver for Microsemi Ocelot Ethernet switch support.
This makes two modules:
mscc_ocelot_commonhandles all the common features that doesn't depend on how the switch is integrated in the SoC. Currently, it handles offloading bridging to the hardware.ocelot_io.chandles register accesses. This is unfortunately needed because the register layout is packed and then depends on the number of ports available on the switch. The register definition files are automatically generated.
ocelot_boardhandles the switch integration on the SoC and on the board.Frame injection and extraction to/from the CPU port is currently done using register accesses which is quite slow. DMA is possible but the port is not able to absorb the whole switch bandwidth.
Quoted 7 lines
Quoted 1 line
Signed-off-by Alexandre Belloni <[email protected]>Random drive by comments because this is quite a number of lines to review!
Overall, looks quite good for a first version. Out of curiosity, is there a particular switch test you ran this driver against? LNST?
We have a really small custom test suite.
Quoted 10 lines
drivers/net/ethernet/mscc/ocelot.c line 417
Quoted 7 lines
drivers/net/ethernet/mscc/ocelot.c new file +7
-0+/* Add dummy CRC */ +ocelot_write_rix (ocelot,0 ,QS_INJ_WR , grp); +skb_tx_timestamp (skb); + + dev->stats.tx_packets++; + dev->stats.tx_bytes += skb->len; +dev_kfree_skb_any (skb);No interrupt to indicate transmit completion?
No, unfortunately, the TX interrupts only indicates there is room to start injecting frames, not that they have been transmitted.
Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/mscc/ocelot.c new file +15
-0+static int ocelot_fdb_add (struct ndmsg *ndm,struct nlattr *tb[], +struct net_device *dev,const unsigned char *addr, +u16 vid,u16 flags) +{ +struct ocelot_port *port =netdev_priv (dev); +struct ocelot *ocelot = port->ocelot; + +if (!vid) { +if (!port->vlan_aware) +/* If the bridge is not VLAN aware and no VID was +* provided, set it to 1 as bridges have a default VID +* of 1. Otherwise the MAC entry wouldn't match incoming +* packets as the VID would differ (0 != 1). +*/ + vid =1 ;
Quoted 9 lines
drivers/net/ethernet/mscc/ocelot.c line 568
Quoted 6 lines
drivers/net/ethernet/mscc/ocelot.c new file +6
-0+else +/* If the bridge is VLAN aware a VID must be provided as +* otherwise the learnt entry wouldn't match any frame. +*/ +return -EINVAL ; + }So if we are targeting vid = 0 we end-up with vid = 1 possibly?
I've removed that part that is not needed for now and will rework when sending VLAN support.
Quoted 28 lines
Quoted 28 lines
drivers/net/ethernet/mscc/ocelot.c new file +28
-0+ocelot_write_gix (ocelot, port_cfg,ANA_PORT_PORT_CFG , + ocelot_port->chip_port); + +/* Apply FWD mask. The loop is needed to add/remove the current port as +* a source for the other ports. +*/ +for (port =0 ; port < ocelot->num_phys_ports; port++) { +if (ocelot->bridge_fwd_mask &BIT (port)) { +unsigned long mask = ocelot->bridge_fwd_mask & ~BIT (port); + +for (i =0 ; i < ocelot->num_phys_ports; i++) { +unsigned long bond_mask = ocelot->lags[i]; + +if (!bond_mask) +continue ; + +if (bond_mask &BIT (port)) { + mask &= ~bond_mask; +break ; + } + } + +ocelot_write_rix (ocelot, +BIT (ocelot->num_phys_ports) | mask, +ANA_PGID_PGID ,PGID_SRC + port); + }else { +/* Only the CPU port, this is compatible with link +* aggregation.
Quoted 9 lines
drivers/net/ethernet/mscc/ocelot.c line 901
Quoted 5 lines
drivers/net/ethernet/mscc/ocelot.c new file +5
-0+*/ +ocelot_write_rix (ocelot, +BIT (ocelot->num_phys_ports), +ANA_PGID_PGID ,PGID_SRC + port); + }All of this sounds like it should be moved into the br_join/leave, this does not appear to be the right place to do that.
No, I've triple checked because this is a comment that both Andrew and you had. Once a port is added to the PGID MASK, it will start forwarding frames so we really want that to happen only when the port is in BR_STATE_FORWARDING state. Else, we may forward frames between the addition of the port to the bridge and setting the port to the BR_STATE_BLOCKING state.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Andrew Lunn
maintainerRe: [PATCH net-next 5/8] net: mscc: Add initial Ocelot switch support
Quoted 10 lines
Quoted 3 lines
All of this sounds like it should be moved into the br_join/leave, this does not appear to be the right place to do that.
No, I've triple checked because this is a comment that both Andrew and you had. Once a port is added to the PGID MASK, it will start forwarding frames so we really want that to happen only when the port is in
BR_STATE_FORWARDINGstate. Else, we may forward frames between the addition of the port to the bridge and setting the port to theBR_STATE_BLOCKINGstate.
Hi Alexandre
Interesting observation. I took a look at some of the other join implementations. mv88e6xxx does the join immediately. mt7539 does it immediately, if the port is enabled. lan9303 does it immediately. qca8k does it immediately. b53 does it immediately.
Either they all get it wrong, or we make the assumption the bridge sets the STP state first, then has the port join the bridge.
Looking at the code, br_add_if() it callsnetdev_master_upper_dev_link() and then later
if (netif_running(dev) && netif_oper_up(dev) &&
(br->dev->flags & IFF_UP))
br_stp_enable_port(p);So it does look like there is a window of time between the port joining and the STP state being set.
I know in the past, we have run into the opposite problem. A port leaves the bridge, while in blocked state. The port should then becomes an individual port, so the STP state needs setting to forwarding. I don't remember where we fix this.
I don't like that this new driver is different, but it also looks like we have a real problem here. More digging needed.
Andrew
Alexandre Belloni
maintainerRe: [PATCH net-next 5/8] net: mscc: Add initial Ocelot switch support
Quoted 11 lines · Andrew Lunn
Quoted 10 lines
Quoted 3 lines
All of this sounds like it should be moved into the br_join/leave, this does not appear to be the right place to do that.
No, I've triple checked because this is a comment that both Andrew and you had. Once a port is added to the PGID MASK, it will start forwarding frames so we really want that to happen only when the port is in
BR_STATE_FORWARDINGstate. Else, we may forward frames between the addition of the port to the bridge and setting the port to theBR_STATE_BLOCKINGstate.
Quoted 7 lines
Hi Alexandre
Interesting observation. I took a look at some of the other join implementations. mv88e6xxx does the join immediately. mt7539 does it immediately, if the port is enabled. lan9303 does it immediately. qca8k does it immediately. b53 does it immediately.
I had a look at b53, my impression was that b53_br_join() adds the port to the bridge but b53_br_set_stp_state() actually enables forwarding. So as long as the default on the port is PORT_CTRL_DIS_STATE, the port will not be forwarding frames. And this is the case because b53_enable_port() does put 0 in B53_PORT_CTRL.
The fact is that ocelot doesn't have separate controls. The port is either forwarding or not. If it is not forwarding, then there is nothing to tell the HW to do.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Andrew Lunn
maintainerRe: [PATCH net-next 5/8] net: mscc: Add initial Ocelot switch support
Quoted 20 lines · Alexandre Belloni
Quoted 11 lines · Andrew Lunn
Quoted 10 lines
Quoted 3 lines
All of this sounds like it should be moved into the br_join/leave, this does not appear to be the right place to do that.
No, I've triple checked because this is a comment that both Andrew and you had. Once a port is added to the PGID MASK, it will start forwarding frames so we really want that to happen only when the port is in
BR_STATE_FORWARDINGstate. Else, we may forward frames between the addition of the port to the bridge and setting the port to theBR_STATE_BLOCKINGstate.Quoted 7 lines
Hi Alexandre
Interesting observation. I took a look at some of the other join implementations. mv88e6xxx does the join immediately. mt7539 does it immediately, if the port is enabled. lan9303 does it immediately. qca8k does it immediately. b53 does it immediately.
Quoted 5 lines
I had a look at b53, my impression was that
b53_br_join()adds the port to the bridge butb53_br_set_stp_state()actually enables forwarding. So as long as the default on the port isPORT_CTRL_DIS_STATE, the port will not be forwarding frames. And this is the case becauseb53_enable_port()does put 0 inB53_PORT_CTRL.
https://elixir.bootlin.com/linux/latest/source/drivers/net/dsa/b53/b53_regs.h#L71
It seems like, 0 means no STP at all. Which to me would mean, forward all packets. But i could be wrong. Florian?
Quoted 3 lines
The fact is that ocelot doesn't have separate controls. The port is either forwarding or not. If it is not forwarding, then there is nothing to tell the HW to do.
Think about the following sequence:
ip link set lan0 up
After this command, i expect to see packets on lan0 arrive at the host, tcpdump to work, etc. This probably means the port is in 'forwarding' mode, or for B53, STP is disabled.
ip link add name br0 type bridge
ip link set dev br0 up
ip link set dev lan0 master br0
When the port is added to the bridge, there is a window of time between the join and the STP change to blocking/learning, when the port is in forwarding mode. You avoid this window. But the other drivers don't appear to.
So i would like to fix this of every driver. I'm not sure how yet...
Andrew
Re: [PATCH net-next 5/8] net: mscc: Add initial Ocelot switch support
Le 03/30/18 à 07:50, Andrew Lunn a écrit :
Quoted 27 lines · Alexandre Belloni
Quoted 20 lines · Andrew Lunn
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines
All of this sounds like it should be moved into the br_join/leave, this does not appear to be the right place to do that.
No, I've triple checked because this is a comment that both Andrew and you had. Once a port is added to the PGID MASK, it will start forwarding frames so we really want that to happen only when the port is in
BR_STATE_FORWARDINGstate. Else, we may forward frames between the addition of the port to the bridge and setting the port to theBR_STATE_BLOCKINGstate.Quoted 7 lines
Hi Alexandre
Interesting observation. I took a look at some of the other join implementations. mv88e6xxx does the join immediately. mt7539 does it immediately, if the port is enabled. lan9303 does it immediately. qca8k does it immediately. b53 does it immediately.
Quoted 5 lines
I had a look at b53, my impression was that
b53_br_join()adds the port to the bridge butb53_br_set_stp_state()actually enables forwarding. So as long as the default on the port isPORT_CTRL_DIS_STATE, the port will not be forwarding frames. And this is the case becauseb53_enable_port()does put 0 inB53_PORT_CTRL.
Quoted 4 lines
https://elixir.bootlin.com/linux/latest/source/drivers/net/dsa/b53/b53_regs.h#L71
It seems like, 0 means no STP at all. Which to me would mean, forward all packets. But i could be wrong. Florian?
Correct, 0 disables STP and therefore means forward all packets.
Quoted 5 lines
Quoted 4 lines
The fact is that ocelot doesn't have separate controls. The port is either forwarding or not. If it is not forwarding, then there is nothing to tell the HW to do.
Quoted 7 lines
Think about the following sequence:
ip link set lan0 up
After this command, i expect to see packets on lan0 arrive at the host, tcpdump to work, etc. This probably means the port is in 'forwarding' mode, or for B53, STP is disabled.
In net/dsa/port.c::dsa_port_enable we have the following:
u8 stp_state = dp->bridge_dev ? BR_STATE_BLOCKING : BR_STATE_FORWARDING;
Quoted 11 lines
ip link add name br0 type bridge
ip link set dev br0 up
ip link set dev lan0 master br0When the port is added to the bridge, there is a window of time between the join and the STP change to blocking/learning, when the port is in forwarding mode. You avoid this window. But the other drivers don't appear to.
So i would like to fix this of every driver. I'm not sure how yet...
Agreed, there does appear to be a window like you outlined in your example if the port was already UP where we may be in an inconsistent STP state. This window does not appear to be existing in case the port was not UP prior to joining the bridge though.
It seems to me like the most natural place where to fix this would be in the bridge code, but this has the potential to break several drivers so within the scope of DSA, it might be as simple as this:
net/dsa/port.c +0 -0
@@ -116,6 +116,8 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct
net_device *br)
if (err)
dp->bridge_dev = NULL;+ dsa_port_set_state_now(dp, BR_STATE_BLOCKING);
+
return err;
}
Signature · 1 line
Florian
Alexandre Belloni
maintainerRe: [PATCH net-next 5/8] net: mscc: Add initial Ocelot switch support
In reply to Andrew LunnI realise now that I didn't reply to this comment:
Quoted 4 lines · Andrew Lunn
Quoted 3 lines
The fact is that ocelot doesn't have separate controls. The port is either forwarding or not. If it is not forwarding, then there is nothing to tell the HW to do.
Quoted 8 lines
Think about the following sequence:
ip link set lan0 up
After this command, i expect to see packets on lan0 arrive at the host, tcpdump to work, etc. This probably means the port is in 'forwarding' mode, or for B53, STP is disabled.
On Ocelot, forwarding packets to the host (i.e. forwarding frames received on the port to the cpu port) is separate from bridging ports together. So after that command, the host can receive packets on lan0.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com