e1000: Removing the unused macro PAGE_USE_COUNT()
[deliverable/linux.git] / drivers / net / igb / igb_main.c
index 20d27e622ec10c1fabefdc24e85a67cb443d27a4..87eed88d958667a32f2a3d970a12b0d94665a8eb 100644 (file)
@@ -1,7 +1,7 @@
 /*******************************************************************************
 
   Intel(R) Gigabit Ethernet Linux driver
-  Copyright(c) 2007 Intel Corporation.
+  Copyright(c) 2007-2009 Intel Corporation.
 
   This program is free software; you can redistribute it and/or modify it
   under the terms and conditions of the GNU General Public License,
@@ -34,6 +34,7 @@
 #include <linux/ipv6.h>
 #include <net/checksum.h>
 #include <net/ip6_checksum.h>
+#include <linux/net_tstamp.h>
 #include <linux/mii.h>
 #include <linux/ethtool.h>
 #include <linux/if_vlan.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/if_ether.h>
+#include <linux/aer.h>
 #ifdef CONFIG_IGB_DCA
 #include <linux/dca.h>
 #endif
 #include "igb.h"
 
-#define DRV_VERSION "1.2.45-k2"
+#define DRV_VERSION "1.3.16-k2"
 char igb_driver_name[] = "igb";
 char igb_driver_version[] = DRV_VERSION;
 static const char igb_driver_string[] =
                                "Intel(R) Gigabit Ethernet Network Driver";
-static const char igb_copyright[] = "Copyright (c) 2008 Intel Corporation.";
+static const char igb_copyright[] = "Copyright (c) 2007-2009 Intel Corporation.";
 
 static const struct e1000_info *igb_info_tbl[] = {
        [board_82575] = &e1000_82575_info,
@@ -76,8 +78,6 @@ static int igb_setup_all_tx_resources(struct igb_adapter *);
 static int igb_setup_all_rx_resources(struct igb_adapter *);
 static void igb_free_all_tx_resources(struct igb_adapter *);
 static void igb_free_all_rx_resources(struct igb_adapter *);
-static void igb_free_tx_resources(struct igb_ring *);
-static void igb_free_rx_resources(struct igb_ring *);
 void igb_update_stats(struct igb_adapter *);
 static int igb_probe(struct pci_dev *, const struct pci_device_id *);
 static void __devexit igb_remove(struct pci_dev *pdev);
@@ -116,9 +116,6 @@ static bool igb_clean_tx_irq(struct igb_ring *);
 static int igb_poll(struct napi_struct *, int);
 static bool igb_clean_rx_irq_adv(struct igb_ring *, int *, int);
 static void igb_alloc_rx_buffers_adv(struct igb_ring *, int);
-#ifdef CONFIG_IGB_LRO
-static int igb_get_skb_hdr(struct sk_buff *skb, void **, void **, u64 *, void *);
-#endif
 static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
 static void igb_tx_timeout(struct net_device *);
 static void igb_reset_task(struct work_struct *);
@@ -179,6 +176,54 @@ MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
 
+/**
+ * Scale the NIC clock cycle by a large factor so that
+ * relatively small clock corrections can be added or
+ * substracted at each clock tick. The drawbacks of a
+ * large factor are a) that the clock register overflows
+ * more quickly (not such a big deal) and b) that the
+ * increment per tick has to fit into 24 bits.
+ *
+ * Note that
+ *   TIMINCA = IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS *
+ *             IGB_TSYNC_SCALE
+ *   TIMINCA += TIMINCA * adjustment [ppm] / 1e9
+ *
+ * The base scale factor is intentionally a power of two
+ * so that the division in %struct timecounter can be done with
+ * a shift.
+ */
+#define IGB_TSYNC_SHIFT (19)
+#define IGB_TSYNC_SCALE (1<<IGB_TSYNC_SHIFT)
+
+/**
+ * The duration of one clock cycle of the NIC.
+ *
+ * @todo This hard-coded value is part of the specification and might change
+ * in future hardware revisions. Add revision check.
+ */
+#define IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS 16
+
+#if (IGB_TSYNC_SCALE * IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS) >= (1<<24)
+# error IGB_TSYNC_SCALE and/or IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS are too large to fit into TIMINCA
+#endif
+
+/**
+ * igb_read_clock - read raw cycle counter (to be used by time counter)
+ */
+static cycle_t igb_read_clock(const struct cyclecounter *tc)
+{
+       struct igb_adapter *adapter =
+               container_of(tc, struct igb_adapter, cycles);
+       struct e1000_hw *hw = &adapter->hw;
+       u64 stamp;
+
+       stamp =  rd32(E1000_SYSTIML);
+       stamp |= (u64)rd32(E1000_SYSTIMH) << 32ULL;
+
+       return stamp;
+}
+
 #ifdef DEBUG
 /**
  * igb_get_hw_dev_name - return device name string
@@ -189,6 +234,30 @@ char *igb_get_hw_dev_name(struct e1000_hw *hw)
        struct igb_adapter *adapter = hw->back;
        return adapter->netdev->name;
 }
+
+/**
+ * igb_get_time_str - format current NIC and system time as string
+ */
+static char *igb_get_time_str(struct igb_adapter *adapter,
+                             char buffer[160])
+{
+       cycle_t hw = adapter->cycles.read(&adapter->cycles);
+       struct timespec nic = ns_to_timespec(timecounter_read(&adapter->clock));
+       struct timespec sys;
+       struct timespec delta;
+       getnstimeofday(&sys);
+
+       delta = timespec_sub(nic, sys);
+
+       sprintf(buffer,
+               "HW %llu, NIC %ld.%09lus, SYS %ld.%09lus, NIC-SYS %lds + %09luns",
+               hw,
+               (long)nic.tv_sec, nic.tv_nsec,
+               (long)sys.tv_sec, sys.tv_nsec,
+               (long)delta.tv_sec, delta.tv_nsec);
+
+       return buffer;
+}
 #endif
 
 /**
@@ -207,10 +276,11 @@ static int __init igb_init_module(void)
 
        global_quad_port_a = 0;
 
-       ret = pci_register_driver(&igb_driver);
 #ifdef CONFIG_IGB_DCA
        dca_register_notify(&dca_notifier);
 #endif
+
+       ret = pci_register_driver(&igb_driver);
        return ret;
 }
 
@@ -232,6 +302,40 @@ static void __exit igb_exit_module(void)
 
 module_exit(igb_exit_module);
 
+#define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
+/**
+ * igb_cache_ring_register - Descriptor ring to register mapping
+ * @adapter: board private structure to initialize
+ *
+ * Once we know the feature-set enabled for the device, we'll cache
+ * the register offset the descriptor ring is assigned to.
+ **/
+static void igb_cache_ring_register(struct igb_adapter *adapter)
+{
+       int i;
+
+       switch (adapter->hw.mac.type) {
+       case e1000_82576:
+               /* The queues are allocated for virtualization such that VF 0
+                * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
+                * In order to avoid collision we start at the first free queue
+                * and continue consuming queues in the same sequence
+                */
+               for (i = 0; i < adapter->num_rx_queues; i++)
+                       adapter->rx_ring[i].reg_idx = Q_IDX_82576(i);
+               for (i = 0; i < adapter->num_tx_queues; i++)
+                       adapter->tx_ring[i].reg_idx = Q_IDX_82576(i);
+               break;
+       case e1000_82575:
+       default:
+               for (i = 0; i < adapter->num_rx_queues; i++)
+                       adapter->rx_ring[i].reg_idx = i;
+               for (i = 0; i < adapter->num_tx_queues; i++)
+                       adapter->tx_ring[i].reg_idx = i;
+               break;
+       }
+}
+
 /**
  * igb_alloc_queues - Allocate memory for all rings
  * @adapter: board private structure to initialize
@@ -259,11 +363,13 @@ static int igb_alloc_queues(struct igb_adapter *adapter)
 
        for (i = 0; i < adapter->num_tx_queues; i++) {
                struct igb_ring *ring = &(adapter->tx_ring[i]);
+               ring->count = adapter->tx_ring_count;
                ring->adapter = adapter;
                ring->queue_index = i;
        }
        for (i = 0; i < adapter->num_rx_queues; i++) {
                struct igb_ring *ring = &(adapter->rx_ring[i]);
+               ring->count = adapter->rx_ring_count;
                ring->adapter = adapter;
                ring->queue_index = i;
                ring->itr_register = E1000_ITR;
@@ -271,6 +377,8 @@ static int igb_alloc_queues(struct igb_adapter *adapter)
                /* set a default napi handler for each rx_ring */
                netif_napi_add(adapter->netdev, &ring->napi, igb_poll, 64);
        }
+
+       igb_cache_ring_register(adapter);
        return 0;
 }
 
@@ -311,36 +419,36 @@ static void igb_assign_vector(struct igb_adapter *adapter, int rx_queue,
                array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
                break;
        case e1000_82576:
-               /* The 82576 uses a table-based method for assigning vectors.
+               /* 82576 uses a table-based method for assigning vectors.
                   Each queue has a single entry in the table to which we write
                   a vector number along with a "valid" bit.  Sadly, the layout
                   of the table is somewhat counterintuitive. */
                if (rx_queue > IGB_N0_QUEUE) {
-                       index = (rx_queue & 0x7);
+                       index = (rx_queue >> 1);
                        ivar = array_rd32(E1000_IVAR0, index);
-                       if (rx_queue < 8) {
-                               /* vector goes into low byte of register */
-                               ivar = ivar & 0xFFFFFF00;
-                               ivar |= msix_vector | E1000_IVAR_VALID;
-                       } else {
+                       if (rx_queue & 0x1) {
                                /* vector goes into third byte of register */
                                ivar = ivar & 0xFF00FFFF;
                                ivar |= (msix_vector | E1000_IVAR_VALID) << 16;
+                       } else {
+                               /* vector goes into low byte of register */
+                               ivar = ivar & 0xFFFFFF00;
+                               ivar |= msix_vector | E1000_IVAR_VALID;
                        }
                        adapter->rx_ring[rx_queue].eims_value= 1 << msix_vector;
                        array_wr32(E1000_IVAR0, index, ivar);
                }
                if (tx_queue > IGB_N0_QUEUE) {
-                       index = (tx_queue & 0x7);
+                       index = (tx_queue >> 1);
                        ivar = array_rd32(E1000_IVAR0, index);
-                       if (tx_queue < 8) {
-                               /* vector goes into second byte of register */
-                               ivar = ivar & 0xFFFF00FF;
-                               ivar |= (msix_vector | E1000_IVAR_VALID) << 8;
-                       } else {
+                       if (tx_queue & 0x1) {
                                /* vector goes into high byte of register */
                                ivar = ivar & 0x00FFFFFF;
                                ivar |= (msix_vector | E1000_IVAR_VALID) << 24;
+                       } else {
+                               /* vector goes into second byte of register */
+                               ivar = ivar & 0xFFFF00FF;
+                               ivar |= (msix_vector | E1000_IVAR_VALID) << 8;
                        }
                        adapter->tx_ring[tx_queue].eims_value= 1 << msix_vector;
                        array_wr32(E1000_IVAR0, index, ivar);
@@ -369,7 +477,7 @@ static void igb_configure_msix(struct igb_adapter *adapter)
                /* Turn on MSI-X capability first, or our settings
                 * won't stick.  And it will take days to debug. */
                wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
-                                  E1000_GPIE_PBA | E1000_GPIE_EIAME | 
+                                  E1000_GPIE_PBA | E1000_GPIE_EIAME |
                                   E1000_GPIE_NSICR);
 
        for (i = 0; i < adapter->num_tx_queues; i++) {
@@ -445,7 +553,7 @@ static int igb_request_msix(struct igb_adapter *adapter)
 
        for (i = 0; i < adapter->num_tx_queues; i++) {
                struct igb_ring *ring = &(adapter->tx_ring[i]);
-               sprintf(ring->name, "%s-tx%d", netdev->name, i);
+               sprintf(ring->name, "%s-tx-%d", netdev->name, i);
                err = request_irq(adapter->msix_entries[vector].vector,
                                  &igb_msix_tx, 0, ring->name,
                                  &(adapter->tx_ring[i]));
@@ -458,7 +566,7 @@ static int igb_request_msix(struct igb_adapter *adapter)
        for (i = 0; i < adapter->num_rx_queues; i++) {
                struct igb_ring *ring = &(adapter->rx_ring[i]);
                if (strlen(netdev->name) < (IFNAMSIZ - 5))
-                       sprintf(ring->name, "%s-rx%d", netdev->name, i);
+                       sprintf(ring->name, "%s-rx-%d", netdev->name, i);
                else
                        memcpy(ring->name, netdev->name, IFNAMSIZ);
                err = request_irq(adapter->msix_entries[vector].vector,
@@ -508,6 +616,11 @@ static void igb_set_interrupt_capability(struct igb_adapter *adapter)
        int err;
        int numvecs, i;
 
+       /* Number of supported queues. */
+       /* Having more queues than CPUs doesn't make sense. */
+       adapter->num_rx_queues = min_t(u32, IGB_MAX_RX_QUEUES, num_online_cpus());
+       adapter->num_tx_queues = min_t(u32, IGB_MAX_TX_QUEUES, num_online_cpus());
+
        numvecs = adapter->num_tx_queues + adapter->num_rx_queues + 1;
        adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry),
                                        GFP_KERNEL);
@@ -649,7 +762,7 @@ static void igb_irq_enable(struct igb_adapter *adapter)
                wr32(E1000_EIAC, adapter->eims_enable_mask);
                wr32(E1000_EIAM, adapter->eims_enable_mask);
                wr32(E1000_EIMS, adapter->eims_enable_mask);
-               wr32(E1000_IMS, E1000_IMS_LSC);
+               wr32(E1000_IMS, E1000_IMS_LSC | E1000_IMS_DOUTSYNC);
        } else {
                wr32(E1000_IMS, IMS_ENABLE_MASK);
                wr32(E1000_IAM, IMS_ENABLE_MASK);
@@ -818,6 +931,10 @@ void igb_down(struct igb_adapter *adapter)
 
        netdev->tx_queue_len = adapter->tx_queue_len;
        netif_carrier_off(netdev);
+
+       /* record the stats before reset*/
+       igb_update_stats(adapter);
+
        adapter->link_speed = 0;
        adapter->link_duplex = 0;
 
@@ -848,11 +965,14 @@ void igb_reset(struct igb_adapter *adapter)
        /* Repartition Pba for greater than 9k mtu
         * To take effect CTRL.RST is required.
         */
-       if (mac->type != e1000_82576) {
-       pba = E1000_PBA_34K;
-       }
-       else {
+       switch (mac->type) {
+       case e1000_82576:
                pba = E1000_PBA_64K;
+               break;
+       case e1000_82575:
+       default:
+               pba = E1000_PBA_34K;
+               break;
        }
 
        if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
@@ -874,7 +994,7 @@ void igb_reset(struct igb_adapter *adapter)
                /* the tx fifo also stores 16 bytes of information about the tx
                 * but don't include ethernet FCS because hardware appends it */
                min_tx_space = (adapter->max_frame_size +
-                               sizeof(struct e1000_tx_desc) -
+                               sizeof(union e1000_adv_tx_desc) -
                                ETH_FCS_LEN) * 2;
                min_tx_space = ALIGN(min_tx_space, 1024);
                min_tx_space >>= 10;
@@ -931,24 +1051,27 @@ void igb_reset(struct igb_adapter *adapter)
        wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
 
        igb_reset_adaptive(&adapter->hw);
-       if (adapter->hw.phy.ops.get_phy_info)
-               adapter->hw.phy.ops.get_phy_info(&adapter->hw);
+       igb_get_phy_info(&adapter->hw);
 }
 
-/**
- * igb_is_need_ioport - determine if an adapter needs ioport resources or not
- * @pdev: PCI device information struct
- *
- * Returns true if an adapter needs ioport resources
- **/
-static int igb_is_need_ioport(struct pci_dev *pdev)
-{
-       switch (pdev->device) {
-       /* Currently there are no adapters that need ioport resources */
-       default:
-               return false;
-       }
-}
+static const struct net_device_ops igb_netdev_ops = {
+       .ndo_open               = igb_open,
+       .ndo_stop               = igb_close,
+       .ndo_start_xmit         = igb_xmit_frame_adv,
+       .ndo_get_stats          = igb_get_stats,
+       .ndo_set_multicast_list = igb_set_multi,
+       .ndo_set_mac_address    = igb_set_mac,
+       .ndo_change_mtu         = igb_change_mtu,
+       .ndo_do_ioctl           = igb_ioctl,
+       .ndo_tx_timeout         = igb_tx_timeout,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_vlan_rx_register   = igb_vlan_rx_register,
+       .ndo_vlan_rx_add_vid    = igb_vlan_rx_add_vid,
+       .ndo_vlan_rx_kill_vid   = igb_vlan_rx_kill_vid,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller    = igb_netpoll,
+#endif
+};
 
 /**
  * igb_probe - Device Initialization Routine
@@ -970,21 +1093,12 @@ static int __devinit igb_probe(struct pci_dev *pdev,
        struct pci_dev *us_dev;
        const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
        unsigned long mmio_start, mmio_len;
-       int i, err, pci_using_dac, pos;
+       int err, pci_using_dac, pos;
        u16 eeprom_data = 0, state = 0;
        u16 eeprom_apme_mask = IGB_EEPROM_APME;
        u32 part_num;
-       int bars, need_ioport;
 
-       /* do not allocate ioport bars when not needed */
-       need_ioport = igb_is_need_ioport(pdev);
-       if (need_ioport) {
-               bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
-               err = pci_enable_device(pdev);
-       } else {
-               bars = pci_select_bars(pdev, IORESOURCE_MEM);
-               err = pci_enable_device_mem(pdev);
-       }
+       err = pci_enable_device_mem(pdev);
        if (err)
                return err;
 
@@ -1027,10 +1141,19 @@ static int __devinit igb_probe(struct pci_dev *pdev,
                break;
        }
 
-       err = pci_request_selected_regions(pdev, bars, igb_driver_name);
+       err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
+                                          IORESOURCE_MEM),
+                                          igb_driver_name);
        if (err)
                goto err_pci_reg;
 
+       err = pci_enable_pcie_error_reporting(pdev);
+       if (err) {
+               dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
+                       "0x%x\n", err);
+               /* non-fatal, continue */
+       }
+
        pci_set_master(pdev);
        pci_save_state(pdev);
 
@@ -1048,34 +1171,18 @@ static int __devinit igb_probe(struct pci_dev *pdev,
        hw = &adapter->hw;
        hw->back = adapter;
        adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE;
-       adapter->bars = bars;
-       adapter->need_ioport = need_ioport;
 
        mmio_start = pci_resource_start(pdev, 0);
        mmio_len = pci_resource_len(pdev, 0);
 
        err = -EIO;
-       adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
-       if (!adapter->hw.hw_addr)
+       hw->hw_addr = ioremap(mmio_start, mmio_len);
+       if (!hw->hw_addr)
                goto err_ioremap;
 
-       netdev->open = &igb_open;
-       netdev->stop = &igb_close;
-       netdev->get_stats = &igb_get_stats;
-       netdev->set_multicast_list = &igb_set_multi;
-       netdev->set_mac_address = &igb_set_mac;
-       netdev->change_mtu = &igb_change_mtu;
-       netdev->do_ioctl = &igb_ioctl;
+       netdev->netdev_ops = &igb_netdev_ops;
        igb_set_ethtool_ops(netdev);
-       netdev->tx_timeout = &igb_tx_timeout;
        netdev->watchdog_timeo = 5 * HZ;
-       netdev->vlan_rx_register = igb_vlan_rx_register;
-       netdev->vlan_rx_add_vid = igb_vlan_rx_add_vid;
-       netdev->vlan_rx_kill_vid = igb_vlan_rx_kill_vid;
-#ifdef CONFIG_NET_POLL_CONTROLLER
-       netdev->poll_controller = igb_netpoll;
-#endif
-       netdev->hard_start_xmit = &igb_xmit_frame_adv;
 
        strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
 
@@ -1098,8 +1205,9 @@ static int __devinit igb_probe(struct pci_dev *pdev,
        /* Initialize skew-specific constants */
        err = ei->get_invariants(hw);
        if (err)
-               goto err_hw_init;
+               goto err_sw_init;
 
+       /* setup the private structure */
        err = igb_sw_init(adapter);
        if (err)
                goto err_sw_init;
@@ -1108,11 +1216,10 @@ static int __devinit igb_probe(struct pci_dev *pdev,
 
        /* set flags */
        switch (hw->mac.type) {
-       case e1000_82576:
        case e1000_82575:
-               adapter->flags |= IGB_FLAG_HAS_DCA;
                adapter->flags |= IGB_FLAG_NEED_CTX_IDX;
                break;
+       case e1000_82576:
        default:
                break;
        }
@@ -1132,27 +1239,25 @@ static int __devinit igb_probe(struct pci_dev *pdev,
                        "PHY reset is blocked due to SOL/IDER session.\n");
 
        netdev->features = NETIF_F_SG |
-                          NETIF_F_HW_CSUM |
+                          NETIF_F_IP_CSUM |
                           NETIF_F_HW_VLAN_TX |
                           NETIF_F_HW_VLAN_RX |
                           NETIF_F_HW_VLAN_FILTER;
 
+       netdev->features |= NETIF_F_IPV6_CSUM;
        netdev->features |= NETIF_F_TSO;
        netdev->features |= NETIF_F_TSO6;
 
-#ifdef CONFIG_IGB_LRO
-       netdev->features |= NETIF_F_LRO;
-#endif
+       netdev->features |= NETIF_F_GRO;
 
        netdev->vlan_features |= NETIF_F_TSO;
        netdev->vlan_features |= NETIF_F_TSO6;
-       netdev->vlan_features |= NETIF_F_HW_CSUM;
+       netdev->vlan_features |= NETIF_F_IP_CSUM;
        netdev->vlan_features |= NETIF_F_SG;
 
        if (pci_using_dac)
                netdev->features |= NETIF_F_HIGHDMA;
 
-       netdev->features |= NETIF_F_LLTX;
        adapter->en_mng_pt = igb_enable_mng_pass_thru(&adapter->hw);
 
        /* before reading the NVM, reset the controller to put the device in a
@@ -1190,14 +1295,7 @@ static int __devinit igb_probe(struct pci_dev *pdev,
        INIT_WORK(&adapter->reset_task, igb_reset_task);
        INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
 
-       /* Initialize link & ring properties that are user-changeable */
-       adapter->tx_ring->count = 256;
-       for (i = 0; i < adapter->num_tx_queues; i++)
-               adapter->tx_ring[i].count = adapter->tx_ring->count;
-       adapter->rx_ring->count = 256;
-       for (i = 0; i < adapter->num_rx_queues; i++)
-               adapter->rx_ring[i].count = adapter->rx_ring->count;
-
+       /* Initialize link properties that are user-changeable */
        adapter->fc_autoneg = true;
        hw->mac.autoneg = true;
        hw->phy.autoneg_advertised = 0x2f;
@@ -1205,7 +1303,7 @@ static int __devinit igb_probe(struct pci_dev *pdev,
        hw->fc.original_type = e1000_fc_default;
        hw->fc.type = e1000_fc_default;
 
-       adapter->itr_setting = 3;
+       adapter->itr_setting = IGB_DEFAULT_ITR;
        adapter->itr = IGB_START_ITR;
 
        igb_validate_mdi_setting(hw);
@@ -1218,8 +1316,7 @@ static int __devinit igb_probe(struct pci_dev *pdev,
 
        if (hw->bus.func == 0 ||
            hw->device_id == E1000_DEV_ID_82575EB_COPPER)
-               hw->nvm.ops.read_nvm(hw, NVM_INIT_CONTROL3_PORT_A, 1,
-                                    &eeprom_data);
+               hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
 
        if (eeprom_data & eeprom_apme_mask)
                adapter->eeprom_wol |= E1000_WUFC_MAG;
@@ -1262,29 +1359,78 @@ static int __devinit igb_probe(struct pci_dev *pdev,
                goto err_register;
 
 #ifdef CONFIG_IGB_DCA
-       if ((adapter->flags & IGB_FLAG_HAS_DCA) &&
-           (dca_add_requester(&pdev->dev) == 0)) {
+       if (dca_add_requester(&pdev->dev) == 0) {
                adapter->flags |= IGB_FLAG_DCA_ENABLED;
                dev_info(&pdev->dev, "DCA enabled\n");
                /* Always use CB2 mode, difference is masked
                 * in the CB driver. */
-               wr32(E1000_DCA_CTRL, 2);
+               wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
                igb_setup_dca(adapter);
        }
 #endif
 
+       /*
+        * Initialize hardware timer: we keep it running just in case
+        * that some program needs it later on.
+        */
+       memset(&adapter->cycles, 0, sizeof(adapter->cycles));
+       adapter->cycles.read = igb_read_clock;
+       adapter->cycles.mask = CLOCKSOURCE_MASK(64);
+       adapter->cycles.mult = 1;
+       adapter->cycles.shift = IGB_TSYNC_SHIFT;
+       wr32(E1000_TIMINCA,
+            (1<<24) |
+            IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS * IGB_TSYNC_SCALE);
+#if 0
+       /*
+        * Avoid rollover while we initialize by resetting the time counter.
+        */
+       wr32(E1000_SYSTIML, 0x00000000);
+       wr32(E1000_SYSTIMH, 0x00000000);
+#else
+       /*
+        * Set registers so that rollover occurs soon to test this.
+        */
+       wr32(E1000_SYSTIML, 0x00000000);
+       wr32(E1000_SYSTIMH, 0xFF800000);
+#endif
+       wrfl();
+       timecounter_init(&adapter->clock,
+                        &adapter->cycles,
+                        ktime_to_ns(ktime_get_real()));
+
+       /*
+        * Synchronize our NIC clock against system wall clock. NIC
+        * time stamp reading requires ~3us per sample, each sample
+        * was pretty stable even under load => only require 10
+        * samples for each offset comparison.
+        */
+       memset(&adapter->compare, 0, sizeof(adapter->compare));
+       adapter->compare.source = &adapter->clock;
+       adapter->compare.target = ktime_get_real;
+       adapter->compare.num_samples = 10;
+       timecompare_update(&adapter->compare, 0);
+
+#ifdef DEBUG
+       {
+               char buffer[160];
+               printk(KERN_DEBUG
+                       "igb: %s: hw %p initialized timer\n",
+                       igb_get_time_str(adapter, buffer),
+                       &adapter->hw);
+       }
+#endif
+
        dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
        /* print bus type/speed/width info */
-       dev_info(&pdev->dev,
-                "%s: (PCIe:%s:%s) %02x:%02x:%02x:%02x:%02x:%02x\n",
+       dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
                 netdev->name,
                 ((hw->bus.speed == e1000_bus_speed_2500)
                  ? "2.5Gb/s" : "unknown"),
                 ((hw->bus.width == e1000_bus_width_pcie_x4)
                  ? "Width x4" : (hw->bus.width == e1000_bus_width_pcie_x1)
                  ? "Width x1" : "unknown"),
-                netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
-                netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
+                netdev->dev_addr);
 
        igb_read_part_num(hw, &part_num);
        dev_info(&pdev->dev, "%s: PBA No: %06x-%03x\n", netdev->name,
@@ -1302,20 +1448,19 @@ err_register:
        igb_release_hw_control(adapter);
 err_eeprom:
        if (!igb_check_reset_block(hw))
-               hw->phy.ops.reset_phy(hw);
+               igb_reset_phy(hw);
 
        if (hw->flash_address)
                iounmap(hw->flash_address);
 
-       igb_remove_device(hw);
        igb_free_queues(adapter);
 err_sw_init:
-err_hw_init:
        iounmap(hw->hw_addr);
 err_ioremap:
        free_netdev(netdev);
 err_alloc_etherdev:
-       pci_release_selected_regions(pdev, bars);
+       pci_release_selected_regions(pdev, pci_select_bars(pdev,
+                                    IORESOURCE_MEM));
 err_pci_reg:
 err_dma:
        pci_disable_device(pdev);
@@ -1335,9 +1480,8 @@ static void __devexit igb_remove(struct pci_dev *pdev)
 {
        struct net_device *netdev = pci_get_drvdata(pdev);
        struct igb_adapter *adapter = netdev_priv(netdev);
-#ifdef CONFIG_IGB_DCA
        struct e1000_hw *hw = &adapter->hw;
-#endif
+       int err;
 
        /* flush_scheduled work may reschedule our watchdog task, so
         * explicitly disable watchdog tasks from being rescheduled  */
@@ -1352,7 +1496,7 @@ static void __devexit igb_remove(struct pci_dev *pdev)
                dev_info(&pdev->dev, "DCA disabled\n");
                dca_remove_requester(&pdev->dev);
                adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
-               wr32(E1000_DCA_CTRL, 1);
+               wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
        }
 #endif
 
@@ -1362,22 +1506,26 @@ static void __devexit igb_remove(struct pci_dev *pdev)
 
        unregister_netdev(netdev);
 
-       if (adapter->hw.phy.ops.reset_phy &&
-           !igb_check_reset_block(&adapter->hw))
-               adapter->hw.phy.ops.reset_phy(&adapter->hw);
+       if (!igb_check_reset_block(&adapter->hw))
+               igb_reset_phy(&adapter->hw);
 
-       igb_remove_device(&adapter->hw);
        igb_reset_interrupt_capability(adapter);
 
        igb_free_queues(adapter);
 
-       iounmap(adapter->hw.hw_addr);
-       if (adapter->hw.flash_address)
-               iounmap(adapter->hw.flash_address);
-       pci_release_selected_regions(pdev, adapter->bars);
+       iounmap(hw->hw_addr);
+       if (hw->flash_address)
+               iounmap(hw->flash_address);
+       pci_release_selected_regions(pdev, pci_select_bars(pdev,
+                                    IORESOURCE_MEM));
 
        free_netdev(netdev);
 
+       err = pci_disable_pcie_error_reporting(pdev);
+       if (err)
+               dev_err(&pdev->dev,
+                       "pci_disable_pcie_error_reporting failed 0x%x\n", err);
+
        pci_disable_device(pdev);
 }
 
@@ -1397,16 +1545,13 @@ static int __devinit igb_sw_init(struct igb_adapter *adapter)
 
        pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
 
+       adapter->tx_ring_count = IGB_DEFAULT_TXD;
+       adapter->rx_ring_count = IGB_DEFAULT_RXD;
        adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
        adapter->rx_ps_hdr_size = 0; /* disable packet split */
        adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
        adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
 
-       /* Number of supported queues. */
-       /* Having more queues than CPUs doesn't make sense. */
-       adapter->num_rx_queues = min((u32)IGB_MAX_RX_QUEUES, (u32)num_online_cpus());
-       adapter->num_tx_queues = min(IGB_MAX_TX_QUEUES, num_online_cpus());
-
        /* This call may decrease the number of queues depending on
         * interrupt mode. */
        igb_set_interrupt_capability(adapter);
@@ -1544,7 +1689,6 @@ static int igb_close(struct net_device *netdev)
  *
  * Return 0 on success, negative on failure
  **/
-
 int igb_setup_tx_resources(struct igb_adapter *adapter,
                           struct igb_ring *tx_ring)
 {
@@ -1558,8 +1702,7 @@ int igb_setup_tx_resources(struct igb_adapter *adapter,
        memset(tx_ring->buffer_info, 0, size);
 
        /* round up to nearest 4K */
-       tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc)
-                       + sizeof(u32);
+       tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
        tx_ring->size = ALIGN(tx_ring->size, 4096);
 
        tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
@@ -1606,7 +1749,7 @@ static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
        for (i = 0; i < IGB_MAX_TX_QUEUES; i++) {
                r_idx = i % adapter->num_tx_queues;
                adapter->multi_tx_table[i] = &adapter->tx_ring[r_idx];
-       }       
+       }
        return err;
 }
 
@@ -1618,47 +1761,39 @@ static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
  **/
 static void igb_configure_tx(struct igb_adapter *adapter)
 {
-       u64 tdba, tdwba;
+       u64 tdba;
        struct e1000_hw *hw = &adapter->hw;
        u32 tctl;
        u32 txdctl, txctrl;
-       int i;
+       int i, j;
 
        for (i = 0; i < adapter->num_tx_queues; i++) {
-               struct igb_ring *ring = &(adapter->tx_ring[i]);
-
-               wr32(E1000_TDLEN(i),
-                               ring->count * sizeof(struct e1000_tx_desc));
+               struct igb_ring *ring = &adapter->tx_ring[i];
+               j = ring->reg_idx;
+               wr32(E1000_TDLEN(j),
+                    ring->count * sizeof(union e1000_adv_tx_desc));
                tdba = ring->dma;
-               wr32(E1000_TDBAL(i),
-                               tdba & 0x00000000ffffffffULL);
-               wr32(E1000_TDBAH(i), tdba >> 32);
-
-               tdwba = ring->dma + ring->count * sizeof(struct e1000_tx_desc);
-               tdwba |= 1; /* enable head wb */
-               wr32(E1000_TDWBAL(i),
-                               tdwba & 0x00000000ffffffffULL);
-               wr32(E1000_TDWBAH(i), tdwba >> 32);
-
-               ring->head = E1000_TDH(i);
-               ring->tail = E1000_TDT(i);
+               wr32(E1000_TDBAL(j),
+                    tdba & 0x00000000ffffffffULL);
+               wr32(E1000_TDBAH(j), tdba >> 32);
+
+               ring->head = E1000_TDH(j);
+               ring->tail = E1000_TDT(j);
                writel(0, hw->hw_addr + ring->tail);
                writel(0, hw->hw_addr + ring->head);
-               txdctl = rd32(E1000_TXDCTL(i));
+               txdctl = rd32(E1000_TXDCTL(j));
                txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
-               wr32(E1000_TXDCTL(i), txdctl);
+               wr32(E1000_TXDCTL(j), txdctl);
 
                /* Turn off Relaxed Ordering on head write-backs.  The
                 * writebacks MUST be delivered in order or it will
                 * completely screw up our bookeeping.
                 */
-               txctrl = rd32(E1000_DCA_TXCTRL(i));
+               txctrl = rd32(E1000_DCA_TXCTRL(j));
                txctrl &= ~E1000_DCA_TXCTRL_TX_WB_RO_EN;
-               wr32(E1000_DCA_TXCTRL(i), txctrl);
+               wr32(E1000_DCA_TXCTRL(j), txctrl);
        }
 
-
-
        /* Use the default values for the Tx Inter Packet Gap (IPG) timer */
 
        /* Program the Transmit Control Register */
@@ -1686,21 +1821,12 @@ static void igb_configure_tx(struct igb_adapter *adapter)
  *
  * Returns 0 on success, negative on failure
  **/
-
 int igb_setup_rx_resources(struct igb_adapter *adapter,
                           struct igb_ring *rx_ring)
 {
        struct pci_dev *pdev = adapter->pdev;
        int size, desc_len;
 
-#ifdef CONFIG_IGB_LRO
-       size = sizeof(struct net_lro_desc) * MAX_LRO_DESCRIPTORS;
-       rx_ring->lro_mgr.lro_arr = vmalloc(size);
-       if (!rx_ring->lro_mgr.lro_arr)
-               goto err;
-       memset(rx_ring->lro_mgr.lro_arr, 0, size);
-#endif
-
        size = sizeof(struct igb_buffer) * rx_ring->count;
        rx_ring->buffer_info = vmalloc(size);
        if (!rx_ring->buffer_info)
@@ -1727,10 +1853,6 @@ int igb_setup_rx_resources(struct igb_adapter *adapter,
        return 0;
 
 err:
-#ifdef CONFIG_IGB_LRO
-       vfree(rx_ring->lro_mgr.lro_arr);
-       rx_ring->lro_mgr.lro_arr = NULL;
-#endif
        vfree(rx_ring->buffer_info);
        dev_err(&adapter->pdev->dev, "Unable to allocate memory for "
                "the receive descriptor ring\n");
@@ -1771,55 +1893,43 @@ static void igb_setup_rctl(struct igb_adapter *adapter)
        struct e1000_hw *hw = &adapter->hw;
        u32 rctl;
        u32 srrctl = 0;
-       int i;
+       int i, j;
 
        rctl = rd32(E1000_RCTL);
 
        rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
+       rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
 
-       rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
-               E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
-               (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
+       rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
+               (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
 
        /*
         * enable stripping of CRC. It's unlikely this will break BMC
         * redirection as it did with e1000. Newer features require
         * that the HW strips the CRC.
-       */
+        */
        rctl |= E1000_RCTL_SECRC;
 
-       rctl &= ~E1000_RCTL_SBP;
+       /*
+        * disable store bad packets and clear size bits.
+        */
+       rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
 
-       if (adapter->netdev->mtu <= ETH_DATA_LEN)
-               rctl &= ~E1000_RCTL_LPE;
-       else
+       /* enable LPE when to prevent packets larger than max_frame_size */
                rctl |= E1000_RCTL_LPE;
-       if (adapter->rx_buffer_len <= IGB_RXBUFFER_2048) {
-               /* Setup buffer sizes */
-               rctl &= ~E1000_RCTL_SZ_4096;
-               rctl |= E1000_RCTL_BSEX;
-               switch (adapter->rx_buffer_len) {
-               case IGB_RXBUFFER_256:
-                       rctl |= E1000_RCTL_SZ_256;
-                       rctl &= ~E1000_RCTL_BSEX;
-                       break;
-               case IGB_RXBUFFER_512:
-                       rctl |= E1000_RCTL_SZ_512;
-                       rctl &= ~E1000_RCTL_BSEX;
-                       break;
-               case IGB_RXBUFFER_1024:
-                       rctl |= E1000_RCTL_SZ_1024;
-                       rctl &= ~E1000_RCTL_BSEX;
-                       break;
-               case IGB_RXBUFFER_2048:
-               default:
-                       rctl |= E1000_RCTL_SZ_2048;
-                       rctl &= ~E1000_RCTL_BSEX;
-                       break;
-               }
-       } else {
-               rctl &= ~E1000_RCTL_BSEX;
-               srrctl = adapter->rx_buffer_len >> E1000_SRRCTL_BSIZEPKT_SHIFT;
+
+       /* Setup buffer sizes */
+       switch (adapter->rx_buffer_len) {
+       case IGB_RXBUFFER_256:
+               rctl |= E1000_RCTL_SZ_256;
+               break;
+       case IGB_RXBUFFER_512:
+               rctl |= E1000_RCTL_SZ_512;
+               break;
+       default:
+               srrctl = ALIGN(adapter->rx_buffer_len, 1024)
+                        >> E1000_SRRCTL_BSIZEPKT_SHIFT;
+               break;
        }
 
        /* 82575 and greater support packet-split where the protocol
@@ -1831,7 +1941,7 @@ static void igb_setup_rctl(struct igb_adapter *adapter)
         */
        /* allocations using alloc_page take too long for regular MTU
         * so only enable packet split for jumbo frames */
-       if (rctl & E1000_RCTL_LPE) {
+       if (adapter->netdev->mtu > ETH_DATA_LEN) {
                adapter->rx_ps_hdr_size = IGB_RXBUFFER_128;
                srrctl |= adapter->rx_ps_hdr_size <<
                         E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
@@ -1841,8 +1951,10 @@ static void igb_setup_rctl(struct igb_adapter *adapter)
                srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
        }
 
-       for (i = 0; i < adapter->num_rx_queues; i++)
-               wr32(E1000_SRRCTL(i), srrctl);
+       for (i = 0; i < adapter->num_rx_queues; i++) {
+               j = adapter->rx_ring[i].reg_idx;
+               wr32(E1000_SRRCTL(j), srrctl);
+       }
 
        wr32(E1000_RCTL, rctl);
 }
@@ -1873,36 +1985,27 @@ static void igb_configure_rx(struct igb_adapter *adapter)
        /* Setup the HW Rx Head and Tail Descriptor Pointers and
         * the Base and Length of the Rx Descriptor Ring */
        for (i = 0; i < adapter->num_rx_queues; i++) {
-               struct igb_ring *ring = &(adapter->rx_ring[i]);
+               struct igb_ring *ring = &adapter->rx_ring[i];
+               int j = ring->reg_idx;
                rdba = ring->dma;
-               wr32(E1000_RDBAL(i),
-                               rdba & 0x00000000ffffffffULL);
-               wr32(E1000_RDBAH(i), rdba >> 32);
-               wr32(E1000_RDLEN(i),
-                              ring->count * sizeof(union e1000_adv_rx_desc));
-
-               ring->head = E1000_RDH(i);
-               ring->tail = E1000_RDT(i);
+               wr32(E1000_RDBAL(j),
+                    rdba & 0x00000000ffffffffULL);
+               wr32(E1000_RDBAH(j), rdba >> 32);
+               wr32(E1000_RDLEN(j),
+                    ring->count * sizeof(union e1000_adv_rx_desc));
+
+               ring->head = E1000_RDH(j);
+               ring->tail = E1000_RDT(j);
                writel(0, hw->hw_addr + ring->tail);
                writel(0, hw->hw_addr + ring->head);
 
-               rxdctl = rd32(E1000_RXDCTL(i));
+               rxdctl = rd32(E1000_RXDCTL(j));
                rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
                rxdctl &= 0xFFF00000;
                rxdctl |= IGB_RX_PTHRESH;
                rxdctl |= IGB_RX_HTHRESH << 8;
                rxdctl |= IGB_RX_WTHRESH << 16;
-               wr32(E1000_RXDCTL(i), rxdctl);
-#ifdef CONFIG_IGB_LRO
-               /* Intitial LRO Settings */
-               ring->lro_mgr.max_aggr = MAX_LRO_AGGR;
-               ring->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
-               ring->lro_mgr.get_skb_header = igb_get_skb_hdr;
-               ring->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
-               ring->lro_mgr.dev = adapter->netdev;
-               ring->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
-               ring->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
-#endif
+               wr32(E1000_RXDCTL(j), rxdctl);
        }
 
        if (adapter->num_rx_queues > 1) {
@@ -1922,7 +2025,7 @@ static void igb_configure_rx(struct igb_adapter *adapter)
                        shift = 6;
                for (j = 0; j < (32 * 4); j++) {
                        reta.bytes[j & 3] =
-                               (j % adapter->num_rx_queues) << shift;
+                               adapter->rx_ring[(j % adapter->num_rx_queues)].reg_idx << shift;
                        if ((j & 3) == 3)
                                writel(reta.dword,
                                       hw->hw_addr + E1000_RETA(0) + (j & ~3));
@@ -1954,17 +2057,11 @@ static void igb_configure_rx(struct igb_adapter *adapter)
        } else {
                /* Enable Receive Checksum Offload for TCP and UDP */
                rxcsum = rd32(E1000_RXCSUM);
-               if (adapter->rx_csum) {
-                       rxcsum |= E1000_RXCSUM_TUOFL;
+               if (adapter->rx_csum)
+                       rxcsum |= E1000_RXCSUM_TUOFL | E1000_RXCSUM_IPPCSE;
+               else
+                       rxcsum &= ~(E1000_RXCSUM_TUOFL | E1000_RXCSUM_IPPCSE);
 
-                       /* Enable IPv4 payload checksum for UDP fragments
-                        * Must be used in conjunction with packet-split. */
-                       if (adapter->rx_ps_hdr_size)
-                               rxcsum |= E1000_RXCSUM_IPPCSE;
-               } else {
-                       rxcsum &= ~E1000_RXCSUM_TUOFL;
-                       /* don't need to clear IPPCSE as it defaults to 0 */
-               }
                wr32(E1000_RXCSUM, rxcsum);
        }
 
@@ -1984,7 +2081,7 @@ static void igb_configure_rx(struct igb_adapter *adapter)
  *
  * Free all transmit software resources
  **/
-static void igb_free_tx_resources(struct igb_ring *tx_ring)
+void igb_free_tx_resources(struct igb_ring *tx_ring)
 {
        struct pci_dev *pdev = tx_ring->adapter->pdev;
 
@@ -2027,6 +2124,7 @@ static void igb_unmap_and_free_tx_resource(struct igb_adapter *adapter,
                buffer_info->skb = NULL;
        }
        buffer_info->time_stamp = 0;
+       buffer_info->next_to_watch = 0;
        /* buffer_info must be completely set up in the transmit path */
 }
 
@@ -2082,7 +2180,7 @@ static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
  *
  * Free all receive software resources
  **/
-static void igb_free_rx_resources(struct igb_ring *rx_ring)
+void igb_free_rx_resources(struct igb_ring *rx_ring)
 {
        struct pci_dev *pdev = rx_ring->adapter->pdev;
 
@@ -2091,11 +2189,6 @@ static void igb_free_rx_resources(struct igb_ring *rx_ring)
        vfree(rx_ring->buffer_info);
        rx_ring->buffer_info = NULL;
 
-#ifdef CONFIG_IGB_LRO
-       vfree(rx_ring->lro_mgr.lro_arr);
-       rx_ring->lro_mgr.lro_arr = NULL;
-#endif 
-
        pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
 
        rx_ring->desc = NULL;
@@ -2195,15 +2288,16 @@ static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
 static int igb_set_mac(struct net_device *netdev, void *p)
 {
        struct igb_adapter *adapter = netdev_priv(netdev);
+       struct e1000_hw *hw = &adapter->hw;
        struct sockaddr *addr = p;
 
        if (!is_valid_ether_addr(addr->sa_data))
                return -EADDRNOTAVAIL;
 
        memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
-       memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
+       memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
 
-       adapter->hw.mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
+       hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
 
        return 0;
 }
@@ -2246,8 +2340,8 @@ static void igb_set_multi(struct net_device *netdev)
 
        if (!netdev->mc_count) {
                /* nothing to program, so clear mc list */
-               igb_update_mc_addr_list_82575(hw, NULL, 0, 1,
-                                         mac->rar_entry_count);
+               igb_update_mc_addr_list(hw, NULL, 0, 1,
+                                       mac->rar_entry_count);
                return;
        }
 
@@ -2264,8 +2358,7 @@ static void igb_set_multi(struct net_device *netdev)
                memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr, ETH_ALEN);
                mc_ptr = mc_ptr->next;
        }
-       igb_update_mc_addr_list_82575(hw, mta_list, i, 1,
-                                     mac->rar_entry_count);
+       igb_update_mc_addr_list(hw, mta_list, i, 1, mac->rar_entry_count);
        kfree(mta_list);
 }
 
@@ -2274,8 +2367,47 @@ static void igb_set_multi(struct net_device *netdev)
 static void igb_update_phy_info(unsigned long data)
 {
        struct igb_adapter *adapter = (struct igb_adapter *) data;
-       if (adapter->hw.phy.ops.get_phy_info)
-               adapter->hw.phy.ops.get_phy_info(&adapter->hw);
+       igb_get_phy_info(&adapter->hw);
+}
+
+/**
+ * igb_has_link - check shared code for link and determine up/down
+ * @adapter: pointer to driver private info
+ **/
+static bool igb_has_link(struct igb_adapter *adapter)
+{
+       struct e1000_hw *hw = &adapter->hw;
+       bool link_active = false;
+       s32 ret_val = 0;
+
+       /* get_link_status is set on LSC (link status) interrupt or
+        * rx sequence error interrupt.  get_link_status will stay
+        * false until the e1000_check_for_link establishes link
+        * for copper adapters ONLY
+        */
+       switch (hw->phy.media_type) {
+       case e1000_media_type_copper:
+               if (hw->mac.get_link_status) {
+                       ret_val = hw->mac.ops.check_for_link(hw);
+                       link_active = !hw->mac.get_link_status;
+               } else {
+                       link_active = true;
+               }
+               break;
+       case e1000_media_type_fiber:
+               ret_val = hw->mac.ops.check_for_link(hw);
+               link_active = !!(rd32(E1000_STATUS) & E1000_STATUS_LU);
+               break;
+       case e1000_media_type_internal_serdes:
+               ret_val = hw->mac.ops.check_for_link(hw);
+               link_active = hw->mac.serdes_has_link;
+               break;
+       default:
+       case e1000_media_type_unknown:
+               break;
+       }
+
+       return link_active;
 }
 
 /**
@@ -2294,34 +2426,16 @@ static void igb_watchdog_task(struct work_struct *work)
        struct igb_adapter *adapter = container_of(work,
                                        struct igb_adapter, watchdog_task);
        struct e1000_hw *hw = &adapter->hw;
-
        struct net_device *netdev = adapter->netdev;
        struct igb_ring *tx_ring = adapter->tx_ring;
-       struct e1000_mac_info *mac = &adapter->hw.mac;
        u32 link;
        u32 eics = 0;
-       s32 ret_val;
        int i;
 
-       if ((netif_carrier_ok(netdev)) &&
-           (rd32(E1000_STATUS) & E1000_STATUS_LU))
+       link = igb_has_link(adapter);
+       if ((netif_carrier_ok(netdev)) && link)
                goto link_up;
 
-       ret_val = hw->mac.ops.check_for_link(&adapter->hw);
-       if ((ret_val == E1000_ERR_PHY) &&
-           (hw->phy.type == e1000_phy_igp_3) &&
-           (rd32(E1000_CTRL) &
-            E1000_PHY_CTRL_GBE_DISABLE))
-               dev_info(&adapter->pdev->dev,
-                        "Gigabit has been disabled, downgrading speed\n");
-
-       if ((hw->phy.media_type == e1000_media_type_internal_serdes) &&
-           !(rd32(E1000_TXCW) & E1000_TXCW_ANE))
-               link = mac->serdes_has_link;
-       else
-               link = rd32(E1000_STATUS) &
-                                     E1000_STATUS_LU;
-
        if (link) {
                if (!netif_carrier_ok(netdev)) {
                        u32 ctrl;
@@ -2330,9 +2444,10 @@ static void igb_watchdog_task(struct work_struct *work)
                                                   &adapter->link_duplex);
 
                        ctrl = rd32(E1000_CTRL);
-                       dev_info(&adapter->pdev->dev,
-                                "NIC Link is Up %d Mbps %s, "
+                       /* Links status message must follow this format */
+                       printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s, "
                                 "Flow Control: %s\n",
+                                netdev->name,
                                 adapter->link_speed,
                                 adapter->link_duplex == FULL_DUPLEX ?
                                 "Full Duplex" : "Half Duplex",
@@ -2359,6 +2474,7 @@ static void igb_watchdog_task(struct work_struct *work)
                        netif_carrier_on(netdev);
                        netif_tx_wake_all_queues(netdev);
 
+                       /* link state has changed, schedule phy info update */
                        if (!test_bit(__IGB_DOWN, &adapter->state))
                                mod_timer(&adapter->phy_info_timer,
                                          round_jiffies(jiffies + 2 * HZ));
@@ -2367,9 +2483,13 @@ static void igb_watchdog_task(struct work_struct *work)
                if (netif_carrier_ok(netdev)) {
                        adapter->link_speed = 0;
                        adapter->link_duplex = 0;
-                       dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
+                       /* Links status message must follow this format */
+                       printk(KERN_INFO "igb: %s NIC Link is Down\n",
+                              netdev->name);
                        netif_carrier_off(netdev);
                        netif_tx_stop_all_queues(netdev);
+
+                       /* link state has changed, schedule phy info update */
                        if (!test_bit(__IGB_DOWN, &adapter->state))
                                mod_timer(&adapter->phy_info_timer,
                                          round_jiffies(jiffies + 2 * HZ));
@@ -2379,9 +2499,9 @@ static void igb_watchdog_task(struct work_struct *work)
 link_up:
        igb_update_stats(adapter);
 
-       mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
+       hw->mac.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
        adapter->tpt_old = adapter->stats.tpt;
-       mac->collision_delta = adapter->stats.colc - adapter->colc_old;
+       hw->mac.collision_delta = adapter->stats.colc - adapter->colc_old;
        adapter->colc_old = adapter->stats.colc;
 
        adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
@@ -2538,7 +2658,7 @@ static unsigned int igb_update_itr(struct igb_adapter *adapter, u16 itr_setting,
                if (bytes > 25000) {
                        if (packets > 35)
                                retval = low_latency;
-               } else if (bytes < 6000) {
+               } else if (bytes < 1500) {
                        retval = low_latency;
                }
                break;
@@ -2570,15 +2690,13 @@ static void igb_set_itr(struct igb_adapter *adapter)
                                            adapter->tx_itr,
                                            adapter->tx_ring->total_packets,
                                            adapter->tx_ring->total_bytes);
-
                current_itr = max(adapter->rx_itr, adapter->tx_itr);
        } else {
                current_itr = adapter->rx_itr;
        }
 
        /* conservative mode (itr 3) eliminates the lowest_latency setting */
-       if (adapter->itr_setting == 3 &&
-           current_itr == lowest_latency)
+       if (adapter->itr_setting == 3 && current_itr == lowest_latency)
                current_itr = low_latency;
 
        switch (current_itr) {
@@ -2630,6 +2748,7 @@ set_itr_now:
 #define IGB_TX_FLAGS_VLAN              0x00000002
 #define IGB_TX_FLAGS_TSO               0x00000004
 #define IGB_TX_FLAGS_IPV4              0x00000008
+#define IGB_TX_FLAGS_TSTAMP             0x00000010
 #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000
 #define IGB_TX_FLAGS_VLAN_SHIFT        16
 
@@ -2695,7 +2814,7 @@ static inline int igb_tso_adv(struct igb_adapter *adapter,
        mss_l4len_idx = (skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT);
        mss_l4len_idx |= (l4len << E1000_ADVTXD_L4LEN_SHIFT);
 
-       /* Context index must be unique per ring. */
+       /* For 82575, context index must be unique per ring. */
        if (adapter->flags & IGB_FLAG_NEED_CTX_IDX)
                mss_l4len_idx |= tx_ring->queue_index << 4;
 
@@ -2703,6 +2822,7 @@ static inline int igb_tso_adv(struct igb_adapter *adapter,
        context_desc->seqnum_seed = 0;
 
        buffer_info->time_stamp = jiffies;
+       buffer_info->next_to_watch = i;
        buffer_info->dma = 0;
        i++;
        if (i == tx_ring->count)
@@ -2740,12 +2860,12 @@ static inline bool igb_tx_csum_adv(struct igb_adapter *adapter,
 
                if (skb->ip_summed == CHECKSUM_PARTIAL) {
                        switch (skb->protocol) {
-                       case __constant_htons(ETH_P_IP):
+                       case cpu_to_be16(ETH_P_IP):
                                tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
                                if (ip_hdr(skb)->protocol == IPPROTO_TCP)
                                        tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
                                break;
-                       case __constant_htons(ETH_P_IPV6):
+                       case cpu_to_be16(ETH_P_IPV6):
                                /* XXX what about other V6 headers?? */
                                if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
                                        tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
@@ -2764,8 +2884,11 @@ static inline bool igb_tx_csum_adv(struct igb_adapter *adapter,
                if (adapter->flags & IGB_FLAG_NEED_CTX_IDX)
                        context_desc->mss_l4len_idx =
                                cpu_to_le32(tx_ring->queue_index << 4);
+               else
+                       context_desc->mss_l4len_idx = 0;
 
                buffer_info->time_stamp = jiffies;
+               buffer_info->next_to_watch = i;
                buffer_info->dma = 0;
 
                i++;
@@ -2775,8 +2898,6 @@ static inline bool igb_tx_csum_adv(struct igb_adapter *adapter,
 
                return true;
        }
-
-
        return false;
 }
 
@@ -2784,8 +2905,8 @@ static inline bool igb_tx_csum_adv(struct igb_adapter *adapter,
 #define IGB_MAX_DATA_PER_TXD   (1<<IGB_MAX_TXD_PWR)
 
 static inline int igb_tx_map_adv(struct igb_adapter *adapter,
-                                struct igb_ring *tx_ring,
-                                struct sk_buff *skb)
+                                struct igb_ring *tx_ring, struct sk_buff *skb,
+                                unsigned int first)
 {
        struct igb_buffer *buffer_info;
        unsigned int len = skb_headlen(skb);
@@ -2799,6 +2920,7 @@ static inline int igb_tx_map_adv(struct igb_adapter *adapter,
        buffer_info->length = len;
        /* set time_stamp *before* dma to help avoid a possible race */
        buffer_info->time_stamp = jiffies;
+       buffer_info->next_to_watch = i;
        buffer_info->dma = pci_map_single(adapter->pdev, skb->data, len,
                                          PCI_DMA_TODEVICE);
        count++;
@@ -2816,6 +2938,7 @@ static inline int igb_tx_map_adv(struct igb_adapter *adapter,
                BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
                buffer_info->length = len;
                buffer_info->time_stamp = jiffies;
+               buffer_info->next_to_watch = i;
                buffer_info->dma = pci_map_page(adapter->pdev,
                                                frag->page,
                                                frag->page_offset,
@@ -2828,8 +2951,9 @@ static inline int igb_tx_map_adv(struct igb_adapter *adapter,
                        i = 0;
        }
 
-       i = (i == 0) ? tx_ring->count - 1 : i - 1;
+       i = ((i == 0) ? tx_ring->count - 1 : i - 1);
        tx_ring->buffer_info[i].skb = skb;
+       tx_ring->buffer_info[first].next_to_watch = i;
 
        return count;
 }
@@ -2850,6 +2974,9 @@ static inline void igb_tx_queue_adv(struct igb_adapter *adapter,
        if (tx_flags & IGB_TX_FLAGS_VLAN)
                cmd_type_len |= E1000_ADVTXD_DCMD_VLE;
 
+       if (tx_flags & IGB_TX_FLAGS_TSTAMP)
+               cmd_type_len |= E1000_ADVTXD_MAC_TSTAMP;
+
        if (tx_flags & IGB_TX_FLAGS_TSO) {
                cmd_type_len |= E1000_ADVTXD_DCMD_TSE;
 
@@ -2929,19 +3056,16 @@ static int igb_maybe_stop_tx(struct net_device *netdev,
        return __igb_maybe_stop_tx(netdev, tx_ring, size);
 }
 
-#define TXD_USE_COUNT(S) (((S) >> (IGB_MAX_TXD_PWR)) + 1)
-
 static int igb_xmit_frame_ring_adv(struct sk_buff *skb,
                                   struct net_device *netdev,
                                   struct igb_ring *tx_ring)
 {
        struct igb_adapter *adapter = netdev_priv(netdev);
+       unsigned int first;
        unsigned int tx_flags = 0;
-       unsigned int len;
        u8 hdr_len = 0;
        int tso = 0;
-
-       len = skb_headlen(skb);
+       union skb_shared_tx *shtx;
 
        if (test_bit(__IGB_DOWN, &adapter->state)) {
                dev_kfree_skb_any(skb);
@@ -2962,7 +3086,29 @@ static int igb_xmit_frame_ring_adv(struct sk_buff *skb,
                /* this is a hard error */
                return NETDEV_TX_BUSY;
        }
-       skb_orphan(skb);
+
+       /*
+        * TODO: check that there currently is no other packet with
+        * time stamping in the queue
+        *
+        * When doing time stamping, keep the connection to the socket
+        * a while longer: it is still needed by skb_hwtstamp_tx(),
+        * called either in igb_tx_hwtstamp() or by our caller when
+        * doing software time stamping.
+        */
+       shtx = skb_tx(skb);
+       if (unlikely(shtx->hardware)) {
+               shtx->in_progress = 1;
+               tx_flags |= IGB_TX_FLAGS_TSTAMP;
+       } else if (likely(!shtx->software)) {
+               /*
+                * TODO: can this be solved in dev.c:dev_hard_start_xmit()?
+                * There are probably unmodified driver which do something
+                * like this and thus don't work in combination with
+                * SOF_TIMESTAMPING_TX_SOFTWARE.
+                */
+               skb_orphan(skb);
+       }
 
        if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
                tx_flags |= IGB_TX_FLAGS_VLAN;
@@ -2972,6 +3118,7 @@ static int igb_xmit_frame_ring_adv(struct sk_buff *skb,
        if (skb->protocol == htons(ETH_P_IP))
                tx_flags |= IGB_TX_FLAGS_IPV4;
 
+       first = tx_ring->next_to_use;
        tso = skb_is_gso(skb) ? igb_tso_adv(adapter, tx_ring, skb, tx_flags,
                                              &hdr_len) : 0;
 
@@ -2982,12 +3129,12 @@ static int igb_xmit_frame_ring_adv(struct sk_buff *skb,
 
        if (tso)
                tx_flags |= IGB_TX_FLAGS_TSO;
-       else if (igb_tx_csum_adv(adapter, tx_ring, skb, tx_flags))
-                       if (skb->ip_summed == CHECKSUM_PARTIAL)
-                               tx_flags |= IGB_TX_FLAGS_CSUM;
+       else if (igb_tx_csum_adv(adapter, tx_ring, skb, tx_flags) &&
+                (skb->ip_summed == CHECKSUM_PARTIAL))
+               tx_flags |= IGB_TX_FLAGS_CSUM;
 
        igb_tx_queue_adv(adapter, tx_ring, tx_flags,
-                        igb_tx_map_adv(adapter, tx_ring, skb),
+                        igb_tx_map_adv(adapter, tx_ring, skb, first),
                         skb->len, hdr_len);
 
        netdev->trans_start = jiffies;
@@ -3026,8 +3173,8 @@ static void igb_tx_timeout(struct net_device *netdev)
        /* Do the reset outside of interrupt context */
        adapter->tx_timeout_count++;
        schedule_work(&adapter->reset_task);
-       wr32(E1000_EICS, adapter->eims_enable_mask &
-               ~(E1000_EIMS_TCP_TIMER | E1000_EIMS_OTHER));
+       wr32(E1000_EICS,
+            (adapter->eims_enable_mask & ~adapter->eims_other));
 }
 
 static void igb_reset_task(struct work_struct *work)
@@ -3045,8 +3192,7 @@ static void igb_reset_task(struct work_struct *work)
  * Returns the address of the device statistics structure.
  * The statistics are actually updated from the timer callback.
  **/
-static struct net_device_stats *
-igb_get_stats(struct net_device *netdev)
+static struct net_device_stats *igb_get_stats(struct net_device *netdev)
 {
        struct igb_adapter *adapter = netdev_priv(netdev);
 
@@ -3080,6 +3226,7 @@ static int igb_change_mtu(struct net_device *netdev, int new_mtu)
 
        while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
                msleep(1);
+
        /* igb_down has a dependency on max_frame_size */
        adapter->max_frame_size = max_frame;
        if (netif_running(netdev))
@@ -3249,8 +3396,7 @@ void igb_update_stats(struct igb_adapter *adapter)
        /* Phy Stats */
        if (hw->phy.media_type == e1000_media_type_copper) {
                if ((adapter->link_speed == SPEED_1000) &&
-                  (!hw->phy.ops.read_phy_reg(hw, PHY_1000T_STATUS,
-                                             &phy_tmp))) {
+                  (!igb_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
                        phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
                        adapter->phy_stats.idle_errors += phy_tmp;
                }
@@ -3262,7 +3408,6 @@ void igb_update_stats(struct igb_adapter *adapter)
        adapter->stats.mgpdc += rd32(E1000_MGTPDC);
 }
 
-
 static irqreturn_t igb_msix_other(int irq, void *data)
 {
        struct net_device *netdev = data;
@@ -3271,15 +3416,20 @@ static irqreturn_t igb_msix_other(int irq, void *data)
        u32 icr = rd32(E1000_ICR);
 
        /* reading ICR causes bit 31 of EICR to be cleared */
+
+       if(icr & E1000_ICR_DOUTSYNC) {
+               /* HW is reporting DMA is out of sync */
+               adapter->stats.doosync++;
+       }
        if (!(icr & E1000_ICR_LSC))
                goto no_link_interrupt;
        hw->mac.get_link_status = 1;
        /* guard against interrupt when we're going down */
        if (!test_bit(__IGB_DOWN, &adapter->state))
                mod_timer(&adapter->watchdog_timer, jiffies + 1);
-       
+
 no_link_interrupt:
-       wr32(E1000_IMS, E1000_IMS_LSC);
+       wr32(E1000_IMS, E1000_IMS_LSC | E1000_IMS_DOUTSYNC);
        wr32(E1000_EIMS, adapter->eims_other);
 
        return IRQ_HANDLED;
@@ -3295,6 +3445,7 @@ static irqreturn_t igb_msix_tx(int irq, void *data)
        if (adapter->flags & IGB_FLAG_DCA_ENABLED)
                igb_update_tx_dca(tx_ring);
 #endif
+
        tx_ring->total_bytes = 0;
        tx_ring->total_packets = 0;
 
@@ -3315,13 +3466,11 @@ static void igb_write_itr(struct igb_ring *ring)
        if ((ring->adapter->itr_setting & 3) && ring->set_itr) {
                switch (hw->mac.type) {
                case e1000_82576:
-                       wr32(ring->itr_register,
-                            ring->itr_val |
+                       wr32(ring->itr_register, ring->itr_val |
                             0x80000000);
                        break;
                default:
-                       wr32(ring->itr_register,
-                            ring->itr_val |
+                       wr32(ring->itr_register, ring->itr_val |
                             (ring->itr_val << 16));
                        break;
                }
@@ -3332,7 +3481,6 @@ static void igb_write_itr(struct igb_ring *ring)
 static irqreturn_t igb_msix_rx(int irq, void *data)
 {
        struct igb_ring *rx_ring = data;
-       struct igb_adapter *adapter = rx_ring->adapter;
 
        /* Write the ITR value calculated at the end of the
         * previous interrupt.
@@ -3340,11 +3488,11 @@ static irqreturn_t igb_msix_rx(int irq, void *data)
 
        igb_write_itr(rx_ring);
 
-       if (netif_rx_schedule_prep(adapter->netdev, &rx_ring->napi))
-               __netif_rx_schedule(adapter->netdev, &rx_ring->napi);
+       if (napi_schedule_prep(&rx_ring->napi))
+               __napi_schedule(&rx_ring->napi);
 
 #ifdef CONFIG_IGB_DCA
-       if (adapter->flags & IGB_FLAG_DCA_ENABLED)
+       if (rx_ring->adapter->flags & IGB_FLAG_DCA_ENABLED)
                igb_update_rx_dca(rx_ring);
 #endif
                return IRQ_HANDLED;
@@ -3357,7 +3505,7 @@ static void igb_update_rx_dca(struct igb_ring *rx_ring)
        struct igb_adapter *adapter = rx_ring->adapter;
        struct e1000_hw *hw = &adapter->hw;
        int cpu = get_cpu();
-       int q = rx_ring - adapter->rx_ring;
+       int q = rx_ring->reg_idx;
 
        if (rx_ring->cpu != cpu) {
                dca_rxctrl = rd32(E1000_DCA_RXCTRL(q));
@@ -3384,7 +3532,7 @@ static void igb_update_tx_dca(struct igb_ring *tx_ring)
        struct igb_adapter *adapter = tx_ring->adapter;
        struct e1000_hw *hw = &adapter->hw;
        int cpu = get_cpu();
-       int q = tx_ring - adapter->tx_ring;
+       int q = tx_ring->reg_idx;
 
        if (tx_ring->cpu != cpu) {
                dca_txctrl = rd32(E1000_DCA_TXCTRL(q));
@@ -3427,19 +3575,16 @@ static int __igb_notify_dca(struct device *dev, void *data)
        struct e1000_hw *hw = &adapter->hw;
        unsigned long event = *(unsigned long *)data;
 
-       if (!(adapter->flags & IGB_FLAG_HAS_DCA))
-               goto out;
-
        switch (event) {
        case DCA_PROVIDER_ADD:
                /* if already enabled, don't do it again */
                if (adapter->flags & IGB_FLAG_DCA_ENABLED)
                        break;
-               adapter->flags |= IGB_FLAG_DCA_ENABLED;
                /* Always use CB2 mode, difference is masked
                 * in the CB driver. */
-               wr32(E1000_DCA_CTRL, 2);
+               wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
                if (dca_add_requester(dev) == 0) {
+                       adapter->flags |= IGB_FLAG_DCA_ENABLED;
                        dev_info(&adapter->pdev->dev, "DCA enabled\n");
                        igb_setup_dca(adapter);
                        break;
@@ -3452,11 +3597,11 @@ static int __igb_notify_dca(struct device *dev, void *data)
                        dca_remove_requester(dev);
                        dev_info(&adapter->pdev->dev, "DCA disabled\n");
                        adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
-                       wr32(E1000_DCA_CTRL, 1);
+                       wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
                }
                break;
        }
-out:
+
        return 0;
 }
 
@@ -3487,19 +3632,24 @@ static irqreturn_t igb_intr_msi(int irq, void *data)
 
        igb_write_itr(adapter->rx_ring);
 
+       if(icr & E1000_ICR_DOUTSYNC) {
+               /* HW is reporting DMA is out of sync */
+               adapter->stats.doosync++;
+       }
+
        if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
                hw->mac.get_link_status = 1;
                if (!test_bit(__IGB_DOWN, &adapter->state))
                        mod_timer(&adapter->watchdog_timer, jiffies + 1);
        }
 
-       netif_rx_schedule(netdev, &adapter->rx_ring[0].napi);
+       napi_schedule(&adapter->rx_ring[0].napi);
 
        return IRQ_HANDLED;
 }
 
 /**
- * igb_intr - Interrupt Handler
+ * igb_intr - Legacy Interrupt Handler
  * @irq: interrupt number
  * @data: pointer to a network interface device structure
  **/
@@ -3511,7 +3661,6 @@ static irqreturn_t igb_intr(int irq, void *data)
        /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked.  No
         * need for the IMC write */
        u32 icr = rd32(E1000_ICR);
-       u32 eicr = 0;
        if (!icr)
                return IRQ_NONE;  /* Not our interrupt */
 
@@ -3522,7 +3671,10 @@ static irqreturn_t igb_intr(int irq, void *data)
        if (!(icr & E1000_ICR_INT_ASSERTED))
                return IRQ_NONE;
 
-       eicr = rd32(E1000_EICR);
+       if(icr & E1000_ICR_DOUTSYNC) {
+               /* HW is reporting DMA is out of sync */
+               adapter->stats.doosync++;
+       }
 
        if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
                hw->mac.get_link_status = 1;
@@ -3531,7 +3683,7 @@ static irqreturn_t igb_intr(int irq, void *data)
                        mod_timer(&adapter->watchdog_timer, jiffies + 1);
        }
 
-       netif_rx_schedule(netdev, &adapter->rx_ring[0].napi);
+       napi_schedule(&adapter->rx_ring[0].napi);
 
        return IRQ_HANDLED;
 }
@@ -3566,7 +3718,7 @@ static int igb_poll(struct napi_struct *napi, int budget)
            !netif_running(netdev)) {
                if (adapter->itr_setting & 3)
                        igb_set_itr(adapter);
-               netif_rx_complete(netdev, napi);
+               napi_complete(napi);
                if (!test_bit(__IGB_DOWN, &adapter->state))
                        igb_irq_enable(adapter);
                return 0;
@@ -3589,10 +3741,9 @@ static int igb_clean_rx_ring_msix(struct napi_struct *napi, int budget)
 #endif
        igb_clean_rx_irq_adv(rx_ring, &work_done, budget);
 
-
        /* If not enough Rx work done, exit the polling mode */
        if ((work_done == 0) || !netif_running(netdev)) {
-               netif_rx_complete(netdev, napi);
+               napi_complete(napi);
 
                if (adapter->itr_setting & 3) {
                        if (adapter->num_rx_queues == 1)
@@ -3600,7 +3751,6 @@ static int igb_clean_rx_ring_msix(struct napi_struct *napi, int budget)
                        else
                                igb_update_ring_itr(rx_ring);
                }
-
                if (!test_bit(__IGB_DOWN, &adapter->state))
                        wr32(E1000_EIMS, rx_ring->eims_value);
 
@@ -3610,10 +3760,41 @@ static int igb_clean_rx_ring_msix(struct napi_struct *napi, int budget)
        return 1;
 }
 
-static inline u32 get_head(struct igb_ring *tx_ring)
+/**
+ * igb_hwtstamp - utility function which checks for TX time stamp
+ * @adapter: board private structure
+ * @skb: packet that was just sent
+ *
+ * If we were asked to do hardware stamping and such a time stamp is
+ * available, then it must have been for this skb here because we only
+ * allow only one such packet into the queue.
+ */
+static void igb_tx_hwtstamp(struct igb_adapter *adapter, struct sk_buff *skb)
 {
-       void *end = (struct e1000_tx_desc *)tx_ring->desc + tx_ring->count;
-       return le32_to_cpu(*(volatile __le32 *)end);
+       union skb_shared_tx *shtx = skb_tx(skb);
+       struct e1000_hw *hw = &adapter->hw;
+
+       if (unlikely(shtx->hardware)) {
+               u32 valid = rd32(E1000_TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID;
+               if (valid) {
+                       u64 regval = rd32(E1000_TXSTMPL);
+                       u64 ns;
+                       struct skb_shared_hwtstamps shhwtstamps;
+
+                       memset(&shhwtstamps, 0, sizeof(shhwtstamps));
+                       regval |= (u64)rd32(E1000_TXSTMPH) << 32;
+                       ns = timecounter_cyc2time(&adapter->clock,
+                                                 regval);
+                       timecompare_update(&adapter->compare, ns);
+                       shhwtstamps.hwtstamp = ns_to_ktime(ns);
+                       shhwtstamps.syststamp =
+                               timecompare_transform(&adapter->compare, ns);
+                       skb_tstamp_tx(skb, &shhwtstamps);
+               }
+
+               /* delayed orphaning: skb_tstamp_tx() needs the socket */
+               skb_orphan(skb);
+       }
 }
 
 /**
@@ -3624,24 +3805,25 @@ static inline u32 get_head(struct igb_ring *tx_ring)
 static bool igb_clean_tx_irq(struct igb_ring *tx_ring)
 {
        struct igb_adapter *adapter = tx_ring->adapter;
-       struct e1000_hw *hw = &adapter->hw;
        struct net_device *netdev = adapter->netdev;
-       struct e1000_tx_desc *tx_desc;
+       struct e1000_hw *hw = &adapter->hw;
        struct igb_buffer *buffer_info;
        struct sk_buff *skb;
-       unsigned int i;
-       u32 head, oldhead;
-       unsigned int count = 0;
+       union e1000_adv_tx_desc *tx_desc, *eop_desc;
        unsigned int total_bytes = 0, total_packets = 0;
-       bool retval = true;
+       unsigned int i, eop, count = 0;
+       bool cleaned = false;
 
-       rmb();
-       head = get_head(tx_ring);
        i = tx_ring->next_to_clean;
-       while (1) {
-               while (i != head) {
-                       tx_desc = E1000_TX_DESC(*tx_ring, i);
+       eop = tx_ring->buffer_info[i].next_to_watch;
+       eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop);
+
+       while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) &&
+              (count < tx_ring->count)) {
+               for (cleaned = false; !cleaned; count++) {
+                       tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
                        buffer_info = &tx_ring->buffer_info[i];
+                       cleaned = (i == eop);
                        skb = buffer_info->skb;
 
                        if (skb) {
@@ -3653,28 +3835,21 @@ static bool igb_clean_tx_irq(struct igb_ring *tx_ring)
                                            skb->len;
                                total_packets += segs;
                                total_bytes += bytecount;
+
+                               igb_tx_hwtstamp(adapter, skb);
                        }
 
                        igb_unmap_and_free_tx_resource(adapter, buffer_info);
+                       tx_desc->wb.status = 0;
 
                        i++;
                        if (i == tx_ring->count)
                                i = 0;
-
-                       count++;
-                       if (count == IGB_MAX_TX_CLEAN) {
-                               retval = false;
-                               goto done_cleaning;
-                       }
                }
-               oldhead = head;
-               rmb();
-               head = get_head(tx_ring);
-               if (head == oldhead)
-                       goto done_cleaning;
-       }  /* while (1) */
-
-done_cleaning:
+               eop = tx_ring->buffer_info[i].next_to_watch;
+               eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop);
+       }
+
        tx_ring->next_to_clean = i;
 
        if (unlikely(count &&
@@ -3701,7 +3876,6 @@ done_cleaning:
                    && !(rd32(E1000_STATUS) &
                         E1000_STATUS_TXOFF)) {
 
-                       tx_desc = E1000_TX_DESC(*tx_ring, i);
                        /* detected Tx unit hang */
                        dev_err(&adapter->pdev->dev,
                                "Detected Tx Unit Hang\n"
@@ -3710,9 +3884,9 @@ done_cleaning:
                                "  TDT                  <%x>\n"
                                "  next_to_use          <%x>\n"
                                "  next_to_clean        <%x>\n"
-                               "  head (WB)            <%x>\n"
                                "buffer_info[next_to_clean]\n"
                                "  time_stamp           <%lx>\n"
+                               "  next_to_watch        <%x>\n"
                                "  jiffies              <%lx>\n"
                                "  desc.status          <%x>\n",
                                tx_ring->queue_index,
@@ -3720,10 +3894,10 @@ done_cleaning:
                                readl(adapter->hw.hw_addr + tx_ring->tail),
                                tx_ring->next_to_use,
                                tx_ring->next_to_clean,
-                               head,
                                tx_ring->buffer_info[i].time_stamp,
+                               eop,
                                jiffies,
-                               tx_desc->upper.fields.status);
+                               eop_desc->wb.status);
                        netif_stop_subqueue(netdev, tx_ring->queue_index);
                }
        }
@@ -3733,47 +3907,14 @@ done_cleaning:
        tx_ring->tx_stats.packets += total_packets;
        adapter->net_stats.tx_bytes += total_bytes;
        adapter->net_stats.tx_packets += total_packets;
-       return retval;
-}
-
-#ifdef CONFIG_IGB_LRO
- /**
- * igb_get_skb_hdr - helper function for LRO header processing
- * @skb: pointer to sk_buff to be added to LRO packet
- * @iphdr: pointer to ip header structure
- * @tcph: pointer to tcp header structure
- * @hdr_flags: pointer to header flags
- * @priv: pointer to the receive descriptor for the current sk_buff
- **/
-static int igb_get_skb_hdr(struct sk_buff *skb, void **iphdr, void **tcph,
-                           u64 *hdr_flags, void *priv)
-{
-       union e1000_adv_rx_desc *rx_desc = priv;
-       u16 pkt_type = rx_desc->wb.lower.lo_dword.pkt_info &
-                      (E1000_RXDADV_PKTTYPE_IPV4 | E1000_RXDADV_PKTTYPE_TCP);
-
-       /* Verify that this is a valid IPv4 TCP packet */
-       if (pkt_type != (E1000_RXDADV_PKTTYPE_IPV4 |
-                         E1000_RXDADV_PKTTYPE_TCP))
-               return -1;
-
-       /* Set network headers */
-       skb_reset_network_header(skb);
-       skb_set_transport_header(skb, ip_hdrlen(skb));
-       *iphdr = ip_hdr(skb);
-       *tcph = tcp_hdr(skb);
-       *hdr_flags = LRO_IPV4 | LRO_TCP;
-
-       return 0;
-
+       return (count < tx_ring->count);
 }
-#endif /* CONFIG_IGB_LRO */
 
 /**
  * igb_receive_skb - helper function to handle rx indications
- * @ring: pointer to receive ring receving this packet 
+ * @ring: pointer to receive ring receving this packet
  * @status: descriptor status field as written by hardware
- * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
+ * @rx_desc: receive descriptor containing vlan and type information.
  * @skb: pointer to sk_buff to be indicated to stack
  **/
 static void igb_receive_skb(struct igb_ring *ring, u8 status,
@@ -3783,31 +3924,23 @@ static void igb_receive_skb(struct igb_ring *ring, u8 status,
        struct igb_adapter * adapter = ring->adapter;
        bool vlan_extracted = (adapter->vlgrp && (status & E1000_RXD_STAT_VP));
 
-#ifdef CONFIG_IGB_LRO
-       if (adapter->netdev->features & NETIF_F_LRO &&
-           skb->ip_summed == CHECKSUM_UNNECESSARY) {
+       skb_record_rx_queue(skb, ring->queue_index);
+       if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
                if (vlan_extracted)
-                       lro_vlan_hwaccel_receive_skb(&ring->lro_mgr, skb,
-                                          adapter->vlgrp,
-                                          le16_to_cpu(rx_desc->wb.upper.vlan),
-                                          rx_desc);
+                       vlan_gro_receive(&ring->napi, adapter->vlgrp,
+                                        le16_to_cpu(rx_desc->wb.upper.vlan),
+                                        skb);
                else
-                       lro_receive_skb(&ring->lro_mgr,skb, rx_desc);
-               ring->lro_used = 1;
+                       napi_gro_receive(&ring->napi, skb);
        } else {
-#endif
                if (vlan_extracted)
                        vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
                                          le16_to_cpu(rx_desc->wb.upper.vlan));
                else
-
                        netif_receive_skb(skb);
-#ifdef CONFIG_IGB_LRO
        }
-#endif
 }
 
-
 static inline void igb_rx_checksum_adv(struct igb_adapter *adapter,
                                       u32 status_err, struct sk_buff *skb)
 {
@@ -3835,17 +3968,19 @@ static bool igb_clean_rx_irq_adv(struct igb_ring *rx_ring,
 {
        struct igb_adapter *adapter = rx_ring->adapter;
        struct net_device *netdev = adapter->netdev;
+       struct e1000_hw *hw = &adapter->hw;
        struct pci_dev *pdev = adapter->pdev;
        union e1000_adv_rx_desc *rx_desc , *next_rxd;
        struct igb_buffer *buffer_info , *next_buffer;
        struct sk_buff *skb;
-       unsigned int i;
-       u32 length, hlen, staterr;
        bool cleaned = false;
        int cleaned_count = 0;
        unsigned int total_bytes = 0, total_packets = 0;
+       unsigned int i;
+       u32 length, hlen, staterr;
 
        i = rx_ring->next_to_clean;
+       buffer_info = &rx_ring->buffer_info[i];
        rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
        staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
 
@@ -3853,25 +3988,22 @@ static bool igb_clean_rx_irq_adv(struct igb_ring *rx_ring,
                if (*work_done >= budget)
                        break;
                (*work_done)++;
-               buffer_info = &rx_ring->buffer_info[i];
 
-               /* HW will not DMA in data larger than the given buffer, even
-                * if it parses the (NFS, of course) header to be larger.  In
-                * that case, it fills the header buffer and spills the rest
-                * into the page.
-                */
-               hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) &
-                 E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT;
-               if (hlen > adapter->rx_ps_hdr_size)
-                       hlen = adapter->rx_ps_hdr_size;
+               skb = buffer_info->skb;
+               prefetch(skb->data - NET_IP_ALIGN);
+               buffer_info->skb = NULL;
+
+               i++;
+               if (i == rx_ring->count)
+                       i = 0;
+               next_rxd = E1000_RX_DESC_ADV(*rx_ring, i);
+               prefetch(next_rxd);
+               next_buffer = &rx_ring->buffer_info[i];
 
                length = le16_to_cpu(rx_desc->wb.upper.length);
                cleaned = true;
                cleaned_count++;
 
-               skb = buffer_info->skb;
-               prefetch(skb->data - NET_IP_ALIGN);
-               buffer_info->skb = NULL;
                if (!adapter->rx_ps_hdr_size) {
                        pci_unmap_single(pdev, buffer_info->dma,
                                         adapter->rx_buffer_len +
@@ -3881,10 +4013,19 @@ static bool igb_clean_rx_irq_adv(struct igb_ring *rx_ring,
                        goto send_up;
                }
 
+               /* HW will not DMA in data larger than the given buffer, even
+                * if it parses the (NFS, of course) header to be larger.  In
+                * that case, it fills the header buffer and spills the rest
+                * into the page.
+                */
+               hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) &
+                 E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT;
+               if (hlen > adapter->rx_ps_hdr_size)
+                       hlen = adapter->rx_ps_hdr_size;
+
                if (!skb_shinfo(skb)->nr_frags) {
                        pci_unmap_single(pdev, buffer_info->dma,
-                                        adapter->rx_ps_hdr_size +
-                                          NET_IP_ALIGN,
+                                        adapter->rx_ps_hdr_size + NET_IP_ALIGN,
                                         PCI_DMA_FROMDEVICE);
                        skb_put(skb, hlen);
                }
@@ -3910,19 +4051,55 @@ static bool igb_clean_rx_irq_adv(struct igb_ring *rx_ring,
 
                        skb->truesize += length;
                }
-send_up:
-               i++;
-               if (i == rx_ring->count)
-                       i = 0;
-               next_rxd = E1000_RX_DESC_ADV(*rx_ring, i);
-               prefetch(next_rxd);
-               next_buffer = &rx_ring->buffer_info[i];
 
                if (!(staterr & E1000_RXD_STAT_EOP)) {
-                       buffer_info->skb = xchg(&next_buffer->skb, skb);
-                       buffer_info->dma = xchg(&next_buffer->dma, 0);
+                       buffer_info->skb = next_buffer->skb;
+                       buffer_info->dma = next_buffer->dma;
+                       next_buffer->skb = skb;
+                       next_buffer->dma = 0;
                        goto next_desc;
                }
+send_up:
+               /*
+                * If this bit is set, then the RX registers contain
+                * the time stamp. No other packet will be time
+                * stamped until we read these registers, so read the
+                * registers to make them available again. Because
+                * only one packet can be time stamped at a time, we
+                * know that the register values must belong to this
+                * one here and therefore we don't need to compare
+                * any of the additional attributes stored for it.
+                *
+                * If nothing went wrong, then it should have a
+                * skb_shared_tx that we can turn into a
+                * skb_shared_hwtstamps.
+                *
+                * TODO: can time stamping be triggered (thus locking
+                * the registers) without the packet reaching this point
+                * here? In that case RX time stamping would get stuck.
+                *
+                * TODO: in "time stamp all packets" mode this bit is
+                * not set. Need a global flag for this mode and then
+                * always read the registers. Cannot be done without
+                * a race condition.
+                */
+               if (unlikely(staterr & E1000_RXD_STAT_TS)) {
+                       u64 regval;
+                       u64 ns;
+                       struct skb_shared_hwtstamps *shhwtstamps =
+                               skb_hwtstamps(skb);
+
+                       WARN(!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID),
+                            "igb: no RX time stamp available for time stamped packet");
+                       regval = rd32(E1000_RXSTMPL);
+                       regval |= (u64)rd32(E1000_RXSTMPH) << 32;
+                       ns = timecounter_cyc2time(&adapter->clock, regval);
+                       timecompare_update(&adapter->compare, ns);
+                       memset(shhwtstamps, 0, sizeof(*shhwtstamps));
+                       shhwtstamps->hwtstamp = ns_to_ktime(ns);
+                       shhwtstamps->syststamp =
+                               timecompare_transform(&adapter->compare, ns);
+               }
 
                if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
                        dev_kfree_skb_irq(skb);
@@ -3938,8 +4115,6 @@ send_up:
 
                igb_receive_skb(rx_ring, staterr, rx_desc, skb);
 
-               netdev->last_rx = jiffies;
-
 next_desc:
                rx_desc->wb.upper.status_error = 0;
 
@@ -3952,20 +4127,12 @@ next_desc:
                /* use prefetched values */
                rx_desc = next_rxd;
                buffer_info = next_buffer;
-
                staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
        }
 
        rx_ring->next_to_clean = i;
        cleaned_count = IGB_DESC_UNUSED(rx_ring);
 
-#ifdef CONFIG_IGB_LRO
-       if (rx_ring->lro_used) {
-               lro_flush_all(&rx_ring->lro_mgr);
-               rx_ring->lro_used = 0;
-       }
-#endif
-
        if (cleaned_count)
                igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
 
@@ -3978,7 +4145,6 @@ next_desc:
        return cleaned;
 }
 
-
 /**
  * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split
  * @adapter: address of board private structure
@@ -3993,10 +4159,17 @@ static void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring,
        struct igb_buffer *buffer_info;
        struct sk_buff *skb;
        unsigned int i;
+       int bufsz;
 
        i = rx_ring->next_to_use;
        buffer_info = &rx_ring->buffer_info[i];
 
+       if (adapter->rx_ps_hdr_size)
+               bufsz = adapter->rx_ps_hdr_size;
+       else
+               bufsz = adapter->rx_buffer_len;
+       bufsz += NET_IP_ALIGN;
+
        while (cleaned_count--) {
                rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
 
@@ -4012,23 +4185,14 @@ static void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring,
                                buffer_info->page_offset ^= PAGE_SIZE / 2;
                        }
                        buffer_info->page_dma =
-                               pci_map_page(pdev,
-                                            buffer_info->page,
+                               pci_map_page(pdev, buffer_info->page,
                                             buffer_info->page_offset,
                                             PAGE_SIZE / 2,
                                             PCI_DMA_FROMDEVICE);
                }
 
                if (!buffer_info->skb) {
-                       int bufsz;
-
-                       if (adapter->rx_ps_hdr_size)
-                               bufsz = adapter->rx_ps_hdr_size;
-                       else
-                               bufsz = adapter->rx_buffer_len;
-                       bufsz += NET_IP_ALIGN;
                        skb = netdev_alloc_skb(netdev, bufsz);
-
                        if (!skb) {
                                adapter->alloc_rx_buff_failed++;
                                goto no_buffers;
@@ -4044,7 +4208,6 @@ static void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring,
                        buffer_info->dma = pci_map_single(pdev, skb->data,
                                                          bufsz,
                                                          PCI_DMA_FROMDEVICE);
-
                }
                /* Refresh the desc even if buffer_addrs didn't change because
                 * each write-back erases this info. */
@@ -4102,9 +4265,8 @@ static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
        case SIOCGMIIREG:
                if (!capable(CAP_NET_ADMIN))
                        return -EPERM;
-               if (adapter->hw.phy.ops.read_phy_reg(&adapter->hw,
-                                                    data->reg_num
-                                                    & 0x1F, &data->val_out))
+               if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
+                                    &data->val_out))
                        return -EIO;
                break;
        case SIOCSMIIREG:
@@ -4114,6 +4276,163 @@ static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
        return 0;
 }
 
+/**
+ * igb_hwtstamp_ioctl - control hardware time stamping
+ * @netdev:
+ * @ifreq:
+ * @cmd:
+ *
+ * Outgoing time stamping can be enabled and disabled. Play nice and
+ * disable it when requested, although it shouldn't case any overhead
+ * when no packet needs it. At most one packet in the queue may be
+ * marked for time stamping, otherwise it would be impossible to tell
+ * for sure to which packet the hardware time stamp belongs.
+ *
+ * Incoming time stamping has to be configured via the hardware
+ * filters. Not all combinations are supported, in particular event
+ * type has to be specified. Matching the kind of event packet is
+ * not supported, with the exception of "all V2 events regardless of
+ * level 2 or 4".
+ *
+ **/
+static int igb_hwtstamp_ioctl(struct net_device *netdev,
+                             struct ifreq *ifr, int cmd)
+{
+       struct igb_adapter *adapter = netdev_priv(netdev);
+       struct e1000_hw *hw = &adapter->hw;
+       struct hwtstamp_config config;
+       u32 tsync_tx_ctl_bit = E1000_TSYNCTXCTL_ENABLED;
+       u32 tsync_rx_ctl_bit = E1000_TSYNCRXCTL_ENABLED;
+       u32 tsync_rx_ctl_type = 0;
+       u32 tsync_rx_cfg = 0;
+       int is_l4 = 0;
+       int is_l2 = 0;
+       short port = 319; /* PTP */
+       u32 regval;
+
+       if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
+               return -EFAULT;
+
+       /* reserved for future extensions */
+       if (config.flags)
+               return -EINVAL;
+
+       switch (config.tx_type) {
+       case HWTSTAMP_TX_OFF:
+               tsync_tx_ctl_bit = 0;
+               break;
+       case HWTSTAMP_TX_ON:
+               tsync_tx_ctl_bit = E1000_TSYNCTXCTL_ENABLED;
+               break;
+       default:
+               return -ERANGE;
+       }
+
+       switch (config.rx_filter) {
+       case HWTSTAMP_FILTER_NONE:
+               tsync_rx_ctl_bit = 0;
+               break;
+       case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
+       case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
+       case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
+       case HWTSTAMP_FILTER_ALL:
+               /*
+                * register TSYNCRXCFG must be set, therefore it is not
+                * possible to time stamp both Sync and Delay_Req messages
+                * => fall back to time stamping all packets
+                */
+               tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_ALL;
+               config.rx_filter = HWTSTAMP_FILTER_ALL;
+               break;
+       case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
+               tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L4_V1;
+               tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE;
+               is_l4 = 1;
+               break;
+       case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
+               tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L4_V1;
+               tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE;
+               is_l4 = 1;
+               break;
+       case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
+       case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
+               tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
+               tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE;
+               is_l2 = 1;
+               is_l4 = 1;
+               config.rx_filter = HWTSTAMP_FILTER_SOME;
+               break;
+       case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
+       case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
+               tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
+               tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE;
+               is_l2 = 1;
+               is_l4 = 1;
+               config.rx_filter = HWTSTAMP_FILTER_SOME;
+               break;
+       case HWTSTAMP_FILTER_PTP_V2_EVENT:
+       case HWTSTAMP_FILTER_PTP_V2_SYNC:
+       case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
+               tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_EVENT_V2;
+               config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
+               is_l2 = 1;
+               break;
+       default:
+               return -ERANGE;
+       }
+
+       /* enable/disable TX */
+       regval = rd32(E1000_TSYNCTXCTL);
+       regval = (regval & ~E1000_TSYNCTXCTL_ENABLED) | tsync_tx_ctl_bit;
+       wr32(E1000_TSYNCTXCTL, regval);
+
+       /* enable/disable RX, define which PTP packets are time stamped */
+       regval = rd32(E1000_TSYNCRXCTL);
+       regval = (regval & ~E1000_TSYNCRXCTL_ENABLED) | tsync_rx_ctl_bit;
+       regval = (regval & ~0xE) | tsync_rx_ctl_type;
+       wr32(E1000_TSYNCRXCTL, regval);
+       wr32(E1000_TSYNCRXCFG, tsync_rx_cfg);
+
+       /*
+        * Ethertype Filter Queue Filter[0][15:0] = 0x88F7
+        *                                          (Ethertype to filter on)
+        * Ethertype Filter Queue Filter[0][26] = 0x1 (Enable filter)
+        * Ethertype Filter Queue Filter[0][30] = 0x1 (Enable Timestamping)
+        */
+       wr32(E1000_ETQF0, is_l2 ? 0x440088f7 : 0);
+
+       /* L4 Queue Filter[0]: only filter by source and destination port */
+       wr32(E1000_SPQF0, htons(port));
+       wr32(E1000_IMIREXT(0), is_l4 ?
+            ((1<<12) | (1<<19) /* bypass size and control flags */) : 0);
+       wr32(E1000_IMIR(0), is_l4 ?
+            (htons(port)
+             | (0<<16) /* immediate interrupt disabled */
+             | 0 /* (1<<17) bit cleared: do not bypass
+                    destination port check */)
+               : 0);
+       wr32(E1000_FTQF0, is_l4 ?
+            (0x11 /* UDP */
+             | (1<<15) /* VF not compared */
+             | (1<<27) /* Enable Timestamping */
+             | (7<<28) /* only source port filter enabled,
+                          source/target address and protocol
+                          masked */)
+            : ((1<<15) | (15<<28) /* all mask bits set = filter not
+                                     enabled */));
+
+       wrfl();
+
+       adapter->hwtstamp_config = config;
+
+       /* clear TX/RX time stamp registers, just to be sure */
+       regval = rd32(E1000_TXSTMPH);
+       regval = rd32(E1000_RXSTMPH);
+
+       return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
+               -EFAULT : 0;
+}
+
 /**
  * igb_ioctl -
  * @netdev:
@@ -4127,6 +4446,8 @@ static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
        case SIOCGMIIREG:
        case SIOCSMIIREG:
                return igb_mii_ioctl(netdev, ifr, cmd);
+       case SIOCSHWTSTAMP:
+               return igb_hwtstamp_ioctl(netdev, ifr, cmd);
        default:
                return -EOPNOTSUPP;
        }
@@ -4179,7 +4500,7 @@ static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
        struct e1000_hw *hw = &adapter->hw;
        u32 vfta, index;
 
-       if ((adapter->hw.mng_cookie.status &
+       if ((hw->mng_cookie.status &
             E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
            (vid == adapter->mng_vlan_id))
                return;
@@ -4271,7 +4592,6 @@ int igb_set_spd_dplx(struct igb_adapter *adapter, u16 spddplx)
        return 0;
 }
 
-
 static int igb_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        struct net_device *netdev = pci_get_drvdata(pdev);
@@ -4363,10 +4683,7 @@ static int igb_resume(struct pci_dev *pdev)
        pci_set_power_state(pdev, PCI_D0);
        pci_restore_state(pdev);
 
-       if (adapter->need_ioport)
-               err = pci_enable_device(pdev);
-       else
-               err = pci_enable_device_mem(pdev);
+       err = pci_enable_device_mem(pdev);
        if (err) {
                dev_err(&pdev->dev,
                        "igb: Cannot enable PCI device from suspend\n");
@@ -4387,6 +4704,11 @@ static int igb_resume(struct pci_dev *pdev)
        /* e1000_power_up_phy(adapter); */
 
        igb_reset(adapter);
+
+       /* let the f/w know that the h/w is now under the control of the
+        * driver. */
+       igb_get_hw_control(adapter);
+
        wr32(E1000_WUS, ~0);
 
        if (netif_running(netdev)) {
@@ -4397,10 +4719,6 @@ static int igb_resume(struct pci_dev *pdev)
 
        netif_device_attach(netdev);
 
-       /* let the f/w know that the h/w is now under the control of the
-        * driver. */
-       igb_get_hw_control(adapter);
-
        return 0;
 }
 #endif
@@ -4419,22 +4737,27 @@ static void igb_shutdown(struct pci_dev *pdev)
 static void igb_netpoll(struct net_device *netdev)
 {
        struct igb_adapter *adapter = netdev_priv(netdev);
+       struct e1000_hw *hw = &adapter->hw;
        int i;
-       int work_done = 0;
 
-       igb_irq_disable(adapter);
-       adapter->flags |= IGB_FLAG_IN_NETPOLL;
-
-       for (i = 0; i < adapter->num_tx_queues; i++)
-               igb_clean_tx_irq(&adapter->tx_ring[i]);
+       if (!adapter->msix_entries) {
+               igb_irq_disable(adapter);
+               napi_schedule(&adapter->rx_ring[0].napi);
+               return;
+       }
 
-       for (i = 0; i < adapter->num_rx_queues; i++)
-               igb_clean_rx_irq_adv(&adapter->rx_ring[i],
-                                    &work_done,
-                                    adapter->rx_ring[i].napi.weight);
+       for (i = 0; i < adapter->num_tx_queues; i++) {
+               struct igb_ring *tx_ring = &adapter->tx_ring[i];
+               wr32(E1000_EIMC, tx_ring->eims_value);
+               igb_clean_tx_irq(tx_ring);
+               wr32(E1000_EIMS, tx_ring->eims_value);
+       }
 
-       adapter->flags &= ~IGB_FLAG_IN_NETPOLL;
-       igb_irq_enable(adapter);
+       for (i = 0; i < adapter->num_rx_queues; i++) {
+               struct igb_ring *rx_ring = &adapter->rx_ring[i];
+               wr32(E1000_EIMC, rx_ring->eims_value);
+               napi_schedule(&rx_ring->napi);
+       }
 }
 #endif /* CONFIG_NET_POLL_CONTROLLER */
 
@@ -4474,27 +4797,33 @@ static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
        struct net_device *netdev = pci_get_drvdata(pdev);
        struct igb_adapter *adapter = netdev_priv(netdev);
        struct e1000_hw *hw = &adapter->hw;
+       pci_ers_result_t result;
        int err;
 
-       if (adapter->need_ioport)
-               err = pci_enable_device(pdev);
-       else
-               err = pci_enable_device_mem(pdev);
-       if (err) {
+       if (pci_enable_device_mem(pdev)) {
                dev_err(&pdev->dev,
                        "Cannot re-enable PCI device after reset.\n");
-               return PCI_ERS_RESULT_DISCONNECT;
-       }
-       pci_set_master(pdev);
-       pci_restore_state(pdev);
+               result = PCI_ERS_RESULT_DISCONNECT;
+       } else {
+               pci_set_master(pdev);
+               pci_restore_state(pdev);
 
-       pci_enable_wake(pdev, PCI_D3hot, 0);
-       pci_enable_wake(pdev, PCI_D3cold, 0);
+               pci_enable_wake(pdev, PCI_D3hot, 0);
+               pci_enable_wake(pdev, PCI_D3cold, 0);
 
-       igb_reset(adapter);
-       wr32(E1000_WUS, ~0);
+               igb_reset(adapter);
+               wr32(E1000_WUS, ~0);
+               result = PCI_ERS_RESULT_RECOVERED;
+       }
+
+       err = pci_cleanup_aer_uncorrect_error_status(pdev);
+       if (err) {
+               dev_err(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status "
+                       "failed 0x%0x\n", err);
+               /* non-fatal, continue */
+       }
 
-       return PCI_ERS_RESULT_RECOVERED;
+       return result;
 }
 
 /**
@@ -4522,7 +4851,6 @@ static void igb_io_resume(struct pci_dev *pdev)
        /* let the f/w know that the h/w is now under the control of the
         * driver. */
        igb_get_hw_control(adapter);
-
 }
 
 /* igb_main.c */
This page took 0.068964 seconds and 5 git commands to generate.