Skip to content

Commit

Permalink
net: macb: fix probing of PHY not described in the dt
Browse files Browse the repository at this point in the history
This patch fixes the case where the PHY isn't described in the device
tree. This is due to the way the MDIO bus is registered in the driver:
whether the PHY is described in the device tree or not, the bus is
registered through of_mdiobus_register. The function masks all the PHYs
and only allow probing the ones described in the device tree. Prior to
the Phylink conversion this was also done but later on in the driver
the MDIO bus was manually scanned to circumvent the fact that the PHY
wasn't described.

This patch fixes it in a proper way, by registering the MDIO bus based
on if the PHY attached to a given interface is described in the device
tree or not.

Fixes: 7897b07 ("net: macb: convert to phylink")
Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Antoine Tenart authored and David S. Miller committed Dec 20, 2019
1 parent 0aa4d01 commit ef8a2e2
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions drivers/net/ethernet/cadence/macb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,30 @@ static int macb_mii_probe(struct net_device *dev)
return 0;
}

static int macb_mdiobus_register(struct macb *bp)
{
struct device_node *child, *np = bp->pdev->dev.of_node;

/* Only create the PHY from the device tree if at least one PHY is
* described. Otherwise scan the entire MDIO bus. We do this to support
* old device tree that did not follow the best practices and did not
* describe their network PHYs.
*/
for_each_available_child_of_node(np, child)
if (of_mdiobus_child_is_phy(child)) {
/* The loop increments the child refcount,
* decrement it before returning.
*/
of_node_put(child);

return of_mdiobus_register(bp->mii_bus, np);
}

return mdiobus_register(bp->mii_bus);
}

static int macb_mii_init(struct macb *bp)
{
struct device_node *np;
int err = -ENXIO;

/* Enable management port */
Expand All @@ -688,9 +709,7 @@ static int macb_mii_init(struct macb *bp)

dev_set_drvdata(&bp->dev->dev, bp->mii_bus);

np = bp->pdev->dev.of_node;

err = of_mdiobus_register(bp->mii_bus, np);
err = macb_mdiobus_register(bp);
if (err)
goto err_out_free_mdiobus;

Expand Down

0 comments on commit ef8a2e2

Please sign in to comment.