Skip to contentSkip to conversation

net: dsa: mt7628 embedded switch initial support

PATCH Superseded Joris Vaisvila 3 participants 10 messages Jul 4 – Aug 3

Subsystems (6)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover net: dsa: mt7628 embedded switch initial support

This patch series adds initial support for the MediaTek MT7628 Embedded Switch.

The driver implements the basic functionality required to operate the switch using DSA. The hardware provides five internal Fast Ethernet user ports and one Gigabit port connected internally to the CPU MAC.

Bridge offloading is not yet supported.

Tested on an MT7628NN-based board.

Changes since v5:
- updated tag_mt7628 to kfree_skb() on error in receive path
- removed Reviewed-by tags from tag_mt7628
- removed mmio base pointer from mt7628_esw since it's only used to initialize the regmap
- rebased on net-next

Changes since v4:
mt7628 dsa driver:
- updated mdiobus allocation to use ds->dev instead of esw->dev, matching other DSA drivers (no functional change)
mt7628 phy driver:
- replaced phy_write() with phy_modify() when setting PHY init bit (no functional change)
mt7628 dt binding:
- moved unevaluatedProperties after required block
- removed blank line between compatible and reg in example

Changes since v3:
- rebased on latest net-next
mt7628 dsa driver:
- simplified vlan_add hardware vlan slot search
- fixed vlan_del not removing vid from port pvid
- separated mii_read/mii_write error handling from return value parsing. Updated RD_DONE/WT_DONE bit checking with clearer logic and a comment.
- moved NET_DSA_MT7628 after NET_DSA_MT7530 in Kconfig
- added missing reset return value checks in probe
- fixed mt7628_switch_ops missing const specifier
- removed mdio node parsing from of, as there is nothing to configure
mt7628 dt binding:
- updated description to be more clear about port count
- dropped optional mdio subnode. the switch does not expose an external MDIO bus and all integrated PHY access is handled by the driver.
- removed unused switch0 label in example

Changes since v2:
- fix binding issues found in review
- fix ignored dsa_tag_8021q_register return value
- add switch teardown to clean up tag_8021q
- fix ordering issue where mdio probe fail would leak tag_8021q

Changes since v1:
- changed port 6 phy-mode to internal
- cleaned up tag_mt7628 rcv function and mask defines
- fixed sorting error in drivers/net/dsa/ Kconfig and Makefile
- fixed sorting error in net/dsa/ Kconfig and Makefile
- fixed mt7628_mii_read/write return values on error

Thanks,
Joris

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 |  96 +++
 drivers/net/dsa/Kconfig                       |   8 +
 drivers/net/dsa/Makefile                      |   1 +
 drivers/net/dsa/mt7628.c                      | 649 ++++++++++++++++++
 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                          |  93 +++
 11 files changed, 916 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.54.0
#1 lore raw

PATCH v6 1/4 dt-bindings: net: dsa: add MT7628 ESW

Add device tree bindings for the MediaTek MT7628 embedded Ethernet Switch.

The Switch provides 5 external user ports and 1 internal CPU port, with integrated 10/100 PHYs and fixed port to PHY mapping.

The CPU port is internally connected and uses port index 6.

---
 .../bindings/net/dsa/mediatek,mt7628-esw.yaml | 96 +++++++++++++++++++
 1 file changed, 96 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +96 -0
new file mode 100644
index 000000000000..e0e7ffef6648
@@ -0,0 +1,96 @@
+# 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 has five user ports and one
+  internally connected CPU port. The user ports are all connected to the SoC's
+  integrated Fast Ethernet PHYs. The switch registers are directly mapped in
+  the SoC's memory.
+
+allOf:
+  - $ref: dsa.yaml#/$defs/ethernet-ports
+
+properties:
+  compatible:
+    const: mediatek,mt7628-esw
+
+  reg:
+    maxItems: 1
+
+  resets:
+    items:
+      - description: internal switch block reset
+      - description: internal phy package reset
+
+  reset-names:
+    items:
+      - const: esw
+      - const: ephy
+
+required:
+  - compatible
+  - reg
+  - resets
+  - reset-names
+  - ethernet-ports
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    switch@10110000 {
+        compatible = "mediatek,mt7628-esw";
+        reg = <0x10110000 0x8000>;
+
+        resets = <&sysc 23>, <&sysc 24>;
+        reset-names = "esw", "ephy";
+
+        ethernet-ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            ethernet-port@0 {
+                reg = <0>;
+                phy-mode = "internal";
+            };
+
+            ethernet-port@1 {
+                reg = <1>;
+                phy-mode = "internal";
+            };
+
+            ethernet-port@2 {
+                reg = <2>;
+                phy-mode = "internal";
+            };
+
+            ethernet-port@3 {
+                reg = <3>;
+                phy-mode = "internal";
+            };
+
+            ethernet-port@4 {
+                reg = <4>;
+                phy-mode = "internal";
+            };
+
+            ethernet-port@6 {
+                reg = <6>;
+                phy-mode = "internal";
+                ethernet = <&ethernet>;
+
+                fixed-link {
+                    speed = <1000>;
+                    full-duplex;
+                };
+            };
+        };
+    };
Signature · 1 line
2.54.0
#2 lore raw

PATCH v6 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.54.0
#3 lore raw

PATCH v6 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 | 93 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 102 insertions(+)
 create mode 100644 net/dsa/tag_mt7628.c
include/net/dsa.h +2 -0
index 8c16ef23cc10..913d1f71e3db 100644
@@ -59,6 +59,7 @@ struct tc_action;
 #define DSA_TAG_PROTO_MXL_GSW1XX_VALUE		31
 #define DSA_TAG_PROTO_MXL862_VALUE		32
 #define DSA_TAG_PROTO_NETC_VALUE		33
+#define DSA_TAG_PROTO_MT7628_VALUE		34
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
@@ -95,6 +96,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_MXL_GSW1XX	= DSA_TAG_PROTO_MXL_GSW1XX_VALUE,
 	DSA_TAG_PROTO_MXL862		= DSA_TAG_PROTO_MXL862_VALUE,
 	DSA_TAG_PROTO_NETC		= DSA_TAG_PROTO_NETC_VALUE,
+	DSA_TAG_PROTO_MT7628		= DSA_TAG_PROTO_MT7628_VALUE,
 };
 
 struct dsa_switch;
net/dsa/Kconfig +6 -0
index d5e725b90d78..23b4b74004ed 100644
@@ -98,6 +98,12 @@ config NET_DSA_TAG_EDSA
 	  Say Y or M if you want to enable support for tagging frames for the
 	  Marvell switches which use EtherType DSA headers.
 
+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.
+
 config NET_DSA_TAG_MTK
 	tristate "Tag driver for Mediatek switches"
 	help
net/dsa/Makefile +1 -0
index b8c2667cd14a..d15bcf5c68f0 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o
 obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o
 obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
 obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
+obj-$(CONFIG_NET_DSA_TAG_MT7628) += tag_mt7628.o
 obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
 obj-$(CONFIG_NET_DSA_TAG_MXL_862XX) += tag_mxl862xx.o
 obj-$(CONFIG_NET_DSA_TAG_MXL_GSW1XX) += tag_mxl-gsw1xx.o
net/dsa/tag_mt7628.c new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
2.54.0
#4 lore raw

PATCH v6 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  |   8 +
 drivers/net/dsa/Makefile |   1 +
 drivers/net/dsa/mt7628.c | 649 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 658 insertions(+)
 create mode 100644 drivers/net/dsa/mt7628.c
drivers/net/dsa/Kconfig +8 -0
index 4ab567c5bbaf..daa1d3d4ba60 100644
@@ -63,6 +63,14 @@ config NET_DSA_MT7530_MMIO
 	  are directly mapped into the SoCs register space rather than being
 	  accessible via MDIO.
 
+config NET_DSA_MT7628
+	tristate "MediaTek MT7628 Embedded Ethernet switch support"
+	select NET_DSA_TAG_MT7628
+	select MEDIATEK_FE_SOC_PHY
+	help
+	  This enables support for the built-in Ethernet switch found
+	  in the MT7628 SoC.
+
 config NET_DSA_MV88E6060
 	tristate "Marvell 88E6060 ethernet switch chip support"
 	select NET_DSA_TAG_TRAILER
drivers/net/dsa/Makefile +1 -0
index d2975badffc0..6ceb78a755d7 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_NET_DSA_KS8995) 	+= ks8995.o
 obj-$(CONFIG_NET_DSA_MT7530)	+= mt7530.o
 obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o
 obj-$(CONFIG_NET_DSA_MT7530_MMIO) += mt7530-mmio.o
+obj-$(CONFIG_NET_DSA_MT7628) += mt7628.o
 obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o
 obj-$(CONFIG_NET_DSA_RZN1_A5PSW) += rzn1_a5psw.o
 obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
drivers/net/dsa/mt7628.c new file +649 -0

649 lines not on this page · raw message

Signature · 1 line
2.54.0
#5 lore raw

Re: [PATCH net-next v6 4/4] net: dsa: initial support for MT7628 embedded switch

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] MDIO bus is allocated and registered using devm_* in the setup callback, leading to resource leaks…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] MDIO bus is allocated and registered using devm_* in the setup callback, leading to resource leaks and name collisions.
- [High] The switch hardware is not explicitly isolated immediately after reset, creating a persistent window where traffic can leak across all physical ports.
- [Low] NET_DSA_MT7628 fails to select REGMAP_MMIO and lacks architectural/IOMEM dependencies, leading to build and link failures on randconfig. --

commit 1fc6f79da05a91b1b381be13133c0c6902366d8f
Author: Joris Vaisvila <[email protected]>

net: dsa: initial support for MT7628 embedded switch

Add support for the MT7628 embedded switch. The switch has 5 built-in 100Mbps user ports and one 1Gbps CPU port.

drivers/net/dsa/Kconfig config NET_DSA_MT7530_MMIO · line 70

Quoted 13 lines
drivers/net/dsa/Kconfig +5 -0
index 4ab567c5bbafc..daa1d3d4ba609 100644
@@ -63,6 +63,14 @@ config NET_DSA_MT7530_MMIO
 	  are directly mapped into the SoCs register space rather than being
 	  accessible via MDIO.
 
+config NET_DSA_MT7628
+	tristate "MediaTek MT7628 Embedded Ethernet switch support"
+	select NET_DSA_TAG_MT7628
+	select MEDIATEK_FE_SOC_PHY
+	help

[Severity: Low]
Can this lead to a build or link failure on randconfig? It looks like this is missing a select REGMAP_MMIO and depends on HAS_IOMEM, which might cause devm_regmap_init_mmio() to be unresolved when CONFIG_REGMAP_MMIO is not set.

Quoted 19 lines
drivers/net/dsa/mt7628.c new file +12 -0
new file mode 100644
index 0000000000000..eccdb05fce9b7
@@ -0,0 +1,649 @@
[ ... ]
+static int mt7628_setup_internal_mdio(struct dsa_switch *ds)
+{
+	struct mt7628_esw *esw = ds->priv;
+	struct device *dev = ds->dev;
+	struct mii_bus *bus;
+
+	bus = devm_mdiobus_alloc(dev);
+	if (!bus)
+		return -ENOMEM;
+
+	bus->name = "MT7628 internal MDIO bus";
+	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(dev));

drivers/net/dsa/mt7628.c line 263

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+	bus->priv = esw;
+	bus->read = mt7628_mii_read;
+	bus->write = mt7628_mii_write;
+	bus->parent = dev;
+
+	ds->user_mii_bus = bus;
+	bus->phy_mask = ~ds->phys_mii_mask;
+
+	return devm_mdiobus_register(dev, bus);
+}

[Severity: High]
Does this cause a resource leak and sysfs name collision if the switch setup callback runs multiple times?

If the DSA master device unbinds and rebinds, dsa_tree_teardown() and dsa_tree_setup() can be triggered again. Because devm_mdiobus_alloc() and devm_mdiobus_register() tie the resource to the platform device's lifetime rather than the DSA tree setup/teardown cycle, the first registration will leak, and the second might fail with -EEXIST.

drivers/net/dsa/mt7628.c line 273

Quoted 10 lines

[ ... ]

drivers/net/dsa/mt7628.c new file +9 -0
+static void mt7628_switch_init(struct dsa_switch *ds)
+{
+	struct mt7628_esw *esw = ds->priv;
+
+	regmap_write(esw->regmap, MT7628_ESW_REG_FCT0,
+		     FIELD_PREP(MT7628_ESW_FCT0_DROP_SET_TH, 0x50) |
+		     FIELD_PREP(MT7628_ESW_FCT0_DROP_RLS_TH, 0x78) |
+		     FIELD_PREP(MT7628_ESW_FCT0_FC_SET_TH, 0xa0) |
+		     FIELD_PREP(MT7628_ESW_FCT0_FC_RLS_TH, 0xc8));

[Severity: High]
Can traffic leak across isolated ports (like WAN and LAN) during boot?

It looks like mt7628_switch_init() resets the switch but fails to explicitly set the MT7628_ESW_POC0_PORT_DISABLE bits for the user ports. Since the DSA core relies on port_disable during ndo_close and doesn't automatically disable ports upon initialization, does the hardware default to acting as an unmanaged switch, bridging all networks until the interfaces are brought up administratively?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
maintainer
#6 lore raw

Re: [PATCH net-next v6 4/4] net: dsa: initial support for MT7628 embedded switch

In reply to Joris Vaisvila

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: initial support for MT7628 embedded switch

This patch adds a DSA driver for the MT7628 embedded switch, which has five 100Mbps user ports and a 1Gbps CPU port. tag_8021q is used to isolate ports via the switch's 16-entry VLAN table, with the double tag feature enabled to simulate VLAN-unaware behaviour.

Quoted 5 lines
drivers/net/dsa/mt7628.c new file +0 -0
new file mode 100644
index 000000000000..eccdb05fce9b

[ ... ]

drivers/net/dsa/mt7628.c line 560

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+static const struct dsa_switch_ops mt7628_switch_ops = {
+	.get_tag_protocol = mt7628_get_tag_proto,
+	.setup = mt7628_setup,
+	.teardown = mt7628_teardown,
+	.port_enable = mt7628_port_enable,
+	.port_disable = mt7628_port_disable,
+	.phylink_get_caps = mt7628_phylink_get_caps,
+	.tag_8021q_vlan_add = mt7628_dsa_8021q_vlan_add,
+	.tag_8021q_vlan_del = mt7628_dsa_8021q_vlan_del,
+};

[Medium]
How is a user expected to place two of the user ports into a Linux bridge?

The ops table does not implement port_bridge_join or port_bridge_leave, so dsa_switch_bridge_join() in net/dsa/switch.c returns -EOPNOTSUPP:

    if (!ds->ops->port_bridge_join)
        return -EOPNOTSUPP;

That makes ip link set swpN master brX fail for every user port, which seems to contradict the commit message:

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.

Without a port_bridge_join hook, dsa_tag_8021q_bridge_join() is never invoked, so there is no path to migrate a port's tag_8021q VID from its standalone VID to a bridge VID.

Would wiring the tag_8021q helpers directly, similar to what vitesse-vsc73xx-core.c does, be sufficient here:

    .port_bridge_join = dsa_tag_8021q_bridge_join,
    .port_bridge_leave = dsa_tag_8021q_bridge_leave,

Related bridge-lifecycle callbacks such as port_stp_state_set, port_pre_bridge_flags, port_bridge_flags and port_fast_age also appear to be absent, is that intentional for this initial submission?

maintainer
#8 lore raw

Re: [PATCH net-next v6 4/4] net: dsa: initial support for MT7628 embedded switch

In reply to Joris Vaisvila

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: initial support for MT7628 embedded switch

Add support for the MT7628 embedded switch. The switch has 5 built-in 100Mbps user ports and one 1Gbps CPU port.

drivers/net/dsa/Kconfig config NET_DSA_MT7530_MMIO · line 70

Quoted 13 lines
drivers/net/dsa/Kconfig +5 -0
index 4ab567c5bbafc..daa1d3d4ba609 100644
@@ -63,6 +63,14 @@ config NET_DSA_MT7530_MMIO
 	  are directly mapped into the SoCs register space rather than being
 	  accessible via MDIO.
 
+config NET_DSA_MT7628
+	tristate "MediaTek MT7628 Embedded Ethernet switch support"
+	select NET_DSA_TAG_MT7628
+	select MEDIATEK_FE_SOC_PHY
+	help

[Severity: Low]
Can this lead to a build or link failure on randconfig? It looks like this is missing a select REGMAP_MMIO and depends on HAS_IOMEM, which might cause devm_regmap_init_mmio() to be unresolved when CONFIG_REGMAP_MMIO is not set.

Quoted 19 lines
drivers/net/dsa/mt7628.c new file +12 -0
new file mode 100644
index 0000000000000..eccdb05fce9b7
@@ -0,0 +1,649 @@
[ ... ]
+static int mt7628_setup_internal_mdio(struct dsa_switch *ds)
+{
+	struct mt7628_esw *esw = ds->priv;
+	struct device *dev = ds->dev;
+	struct mii_bus *bus;
+
+	bus = devm_mdiobus_alloc(dev);
+	if (!bus)
+		return -ENOMEM;
+
+	bus->name = "MT7628 internal MDIO bus";
+	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(dev));

drivers/net/dsa/mt7628.c line 263

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+	bus->priv = esw;
+	bus->read = mt7628_mii_read;
+	bus->write = mt7628_mii_write;
+	bus->parent = dev;
+
+	ds->user_mii_bus = bus;
+	bus->phy_mask = ~ds->phys_mii_mask;
+
+	return devm_mdiobus_register(dev, bus);
+}

[Severity: High]
Does this cause a resource leak and sysfs name collision if the switch setup callback runs multiple times?

If the DSA master device unbinds and rebinds, dsa_tree_teardown() and dsa_tree_setup() can be triggered again. Because devm_mdiobus_alloc() and devm_mdiobus_register() tie the resource to the platform device's lifetime rather than the DSA tree setup/teardown cycle, the first registration will leak, and the second might fail with -EEXIST.

drivers/net/dsa/mt7628.c line 273

Quoted 10 lines

[ ... ]

drivers/net/dsa/mt7628.c new file +9 -0
+static void mt7628_switch_init(struct dsa_switch *ds)
+{
+	struct mt7628_esw *esw = ds->priv;
+
+	regmap_write(esw->regmap, MT7628_ESW_REG_FCT0,
+		     FIELD_PREP(MT7628_ESW_FCT0_DROP_SET_TH, 0x50) |
+		     FIELD_PREP(MT7628_ESW_FCT0_DROP_RLS_TH, 0x78) |
+		     FIELD_PREP(MT7628_ESW_FCT0_FC_SET_TH, 0xa0) |
+		     FIELD_PREP(MT7628_ESW_FCT0_FC_RLS_TH, 0xc8));

[Severity: High]
Can traffic leak across isolated ports (like WAN and LAN) during boot?

It looks like mt7628_switch_init() resets the switch but fails to explicitly set the MT7628_ESW_POC0_PORT_DISABLE bits for the user ports. Since the DSA core relies on port_disable during ndo_close and doesn't automatically disable ports upon initialization, does the hardware default to acting as an unmanaged switch, bridging all networks until the interfaces are brought up administratively?

#9 lore raw

Re: [PATCH net-next v6 4/4] net: dsa: initial support for MT7628 embedded switch

Quoted 16 lines · Jakub Kicinski

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: initial support for MT7628 embedded switch

Add support for the MT7628 embedded switch. The switch has 5 built-in 100Mbps user ports and one 1Gbps CPU port.

Quoted 8 lines
drivers/net/dsa/Kconfig +0 -0
index 4ab567c5bbafc..daa1d3d4ba609 100644
@@ -63,6 +63,14 @@ config NET_DSA_MT7530_MMIO
 	  are directly mapped into the SoCs register space rather than being
 	  accessible via MDIO.
 
Quoted 10 lines

drivers/net/dsa/Kconfig config NET_DSA_MT7530_MMIO · line 70

Quoted 5 lines
drivers/net/dsa/Kconfig +5 -0
+config NET_DSA_MT7628
+	tristate "MediaTek MT7628 Embedded Ethernet switch support"
+	select NET_DSA_TAG_MT7628
+	select MEDIATEK_FE_SOC_PHY
+	help

[Severity: Low]
Can this lead to a build or link failure on randconfig? It looks like this is missing a select REGMAP_MMIO and depends on HAS_IOMEM, which might cause devm_regmap_init_mmio() to be unresolved when CONFIG_REGMAP_MMIO is not set.

Will fix with v7.

Quoted 34 lines
Quoted 19 lines
drivers/net/dsa/mt7628.c new file +12 -0
new file mode 100644
index 0000000000000..eccdb05fce9b7
@@ -0,0 +1,649 @@
[ ... ]
+static int mt7628_setup_internal_mdio(struct dsa_switch *ds)
+{
+	struct mt7628_esw *esw = ds->priv;
+	struct device *dev = ds->dev;
+	struct mii_bus *bus;
+
+	bus = devm_mdiobus_alloc(dev);
+	if (!bus)
+		return -ENOMEM;
+
+	bus->name = "MT7628 internal MDIO bus";
+	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(dev));

drivers/net/dsa/mt7628.c line 263

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+	bus->priv = esw;
+	bus->read = mt7628_mii_read;
+	bus->write = mt7628_mii_write;
+	bus->parent = dev;
+
+	ds->user_mii_bus = bus;
+	bus->phy_mask = ~ds->phys_mii_mask;
+
+	return devm_mdiobus_register(dev, bus);
+}

[Severity: High]
Does this cause a resource leak and sysfs name collision if the switch setup callback runs multiple times?

Quoted 5 lines

If the DSA master device unbinds and rebinds, dsa_tree_teardown() and dsa_tree_setup() can be triggered again. Because devm_mdiobus_alloc() and devm_mdiobus_register() tie the resource to the platform device's lifetime rather than the DSA tree setup/teardown cycle, the first registration will leak, and the second might fail with -EEXIST.

I am not able to find any code path that would trigger dsa_switch_ops setup other than through dsa_register_switch, which is called in the platform device probe. That would make it impossible for setup to be called again without removing the platform device first, which tears down the mdiobus.

This pattern is used in multiple other DSA drivers. A few examples:

- in NXP NETC priv->dev is sset to the &pci_dev->dev, which is used in devm_mdiobus_alloc_size().
- in mt7530-mmio priv->dev is set to the &platform_device->dev, which is then used in devm_mdiobus_alloc().

This seems like an AI review false positive.

Quoted 14 lines

drivers/net/dsa/mt7628.c line 273

Quoted 10 lines

[ ... ]

drivers/net/dsa/mt7628.c new file +9 -0
+static void mt7628_switch_init(struct dsa_switch *ds)
+{
+	struct mt7628_esw *esw = ds->priv;
+
+	regmap_write(esw->regmap, MT7628_ESW_REG_FCT0,
+		     FIELD_PREP(MT7628_ESW_FCT0_DROP_SET_TH, 0x50) |
+		     FIELD_PREP(MT7628_ESW_FCT0_DROP_RLS_TH, 0x78) |
+		     FIELD_PREP(MT7628_ESW_FCT0_FC_SET_TH, 0xa0) |
+		     FIELD_PREP(MT7628_ESW_FCT0_FC_RLS_TH, 0xc8));

[Severity: High]
Can traffic leak across isolated ports (like WAN and LAN) during boot?

Quoted 6 lines

It looks like mt7628_switch_init() resets the switch but fails to explicitly set the MT7628_ESW_POC0_PORT_DISABLE bits for the user ports. Since the DSA core relies on port_disable during ndo_close and doesn't automatically disable ports upon initialization, does the hardware default to acting as an unmanaged switch, bridging all networks until the interfaces are brought up administratively?

The hardware defaults to an all ports disabled state. Will add this as a comment in v7.

#7 lore raw

Re: [PATCH net-next v6 4/4] net: dsa: initial support for MT7628 embedded switch

In reply to Jakub Kicinski
Quoted 38 lines · Jakub Kicinski

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: initial support for MT7628 embedded switch

This patch adds a DSA driver for the MT7628 embedded switch, which has five 100Mbps user ports and a 1Gbps CPU port. tag_8021q is used to isolate ports via the switch's 16-entry VLAN table, with the double tag feature enabled to simulate VLAN-unaware behaviour.

Quoted 5 lines
drivers/net/dsa/mt7628.c new file +0 -0
new file mode 100644
index 000000000000..eccdb05fce9b

[ ... ]

drivers/net/dsa/mt7628.c line 560

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+static const struct dsa_switch_ops mt7628_switch_ops = {
+	.get_tag_protocol = mt7628_get_tag_proto,
+	.setup = mt7628_setup,
+	.teardown = mt7628_teardown,
+	.port_enable = mt7628_port_enable,
+	.port_disable = mt7628_port_disable,
+	.phylink_get_caps = mt7628_phylink_get_caps,
+	.tag_8021q_vlan_add = mt7628_dsa_8021q_vlan_add,
+	.tag_8021q_vlan_del = mt7628_dsa_8021q_vlan_del,
+};

[Medium]
How is a user expected to place two of the user ports into a Linux bridge?

The ops table does not implement port_bridge_join or port_bridge_leave, so dsa_switch_bridge_join() in net/dsa/switch.c returns -EOPNOTSUPP:

    if (!ds->ops->port_bridge_join)
        return -EOPNOTSUPP;
Quoted 7 lines

That makes ip link set swpN master brX fail for every user port, which seems to contradict the commit message:

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.

It does not contradict the commit message. The driver intentionally does not implement bridge offloading.

The ports can still be bridged in software without propagating it to the hardware. This is a deliberate simplification to keep the initial driver easier to review. It is also a practical initial solution for this switch, as all of the user ports are 100mbps, while the CPU to switch link is 1gbps, making it possible to bridge multiple ports at line rate in software.

Quoted 7 lines

Without a port_bridge_join hook, dsa_tag_8021q_bridge_join() is never invoked, so there is no path to migrate a port's tag_8021q VID from its standalone VID to a bridge VID.

Would wiring the tag_8021q helpers directly, similar to what vitesse-vsc73xx-core.c does, be sufficient here:

Quoted 6 lines
    .port_bridge_join = dsa_tag_8021q_bridge_join,
    .port_bridge_leave = dsa_tag_8021q_bridge_leave,

Related bridge-lifecycle callbacks such as port_stp_state_set, port_pre_bridge_flags, port_bridge_flags and port_fast_age also appear to be absent, is that intentional for this initial submission?

For the initial submission tag_8021q is only used for the standalone VID feature and software bridging is used. I intend to work on hardware bridging after initial support is complete.