aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennert Buytenhek <buytenh@marvell.com>2008-10-08 19:29:57 -0400
committerDavid S. Miller <davem@davemloft.net>2008-10-08 19:29:57 -0400
commit298cf9beb9679522de995e249eccbd82f7c51999 (patch)
treecabbc9c696a063982aea9a24d8caa667daa33a1a
parent18ee49ddb0d242ed1d0e273038d5e4f6de7379d3 (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>
-rw-r--r--drivers/net/au1000_eth.c43
-rw-r--r--drivers/net/au1000_eth.h2
-rw-r--r--drivers/net/bfin_mac.c31
-rw-r--r--drivers/net/bfin_mac.h2
-rw-r--r--drivers/net/cpmac.c51
-rw-r--r--drivers/net/fec_mpc52xx_phy.c6
-rw-r--r--drivers/net/fs_enet/mii-bitbang.c7
-rw-r--r--drivers/net/fs_enet/mii-fec.c6
-rw-r--r--drivers/net/gianfar_mii.c7
-rw-r--r--drivers/net/macb.c49
-rw-r--r--drivers/net/macb.h2
-rw-r--r--drivers/net/mv643xx_eth.c32
-rw-r--r--drivers/net/phy/fixed.c29
-rw-r--r--drivers/net/phy/mdio-bitbang.c4
-rw-r--r--drivers/net/phy/mdio-ofgpio.c9
-rw-r--r--drivers/net/phy/mdio_bus.c24
-rw-r--r--drivers/net/sb1250-mac.c36
-rw-r--r--drivers/net/sh_eth.c2
-rw-r--r--drivers/net/tc35815.c45
-rw-r--r--drivers/net/tg3.c66
-rw-r--r--drivers/net/tg3.h2
-rw-r--r--drivers/net/ucc_geth_mii.c7
-rw-r--r--include/linux/phy.h2
23 files changed, 279 insertions, 185 deletions
diff --git a/drivers/net/au1000_eth.c b/drivers/net/au1000_eth.c
index 92c16c37ff2..7b92201a7b5 100644
--- a/drivers/net/au1000_eth.c
+++ b/drivers/net/au1000_eth.c
@@ -290,7 +290,7 @@ static int mii_probe (struct net_device *dev)
290 290
291 if(aup->mac_id == 0) { /* get PHY0 */ 291 if(aup->mac_id == 0) { /* get PHY0 */
292# if defined(AU1XXX_PHY0_ADDR) 292# if defined(AU1XXX_PHY0_ADDR)
293 phydev = au_macs[AU1XXX_PHY0_BUSID]->mii_bus.phy_map[AU1XXX_PHY0_ADDR]; 293 phydev = au_macs[AU1XXX_PHY0_BUSID]->mii_bus->phy_map[AU1XXX_PHY0_ADDR];
294# else 294# else
295 printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n", 295 printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n",
296 dev->name); 296 dev->name);
@@ -298,7 +298,7 @@ static int mii_probe (struct net_device *dev)
298# endif /* defined(AU1XXX_PHY0_ADDR) */ 298# endif /* defined(AU1XXX_PHY0_ADDR) */
299 } else if (aup->mac_id == 1) { /* get PHY1 */ 299 } else if (aup->mac_id == 1) { /* get PHY1 */
300# if defined(AU1XXX_PHY1_ADDR) 300# if defined(AU1XXX_PHY1_ADDR)
301 phydev = au_macs[AU1XXX_PHY1_BUSID]->mii_bus.phy_map[AU1XXX_PHY1_ADDR]; 301 phydev = au_macs[AU1XXX_PHY1_BUSID]->mii_bus->phy_map[AU1XXX_PHY1_ADDR];
302# else 302# else
303 printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n", 303 printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n",
304 dev->name); 304 dev->name);
@@ -311,8 +311,8 @@ static int mii_probe (struct net_device *dev)
311 311
312 /* find the first (lowest address) PHY on the current MAC's MII bus */ 312 /* find the first (lowest address) PHY on the current MAC's MII bus */
313 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) 313 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++)
314 if (aup->mii_bus.phy_map[phy_addr]) { 314 if (aup->mii_bus->phy_map[phy_addr]) {
315 phydev = aup->mii_bus.phy_map[phy_addr]; 315 phydev = aup->mii_bus->phy_map[phy_addr];
316# if !defined(AU1XXX_PHY_SEARCH_HIGHEST_ADDR) 316# if !defined(AU1XXX_PHY_SEARCH_HIGHEST_ADDR)
317 break; /* break out with first one found */ 317 break; /* break out with first one found */
318# endif 318# endif
@@ -331,7 +331,7 @@ static int mii_probe (struct net_device *dev)
331 * the MAC0 MII bus */ 331 * the MAC0 MII bus */
332 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) { 332 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
333 struct phy_device *const tmp_phydev = 333 struct phy_device *const tmp_phydev =
334 au_macs[0]->mii_bus.phy_map[phy_addr]; 334 au_macs[0]->mii_bus->phy_map[phy_addr];
335 335
336 if (!tmp_phydev) 336 if (!tmp_phydev)
337 continue; /* no PHY here... */ 337 continue; /* no PHY here... */
@@ -698,28 +698,32 @@ static struct net_device * au1000_probe(int port_num)
698 *aup->enable = 0; 698 *aup->enable = 0;
699 aup->mac_enabled = 0; 699 aup->mac_enabled = 0;
700 700
701 aup->mii_bus.priv = dev; 701 aup->mii_bus = mdiobus_alloc();
702 aup->mii_bus.read = mdiobus_read; 702 if (aup->mii_bus == NULL)
703 aup->mii_bus.write = mdiobus_write; 703 goto err_out;
704 aup->mii_bus.reset = mdiobus_reset; 704
705 aup->mii_bus.name = "au1000_eth_mii"; 705 aup->mii_bus->priv = dev;
706 snprintf(aup->mii_bus.id, MII_BUS_ID_SIZE, "%x", aup->mac_id); 706 aup->mii_bus->read = mdiobus_read;
707 aup->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); 707 aup->mii_bus->write = mdiobus_write;
708 aup->mii_bus->reset = mdiobus_reset;
709 aup->mii_bus->name = "au1000_eth_mii";
710 snprintf(aup->mii_bus->id, MII_BUS_ID_SIZE, "%x", aup->mac_id);
711 aup->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
708 for(i = 0; i < PHY_MAX_ADDR; ++i) 712 for(i = 0; i < PHY_MAX_ADDR; ++i)
709 aup->mii_bus.irq[i] = PHY_POLL; 713 aup->mii_bus->irq[i] = PHY_POLL;
710 714
711 /* if known, set corresponding PHY IRQs */ 715 /* if known, set corresponding PHY IRQs */
712#if defined(AU1XXX_PHY_STATIC_CONFIG) 716#if defined(AU1XXX_PHY_STATIC_CONFIG)
713# if defined(AU1XXX_PHY0_IRQ) 717# if defined(AU1XXX_PHY0_IRQ)
714 if (AU1XXX_PHY0_BUSID == aup->mac_id) 718 if (AU1XXX_PHY0_BUSID == aup->mac_id)
715 aup->mii_bus.irq[AU1XXX_PHY0_ADDR] = AU1XXX_PHY0_IRQ; 719 aup->mii_bus->irq[AU1XXX_PHY0_ADDR] = AU1XXX_PHY0_IRQ;
716# endif 720# endif
717# if defined(AU1XXX_PHY1_IRQ) 721# if defined(AU1XXX_PHY1_IRQ)
718 if (AU1XXX_PHY1_BUSID == aup->mac_id) 722 if (AU1XXX_PHY1_BUSID == aup->mac_id)
719 aup->mii_bus.irq[AU1XXX_PHY1_ADDR] = AU1XXX_PHY1_IRQ; 723 aup->mii_bus->irq[AU1XXX_PHY1_ADDR] = AU1XXX_PHY1_IRQ;
720# endif 724# endif
721#endif 725#endif
722 mdiobus_register(&aup->mii_bus); 726 mdiobus_register(aup->mii_bus);
723 727
724 if (mii_probe(dev) != 0) { 728 if (mii_probe(dev) != 0) {
725 goto err_out; 729 goto err_out;
@@ -775,6 +779,11 @@ static struct net_device * au1000_probe(int port_num)
775 return dev; 779 return dev;
776 780
777err_out: 781err_out:
782 if (aup->mii_bus != NULL) {
783 mdiobus_unregister(aup->mii_bus);
784 mdiobus_free(aup->mii_bus);
785 }
786
778 /* here we should have a valid dev plus aup-> register addresses 787 /* here we should have a valid dev plus aup-> register addresses
779 * so we can reset the mac properly.*/ 788 * so we can reset the mac properly.*/
780 reset_mac(dev); 789 reset_mac(dev);
@@ -1005,6 +1014,8 @@ static void __exit au1000_cleanup_module(void)
1005 if (dev) { 1014 if (dev) {
1006 aup = (struct au1000_private *) dev->priv; 1015 aup = (struct au1000_private *) dev->priv;
1007 unregister_netdev(dev); 1016 unregister_netdev(dev);
1017 mdiobus_unregister(aup->mii_bus);
1018 mdiobus_free(aup->mii_bus);
1008 for (j = 0; j < NUM_RX_DMA; j++) 1019 for (j = 0; j < NUM_RX_DMA; j++)
1009 if (aup->rx_db_inuse[j]) 1020 if (aup->rx_db_inuse[j])
1010 ReleaseDB(aup, aup->rx_db_inuse[j]); 1021 ReleaseDB(aup, aup->rx_db_inuse[j]);
diff --git a/drivers/net/au1000_eth.h b/drivers/net/au1000_eth.h
index f3baeaa1285..824ecd5ff3a 100644
--- a/drivers/net/au1000_eth.h
+++ b/drivers/net/au1000_eth.h
@@ -106,7 +106,7 @@ struct au1000_private {
106 int old_duplex; 106 int old_duplex;
107 107
108 struct phy_device *phy_dev; 108 struct phy_device *phy_dev;
109 struct mii_bus mii_bus; 109 struct mii_bus *mii_bus;
110 110
111 /* These variables are just for quick access to certain regs addresses. */ 111 /* These variables are just for quick access to certain regs addresses. */
112 volatile mac_reg_t *mac; /* mac registers */ 112 volatile mac_reg_t *mac; /* mac registers */
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c
index df896e23e2c..a0d41c5d97d 100644
--- a/drivers/net/bfin_mac.c
+++ b/drivers/net/bfin_mac.c
@@ -398,7 +398,7 @@ static int mii_probe(struct net_device *dev)
398 398
399 /* search for connect PHY device */ 399 /* search for connect PHY device */
400 for (i = 0; i < PHY_MAX_ADDR; i++) { 400 for (i = 0; i < PHY_MAX_ADDR; i++) {
401 struct phy_device *const tmp_phydev = lp->mii_bus.phy_map[i]; 401 struct phy_device *const tmp_phydev = lp->mii_bus->phy_map[i];
402 402
403 if (!tmp_phydev) 403 if (!tmp_phydev)
404 continue; /* no PHY here... */ 404 continue; /* no PHY here... */
@@ -1058,17 +1058,21 @@ static int __devinit bfin_mac_probe(struct platform_device *pdev)
1058 setup_mac_addr(ndev->dev_addr); 1058 setup_mac_addr(ndev->dev_addr);
1059 1059
1060 /* MDIO bus initial */ 1060 /* MDIO bus initial */
1061 lp->mii_bus.priv = ndev; 1061 lp->mii_bus = mdiobus_alloc();
1062 lp->mii_bus.read = mdiobus_read; 1062 if (lp->mii_bus == NULL)
1063 lp->mii_bus.write = mdiobus_write; 1063 goto out_err_mdiobus_alloc;
1064 lp->mii_bus.reset = mdiobus_reset; 1064
1065 lp->mii_bus.name = "bfin_mac_mdio"; 1065 lp->mii_bus->priv = ndev;
1066 snprintf(lp->mii_bus.id, MII_BUS_ID_SIZE, "0"); 1066 lp->mii_bus->read = mdiobus_read;
1067 lp->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); 1067 lp->mii_bus->write = mdiobus_write;
1068 lp->mii_bus->reset = mdiobus_reset;
1069 lp->mii_bus->name = "bfin_mac_mdio";
1070 snprintf(lp->mii_bus->id, MII_BUS_ID_SIZE, "0");
1071 lp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
1068 for (i = 0; i < PHY_MAX_ADDR; ++i) 1072 for (i = 0; i < PHY_MAX_ADDR; ++i)
1069 lp->mii_bus.irq[i] = PHY_POLL; 1073 lp->mii_bus->irq[i] = PHY_POLL;
1070 1074
1071 rc = mdiobus_register(&lp->mii_bus); 1075 rc = mdiobus_register(lp->mii_bus);
1072 if (rc) { 1076 if (rc) {
1073 dev_err(&pdev->dev, "Cannot register MDIO bus!\n"); 1077 dev_err(&pdev->dev, "Cannot register MDIO bus!\n");
1074 goto out_err_mdiobus_register; 1078 goto out_err_mdiobus_register;
@@ -1121,8 +1125,10 @@ out_err_reg_ndev:
1121 free_irq(IRQ_MAC_RX, ndev); 1125 free_irq(IRQ_MAC_RX, ndev);
1122out_err_request_irq: 1126out_err_request_irq:
1123out_err_mii_probe: 1127out_err_mii_probe:
1124 mdiobus_unregister(&lp->mii_bus); 1128 mdiobus_unregister(lp->mii_bus);
1125out_err_mdiobus_register: 1129out_err_mdiobus_register:
1130 mdiobus_free(lp->mii_bus);
1131out_err_mdiobus_alloc:
1126 peripheral_free_list(pin_req); 1132 peripheral_free_list(pin_req);
1127out_err_setup_pin_mux: 1133out_err_setup_pin_mux:
1128out_err_probe_mac: 1134out_err_probe_mac:
@@ -1139,7 +1145,8 @@ static int __devexit bfin_mac_remove(struct platform_device *pdev)
1139 1145
1140 platform_set_drvdata(pdev, NULL); 1146 platform_set_drvdata(pdev, NULL);
1141 1147
1142 mdiobus_unregister(&lp->mii_bus); 1148 mdiobus_unregister(lp->mii_bus);
1149 mdiobus_free(lp->mii_bus);
1143 1150
1144 unregister_netdev(ndev); 1151 unregister_netdev(ndev);
1145 1152
diff --git a/drivers/net/bfin_mac.h b/drivers/net/bfin_mac.h
index beff51064ff..052b5dce3e3 100644
--- a/drivers/net/bfin_mac.h
+++ b/drivers/net/bfin_mac.h
@@ -66,7 +66,7 @@ struct bfin_mac_local {
66 int old_duplex; 66 int old_duplex;
67 67
68 struct phy_device *phydev; 68 struct phy_device *phydev;
69 struct mii_bus mii_bus; 69 struct mii_bus *mii_bus;
70}; 70};
71 71
72extern void bfin_get_ether_addr(char *addr); 72extern void bfin_get_ether_addr(char *addr);
diff --git a/drivers/net/cpmac.c b/drivers/net/cpmac.c
index ec6b0af3d46..017a5361b98 100644
--- a/drivers/net/cpmac.c
+++ b/drivers/net/cpmac.c
@@ -302,13 +302,7 @@ static int cpmac_mdio_reset(struct mii_bus *bus)
302 302
303static int mii_irqs[PHY_MAX_ADDR] = { PHY_POLL, }; 303static int mii_irqs[PHY_MAX_ADDR] = { PHY_POLL, };
304 304
305static struct mii_bus cpmac_mii = { 305static struct mii_bus *cpmac_mii;
306 .name = "cpmac-mii",
307 .read = cpmac_mdio_read,
308 .write = cpmac_mdio_write,
309 .reset = cpmac_mdio_reset,
310 .irq = mii_irqs,
311};
312 306
313static int cpmac_config(struct net_device *dev, struct ifmap *map) 307static int cpmac_config(struct net_device *dev, struct ifmap *map)
314{ 308{
@@ -1116,7 +1110,7 @@ static int __devinit cpmac_probe(struct platform_device *pdev)
1116 for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) { 1110 for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) {
1117 if (!(pdata->phy_mask & (1 << phy_id))) 1111 if (!(pdata->phy_mask & (1 << phy_id)))
1118 continue; 1112 continue;
1119 if (!cpmac_mii.phy_map[phy_id]) 1113 if (!cpmac_mii->phy_map[phy_id])
1120 continue; 1114 continue;
1121 break; 1115 break;
1122 } 1116 }
@@ -1168,7 +1162,7 @@ static int __devinit cpmac_probe(struct platform_device *pdev)
1168 priv->msg_enable = netif_msg_init(debug_level, 0xff); 1162 priv->msg_enable = netif_msg_init(debug_level, 0xff);
1169 memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr)); 1163 memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
1170 1164
1171 priv->phy = phy_connect(dev, cpmac_mii.phy_map[phy_id]->dev.bus_id, 1165 priv->phy = phy_connect(dev, cpmac_mii->phy_map[phy_id]->dev.bus_id,
1172 &cpmac_adjust_link, 0, PHY_INTERFACE_MODE_MII); 1166 &cpmac_adjust_link, 0, PHY_INTERFACE_MODE_MII);
1173 if (IS_ERR(priv->phy)) { 1167 if (IS_ERR(priv->phy)) {
1174 if (netif_msg_drv(priv)) 1168 if (netif_msg_drv(priv))
@@ -1216,11 +1210,22 @@ int __devinit cpmac_init(void)
1216 u32 mask; 1210 u32 mask;
1217 int i, res; 1211 int i, res;
1218 1212
1219 cpmac_mii.priv = ioremap(AR7_REGS_MDIO, 256); 1213 cpmac_mii = mdiobus_alloc();
1214 if (cpmac_mii == NULL)
1215 return -ENOMEM;
1216
1217 cpmac_mii->name = "cpmac-mii";
1218 cpmac_mii->read = cpmac_mdio_read;
1219 cpmac_mii->write = cpmac_mdio_write;
1220 cpmac_mii->reset = cpmac_mdio_reset;
1221 cpmac_mii->irq = mii_irqs;
1222
1223 cpmac_mii->priv = ioremap(AR7_REGS_MDIO, 256);
1220 1224
1221 if (!cpmac_mii.priv) { 1225 if (!cpmac_mii->priv) {
1222 printk(KERN_ERR "Can't ioremap mdio registers\n"); 1226 printk(KERN_ERR "Can't ioremap mdio registers\n");
1223 return -ENXIO; 1227 res = -ENXIO;
1228 goto fail_alloc;
1224 } 1229 }
1225 1230
1226#warning FIXME: unhardcode gpio&reset bits 1231#warning FIXME: unhardcode gpio&reset bits
@@ -1230,10 +1235,10 @@ int __devinit cpmac_init(void)
1230 ar7_device_reset(AR7_RESET_BIT_CPMAC_HI); 1235 ar7_device_reset(AR7_RESET_BIT_CPMAC_HI);
1231 ar7_device_reset(AR7_RESET_BIT_EPHY); 1236 ar7_device_reset(AR7_RESET_BIT_EPHY);
1232 1237
1233 cpmac_mii.reset(&cpmac_mii); 1238 cpmac_mii->reset(cpmac_mii);
1234 1239
1235 for (i = 0; i < 300000; i++) 1240 for (i = 0; i < 300000; i++)
1236 if ((mask = cpmac_read(cpmac_mii.priv, CPMAC_MDIO_ALIVE))) 1241 if ((mask = cpmac_read(cpmac_mii->priv, CPMAC_MDIO_ALIVE)))
1237 break; 1242 break;
1238 else 1243 else
1239 cpu_relax(); 1244 cpu_relax();
@@ -1244,10 +1249,10 @@ int __devinit cpmac_init(void)
1244 mask = 0; 1249 mask = 0;
1245 } 1250 }
1246 1251
1247 cpmac_mii.phy_mask = ~(mask | 0x80000000); 1252 cpmac_mii->phy_mask = ~(mask | 0x80000000);
1248 snprintf(cpmac_mii.id, MII_BUS_ID_SIZE, "0"); 1253 snprintf(cpmac_mii->id, MII_BUS_ID_SIZE, "0");
1249 1254
1250 res = mdiobus_register(&cpmac_mii); 1255 res = mdiobus_register(cpmac_mii);
1251 if (res) 1256 if (res)
1252 goto fail_mii; 1257 goto fail_mii;
1253 1258
@@ -1258,10 +1263,13 @@ int __devinit cpmac_init(void)
1258 return 0; 1263 return 0;
1259 1264
1260fail_cpmac: 1265fail_cpmac:
1261 mdiobus_unregister(&cpmac_mii); 1266 mdiobus_unregister(cpmac_mii);
1262 1267
1263fail_mii: 1268fail_mii:
1264 iounmap(cpmac_mii.priv); 1269 iounmap(cpmac_mii->priv);
1270
1271fail_alloc:
1272 mdiobus_free(cpmac_mii);
1265 1273
1266 return res; 1274 return res;
1267} 1275}
@@ -1269,8 +1277,9 @@ fail_mii:
1269void __devexit cpmac_exit(void) 1277void __devexit cpmac_exit(void)
1270{ 1278{
1271 platform_driver_unregister(&cpmac_driver); 1279 platform_driver_unregister(&cpmac_driver);
1272 mdiobus_unregister(&cpmac_mii); 1280 mdiobus_unregister(cpmac_mii);
1273 iounmap(cpmac_mii.priv); 1281 mdiobus_free(cpmac_mii);
1282 iounmap(cpmac_mii->priv);
1274} 1283}
1275 1284
1276module_init(cpmac_init); 1285module_init(cpmac_init);
diff --git a/drivers/net/fec_mpc52xx_phy.c b/drivers/net/fec_mpc52xx_phy.c
index 2a523308c77..08e18bcb970 100644
--- a/drivers/net/fec_mpc52xx_phy.c
+++ b/drivers/net/fec_mpc52xx_phy.c
@@ -83,7 +83,7 @@ static int mpc52xx_fec_mdio_probe(struct of_device *of, const struct of_device_i
83 int err; 83 int err;
84 int i; 84 int i;
85 85
86 bus = kzalloc(sizeof(*bus), GFP_KERNEL); 86 bus = mdiobus_alloc();
87 if (bus == NULL) 87 if (bus == NULL)
88 return -ENOMEM; 88 return -ENOMEM;
89 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 89 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
@@ -150,7 +150,7 @@ static int mpc52xx_fec_mdio_probe(struct of_device *of, const struct of_device_i
150 irq_dispose_mapping(bus->irq[i]); 150 irq_dispose_mapping(bus->irq[i]);
151 kfree(bus->irq); 151 kfree(bus->irq);
152 kfree(priv); 152 kfree(priv);
153 kfree(bus); 153 mdiobus_free(bus);
154 154
155 return err; 155 return err;
156} 156}
@@ -171,7 +171,7 @@ static int mpc52xx_fec_mdio_remove(struct of_device *of)
171 irq_dispose_mapping(bus->irq[i]); 171 irq_dispose_mapping(bus->irq[i]);
172 kfree(priv); 172 kfree(priv);
173 kfree(bus->irq); 173 kfree(bus->irq);
174 kfree(bus); 174 mdiobus_free(bus);
175 175
176 return 0; 176 return 0;
177} 177}
diff --git a/drivers/net/fs_enet/mii-bitbang.c b/drivers/net/fs_enet/mii-bitbang.c
index 2774252c235..49b6645d7e0 100644
--- a/drivers/net/fs_enet/mii-bitbang.c
+++ b/drivers/net/fs_enet/mii-bitbang.c
@@ -218,9 +218,9 @@ out_free_irqs:
218out_unmap_regs: 218out_unmap_regs:
219 iounmap(bitbang->dir); 219 iounmap(bitbang->dir);
220out_free_bus: 220out_free_bus:
221 kfree(new_bus);
222out_free_priv:
223 free_mdio_bitbang(new_bus); 221 free_mdio_bitbang(new_bus);
222out_free_priv:
223 kfree(bitbang);
224out: 224out:
225 return ret; 225 return ret;
226} 226}
@@ -231,12 +231,11 @@ static int fs_enet_mdio_remove(struct of_device *ofdev)
231 struct bb_info *bitbang = bus->priv; 231 struct bb_info *bitbang = bus->priv;
232 232
233 mdiobus_unregister(bus); 233 mdiobus_unregister(bus);
234 free_mdio_bitbang(bus);
235 dev_set_drvdata(&ofdev->dev, NULL); 234 dev_set_drvdata(&ofdev->dev, NULL);
236 kfree(bus->irq); 235 kfree(bus->irq);
236 free_mdio_bitbang(bus);
237 iounmap(bitbang->dir); 237 iounmap(bitbang->dir);
238 kfree(bitbang); 238 kfree(bitbang);
239 kfree(bus);
240 239
241 return 0; 240 return 0;
242} 241}
diff --git a/drivers/net/fs_enet/mii-fec.c b/drivers/net/fs_enet/mii-fec.c
index 4d89a22317a..28077cc1b94 100644
--- a/drivers/net/fs_enet/mii-fec.c
+++ b/drivers/net/fs_enet/mii-fec.c
@@ -128,7 +128,7 @@ static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
128 struct fec_info *fec; 128 struct fec_info *fec;
129 int ret = -ENOMEM, i; 129 int ret = -ENOMEM, i;
130 130
131 new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL); 131 new_bus = mdiobus_alloc();
132 if (!new_bus) 132 if (!new_bus)
133 goto out; 133 goto out;
134 134
@@ -190,7 +190,7 @@ out_res:
190out_fec: 190out_fec:
191 kfree(fec); 191 kfree(fec);
192out_mii: 192out_mii:
193 kfree(new_bus); 193 mdiobus_free(new_bus);
194out: 194out:
195 return ret; 195 return ret;
196} 196}
@@ -205,7 +205,7 @@ static int fs_enet_mdio_remove(struct of_device *ofdev)
205 kfree(bus->irq); 205 kfree(bus->irq);
206 iounmap(fec->fecp); 206 iounmap(fec->fecp);
207 kfree(fec); 207 kfree(fec);
208 kfree(bus); 208 mdiobus_free(bus);
209 209
210 return 0; 210 return 0;
211} 211}
diff --git a/drivers/net/gianfar_mii.c b/drivers/net/gianfar_mii.c
index 38895b0e376..bf73eea9801 100644
--- a/drivers/net/gianfar_mii.c
+++ b/drivers/net/gianfar_mii.c
@@ -164,8 +164,7 @@ static int gfar_mdio_probe(struct device *dev)
164 if (NULL == dev) 164 if (NULL == dev)
165 return -EINVAL; 165 return -EINVAL;
166 166
167 new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL); 167 new_bus = mdiobus_alloc();
168
169 if (NULL == new_bus) 168 if (NULL == new_bus)
170 return -ENOMEM; 169 return -ENOMEM;
171 170
@@ -242,7 +241,7 @@ static int gfar_mdio_probe(struct device *dev)
242bus_register_fail: 241bus_register_fail:
243 iounmap(regs); 242 iounmap(regs);
244reg_map_fail: 243reg_map_fail:
245 kfree(new_bus); 244 mdiobus_free(new_bus);
246 245
247 return err; 246 return err;
248} 247}
@@ -258,7 +257,7 @@ static int gfar_mdio_remove(struct device *dev)
258 257
259 iounmap((void __iomem *)bus->priv); 258 iounmap((void __iomem *)bus->priv);
260 bus->priv = NULL; 259 bus->priv = NULL;
261 kfree(bus); 260 mdiobus_free(bus);
262 261
263 return 0; 262 return 0;
264} 263}
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index 045361fe3d6..01f7a31bac7 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -195,8 +195,8 @@ static int macb_mii_probe(struct net_device *dev)
195 195
196 /* find the first phy */ 196 /* find the first phy */
197 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) { 197 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
198 if (bp->mii_bus.phy_map[phy_addr]) { 198 if (bp->mii_bus->phy_map[phy_addr]) {
199 phydev = bp->mii_bus.phy_map[phy_addr]; 199 phydev = bp->mii_bus->phy_map[phy_addr];
200 break; 200 break;
201 } 201 }
202 } 202 }
@@ -244,30 +244,36 @@ static int macb_mii_init(struct macb *bp)
244 /* Enable managment port */ 244 /* Enable managment port */
245 macb_writel(bp, NCR, MACB_BIT(MPE)); 245 macb_writel(bp, NCR, MACB_BIT(MPE));
246 246
247 bp->mii_bus.name = "MACB_mii_bus"; 247 bp->mii_bus = mdiobus_alloc();
248 bp->mii_bus.read = &macb_mdio_read; 248 if (bp->mii_bus == NULL) {
249 bp->mii_bus.write = &macb_mdio_write; 249 err = -ENOMEM;
250 bp->mii_bus.reset = &macb_mdio_reset; 250 goto err_out;
251 snprintf(bp->mii_bus.id, MII_BUS_ID_SIZE, "%x", bp->pdev->id); 251 }
252 bp->mii_bus.priv = bp; 252
253 bp->mii_bus.parent = &bp->dev->dev; 253 bp->mii_bus->name = "MACB_mii_bus";
254 bp->mii_bus->read = &macb_mdio_read;
255 bp->mii_bus->write = &macb_mdio_write;
256 bp->mii_bus->reset = &macb_mdio_reset;
257 snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%x", bp->pdev->id);
258 bp->mii_bus->priv = bp;
259 bp->mii_bus->parent = &bp->dev->dev;
254 pdata = bp->pdev->dev.platform_data; 260 pdata = bp->pdev->dev.platform_data;
255 261
256 if (pdata) 262 if (pdata)
257 bp->mii_bus.phy_mask = pdata->phy_mask; 263 bp->mii_bus->phy_mask = pdata->phy_mask;
258 264
259 bp->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); 265 bp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
260 if (!bp->mii_bus.irq) { 266 if (!bp->mii_bus->irq) {
261 err = -ENOMEM; 267 err = -ENOMEM;
262 goto err_out; 268 goto err_out_free_mdiobus;
263 } 269 }
264 270
265 for (i = 0; i < PHY_MAX_ADDR; i++) 271 for (i = 0; i < PHY_MAX_ADDR; i++)
266 bp->mii_bus.irq[i] = PHY_POLL; 272 bp->mii_bus->irq[i] = PHY_POLL;
267 273
268 platform_set_drvdata(bp->dev, &bp->mii_bus); 274 platform_set_drvdata(bp->dev, bp->mii_bus);
269 275
270 if (mdiobus_register(&bp->mii_bus)) 276 if (mdiobus_register(bp->mii_bus))
271 goto err_out_free_mdio_irq; 277 goto err_out_free_mdio_irq;
272 278
273 if (macb_mii_probe(bp->dev) != 0) { 279 if (macb_mii_probe(bp->dev) != 0) {
@@ -277,9 +283,11 @@ static int macb_mii_init(struct macb *bp)
277 return 0; 283 return 0;
278 284
279err_out_unregister_bus: 285err_out_unregister_bus:
280 mdiobus_unregister(&bp->mii_bus); 286 mdiobus_unregister(bp->mii_bus);
281err_out_free_mdio_irq: 287err_out_free_mdio_irq:
282 kfree(bp->mii_bus.irq); 288 kfree(bp->mii_bus->irq);
289err_out_free_mdiobus:
290 mdiobus_free(bp->mii_bus);
283err_out: 291err_out:
284 return err; 292 return err;
285} 293}
@@ -1261,8 +1269,9 @@ static int __exit macb_remove(struct platform_device *pdev)
1261 bp = netdev_priv(dev); 1269 bp = netdev_priv(dev);
1262 if (bp->phy_dev) 1270 if (bp->phy_dev)
1263 phy_disconnect(bp->phy_dev); 1271 phy_disconnect(bp->phy_dev);
1264 mdiobus_unregister(&bp->mii_bus); 1272 mdiobus_unregister(bp->mii_bus);
1265 kfree(bp->mii_bus.irq); 1273 kfree(bp->mii_bus->irq);
1274 mdiobus_free(bp->mii_bus);
1266 unregister_netdev(dev); 1275 unregister_netdev(dev);
1267 free_irq(dev->irq, dev); 1276 free_irq(dev->irq, dev);
1268 iounmap(bp->regs); 1277 iounmap(bp->regs);
diff --git a/drivers/net/macb.h b/drivers/net/macb.h
index 57b85acf0d1..d3212f6db70 100644
--- a/drivers/net/macb.h
+++ b/drivers/net/macb.h
@@ -384,7 +384,7 @@ struct macb {
384 384
385 unsigned int rx_pending, tx_pending; 385 unsigned int rx_pending, tx_pending;
386 386
387 struct mii_bus mii_bus; 387 struct mii_bus *mii_bus;
388 struct phy_device *phy_dev; 388 struct phy_device *phy_dev;
389 unsigned int link; 389 unsigned int link;
390 unsigned int speed; 390 unsigned int speed;
diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index 63400815448..d25a3025113 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -250,7 +250,7 @@ struct mv643xx_eth_shared_private {
250 /* 250 /*
251 * Provides access to local SMI interface. 251 * Provides access to local SMI interface.
252 */ 252 */
253 struct mii_bus smi_bus; 253 struct mii_bus *smi_bus;
254 254
255 /* 255 /*
256 * If we have access to the error interrupt pin (which is 256 * If we have access to the error interrupt pin (which is
@@ -2363,15 +2363,19 @@ static int mv643xx_eth_shared_probe(struct platform_device *pdev)
2363 * Set up and register SMI bus. 2363 * Set up and register SMI bus.
2364 */ 2364 */
2365 if (pd == NULL || pd->shared_smi == NULL) { 2365 if (pd == NULL || pd->shared_smi == NULL) {
2366 msp->smi_bus.priv = msp; 2366 msp->smi_bus = mdiobus_alloc();
2367 msp->smi_bus.name = "mv643xx_eth smi"; 2367 if (msp->smi_bus == NULL)
2368 msp->smi_bus.read = smi_bus_read;
2369 msp->smi_bus.write = smi_bus_write,
2370 snprintf(msp->smi_bus.id, MII_BUS_ID_SIZE, "%d", pdev->id);
2371 msp->smi_bus.parent = &pdev->dev;
2372 msp->smi_bus.phy_mask = 0xffffffff;
2373 if (mdiobus_register(&msp->smi_bus) < 0)
2374 goto out_unmap; 2368 goto out_unmap;
2369
2370 msp->smi_bus->priv = msp;
2371 msp->smi_bus->name = "mv643xx_eth smi";
2372 msp->smi_bus->read = smi_bus_read;
2373 msp->smi_bus->write = smi_bus_write,
2374 snprintf(msp->smi_bus->id, MII_BUS_ID_SIZE, "%d", pdev->id);
2375 msp->smi_bus->parent = &pdev->dev;
2376 msp->smi_bus->phy_mask = 0xffffffff;
2377 if (mdiobus_register(msp->smi_bus) < 0)
2378 goto out_free_mii_bus;
2375 msp->smi = msp; 2379 msp->smi = msp;
2376 } else { 2380 } else {
2377 msp->smi = platform_get_drvdata(pd->shared_smi); 2381 msp->smi = platform_get_drvdata(pd->shared_smi);
@@ -2411,6 +2415,8 @@ static int mv643xx_eth_shared_probe(struct platform_device *pdev)
2411 2415
2412 return 0; 2416 return 0;
2413 2417
2418out_free_mii_bus:
2419 mdiobus_free(msp->smi_bus);
2414out_unmap: 2420out_unmap:
2415 iounmap(msp->base); 2421 iounmap(msp->base);
2416out_free: 2422out_free:
@@ -2424,8 +2430,10 @@ static int mv643xx_eth_shared_remove(struct platform_device *pdev)
2424 struct mv643xx_eth_shared_private *msp = platform_get_drvdata(pdev); 2430 struct mv643xx_eth_shared_private *msp = platform_get_drvdata(pdev);
2425 struct mv643xx_eth_shared_platform_data *pd = pdev->dev.platform_data; 2431 struct mv643xx_eth_shared_platform_data *pd = pdev->dev.platform_data;
2426 2432
2427 if (pd == NULL || pd->shared_smi == NULL) 2433 if (pd == NULL || pd->shared_smi == NULL) {
2428 mdiobus_unregister(&msp->smi_bus); 2434 mdiobus_free(msp->smi_bus);
2435 mdiobus_unregister(msp->smi_bus);
2436 }
2429 if (msp->err_interrupt != NO_IRQ) 2437 if (msp->err_interrupt != NO_IRQ)
2430 free_irq(msp->err_interrupt, msp); 2438 free_irq(msp->err_interrupt, msp);
2431 iounmap(msp->base); 2439 iounmap(msp->base);
@@ -2493,7 +2501,7 @@ static void set_params(struct mv643xx_eth_private *mp,
2493static struct phy_device *phy_scan(struct mv643xx_eth_private *mp, 2501static struct phy_device *phy_scan(struct mv643xx_eth_private *mp,
2494 int phy_addr) 2502 int phy_addr)
2495{ 2503{
2496 struct mii_bus *bus = &mp->shared->smi->smi_bus; 2504 struct mii_bus *bus = mp->shared->smi->smi_bus;
2497 struct phy_device *phydev; 2505 struct phy_device *phydev;
2498 int start; 2506 int start;
2499 int num; 2507 int num;
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c
index 1cec8967a08..b5e13f8d5e3 100644
--- a/drivers/net/phy/fixed.c
+++ b/drivers/net/phy/fixed.c
@@ -24,7 +24,7 @@
24 24
25struct fixed_mdio_bus { 25struct fixed_mdio_bus {
26 int irqs[PHY_MAX_ADDR]; 26 int irqs[PHY_MAX_ADDR];
27 struct mii_bus mii_bus; 27 struct mii_bus *mii_bus;
28 struct list_head phys; 28 struct list_head phys;
29}; 29};
30 30
@@ -213,19 +213,27 @@ static int __init fixed_mdio_bus_init(void)
213 goto err_pdev; 213 goto err_pdev;
214 } 214 }
215 215
216 snprintf(fmb->mii_bus.id, MII_BUS_ID_SIZE, "0"); 216 fmb->mii_bus = mdiobus_alloc();
217 fmb->mii_bus.name = "Fixed MDIO Bus"; 217 if (fmb->mii_bus == NULL) {
218 fmb->mii_bus.parent = &pdev->dev; 218 ret = -ENOMEM;
219 fmb->mii_bus.read = &fixed_mdio_read; 219 goto err_mdiobus_reg;
220 fmb->mii_bus.write = &fixed_mdio_write; 220 }
221 fmb->mii_bus.irq = fmb->irqs;
222 221
223 ret = mdiobus_register(&fmb->mii_bus); 222 snprintf(fmb->mii_bus->id, MII_BUS_ID_SIZE, "0");
223 fmb->mii_bus->name = "Fixed MDIO Bus";
224 fmb->mii_bus->parent = &pdev->dev;
225 fmb->mii_bus->read = &fixed_mdio_read;
226 fmb->mii_bus->write = &fixed_mdio_write;
227 fmb->mii_bus->irq = fmb->irqs;
228
229 ret = mdiobus_register(fmb->mii_bus);
224 if (ret) 230 if (ret)
225 goto err_mdiobus_reg; 231 goto err_mdiobus_alloc;
226 232
227 return 0; 233 return 0;
228 234
235err_mdiobus_alloc:
236 mdiobus_free(fmb->mii_bus);
229err_mdiobus_reg: 237err_mdiobus_reg:
230 platform_device_unregister(pdev); 238 platform_device_unregister(pdev);
231err_pdev: 239err_pdev:
@@ -238,7 +246,8 @@ static void __exit fixed_mdio_bus_exit(void)
238 struct fixed_mdio_bus *fmb = &platform_fmb; 246 struct fixed_mdio_bus *fmb = &platform_fmb;
239 struct fixed_phy *fp, *tmp; 247 struct fixed_phy *fp, *tmp;
240 248
241 mdiobus_unregister(&fmb->mii_bus); 249 mdiobus_unregister(fmb->mii_bus);
250 mdiobus_free(fmb->mii_bus);
242 platform_device_unregister(pdev); 251 platform_device_unregister(pdev);
243 252
244 list_for_each_entry_safe(fp, tmp, &fmb->phys, node) { 253 list_for_each_entry_safe(fp, tmp, &fmb->phys, node) {
diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
index c01b78013dd..2576055b350 100644
--- a/drivers/net/phy/mdio-bitbang.c
+++ b/drivers/net/phy/mdio-bitbang.c
@@ -165,7 +165,7 @@ struct mii_bus *alloc_mdio_bitbang(struct mdiobb_ctrl *ctrl)
165{ 165{
166 struct mii_bus *bus; 166 struct mii_bus *bus;
167 167
168 bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL); 168 bus = mdiobus_alloc();
169 if (!bus) 169 if (!bus)
170 return NULL; 170 return NULL;
171 171
@@ -184,7 +184,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
184 struct mdiobb_ctrl *ctrl = bus->priv; 184 struct mdiobb_ctrl *ctrl = bus->priv;
185 185
186 module_put(ctrl->ops->owner); 186 module_put(ctrl->ops->owner);
187 kfree(bus); 187 mdiobus_free(bus);
188} 188}
189EXPORT_SYMBOL(free_mdio_bitbang); 189EXPORT_SYMBOL(free_mdio_bitbang);
190 190
diff --git a/drivers/net/phy/mdio-ofgpio.c b/drivers/net/phy/mdio-ofgpio.c
index 27bd4539d08..2ff97754e57 100644
--- a/drivers/net/phy/mdio-ofgpio.c
+++ b/drivers/net/phy/mdio-ofgpio.c
@@ -122,7 +122,7 @@ static int __devinit mdio_ofgpio_probe(struct of_device *ofdev,
122 122
123 new_bus = alloc_mdio_bitbang(&bitbang->ctrl); 123 new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
124 if (!new_bus) 124 if (!new_bus)
125 goto out_free_priv; 125 goto out_free_bitbang;
126 126
127 new_bus->name = "GPIO Bitbanged MII", 127 new_bus->name = "GPIO Bitbanged MII",
128 128
@@ -155,9 +155,9 @@ out_free_irqs:
155 dev_set_drvdata(&ofdev->dev, NULL); 155 dev_set_drvdata(&ofdev->dev, NULL);
156 kfree(new_bus->irq); 156 kfree(new_bus->irq);
157out_free_bus: 157out_free_bus:
158 kfree(new_bus);
159out_free_priv:
160 free_mdio_bitbang(new_bus); 158 free_mdio_bitbang(new_bus);
159out_free_bitbang:
160 kfree(bitbang);
161out: 161out:
162 return ret; 162 return ret;
163} 163}
@@ -168,11 +168,10 @@ static int mdio_ofgpio_remove(struct of_device *ofdev)
168 struct mdio_gpio_info *bitbang = bus->priv; 168 struct mdio_gpio_info *bitbang = bus->priv;
169 169
170 mdiobus_unregister(bus); 170 mdiobus_unregister(bus);
171 kfree(bus->irq);
171 free_mdio_bitbang(bus); 172 free_mdio_bitbang(bus);
172 dev_set_drvdata(&ofdev->dev, NULL); 173 dev_set_drvdata(&ofdev->dev, NULL);
173 kfree(bus->irq);
174 kfree(bitbang); 174 kfree(bitbang);
175 kfree(bus);
176 175
177 return 0; 176 return 0;
178} 177}
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index a7211a32bb4..d206691f15d 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -36,6 +36,18 @@
36#include <asm/uaccess.h> 36#include <asm/uaccess.h>
37 37
38/** 38/**
39 * mdiobus_alloc - allocate a mii_bus structure
40 *
41 * Description: called by a bus driver to allocate an mii_bus
42 * structure to fill in.
43 */
44struct mii_bus *mdiobus_alloc(void)
45{
46 return kzalloc(sizeof(struct mii_bus), GFP_KERNEL);
47}
48EXPORT_SYMBOL(mdiobus_alloc);
49
50/**
39 * mdiobus_register - bring up all the PHYs on a given bus and attach them to bus 51 * mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
40 * @bus: target mii_bus 52 * @bus: target mii_bus
41 * 53 *
@@ -87,6 +99,18 @@ void mdiobus_unregister(struct mii_bus *bus)
87} 99}
88EXPORT_SYMBOL(mdiobus_unregister); 100EXPORT_SYMBOL(mdiobus_unregister);
89 101
102/**
103 * mdiobus_free - free a struct mii_bus
104 * @bus: mii_bus to free
105 *
106 * This function frees the mii_bus.
107 */
108void mdiobus_free(struct mii_bus *bus)
109{
110 kfree(bus);
111}
112EXPORT_SYMBOL(mdiobus_free);
113
90struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr) 114struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
91{ 115{
92 struct phy_device *phydev; 116 struct phy_device *phydev;
diff --git a/drivers/net/sb1250-mac.c b/drivers/net/sb1250-mac.c
index d0ee735590b..2615d46e6e5 100644
--- a/drivers/net/sb1250-mac.c
+++ b/drivers/net/sb1250-mac.c
@@ -256,7 +256,7 @@ struct sbmac_softc {
256 struct net_device *sbm_dev; /* pointer to linux device */ 256 struct net_device *sbm_dev; /* pointer to linux device */
257 struct napi_struct napi; 257 struct napi_struct napi;
258 struct phy_device *phy_dev; /* the associated PHY device */ 258 struct phy_device *phy_dev; /* the associated PHY device */
259 struct mii_bus mii_bus; /* the MII bus */ 259 struct mii_bus *mii_bus; /* the MII bus */
260 int phy_irq[PHY_MAX_ADDR]; 260 int phy_irq[PHY_MAX_ADDR];
261 spinlock_t sbm_lock; /* spin lock */ 261 spinlock_t sbm_lock; /* spin lock */
262 int sbm_devflags; /* current device flags */ 262 int sbm_devflags; /* current device flags */
@@ -2348,10 +2348,17 @@ static int sbmac_init(struct platform_device *pldev, long long base)
2348 /* This is needed for PASS2 for Rx H/W checksum feature */ 2348 /* This is needed for PASS2 for Rx H/W checksum feature */
2349 sbmac_set_iphdr_offset(sc); 2349 sbmac_set_iphdr_offset(sc);
2350 2350
2351 sc->mii_bus = mdiobus_alloc();
2352 if (sc->mii_bus == NULL) {
2353 sbmac_uninitctx(sc);
2354 return -ENOMEM;
2355 }
2356
2351 err = register_netdev(dev); 2357 err = register_netdev(dev);
2352 if (err) { 2358 if (err) {
2353 printk(KERN_ERR "%s.%d: unable to register netdev\n", 2359 printk(KERN_ERR "%s.%d: unable to register netdev\n",
2354 sbmac_string, idx); 2360 sbmac_string, idx);
2361 mdiobus_free(sc->mii_bus);
2355 sbmac_uninitctx(sc); 2362 sbmac_uninitctx(sc);
2356 return err; 2363 return err;
2357 } 2364 }
@@ -2369,17 +2376,17 @@ static int sbmac_init(struct platform_device *pldev, long long base)
2369 pr_info("%s: SiByte Ethernet at 0x%08Lx, address: %s\n", 2376 pr_info("%s: SiByte Ethernet at 0x%08Lx, address: %s\n",
2370 dev->name, base, print_mac(mac, eaddr)); 2377 dev->name, base, print_mac(mac, eaddr));
2371 2378
2372 sc->mii_bus.name = sbmac_mdio_string; 2379 sc->mii_bus->name = sbmac_mdio_string;
2373 snprintf(sc->mii_bus.id, MII_BUS_ID_SIZE, "%x", idx); 2380 snprintf(sc->mii_bus->id, MII_BUS_ID_SIZE, "%x", idx);
2374 sc->mii_bus.priv = sc; 2381 sc->mii_bus->priv = sc;
2375 sc->mii_bus.read = sbmac_mii_read; 2382 sc->mii_bus->read = sbmac_mii_read;
2376 sc->mii_bus.write = sbmac_mii_write; 2383 sc->mii_bus->write = sbmac_mii_write;
2377 sc->mii_bus.irq = sc->phy_irq; 2384 sc->mii_bus->irq = sc->phy_irq;
2378 for (i = 0; i < PHY_MAX_ADDR; ++i) 2385 for (i = 0; i < PHY_MAX_ADDR; ++i)
2379 sc->mii_bus.irq[i] = SBMAC_PHY_INT; 2386 sc->mii_bus->irq[i] = SBMAC_PHY_INT;
2380 2387
2381 sc->mii_bus.parent = &pldev->dev; 2388 sc->mii_bus->parent = &pldev->dev;
2382 dev_set_drvdata(&pldev->dev, &sc->mii_bus); 2389 dev_set_drvdata(&pldev->dev, sc->mii_bus);
2383 2390
2384 return 0; 2391 return 0;
2385} 2392}
@@ -2410,7 +2417,7 @@ static int sbmac_open(struct net_device *dev)
2410 /* 2417 /*
2411 * Probe PHY address 2418 * Probe PHY address
2412 */ 2419 */
2413 err = mdiobus_register(&sc->mii_bus); 2420 err = mdiobus_register(sc->mii_bus);
2414 if (err) { 2421 if (err) {
2415 printk(KERN_ERR "%s: unable to register MDIO bus\n", 2422 printk(KERN_ERR "%s: unable to register MDIO bus\n",
2416 dev->name); 2423 dev->name);
@@ -2447,7 +2454,7 @@ static int sbmac_open(struct net_device *dev)
2447 return 0; 2454 return 0;
2448 2455
2449out_unregister: 2456out_unregister:
2450 mdiobus_unregister(&sc->mii_bus); 2457 mdiobus_unregister(sc->mii_bus);
2451 2458
2452out_unirq: 2459out_unirq:
2453 free_irq(dev->irq, dev); 2460 free_irq(dev->irq, dev);
@@ -2463,7 +2470,7 @@ static int sbmac_mii_probe(struct net_device *dev)
2463 int i; 2470 int i;
2464 2471
2465 for (i = 0; i < PHY_MAX_ADDR; i++) { 2472 for (i = 0; i < PHY_MAX_ADDR; i++) {
2466 phy_dev = sc->mii_bus.phy_map[i]; 2473 phy_dev = sc->mii_bus->phy_map[i];
2467 if (phy_dev) 2474 if (phy_dev)
2468 break; 2475 break;
2469 } 2476 }
@@ -2641,7 +2648,7 @@ static int sbmac_close(struct net_device *dev)
2641 phy_disconnect(sc->phy_dev); 2648 phy_disconnect(sc->phy_dev);
2642 sc->phy_dev = NULL; 2649 sc->phy_dev = NULL;
2643 2650
2644 mdiobus_unregister(&sc->mii_bus); 2651 mdiobus_unregister(sc->mii_bus);
2645 2652
2646 free_irq(dev->irq, dev); 2653 free_irq(dev->irq, dev);
2647 2654
@@ -2750,6 +2757,7 @@ static int __exit sbmac_remove(struct platform_device *pldev)
2750 2757
2751 unregister_netdev(dev); 2758 unregister_netdev(dev);
2752 sbmac_uninitctx(sc); 2759 sbmac_uninitctx(sc);
2760 mdiobus_free(sc->mii_bus);
2753 iounmap(sc->sbm_base); 2761 iounmap(sc->sbm_base);
2754 free_netdev(dev); 2762 free_netdev(dev);
2755 2763
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
index 1b3b7b66ffd..b39d1cc1ef0 100644
--- a/drivers/net/sh_eth.c
+++ b/drivers/net/sh_eth.c
@@ -1166,7 +1166,7 @@ out_free_irq:
1166 kfree(mdp->mii_bus->irq); 1166 kfree(mdp->mii_bus->irq);
1167 1167
1168out_free_bus: 1168out_free_bus:
1169 kfree(mdp->mii_bus); 1169 free_mdio_bitbang(mdp->mii_bus);
1170 1170
1171out_free_bitbang: 1171out_free_bitbang:
1172 kfree(bitbang); 1172 kfree(bitbang);
diff --git a/drivers/net/tc35815.c b/drivers/net/tc35815.c
index 1f2b1f2d73a..4980b12b621 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
789err_out_unregister_bus: 795err_out_unregister_bus:
790 mdiobus_unregister(&lp->mii_bus); 796 mdiobus_unregister(lp->mii_bus);
791err_out_free_mdio_irq: 797err_out_free_mdio_irq:
792 kfree(lp->mii_bus.irq); 798 kfree(lp->mii_bus->irq);
799err_out_free_mii_bus;
800 mdiobus_free(lp->mii_bus);
793err_out: 801err_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);
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 4b8b75bcbde..eb9f8f3638e 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -876,7 +876,7 @@ static void tg3_mdio_config(struct tg3 *tp)
876{ 876{
877 u32 val; 877 u32 val;
878 878
879 if (tp->mdio_bus.phy_map[PHY_ADDR]->interface != 879 if (tp->mdio_bus->phy_map[PHY_ADDR]->interface !=
880 PHY_INTERFACE_MODE_RGMII) 880 PHY_INTERFACE_MODE_RGMII)
881 return; 881 return;
882 882
@@ -920,9 +920,9 @@ static void tg3_mdio_config(struct tg3 *tp)
920static void tg3_mdio_start(struct tg3 *tp) 920static void tg3_mdio_start(struct tg3 *tp)
921{ 921{
922 if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { 922 if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) {
923 mutex_lock(&tp->mdio_bus.mdio_lock); 923 mutex_lock(&tp->mdio_bus->mdio_lock);
924 tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_PAUSED; 924 tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_PAUSED;
925 mutex_unlock(&tp->mdio_bus.mdio_lock); 925 mutex_unlock(&tp->mdio_bus->mdio_lock);
926 } 926 }
927 927
928 tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; 928 tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL;
@@ -936,9 +936,9 @@ static void tg3_mdio_start(struct tg3 *tp)
936static void tg3_mdio_stop(struct tg3 *tp) 936static void tg3_mdio_stop(struct tg3 *tp)
937{ 937{
938 if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { 938 if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) {
939 mutex_lock(&tp->mdio_bus.mdio_lock); 939 mutex_lock(&tp->mdio_bus->mdio_lock);
940 tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_PAUSED; 940 tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_PAUSED;
941 mutex_unlock(&tp->mdio_bus.mdio_lock); 941 mutex_unlock(&tp->mdio_bus->mdio_lock);
942 } 942 }
943} 943}
944 944
@@ -947,7 +947,6 @@ static int tg3_mdio_init(struct tg3 *tp)
947 int i; 947 int i;
948 u32 reg; 948 u32 reg;
949 struct phy_device *phydev; 949 struct phy_device *phydev;
950 struct mii_bus *mdio_bus = &tp->mdio_bus;
951 950
952 tg3_mdio_start(tp); 951 tg3_mdio_start(tp);
953 952
@@ -955,21 +954,23 @@ static int tg3_mdio_init(struct tg3 *tp)
955 (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED)) 954 (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED))
956 return 0; 955 return 0;
957 956
958 memset(mdio_bus, 0, sizeof(*mdio_bus)); 957 tp->mdio_bus = mdiobus_alloc();
958 if (tp->mdio_bus == NULL)
959 return -ENOMEM;
959 960
960 mdio_bus->name = "tg3 mdio bus"; 961 tp->mdio_bus->name = "tg3 mdio bus";
961 snprintf(mdio_bus->id, MII_BUS_ID_SIZE, "%x", 962 snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x",
962 (tp->pdev->bus->number << 8) | tp->pdev->devfn); 963 (tp->pdev->bus->number << 8) | tp->pdev->devfn);
963 mdio_bus->priv = tp; 964 tp->mdio_bus->priv = tp;
964 mdio_bus->parent = &tp->pdev->dev; 965 tp->mdio_bus->parent = &tp->pdev->dev;
965 mdio_bus->read = &tg3_mdio_read; 966 tp->mdio_bus->read = &tg3_mdio_read;
966 mdio_bus->write = &tg3_mdio_write; 967 tp->mdio_bus->write = &tg3_mdio_write;
967 mdio_bus->reset = &tg3_mdio_reset; 968 tp->mdio_bus->reset = &tg3_mdio_reset;
968 mdio_bus->phy_mask = ~(1 << PHY_ADDR); 969 tp->mdio_bus->phy_mask = ~(1 << PHY_ADDR);
969 mdio_bus->irq = &tp->mdio_irq[0]; 970 tp->mdio_bus->irq = &tp->mdio_irq[0];
970 971
971 for (i = 0; i < PHY_MAX_ADDR; i++) 972 for (i = 0; i < PHY_MAX_ADDR; i++)
972 mdio_bus->irq[i] = PHY_POLL; 973 tp->mdio_bus->irq[i] = PHY_POLL;
973 974
974 /* The bus registration will look for all the PHYs on the mdio bus. 975 /* The bus registration will look for all the PHYs on the mdio bus.
975 * Unfortunately, it does not ensure the PHY is powered up before 976 * Unfortunately, it does not ensure the PHY is powered up before
@@ -979,7 +980,7 @@ static int tg3_mdio_init(struct tg3 *tp)
979 if (tg3_readphy(tp, MII_BMCR, &reg) || (reg & BMCR_PDOWN)) 980 if (tg3_readphy(tp, MII_BMCR, &reg) || (reg & BMCR_PDOWN))
980 tg3_bmcr_reset(tp); 981 tg3_bmcr_reset(tp);
981 982
982 i = mdiobus_register(mdio_bus); 983 i = mdiobus_register(tp->mdio_bus);
983 if (i) { 984 if (i) {
984 printk(KERN_WARNING "%s: mdiobus_reg failed (0x%x)\n", 985 printk(KERN_WARNING "%s: mdiobus_reg failed (0x%x)\n",
985 tp->dev->name, i); 986 tp->dev->name, i);
@@ -988,7 +989,7 @@ static int tg3_mdio_init(struct tg3 *tp)
988 989
989 tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_INITED; 990 tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_INITED;
990 991
991 phydev = tp->mdio_bus.phy_map[PHY_ADDR]; 992 phydev = tp->mdio_bus->phy_map[PHY_ADDR];
992 993
993 switch (phydev->phy_id) { 994 switch (phydev->phy_id) {
994 case TG3_PHY_ID_BCM50610: 995 case TG3_PHY_ID_BCM50610:
@@ -1014,7 +1015,8 @@ static void tg3_mdio_fini(struct tg3 *tp)
1014{ 1015{
1015 if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { 1016 if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) {
1016 tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_INITED; 1017 tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_INITED;
1017 mdiobus_unregister(&tp->mdio_bus); 1018 mdiobus_unregister(tp->mdio_bus);
1019 mdiobus_free(tp->mdio_bus);
1018 tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_PAUSED; 1020 tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_PAUSED;
1019 } 1021 }
1020} 1022}
@@ -1220,7 +1222,7 @@ static void tg3_setup_flow_control(struct tg3 *tp, u32 lcladv, u32 rmtadv)
1220 u32 old_tx_mode = tp->tx_mode; 1222 u32 old_tx_mode = tp->tx_mode;
1221 1223
1222 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) 1224 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)
1223 autoneg = tp->mdio_bus.phy_map[PHY_ADDR]->autoneg; 1225 autoneg = tp->mdio_bus->phy_map[PHY_ADDR]->autoneg;
1224 else 1226 else
1225 autoneg = tp->link_config.autoneg; 1227 autoneg = tp->link_config.autoneg;
1226 1228
@@ -1257,7 +1259,7 @@ static void tg3_adjust_link(struct net_device *dev)
1257 u8 oldflowctrl, linkmesg = 0; 1259 u8 oldflowctrl, linkmesg = 0;
1258 u32 mac_mode, lcl_adv, rmt_adv; 1260 u32 mac_mode, lcl_adv, rmt_adv;
1259 struct tg3 *tp = netdev_priv(dev); 1261 struct tg3 *tp = netdev_priv(dev);
1260 struct phy_device *phydev = tp->mdio_bus.phy_map[PHY_ADDR]; 1262 struct phy_device *phydev = tp->mdio_bus->phy_map[PHY_ADDR];
1261 1263
1262 spin_lock(&tp->lock); 1264 spin_lock(&tp->lock);
1263 1265
@@ -1334,7 +1336,7 @@ static int tg3_phy_init(struct tg3 *tp)
1334 /* Bring the PHY back to a known state. */ 1336 /* Bring the PHY back to a known state. */
1335 tg3_bmcr_reset(tp); 1337 tg3_bmcr_reset(tp);
1336 1338
1337 phydev = tp->mdio_bus.phy_map[PHY_ADDR]; 1339 phydev = tp->mdio_bus->phy_map[PHY_ADDR];
1338 1340
1339 /* Attach the MAC to the PHY. */ 1341 /* Attach the MAC to the PHY. */
1340 phydev = phy_connect(tp->dev, phydev->dev.bus_id, tg3_adjust_link, 1342 phydev = phy_connect(tp->dev, phydev->dev.bus_id, tg3_adjust_link,
@@ -1367,7 +1369,7 @@ static void tg3_phy_start(struct tg3 *tp)
1367 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) 1369 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED))
1368 return; 1370 return;
1369 1371
1370 phydev = tp->mdio_bus.phy_map[PHY_ADDR]; 1372 phydev = tp->mdio_bus->phy_map[PHY_ADDR];
1371 1373
1372 if (tp->link_config.phy_is_low_power) { 1374 if (tp->link_config.phy_is_low_power) {
1373 tp->link_config.phy_is_low_power = 0; 1375 tp->link_config.phy_is_low_power = 0;
@@ -1387,13 +1389,13 @@ static void tg3_phy_stop(struct tg3 *tp)
1387 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) 1389 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED))
1388 return; 1390 return;
1389 1391
1390 phy_stop(tp->mdio_bus.phy_map[PHY_ADDR]); 1392 phy_stop(tp->mdio_bus->phy_map[PHY_ADDR]);
1391} 1393}
1392 1394
1393static void tg3_phy_fini(struct tg3 *tp) 1395static void tg3_phy_fini(struct tg3 *tp)
1394{ 1396{
1395 if (tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) { 1397 if (tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) {
1396 phy_disconnect(tp->mdio_bus.phy_map[PHY_ADDR]); 1398 phy_disconnect(tp->mdio_bus->phy_map[PHY_ADDR]);
1397 tp->tg3_flags3 &= ~TG3_FLG3_PHY_CONNECTED; 1399 tp->tg3_flags3 &= ~TG3_FLG3_PHY_CONNECTED;
1398 } 1400 }
1399} 1401}
@@ -2049,7 +2051,7 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
2049 struct phy_device *phydev; 2051 struct phy_device *phydev;
2050 u32 advertising; 2052 u32 advertising;
2051 2053
2052 phydev = tp->mdio_bus.phy_map[PHY_ADDR]; 2054 phydev = tp->mdio_bus->phy_map[PHY_ADDR];
2053 2055
2054 tp->link_config.phy_is_low_power = 1; 2056 tp->link_config.phy_is_low_power = 1;
2055 2057
@@ -8954,7 +8956,7 @@ static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
8954 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { 8956 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
8955 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) 8957 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED))
8956 return -EAGAIN; 8958 return -EAGAIN;
8957 return phy_ethtool_gset(tp->mdio_bus.phy_map[PHY_ADDR], cmd); 8959 return phy_ethtool_gset(tp->mdio_bus->phy_map[PHY_ADDR], cmd);
8958 } 8960 }
8959 8961
8960 cmd->supported = (SUPPORTED_Autoneg); 8962 cmd->supported = (SUPPORTED_Autoneg);
@@ -8995,7 +8997,7 @@ static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
8995 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { 8997 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
8996 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) 8998 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED))
8997 return -EAGAIN; 8999 return -EAGAIN;
8998 return phy_ethtool_sset(tp->mdio_bus.phy_map[PHY_ADDR], cmd); 9000 return phy_ethtool_sset(tp->mdio_bus->phy_map[PHY_ADDR], cmd);
8999 } 9001 }
9000 9002
9001 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) { 9003 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
@@ -9143,7 +9145,7 @@ static int tg3_nway_reset(struct net_device *dev)
9143 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { 9145 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
9144 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) 9146 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED))
9145 return -EAGAIN; 9147 return -EAGAIN;
9146 r = phy_start_aneg(tp->mdio_bus.phy_map[PHY_ADDR]); 9148 r = phy_start_aneg(tp->mdio_bus->phy_map[PHY_ADDR]);
9147 } else { 9149 } else {
9148 u32 bmcr; 9150 u32 bmcr;
9149 9151
@@ -9260,7 +9262,7 @@ static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam
9260 u32 newadv; 9262 u32 newadv;
9261 struct phy_device *phydev; 9263 struct phy_device *phydev;
9262 9264
9263 phydev = tp->mdio_bus.phy_map[PHY_ADDR]; 9265 phydev = tp->mdio_bus->phy_map[PHY_ADDR];
9264 9266
9265 if (epause->rx_pause) { 9267 if (epause->rx_pause) {
9266 if (epause->tx_pause) 9268 if (epause->tx_pause)
@@ -10242,7 +10244,7 @@ static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
10242 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { 10244 if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
10243 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) 10245 if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED))
10244 return -EAGAIN; 10246 return -EAGAIN;
10245 return phy_mii_ioctl(tp->mdio_bus.phy_map[PHY_ADDR], data, cmd); 10247 return phy_mii_ioctl(tp->mdio_bus->phy_map[PHY_ADDR], data, cmd);
10246 } 10248 }
10247 10249
10248 switch(cmd) { 10250 switch(cmd) {
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index 6c7b5e303db..be252abe898 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -2556,7 +2556,7 @@ struct tg3 {
2556 int msi_cap; 2556 int msi_cap;
2557 int pcix_cap; 2557 int pcix_cap;
2558 2558
2559 struct mii_bus mdio_bus; 2559 struct mii_bus *mdio_bus;
2560 int mdio_irq[PHY_MAX_ADDR]; 2560 int mdio_irq[PHY_MAX_ADDR];
2561 2561
2562 /* PHY info */ 2562 /* PHY info */
diff --git a/drivers/net/ucc_geth_mii.c b/drivers/net/ucc_geth_mii.c
index 75b72fe1f23..c001d261366 100644
--- a/drivers/net/ucc_geth_mii.c
+++ b/drivers/net/ucc_geth_mii.c
@@ -141,8 +141,7 @@ static int uec_mdio_probe(struct of_device *ofdev, const struct of_device_id *ma
141 struct resource res; 141 struct resource res;
142 int k, err = 0; 142 int k, err = 0;
143 143
144 new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL); 144 new_bus = mdiobus_alloc();
145
146 if (NULL == new_bus) 145 if (NULL == new_bus)
147 return -ENOMEM; 146 return -ENOMEM;
148 147
@@ -235,7 +234,7 @@ bus_register_fail:
235ioremap_fail: 234ioremap_fail:
236 kfree(new_bus->irq); 235 kfree(new_bus->irq);
237reg_map_fail: 236reg_map_fail:
238 kfree(new_bus); 237 mdiobus_free(new_bus);
239 238
240 return err; 239 return err;
241} 240}
@@ -251,7 +250,7 @@ static int uec_mdio_remove(struct of_device *ofdev)
251 250
252 iounmap((void __iomem *)bus->priv); 251 iounmap((void __iomem *)bus->priv);
253 bus->priv = NULL; 252 bus->priv = NULL;
254 kfree(bus); 253 mdiobus_free(bus);
255 254
256 return 0; 255 return 0;
257} 256}
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 87499bdedc6..ca4a83c4c53 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -408,8 +408,10 @@ void phy_start(struct phy_device *phydev);
408void phy_stop(struct phy_device *phydev); 408void phy_stop(struct phy_device *phydev);
409int phy_start_aneg(struct phy_device *phydev); 409int phy_start_aneg(struct phy_device *phydev);
410 410
411struct mii_bus *mdiobus_alloc(void);
411int mdiobus_register(struct mii_bus *bus); 412int mdiobus_register(struct mii_bus *bus);
412void mdiobus_unregister(struct mii_bus *bus); 413void mdiobus_unregister(struct mii_bus *bus);
414void mdiobus_free(struct mii_bus *bus);
413struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr); 415struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
414 416
415void phy_sanitize_settings(struct phy_device *phydev); 417void phy_sanitize_settings(struct phy_device *phydev);