Skip to contentSkip to conversation

net: dsa: mt7628 embedded switch initial support

PATCH Superseded Joris Vaisvila 3 participants 8 messages Jun 8 – Jun 9

Subsystems (6)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 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 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 |  97 +++
 drivers/net/dsa/Kconfig                       |   8 +
 drivers/net/dsa/Makefile                      |   1 +
 drivers/net/dsa/mt7628.c                      | 648 ++++++++++++++++++
 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                          |  89 +++
 11 files changed, 912 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 v4 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.

---
 .../bindings/net/dsa/mediatek,mt7628-esw.yaml | 97 +++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +97 -0
new file mode 100644
index 000000000000..0c16cf858035
@@ -0,0 +1,97 @@
+# 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.
+
+unevaluatedProperties: false
+
+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
+
+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
Reviewed-by on v4 1/4
#2 lore raw

Re: [PATCH net-next v4 1/4] dt-bindings: net: dsa: add MT7628 ESW

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

Quoted 7 lines · Joris Vaisvila
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +7 -0
+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.
+
+unevaluatedProperties: false

This goes after "required:" block.

Quoted 23 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +23 -0
+
+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

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

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +10 -0
+  - reg
+  - resets
+  - reset-names
+  - ethernet-ports
+
+examples:
+  - |
+    switch@10110000 {
+        compatible = "mediatek,mt7628-esw";
+

Drop blank line

With these two fixed:

Best regards,
Krzysztof

#3 lore raw

PATCH v4 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
#4 lore raw

Re: [PATCH net-next v4 2/4] net: phy: mediatek: add phy driver for MT7628 built-in Fast Ethernet PHYs

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Register overwrite due to unconditional write instead of read-modify-write. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Register overwrite due to unconditional write instead of read-modify-write. --

commit c56d71446569801055eeaf712bd2739d4e88d605
Author: Joris Vaisvila <[email protected]>

net: phy: mediatek: add phy driver for MT7628 built-in Fast Ethernet PHYs

This commit adds a new driver for MediaTek MT7628 built-in Fast Ethernet PHYs. It configures the PHY to establish 100mbps links by setting an initialization bit in an undocumented register.

Quoted 5 lines
drivers/net/phy/mediatek/mtk-fe-soc.c new file +0 -0
new file mode 100644
index 0000000000000..317944411fbe7

[ ... ]

drivers/net/phy/mediatek/mtk-fe-soc.c line 27

Quoted 7 lines
drivers/net/phy/mediatek/mtk-fe-soc.c new file +7 -0
+static int mt7628_phy_config_init(struct phy_device *phydev)
+{
+	/*
+	 * This undocumented bit is required for the PHYs to be able to
+	 * establish 100mbps links.
+	 */
+	return phy_write_paged(phydev, 0x8000, 30, BIT(13));

[Severity: Medium]
The comment and commit message mention setting an initialization bit. Does this unconditional write safely preserve the other bits in this register?

If other fields in this undocumented register are initialized by hardware reset or the bootloader, writing 0x2000 will destructively clear them to 0. Should this use a read-modify-write operation like phy_modify_paged() instead, or is overwriting the entire register intentional?

Quoted 1 line

+}

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

PATCH v4 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 | 89 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 98 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 +89 -0

89 lines not on this page · raw message

Signature · 1 line
2.54.0
#6 lore raw

PATCH v4 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 | 648 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 657 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 +648 -0

648 lines not on this page · raw message

Signature · 1 line
2.54.0
#7 lore raw

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

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Using devm_mdiobus_alloc() and devm_mdiobus_register() within the DSA .setup() callback causes…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Using devm_mdiobus_alloc() and devm_mdiobus_register() within the DSA .setup() callback causes memory leaks and sysfs naming collisions on device unbind/rebind. --

commit 3622b1e586d001c3ba3f067ff8677605bcde34cc
Author: Joris Vaisvila <[email protected]>

net: dsa: initial support for MT7628 embedded switch

This commit adds support for the MT7628 embedded switch, which includes 5 user ports and 1 CPU port. It uses a 16-entry VLAN table for port isolation and configures a double tag feature to simulate VLAN-unaware functionality.

Quoted 6 lines
drivers/net/dsa/mt7628.c new file +0 -0
new file mode 100644
index 0000000000000..a2338f02f78a0
@@ -0,0 +1,648 @@

[ ... ]

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+static int mt7628_setup_internal_mdio(struct dsa_switch *ds)
+{
+	struct mt7628_esw *esw = ds->priv;
+	struct mii_bus *bus;
+
+	bus = devm_mdiobus_alloc(esw->dev);
+	if (!bus)
+		return -ENOMEM;
+
+	bus->name = "MT7628 internal MDIO bus";

drivers/net/dsa/mt7628.c line 262

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

[Severity: High]
Is it safe to use devm_mdiobus_alloc() and devm_mdiobus_register() tied to the platform device here?

Since mt7628_setup_internal_mdio() is called from the DSA .setup() callback below, it can be executed multiple times without the platform device unbinding (for instance, when the conduit interface unbinds and rebinds).

Because the devm_ functions tie the MDIO bus allocation and registration to the platform device, the bus is never unregistered or freed during the DSA .teardown() phase.

When the tree is re-setup, won't it attempt to register a new MDIO bus with the same ID, causing a sysfs name collision and resource leak?

[ ... ]

Quoted 4 lines
drivers/net/dsa/mt7628.c new file +4 -0
+static int mt7628_setup(struct dsa_switch *ds)
+{
+	struct mt7628_esw *esw = ds->priv;
+	int ret;

[ ... ]

Quoted 5 lines
drivers/net/dsa/mt7628.c new file +5 -0
+	mt7628_switch_init(ds);
+
+	ret = mt7628_setup_internal_mdio(ds);
+	if (ret)
+		return ret;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4