diff options
Diffstat (limited to 'drivers/net/au1000_eth.c')
-rw-r--r-- | drivers/net/au1000_eth.c | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/drivers/net/au1000_eth.c b/drivers/net/au1000_eth.c index 5ee1b0557a02..019b13c08ae6 100644 --- a/drivers/net/au1000_eth.c +++ b/drivers/net/au1000_eth.c | |||
@@ -94,8 +94,8 @@ static irqreturn_t au1000_interrupt(int, void *); | |||
94 | static void au1000_tx_timeout(struct net_device *); | 94 | static void au1000_tx_timeout(struct net_device *); |
95 | static void set_rx_mode(struct net_device *); | 95 | static void set_rx_mode(struct net_device *); |
96 | static int au1000_ioctl(struct net_device *, struct ifreq *, int); | 96 | static int au1000_ioctl(struct net_device *, struct ifreq *, int); |
97 | static int mdio_read(struct net_device *, int, int); | 97 | static int au1000_mdio_read(struct net_device *, int, int); |
98 | static void mdio_write(struct net_device *, int, int, u16); | 98 | static void au1000_mdio_write(struct net_device *, int, int, u16); |
99 | static void au1000_adjust_link(struct net_device *); | 99 | static void au1000_adjust_link(struct net_device *); |
100 | static void enable_mac(struct net_device *, int); | 100 | static void enable_mac(struct net_device *, int); |
101 | 101 | ||
@@ -191,7 +191,7 @@ struct au1000_private *au_macs[NUM_ETH_INTERFACES]; | |||
191 | /* | 191 | /* |
192 | * MII operations | 192 | * MII operations |
193 | */ | 193 | */ |
194 | static int mdio_read(struct net_device *dev, int phy_addr, int reg) | 194 | static int au1000_mdio_read(struct net_device *dev, int phy_addr, int reg) |
195 | { | 195 | { |
196 | struct au1000_private *aup = (struct au1000_private *) dev->priv; | 196 | struct au1000_private *aup = (struct au1000_private *) dev->priv; |
197 | volatile u32 *const mii_control_reg = &aup->mac->mii_control; | 197 | volatile u32 *const mii_control_reg = &aup->mac->mii_control; |
@@ -225,7 +225,8 @@ static int mdio_read(struct net_device *dev, int phy_addr, int reg) | |||
225 | return (int)*mii_data_reg; | 225 | return (int)*mii_data_reg; |
226 | } | 226 | } |
227 | 227 | ||
228 | static void mdio_write(struct net_device *dev, int phy_addr, int reg, u16 value) | 228 | static void au1000_mdio_write(struct net_device *dev, int phy_addr, |
229 | int reg, u16 value) | ||
229 | { | 230 | { |
230 | struct au1000_private *aup = (struct au1000_private *) dev->priv; | 231 | struct au1000_private *aup = (struct au1000_private *) dev->priv; |
231 | volatile u32 *const mii_control_reg = &aup->mac->mii_control; | 232 | volatile u32 *const mii_control_reg = &aup->mac->mii_control; |
@@ -249,7 +250,7 @@ static void mdio_write(struct net_device *dev, int phy_addr, int reg, u16 value) | |||
249 | *mii_control_reg = mii_control; | 250 | *mii_control_reg = mii_control; |
250 | } | 251 | } |
251 | 252 | ||
252 | static int mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum) | 253 | static int au1000_mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum) |
253 | { | 254 | { |
254 | /* WARNING: bus->phy_map[phy_addr].attached_dev == dev does | 255 | /* WARNING: bus->phy_map[phy_addr].attached_dev == dev does |
255 | * _NOT_ hold (e.g. when PHY is accessed through other MAC's MII bus) */ | 256 | * _NOT_ hold (e.g. when PHY is accessed through other MAC's MII bus) */ |
@@ -257,21 +258,21 @@ static int mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum) | |||
257 | 258 | ||
258 | enable_mac(dev, 0); /* make sure the MAC associated with this | 259 | enable_mac(dev, 0); /* make sure the MAC associated with this |
259 | * mii_bus is enabled */ | 260 | * mii_bus is enabled */ |
260 | return mdio_read(dev, phy_addr, regnum); | 261 | return au1000_mdio_read(dev, phy_addr, regnum); |
261 | } | 262 | } |
262 | 263 | ||
263 | static int mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum, | 264 | static int au1000_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum, |
264 | u16 value) | 265 | u16 value) |
265 | { | 266 | { |
266 | struct net_device *const dev = bus->priv; | 267 | struct net_device *const dev = bus->priv; |
267 | 268 | ||
268 | enable_mac(dev, 0); /* make sure the MAC associated with this | 269 | enable_mac(dev, 0); /* make sure the MAC associated with this |
269 | * mii_bus is enabled */ | 270 | * mii_bus is enabled */ |
270 | mdio_write(dev, phy_addr, regnum, value); | 271 | au1000_mdio_write(dev, phy_addr, regnum, value); |
271 | return 0; | 272 | return 0; |
272 | } | 273 | } |
273 | 274 | ||
274 | static int mdiobus_reset(struct mii_bus *bus) | 275 | static int au1000_mdiobus_reset(struct mii_bus *bus) |
275 | { | 276 | { |
276 | struct net_device *const dev = bus->priv; | 277 | struct net_device *const dev = bus->priv; |
277 | 278 | ||
@@ -290,7 +291,7 @@ static int mii_probe (struct net_device *dev) | |||
290 | 291 | ||
291 | if(aup->mac_id == 0) { /* get PHY0 */ | 292 | if(aup->mac_id == 0) { /* get PHY0 */ |
292 | # if defined(AU1XXX_PHY0_ADDR) | 293 | # if defined(AU1XXX_PHY0_ADDR) |
293 | phydev = au_macs[AU1XXX_PHY0_BUSID]->mii_bus.phy_map[AU1XXX_PHY0_ADDR]; | 294 | phydev = au_macs[AU1XXX_PHY0_BUSID]->mii_bus->phy_map[AU1XXX_PHY0_ADDR]; |
294 | # else | 295 | # else |
295 | printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n", | 296 | printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n", |
296 | dev->name); | 297 | dev->name); |
@@ -298,7 +299,7 @@ static int mii_probe (struct net_device *dev) | |||
298 | # endif /* defined(AU1XXX_PHY0_ADDR) */ | 299 | # endif /* defined(AU1XXX_PHY0_ADDR) */ |
299 | } else if (aup->mac_id == 1) { /* get PHY1 */ | 300 | } else if (aup->mac_id == 1) { /* get PHY1 */ |
300 | # if defined(AU1XXX_PHY1_ADDR) | 301 | # if defined(AU1XXX_PHY1_ADDR) |
301 | phydev = au_macs[AU1XXX_PHY1_BUSID]->mii_bus.phy_map[AU1XXX_PHY1_ADDR]; | 302 | phydev = au_macs[AU1XXX_PHY1_BUSID]->mii_bus->phy_map[AU1XXX_PHY1_ADDR]; |
302 | # else | 303 | # else |
303 | printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n", | 304 | printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n", |
304 | dev->name); | 305 | dev->name); |
@@ -311,8 +312,8 @@ static int mii_probe (struct net_device *dev) | |||
311 | 312 | ||
312 | /* find the first (lowest address) PHY on the current MAC's MII bus */ | 313 | /* 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++) | 314 | for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) |
314 | if (aup->mii_bus.phy_map[phy_addr]) { | 315 | if (aup->mii_bus->phy_map[phy_addr]) { |
315 | phydev = aup->mii_bus.phy_map[phy_addr]; | 316 | phydev = aup->mii_bus->phy_map[phy_addr]; |
316 | # if !defined(AU1XXX_PHY_SEARCH_HIGHEST_ADDR) | 317 | # if !defined(AU1XXX_PHY_SEARCH_HIGHEST_ADDR) |
317 | break; /* break out with first one found */ | 318 | break; /* break out with first one found */ |
318 | # endif | 319 | # endif |
@@ -331,7 +332,7 @@ static int mii_probe (struct net_device *dev) | |||
331 | * the MAC0 MII bus */ | 332 | * the MAC0 MII bus */ |
332 | for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) { | 333 | for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) { |
333 | struct phy_device *const tmp_phydev = | 334 | struct phy_device *const tmp_phydev = |
334 | au_macs[0]->mii_bus.phy_map[phy_addr]; | 335 | au_macs[0]->mii_bus->phy_map[phy_addr]; |
335 | 336 | ||
336 | if (!tmp_phydev) | 337 | if (!tmp_phydev) |
337 | continue; /* no PHY here... */ | 338 | continue; /* no PHY here... */ |
@@ -653,6 +654,8 @@ static struct net_device * au1000_probe(int port_num) | |||
653 | 654 | ||
654 | aup = dev->priv; | 655 | aup = dev->priv; |
655 | 656 | ||
657 | spin_lock_init(&aup->lock); | ||
658 | |||
656 | /* Allocate the data buffers */ | 659 | /* Allocate the data buffers */ |
657 | /* Snooping works fine with eth on all au1xxx */ | 660 | /* Snooping works fine with eth on all au1xxx */ |
658 | aup->vaddr = (u32)dma_alloc_noncoherent(NULL, MAX_BUF_SIZE * | 661 | aup->vaddr = (u32)dma_alloc_noncoherent(NULL, MAX_BUF_SIZE * |
@@ -696,28 +699,32 @@ static struct net_device * au1000_probe(int port_num) | |||
696 | *aup->enable = 0; | 699 | *aup->enable = 0; |
697 | aup->mac_enabled = 0; | 700 | aup->mac_enabled = 0; |
698 | 701 | ||
699 | aup->mii_bus.priv = dev; | 702 | aup->mii_bus = mdiobus_alloc(); |
700 | aup->mii_bus.read = mdiobus_read; | 703 | if (aup->mii_bus == NULL) |
701 | aup->mii_bus.write = mdiobus_write; | 704 | goto err_out; |
702 | aup->mii_bus.reset = mdiobus_reset; | 705 | |
703 | aup->mii_bus.name = "au1000_eth_mii"; | 706 | aup->mii_bus->priv = dev; |
704 | snprintf(aup->mii_bus.id, MII_BUS_ID_SIZE, "%x", aup->mac_id); | 707 | aup->mii_bus->read = au1000_mdiobus_read; |
705 | aup->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); | 708 | aup->mii_bus->write = au1000_mdiobus_write; |
709 | aup->mii_bus->reset = au1000_mdiobus_reset; | ||
710 | aup->mii_bus->name = "au1000_eth_mii"; | ||
711 | snprintf(aup->mii_bus->id, MII_BUS_ID_SIZE, "%x", aup->mac_id); | ||
712 | aup->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); | ||
706 | for(i = 0; i < PHY_MAX_ADDR; ++i) | 713 | for(i = 0; i < PHY_MAX_ADDR; ++i) |
707 | aup->mii_bus.irq[i] = PHY_POLL; | 714 | aup->mii_bus->irq[i] = PHY_POLL; |
708 | 715 | ||
709 | /* if known, set corresponding PHY IRQs */ | 716 | /* if known, set corresponding PHY IRQs */ |
710 | #if defined(AU1XXX_PHY_STATIC_CONFIG) | 717 | #if defined(AU1XXX_PHY_STATIC_CONFIG) |
711 | # if defined(AU1XXX_PHY0_IRQ) | 718 | # if defined(AU1XXX_PHY0_IRQ) |
712 | if (AU1XXX_PHY0_BUSID == aup->mac_id) | 719 | if (AU1XXX_PHY0_BUSID == aup->mac_id) |
713 | aup->mii_bus.irq[AU1XXX_PHY0_ADDR] = AU1XXX_PHY0_IRQ; | 720 | aup->mii_bus->irq[AU1XXX_PHY0_ADDR] = AU1XXX_PHY0_IRQ; |
714 | # endif | 721 | # endif |
715 | # if defined(AU1XXX_PHY1_IRQ) | 722 | # if defined(AU1XXX_PHY1_IRQ) |
716 | if (AU1XXX_PHY1_BUSID == aup->mac_id) | 723 | if (AU1XXX_PHY1_BUSID == aup->mac_id) |
717 | aup->mii_bus.irq[AU1XXX_PHY1_ADDR] = AU1XXX_PHY1_IRQ; | 724 | aup->mii_bus->irq[AU1XXX_PHY1_ADDR] = AU1XXX_PHY1_IRQ; |
718 | # endif | 725 | # endif |
719 | #endif | 726 | #endif |
720 | mdiobus_register(&aup->mii_bus); | 727 | mdiobus_register(aup->mii_bus); |
721 | 728 | ||
722 | if (mii_probe(dev) != 0) { | 729 | if (mii_probe(dev) != 0) { |
723 | goto err_out; | 730 | goto err_out; |
@@ -753,7 +760,6 @@ static struct net_device * au1000_probe(int port_num) | |||
753 | aup->tx_db_inuse[i] = pDB; | 760 | aup->tx_db_inuse[i] = pDB; |
754 | } | 761 | } |
755 | 762 | ||
756 | spin_lock_init(&aup->lock); | ||
757 | dev->base_addr = base; | 763 | dev->base_addr = base; |
758 | dev->irq = irq; | 764 | dev->irq = irq; |
759 | dev->open = au1000_open; | 765 | dev->open = au1000_open; |
@@ -774,6 +780,11 @@ static struct net_device * au1000_probe(int port_num) | |||
774 | return dev; | 780 | return dev; |
775 | 781 | ||
776 | err_out: | 782 | err_out: |
783 | if (aup->mii_bus != NULL) { | ||
784 | mdiobus_unregister(aup->mii_bus); | ||
785 | mdiobus_free(aup->mii_bus); | ||
786 | } | ||
787 | |||
777 | /* here we should have a valid dev plus aup-> register addresses | 788 | /* here we should have a valid dev plus aup-> register addresses |
778 | * so we can reset the mac properly.*/ | 789 | * so we can reset the mac properly.*/ |
779 | reset_mac(dev); | 790 | reset_mac(dev); |
@@ -1004,6 +1015,8 @@ static void __exit au1000_cleanup_module(void) | |||
1004 | if (dev) { | 1015 | if (dev) { |
1005 | aup = (struct au1000_private *) dev->priv; | 1016 | aup = (struct au1000_private *) dev->priv; |
1006 | unregister_netdev(dev); | 1017 | unregister_netdev(dev); |
1018 | mdiobus_unregister(aup->mii_bus); | ||
1019 | mdiobus_free(aup->mii_bus); | ||
1007 | for (j = 0; j < NUM_RX_DMA; j++) | 1020 | for (j = 0; j < NUM_RX_DMA; j++) |
1008 | if (aup->rx_db_inuse[j]) | 1021 | if (aup->rx_db_inuse[j]) |
1009 | ReleaseDB(aup, aup->rx_db_inuse[j]); | 1022 | ReleaseDB(aup, aup->rx_db_inuse[j]); |