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, so nodes with a phy-handle keep MDIO management. Signed-off-by: David Yang --- drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 63 ++++++++++++------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c index a176870079e9..b787b7777e92 100644 --- a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +++ b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c @@ -1176,37 +1176,52 @@ 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; - mdio_np = of_get_child_by_name(node, "mdio"); - ret = devm_of_mdiobus_register(dev, 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 = devm_of_mdiobus_register(dev, bus, mdio_np ?: node); + if (ret) { + of_node_put(mdio_np); + 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 out_disable_clk; - } - - 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 out_disable_clk; + goto out_phy_node; } ndev->irq = platform_get_irq(pdev, 0); @@ -1271,6 +1286,8 @@ 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); out_disable_clk: clk_disable_unprepare(priv->mac_ifc_clk); @@ -1291,6 +1308,8 @@ static void hix5hd2_dev_remove(struct platform_device *pdev) 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); } -- 2.53.0