Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh...
[pandora-kernel.git] / drivers / net / e1000 / e1000_main.c
index f772e4d..a710237 100644 (file)
@@ -36,7 +36,7 @@ static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
 #else
 #define DRIVERNAPI "-NAPI"
 #endif
-#define DRV_VERSION "7.3.15-k2"DRIVERNAPI
+#define DRV_VERSION "7.3.20-k2"DRIVERNAPI
 char e1000_driver_version[] = DRV_VERSION;
 static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
 
@@ -213,6 +213,12 @@ static void e1000_netpoll (struct net_device *netdev);
 
 extern void e1000_check_options(struct e1000_adapter *adapter);
 
+#define COPYBREAK_DEFAULT 256
+static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
+module_param(copybreak, uint, 0644);
+MODULE_PARM_DESC(copybreak,
+       "Maximum size of packet that is copied to a new buffer on receive");
+
 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
                      pci_channel_state_t state);
 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
@@ -264,7 +270,13 @@ e1000_init_module(void)
        printk(KERN_INFO "%s\n", e1000_copyright);
 
        ret = pci_register_driver(&e1000_driver);
-
+       if (copybreak != COPYBREAK_DEFAULT) {
+               if (copybreak == 0)
+                       printk(KERN_INFO "e1000: copybreak disabled\n");
+               else
+                       printk(KERN_INFO "e1000: copybreak enabled for "
+                              "packets <= %u bytes\n", copybreak);
+       }
        return ret;
 }
 
@@ -544,7 +556,8 @@ e1000_up(struct e1000_adapter *adapter)
 
        clear_bit(__E1000_DOWN, &adapter->flags);
 
-       mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
+       /* fire a link change interrupt to start the watchdog */
+       E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
        return 0;
 }
 
@@ -661,16 +674,34 @@ e1000_reinit_locked(struct e1000_adapter *adapter)
 void
 e1000_reset(struct e1000_adapter *adapter)
 {
-       uint32_t pba;
+       uint32_t pba = 0, tx_space, min_tx_space, min_rx_space;
        uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
+       boolean_t legacy_pba_adjust = FALSE;
 
        /* Repartition Pba for greater than 9k mtu
         * To take effect CTRL.RST is required.
         */
 
        switch (adapter->hw.mac_type) {
+       case e1000_82542_rev2_0:
+       case e1000_82542_rev2_1:
+       case e1000_82543:
+       case e1000_82544:
+       case e1000_82540:
+       case e1000_82541:
+       case e1000_82541_rev_2:
+               legacy_pba_adjust = TRUE;
+               pba = E1000_PBA_48K;
+               break;
+       case e1000_82545:
+       case e1000_82545_rev_3:
+       case e1000_82546:
+       case e1000_82546_rev_3:
+               pba = E1000_PBA_48K;
+               break;
        case e1000_82547:
        case e1000_82547_rev_2:
+               legacy_pba_adjust = TRUE;
                pba = E1000_PBA_30K;
                break;
        case e1000_82571:
@@ -679,27 +710,80 @@ e1000_reset(struct e1000_adapter *adapter)
                pba = E1000_PBA_38K;
                break;
        case e1000_82573:
-               pba = E1000_PBA_12K;
+               pba = E1000_PBA_20K;
                break;
        case e1000_ich8lan:
                pba = E1000_PBA_8K;
-               break;
-       default:
-               pba = E1000_PBA_48K;
+       case e1000_undefined:
+       case e1000_num_macs:
                break;
        }
 
-       if ((adapter->hw.mac_type != e1000_82573) &&
-          (adapter->netdev->mtu > E1000_RXBUFFER_8192))
-               pba -= 8; /* allocate more FIFO for Tx */
+       if (legacy_pba_adjust == TRUE) {
+               if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
+                       pba -= 8; /* allocate more FIFO for Tx */
 
+               if (adapter->hw.mac_type == e1000_82547) {
+                       adapter->tx_fifo_head = 0;
+                       adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
+                       adapter->tx_fifo_size =
+                               (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
+                       atomic_set(&adapter->tx_fifo_stall, 0);
+               }
+       } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
+               /* adjust PBA for jumbo frames */
+               E1000_WRITE_REG(&adapter->hw, PBA, pba);
+
+               /* To maintain wire speed transmits, the Tx FIFO should be
+                * large enough to accomodate two full transmit packets,
+                * rounded up to the next 1KB and expressed in KB.  Likewise,
+                * the Rx FIFO should be large enough to accomodate at least
+                * one full receive packet and is similarly rounded up and
+                * expressed in KB. */
+               pba = E1000_READ_REG(&adapter->hw, PBA);
+               /* upper 16 bits has Tx packet buffer allocation size in KB */
+               tx_space = pba >> 16;
+               /* lower 16 bits has Rx packet buffer allocation size in KB */
+               pba &= 0xffff;
+               /* don't include ethernet FCS because hardware appends/strips */
+               min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
+                              VLAN_TAG_SIZE;
+               min_tx_space = min_rx_space;
+               min_tx_space *= 2;
+               E1000_ROUNDUP(min_tx_space, 1024);
+               min_tx_space >>= 10;
+               E1000_ROUNDUP(min_rx_space, 1024);
+               min_rx_space >>= 10;
+
+               /* If current Tx allocation is less than the min Tx FIFO size,
+                * and the min Tx FIFO size is less than the current Rx FIFO
+                * allocation, take space away from current Rx allocation */
+               if (tx_space < min_tx_space &&
+                   ((min_tx_space - tx_space) < pba)) {
+                       pba = pba - (min_tx_space - tx_space);
+
+                       /* PCI/PCIx hardware has PBA alignment constraints */
+                       switch (adapter->hw.mac_type) {
+                       case e1000_82545 ... e1000_82546_rev_3:
+                               pba &= ~(E1000_PBA_8K - 1);
+                               break;
+                       default:
+                               break;
+                       }
 
-       if (adapter->hw.mac_type == e1000_82547) {
-               adapter->tx_fifo_head = 0;
-               adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
-               adapter->tx_fifo_size =
-                       (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
-               atomic_set(&adapter->tx_fifo_stall, 0);
+                       /* if short on rx space, rx wins and must trump tx
+                        * adjustment or use Early Receive if available */
+                       if (pba < min_rx_space) {
+                               switch (adapter->hw.mac_type) {
+                               case e1000_82573:
+                                       /* ERT enabled in e1000_configure_rx */
+                                       break;
+                               default:
+                                       pba = min_rx_space;
+                                       break;
+                               }
+                       }
+               }
        }
 
        E1000_WRITE_REG(&adapter->hw, PBA, pba);
@@ -906,16 +990,12 @@ e1000_probe(struct pci_dev *pdev,
                        netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
        }
 
-#ifdef NETIF_F_TSO
        if ((adapter->hw.mac_type >= e1000_82544) &&
           (adapter->hw.mac_type != e1000_82547))
                netdev->features |= NETIF_F_TSO;
 
-#ifdef NETIF_F_TSO6
        if (adapter->hw.mac_type > e1000_82547_rev_2)
                netdev->features |= NETIF_F_TSO6;
-#endif
-#endif
        if (pci_using_dac)
                netdev->features |= NETIF_F_HIGHDMA;
 
@@ -1337,10 +1417,6 @@ e1000_open(struct net_device *netdev)
        if ((err = e1000_setup_all_rx_resources(adapter)))
                goto err_setup_rx;
 
-       err = e1000_request_irq(adapter);
-       if (err)
-               goto err_req_irq;
-
        e1000_power_up_phy(adapter);
 
        if ((err = e1000_up(adapter)))
@@ -1351,6 +1427,10 @@ e1000_open(struct net_device *netdev)
                e1000_update_mng_vlan(adapter);
        }
 
+       err = e1000_request_irq(adapter);
+       if (err)
+               goto err_req_irq;
+
        /* If AMT is enabled, let the firmware know that the network
         * interface is now open */
        if (adapter->hw.mac_type == e1000_82573 &&
@@ -1359,10 +1439,10 @@ e1000_open(struct net_device *netdev)
 
        return E1000_SUCCESS;
 
+err_req_irq:
+       e1000_down(adapter);
 err_up:
        e1000_power_down_phy(adapter);
-       e1000_free_irq(adapter);
-err_req_irq:
        e1000_free_all_rx_resources(adapter);
 err_setup_rx:
        e1000_free_all_tx_resources(adapter);
@@ -1576,9 +1656,9 @@ e1000_configure_tx(struct e1000_adapter *adapter)
        }
 
        /* Set the default values for the Tx Inter Packet Gap timer */
-
-       if (hw->media_type == e1000_media_type_fiber ||
-           hw->media_type == e1000_media_type_internal_serdes)
+       if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
+           (hw->media_type == e1000_media_type_fiber ||
+            hw->media_type == e1000_media_type_internal_serdes))
                tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
        else
                tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
@@ -2499,15 +2579,22 @@ e1000_watchdog(unsigned long data)
 
        if (link) {
                if (!netif_carrier_ok(netdev)) {
+                       uint32_t ctrl;
                        boolean_t txb2b = 1;
                        e1000_get_speed_and_duplex(&adapter->hw,
                                                   &adapter->link_speed,
                                                   &adapter->link_duplex);
 
-                       DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
-                              adapter->link_speed,
-                              adapter->link_duplex == FULL_DUPLEX ?
-                              "Full Duplex" : "Half Duplex");
+                       ctrl = E1000_READ_REG(&adapter->hw, CTRL);
+                       DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
+                               "Flow Control: %s\n",
+                               adapter->link_speed,
+                               adapter->link_duplex == FULL_DUPLEX ?
+                               "Full Duplex" : "Half Duplex",
+                               ((ctrl & E1000_CTRL_TFCE) && (ctrl &
+                               E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
+                               E1000_CTRL_RFCE) ? "RX" : ((ctrl &
+                               E1000_CTRL_TFCE) ? "TX" : "None" )));
 
                        /* tweak tx_queue_len according to speed/duplex
                         * and adjust the timeout factor */
@@ -2535,7 +2622,6 @@ e1000_watchdog(unsigned long data)
                                E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
                        }
 
-#ifdef NETIF_F_TSO
                        /* disable TSO for pcie and 10/100 speeds, to avoid
                         * some hardware issues */
                        if (!adapter->tso_force &&
@@ -2546,22 +2632,17 @@ e1000_watchdog(unsigned long data)
                                        DPRINTK(PROBE,INFO,
                                        "10/100 speed: disabling TSO\n");
                                        netdev->features &= ~NETIF_F_TSO;
-#ifdef NETIF_F_TSO6
                                        netdev->features &= ~NETIF_F_TSO6;
-#endif
                                        break;
                                case SPEED_1000:
                                        netdev->features |= NETIF_F_TSO;
-#ifdef NETIF_F_TSO6
                                        netdev->features |= NETIF_F_TSO6;
-#endif
                                        break;
                                default:
                                        /* oops */
                                        break;
                                }
                        }
-#endif
 
                        /* enable transmits in the hardware, need to do this
                         * after setting TARC0 */
@@ -2573,6 +2654,13 @@ e1000_watchdog(unsigned long data)
                        netif_wake_queue(netdev);
                        mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
                        adapter->smartspeed = 0;
+               } else {
+                       /* make sure the receive unit is started */
+                       if (adapter->hw.rx_needs_kicking) {
+                               struct e1000_hw *hw = &adapter->hw;
+                               uint32_t rctl = E1000_READ_REG(hw, RCTL);
+                               E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
+                       }
                }
        } else {
                if (netif_carrier_ok(netdev)) {
@@ -2784,7 +2872,6 @@ static int
 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
           struct sk_buff *skb)
 {
-#ifdef NETIF_F_TSO
        struct e1000_context_desc *context_desc;
        struct e1000_buffer *buffer_info;
        unsigned int i;
@@ -2813,7 +2900,6 @@ e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                                                   0);
                        cmd_length = E1000_TXD_CMD_IP;
                        ipcse = skb->h.raw - skb->data - 1;
-#ifdef NETIF_F_TSO6
                } else if (skb->protocol == htons(ETH_P_IPV6)) {
                        skb->nh.ipv6h->payload_len = 0;
                        skb->h.th->check =
@@ -2823,7 +2909,6 @@ e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                                                 IPPROTO_TCP,
                                                 0);
                        ipcse = 0;
-#endif
                }
                ipcss = skb->nh.raw - skb->data;
                ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
@@ -2856,8 +2941,6 @@ e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
 
                return TRUE;
        }
-#endif
-
        return FALSE;
 }
 
@@ -2877,8 +2960,9 @@ e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                buffer_info = &tx_ring->buffer_info[i];
                context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
 
+               context_desc->lower_setup.ip_config = 0;
                context_desc->upper_setup.tcp_fields.tucss = css;
-               context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
+               context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
                context_desc->upper_setup.tcp_fields.tucse = 0;
                context_desc->tcp_seg_setup.data = 0;
                context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
@@ -2914,7 +2998,6 @@ e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
        while (len) {
                buffer_info = &tx_ring->buffer_info[i];
                size = min(len, max_per_txd);
-#ifdef NETIF_F_TSO
                /* Workaround for Controller erratum --
                 * descriptor for non-tso packet in a linear SKB that follows a
                 * tso gets written back prematurely before the data is fully
@@ -2929,7 +3012,6 @@ e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                 * in TSO mode.  Append 4-byte sentinel desc */
                if (unlikely(mss && !nr_frags && size == len && size > 8))
                        size -= 4;
-#endif
                /* work-around for errata 10 and it applies
                 * to all controllers in PCI-X mode
                 * The fix is to make sure that the first descriptor of a
@@ -2971,12 +3053,10 @@ e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                while (len) {
                        buffer_info = &tx_ring->buffer_info[i];
                        size = min(len, max_per_txd);
-#ifdef NETIF_F_TSO
                        /* Workaround for premature desc write-backs
                         * in TSO mode.  Append 4-byte sentinel desc */
                        if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
                                size -= 4;
-#endif
                        /* Workaround for potential 82544 hang in PCI-X.
                         * Avoid terminating buffers within evenly-aligned
                         * dwords. */
@@ -3201,7 +3281,6 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
        if (adapter->hw.mac_type >= e1000_82571)
                max_per_txd = 8192;
 
-#ifdef NETIF_F_TSO
        mss = skb_shinfo(skb)->gso_size;
        /* The controller does a simple calculation to
         * make sure there is enough room in the FIFO before
@@ -3221,6 +3300,16 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
                if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
                        switch (adapter->hw.mac_type) {
                                unsigned int pull_size;
+                       case e1000_82544:
+                               /* Make sure we have room to chop off 4 bytes,
+                                * and that the end alignment will work out to
+                                * this hardware's requirements
+                                * NOTE: this is a TSO only workaround
+                                * if end byte alignment not correct move us
+                                * into the next dword */
+                               if ((unsigned long)(skb->tail - 1) & 4)
+                                       break;
+                               /* fall through */
                        case e1000_82571:
                        case e1000_82572:
                        case e1000_82573:
@@ -3245,16 +3334,10 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
        if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
                count++;
        count++;
-#else
-       if (skb->ip_summed == CHECKSUM_PARTIAL)
-               count++;
-#endif
 
-#ifdef NETIF_F_TSO
        /* Controller Erratum workaround */
        if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
                count++;
-#endif
 
        count += TXD_USE_COUNT(len, max_txd_pwr);
 
@@ -3472,12 +3555,11 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu)
                adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
 
        netdev->mtu = new_mtu;
+       adapter->hw.max_frame_size = max_frame;
 
        if (netif_running(netdev))
                e1000_reinit_locked(adapter);
 
-       adapter->hw.max_frame_size = max_frame;
-
        return 0;
 }
 
@@ -3502,7 +3584,7 @@ e1000_update_stats(struct e1000_adapter *adapter)
         */
        if (adapter->link_speed == 0)
                return;
-       if (pdev->error_state && pdev->error_state != pci_channel_io_normal)
+       if (pci_channel_offline(pdev))
                return;
 
        spin_lock_irqsave(&adapter->stats_lock, flags);
@@ -3648,6 +3730,13 @@ e1000_update_stats(struct e1000_adapter *adapter)
                        adapter->phy_stats.receive_errors += phy_tmp;
        }
 
+       /* Management Stats */
+       if (adapter->hw.has_smbus) {
+               adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC);
+               adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC);
+               adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC);
+       }
+
        spin_unlock_irqrestore(&adapter->stats_lock, flags);
 }
 #ifdef CONFIG_PCI_MSI
@@ -3658,8 +3747,8 @@ e1000_update_stats(struct e1000_adapter *adapter)
  * @data: pointer to a network interface device structure
  **/
 
-static
-irqreturn_t e1000_intr_msi(int irq, void *data)
+static irqreturn_t
+e1000_intr_msi(int irq, void *data)
 {
        struct net_device *netdev = data;
        struct e1000_adapter *adapter = netdev_priv(netdev);
@@ -3667,49 +3756,27 @@ irqreturn_t e1000_intr_msi(int irq, void *data)
 #ifndef CONFIG_E1000_NAPI
        int i;
 #endif
+       uint32_t icr = E1000_READ_REG(hw, ICR);
 
-       /* this code avoids the read of ICR but has to get 1000 interrupts
-        * at every link change event before it will notice the change */
-       if (++adapter->detect_link >= 1000) {
-               uint32_t icr = E1000_READ_REG(hw, ICR);
 #ifdef CONFIG_E1000_NAPI
-               /* read ICR disables interrupts using IAM, so keep up with our
-                * enable/disable accounting */
-               atomic_inc(&adapter->irq_sem);
+       /* read ICR disables interrupts using IAM, so keep up with our
+        * enable/disable accounting */
+       atomic_inc(&adapter->irq_sem);
 #endif
-               adapter->detect_link = 0;
-               if ((icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) &&
-                   (icr & E1000_ICR_INT_ASSERTED)) {
-                       hw->get_link_status = 1;
-                       /* 80003ES2LAN workaround--
-                       * For packet buffer work-around on link down event;
-                       * disable receives here in the ISR and
-                       * reset adapter in watchdog
-                       */
-                       if (netif_carrier_ok(netdev) &&
-                           (adapter->hw.mac_type == e1000_80003es2lan)) {
-                               /* disable receives */
-                               uint32_t rctl = E1000_READ_REG(hw, RCTL);
-                               E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
-                       }
-                       /* guard against interrupt when we're going down */
-                       if (!test_bit(__E1000_DOWN, &adapter->flags))
-                               mod_timer(&adapter->watchdog_timer,
-                                         jiffies + 1);
+       if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
+               hw->get_link_status = 1;
+               /* 80003ES2LAN workaround-- For packet buffer work-around on
+                * link down event; disable receives here in the ISR and reset
+                * adapter in watchdog */
+               if (netif_carrier_ok(netdev) &&
+                   (adapter->hw.mac_type == e1000_80003es2lan)) {
+                       /* disable receives */
+                       uint32_t rctl = E1000_READ_REG(hw, RCTL);
+                       E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
                }
-       } else {
-               E1000_WRITE_REG(hw, ICR, (0xffffffff & ~(E1000_ICR_RXSEQ |
-                                                        E1000_ICR_LSC)));
-               /* bummer we have to flush here, but things break otherwise as
-                * some event appears to be lost or delayed and throughput
-                * drops.  In almost all tests this flush is un-necessary */
-               E1000_WRITE_FLUSH(hw);
-#ifdef CONFIG_E1000_NAPI
-               /* Interrupt Auto-Mask (IAM)...upon writing ICR, interrupts are
-                * masked.  No need for the IMC write, but it does mean we
-                * should account for it ASAP. */
-               atomic_inc(&adapter->irq_sem);
-#endif
+               /* guard against interrupt when we're going down */
+               if (!test_bit(__E1000_DOWN, &adapter->flags))
+                       mod_timer(&adapter->watchdog_timer, jiffies + 1);
        }
 
 #ifdef CONFIG_E1000_NAPI
@@ -3729,7 +3796,7 @@ irqreturn_t e1000_intr_msi(int irq, void *data)
 
        for (i = 0; i < E1000_MAX_INTR; i++)
                if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
-                  !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
+                  e1000_clean_tx_irq(adapter, adapter->tx_ring)))
                        break;
 
        if (likely(adapter->itr_setting & 3))
@@ -3832,7 +3899,7 @@ e1000_intr(int irq, void *data)
 
        for (i = 0; i < E1000_MAX_INTR; i++)
                if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
-                  !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
+                  e1000_clean_tx_irq(adapter, adapter->tx_ring)))
                        break;
 
        if (likely(adapter->itr_setting & 3))
@@ -3882,7 +3949,7 @@ e1000_clean(struct net_device *poll_dev, int *budget)
        poll_dev->quota -= work_done;
 
        /* If no Tx and not enough Rx work done, exit the polling mode */
-       if ((!tx_cleaned && (work_done == 0)) ||
+       if ((tx_cleaned && (work_done < work_to_do)) ||
           !netif_running(poll_dev)) {
 quit_polling:
                if (likely(adapter->itr_setting & 3))
@@ -3912,7 +3979,7 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter,
 #ifdef CONFIG_E1000_NAPI
        unsigned int count = 0;
 #endif
-       boolean_t cleaned = FALSE;
+       boolean_t cleaned = TRUE;
        unsigned int total_tx_bytes=0, total_tx_packets=0;
 
        i = tx_ring->next_to_clean;
@@ -3927,10 +3994,13 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter,
 
                        if (cleaned) {
                                struct sk_buff *skb = buffer_info->skb;
-                               unsigned int segs = skb_shinfo(skb)->gso_segs;
+                               unsigned int segs, bytecount;
+                               segs = skb_shinfo(skb)->gso_segs ?: 1;
+                               /* multiply data chunks by size of headers */
+                               bytecount = ((segs - 1) * skb_headlen(skb)) +
+                                           skb->len;
                                total_tx_packets += segs;
-                               total_tx_packets++;
-                               total_tx_bytes += skb->len;
+                               total_tx_bytes += bytecount;
                        }
                        e1000_unmap_and_free_tx_resource(adapter, buffer_info);
                        tx_desc->upper.data = 0;
@@ -3943,7 +4013,10 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter,
 #ifdef CONFIG_E1000_NAPI
 #define E1000_TX_WEIGHT 64
                /* weight of a sort for tx, to avoid endless transmit cleanup */
-               if (count++ == E1000_TX_WEIGHT) break;
+               if (count++ == E1000_TX_WEIGHT) {
+                       cleaned = FALSE;
+                       break;
+               }
 #endif
        }
 
@@ -4152,8 +4225,7 @@ e1000_clean_rx_irq(struct e1000_adapter *adapter,
                /* code added for copybreak, this should improve
                 * performance for small packets with large amounts
                 * of reassembly being done in the stack */
-#define E1000_CB_LENGTH 256
-               if (length < E1000_CB_LENGTH) {
+               if (length < copybreak) {
                        struct sk_buff *new_skb =
                            netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
                        if (new_skb) {
@@ -4311,7 +4383,7 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
 
                /* page alloc/put takes too long and effects small packet
                 * throughput, so unsplit small packets and save the alloc/put*/
-               if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) {
+               if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
                        u8 *vaddr;
                        /* there is no documentation about how to call
                         * kmap_atomic, so we can't hold the mapping
@@ -4999,58 +5071,6 @@ e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
        return 0;
 }
 
-#ifdef CONFIG_PM
-/* Save/restore 16 or 64 dwords of PCI config space depending on which
- * bus we're on (PCI(X) vs. PCI-E)
- */
-#define PCIE_CONFIG_SPACE_LEN 256
-#define PCI_CONFIG_SPACE_LEN 64
-static int
-e1000_pci_save_state(struct e1000_adapter *adapter)
-{
-       struct pci_dev *dev = adapter->pdev;
-       int size;
-       int i;
-
-       if (adapter->hw.mac_type >= e1000_82571)
-               size = PCIE_CONFIG_SPACE_LEN;
-       else
-               size = PCI_CONFIG_SPACE_LEN;
-
-       WARN_ON(adapter->config_space != NULL);
-
-       adapter->config_space = kmalloc(size, GFP_KERNEL);
-       if (!adapter->config_space) {
-               DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
-               return -ENOMEM;
-       }
-       for (i = 0; i < (size / 4); i++)
-               pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
-       return 0;
-}
-
-static void
-e1000_pci_restore_state(struct e1000_adapter *adapter)
-{
-       struct pci_dev *dev = adapter->pdev;
-       int size;
-       int i;
-
-       if (adapter->config_space == NULL)
-               return;
-
-       if (adapter->hw.mac_type >= e1000_82571)
-               size = PCIE_CONFIG_SPACE_LEN;
-       else
-               size = PCI_CONFIG_SPACE_LEN;
-       for (i = 0; i < (size / 4); i++)
-               pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
-       kfree(adapter->config_space);
-       adapter->config_space = NULL;
-       return;
-}
-#endif /* CONFIG_PM */
-
 static int
 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
 {
@@ -5070,9 +5090,7 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
        }
 
 #ifdef CONFIG_PM
-       /* Implement our own version of pci_save_state(pdev) because pci-
-        * express adapters have 256-byte config spaces. */
-       retval = e1000_pci_save_state(adapter);
+       retval = pci_save_state(pdev);
        if (retval)
                return retval;
 #endif
@@ -5159,7 +5177,7 @@ e1000_resume(struct pci_dev *pdev)
        uint32_t err;
 
        pci_set_power_state(pdev, PCI_D0);
-       e1000_pci_restore_state(adapter);
+       pci_restore_state(pdev);
        if ((err = pci_enable_device(pdev))) {
                printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
                return err;