[PATCH] libertas: remove incorrect vi modelines
[safe/jmp/linux-2.6] / drivers / net / starfire.c
index 12e2b68..9d6e454 100644 (file)
 
        Support and updates available at
        http://www.scyld.com/network/starfire.html
+       [link no longer provides useful info -jgarzik]
 
-       -----------------------------------------------------------
-
-       Linux kernel-specific changes:
-
-       LK1.1.1 (jgarzik):
-       - Use PCI driver interface
-       - Fix MOD_xxx races
-       - softnet fixups
-
-       LK1.1.2 (jgarzik):
-       - Merge Becker version 0.15
-
-       LK1.1.3 (Andrew Morton)
-       - Timer cleanups
-
-       LK1.1.4 (jgarzik):
-       - Merge Becker version 1.03
-
-       LK1.2.1 (Ion Badulescu <ionut@cs.columbia.edu>)
-       - Support hardware Rx/Tx checksumming
-       - Use the GFP firmware taken from Adaptec's Netware driver
-
-       LK1.2.2 (Ion Badulescu)
-       - Backported to 2.2.x
-
-       LK1.2.3 (Ion Badulescu)
-       - Fix the flaky mdio interface
-       - More compat clean-ups
-
-       LK1.2.4 (Ion Badulescu)
-       - More 2.2.x initialization fixes
-
-       LK1.2.5 (Ion Badulescu)
-       - Several fixes from Manfred Spraul
-
-       LK1.2.6 (Ion Badulescu)
-       - Fixed ifup/ifdown/ifup problem in 2.4.x
-
-       LK1.2.7 (Ion Badulescu)
-       - Removed unused code
-       - Made more functions static and __init
-
-       LK1.2.8 (Ion Badulescu)
-       - Quell bogus error messages, inform about the Tx threshold
-       - Removed #ifdef CONFIG_PCI, this driver is PCI only
-
-       LK1.2.9 (Ion Badulescu)
-       - Merged Jeff Garzik's changes from 2.4.4-pre5
-       - Added 2.2.x compatibility stuff required by the above changes
-
-       LK1.2.9a (Ion Badulescu)
-       - More updates from Jeff Garzik
-
-       LK1.3.0 (Ion Badulescu)
-       - Merged zerocopy support
-
-       LK1.3.1 (Ion Badulescu)
-       - Added ethtool support
-       - Added GPIO (media change) interrupt support
-
-       LK1.3.2 (Ion Badulescu)
-       - Fixed 2.2.x compatibility issues introduced in 1.3.1
-       - Fixed ethtool ioctl returning uninitialized memory
-
-       LK1.3.3 (Ion Badulescu)
-       - Initialize the TxMode register properly
-       - Don't dereference dev->priv after freeing it
-
-       LK1.3.4 (Ion Badulescu)
-       - Fixed initialization timing problems
-       - Fixed interrupt mask definitions
-
-       LK1.3.5 (jgarzik)
-       - ethtool NWAY_RST, GLINK, [GS]MSGLVL support
-
-       LK1.3.6:
-       - Sparc64 support and fixes (Ion Badulescu)
-       - Better stats and error handling (Ion Badulescu)
-       - Use new pci_set_mwi() PCI API function (jgarzik)
-
-       LK1.3.7 (Ion Badulescu)
-       - minimal implementation of tx_timeout()
-       - correctly shutdown the Rx/Tx engines in netdev_close()
-       - added calls to netif_carrier_on/off
-       (patch from Stefan Rompf <srompf@isg.de>)
-       - VLAN support
-
-       LK1.3.8 (Ion Badulescu)
-       - adjust DMA burst size on sparc64
-       - 64-bit support
-       - reworked zerocopy support for 64-bit buffers
-       - working and usable interrupt mitigation/latency
-       - reduced Tx interrupt frequency for lower interrupt overhead
-
-       LK1.3.9 (Ion Badulescu)
-       - bugfix for mcast filter
-       - enable the right kind of Tx interrupts (TxDMADone, not TxDone)
-
-       LK1.4.0 (Ion Badulescu)
-       - NAPI support
-
-       LK1.4.1 (Ion Badulescu)
-       - flush PCI posting buffers after disabling Rx interrupts
-       - put the chip to a D3 slumber on driver unload
-       - added config option to enable/disable NAPI
-
-       LK1.4.2 (Ion Badulescu)
-       - finally added firmware (GPL'ed by Adaptec)
-       - removed compatibility code for 2.2.x
-
-TODO:  - fix forced speed/duplexing code (broken a long time ago, when
-       somebody converted the driver to use the generic MII code)
-       - fix VLAN support
 */
 
 #define DRV_NAME       "starfire"
-#define DRV_VERSION    "1.03+LK1.4.2"
-#define DRV_RELDATE    "January 19, 2005"
+#define DRV_VERSION    "2.0"
+#define DRV_RELDATE    "June 27, 2006"
 
-#include <linux/config.h>
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
@@ -155,6 +41,7 @@ TODO:        - fix forced speed/duplexing code (broken a long time ago, when
 #include <linux/ethtool.h>
 #include <linux/mii.h>
 #include <linux/if_vlan.h>
+#include <linux/mm.h>
 #include <asm/processor.h>             /* Processor type for cache alignment. */
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -165,6 +52,14 @@ TODO:       - fix forced speed/duplexing code (broken a long time ago, when
  * of length 1. If and when this is fixed, the #define below can be removed.
  */
 #define HAS_BROKEN_FIRMWARE
+
+/*
+ * If using the broken firmware, data must be padded to the next 32-bit boundary.
+ */
+#ifdef HAS_BROKEN_FIRMWARE
+#define PADDING_MASK 3
+#endif
+
 /*
  * Define this if using the driver with the zero-copy patch
  */
@@ -190,7 +85,7 @@ static int max_interrupt_work = 20;
 static int mtu;
 /* Maximum number of multicast addresses to filter (vs. rx-all-multicast).
    The Starfire has a 512 element hash table based on the Ethernet CRC. */
-static int multicast_filter_limit = 512;
+static const int multicast_filter_limit = 512;
 /* Whether to do TCP/UDP checksums in hardware */
 static int enable_hw_cksum = 1;
 
@@ -257,9 +152,10 @@ static int full_duplex[MAX_UNITS] = {0, };
  * This SUCKS.
  * We need a much better method to determine if dma_addr_t is 64-bit.
  */
-#if (defined(__i386__) && defined(CONFIG_HIGHMEM) && (LINUX_VERSION_CODE > 0x20500 || defined(CONFIG_HIGHMEM64G))) || defined(__x86_64__) || defined (__ia64__) || defined(__mips64__) || (defined(__mips__) && defined(CONFIG_HIGHMEM) && defined(CONFIG_64BIT_PHYS_ADDR))
+#if (defined(__i386__) && defined(CONFIG_HIGHMEM64G)) || defined(__x86_64__) || defined (__ia64__) || defined(__mips64__) || (defined(__mips__) && defined(CONFIG_HIGHMEM) && defined(CONFIG_64BIT_PHYS_ADDR))
 /* 64-bit dma_addr_t */
 #define ADDR_64BITS    /* This chip uses 64 bit addresses. */
+#define netdrv_addr_t u64
 #define cpu_to_dma(x) cpu_to_le64(x)
 #define dma_to_cpu(x) le64_to_cpu(x)
 #define RX_DESC_Q_ADDR_SIZE RxDescQAddr64bit
@@ -268,6 +164,7 @@ static int full_duplex[MAX_UNITS] = {0, };
 #define TX_COMPL_Q_ADDR_SIZE TxComplQAddr64bit
 #define RX_DESC_ADDR_SIZE RxDescAddr64bit
 #else  /* 32-bit dma_addr_t */
+#define netdrv_addr_t u32
 #define cpu_to_dma(x) cpu_to_le32(x)
 #define dma_to_cpu(x) le32_to_cpu(x)
 #define RX_DESC_Q_ADDR_SIZE RxDescQAddr32bit
@@ -322,7 +219,7 @@ do { \
 
 
 /* These identify the driver base version and may not be removed. */
-static char version[] __devinitdata =
+static const char version[] __devinitdata =
 KERN_INFO "starfire.c:v1.03 7/26/2000  Written by Donald Becker <becker@scyld.com>\n"
 KERN_INFO " (unofficial 2.2/2.4 kernel port, version " DRV_VERSION ", " DRV_RELDATE ")\n";
 
@@ -450,7 +347,7 @@ static struct pci_device_id starfire_pci_tbl[] = {
 MODULE_DEVICE_TABLE(pci, starfire_pci_tbl);
 
 /* A chip capabilities table, matching the CH_xxx entries in xxx_pci_tbl[] above. */
-static struct chip_info {
+static const struct chip_info {
        const char *name;
        int drv_flags;
 } netdrv_tbl[] __devinitdata = {
@@ -736,7 +633,7 @@ static void check_duplex(struct net_device *dev);
 static void    tx_timeout(struct net_device *dev);
 static void    init_ring(struct net_device *dev);
 static int     start_tx(struct sk_buff *skb, struct net_device *dev);
-static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *regs);
+static irqreturn_t intr_handler(int irq, void *dev_instance);
 static void    netdev_error(struct net_device *dev, int intr_status);
 static int     __netdev_rx(struct net_device *dev, int *quota);
 static void    refill_rx_ring(struct net_device *dev);
@@ -746,7 +643,7 @@ static struct net_device_stats *get_stats(struct net_device *dev);
 static int     netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 static int     netdev_close(struct net_device *dev);
 static void    netdev_media_change(struct net_device *dev);
-static struct ethtool_ops ethtool_ops;
+static const struct ethtool_ops ethtool_ops;
 
 
 #ifdef VLAN_SUPPORT
@@ -780,8 +677,7 @@ static void netdev_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
        spin_lock(&np->lock);
        if (debug > 1)
                printk("%s: removing vlanid %d from vlan filter\n", dev->name, vid);
-       if (np->vlgrp)
-               np->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(np->vlgrp, vid, NULL);
        set_rx_mode(dev);
        spin_unlock(&np->lock);
 }
@@ -834,7 +730,6 @@ static int __devinit starfire_init_one(struct pci_dev *pdev,
                goto err_out_free_netdev;
        }
 
-       /* ioremap is borken in Linux-2.2.x/sparc64 */
        base = ioremap(ioaddr, io_size);
        if (!base) {
                printk(KERN_ERR DRV_NAME " %d: cannot remap %#x @ %#lx, aborting\n",
@@ -1058,7 +953,7 @@ static int netdev_open(struct net_device *dev)
 
        /* Do we ever need to reset the chip??? */
 
-       retval = request_irq(dev->irq, &intr_handler, SA_SHIRQ, dev->name, dev);
+       retval = request_irq(dev->irq, &intr_handler, IRQF_SHARED, dev->name, dev);
        if (retval)
                return retval;
 
@@ -1077,8 +972,10 @@ static int netdev_open(struct net_device *dev)
                rx_ring_size = sizeof(struct starfire_rx_desc) * RX_RING_SIZE;
                np->queue_mem_size = tx_done_q_size + rx_done_q_size + tx_ring_size + rx_ring_size;
                np->queue_mem = pci_alloc_consistent(np->pci_dev, np->queue_mem_size, &np->queue_mem_dma);
-               if (np->queue_mem == 0)
+               if (np->queue_mem == NULL) {
+                       free_irq(dev->irq, dev);
                        return -ENOMEM;
+               }
 
                np->tx_done_q     = np->queue_mem;
                np->tx_done_q_dma = np->queue_mem_dma;
@@ -1286,7 +1183,7 @@ static void init_ring(struct net_device *dev)
                np->rx_info[i].skb = skb;
                if (skb == NULL)
                        break;
-               np->rx_info[i].mapping = pci_map_single(np->pci_dev, skb->tail, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
+               np->rx_info[i].mapping = pci_map_single(np->pci_dev, skb->data, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
                skb->dev = dev;                 /* Mark as being used by this device. */
                /* Grrr, we cannot offset to correctly align the IP header. */
                np->rx_ring[i].rxaddr = cpu_to_dma(np->rx_info[i].mapping | RxDescValid);
@@ -1333,21 +1230,9 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
        }
 
 #if defined(ZEROCOPY) && defined(HAS_BROKEN_FIRMWARE)
-       {
-               int has_bad_length = 0;
-
-               if (skb_first_frag_len(skb) == 1)
-                       has_bad_length = 1;
-               else {
-                       for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
-                               if (skb_shinfo(skb)->frags[i].size == 1) {
-                                       has_bad_length = 1;
-                                       break;
-                               }
-               }
-
-               if (has_bad_length)
-                       skb_checksum_help(skb, 0);
+       if (skb->ip_summed == CHECKSUM_PARTIAL) {
+               if (skb_padto(skb, (skb->len + PADDING_MASK) & ~PADDING_MASK))
+                       return NETDEV_TX_OK;
        }
 #endif /* ZEROCOPY && HAS_BROKEN_FIRMWARE */
 
@@ -1367,7 +1252,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
                                status |= TxDescIntr;
                                np->reap_tx = 0;
                        }
-                       if (skb->ip_summed == CHECKSUM_HW) {
+                       if (skb->ip_summed == CHECKSUM_PARTIAL) {
                                status |= TxCalTCP;
                                np->stats.tx_compressed++;
                        }
@@ -1422,7 +1307,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
 
 /* The interrupt handler does all of the Rx thread work and cleans up
    after the Tx thread. */
-static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *rgs)
+static irqreturn_t intr_handler(int irq, void *dev_instance)
 {
        struct net_device *dev = dev_instance;
        struct netdev_private *np = netdev_priv(dev);
@@ -1567,12 +1452,11 @@ static int __netdev_rx(struct net_device *dev, int *quota)
                   to a minimally-sized skbuff. */
                if (pkt_len < rx_copybreak
                    && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
-                       skb->dev = dev;
                        skb_reserve(skb, 2);    /* 16 byte align the IP header */
                        pci_dma_sync_single_for_cpu(np->pci_dev,
                                                    np->rx_info[entry].mapping,
                                                    pkt_len, PCI_DMA_FROMDEVICE);
-                       eth_copy_and_sum(skb, np->rx_info[entry].skb->tail, pkt_len, 0);
+                       eth_copy_and_sum(skb, np->rx_info[entry].skb->data, pkt_len, 0);
                        pci_dma_sync_single_for_device(np->pci_dev,
                                                       np->rx_info[entry].mapping,
                                                       pkt_len, PCI_DMA_FROMDEVICE);
@@ -1614,7 +1498,7 @@ static int __netdev_rx(struct net_device *dev, int *quota)
                 * Until then, the printk stays. :-) -Ion
                 */
                else if (le16_to_cpu(desc->status2) & 0x0040) {
-                       skb->ip_summed = CHECKSUM_HW;
+                       skb->ip_summed = CHECKSUM_COMPLETE;
                        skb->csum = le16_to_cpu(desc->csum);
                        printk(KERN_DEBUG "%s: checksum_hw, status2 = %#x\n", dev->name, le16_to_cpu(desc->status2));
                }
@@ -1696,7 +1580,7 @@ static void refill_rx_ring(struct net_device *dev)
                        if (skb == NULL)
                                break;  /* Better luck next round. */
                        np->rx_info[entry].mapping =
-                               pci_map_single(np->pci_dev, skb->tail, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
+                               pci_map_single(np->pci_dev, skb->data, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
                        skb->dev = dev; /* Mark as being used by this device. */
                        np->rx_ring[entry].rxaddr =
                                cpu_to_dma(np->rx_info[entry].mapping | RxDescValid);
@@ -1852,7 +1736,7 @@ static void set_rx_mode(struct net_device *dev)
                int vlan_count = 0;
                void __iomem *filter_addr = ioaddr + HashTable + 8;
                for (i = 0; i < VLAN_VID_MASK; i++) {
-                       if (np->vlgrp->vlan_devices[i]) {
+                       if (vlan_group_get_device(np->vlgrp, i)) {
                                if (vlan_count >= 32)
                                        break;
                                writew(cpu_to_be16(i), filter_addr);
@@ -1983,7 +1867,7 @@ static void set_msglevel(struct net_device *dev, u32 val)
        debug = val;
 }
 
-static struct ethtool_ops ethtool_ops = {
+static const struct ethtool_ops ethtool_ops = {
        .begin = check_if_running,
        .get_drvinfo = get_drvinfo,
        .get_settings = get_settings,
@@ -2080,14 +1964,45 @@ static int netdev_close(struct net_device *dev)
        return 0;
 }
 
+#ifdef CONFIG_PM
+static int starfire_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+       struct net_device *dev = pci_get_drvdata(pdev);
+
+       if (netif_running(dev)) {
+               netif_device_detach(dev);
+               netdev_close(dev);
+       }
+
+       pci_save_state(pdev);
+       pci_set_power_state(pdev, pci_choose_state(pdev,state));
+
+       return 0;
+}
+
+static int starfire_resume(struct pci_dev *pdev)
+{
+       struct net_device *dev = pci_get_drvdata(pdev);
+
+       pci_set_power_state(pdev, PCI_D0);
+       pci_restore_state(pdev);
+
+       if (netif_running(dev)) {
+               netdev_open(dev);
+               netif_device_attach(dev);
+       }
+
+       return 0;
+}
+#endif /* CONFIG_PM */
+
 
 static void __devexit starfire_remove_one (struct pci_dev *pdev)
 {
        struct net_device *dev = pci_get_drvdata(pdev);
        struct netdev_private *np = netdev_priv(dev);
 
-       if (!dev)
-               BUG();
+       BUG_ON(!dev);
 
        unregister_netdev(dev);
 
@@ -2111,6 +2026,10 @@ static struct pci_driver starfire_driver = {
        .name           = DRV_NAME,
        .probe          = starfire_init_one,
        .remove         = __devexit_p(starfire_remove_one),
+#ifdef CONFIG_PM
+       .suspend        = starfire_suspend,
+       .resume         = starfire_resume,
+#endif /* CONFIG_PM */
        .id_table       = starfire_pci_tbl,
 };
 
@@ -2127,14 +2046,13 @@ static int __init starfire_init (void)
 #endif
 #endif
 
-#ifndef ADDR_64BITS
        /* we can do this test only at run-time... sigh */
-       if (sizeof(dma_addr_t) == sizeof(u64)) {
-               printk("This driver has not been ported to this 64-bit architecture yet\n");
+       if (sizeof(dma_addr_t) != sizeof(netdrv_addr_t)) {
+               printk("This driver has dma_addr_t issues, please send email to maintainer\n");
                return -ENODEV;
        }
-#endif /* not ADDR_64BITS */
-       return pci_module_init (&starfire_driver);
+
+       return pci_register_driver(&starfire_driver);
 }