Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / net / e1000 / e1000_ethtool.c
index 1572d61..d1c705b 100644 (file)
@@ -1,7 +1,7 @@
 /*******************************************************************************
 
   
-  Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
+  Copyright(c) 1999 - 2005 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 
 
 #include <asm/uaccess.h>
 
-extern char e1000_driver_name[];
-extern char e1000_driver_version[];
-
-extern int e1000_up(struct e1000_adapter *adapter);
-extern void e1000_down(struct e1000_adapter *adapter);
-extern void e1000_reset(struct e1000_adapter *adapter);
-extern int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
-extern int e1000_setup_rx_resources(struct e1000_adapter *adapter);
-extern int e1000_setup_tx_resources(struct e1000_adapter *adapter);
-extern void e1000_free_rx_resources(struct e1000_adapter *adapter);
-extern void e1000_free_tx_resources(struct e1000_adapter *adapter);
-extern void e1000_update_stats(struct e1000_adapter *adapter);
-
 struct e1000_stats {
        char stat_string[ETH_GSTRING_LEN];
        int sizeof_stat;
@@ -53,14 +40,13 @@ struct e1000_stats {
 
 #define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
                      offsetof(struct e1000_adapter, m)
-static struct e1000_stats e1000_gstrings_stats[] = {
+static const struct e1000_stats e1000_gstrings_stats[] = {
        { "rx_packets", E1000_STAT(net_stats.rx_packets) },
        { "tx_packets", E1000_STAT(net_stats.tx_packets) },
        { "rx_bytes", E1000_STAT(net_stats.rx_bytes) },
        { "tx_bytes", E1000_STAT(net_stats.tx_bytes) },
        { "rx_errors", E1000_STAT(net_stats.rx_errors) },
        { "tx_errors", E1000_STAT(net_stats.tx_errors) },
-       { "rx_dropped", E1000_STAT(net_stats.rx_dropped) },
        { "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
        { "multicast", E1000_STAT(net_stats.multicast) },
        { "collisions", E1000_STAT(net_stats.collisions) },
@@ -68,7 +54,7 @@ static struct e1000_stats e1000_gstrings_stats[] = {
        { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
        { "rx_crc_errors", E1000_STAT(net_stats.rx_crc_errors) },
        { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
-       { "rx_fifo_errors", E1000_STAT(net_stats.rx_fifo_errors) },
+       { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
        { "rx_missed_errors", E1000_STAT(net_stats.rx_missed_errors) },
        { "tx_aborted_errors", E1000_STAT(net_stats.tx_aborted_errors) },
        { "tx_carrier_errors", E1000_STAT(net_stats.tx_carrier_errors) },
@@ -79,6 +65,7 @@ static struct e1000_stats e1000_gstrings_stats[] = {
        { "tx_deferred_ok", E1000_STAT(stats.dc) },
        { "tx_single_coll_ok", E1000_STAT(stats.scc) },
        { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
+       { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
        { "rx_long_length_errors", E1000_STAT(stats.roc) },
        { "rx_short_length_errors", E1000_STAT(stats.ruc) },
        { "rx_align_errors", E1000_STAT(stats.algnerrc) },
@@ -88,24 +75,31 @@ static struct e1000_stats e1000_gstrings_stats[] = {
        { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
        { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
        { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
+       { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
        { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
-       { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) }
+       { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
+       { "rx_header_split", E1000_STAT(rx_hdr_split) },
+       { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
 };
-#define E1000_STATS_LEN        \
+
+#define E1000_QUEUE_STATS_LEN 0
+#define E1000_GLOBAL_STATS_LEN \
        sizeof(e1000_gstrings_stats) / sizeof(struct e1000_stats)
-static char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
+#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
+static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
        "Register test  (offline)", "Eeprom test    (offline)",
        "Interrupt test (offline)", "Loopback test  (offline)",
        "Link test   (on/offline)"
 };
 #define E1000_TEST_LEN sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN
 
-static void
-e1000_ethtool_gset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd)
+static int
+e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
 {
+       struct e1000_adapter *adapter = netdev_priv(netdev);
        struct e1000_hw *hw = &adapter->hw;
 
-       if(hw->media_type == e1000_media_type_copper) {
+       if (hw->media_type == e1000_media_type_copper) {
 
                ecmd->supported = (SUPPORTED_10baseT_Half |
                                   SUPPORTED_10baseT_Full |
@@ -117,7 +111,7 @@ e1000_ethtool_gset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd)
 
                ecmd->advertising = ADVERTISED_TP;
 
-               if(hw->autoneg == 1) {
+               if (hw->autoneg == 1) {
                        ecmd->advertising |= ADVERTISED_Autoneg;
 
                        /* the e1000 autoneg seems to match ethtool nicely */
@@ -128,7 +122,7 @@ e1000_ethtool_gset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd)
                ecmd->port = PORT_TP;
                ecmd->phy_address = hw->phy_addr;
 
-               if(hw->mac_type == e1000_82543)
+               if (hw->mac_type == e1000_82543)
                        ecmd->transceiver = XCVR_EXTERNAL;
                else
                        ecmd->transceiver = XCVR_INTERNAL;
@@ -138,19 +132,19 @@ e1000_ethtool_gset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd)
                                     SUPPORTED_FIBRE |
                                     SUPPORTED_Autoneg);
 
-               ecmd->advertising = (SUPPORTED_1000baseT_Full |
-                                    SUPPORTED_FIBRE |
-                                    SUPPORTED_Autoneg);
+               ecmd->advertising = (ADVERTISED_1000baseT_Full |
+                                    ADVERTISED_FIBRE |
+                                    ADVERTISED_Autoneg);
 
                ecmd->port = PORT_FIBRE;
 
-               if(hw->mac_type >= e1000_82545)
+               if (hw->mac_type >= e1000_82545)
                        ecmd->transceiver = XCVR_INTERNAL;
                else
                        ecmd->transceiver = XCVR_EXTERNAL;
        }
 
-       if(netif_carrier_ok(adapter->netdev)) {
+       if (netif_carrier_ok(adapter->netdev)) {
 
                e1000_get_speed_and_duplex(hw, &adapter->link_speed,
                                                   &adapter->link_duplex);
@@ -159,7 +153,7 @@ e1000_ethtool_gset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd)
                /* unfortunatly FULL_DUPLEX != DUPLEX_FULL
                 *          and HALF_DUPLEX != DUPLEX_HALF */
 
-               if(adapter->link_duplex == FULL_DUPLEX)
+               if (adapter->link_duplex == FULL_DUPLEX)
                        ecmd->duplex = DUPLEX_FULL;
                else
                        ecmd->duplex = DUPLEX_HALF;
@@ -168,26 +162,49 @@ e1000_ethtool_gset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd)
                ecmd->duplex = -1;
        }
 
-       ecmd->autoneg = (hw->autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
+       ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
+                        hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
+       return 0;
 }
 
 static int
-e1000_ethtool_sset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd)
+e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
 {
+       struct e1000_adapter *adapter = netdev_priv(netdev);
        struct e1000_hw *hw = &adapter->hw;
 
-       if(ecmd->autoneg == AUTONEG_ENABLE) {
+       /* When SoL/IDER sessions are active, autoneg/speed/duplex
+        * cannot be changed */
+       if (e1000_check_phy_reset_block(hw)) {
+               DPRINTK(DRV, ERR, "Cannot change link characteristics "
+                       "when SoL/IDER is active.\n");
+               return -EINVAL;
+       }
+
+       if (ecmd->autoneg == AUTONEG_ENABLE) {
                hw->autoneg = 1;
-               hw->autoneg_advertised = 0x002F;
-               ecmd->advertising = 0x002F;
+               if (hw->media_type == e1000_media_type_fiber)
+                       hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
+                                    ADVERTISED_FIBRE |
+                                    ADVERTISED_Autoneg;
+               else
+                       hw->autoneg_advertised = ADVERTISED_10baseT_Half |
+                                                 ADVERTISED_10baseT_Full |
+                                                 ADVERTISED_100baseT_Half |
+                                                 ADVERTISED_100baseT_Full |
+                                                 ADVERTISED_1000baseT_Full|
+                                                 ADVERTISED_Autoneg |
+                                                 ADVERTISED_TP;
+               ecmd->advertising = hw->autoneg_advertised;
        } else
-               if(e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex))
+               if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex))
                        return -EINVAL;
 
        /* reset the link */
 
-       if(netif_running(adapter->netdev)) {
+       if (netif_running(adapter->netdev)) {
                e1000_down(adapter);
+               e1000_reset(adapter);
                e1000_up(adapter);
        } else
                e1000_reset(adapter);
@@ -195,81 +212,157 @@ e1000_ethtool_sset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd)
        return 0;
 }
 
-static int
-e1000_ethtool_gpause(struct e1000_adapter *adapter,
-                     struct ethtool_pauseparam *epause)
+static void
+e1000_get_pauseparam(struct net_device *netdev,
+                     struct ethtool_pauseparam *pause)
 {
+       struct e1000_adapter *adapter = netdev_priv(netdev);
        struct e1000_hw *hw = &adapter->hw;
-       
-       epause->autoneg = 
+
+       pause->autoneg =
                (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
-       
-       if(hw->fc == e1000_fc_rx_pause)
-               epause->rx_pause = 1;
-       else if(hw->fc == e1000_fc_tx_pause)
-               epause->tx_pause = 1;
-       else if(hw->fc == e1000_fc_full) {
-               epause->rx_pause = 1;
-               epause->tx_pause = 1;
+
+       if (hw->fc == e1000_fc_rx_pause)
+               pause->rx_pause = 1;
+       else if (hw->fc == e1000_fc_tx_pause)
+               pause->tx_pause = 1;
+       else if (hw->fc == e1000_fc_full) {
+               pause->rx_pause = 1;
+               pause->tx_pause = 1;
        }
-       
-       return 0;
 }
 
 static int
-e1000_ethtool_spause(struct e1000_adapter *adapter,
-                     struct ethtool_pauseparam *epause)
+e1000_set_pauseparam(struct net_device *netdev,
+                     struct ethtool_pauseparam *pause)
 {
+       struct e1000_adapter *adapter = netdev_priv(netdev);
        struct e1000_hw *hw = &adapter->hw;
-       
-       adapter->fc_autoneg = epause->autoneg;
 
-       if(epause->rx_pause && epause->tx_pause)
+       adapter->fc_autoneg = pause->autoneg;
+
+       if (pause->rx_pause && pause->tx_pause)
                hw->fc = e1000_fc_full;
-       else if(epause->rx_pause && !epause->tx_pause)
+       else if (pause->rx_pause && !pause->tx_pause)
                hw->fc = e1000_fc_rx_pause;
-       else if(!epause->rx_pause && epause->tx_pause)
+       else if (!pause->rx_pause && pause->tx_pause)
                hw->fc = e1000_fc_tx_pause;
-       else if(!epause->rx_pause && !epause->tx_pause)
+       else if (!pause->rx_pause && !pause->tx_pause)
                hw->fc = e1000_fc_none;
 
        hw->original_fc = hw->fc;
 
-       if(adapter->fc_autoneg == AUTONEG_ENABLE) {
-               if(netif_running(adapter->netdev)) {
+       if (adapter->fc_autoneg == AUTONEG_ENABLE) {
+               if (netif_running(adapter->netdev)) {
                        e1000_down(adapter);
                        e1000_up(adapter);
                } else
                        e1000_reset(adapter);
+       } else
+               return ((hw->media_type == e1000_media_type_fiber) ?
+                       e1000_setup_link(hw) : e1000_force_mac_fc(hw));
+
+       return 0;
+}
+
+static uint32_t
+e1000_get_rx_csum(struct net_device *netdev)
+{
+       struct e1000_adapter *adapter = netdev_priv(netdev);
+       return adapter->rx_csum;
+}
+
+static int
+e1000_set_rx_csum(struct net_device *netdev, uint32_t data)
+{
+       struct e1000_adapter *adapter = netdev_priv(netdev);
+       adapter->rx_csum = data;
+
+       if (netif_running(netdev)) {
+               e1000_down(adapter);
+               e1000_up(adapter);
+       } else
+               e1000_reset(adapter);
+       return 0;
+}
+
+static uint32_t
+e1000_get_tx_csum(struct net_device *netdev)
+{
+       return (netdev->features & NETIF_F_HW_CSUM) != 0;
+}
+
+static int
+e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
+{
+       struct e1000_adapter *adapter = netdev_priv(netdev);
+
+       if (adapter->hw.mac_type < e1000_82543) {
+               if (!data)
+                       return -EINVAL;
+               return 0;
        }
+
+       if (data)
+               netdev->features |= NETIF_F_HW_CSUM;
+       else
+               netdev->features &= ~NETIF_F_HW_CSUM;
+
+       return 0;
+}
+
+#ifdef NETIF_F_TSO
+static int
+e1000_set_tso(struct net_device *netdev, uint32_t data)
+{
+       struct e1000_adapter *adapter = netdev_priv(netdev);
+       if ((adapter->hw.mac_type < e1000_82544) ||
+           (adapter->hw.mac_type == e1000_82547))
+               return data ? -EINVAL : 0;
+
+       if (data)
+               netdev->features |= NETIF_F_TSO;
        else
-               return e1000_force_mac_fc(hw);
-       
+               netdev->features &= ~NETIF_F_TSO;
+
+       DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
+       adapter->tso_force = TRUE;
        return 0;
 }
+#endif /* NETIF_F_TSO */
+
+static uint32_t
+e1000_get_msglevel(struct net_device *netdev)
+{
+       struct e1000_adapter *adapter = netdev_priv(netdev);
+       return adapter->msg_enable;
+}
 
 static void
-e1000_ethtool_gdrvinfo(struct e1000_adapter *adapter,
-                       struct ethtool_drvinfo *drvinfo)
+e1000_set_msglevel(struct net_device *netdev, uint32_t data)
+{
+       struct e1000_adapter *adapter = netdev_priv(netdev);
+       adapter->msg_enable = data;
+}
+
+static int
+e1000_get_regs_len(struct net_device *netdev)
 {
-       strncpy(drvinfo->driver,  e1000_driver_name, 32);
-       strncpy(drvinfo->version, e1000_driver_version, 32);
-       strncpy(drvinfo->fw_version, "N/A", 32);
-       strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
-       drvinfo->n_stats = E1000_STATS_LEN;
-       drvinfo->testinfo_len = E1000_TEST_LEN;
 #define E1000_REGS_LEN 32
-       drvinfo->regdump_len  = E1000_REGS_LEN * sizeof(uint32_t);
-       drvinfo->eedump_len = adapter->hw.eeprom.word_size * 2;
+       return E1000_REGS_LEN * sizeof(uint32_t);
 }
 
 static void
-e1000_ethtool_gregs(struct e1000_adapter *adapter,
-                    struct ethtool_regs *regs, uint32_t *regs_buff)
+e1000_get_regs(struct net_device *netdev,
+              struct ethtool_regs *regs, void *p)
 {
+       struct e1000_adapter *adapter = netdev_priv(netdev);
        struct e1000_hw *hw = &adapter->hw;
+       uint32_t *regs_buff = p;
        uint16_t phy_data;
 
+       memset(p, 0, E1000_REGS_LEN * sizeof(uint32_t));
+
        regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
 
        regs_buff[0]  = E1000_READ_REG(hw, CTRL);
@@ -288,7 +381,7 @@ e1000_ethtool_gregs(struct e1000_adapter *adapter,
        regs_buff[11] = E1000_READ_REG(hw, TIDV);
 
        regs_buff[12] = adapter->hw.phy_type;  /* PHY type (IGP=1, M88=0) */
-       if(hw->phy_type == e1000_phy_igp) {
+       if (hw->phy_type == e1000_phy_igp) {
                e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
                                    IGP01E1000_PHY_AGC_A);
                e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
@@ -342,44 +435,50 @@ e1000_ethtool_gregs(struct e1000_adapter *adapter,
        e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
        regs_buff[24] = (uint32_t)phy_data;  /* phy local receiver status */
        regs_buff[25] = regs_buff[24];  /* phy remote receiver status */
+       if (hw->mac_type >= e1000_82540 &&
+          hw->media_type == e1000_media_type_copper) {
+               regs_buff[26] = E1000_READ_REG(hw, MANC);
+       }
+}
 
-       return;
+static int
+e1000_get_eeprom_len(struct net_device *netdev)
+{
+       struct e1000_adapter *adapter = netdev_priv(netdev);
+       return adapter->hw.eeprom.word_size * 2;
 }
 
 static int
-e1000_ethtool_geeprom(struct e1000_adapter *adapter,
-                      struct ethtool_eeprom *eeprom, uint16_t *eeprom_buff)
+e1000_get_eeprom(struct net_device *netdev,
+                      struct ethtool_eeprom *eeprom, uint8_t *bytes)
 {
+       struct e1000_adapter *adapter = netdev_priv(netdev);
        struct e1000_hw *hw = &adapter->hw;
+       uint16_t *eeprom_buff;
        int first_word, last_word;
        int ret_val = 0;
        uint16_t i;
 
-       if(eeprom->len == 0) {
-               ret_val = -EINVAL;
-               goto geeprom_error;
-       }
+       if (eeprom->len == 0)
+               return -EINVAL;
 
        eeprom->magic = hw->vendor_id | (hw->device_id << 16);
 
-       if(eeprom->offset > eeprom->offset + eeprom->len) {
-               ret_val = -EINVAL;
-               goto geeprom_error;
-       }
-
-       if((eeprom->offset + eeprom->len) > (hw->eeprom.word_size * 2))
-               eeprom->len = ((hw->eeprom.word_size * 2) - eeprom->offset);
-
        first_word = eeprom->offset >> 1;
        last_word = (eeprom->offset + eeprom->len - 1) >> 1;
 
-       if(hw->eeprom.type == e1000_eeprom_spi)
+       eeprom_buff = kmalloc(sizeof(uint16_t) *
+                       (last_word - first_word + 1), GFP_KERNEL);
+       if (!eeprom_buff)
+               return -ENOMEM;
+
+       if (hw->eeprom.type == e1000_eeprom_spi)
                ret_val = e1000_read_eeprom(hw, first_word,
                                            last_word - first_word + 1,
                                            eeprom_buff);
        else {
                for (i = 0; i < last_word - first_word + 1; i++)
-                       if((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
+                       if ((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
                                                        &eeprom_buff[i])))
                                break;
        }
@@ -388,47 +487,48 @@ e1000_ethtool_geeprom(struct e1000_adapter *adapter,
        for (i = 0; i < last_word - first_word + 1; i++)
                le16_to_cpus(&eeprom_buff[i]);
 
-geeprom_error:
+       memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset & 1),
+                       eeprom->len);
+       kfree(eeprom_buff);
+
        return ret_val;
 }
 
 static int
-e1000_ethtool_seeprom(struct e1000_adapter *adapter,
-                      struct ethtool_eeprom *eeprom, void *user_data)
+e1000_set_eeprom(struct net_device *netdev,
+                      struct ethtool_eeprom *eeprom, uint8_t *bytes)
 {
+       struct e1000_adapter *adapter = netdev_priv(netdev);
        struct e1000_hw *hw = &adapter->hw;
        uint16_t *eeprom_buff;
        void *ptr;
        int max_len, first_word, last_word, ret_val = 0;
        uint16_t i;
 
-       if(eeprom->len == 0)
+       if (eeprom->len == 0)
                return -EOPNOTSUPP;
 
-       if(eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
+       if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
                return -EFAULT;
 
        max_len = hw->eeprom.word_size * 2;
 
-       if((eeprom->offset + eeprom->len) > max_len)
-               eeprom->len = (max_len - eeprom->offset);
-
        first_word = eeprom->offset >> 1;
        last_word = (eeprom->offset + eeprom->len - 1) >> 1;
        eeprom_buff = kmalloc(max_len, GFP_KERNEL);
-       if(!eeprom_buff)
+       if (!eeprom_buff)
                return -ENOMEM;
 
        ptr = (void *)eeprom_buff;
 
-       if(eeprom->offset & 1) {
+       if (eeprom->offset & 1) {
                /* need read/modify/write of first changed EEPROM word */
                /* only the second byte of the word is being modified */
                ret_val = e1000_read_eeprom(hw, first_word, 1,
                                            &eeprom_buff[0]);
                ptr++;
        }
-       if(((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
+       if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
                /* need read/modify/write of last changed EEPROM word */
                /* only the first byte of the word is being modified */
                ret_val = e1000_read_eeprom(hw, last_word, 1,
@@ -439,10 +539,7 @@ e1000_ethtool_seeprom(struct e1000_adapter *adapter,
        for (i = 0; i < last_word - first_word + 1; i++)
                le16_to_cpus(&eeprom_buff[i]);
 
-       if((ret_val != 0) || copy_from_user(ptr, user_data, eeprom->len)) {
-               ret_val = -EFAULT;
-               goto seeprom_error;
-       }
+       memcpy(ptr, bytes, eeprom->len);
 
        for (i = 0; i < last_word - first_word + 1; i++)
                eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
@@ -450,22 +547,60 @@ e1000_ethtool_seeprom(struct e1000_adapter *adapter,
        ret_val = e1000_write_eeprom(hw, first_word,
                                     last_word - first_word + 1, eeprom_buff);
 
-       /* Update the checksum over the first part of the EEPROM if needed */
-       if((ret_val == 0) && first_word <= EEPROM_CHECKSUM_REG)
+       /* Update the checksum over the first part of the EEPROM if needed
+        * and flush shadow RAM for 82573 conrollers */
+       if ((ret_val == 0) && ((first_word <= EEPROM_CHECKSUM_REG) ||
+                               (hw->mac_type == e1000_82573)))
                e1000_update_eeprom_checksum(hw);
 
-seeprom_error:
        kfree(eeprom_buff);
        return ret_val;
 }
 
-static int
-e1000_ethtool_gring(struct e1000_adapter *adapter,
+static void
+e1000_get_drvinfo(struct net_device *netdev,
+                       struct ethtool_drvinfo *drvinfo)
+{
+       struct e1000_adapter *adapter = netdev_priv(netdev);
+       char firmware_version[32];
+       uint16_t eeprom_data;
+
+       strncpy(drvinfo->driver,  e1000_driver_name, 32);
+       strncpy(drvinfo->version, e1000_driver_version, 32);
+
+       /* EEPROM image version # is reported as firmware version # for
+        * 8257{1|2|3} controllers */
+       e1000_read_eeprom(&adapter->hw, 5, 1, &eeprom_data);
+       switch (adapter->hw.mac_type) {
+       case e1000_82571:
+       case e1000_82572:
+       case e1000_82573:
+       case e1000_80003es2lan:
+               sprintf(firmware_version, "%d.%d-%d",
+                       (eeprom_data & 0xF000) >> 12,
+                       (eeprom_data & 0x0FF0) >> 4,
+                       eeprom_data & 0x000F);
+               break;
+       default:
+               sprintf(firmware_version, "N/A");
+       }
+
+       strncpy(drvinfo->fw_version, firmware_version, 32);
+       strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
+       drvinfo->n_stats = E1000_STATS_LEN;
+       drvinfo->testinfo_len = E1000_TEST_LEN;
+       drvinfo->regdump_len = e1000_get_regs_len(netdev);
+       drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
+}
+
+static void
+e1000_get_ringparam(struct net_device *netdev,
                     struct ethtool_ringparam *ring)
 {
+       struct e1000_adapter *adapter = netdev_priv(netdev);
        e1000_mac_type mac_type = adapter->hw.mac_type;
-       struct e1000_desc_ring *txdr = &adapter->tx_ring;
-       struct e1000_desc_ring *rxdr = &adapter->rx_ring;
+       struct e1000_tx_ring *txdr = adapter->tx_ring;
+       struct e1000_rx_ring *rxdr = adapter->rx_ring;
 
        ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
                E1000_MAX_82544_RXD;
@@ -477,60 +612,90 @@ e1000_ethtool_gring(struct e1000_adapter *adapter,
        ring->tx_pending = txdr->count;
        ring->rx_mini_pending = 0;
        ring->rx_jumbo_pending = 0;
-
-       return 0;
 }
-static int 
-e1000_ethtool_sring(struct e1000_adapter *adapter,
+
+static int
+e1000_set_ringparam(struct net_device *netdev,
                     struct ethtool_ringparam *ring)
 {
-       int err;
+       struct e1000_adapter *adapter = netdev_priv(netdev);
        e1000_mac_type mac_type = adapter->hw.mac_type;
-       struct e1000_desc_ring *txdr = &adapter->tx_ring;
-       struct e1000_desc_ring *rxdr = &adapter->rx_ring;
-       struct e1000_desc_ring tx_old, tx_new;
-       struct e1000_desc_ring rx_old, rx_new;
+       struct e1000_tx_ring *txdr, *tx_old, *tx_new;
+       struct e1000_rx_ring *rxdr, *rx_old, *rx_new;
+       int i, err, tx_ring_size, rx_ring_size;
+
+       if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
+               return -EINVAL;
+
+       tx_ring_size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
+       rx_ring_size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
+
+       if (netif_running(adapter->netdev))
+               e1000_down(adapter);
 
        tx_old = adapter->tx_ring;
        rx_old = adapter->rx_ring;
-       
-       if(netif_running(adapter->netdev))
-               e1000_down(adapter);
+
+       adapter->tx_ring = kmalloc(tx_ring_size, GFP_KERNEL);
+       if (!adapter->tx_ring) {
+               err = -ENOMEM;
+               goto err_setup_rx;
+       }
+       memset(adapter->tx_ring, 0, tx_ring_size);
+
+       adapter->rx_ring = kmalloc(rx_ring_size, GFP_KERNEL);
+       if (!adapter->rx_ring) {
+               kfree(adapter->tx_ring);
+               err = -ENOMEM;
+               goto err_setup_rx;
+       }
+       memset(adapter->rx_ring, 0, rx_ring_size);
+
+       txdr = adapter->tx_ring;
+       rxdr = adapter->rx_ring;
 
        rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD);
        rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ?
                E1000_MAX_RXD : E1000_MAX_82544_RXD));
-       E1000_ROUNDUP(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE); 
+       E1000_ROUNDUP(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
 
        txdr->count = max(ring->tx_pending,(uint32_t)E1000_MIN_TXD);
        txdr->count = min(txdr->count,(uint32_t)(mac_type < e1000_82544 ?
                E1000_MAX_TXD : E1000_MAX_82544_TXD));
-       E1000_ROUNDUP(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE); 
+       E1000_ROUNDUP(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
+
+       for (i = 0; i < adapter->num_tx_queues; i++)
+               txdr[i].count = txdr->count;
+       for (i = 0; i < adapter->num_rx_queues; i++)
+               rxdr[i].count = rxdr->count;
 
-       if(netif_running(adapter->netdev)) {
-               /* try to get new resources before deleting old */
-               if((err = e1000_setup_rx_resources(adapter)))
+       if (netif_running(adapter->netdev)) {
+               /* Try to get new resources before deleting old */
+               if ((err = e1000_setup_all_rx_resources(adapter)))
                        goto err_setup_rx;
-               if((err = e1000_setup_tx_resources(adapter)))
+               if ((err = e1000_setup_all_tx_resources(adapter)))
                        goto err_setup_tx;
 
                /* save the new, restore the old in order to free it,
-                * then restore the new back again */   
-       
+                * then restore the new back again */
+
                rx_new = adapter->rx_ring;
                tx_new = adapter->tx_ring;
                adapter->rx_ring = rx_old;
                adapter->tx_ring = tx_old;
-               e1000_free_rx_resources(adapter);
-               e1000_free_tx_resources(adapter);
+               e1000_free_all_rx_resources(adapter);
+               e1000_free_all_tx_resources(adapter);
+               kfree(tx_old);
+               kfree(rx_old);
                adapter->rx_ring = rx_new;
                adapter->tx_ring = tx_new;
-               if((err = e1000_up(adapter)))
+               if ((err = e1000_up(adapter)))
                        return err;
        }
+
        return 0;
 err_setup_tx:
-       e1000_free_rx_resources(adapter);
+       e1000_free_all_rx_resources(adapter);
 err_setup_rx:
        adapter->rx_ring = rx_old;
        adapter->tx_ring = tx_old;
@@ -543,10 +708,13 @@ err_setup_rx:
        uint32_t pat, value;                                                   \
        uint32_t test[] =                                                      \
                {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};              \
-       for(pat = 0; pat < sizeof(test)/sizeof(test[0]); pat++) {              \
+       for (pat = 0; pat < sizeof(test)/sizeof(test[0]); pat++) {              \
                E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W));             \
                value = E1000_READ_REG(&adapter->hw, R);                       \
-               if(value != (test[pat] & W & M)) {                             \
+               if (value != (test[pat] & W & M)) {                             \
+                       DPRINTK(DRV, ERR, "pattern test reg %04X failed: got " \
+                               "0x%08X expected 0x%08X\n",                    \
+                               E1000_##R, value, (test[pat] & W & M));        \
                        *data = (adapter->hw.mac_type < e1000_82543) ?         \
                                E1000_82542_##R : E1000_##R;                   \
                        return 1;                                              \
@@ -560,6 +728,8 @@ err_setup_rx:
        E1000_WRITE_REG(&adapter->hw, R, W & M);                               \
        value = E1000_READ_REG(&adapter->hw, R);                               \
        if ((W & M) != (value & M)) {                                          \
+               DPRINTK(DRV, ERR, "set/check reg %04X test failed: got 0x%08X "\
+                       "expected 0x%08X\n", E1000_##R, (value & M), (W & M)); \
                *data = (adapter->hw.mac_type < e1000_82543) ?                 \
                        E1000_82542_##R : E1000_##R;                           \
                return 1;                                                      \
@@ -569,18 +739,39 @@ err_setup_rx:
 static int
 e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
 {
-       uint32_t value;
-       uint32_t i;
+       uint32_t value, before, after;
+       uint32_t i, toggle;
 
        /* The status register is Read Only, so a write should fail.
         * Some bits that get toggled are ignored.
         */
-       value = (E1000_READ_REG(&adapter->hw, STATUS) & (0xFFFFF833));
-       E1000_WRITE_REG(&adapter->hw, STATUS, (0xFFFFFFFF));
-       if(value != (E1000_READ_REG(&adapter->hw, STATUS) & (0xFFFFF833))) {
+        switch (adapter->hw.mac_type) {
+       /* there are several bits on newer hardware that are r/w */
+       case e1000_82571:
+       case e1000_82572:
+       case e1000_80003es2lan:
+               toggle = 0x7FFFF3FF;
+               break;
+       case e1000_82573:
+               toggle = 0x7FFFF033;
+               break;
+       default:
+               toggle = 0xFFFFF833;
+               break;
+       }
+
+       before = E1000_READ_REG(&adapter->hw, STATUS);
+       value = (E1000_READ_REG(&adapter->hw, STATUS) & toggle);
+       E1000_WRITE_REG(&adapter->hw, STATUS, toggle);
+       after = E1000_READ_REG(&adapter->hw, STATUS) & toggle;
+       if (value != after) {
+               DPRINTK(DRV, ERR, "failed STATUS register test got: "
+                       "0x%08X expected: 0x%08X\n", after, value);
                *data = 1;
                return 1;
        }
+       /* restore previous status */
+       E1000_WRITE_REG(&adapter->hw, STATUS, before);
 
        REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
        REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
@@ -601,7 +792,7 @@ e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
        REG_SET_AND_CHECK(RCTL, 0x06DFB3FE, 0x003FFFFB);
        REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
 
-       if(adapter->hw.mac_type >= e1000_82543) {
+       if (adapter->hw.mac_type >= e1000_82543) {
 
                REG_SET_AND_CHECK(RCTL, 0x06DFB3FE, 0xFFFFFFFF);
                REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
@@ -609,7 +800,7 @@ e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
                REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
                REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
 
-               for(i = 0; i < E1000_RAR_ENTRIES; i++) {
+               for (i = 0; i < E1000_RAR_ENTRIES; i++) {
                        REG_PATTERN_TEST(RA + ((i << 1) << 2), 0xFFFFFFFF,
                                         0xFFFFFFFF);
                        REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
@@ -625,9 +816,10 @@ e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
 
        }
 
-       for(i = 0; i < E1000_MC_TBL_SIZE; i++)
+       for (i = 0; i < E1000_MC_TBL_SIZE; i++)
                REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
 
+       *data = 0;
        return 0;
 }
 
@@ -640,8 +832,8 @@ e1000_eeprom_test(struct e1000_adapter *adapter, uint64_t *data)
 
        *data = 0;
        /* Read and add up the contents of the EEPROM */
-       for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
-               if((e1000_read_eeprom(&adapter->hw, i, 1, &temp)) < 0) {
+       for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
+               if ((e1000_read_eeprom(&adapter->hw, i, 1, &temp)) < 0) {
                        *data = 1;
                        break;
                }
@@ -649,7 +841,7 @@ e1000_eeprom_test(struct e1000_adapter *adapter, uint64_t *data)
        }
 
        /* If Checksum is not Correct return error else test passed */
-       if((checksum != (uint16_t) EEPROM_SUM) && !(*data))
+       if ((checksum != (uint16_t) EEPROM_SUM) && !(*data))
                *data = 2;
 
        return *data;
@@ -661,7 +853,7 @@ e1000_test_intr(int irq,
                struct pt_regs *regs)
 {
        struct net_device *netdev = (struct net_device *) data;
-       struct e1000_adapter *adapter = netdev->priv;
+       struct e1000_adapter *adapter = netdev_priv(netdev);
 
        adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR);
 
@@ -672,56 +864,49 @@ static int
 e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
 {
        struct net_device *netdev = adapter->netdev;
-       uint32_t icr, mask, i=0;
+       uint32_t mask, i=0, shared_int = TRUE;
+       uint32_t irq = adapter->pdev->irq;
 
        *data = 0;
 
        /* Hook up test interrupt handler just for this test */
-       if(request_irq(adapter->pdev->irq, &e1000_test_intr, SA_SHIRQ,
-          netdev->name, netdev)) {
+       if (!request_irq(irq, &e1000_test_intr, SA_PROBEIRQ, netdev->name,
+                        netdev)) {
+               shared_int = FALSE;
+       } else if (request_irq(irq, &e1000_test_intr, SA_SHIRQ,
+                             netdev->name, netdev)){
                *data = 1;
                return -1;
        }
+       DPRINTK(PROBE,INFO, "testing %s interrupt\n",
+               (shared_int ? "shared" : "unshared"));
 
        /* Disable all the interrupts */
        E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
        msec_delay(10);
 
-       /* Interrupts are disabled, so read interrupt cause
-        * register (icr) twice to verify that there are no interrupts
-        * pending.  icr is clear on read.
-        */
-       icr = E1000_READ_REG(&adapter->hw, ICR);
-       icr = E1000_READ_REG(&adapter->hw, ICR);
-
-       if(icr != 0) {
-               /* if icr is non-zero, there is no point
-                * running other interrupt tests.
-                */
-               *data = 2;
-               i = 10;
-       }
-
        /* Test each interrupt */
-       for(; i < 10; i++) {
+       for (; i < 10; i++) {
 
                /* Interrupt to test */
                mask = 1 << i;
 
-               /* Disable the interrupt to be reported in
-                * the cause register and then force the same
-                * interrupt and see if one gets posted.  If
-                * an interrupt was posted to the bus, the
-                * test failed.
-                */
-               adapter->test_icr = 0;
-               E1000_WRITE_REG(&adapter->hw, IMC, mask);
-               E1000_WRITE_REG(&adapter->hw, ICS, mask);
-               msec_delay(10);
-
-               if(adapter->test_icr & mask) {
-                       *data = 3;
-                       break;
+               if (!shared_int) {
+                       /* Disable the interrupt to be reported in
+                        * the cause register and then force the same
+                        * interrupt and see if one gets posted.  If
+                        * an interrupt was posted to the bus, the
+                        * test failed.
+                        */
+                       adapter->test_icr = 0;
+                       E1000_WRITE_REG(&adapter->hw, IMC, mask);
+                       E1000_WRITE_REG(&adapter->hw, ICS, mask);
+                       msec_delay(10);
+
+                       if (adapter->test_icr & mask) {
+                               *data = 3;
+                               break;
+                       }
                }
 
                /* Enable the interrupt to be reported in
@@ -735,25 +920,27 @@ e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
                E1000_WRITE_REG(&adapter->hw, ICS, mask);
                msec_delay(10);
 
-               if(!(adapter->test_icr & mask)) {
+               if (!(adapter->test_icr & mask)) {
                        *data = 4;
                        break;
                }
 
-               /* Disable the other interrupts to be reported in
-                * the cause register and then force the other
-                * interrupts and see if any get posted.  If
-                * an interrupt was posted to the bus, the
-                * test failed.
-                */
-               adapter->test_icr = 0;
-               E1000_WRITE_REG(&adapter->hw, IMC, ~mask);
-               E1000_WRITE_REG(&adapter->hw, ICS, ~mask);
-               msec_delay(10);
+               if (!shared_int) {
+                       /* Disable the other interrupts to be reported in
+                        * the cause register and then force the other
+                        * interrupts and see if any get posted.  If
+                        * an interrupt was posted to the bus, the
+                        * test failed.
+                        */
+                       adapter->test_icr = 0;
+                       E1000_WRITE_REG(&adapter->hw, IMC, ~mask & 0x00007FFF);
+                       E1000_WRITE_REG(&adapter->hw, ICS, ~mask & 0x00007FFF);
+                       msec_delay(10);
 
-               if(adapter->test_icr) {
-                       *data = 5;
-                       break;
+                       if (adapter->test_icr) {
+                               *data = 5;
+                               break;
+                       }
                }
        }
 
@@ -762,7 +949,7 @@ e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
        msec_delay(10);
 
        /* Unhook test interrupt handler */
-       free_irq(adapter->pdev->irq, netdev);
+       free_irq(irq, netdev);
 
        return *data;
 }
@@ -770,42 +957,46 @@ e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
 static void
 e1000_free_desc_rings(struct e1000_adapter *adapter)
 {
-       struct e1000_desc_ring *txdr = &adapter->test_tx_ring;
-       struct e1000_desc_ring *rxdr = &adapter->test_rx_ring;
+       struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
+       struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
        struct pci_dev *pdev = adapter->pdev;
        int i;
 
-       if(txdr->desc && txdr->buffer_info) {
-               for(i = 0; i < txdr->count; i++) {
-                       if(txdr->buffer_info[i].dma)
+       if (txdr->desc && txdr->buffer_info) {
+               for (i = 0; i < txdr->count; i++) {
+                       if (txdr->buffer_info[i].dma)
                                pci_unmap_single(pdev, txdr->buffer_info[i].dma,
                                                 txdr->buffer_info[i].length,
                                                 PCI_DMA_TODEVICE);
-                       if(txdr->buffer_info[i].skb)
+                       if (txdr->buffer_info[i].skb)
                                dev_kfree_skb(txdr->buffer_info[i].skb);
                }
        }
 
-       if(rxdr->desc && rxdr->buffer_info) {
-               for(i = 0; i < rxdr->count; i++) {
-                       if(rxdr->buffer_info[i].dma)
+       if (rxdr->desc && rxdr->buffer_info) {
+               for (i = 0; i < rxdr->count; i++) {
+                       if (rxdr->buffer_info[i].dma)
                                pci_unmap_single(pdev, rxdr->buffer_info[i].dma,
                                                 rxdr->buffer_info[i].length,
                                                 PCI_DMA_FROMDEVICE);
-                       if(rxdr->buffer_info[i].skb)
+                       if (rxdr->buffer_info[i].skb)
                                dev_kfree_skb(rxdr->buffer_info[i].skb);
                }
        }
 
-       if(txdr->desc)
+       if (txdr->desc) {
                pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
-       if(rxdr->desc)
+               txdr->desc = NULL;
+       }
+       if (rxdr->desc) {
                pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
+               rxdr->desc = NULL;
+       }
 
-       if(txdr->buffer_info)
-               kfree(txdr->buffer_info);
-       if(rxdr->buffer_info)
-               kfree(rxdr->buffer_info);
+       kfree(txdr->buffer_info);
+       txdr->buffer_info = NULL;
+       kfree(rxdr->buffer_info);
+       rxdr->buffer_info = NULL;
 
        return;
 }
@@ -813,18 +1004,19 @@ e1000_free_desc_rings(struct e1000_adapter *adapter)
 static int
 e1000_setup_desc_rings(struct e1000_adapter *adapter)
 {
-       struct e1000_desc_ring *txdr = &adapter->test_tx_ring;
-       struct e1000_desc_ring *rxdr = &adapter->test_rx_ring;
+       struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
+       struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
        struct pci_dev *pdev = adapter->pdev;
        uint32_t rctl;
        int size, i, ret_val;
 
        /* Setup Tx descriptor ring and Tx buffers */
 
-       txdr->count = 80;
+       if (!txdr->count)
+               txdr->count = E1000_DEFAULT_TXD;
 
        size = txdr->count * sizeof(struct e1000_buffer);
-       if(!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
+       if (!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
                ret_val = 1;
                goto err_nomem;
        }
@@ -832,7 +1024,7 @@ e1000_setup_desc_rings(struct e1000_adapter *adapter)
 
        txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
        E1000_ROUNDUP(txdr->size, 4096);
-       if(!(txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma))) {
+       if (!(txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma))) {
                ret_val = 2;
                goto err_nomem;
        }
@@ -851,12 +1043,12 @@ e1000_setup_desc_rings(struct e1000_adapter *adapter)
                        E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
                        E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
 
-       for(i = 0; i < txdr->count; i++) {
+       for (i = 0; i < txdr->count; i++) {
                struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
                struct sk_buff *skb;
                unsigned int size = 1024;
 
-               if(!(skb = alloc_skb(size, GFP_KERNEL))) {
+               if (!(skb = alloc_skb(size, GFP_KERNEL))) {
                        ret_val = 3;
                        goto err_nomem;
                }
@@ -876,17 +1068,18 @@ e1000_setup_desc_rings(struct e1000_adapter *adapter)
 
        /* Setup Rx descriptor ring and Rx buffers */
 
-       rxdr->count = 80;
+       if (!rxdr->count)
+               rxdr->count = E1000_DEFAULT_RXD;
 
        size = rxdr->count * sizeof(struct e1000_buffer);
-       if(!(rxdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
+       if (!(rxdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
                ret_val = 4;
                goto err_nomem;
        }
        memset(rxdr->buffer_info, 0, size);
 
        rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
-       if(!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) {
+       if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) {
                ret_val = 5;
                goto err_nomem;
        }
@@ -906,15 +1099,16 @@ e1000_setup_desc_rings(struct e1000_adapter *adapter)
                (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
        E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
 
-       for(i = 0; i < rxdr->count; i++) {
+       for (i = 0; i < rxdr->count; i++) {
                struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
                struct sk_buff *skb;
 
-               if(!(skb = alloc_skb(E1000_RXBUFFER_2048 + 2, GFP_KERNEL))) {
+               if (!(skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN,
+                               GFP_KERNEL))) {
                        ret_val = 6;
                        goto err_nomem;
                }
-               skb_reserve(skb, 2);
+               skb_reserve(skb, NET_IP_ALIGN);
                rxdr->buffer_info[i].skb = skb;
                rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
                rxdr->buffer_info[i].dma =
@@ -926,7 +1120,7 @@ e1000_setup_desc_rings(struct e1000_adapter *adapter)
 
        return 0;
 
-      err_nomem:
+err_nomem:
        e1000_free_desc_rings(adapter);
        return ret_val;
 }
@@ -939,8 +1133,6 @@ e1000_phy_disable_receiver(struct e1000_adapter *adapter)
        e1000_write_phy_reg(&adapter->hw, 30, 0x8FFC);
        e1000_write_phy_reg(&adapter->hw, 29, 0x001A);
        e1000_write_phy_reg(&adapter->hw, 30, 0x8FF0);
-
-       return;
 }
 
 static void
@@ -1020,15 +1212,15 @@ e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
 
        /* Check Phy Configuration */
        e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
-       if(phy_reg != 0x4100)
+       if (phy_reg != 0x4100)
                 return 9;
 
        e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
-       if(phy_reg != 0x0070)
+       if (phy_reg != 0x0070)
                return 10;
 
        e1000_read_phy_reg(&adapter->hw, 29, &phy_reg);
-       if(phy_reg != 0x001A)
+       if (phy_reg != 0x001A)
                return 11;
 
        return 0;
@@ -1042,7 +1234,7 @@ e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
 
        adapter->hw.autoneg = FALSE;
 
-       if(adapter->hw.phy_type == e1000_phy_m88) {
+       if (adapter->hw.phy_type == e1000_phy_m88) {
                /* Auto-MDI/MDIX Off */
                e1000_write_phy_reg(&adapter->hw,
                                    M88E1000_PHY_SPEC_CTRL, 0x0808);
@@ -1050,6 +1242,10 @@ e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
                e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x9140);
                /* autoneg off */
                e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8140);
+       } else if (adapter->hw.phy_type == e1000_phy_gg82563) {
+               e1000_write_phy_reg(&adapter->hw,
+                                   GG82563_PHY_KMRN_MODE_CTRL,
+                                   0x1CE);
        }
        /* force 1000, set loopback */
        e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x4140);
@@ -1062,14 +1258,14 @@ e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
                     E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
                     E1000_CTRL_FD);     /* Force Duplex to FULL */
 
-       if(adapter->hw.media_type == e1000_media_type_copper &&
+       if (adapter->hw.media_type == e1000_media_type_copper &&
           adapter->hw.phy_type == e1000_phy_m88) {
                ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
        } else {
                /* Set the ILOS bit on the fiber Nic is half
                 * duplex link is detected. */
                stat_reg = E1000_READ_REG(&adapter->hw, STATUS);
-               if((stat_reg & E1000_STATUS_FD) == 0)
+               if ((stat_reg & E1000_STATUS_FD) == 0)
                        ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
        }
 
@@ -1078,7 +1274,7 @@ e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
        /* Disable the receiver on the PHY so when a cable is plugged in, the
         * PHY does not begin to autoneg when a cable is reconnected to the NIC.
         */
-       if(adapter->hw.phy_type == e1000_phy_m88)
+       if (adapter->hw.phy_type == e1000_phy_m88)
                e1000_phy_disable_receiver(adapter);
 
        udelay(500);
@@ -1094,14 +1290,14 @@ e1000_set_phy_loopback(struct e1000_adapter *adapter)
 
        switch (adapter->hw.mac_type) {
        case e1000_82543:
-               if(adapter->hw.media_type == e1000_media_type_copper) {
+               if (adapter->hw.media_type == e1000_media_type_copper) {
                        /* Attempt to setup Loopback mode on Non-integrated PHY.
                         * Some PHY registers get corrupted at random, so
                         * attempt this 10 times.
                         */
-                       while(e1000_nonintegrated_phy_loopback(adapter) &&
+                       while (e1000_nonintegrated_phy_loopback(adapter) &&
                              count++ < 10);
-                       if(count < 11)
+                       if (count < 11)
                                return 0;
                }
                break;
@@ -1116,6 +1312,10 @@ e1000_set_phy_loopback(struct e1000_adapter *adapter)
        case e1000_82541_rev_2:
        case e1000_82547:
        case e1000_82547_rev_2:
+       case e1000_82571:
+       case e1000_82572:
+       case e1000_82573:
+       case e1000_80003es2lan:
                return e1000_integrated_phy_loopback(adapter);
                break;
 
@@ -1136,22 +1336,33 @@ e1000_set_phy_loopback(struct e1000_adapter *adapter)
 static int
 e1000_setup_loopback_test(struct e1000_adapter *adapter)
 {
+       struct e1000_hw *hw = &adapter->hw;
        uint32_t rctl;
 
-       if(adapter->hw.media_type == e1000_media_type_fiber ||
-          adapter->hw.media_type == e1000_media_type_internal_serdes) {
-               if(adapter->hw.mac_type == e1000_82545 ||
-                  adapter->hw.mac_type == e1000_82546 ||
-                  adapter->hw.mac_type == e1000_82545_rev_3 ||
-                  adapter->hw.mac_type == e1000_82546_rev_3)
+       if (hw->media_type == e1000_media_type_fiber ||
+           hw->media_type == e1000_media_type_internal_serdes) {
+               switch (hw->mac_type) {
+               case e1000_82545:
+               case e1000_82546:
+               case e1000_82545_rev_3:
+               case e1000_82546_rev_3:
                        return e1000_set_phy_loopback(adapter);
-               else {
-                       rctl = E1000_READ_REG(&adapter->hw, RCTL);
+                       break;
+               case e1000_82571:
+               case e1000_82572:
+#define E1000_SERDES_LB_ON 0x410
+                       e1000_set_phy_loopback(adapter);
+                       E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_ON);
+                       msec_delay(10);
+                       return 0;
+                       break;
+               default:
+                       rctl = E1000_READ_REG(hw, RCTL);
                        rctl |= E1000_RCTL_LBM_TCVR;
-                       E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
+                       E1000_WRITE_REG(hw, RCTL, rctl);
                        return 0;
                }
-       } else if(adapter->hw.media_type == e1000_media_type_copper)
+       } else if (hw->media_type == e1000_media_type_copper)
                return e1000_set_phy_loopback(adapter);
 
        return 7;
@@ -1160,27 +1371,43 @@ e1000_setup_loopback_test(struct e1000_adapter *adapter)
 static void
 e1000_loopback_cleanup(struct e1000_adapter *adapter)
 {
+       struct e1000_hw *hw = &adapter->hw;
        uint32_t rctl;
        uint16_t phy_reg;
 
-       rctl = E1000_READ_REG(&adapter->hw, RCTL);
+       rctl = E1000_READ_REG(hw, RCTL);
        rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
-       E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
-
-       if(adapter->hw.media_type == e1000_media_type_copper ||
-          ((adapter->hw.media_type == e1000_media_type_fiber ||
-            adapter->hw.media_type == e1000_media_type_internal_serdes) &&
-           (adapter->hw.mac_type == e1000_82545 ||
-            adapter->hw.mac_type == e1000_82546 ||
-            adapter->hw.mac_type == e1000_82545_rev_3 ||
-            adapter->hw.mac_type == e1000_82546_rev_3))) {
-               adapter->hw.autoneg = TRUE;
-               e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
-               if(phy_reg & MII_CR_LOOPBACK) {
+       E1000_WRITE_REG(hw, RCTL, rctl);
+
+       switch (hw->mac_type) {
+       case e1000_82571:
+       case e1000_82572:
+               if (hw->media_type == e1000_media_type_fiber ||
+                   hw->media_type == e1000_media_type_internal_serdes) {
+#define E1000_SERDES_LB_OFF 0x400
+                       E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_OFF);
+                       msec_delay(10);
+                       break;
+               }
+               /* Fall Through */
+       case e1000_82545:
+       case e1000_82546:
+       case e1000_82545_rev_3:
+       case e1000_82546_rev_3:
+       default:
+               hw->autoneg = TRUE;
+               if (hw->phy_type == e1000_phy_gg82563) {
+                       e1000_write_phy_reg(hw,
+                                           GG82563_PHY_KMRN_MODE_CTRL,
+                                           0x180);
+               }
+               e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
+               if (phy_reg & MII_CR_LOOPBACK) {
                        phy_reg &= ~MII_CR_LOOPBACK;
-                       e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
-                       e1000_phy_reset(&adapter->hw);
+                       e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
+                       e1000_phy_reset(hw);
                }
+               break;
        }
 }
 
@@ -1188,7 +1415,7 @@ static void
 e1000_create_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
 {
        memset(skb->data, 0xFF, frame_size);
-       frame_size = (frame_size % 2) ? (frame_size - 1) : frame_size;
+       frame_size &= ~1;
        memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
        memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
        memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
@@ -1197,9 +1424,9 @@ e1000_create_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
 static int
 e1000_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
 {
-       frame_size = (frame_size % 2) ? (frame_size - 1) : frame_size;
-       if(*(skb->data + 3) == 0xFF) {
-               if((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
+       frame_size &= ~1;
+       if (*(skb->data + 3) == 0xFF) {
+               if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
                   (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
                        return 0;
                }
@@ -1210,38 +1437,90 @@ e1000_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
 static int
 e1000_run_loopback_test(struct e1000_adapter *adapter)
 {
-       struct e1000_desc_ring *txdr = &adapter->test_tx_ring;
-       struct e1000_desc_ring *rxdr = &adapter->test_rx_ring;
+       struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
+       struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
        struct pci_dev *pdev = adapter->pdev;
-       int i;
+       int i, j, k, l, lc, good_cnt, ret_val=0;
+       unsigned long time;
 
        E1000_WRITE_REG(&adapter->hw, RDT, rxdr->count - 1);
 
-       for(i = 0; i < 64; i++) {
-               e1000_create_lbtest_frame(txdr->buffer_info[i].skb, 1024);
-               pci_dma_sync_single_for_device(pdev, txdr->buffer_info[i].dma,
-                                              txdr->buffer_info[i].length,
-                                              PCI_DMA_TODEVICE);
-       }
-       E1000_WRITE_REG(&adapter->hw, TDT, i);
-
-       msec_delay(200);
-
-       pci_dma_sync_single_for_cpu(pdev, rxdr->buffer_info[0].dma,
-                                   rxdr->buffer_info[0].length, PCI_DMA_FROMDEVICE);
+       /* Calculate the loop count based on the largest descriptor ring
+        * The idea is to wrap the largest ring a number of times using 64
+        * send/receive pairs during each loop
+        */
 
-       return e1000_check_lbtest_frame(rxdr->buffer_info[0].skb, 1024);
+       if (rxdr->count <= txdr->count)
+               lc = ((txdr->count / 64) * 2) + 1;
+       else
+               lc = ((rxdr->count / 64) * 2) + 1;
+
+       k = l = 0;
+       for (j = 0; j <= lc; j++) { /* loop count loop */
+               for (i = 0; i < 64; i++) { /* send the packets */
+                       e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
+                                       1024);
+                       pci_dma_sync_single_for_device(pdev,
+                                       txdr->buffer_info[k].dma,
+                                       txdr->buffer_info[k].length,
+                                       PCI_DMA_TODEVICE);
+                       if (unlikely(++k == txdr->count)) k = 0;
+               }
+               E1000_WRITE_REG(&adapter->hw, TDT, k);
+               msec_delay(200);
+               time = jiffies; /* set the start time for the receive */
+               good_cnt = 0;
+               do { /* receive the sent packets */
+                       pci_dma_sync_single_for_cpu(pdev,
+                                       rxdr->buffer_info[l].dma,
+                                       rxdr->buffer_info[l].length,
+                                       PCI_DMA_FROMDEVICE);
+
+                       ret_val = e1000_check_lbtest_frame(
+                                       rxdr->buffer_info[l].skb,
+                                       1024);
+                       if (!ret_val)
+                               good_cnt++;
+                       if (unlikely(++l == rxdr->count)) l = 0;
+                       /* time + 20 msecs (200 msecs on 2.4) is more than
+                        * enough time to complete the receives, if it's
+                        * exceeded, break and error off
+                        */
+               } while (good_cnt < 64 && jiffies < (time + 20));
+               if (good_cnt != 64) {
+                       ret_val = 13; /* ret_val is the same as mis-compare */
+                       break;
+               }
+               if (jiffies >= (time + 2)) {
+                       ret_val = 14; /* error code for time out error */
+                       break;
+               }
+       } /* end loop count loop */
+       return ret_val;
 }
 
 static int
 e1000_loopback_test(struct e1000_adapter *adapter, uint64_t *data)
 {
-       if((*data = e1000_setup_desc_rings(adapter))) goto err_loopback;
-       if((*data = e1000_setup_loopback_test(adapter))) goto err_loopback;
+       /* PHY loopback cannot be performed if SoL/IDER
+        * sessions are active */
+       if (e1000_check_phy_reset_block(&adapter->hw)) {
+               DPRINTK(DRV, ERR, "Cannot do PHY loopback test "
+                       "when SoL/IDER is active.\n");
+               *data = 0;
+               goto out;
+       }
+
+       if ((*data = e1000_setup_desc_rings(adapter)))
+               goto out;
+       if ((*data = e1000_setup_loopback_test(adapter)))
+               goto err_loopback;
        *data = e1000_run_loopback_test(adapter);
        e1000_loopback_cleanup(adapter);
-       e1000_free_desc_rings(adapter);
+
 err_loopback:
+       e1000_free_desc_rings(adapter);
+out:
        return *data;
 }
 
@@ -1249,54 +1528,89 @@ static int
 e1000_link_test(struct e1000_adapter *adapter, uint64_t *data)
 {
        *data = 0;
-       e1000_check_for_link(&adapter->hw);
+       if (adapter->hw.media_type == e1000_media_type_internal_serdes) {
+               int i = 0;
+               adapter->hw.serdes_link_down = TRUE;
+
+               /* On some blade server designs, link establishment
+                * could take as long as 2-3 minutes */
+               do {
+                       e1000_check_for_link(&adapter->hw);
+                       if (adapter->hw.serdes_link_down == FALSE)
+                               return *data;
+                       msec_delay(20);
+               } while (i++ < 3750);
 
-       if(!(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU)) {
                *data = 1;
+       } else {
+               e1000_check_for_link(&adapter->hw);
+               if (adapter->hw.autoneg)  /* if auto_neg is set wait for it */
+                       msec_delay(4000);
+
+               if (!(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU)) {
+                       *data = 1;
+               }
        }
        return *data;
 }
 
 static int
-e1000_ethtool_test(struct e1000_adapter *adapter,
+e1000_diag_test_count(struct net_device *netdev)
+{
+       return E1000_TEST_LEN;
+}
+
+static void
+e1000_diag_test(struct net_device *netdev,
                   struct ethtool_test *eth_test, uint64_t *data)
 {
-       boolean_t if_running = netif_running(adapter->netdev);
+       struct e1000_adapter *adapter = netdev_priv(netdev);
+       boolean_t if_running = netif_running(netdev);
 
-       if(eth_test->flags == ETH_TEST_FL_OFFLINE) {
+       if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
                /* Offline tests */
 
+               /* save speed, duplex, autoneg settings */
+               uint16_t autoneg_advertised = adapter->hw.autoneg_advertised;
+               uint8_t forced_speed_duplex = adapter->hw.forced_speed_duplex;
+               uint8_t autoneg = adapter->hw.autoneg;
+
                /* Link test performed before hardware reset so autoneg doesn't
                 * interfere with test result */
-               if(e1000_link_test(adapter, &data[4]))
+               if (e1000_link_test(adapter, &data[4]))
                        eth_test->flags |= ETH_TEST_FL_FAILED;
 
-               if(if_running)
+               if (if_running)
                        e1000_down(adapter);
                else
                        e1000_reset(adapter);
 
-               if(e1000_reg_test(adapter, &data[0]))
+               if (e1000_reg_test(adapter, &data[0]))
                        eth_test->flags |= ETH_TEST_FL_FAILED;
 
                e1000_reset(adapter);
-               if(e1000_eeprom_test(adapter, &data[1]))
+               if (e1000_eeprom_test(adapter, &data[1]))
                        eth_test->flags |= ETH_TEST_FL_FAILED;
 
                e1000_reset(adapter);
-               if(e1000_intr_test(adapter, &data[2]))
+               if (e1000_intr_test(adapter, &data[2]))
                        eth_test->flags |= ETH_TEST_FL_FAILED;
 
                e1000_reset(adapter);
-               if(e1000_loopback_test(adapter, &data[3]))
+               if (e1000_loopback_test(adapter, &data[3]))
                        eth_test->flags |= ETH_TEST_FL_FAILED;
 
+               /* restore speed, duplex, autoneg settings */
+               adapter->hw.autoneg_advertised = autoneg_advertised;
+               adapter->hw.forced_speed_duplex = forced_speed_duplex;
+               adapter->hw.autoneg = autoneg;
+
                e1000_reset(adapter);
-               if(if_running)
+               if (if_running)
                        e1000_up(adapter);
        } else {
                /* Online tests */
-               if(e1000_link_test(adapter, &data[4]))
+               if (e1000_link_test(adapter, &data[4]))
                        eth_test->flags |= ETH_TEST_FL_FAILED;
 
                /* Offline tests aren't run; pass by default */
@@ -1305,27 +1619,48 @@ e1000_ethtool_test(struct e1000_adapter *adapter,
                data[2] = 0;
                data[3] = 0;
        }
-       return 0;
+       msleep_interruptible(4 * 1000);
 }
 
 static void
-e1000_ethtool_gwol(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol)
+e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
 {
+       struct e1000_adapter *adapter = netdev_priv(netdev);
        struct e1000_hw *hw = &adapter->hw;
 
-       switch(adapter->hw.device_id) {
+       switch (adapter->hw.device_id) {
        case E1000_DEV_ID_82542:
        case E1000_DEV_ID_82543GC_FIBER:
        case E1000_DEV_ID_82543GC_COPPER:
        case E1000_DEV_ID_82544EI_FIBER:
+       case E1000_DEV_ID_82546EB_QUAD_COPPER:
+       case E1000_DEV_ID_82545EM_FIBER:
+       case E1000_DEV_ID_82545EM_COPPER:
+       case E1000_DEV_ID_82546GB_QUAD_COPPER:
                wol->supported = 0;
                wol->wolopts   = 0;
                return;
 
+       case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
+               /* device id 10B5 port-A supports wol */
+               if (!adapter->ksp3_port_a) {
+                       wol->supported = 0;
+                       return;
+               }
+               /* KSP3 does not suppport UCAST wake-ups for any interface */
+               wol->supported = WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC;
+
+               if (adapter->wol & E1000_WUFC_EX)
+                       DPRINTK(DRV, ERR, "Interface does not support "
+                       "directed (unicast) frame wake-up packets\n");
+               wol->wolopts = 0;
+               goto do_defaults;
+
        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 */
-               if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) {
+               if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) {
                        wol->supported = 0;
                        wol->wolopts   = 0;
                        return;
@@ -1335,59 +1670,76 @@ e1000_ethtool_gwol(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol)
        default:
                wol->supported = WAKE_UCAST | WAKE_MCAST |
                                 WAKE_BCAST | WAKE_MAGIC;
-
                wol->wolopts = 0;
-               if(adapter->wol & E1000_WUFC_EX)
+
+do_defaults:
+               if (adapter->wol & E1000_WUFC_EX)
                        wol->wolopts |= WAKE_UCAST;
-               if(adapter->wol & E1000_WUFC_MC)
+               if (adapter->wol & E1000_WUFC_MC)
                        wol->wolopts |= WAKE_MCAST;
-               if(adapter->wol & E1000_WUFC_BC)
+               if (adapter->wol & E1000_WUFC_BC)
                        wol->wolopts |= WAKE_BCAST;
-               if(adapter->wol & E1000_WUFC_MAG)
+               if (adapter->wol & E1000_WUFC_MAG)
                        wol->wolopts |= WAKE_MAGIC;
                return;
        }
 }
 
 static int
-e1000_ethtool_swol(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol)
+e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
 {
+       struct e1000_adapter *adapter = netdev_priv(netdev);
        struct e1000_hw *hw = &adapter->hw;
 
-       switch(adapter->hw.device_id) {
+       switch (adapter->hw.device_id) {
        case E1000_DEV_ID_82542:
        case E1000_DEV_ID_82543GC_FIBER:
        case E1000_DEV_ID_82543GC_COPPER:
        case E1000_DEV_ID_82544EI_FIBER:
+       case E1000_DEV_ID_82546EB_QUAD_COPPER:
+       case E1000_DEV_ID_82546GB_QUAD_COPPER:
+       case E1000_DEV_ID_82545EM_FIBER:
+       case E1000_DEV_ID_82545EM_COPPER:
                return wol->wolopts ? -EOPNOTSUPP : 0;
 
+       case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
+               /* device id 10B5 port-A supports wol */
+               if (!adapter->ksp3_port_a)
+                       return wol->wolopts ? -EOPNOTSUPP : 0;
+
+               if (wol->wolopts & WAKE_UCAST) {
+                       DPRINTK(DRV, ERR, "Interface does not support "
+                       "directed (unicast) frame wake-up packets\n");
+                       return -EOPNOTSUPP;
+               }
+
        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 */
-               if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
+               if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
                        return wol->wolopts ? -EOPNOTSUPP : 0;
                /* Fall Through */
 
        default:
-               if(wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
+               if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
                        return -EOPNOTSUPP;
 
                adapter->wol = 0;
 
-               if(wol->wolopts & WAKE_UCAST)
+               if (wol->wolopts & WAKE_UCAST)
                        adapter->wol |= E1000_WUFC_EX;
-               if(wol->wolopts & WAKE_MCAST)
+               if (wol->wolopts & WAKE_MCAST)
                        adapter->wol |= E1000_WUFC_MC;
-               if(wol->wolopts & WAKE_BCAST)
+               if (wol->wolopts & WAKE_BCAST)
                        adapter->wol |= E1000_WUFC_BC;
-               if(wol->wolopts & WAKE_MAGIC)
+               if (wol->wolopts & WAKE_MAGIC)
                        adapter->wol |= E1000_WUFC_MAG;
        }
 
        return 0;
 }
 
-
 /* toggle LED 4 times per second = 2 "blinks" per second */
 #define E1000_ID_INTERVAL      (HZ/4)
 
@@ -1399,7 +1751,7 @@ e1000_led_blink_callback(unsigned long data)
 {
        struct e1000_adapter *adapter = (struct e1000_adapter *) data;
 
-       if(test_and_change_bit(E1000_LED_ON, &adapter->led_status))
+       if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
                e1000_led_off(&adapter->hw);
        else
                e1000_led_on(&adapter->hw);
@@ -1408,24 +1760,41 @@ e1000_led_blink_callback(unsigned long data)
 }
 
 static int
-e1000_ethtool_led_blink(struct e1000_adapter *adapter, struct ethtool_value *id)
+e1000_phys_id(struct net_device *netdev, uint32_t data)
 {
-       if(!adapter->blink_timer.function) {
-               init_timer(&adapter->blink_timer);
-               adapter->blink_timer.function = e1000_led_blink_callback;
-               adapter->blink_timer.data = (unsigned long) adapter;
-       }
+       struct e1000_adapter *adapter = netdev_priv(netdev);
 
-       e1000_setup_led(&adapter->hw);
-       mod_timer(&adapter->blink_timer, jiffies);
+       if (!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
+               data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
 
-       set_current_state(TASK_INTERRUPTIBLE);
-       if(id->data)
-               schedule_timeout(id->data * HZ);
-       else
-               schedule_timeout(MAX_SCHEDULE_TIMEOUT);
+       if (adapter->hw.mac_type < e1000_82571) {
+               if (!adapter->blink_timer.function) {
+                       init_timer(&adapter->blink_timer);
+                       adapter->blink_timer.function = e1000_led_blink_callback;
+                       adapter->blink_timer.data = (unsigned long) adapter;
+               }
+               e1000_setup_led(&adapter->hw);
+               mod_timer(&adapter->blink_timer, jiffies);
+               msleep_interruptible(data * 1000);
+               del_timer_sync(&adapter->blink_timer);
+       } else if (adapter->hw.mac_type < e1000_82573) {
+               E1000_WRITE_REG(&adapter->hw, LEDCTL,
+                       (E1000_LEDCTL_LED2_BLINK_RATE |
+                        E1000_LEDCTL_LED0_BLINK | E1000_LEDCTL_LED2_BLINK |
+                        (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED2_MODE_SHIFT) |
+                        (E1000_LEDCTL_MODE_LINK_ACTIVITY << E1000_LEDCTL_LED0_MODE_SHIFT) |
+                        (E1000_LEDCTL_MODE_LED_OFF << E1000_LEDCTL_LED1_MODE_SHIFT)));
+               msleep_interruptible(data * 1000);
+       } else {
+               E1000_WRITE_REG(&adapter->hw, LEDCTL,
+                       (E1000_LEDCTL_LED2_BLINK_RATE |
+                        E1000_LEDCTL_LED1_BLINK | E1000_LEDCTL_LED2_BLINK |
+                        (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED2_MODE_SHIFT) |
+                        (E1000_LEDCTL_MODE_LINK_ACTIVITY << E1000_LEDCTL_LED1_MODE_SHIFT) |
+                        (E1000_LEDCTL_MODE_LED_OFF << E1000_LEDCTL_LED0_MODE_SHIFT)));
+               msleep_interruptible(data * 1000);
+       }
 
-       del_timer_sync(&adapter->blink_timer);
        e1000_led_off(&adapter->hw);
        clear_bit(E1000_LED_ON, &adapter->led_status);
        e1000_cleanup_led(&adapter->hw);
@@ -1433,345 +1802,100 @@ e1000_ethtool_led_blink(struct e1000_adapter *adapter, struct ethtool_value *id)
        return 0;
 }
 
-int
-e1000_ethtool_ioctl(struct net_device *netdev, struct ifreq *ifr)
+static int
+e1000_nway_reset(struct net_device *netdev)
 {
-       struct e1000_adapter *adapter = netdev->priv;
-       void *addr = ifr->ifr_data;
-       uint32_t cmd;
-
-       if(get_user(cmd, (uint32_t *) addr))
-               return -EFAULT;
-
-       switch(cmd) {
-       case ETHTOOL_GSET: {
-               struct ethtool_cmd ecmd = {ETHTOOL_GSET};
-               e1000_ethtool_gset(adapter, &ecmd);
-               if(copy_to_user(addr, &ecmd, sizeof(ecmd)))
-                       return -EFAULT;
-               return 0;
-       }
-       case ETHTOOL_SSET: {
-               struct ethtool_cmd ecmd;
-               if(copy_from_user(&ecmd, addr, sizeof(ecmd)))
-                       return -EFAULT;
-               return e1000_ethtool_sset(adapter, &ecmd);
-       }
-       case ETHTOOL_GDRVINFO: {
-               struct ethtool_drvinfo drvinfo = {ETHTOOL_GDRVINFO};
-               e1000_ethtool_gdrvinfo(adapter, &drvinfo);
-               if(copy_to_user(addr, &drvinfo, sizeof(drvinfo)))
-                       return -EFAULT;
-               return 0;
-       }
-       case ETHTOOL_GSTRINGS: {
-               struct ethtool_gstrings gstrings = { ETHTOOL_GSTRINGS };
-               char *strings = NULL;
-               int err = 0;
-
-               if(copy_from_user(&gstrings, addr, sizeof(gstrings)))
-                       return -EFAULT;
-               switch(gstrings.string_set) {
-               case ETH_SS_TEST:
-                       gstrings.len = E1000_TEST_LEN;
-                       strings = kmalloc(E1000_TEST_LEN * ETH_GSTRING_LEN,
-                                         GFP_KERNEL);
-                       if(!strings)
-                               return -ENOMEM;
-                       memcpy(strings, e1000_gstrings_test, E1000_TEST_LEN *
-                              ETH_GSTRING_LEN);
-                       break;
-               case ETH_SS_STATS: {
-                       int i;
-                       gstrings.len = E1000_STATS_LEN;
-                       strings = kmalloc(E1000_STATS_LEN * ETH_GSTRING_LEN,
-                                         GFP_KERNEL);
-                       if(!strings)
-                               return -ENOMEM;
-                       for(i=0; i < E1000_STATS_LEN; i++) {
-                               memcpy(&strings[i * ETH_GSTRING_LEN],
-                                      e1000_gstrings_stats[i].stat_string,
-                                      ETH_GSTRING_LEN);
-                       }
-                       break;
-               }
-               default:
-                       return -EOPNOTSUPP;
-               }
-               if(copy_to_user(addr, &gstrings, sizeof(gstrings)))
-                       err = -EFAULT;
-               addr += offsetof(struct ethtool_gstrings, data);
-               if(!err && copy_to_user(addr, strings,
-                  gstrings.len * ETH_GSTRING_LEN))
-                       err = -EFAULT;
-
-               kfree(strings);
-               return err;
-       }
-       case ETHTOOL_GREGS: {
-               struct ethtool_regs regs = {ETHTOOL_GREGS};
-               uint32_t regs_buff[E1000_REGS_LEN];
-
-               if(copy_from_user(&regs, addr, sizeof(regs)))
-                       return -EFAULT;
-               memset(regs_buff, 0, sizeof(regs_buff));
-               if (regs.len > E1000_REGS_LEN)
-                       regs.len = E1000_REGS_LEN;
-               e1000_ethtool_gregs(adapter, &regs, regs_buff);
-               if(copy_to_user(addr, &regs, sizeof(regs)))
-                       return -EFAULT;
-
-               addr += offsetof(struct ethtool_regs, data);
-               if(copy_to_user(addr, regs_buff, regs.len))
-                       return -EFAULT;
-
-               return 0;
-       }
-       case ETHTOOL_NWAY_RST: {
-               if(netif_running(netdev)) {
-                       e1000_down(adapter);
-                       e1000_up(adapter);
-               }
-               return 0;
-       }
-       case ETHTOOL_PHYS_ID: {
-               struct ethtool_value id;
-               if(copy_from_user(&id, addr, sizeof(id)))
-                       return -EFAULT;
-               return e1000_ethtool_led_blink(adapter, &id);
-       }
-       case ETHTOOL_GLINK: {
-               struct ethtool_value link = {ETHTOOL_GLINK};
-               link.data = netif_carrier_ok(netdev);
-               if(copy_to_user(addr, &link, sizeof(link)))
-                       return -EFAULT;
-               return 0;
-       }
-       case ETHTOOL_GWOL: {
-               struct ethtool_wolinfo wol = {ETHTOOL_GWOL};
-               e1000_ethtool_gwol(adapter, &wol);
-               if(copy_to_user(addr, &wol, sizeof(wol)) != 0)
-                       return -EFAULT;
-               return 0;
-       }
-       case ETHTOOL_SWOL: {
-               struct ethtool_wolinfo wol;
-               if(copy_from_user(&wol, addr, sizeof(wol)) != 0)
-                       return -EFAULT;
-               return e1000_ethtool_swol(adapter, &wol);
-       }
-       case ETHTOOL_GEEPROM: {
-               struct ethtool_eeprom eeprom = {ETHTOOL_GEEPROM};
-               struct e1000_hw *hw = &adapter->hw;
-               uint16_t *eeprom_buff;
-               void *ptr;
-               int err = 0;
-
-               if(copy_from_user(&eeprom, addr, sizeof(eeprom)))
-                       return -EFAULT;
-
-               eeprom_buff = kmalloc(hw->eeprom.word_size * 2, GFP_KERNEL);
-
-               if(!eeprom_buff)
-                       return -ENOMEM;
-
-               if((err = e1000_ethtool_geeprom(adapter, &eeprom,
-                                               eeprom_buff)))
-                       goto err_geeprom_ioctl;
-
-               if(copy_to_user(addr, &eeprom, sizeof(eeprom))) {
-                       err = -EFAULT;
-                       goto err_geeprom_ioctl;
-               }
-
-               addr += offsetof(struct ethtool_eeprom, data);
-               ptr = ((void *)eeprom_buff) + (eeprom.offset & 1);
-
-               if(copy_to_user(addr, ptr, eeprom.len))
-                       err = -EFAULT;
-
-err_geeprom_ioctl:
-               kfree(eeprom_buff);
-               return err;
-       }
-       case ETHTOOL_SEEPROM: {
-               struct ethtool_eeprom eeprom;
-
-               if(copy_from_user(&eeprom, addr, sizeof(eeprom)))
-                       return -EFAULT;
-
-               addr += offsetof(struct ethtool_eeprom, data);
-               return e1000_ethtool_seeprom(adapter, &eeprom, addr);
-       }
-       case ETHTOOL_GRINGPARAM: {
-               struct ethtool_ringparam ering = {ETHTOOL_GRINGPARAM};
-               e1000_ethtool_gring(adapter, &ering);
-               if(copy_to_user(addr, &ering, sizeof(ering)))
-                       return -EFAULT;
-               return 0;
-       }
-       case ETHTOOL_SRINGPARAM: {
-               struct ethtool_ringparam ering;
-               if(copy_from_user(&ering, addr, sizeof(ering)))
-                       return -EFAULT;
-               return e1000_ethtool_sring(adapter, &ering);
-       }
-       case ETHTOOL_GPAUSEPARAM: {
-               struct ethtool_pauseparam epause = {ETHTOOL_GPAUSEPARAM};
-               e1000_ethtool_gpause(adapter, &epause);
-               if(copy_to_user(addr, &epause, sizeof(epause)))
-                       return -EFAULT;
-               return 0;
-       }
-       case ETHTOOL_SPAUSEPARAM: {
-               struct ethtool_pauseparam epause;
-               if(copy_from_user(&epause, addr, sizeof(epause)))
-                       return -EFAULT;
-               return e1000_ethtool_spause(adapter, &epause);
-       }
-       case ETHTOOL_GSTATS: {
-               struct {
-                       struct ethtool_stats eth_stats;
-                       uint64_t data[E1000_STATS_LEN];
-               } stats = { {ETHTOOL_GSTATS, E1000_STATS_LEN} };
-               int i;
-
-               e1000_update_stats(adapter);
-               for(i = 0; i < E1000_STATS_LEN; i++)
-                       stats.data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
-                                       sizeof(uint64_t)) ?
-                               *(uint64_t *)((char *)adapter +
-                                       e1000_gstrings_stats[i].stat_offset) :
-                               *(uint32_t *)((char *)adapter +
-                                       e1000_gstrings_stats[i].stat_offset);
-               if(copy_to_user(addr, &stats, sizeof(stats)))
-                       return -EFAULT;
-               return 0;
+       struct e1000_adapter *adapter = netdev_priv(netdev);
+       if (netif_running(netdev)) {
+               e1000_down(adapter);
+               e1000_up(adapter);
        }
-       case ETHTOOL_TEST: {
-               struct {
-                       struct ethtool_test eth_test;
-                       uint64_t data[E1000_TEST_LEN];
-               } test = { {ETHTOOL_TEST} };
-               int err;
-
-               if(copy_from_user(&test.eth_test, addr, sizeof(test.eth_test)))
-                       return -EFAULT;
-
-               test.eth_test.len = E1000_TEST_LEN;
-
-               if((err = e1000_ethtool_test(adapter, &test.eth_test,
-                                            test.data)))
-                       return err;
+       return 0;
+}
 
-               if(copy_to_user(addr, &test, sizeof(test)) != 0)
-                       return -EFAULT;
-               return 0;
-       }
-       case ETHTOOL_GRXCSUM: {
-               struct ethtool_value edata = { ETHTOOL_GRXCSUM };
+static int
+e1000_get_stats_count(struct net_device *netdev)
+{
+       return E1000_STATS_LEN;
+}
 
-               edata.data = adapter->rx_csum;
-               if (copy_to_user(addr, &edata, sizeof(edata)))
-                       return -EFAULT;
-               return 0;
-       }
-       case ETHTOOL_SRXCSUM: {
-               struct ethtool_value edata;
+static void
+e1000_get_ethtool_stats(struct net_device *netdev,
+               struct ethtool_stats *stats, uint64_t *data)
+{
+       struct e1000_adapter *adapter = netdev_priv(netdev);
+       int i;
 
-               if (copy_from_user(&edata, addr, sizeof(edata)))
-                       return -EFAULT;
-               adapter->rx_csum = edata.data;
-               if(netif_running(netdev)) {
-                       e1000_down(adapter);
-                       e1000_up(adapter);
-               } else
-                       e1000_reset(adapter);
-               return 0;
+       e1000_update_stats(adapter);
+       for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
+               char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
+               data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
+                       sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
        }
-       case ETHTOOL_GTXCSUM: {
-               struct ethtool_value edata = { ETHTOOL_GTXCSUM };
-
-               edata.data =
-                       (netdev->features & NETIF_F_HW_CSUM) != 0;
-               if (copy_to_user(addr, &edata, sizeof(edata)))
-                       return -EFAULT;
-               return 0;
-       }
-       case ETHTOOL_STXCSUM: {
-               struct ethtool_value edata;
+/*     BUG_ON(i != E1000_STATS_LEN); */
+}
 
-               if (copy_from_user(&edata, addr, sizeof(edata)))
-                       return -EFAULT;
+static void
+e1000_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
+{
+       uint8_t *p = data;
+       int i;
 
-               if(adapter->hw.mac_type < e1000_82543) {
-                       if (edata.data != 0)
-                               return -EINVAL;
-                       return 0;
+       switch (stringset) {
+       case ETH_SS_TEST:
+               memcpy(data, *e1000_gstrings_test,
+                       E1000_TEST_LEN*ETH_GSTRING_LEN);
+               break;
+       case ETH_SS_STATS:
+               for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
+                       memcpy(p, e1000_gstrings_stats[i].stat_string,
+                              ETH_GSTRING_LEN);
+                       p += ETH_GSTRING_LEN;
                }
-
-               if (edata.data)
-                       netdev->features |= NETIF_F_HW_CSUM;
-               else
-                       netdev->features &= ~NETIF_F_HW_CSUM;
-
-               return 0;
-       }
-       case ETHTOOL_GSG: {
-               struct ethtool_value edata = { ETHTOOL_GSG };
-
-               edata.data =
-                       (netdev->features & NETIF_F_SG) != 0;
-               if (copy_to_user(addr, &edata, sizeof(edata)))
-                       return -EFAULT;
-               return 0;
+/*             BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
+               break;
        }
-       case ETHTOOL_SSG: {
-               struct ethtool_value edata;
-
-               if (copy_from_user(&edata, addr, sizeof(edata)))
-                       return -EFAULT;
-
-               if (edata.data)
-                       netdev->features |= NETIF_F_SG;
-               else
-                       netdev->features &= ~NETIF_F_SG;
+}
 
-               return 0;
-       }
+static struct ethtool_ops e1000_ethtool_ops = {
+       .get_settings           = e1000_get_settings,
+       .set_settings           = e1000_set_settings,
+       .get_drvinfo            = e1000_get_drvinfo,
+       .get_regs_len           = e1000_get_regs_len,
+       .get_regs               = e1000_get_regs,
+       .get_wol                = e1000_get_wol,
+       .set_wol                = e1000_set_wol,
+       .get_msglevel           = e1000_get_msglevel,
+       .set_msglevel           = e1000_set_msglevel,
+       .nway_reset             = e1000_nway_reset,
+       .get_link               = ethtool_op_get_link,
+       .get_eeprom_len         = e1000_get_eeprom_len,
+       .get_eeprom             = e1000_get_eeprom,
+       .set_eeprom             = e1000_set_eeprom,
+       .get_ringparam          = e1000_get_ringparam,
+       .set_ringparam          = e1000_set_ringparam,
+       .get_pauseparam         = e1000_get_pauseparam,
+       .set_pauseparam         = e1000_set_pauseparam,
+       .get_rx_csum            = e1000_get_rx_csum,
+       .set_rx_csum            = e1000_set_rx_csum,
+       .get_tx_csum            = e1000_get_tx_csum,
+       .set_tx_csum            = e1000_set_tx_csum,
+       .get_sg                 = ethtool_op_get_sg,
+       .set_sg                 = ethtool_op_set_sg,
 #ifdef NETIF_F_TSO
-       case ETHTOOL_GTSO: {
-               struct ethtool_value edata = { ETHTOOL_GTSO };
-
-               edata.data = (netdev->features & NETIF_F_TSO) != 0;
-               if (copy_to_user(addr, &edata, sizeof(edata)))
-                       return -EFAULT;
-               return 0;
-       }
-       case ETHTOOL_STSO: {
-               struct ethtool_value edata;
-
-               if (copy_from_user(&edata, addr, sizeof(edata)))
-                       return -EFAULT;
-
-               if ((adapter->hw.mac_type < e1000_82544) ||
-                   (adapter->hw.mac_type == e1000_82547)) {
-                       if (edata.data != 0)
-                               return -EINVAL;
-                       return 0;
-               }
-
-               if (edata.data)
-                       netdev->features |= NETIF_F_TSO;
-               else
-                       netdev->features &= ~NETIF_F_TSO;
-
-               return 0;
-       }
+       .get_tso                = ethtool_op_get_tso,
+       .set_tso                = e1000_set_tso,
 #endif
-       default:
-               return -EOPNOTSUPP;
-       }
-}
-
+       .self_test_count        = e1000_diag_test_count,
+       .self_test              = e1000_diag_test,
+       .get_strings            = e1000_get_strings,
+       .phys_id                = e1000_phys_id,
+       .get_stats_count        = e1000_get_stats_count,
+       .get_ethtool_stats      = e1000_get_ethtool_stats,
+       .get_perm_addr          = ethtool_op_get_perm_addr,
+};
 
+void e1000_set_ethtool_ops(struct net_device *netdev)
+{
+       SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
+}