Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3907c432 authored by David S. Miller's avatar David S. Miller
Browse files

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: default avatarDavid S. Miller <davem@davemloft.net>
parents 54af36e7 f738a13d
Loading
Loading
Loading
Loading
+31 −54
Original line number Diff line number Diff line
@@ -873,7 +873,7 @@ static int sh_eth_reset(struct net_device *ndev)

		ret = sh_eth_check_reset(ndev);
		if (ret)
			goto out;
			return ret;

		/* Table Init */
		sh_eth_write(ndev, 0x0, TDLAR);
@@ -900,7 +900,6 @@ static int sh_eth_reset(struct net_device *ndev)
			     EDMR);
	}

out:
	return ret;
}

@@ -1264,7 +1263,7 @@ static int sh_eth_dev_init(struct net_device *ndev, bool start)
	/* Soft Reset */
	ret = sh_eth_reset(ndev);
	if (ret)
		goto out;
		return ret;

	if (mdp->cd->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);
	}

out:
	return ret;
}

@@ -2583,37 +2581,30 @@ static void sh_eth_tsu_init(struct sh_eth_private *mdp)
}

/* 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 */
	mdiobus_unregister(bus);

	/* remove mdio bus info from net_device */
	dev_set_drvdata(&ndev->dev, NULL);
	mdiobus_unregister(mdp->mii_bus);

	/* free bitbang info */
	free_mdio_bitbang(bus);
	free_mdio_bitbang(mdp->mii_bus);

	return 0;
}

/* 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)
{
	int ret, i;
	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 */
	bitbang = devm_kzalloc(&ndev->dev, sizeof(struct bb_info),
			       GFP_KERNEL);
	if (!bitbang) {
		ret = -ENOMEM;
		goto out;
	}
	bitbang = devm_kzalloc(dev, sizeof(struct bb_info), GFP_KERNEL);
	if (!bitbang)
		return -ENOMEM;

	/* bitbang init */
	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 */
	mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl);
	if (!mdp->mii_bus) {
		ret = -ENOMEM;
		goto out;
	}
	if (!mdp->mii_bus)
		return -ENOMEM;

	/* Hook up MII support for ethtool */
	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",
		 mdp->pdev->name, id);
		 pdev->name, pdev->id);

	/* PHY IRQ */
	mdp->mii_bus->irq = devm_kzalloc(&ndev->dev,
					 sizeof(int) * PHY_MAX_ADDR,
	mdp->mii_bus->irq = devm_kzalloc(dev, sizeof(int) * PHY_MAX_ADDR,
					 GFP_KERNEL);
	if (!mdp->mii_bus->irq) {
		ret = -ENOMEM;
		goto out_free_bus;
	}

	/* register mdio bus */
	if (ndev->dev.parent->of_node) {
		ret = of_mdiobus_register(mdp->mii_bus,
					  ndev->dev.parent->of_node);
	/* register MDIO bus */
	if (dev->of_node) {
		ret = of_mdiobus_register(mdp->mii_bus, dev->of_node);
	} else {
		for (i = 0; i < PHY_MAX_ADDR; i++)
			mdp->mii_bus->irq[i] = PHY_POLL;
@@ -2662,14 +2649,10 @@ static int sh_mdio_init(struct net_device *ndev, int id,
	if (ret)
		goto out_free_bus;

	dev_set_drvdata(&ndev->dev, mdp->mii_bus);

	return 0;

out_free_bus:
	free_mdio_bitbang(mdp->mii_bus);

out:
	return ret;
}

@@ -2782,15 +2765,12 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (unlikely(res == NULL)) {
		dev_err(&pdev->dev, "invalid resource\n");
		ret = -EINVAL;
		goto out;
		return -EINVAL;
	}

	ndev = alloc_etherdev(sizeof(struct sh_eth_private));
	if (!ndev) {
		ret = -ENOMEM;
		goto out;
	}
	if (!ndev)
		return -ENOMEM;

	/* The sh Ether-specific entries in the device structure. */
	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);

	/* network device register */
@@ -2907,13 +2894,6 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
	if (ret)
		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 */
	netdev_info(ndev, "Base address at 0x%x, %pM, IRQ %d.\n",
		    (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;

out_unregister:
	unregister_netdev(ndev);

out_napi_del:
	netif_napi_del(&mdp->napi);
	sh_mdio_release(mdp);

out_release:
	/* net_dev free */
	if (ndev)
		free_netdev(ndev);

out:
	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 sh_eth_private *mdp = netdev_priv(ndev);

	sh_mdio_release(ndev);
	unregister_netdev(ndev);
	netif_napi_del(&mdp->napi);
	sh_mdio_release(mdp);
	pm_runtime_disable(&pdev->dev);
	free_netdev(ndev);