sis190: add identifier for Atheros AR8021 PHY
[safe/jmp/linux-2.6] / drivers / net / e100.c
index 5de9843..3d69fae 100644 (file)
@@ -1,27 +1,27 @@
 /*******************************************************************************
 
-
-  Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
+  Intel PRO/100 Linux driver
+  Copyright(c) 1999 - 2006 Intel Corporation.
 
   This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the Free
-  Software Foundation; either version 2 of the License, or (at your option)
-  any later version.
+  under the terms and conditions of the GNU General Public License,
+  version 2, as published by the Free Software Foundation.
 
-  This program is distributed in the hope that it will be useful, but WITHOUT
+  This program is distributed in the hope it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
   You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc., 59
-  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+  this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 
-  The full GNU General Public License is included in this distribution in the
-  file called LICENSE.
+  The full GNU General Public License is included in this distribution in
+  the file called "COPYING".
 
   Contact Information:
   Linux NICS <linux.nics@intel.com>
+  e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 
 *******************************************************************************/
@@ -94,7 +94,7 @@
  *     enabled.  82557 pads with 7Eh, while the later controllers pad
  *     with 00h.
  *
- *     IV.  Recieve
+ *     IV.  Receive
  *
  *     The Receive Frame Area (RFA) comprises a ring of Receive Frame
  *     Descriptors (RFD) + data buffer, thus forming the simplified mode
  *     the RFD, the RFD must be dma_sync'ed to maintain a consistent
  *     view from software and hardware.
  *
+ *     In order to keep updates to the RFD link field from colliding with
+ *     hardware writes to mark packets complete, we use the feature that
+ *     hardware will not write to a size 0 descriptor and mark the previous
+ *     packet as end-of-list (EL).   After updating the link, we remove EL
+ *     and only then restore the size such that hardware may use the
+ *     previous-to-end RFD.
+ *
  *     Under typical operation, the  receive unit (RU) is start once,
  *     and the controller happily fills RFDs as frames arrive.  If
  *     replacement RFDs cannot be allocated, or the RU goes non-active,
  *     and Rx indication and re-allocation happen in the same context,
  *     therefore no locking is required.  A software-generated interrupt
  *     is generated from the watchdog to recover from a failed allocation
- *     senario where all Rx resources have been indicated and none re-
+ *     scenario where all Rx resources have been indicated and none re-
  *     placed.
  *
  *     V.   Miscellaneous
 
 
 #define DRV_NAME               "e100"
-#define DRV_EXT                "-NAPI"
-#define DRV_VERSION            "3.5.10-k2"DRV_EXT
+#define DRV_EXT                        "-NAPI"
+#define DRV_VERSION            "3.5.23-k4"DRV_EXT
 #define DRV_DESCRIPTION                "Intel(R) PRO/100 Network Driver"
-#define DRV_COPYRIGHT          "Copyright(c) 1999-2005 Intel Corporation"
+#define DRV_COPYRIGHT          "Copyright(c) 1999-2006 Intel Corporation"
 #define PFX                    DRV_NAME ": "
 
 #define E100_WATCHDOG_PERIOD   (2 * HZ)
@@ -173,12 +180,18 @@ MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
 
 static int debug = 3;
+static int eeprom_bad_csum_allow = 0;
+static int use_io = 0;
 module_param(debug, int, 0);
+module_param(eeprom_bad_csum_allow, int, 0);
+module_param(use_io, int, 0);
 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
+MODULE_PARM_DESC(eeprom_bad_csum_allow, "Allow bad eeprom checksums");
+MODULE_PARM_DESC(use_io, "Force use of i/o access mode");
 #define DPRINTK(nlevel, klevel, fmt, args...) \
        (void)((NETIF_MSG_##nlevel & nic->msg_enable) && \
        printk(KERN_##klevel PFX "%s: %s: " fmt, nic->netdev->name, \
-               __FUNCTION__ , ## args))
+               __func__ , ## args))
 
 #define INTEL_8255X_ETHERNET_DEVICE(device_id, ich) {\
        PCI_VENDOR_ID_INTEL, device_id, PCI_ANY_ID, PCI_ANY_ID, \
@@ -275,6 +288,7 @@ struct csr {
 };
 
 enum scb_status {
+       rus_no_res       = 0x08,
        rus_ready        = 0x10,
        rus_mask         = 0x3C,
 };
@@ -387,12 +401,12 @@ enum cb_command {
 };
 
 struct rfd {
-       u16 status;
-       u16 command;
-       u32 link;
-       u32 rbd;
-       u16 actual_size;
-       u16 size;
+       __le16 status;
+       __le16 command;
+       __le32 link;
+       __le32 rbd;
+       __le16 actual_size;
+       __le16 size;
 };
 
 struct rx {
@@ -447,19 +461,19 @@ struct config {
 
 #define E100_MAX_MULTICAST_ADDRS       64
 struct multi {
-       u16 count;
+       __le16 count;
        u8 addr[E100_MAX_MULTICAST_ADDRS * ETH_ALEN + 2/*pad*/];
 };
 
 /* Important: keep total struct u32-aligned */
 #define UCODE_SIZE                     134
 struct cb {
-       u16 status;
-       u16 command;
-       u32 link;
+       __le16 status;
+       __le16 command;
+       __le32 link;
        union {
                u8 iaaddr[ETH_ALEN];
-               u32 ucode[UCODE_SIZE];
+               __le32 ucode[UCODE_SIZE];
                struct config config;
                struct multi multi;
                struct {
@@ -468,12 +482,12 @@ struct cb {
                        u8 threshold;
                        u8 tbd_count;
                        struct {
-                               u32 buf_addr;
-                               u16 size;
+                               __le32 buf_addr;
+                               __le16 size;
                                u16 eol;
                        } tbd;
                } tcb;
-               u32 dump_buffer_addr;
+               __le32 dump_buffer_addr;
        } u;
        struct cb *next, *prev;
        dma_addr_t dma_addr;
@@ -485,15 +499,15 @@ enum loopback {
 };
 
 struct stats {
-       u32 tx_good_frames, tx_max_collisions, tx_late_collisions,
+       __le32 tx_good_frames, tx_max_collisions, tx_late_collisions,
                tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions,
                tx_multiple_collisions, tx_total_collisions;
-       u32 rx_good_frames, rx_crc_errors, rx_alignment_errors,
+       __le32 rx_good_frames, rx_crc_errors, rx_alignment_errors,
                rx_resource_errors, rx_overrun_errors, rx_cdt_errors,
                rx_short_frame_errors;
-       u32 fc_xmt_pause, fc_rcv_pause, fc_rcv_unsupported;
-       u16 xmt_tco_frames, rcv_tco_frames;
-       u32 complete;
+       __le32 fc_xmt_pause, fc_rcv_pause, fc_rcv_unsupported;
+       __le16 xmt_tco_frames, rcv_tco_frames;
+       __le32 complete;
 };
 
 struct mem {
@@ -533,11 +547,12 @@ struct nic {
        struct csr __iomem *csr;
        enum scb_cmd_lo cuc_cmd;
        unsigned int cbs_avail;
+       struct napi_struct napi;
        struct cb *cbs;
        struct cb *cb_to_use;
        struct cb *cb_to_send;
        struct cb *cb_to_clean;
-       u16 tx_command;
+       __le16 tx_command;
        /* End: frequently used values: keep adjacent for cache effect */
 
        enum {
@@ -551,7 +566,6 @@ struct nic {
        enum mac mac;
        enum phy phy;
        struct params params;
-       struct net_device_stats net_stats;
        struct timer_list watchdog;
        struct timer_list blink_timer;
        struct mii_if_info mii;
@@ -577,10 +591,9 @@ struct nic {
        u32 rx_tco_frames;
        u32 rx_over_length_errors;
 
-       u8 rev_id;
        u16 leds;
        u16 eeprom_wc;
-       u16 eeprom[256];
+       __le16 eeprom[256];
        spinlock_t mdio_lock;
 };
 
@@ -588,7 +601,7 @@ static inline void e100_write_flush(struct nic *nic)
 {
        /* Flush previous PCI writes through intermediate bridges
         * by doing a benign read */
-       (void)readb(&nic->csr->scb.status);
+       (void)ioread8(&nic->csr->scb.status);
 }
 
 static void e100_enable_irq(struct nic *nic)
@@ -596,7 +609,7 @@ static void e100_enable_irq(struct nic *nic)
        unsigned long flags;
 
        spin_lock_irqsave(&nic->cmd_lock, flags);
-       writeb(irq_mask_none, &nic->csr->scb.cmd_hi);
+       iowrite8(irq_mask_none, &nic->csr->scb.cmd_hi);
        e100_write_flush(nic);
        spin_unlock_irqrestore(&nic->cmd_lock, flags);
 }
@@ -606,7 +619,7 @@ static void e100_disable_irq(struct nic *nic)
        unsigned long flags;
 
        spin_lock_irqsave(&nic->cmd_lock, flags);
-       writeb(irq_mask_all, &nic->csr->scb.cmd_hi);
+       iowrite8(irq_mask_all, &nic->csr->scb.cmd_hi);
        e100_write_flush(nic);
        spin_unlock_irqrestore(&nic->cmd_lock, flags);
 }
@@ -615,11 +628,11 @@ static void e100_hw_reset(struct nic *nic)
 {
        /* Put CU and RU into idle with a selective reset to get
         * device off of PCI bus */
-       writel(selective_reset, &nic->csr->port);
+       iowrite32(selective_reset, &nic->csr->port);
        e100_write_flush(nic); udelay(20);
 
        /* Now fully reset device */
-       writel(software_reset, &nic->csr->port);
+       iowrite32(software_reset, &nic->csr->port);
        e100_write_flush(nic); udelay(20);
 
        /* Mask off our interrupt line - it's unmasked after reset */
@@ -636,7 +649,7 @@ static int e100_self_test(struct nic *nic)
        nic->mem->selftest.signature = 0;
        nic->mem->selftest.result = 0xFFFFFFFF;
 
-       writel(selftest | dma_addr, &nic->csr->port);
+       iowrite32(selftest | dma_addr, &nic->csr->port);
        e100_write_flush(nic);
        /* Wait 10 msec for self-test to complete */
        msleep(10);
@@ -658,7 +671,7 @@ static int e100_self_test(struct nic *nic)
        return 0;
 }
 
-static void e100_eeprom_write(struct nic *nic, u16 addr_len, u16 addr, u16 data)
+static void e100_eeprom_write(struct nic *nic, u16 addr_len, u16 addr, __le16 data)
 {
        u32 cmd_addr_data[3];
        u8 ctrl;
@@ -667,36 +680,36 @@ static void e100_eeprom_write(struct nic *nic, u16 addr_len, u16 addr, u16 data)
        /* Three cmds: write/erase enable, write data, write/erase disable */
        cmd_addr_data[0] = op_ewen << (addr_len - 2);
        cmd_addr_data[1] = (((op_write << addr_len) | addr) << 16) |
-               cpu_to_le16(data);
+               le16_to_cpu(data);
        cmd_addr_data[2] = op_ewds << (addr_len - 2);
 
        /* Bit-bang cmds to write word to eeprom */
        for(j = 0; j < 3; j++) {
 
                /* Chip select */
-               writeb(eecs | eesk, &nic->csr->eeprom_ctrl_lo);
+               iowrite8(eecs | eesk, &nic->csr->eeprom_ctrl_lo);
                e100_write_flush(nic); udelay(4);
 
                for(i = 31; i >= 0; i--) {
                        ctrl = (cmd_addr_data[j] & (1 << i)) ?
                                eecs | eedi : eecs;
-                       writeb(ctrl, &nic->csr->eeprom_ctrl_lo);
+                       iowrite8(ctrl, &nic->csr->eeprom_ctrl_lo);
                        e100_write_flush(nic); udelay(4);
 
-                       writeb(ctrl | eesk, &nic->csr->eeprom_ctrl_lo);
+                       iowrite8(ctrl | eesk, &nic->csr->eeprom_ctrl_lo);
                        e100_write_flush(nic); udelay(4);
                }
                /* Wait 10 msec for cmd to complete */
                msleep(10);
 
                /* Chip deselect */
-               writeb(0, &nic->csr->eeprom_ctrl_lo);
+               iowrite8(0, &nic->csr->eeprom_ctrl_lo);
                e100_write_flush(nic); udelay(4);
        }
 };
 
 /* General technique stolen from the eepro100 driver - very clever */
-static u16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr)
+static __le16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr)
 {
        u32 cmd_addr_data;
        u16 data = 0;
@@ -706,21 +719,21 @@ static u16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr)
        cmd_addr_data = ((op_read << *addr_len) | addr) << 16;
 
        /* Chip select */
-       writeb(eecs | eesk, &nic->csr->eeprom_ctrl_lo);
+       iowrite8(eecs | eesk, &nic->csr->eeprom_ctrl_lo);
        e100_write_flush(nic); udelay(4);
 
        /* Bit-bang to read word from eeprom */
        for(i = 31; i >= 0; i--) {
                ctrl = (cmd_addr_data & (1 << i)) ? eecs | eedi : eecs;
-               writeb(ctrl, &nic->csr->eeprom_ctrl_lo);
+               iowrite8(ctrl, &nic->csr->eeprom_ctrl_lo);
                e100_write_flush(nic); udelay(4);
 
-               writeb(ctrl | eesk, &nic->csr->eeprom_ctrl_lo);
+               iowrite8(ctrl | eesk, &nic->csr->eeprom_ctrl_lo);
                e100_write_flush(nic); udelay(4);
 
                /* Eeprom drives a dummy zero to EEDO after receiving
                 * complete address.  Use this to adjust addr_len. */
-               ctrl = readb(&nic->csr->eeprom_ctrl_lo);
+               ctrl = ioread8(&nic->csr->eeprom_ctrl_lo);
                if(!(ctrl & eedo) && i > 16) {
                        *addr_len -= (i - 16);
                        i = 17;
@@ -730,10 +743,10 @@ static u16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr)
        }
 
        /* Chip deselect */
-       writeb(0, &nic->csr->eeprom_ctrl_lo);
+       iowrite8(0, &nic->csr->eeprom_ctrl_lo);
        e100_write_flush(nic); udelay(4);
 
-       return le16_to_cpu(data);
+       return cpu_to_le16(data);
 };
 
 /* Load entire EEPROM image into driver cache and validate checksum */
@@ -748,15 +761,15 @@ static int e100_eeprom_load(struct nic *nic)
        for(addr = 0; addr < nic->eeprom_wc; addr++) {
                nic->eeprom[addr] = e100_eeprom_read(nic, &addr_len, addr);
                if(addr < nic->eeprom_wc - 1)
-                       checksum += cpu_to_le16(nic->eeprom[addr]);
+                       checksum += le16_to_cpu(nic->eeprom[addr]);
        }
 
        /* The checksum, stored in the last word, is calculated such that
         * the sum of words should be 0xBABA */
-       checksum = le16_to_cpu(0xBABA - checksum);
-       if(checksum != nic->eeprom[nic->eeprom_wc - 1]) {
+       if (cpu_to_le16(0xBABA - checksum) != nic->eeprom[nic->eeprom_wc - 1]) {
                DPRINTK(PROBE, ERR, "EEPROM corrupted\n");
-               return -EAGAIN;
+               if (!eeprom_bad_csum_allow)
+                       return -EAGAIN;
        }
 
        return 0;
@@ -780,8 +793,8 @@ static int e100_eeprom_save(struct nic *nic, u16 start, u16 count)
        /* The checksum, stored in the last word, is calculated such that
         * the sum of words should be 0xBABA */
        for(addr = 0; addr < nic->eeprom_wc - 1; addr++)
-               checksum += cpu_to_le16(nic->eeprom[addr]);
-       nic->eeprom[nic->eeprom_wc - 1] = le16_to_cpu(0xBABA - checksum);
+               checksum += le16_to_cpu(nic->eeprom[addr]);
+       nic->eeprom[nic->eeprom_wc - 1] = cpu_to_le16(0xBABA - checksum);
        e100_eeprom_write(nic, addr_len, nic->eeprom_wc - 1,
                nic->eeprom[nic->eeprom_wc - 1]);
 
@@ -800,7 +813,7 @@ static int e100_exec_cmd(struct nic *nic, u8 cmd, dma_addr_t dma_addr)
 
        /* Previous command is accepted when SCB clears */
        for(i = 0; i < E100_WAIT_SCB_TIMEOUT; i++) {
-               if(likely(!readb(&nic->csr->scb.cmd_lo)))
+               if(likely(!ioread8(&nic->csr->scb.cmd_lo)))
                        break;
                cpu_relax();
                if(unlikely(i > E100_WAIT_SCB_FAST))
@@ -812,8 +825,8 @@ static int e100_exec_cmd(struct nic *nic, u8 cmd, dma_addr_t dma_addr)
        }
 
        if(unlikely(cmd != cuc_resume))
-               writel(dma_addr, &nic->csr->scb.gen_ptr);
-       writeb(cmd, &nic->csr->scb.cmd_lo);
+               iowrite32(dma_addr, &nic->csr->scb.gen_ptr);
+       iowrite8(cmd, &nic->csr->scb.cmd_lo);
 
 err_unlock:
        spin_unlock_irqrestore(&nic->cmd_lock, flags);
@@ -891,7 +904,7 @@ static u16 mdio_ctrl(struct nic *nic, u32 addr, u32 dir, u32 reg, u16 data)
         */
        spin_lock_irqsave(&nic->mdio_lock, flags);
        for (i = 100; i; --i) {
-               if (readl(&nic->csr->mdi_ctrl) & mdi_ready)
+               if (ioread32(&nic->csr->mdi_ctrl) & mdi_ready)
                        break;
                udelay(20);
        }
@@ -901,11 +914,11 @@ static u16 mdio_ctrl(struct nic *nic, u32 addr, u32 dir, u32 reg, u16 data)
                spin_unlock_irqrestore(&nic->mdio_lock, flags);
                return 0;               /* No way to indicate timeout error */
        }
-       writel((reg << 16) | (addr << 21) | dir | data, &nic->csr->mdi_ctrl);
+       iowrite32((reg << 16) | (addr << 21) | dir | data, &nic->csr->mdi_ctrl);
 
        for (i = 0; i < 100; i++) {
                udelay(20);
-               if ((data_out = readl(&nic->csr->mdi_ctrl)) & mdi_ready)
+               if ((data_out = ioread32(&nic->csr->mdi_ctrl)) & mdi_ready)
                        break;
        }
        spin_unlock_irqrestore(&nic->mdio_lock, flags);
@@ -930,9 +943,8 @@ static void e100_get_defaults(struct nic *nic)
        struct param_range rfds = { .min = 16, .max = 256, .count = 256 };
        struct param_range cbs  = { .min = 64, .max = 256, .count = 128 };
 
-       pci_read_config_byte(nic->pdev, PCI_REVISION_ID, &nic->rev_id);
        /* MAC type is encoded as rev ID; exception: ICH is treated as 82559 */
-       nic->mac = (nic->flags & ich) ? mac_82559_D101M : nic->rev_id;
+       nic->mac = (nic->flags & ich) ? mac_82559_D101M : nic->pdev->revision;
        if(nic->mac == mac_unknown)
                nic->mac = mac_82557_D100_A;
 
@@ -942,13 +954,13 @@ static void e100_get_defaults(struct nic *nic)
        /* Quadwords to DMA into FIFO before starting frame transmit */
        nic->tx_threshold = 0xE0;
 
-       /* no interrupt for every tx completion, delay = 256us if not 557*/
+       /* no interrupt for every tx completion, delay = 256us if not 557 */
        nic->tx_command = cpu_to_le16(cb_tx | cb_tx_sf |
                ((nic->mac >= mac_82558_D101_A4) ? cb_cid : cb_i));
 
        /* Template for a freshly allocated RFD */
-       nic->blank_rfd.command = cpu_to_le16(cb_el);
-       nic->blank_rfd.rbd = 0xFFFFFFFF;
+       nic->blank_rfd.command = 0;
+       nic->blank_rfd.rbd = cpu_to_le32(0xFFFFFFFF);
        nic->blank_rfd.size = cpu_to_le16(VLAN_ETH_FRAME_LEN);
 
        /* MII setup */
@@ -1017,10 +1029,16 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
                config->mwi_enable = 0x1;       /* 1=enable, 0=disable */
                config->standard_tcb = 0x0;     /* 1=standard, 0=extended */
                config->rx_long_ok = 0x1;       /* 1=VLANs ok, 0=standard */
-               if(nic->mac >= mac_82559_D101M)
+               if (nic->mac >= mac_82559_D101M) {
                        config->tno_intr = 0x1;         /* TCO stats enable */
-               else
+                       /* Enable TCO in extended config */
+                       if (nic->mac >= mac_82551_10) {
+                               config->byte_count = 0x20; /* extended bytes */
+                               config->rx_d102_mode = 0x1; /* GMRC for TCO */
+                       }
+               } else {
                        config->standard_stat_counter = 0x0;
+               }
        }
 
        DPRINTK(HW, DEBUG, "[00-07]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
@@ -1211,7 +1229,7 @@ static void e100_setup_ucode(struct nic *nic, struct cb *cb, struct sk_buff *skb
 *  the literal in the instruction before the code is loaded, the
 *  driver can change the algorithm.
 *
-*  INTDELAY - This loads the dead-man timer with its inital value.
+*  INTDELAY - This loads the dead-man timer with its initial value.
 *    When this timer expires the interrupt is asserted, and the
 *    timer is reset each time a new packet is received.  (see
 *    BUNDLEMAX below to set the limit on number of chained packets)
@@ -1266,7 +1284,7 @@ static void e100_setup_ucode(struct nic *nic, struct cb *cb, struct sk_buff *skb
        if (nic->flags & ich)
                goto noloaducode;
 
-       /* Search for ucode match against h/w rev_id */
+       /* Search for ucode match against h/w revision */
        for (opts = ucode_opts; opts->mac; opts++) {
                int i;
                u32 *ucode = opts->ucode;
@@ -1313,8 +1331,8 @@ static inline int e100_exec_cb_wait(struct nic *nic, struct sk_buff *skb,
                if (!--counter) break;
        }
 
-       /* ack any interupts, something could have been set */
-       writeb(~0, &nic->csr->scb.stat_ack);
+       /* ack any interrupts, something could have been set */
+       iowrite8(~0, &nic->csr->scb.stat_ack);
 
        /* if the command failed, or is not OK, notify and return */
        if (!counter || !(cb->status & cpu_to_le16(cb_ok))) {
@@ -1471,17 +1489,18 @@ static void e100_set_multicast_list(struct net_device *netdev)
 
 static void e100_update_stats(struct nic *nic)
 {
-       struct net_device_stats *ns = &nic->net_stats;
+       struct net_device *dev = nic->netdev;
+       struct net_device_stats *ns = &dev->stats;
        struct stats *s = &nic->mem->stats;
-       u32 *complete = (nic->mac < mac_82558_D101_A4) ? &s->fc_xmt_pause :
-               (nic->mac < mac_82559_D101M) ? (u32 *)&s->xmt_tco_frames :
+       __le32 *complete = (nic->mac < mac_82558_D101_A4) ? &s->fc_xmt_pause :
+               (nic->mac < mac_82559_D101M) ? (__le32 *)&s->xmt_tco_frames :
                &s->complete;
 
        /* Device's stats reporting may take several microseconds to
-        * complete, so where always waiting for results of the
+        * complete, so we're always waiting for results of the
         * previous command. */
 
-       if(*complete == le32_to_cpu(cuc_dump_reset_complete)) {
+       if(*complete == cpu_to_le32(cuc_dump_reset_complete)) {
                *complete = 0;
                nic->tx_frames = le32_to_cpu(s->tx_good_frames);
                nic->tx_collisions = le32_to_cpu(s->tx_total_collisions);
@@ -1576,7 +1595,7 @@ static void e100_watchdog(unsigned long data)
         * accidentally, due to hardware that shares a register between the
         * interrupt mask bit and the SW Interrupt generation bit */
        spin_lock_irq(&nic->cmd_lock);
-       writeb(readb(&nic->csr->scb.cmd_hi) | irq_sw_gen,&nic->csr->scb.cmd_hi);
+       iowrite8(ioread8(&nic->csr->scb.cmd_hi) | irq_sw_gen,&nic->csr->scb.cmd_hi);
        e100_write_flush(nic);
        spin_unlock_irq(&nic->cmd_lock);
 
@@ -1593,7 +1612,8 @@ static void e100_watchdog(unsigned long data)
        else
                nic->flags &= ~ich_10h_workaround;
 
-       mod_timer(&nic->watchdog, jiffies + E100_WATCHDOG_PERIOD);
+       mod_timer(&nic->watchdog,
+                 round_jiffies(jiffies + E100_WATCHDOG_PERIOD));
 }
 
 static void e100_xmit_prepare(struct nic *nic, struct cb *cb,
@@ -1648,21 +1668,23 @@ static int e100_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
 
 static int e100_tx_clean(struct nic *nic)
 {
+       struct net_device *dev = nic->netdev;
        struct cb *cb;
        int tx_cleaned = 0;
 
        spin_lock(&nic->cb_lock);
 
-       DPRINTK(TX_DONE, DEBUG, "cb->status = 0x%04X\n",
-               nic->cb_to_clean->status);
-
        /* Clean CBs marked complete */
        for(cb = nic->cb_to_clean;
            cb->status & cpu_to_le16(cb_complete);
            cb = nic->cb_to_clean = cb->next) {
+               DPRINTK(TX_DONE, DEBUG, "cb[%d]->status = 0x%04X\n",
+                       (int)(((void*)cb - (void*)nic->cbs)/sizeof(struct cb)),
+                       cb->status);
+
                if(likely(cb->skb != NULL)) {
-                       nic->net_stats.tx_packets++;
-                       nic->net_stats.tx_bytes += cb->skb->len;
+                       dev->stats.tx_packets++;
+                       dev->stats.tx_bytes += cb->skb->len;
 
                        pci_unmap_single(nic->pdev,
                                le32_to_cpu(cb->u.tcb.tbd.buf_addr),
@@ -1759,17 +1781,16 @@ static inline void e100_start_receiver(struct nic *nic, struct rx *rx)
 #define RFD_BUF_LEN (sizeof(struct rfd) + VLAN_ETH_FRAME_LEN)
 static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)
 {
-       if(!(rx->skb = dev_alloc_skb(RFD_BUF_LEN + NET_IP_ALIGN)))
+       if(!(rx->skb = netdev_alloc_skb(nic->netdev, RFD_BUF_LEN + NET_IP_ALIGN)))
                return -ENOMEM;
 
        /* Align, init, and map the RFD. */
-       rx->skb->dev = nic->netdev;
        skb_reserve(rx->skb, NET_IP_ALIGN);
-       memcpy(rx->skb->data, &nic->blank_rfd, sizeof(struct rfd));
+       skb_copy_to_linear_data(rx->skb, &nic->blank_rfd, sizeof(struct rfd));
        rx->dma_addr = pci_map_single(nic->pdev, rx->skb->data,
                RFD_BUF_LEN, PCI_DMA_BIDIRECTIONAL);
 
-       if(pci_dma_mapping_error(rx->dma_addr)) {
+       if (pci_dma_mapping_error(nic->pdev, rx->dma_addr)) {
                dev_kfree_skb_any(rx->skb);
                rx->skb = NULL;
                rx->dma_addr = 0;
@@ -1777,13 +1798,11 @@ static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)
        }
 
        /* Link the RFD to end of RFA by linking previous RFD to
-        * this one, and clearing EL bit of previous.  */
-       if(rx->prev->skb) {
+        * this one.  We are safe to touch the previous RFD because
+        * it is protected by the before last buffer's el bit being set */
+       if (rx->prev->skb) {
                struct rfd *prev_rfd = (struct rfd *)rx->prev->skb->data;
-               put_unaligned(cpu_to_le32(rx->dma_addr),
-                       (u32 *)&prev_rfd->link);
-               wmb();
-               prev_rfd->command &= ~cpu_to_le16(cb_el);
+               put_unaligned_le32(rx->dma_addr, &prev_rfd->link);
                pci_dma_sync_single_for_device(nic->pdev, rx->prev->dma_addr,
                        sizeof(struct rfd), PCI_DMA_TODEVICE);
        }
@@ -1794,6 +1813,7 @@ static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)
 static int e100_rx_indicate(struct nic *nic, struct rx *rx,
        unsigned int *work_done, unsigned int work_to_do)
 {
+       struct net_device *dev = nic->netdev;
        struct sk_buff *skb = rx->skb;
        struct rfd *rfd = (struct rfd *)skb->data;
        u16 rfd_status, actual_size;
@@ -1809,8 +1829,19 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,
        DPRINTK(RX_STATUS, DEBUG, "status=0x%04X\n", rfd_status);
 
        /* If data isn't ready, nothing to indicate */
-       if(unlikely(!(rfd_status & cb_complete)))
+       if (unlikely(!(rfd_status & cb_complete))) {
+               /* If the next buffer has the el bit, but we think the receiver
+                * is still running, check to see if it really stopped while
+                * we had interrupts off.
+                * This allows for a fast restart without re-enabling
+                * interrupts */
+               if ((le16_to_cpu(rfd->command) & cb_el) &&
+                   (RU_RUNNING == nic->ru_running))
+
+                       if (ioread8(&nic->csr->scb.status) & rus_no_res)
+                               nic->ru_running = RU_SUSPENDED;
                return -ENODATA;
+       }
 
        /* Get actual data size */
        actual_size = le16_to_cpu(rfd->actual_size) & 0x3FFF;
@@ -1821,9 +1852,18 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,
        pci_unmap_single(nic->pdev, rx->dma_addr,
                RFD_BUF_LEN, PCI_DMA_FROMDEVICE);
 
-       /* this allows for a fast restart without re-enabling interrupts */
-       if(le16_to_cpu(rfd->command) & cb_el)
+       /* If this buffer has the el bit, but we think the receiver
+        * is still running, check to see if it really stopped while
+        * we had interrupts off.
+        * This allows for a fast restart without re-enabling interrupts.
+        * This can happen when the RU sees the size change but also sees
+        * the el bit set. */
+       if ((le16_to_cpu(rfd->command) & cb_el) &&
+           (RU_RUNNING == nic->ru_running)) {
+
+           if (ioread8(&nic->csr->scb.status) & rus_no_res)
                nic->ru_running = RU_SUSPENDED;
+       }
 
        /* Pull off the RFD and put the actual data (minus eth hdr) */
        skb_reserve(skb, sizeof(struct rfd));
@@ -1838,8 +1878,8 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,
                nic->rx_over_length_errors++;
                dev_kfree_skb_any(skb);
        } else {
-               nic->net_stats.rx_packets++;
-               nic->net_stats.rx_bytes += actual_size;
+               dev->stats.rx_packets++;
+               dev->stats.rx_bytes += actual_size;
                nic->netdev->last_rx = jiffies;
                netif_receive_skb(skb);
                if(work_done)
@@ -1855,31 +1895,30 @@ static void e100_rx_clean(struct nic *nic, unsigned int *work_done,
        unsigned int work_to_do)
 {
        struct rx *rx;
-       int restart_required = 0;
-       struct rx *rx_to_start = NULL;
-
-       /* are we already rnr? then pay attention!!! this ensures that
-        * the state machine progression never allows a start with a
-        * partially cleaned list, avoiding a race between hardware
-        * and rx_to_clean when in NAPI mode */
-       if(RU_SUSPENDED == nic->ru_running)
-               restart_required = 1;
+       int restart_required = 0, err = 0;
+       struct rx *old_before_last_rx, *new_before_last_rx;
+       struct rfd *old_before_last_rfd, *new_before_last_rfd;
 
        /* Indicate newly arrived packets */
        for(rx = nic->rx_to_clean; rx->skb; rx = nic->rx_to_clean = rx->next) {
-               int err = e100_rx_indicate(nic, rx, work_done, work_to_do);
-               if(-EAGAIN == err) {
-                       /* hit quota so have more work to do, restart once
-                        * cleanup is complete */
-                       restart_required = 0;
+               err = e100_rx_indicate(nic, rx, work_done, work_to_do);
+               /* Hit quota or no more to clean */
+               if (-EAGAIN == err || -ENODATA == err)
                        break;
-               } else if(-ENODATA == err)
-                       break; /* No more to clean */
        }
 
-       /* save our starting point as the place we'll restart the receiver */
-       if(restart_required)
-               rx_to_start = nic->rx_to_clean;
+
+       /* On EAGAIN, hit quota so have more work to do, restart once
+        * cleanup is complete.
+        * Else, are we already rnr? then pay attention!!! this ensures that
+        * the state machine progression never allows a start with a
+        * partially cleaned list, avoiding a race between hardware
+        * and rx_to_clean when in NAPI mode */
+       if (-EAGAIN != err && RU_SUSPENDED == nic->ru_running)
+               restart_required = 1;
+
+       old_before_last_rx = nic->rx_to_use->prev->prev;
+       old_before_last_rfd = (struct rfd *)old_before_last_rx->skb->data;
 
        /* Alloc new skbs to refill list */
        for(rx = nic->rx_to_use; !rx->skb; rx = nic->rx_to_use = rx->next) {
@@ -1887,10 +1926,42 @@ static void e100_rx_clean(struct nic *nic, unsigned int *work_done,
                        break; /* Better luck next time (see watchdog) */
        }
 
+       new_before_last_rx = nic->rx_to_use->prev->prev;
+       if (new_before_last_rx != old_before_last_rx) {
+               /* Set the el-bit on the buffer that is before the last buffer.
+                * This lets us update the next pointer on the last buffer
+                * without worrying about hardware touching it.
+                * We set the size to 0 to prevent hardware from touching this
+                * buffer.
+                * When the hardware hits the before last buffer with el-bit
+                * and size of 0, it will RNR interrupt, the RUS will go into
+                * the No Resources state.  It will not complete nor write to
+                * this buffer. */
+               new_before_last_rfd =
+                       (struct rfd *)new_before_last_rx->skb->data;
+               new_before_last_rfd->size = 0;
+               new_before_last_rfd->command |= cpu_to_le16(cb_el);
+               pci_dma_sync_single_for_device(nic->pdev,
+                       new_before_last_rx->dma_addr, sizeof(struct rfd),
+                       PCI_DMA_TODEVICE);
+
+               /* Now that we have a new stopping point, we can clear the old
+                * stopping point.  We must sync twice to get the proper
+                * ordering on the hardware side of things. */
+               old_before_last_rfd->command &= ~cpu_to_le16(cb_el);
+               pci_dma_sync_single_for_device(nic->pdev,
+                       old_before_last_rx->dma_addr, sizeof(struct rfd),
+                       PCI_DMA_TODEVICE);
+               old_before_last_rfd->size = cpu_to_le16(VLAN_ETH_FRAME_LEN);
+               pci_dma_sync_single_for_device(nic->pdev,
+                       old_before_last_rx->dma_addr, sizeof(struct rfd),
+                       PCI_DMA_TODEVICE);
+       }
+
        if(restart_required) {
                // ack the rnr?
-               writeb(stat_ack_rnr, &nic->csr->scb.stat_ack);
-               e100_start_receiver(nic, rx_to_start);
+               iowrite8(stat_ack_rnr, &nic->csr->scb.stat_ack);
+               e100_start_receiver(nic, nic->rx_to_clean);
                if(work_done)
                        (*work_done)++;
        }
@@ -1922,13 +1993,13 @@ static int e100_rx_alloc_list(struct nic *nic)
 {
        struct rx *rx;
        unsigned int i, count = nic->params.rfds.count;
+       struct rfd *before_last;
 
        nic->rx_to_use = nic->rx_to_clean = NULL;
        nic->ru_running = RU_UNINITIALIZED;
 
-       if(!(nic->rxs = kmalloc(sizeof(struct rx) * count, GFP_ATOMIC)))
+       if(!(nic->rxs = kcalloc(count, sizeof(struct rx), GFP_ATOMIC)))
                return -ENOMEM;
-       memset(nic->rxs, 0, sizeof(struct rx) * count);
 
        for(rx = nic->rxs, i = 0; i < count; rx++, i++) {
                rx->next = (i + 1 < count) ? rx + 1 : nic->rxs;
@@ -1938,6 +2009,19 @@ static int e100_rx_alloc_list(struct nic *nic)
                        return -ENOMEM;
                }
        }
+       /* Set the el-bit on the buffer that is before the last buffer.
+        * This lets us update the next pointer on the last buffer without
+        * worrying about hardware touching it.
+        * We set the size to 0 to prevent hardware from touching this buffer.
+        * When the hardware hits the before last buffer with el-bit and size
+        * of 0, it will RNR interrupt, the RU will go into the No Resources
+        * state.  It will not complete nor write to this buffer. */
+       rx = nic->rxs->prev->prev;
+       before_last = (struct rfd *)rx->skb->data;
+       before_last->command |= cpu_to_le16(cb_el);
+       before_last->size = 0;
+       pci_dma_sync_single_for_device(nic->pdev, rx->dma_addr,
+               sizeof(struct rfd), PCI_DMA_TODEVICE);
 
        nic->rx_to_use = nic->rx_to_clean = nic->rxs;
        nic->ru_running = RU_SUSPENDED;
@@ -1945,11 +2029,11 @@ static int e100_rx_alloc_list(struct nic *nic)
        return 0;
 }
 
-static irqreturn_t e100_intr(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t e100_intr(int irq, void *dev_id)
 {
        struct net_device *netdev = dev_id;
        struct nic *nic = netdev_priv(netdev);
-       u8 stat_ack = readb(&nic->csr->scb.stat_ack);
+       u8 stat_ack = ioread8(&nic->csr->scb.stat_ack);
 
        DPRINTK(INTR, DEBUG, "stat_ack = 0x%02X\n", stat_ack);
 
@@ -1958,41 +2042,36 @@ static irqreturn_t e100_intr(int irq, void *dev_id, struct pt_regs *regs)
                return IRQ_NONE;
 
        /* Ack interrupt(s) */
-       writeb(stat_ack, &nic->csr->scb.stat_ack);
+       iowrite8(stat_ack, &nic->csr->scb.stat_ack);
 
        /* We hit Receive No Resource (RNR); restart RU after cleaning */
        if(stat_ack & stat_ack_rnr)
                nic->ru_running = RU_SUSPENDED;
 
-       if(likely(netif_rx_schedule_prep(netdev))) {
+       if(likely(netif_rx_schedule_prep(netdev, &nic->napi))) {
                e100_disable_irq(nic);
-               __netif_rx_schedule(netdev);
+               __netif_rx_schedule(netdev, &nic->napi);
        }
 
        return IRQ_HANDLED;
 }
 
-static int e100_poll(struct net_device *netdev, int *budget)
+static int e100_poll(struct napi_struct *napi, int budget)
 {
-       struct nic *nic = netdev_priv(netdev);
-       unsigned int work_to_do = min(netdev->quota, *budget);
+       struct nic *nic = container_of(napi, struct nic, napi);
+       struct net_device *netdev = nic->netdev;
        unsigned int work_done = 0;
-       int tx_cleaned;
 
-       e100_rx_clean(nic, &work_done, work_to_do);
-       tx_cleaned = e100_tx_clean(nic);
+       e100_rx_clean(nic, &work_done, budget);
+       e100_tx_clean(nic);
 
-       /* If no Rx and Tx cleanup work was done, exit polling mode. */
-       if((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
-               netif_rx_complete(netdev);
+       /* If budget not fully consumed, exit the polling mode */
+       if (work_done < budget) {
+               netif_rx_complete(netdev, napi);
                e100_enable_irq(nic);
-               return 0;
        }
 
-       *budget -= work_done;
-       netdev->quota -= work_done;
-
-       return 1;
+       return work_done;
 }
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
@@ -2001,18 +2080,12 @@ static void e100_netpoll(struct net_device *netdev)
        struct nic *nic = netdev_priv(netdev);
 
        e100_disable_irq(nic);
-       e100_intr(nic->pdev->irq, netdev, NULL);
+       e100_intr(nic->pdev->irq, netdev);
        e100_tx_clean(nic);
        e100_enable_irq(nic);
 }
 #endif
 
-static struct net_device_stats *e100_get_stats(struct net_device *netdev)
-{
-       struct nic *nic = netdev_priv(netdev);
-       return &nic->net_stats;
-}
-
 static int e100_set_mac_address(struct net_device *netdev, void *p)
 {
        struct nic *nic = netdev_priv(netdev);
@@ -2035,7 +2108,6 @@ static int e100_change_mtu(struct net_device *netdev, int new_mtu)
        return 0;
 }
 
-#ifdef CONFIG_PM
 static int e100_asf(struct nic *nic)
 {
        /* ASF can be enabled from eeprom */
@@ -2044,7 +2116,6 @@ static int e100_asf(struct nic *nic)
           !(nic->eeprom[eeprom_config_asf] & eeprom_gcl) &&
           ((nic->eeprom[eeprom_smbus_addr] & 0xFF) != 0xFE));
 }
-#endif
 
 static int e100_up(struct nic *nic)
 {
@@ -2063,7 +2134,7 @@ static int e100_up(struct nic *nic)
                nic->netdev->name, nic->netdev)))
                goto err_no_irq;
        netif_wake_queue(nic->netdev);
-       netif_poll_enable(nic->netdev);
+       napi_enable(&nic->napi);
        /* enable ints _after_ enabling poll, preventing a race between
         * disable ints+schedule */
        e100_enable_irq(nic);
@@ -2081,7 +2152,7 @@ err_rx_clean_list:
 static void e100_down(struct nic *nic)
 {
        /* wait here for poll to complete */
-       netif_poll_disable(nic->netdev);
+       napi_disable(&nic->napi);
        netif_stop_queue(nic->netdev);
        e100_hw_reset(nic);
        free_irq(nic->pdev->irq, nic->netdev);
@@ -2100,12 +2171,13 @@ static void e100_tx_timeout(struct net_device *netdev)
        schedule_work(&nic->tx_timeout_task);
 }
 
-static void e100_tx_timeout_task(struct net_device *netdev)
+static void e100_tx_timeout_task(struct work_struct *work)
 {
-       struct nic *nic = netdev_priv(netdev);
+       struct nic *nic = container_of(work, struct nic, tx_timeout_task);
+       struct net_device *netdev = nic->netdev;
 
        DPRINTK(TX_ERR, DEBUG, "scb.status=0x%02X\n",
-               readb(&nic->csr->scb.status));
+               ioread8(&nic->csr->scb.status));
        e100_down(netdev_priv(netdev));
        e100_up(netdev_priv(netdev));
 }
@@ -2139,7 +2211,7 @@ static int e100_loopback_test(struct nic *nic, enum loopback loopback_mode)
 
        e100_start_receiver(nic, NULL);
 
-       if(!(skb = dev_alloc_skb(ETH_DATA_LEN))) {
+       if(!(skb = netdev_alloc_skb(nic->netdev, ETH_DATA_LEN))) {
                err = -ENOMEM;
                goto err_loopback_none;
        }
@@ -2211,13 +2283,11 @@ static void e100_get_drvinfo(struct net_device *netdev,
        strcpy(info->bus_info, pci_name(nic->pdev));
 }
 
+#define E100_PHY_REGS 0x1C
 static int e100_get_regs_len(struct net_device *netdev)
 {
        struct nic *nic = netdev_priv(netdev);
-#define E100_PHY_REGS          0x1C
-#define E100_REGS_LEN          1 + E100_PHY_REGS + \
-       sizeof(nic->mem->dump_buf) / sizeof(u32)
-       return E100_REGS_LEN * sizeof(u32);
+       return 1 + E100_PHY_REGS + sizeof(nic->mem->dump_buf);
 }
 
 static void e100_get_regs(struct net_device *netdev,
@@ -2227,10 +2297,10 @@ static void e100_get_regs(struct net_device *netdev,
        u32 *buff = p;
        int i;
 
-       regs->version = (1 << 24) | nic->rev_id;
-       buff[0] = readb(&nic->csr->scb.cmd_hi) << 24 |
-               readb(&nic->csr->scb.cmd_lo) << 16 |
-               readw(&nic->csr->scb.status);
+       regs->version = (1 << 24) | nic->pdev->revision;
+       buff[0] = ioread8(&nic->csr->scb.cmd_hi) << 24 |
+               ioread8(&nic->csr->scb.cmd_lo) << 16 |
+               ioread16(&nic->csr->scb.status);
        for(i = E100_PHY_REGS; i >= 0; i--)
                buff[1 + E100_PHY_REGS - i] =
                        mdio_read(netdev, nic->mii.phy_id, i);
@@ -2369,12 +2439,7 @@ static const char e100_gstrings_test[][ETH_GSTRING_LEN] = {
        "Mac loopback     (offline)",
        "Phy loopback     (offline)",
 };
-#define E100_TEST_LEN  sizeof(e100_gstrings_test) / ETH_GSTRING_LEN
-
-static int e100_diag_test_count(struct net_device *netdev)
-{
-       return E100_TEST_LEN;
-}
+#define E100_TEST_LEN  ARRAY_SIZE(e100_gstrings_test)
 
 static void e100_diag_test(struct net_device *netdev,
        struct ethtool_test *test, u64 *data)
@@ -2436,11 +2501,18 @@ static const char e100_gstrings_stats[][ETH_GSTRING_LEN] = {
        "rx_flow_control_unsupported", "tx_tco_packets", "rx_tco_packets",
 };
 #define E100_NET_STATS_LEN     21
-#define E100_STATS_LEN sizeof(e100_gstrings_stats) / ETH_GSTRING_LEN
+#define E100_STATS_LEN ARRAY_SIZE(e100_gstrings_stats)
 
-static int e100_get_stats_count(struct net_device *netdev)
+static int e100_get_sset_count(struct net_device *netdev, int sset)
 {
-       return E100_STATS_LEN;
+       switch (sset) {
+       case ETH_SS_TEST:
+               return E100_TEST_LEN;
+       case ETH_SS_STATS:
+               return E100_STATS_LEN;
+       default:
+               return -EOPNOTSUPP;
+       }
 }
 
 static void e100_get_ethtool_stats(struct net_device *netdev,
@@ -2450,7 +2522,7 @@ static void e100_get_ethtool_stats(struct net_device *netdev,
        int i;
 
        for(i = 0; i < E100_NET_STATS_LEN; i++)
-               data[i] = ((unsigned long *)&nic->net_stats)[i];
+               data[i] = ((unsigned long *)&netdev->stats)[i];
 
        data[i++] = nic->tx_deferred;
        data[i++] = nic->tx_single_collisions;
@@ -2474,7 +2546,7 @@ static void e100_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
        }
 }
 
-static struct ethtool_ops e100_ethtool_ops = {
+static const struct ethtool_ops e100_ethtool_ops = {
        .get_settings           = e100_get_settings,
        .set_settings           = e100_set_settings,
        .get_drvinfo            = e100_get_drvinfo,
@@ -2491,13 +2563,11 @@ static struct ethtool_ops e100_ethtool_ops = {
        .set_eeprom             = e100_set_eeprom,
        .get_ringparam          = e100_get_ringparam,
        .set_ringparam          = e100_set_ringparam,
-       .self_test_count        = e100_diag_test_count,
        .self_test              = e100_diag_test,
        .get_strings            = e100_get_strings,
        .phys_id                = e100_phys_id,
-       .get_stats_count        = e100_get_stats_count,
        .get_ethtool_stats      = e100_get_ethtool_stats,
-       .get_perm_addr          = ethtool_op_get_perm_addr,
+       .get_sset_count         = e100_get_sset_count,
 };
 
 static int e100_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
@@ -2546,6 +2616,7 @@ static int __devinit e100_probe(struct pci_dev *pdev,
        struct net_device *netdev;
        struct nic *nic;
        int err;
+       DECLARE_MAC_BUF(mac);
 
        if(!(netdev = alloc_etherdev(sizeof(struct nic)))) {
                if(((1 << debug) - 1) & NETIF_MSG_PROBE)
@@ -2556,7 +2627,6 @@ static int __devinit e100_probe(struct pci_dev *pdev,
        netdev->open = e100_open;
        netdev->stop = e100_close;
        netdev->hard_start_xmit = e100_xmit_frame;
-       netdev->get_stats = e100_get_stats;
        netdev->set_multicast_list = e100_set_multicast_list;
        netdev->set_mac_address = e100_set_mac_address;
        netdev->change_mtu = e100_change_mtu;
@@ -2564,14 +2634,13 @@ static int __devinit e100_probe(struct pci_dev *pdev,
        SET_ETHTOOL_OPS(netdev, &e100_ethtool_ops);
        netdev->tx_timeout = e100_tx_timeout;
        netdev->watchdog_timeo = E100_WATCHDOG_PERIOD;
-       netdev->poll = e100_poll;
-       netdev->weight = E100_NAPI_WEIGHT;
 #ifdef CONFIG_NET_POLL_CONTROLLER
        netdev->poll_controller = e100_netpoll;
 #endif
-       strcpy(netdev->name, pci_name(pdev));
+       strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
 
        nic = netdev_priv(netdev);
+       netif_napi_add(netdev, &nic->napi, e100_poll, E100_NAPI_WEIGHT);
        nic->netdev = netdev;
        nic->pdev = pdev;
        nic->msg_enable = (1 << debug) - 1;
@@ -2599,10 +2668,12 @@ static int __devinit e100_probe(struct pci_dev *pdev,
                goto err_out_free_res;
        }
 
-       SET_MODULE_OWNER(netdev);
        SET_NETDEV_DEV(netdev, &pdev->dev);
 
-       nic->csr = ioremap(pci_resource_start(pdev, 0), sizeof(struct csr));
+       if (use_io)
+               DPRINTK(PROBE, INFO, "using i/o access mode\n");
+
+       nic->csr = pci_iomap(pdev, (use_io ? 1 : 0), sizeof(struct csr));
        if(!nic->csr) {
                DPRINTK(PROBE, ERR, "Cannot map device registers, aborting.\n");
                err = -ENOMEM;
@@ -2635,8 +2706,7 @@ static int __devinit e100_probe(struct pci_dev *pdev,
        nic->blink_timer.function = e100_blink_led;
        nic->blink_timer.data = (unsigned long)nic;
 
-       INIT_WORK(&nic->tx_timeout_task,
-               (void (*)(void *))e100_tx_timeout_task, netdev);
+       INIT_WORK(&nic->tx_timeout_task, e100_tx_timeout_task);
 
        if((err = e100_alloc(nic))) {
                DPRINTK(PROBE, ERR, "Cannot alloc driver memory, aborting.\n");
@@ -2650,11 +2720,16 @@ static int __devinit e100_probe(struct pci_dev *pdev,
 
        memcpy(netdev->dev_addr, nic->eeprom, ETH_ALEN);
        memcpy(netdev->perm_addr, nic->eeprom, ETH_ALEN);
-       if(!is_valid_ether_addr(netdev->perm_addr)) {
-               DPRINTK(PROBE, ERR, "Invalid MAC address from "
-                       "EEPROM, aborting.\n");
-               err = -EAGAIN;
-               goto err_out_free;
+       if (!is_valid_ether_addr(netdev->perm_addr)) {
+               if (!eeprom_bad_csum_allow) {
+                       DPRINTK(PROBE, ERR, "Invalid MAC address from "
+                               "EEPROM, aborting.\n");
+                       err = -EAGAIN;
+                       goto err_out_free;
+               } else {
+                       DPRINTK(PROBE, ERR, "Invalid MAC address from EEPROM, "
+                               "you MUST configure one.\n");
+               }
        }
 
        /* Wol magic packet can be enabled from eeprom */
@@ -2663,9 +2738,7 @@ static int __devinit e100_probe(struct pci_dev *pdev,
                nic->flags |= wol_magic;
 
        /* ack any pending wake events, disable PME */
-       err = pci_enable_wake(pdev, 0, 0);
-       if (err)
-               DPRINTK(PROBE, ERR, "Error clearing wake event\n");
+       pci_pme_active(pdev, false);
 
        strcpy(netdev->name, "eth%d");
        if((err = register_netdev(netdev))) {
@@ -2673,18 +2746,16 @@ static int __devinit e100_probe(struct pci_dev *pdev,
                goto err_out_free;
        }
 
-       DPRINTK(PROBE, INFO, "addr 0x%llx, irq %d, "
-               "MAC addr %02X:%02X:%02X:%02X:%02X:%02X\n",
-               (unsigned long long)pci_resource_start(pdev, 0), pdev->irq,
-               netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
-               netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
+       DPRINTK(PROBE, INFO, "addr 0x%llx, irq %d, MAC addr %s\n",
+               (unsigned long long)pci_resource_start(pdev, use_io ? 1 : 0),
+               pdev->irq, print_mac(mac, netdev->dev_addr));
 
        return 0;
 
 err_out_free:
        e100_free(nic);
 err_out_iounmap:
-       iounmap(nic->csr);
+       pci_iounmap(pdev, nic->csr);
 err_out_free_res:
        pci_release_regions(pdev);
 err_out_disable_pdev:
@@ -2703,7 +2774,7 @@ static void __devexit e100_remove(struct pci_dev *pdev)
                struct nic *nic = netdev_priv(netdev);
                unregister_netdev(netdev);
                e100_free(nic);
-               iounmap(nic->csr);
+               pci_iounmap(pdev, nic->csr);
                free_netdev(netdev);
                pci_release_regions(pdev);
                pci_disable_device(pdev);
@@ -2711,86 +2782,73 @@ static void __devexit e100_remove(struct pci_dev *pdev)
        }
 }
 
-#ifdef CONFIG_PM
 static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        struct net_device *netdev = pci_get_drvdata(pdev);
        struct nic *nic = netdev_priv(netdev);
-       int retval;
 
-       if(netif_running(netdev))
+       if (netif_running(netdev))
                e100_down(nic);
-       e100_hw_reset(nic);
        netif_device_detach(netdev);
 
        pci_save_state(pdev);
-       retval = pci_enable_wake(pdev, pci_choose_state(pdev, state),
-                                nic->flags & (wol_magic | e100_asf(nic)));
-       if (retval)
-               DPRINTK(PROBE,ERR, "Error enabling wake\n");
+
+       if ((nic->flags & wol_magic) | e100_asf(nic)) {
+               pci_enable_wake(pdev, PCI_D3hot, 1);
+               pci_enable_wake(pdev, PCI_D3cold, 1);
+       } else {
+               pci_enable_wake(pdev, PCI_D3hot, 0);
+               pci_enable_wake(pdev, PCI_D3cold, 0);
+       }
+
        pci_disable_device(pdev);
-       retval = pci_set_power_state(pdev, pci_choose_state(pdev, state));
-       if (retval)
-               DPRINTK(PROBE,ERR, "Error %d setting power state\n", retval);
+       pci_set_power_state(pdev, PCI_D3hot);
 
        return 0;
 }
 
+#ifdef CONFIG_PM
 static int e100_resume(struct pci_dev *pdev)
 {
        struct net_device *netdev = pci_get_drvdata(pdev);
        struct nic *nic = netdev_priv(netdev);
-       int retval;
 
-       retval = pci_set_power_state(pdev, PCI_D0);
-       if (retval)
-               DPRINTK(PROBE,ERR, "Error waking adapter\n");
+       pci_set_power_state(pdev, PCI_D0);
        pci_restore_state(pdev);
        /* ack any pending wake events, disable PME */
-       retval = pci_enable_wake(pdev, 0, 0);
-       if (retval)
-               DPRINTK(PROBE,ERR, "Error clearing wake events\n");
+       pci_enable_wake(pdev, 0, 0);
 
        netif_device_attach(netdev);
-       if(netif_running(netdev))
+       if (netif_running(netdev))
                e100_up(nic);
 
        return 0;
 }
-#endif
-
+#endif /* CONFIG_PM */
 
 static void e100_shutdown(struct pci_dev *pdev)
 {
-       struct net_device *netdev = pci_get_drvdata(pdev);
-       struct nic *nic = netdev_priv(netdev);
-       int retval;
-
-#ifdef CONFIG_PM
-       retval = pci_enable_wake(pdev, 0, nic->flags & (wol_magic | e100_asf(nic)));
-#else
-       retval = pci_enable_wake(pdev, 0, nic->flags & (wol_magic));
-#endif
-       if (retval)
-               DPRINTK(PROBE,ERR, "Error enabling wake\n");
+       e100_suspend(pdev, PMSG_SUSPEND);
 }
 
 /* ------------------ PCI Error Recovery infrastructure  -------------- */
 /**
  * e100_io_error_detected - called when PCI error is detected.
  * @pdev: Pointer to PCI device
- * @state: The current pci conneection state
+ * @state: The current pci connection state
  */
 static pci_ers_result_t e100_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
 {
        struct net_device *netdev = pci_get_drvdata(pdev);
+       struct nic *nic = netdev_priv(netdev);
 
-       /* Similar to calling e100_down(), but avoids adpater I/O. */
+       /* Similar to calling e100_down(), but avoids adapter I/O. */
        netdev->stop(netdev);
 
-       /* Detach; put netif into state similar to hotplug unplug. */
-       netif_poll_enable(netdev);
+       /* Detach; put netif into state similar to hotplug unplug. */
+       napi_enable(&nic->napi);
        netif_device_detach(netdev);
+       pci_disable_device(pdev);
 
        /* Request a slot reset. */
        return PCI_ERS_RESULT_NEED_RESET;
@@ -2856,6 +2914,7 @@ static struct pci_driver e100_driver = {
        .probe =        e100_probe,
        .remove =       __devexit_p(e100_remove),
 #ifdef CONFIG_PM
+       /* Power Management hooks */
        .suspend =      e100_suspend,
        .resume =       e100_resume,
 #endif
@@ -2869,7 +2928,7 @@ static int __init e100_init_module(void)
                printk(KERN_INFO PFX "%s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
                printk(KERN_INFO PFX "%s\n", DRV_COPYRIGHT);
        }
-       return pci_module_init(&e100_driver);
+       return pci_register_driver(&e100_driver);
 }
 
 static void __exit e100_cleanup_module(void)