Skip to contentSkip to conversation

net: dsa: MT7628 embedded switch initial support

RFC In review Joris Vaisvila 3 participants 9 messages Mar 21 – Mar 23

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

v3 cover net: dsa: MT7628 embedded switch initial support

Hi all,

This RFC series adds initial support for the MT7628 Embedded Switch.

The implementation provides basic functionality required to operate the switch using DSA. The hardware exposes 5 internal Fast Ethernet ports and a Gigabit port which is internally connected to the CPU MAC.

This version aims to be functionally complete and attempts to address all feedback received on the previous versions.

Tested on a MT7628NN based board.

RFC:

I would like to transition this series toward a proper PATCH submission as it seems that the feedback on the last RFC did not point out major issues. As this is my first driver submission, I would greatly appreciate any guidance on what should be addressed before it is appropriate to send this in as a PATCH.

Thank you for your time and review.

---

v3:
- add DTS bindings for mediatek,mt7628-esw
- update tagging driver to use htons instead of manual byte swapping
- remove port 5 from config as it doesn't exist in the hardware
- fix code formatting
- add helper macros for configuring packed VLAN table registers
- fix mac_capabilities for cpu port, replace supported_interfaces with PHY_INTERFACE_INTERNAL to accurately reflect the hardware
- update MEDIATEK_GE_SOC_PHY tristate name, fix sorting
- remove unneeded PHY_PACKAGE from MEDIATEK_FE_SOC_PHY Kconfig
- remove untested features from mtk-fe-soc.c phy driver

v2: https://lore.kernel.org/netdev/[email protected]
- Update commit messages with more relevant information
- Change all references of "special" tag to "MT7628" tag
- Fix coding style errors
- Use dsa_xmit_port_mask instead of BIT(dp->index)
- Replace phy_read/phy_write with an MDIO bus definition
- Remove PHY init from switch driver
- Fix undocumented writes to SGC2 and FCT0
- Fix missing double-tag enable required for VLAN unaware functionality
- Fix VLAN remove logic
- Update VLAN add logic to use the first unused slot
- Add a dedicated phy driver for MT7628 FE PHYs

v1: https://lore.kernel.org/netdev/[email protected]

Joris Vaisvila (4):
dt-bindings: net: dsa: add MT7628 ESW
net: phy: mediatek: add phy driver for MT7628 built-in Fast Ethernet
PHYs
net: dsa: initial MT7628 tagging driver
net: dsa: initial support for MT7628 embedded switch

 .../bindings/net/dsa/mediatek,mt7628-esw.yaml | 136 ++++
 drivers/net/dsa/Kconfig                       |   7 +
 drivers/net/dsa/Makefile                      |   1 +
 drivers/net/dsa/mt7628.c                      | 634 ++++++++++++++++++
 drivers/net/phy/mediatek/Kconfig              |  10 +-
 drivers/net/phy/mediatek/Makefile             |   1 +
 drivers/net/phy/mediatek/mtk-fe-soc.c         |  50 ++
 include/net/dsa.h                             |   2 +
 net/dsa/Kconfig                               |   6 +
 net/dsa/Makefile                              |   1 +
 net/dsa/tag_mt7628.c                          |  92 +++
 11 files changed, 939 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml
 create mode 100644 drivers/net/dsa/mt7628.c
 create mode 100644 drivers/net/phy/mediatek/mtk-fe-soc.c
 create mode 100644 net/dsa/tag_mt7628.c
Signature · 1 line
2.53.0
#1 lore raw

RFC v3 1/4 dt-bindings: net: dsa: add MT7628 ESW

Add bindings for MT7628 SoC's Embedded Switch.

---
 .../bindings/net/dsa/mediatek,mt7628-esw.yaml | 136 ++++++++++++++++++
 1 file changed, 136 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +136 -0
new file mode 100644
index 000000000000..5955c07a1be7
@@ -0,0 +1,136 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/dsa/mediatek,mt7628-esw.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek MT7628 Embedded Ethernet Switch
+
+maintainers:
+  - Joris Vaisvila <[email protected]>
+
+description:
+  The MT7628 SoC's built-in Ethernet Switch is a five port switch with
+  integrated 10/100 PHYs. The switch registers are directly mapped in the SoC's
+  memory. The switch has an internally connected 1G CPU port and 5 user ports
+  connected to the built-in Fast Ethernet PHYs.
+
+unevaluatedProperties: false
+
+allOf:
+  - $ref: dsa.yaml#/$defs/ethernet-ports
+
+properties:
+  compatible:
+    const: mediatek,mt7628-esw
+
+  reg:
+    maxItems: 1
+    description: MMIO address of the switch
+
+  resets:
+    items:
+      - description: Phandle of system reset controller with ESW reset index
+      - description: Phandle of system reset controller with EPHY reset index
+
+  reset-names:
+    items:
+      - const: esw
+      - const: ephy
+
+  mdio:
+    $ref: /schemas/net/mdio.yaml#
+    unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - resets
+  - reset-names
+
+examples:
+  - |
+    switch0: switch@10110000 {
+        reg = <0x10110000 0x8000>;
+
+        resets = <&sysc 23>, <&sysc 24>;
+        reset-names = "esw", "ephy";
+
+        compatible = "mediatek,mt7628-esw";
+
+        ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            port@0 {
+                reg = <0>;
+                label = "swp0";
+                phy-handle = <&swp0_phy>;
+                phy-mode = "internal";
+            };
+
+            port@1 {
+                reg = <1>;
+                label = "swp1";
+                phy-handle = <&swp1_phy>;
+                phy-mode = "internal";
+            };
+
+            port@2 {
+                reg = <2>;
+                label = "swp2";
+                phy-handle = <&swp2_phy>;
+                phy-mode = "internal";
+            };
+
+            port@3 {
+                reg = <3>;
+                label = "swp3";
+                phy-handle = <&swp3_phy>;
+                phy-mode = "internal";
+            };
+
+            port@4 {
+                reg = <4>;
+                label = "swp4";
+                phy-handle = <&swp4_phy>;
+                phy-mode = "internal";
+            };
+
+            port@6 {
+                reg = <6>;
+                ethernet = <&ethernet>;
+                phy-mode = "rgmii";
+
+                fixed-link {
+                    speed = <1000>;
+                    full-duplex;
+                };
+            };
+        };
+
+        mdio {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            swp0_phy: swp0_phy@0 {
+                reg = <0>;
+            };
+
+            swp1_phy: swp1_phy@1 {
+                reg = <1>;
+            };
+
+            swp2_phy: swp2_phy@2 {
+                reg = <2>;
+            };
+
+            swp3_phy: swp3_phy@3 {
+                reg = <3>;
+            };
+
+            swp4_phy: swp4_phy@4 {
+                reg = <4>;
+            };
+        };
+    };
Signature · 1 line
2.53.0
#2 lore raw

Re: [RFC v3 1/4] dt-bindings: net: dsa: add MT7628 ESW

Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml line 42

Quoted 13 lines · Joris Vaisvila

Add bindings for MT7628 SoC's Embedded Switch.

Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +3 -0
new file mode 100644
index 000000000000..5955c07a1be7
[...]
+
+  mdio:
+    $ref: /schemas/net/mdio.yaml#

Why would anyone define the MDIO bus or PHYs therein?
- PHY addresses match port addresses
- Only C22 operations are used
- No reasonable way to connect any external PHYs
=> relying on ds->user_mii_bus, or even just defining phy_read and phy_read ops in struct dsa_switch_ops should be sufficient? Unless you need the PHYs in DT, eg. to define PHY LEDs... But that can then come later once you actually add support for that.
(netdev maintainer folks: correct me if I'm wrong)

Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml line 67

Quoted 8 lines

[...]

Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +7 -0
+        ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            port@0 {
+                reg = <0>;
+                label = "swp0";

Do not add labels in binding example, remove them from all ports.

#3 lore raw

RFC v3 2/4 net: phy: mediatek: add phy driver for MT7628 built-in Fast Ethernet PHYs

In reply to Joris Vaisvila

The Fast Ethernet PHYs present in the MT7628 SoCs require an undocumented bit to be set before they can establish 100mbps links.

This commit adds the Kconfig option MEDIATEK_FE_SOC_PHY and the corresponding driver mtk-fe-soc.c.

---
 drivers/net/phy/mediatek/Kconfig      | 10 +++++-
 drivers/net/phy/mediatek/Makefile     |  1 +
 drivers/net/phy/mediatek/mtk-fe-soc.c | 50 +++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/phy/mediatek/mtk-fe-soc.c
drivers/net/phy/mediatek/Kconfig +9 -1
index bb7dc876271e..b6a51f38c358 100644
@@ -21,8 +21,16 @@ config MEDIATEK_GE_PHY
 	  common operations with MediaTek SoC built-in Gigabit
 	  Ethernet PHYs.
 
+config MEDIATEK_FE_SOC_PHY
+	tristate "MediaTek SoC Fast Ethernet PHYs"
+	help
+	  Support for MediaTek MT7628 built-in Fast Ethernet PHYs.
+	  This driver only sets an initialization bit required for the PHY
+	  to establish 100 Mbps links. All other PHY operations are handled
+	  by the kernel's generic PHY code.
+
 config MEDIATEK_GE_SOC_PHY
-	tristate "MediaTek SoC Ethernet PHYs"
+	tristate "MediaTek SoC Gigabit Ethernet PHYs"
 	depends on ARM64 || COMPILE_TEST
 	depends on ARCH_AIROHA || (ARCH_MEDIATEK && NVMEM_MTK_EFUSE) || \
 		   COMPILE_TEST
drivers/net/phy/mediatek/Makefile +1 -0
index ac57ecc799fc..6f9cacf7f906 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_MEDIATEK_2P5GE_PHY)	+= mtk-2p5ge.o
+obj-$(CONFIG_MEDIATEK_FE_SOC_PHY)	+= mtk-fe-soc.o
 obj-$(CONFIG_MEDIATEK_GE_PHY)		+= mtk-ge.o
 obj-$(CONFIG_MEDIATEK_GE_SOC_PHY)	+= mtk-ge-soc.o
 obj-$(CONFIG_MTK_NET_PHYLIB)		+= mtk-phy-lib.o
drivers/net/phy/mediatek/mtk-fe-soc.c new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.53.0
#4 lore raw

RFC v3 3/4 net: dsa: initial MT7628 tagging driver

In reply to Joris Vaisvila

Add support for the MT7628 embedded switch's tag.

The MT7628 tag is merged with the VLAN TPID field when a VLAN is appended by the switch hardware. It is not installed if the VLAN tag is already there on ingress. Due to this hardware quirk the tag cannot be trusted for port 0 if we don't know that the VLAN was added by the hardware. As a workaround for this the switch is configured to always append the port PVID tag even if the incoming packet is already tagged. The tagging driver can then trust that the tag is always accurate and the whole VLAN tag can be removed on ingress as it's only metadata for the tagger.

On egress the MT7628 tag allows precise TX, but the correct VLAN tag from tag_8021q is still appended or the switch will not forward the packet.

---
 include/net/dsa.h    |  2 +
 net/dsa/Kconfig      |  6 +++
 net/dsa/Makefile     |  1 +
 net/dsa/tag_mt7628.c | 92 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 101 insertions(+)
 create mode 100644 net/dsa/tag_mt7628.c
include/net/dsa.h +2 -0
index 6c17446f3dcc..e93f9356b5c3 100644
@@ -58,6 +58,7 @@ struct tc_action;
 #define DSA_TAG_PROTO_YT921X_VALUE		30
 #define DSA_TAG_PROTO_MXL_GSW1XX_VALUE		31
 #define DSA_TAG_PROTO_MXL862_VALUE		32
+#define DSA_TAG_PROTO_MT7628_VALUE		33
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
@@ -93,6 +94,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_YT921X		= DSA_TAG_PROTO_YT921X_VALUE,
 	DSA_TAG_PROTO_MXL_GSW1XX	= DSA_TAG_PROTO_MXL_GSW1XX_VALUE,
 	DSA_TAG_PROTO_MXL862		= DSA_TAG_PROTO_MXL862_VALUE,
+	DSA_TAG_PROTO_MT7628		= DSA_TAG_PROTO_MT7628_VALUE,
 };
 
 struct dsa_switch;
net/dsa/Kconfig +6 -0
index 5ed8c704636d..4aa73bd1aa9b 100644
@@ -211,4 +211,10 @@ config NET_DSA_TAG_YT921X
 	  Say Y or M if you want to enable support for tagging frames for
 	  Motorcomm YT921x switches.
 
+config NET_DSA_TAG_MT7628
+	tristate "Tag driver for the MT7628 embedded switch"
+	help
+	  Say Y or M if you want to enable support for tagging frames for the
+	  switch embedded in the MT7628 SoC.
+
 endif
net/dsa/Makefile +1 -0
index bf7247759a64..d25ec0ab7d67 100644
@@ -42,6 +42,7 @@ obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
 obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o
 obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o
 obj-$(CONFIG_NET_DSA_TAG_YT921X) += tag_yt921x.o
+obj-$(CONFIG_NET_DSA_TAG_MT7628) += tag_mt7628.o
 
 # for tracing framework to find trace.h
 CFLAGS_trace.o := -I$(src)
net/dsa/tag_mt7628.c new file +92 -0

92 lines not on this page · raw message

Signature · 1 line
2.53.0
#5 lore raw

RFC v3 4/4 net: dsa: initial support for MT7628 embedded switch

In reply to Joris Vaisvila

Add support for the MT7628 embedded switch.

The switch has 5 built-in 100Mbps user ports (ports 0-4) and one 1Gbps port that is internally attached to the SoCs CPU MAC and serves as the CPU port.

The switch hardware has a very limited 16 entry VLAN table. Configuring VLANs is the only way to control switch forwarding. Currently 6 entries are used by tag_8021q to isolate the ports. Double tag feature is enabled to force the switch to append the VLAN tag even if the incoming packet is already tagged, this simulates VLAN-unaware functionality and simplifies the tagger implementation.

---
 drivers/net/dsa/Kconfig  |   7 +
 drivers/net/dsa/Makefile |   1 +
 drivers/net/dsa/mt7628.c | 634 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 642 insertions(+)
 create mode 100644 drivers/net/dsa/mt7628.c
drivers/net/dsa/Kconfig +7 -0
index 39fb8ead16b5..d07fc8dfe228 100644
@@ -70,6 +70,13 @@ config NET_DSA_MV88E6060
 	  This enables support for the Marvell 88E6060 ethernet switch
 	  chip.
 
+config NET_DSA_MT7628
+	tristate "MT7628 Embedded ethernet switch support"
+	select NET_DSA_TAG_MT7628
+	select MEDIATEK_FE_SOC_PHY
+	help
+	  This enables support for the switch in the MT7628 SoC.
+
 source "drivers/net/dsa/microchip/Kconfig"
 
 source "drivers/net/dsa/mv88e6xxx/Kconfig"
drivers/net/dsa/Makefile +1 -0
index f5a463b87ec2..22da6b680f29 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX) += vitesse-vsc73xx-core.o
 obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX_PLATFORM) += vitesse-vsc73xx-platform.o
 obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX_SPI) += vitesse-vsc73xx-spi.o
 obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o
+obj-$(CONFIG_NET_DSA_MT7628) += mt7628.o
 obj-y				+= b53/
 obj-y				+= hirschmann/
 obj-y				+= lantiq/
drivers/net/dsa/mt7628.c new file +634 -0

634 lines not on this page · raw message

Signature · 1 line
2.53.0
#6 lore raw

Re: [RFC v3 4/4] net: dsa: initial support for MT7628 embedded switch

Quoted 24 lines · Joris Vaisvila

Add support for the MT7628 embedded switch.

The switch has 5 built-in 100Mbps user ports (ports 0-4) and one 1Gbps port that is internally attached to the SoCs CPU MAC and serves as the CPU port.

The switch hardware has a very limited 16 entry VLAN table. Configuring VLANs is the only way to control switch forwarding. Currently 6 entries are used by tag_8021q to isolate the ports. Double tag feature is enabled to force the switch to append the VLAN tag even if the incoming packet is already tagged, this simulates VLAN-unaware functionality and simplifies the tagger implementation.

drivers/net/dsa/mt7628.c new file +9 -0
+static int mt7628_setup_internal_mdio(struct dsa_switch *ds,
+				      struct device_node *node)
+{
+	struct mt7628_esw *esw = ds->priv;
+	struct mii_bus *bus;
+	int ret;
+
+	bus = devm_mdiobus_alloc(esw->dev);
+	if (!bus)

drivers/net/dsa/mt7628.c line 253

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+		return -ENOMEM;
+
+	bus->name = "MT7628 internal MDIO bus";
+	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(ds->dev));
+	bus->priv = esw;
+	bus->read = mt7628_mii_read;
+	bus->write = mt7628_mii_write;
+	bus->parent = esw->dev;
+
+	ret = devm_of_mdiobus_register(esw->dev, bus, node);

As mentioned in the binding comment:
- The MDIO bus is exclusively used to speak with the built-in PHYs.
- The PHY addresses match the port IDs.
- Only Clause-22 read/write operations are supported.
- There is no way to connect an external PHY (no MII interface exposed on external pins)

Imho it would hence be much easier to just use DSA's simple .phy_read and .phy_write operations instead of registering a bus manually in the driver, and even requiring a description of the MDIO bus in device tree.

If you want to reserve the option of adding PHY-specific DT properties in future (eg. for PHY-controlled LEDs? but afair the LEDs are controlled by the switch itself and SoC-level pinctrl), at least set ds->user_mii_bus = bus; to make the device tree description optional. Completely omitting the whole bus definition and changing mt7628_mii_read and mt7628_mii_write to be useful as .phy_read and .phy_write ops in struct dsa_switch is the better option for simple legacy hardware like that imho. See b53 driver, for example.

@DSA maintainers: correct me if I'm wrong and, for which ever reason, using the .phy_read/.phy_write ops is discouraged in new drivers, even for dead-simple hardware like that one.

#7 lore raw

Re: [RFC v3 4/4] net: dsa: initial support for MT7628 embedded switch

Hi Daniel, thanks for the feedback and suggestions.

Quoted 12 lines · Daniel Golle

As mentioned in the binding comment:
- The MDIO bus is exclusively used to speak with the built-in PHYs.
- The PHY addresses match the port IDs.
- Only Clause-22 read/write operations are supported.
- There is no way to connect an external PHY (no MII interface exposed on external pins)

Imho it would hence be much easier to just use DSA's simple .phy_read and .phy_write operations instead of registering a bus manually in the driver, and even requiring a description of the MDIO bus in device tree.

Quoted 8 lines

If you want to reserve the option of adding PHY-specific DT properties in future (eg. for PHY-controlled LEDs? but afair the LEDs are controlled by the switch itself and SoC-level pinctrl), at least set ds->user_mii_bus = bus; to make the device tree description optional. Completely omitting the whole bus definition and changing mt7628_mii_read and mt7628_mii_write to be useful as .phy_read and .phy_write ops in struct dsa_switch is the better option for simple legacy hardware like that imho. See b53 driver, for example.

The LEDs are indeed controlled by the switch, so there doesn't appear to be anything to configure now or in the future. Using ds->user_mii_bus sounds like a reasonable option to simplify configuration and works fine on this switch, I was not aware of it earlier.

Quoted 3 lines

@DSA maintainers: correct me if I'm wrong and, for which ever reason, using the .phy_read/.phy_write ops is discouraged in new drivers, even for dead-simple hardware like that one.

Regarding .phy_read/.phy_write, I was advised against using them in new drivers in v1 of this RFC. I'm happy to rework this, but would appreciate clarification from the DSA maintainers on the preferred direction for hardware like this.

maintainer
#8 lore raw

Re: [RFC v3 4/4] net: dsa: initial support for MT7628 embedded switch

Quoted 8 lines
Quoted 3 lines

@DSA maintainers: correct me if I'm wrong and, for which ever reason, using the .phy_read/.phy_write ops is discouraged in new drivers, even for dead-simple hardware like that one.

Regarding .phy_read/.phy_write, I was advised against using them in new drivers in v1 of this RFC. I'm happy to rework this, but would appreciate clarification from the DSA maintainers on the preferred direction for hardware like this.

Yes, it is better to call of_mdiobus_register() in the DSA driver. .phy_read/.phy_write are historic.

Andrew