[SPARC64]: Fix MODULE_DEVICE_TABLE() specification in VDC and VNET.
[safe/jmp/linux-2.6] / drivers / net / ns83820.c
index d0ed864..ea80e6c 100644 (file)
@@ -65,7 +65,7 @@
  *                     0.20 -  fix stupid RFEN thinko.  i am such a smurf.
  *     20040828        0.21 -  add hardware vlan accleration
  *                             by Neil Horman <nhorman@redhat.com>
- *     20050406        0.22 -  improved DAC ifdefs from Andi Kleen     
+ *     20050406        0.22 -  improved DAC ifdefs from Andi Kleen
  *                          -  removal of dead code from Adrian Bunk
  *                          -  fix half duplex collision behaviour
  * Driver Overview
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/delay.h>
-#include <linux/smp_lock.h>
 #include <linux/workqueue.h>
 #include <linux/init.h>
 #include <linux/ip.h>  /* for iph */
@@ -377,7 +376,7 @@ static int lnksts = 0;              /* CFG_LNKSTS bit polarity */
 #define LINK_DOWN              0x02
 #define LINK_UP                        0x04
 
-#define HW_ADDR_LEN    sizeof(dma_addr_t) 
+#define HW_ADDR_LEN    sizeof(dma_addr_t)
 #define desc_addr_set(desc, addr)                              \
        do {                                                    \
                ((desc)[0] = cpu_to_le32(addr));                \
@@ -414,10 +413,10 @@ struct rx_info {
 
        struct sk_buff  *skbs[NR_RX_DESC];
 
-       u32             *next_rx_desc;
+       __le32          *next_rx_desc;
        u16             next_rx, next_empty;
 
-       u32             *descs;
+       __le32          *descs;
        dma_addr_t      phy_descs;
 };
 
@@ -427,6 +426,7 @@ struct ns83820 {
        u8                      __iomem *base;
 
        struct pci_dev          *pci_dev;
+       struct net_device       *ndev;
 
 #ifdef NS83820_VLAN_ACCEL_SUPPORT
        struct vlan_group       *vlgrp;
@@ -459,7 +459,7 @@ struct ns83820 {
        struct sk_buff  *tx_skbs[NR_TX_DESC];
 
        char            pad[16] __attribute__((aligned(16)));
-       u32             *tx_descs;
+       __le32          *tx_descs;
        dma_addr_t      tx_phy_descs;
 
        struct timer_list       tx_watchdog;
@@ -493,7 +493,7 @@ static inline void kick_rx(struct net_device *ndev)
        (((NR_TX_DESC-2 + dev->tx_done_idx - dev->tx_free_idx) % NR_TX_DESC) > MIN_TX_DESC_FREE)
 
 
-#ifdef NS83820_VLAN_ACCEL_SUPPORT 
+#ifdef NS83820_VLAN_ACCEL_SUPPORT
 static void ns83820_vlan_rx_register(struct net_device *ndev, struct vlan_group *grp)
 {
        struct ns83820 *dev = PRIV(ndev);
@@ -506,18 +506,6 @@ static void ns83820_vlan_rx_register(struct net_device *ndev, struct vlan_group
        spin_unlock(&dev->tx_lock);
        spin_unlock_irq(&dev->misc_lock);
 }
-
-static void ns83820_vlan_rx_kill_vid(struct net_device *ndev, unsigned short vid)
-{
-       struct ns83820 *dev = PRIV(ndev);
-
-       spin_lock_irq(&dev->misc_lock);
-       spin_lock(&dev->tx_lock);
-       if (dev->vlgrp)
-               dev->vlgrp->vlan_devices[vid] = NULL;
-       spin_unlock(&dev->tx_lock);
-       spin_unlock_irq(&dev->misc_lock);
-}
 #endif
 
 /* Packet Receiver
@@ -533,7 +521,7 @@ static void ns83820_vlan_rx_kill_vid(struct net_device *ndev, unsigned short vid
  * conditions, still route realtime traffic with as low jitter as
  * possible.
  */
-static inline void build_rx_desc(struct ns83820 *dev, u32 *desc, dma_addr_t link, dma_addr_t buf, u32 cmdsts, u32 extsts)
+static inline void build_rx_desc(struct ns83820 *dev, __le32 *desc, dma_addr_t link, dma_addr_t buf, u32 cmdsts, u32 extsts)
 {
        desc_addr_set(desc + DESC_LINK, link);
        desc_addr_set(desc + DESC_BUFPTR, buf);
@@ -547,7 +535,7 @@ static inline int ns83820_add_rx_skb(struct ns83820 *dev, struct sk_buff *skb)
 {
        unsigned next_empty;
        u32 cmdsts;
-       u32 *sg;
+       __le32 *sg;
        dma_addr_t buf;
 
        next_empty = dev->rx_info.next_empty;
@@ -607,7 +595,6 @@ static inline int rx_refill(struct net_device *ndev, gfp_t gfp)
                res &= 0xf;
                skb_reserve(skb, res);
 
-               skb->dev = ndev;
                if (gfp != GFP_ATOMIC)
                        spin_lock_irqsave(&dev->rx_info.lock, flags);
                res = ns83820_add_rx_skb(dev, skb);
@@ -631,10 +618,10 @@ static void fastcall rx_refill_atomic(struct net_device *ndev)
 }
 
 /* REFILL */
-static inline void queue_refill(void *_dev)
+static inline void queue_refill(struct work_struct *work)
 {
-       struct net_device *ndev = _dev;
-       struct ns83820 *dev = PRIV(ndev);
+       struct ns83820 *dev = container_of(work, struct ns83820, tq_refill);
+       struct net_device *ndev = dev->ndev;
 
        rx_refill(ndev, GFP_KERNEL);
        if (dev->rx_info.up)
@@ -803,7 +790,7 @@ static int ns83820_setup_rx(struct net_device *ndev)
 
                writel(dev->IMR_cache, dev->base + IMR);
                writel(1, dev->base + IER);
-               spin_unlock_irq(&dev->misc_lock);
+               spin_unlock(&dev->misc_lock);
 
                kick_rx(ndev);
 
@@ -865,7 +852,7 @@ static void fastcall ns83820_rx_kick(struct net_device *ndev)
 }
 
 /* rx_irq
- *     
+ *
  */
 static void FASTCALL(rx_irq(struct net_device *ndev));
 static void fastcall rx_irq(struct net_device *ndev)
@@ -874,7 +861,8 @@ static void fastcall rx_irq(struct net_device *ndev)
        struct rx_info *info = &dev->rx_info;
        unsigned next_rx;
        int rx_rc, len;
-       u32 cmdsts, *desc;
+       u32 cmdsts;
+       __le32 *desc;
        unsigned long flags;
        int nr = 0;
 
@@ -921,14 +909,14 @@ static void fastcall rx_irq(struct net_device *ndev)
                 * that are 64 bytes with a vlan header appended
                 * like arp frames, or pings, are flagged as Runts
                 * when the tag is stripped and hardware.  This
-                * also means that the OK bit in the descriptor 
+                * also means that the OK bit in the descriptor
                 * is cleared when the frame comes in so we have
                 * to do a specific length check here to make sure
                 * the frame would have been ok, had we not stripped
                 * the tag.
-                */ 
+                */
                if (likely((CMDSTS_OK & cmdsts) ||
-                       ((cmdsts & CMDSTS_RUNT) && len >= 56))) {   
+                       ((cmdsts & CMDSTS_RUNT) && len >= 56))) {
 #else
                if (likely(CMDSTS_OK & cmdsts)) {
 #endif
@@ -945,7 +933,7 @@ static void fastcall rx_irq(struct net_device *ndev)
                                skb->ip_summed = CHECKSUM_NONE;
                        }
                        skb->protocol = eth_type_trans(skb, ndev);
-#ifdef NS83820_VLAN_ACCEL_SUPPORT 
+#ifdef NS83820_VLAN_ACCEL_SUPPORT
                        if(extsts & EXTSTS_VPKT) {
                                unsigned short tag;
                                tag = ntohs(extsts & EXTSTS_VTG_MASK);
@@ -1010,9 +998,8 @@ static inline void kick_tx(struct ns83820 *dev)
 static void do_tx_done(struct net_device *ndev)
 {
        struct ns83820 *dev = PRIV(ndev);
-       u32 cmdsts, tx_done_idx, *desc;
-
-       spin_lock_irq(&dev->tx_lock);
+       u32 cmdsts, tx_done_idx;
+       __le32 *desc;
 
        dprintk("do_tx_done(%p)\n", ndev);
        tx_done_idx = dev->tx_done_idx;
@@ -1049,7 +1036,7 @@ static void do_tx_done(struct net_device *ndev)
                        dev_kfree_skb_irq(skb);
                        atomic_dec(&dev->nr_tx_skbs);
                } else
-                       pci_unmap_page(dev->pci_dev, 
+                       pci_unmap_page(dev->pci_dev,
                                        addr,
                                        len,
                                        PCI_DMA_TODEVICE);
@@ -1069,7 +1056,6 @@ static void do_tx_done(struct net_device *ndev)
                netif_start_queue(ndev);
                netif_wake_queue(ndev);
        }
-       spin_unlock_irq(&dev->tx_lock);
 }
 
 static void ns83820_cleanup_tx(struct ns83820 *dev)
@@ -1080,7 +1066,7 @@ static void ns83820_cleanup_tx(struct ns83820 *dev)
                struct sk_buff *skb = dev->tx_skbs[i];
                dev->tx_skbs[i] = NULL;
                if (skb) {
-                       u32 *desc = dev->tx_descs + (i * DESC_SIZE);
+                       __le32 *desc = dev->tx_descs + (i * DESC_SIZE);
                        pci_unmap_single(dev->pci_dev,
                                        desc_addr_get(desc + DESC_BUFPTR),
                                        le32_to_cpu(desc[DESC_CMDSTS]) & CMDSTS_LEN_MASK,
@@ -1110,7 +1096,7 @@ static int ns83820_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
        skb_frag_t *frag;
        int stopped = 0;
        int do_intr = 0;
-       volatile u32 *first_desc;
+       volatile __le32 *first_desc;
 
        dprintk("ns83820_hard_start_xmit\n");
 
@@ -1156,11 +1142,11 @@ again:
        if (!nr_frags)
                frag = NULL;
        extsts = 0;
-       if (skb->ip_summed == CHECKSUM_HW) {
+       if (skb->ip_summed == CHECKSUM_PARTIAL) {
                extsts |= EXTSTS_IPPKT;
-               if (IPPROTO_TCP == skb->nh.iph->protocol)
+               if (IPPROTO_TCP == ip_hdr(skb)->protocol)
                        extsts |= EXTSTS_TCPPKT;
-               else if (IPPROTO_UDP == skb->nh.iph->protocol)
+               else if (IPPROTO_UDP == ip_hdr(skb)->protocol)
                        extsts |= EXTSTS_UDPPKT;
        }
 
@@ -1183,7 +1169,7 @@ again:
        first_desc = dev->tx_descs + (free_idx * DESC_SIZE);
 
        for (;;) {
-               volatile u32 *desc = dev->tx_descs + (free_idx * DESC_SIZE);
+               volatile __le32 *desc = dev->tx_descs + (free_idx * DESC_SIZE);
 
                dprintk("frag[%3u]: %4u @ 0x%08Lx\n", free_idx, len,
                        (unsigned long long)buf);
@@ -1276,20 +1262,22 @@ static u32 ns83820_get_link(struct net_device *ndev)
        return cfg & CFG_LNKSTS ? 1 : 0;
 }
 
-static struct ethtool_ops ops = {
+static const struct ethtool_ops ops = {
        .get_drvinfo = ns83820_get_drvinfo,
        .get_link = ns83820_get_link
 };
 
+/* this function is called in irq context from the ISR */
 static void ns83820_mib_isr(struct ns83820 *dev)
 {
-       spin_lock(&dev->misc_lock);
+       unsigned long flags;
+       spin_lock_irqsave(&dev->misc_lock, flags);
        ns83820_update_stats(dev);
-       spin_unlock(&dev->misc_lock);
+       spin_unlock_irqrestore(&dev->misc_lock, flags);
 }
 
 static void ns83820_do_isr(struct net_device *ndev, u32 isr);
-static irqreturn_t ns83820_irq(int foo, void *data, struct pt_regs *regs)
+static irqreturn_t ns83820_irq(int foo, void *data)
 {
        struct net_device *ndev = data;
        struct ns83820 *dev = PRIV(ndev);
@@ -1307,6 +1295,8 @@ static irqreturn_t ns83820_irq(int foo, void *data, struct pt_regs *regs)
 static void ns83820_do_isr(struct net_device *ndev, u32 isr)
 {
        struct ns83820 *dev = PRIV(ndev);
+       unsigned long flags;
+
 #ifdef DEBUG
        if (isr & ~(ISR_PHY | ISR_RXDESC | ISR_RXEARLY | ISR_RXOK | ISR_RXERR | ISR_TXIDLE | ISR_TXOK | ISR_TXDESC))
                Dprintk("odd isr? 0x%08x\n", isr);
@@ -1321,10 +1311,10 @@ static void ns83820_do_isr(struct net_device *ndev, u32 isr)
        if ((ISR_RXDESC | ISR_RXOK) & isr) {
                prefetch(dev->rx_info.next_rx_desc);
 
-               spin_lock_irq(&dev->misc_lock);
+               spin_lock_irqsave(&dev->misc_lock, flags);
                dev->IMR_cache &= ~(ISR_RXDESC | ISR_RXOK);
                writel(dev->IMR_cache, dev->base + IMR);
-               spin_unlock_irq(&dev->misc_lock);
+               spin_unlock_irqrestore(&dev->misc_lock, flags);
 
                tasklet_schedule(&dev->rx_tasklet);
                //rx_irq(ndev);
@@ -1358,8 +1348,8 @@ static void ns83820_do_isr(struct net_device *ndev, u32 isr)
                        dev->tx_idx = 0;
                }
                /* The may have been a race between a pci originated read
-                * and the descriptor update from the cpu.  Just in case, 
-                * kick the transmitter if the hardware thinks it is on a 
+                * and the descriptor update from the cpu.  Just in case,
+                * kick the transmitter if the hardware thinks it is on a
                 * different descriptor than we are.
                 */
                if (dev->tx_idx != dev->tx_free_idx)
@@ -1370,30 +1360,32 @@ static void ns83820_do_isr(struct net_device *ndev, u32 isr)
         * work has accumulated
         */
        if ((ISR_TXDESC | ISR_TXIDLE | ISR_TXOK | ISR_TXERR) & isr) {
+               spin_lock_irqsave(&dev->tx_lock, flags);
                do_tx_done(ndev);
+               spin_unlock_irqrestore(&dev->tx_lock, flags);
 
                /* Disable TxOk if there are no outstanding tx packets.
                 */
                if ((dev->tx_done_idx == dev->tx_free_idx) &&
                    (dev->IMR_cache & ISR_TXOK)) {
-                       spin_lock_irq(&dev->misc_lock);
+                       spin_lock_irqsave(&dev->misc_lock, flags);
                        dev->IMR_cache &= ~ISR_TXOK;
                        writel(dev->IMR_cache, dev->base + IMR);
-                       spin_unlock_irq(&dev->misc_lock);
+                       spin_unlock_irqrestore(&dev->misc_lock, flags);
                }
        }
 
        /* The TxIdle interrupt can come in before the transmit has
         * completed.  Normally we reap packets off of the combination
-        * of TxDesc and TxIdle and leave TxOk disabled (since it 
-        * occurs on every packet), but when no further irqs of this 
+        * of TxDesc and TxIdle and leave TxOk disabled (since it
+        * occurs on every packet), but when no further irqs of this
         * nature are expected, we must enable TxOk.
         */
        if ((ISR_TXIDLE & isr) && (dev->tx_done_idx != dev->tx_free_idx)) {
-               spin_lock_irq(&dev->misc_lock);
+               spin_lock_irqsave(&dev->misc_lock, flags);
                dev->IMR_cache |= ISR_TXOK;
                writel(dev->IMR_cache, dev->base + IMR);
-               spin_unlock_irq(&dev->misc_lock);
+               spin_unlock_irqrestore(&dev->misc_lock, flags);
        }
 
        /* MIB interrupt: one of the statistics counters is about to overflow */
@@ -1452,10 +1444,11 @@ static int ns83820_stop(struct net_device *ndev)
 static void ns83820_tx_timeout(struct net_device *ndev)
 {
        struct ns83820 *dev = PRIV(ndev);
-        u32 tx_done_idx, *desc;
+        u32 tx_done_idx;
+       __le32 *desc;
        unsigned long flags;
 
-       local_irq_save(flags);
+       spin_lock_irqsave(&dev->tx_lock, flags);
 
        tx_done_idx = dev->tx_done_idx;
        desc = dev->tx_descs + (tx_done_idx * DESC_SIZE);
@@ -1482,7 +1475,7 @@ static void ns83820_tx_timeout(struct net_device *ndev)
                ndev->name,
                tx_done_idx, dev->tx_free_idx, le32_to_cpu(desc[DESC_CMDSTS]));
 
-       local_irq_restore(flags);
+       spin_unlock_irqrestore(&dev->tx_lock, flags);
 }
 
 static void ns83820_tx_watch(unsigned long data)
@@ -1589,7 +1582,7 @@ static void ns83820_set_multicast(struct net_device *ndev)
        else
                and_mask &= ~(RFCR_AAU | RFCR_AAM);
 
-       if (ndev->flags & IFF_ALLMULTI)
+       if (ndev->flags & IFF_ALLMULTI || ndev->mc_count)
                or_mask |= RFCR_AAM;
        else
                and_mask &= ~RFCR_AAM;
@@ -1838,10 +1831,13 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
 
        ndev = alloc_etherdev(sizeof(struct ns83820));
        dev = PRIV(ndev);
+
        err = -ENOMEM;
        if (!dev)
                goto out;
 
+       dev->ndev = ndev;
+
        spin_lock_init(&dev->rx_info.lock);
        spin_lock_init(&dev->tx_lock);
        spin_lock_init(&dev->misc_lock);
@@ -1850,7 +1846,7 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
        SET_MODULE_OWNER(ndev);
        SET_NETDEV_DEV(ndev, &pci_dev->dev);
 
-       INIT_WORK(&dev->tq_refill, queue_refill, ndev);
+       INIT_WORK(&dev->tq_refill, queue_refill);
        tasklet_init(&dev->rx_tasklet, rx_action, (unsigned long)ndev);
 
        err = pci_enable_device(pci_dev);
@@ -1953,7 +1949,7 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
        /* When compiled with 64 bit addressing, we must always enable
         * the 64 bit descriptor format.
         */
-       if (sizeof(dma_addr_t) == 8) 
+       if (sizeof(dma_addr_t) == 8)
                dev->CFG_cache |= CFG_M64ADDR;
        if (using_dac)
                dev->CFG_cache |= CFG_T64ADDR;
@@ -1991,7 +1987,7 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
                writel(dev->CFG_cache, dev->base + CFG);
        }
 
-#if 0  /* Huh?  This sets the PCI latency register.  Should be done via 
+#if 0  /* Huh?  This sets the PCI latency register.  Should be done via
         * the PCI layer.  FIXME.
         */
        if (readl(dev->base + SRR))
@@ -2003,7 +1999,7 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
         * can be transmitted is 8192 - FLTH - burst size.
         * If only the transmit fifo was larger...
         */
-       /* Ramit : 1024 DMA is not a good idea, it ends up banging 
+       /* Ramit : 1024 DMA is not a good idea, it ends up banging
         * some DELL and COMPAQ SMP systems */
        writel(TXCFG_CSI | TXCFG_HBI | TXCFG_ATP | TXCFG_MXDMA512
                | ((1600 / 32) * 0x100),
@@ -2017,8 +2013,8 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
        /* Set Rx to full duplex, don't accept runt, errored, long or length
         * range errored packets.  Use 512 byte DMA.
         */
-       /* Ramit : 1024 DMA is not a good idea, it ends up banging 
-        * some DELL and COMPAQ SMP systems 
+       /* Ramit : 1024 DMA is not a good idea, it ends up banging
+        * some DELL and COMPAQ SMP systems
         * Turn on ALP, only we are accpeting Jumbo Packets */
        writel(RXCFG_AEP | RXCFG_ARP | RXCFG_AIRL | RXCFG_RX_FD
                | RXCFG_STRIPCRC
@@ -2042,7 +2038,7 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
         * also turn on tag stripping if hardware acceleration is enabled
         */
 #ifdef NS83820_VLAN_ACCEL_SUPPORT
-#define VRCR_INIT_VALUE (VRCR_IPEN|VRCR_VTDEN|VRCR_VTREN) 
+#define VRCR_INIT_VALUE (VRCR_IPEN|VRCR_VTDEN|VRCR_VTREN)
 #else
 #define VRCR_INIT_VALUE (VRCR_IPEN|VRCR_VTDEN)
 #endif
@@ -2078,7 +2074,6 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
        /* We also support hardware vlan acceleration */
        ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
        ndev->vlan_rx_register = ns83820_vlan_rx_register;
-       ndev->vlan_rx_kill_vid = ns83820_vlan_rx_kill_vid;
 #endif
 
        if (using_dac) {
@@ -2175,7 +2170,7 @@ static struct pci_driver driver = {
 static int __init ns83820_init(void)
 {
        printk(KERN_INFO "ns83820.c: National Semiconductor DP83820 10/100/1000 driver.\n");
-       return pci_module_init(&driver);
+       return pci_register_driver(&driver);
 }
 
 static void __exit ns83820_exit(void)