mirror of https://gitee.com/openkylin/linux.git
Merge branch 'sh_eth-next'
Laurent Pinchart says: ==================== sh_eth: Fix the race between open and MDIO bus registration This patch series fixes the race condition that exists in the sh_eth driver between network device open and MDIO bus registration. The actual fix is in patch 4/5, with previous patches preparing the driver and patch 5/5 cleaning up an unrelated issue. I've based the idea on Sergei's attempt to fix the problem and can successfully boot the Koelsch board over NFS with this series. I might have missed other issues though, hence the RFC status. The patches are based on top of the latest net-next master branch. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
3907c432cb
|
@ -873,7 +873,7 @@ static int sh_eth_reset(struct net_device *ndev)
|
||||||
|
|
||||||
ret = sh_eth_check_reset(ndev);
|
ret = sh_eth_check_reset(ndev);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
return ret;
|
||||||
|
|
||||||
/* Table Init */
|
/* Table Init */
|
||||||
sh_eth_write(ndev, 0x0, TDLAR);
|
sh_eth_write(ndev, 0x0, TDLAR);
|
||||||
|
@ -900,7 +900,6 @@ static int sh_eth_reset(struct net_device *ndev)
|
||||||
EDMR);
|
EDMR);
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1264,7 +1263,7 @@ static int sh_eth_dev_init(struct net_device *ndev, bool start)
|
||||||
/* Soft Reset */
|
/* Soft Reset */
|
||||||
ret = sh_eth_reset(ndev);
|
ret = sh_eth_reset(ndev);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
return ret;
|
||||||
|
|
||||||
if (mdp->cd->rmiimode)
|
if (mdp->cd->rmiimode)
|
||||||
sh_eth_write(ndev, 0x1, RMIIMODE);
|
sh_eth_write(ndev, 0x1, RMIIMODE);
|
||||||
|
@ -1343,7 +1342,6 @@ static int sh_eth_dev_init(struct net_device *ndev, bool start)
|
||||||
netif_start_queue(ndev);
|
netif_start_queue(ndev);
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2583,37 +2581,30 @@ static void sh_eth_tsu_init(struct sh_eth_private *mdp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MDIO bus release function */
|
/* MDIO bus release function */
|
||||||
static int sh_mdio_release(struct net_device *ndev)
|
static int sh_mdio_release(struct sh_eth_private *mdp)
|
||||||
{
|
{
|
||||||
struct mii_bus *bus = dev_get_drvdata(&ndev->dev);
|
|
||||||
|
|
||||||
/* unregister mdio bus */
|
/* unregister mdio bus */
|
||||||
mdiobus_unregister(bus);
|
mdiobus_unregister(mdp->mii_bus);
|
||||||
|
|
||||||
/* remove mdio bus info from net_device */
|
|
||||||
dev_set_drvdata(&ndev->dev, NULL);
|
|
||||||
|
|
||||||
/* free bitbang info */
|
/* free bitbang info */
|
||||||
free_mdio_bitbang(bus);
|
free_mdio_bitbang(mdp->mii_bus);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MDIO bus init function */
|
/* MDIO bus init function */
|
||||||
static int sh_mdio_init(struct net_device *ndev, int id,
|
static int sh_mdio_init(struct sh_eth_private *mdp,
|
||||||
struct sh_eth_plat_data *pd)
|
struct sh_eth_plat_data *pd)
|
||||||
{
|
{
|
||||||
int ret, i;
|
int ret, i;
|
||||||
struct bb_info *bitbang;
|
struct bb_info *bitbang;
|
||||||
struct sh_eth_private *mdp = netdev_priv(ndev);
|
struct platform_device *pdev = mdp->pdev;
|
||||||
|
struct device *dev = &mdp->pdev->dev;
|
||||||
|
|
||||||
/* create bit control struct for PHY */
|
/* create bit control struct for PHY */
|
||||||
bitbang = devm_kzalloc(&ndev->dev, sizeof(struct bb_info),
|
bitbang = devm_kzalloc(dev, sizeof(struct bb_info), GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
if (!bitbang)
|
||||||
if (!bitbang) {
|
return -ENOMEM;
|
||||||
ret = -ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* bitbang init */
|
/* bitbang init */
|
||||||
bitbang->addr = mdp->addr + mdp->reg_offset[PIR];
|
bitbang->addr = mdp->addr + mdp->reg_offset[PIR];
|
||||||
|
@ -2626,30 +2617,26 @@ static int sh_mdio_init(struct net_device *ndev, int id,
|
||||||
|
|
||||||
/* MII controller setting */
|
/* MII controller setting */
|
||||||
mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl);
|
mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl);
|
||||||
if (!mdp->mii_bus) {
|
if (!mdp->mii_bus)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Hook up MII support for ethtool */
|
/* Hook up MII support for ethtool */
|
||||||
mdp->mii_bus->name = "sh_mii";
|
mdp->mii_bus->name = "sh_mii";
|
||||||
mdp->mii_bus->parent = &ndev->dev;
|
mdp->mii_bus->parent = dev;
|
||||||
snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
|
snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
|
||||||
mdp->pdev->name, id);
|
pdev->name, pdev->id);
|
||||||
|
|
||||||
/* PHY IRQ */
|
/* PHY IRQ */
|
||||||
mdp->mii_bus->irq = devm_kzalloc(&ndev->dev,
|
mdp->mii_bus->irq = devm_kzalloc(dev, sizeof(int) * PHY_MAX_ADDR,
|
||||||
sizeof(int) * PHY_MAX_ADDR,
|
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!mdp->mii_bus->irq) {
|
if (!mdp->mii_bus->irq) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out_free_bus;
|
goto out_free_bus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* register mdio bus */
|
/* register MDIO bus */
|
||||||
if (ndev->dev.parent->of_node) {
|
if (dev->of_node) {
|
||||||
ret = of_mdiobus_register(mdp->mii_bus,
|
ret = of_mdiobus_register(mdp->mii_bus, dev->of_node);
|
||||||
ndev->dev.parent->of_node);
|
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < PHY_MAX_ADDR; i++)
|
for (i = 0; i < PHY_MAX_ADDR; i++)
|
||||||
mdp->mii_bus->irq[i] = PHY_POLL;
|
mdp->mii_bus->irq[i] = PHY_POLL;
|
||||||
|
@ -2662,14 +2649,10 @@ static int sh_mdio_init(struct net_device *ndev, int id,
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_free_bus;
|
goto out_free_bus;
|
||||||
|
|
||||||
dev_set_drvdata(&ndev->dev, mdp->mii_bus);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_free_bus:
|
out_free_bus:
|
||||||
free_mdio_bitbang(mdp->mii_bus);
|
free_mdio_bitbang(mdp->mii_bus);
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2782,15 +2765,12 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
|
||||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
if (unlikely(res == NULL)) {
|
if (unlikely(res == NULL)) {
|
||||||
dev_err(&pdev->dev, "invalid resource\n");
|
dev_err(&pdev->dev, "invalid resource\n");
|
||||||
ret = -EINVAL;
|
return -EINVAL;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ndev = alloc_etherdev(sizeof(struct sh_eth_private));
|
ndev = alloc_etherdev(sizeof(struct sh_eth_private));
|
||||||
if (!ndev) {
|
if (!ndev)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The sh Ether-specific entries in the device structure. */
|
/* The sh Ether-specific entries in the device structure. */
|
||||||
ndev->base_addr = res->start;
|
ndev->base_addr = res->start;
|
||||||
|
@ -2900,6 +2880,13 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* MDIO bus init */
|
||||||
|
ret = sh_mdio_init(mdp, pd);
|
||||||
|
if (ret) {
|
||||||
|
dev_err(&ndev->dev, "failed to initialise MDIO\n");
|
||||||
|
goto out_release;
|
||||||
|
}
|
||||||
|
|
||||||
netif_napi_add(ndev, &mdp->napi, sh_eth_poll, 64);
|
netif_napi_add(ndev, &mdp->napi, sh_eth_poll, 64);
|
||||||
|
|
||||||
/* network device register */
|
/* network device register */
|
||||||
|
@ -2907,13 +2894,6 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_napi_del;
|
goto out_napi_del;
|
||||||
|
|
||||||
/* mdio bus init */
|
|
||||||
ret = sh_mdio_init(ndev, pdev->id, pd);
|
|
||||||
if (ret) {
|
|
||||||
dev_err(&ndev->dev, "failed to initialise MDIO\n");
|
|
||||||
goto out_unregister;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* print device information */
|
/* print device information */
|
||||||
netdev_info(ndev, "Base address at 0x%x, %pM, IRQ %d.\n",
|
netdev_info(ndev, "Base address at 0x%x, %pM, IRQ %d.\n",
|
||||||
(u32)ndev->base_addr, ndev->dev_addr, ndev->irq);
|
(u32)ndev->base_addr, ndev->dev_addr, ndev->irq);
|
||||||
|
@ -2922,18 +2902,15 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
out_unregister:
|
|
||||||
unregister_netdev(ndev);
|
|
||||||
|
|
||||||
out_napi_del:
|
out_napi_del:
|
||||||
netif_napi_del(&mdp->napi);
|
netif_napi_del(&mdp->napi);
|
||||||
|
sh_mdio_release(mdp);
|
||||||
|
|
||||||
out_release:
|
out_release:
|
||||||
/* net_dev free */
|
/* net_dev free */
|
||||||
if (ndev)
|
if (ndev)
|
||||||
free_netdev(ndev);
|
free_netdev(ndev);
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2942,9 +2919,9 @@ static int sh_eth_drv_remove(struct platform_device *pdev)
|
||||||
struct net_device *ndev = platform_get_drvdata(pdev);
|
struct net_device *ndev = platform_get_drvdata(pdev);
|
||||||
struct sh_eth_private *mdp = netdev_priv(ndev);
|
struct sh_eth_private *mdp = netdev_priv(ndev);
|
||||||
|
|
||||||
sh_mdio_release(ndev);
|
|
||||||
unregister_netdev(ndev);
|
unregister_netdev(ndev);
|
||||||
netif_napi_del(&mdp->napi);
|
netif_napi_del(&mdp->napi);
|
||||||
|
sh_mdio_release(mdp);
|
||||||
pm_runtime_disable(&pdev->dev);
|
pm_runtime_disable(&pdev->dev);
|
||||||
free_netdev(ndev);
|
free_netdev(ndev);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue