Skip to contentSkip to conversation

Add ethernet support for the Amlogic T7

PATCH Superseded Lucas Tanure 5 participants 20 messages Oct 22 – Nov 3

Subsystems (6)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add ethernet support for the Amlogic T7

The T7 has the same ethernet glue as the G12A. This adds the binding, the driver support and the device tree nodes, and enables the port on the Khadas VIM4.

Two clocks are new. The pipeline stage between the controller and the DRAM has its own gate, which nothing else claims. The glue registers sit in a block gated by sys_ethphy, so far claimed only by the MDIO mux, which probes after the glue is programmed: every write to PRG_ETH0/1 was lost. The T7 node lists that clock as "pclk".

The delays follow ethernet-controller.yaml: phy-mode is never changed, the PHY adds the 2ns, and the T7 accepts only rx-internal-delay-ps, as fine tuning. Its TX side is a quarter-period phase selector with no small step, so tx-internal-delay-ps is not valid for it. The VIM4 is plain rgmii-id. v3 said the RTL8211F TX delay did not work; that test ran with the glue registers gated, so the bootloader's MAC TX delay stayed on and the link had 4ns on TX.

Tested on v7.3-4494-g2a08195e4db5 plus "clk: meson: t7: keep the memory fabric clocks running" (clk-meson-next): 940/941Mbit/s with iperf3, no CRC error in 421k frames.

Overlaps with Xianwei Zhao's "[PATCH v2 0/3] t7: add some nodes for Amlogc t7."; I will drop or rebase whatever overlaps once we agree.

Changes since v3:
- phy-mode untouched, the PHY adds the 2ns, rx-internal-delay-ps is tuning only, tx-internal-delay-ps not valid for the T7
- 0 dropped from rx-internal-delay-ps; vendor delay properties explicitly false for the T7
- init_delays callback; the old parsing moved into the older-SoC function, marked not for new SoCs; patch 4 renamed
- VIM4 without tx-internal-delay-ps, the PHY TX delay works
- Meson8m2 moved to the dwmac-3.70a list; its boards warn in dtbs_check until Martin's dtsi patch lands
- the delay table in ethernet-controller.yaml dropped
- Martin's Reviewed-by on patch 3

Changes since v2:
- the controller-side delays are applied on a T7-only path instead of changing every Amlogic board (Andrew); the PHY mode left over comes from phy_fix_phy_mode_for_mac_delays() (Maxime)
- tx-internal-delay-ps is checked against the four values the hardware has, in the binding and in the driver, instead of being truncated (Sashiko)
- amlogic,tx-delay-ns and amlogic,rx-delay-ns are not valid for the T7 (Neil, Andrew)
- the on-chip PHY no longer carries max-speed, phylib reads what the chip reports (Andrew); same for the RTL8211F on the VIM4
- the PHY interrupt line, GPIOH_6, is described on the VIM4 (Sashiko)
- new: the T7 node owns sys_ethphy as "pclk", see above
- new patch 8: the delay ownership table in ethernet-controller.yaml
- no longer RFC
- Conor's Acked-by dropped from patch 2 and Neil's Reviewed-by from patch 6, as both patches changed. Patches 1, 3 and 5 only moved in the series, so their tags stay.

Changes since v1:
- new patch 1: honour tx-internal-delay-ps and rx-internal-delay-ps in the rgmii-*id modes, and pass the PHY whatever delay is left over
- vim4: phy-mode rgmii -> rgmii-id, and amlogic,tx-delay-ns plus rx-internal-delay-ps replaced by tx-internal-delay-ps = <2000>. Neil's Reviewed-by dropped from this one, the change is not cosmetic

Lucas Tanure (7):
dt-bindings: net: amlogic,meson-dwmac: list the compatible
combinations
dt-bindings: net: amlogic,meson-dwmac: add amlogic,t7-dwmac
net: stmmac: dwmac-meson8b: add support for the Amlogic T7
net: stmmac: dwmac-meson8b: follow the generic RGMII delay rules on
the T7
arm64: dts: amlogic: t7: add the ethernet pinctrl nodes
arm64: dts: amlogic: t7: add the ethernet controller
arm64: dts: amlogic: t7: khadas-vim4: enable the ethernet port

 .../bindings/net/amlogic,meson-dwmac.yaml     |  89 +++++++++--
 .../amlogic/amlogic-t7-a311d2-khadas-vim4.dts |  19 +++
 arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi   |  88 +++++++++++
 .../ethernet/stmicro/stmmac/dwmac-meson8b.c   | 139 +++++++++++++-----
 4 files changed, 284 insertions(+), 51 deletions(-)
Signature · 1 line
2.56.0
#1 lore raw

PATCH v4 1/7 dt-bindings: net: amlogic,meson-dwmac: list the compatible combinations

The compatible property only checks that the first entry is an Amlogic name and that "snps,dwmac" or "snps,dwmac-3.70a" appears somewhere in the list. It cannot express which fallbacks each SoC takes, so a SoC built on a different Synopsys core cannot be added without loosening the check for every other one.

List the combinations the device trees use: Meson6 falls back to "snps,dwmac" alone, the others also name the 3.70a core. The Meson8m2 reports a 3.70a core too, so it joins that list; its dtsi gets the missing entry in a separate patch. The example used a two-entry form no device tree has, so give it the Meson GXBB combination.

---
 .../bindings/net/amlogic,meson-dwmac.yaml     | 29 +++++++++----------
 1 file changed, 14 insertions(+), 15 deletions(-)
Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml +14 -15
index 5c91716d1f21..69244afc4ff8 100644
@@ -129,20 +129,19 @@ allOf:
 
 properties:
   compatible:
-    additionalItems: true
-    maxItems: 3
-    items:
-      - enum:
-          - amlogic,meson6-dwmac
-          - amlogic,meson8b-dwmac
-          - amlogic,meson8m2-dwmac
-          - amlogic,meson-gxbb-dwmac
-          - amlogic,meson-axg-dwmac
-          - amlogic,meson-g12a-dwmac
-    contains:
-      enum:
-        - snps,dwmac-3.70a
-        - snps,dwmac
+    oneOf:
+      - items:
+          - enum:
+              - amlogic,meson8b-dwmac
+              - amlogic,meson8m2-dwmac
+              - amlogic,meson-gxbb-dwmac
+              - amlogic,meson-axg-dwmac
+              - amlogic,meson-g12a-dwmac
+          - const: snps,dwmac-3.70a
+          - const: snps,dwmac
+      - items:
+          - const: amlogic,meson6-dwmac
+          - const: snps,dwmac
 
   reg:
     items:
@@ -172,7 +171,7 @@ unevaluatedProperties: false
 examples:
   - |
     ethmac: ethernet@c9410000 {
-        compatible = "amlogic,meson-gxbb-dwmac", "snps,dwmac";
+        compatible = "amlogic,meson-gxbb-dwmac", "snps,dwmac-3.70a", "snps,dwmac";
         reg = <0xc9410000 0x10000>, <0xc8834540 0x8>;
         interrupts = <8>;
         interrupt-names = "macirq";
Signature · 1 line
2.56.0
#2 lore raw

PATCH v4 2/7 dt-bindings: net: amlogic,meson-dwmac: add amlogic,t7-dwmac

In reply to Lucas Tanure

The T7 has the same ethernet glue as the G12A but needs two clocks of its own. The controller reaches memory through a pipeline stage with its own gate; nothing else claims it, so it is switched off as unused and transfers never finish. The glue registers sit in a block clocked together with the MDIO multiplexer, which probes after the controller has programmed them: the writes are lost and the port keeps the bootloader's delays.

So the T7 gets its own clock list, without the timing adjustment clock it never uses. Its delays follow ethernet-controller.yaml: the PHY adds the 2ns, and only the receive delay line offers fine tuning, so only rx-internal-delay-ps is valid here.

Assisted-by LLM
---
 .../bindings/net/amlogic,meson-dwmac.yaml     | 60 +++++++++++++++++++
 1 file changed, 60 insertions(+)
Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml +60 -0
index 69244afc4ff8..d27f0f2c52b0 100644
@@ -23,6 +23,7 @@ select:
           - amlogic,meson-gxbb-dwmac
           - amlogic,meson-axg-dwmac
           - amlogic,meson-g12a-dwmac
+          - amlogic,t7-dwmac
   required:
     - compatible
 
@@ -57,6 +58,61 @@ allOf:
             - const: clkin1
             - const: timing-adjustment
 
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: amlogic,t7-dwmac
+    then:
+      properties:
+        clocks:
+          items:
+            - description: GMAC main clock
+            - description: First parent clock of the internal mux
+            - description: Second parent clock of the internal mux
+            - description:
+                clock of the pipeline stage inserted in the bus path between
+                the controller and the DRAM. Without it, the controller cannot
+                complete DMA transfers.
+            - description:
+                clock of the register block holding PRG_ETH0 and PRG_ETH1.
+                Without it, the block reads as zero and ignores writes.
+
+        clock-names:
+          items:
+            - const: stmmaceth
+            - const: clkin0
+            - const: clkin1
+            - const: pipeline
+            - const: pclk
+
+        # The PHY adds the 2ns RGMII delays, see ethernet-controller.yaml.
+        # The RX delay line of this glue is fine tuning in 200ps steps,
+        # added on top of what phy-mode describes. The TX side has no fine
+        # tuning: its only step is a quarter of the clock period, the full
+        # 2ns at 1Gbit/s, so the TX property is not accepted.
+        tx-internal-delay-ps: false
+
+        rx-internal-delay-ps:
+          enum: [200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000,
+                 2200, 2400, 2600, 2800, 3000]
+
+        amlogic,tx-delay-ns: false
+        amlogic,rx-delay-ns: false
+
+  # Delay definitions for Meson8b and newer
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - amlogic,meson8b-dwmac
+              - amlogic,meson8m2-dwmac
+              - amlogic,meson-gxbb-dwmac
+              - amlogic,meson-axg-dwmac
+              - amlogic,meson-g12a-dwmac
+    then:
+      properties:
         amlogic,tx-delay-ns:
           enum: [0, 2, 4, 6]
           default: 2
@@ -142,6 +198,10 @@ properties:
       - items:
           - const: amlogic,meson6-dwmac
           - const: snps,dwmac
+      - items:
+          - const: amlogic,t7-dwmac
+          - const: snps,dwmac-5.10a
+          - const: snps,dwmac
 
   reg:
     items:
Signature · 1 line
2.56.0
#3 lore raw

Re: [PATCH v4 2/7] dt-bindings: net: amlogic,meson-dwmac: add amlogic,t7-dwmac

Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml allOf: · line 98

Quoted 10 lines
Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml +10 -0
+        # The PHY adds the 2ns RGMII delays, see ethernet-controller.yaml.
+        # The RX delay line of this glue is fine tuning in 200ps steps,
+        # added on top of what phy-mode describes. The TX side has no fine
+        # tuning: its only step is a quarter of the clock period, the full
+        # 2ns at 1Gbit/s, so the TX property is not accepted.
+        tx-internal-delay-ps: false
+
+        rx-internal-delay-ps:
+          enum: [200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000,
+                 2200, 2400, 2600, 2800, 3000]

This is good, thanks.

Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml allOf: · line 101

Quoted 3 lines
Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml +3 -0
+
+        amlogic,tx-delay-ns: false
+        amlogic,rx-delay-ns: false

Maybe add a comment that these are deprecated in new SoCs favour of the standard {rx|tx}-internal-delay-ps properties.

Andrew

#4 lore raw

Re: [PATCH v4 2/7] dt-bindings: net: amlogic,meson-dwmac: add amlogic,t7-dwmac

Quoted 12 lines · Andrew Lunn

Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml allOf: · line 98

Quoted 11 lines
Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml +10 -0
+        # The PHY adds the 2ns RGMII delays, see ethernet-controller.yaml.
+        # The RX delay line of this glue is fine tuning in 200ps steps,
+        # added on top of what phy-mode describes. The TX side has no fine
+        # tuning: its only step is a quarter of the clock period, the full
+        # 2ns at 1Gbit/s, so the TX property is not accepted.
+        tx-internal-delay-ps: false
+
+        rx-internal-delay-ps:
+          enum: [200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000,
+                 2200, 2400, 2600, 2800, 3000]
Quoted 8 lines

This is good, thanks.

Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml allOf: · line 101

Quoted 3 lines
Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml +3 -0
+
+        amlogic,tx-delay-ns: false
+        amlogic,rx-delay-ns: false

Maybe add a comment that these are deprecated in new SoCs favour of the standard {rx|tx}-internal-delay-ps properties.

Done in v5.

Quoted 3 lines

Andrew

#5 lore raw

Re: [PATCH v4 2/7] dt-bindings: net: amlogic,meson-dwmac: add amlogic,t7-dwmac

In reply to Lucas Tanure

Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml allOf: · line 98

Quoted 3 lines
Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml +3 -0
+        rx-internal-delay-ps:
+          enum: [200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000,
+                 2200, 2400, 2600, 2800, 3000]

Is 0 possible with the hardware? If so, i would accept it.

Andrew

#6 lore raw

Re: [PATCH v4 2/7] dt-bindings: net: amlogic,meson-dwmac: add amlogic,t7-dwmac

Quoted 6 lines · Andrew Lunn

Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml allOf: · line 98

Quoted 4 lines
Documentation/devicetree/bindings/net/amlogic,meson-dwmac.yaml +3 -0
+        rx-internal-delay-ps:
+          enum: [200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000,
+                 2200, 2400, 2600, 2800, 3000]

Is 0 possible with the hardware? If so, i would accept it.

Yes, 0 is the delay line switched off. v5 accepts it, and the T7 joins the existing G12A list in the binding instead of carrying its own.

Quoted 2 lines

Andrew

#7 lore raw

PATCH v4 3/7 net: stmmac: dwmac-meson8b: add support for the Amlogic T7

In reply to Lucas Tanure

The glue registers on the T7 are laid out exactly as the G12A ones, RX delay field included, so the T7 can reuse the G12A settings.

What it does not share is how the controller reaches memory. That path runs through a pipeline stage with a gate of its own, and no other device has any use for that gate. Nothing claims it, so it is switched off as unused and a transfer that has started can never finish.

Without that gate the controller cannot do DMA at all, so it is required rather than optional: a clear probe failure beats an undiagnosable hang later.

---
 .../ethernet/stmicro/stmmac/dwmac-meson8b.c   | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c +19 -0
index e4d5c41294f4..450f7b4b29a6 100644
@@ -81,6 +81,7 @@ struct meson8b_dwmac;
 struct meson8b_dwmac_data {
 	int (*set_phy_mode)(struct meson8b_dwmac *dwmac);
 	bool has_prg_eth1_rgmii_rx_delay;
+	bool has_pipeline_clk;
 };
 
 struct meson8b_dwmac {
@@ -384,6 +385,7 @@ static int meson8b_dwmac_probe(struct platform_device *pdev)
 	struct plat_stmmacenet_data *plat_dat;
 	struct stmmac_resources stmmac_res;
 	struct meson8b_dwmac *dwmac;
+	struct clk *pipeline_clk;
 	int ret;
 
 	ret = stmmac_get_platform_resources(pdev, &stmmac_res);
@@ -443,6 +445,13 @@ static int meson8b_dwmac_probe(struct platform_device *pdev)
 	if (IS_ERR(dwmac->timing_adj_clk))
 		return PTR_ERR(dwmac->timing_adj_clk);
 
+	if (dwmac->data->has_pipeline_clk) {
+		pipeline_clk = devm_clk_get_enabled(dwmac->dev, "pipeline");
+		if (IS_ERR(pipeline_clk))
+			return dev_err_probe(dwmac->dev, PTR_ERR(pipeline_clk),
+					     "missing pipeline clock\n");
+	}
+
 	ret = meson8b_init_rgmii_delays(dwmac);
 	if (ret)
 		return ret;
@@ -479,6 +488,12 @@ static const struct meson8b_dwmac_data meson_g12a_dwmac_data = {
 	.has_prg_eth1_rgmii_rx_delay = true,
 };
 
+static const struct meson8b_dwmac_data meson_t7_dwmac_data = {
+	.set_phy_mode = meson_axg_set_phy_mode,
+	.has_prg_eth1_rgmii_rx_delay = true,
+	.has_pipeline_clk = true,
+};
+
 static const struct of_device_id meson8b_dwmac_match[] = {
 	{
 		.compatible = "amlogic,meson8b-dwmac",
@@ -500,6 +515,10 @@ static const struct of_device_id meson8b_dwmac_match[] = {
 		.compatible = "amlogic,meson-g12a-dwmac",
 		.data = &meson_g12a_dwmac_data,
 	},
+	{
+		.compatible = "amlogic,t7-dwmac",
+		.data = &meson_t7_dwmac_data,
+	},
 	{ }
 };
 MODULE_DEVICE_TABLE(of, meson8b_dwmac_match);
Signature · 1 line
2.56.0
#8 lore raw

Re: [PATCH v4 3/7] net: stmmac: dwmac-meson8b: add support for the Amlogic T7

Quoted 3 lines

Without that gate the controller cannot do DMA at all, so it is required rather than optional: a clear probe failure beats an undiagnosable hang later.

Does the DT binding mark it as required?

Andrew

#9 lore raw

Re: [PATCH v4 3/7] net: stmmac: dwmac-meson8b: add support for the Amlogic T7

Quoted 6 lines · Andrew Lunn
Quoted 4 lines

Without that gate the controller cannot do DMA at all, so it is required rather than optional: a clear probe failure beats an undiagnosable hang later.

Does the DT binding mark it as required?

Yes. The T7 block in patch 2 lists the five clocks as an "items" list without minItems, so all five, pipeline included, are required.

Quoted 2 lines

Andrew

#10 lore raw

PATCH v4 4/7 net: stmmac: dwmac-meson8b: follow the generic RGMII delay rules on the T7

In reply to Lucas Tanure

The delay code reads phy-mode as the list of delays this glue has to add, falls back to a 2ns transmit delay when no property asks for one, and takes the vendor delay properties. ethernet-controller.yaml says the opposite: the PHY adds the 2ns delays, and the MAC properties only hold small fine tuning added on top. Every board in the tree depends on the old reading, so it stays.

The T7 has no boards yet, so it follows the generic rules. Its receive delay line is fine tuning, 200ps steps up to 3000ps. Its transmit side only has a quarter-period phase step, the full 2ns at 1Gbit/s, so there is nothing to fine tune and the transmit property is refused.

Assisted-by LLM
---
 .../ethernet/stmicro/stmmac/dwmac-meson8b.c   | 122 ++++++++++++------
 1 file changed, 85 insertions(+), 37 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c +85 -37
index 450f7b4b29a6..95a185691503 100644
@@ -80,6 +80,7 @@ struct meson8b_dwmac;
 
 struct meson8b_dwmac_data {
 	int (*set_phy_mode)(struct meson8b_dwmac *dwmac);
+	int (*init_delays)(struct meson8b_dwmac *dwmac);
 	bool has_prg_eth1_rgmii_rx_delay;
 	bool has_pipeline_clk;
 };
@@ -91,8 +92,6 @@ struct meson8b_dwmac {
 	const struct meson8b_dwmac_data	*data;
 	phy_interface_t			phy_mode;
 	struct clk			*rgmii_tx_clk;
-	u32				tx_delay_ns;
-	u32				rx_delay_ps;
 	struct clk			*timing_adj_clk;
 };
 
@@ -272,20 +271,91 @@ static int meson8b_devm_clk_prepare_enable(struct meson8b_dwmac *dwmac,
 					meson8b_clk_disable_unprepare, clk);
 }
 
+/*
+ * The T7 follows ethernet-controller.yaml: the PHY adds the 2ns RGMII
+ * delays and this glue only fine tunes the RX clock, on top of what
+ * phy-mode describes. The TX clock has no fine tuning, its only step is
+ * a quarter of the clock period, so the TX property is refused.
+ */
+static int meson_t7_init_delays(struct meson8b_dwmac *dwmac)
+{
+	struct device_node *np = dwmac->dev->of_node;
+	u32 rx_delay_ps = 0;
+
+	if (of_property_present(np, "tx-internal-delay-ps"))
+		return dev_err_probe(dwmac->dev, -EINVAL,
+				     "tx-internal-delay-ps is not supported, the PHY adds the TX delay\n");
+
+	if (!of_property_read_u32(np, "rx-internal-delay-ps", &rx_delay_ps)) {
+		if (!phy_interface_mode_is_rgmii(dwmac->phy_mode))
+			return dev_err_probe(dwmac->dev, -EINVAL,
+					     "rx-internal-delay-ps needs an RGMII phy-mode\n");
+
+		/* the RX delay line moves in 200ps steps and reaches 3000ps */
+		if (!rx_delay_ps || rx_delay_ps > 3000 || rx_delay_ps % 200)
+			return dev_err_probe(dwmac->dev, -EINVAL,
+					     "The RGMII RX delay range is 200..3000ps in 200ps steps\n");
+	}
+
+	meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TXDLY_MASK |
+				PRG_ETH0_ADJ_ENABLE | PRG_ETH0_ADJ_SETUP |
+				PRG_ETH0_ADJ_DELAY | PRG_ETH0_ADJ_SKEW, 0);
+
+	meson8b_dwmac_mask_bits(dwmac, PRG_ETH1, PRG_ETH1_CFG_RXCLK_DLY,
+				FIELD_PREP(PRG_ETH1_CFG_RXCLK_DLY,
+					   rx_delay_ps / 200));
+
+	return 0;
+}
+
+/*
+ * Delay handling of the SoCs up to the G12A. It reads phy-mode as the
+ * list of delays this glue has to add, falls back to a 2ns TX delay and
+ * takes the vendor delay properties, all of which ethernet-controller.yaml
+ * rules out. The boards in the tree depend on it, so it stays, but a new
+ * SoC must not use it.
+ */
 static int meson8b_init_rgmii_delays(struct meson8b_dwmac *dwmac)
 {
 	u32 tx_dly_config, rx_adj_config, cfg_rxclk_dly, delay_config;
+	struct device_node *np = dwmac->dev->of_node;
+	u32 tx_delay_ns, rx_delay_ps = 0;
 	int ret;
 
+	/* use 2ns as fallback since this value was previously hardcoded */
+	if (of_property_read_u32(np, "amlogic,tx-delay-ns", &tx_delay_ns))
+		tx_delay_ns = 2;
+
+	/* RX delay defaults to 0ps since this is what many boards use */
+	if (of_property_read_u32(np, "rx-internal-delay-ps", &rx_delay_ps)) {
+		if (!of_property_read_u32(np, "amlogic,rx-delay-ns",
+					  &rx_delay_ps))
+			/* convert ns to ps */
+			rx_delay_ps *= 1000;
+	}
+
+	if (dwmac->data->has_prg_eth1_rgmii_rx_delay) {
+		if (rx_delay_ps > 3000 || rx_delay_ps % 200) {
+			dev_err(dwmac->dev,
+				"The RGMII RX delay range is 0..3000ps in 200ps steps");
+			return -EINVAL;
+		}
+	} else {
+		if (rx_delay_ps != 0 && rx_delay_ps != 2000) {
+			dev_err(dwmac->dev,
+				"The only allowed RGMII RX delays values are: 0ps, 2000ps");
+			return -EINVAL;
+		}
+	}
+
 	rx_adj_config = 0;
 	cfg_rxclk_dly = 0;
-	tx_dly_config = FIELD_PREP(PRG_ETH0_TXDLY_MASK,
-				   dwmac->tx_delay_ns >> 1);
+	tx_dly_config = FIELD_PREP(PRG_ETH0_TXDLY_MASK, tx_delay_ns >> 1);
 
 	if (dwmac->data->has_prg_eth1_rgmii_rx_delay)
 		cfg_rxclk_dly = FIELD_PREP(PRG_ETH1_CFG_RXCLK_DLY,
-					   dwmac->rx_delay_ps / 200);
-	else if (dwmac->rx_delay_ps == 2000)
+					   rx_delay_ps / 200);
+	else if (rx_delay_ps == 2000)
 		rx_adj_config = PRG_ETH0_ADJ_ENABLE | PRG_ETH0_ADJ_SETUP;
 
 	switch (dwmac->phy_mode) {
@@ -411,35 +481,6 @@ static int meson8b_dwmac_probe(struct platform_device *pdev)
 	dwmac->dev = &pdev->dev;
 	dwmac->phy_mode = plat_dat->phy_interface;
 
-	/* use 2ns as fallback since this value was previously hardcoded */
-	if (of_property_read_u32(pdev->dev.of_node, "amlogic,tx-delay-ns",
-				 &dwmac->tx_delay_ns))
-		dwmac->tx_delay_ns = 2;
-
-	/* RX delay defaults to 0ps since this is what many boards use */
-	if (of_property_read_u32(pdev->dev.of_node, "rx-internal-delay-ps",
-				 &dwmac->rx_delay_ps)) {
-		if (!of_property_read_u32(pdev->dev.of_node,
-					  "amlogic,rx-delay-ns",
-					  &dwmac->rx_delay_ps))
-			/* convert ns to ps */
-			dwmac->rx_delay_ps *= 1000;
-	}
-
-	if (dwmac->data->has_prg_eth1_rgmii_rx_delay) {
-		if (dwmac->rx_delay_ps > 3000 || dwmac->rx_delay_ps % 200) {
-			dev_err(dwmac->dev,
-				"The RGMII RX delay range is 0..3000ps in 200ps steps");
-			return -EINVAL;
-		}
-	} else {
-		if (dwmac->rx_delay_ps != 0 && dwmac->rx_delay_ps != 2000) {
-			dev_err(dwmac->dev,
-				"The only allowed RGMII RX delays values are: 0ps, 2000ps");
-			return -EINVAL;
-		}
-	}
-
 	dwmac->timing_adj_clk = devm_clk_get_optional(dwmac->dev,
 						      "timing-adjustment");
 	if (IS_ERR(dwmac->timing_adj_clk))
@@ -452,7 +493,11 @@ static int meson8b_dwmac_probe(struct platform_device *pdev)
 					     "missing pipeline clock\n");
 	}
 
-	ret = meson8b_init_rgmii_delays(dwmac);
+	if (!dwmac->data->init_delays)
+		return dev_err_probe(dwmac->dev, -EINVAL,
+				     "missing init_delays callback\n");
+
+	ret = dwmac->data->init_delays(dwmac);
 	if (ret)
 		return ret;
 
@@ -475,22 +520,25 @@ static int meson8b_dwmac_probe(struct platform_device *pdev)
 
 static const struct meson8b_dwmac_data meson8b_dwmac_data = {
 	.set_phy_mode = meson8b_set_phy_mode,
+	.init_delays = meson8b_init_rgmii_delays,
 	.has_prg_eth1_rgmii_rx_delay = false,
 };
 
 static const struct meson8b_dwmac_data meson_axg_dwmac_data = {
 	.set_phy_mode = meson_axg_set_phy_mode,
+	.init_delays = meson8b_init_rgmii_delays,
 	.has_prg_eth1_rgmii_rx_delay = false,
 };
 
 static const struct meson8b_dwmac_data meson_g12a_dwmac_data = {
 	.set_phy_mode = meson_axg_set_phy_mode,
+	.init_delays = meson8b_init_rgmii_delays,
 	.has_prg_eth1_rgmii_rx_delay = true,
 };
 
 static const struct meson8b_dwmac_data meson_t7_dwmac_data = {
 	.set_phy_mode = meson_axg_set_phy_mode,
-	.has_prg_eth1_rgmii_rx_delay = true,
+	.init_delays = meson_t7_init_delays,
 	.has_pipeline_clk = true,
 };
 
Signature · 1 line
2.56.0
#11 lore raw

Re: [PATCH v4 4/7] net: stmmac: dwmac-meson8b: follow the generic RGMII delay rules on the T7

On Thu, Oct 22, 2026 at 10:06 PM Lucas Tanure <[email protected]> wrote:
[...]

drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c static int meson8b_dwmac_probe(struct platform_device *pdev) · line 498

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c +3 -0
+       if (!dwmac->data->init_delays)
+               return dev_err_probe(dwmac->dev, -EINVAL,
+                                    "missing init_delays callback\n");

I'd rather let this crash hard to make it obvious to someone adding a new SoC that they forgot something.

Other than that this looks good.
It would be great if the netdev maintainers could comment on whether this now matches the approach they had in mind.

#12 lore raw

Re: [PATCH v4 4/7] net: stmmac: dwmac-meson8b: follow the generic RGMII delay rules on the T7

Quoted 8 lines · Martin Blumenstingl

On Thu, Oct 22, 2026 at 10:06 PM Lucas Tanure <[email protected]> wrote:
[...]

drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c static int meson8b_dwmac_probe(struct platform_device *pdev) · line 498

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c +3 -0
+       if (!dwmac->data->init_delays)
+               return dev_err_probe(dwmac->dev, -EINVAL,
+                                    "missing init_delays callback\n");

I'd rather let this crash hard to make it obvious to someone adding a new SoC that they forgot something.

OK, the NULL check is gone in v5.

Quoted 3 lines

Other than that this looks good.
It would be great if the netdev maintainers could comment on whether this now matches the approach they had in mind.

#13 lore raw

Re: [PATCH v4 4/7] net: stmmac: dwmac-meson8b: follow the generic RGMII delay rules on the T7

In reply to Lucas Tanure

drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c static int meson8b_devm_clk_prepare_enable(struct meson8b_dwmac *dwmac, · line 323

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c +9 -0
+/*
+ * Delay handling of the SoCs up to the G12A. It reads phy-mode as the
+ * list of delays this glue has to add, falls back to a 2ns TX delay and
+ * takes the vendor delay properties, all of which ethernet-controller.yaml
+ * rules out. The boards in the tree depend on it, so it stays, but a new
+ * SoC must not use it.
+ */
 static int meson8b_init_rgmii_delays(struct meson8b_dwmac *dwmac)
 {
 	u32 tx_dly_config, rx_adj_config, cfg_rxclk_dly, delay_config;
+	struct device_node *np = dwmac->dev->of_node;
+	u32 tx_delay_ns, rx_delay_ps = 0;
 	int ret;

Does this code need to change?

It would be better if you did not need to change the old code, so you don't need to worry about breaking other SoCs. Just don't call it for the T7, use you new function in its place.

Andrew

#14 lore raw

Re: [PATCH v4 4/7] net: stmmac: dwmac-meson8b: follow the generic RGMII delay rules on the T7

Quoted 15 lines · Andrew Lunn
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c +3 -0
+/*
+ * Delay handling of the SoCs up to the G12A. It reads phy-mode as the
+ * list of delays this glue has to add, falls back to a 2ns TX delay and

drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c static int meson8b_devm_clk_prepare_enable(struct meson8b_dwmac *dwmac, · line 323

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c +6 -0
+ * takes the vendor delay properties, all of which ethernet-controller.yaml
+ * rules out. The boards in the tree depend on it, so it stays, but a new
+ * SoC must not use it.
+ */
 static int meson8b_init_rgmii_delays(struct meson8b_dwmac *dwmac)
 {
      u32 tx_dly_config, rx_adj_config, cfg_rxclk_dly, delay_config;
+     struct device_node *np = dwmac->dev->of_node;
+     u32 tx_delay_ns, rx_delay_ps = 0;
      int ret;
Quoted 5 lines

Does this code need to change?

It would be better if you did not need to change the old code, so you don't need to worry about breaking other SoCs. Just don't call it for the T7, use you new function in its place.

OK. In v5 the old code is untouched: the parsing stays in probe and meson8b_init_rgmii_delays() is as it was. The T7 gets a callback of its own, and the only change to probe is calling the callback instead of the function directly. The T7 keeps has_prg_eth1_rgmii_rx_delay, so the existing probe code already validates its RX value.

Quoted 2 lines

Andrew

#15 lore raw

PATCH v4 5/7 arm64: dts: amlogic: t7: add the ethernet pinctrl nodes

In reply to Lucas Tanure

The SoC brings its ethernet interface out on bank Z, but no pin groups were described, so a board had no way to hand those pins over to the MAC.

Describe them as the two sets a board actually needs: the nine pins the interface always uses, and the five extra ones RGMII adds for its wider data path.

---
 arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi | 30 +++++++++++++++++++++
 1 file changed, 30 insertions(+)
arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi +30 -0
index 6894c06a836b..7bd53ec16607 100644
@@ -376,6 +376,36 @@ mux {
 					};
 				};
 
+				eth_pins: eth {
+					mux {
+						groups = "eth_mdio",
+							 "eth_mdc",
+							 "eth_rgmii_rx_clk",
+							 "eth_rx_dv",
+							 "eth_rxd0",
+							 "eth_rxd1",
+							 "eth_txen",
+							 "eth_txd0",
+							 "eth_txd1";
+						function = "eth";
+						drive-strength-microamp = <4000>;
+						bias-disable;
+					};
+				};
+
+				eth_rgmii_pins: eth-rgmii {
+					mux {
+						groups = "eth_rxd2_rgmii",
+							 "eth_rxd3_rgmii",
+							 "eth_rgmii_tx_clk",
+							 "eth_txd2_rgmii",
+							 "eth_txd3_rgmii";
+						function = "eth";
+						drive-strength-microamp = <4000>;
+						bias-disable;
+					};
+				};
+
 				i2c0_ao_d_pins: i2c0-ao-d {
 					mux {
 						groups = "i2c0_ao_sck_d",
Signature · 1 line
2.56.0
#16 lore raw

PATCH v4 6/7 arm64: dts: amlogic: t7: add the ethernet controller

In reply to Lucas Tanure

The SoC has a Synopsys gigabit MAC, glue registers for the interface type and clock timing, and a multiplexer that points the management bus at the on-chip 100M PHY or the external pins. None of it was described.

The controller reaches memory through a pipeline stage with its own gate that nothing else claims, so it is switched off as unused. The glue registers share a clock with the multiplexer, which probes only after the controller has programmed them: unless the controller holds that clock itself, the writes are lost and the port keeps the bootloader's delays.

The on-chip PHY follows the G12A; no board in tree uses it, so it is untested. It stays disabled for boards to enable.

Assisted-by LLM
---
 arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi | 58 +++++++++++++++++++++
 1 file changed, 58 insertions(+)
arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi +58 -0
index 7bd53ec16607..94ea22514501 100644
@@ -250,6 +250,33 @@ gic: interrupt-controller@fff01000 {
 			interrupts = <GIC_PPI 9 (GIC_CPU_MASK_SIMPLE(8) | IRQ_TYPE_LEVEL_HIGH)>;
 		};
 
+		ethmac: ethernet@fdc00000 {
+			compatible = "amlogic,t7-dwmac",
+				     "snps,dwmac-5.10a",
+				     "snps,dwmac";
+			reg = <0x0 0xfdc00000 0x0 0x10000>,
+			      <0x0 0xfe024000 0x0 0x8>;
+			interrupts = <GIC_SPI 74 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "macirq";
+			clocks = <&clkc_periphs CLKID_SYS_ETH>,
+				 <&scmi_clk CLKID_FCLK_DIV2>,
+				 <&mpll CLKID_MPLL2>,
+				 <&clkc_periphs CLKID_SYS_AMPIPE_ETH>,
+				 <&clkc_periphs CLKID_SYS_ETHPHY>;
+			clock-names = "stmmaceth", "clkin0", "clkin1", "pipeline",
+				      "pclk";
+			power-domains = <&pwrc PWRC_T7_ETH_ID>;
+			rx-fifo-depth = <4096>;
+			tx-fifo-depth = <2048>;
+			status = "disabled";
+
+			mdio0: mdio {
+				compatible = "snps,dwmac-mdio";
+				#address-cells = <1>;
+				#size-cells = <0>;
+			};
+		};
+
 		apb4: bus@fe000000 {
 			compatible = "simple-bus";
 			reg = <0x0 0xfe000000 0x0 0x480000>;
@@ -645,6 +672,37 @@ gpio_intc: interrupt-controller@4080 {
 					<10 11 12 13 14 15 16 17 18 19 20 21>;
 			};
 
+			eth_phy: mdio-multiplexer@28000 {
+				compatible = "amlogic,g12a-mdio-mux";
+				reg = <0x0 0x28000 0x0 0xa4>;
+				clocks = <&clkc_periphs CLKID_SYS_ETHPHY>,
+					 <&xtal>,
+					 <&scmi_clk CLKID_FCLK_50M>;
+				clock-names = "pclk", "clkin0", "clkin1";
+				mdio-parent-bus = <&mdio0>;
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				ext_mdio: mdio@0 {
+					reg = <0>;
+					#address-cells = <1>;
+					#size-cells = <0>;
+				};
+
+				int_mdio: mdio@1 {
+					reg = <1>;
+					#address-cells = <1>;
+					#size-cells = <0>;
+
+					internal_ephy: ethernet-phy@8 {
+						compatible = "ethernet-phy-id0180.3301",
+							     "ethernet-phy-ieee802.3-c22";
+						interrupts = <GIC_SPI 340 IRQ_TYPE_LEVEL_HIGH>;
+						reg = <8>;
+					};
+				};
+			};
+
 			uart_a: serial@78000 {
 				compatible = "amlogic,t7-uart", "amlogic,meson-s4-uart";
 				reg = <0x0 0x78000 0x0 0x18>;
Signature · 1 line
2.56.0
#17 lore raw

Re: [PATCH v4 6/7] arm64: dts: amlogic: t7: add the ethernet controller

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] arm64: dts: amlogic: t7: missing status disabled on untested internal_ephy --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] arm64: dts: amlogic: t7: missing status disabled on untested internal_ephy --

commit 8b67e94cfb48fb74bfbb5053e5ce7da85b48466a
Author: Lucas Tanure <[email protected]>

arm64: dts: amlogic: t7: add the ethernet controller

This patch adds the Synopsys DWMAC ethernet controller, the MDIO multiplexer, and the internal 100M PHY nodes to the Amlogic T7 SoC device tree.

Quoted 4 lines
arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi +0 -0
index 7bd53ec166071..94ea225145015 100644

[ ... ]

Quoted 24 lines
arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi +20 -0
@@ -645,6 +672,37 @@ gpio_intc: interrupt-controller@4080 {
 					<10 11 12 13 14 15 16 17 18 19 20 21>;
 			};
 
+			eth_phy: mdio-multiplexer@28000 {
+				compatible = "amlogic,g12a-mdio-mux";
+				reg = <0x0 0x28000 0x0 0xa4>;
+				clocks = <&clkc_periphs CLKID_SYS_ETHPHY>,
+					 <&xtal>,
+					 <&scmi_clk CLKID_FCLK_50M>;
+				clock-names = "pclk", "clkin0", "clkin1";
+				mdio-parent-bus = <&mdio0>;
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				ext_mdio: mdio@0 {
+					reg = <0>;
+					#address-cells = <1>;
+					#size-cells = <0>;
+				};
+
+				int_mdio: mdio@1 {
+					reg = <1>;
+					#address-cells = <1>;

arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi gpio_intc: interrupt-controller@4080 { · line 704

Quoted 10 lines
arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi +10 -0
+					#size-cells = <0>;
+
+					internal_ephy: ethernet-phy@8 {
+						compatible = "ethernet-phy-id0180.3301",
+							     "ethernet-phy-ieee802.3-c22";
+						interrupts = <GIC_SPI 340 IRQ_TYPE_LEVEL_HIGH>;
+						reg = <8>;
+					};
+				};
+			};

[Severity: Medium]
The commit message states:

The on-chip PHY follows the G12A; no board in tree uses it, so it is untested. It stays disabled for boards to enable.

However, in arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi, only ethmac has status = "disabled"; while eth_phy, int_mdio, and internal_ephy are all left enabled by default.

When a board enables ethmac (even to use an external RGMII PHY on ext_mdio), g12a_mdio_mux_probe() calls mdio_mux_init() in drivers/net/mdio/mdio-mux.c, which registers every available child bus:

    for_each_available_child_of_node(mux_node, child_bus_node) {
        ...
        r = of_mdiobus_register(cb->mii_bus, child_bus_node);

Because internal_ephy under int_mdio is available and specifies a hardcoded PHY ID compatible string ("ethernet-phy-id0180.3301"), __of_mdiobus_parse_phys() in drivers/net/mdio/of_mdio.c creates and registers the PHY device without reading hardware ID registers:

    of_mdiobus_register()
      -> __of_mdiobus_parse_phys()
        -> fwnode_mdiobus_register_phy()
          -> phy_device_register()
            -> device_add()
              -> phy_probe()

During phy_probe() in drivers/net/phy/phy_device.c, MDIO reads issued by phy_disable_interrupts() and genphy_read_abilities() switch the mux to child bus 1 via g12a_mdio_switch_fn() -> g12a_enable_internal_mdio() in drivers/net/mdio/mdio-mux-meson-g12a.c:

    if (!__clk_is_enabled(priv->pll)) {
        ret = clk_prepare_enable(priv->pll);
        if (ret)
            return ret;
    }
    ...
    writel(PHY_CNTL2_USE_INTERNAL |
           PHY_CNTL2_SMI_SRC_MAC |
           PHY_CNTL2_RX_CLK_EPHY,
           priv->regs + ETH_PHY_CNTL2);

    value |= PHY_CNTL1_PHY_ENB;
    writel(value, priv->regs + ETH_PHY_CNTL1);

This powers on the untested internal EPHY PLL and enables the internal PHY in ETH_PHY_CNTL1 and ETH_PHY_CNTL2 even on boards using an external PHY.

Additionally, on T7 boards that leave ethmac disabled, leaving eth_phy enabled causes g12a_mdio_mux_probe() to enable pclk, program the PLL registers in g12a_ephy_pll_init(), and then fail in mdio_mux_init() with -EPROBE_DEFER because mdio0 is never registered.

Should internal_ephy (or int_mdio) and eth_phy have status = "disabled"; so that the untested internal PHY stays disabled until a board explicitly enables it?

Quoted 4 lines
arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi +0 -0
 			uart_a: serial@78000 {
 				compatible = "amlogic,t7-uart", "amlogic,meson-s4-uart";
 				reg = <0x0 0x78000 0x0 0x18>;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#18 lore raw

PATCH v4 7/7 arm64: dts: amlogic: t7: khadas-vim4: enable the ethernet port

In reply to Lucas Tanure

The board carries a Realtek RTL8211F gigabit PHY on the external management bus, connected to the MAC over RGMII.

Enable the controller, hand it the ethernet pins and point it at the PHY. RGMII needs a delay on each of its two clocks. The board traces add none, so the PHY adds both, which is what rgmii-id asks of it.

The PHY interrupt output is wired to GPIOH_6, so link changes are reported instead of polled. The PHY reset is an RC network on the board, not a SoC pin, so there is no reset line to describe.

Assisted-by LLM
---
 .../amlogic/amlogic-t7-a311d2-khadas-vim4.dts | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
arch/arm64/boot/dts/amlogic/amlogic-t7-a311d2-khadas-vim4.dts +19 -0
index 0fa83362b417..4914b0dff8a8 100644
@@ -14,6 +14,7 @@ / {
 	compatible = "khadas,vim4", "amlogic,a311d2", "amlogic,t7";
 
 	aliases {
+		ethernet0 = &ethmac;
 		serial0 = &uart_a;
 		mmc0 = &sd_emmc_c;
 		mmc1 = &sd_emmc_b;
@@ -256,6 +257,24 @@ xtal: xtal-clk {
 	};
 };
 
+&ethmac {
+	status = "okay";
+	pinctrl-0 = <&eth_pins>, <&eth_rgmii_pins>;
+	pinctrl-names = "default";
+	phy-mode = "rgmii-id";
+	phy-handle = <&external_phy>;
+};
+
+&ext_mdio {
+	external_phy: ethernet-phy@0 {
+		/* Realtek RTL8211FD-CG */
+		reg = <0>;
+
+		interrupt-parent = <&gpio_intc>;
+		interrupts = <GPIOH_6 IRQ_TYPE_LEVEL_LOW>;
+	};
+};
+
 &i2c_m_ao_a {
 	status = "okay";
 	pinctrl-0 = <&i2c0_ao_d_pins>;
Signature · 1 line
2.56.0
maintainer
#19 lore raw
In reply to Lucas Tanure
Quoted 3 lines · On Thu, 22 Oct 2026 21:06:33 +0100 Lucas Tanure wrote:

The T7 has the same ethernet glue as the G12A. This adds the binding, the driver support and the device tree nodes, and enables the port on the Khadas VIM4.

## Form letter - net-next-closed

The merge window for Linux v7.4 has begun, and the net-next tree is now closed for new drivers, features, code refactoring and optimizations. We are currently accepting bug fixes only.

Please repost when net-next reopens. There is some uncertainty about how long this merge window will last, so please check
https://netdev.bots.linux.dev/net-next.html
before reposting. net-next _may_ reopen on Nov 2nd.

See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle

Signature · 2 lines
pw-bot: defer
pv-bot: closed