Skip to content

Commit 922071b

Browse files
atenartclaudiubeznea
authored andcommitted
net: macb: fix probing of PHY not described in the dt
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>
1 parent 609e9c0 commit 922071b

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

drivers/net/ethernet/cadence/macb_main.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,30 @@ static int macb_mii_probe(struct net_device *dev)
664664
return 0;
665665
}
666666

667+
static int macb_mdiobus_register(struct macb *bp)
668+
{
669+
struct device_node *child, *np = bp->pdev->dev.of_node;
670+
671+
/* Only create the PHY from the device tree if at least one PHY is
672+
* described. Otherwise scan the entire MDIO bus. We do this to support
673+
* old device tree that did not follow the best practices and did not
674+
* describe their network PHYs.
675+
*/
676+
for_each_available_child_of_node(np, child)
677+
if (of_mdiobus_child_is_phy(child)) {
678+
/* The loop increments the child refcount,
679+
* decrement it before returning.
680+
*/
681+
of_node_put(child);
682+
683+
return of_mdiobus_register(bp->mii_bus, np);
684+
}
685+
686+
return mdiobus_register(bp->mii_bus);
687+
}
688+
667689
static int macb_mii_init(struct macb *bp)
668690
{
669-
struct device_node *np;
670691
int err = -ENXIO;
671692

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

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

691-
np = bp->pdev->dev.of_node;
692-
693-
err = of_mdiobus_register(bp->mii_bus, np);
712+
err = macb_mdiobus_register(bp);
694713
if (err)
695714
goto err_out_free_mdiobus;
696715

0 commit comments

Comments
 (0)