Commit aea95dd5 authored by Jeremy Linton's avatar Jeremy Linton Committed by David S. Miller

net: smsc911x: Fix register_netdev, phy startup, driver unload ordering

Move phy startup/shutdown into the smsc911x_open/stop routines. This
allows the module to be unloaded because phy_connect_direct is no longer
always holding the module use count. This one change also resolves a
number of other problems.

The link status of a downed interface no longer reflects a stale state.
Errors caused by the net device being opened before the mdio/phy was
configured. There is also a potential power savings as the phy's don't
remain powered when the interface isn't running.
Signed-off-by: default avatarJeremy Linton <jeremy.linton@arm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1358bd5a
......@@ -1099,15 +1099,8 @@ static int smsc911x_mii_init(struct platform_device *pdev,
goto err_out_free_bus_2;
}
if (smsc911x_mii_probe(dev) < 0) {
SMSC_WARN(pdata, probe, "Error registering mii bus");
goto err_out_unregister_bus_3;
}
return 0;
err_out_unregister_bus_3:
mdiobus_unregister(pdata->mii_bus);
err_out_free_bus_2:
mdiobus_free(pdata->mii_bus);
err_out_1:
......@@ -1522,18 +1515,20 @@ static int smsc911x_open(struct net_device *dev)
unsigned int intcfg;
int retval;
/* if the phy is not yet registered, retry later*/
/* find and start the given phy */
if (!dev->phydev) {
SMSC_WARN(pdata, hw, "phy_dev is NULL");
retval = -EAGAIN;
retval = smsc911x_mii_probe(dev);
if (retval < 0) {
SMSC_WARN(pdata, probe, "Error starting phy");
goto out;
}
}
/* Reset the LAN911x */
retval = smsc911x_soft_reset(pdata);
if (retval) {
SMSC_WARN(pdata, hw, "soft reset failed");
goto out;
goto mii_free_out;
}
smsc911x_reg_write(pdata, HW_CFG, 0x00050000);
......@@ -1604,7 +1599,7 @@ static int smsc911x_open(struct net_device *dev)
netdev_warn(dev, "ISR failed signaling test (IRQ %d)\n",
dev->irq);
retval = -ENODEV;
goto out;
goto mii_free_out;
}
SMSC_TRACE(pdata, ifup, "IRQ handler passed test using IRQ %d",
dev->irq);
......@@ -1650,6 +1645,10 @@ static int smsc911x_open(struct net_device *dev)
netif_start_queue(dev);
return 0;
mii_free_out:
phy_disconnect(dev->phydev);
dev->phydev = NULL;
out:
return retval;
}
......@@ -1674,8 +1673,12 @@ static int smsc911x_stop(struct net_device *dev)
smsc911x_tx_update_txcounters(dev);
/* Bring the PHY down */
if (dev->phydev)
if (dev->phydev) {
phy_stop(dev->phydev);
phy_disconnect(dev->phydev);
dev->phydev = NULL;
}
netif_carrier_off(dev);
SMSC_TRACE(pdata, ifdown, "Interface stopped");
return 0;
......@@ -2297,11 +2300,10 @@ static int smsc911x_drv_remove(struct platform_device *pdev)
pdata = netdev_priv(dev);
BUG_ON(!pdata);
BUG_ON(!pdata->ioaddr);
BUG_ON(!dev->phydev);
WARN_ON(dev->phydev);
SMSC_TRACE(pdata, ifdown, "Stopping driver");
phy_disconnect(dev->phydev);
mdiobus_unregister(pdata->mii_bus);
mdiobus_free(pdata->mii_bus);
......@@ -2500,6 +2502,12 @@ static int smsc911x_drv_probe(struct platform_device *pdev)
netif_carrier_off(dev);
retval = smsc911x_mii_init(pdev, dev);
if (retval) {
SMSC_WARN(pdata, probe, "Error %i initialising mii", retval);
goto out_free_irq;
}
retval = register_netdev(dev);
if (retval) {
SMSC_WARN(pdata, probe, "Error %i registering device", retval);
......@@ -2509,12 +2517,6 @@ static int smsc911x_drv_probe(struct platform_device *pdev)
"Network interface: \"%s\"", dev->name);
}
retval = smsc911x_mii_init(pdev, dev);
if (retval) {
SMSC_WARN(pdata, probe, "Error %i initialising mii", retval);
goto out_unregister_netdev_5;
}
spin_lock_irq(&pdata->mac_lock);
/* Check if mac address has been specified when bringing interface up */
......@@ -2550,8 +2552,6 @@ static int smsc911x_drv_probe(struct platform_device *pdev)
return 0;
out_unregister_netdev_5:
unregister_netdev(dev);
out_free_irq:
free_irq(dev->irq, dev);
out_disable_resources:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment