Skip to contentSkip to conversation

net: hix5hd2_gmac: support fixed-link

PATCH Superseded David Yang 3 participants 5 messages Nov 22 – Nov 23

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

David Yang

author
#0 lore raw

v2 cover net: hix5hd2_gmac: support fixed-link

Support MAC-to-MAC link on hix5hd2_gmac. Also add and support mdio child node to suppress warnings when fixed linked, as in macb.

David Yang (2):
dt-bindings: net: hisilicon,hisi-gmac-v1: allow fixed-link and mdio
child
net: hix5hd2_gmac: support fixed-link and mdio child

 .../bindings/net/hisilicon,hisi-gmac-v1.yaml  | 15 +++-
 drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 78 +++++++++++++------
 2 files changed, 67 insertions(+), 26 deletions(-)
Signature · 1 line
2.53.0
author
#1 lore raw

PATCH v2 1/2 dt-bindings: net: hisilicon,hisi-gmac-v1: allow fixed-link and mdio child

Describe the "mdio" child node the controller registers its MDIO bus against when devices are attached to the bus.

With a fixed link there is no phy-handle: make it required only when no fixed-link is declared.

---
 .../bindings/net/hisilicon,hisi-gmac-v1.yaml      | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/net/hisilicon,hisi-gmac-v1.yaml +14 -1
index 89ed6ab1905e..ae2b1505a52c 100644
@@ -13,6 +13,13 @@ maintainers:
 allOf:
   - $ref: /schemas/net/ethernet-controller.yaml#
   - $ref: /schemas/net/mdio.yaml#
+  - if:
+      not:
+        required:
+          - fixed-link
+    then:
+      required:
+        - phy-handle
 
 properties:
   compatible:
@@ -53,6 +60,13 @@ properties:
       - const: mac_ifc
       - const: phy
 
+  mdio:
+    $ref: mdio.yaml#
+    unevaluatedProperties: false
+    description:
+      Node containing PHY children. If this node is not present, then PHYs will
+      be direct children.
+
   hisilicon,phy-reset-delays-us:
     description: Triplet of PHY reset delays in microseconds.
     items:
@@ -67,7 +81,6 @@ required:
   - clocks
   - clock-names
   - phy-mode
-  - phy-handle
 
 unevaluatedProperties: false
 
Signature · 1 line
2.53.0
author
#2 lore raw

PATCH v2 2/2 net: hix5hd2_gmac: support fixed-link and mdio child

In reply to David Yang

On Hi3716cv200 hix5hd2_gmac is found directly linked to another MAC without PHY. The driver didn't take fixed-link into account and failed probe when the node has no phy-handle. Add support for fixed-link.

With a fixed link declared on the MAC node, of_mdiobus_register() treats the reg-less fixed-link child as a PHY candidate and walks all 32 bus addresses, printing "scan phy fixed-link at address X" for each address. Register the bus based on if the PHY attached to a given interface is described in the device tree or not, like commit ef8a2e27289e ("net:
macb: fix probing of PHY not described in the dt").

---
 drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 78 +++++++++++++------
 1 file changed, 53 insertions(+), 25 deletions(-)
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +53 -25
index 12a5657653f8..9a2a3fa1455f 100644
@@ -1101,6 +1101,7 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct device_node *node = dev->of_node;
+	struct device_node *mdio_np;
 	struct net_device *ndev;
 	struct hix5hd2_priv *priv;
 	struct mii_bus *bus;
@@ -1175,23 +1176,35 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 		hix5hd2_phy_reset(priv);
 	}
 
-	bus = mdiobus_alloc();
-	if (bus == NULL) {
-		ret = -ENOMEM;
-		goto out_disable_clk;
-	}
-
-	bus->priv = priv;
-	bus->name = "hix5hd2_mii_bus";
-	bus->read = hix5hd2_mdio_read;
-	bus->write = hix5hd2_mdio_write;
-	bus->parent = &pdev->dev;
-	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev->dev));
-	priv->bus = bus;
+	bus = NULL;
+	mdio_np = of_get_child_by_name(node, "mdio");
+	if (mdio_np || !of_phy_is_fixed_link(node)) {
+		bus = mdiobus_alloc();
+		if (!bus) {
+			ret = -ENOMEM;
+			of_node_put(mdio_np);
+			goto out_disable_clk;
+		}
 
-	ret = of_mdiobus_register(bus, node);
-	if (ret)
-		goto err_free_mdio;
+		bus->priv = priv;
+		bus->name = "hix5hd2_mii_bus";
+		bus->read = hix5hd2_mdio_read;
+		bus->write = hix5hd2_mdio_write;
+		bus->parent = &pdev->dev;
+		snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii",
+			 dev_name(&pdev->dev));
+		priv->bus = bus;
+
+		if (mdio_np)
+			ret = of_mdiobus_register(bus, mdio_np);
+		else
+			ret = of_mdiobus_register(bus, node);
+		if (ret) {
+			of_node_put(mdio_np);
+			goto err_free_mdio;
+		}
+	}
+	of_node_put(mdio_np);
 
 	ret = of_get_phy_mode(node, &priv->phy_mode);
 	if (ret) {
@@ -1199,11 +1212,18 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 		goto err_mdiobus;
 	}
 
-	priv->phy_node = of_parse_phandle(node, "phy-handle", 0);
-	if (!priv->phy_node) {
-		netdev_err(ndev, "not find phy-handle\n");
-		ret = -EINVAL;
-		goto err_mdiobus;
+	if (of_phy_is_fixed_link(node)) {
+		ret = of_phy_register_fixed_link(node);
+		if (ret < 0)
+			goto err_mdiobus;
+		priv->phy_node = of_node_get(node);
+	} else {
+		priv->phy_node = of_parse_phandle(node, "phy-handle", 0);
+		if (!priv->phy_node) {
+			netdev_err(ndev, "not find phy-handle\n");
+			ret = -EINVAL;
+			goto err_mdiobus;
+		}
 	}
 
 	ndev->irq = platform_get_irq(pdev, 0);
@@ -1268,11 +1288,15 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 	netif_napi_del(&priv->napi);
 	hix5hd2_destroy_hw_desc_queue(priv);
 out_phy_node:
+	if (of_phy_is_fixed_link(node))
+		of_phy_deregister_fixed_link(node);
 	of_node_put(priv->phy_node);
 err_mdiobus:
-	mdiobus_unregister(bus);
+	if (bus)
+		mdiobus_unregister(bus);
 err_free_mdio:
-	mdiobus_free(bus);
+	if (bus)
+		mdiobus_free(bus);
 out_disable_clk:
 	clk_disable_unprepare(priv->mac_ifc_clk);
 out_disable_mac_core_clk:
@@ -1290,12 +1314,16 @@ static void hix5hd2_dev_remove(struct platform_device *pdev)
 
 	unregister_netdev(ndev);
 	cancel_work_sync(&priv->tx_timeout_task);
-	mdiobus_unregister(priv->bus);
-	mdiobus_free(priv->bus);
+	if (priv->bus) {
+		mdiobus_unregister(priv->bus);
+		mdiobus_free(priv->bus);
+	}
 
 	if (HAS_CAP_TSO(priv->hw_cap))
 		hix5hd2_destroy_sg_desc_queue(priv);
 	hix5hd2_destroy_hw_desc_queue(priv);
+	if (of_phy_is_fixed_link(pdev->dev.of_node))
+		of_phy_deregister_fixed_link(pdev->dev.of_node);
 	of_node_put(priv->phy_node);
 	free_netdev(ndev);
 }
Signature · 1 line
2.53.0
#3 lore raw

Re: [PATCH net-next v2 2/2] net: hix5hd2_gmac: support fixed-link and mdio child

Quoted 10 lines · David Yang

On Hi3716cv200 hix5hd2_gmac is found directly linked to another MAC without PHY. The driver didn't take fixed-link into account and failed probe when the node has no phy-handle. Add support for fixed-link.

With a fixed link declared on the MAC node, of_mdiobus_register() treats the reg-less fixed-link child as a PHY candidate and walks all 32 bus addresses, printing "scan phy fixed-link at address X" for each address. Register the bus based on if the PHY attached to a given interface is described in the device tree or not, like commit ef8a2e27289e ("net:
macb: fix probing of PHY not described in the dt").

Please split this patch up.

Add support for the optional mdio node.

Then add support for fixed link.

These are logically different things, so should be in different patches.

Andrew

---
pw-bot: cr

#4 lore raw

Re: [PATCH net-next v2 2/2] net: hix5hd2_gmac: support fixed-link and mdio child

In reply to David Yang
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] In hix5hd2_dev_probe() (drivers/net/ethernet/hisilicon/hix5hd2_gmac.c), the MDIO bus is now…
- [Low] hix5hd2_dev_probe() now uses of_phy_is_fixed_link(node) to choose between the fixed-link path and the phy-handle path, and also to…

--

net: hix5hd2_gmac: support fixed-link and mdio child

This commit adds fixed-link support to hix5hd2_gmac. With it, the MAC can probe when it is wired directly to another MAC with no PHY. It also registers the MDIO bus on an "mdio" child node when one is present. When the MAC node has a fixed-link and no mdio child, it skips the MDIO bus entirely.

Quoted 4 lines
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +0 -0
index 12a5657653f85..9a2a3fa1455fb 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +0 -0
@@ -1175,23 +1176,35 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 		hix5hd2_phy_reset(priv);
 	}
 

[ ... ]

drivers/net/ethernet/hisilicon/hix5hd2_gmac.c static int hix5hd2_dev_probe(struct platform_device *pdev) · line 1187

Quoted 9 lines
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +9 -0
+	bus = NULL;
+	mdio_np = of_get_child_by_name(node, "mdio");
+	if (mdio_np || !of_phy_is_fixed_link(node)) {
+		bus = mdiobus_alloc();
+		if (!bus) {
+			ret = -ENOMEM;
+			of_node_put(mdio_np);
+			goto out_disable_clk;
+		}

[Severity: Medium]
In hix5hd2_dev_probe(), if the MAC node has a fixed-link but no "mdio" child, this condition is false. mdiobus_alloc() and of_mdiobus_register() are never called, and bus and priv->bus stay NULL.

Are MDIO devices described as direct children of the MAC node then silently ignored?

The binding from the preceding patch ("dt-bindings: net:
hisilicon,hisi-gmac-v1: allow fixed-link and mdio child") still says this for the mdio property:

Node containing PHY children. If this node is not present, then PHYs will be direct children.

The binding also still references mdio.yaml at the MAC node level. So a fixed-link node with direct <name>@<addr> MDIO children looks binding-valid. Examples would be a PHY used by another MAC, or a switch managed over this GMAC's MDIO lines. In that case nothing is probed and no warning is printed.

Separately, the commit message says:

Register the bus based on if the PHY attached to a given interface is described in the device tree or not, like commit ef8a2e27289e ("net:
macb: fix probing of PHY not described in the dt").

Is that accurate? macb_mdiobus_register() always registers the bus. It only chooses between DT-based and scan-based registration:

drivers/net/ethernet/cadence/macb_main.c:macb_mdiobus_register() {
    ...
	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);
		}

	return mdiobus_register(bp->mii_bus);
}

Also, of_mdiobus_child_is_phy() returns true for any child that has no compatible property:

drivers/net/mdio/of_mdio.c:of_mdiobus_child_is_phy() {
    ...
	if (!of_property_present(child, "compatible"))
		return true;
    ...
}

Under the macb logic, the fixed-link subnode would therefore still count as a PHY. of_mdiobus_register(np) would still run and print the "scan phy fixed-link at address X" messages.

The code here takes a different approach: it registers no bus at all for fixed-link. Could the commit message describe what the code does instead?

The commit message also doesn't mention that an "mdio" child is now used as the bus node. Before this patch it was scanned as a reg-less PHY candidate of the MAC node.

[ ... ]

Quoted 6 lines
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +0 -2
@@ -1199,11 +1212,18 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 		goto err_mdiobus;
 	}
 
-	priv->phy_node = of_parse_phandle(node, "phy-handle", 0);
-	if (!priv->phy_node) {

drivers/net/ethernet/hisilicon/hix5hd2_gmac.c static int hix5hd2_dev_probe(struct platform_device *pdev) · line 1221

Quoted 10 lines
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +7 -3
-		netdev_err(ndev, "not find phy-handle\n");
-		ret = -EINVAL;
-		goto err_mdiobus;
+	if (of_phy_is_fixed_link(node)) {
+		ret = of_phy_register_fixed_link(node);
+		if (ret < 0)
+			goto err_mdiobus;
+		priv->phy_node = of_node_get(node);
+	} else {
+		priv->phy_node = of_parse_phandle(node, "phy-handle", 0);

[Severity: Low]
of_phy_is_fixed_link() also returns true when the node sets managed to anything other than "auto". This happens even with no fixed-link property or subnode:

drivers/net/mdio/of_mdio.c:of_phy_is_fixed_link() {
    ...
	err = of_property_read_string(np, "managed", &managed);
	if (err == 0 && strcmp(managed, "auto") != 0)
		return true;
    ...
}

What happens to a node with managed = "in-band-status", a phy-handle and no mdio child? Before this patch the driver ignored managed and connected the real PHY through phy-handle.

After this patch:

- no MDIO bus is registered, because of the bus condition above
- phy-handle is never parsed
- of_phy_register_fixed_link() takes the in-band-status path:

drivers/net/mdio/of_mdio.c:of_phy_register_fixed_link() {
    ...
	if (of_property_read_string(np, "managed", &managed) == 0 &&
	    strcmp(managed, "in-band-status") == 0) {
		/* status is zeroed, namely its .link member */
		goto register_phy;
	}
    ...
}

hix5hd2 has no PCS or in-band status handling, so nothing ever sets the fixed PHY's link. Would the interface stay link-down permanently?

The binding from this series only drops the phy-handle requirement when fixed-link is present:

- if:
not:
required:
- fixed-link
then:
required:
- phy-handle

So the binding still treats such a node as a phy-handle configuration.

No in-tree hix5hd2 DTS uses managed, and of_phy_get_and_connect() uses the same precedence. The commit message doesn't mention this behaviour change, though.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122230134.3366017-1-mmyangfl%40gmail.com