net: use netdev_mc_count and netdev_mc_empty when appropriate
[safe/jmp/linux-2.6] / drivers / net / arm / at91_ether.c
index fada15d..17d85d9 100644 (file)
@@ -32,9 +32,9 @@
 #include <asm/uaccess.h>
 #include <asm/mach-types.h>
 
-#include <asm/arch/at91rm9200_emac.h>
-#include <asm/arch/gpio.h>
-#include <asm/arch/board.h>
+#include <mach/at91rm9200_emac.h>
+#include <mach/gpio.h>
+#include <mach/board.h>
 
 #include "at91_ether.h"
 
@@ -225,6 +225,16 @@ static irqreturn_t at91ether_phy_interrupt(int irq, void *dev_id)
                if (!(phy & ((1 << 2) | 1)))
                        goto done;
        }
+       else if (lp->phy_type == MII_T78Q21x3_ID) {                     /* ack interrupt in Teridian PHY */
+               read_phy(lp->phy_address, MII_T78Q21INT_REG, &phy);
+               if (!(phy & ((1 << 2) | 1)))
+                       goto done;
+       }
+       else if (lp->phy_type == MII_DP83848_ID) {
+               read_phy(lp->phy_address, MII_DPPHYSTS_REG, &phy);      /* ack interrupt in DP83848 PHY */
+               if (!(phy & (1 << 7)))
+                       goto done;
+       }
 
        update_linkspeed(dev, 0);
 
@@ -280,6 +290,19 @@ static void enable_phyirq(struct net_device *dev)
                dsintr = (1 << 10) | ( 1 << 8);
                write_phy(lp->phy_address, MII_TPISTATUS, dsintr);
        }
+       else if (lp->phy_type == MII_T78Q21x3_ID) {     /* for Teridian PHY */
+               read_phy(lp->phy_address, MII_T78Q21INT_REG, &dsintr);
+               dsintr = dsintr | 0x500;                /* set bits 8, 10 */
+               write_phy(lp->phy_address, MII_T78Q21INT_REG, dsintr);
+       }
+       else if (lp->phy_type == MII_DP83848_ID) {      /* National Semiconductor DP83848 PHY */
+               read_phy(lp->phy_address, MII_DPMISR_REG, &dsintr);
+               dsintr = dsintr | 0x3c;                 /* set bits 2..5 */
+               write_phy(lp->phy_address, MII_DPMISR_REG, dsintr);
+               read_phy(lp->phy_address, MII_DPMICR_REG, &dsintr);
+               dsintr = dsintr | 0x3;                  /* set bits 0,1 */
+               write_phy(lp->phy_address, MII_DPMICR_REG, dsintr);
+       }
 
        disable_mdi();
        spin_unlock_irq(&lp->lock);
@@ -323,6 +346,19 @@ static void disable_phyirq(struct net_device *dev)
                dsintr = ~((1 << 10) | (1 << 8));
                write_phy(lp->phy_address, MII_TPISTATUS, dsintr);
        }
+       else if (lp->phy_type == MII_T78Q21x3_ID) {     /* for Teridian PHY */
+               read_phy(lp->phy_address, MII_T78Q21INT_REG, &dsintr);
+               dsintr = dsintr & ~0x500;                       /* clear bits 8, 10 */
+               write_phy(lp->phy_address, MII_T78Q21INT_REG, dsintr);
+       }
+       else if (lp->phy_type == MII_DP83848_ID) {      /* National Semiconductor DP83848 PHY */
+               read_phy(lp->phy_address, MII_DPMICR_REG, &dsintr);
+               dsintr = dsintr & ~0x3;                         /* clear bits 0, 1 */
+               write_phy(lp->phy_address, MII_DPMICR_REG, dsintr);
+               read_phy(lp->phy_address, MII_DPMISR_REG, &dsintr);
+               dsintr = dsintr & ~0x3c;                        /* clear bits 2..5 */
+               write_phy(lp->phy_address, MII_DPMISR_REG, dsintr);
+       }
 
        disable_mdi();
        spin_unlock_irq(&lp->lock);
@@ -348,7 +384,7 @@ static void reset_phy(struct net_device *dev)
        /* Wait until PHY reset is complete */
        do {
                read_phy(lp->phy_address, MII_BMCR, &bmcr);
-       } while (!(bmcr && BMCR_RESET));
+       } while (!(bmcr & BMCR_RESET));
 
        disable_mdi();
        spin_unlock_irq(&lp->lock);
@@ -456,9 +492,8 @@ static int set_mac_address(struct net_device *dev, void* addr)
        memcpy(dev->dev_addr, address->sa_data, dev->addr_len);
        update_mac_address(dev);
 
-       printk("%s: Setting MAC address to %02x:%02x:%02x:%02x:%02x:%02x\n", dev->name,
-               dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
-               dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
+       printk("%s: Setting MAC address to %pM\n", dev->name,
+              dev->dev_addr);
 
        return 0;
 }
@@ -528,21 +563,21 @@ static void at91ether_sethashtable(struct net_device *dev)
        mc_filter[0] = mc_filter[1] = 0;
 
        curr = dev->mc_list;
-       for (i = 0; i < dev->mc_count; i++, curr = curr->next) {
+       for (i = 0; i < netdev_mc_count(dev); i++, curr = curr->next) {
                if (!curr) break;       /* unexpected end of list */
 
                bitnr = hash_get_index(curr->dmi_addr);
                mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
        }
 
-       at91_emac_write(AT91_EMAC_HSH, mc_filter[0]);
-       at91_emac_write(AT91_EMAC_HSL, mc_filter[1]);
+       at91_emac_write(AT91_EMAC_HSL, mc_filter[0]);
+       at91_emac_write(AT91_EMAC_HSH, mc_filter[1]);
 }
 
 /*
  * Enable/Disable promiscuous and multicast modes.
  */
-static void at91ether_set_rx_mode(struct net_device *dev)
+static void at91ether_set_multicast_list(struct net_device *dev)
 {
        unsigned long cfg;
 
@@ -557,7 +592,7 @@ static void at91ether_set_rx_mode(struct net_device *dev)
                at91_emac_write(AT91_EMAC_HSH, -1);
                at91_emac_write(AT91_EMAC_HSL, -1);
                cfg |= AT91_EMAC_MTI;
-       } else if (dev->mc_count > 0) {                 /* Enable specific multicasts */
+       } else if (!netdev_mc_empty(dev)) { /* Enable specific multicasts */
                at91ether_sethashtable(dev);
                cfg |= AT91_EMAC_MTI;
        } else if (dev->flags & (~IFF_ALLMULTI)) {      /* Disable all multicast mode */
@@ -641,7 +676,7 @@ static void at91ether_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo
 {
        strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
        strlcpy(info->version, DRV_VERSION, sizeof(info->version));
-       strlcpy(info->bus_info, dev->class_dev.dev->bus_id, sizeof(info->bus_info));
+       strlcpy(info->bus_info, dev_name(dev->dev.parent), sizeof(info->bus_info));
 }
 
 static const struct ethtool_ops at91ether_ethtool_ops = {
@@ -773,7 +808,7 @@ static int at91ether_close(struct net_device *dev)
 /*
  * Transmit packet.
  */
-static int at91ether_tx(struct sk_buff *skb, struct net_device *dev)
+static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        struct at91_private *lp = netdev_priv(dev);
 
@@ -784,7 +819,7 @@ static int at91ether_tx(struct sk_buff *skb, struct net_device *dev)
                lp->skb = skb;
                lp->skb_length = skb->len;
                lp->skb_physaddr = dma_map_single(NULL, skb->data, skb->len, DMA_TO_DEVICE);
-               lp->stats.tx_bytes += skb->len;
+               dev->stats.tx_bytes += skb->len;
 
                /* Set address of the data in the Transmit Address register */
                at91_emac_write(AT91_EMAC_TAR, lp->skb_physaddr);
@@ -793,13 +828,13 @@ static int at91ether_tx(struct sk_buff *skb, struct net_device *dev)
 
                dev->trans_start = jiffies;
        } else {
-               printk(KERN_ERR "at91_ether.c: at91ether_tx() called, but device is busy!\n");
-               return 1;       /* if we return anything but zero, dev.c:1055 calls kfree_skb(skb)
+               printk(KERN_ERR "at91_ether.c: at91ether_start_xmit() called, but device is busy!\n");
+               return NETDEV_TX_BUSY;  /* if we return anything but zero, dev.c:1055 calls kfree_skb(skb)
                                on this skb, he also reports -ENETDOWN and printk's, so either
                                we free and return(0) or don't free and return 1 */
        }
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 /*
@@ -807,34 +842,33 @@ static int at91ether_tx(struct sk_buff *skb, struct net_device *dev)
  */
 static struct net_device_stats *at91ether_stats(struct net_device *dev)
 {
-       struct at91_private *lp = netdev_priv(dev);
        int ale, lenerr, seqe, lcol, ecol;
 
        if (netif_running(dev)) {
-               lp->stats.rx_packets += at91_emac_read(AT91_EMAC_OK);           /* Good frames received */
+               dev->stats.rx_packets += at91_emac_read(AT91_EMAC_OK);          /* Good frames received */
                ale = at91_emac_read(AT91_EMAC_ALE);
-               lp->stats.rx_frame_errors += ale;                               /* Alignment errors */
+               dev->stats.rx_frame_errors += ale;                              /* Alignment errors */
                lenerr = at91_emac_read(AT91_EMAC_ELR) + at91_emac_read(AT91_EMAC_USF);
-               lp->stats.rx_length_errors += lenerr;                           /* Excessive Length or Undersize Frame error */
+               dev->stats.rx_length_errors += lenerr;                          /* Excessive Length or Undersize Frame error */
                seqe = at91_emac_read(AT91_EMAC_SEQE);
-               lp->stats.rx_crc_errors += seqe;                                /* CRC error */
-               lp->stats.rx_fifo_errors += at91_emac_read(AT91_EMAC_DRFC);     /* Receive buffer not available */
-               lp->stats.rx_errors += (ale + lenerr + seqe
+               dev->stats.rx_crc_errors += seqe;                               /* CRC error */
+               dev->stats.rx_fifo_errors += at91_emac_read(AT91_EMAC_DRFC);    /* Receive buffer not available */
+               dev->stats.rx_errors += (ale + lenerr + seqe
                        + at91_emac_read(AT91_EMAC_CDE) + at91_emac_read(AT91_EMAC_RJB));
 
-               lp->stats.tx_packets += at91_emac_read(AT91_EMAC_FRA);          /* Frames successfully transmitted */
-               lp->stats.tx_fifo_errors += at91_emac_read(AT91_EMAC_TUE);      /* Transmit FIFO underruns */
-               lp->stats.tx_carrier_errors += at91_emac_read(AT91_EMAC_CSE);   /* Carrier Sense errors */
-               lp->stats.tx_heartbeat_errors += at91_emac_read(AT91_EMAC_SQEE);/* Heartbeat error */
+               dev->stats.tx_packets += at91_emac_read(AT91_EMAC_FRA);         /* Frames successfully transmitted */
+               dev->stats.tx_fifo_errors += at91_emac_read(AT91_EMAC_TUE);     /* Transmit FIFO underruns */
+               dev->stats.tx_carrier_errors += at91_emac_read(AT91_EMAC_CSE);  /* Carrier Sense errors */
+               dev->stats.tx_heartbeat_errors += at91_emac_read(AT91_EMAC_SQEE);/* Heartbeat error */
 
                lcol = at91_emac_read(AT91_EMAC_LCOL);
                ecol = at91_emac_read(AT91_EMAC_ECOL);
-               lp->stats.tx_window_errors += lcol;                     /* Late collisions */
-               lp->stats.tx_aborted_errors += ecol;                    /* 16 collisions */
+               dev->stats.tx_window_errors += lcol;                    /* Late collisions */
+               dev->stats.tx_aborted_errors += ecol;                   /* 16 collisions */
 
-               lp->stats.collisions += (at91_emac_read(AT91_EMAC_SCOL) + at91_emac_read(AT91_EMAC_MCOL) + lcol + ecol);
+               dev->stats.collisions += (at91_emac_read(AT91_EMAC_SCOL) + at91_emac_read(AT91_EMAC_MCOL) + lcol + ecol);
        }
-       return &lp->stats;
+       return &dev->stats;
 }
 
 /*
@@ -858,19 +892,17 @@ static void at91ether_rx(struct net_device *dev)
                        skb_reserve(skb, 2);
                        memcpy(skb_put(skb, pktlen), p_recv, pktlen);
 
-                       skb->dev = dev;
                        skb->protocol = eth_type_trans(skb, dev);
-                       dev->last_rx = jiffies;
-                       lp->stats.rx_bytes += pktlen;
+                       dev->stats.rx_bytes += pktlen;
                        netif_rx(skb);
                }
                else {
-                       lp->stats.rx_dropped += 1;
+                       dev->stats.rx_dropped += 1;
                        printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
                }
 
                if (dlist->descriptors[lp->rxBuffIndex].size & EMAC_MULTICAST)
-                       lp->stats.multicast++;
+                       dev->stats.multicast++;
 
                dlist->descriptors[lp->rxBuffIndex].addr &= ~EMAC_DESC_DONE;    /* reset ownership bit */
                if (lp->rxBuffIndex == MAX_RX_DESCR-1)                          /* wrap after last buffer */
@@ -899,7 +931,7 @@ static irqreturn_t at91ether_interrupt(int irq, void *dev_id)
        if (intstatus & AT91_EMAC_TCOM) {       /* Transmit complete */
                /* The TCOM bit is set even if the transmission failed. */
                if (intstatus & (AT91_EMAC_TUND | AT91_EMAC_RTRY))
-                       lp->stats.tx_errors += 1;
+                       dev->stats.tx_errors += 1;
 
                if (lp->skb) {
                        dev_kfree_skb_irq(lp->skb);
@@ -933,6 +965,21 @@ static void at91ether_poll_controller(struct net_device *dev)
 }
 #endif
 
+static const struct net_device_ops at91ether_netdev_ops = {
+       .ndo_open               = at91ether_open,
+       .ndo_stop               = at91ether_close,
+       .ndo_start_xmit         = at91ether_start_xmit,
+       .ndo_get_stats          = at91ether_stats,
+       .ndo_set_multicast_list = at91ether_set_multicast_list,
+       .ndo_set_mac_address    = set_mac_address,
+       .ndo_do_ioctl           = at91ether_ioctl,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_change_mtu         = eth_change_mtu,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller    = at91ether_poll_controller,
+#endif
+};
+
 /*
  * Initialize the ethernet interface
  */
@@ -951,7 +998,6 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add
 
        dev->base_addr = AT91_VA_BASE_EMAC;
        dev->irq = AT91RM9200_ID_EMAC;
-       SET_MODULE_OWNER(dev);
 
        /* Install the interrupt handler */
        if (request_irq(dev->irq, at91ether_interrupt, 0, dev->name, dev)) {
@@ -974,17 +1020,8 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add
        spin_lock_init(&lp->lock);
 
        ether_setup(dev);
-       dev->open = at91ether_open;
-       dev->stop = at91ether_close;
-       dev->hard_start_xmit = at91ether_tx;
-       dev->get_stats = at91ether_stats;
-       dev->set_multicast_list = at91ether_set_rx_mode;
-       dev->set_mac_address = set_mac_address;
+       dev->netdev_ops = &at91ether_netdev_ops;
        dev->ethtool_ops = &at91ether_ethtool_ops;
-       dev->do_ioctl = at91ether_ioctl;
-#ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = at91ether_poll_controller;
-#endif
 
        SET_NETDEV_DEV(dev, &pdev->dev);
 
@@ -1008,7 +1045,9 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add
        } else if (machine_is_csb337()) {
                /* mix link activity status into LED2 link state */
                write_phy(phy_address, MII_LEDCTRL_REG, 0x0d22);
-       }
+       } else if (machine_is_ecbat91())
+               write_phy(phy_address, MII_LEDCTRL_REG, 0x156A);
+
        disable_mdi();
        spin_unlock_irq(&lp->lock);
 
@@ -1044,15 +1083,15 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add
                init_timer(&lp->check_timer);
                lp->check_timer.data = (unsigned long)dev;
                lp->check_timer.function = at91ether_check_link;
-       }
+       } else if (lp->board_data.phy_irq_pin >= 32)
+               gpio_request(lp->board_data.phy_irq_pin, "ethernet_phy");
 
        /* Display ethernet banner */
-       printk(KERN_INFO "%s: AT91 ethernet at 0x%08x int=%d %s%s (%02x:%02x:%02x:%02x:%02x:%02x)\n",
-               dev->name, (uint) dev->base_addr, dev->irq,
-               at91_emac_read(AT91_EMAC_CFG) & AT91_EMAC_SPD ? "100-" : "10-",
-               at91_emac_read(AT91_EMAC_CFG) & AT91_EMAC_FD ? "FullDuplex" : "HalfDuplex",
-               dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
-               dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
+       printk(KERN_INFO "%s: AT91 ethernet at 0x%08x int=%d %s%s (%pM)\n",
+              dev->name, (uint) dev->base_addr, dev->irq,
+              at91_emac_read(AT91_EMAC_CFG) & AT91_EMAC_SPD ? "100-" : "10-",
+              at91_emac_read(AT91_EMAC_CFG) & AT91_EMAC_FD ? "FullDuplex" : "HalfDuplex",
+              dev->dev_addr);
        if ((phy_type == MII_DM9161_ID) || (lp->phy_type == MII_DM9161A_ID))
                printk(KERN_INFO "%s: Davicom 9161 PHY %s\n", dev->name, (lp->phy_media == PORT_FIBRE) ? "(Fiber)" : "(Copper)");
        else if (phy_type == MII_LXT971A_ID)
@@ -1063,10 +1102,16 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add
                printk(KERN_INFO "%s: Broadcom BCM5221 PHY\n", dev->name);
        else if (phy_type == MII_DP83847_ID)
                printk(KERN_INFO "%s: National Semiconductor DP83847 PHY\n", dev->name);
+       else if (phy_type == MII_DP83848_ID)
+               printk(KERN_INFO "%s: National Semiconductor DP83848 PHY\n", dev->name);
        else if (phy_type == MII_AC101L_ID)
                printk(KERN_INFO "%s: Altima AC101L PHY\n", dev->name);
        else if (phy_type == MII_KS8721_ID)
                printk(KERN_INFO "%s: Micrel KS8721 PHY\n", dev->name);
+       else if (phy_type == MII_T78Q21x3_ID)
+               printk(KERN_INFO "%s: Teridian 78Q21x3 PHY\n", dev->name);
+       else if (phy_type == MII_LAN83C185_ID)
+               printk(KERN_INFO "%s: SMSC LAN83C185 PHY\n", dev->name);
 
        return 0;
 }
@@ -1104,8 +1149,11 @@ static int __init at91ether_probe(struct platform_device *pdev)
                        case MII_RTL8201_ID:            /* Realtek RTL8201: PHY_ID1 = 0, PHY_ID2 = 0x8201 */
                        case MII_BCM5221_ID:            /* Broadcom BCM5221: PHY_ID1 = 0x40, PHY_ID2 = 0x61e0 */
                        case MII_DP83847_ID:            /* National Semiconductor DP83847:  */
+                       case MII_DP83848_ID:            /* National Semiconductor DP83848:  */
                        case MII_AC101L_ID:             /* Altima AC101L: PHY_ID1 = 0x22, PHY_ID2 = 0x5520 */
                        case MII_KS8721_ID:             /* Micrel KS8721: PHY_ID1 = 0x22, PHY_ID2 = 0x1610 */
+                       case MII_T78Q21x3_ID:           /* Teridian 78Q21x3: PHY_ID1 = 0x0E, PHY_ID2 = 7237 */
+                       case MII_LAN83C185_ID:          /* SMSC LAN83C185: PHY_ID1 = 0x0007, PHY_ID2 = 0xC0A1 */
                                detected = at91ether_setup(phy_id, phy_address, pdev, ether_clk);
                                break;
                }
@@ -1123,6 +1171,9 @@ static int __devexit at91ether_remove(struct platform_device *pdev)
        struct net_device *dev = platform_get_drvdata(pdev);
        struct at91_private *lp = netdev_priv(dev);
 
+       if (lp->board_data.phy_irq_pin >= 32)
+               gpio_free(lp->board_data.phy_irq_pin);
+
        unregister_netdev(dev);
        free_irq(dev->irq, dev);
        dma_free_coherent(NULL, sizeof(struct recv_desc_bufs), lp->dlist, (dma_addr_t)lp->dlist_phys);
@@ -1177,7 +1228,6 @@ static int at91ether_resume(struct platform_device *pdev)
 #endif
 
 static struct platform_driver at91ether_driver = {
-       .probe          = at91ether_probe,
        .remove         = __devexit_p(at91ether_remove),
        .suspend        = at91ether_suspend,
        .resume         = at91ether_resume,
@@ -1189,7 +1239,7 @@ static struct platform_driver at91ether_driver = {
 
 static int __init at91ether_init(void)
 {
-       return platform_driver_register(&at91ether_driver);
+       return platform_driver_probe(&at91ether_driver, at91ether_probe);
 }
 
 static void __exit at91ether_exit(void)
@@ -1203,3 +1253,4 @@ module_exit(at91ether_exit)
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("AT91RM9200 EMAC Ethernet driver");
 MODULE_AUTHOR("Andrew Victor");
+MODULE_ALIAS("platform:" DRV_NAME);