Skip to contentSkip to conversation

Add an MDIO sub-node under MACB

PATCH In review Codrin Ciubotariu 2 participants 10 messages Jul 24, 2020 – Jul 27, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v3 cover Add an MDIO sub-node under MACB

Changes in v3:
- in patch 3/7, moved the checking for mdio node at the beginning of the macb_mdiobus_register(). This allows to probe the MDIO devices even if macb is a fixed-link
- added tags received on v2

Changes in v2:
- renamed patch 2/7 from "macb: bindings doc: use an MDIO node as a container for PHY nodes" to "dt-bindings: net: macb: use an MDIO node as a container for PHY nodes"
- added back a newline removed by mistake in patch 3/7

Codrin Ciubotariu (7):
net: macb: use device-managed devm_mdiobus_alloc()
dt-bindings: net: macb: use an MDIO node as a container for PHY nodes
net: macb: parse PHY nodes found under an MDIO node
ARM: dts: at91: sama5d2: add an mdio sub-node to macb
ARM: dts: at91: sama5d3: add an mdio sub-node to macb
ARM: dts: at91: sama5d4: add an mdio sub-node to macb
ARM: dts: at91: sam9x60: add an mdio sub-node to macb

 Documentation/devicetree/bindings/net/macb.txt | 15 ++++++++++++---
 arch/arm/boot/dts/at91-sam9x60ek.dts           |  8 ++++++--
 arch/arm/boot/dts/at91-sama5d27_som1.dtsi      | 16 ++++++++++------
 arch/arm/boot/dts/at91-sama5d27_wlsom1.dtsi    | 17 ++++++++++-------
 arch/arm/boot/dts/at91-sama5d2_ptc_ek.dts      | 13 ++++++++-----
 arch/arm/boot/dts/at91-sama5d2_xplained.dts    | 12 ++++++++----
 arch/arm/boot/dts/at91-sama5d3_xplained.dts    | 16 ++++++++++++----
 arch/arm/boot/dts/at91-sama5d4_xplained.dts    | 12 ++++++++----
 drivers/net/ethernet/cadence/macb_main.c       | 18 ++++++++++++------
 9 files changed, 86 insertions(+), 41 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/7 net: macb: use device-managed devm_mdiobus_alloc()

Use the device-managed variant for the allocating the MDIO bus. This cleans-up the code a little on the remove and error paths.

---

Changes in v3:
- added tags from Claudiu and Florian

Changes in v2:
- none

 drivers/net/ethernet/cadence/macb_main.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +2 -6
index a6a35e1b0115..89fe7af5e408 100644
@@ -769,7 +769,7 @@ static int macb_mii_init(struct macb *bp)
 	/* Enable management port */
 	macb_writel(bp, NCR, MACB_BIT(MPE));
 
-	bp->mii_bus = mdiobus_alloc();
+	bp->mii_bus = devm_mdiobus_alloc(&bp->pdev->dev);
 	if (!bp->mii_bus) {
 		err = -ENOMEM;
 		goto err_out;
@@ -787,7 +787,7 @@ static int macb_mii_init(struct macb *bp)
 
 	err = macb_mdiobus_register(bp);
 	if (err)
-		goto err_out_free_mdiobus;
+		goto err_out;
 
 	err = macb_mii_probe(bp->dev);
 	if (err)
@@ -797,8 +797,6 @@ static int macb_mii_init(struct macb *bp)
 
 err_out_unregister_bus:
 	mdiobus_unregister(bp->mii_bus);
-err_out_free_mdiobus:
-	mdiobus_free(bp->mii_bus);
 err_out:
 	return err;
 }
@@ -4571,7 +4569,6 @@ static int macb_probe(struct platform_device *pdev)
 
 err_out_unregister_mdio:
 	mdiobus_unregister(bp->mii_bus);
-	mdiobus_free(bp->mii_bus);
 
 err_out_free_netdev:
 	free_netdev(dev);
@@ -4599,7 +4596,6 @@ static int macb_remove(struct platform_device *pdev)
 	if (dev) {
 		bp = netdev_priv(dev);
 		mdiobus_unregister(bp->mii_bus);
-		mdiobus_free(bp->mii_bus);
 
 		unregister_netdev(dev);
 		tasklet_kill(&bp->hresp_err_tasklet);
Signature · 1 line
2.25.1
#2 lore raw

PATCH v3 2/7 dt-bindings: net: macb: use an MDIO node as a container for PHY nodes

In reply to Codrin Ciubotariu

The MACB driver embeds an MDIO bus controller and for this reason there was no need for an MDIO sub-node present to contain the PHY nodes. Adding MDIO devies directly under an Ethernet node is deprecated, so an MDIO node is included to contain of the PHY nodes (and other MDIO devices' nodes).

---

Changes in v3:
- Added tags from Claudiu, Rob and Florian

Changes in v2:
- patch renamed from "macb: bindings doc: use an MDIO node as a container for PHY nodes" to "dt-bindings: net: macb: use an MDIO node as a container for PHY nodes"

 Documentation/devicetree/bindings/net/macb.txt | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/net/macb.txt +12 -3
index 0b61a90f1592..88d5199c2279 100644
@@ -32,6 +32,11 @@ Required properties:
 The MAC address will be determined using the optional properties
 defined in ethernet.txt.
 
+Optional subnodes:
+- mdio : specifies the MDIO bus in the MACB, used as a container for PHY nodes or other
+  nodes of devices present on the MDIO bus. Please see ethernet-phy.yaml in the same
+  directory for more details.
+
 Optional properties for PHY child node:
 - reset-gpios : Should specify the gpio for phy reset
 - magic-packet : If present, indicates that the hardware supports waking
@@ -48,8 +53,12 @@ Examples:
 		local-mac-address = [3a 0e 03 04 05 06];
 		clock-names = "pclk", "hclk", "tx_clk";
 		clocks = <&clkc 30>, <&clkc 30>, <&clkc 13>;
-		ethernet-phy@1 {
-			reg = <0x1>;
-			reset-gpios = <&pioE 6 1>;
+		mdio {
+			#address-cells = <1>;
+			#size-cells = <0>;
+			ethernet-phy@1 {
+				reg = <0x1>;
+				reset-gpios = <&pioE 6 1>;
+			};
 		};
 	};
Signature · 1 line
2.25.1
#3 lore raw

PATCH v3 3/7 net: macb: parse PHY nodes found under an MDIO node

In reply to Codrin Ciubotariu

The MACB embeds an MDIO bus controller. For this reason, the PHY nodes were represented as sub-nodes in the MACB node. Generally, the Ethernet controller is different than the MDIO controller, so the PHYs are probed by a separate MDIO driver. Since adding the PHY nodes directly under the ETH node became deprecated, we adjust the MACB driver to look for an MDIO node and register the subnode MDIO devices.

---

Changes in v3:
- moved the check for the mdio node at the beginnging of macb_mdiobus_register(). This way, the mdio devices will be probed even if macb is a fixed-link

Changes in v2:
- readded newline removed by mistake;

 drivers/net/ethernet/cadence/macb_main.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/ethernet/cadence/macb_main.c +10 -0
index 89fe7af5e408..cb0b3637651c 100644
@@ -740,6 +740,16 @@ static int macb_mii_probe(struct net_device *dev)
 static int macb_mdiobus_register(struct macb *bp)
 {
 	struct device_node *child, *np = bp->pdev->dev.of_node;
+	struct device_node *mdio_node;
+	int ret;
+
+	/* if an MDIO node is present, it should contain the PHY nodes */
+	mdio_node = of_get_child_by_name(np, "mdio");
+	if (mdio_node) {
+		ret = of_mdiobus_register(bp->mii_bus, mdio_node);
+		of_node_put(mdio_node);
+		return ret;
+	}
 
 	if (of_phy_is_fixed_link(np))
 		return mdiobus_register(bp->mii_bus);
Signature · 1 line
2.25.1
#6 lore raw

PATCH v3 4/7 ARM: dts: at91: sama5d2: add an mdio sub-node to macb

In reply to Codrin Ciubotariu

Use the new macb bindings and add an mdio sub-node to contain all the phy nodes.

---

Changes in v3:
- added tag from Florian

Changes in v2:
- none

 arch/arm/boot/dts/at91-sama5d27_som1.dtsi   | 16 ++++++++++------
 arch/arm/boot/dts/at91-sama5d27_wlsom1.dtsi | 17 ++++++++++-------
 arch/arm/boot/dts/at91-sama5d2_ptc_ek.dts   | 13 ++++++++-----
 arch/arm/boot/dts/at91-sama5d2_xplained.dts | 12 ++++++++----
 4 files changed, 36 insertions(+), 22 deletions(-)
arch/arm/boot/dts/at91-sama5d27_som1.dtsi +10 -6
index b1f994c0ae79..dfcee23dcce0 100644
@@ -84,12 +84,16 @@ macb0: ethernet@f8008000 {
 				pinctrl-0 = <&pinctrl_macb0_default>;
 				phy-mode = "rmii";
 
-				ethernet-phy@0 {
-					reg = <0x0>;
-					interrupt-parent = <&pioA>;
-					interrupts = <PIN_PD31 IRQ_TYPE_LEVEL_LOW>;
-					pinctrl-names = "default";
-					pinctrl-0 = <&pinctrl_macb0_phy_irq>;
+				mdio {
+					#address-cells = <1>;
+					#size-cells = <0>;
+					ethernet-phy@0 {
+						reg = <0x0>;
+						interrupt-parent = <&pioA>;
+						interrupts = <PIN_PD31 IRQ_TYPE_LEVEL_LOW>;
+						pinctrl-names = "default";
+						pinctrl-0 = <&pinctrl_macb0_phy_irq>;
+					};
 				};
 			};
 
arch/arm/boot/dts/at91-sama5d27_wlsom1.dtsi +10 -7
index a06700e53e4c..9c4dce29d2fe 100644
@@ -181,13 +181,16 @@ &macb0 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&pinctrl_macb0_default>;
 	phy-mode = "rmii";
-
-	ethernet-phy@0 {
-		reg = <0x0>;
-		interrupt-parent = <&pioA>;
-		interrupts = <PIN_PB24 IRQ_TYPE_LEVEL_LOW>;
-		pinctrl-names = "default";
-		pinctrl-0 = <&pinctrl_macb0_phy_irq>;
+	mdio {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		ethernet-phy@0 {
+			reg = <0x0>;
+			interrupt-parent = <&pioA>;
+			interrupts = <PIN_PB24 IRQ_TYPE_LEVEL_LOW>;
+			pinctrl-names = "default";
+			pinctrl-0 = <&pinctrl_macb0_phy_irq>;
+		};
 	};
 };
 
arch/arm/boot/dts/at91-sama5d2_ptc_ek.dts +8 -5
index c894c7c788a9..fc3375c43ef6 100644
@@ -140,11 +140,14 @@ macb0: ethernet@f8008000 {
 				pinctrl-0 = <&pinctrl_macb0_default &pinctrl_macb0_phy_irq>;
 				phy-mode = "rmii";
 				status = "okay";
-
-				ethernet-phy@1 {
-					reg = <0x1>;
-					interrupt-parent = <&pioA>;
-					interrupts = <56 IRQ_TYPE_LEVEL_LOW>;
+				mdio {
+					#address-cells = <1>;
+					#size-cells = <0>;
+					ethernet-phy@1 {
+						reg = <0x1>;
+						interrupt-parent = <&pioA>;
+						interrupts = <56 IRQ_TYPE_LEVEL_LOW>;
+					};
 				};
 			};
 
arch/arm/boot/dts/at91-sama5d2_xplained.dts +8 -4
index a927165ea7c2..a62f475d9d0a 100644
@@ -149,10 +149,14 @@ macb0: ethernet@f8008000 {
 				phy-mode = "rmii";
 				status = "okay";
 
-				ethernet-phy@1 {
-					reg = <0x1>;
-					interrupt-parent = <&pioA>;
-					interrupts = <PIN_PC9 IRQ_TYPE_LEVEL_LOW>;
+				mdio {
+					#address-cells = <1>;
+					#size-cells = <0>;
+					ethernet-phy@1 {
+						reg = <0x1>;
+						interrupt-parent = <&pioA>;
+						interrupts = <PIN_PC9 IRQ_TYPE_LEVEL_LOW>;
+					};
 				};
 			};
 
Signature · 1 line
2.25.1
#7 lore raw

PATCH v3 5/7 ARM: dts: at91: sama5d3: add an mdio sub-node to macb

In reply to Codrin Ciubotariu

Use the new macb bindings and add an mdio sub-node to contain all the phy nodes.

---

Changes in v3:
- added tag from Florian

Changes in v2:
- none

 arch/arm/boot/dts/at91-sama5d3_xplained.dts | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
arch/arm/boot/dts/at91-sama5d3_xplained.dts +12 -4
index 61f068a7b362..25d2646ce4cb 100644
@@ -133,8 +133,12 @@ macb0: ethernet@f0028000 {
 				#size-cells = <0>;
 				status = "okay";
 
-				ethernet-phy@7 {
-					reg = <0x7>;
+				mdio {
+					#address-cells = <1>;
+					#size-cells = <0>;
+					ethernet-phy@7 {
+						reg = <0x7>;
+					};
 				};
 			};
 
@@ -200,8 +204,12 @@ macb1: ethernet@f802c000 {
 				#size-cells = <0>;
 				status = "okay";
 
-				ethernet-phy@1 {
-					reg = <0x1>;
+				mdio {
+					#address-cells = <1>;
+					#size-cells = <0>;
+					ethernet-phy@1 {
+						reg = <0x1>;
+					};
 				};
 			};
 
Signature · 1 line
2.25.1
#8 lore raw

PATCH v3 6/7 ARM: dts: at91: sama5d4: add an mdio sub-node to macb

In reply to Codrin Ciubotariu

Use the new macb bindings and add an mdio sub-node to contain all the phy nodes.

---

Changes in v3:
- added tag from Florian

Changes in v2:
- none

 arch/arm/boot/dts/at91-sama5d4_xplained.dts | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/arm/boot/dts/at91-sama5d4_xplained.dts +8 -4
index 924d9491780d..62598d06aead 100644
@@ -59,10 +59,14 @@ macb0: ethernet@f8020000 {
 				pinctrl-names = "default";
 				pinctrl-0 = <&pinctrl_macb0_rmii &pinctrl_macb0_phy_irq>;
 
-				phy0: ethernet-phy@1 {
-					interrupt-parent = <&pioE>;
-					interrupts = <1 IRQ_TYPE_LEVEL_LOW>;
-					reg = <1>;
+				mdio {
+					#address-cells = <1>;
+					#size-cells = <0>;
+					phy0: ethernet-phy@1 {
+						interrupt-parent = <&pioE>;
+						interrupts = <1 IRQ_TYPE_LEVEL_LOW>;
+						reg = <1>;
+					};
 				};
 			};
 
Signature · 1 line
2.25.1
#9 lore raw

PATCH v3 7/7 ARM: dts: at91: sam9x60: add an mdio sub-node to macb

In reply to Codrin Ciubotariu

Use the new macb bindings and add an mdio sub-node to contain all the phy nodes.

---

Changes in v3:
- added tag from Florian

Changes in v2:
- none

 arch/arm/boot/dts/at91-sam9x60ek.dts | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/arm/boot/dts/at91-sam9x60ek.dts +6 -2
index a5f5718c711a..ba871ebe10d4 100644
@@ -324,8 +324,12 @@ &macb0 {
 	pinctrl-0 = <&pinctrl_macb0_rmii>;
 	status = "okay";
 
-	ethernet-phy@0 {
-		reg = <0x0>;
+	mdio {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		ethernet-phy@0 {
+			reg = <0x0>;
+		};
 	};
 };
 
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH net-next v3 3/7] net: macb: parse PHY nodes found under an MDIO node

In reply to Codrin Ciubotariu
Quoted 29 lines · Codrin Ciubotariu

The MACB embeds an MDIO bus controller. For this reason, the PHY nodes were represented as sub-nodes in the MACB node. Generally, the Ethernet controller is different than the MDIO controller, so the PHYs are probed by a separate MDIO driver. Since adding the PHY nodes directly under the ETH node became deprecated, we adjust the MACB driver to look for an MDIO node and register the subnode MDIO devices.

---

Changes in v3:
- moved the check for the mdio node at the beginnging of macb_mdiobus_register(). This way, the mdio devices will be probed even if macb is a fixed-link

Changes in v2:
- readded newline removed by mistake;

 drivers/net/ethernet/cadence/macb_main.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/ethernet/cadence/macb_main.c +0 -0
index 89fe7af5e408..cb0b3637651c 100644
@@ -740,6 +740,16 @@ static int macb_mii_probe(struct net_device *dev)
 static int macb_mdiobus_register(struct macb *bp)
 {
 	struct device_node *child, *np = bp->pdev->dev.of_node;

drivers/net/ethernet/cadence/macb_main.c static int macb_mii_probe(struct net_device *dev) · line 752

Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +10 -0
+	struct device_node *mdio_node;
+	int ret;
+
+	/* if an MDIO node is present, it should contain the PHY nodes */
+	mdio_node = of_get_child_by_name(np, "mdio");
+	if (mdio_node) {
+		ret = of_mdiobus_register(bp->mii_bus, mdio_node);
+		of_node_put(mdio_node);
+		return ret;
+	}

This does take care of registering the MDIO bus controller when present as a sub-node, however if you also plan on making use of fixed-link, we will have already returned.

drivers/net/ethernet/cadence/macb_main.c static int macb_mii_probe(struct net_device *dev)

Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +0 -0
 	if (of_phy_is_fixed_link(np))
 		return mdiobus_register(bp->mii_bus);
 

Really not sure what this is achieving, because we start off assuming that we have an OF driven configuration, but later on we register the MDIO bus with mdiobus_register() (and not of_mdiobus_register()), so no scanning of the MDIO bus will happen.

How does the driver currently support being provided a fixed-link property? Should not we at least have this pattern:

         */
        if (of_phy_is_fixed_link(dn)) {
                ret = of_phy_register_fixed_link(dn);
                if (ret)
			return ret;

                priv->phy_dn = dn;
        }

It does not look like you are breaking anything here, because it does not look like this works at all.

Signature · 1 line
Florian
#5 lore raw

Re: [PATCH net-next v3 3/7] net: macb: parse PHY nodes found under an MDIO node

Quoted 48 lines · Florian Fainelli

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 29 lines · Codrin Ciubotariu

The MACB embeds an MDIO bus controller. For this reason, the PHY nodes were represented as sub-nodes in the MACB node. Generally, the Ethernet controller is different than the MDIO controller, so the PHYs are probed by a separate MDIO driver. Since adding the PHY nodes directly under the ETH node became deprecated, we adjust the MACB driver to look for an MDIO node and register the subnode MDIO devices.

---

Changes in v3:
- moved the check for the mdio node at the beginnging of macb_mdiobus_register(). This way, the mdio devices will be probed even if macb is a fixed-link

Changes in v2:
- readded newline removed by mistake;

  drivers/net/ethernet/cadence/macb_main.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
drivers/net/ethernet/cadence/macb_main.c +0 -0
index 89fe7af5e408..cb0b3637651c 100644
@@ -740,6 +740,16 @@ static int macb_mii_probe(struct net_device *dev)
  static int macb_mdiobus_register(struct macb *bp)
  {
       struct device_node *child, *np = bp->pdev->dev.of_node;

drivers/net/ethernet/cadence/macb_main.c static int macb_mii_probe(struct net_device *dev) · line 752

Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +10 -0
+     struct device_node *mdio_node;
+     int ret;
+
+     /* if an MDIO node is present, it should contain the PHY nodes */
+     mdio_node = of_get_child_by_name(np, "mdio");
+     if (mdio_node) {
+             ret = of_mdiobus_register(bp->mii_bus, mdio_node);
+             of_node_put(mdio_node);
+             return ret;
+     }

This does take care of registering the MDIO bus controller when present as a sub-node, however if you also plan on making use of fixed-link, we will have already returned.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines
       if (of_phy_is_fixed_link(np))
               return mdiobus_register(bp->mii_bus);

Really not sure what this is achieving, because we start off assuming that we have an OF driven configuration, but later on we register the MDIO bus with mdiobus_register() (and not of_mdiobus_register()), so no scanning of the MDIO bus will happen.

I agree that returning mdiobus_register() here makes no sense since there are no other PHY devices to scan for and probe. I can replace this with NULL.
The reason for fixed-link check here is to skip the following loop:
for_each_available_child_of_node(np, child)

		if (of_mdiobus_child_is_phy(child)) {
			of_node_put(child);
			return of_mdiobus_register(bp->mii_bus, np);
		}

of_mdiobus_child_is_phy() returns true when it finds the fixed-link node, because it has no compatible.

Quoted 13 lines

How does the driver currently support being provided a fixed-link property? Should not we at least have this pattern:

          */
         if (of_phy_is_fixed_link(dn)) {
                 ret = of_phy_register_fixed_link(dn);
                 if (ret)
                         return ret;

                 priv->phy_dn = dn;
         }
Quoted 2 lines

It does not look like you are breaking anything here, because it does not look like this works at all.

From what I understand, the new phylink(_create) handles the fixed-link
case, so there is not reason to explicitly register the fixed-link.

Best regards,
Codrin

Quoted 3 lines

--
Florian