net/au1000_eth.c MDIO namespace fixes
[safe/jmp/linux-2.6] / drivers / net / au1000_eth.c
index 97b55f2..019b13c 100644 (file)
@@ -34,7 +34,7 @@
  *
  *
  */
-
+#include <linux/dma-mapping.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
@@ -45,7 +45,6 @@
 #include <linux/bitops.h>
 #include <linux/slab.h>
 #include <linux/interrupt.h>
-#include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/delay.h>
 #include <linux/crc32.h>
 #include <linux/phy.h>
+
+#include <asm/cpu.h>
 #include <asm/mipsregs.h>
 #include <asm/irq.h>
 #include <asm/io.h>
 #include <asm/processor.h>
 
-#include <asm/mach-au1x00/au1000.h>
-#include <asm/cpu.h>
+#include <au1000.h>
+#include <prom.h>
+
 #include "au1000_eth.h"
 
 #ifdef AU1000_ETH_DEBUG
@@ -91,18 +93,12 @@ static int au1000_rx(struct net_device *);
 static irqreturn_t au1000_interrupt(int, void *);
 static void au1000_tx_timeout(struct net_device *);
 static void set_rx_mode(struct net_device *);
-static struct net_device_stats *au1000_get_stats(struct net_device *);
 static int au1000_ioctl(struct net_device *, struct ifreq *, int);
-static int mdio_read(struct net_device *, int, int);
-static void mdio_write(struct net_device *, int, int, u16);
+static int au1000_mdio_read(struct net_device *, int, int);
+static void au1000_mdio_write(struct net_device *, int, int, u16);
 static void au1000_adjust_link(struct net_device *);
 static void enable_mac(struct net_device *, int);
 
-// externs
-extern int get_ethernet_addr(char *ethernet_addr);
-extern void str2eaddr(unsigned char *ea, unsigned char *str);
-extern char * prom_getcmdline(void);
-
 /*
  * Theory of operation
  *
@@ -195,7 +191,7 @@ struct au1000_private *au_macs[NUM_ETH_INTERFACES];
 /*
  * MII operations
  */
-static int mdio_read(struct net_device *dev, int phy_addr, int reg)
+static int au1000_mdio_read(struct net_device *dev, int phy_addr, int reg)
 {
        struct au1000_private *aup = (struct au1000_private *) dev->priv;
        volatile u32 *const mii_control_reg = &aup->mac->mii_control;
@@ -229,7 +225,8 @@ static int mdio_read(struct net_device *dev, int phy_addr, int reg)
        return (int)*mii_data_reg;
 }
 
-static void mdio_write(struct net_device *dev, int phy_addr, int reg, u16 value)
+static void au1000_mdio_write(struct net_device *dev, int phy_addr,
+                             int reg, u16 value)
 {
        struct au1000_private *aup = (struct au1000_private *) dev->priv;
        volatile u32 *const mii_control_reg = &aup->mac->mii_control;
@@ -253,7 +250,7 @@ static void mdio_write(struct net_device *dev, int phy_addr, int reg, u16 value)
        *mii_control_reg = mii_control;
 }
 
-static int mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum)
+static int au1000_mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum)
 {
        /* WARNING: bus->phy_map[phy_addr].attached_dev == dev does
         * _NOT_ hold (e.g. when PHY is accessed through other MAC's MII bus) */
@@ -261,21 +258,21 @@ static int mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum)
 
        enable_mac(dev, 0); /* make sure the MAC associated with this
                             * mii_bus is enabled */
-       return mdio_read(dev, phy_addr, regnum);
+       return au1000_mdio_read(dev, phy_addr, regnum);
 }
 
-static int mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum,
-                        u16 value)
+static int au1000_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum,
+                               u16 value)
 {
        struct net_device *const dev = bus->priv;
 
        enable_mac(dev, 0); /* make sure the MAC associated with this
                             * mii_bus is enabled */
-       mdio_write(dev, phy_addr, regnum, value);
+       au1000_mdio_write(dev, phy_addr, regnum, value);
        return 0;
 }
 
-static int mdiobus_reset(struct mii_bus *bus)
+static int au1000_mdiobus_reset(struct mii_bus *bus)
 {
        struct net_device *const dev = bus->priv;
 
@@ -294,7 +291,7 @@ static int mii_probe (struct net_device *dev)
 
        if(aup->mac_id == 0) { /* get PHY0 */
 # if defined(AU1XXX_PHY0_ADDR)
-               phydev = au_macs[AU1XXX_PHY0_BUSID]->mii_bus.phy_map[AU1XXX_PHY0_ADDR];
+               phydev = au_macs[AU1XXX_PHY0_BUSID]->mii_bus->phy_map[AU1XXX_PHY0_ADDR];
 # else
                printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n",
                        dev->name);
@@ -302,7 +299,7 @@ static int mii_probe (struct net_device *dev)
 # endif /* defined(AU1XXX_PHY0_ADDR) */
        } else if (aup->mac_id == 1) { /* get PHY1 */
 # if defined(AU1XXX_PHY1_ADDR)
-               phydev = au_macs[AU1XXX_PHY1_BUSID]->mii_bus.phy_map[AU1XXX_PHY1_ADDR];
+               phydev = au_macs[AU1XXX_PHY1_BUSID]->mii_bus->phy_map[AU1XXX_PHY1_ADDR];
 # else
                printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n",
                        dev->name);
@@ -315,8 +312,8 @@ static int mii_probe (struct net_device *dev)
 
        /* find the first (lowest address) PHY on the current MAC's MII bus */
        for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++)
-               if (aup->mii_bus.phy_map[phy_addr]) {
-                       phydev = aup->mii_bus.phy_map[phy_addr];
+               if (aup->mii_bus->phy_map[phy_addr]) {
+                       phydev = aup->mii_bus->phy_map[phy_addr];
 # if !defined(AU1XXX_PHY_SEARCH_HIGHEST_ADDR)
                        break; /* break out with first one found */
 # endif
@@ -335,7 +332,7 @@ static int mii_probe (struct net_device *dev)
                 * the MAC0 MII bus */
                for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
                        struct phy_device *const tmp_phydev =
-                               au_macs[0]->mii_bus.phy_map[phy_addr];
+                               au_macs[0]->mii_bus->phy_map[phy_addr];
 
                        if (!tmp_phydev)
                                continue; /* no PHY here... */
@@ -546,7 +543,7 @@ static struct {
 static int num_ifs;
 
 /*
- * Setup the base address and interupt of the Au1xxx ethernet macs
+ * Setup the base address and interrupt of the Au1xxx ethernet macs
  * based on cpu type and whether the interface is enabled in sys_pinfunc
  * register. The last interface is enabled if SYS_PF_NI2 (bit 4) is 0.
  */
@@ -621,7 +618,6 @@ static struct net_device * au1000_probe(int port_num)
        struct au1000_private *aup = NULL;
        struct net_device *dev = NULL;
        db_dest_t *pDB, *pDBfree;
-       char *pmac, *argptr;
        char ethaddr[6];
        int irq, i, err;
        u32 base, macen;
@@ -658,6 +654,8 @@ static struct net_device * au1000_probe(int port_num)
 
        aup = dev->priv;
 
+       spin_lock_init(&aup->lock);
+
        /* Allocate the data buffers */
        /* Snooping works fine with eth on all au1xxx */
        aup->vaddr = (u32)dma_alloc_noncoherent(NULL, MAX_BUF_SIZE *
@@ -679,21 +677,12 @@ static struct net_device * au1000_probe(int port_num)
        au_macs[port_num] = aup;
 
        if (port_num == 0) {
-               /* Check the environment variables first */
-               if (get_ethernet_addr(ethaddr) == 0)
+               if (prom_get_ethernet_addr(ethaddr) == 0)
                        memcpy(au1000_mac_addr, ethaddr, sizeof(au1000_mac_addr));
                else {
-                       /* Check command line */
-                       argptr = prom_getcmdline();
-                       if ((pmac = strstr(argptr, "ethaddr=")) == NULL)
-                               printk(KERN_INFO "%s: No MAC address found\n",
-                                                dev->name);
+                       printk(KERN_INFO "%s: No MAC address found\n",
+                                        dev->name);
                                /* Use the hard coded MAC addresses */
-                       else {
-                               str2eaddr(ethaddr, pmac + strlen("ethaddr="));
-                               memcpy(au1000_mac_addr, ethaddr,
-                                      sizeof(au1000_mac_addr));
-                       }
                }
 
                setup_hw_rings(aup, MAC0_RX_DMA_ADDR, MAC0_TX_DMA_ADDR);
@@ -710,28 +699,32 @@ static struct net_device * au1000_probe(int port_num)
        *aup->enable = 0;
        aup->mac_enabled = 0;
 
-       aup->mii_bus.priv = dev;
-       aup->mii_bus.read = mdiobus_read;
-       aup->mii_bus.write = mdiobus_write;
-       aup->mii_bus.reset = mdiobus_reset;
-       aup->mii_bus.name = "au1000_eth_mii";
-       aup->mii_bus.id = aup->mac_id;
-       aup->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
+       aup->mii_bus = mdiobus_alloc();
+       if (aup->mii_bus == NULL)
+               goto err_out;
+
+       aup->mii_bus->priv = dev;
+       aup->mii_bus->read = au1000_mdiobus_read;
+       aup->mii_bus->write = au1000_mdiobus_write;
+       aup->mii_bus->reset = au1000_mdiobus_reset;
+       aup->mii_bus->name = "au1000_eth_mii";
+       snprintf(aup->mii_bus->id, MII_BUS_ID_SIZE, "%x", aup->mac_id);
+       aup->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
        for(i = 0; i < PHY_MAX_ADDR; ++i)
-               aup->mii_bus.irq[i] = PHY_POLL;
+               aup->mii_bus->irq[i] = PHY_POLL;
 
        /* if known, set corresponding PHY IRQs */
 #if defined(AU1XXX_PHY_STATIC_CONFIG)
 # if defined(AU1XXX_PHY0_IRQ)
-       if (AU1XXX_PHY0_BUSID == aup->mii_bus.id)
-               aup->mii_bus.irq[AU1XXX_PHY0_ADDR] = AU1XXX_PHY0_IRQ;
+       if (AU1XXX_PHY0_BUSID == aup->mac_id)
+               aup->mii_bus->irq[AU1XXX_PHY0_ADDR] = AU1XXX_PHY0_IRQ;
 # endif
 # if defined(AU1XXX_PHY1_IRQ)
-       if (AU1XXX_PHY1_BUSID == aup->mii_bus.id)
-               aup->mii_bus.irq[AU1XXX_PHY1_ADDR] = AU1XXX_PHY1_IRQ;
+       if (AU1XXX_PHY1_BUSID == aup->mac_id)
+               aup->mii_bus->irq[AU1XXX_PHY1_ADDR] = AU1XXX_PHY1_IRQ;
 # endif
 #endif
-       mdiobus_register(&aup->mii_bus);
+       mdiobus_register(aup->mii_bus);
 
        if (mii_probe(dev) != 0) {
                goto err_out;
@@ -767,13 +760,11 @@ static struct net_device * au1000_probe(int port_num)
                aup->tx_db_inuse[i] = pDB;
        }
 
-       spin_lock_init(&aup->lock);
        dev->base_addr = base;
        dev->irq = irq;
        dev->open = au1000_open;
        dev->hard_start_xmit = au1000_tx;
        dev->stop = au1000_close;
-       dev->get_stats = au1000_get_stats;
        dev->set_multicast_list = &set_rx_mode;
        dev->do_ioctl = &au1000_ioctl;
        SET_ETHTOOL_OPS(dev, &au1000_ethtool_ops);
@@ -789,6 +780,11 @@ static struct net_device * au1000_probe(int port_num)
        return dev;
 
 err_out:
+       if (aup->mii_bus != NULL) {
+               mdiobus_unregister(aup->mii_bus);
+               mdiobus_free(aup->mii_bus);
+       }
+
        /* here we should have a valid dev plus aup-> register addresses
         * so we can reset the mac properly.*/
        reset_mac(dev);
@@ -822,7 +818,7 @@ err_out:
 static int au1000_init(struct net_device *dev)
 {
        struct au1000_private *aup = (struct au1000_private *) dev->priv;
-       u32 flags;
+       unsigned long flags;
        int i;
        u32 control;
 
@@ -926,9 +922,8 @@ au1000_adjust_link(struct net_device *dev)
        if(phydev->link != aup->old_link) {
                // link state changed
 
-               if (phydev->link) // link went up
-                       netif_schedule(dev);
-               else { // link went down
+               if (!phydev->link) {
+                       /* link went down */
                        aup->old_speed = 0;
                        aup->old_duplex = -1;
                }
@@ -1020,6 +1015,8 @@ static void __exit au1000_cleanup_module(void)
                if (dev) {
                        aup = (struct au1000_private *) dev->priv;
                        unregister_netdev(dev);
+                       mdiobus_unregister(aup->mii_bus);
+                       mdiobus_free(aup->mii_bus);
                        for (j = 0; j < NUM_RX_DMA; j++)
                                if (aup->rx_db_inuse[j])
                                        ReleaseDB(aup, aup->rx_db_inuse[j]);
@@ -1039,7 +1036,7 @@ static void __exit au1000_cleanup_module(void)
 static void update_tx_stats(struct net_device *dev, u32 status)
 {
        struct au1000_private *aup = (struct au1000_private *) dev->priv;
-       struct net_device_stats *ps = &aup->stats;
+       struct net_device_stats *ps = &dev->stats;
 
        if (status & TX_FRAME_ABORTED) {
                if (!aup->phy_dev || (DUPLEX_FULL == aup->phy_dev->duplex)) {
@@ -1095,7 +1092,7 @@ static void au1000_tx_ack(struct net_device *dev)
 static int au1000_tx(struct sk_buff *skb, struct net_device *dev)
 {
        struct au1000_private *aup = (struct au1000_private *) dev->priv;
-       struct net_device_stats *ps = &aup->stats;
+       struct net_device_stats *ps = &dev->stats;
        volatile tx_dma_t *ptxd;
        u32 buff_stat;
        db_dest_t *pDB;
@@ -1125,7 +1122,7 @@ static int au1000_tx(struct sk_buff *skb, struct net_device *dev)
        }
 
        pDB = aup->tx_db_inuse[aup->tx_head];
-       memcpy((void *)pDB->vaddr, skb->data, skb->len);
+       skb_copy_from_linear_data(skb, pDB->vaddr, skb->len);
        if (skb->len < ETH_ZLEN) {
                for (i=skb->len; i<ETH_ZLEN; i++) {
                        ((char *)pDB->vaddr)[i] = 0;
@@ -1149,7 +1146,7 @@ static int au1000_tx(struct sk_buff *skb, struct net_device *dev)
 static inline void update_rx_stats(struct net_device *dev, u32 status)
 {
        struct au1000_private *aup = (struct au1000_private *) dev->priv;
-       struct net_device_stats *ps = &aup->stats;
+       struct net_device_stats *ps = &dev->stats;
 
        ps->rx_packets++;
        if (status & RX_MCAST_FRAME)
@@ -1202,12 +1199,12 @@ static int au1000_rx(struct net_device *dev)
                                printk(KERN_ERR
                                       "%s: Memory squeeze, dropping packet.\n",
                                       dev->name);
-                               aup->stats.rx_dropped++;
+                               dev->stats.rx_dropped++;
                                continue;
                        }
                        skb_reserve(skb, 2);    /* 16 byte IP header align */
-                       eth_copy_and_sum(skb,
-                               (unsigned char *)pDB->vaddr, frmlen, 0);
+                       skb_copy_to_linear_data(skb,
+                               (unsigned char *)pDB->vaddr, frmlen);
                        skb_put(skb, frmlen);
                        skb->protocol = eth_type_trans(skb, dev);
                        netif_rx(skb);  /* pass the packet to upper layers */
@@ -1254,12 +1251,7 @@ static int au1000_rx(struct net_device *dev)
  */
 static irqreturn_t au1000_interrupt(int irq, void *dev_id)
 {
-       struct net_device *dev = (struct net_device *) dev_id;
-
-       if (dev == NULL) {
-               printk(KERN_ERR "%s: isr: null dev ptr\n", dev->name);
-               return IRQ_RETVAL(1);
-       }
+       struct net_device *dev = dev_id;
 
        /* Handle RX interrupts first to minimize chance of overrun */
 
@@ -1325,18 +1317,5 @@ static int au1000_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        return phy_mii_ioctl(aup->phy_dev, if_mii(rq), cmd);
 }
 
-static struct net_device_stats *au1000_get_stats(struct net_device *dev)
-{
-       struct au1000_private *aup = (struct au1000_private *) dev->priv;
-
-       if (au1000_debug > 4)
-               printk("%s: au1000_get_stats: dev=%p\n", dev->name, dev);
-
-       if (netif_device_present(dev)) {
-               return &aup->stats;
-       }
-       return 0;
-}
-
 module_init(au1000_init_module);
 module_exit(au1000_cleanup_module);