Skip to content

Commit 6cc8e6d

Browse files
ffainellidavem330
authored andcommitted
net: bcmgenet: Delay PHY initialization to bcmgenet_open()
We are currently doing a full PHY initialization and even starting the pHY state machine during bcmgenet_mii_init() which is executed in the driver's probe function. This is convenient to determine whether we can attach to a proper PHY device but comes at the expense of spending up to 10ms per MDIO transactions (to reach the waitqueue timeout), which slows things down. This also creates a sitaution where we end-up attaching twice to the PHY, which is not quite correct either. Fix this by moving bcmgenet_mii_probe() into bcmgenet_open() and update its error path accordingly. Avoid printing the message "attached PHY at address 1 [...]" every time we bring up/down the interface and remove this print since it duplicates what the PHY driver already does for us. Fixes: 1c1008c ("net: bcmgenet: add main driver file") Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c624f89 commit 6cc8e6d

File tree

3 files changed

+20
-30
lines changed

3 files changed

+20
-30
lines changed

drivers/net/ethernet/broadcom/genet/bcmgenet.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,16 +2686,18 @@ static int bcmgenet_open(struct net_device *dev)
26862686
goto err_irq0;
26872687
}
26882688

2689-
/* Re-configure the port multiplexer towards the PHY device */
2690-
bcmgenet_mii_config(priv->dev, false);
2691-
2692-
phy_connect_direct(dev, priv->phydev, bcmgenet_mii_setup,
2693-
priv->phy_interface);
2689+
ret = bcmgenet_mii_probe(dev);
2690+
if (ret) {
2691+
netdev_err(dev, "failed to connect to PHY\n");
2692+
goto err_irq1;
2693+
}
26942694

26952695
bcmgenet_netif_start(dev);
26962696

26972697
return 0;
26982698

2699+
err_irq1:
2700+
free_irq(priv->irq1, priv);
26992701
err_irq0:
27002702
free_irq(priv->irq0, priv);
27012703
err_fini_dma:

drivers/net/ethernet/broadcom/genet/bcmgenet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ GENET_IO_MACRO(rbuf, GENET_RBUF_OFF);
672672
/* MDIO routines */
673673
int bcmgenet_mii_init(struct net_device *dev);
674674
int bcmgenet_mii_config(struct net_device *dev, bool init);
675+
int bcmgenet_mii_probe(struct net_device *dev);
675676
void bcmgenet_mii_exit(struct net_device *dev);
676677
void bcmgenet_phy_power_set(struct net_device *dev, bool enable);
677678
void bcmgenet_mii_setup(struct net_device *dev);

drivers/net/ethernet/broadcom/genet/bcmmii.c

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ int bcmgenet_mii_config(struct net_device *dev, bool init)
316316
return 0;
317317
}
318318

319-
static int bcmgenet_mii_probe(struct net_device *dev)
319+
int bcmgenet_mii_probe(struct net_device *dev)
320320
{
321321
struct bcmgenet_priv *priv = netdev_priv(dev);
322322
struct device_node *dn = priv->pdev->dev.of_node;
@@ -334,22 +334,6 @@ static int bcmgenet_mii_probe(struct net_device *dev)
334334
priv->old_pause = -1;
335335

336336
if (dn) {
337-
if (priv->phydev) {
338-
pr_info("PHY already attached\n");
339-
return 0;
340-
}
341-
342-
/* In the case of a fixed PHY, the DT node associated
343-
* to the PHY is the Ethernet MAC DT node.
344-
*/
345-
if (!priv->phy_dn && of_phy_is_fixed_link(dn)) {
346-
ret = of_phy_register_fixed_link(dn);
347-
if (ret)
348-
return ret;
349-
350-
priv->phy_dn = of_node_get(dn);
351-
}
352-
353337
phydev = of_phy_connect(dev, priv->phy_dn, bcmgenet_mii_setup,
354338
phy_flags, priv->phy_interface);
355339
if (!phydev) {
@@ -391,9 +375,6 @@ static int bcmgenet_mii_probe(struct net_device *dev)
391375
else
392376
priv->mii_bus->irq[phydev->addr] = PHY_POLL;
393377

394-
pr_info("attached PHY at address %d [%s]\n",
395-
phydev->addr, phydev->drv->name);
396-
397378
return 0;
398379
}
399380

@@ -504,6 +485,17 @@ static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv)
504485
/* Fetch the PHY phandle */
505486
priv->phy_dn = of_parse_phandle(dn, "phy-handle", 0);
506487

488+
/* In the case of a fixed PHY, the DT node associated
489+
* to the PHY is the Ethernet MAC DT node.
490+
*/
491+
if (!priv->phy_dn && of_phy_is_fixed_link(dn)) {
492+
ret = of_phy_register_fixed_link(dn);
493+
if (ret)
494+
return ret;
495+
496+
priv->phy_dn = of_node_get(dn);
497+
}
498+
507499
/* Get the link mode */
508500
phy_mode = of_get_phy_mode(dn);
509501
priv->phy_interface = phy_mode;
@@ -622,10 +614,6 @@ int bcmgenet_mii_init(struct net_device *dev)
622614
return ret;
623615

624616
ret = bcmgenet_mii_bus_init(priv);
625-
if (ret)
626-
goto out_free;
627-
628-
ret = bcmgenet_mii_probe(dev);
629617
if (ret)
630618
goto out;
631619

@@ -634,7 +622,6 @@ int bcmgenet_mii_init(struct net_device *dev)
634622
out:
635623
of_node_put(priv->phy_dn);
636624
mdiobus_unregister(priv->mii_bus);
637-
out_free:
638625
kfree(priv->mii_bus->irq);
639626
mdiobus_free(priv->mii_bus);
640627
return ret;

0 commit comments

Comments
 (0)