Skip to contentSkip to conversation

net: dsa: mt7628 embedded switch initial support

PATCH Superseded Joris Vaisvila 5 participants 11 messages Apr 28 – May 6

Subsystems (6)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover net: dsa: mt7628 embedded switch initial support

Hello,

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 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 | 101 +++
 drivers/net/dsa/Kconfig                       |   8 +
 drivers/net/dsa/Makefile                      |   1 +
 drivers/net/dsa/mt7628.c                      | 639 ++++++++++++++++++
 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, 907 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 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 | 101 ++++++++++++++++++
 1 file changed, 101 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +101 -0
new file mode 100644
index 000000000000..a9db9057ee54
@@ -0,0 +1,101 @@
+# 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
+
+  resets:
+    items:
+      - description: internal switch block reset
+      - description: internal phy package reset
+
+  reset-names:
+    items:
+      - const: esw
+      - const: ephy
+
+  mdio:
+    $ref: /schemas/net/mdio.yaml#
+    unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - resets
+  - reset-names
+  - ethernet-ports
+
+examples:
+  - |
+    switch0: 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
maintainer
#2 lore raw

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

This is an AI-generated review of your patch. The human sending this email says "Since Andrew requested some changes already here is the AI review to look thru as well (could be false positives)."
---
Subject: dt-bindings: net: dsa: add MT7628 ESW

This patch adds a new YAML device tree binding for the Embedded Switch block found in the MediaTek MT7628 SoC. The binding describes a five port switch with integrated 10/100 PHYs plus an internally connected 1G CPU port, together with reset lines and an optional MDIO subnode.

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +0 -0
new file mode 100644
index 000000000000..a9db9057ee54

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

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +10 -0
@@ -0,0 +1,101 @@
+# 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]>

This isn't a bug, but the maintainers list only contains the submitter at an unrelated domain. Existing in-tree MediaTek DSA bindings such as Documentation/devicetree/bindings/net/dsa/mediatek,mt7530.yaml list multiple MediaTek or long-standing MediaTek-community maintainers.

For an official MediaTek SoC's built-in switch IP, would it make sense to CC or co-list a MediaTek networking maintainer (Sean Wang, Landen Chao, Daniel Golle, ...) so the hardware description can be corroborated and the binding ABI has long-term stewardship?

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

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

Is the description internally consistent?

The first sentence says "a five port switch with integrated 10/100 PHYs", but the following sentences describe "an internally connected 1G CPU port and 5 user ports", which is six ports in total. The example below also enumerates six ports (reg = 0..4 and 6).

Could this be reworded as e.g. "5 user ports plus 1 internal CPU port" to avoid the ambiguity?

Separately, there is no justification in the commit message or binding for the absence of a clocks property. MT7628 peripherals are typically gated by syscon clock outputs (see arch/mips/boot/dts/ralink/mt7628a.dtsi), and drivers/net/ethernet/mediatek/mtk_eth_soc.c already treats "esw" as a named clock.

The MT7628 ESW driver added alongside this binding deliberately does not call any clk_* API, which is a valid design choice if the esw gate is always on after reset. Since DT bindings are ABI, though, adding a clocks property later would be a backward-incompatible change.

Could the commit message explain why no clocks property is needed, or alternatively could clocks/clock-names be described in the binding now even if the initial driver ignores them?

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

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

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +10 -0
+      - description: internal phy package reset
+
+  reset-names:
+    items:
+      - const: esw
+      - const: ephy
+
+  mdio:
+    $ref: /schemas/net/mdio.yaml#
+    unevaluatedProperties: false

The mdio subnode is referenced here and is actually consumed by the driver (drivers/net/dsa/mt7628.c mt7628_setup_internal_mdio() calls of_get_available_child_by_name(..., "mdio") and devm_of_mdiobus_register()), but the binding provides no description of when or why a user would populate it.

Given the top-level description says the PHYs are "integrated" and "internally connected", when should an mdio subnode be present? Is an external MDIO master ever supported?

A short description attached to the mdio property would make the intent clear to DT authors.

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

Quoted 7 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +7 -0
+
+required:
+  - compatible
+  - reg
+  - resets
+  - reset-names
+  - ethernet-ports

Should the valid port reg values be constrained here?

The MT7628 ESW has a fixed, well-known set of valid port indices (0..4 for user ports and 6 for the CPU, with port 5 not existing). See mt7628_phylink_get_caps() in drivers/net/dsa/mt7628.c, which explicitly comments that "port 5 does not exist on MT7628".

As written the schema accepts ethernet-port@5 or ethernet-port@7 at dt_binding_check time, even though the driver will silently ignore them. Would adding a reg enum constraint on the ethernet-port children (e.g. via patternProperties, or an override of the $defs/ethernet-ports reg) catch these mistakes at schema-validation time?

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

[ ... ]

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

Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +4 -0
+            ethernet-port@6 {
+                reg = <6>;
+                phy-mode = "internal";
+                ethernet = <&ethernet>;

The example references an undefined phandle here: ethernet-port@6 uses ethernet = <&ethernet> but no node labelled "ethernet" is defined in the example snippet.

Other DSA binding examples in Documentation/devicetree/bindings/net/dsa/ typically either provide a minimal stub for referenced phandles inside the example or use a reg-based reference. Will dt_binding_check emit a warning about the unresolved phandle as written?

Quoted 8 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +8 -0
+
+                fixed-link {
+                    speed = <1000>;
+                    full-duplex;
+                };
+            };
+        };
+    };
Signature · 1 line
pw-bot: cr
maintainer
#3 lore raw

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

Quoted 134 lines · Jakub Kicinski

This is an AI-generated review of your patch. The human sending this email says "Since Andrew requested some changes already here is the AI review to look thru as well (could be false positives)."
---
Subject: dt-bindings: net: dsa: add MT7628 ESW

This patch adds a new YAML device tree binding for the Embedded Switch block found in the MediaTek MT7628 SoC. The binding describes a five port switch with integrated 10/100 PHYs plus an internally connected 1G CPU port, together with reset lines and an optional MDIO subnode.

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +0 -0
new file mode 100644
index 000000000000..a9db9057ee54

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

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +10 -0
@@ -0,0 +1,101 @@
+# 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]>

This isn't a bug, but the maintainers list only contains the submitter at an unrelated domain. Existing in-tree MediaTek DSA bindings such as Documentation/devicetree/bindings/net/dsa/mediatek,mt7530.yaml list multiple MediaTek or long-standing MediaTek-community maintainers.

For an official MediaTek SoC's built-in switch IP, would it make sense to CC or co-list a MediaTek networking maintainer (Sean Wang, Landen Chao, Daniel Golle, ...) so the hardware description can be corroborated and the binding ABI has long-term stewardship?

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

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

Is the description internally consistent?

The first sentence says "a five port switch with integrated 10/100 PHYs", but the following sentences describe "an internally connected 1G CPU port and 5 user ports", which is six ports in total. The example below also enumerates six ports (reg = 0..4 and 6).

Could this be reworded as e.g. "5 user ports plus 1 internal CPU port" to avoid the ambiguity?

Separately, there is no justification in the commit message or binding for the absence of a clocks property. MT7628 peripherals are typically gated by syscon clock outputs (see arch/mips/boot/dts/ralink/mt7628a.dtsi), and drivers/net/ethernet/mediatek/mtk_eth_soc.c already treats "esw" as a named clock.

The MT7628 ESW driver added alongside this binding deliberately does not call any clk_* API, which is a valid design choice if the esw gate is always on after reset. Since DT bindings are ABI, though, adding a clocks property later would be a backward-incompatible change.

Could the commit message explain why no clocks property is needed, or alternatively could clocks/clock-names be described in the binding now even if the initial driver ignores them?

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

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

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +10 -0
+      - description: internal phy package reset
+
+  reset-names:
+    items:
+      - const: esw
+      - const: ephy
+
+  mdio:
+    $ref: /schemas/net/mdio.yaml#
+    unevaluatedProperties: false

The mdio subnode is referenced here and is actually consumed by the driver (drivers/net/dsa/mt7628.c mt7628_setup_internal_mdio() calls of_get_available_child_by_name(..., "mdio") and devm_of_mdiobus_register()), but the binding provides no description of when or why a user would populate it.

Given the top-level description says the PHYs are "integrated" and "internally connected", when should an mdio subnode be present? Is an external MDIO master ever supported?

A short description attached to the mdio property would make the intent clear to DT authors.

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

Quoted 7 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +7 -0
+
+required:
+  - compatible
+  - reg
+  - resets
+  - reset-names
+  - ethernet-ports

Should the valid port reg values be constrained here?

The MT7628 ESW has a fixed, well-known set of valid port indices (0..4 for user ports and 6 for the CPU, with port 5 not existing). See mt7628_phylink_get_caps() in drivers/net/dsa/mt7628.c, which explicitly comments that "port 5 does not exist on MT7628".

As written the schema accepts ethernet-port@5 or ethernet-port@7 at dt_binding_check time, even though the driver will silently ignore them. Would adding a reg enum constraint on the ethernet-port children (e.g. via patternProperties, or an override of the $defs/ethernet-ports reg) catch these mistakes at schema-validation time?

Quoted 4 lines

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

Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +4 -0
+
+examples:
+  - |
+    switch0: switch@10110000 {

This label is unused and should be dropped.

Quoted 16 lines
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +10 -0
+        compatible = "mediatek,mt7628-esw";
+
+        reg = <0x10110000 0x8000>;
+
+        resets = <&sysc 23>, <&sysc 24>;
+        reset-names = "esw", "ephy";
+
+        ethernet-ports {
+            #address-cells = <1>;
+            #size-cells = <0>;

[ ... ]

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

Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/mediatek,mt7628-esw.yaml new file +4 -0
+            ethernet-port@6 {
+                reg = <6>;
+                phy-mode = "internal";
+                ethernet = <&ethernet>;
Quoted 8 lines

The example references an undefined phandle here: ethernet-port@6 uses ethernet = <&ethernet> but no node labelled "ethernet" is defined in the example snippet.

Other DSA binding examples in Documentation/devicetree/bindings/net/dsa/ typically either provide a minimal stub for referenced phandles inside the example or use a reg-based reference. Will dt_binding_check emit a warning about the unresolved phandle as written?

No, example phandles don't have to resolve to a provider and we actively don't want providers in the examples.

Rob

#4 lore raw

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

PATCH 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 | 89 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+)
 create mode 100644 net/dsa/tag_mt7628.c
include/net/dsa.h +2 -0
index 8b6d34e8a6f0..0a314f62023d 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..946f44f0b843 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 bf7247759a64..a84f33f0963d 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 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  |   8 +
 drivers/net/dsa/Makefile |   1 +
 drivers/net/dsa/mt7628.c | 639 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 648 insertions(+)
 create mode 100644 drivers/net/dsa/mt7628.c
drivers/net/dsa/Kconfig +8 -0
index 39fb8ead16b5..defe74625cef 100644
@@ -28,6 +28,14 @@ source "drivers/net/dsa/hirschmann/Kconfig"
 
 source "drivers/net/dsa/lantiq/Kconfig"
 
+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_MT7530
 	tristate "MediaTek MT7530 and MT7531 Ethernet switch support"
 	select NET_DSA_TAG_MTK
drivers/net/dsa/Makefile +1 -0
index f5a463b87ec2..8d4461f2d437 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 +639 -0

639 lines not on this page · raw message

Signature · 1 line
2.54.0
maintainer
#7 lore raw

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

drivers/net/dsa/Kconfig source "drivers/net/dsa/hirschmann/Kconfig" · line 40

Quoted 12 lines

source "drivers/net/dsa/lantiq/Kconfig"

drivers/net/dsa/Kconfig +8 -0
+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_MT7530
 	tristate "MediaTek MT7530 and MT7531 Ethernet switch support"

NET_DSA_MT7628 is > NET_DSA_MT7530 so should come second.

Quoted 19 lines
drivers/net/dsa/mt7628.c new file +19 -0
+static int mt7628_mii_read(struct mii_bus *bus, int port, int regnum)
+{
+	struct mt7628_esw *esw = bus->priv;
+	int ret;
+	u32 val;
+
+	ret = regmap_read_poll_timeout(esw->regmap, MT7628_ESW_REG_PCR1, val,
+				       !(val & MT7628_ESW_PCR1_RD_DONE), 10,
+				       5000);
+	if (ret)
+		goto out;
+
+	ret = regmap_write(esw->regmap, MT7628_ESW_REG_PCR0,
+			   FIELD_PREP(MT7628_ESW_PCR0_CPU_PHY_REG,
+				      regnum) |
+			   FIELD_PREP(MT7628_ESW_PCR0_CPU_PHY_ADDR,
+				      port) | MT7628_ESW_PCR0_RD_PHY_CMD);
+	if (ret)
+		goto out;

drivers/net/dsa/mt7628.c line 200

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+
+	ret = regmap_read_poll_timeout(esw->regmap, MT7628_ESW_REG_PCR1, val,
+				       (val & MT7628_ESW_PCR1_RD_DONE), 10,
+				       5000);
+out:
+	if (ret) {
+		dev_err(&bus->dev, "read failed. MDIO timeout?\n");
+		return ret;
+	}
+	return FIELD_GET(MT7628_ESW_PCR1_RD_DATA, val);

This works, but it is an unusual structure. Normally the label is after the normal exist path, and only deals with errors.

Quoted 4 lines
drivers/net/dsa/mt7628.c new file +4 -0
+}
+
+static int mt7628_mii_write(struct mii_bus *bus, int port, int regnum, u16 dat)
+{

drivers/net/dsa/mt7628.c line 233

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+	ret = regmap_read_poll_timeout(esw->regmap, MT7628_ESW_REG_PCR1, val,
+				       (val & MT7628_ESW_PCR1_WT_DONE), 10,
+				       5000);
+out:
+	if (ret) {
+		dev_err(&bus->dev, "write failed. MDIO timeout?\n");
+		return ret;
+	}
+	return 0;
+}

Same here.

Otherwise this looks O.K.

Andrew

maintainer
#8 lore raw

Re: [PATCH net-next v3 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 says "Since Andrew requested some changes already here is the AI review to look thru as well (could be false positives)."
---
net: dsa: initial support for MT7628 embedded switch

This patch adds a new DSA driver for the MT7628 embedded switch, with five 100Mbps user ports, a 1Gbps CPU port, and a 16-entry VLAN table that is used via tag_8021q for port isolation.

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

[ ... ]

Quoted 14 lines
drivers/net/dsa/mt7628.c new file +14 -0
+static int mt7628_mii_read(struct mii_bus *bus, int port, int regnum)
+{
+	struct mt7628_esw *esw = bus->priv;
+	int ret;
+	u32 val;
+
+	ret = regmap_read_poll_timeout(esw->regmap, MT7628_ESW_REG_PCR1, val,
+				       !(val & MT7628_ESW_PCR1_RD_DONE), 10,
+				       5000);
+	if (ret)
+		goto out;
+
+	ret = regmap_write(esw->regmap, MT7628_ESW_REG_PCR0,
+			   FIELD_PREP(MT7628_ESW_PCR0_CPU_PHY_REG,

drivers/net/dsa/mt7628.c line 195

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+				      regnum) |
+			   FIELD_PREP(MT7628_ESW_PCR0_CPU_PHY_ADDR,
+				      port) | MT7628_ESW_PCR0_RD_PHY_CMD);
+	if (ret)
+		goto out;
+
+	ret = regmap_read_poll_timeout(esw->regmap, MT7628_ESW_REG_PCR1, val,
+				       (val & MT7628_ESW_PCR1_RD_DONE), 10,
+				       5000);
+out:

Can these MDIO routines work after the first transaction?

Both mt7628_mii_read() and mt7628_mii_write() first poll for MT7628_ESW_PCR1_RD_DONE / WT_DONE to be clear, then issue the PCR0 command, then poll for the done bit to become set. Nothing in the driver writes-to-clear these done bits.

After a successful read, MT7628_ESW_PCR1_RD_DONE is 1 (that is the loop's exit condition). On the next mt7628_mii_read() call the first poll waits for it to become 0, which only happens if the hardware auto-clears the done bit on a new PCR0 command write.

Is that hardware behavior documented? Similar MediaTek DSA drivers (mt7530/mt7531) do not precede the command with a wait-for-not-done poll. If the bit does not self-clear on command issue, every MDIO transaction after the first would spin for ~5ms and return -ETIMEDOUT.

Quoted 6 lines
drivers/net/dsa/mt7628.c new file +6 -0
+	if (ret) {
+		dev_err(&bus->dev, "read failed. MDIO timeout?\n");
+		return ret;
+	}
+	return FIELD_GET(MT7628_ESW_PCR1_RD_DATA, val);
+}

[ ... ]

Quoted 5 lines
drivers/net/dsa/mt7628.c new file +5 -0
+static void mt7628_switch_init(struct dsa_switch *ds)
+{
+	struct mt7628_esw *esw = ds->priv;
+
+	regmap_write(esw->regmap, MT7628_ESW_REG_FCT0,

[ ... ]

drivers/net/dsa/mt7628.c line 355

Quoted 5 lines
drivers/net/dsa/mt7628.c new file +5 -0
+	regmap_update_bits(esw->regmap, MT7628_ESW_REG_PFC1,
+			   MT7628_ESW_PFC1_EN_VLAN,
+			   FIELD_PREP(MT7628_ESW_PFC1_EN_VLAN,
+				      MT7628_ESW_PORTS_ALL));
+}

Should mt7628_switch_init() also initialize MT7628_ESW_REG_POC0's PORT_DISABLE field to a known state?

DSA only invokes .port_enable / .port_disable for ports described in the DT and brought up by the stack. The CPU port and the non-existent port 5 are never touched, so they stay at the hardware reset default. If the default is enabled, traffic may be forwarded on ports the driver believes are inactive; if disabled, the CPU port may never come up because mt7628_port_enable() is only called for user ports.

Other DSA drivers (for example b53_common.c) explicitly set all port enable bits to a known state in .setup() before letting per-port callbacks modify them. Is a similar initialization needed here?

[ ... ]

Quoted 2 lines
drivers/net/dsa/mt7628.c new file +2 -0
+static void mt7628_vlan_sync(struct dsa_switch *ds)
+{

[ ... ]

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

drivers/net/dsa/mt7628.c line 419

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+
+	reset_control_reset(esw->rst_esw);
+	usleep_range(1000, 2000);
+	reset_control_reset(esw->rst_ephy);
+	usleep_range(1000, 2000);
+	/*
+	 * all MMIO reads hang if esw is not out of reset
+	 * ephy needs extra time to get out of reset or it ends up misconfigured
+	 */
+	mt7628_switch_init(ds);

Should the return values from reset_control_reset() be checked?

The comment in this function says "all MMIO reads hang if esw is not out of reset". reset_control_reset() can fail with -EBUSY, -ENOTSUPP and similar (see drivers/reset/core.c), and on failure mt7628_switch_init() proceeds to issue regmap writes/reads against a block still held in reset, which by this comment hangs the CPU.

Can these return values be propagated from mt7628_setup()?

[ ... ]

Quoted 6 lines
drivers/net/dsa/mt7628.c new file +6 -0
+static void mt7628_phylink_get_caps(struct dsa_switch *ds, int port,
+				    struct phylink_config *config)
+{
+	switch (port) {
+	case 6:
+		config->mac_capabilities |= MAC_1000;

drivers/net/dsa/mt7628.c line 471

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+		fallthrough;
+	case 0 ... 4:
+		config->mac_capabilities |= MAC_100 | MAC_10;
+		__set_bit(PHY_INTERFACE_MODE_INTERNAL,
+			  config->supported_interfaces);
+		break;
+	default:
+		break;		/* port 5 does not exist on MT7628 */
+	}
+}

How is port 5 meant to be handled?

ds->num_ports is set to MT7628_ESW_NUM_PORTS (7), but this function comments that port 5 does not exist on MT7628 and leaves its capabilities empty. DSA iterates 0..num_ports-1 in several generic paths (for example the tag_8021q setup loop), and phylink setup on a port with empty mac_capabilities and no supported_interfaces will warn.

The driver appears to rely on the DT never declaring a port@5 node. Is that implicit contract intentional, and should it be documented or enforced (for example by rejecting a port@5 in probe)?

Quoted 8 lines
drivers/net/dsa/mt7628.c new file +8 -0
+
+static int mt7628_dsa_8021q_vlan_add(struct dsa_switch *ds, int port,
+				     u16 vid, u16 flags)
+{
+	struct mt7628_esw *esw = ds->priv;
+	struct mt7628_vlan *vlan = NULL;
+	int i;
+

drivers/net/dsa/mt7628.c line 489

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+	for (i = 0; i < MT7628_NUM_VLANS; i++) {
+		struct mt7628_vlan *check_vlan = &esw->vlans[i];
+
+		if (!check_vlan->active && !vlan) {
+			vlan = check_vlan;
+		} else if (check_vlan->vid == vid) {
+			vlan = check_vlan;
+			break;
+		}
+	}

Is the else-if branch here intentional for inactive slots?

mt7628_dsa_8021q_vlan_del() clears members, untag and active, but leaves vlan->vid untouched:

	vlan->members &= ~BIT(port);
	vlan->untag &= ~BIT(port);

	if (!vlan->members)
		vlan->active = false;

An inactive slot that previously held the same VID will therefore match via check_vlan->vid == vid and be reused. For vid == 0 every pristine zero-initialized slot also matches, making slot selection non-deterministic.

tag_8021q currently composes non-zero VIDs (see DSA_8021Q_RSV in net/dsa/tag_8021q.c), so vid == 0 is not reachable via tag_8021q today, but the .tag_8021q_vlan_add API itself accepts any u16. Would guarding the match with check_vlan->active (or clearing vid on delete) make the allocator more robust?

Quoted 34 lines
drivers/net/dsa/mt7628.c new file +34 -0
+
+	if (!vlan)
+		return -ENOSPC;
+
+	vlan->vid = vid;
+	vlan->active = true;
+	vlan->members |= BIT(port);
+
+	if (flags & BRIDGE_VLAN_INFO_PVID)
+		esw->tag_8021q_pvid[port] = vid;
+
+	if (flags & BRIDGE_VLAN_INFO_UNTAGGED)
+		vlan->untag |= BIT(port);
+
+	mt7628_vlan_sync(ds);
+	return 0;
+}
+
+static int mt7628_dsa_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid)
+{
+	struct mt7628_esw *esw = ds->priv;
+	struct mt7628_vlan *vlan = NULL;
+	int i;
+
+	for (i = 0; i < MT7628_NUM_VLANS; i++) {
+		struct mt7628_vlan *check_vlan = &esw->vlans[i];
+
+		if (!check_vlan->active || check_vlan->vid != vid)
+			continue;
+		vlan = check_vlan;
+		break;
+	}
+	if (!vlan)
+		return -ENOENT;

drivers/net/dsa/mt7628.c line 533

Quoted 10 lines
drivers/net/dsa/mt7628.c new file +10 -0
+
+	vlan->members &= ~BIT(port);
+	vlan->untag &= ~BIT(port);
+
+	if (!vlan->members)
+		vlan->active = false;
+
+	mt7628_vlan_sync(ds);
+	return 0;
+}

Should vlan_del also clear esw->tag_8021q_pvid[port] when the VID being deleted is the port's current PVID?

mt7628_vlan_sync() unconditionally programs esw->tag_8021q_pvid[port] into MT7628_ESW_REG_PVIDC for every port:

	for (i = 0; i < ds->num_ports; i++)
		mt7628_esw_set_pvid(esw, i, esw->tag_8021q_pvid[i]);

If the VLAN being deleted becomes inactive (members == 0), the hardware PVID for the port still references that VLAN slot, which will be reprogrammed with empty members/untag. Untagged ingress on that port would then be tagged with a VID whose VLAN table entry has no members.

In the normal bridge_join/bridge_leave flow (dsa_tag_8021q_bridge_join/leave in net/dsa/tag_8021q.c) the replacement VID is added (with BRIDGE_VLAN_INFO_PVID) before the old one is deleted, which masks the issue. On teardown/unbind (dsa_tag_8021q_port_teardown() deletes without a preceding add) the stale pvid can linger and be re-applied by any later vlan_sync.

drivers/net/dsa/mt7628.c line 542

Quoted 9 lines
drivers/net/dsa/mt7628.c new file +9 -0
+
+static void mt7628_teardown(struct dsa_switch *ds)
+{
+	rtnl_lock();
+	dsa_tag_8021q_unregister(ds);
+	rtnl_unlock();
+}
+
+static struct dsa_switch_ops mt7628_switch_ops = {
       ^^^^^^

This isn't a bug, but should mt7628_switch_ops be const? struct dsa_switch holds a const struct dsa_switch_ops *ops, and other DSA drivers (mt7530, sja1105, felix, ...) declare their ops tables const so the vtable lives in .rodata.

Quoted 9 lines
drivers/net/dsa/mt7628.c new file +9 -0
+	.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,
+};

[ ... ]

#9 lore raw
In reply to Joris Vaisvila
Quoted 9 lines · Joris Vaisvila

Hello,

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.

Quoted 6 lines

Bridge offloading is not yet supported.

Tested on an MT7628NN-based board.

changes since v2:
- fix binding issues found in review

Which issues exactly?

This has to be specific.

Best regards,
Krzysztof

#10 lore raw
Quoted 17 lines · Krzysztof Kozlowski
Quoted 9 lines · Joris Vaisvila

Hello,

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.

Quoted 6 lines

Bridge offloading is not yet supported.

Tested on an MT7628NN-based board.

changes since v2:
- fix binding issues found in review

Quoted 7 lines

Which issues exactly?

This has to be specific.

Best regards,
Krzysztof

Hi Krzysztof,

My bad. These are the binding changes since v2:

- Removed description from reg property
- Clarify reset descriptions
- Added ethernet-ports to required
- Fix reg coming before compatible in the example
- Replaced 'ports' and 'port' with 'ethernet-ports' and 'ethernet-port' respectively in the example