Skip to contentSkip to conversation

net: hix5hd2_gmac: Support fixed-link

PATCH New David Yang 1 participant 6 messages Nov 27

Subsystems (4)
lore
Share & tools
lore

David Yang

author
#0 lore raw

v5 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.

v5:
- fix bus registration for in-band links
- check NULL for priv->bus on remove
v4: https://lore.kernel.org/r/[email protected]
- reword in dt bindings
- register MDIO bus manually
- skip disabled mdio child
v3: https://lore.kernel.org/r/[email protected]
- use devm_*
- split mdio child node and fixed-link
v2: https://lore.kernel.org/r/[email protected]
- add mdio bus child node
v1: https://lore.kernel.org/r/[email protected]

David Yang (5):
net: hix5hd2_gmac: Use devm_ managed netdev and MDIO bus
dt-bindings: net: hisilicon,hisi-gmac-v1: Add mdio bus child node
net: hix5hd2_gmac: Use mdio child node for MDIO bus if it exists
dt-bindings: net: hisilicon,hisi-gmac-v1: Allow fixed-link
net: hix5hd2_gmac: Support fixed-link

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

PATCH v5 1/5 net: hix5hd2_gmac: Use devm_ managed netdev and MDIO bus

Let devres manage the netdev and the MDIO bus allocation, so that neither needs to be freed by hand in the error path and on remove. The MDIO bus itself is still registered and unregistered by hand, so that it is torn down before the MAC clocks are disabled on the probe error path.

---
 drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 20 +++++++------------
 1 file changed, 7 insertions(+), 13 deletions(-)
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +7 -13
index 12a5657653f8..44b05d41cb95 100644
@@ -1106,7 +1106,7 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 	struct mii_bus *bus;
 	int ret;
 
-	ndev = alloc_etherdev(sizeof(struct hix5hd2_priv));
+	ndev = devm_alloc_etherdev(dev, sizeof(struct hix5hd2_priv));
 	if (!ndev)
 		return -ENOMEM;
 
@@ -1121,26 +1121,26 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 	priv->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(priv->base)) {
 		ret = PTR_ERR(priv->base);
-		goto out_free_netdev;
+		return ret;
 	}
 
 	priv->ctrl_base = devm_platform_ioremap_resource(pdev, 1);
 	if (IS_ERR(priv->ctrl_base)) {
 		ret = PTR_ERR(priv->ctrl_base);
-		goto out_free_netdev;
+		return ret;
 	}
 
 	priv->mac_core_clk = devm_clk_get(&pdev->dev, "mac_core");
 	if (IS_ERR(priv->mac_core_clk)) {
 		netdev_err(ndev, "failed to get mac core clk\n");
 		ret = -ENODEV;
-		goto out_free_netdev;
+		return ret;
 	}
 
 	ret = clk_prepare_enable(priv->mac_core_clk);
 	if (ret < 0) {
 		netdev_err(ndev, "failed to enable mac core clk %d\n", ret);
-		goto out_free_netdev;
+		return ret;
 	}
 
 	priv->mac_ifc_clk = devm_clk_get(&pdev->dev, "mac_ifc");
@@ -1175,7 +1175,7 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 		hix5hd2_phy_reset(priv);
 	}
 
-	bus = mdiobus_alloc();
+	bus = devm_mdiobus_alloc(dev);
 	if (bus == NULL) {
 		ret = -ENOMEM;
 		goto out_disable_clk;
@@ -1191,7 +1191,7 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 
 	ret = of_mdiobus_register(bus, node);
 	if (ret)
-		goto err_free_mdio;
+		goto out_disable_clk;
 
 	ret = of_get_phy_mode(node, &priv->phy_mode);
 	if (ret) {
@@ -1271,14 +1271,10 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 	of_node_put(priv->phy_node);
 err_mdiobus:
 	mdiobus_unregister(bus);
-err_free_mdio:
-	mdiobus_free(bus);
 out_disable_clk:
 	clk_disable_unprepare(priv->mac_ifc_clk);
 out_disable_mac_core_clk:
 	clk_disable_unprepare(priv->mac_core_clk);
-out_free_netdev:
-	free_netdev(ndev);
 
 	return ret;
 }
@@ -1291,13 +1287,11 @@ 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 (HAS_CAP_TSO(priv->hw_cap))
 		hix5hd2_destroy_sg_desc_queue(priv);
 	hix5hd2_destroy_hw_desc_queue(priv);
 	of_node_put(priv->phy_node);
-	free_netdev(ndev);
 }
 
 static const struct of_device_id hix5hd2_of_match[] = {
Signature · 1 line
2.53.0
author
#2 lore raw

PATCH v5 2/5 dt-bindings: net: hisilicon,hisi-gmac-v1: Add mdio bus child node

In reply to David Yang

This adds an optional mdio bus child node. If present, the mac will look for PHYs there instead of directly under the top-level node. This eliminates any ambiguity about whether child nodes are PHYs, and allows the MDIO bus to contain non-PHY devices.

---
 .../devicetree/bindings/net/hisilicon,hisi-gmac-v1.yaml    | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/net/hisilicon,hisi-gmac-v1.yaml +7 -0
index 89ed6ab1905e..a71529825955 100644
@@ -53,6 +53,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:
Signature · 1 line
2.53.0
author
#3 lore raw

PATCH v5 3/5 net: hix5hd2_gmac: Use mdio child node for MDIO bus if it exists

In reply to David Yang

This allows explicitly specifying which children are present on the mdio bus, like commit 4d98bb0d7ec2 ("net: macb: Use mdio child node for MDIO bus if it exists").

---
 drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +4 -1
index 44b05d41cb95..b3b2aa1b7698 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;
@@ -1189,7 +1190,9 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev->dev));
 	priv->bus = bus;
 
-	ret = of_mdiobus_register(bus, node);
+	mdio_np = of_get_available_child_by_name(node, "mdio");
+	ret = of_mdiobus_register(bus, mdio_np ?: node);
+	of_node_put(mdio_np);
 	if (ret)
 		goto out_disable_clk;
 
Signature · 1 line
2.53.0
author
#4 lore raw

PATCH v5 4/5 dt-bindings: net: hisilicon,hisi-gmac-v1: Allow fixed-link

In reply to David Yang

With fixed-link there is no phy-handle, make phy-handle required only when no fixed-link is declared.

A fixed link gets no MDIO bus by default. In such case, MDIO devices must be placed under the mdio node, and PHY nodes directly under the ethernet node are rejected.

---
 .../bindings/net/hisilicon,hisi-gmac-v1.yaml  | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/net/hisilicon,hisi-gmac-v1.yaml +18 -2
index a71529825955..2f1c0e0afb88 100644
@@ -13,6 +13,22 @@ maintainers:
 allOf:
   - $ref: /schemas/net/ethernet-controller.yaml#
   - $ref: /schemas/net/mdio.yaml#
+  - if:
+      not:
+        required:
+          - fixed-link
+    then:
+      required:
+        - phy-handle
+  - if:
+      required:
+        - fixed-link
+    then:
+      not:
+        required:
+          - phy-handle
+      patternProperties:
+        '@[0-9a-f]+$': false
 
 properties:
   compatible:
@@ -58,7 +74,8 @@ properties:
     unevaluatedProperties: false
     description:
       Node containing PHY children. If this node is not present, then PHYs will
-      be direct children.
+      be direct children. With fixed-link, MDIO devices must be placed under the
+      mdio node.
 
   hisilicon,phy-reset-delays-us:
     description: Triplet of PHY reset delays in microseconds.
@@ -74,7 +91,6 @@ required:
   - clocks
   - clock-names
   - phy-mode
-  - phy-handle
 
 unevaluatedProperties: false
 
Signature · 1 line
2.53.0
author
#5 lore raw

PATCH v5 5/5 net: hix5hd2_gmac: Support fixed-link

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. Register a fixed PHY from the node in that case.

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. Skip the MDIO bus registration for a fixed link, unless devices are described under an "mdio" child node, like
commit d0c3601f2c4e ("net: macb: Avoid 20s boot delay by skipping MDIO bus registration for fixed-link PHY").

of_phy_is_fixed_link() also returns true for managed = "in-band-status"; give phy-handle precedence over it, like fec and gianfar.

---
 drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 72 ++++++++++++-------
 1 file changed, 47 insertions(+), 25 deletions(-)
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +47 -25
index b3b2aa1b7698..42c539d172b7 100644
@@ -1176,37 +1176,54 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 		hix5hd2_phy_reset(priv);
 	}
 
-	bus = devm_mdiobus_alloc(dev);
-	if (bus == NULL) {
-		ret = -ENOMEM;
+	priv->phy_node = of_parse_phandle(node, "phy-handle", 0);
+
+	/* In the case of a fixed PHY, the DT node associated
+	 * to the PHY is the Ethernet MAC DT node.
+	 */
+	if (!priv->phy_node && of_phy_is_fixed_link(node)) {
+		ret = of_phy_register_fixed_link(node);
+		if (ret < 0)
+			goto out_disable_clk;
+		priv->phy_node = of_node_get(node);
+	} else if (!priv->phy_node) {
+		netdev_err(ndev, "not find phy-handle\n");
+		ret = -EINVAL;
 		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_available_child_by_name(node, "mdio");
-	ret = of_mdiobus_register(bus, mdio_np ?: node);
+	if (mdio_np || priv->phy_node != node) {
+		bus = devm_mdiobus_alloc(dev);
+		if (!bus) {
+			ret = -ENOMEM;
+			of_node_put(mdio_np);
+			goto out_phy_node;
+		}
+
+		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;
+
+		ret = of_mdiobus_register(bus, mdio_np ?: node);
+		if (ret) {
+			of_node_put(mdio_np);
+			bus = NULL;
+			goto out_phy_node;
+		}
+	}
 	of_node_put(mdio_np);
-	if (ret)
-		goto out_disable_clk;
 
 	ret = of_get_phy_mode(node, &priv->phy_mode);
 	if (ret) {
 		netdev_err(ndev, "not find phy-mode\n");
-		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;
+		goto out_phy_node;
 	}
 
 	ndev->irq = platform_get_irq(pdev, 0);
@@ -1271,9 +1288,11 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)
 	netif_napi_del(&priv->napi);
 	hix5hd2_destroy_hw_desc_queue(priv);
 out_phy_node:
+	if (priv->phy_node == node)
+		of_phy_deregister_fixed_link(node);
 	of_node_put(priv->phy_node);
-err_mdiobus:
-	mdiobus_unregister(bus);
+	if (bus)
+		mdiobus_unregister(bus);
 out_disable_clk:
 	clk_disable_unprepare(priv->mac_ifc_clk);
 out_disable_mac_core_clk:
@@ -1289,11 +1308,14 @@ static void hix5hd2_dev_remove(struct platform_device *pdev)
 
 	unregister_netdev(ndev);
 	cancel_work_sync(&priv->tx_timeout_task);
-	mdiobus_unregister(priv->bus);
+	if (priv->bus)
+		mdiobus_unregister(priv->bus);
 
 	if (HAS_CAP_TSO(priv->hw_cap))
 		hix5hd2_destroy_sg_desc_queue(priv);
 	hix5hd2_destroy_hw_desc_queue(priv);
+	if (priv->phy_node == pdev->dev.of_node)
+		of_phy_deregister_fixed_link(pdev->dev.of_node);
 	of_node_put(priv->phy_node);
 }
 
Signature · 1 line
2.53.0