Skip to contentSkip to conversation

net: stmmac: Add support for RZN1 GMAC devices

PATCH Superseded Romain Gantois 5 participants 13 messages Apr 2, 2024 – Apr 3, 2024

Subsystems (8)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Romain Gantois

author maintainer
#0 lore raw

cover net: stmmac: Add support for RZN1 GMAC devices

Hello everyone,

This is version one of my series that adds support for a Gigabit Ethernet controller featured in the Renesas r9a06g032 SoC, of the RZ/N1 family. This GMAC device is based on a Synopsys IP and is compatible with the stmmac driver.

My former colleague Clément Léger originally sent a series for this driver, but an issue in bringing up the PCS clock had blocked the upstreaming process. This issue has since been resolved by the following series:

https://lore.kernel.org/all/[email protected]/

This series consists of a devicetree binding describing the RZN1 GMAC controller IP, a node for the GMAC1 device in the r9a06g032 SoC device tree, and the GMAC driver itself which is a glue layer in stmmac.

Best Regards,

Romain Gantois

---
Clément Léger (3):
dt-bindings: net: renesas,rzn1-gmac: Document RZ/N1 GMAC support
net: stmmac: add support for RZ/N1 GMAC
ARM: dts: r9a06g032: describe GMAC1

 .../devicetree/bindings/net/renesas,rzn1-gmac.yaml | 66 ++++++++++++++++
 MAINTAINERS                                        |  6 ++
 arch/arm/boot/dts/renesas/r9a06g032.dtsi           | 19 +++++
 drivers/net/ethernet/stmicro/stmmac/Kconfig        | 12 +++
 drivers/net/ethernet/stmicro/stmmac/Makefile       |  1 +
 drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c   | 87 ++++++++++++++++++++++
 6 files changed, 191 insertions(+)

---
base-commit: 5fc68320c1fb3c7d456ddcae0b4757326a043e6f
change-id: 20240402-rzn1-gmac1-685cf8793d0e

Best regards,

Signature · 1 line
Romain Gantois <[email protected]>
author maintainer
#1 lore raw

PATCH 1/3 dt-bindings: net: renesas,rzn1-gmac: Document RZ/N1 GMAC support

From: Clément Léger <[email protected]>

The RZ/N1 series of MPUs feature up to two Gigabit Ethernet controllers. These controllers are based on Synopsys IPs. They can be connected to RZ/N1 RGMII/RMII converters.

Add a binding that describes these GMAC devices.

[rgantois: commit log]
---
 .../devicetree/bindings/net/renesas,rzn1-gmac.yaml | 66 ++++++++++++++++++++++
 1 file changed, 66 insertions(+)
Documentation/devicetree/bindings/net/renesas,rzn1-gmac.yaml new file +66 -0
new file mode 100644
index 000000000000..c6f61fb1e5b0
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/renesas,rzn1-gmac.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Renesas GMAC
+
+maintainers:
+  - Romain Gantois <[email protected]>
+
+select:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - renesas,r9a06g032-gmac
+          - renesas,rzn1-gmac
+  required:
+    - compatible
+
+allOf:
+  - $ref: snps,dwmac.yaml#
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - renesas,r9a06g032-gmac
+      - const: renesas,rzn1-gmac
+      - const: snps,dwmac
+
+  pcs-handle:
+    description:
+      phandle pointing to a PCS sub-node compatible with
+      renesas,rzn1-miic.yaml#
+
+required:
+  - compatible
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/r9a06g032-sysctrl.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    ethernet@44000000 {
+      compatible = "renesas,r9a06g032-gmac", "renesas,rzn1-gmac", "snps,dwmac";
+      reg = <0x44000000 0x2000>;
+      interrupt-parent = <&gic>;
+      interrupts = <GIC_SPI 34 IRQ_TYPE_LEVEL_HIGH>,
+                   <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>,
+                   <GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>;
+      interrupt-names = "macirq", "eth_wake_irq", "eth_lpi";
+      clock-names = "stmmaceth";
+      clocks = <&sysctrl R9A06G032_HCLK_GMAC0>;
+      snps,multicast-filter-bins = <256>;
+      snps,perfect-filter-entries = <128>;
+      tx-fifo-depth = <2048>;
+      rx-fifo-depth = <4096>;
+      pcs-handle = <&mii_conv1>;
+      phy-mode = "mii";
+    };
+
+...
Signature · 1 line
2.44.0
#2 lore raw

Re: [PATCH net-next 1/3] dt-bindings: net: renesas,rzn1-gmac: Document RZ/N1 GMAC support

Hi Romain,

Quoted 11 lines · Romain Gantois

From: Clément Léger <[email protected]>

The RZ/N1 series of MPUs feature up to two Gigabit Ethernet controllers. These controllers are based on Synopsys IPs. They can be connected to RZ/N1 RGMII/RMII converters.

Add a binding that describes these GMAC devices.

[rgantois: commit log]

Thanks for your patch!

Documentation/devicetree/bindings/net/renesas,rzn1-gmac.yaml line 51

Quoted 12 lines
Documentation/devicetree/bindings/net/renesas,rzn1-gmac.yaml new file +9 -0
 
+examples:
+  - |
+    #include <dt-bindings/clock/r9a06g032-sysctrl.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    ethernet@44000000 {
+      compatible = "renesas,r9a06g032-gmac", "renesas,rzn1-gmac", "snps,dwmac";
+      reg = <0x44000000 0x2000>;
+      interrupt-parent = <&gic>;

There is no need to use interrupt-parent in examples.

Documentation/devicetree/bindings/net/renesas,rzn1-gmac.yaml line 57

Quoted 6 lines
Documentation/devicetree/bindings/net/renesas,rzn1-gmac.yaml new file +6 -0
+      interrupts = <GIC_SPI 34 IRQ_TYPE_LEVEL_HIGH>,
+                   <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>,
+                   <GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>;
+      interrupt-names = "macirq", "eth_wake_irq", "eth_lpi";
+      clock-names = "stmmaceth";
+      clocks = <&sysctrl R9A06G032_HCLK_GMAC0>;

If you want this to be a real example, you should add power-domains.

Documentation/devicetree/bindings/net/renesas,rzn1-gmac.yaml line 64

Quoted 7 lines
Documentation/devicetree/bindings/net/renesas,rzn1-gmac.yaml new file +7 -0
+      snps,multicast-filter-bins = <256>;
+      snps,perfect-filter-entries = <128>;
+      tx-fifo-depth = <2048>;
+      rx-fifo-depth = <4096>;
+      pcs-handle = <&mii_conv1>;
+      phy-mode = "mii";
+    };

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author maintainer
#3 lore raw

PATCH 2/3 net: stmmac: add support for RZ/N1 GMAC

In reply to Romain Gantois

From: Clément Léger <[email protected]>

Add support for the Renesas RZ/N1 GMAC. This support can make use of a custom RZ/N1 PCS which is fetched by parsing the pcs-handle device tree property.

---
 MAINTAINERS                                      |  6 ++
 drivers/net/ethernet/stmicro/stmmac/Kconfig      | 12 ++++
 drivers/net/ethernet/stmicro/stmmac/Makefile     |  1 +
 drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c | 87 ++++++++++++++++++++++++
 4 files changed, 106 insertions(+)
MAINTAINERS +6 -0
index 6a233e1a3cf2..9735c7d2ee38 100644
@@ -18833,6 +18833,12 @@ F:	include/dt-bindings/net/pcs-rzn1-miic.h
 F:	include/linux/pcs-rzn1-miic.h
 F:	net/dsa/tag_rzn1_a5psw.c
 
+RENESAS RZ/N1 DWMAC GLUE LAYER
+M:	Romain Gantois <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/net/renesas,rzn1-gmac.yaml
+F:	drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c
+
 RENESAS RZ/N1 RTC CONTROLLER DRIVER
 M:	Miquel Raynal <[email protected]>
 L:	[email protected]
drivers/net/ethernet/stmicro/stmmac/Kconfig +12 -0
index 4ec61f1ee71a..05cc07b8f48c 100644
@@ -142,6 +142,18 @@ config DWMAC_ROCKCHIP
 	  This selects the Rockchip RK3288 SoC glue layer support for
 	  the stmmac device driver.
 
+config DWMAC_RZN1
+	tristate "Renesas RZ/N1 dwmac support"
+	default ARCH_RZN1
+	depends on OF && (ARCH_RZN1 || COMPILE_TEST)
+	select PCS_RZN1_MIIC
+	help
+	  Support for Ethernet controller on Renesas RZ/N1 SoC family.
+
+	  This selects the Renesas RZ/N1 SoC glue layer support for
+	  the stmmac device driver. This support can make use of a custom MII
+	  converter PCS device.
+
 config DWMAC_SOCFPGA
 	tristate "SOCFPGA dwmac support"
 	default ARCH_INTEL_SOCFPGA
drivers/net/ethernet/stmicro/stmmac/Makefile +1 -0
index 26cad4344701..c2f0e91f6bf8 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_DWMAC_MEDIATEK)	+= dwmac-mediatek.o
 obj-$(CONFIG_DWMAC_MESON)	+= dwmac-meson.o dwmac-meson8b.o
 obj-$(CONFIG_DWMAC_QCOM_ETHQOS)	+= dwmac-qcom-ethqos.o
 obj-$(CONFIG_DWMAC_ROCKCHIP)	+= dwmac-rk.o
+obj-$(CONFIG_DWMAC_RZN1)	+= dwmac-rzn1.o
 obj-$(CONFIG_DWMAC_SOCFPGA)	+= dwmac-altr-socfpga.o
 obj-$(CONFIG_DWMAC_STARFIVE)	+= dwmac-starfive.o
 obj-$(CONFIG_DWMAC_STI)		+= dwmac-sti.o
drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
2.44.0
#4 lore raw

Re: [PATCH net-next 2/3] net: stmmac: add support for RZ/N1 GMAC

Quoted 6 lines · Romain Gantois
drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c new file +6 -0
+	ret = stmmac_dvr_probe(dev, plat_dat, &stmmac_res);
+	if (ret)
+		return ret;
+
+	ndev = platform_get_drvdata(pdev);
+	priv = netdev_priv(ndev);

drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c line 53

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c new file +10 -0
+
+	pcs_node = of_parse_phandle(np, "pcs-handle", 0);
+	if (pcs_node) {
+		pcs = miic_create(dev, pcs_node);
+		of_node_put(pcs_node);
+		if (IS_ERR(pcs))
+			return PTR_ERR(pcs);
+
+		priv->hw->phylink_pcs = pcs;
+	}

I'm afraid that this fails at one of the most basic principles of kernel multi-threaded programming. stmmac_dvr_probe() as part of its work calls register_netdev() which publishes to userspace the network device.

Everything that is required must be setup _prior_ to publication to userspace to avoid races, because as soon as the network device is published, userspace can decide to bring that interface up. If one hasn't finished the initialisation, the interface can be brought up before that initialisation is complete.

I don't see anything obvious in the stmmac data structures that would allow you to hook in at an appropriate point before the register_netdev() but after the netdev has been created. The priv->hw data structure is created by stmmac_hwif_init()

I see that drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c is also guilty of this as well, and should be fixed. It's even worse because it does a truck load of stuff after stmmac_dvr_probe() which it most definitely should not be doing.

I definitely get the feeling that the structure of the stmmac driver is really getting out of hand, and is making stuff harder for people, and it's not improving over time - in fact, it's getting worse. It needs a *lot* of work to bring it back to a sane model.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#5 lore raw

Re: [PATCH net-next 2/3] net: stmmac: add support for RZ/N1 GMAC

Quoted 38 lines · Russell King (Oracle)
Quoted 6 lines · Romain Gantois
drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c new file +6 -0
+	ret = stmmac_dvr_probe(dev, plat_dat, &stmmac_res);
+	if (ret)
+		return ret;
+
+	ndev = platform_get_drvdata(pdev);
+	priv = netdev_priv(ndev);

drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c line 53

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c new file +10 -0
+
+	pcs_node = of_parse_phandle(np, "pcs-handle", 0);
+	if (pcs_node) {
+		pcs = miic_create(dev, pcs_node);
+		of_node_put(pcs_node);
+		if (IS_ERR(pcs))
+			return PTR_ERR(pcs);
+
+		priv->hw->phylink_pcs = pcs;
+	}

I'm afraid that this fails at one of the most basic principles of kernel multi-threaded programming. stmmac_dvr_probe() as part of its work calls register_netdev() which publishes to userspace the network device.

Everything that is required must be setup _prior_ to publication to userspace to avoid races, because as soon as the network device is published, userspace can decide to bring that interface up. If one hasn't finished the initialisation, the interface can be brought up before that initialisation is complete.

I don't see anything obvious in the stmmac data structures that would allow you to hook in at an appropriate point before the register_netdev() but after the netdev has been created. The priv->hw data structure is created by stmmac_hwif_init()

I see that drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c is also guilty of this as well, and should be fixed. It's even worse because it does a truck load of stuff after stmmac_dvr_probe() which it most definitely should not be doing.

Quoted 4 lines

I definitely get the feeling that the structure of the stmmac driver is really getting out of hand, and is making stuff harder for people, and it's not improving over time - in fact, it's getting worse. It needs a *lot* of work to bring it back to a sane model.

I'm not going to say that the two patches threaded to this email are "sane" but at least it avoids the problem. socfpga still has issues with initialisation done after register_netdev() though.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#6 lore raw

PATCH 1/2 net: stmmac: introduce pcs_init/pcs_exit stmmac operations

Introduce a mechanism whereby platforms can create their PCS instances prior to the network device being published to userspace, but after some of the core stmmac initialisation has been completed. This means that the data structures that platforms need will be available.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 14 ++++++++++++++
 include/linux/stmmac.h                            |  2 ++
 2 files changed, 16 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +14 -0
index fe3498e86de9..25fa33ae7017 100644
@@ -7208,6 +7208,12 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
 	if (ret)
 		return ret;
 
+	if (priv->plat->pcs_init) {
+		ret = priv->plat->pcs_init(priv, priv->hw);
+		if (ret)
+			return ret;
+	}
+
 	/* Get the HW capability (new GMAC newer than 3.50a) */
 	priv->hw_cap_support = stmmac_get_hw_features(priv);
 	if (priv->hw_cap_support) {
@@ -7290,6 +7296,12 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
 	return 0;
 }
 
+static void stmmac_hw_exit(struct stmmac_priv *priv)
+{
+	if (priv->plat->pcs_exit)
+		priv->plat->pcs_exit(priv, priv->hw);
+}
+
 static void stmmac_napi_add(struct net_device *dev)
 {
 	struct stmmac_priv *priv = netdev_priv(dev);
@@ -7804,6 +7816,7 @@ int stmmac_dvr_probe(struct device *device,
 	    priv->hw->pcs != STMMAC_PCS_RTBI)
 		stmmac_mdio_unregister(ndev);
 error_mdio_register:
+	stmmac_hw_exit(priv);
 	stmmac_napi_del(ndev);
 error_hw_init:
 	destroy_workqueue(priv->wq);
@@ -7844,6 +7857,7 @@ void stmmac_dvr_remove(struct device *dev)
 	if (priv->hw->pcs != STMMAC_PCS_TBI &&
 	    priv->hw->pcs != STMMAC_PCS_RTBI)
 		stmmac_mdio_unregister(ndev);
+	stmmac_hw_exit(priv);
 	destroy_workqueue(priv->wq);
 	mutex_destroy(&priv->lock);
 	bitmap_free(priv->af_xdp_zc_qps);
include/linux/stmmac.h +2 -0
index dfa1828cd756..941fde506e51 100644
@@ -285,6 +285,8 @@ struct plat_stmmacenet_data {
 	int (*crosststamp)(ktime_t *device, struct system_counterval_t *system,
 			   void *ctx);
 	void (*dump_debug_regs)(void *priv);
+	int (*pcs_init)(struct stmmac_priv *priv, struct mac_device_info *hw);
+	void (*pcs_exit)(struct stmmac_priv *priv, struct mac_device_info *hw);
 	void *bsp_priv;
 	struct clk *stmmac_clk;
 	struct clk *pclk;
Signature · 1 line
2.30.2
maintainer Reviewed-by on v1 1/2
#7 lore raw

Re: [Linux-stm32] [PATCH net-next 1/2] net: stmmac: introduce pcs_init/pcs_exit stmmac operations

Hello Russell,

Quoted 6 lines · On Tue, 02 Apr 2024 16:51:43 +0100 "Russell King (Oracle)"…

Introduce a mechanism whereby platforms can create their PCS instances prior to the network device being published to userspace, but after some of the core stmmac initialisation has been completed. This means that the data structures that platforms need will be available.

#8 lore raw

PATCH 2/2 net: stmmac: dwmac-socfpga: use pcs_init/pcs_exit

In reply to Russell King (Oracle)

Use the newly introduced pcs_init() and pcs_exit() operations to create and destroy the PCS instance at a more appropriate moment during the driver lifecycle, thereby avoiding publishing a network device to userspace that has not yet finished its PCS initialisation.

There are other similar issues with this driver which remain unaddressed, but these are out of scope for this patch.

---
 .../ethernet/stmicro/stmmac/dwmac-socfpga.c   | 109 +++++++++---------
 1 file changed, 55 insertions(+), 54 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +55 -54
index 12b4a80ea3aa..67ca163936c8 100644
@@ -379,6 +379,58 @@ static int socfpga_gen10_set_phy_mode(struct socfpga_dwmac *dwmac)
 	return 0;
 }
 
+static int socfpga_dwmac_pcs_init(struct stmmac_priv *priv,
+				  struct mac_device_info *hw)
+{
+	struct socfpga_dwmac *dwmac = priv->plat->bsp_priv;
+	struct regmap_config pcs_regmap_cfg = {
+		.reg_bits = 16,
+		.val_bits = 16,
+		.reg_shift = regmap_upshift(1),
+	};
+	struct mdio_regmap_config mrc;
+	struct regmap *pcs_regmap;
+	struct phylink_pcs *pcs;
+	struct mii_bus *pcs_bus;
+
+	if (!dwmac->tse_pcs_base)
+		return 0;
+
+	pcs_regmap = devm_regmap_init_mmio(priv->device, dwmac->tse_pcs_base,
+					   &pcs_regmap_cfg);
+	if (IS_ERR(pcs_regmap))
+		return PTR_ERR(pcs_regmap);
+
+	memset(&mrc, 0, sizeof(mrc));
+	mrc.regmap = pcs_regmap;
+	mrc.parent = priv->device;
+	mrc.valid_addr = 0x0;
+	mrc.autoscan = false;
+
+	/* Can't use ndev->name here because it will not have been initialised,
+	 * and in any case, the user can rename network interfaces at runtime.
+	 */
+	snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii",
+		 dev_name(priv->device));
+	pcs_bus = devm_mdio_regmap_register(priv->device, &mrc);
+	if (IS_ERR(pcs_bus))
+		return PTR_ERR(pcs_bus);
+
+	pcs = lynx_pcs_create_mdiodev(pcs_bus, 0);
+	if (IS_ERR(pcs))
+		return PTR_ERR(pcs);
+
+	hw->phylink_pcs = pcs;
+	return 0;
+}
+
+static void socfpga_dwmac_pcs_exit(struct stmmac_priv *priv,
+				   struct mac_device_info *hw)
+{
+	if (hw->phylink_pcs)
+		lynx_pcs_destroy(hw->phylink_pcs);
+}
+
 static int socfpga_dwmac_probe(struct platform_device *pdev)
 {
 	struct plat_stmmacenet_data *plat_dat;
@@ -426,6 +478,8 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
 	dwmac->ops = ops;
 	plat_dat->bsp_priv = dwmac;
 	plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed;
+	plat_dat->pcs_init = socfpga_dwmac_pcs_init;
+	plat_dat->pcs_exit = socfpga_dwmac_pcs_exit;
 
 	ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
 	if (ret)
@@ -444,48 +498,6 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_dvr_remove;
 
-	/* Create a regmap for the PCS so that it can be used by the PCS driver,
-	 * if we have such a PCS
-	 */
-	if (dwmac->tse_pcs_base) {
-		struct regmap_config pcs_regmap_cfg;
-		struct mdio_regmap_config mrc;
-		struct regmap *pcs_regmap;
-		struct mii_bus *pcs_bus;
-
-		memset(&pcs_regmap_cfg, 0, sizeof(pcs_regmap_cfg));
-		memset(&mrc, 0, sizeof(mrc));
-
-		pcs_regmap_cfg.reg_bits = 16;
-		pcs_regmap_cfg.val_bits = 16;
-		pcs_regmap_cfg.reg_shift = REGMAP_UPSHIFT(1);
-
-		pcs_regmap = devm_regmap_init_mmio(&pdev->dev, dwmac->tse_pcs_base,
-						   &pcs_regmap_cfg);
-		if (IS_ERR(pcs_regmap)) {
-			ret = PTR_ERR(pcs_regmap);
-			goto err_dvr_remove;
-		}
-
-		mrc.regmap = pcs_regmap;
-		mrc.parent = &pdev->dev;
-		mrc.valid_addr = 0x0;
-		mrc.autoscan = false;
-
-		snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", ndev->name);
-		pcs_bus = devm_mdio_regmap_register(&pdev->dev, &mrc);
-		if (IS_ERR(pcs_bus)) {
-			ret = PTR_ERR(pcs_bus);
-			goto err_dvr_remove;
-		}
-
-		stpriv->hw->phylink_pcs = lynx_pcs_create_mdiodev(pcs_bus, 0);
-		if (IS_ERR(stpriv->hw->phylink_pcs)) {
-			ret = PTR_ERR(stpriv->hw->phylink_pcs);
-			goto err_dvr_remove;
-		}
-	}
-
 	return 0;
 
 err_dvr_remove:
@@ -494,17 +506,6 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static void socfpga_dwmac_remove(struct platform_device *pdev)
-{
-	struct net_device *ndev = platform_get_drvdata(pdev);
-	struct stmmac_priv *priv = netdev_priv(ndev);
-	struct phylink_pcs *pcs = priv->hw->phylink_pcs;
-
-	stmmac_pltfr_remove(pdev);
-
-	lynx_pcs_destroy(pcs);
-}
-
 #ifdef CONFIG_PM_SLEEP
 static int socfpga_dwmac_resume(struct device *dev)
 {
@@ -576,7 +577,7 @@ MODULE_DEVICE_TABLE(of, socfpga_dwmac_match);
 
 static struct platform_driver socfpga_dwmac_driver = {
 	.probe  = socfpga_dwmac_probe,
-	.remove_new = socfpga_dwmac_remove,
+	.remove_new = stmmac_pltfr_remove,
 	.driver = {
 		.name           = "socfpga-dwmac",
 		.pm		= &socfpga_dwmac_pm_ops,
Signature · 1 line
2.30.2
maintainer Reviewed-by on v1 2/2
#9 lore raw

Re: [Linux-stm32] [PATCH net-next 2/2] net: stmmac: dwmac-socfpga: use pcs_init/pcs_exit

Hello Russell,

Quoted 9 lines · On Tue, 02 Apr 2024 16:51:48 +0100 "Russell King (Oracle)"…

Use the newly introduced pcs_init() and pcs_exit() operations to create and destroy the PCS instance at a more appropriate moment during the driver lifecycle, thereby avoiding publishing a network device to userspace that has not yet finished its PCS initialisation.

There are other similar issues with this driver which remain unaddressed, but these are out of scope for this patch.

Thanks for addressing this,

#10 lore raw

Re: [PATCH net-next 2/2] net: stmmac: dwmac-socfpga: use pcs_init/pcs_exit

In reply to Russell King (Oracle)
Quoted 7 lines · Russell King (Oracle)

Use the newly introduced pcs_init() and pcs_exit() operations to create and destroy the PCS instance at a more appropriate moment during the driver lifecycle, thereby avoiding publishing a network device to userspace that has not yet finished its PCS initialisation.

There are other similar issues with this driver which remain unaddressed, but these are out of scope for this patch.

Just for the record...

Digging into the history of this driver, the init-after-publish issue was introduced by commit 3c201b5a84ed ("net: stmmac: socfpga: Remove re-registration of reset controller") which gives information on why calling the PHY configuration before stmmac_dvr_probe() didn't work.

This was further modified by 56868deece92 ("stmmac: dwmac-socfpga: add PM ops and resume function").

I haven't decided what can be done about that yet - and I'm tempted to leave it as-is for the time being until more of stmmac gets cleaned up.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
author maintainer
#11 lore raw

Re: [PATCH net-next 2/3] net: stmmac: add support for RZ/N1 GMAC

In reply to Russell King (Oracle)

Hello Russell,

Quoted 9 lines · Russell King (Oracle)
Quoted 9 lines

I'm afraid that this fails at one of the most basic principles of kernel multi-threaded programming. stmmac_dvr_probe() as part of its work calls register_netdev() which publishes to userspace the network device.

Everything that is required must be setup _prior_ to publication to userspace to avoid races, because as soon as the network device is published, userspace can decide to bring that interface up. If one hasn't finished the initialisation, the interface can be brought up before that initialisation is complete.

...

Quoted 4 lines

I'm not going to say that the two patches threaded to this email are "sane" but at least it avoids the problem. socfpga still has issues with initialisation done after register_netdev() though.

Thanks a lot for providing a fix to this issue, introducing new pcs_init/exit() hooks seems like the best solution at this time, I'll make sure to integrate those patches in the v2 for this series.

Thanks,

Signature · 3 lines
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
author maintainer
#12 lore raw

PATCH 3/3 ARM: dts: r9a06g032: describe GMAC1

In reply to Romain Gantois

From: Clément Léger <[email protected]>

The r9a06g032 SoC of the RZ/N1 family features two GMAC devices named GMAC1/2, that are based on Synopsys cores. GMAC1 is connected to a RGMII/RMII converter that is already described in this device tree.

[rgantois: commit log]
---
 arch/arm/boot/dts/renesas/r9a06g032.dtsi | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
arch/arm/boot/dts/renesas/r9a06g032.dtsi +19 -0
index fa63e1afc4ef..cab7a641f95b 100644
@@ -316,6 +316,25 @@ dma1: dma-controller@40105000 {
 			data-width = <8>;
 		};
 
+		gmac1: ethernet@44000000 {
+			compatible = "renesas,r9a06g032-gmac", "renesas,rzn1-gmac", "snps,dwmac";
+			reg = <0x44000000 0x2000>;
+			interrupt-parent = <&gic>;
+			interrupts = <GIC_SPI 34 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "macirq", "eth_wake_irq", "eth_lpi";
+			clocks = <&sysctrl R9A06G032_HCLK_GMAC0>;
+			clock-names = "stmmaceth";
+			power-domains = <&sysctrl>;
+			snps,multicast-filter-bins = <256>;
+			snps,perfect-filter-entries = <128>;
+			tx-fifo-depth = <2048>;
+			rx-fifo-depth = <4096>;
+			pcs-handle = <&mii_conv1>;
+			status = "disabled";
+		};
+
 		gmac2: ethernet@44002000 {
 			compatible = "renesas,r9a06g032-gmac", "renesas,rzn1-gmac", "snps,dwmac";
 			reg = <0x44002000 0x2000>;
Signature · 1 line
2.44.0