Skip to content

Commit

Permalink
mdio: Move allocation of interrupts into core
Browse files Browse the repository at this point in the history
Have mdio_alloc() create the array of interrupt numbers, and
initialize it to POLLING. This is what most MDIO drivers want, so
allowing code to be removed from the drivers.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
lunn authored and davem330 committed Jan 7, 2016
1 parent 35d2aea commit e7f4dc3
Show file tree
Hide file tree
Showing 54 changed files with 48 additions and 396 deletions.
10 changes: 1 addition & 9 deletions arch/powerpc/platforms/82xx/ep8248e.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,15 @@ static int ep8248e_mdio_probe(struct platform_device *ofdev)
if (!bus)
return -ENOMEM;

bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
if (bus->irq == NULL) {
ret = -ENOMEM;
goto err_free_bus;
}

bus->name = "ep8248e-mdio-bitbang";
bus->parent = &ofdev->dev;
snprintf(bus->id, MII_BUS_ID_SIZE, "%x", res.start);

ret = of_mdiobus_register(bus, ofdev->dev.of_node);
if (ret)
goto err_free_irq;
goto err_free_bus;

return 0;
err_free_irq:
kfree(bus->irq);
err_free_bus:
free_mdio_bitbang(bus);
return ret;
Expand Down
3 changes: 0 additions & 3 deletions arch/powerpc/platforms/pasemi/gpio_mdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ static void __iomem *gpio_regs;
struct gpio_priv {
int mdc_pin;
int mdio_pin;
int mdio_irqs[PHY_MAX_ADDR];
};

#define MDC_PIN(bus) (((struct gpio_priv *)bus->priv)->mdc_pin)
Expand Down Expand Up @@ -245,8 +244,6 @@ static int gpio_mdio_probe(struct platform_device *ofdev)
snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", *prop);
new_bus->priv = priv;

new_bus->irq = priv->mdio_irqs;

prop = of_get_property(np, "mdc-pin", NULL);
priv->mdc_pin = *prop;

Expand Down
15 changes: 2 additions & 13 deletions drivers/net/ethernet/8390/ax88796.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ static int ax_mii_init(struct net_device *dev)
struct platform_device *pdev = to_platform_device(dev->dev.parent);
struct ei_device *ei_local = netdev_priv(dev);
struct ax_device *ax = to_ax_dev(dev);
int err, i;
int err;

ax->bb_ctrl.ops = &bb_ops;
ax->addr_memr = ei_local->mem + AX_MEMR;
Expand All @@ -642,23 +642,12 @@ static int ax_mii_init(struct net_device *dev)
snprintf(ax->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
pdev->name, pdev->id);

ax->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
if (!ax->mii_bus->irq) {
err = -ENOMEM;
goto out_free_mdio_bitbang;
}

for (i = 0; i < PHY_MAX_ADDR; i++)
ax->mii_bus->irq[i] = PHY_POLL;

err = mdiobus_register(ax->mii_bus);
if (err)
goto out_free_irq;
goto out_free_mdio_bitbang;

return 0;

out_free_irq:
kfree(ax->mii_bus->irq);
out_free_mdio_bitbang:
free_mdio_bitbang(ax->mii_bus);
out:
Expand Down
11 changes: 1 addition & 10 deletions drivers/net/ethernet/adi/bfin_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1838,12 +1838,6 @@ static int bfin_mii_bus_probe(struct platform_device *pdev)

snprintf(miibus->id, MII_BUS_ID_SIZE, "%s-%x",
pdev->name, pdev->id);
miibus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
if (!miibus->irq)
goto out_err_irq_alloc;

for (i = rc; i < PHY_MAX_ADDR; ++i)
miibus->irq[i] = PHY_POLL;

rc = clamp(mii_bus_pd->phydev_number, 0, PHY_MAX_ADDR);
if (rc != mii_bus_pd->phydev_number)
Expand All @@ -1862,14 +1856,12 @@ static int bfin_mii_bus_probe(struct platform_device *pdev)
rc = mdiobus_register(miibus);
if (rc) {
dev_err(&pdev->dev, "Cannot register MDIO bus!\n");
goto out_err_mdiobus_register;
goto out_err_alloc;
}

platform_set_drvdata(pdev, miibus);
return 0;

out_err_mdiobus_register:
kfree(miibus->irq);
out_err_irq_alloc:
mdiobus_free(miibus);
out_err_alloc:
Expand All @@ -1885,7 +1877,6 @@ static int bfin_mii_bus_remove(struct platform_device *pdev)
dev_get_platdata(&pdev->dev);

mdiobus_unregister(miibus);
kfree(miibus->irq);
mdiobus_free(miibus);
peripheral_free_list(mii_bus_pd->mac_peripherals);

Expand Down
5 changes: 0 additions & 5 deletions drivers/net/ethernet/aeroflex/greth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1337,11 +1337,6 @@ static int greth_mdio_init(struct greth_private *greth)
greth->mdio->write = greth_mdio_write;
greth->mdio->priv = greth;

greth->mdio->irq = greth->mdio_irqs;

for (phy = 0; phy < PHY_MAX_ADDR; phy++)
greth->mdio->irq[phy] = PHY_POLL;

ret = mdiobus_register(greth->mdio);
if (ret) {
goto error;
Expand Down
1 change: 0 additions & 1 deletion drivers/net/ethernet/aeroflex/greth.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ struct greth_private {

struct phy_device *phy;
struct mii_bus *mdio;
int mdio_irqs[PHY_MAX_ADDR];
unsigned int link;
unsigned int speed;
unsigned int duplex;
Expand Down
13 changes: 1 addition & 12 deletions drivers/net/ethernet/agere/et131x.c
Original file line number Diff line number Diff line change
Expand Up @@ -3325,7 +3325,6 @@ static void et131x_pci_remove(struct pci_dev *pdev)
netif_napi_del(&adapter->napi);
phy_disconnect(adapter->phydev);
mdiobus_unregister(adapter->mii_bus);
kfree(adapter->mii_bus->irq);
mdiobus_free(adapter->mii_bus);

et131x_adapter_memory_free(adapter);
Expand Down Expand Up @@ -3944,7 +3943,6 @@ static int et131x_pci_setup(struct pci_dev *pdev,
struct net_device *netdev;
struct et131x_adapter *adapter;
int rc;
int ii;

rc = pci_enable_device(pdev);
if (rc < 0) {
Expand Down Expand Up @@ -4034,18 +4032,11 @@ static int et131x_pci_setup(struct pci_dev *pdev,
adapter->mii_bus->priv = netdev;
adapter->mii_bus->read = et131x_mdio_read;
adapter->mii_bus->write = et131x_mdio_write;
adapter->mii_bus->irq = kmalloc_array(PHY_MAX_ADDR, sizeof(int),
GFP_KERNEL);
if (!adapter->mii_bus->irq)
goto err_mdio_free;

for (ii = 0; ii < PHY_MAX_ADDR; ii++)
adapter->mii_bus->irq[ii] = PHY_POLL;

rc = mdiobus_register(adapter->mii_bus);
if (rc < 0) {
dev_err(&pdev->dev, "failed to register MII bus\n");
goto err_mdio_free_irq;
goto err_mdio_free;
}

rc = et131x_mii_probe(netdev);
Expand Down Expand Up @@ -4085,8 +4076,6 @@ static int et131x_pci_setup(struct pci_dev *pdev,
phy_disconnect(adapter->phydev);
err_mdio_unregister:
mdiobus_unregister(adapter->mii_bus);
err_mdio_free_irq:
kfree(adapter->mii_bus->irq);
err_mdio_free:
mdiobus_free(adapter->mii_bus);
err_mem_free:
Expand Down
13 changes: 1 addition & 12 deletions drivers/net/ethernet/altera/altera_tse_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ static int altera_tse_mdio_create(struct net_device *dev, unsigned int id)
{
struct altera_tse_private *priv = netdev_priv(dev);
int ret;
int i;
struct device_node *mdio_node = NULL;
struct mii_bus *mdio = NULL;
struct device_node *child_node = NULL;
Expand Down Expand Up @@ -161,31 +160,21 @@ static int altera_tse_mdio_create(struct net_device *dev, unsigned int id)
mdio->write = &altera_tse_mdio_write;
snprintf(mdio->id, MII_BUS_ID_SIZE, "%s-%u", mdio->name, id);

mdio->irq = kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
if (mdio->irq == NULL) {
ret = -ENOMEM;
goto out_free_mdio;
}
for (i = 0; i < PHY_MAX_ADDR; i++)
mdio->irq[i] = PHY_POLL;

mdio->priv = dev;
mdio->parent = priv->device;

ret = of_mdiobus_register(mdio, mdio_node);
if (ret != 0) {
netdev_err(dev, "Cannot register MDIO bus %s\n",
mdio->id);
goto out_free_mdio_irq;
goto out_free_mdio;
}

if (netif_msg_drv(priv))
netdev_info(dev, "MDIO bus %s: created\n", mdio->id);

priv->mdio = mdio;
return 0;
out_free_mdio_irq:
kfree(mdio->irq);
out_free_mdio:
mdiobus_free(mdio);
mdio = NULL;
Expand Down
7 changes: 0 additions & 7 deletions drivers/net/ethernet/amd/au1000_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1291,14 +1291,7 @@ static int au1000_probe(struct platform_device *pdev)
aup->mii_bus->name = "au1000_eth_mii";
snprintf(aup->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
pdev->name, aup->mac_id);
aup->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
if (aup->mii_bus->irq == NULL) {
err = -ENOMEM;
goto err_out;
}

for (i = 0; i < PHY_MAX_ADDR; ++i)
aup->mii_bus->irq[i] = PHY_POLL;
/* if known, set corresponding PHY IRQs */
if (aup->phy_static_config)
if (aup->phy_irq && aup->phy_busid == aup->mac_id)
Expand Down
14 changes: 1 addition & 13 deletions drivers/net/ethernet/broadcom/b44.c
Original file line number Diff line number Diff line change
Expand Up @@ -2263,21 +2263,13 @@ static int b44_register_phy_one(struct b44 *bp)
mii_bus->parent = sdev->dev;
mii_bus->phy_mask = ~(1 << bp->phy_addr);
snprintf(mii_bus->id, MII_BUS_ID_SIZE, "%x", instance);
mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
if (!mii_bus->irq) {
dev_err(sdev->dev, "mii_bus irq allocation failed\n");
err = -ENOMEM;
goto err_out_mdiobus;
}

memset(mii_bus->irq, PHY_POLL, sizeof(int) * PHY_MAX_ADDR);

bp->mii_bus = mii_bus;

err = mdiobus_register(mii_bus);
if (err) {
dev_err(sdev->dev, "failed to register MII bus\n");
goto err_out_mdiobus_irq;
goto err_out_mdiobus;
}

if (!bp->mii_bus->phy_map[bp->phy_addr] &&
Expand Down Expand Up @@ -2322,9 +2314,6 @@ static int b44_register_phy_one(struct b44 *bp)
err_out_mdiobus_unregister:
mdiobus_unregister(mii_bus);

err_out_mdiobus_irq:
kfree(mii_bus->irq);

err_out_mdiobus:
mdiobus_free(mii_bus);

Expand All @@ -2338,7 +2327,6 @@ static void b44_unregister_phy_one(struct b44 *bp)

phy_disconnect(bp->phydev);
mdiobus_unregister(mii_bus);
kfree(mii_bus->irq);
mdiobus_free(mii_bus);
}

Expand Down
9 changes: 0 additions & 9 deletions drivers/net/ethernet/broadcom/bcm63xx_enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1848,17 +1848,8 @@ static int bcm_enet_probe(struct platform_device *pdev)
* if a slave is not present on hw */
bus->phy_mask = ~(1 << priv->phy_id);

bus->irq = devm_kzalloc(&pdev->dev, sizeof(int) * PHY_MAX_ADDR,
GFP_KERNEL);
if (!bus->irq) {
ret = -ENOMEM;
goto out_free_mdio;
}

if (priv->has_phy_interrupt)
bus->irq[priv->phy_id] = priv->phy_interrupt;
else
bus->irq[priv->phy_id] = PHY_POLL;

ret = mdiobus_register(bus);
if (ret) {
Expand Down
15 changes: 2 additions & 13 deletions drivers/net/ethernet/broadcom/bgmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ static int bgmac_mii_register(struct bgmac *bgmac)
struct mii_bus *mii_bus;
struct phy_device *phy_dev;
char bus_id[MII_BUS_ID_SIZE + 3];
int i, err = 0;
int err = 0;

if (ci->id == BCMA_CHIP_ID_BCM4707 ||
ci->id == BCMA_CHIP_ID_BCM53018)
Expand All @@ -1490,18 +1490,10 @@ static int bgmac_mii_register(struct bgmac *bgmac)
mii_bus->parent = &bgmac->core->dev;
mii_bus->phy_mask = ~(1 << bgmac->phyaddr);

mii_bus->irq = kmalloc_array(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
if (!mii_bus->irq) {
err = -ENOMEM;
goto err_free_bus;
}
for (i = 0; i < PHY_MAX_ADDR; i++)
mii_bus->irq[i] = PHY_POLL;

err = mdiobus_register(mii_bus);
if (err) {
bgmac_err(bgmac, "Registration of mii bus failed\n");
goto err_free_irq;
goto err_free_bus;
}

bgmac->mii_bus = mii_bus;
Expand All @@ -1522,8 +1514,6 @@ static int bgmac_mii_register(struct bgmac *bgmac)

err_unregister_bus:
mdiobus_unregister(mii_bus);
err_free_irq:
kfree(mii_bus->irq);
err_free_bus:
mdiobus_free(mii_bus);
return err;
Expand All @@ -1534,7 +1524,6 @@ static void bgmac_mii_unregister(struct bgmac *bgmac)
struct mii_bus *mii_bus = bgmac->mii_bus;

mdiobus_unregister(mii_bus);
kfree(mii_bus->irq);
mdiobus_free(mii_bus);
}

Expand Down
10 changes: 0 additions & 10 deletions drivers/net/ethernet/broadcom/genet/bcmmii.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,6 @@ int bcmgenet_mii_probe(struct net_device *dev)
*/
if (priv->internal_phy)
priv->mii_bus->irq[phydev->addr] = PHY_IGNORE_INTERRUPT;
else
priv->mii_bus->irq[phydev->addr] = PHY_POLL;

return 0;
}
Expand Down Expand Up @@ -477,12 +475,6 @@ static int bcmgenet_mii_alloc(struct bcmgenet_priv *priv)
snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%d",
priv->pdev->name, priv->pdev->id);

bus->irq = kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
if (!bus->irq) {
mdiobus_free(priv->mii_bus);
return -ENOMEM;
}

return 0;
}

Expand Down Expand Up @@ -648,7 +640,6 @@ int bcmgenet_mii_init(struct net_device *dev)
out:
of_node_put(priv->phy_dn);
mdiobus_unregister(priv->mii_bus);
kfree(priv->mii_bus->irq);
mdiobus_free(priv->mii_bus);
return ret;
}
Expand All @@ -659,6 +650,5 @@ void bcmgenet_mii_exit(struct net_device *dev)

of_node_put(priv->phy_dn);
mdiobus_unregister(priv->mii_bus);
kfree(priv->mii_bus->irq);
mdiobus_free(priv->mii_bus);
}
4 changes: 0 additions & 4 deletions drivers/net/ethernet/broadcom/sb1250-mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ struct sbmac_softc {
struct napi_struct napi;
struct phy_device *phy_dev; /* the associated PHY device */
struct mii_bus *mii_bus; /* the MII bus */
int phy_irq[PHY_MAX_ADDR];
spinlock_t sbm_lock; /* spin lock */
int sbm_devflags; /* current device flags */

Expand Down Expand Up @@ -2250,9 +2249,6 @@ static int sbmac_init(struct platform_device *pldev, long long base)
sc->mii_bus->priv = sc;
sc->mii_bus->read = sbmac_mii_read;
sc->mii_bus->write = sbmac_mii_write;
sc->mii_bus->irq = sc->phy_irq;
for (i = 0; i < PHY_MAX_ADDR; ++i)
sc->mii_bus->irq[i] = SBMAC_PHY_INT;

sc->mii_bus->parent = &pldev->dev;
/*
Expand Down

0 comments on commit e7f4dc3

Please sign in to comment.