r6040: save and restore MIER correctly in the interrupt routine
[safe/jmp/linux-2.6] / drivers / net / e100.c
index 720994b..dce7ff2 100644 (file)
@@ -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.23-k4"DRV_EXT
+#define DRV_VERSION            "3.5.23-k6"DRV_EXT
 #define DRV_DESCRIPTION                "Intel(R) PRO/100 Network Driver"
 #define DRV_COPYRIGHT          "Copyright(c) 1999-2006 Intel Corporation"
 #define PFX                    DRV_NAME ": "
@@ -184,7 +191,7 @@ 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, \
@@ -281,6 +288,7 @@ struct csr {
 };
 
 enum scb_status {
+       rus_no_res       = 0x08,
        rus_ready        = 0x10,
        rus_mask         = 0x3C,
 };
@@ -393,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 {
@@ -453,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 {
@@ -474,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;
@@ -491,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 {
@@ -544,7 +552,7 @@ struct nic {
        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 {
@@ -585,7 +593,7 @@ struct nic {
 
        u16 leds;
        u16 eeprom_wc;
-       u16 eeprom[256];
+       __le16 eeprom[256];
        spinlock_t mdio_lock;
 };
 
@@ -663,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;
@@ -672,7 +680,7 @@ 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 */
@@ -701,7 +709,7 @@ static void e100_eeprom_write(struct nic *nic, u16 addr_len, u16 addr, u16 data)
 };
 
 /* 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;
@@ -738,7 +746,7 @@ static u16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr)
        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 */
@@ -753,13 +761,12 @@ 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");
                if (!eeprom_bad_csum_allow)
                        return -EAGAIN;
@@ -786,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]);
 
@@ -947,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 */
@@ -1324,7 +1331,7 @@ 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 */
+       /* 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 */
@@ -1485,15 +1492,15 @@ static void e100_update_stats(struct nic *nic)
        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);
@@ -1573,11 +1580,13 @@ static void e100_watchdog(unsigned long data)
        mii_ethtool_gset(&nic->mii, &cmd);
 
        if(mii_link_ok(&nic->mii) && !netif_carrier_ok(nic->netdev)) {
-               DPRINTK(LINK, INFO, "link up, %sMbps, %s-duplex\n",
-                       cmd.speed == SPEED_100 ? "100" : "10",
-                       cmd.duplex == DUPLEX_FULL ? "full" : "half");
+               printk(KERN_INFO "e100: %s NIC Link is Up %s Mbps %s Duplex\n",
+                      nic->netdev->name,
+                      cmd.speed == SPEED_100 ? "100" : "10",
+                      cmd.duplex == DUPLEX_FULL ? "Full" : "Half");
        } else if(!mii_link_ok(&nic->mii) && netif_carrier_ok(nic->netdev)) {
-               DPRINTK(LINK, INFO, "link down\n");
+               printk(KERN_INFO "e100: %s NIC Link is Down\n",
+                      nic->netdev->name);
        }
 
        mii_check_link(&nic->mii);
@@ -1783,7 +1792,7 @@ static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)
        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;
@@ -1791,15 +1800,13 @@ 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);
+                       sizeof(struct rfd), PCI_DMA_BIDIRECTIONAL);
        }
 
        return 0;
@@ -1818,14 +1825,25 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,
 
        /* Need to sync before taking a peek at cb_complete bit */
        pci_dma_sync_single_for_cpu(nic->pdev, rx->dma_addr,
-               sizeof(struct rfd), PCI_DMA_FROMDEVICE);
+               sizeof(struct rfd), PCI_DMA_BIDIRECTIONAL);
        rfd_status = le16_to_cpu(rfd->status);
 
        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;
@@ -1834,11 +1852,20 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,
 
        /* Get data */
        pci_unmap_single(nic->pdev, rx->dma_addr,
-               RFD_BUF_LEN, PCI_DMA_FROMDEVICE);
+               RFD_BUF_LEN, PCI_DMA_BIDIRECTIONAL);
+
+       /* 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)) {
 
-       /* this allows for a fast restart without re-enabling interrupts */
-       if(le16_to_cpu(rfd->command) & cb_el)
+           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));
@@ -1855,7 +1882,6 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,
        } else {
                dev->stats.rx_packets++;
                dev->stats.rx_bytes += actual_size;
-               nic->netdev->last_rx = jiffies;
                netif_receive_skb(skb);
                if(work_done)
                        (*work_done)++;
@@ -1870,31 +1896,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) {
@@ -1902,10 +1927,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_BIDIRECTIONAL);
+
+               /* 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_BIDIRECTIONAL);
+               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_BIDIRECTIONAL);
+       }
+
        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,7 +1979,7 @@ static void e100_rx_clean_list(struct nic *nic)
                for(rx = nic->rxs, i = 0; i < count; rx++, i++) {
                        if(rx->skb) {
                                pci_unmap_single(nic->pdev, rx->dma_addr,
-                                       RFD_BUF_LEN, PCI_DMA_FROMDEVICE);
+                                       RFD_BUF_LEN, PCI_DMA_BIDIRECTIONAL);
                                dev_kfree_skb(rx->skb);
                        }
                }
@@ -1937,6 +1994,7 @@ 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;
@@ -1952,6 +2010,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_BIDIRECTIONAL);
 
        nic->rx_to_use = nic->rx_to_clean = nic->rxs;
        nic->ru_running = RU_SUSPENDED;
@@ -1990,14 +2061,13 @@ static int e100_poll(struct napi_struct *napi, int budget)
 {
        struct nic *nic = container_of(napi, struct nic, napi);
        struct net_device *netdev = nic->netdev;
-       int work_done = 0;
-       int tx_cleaned;
+       unsigned int work_done = 0;
 
        e100_rx_clean(nic, &work_done, budget);
-       tx_cleaned = e100_tx_clean(nic);
+       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)) {
+       /* If budget not fully consumed, exit the polling mode */
+       if (work_done < budget) {
                netif_rx_complete(netdev, napi);
                e100_enable_irq(nic);
        }
@@ -2153,7 +2223,7 @@ static int e100_loopback_test(struct nic *nic, enum loopback loopback_mode)
        msleep(10);
 
        pci_dma_sync_single_for_cpu(nic->pdev, nic->rx_to_clean->dma_addr,
-                       RFD_BUF_LEN, PCI_DMA_FROMDEVICE);
+                       RFD_BUF_LEN, PCI_DMA_BIDIRECTIONAL);
 
        if(memcmp(nic->rx_to_clean->skb->data + sizeof(struct rfd),
           skb->data, ETH_DATA_LEN))
@@ -2214,13 +2284,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,
@@ -2255,7 +2323,8 @@ static int e100_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
 {
        struct nic *nic = netdev_priv(netdev);
 
-       if(wol->wolopts != WAKE_MAGIC && wol->wolopts != 0)
+       if ((wol->wolopts && wol->wolopts != WAKE_MAGIC) ||
+           !device_can_wakeup(&nic->pdev->dev))
                return -EOPNOTSUPP;
 
        if(wol->wolopts)
@@ -2263,6 +2332,8 @@ static int e100_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
        else
                nic->flags &= ~wol_magic;
 
+       device_set_wakeup_enable(&nic->pdev->dev, wol->wolopts);
+
        e100_exec_cb(nic, NULL, e100_configure);
 
        return 0;
@@ -2372,12 +2443,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)
@@ -2439,11 +2505,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,
@@ -2494,12 +2567,11 @@ static const 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_sset_count         = e100_get_sset_count,
 };
 
 static int e100_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
@@ -2542,13 +2614,27 @@ static int e100_close(struct net_device *netdev)
        return 0;
 }
 
+static const struct net_device_ops e100_netdev_ops = {
+       .ndo_open               = e100_open,
+       .ndo_stop               = e100_close,
+       .ndo_start_xmit         = e100_xmit_frame,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_set_multicast_list = e100_set_multicast_list,
+       .ndo_set_mac_address    = e100_set_mac_address,
+       .ndo_change_mtu         = e100_change_mtu,
+       .ndo_do_ioctl           = e100_do_ioctl,
+       .ndo_tx_timeout         = e100_tx_timeout,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller    = e100_netpoll,
+#endif
+};
+
 static int __devinit e100_probe(struct pci_dev *pdev,
        const struct pci_device_id *ent)
 {
        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,19 +2642,9 @@ static int __devinit e100_probe(struct pci_dev *pdev,
                return -ENOMEM;
        }
 
-       netdev->open = e100_open;
-       netdev->stop = e100_close;
-       netdev->hard_start_xmit = e100_xmit_frame;
-       netdev->set_multicast_list = e100_set_multicast_list;
-       netdev->set_mac_address = e100_set_mac_address;
-       netdev->change_mtu = e100_change_mtu;
-       netdev->do_ioctl = e100_do_ioctl;
+       netdev->netdev_ops = &e100_netdev_ops;
        SET_ETHTOOL_OPS(netdev, &e100_ethtool_ops);
-       netdev->tx_timeout = e100_tx_timeout;
        netdev->watchdog_timeo = E100_WATCHDOG_PERIOD;
-#ifdef CONFIG_NET_POLL_CONTROLLER
-       netdev->poll_controller = e100_netpoll;
-#endif
        strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
 
        nic = netdev_priv(netdev);
@@ -2666,13 +2742,13 @@ static int __devinit e100_probe(struct pci_dev *pdev,
 
        /* Wol magic packet can be enabled from eeprom */
        if((nic->mac >= mac_82558_D101_A4) &&
-          (nic->eeprom[eeprom_id] & eeprom_id_wol))
+          (nic->eeprom[eeprom_id] & eeprom_id_wol)) {
                nic->flags |= wol_magic;
+               device_set_wakeup_enable(&pdev->dev, true);
+       }
 
        /* 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))) {
@@ -2680,9 +2756,9 @@ static int __devinit e100_probe(struct pci_dev *pdev,
                goto err_out_free;
        }
 
-       DPRINTK(PROBE, INFO, "addr 0x%llx, irq %d, MAC addr %s\n",
+       DPRINTK(PROBE, INFO, "addr 0x%llx, irq %d, MAC addr %pM\n",
                (unsigned long long)pci_resource_start(pdev, use_io ? 1 : 0),
-               pdev->irq, print_mac(mac, netdev->dev_addr));
+               pdev->irq, netdev->dev_addr);
 
        return 0;
 
@@ -2708,7 +2784,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);
@@ -2716,35 +2792,31 @@ 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);
 
        if (netif_running(netdev))
-               napi_disable(&nic->napi);
-       del_timer_sync(&nic->watchdog);
-       netif_carrier_off(nic->netdev);
+               e100_down(nic);
        netif_device_detach(netdev);
 
        pci_save_state(pdev);
 
        if ((nic->flags & wol_magic) | e100_asf(nic)) {
-               pci_enable_wake(pdev, PCI_D3hot, 1);
-               pci_enable_wake(pdev, PCI_D3cold, 1);
+               if (pci_enable_wake(pdev, PCI_D3cold, true))
+                       pci_enable_wake(pdev, PCI_D3hot, true);
        } else {
-               pci_enable_wake(pdev, PCI_D3hot, 0);
-               pci_enable_wake(pdev, PCI_D3cold, 0);
+               pci_enable_wake(pdev, PCI_D3hot, false);
        }
 
        pci_disable_device(pdev);
-       free_irq(pdev->irq, netdev);
        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);
@@ -2765,41 +2837,24 @@ static int e100_resume(struct pci_dev *pdev)
 
 static void e100_shutdown(struct pci_dev *pdev)
 {
-       struct net_device *netdev = pci_get_drvdata(pdev);
-       struct nic *nic = netdev_priv(netdev);
-
-       if (netif_running(netdev))
-               napi_disable(&nic->napi);
-       del_timer_sync(&nic->watchdog);
-       netif_carrier_off(nic->netdev);
-
-       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);
-       pci_set_power_state(pdev, PCI_D3hot);
+       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. */
-       netdev->stop(netdev);
+       /* Similar to calling e100_down(), but avoids adapter I/O. */
+       e100_close(netdev);
 
-       /* Detach; put netif into state similar to hotplug unplug. */
+       /* Detach; put netif into state similar to hotplug unplug. */
        napi_enable(&nic->napi);
        netif_device_detach(netdev);
        pci_disable_device(pdev);