diff options
author | Lennert Buytenhek <buytenh@marvell.com> | 2008-10-08 19:29:57 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-10-08 19:29:57 -0400 |
commit | 298cf9beb9679522de995e249eccbd82f7c51999 (patch) | |
tree | cabbc9c696a063982aea9a24d8caa667daa33a1a /drivers/net/tc35815.c | |
parent | 18ee49ddb0d242ed1d0e273038d5e4f6de7379d3 (diff) |
phylib: move to dynamic allocation of struct mii_bus
This patch introduces mdiobus_alloc() and mdiobus_free(), and
makes all mdio bus drivers use these functions to allocate their
struct mii_bus'es dynamically.
Signed-off-by: Lennert Buytenhek <buytenh@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Andy Fleming <afleming@freescale.com>
Diffstat (limited to 'drivers/net/tc35815.c')
-rw-r--r-- | drivers/net/tc35815.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/drivers/net/tc35815.c b/drivers/net/tc35815.c index 1f2b1f2d73ae..4980b12b6219 100644 --- a/drivers/net/tc35815.c +++ b/drivers/net/tc35815.c | |||
@@ -424,7 +424,7 @@ struct tc35815_local { | |||
424 | */ | 424 | */ |
425 | spinlock_t lock; | 425 | spinlock_t lock; |
426 | 426 | ||
427 | struct mii_bus mii_bus; | 427 | struct mii_bus *mii_bus; |
428 | struct phy_device *phy_dev; | 428 | struct phy_device *phy_dev; |
429 | int duplex; | 429 | int duplex; |
430 | int speed; | 430 | int speed; |
@@ -704,13 +704,13 @@ static int tc_mii_probe(struct net_device *dev) | |||
704 | 704 | ||
705 | /* find the first phy */ | 705 | /* find the first phy */ |
706 | for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) { | 706 | for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) { |
707 | if (lp->mii_bus.phy_map[phy_addr]) { | 707 | if (lp->mii_bus->phy_map[phy_addr]) { |
708 | if (phydev) { | 708 | if (phydev) { |
709 | printk(KERN_ERR "%s: multiple PHYs found\n", | 709 | printk(KERN_ERR "%s: multiple PHYs found\n", |
710 | dev->name); | 710 | dev->name); |
711 | return -EINVAL; | 711 | return -EINVAL; |
712 | } | 712 | } |
713 | phydev = lp->mii_bus.phy_map[phy_addr]; | 713 | phydev = lp->mii_bus->phy_map[phy_addr]; |
714 | break; | 714 | break; |
715 | } | 715 | } |
716 | } | 716 | } |
@@ -762,23 +762,29 @@ static int tc_mii_init(struct net_device *dev) | |||
762 | int err; | 762 | int err; |
763 | int i; | 763 | int i; |
764 | 764 | ||
765 | lp->mii_bus.name = "tc35815_mii_bus"; | 765 | lp->mii_bus = mdiobus_alloc(); |
766 | lp->mii_bus.read = tc_mdio_read; | 766 | if (lp->mii_bus == NULL) { |
767 | lp->mii_bus.write = tc_mdio_write; | ||
768 | snprintf(lp->mii_bus.id, MII_BUS_ID_SIZE, "%x", | ||
769 | (lp->pci_dev->bus->number << 8) | lp->pci_dev->devfn); | ||
770 | lp->mii_bus.priv = dev; | ||
771 | lp->mii_bus.parent = &lp->pci_dev->dev; | ||
772 | lp->mii_bus.irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL); | ||
773 | if (!lp->mii_bus.irq) { | ||
774 | err = -ENOMEM; | 767 | err = -ENOMEM; |
775 | goto err_out; | 768 | goto err_out; |
776 | } | 769 | } |
777 | 770 | ||
771 | lp->mii_bus->name = "tc35815_mii_bus"; | ||
772 | lp->mii_bus->read = tc_mdio_read; | ||
773 | lp->mii_bus->write = tc_mdio_write; | ||
774 | snprintf(lp->mii_bus->id, MII_BUS_ID_SIZE, "%x", | ||
775 | (lp->pci_dev->bus->number << 8) | lp->pci_dev->devfn); | ||
776 | lp->mii_bus->priv = dev; | ||
777 | lp->mii_bus->parent = &lp->pci_dev->dev; | ||
778 | lp->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL); | ||
779 | if (!lp->mii_bus->irq) { | ||
780 | err = -ENOMEM; | ||
781 | goto err_out_free_mii_bus; | ||
782 | } | ||
783 | |||
778 | for (i = 0; i < PHY_MAX_ADDR; i++) | 784 | for (i = 0; i < PHY_MAX_ADDR; i++) |
779 | lp->mii_bus.irq[i] = PHY_POLL; | 785 | lp->mii_bus->irq[i] = PHY_POLL; |
780 | 786 | ||
781 | err = mdiobus_register(&lp->mii_bus); | 787 | err = mdiobus_register(lp->mii_bus); |
782 | if (err) | 788 | if (err) |
783 | goto err_out_free_mdio_irq; | 789 | goto err_out_free_mdio_irq; |
784 | err = tc_mii_probe(dev); | 790 | err = tc_mii_probe(dev); |
@@ -787,9 +793,11 @@ static int tc_mii_init(struct net_device *dev) | |||
787 | return 0; | 793 | return 0; |
788 | 794 | ||
789 | err_out_unregister_bus: | 795 | err_out_unregister_bus: |
790 | mdiobus_unregister(&lp->mii_bus); | 796 | mdiobus_unregister(lp->mii_bus); |
791 | err_out_free_mdio_irq: | 797 | err_out_free_mdio_irq: |
792 | kfree(lp->mii_bus.irq); | 798 | kfree(lp->mii_bus->irq); |
799 | err_out_free_mii_bus; | ||
800 | mdiobus_free(lp->mii_bus); | ||
793 | err_out: | 801 | err_out: |
794 | return err; | 802 | return err; |
795 | } | 803 | } |
@@ -961,8 +969,9 @@ static void __devexit tc35815_remove_one(struct pci_dev *pdev) | |||
961 | struct tc35815_local *lp = netdev_priv(dev); | 969 | struct tc35815_local *lp = netdev_priv(dev); |
962 | 970 | ||
963 | phy_disconnect(lp->phy_dev); | 971 | phy_disconnect(lp->phy_dev); |
964 | mdiobus_unregister(&lp->mii_bus); | 972 | mdiobus_unregister(lp->mii_bus); |
965 | kfree(lp->mii_bus.irq); | 973 | kfree(lp->mii_bus->irq); |
974 | mdiobus_free(lp->mii_bus); | ||
966 | unregister_netdev(dev); | 975 | unregister_netdev(dev); |
967 | free_netdev(dev); | 976 | free_netdev(dev); |
968 | pci_set_drvdata(pdev, NULL); | 977 | pci_set_drvdata(pdev, NULL); |