]> err.no Git - linux-2.6/blobdiff - drivers/net/e1000/e1000_main.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-2.6
[linux-2.6] / drivers / net / e1000 / e1000_main.c
index 2ab9f96f5dab899274a1bfb024f5094a7f5c9879..7dca38fba6a1809605340915aa7c9d65abeaa206 100644 (file)
@@ -1,25 +1,24 @@
 /*******************************************************************************
 
-  
-  Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
-  
-  This program is free software; you can redistribute it and/or modify it 
-  under the terms of the GNU General Public License as published by the Free 
-  Software Foundation; either version 2 of the License, or (at your option) 
-  any later version.
-  
-  This program is distributed in the hope that it will be useful, but WITHOUT 
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
+  Intel PRO/1000 Linux driver
+  Copyright(c) 1999 - 2006 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,
+  version 2, as published by the Free Software Foundation.
+
+  This program is distributed in the hope it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
-  
+
   You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc., 59 
-  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-  
-  The full GNU General Public License is included in this distribution in the
-  file called LICENSE.
-  
+  this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+
+  The full GNU General Public License is included in this distribution in
+  the file called "COPYING".
+
   Contact Information:
   Linux NICS <linux.nics@intel.com>
   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
@@ -36,7 +35,7 @@ static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
 #else
 #define DRIVERNAPI "-NAPI"
 #endif
-#define DRV_VERSION "7.1.9-k4"DRIVERNAPI
+#define DRV_VERSION "7.2.9-k2"DRIVERNAPI
 char e1000_driver_version[] = DRV_VERSION;
 static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
 
@@ -99,6 +98,7 @@ static struct pci_device_id e1000_pci_tbl[] = {
        INTEL_E1000_ETHERNET_DEVICE(0x1098),
        INTEL_E1000_ETHERNET_DEVICE(0x1099),
        INTEL_E1000_ETHERNET_DEVICE(0x109A),
+       INTEL_E1000_ETHERNET_DEVICE(0x10A4),
        INTEL_E1000_ETHERNET_DEVICE(0x10B5),
        INTEL_E1000_ETHERNET_DEVICE(0x10B9),
        INTEL_E1000_ETHERNET_DEVICE(0x10BA),
@@ -109,16 +109,24 @@ static struct pci_device_id e1000_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
 
+int e1000_up(struct e1000_adapter *adapter);
+void e1000_down(struct e1000_adapter *adapter);
+void e1000_reinit_locked(struct e1000_adapter *adapter);
+void e1000_reset(struct e1000_adapter *adapter);
+int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
+int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
+int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
+void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
+void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
-                                    struct e1000_tx_ring *txdr);
+                             struct e1000_tx_ring *txdr);
 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
-                                    struct e1000_rx_ring *rxdr);
+                             struct e1000_rx_ring *rxdr);
 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
-                                    struct e1000_tx_ring *tx_ring);
+                             struct e1000_tx_ring *tx_ring);
 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
-                                    struct e1000_rx_ring *rx_ring);
-
-/* Local Function Prototypes */
+                             struct e1000_rx_ring *rx_ring);
+void e1000_update_stats(struct e1000_adapter *adapter);
 
 static int e1000_init_module(void);
 static void e1000_exit_module(void);
@@ -171,6 +179,7 @@ static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
                           int cmd);
+void e1000_set_ethtool_ops(struct net_device *netdev);
 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
 static void e1000_tx_timeout(struct net_device *dev);
@@ -195,6 +204,8 @@ static void e1000_shutdown(struct pci_dev *pdev);
 static void e1000_netpoll (struct net_device *netdev);
 #endif
 
+extern void e1000_check_options(struct e1000_adapter *adapter);
+
 static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
                      pci_channel_state_t state);
 static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
@@ -211,9 +222,9 @@ static struct pci_driver e1000_driver = {
        .id_table = e1000_pci_tbl,
        .probe    = e1000_probe,
        .remove   = __devexit_p(e1000_remove),
+#ifdef CONFIG_PM
        /* Power Managment Hooks */
        .suspend  = e1000_suspend,
-#ifdef CONFIG_PM
        .resume   = e1000_resume,
 #endif
        .shutdown = e1000_shutdown,
@@ -245,7 +256,7 @@ e1000_init_module(void)
 
        printk(KERN_INFO "%s\n", e1000_copyright);
 
-       ret = pci_module_init(&e1000_driver);
+       ret = pci_register_driver(&e1000_driver);
 
        return ret;
 }
@@ -465,13 +476,14 @@ e1000_up(struct e1000_adapter *adapter)
 
        adapter->tx_queue_len = netdev->tx_queue_len;
 
-       mod_timer(&adapter->watchdog_timer, jiffies);
-
 #ifdef CONFIG_E1000_NAPI
        netif_poll_enable(netdev);
 #endif
        e1000_irq_enable(adapter);
 
+       clear_bit(__E1000_DOWN, &adapter->flags);
+
+       mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
        return 0;
 }
 
@@ -485,7 +497,7 @@ e1000_up(struct e1000_adapter *adapter)
  *
  **/
 
-static void e1000_power_up_phy(struct e1000_adapter *adapter)
+void e1000_power_up_phy(struct e1000_adapter *adapter)
 {
        uint16_t mii_reg = 0;
 
@@ -501,25 +513,48 @@ static void e1000_power_up_phy(struct e1000_adapter *adapter)
 
 static void e1000_power_down_phy(struct e1000_adapter *adapter)
 {
-       boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
-                                     e1000_check_mng_mode(&adapter->hw);
-       /* Power down the PHY so no link is implied when interface is down
-        * The PHY cannot be powered down if any of the following is TRUE
+       /* Power down the PHY so no link is implied when interface is down *
+        * The PHY cannot be powered down if any of the following is TRUE *
         * (a) WoL is enabled
         * (b) AMT is active
         * (c) SoL/IDER session is active */
        if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
-           adapter->hw.mac_type != e1000_ich8lan &&
-           adapter->hw.media_type == e1000_media_type_copper &&
-           !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
-           !mng_mode_enabled &&
-           !e1000_check_phy_reset_block(&adapter->hw)) {
+          adapter->hw.media_type == e1000_media_type_copper) {
                uint16_t mii_reg = 0;
+
+               switch (adapter->hw.mac_type) {
+               case e1000_82540:
+               case e1000_82545:
+               case e1000_82545_rev_3:
+               case e1000_82546:
+               case e1000_82546_rev_3:
+               case e1000_82541:
+               case e1000_82541_rev_2:
+               case e1000_82547:
+               case e1000_82547_rev_2:
+                       if (E1000_READ_REG(&adapter->hw, MANC) &
+                           E1000_MANC_SMBUS_EN)
+                               goto out;
+                       break;
+               case e1000_82571:
+               case e1000_82572:
+               case e1000_82573:
+               case e1000_80003es2lan:
+               case e1000_ich8lan:
+                       if (e1000_check_mng_mode(&adapter->hw) ||
+                           e1000_check_phy_reset_block(&adapter->hw))
+                               goto out;
+                       break;
+               default:
+                       goto out;
+               }
                e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
                mii_reg |= MII_CR_POWER_DOWN;
                e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
                mdelay(1);
        }
+out:
+       return;
 }
 
 void
@@ -527,6 +562,10 @@ e1000_down(struct e1000_adapter *adapter)
 {
        struct net_device *netdev = adapter->netdev;
 
+       /* signal that we're down so the interrupt handler does not
+        * reschedule our watchdog timer */
+       set_bit(__E1000_DOWN, &adapter->flags);
+
        e1000_irq_disable(adapter);
 
        del_timer_sync(&adapter->tx_fifo_stall_timer);
@@ -562,6 +601,9 @@ void
 e1000_reset(struct e1000_adapter *adapter)
 {
        uint32_t pba, manc;
+#ifdef DISABLE_MULR
+       uint32_t tctl;
+#endif
        uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
 
        /* Repartition Pba for greater than 9k mtu
@@ -628,6 +670,12 @@ e1000_reset(struct e1000_adapter *adapter)
        e1000_reset_hw(&adapter->hw);
        if (adapter->hw.mac_type >= e1000_82544)
                E1000_WRITE_REG(&adapter->hw, WUC, 0);
+#ifdef DISABLE_MULR
+       /* disable Multiple Reads in Transmit Control Register for debugging */
+       tctl = E1000_READ_REG(hw, TCTL);
+       E1000_WRITE_REG(hw, TCTL, tctl & ~E1000_TCTL_MULR);
+
+#endif
        if (e1000_init_hw(&adapter->hw))
                DPRINTK(PROBE, ERR, "Hardware Error\n");
        e1000_update_mng_vlan(adapter);
@@ -651,9 +699,7 @@ e1000_reset(struct e1000_adapter *adapter)
                                    phy_data);
        }
 
-       if (adapter->hw.mac_type < e1000_ich8lan)
-       /* FIXME: this code is duplicate and wrong for PCI Express */
-       if (adapter->en_mng_pt) {
+       if ((adapter->en_mng_pt) && (adapter->hw.mac_type < e1000_82571)) {
                manc = E1000_READ_REG(&adapter->hw, MANC);
                manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
                E1000_WRITE_REG(&adapter->hw, MANC, manc);
@@ -682,9 +728,9 @@ e1000_probe(struct pci_dev *pdev,
        unsigned long flash_start, flash_len;
 
        static int cards_found = 0;
-       static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
+       static int global_quad_port_a = 0; /* global ksp3 port a indication */
        int i, err, pci_using_dac;
-       uint16_t eeprom_data;
+       uint16_t eeprom_data = 0;
        uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
        if ((err = pci_enable_device(pdev)))
                return err;
@@ -696,21 +742,20 @@ e1000_probe(struct pci_dev *pdev,
                if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
                    (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
                        E1000_ERR("No usable DMA configuration, aborting\n");
-                       return err;
+                       goto err_dma;
                }
                pci_using_dac = 0;
        }
 
        if ((err = pci_request_regions(pdev, e1000_driver_name)))
-               return err;
+               goto err_pci_reg;
 
        pci_set_master(pdev);
 
+       err = -ENOMEM;
        netdev = alloc_etherdev(sizeof(struct e1000_adapter));
-       if (!netdev) {
-               err = -ENOMEM;
+       if (!netdev)
                goto err_alloc_etherdev;
-       }
 
        SET_MODULE_OWNER(netdev);
        SET_NETDEV_DEV(netdev, &pdev->dev);
@@ -725,11 +770,10 @@ e1000_probe(struct pci_dev *pdev,
        mmio_start = pci_resource_start(pdev, BAR_0);
        mmio_len = pci_resource_len(pdev, BAR_0);
 
+       err = -EIO;
        adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
-       if (!adapter->hw.hw_addr) {
-               err = -EIO;
+       if (!adapter->hw.hw_addr)
                goto err_ioremap;
-       }
 
        for (i = BAR_1; i <= BAR_5; i++) {
                if (pci_resource_len(pdev, i) == 0)
@@ -761,7 +805,7 @@ e1000_probe(struct pci_dev *pdev,
 #ifdef CONFIG_NET_POLL_CONTROLLER
        netdev->poll_controller = e1000_netpoll;
 #endif
-       strcpy(netdev->name, pci_name(pdev));
+       strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
 
        netdev->mem_start = mmio_start;
        netdev->mem_end = mmio_start + mmio_len;
@@ -774,6 +818,7 @@ e1000_probe(struct pci_dev *pdev,
        if ((err = e1000_sw_init(adapter)))
                goto err_sw_init;
 
+       err = -EIO;
        /* Flash BAR mapping must happen after e1000_sw_init
         * because it depends on mac_type */
        if ((adapter->hw.mac_type == e1000_ich8lan) &&
@@ -781,24 +826,13 @@ e1000_probe(struct pci_dev *pdev,
                flash_start = pci_resource_start(pdev, 1);
                flash_len = pci_resource_len(pdev, 1);
                adapter->hw.flash_address = ioremap(flash_start, flash_len);
-               if (!adapter->hw.flash_address) {
-                       err = -EIO;
+               if (!adapter->hw.flash_address)
                        goto err_flashmap;
-               }
        }
 
-       if ((err = e1000_check_phy_reset_block(&adapter->hw)))
+       if (e1000_check_phy_reset_block(&adapter->hw))
                DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
 
-       /* if ksp3, indicate if it's port a being setup */
-       if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 &&
-                       e1000_ksp3_port_a == 0)
-               adapter->ksp3_port_a = 1;
-       e1000_ksp3_port_a++;
-       /* Reset for multiple KP3 adapters */
-       if (e1000_ksp3_port_a == 4)
-               e1000_ksp3_port_a = 0;
-
        if (adapter->hw.mac_type >= e1000_82543) {
                netdev->features = NETIF_F_SG |
                                   NETIF_F_HW_CSUM |
@@ -830,7 +864,7 @@ e1000_probe(struct pci_dev *pdev,
 
        if (e1000_init_eeprom_params(&adapter->hw)) {
                E1000_ERR("EEPROM initialization failed\n");
-               return -EIO;
+               goto err_eeprom;
        }
 
        /* before reading the EEPROM, reset the controller to
@@ -842,7 +876,6 @@ e1000_probe(struct pci_dev *pdev,
 
        if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
                DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
-               err = -EIO;
                goto err_eeprom;
        }
 
@@ -855,12 +888,9 @@ e1000_probe(struct pci_dev *pdev,
 
        if (!is_valid_ether_addr(netdev->perm_addr)) {
                DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
-               err = -EIO;
                goto err_eeprom;
        }
 
-       e1000_read_part_num(&adapter->hw, &(adapter->part_num));
-
        e1000_get_bus_info(&adapter->hw);
 
        init_timer(&adapter->tx_fifo_stall_timer);
@@ -878,11 +908,6 @@ e1000_probe(struct pci_dev *pdev,
        INIT_WORK(&adapter->reset_task,
                (void (*)(void *))e1000_reset_task, netdev);
 
-       /* we're going to reset, so assume we have no link for now */
-
-       netif_carrier_off(netdev);
-       netif_stop_queue(netdev);
-
        e1000_check_options(adapter);
 
        /* Initial Wake on LAN setting
@@ -921,7 +946,38 @@ e1000_probe(struct pci_dev *pdev,
                break;
        }
        if (eeprom_data & eeprom_apme_mask)
-               adapter->wol |= E1000_WUFC_MAG;
+               adapter->eeprom_wol |= E1000_WUFC_MAG;
+
+       /* now that we have the eeprom settings, apply the special cases
+        * where the eeprom may be wrong or the board simply won't support
+        * wake on lan on a particular port */
+       switch (pdev->device) {
+       case E1000_DEV_ID_82546GB_PCIE:
+               adapter->eeprom_wol = 0;
+               break;
+       case E1000_DEV_ID_82546EB_FIBER:
+       case E1000_DEV_ID_82546GB_FIBER:
+       case E1000_DEV_ID_82571EB_FIBER:
+               /* Wake events only supported on port A for dual fiber
+                * regardless of eeprom setting */
+               if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
+                       adapter->eeprom_wol = 0;
+               break;
+       case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
+       case E1000_DEV_ID_82571EB_QUAD_COPPER:
+               /* if quad port adapter, disable WoL on all but port A */
+               if (global_quad_port_a != 0)
+                       adapter->eeprom_wol = 0;
+               else
+                       adapter->quad_port_a = 1;
+               /* Reset for multiple quad port adapters */
+               if (++global_quad_port_a == 4)
+                       global_quad_port_a = 0;
+               break;
+       }
+
+       /* initialize the wol settings based on the eeprom settings */
+       adapter->wol = adapter->eeprom_wol;
 
        /* print bus type/speed/width info */
        {
@@ -958,22 +1014,43 @@ e1000_probe(struct pci_dev *pdev,
        if ((err = register_netdev(netdev)))
                goto err_register;
 
+       /* tell the stack to leave us alone until e1000_open() is called */
+       netif_carrier_off(netdev);
+       netif_stop_queue(netdev);
+
        DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
 
        cards_found++;
        return 0;
 
 err_register:
+       e1000_release_hw_control(adapter);
+err_eeprom:
+       if (!e1000_check_phy_reset_block(&adapter->hw))
+               e1000_phy_hw_reset(&adapter->hw);
+
        if (adapter->hw.flash_address)
                iounmap(adapter->hw.flash_address);
 err_flashmap:
+#ifdef CONFIG_E1000_NAPI
+       for (i = 0; i < adapter->num_rx_queues; i++)
+               dev_put(&adapter->polling_netdev[i]);
+#endif
+
+       kfree(adapter->tx_ring);
+       kfree(adapter->rx_ring);
+#ifdef CONFIG_E1000_NAPI
+       kfree(adapter->polling_netdev);
+#endif
 err_sw_init:
-err_eeprom:
        iounmap(adapter->hw.hw_addr);
 err_ioremap:
        free_netdev(netdev);
 err_alloc_etherdev:
        pci_release_regions(pdev);
+err_pci_reg:
+err_dma:
+       pci_disable_device(pdev);
        return err;
 }
 
@@ -999,8 +1076,7 @@ e1000_remove(struct pci_dev *pdev)
 
        flush_scheduled_work();
 
-       if (adapter->hw.mac_type >= e1000_82540 &&
-          adapter->hw.mac_type != e1000_ich8lan &&
+       if (adapter->hw.mac_type < e1000_82571 &&
           adapter->hw.media_type == e1000_media_type_copper) {
                manc = E1000_READ_REG(&adapter->hw, MANC);
                if (manc & E1000_MANC_SMBUS_EN) {
@@ -1128,6 +1204,8 @@ e1000_sw_init(struct e1000_adapter *adapter)
        atomic_set(&adapter->irq_sem, 1);
        spin_lock_init(&adapter->stats_lock);
 
+       set_bit(__E1000_DOWN, &adapter->flags);
+
        return 0;
 }
 
@@ -1193,7 +1271,7 @@ e1000_open(struct net_device *netdev)
        int err;
 
        /* disallow open during test */
-       if (test_bit(__E1000_DRIVER_TESTING, &adapter->flags))
+       if (test_bit(__E1000_TESTING, &adapter->flags))
                return -EBUSY;
 
        /* allocate transmit descriptors */
@@ -1208,7 +1286,7 @@ e1000_open(struct net_device *netdev)
 
        err = e1000_request_irq(adapter);
        if (err)
-               goto err_up;
+               goto err_req_irq;
 
        e1000_power_up_phy(adapter);
 
@@ -1229,6 +1307,9 @@ e1000_open(struct net_device *netdev)
        return E1000_SUCCESS;
 
 err_up:
+       e1000_power_down_phy(adapter);
+       e1000_free_irq(adapter);
+err_req_irq:
        e1000_free_all_rx_resources(adapter);
 err_setup_rx:
        e1000_free_all_tx_resources(adapter);
@@ -1263,8 +1344,12 @@ e1000_close(struct net_device *netdev)
        e1000_free_all_tx_resources(adapter);
        e1000_free_all_rx_resources(adapter);
 
+       /* kill manageability vlan ID if supported, but not if a vlan with
+        * the same ID is registered on the host OS (let 8021q kill it) */
        if ((adapter->hw.mng_cookie.status &
-                         E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
+                         E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
+            !(adapter->vlgrp &&
+                         adapter->vlgrp->vlan_devices[adapter->mng_vlan_id])) {
                e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
        }
 
@@ -1381,10 +1466,6 @@ setup_tx_desc_die:
  *                               (Descriptors) for all queues
  * @adapter: board private structure
  *
- * If this function returns with an error, then it's possible one or
- * more of the rings is populated (while the rest are not).  It is the
- * callers duty to clean those orphaned rings.
- *
  * Return 0 on success, negative on failure
  **/
 
@@ -1398,6 +1479,9 @@ e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
                if (err) {
                        DPRINTK(PROBE, ERR,
                                "Allocation for Tx Queue %u failed\n", i);
+                       for (i-- ; i >= 0; i--)
+                               e1000_free_tx_resources(adapter,
+                                                       &adapter->tx_ring[i]);
                        break;
                }
        }
@@ -1475,32 +1559,17 @@ e1000_configure_tx(struct e1000_adapter *adapter)
        /* Program the Transmit Control Register */
 
        tctl = E1000_READ_REG(hw, TCTL);
-
        tctl &= ~E1000_TCTL_CT;
        tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
                (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
 
-#ifdef DISABLE_MULR
-       /* disable Multiple Reads for debugging */
-       tctl &= ~E1000_TCTL_MULR;
-#endif
-
        if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
                tarc = E1000_READ_REG(hw, TARC0);
-               tarc |= ((1 << 25) | (1 << 21));
+               tarc |= (1 << 21);
                E1000_WRITE_REG(hw, TARC0, tarc);
-               tarc = E1000_READ_REG(hw, TARC1);
-               tarc |= (1 << 25);
-               if (tctl & E1000_TCTL_MULR)
-                       tarc &= ~(1 << 28);
-               else
-                       tarc |= (1 << 28);
-               E1000_WRITE_REG(hw, TARC1, tarc);
        } else if (hw->mac_type == e1000_80003es2lan) {
                tarc = E1000_READ_REG(hw, TARC0);
                tarc |= 1;
-               if (hw->media_type == e1000_media_type_internal_serdes)
-                       tarc |= (1 << 20);
                E1000_WRITE_REG(hw, TARC0, tarc);
                tarc = E1000_READ_REG(hw, TARC1);
                tarc |= 1;
@@ -1639,10 +1708,6 @@ setup_rx_desc_die:
  *                               (Descriptors) for all queues
  * @adapter: board private structure
  *
- * If this function returns with an error, then it's possible one or
- * more of the rings is populated (while the rest are not).  It is the
- * callers duty to clean those orphaned rings.
- *
  * Return 0 on success, negative on failure
  **/
 
@@ -1656,6 +1721,9 @@ e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
                if (err) {
                        DPRINTK(PROBE, ERR,
                                "Allocation for Rx Queue %u failed\n", i);
+                       for (i-- ; i >= 0; i--)
+                               e1000_free_rx_resources(adapter,
+                                                       &adapter->rx_ring[i]);
                        break;
                }
        }
@@ -2442,10 +2510,9 @@ e1000_watchdog(unsigned long data)
                         * disable receives in the ISR and
                         * reset device here in the watchdog
                         */
-                       if (adapter->hw.mac_type == e1000_80003es2lan) {
+                       if (adapter->hw.mac_type == e1000_80003es2lan)
                                /* reset device */
                                schedule_work(&adapter->reset_task);
-                       }
                }
 
                e1000_smartspeed(adapter);
@@ -2545,7 +2612,7 @@ e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
                        cmd_length = E1000_TXD_CMD_IP;
                        ipcse = skb->h.raw - skb->data - 1;
 #ifdef NETIF_F_TSO_IPV6
-               } else if (skb->protocol == ntohs(ETH_P_IPV6)) {
+               } else if (skb->protocol == htons(ETH_P_IPV6)) {
                        skb->nh.ipv6h->payload_len = 0;
                        skb->h.th->check =
                                ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
@@ -2861,6 +2928,35 @@ e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
        return 0;
 }
 
+static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
+{
+       struct e1000_adapter *adapter = netdev_priv(netdev);
+       struct e1000_tx_ring *tx_ring = adapter->tx_ring;
+
+       netif_stop_queue(netdev);
+       /* Herbert's original patch had:
+        *  smp_mb__after_netif_stop_queue();
+        * but since that doesn't exist yet, just open code it. */
+       smp_mb();
+
+       /* We need to check again in a case another CPU has just
+        * made room available. */
+       if (likely(E1000_DESC_UNUSED(tx_ring) < size))
+               return -EBUSY;
+
+       /* A reprieve! */
+       netif_start_queue(netdev);
+       return 0;
+}
+
+static int e1000_maybe_stop_tx(struct net_device *netdev,
+                               struct e1000_tx_ring *tx_ring, int size)
+{
+       if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
+               return 0;
+       return __e1000_maybe_stop_tx(netdev, size);
+}
+
 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
 static int
 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
@@ -2879,6 +2975,10 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
        unsigned int f;
        len -= skb->data_len;
 
+       /* This goes back to the question of how to logically map a tx queue
+        * to a flow.  Right now, performance is impacted slightly negatively
+        * if using multiple tx queues.  If the stack breaks away from a
+        * single qdisc implementation, we can look at this again. */
        tx_ring = adapter->tx_ring;
 
        if (unlikely(skb->len <= 0)) {
@@ -2974,8 +3074,7 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
 
        /* need: count + 2 desc gap to keep tail from touching
         * head, otherwise try next time */
-       if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
-               netif_stop_queue(netdev);
+       if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
                spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
                return NETDEV_TX_BUSY;
        }
@@ -2983,7 +3082,7 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
        if (unlikely(adapter->hw.mac_type == e1000_82547)) {
                if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
                        netif_stop_queue(netdev);
-                       mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
+                       mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
                        spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
                        return NETDEV_TX_BUSY;
                }
@@ -3022,8 +3121,7 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
        netdev->trans_start = jiffies;
 
        /* Make sure there is space in the ring for the next send. */
-       if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
-               netif_stop_queue(netdev);
+       e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
 
        spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
        return NETDEV_TX_OK;
@@ -3100,11 +3198,13 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu)
                }
                break;
        case e1000_82573:
-               /* only enable jumbo frames if ASPM is disabled completely
-                * this means both bits must be zero in 0x1A bits 3:2 */
+               /* Jumbo Frames not supported if:
+                * - this is not an 82573L device
+                * - ASPM is enabled in any way (0x1A bits 3:2) */
                e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
                                  &eeprom_data);
-               if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
+               if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
+                   (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
                        if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
                                DPRINTK(PROBE, ERR,
                                        "Jumbo Frames not supported.\n");
@@ -3112,6 +3212,8 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu)
                        }
                        break;
                }
+               /* ERT will be enabled later to enable wire speed receives */
+
                /* fall through to get support */
        case e1000_82571:
        case e1000_82572:
@@ -3297,16 +3399,15 @@ e1000_update_stats(struct e1000_adapter *adapter)
                adapter->stats.crcerrs + adapter->stats.algnerrc +
                adapter->stats.ruc + adapter->stats.roc +
                adapter->stats.cexterr;
-       adapter->net_stats.rx_length_errors = adapter->stats.ruc +
-                                             adapter->stats.roc;
+       adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
+       adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
        adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
        adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
        adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
 
        /* Tx Errors */
-
-       adapter->net_stats.tx_errors = adapter->stats.ecol +
-                                      adapter->stats.latecol;
+       adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
+       adapter->net_stats.tx_errors = adapter->stats.txerrc;
        adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
        adapter->net_stats.tx_window_errors = adapter->stats.latecol;
        adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
@@ -3377,7 +3478,9 @@ e1000_intr(int irq, void *data, struct pt_regs *regs)
                        rctl = E1000_READ_REG(hw, RCTL);
                        E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
                }
-               mod_timer(&adapter->watchdog_timer, jiffies);
+               /* guard against interrupt when we're going down */
+               if (!test_bit(__E1000_DOWN, &adapter->flags))
+                       mod_timer(&adapter->watchdog_timer, jiffies + 1);
        }
 
 #ifdef CONFIG_E1000_NAPI
@@ -3515,13 +3618,14 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter,
        tx_ring->next_to_clean = i;
 
 #define TX_WAKE_THRESHOLD 32
-       if (unlikely(cleaned && netif_queue_stopped(netdev) &&
-                    netif_carrier_ok(netdev))) {
-               spin_lock(&tx_ring->tx_lock);
-               if (netif_queue_stopped(netdev) &&
-                   (E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))
+       if (unlikely(cleaned && netif_carrier_ok(netdev) &&
+                    E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
+               /* Make sure that anybody stopping the queue after this
+                * sees the new next_to_clean.
+                */
+               smp_mb();
+               if (netif_queue_stopped(netdev))
                        netif_wake_queue(netdev);
-               spin_unlock(&tx_ring->tx_lock);
        }
 
        if (adapter->detect_tx_hung) {
@@ -3680,7 +3784,7 @@ e1000_clean_rx_irq(struct e1000_adapter *adapter,
                        E1000_DBG("%s: Receive packet consumed multiple"
                                  " buffers\n", netdev->name);
                        /* recycle */
-                       buffer_info-> skb = skb;
+                       buffer_info->skb = skb;
                        goto next_desc;
                }
 
@@ -3711,7 +3815,6 @@ e1000_clean_rx_irq(struct e1000_adapter *adapter,
                            netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
                        if (new_skb) {
                                skb_reserve(new_skb, NET_IP_ALIGN);
-                               new_skb->dev = netdev;
                                memcpy(new_skb->data - NET_IP_ALIGN,
                                       skb->data - NET_IP_ALIGN,
                                       length + NET_IP_ALIGN);
@@ -3978,13 +4081,13 @@ e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
        buffer_info = &rx_ring->buffer_info[i];
 
        while (cleaned_count--) {
-               if (!(skb = buffer_info->skb))
-                       skb = netdev_alloc_skb(netdev, bufsz);
-               else {
+               skb = buffer_info->skb;
+               if (skb) {
                        skb_trim(skb, 0);
                        goto map_skb;
                }
 
+               skb = netdev_alloc_skb(netdev, bufsz);
                if (unlikely(!skb)) {
                        /* Better luck next round */
                        adapter->alloc_rx_buff_failed++;
@@ -4009,10 +4112,10 @@ e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
                                dev_kfree_skb(skb);
                                dev_kfree_skb(oldskb);
                                break; /* while !buffer_info->skb */
-                       } else {
-                               /* Use new allocation */
-                               dev_kfree_skb(oldskb);
                        }
+
+                       /* Use new allocation */
+                       dev_kfree_skb(oldskb);
                }
                /* Make buffer alignment 2 beyond a 16 byte boundary
                 * this will result in a 16 byte aligned IP header after
@@ -4020,8 +4123,6 @@ e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
                 */
                skb_reserve(skb, NET_IP_ALIGN);
 
-               skb->dev = netdev;
-
                buffer_info->skb = skb;
                buffer_info->length = adapter->rx_buffer_len;
 map_skb:
@@ -4135,8 +4236,6 @@ e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
                 */
                skb_reserve(skb, NET_IP_ALIGN);
 
-               skb->dev = netdev;
-
                buffer_info->skb = skb;
                buffer_info->length = adapter->rx_ps_bsize0;
                buffer_info->dma = pci_map_single(pdev, skb->data,
@@ -4386,13 +4485,21 @@ e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
        pci_write_config_word(adapter->pdev, reg, *value);
 }
 
-#if 0
-uint32_t
-e1000_io_read(struct e1000_hw *hw, unsigned long port)
+int32_t
+e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
 {
-       return inl(port);
+    struct e1000_adapter *adapter = hw->back;
+    uint16_t cap_offset;
+
+    cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
+    if (!cap_offset)
+        return -E1000_ERR_CONFIG;
+
+    pci_read_config_word(adapter->pdev, cap_offset + reg, value);
+
+    return E1000_SUCCESS;
 }
-#endif  /*  0  */
+
 
 void
 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
@@ -4628,7 +4735,7 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
                e1000_set_multi(netdev);
 
                /* turn on all-multi mode if wake on multicast is enabled */
-               if (adapter->wol & E1000_WUFC_MC) {
+               if (wufc & E1000_WUFC_MC) {
                        rctl = E1000_READ_REG(&adapter->hw, RCTL);
                        rctl |= E1000_RCTL_MPE;
                        E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
@@ -4667,9 +4774,7 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
                pci_enable_wake(pdev, PCI_D3cold, 0);
        }
 
-       /* FIXME: this code is incorrect for PCI Express */
-       if (adapter->hw.mac_type >= e1000_82540 &&
-          adapter->hw.mac_type != e1000_ich8lan &&
+       if (adapter->hw.mac_type < e1000_82571 &&
           adapter->hw.media_type == e1000_media_type_copper) {
                manc = E1000_READ_REG(&adapter->hw, MANC);
                if (manc & E1000_MANC_SMBUS_EN) {
@@ -4700,11 +4805,14 @@ e1000_resume(struct pci_dev *pdev)
 {
        struct net_device *netdev = pci_get_drvdata(pdev);
        struct e1000_adapter *adapter = netdev_priv(netdev);
-       uint32_t manc, ret_val;
+       uint32_t manc, err;
 
        pci_set_power_state(pdev, PCI_D0);
        e1000_pci_restore_state(adapter);
-       ret_val = pci_enable_device(pdev);
+       if ((err = pci_enable_device(pdev))) {
+               printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
+               return err;
+       }
        pci_set_master(pdev);
 
        pci_enable_wake(pdev, PCI_D3hot, 0);
@@ -4718,9 +4826,7 @@ e1000_resume(struct pci_dev *pdev)
 
        netif_device_attach(netdev);
 
-       /* FIXME: this code is incorrect for PCI Express */
-       if (adapter->hw.mac_type >= e1000_82540 &&
-          adapter->hw.mac_type != e1000_ich8lan &&
+       if (adapter->hw.mac_type < e1000_82571 &&
           adapter->hw.media_type == e1000_media_type_copper) {
                manc = E1000_READ_REG(&adapter->hw, MANC);
                manc &= ~(E1000_MANC_ARP_EN);
@@ -4782,6 +4888,7 @@ static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channe
 
        if (netif_running(netdev))
                e1000_down(adapter);
+       pci_disable_device(pdev);
 
        /* Request a slot slot reset. */
        return PCI_ERS_RESULT_NEED_RESET;
@@ -4805,8 +4912,8 @@ static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
        }
        pci_set_master(pdev);
 
-       pci_enable_wake(pdev, 3, 0);
-       pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */
+       pci_enable_wake(pdev, PCI_D3hot, 0);
+       pci_enable_wake(pdev, PCI_D3cold, 0);
 
        /* Perform card reset only on one instance of the card */
        if (PCI_FUNC (pdev->devfn) != 0)