devices/e1000e/ethtool-2.6.37-orig.c
branchredundancy
changeset 2135 f99b2249704c
equal deleted inserted replaced
2134:2aee73b9f63f 2135:f99b2249704c
       
     1 /*******************************************************************************
       
     2 
       
     3   Intel PRO/1000 Linux driver
       
     4   Copyright(c) 1999 - 2010 Intel Corporation.
       
     5 
       
     6   This program is free software; you can redistribute it and/or modify it
       
     7   under the terms and conditions of the GNU General Public License,
       
     8   version 2, as published by the Free Software Foundation.
       
     9 
       
    10   This program is distributed in the hope it will be useful, but WITHOUT
       
    11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    12   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
       
    13   more details.
       
    14 
       
    15   You should have received a copy of the GNU General Public License along with
       
    16   this program; if not, write to the Free Software Foundation, Inc.,
       
    17   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
       
    18 
       
    19   The full GNU General Public License is included in this distribution in
       
    20   the file called "COPYING".
       
    21 
       
    22   Contact Information:
       
    23   Linux NICS <linux.nics@intel.com>
       
    24   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
       
    25   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
       
    26 
       
    27 *******************************************************************************/
       
    28 
       
    29 /* ethtool support for e1000 */
       
    30 
       
    31 #include <linux/netdevice.h>
       
    32 #include <linux/ethtool.h>
       
    33 #include <linux/pci.h>
       
    34 #include <linux/slab.h>
       
    35 #include <linux/delay.h>
       
    36 
       
    37 #include "e1000.h"
       
    38 
       
    39 enum {NETDEV_STATS, E1000_STATS};
       
    40 
       
    41 struct e1000_stats {
       
    42 	char stat_string[ETH_GSTRING_LEN];
       
    43 	int type;
       
    44 	int sizeof_stat;
       
    45 	int stat_offset;
       
    46 };
       
    47 
       
    48 #define E1000_STAT(m)		E1000_STATS, \
       
    49 				sizeof(((struct e1000_adapter *)0)->m), \
       
    50 		      		offsetof(struct e1000_adapter, m)
       
    51 #define E1000_NETDEV_STAT(m)	NETDEV_STATS, \
       
    52 				sizeof(((struct net_device *)0)->m), \
       
    53 				offsetof(struct net_device, m)
       
    54 
       
    55 static const struct e1000_stats e1000_gstrings_stats[] = {
       
    56 	{ "rx_packets", E1000_STAT(stats.gprc) },
       
    57 	{ "tx_packets", E1000_STAT(stats.gptc) },
       
    58 	{ "rx_bytes", E1000_STAT(stats.gorc) },
       
    59 	{ "tx_bytes", E1000_STAT(stats.gotc) },
       
    60 	{ "rx_broadcast", E1000_STAT(stats.bprc) },
       
    61 	{ "tx_broadcast", E1000_STAT(stats.bptc) },
       
    62 	{ "rx_multicast", E1000_STAT(stats.mprc) },
       
    63 	{ "tx_multicast", E1000_STAT(stats.mptc) },
       
    64 	{ "rx_errors", E1000_NETDEV_STAT(stats.rx_errors) },
       
    65 	{ "tx_errors", E1000_NETDEV_STAT(stats.tx_errors) },
       
    66 	{ "tx_dropped", E1000_NETDEV_STAT(stats.tx_dropped) },
       
    67 	{ "multicast", E1000_STAT(stats.mprc) },
       
    68 	{ "collisions", E1000_STAT(stats.colc) },
       
    69 	{ "rx_length_errors", E1000_NETDEV_STAT(stats.rx_length_errors) },
       
    70 	{ "rx_over_errors", E1000_NETDEV_STAT(stats.rx_over_errors) },
       
    71 	{ "rx_crc_errors", E1000_STAT(stats.crcerrs) },
       
    72 	{ "rx_frame_errors", E1000_NETDEV_STAT(stats.rx_frame_errors) },
       
    73 	{ "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
       
    74 	{ "rx_missed_errors", E1000_STAT(stats.mpc) },
       
    75 	{ "tx_aborted_errors", E1000_STAT(stats.ecol) },
       
    76 	{ "tx_carrier_errors", E1000_STAT(stats.tncrs) },
       
    77 	{ "tx_fifo_errors", E1000_NETDEV_STAT(stats.tx_fifo_errors) },
       
    78 	{ "tx_heartbeat_errors", E1000_NETDEV_STAT(stats.tx_heartbeat_errors) },
       
    79 	{ "tx_window_errors", E1000_STAT(stats.latecol) },
       
    80 	{ "tx_abort_late_coll", E1000_STAT(stats.latecol) },
       
    81 	{ "tx_deferred_ok", E1000_STAT(stats.dc) },
       
    82 	{ "tx_single_coll_ok", E1000_STAT(stats.scc) },
       
    83 	{ "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
       
    84 	{ "tx_timeout_count", E1000_STAT(tx_timeout_count) },
       
    85 	{ "tx_restart_queue", E1000_STAT(restart_queue) },
       
    86 	{ "rx_long_length_errors", E1000_STAT(stats.roc) },
       
    87 	{ "rx_short_length_errors", E1000_STAT(stats.ruc) },
       
    88 	{ "rx_align_errors", E1000_STAT(stats.algnerrc) },
       
    89 	{ "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
       
    90 	{ "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
       
    91 	{ "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
       
    92 	{ "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
       
    93 	{ "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
       
    94 	{ "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
       
    95 	{ "rx_long_byte_count", E1000_STAT(stats.gorc) },
       
    96 	{ "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
       
    97 	{ "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
       
    98 	{ "rx_header_split", E1000_STAT(rx_hdr_split) },
       
    99 	{ "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
       
   100 	{ "tx_smbus", E1000_STAT(stats.mgptc) },
       
   101 	{ "rx_smbus", E1000_STAT(stats.mgprc) },
       
   102 	{ "dropped_smbus", E1000_STAT(stats.mgpdc) },
       
   103 	{ "rx_dma_failed", E1000_STAT(rx_dma_failed) },
       
   104 	{ "tx_dma_failed", E1000_STAT(tx_dma_failed) },
       
   105 };
       
   106 
       
   107 #define E1000_GLOBAL_STATS_LEN	ARRAY_SIZE(e1000_gstrings_stats)
       
   108 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
       
   109 static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
       
   110 	"Register test  (offline)", "Eeprom test    (offline)",
       
   111 	"Interrupt test (offline)", "Loopback test  (offline)",
       
   112 	"Link test   (on/offline)"
       
   113 };
       
   114 #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
       
   115 
       
   116 static int e1000_get_settings(struct net_device *netdev,
       
   117 			      struct ethtool_cmd *ecmd)
       
   118 {
       
   119 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   120 	struct e1000_hw *hw = &adapter->hw;
       
   121 
       
   122 	if (hw->phy.media_type == e1000_media_type_copper) {
       
   123 
       
   124 		ecmd->supported = (SUPPORTED_10baseT_Half |
       
   125 				   SUPPORTED_10baseT_Full |
       
   126 				   SUPPORTED_100baseT_Half |
       
   127 				   SUPPORTED_100baseT_Full |
       
   128 				   SUPPORTED_1000baseT_Full |
       
   129 				   SUPPORTED_Autoneg |
       
   130 				   SUPPORTED_TP);
       
   131 		if (hw->phy.type == e1000_phy_ife)
       
   132 			ecmd->supported &= ~SUPPORTED_1000baseT_Full;
       
   133 		ecmd->advertising = ADVERTISED_TP;
       
   134 
       
   135 		if (hw->mac.autoneg == 1) {
       
   136 			ecmd->advertising |= ADVERTISED_Autoneg;
       
   137 			/* the e1000 autoneg seems to match ethtool nicely */
       
   138 			ecmd->advertising |= hw->phy.autoneg_advertised;
       
   139 		}
       
   140 
       
   141 		ecmd->port = PORT_TP;
       
   142 		ecmd->phy_address = hw->phy.addr;
       
   143 		ecmd->transceiver = XCVR_INTERNAL;
       
   144 
       
   145 	} else {
       
   146 		ecmd->supported   = (SUPPORTED_1000baseT_Full |
       
   147 				     SUPPORTED_FIBRE |
       
   148 				     SUPPORTED_Autoneg);
       
   149 
       
   150 		ecmd->advertising = (ADVERTISED_1000baseT_Full |
       
   151 				     ADVERTISED_FIBRE |
       
   152 				     ADVERTISED_Autoneg);
       
   153 
       
   154 		ecmd->port = PORT_FIBRE;
       
   155 		ecmd->transceiver = XCVR_EXTERNAL;
       
   156 	}
       
   157 
       
   158 	ecmd->speed = -1;
       
   159 	ecmd->duplex = -1;
       
   160 
       
   161 	if (netif_running(netdev)) {
       
   162 		if (netif_carrier_ok(netdev)) {
       
   163 			ecmd->speed = adapter->link_speed;
       
   164 			ecmd->duplex = adapter->link_duplex - 1;
       
   165 		}
       
   166 	} else {
       
   167 		u32 status = er32(STATUS);
       
   168 		if (status & E1000_STATUS_LU) {
       
   169 			if (status & E1000_STATUS_SPEED_1000)
       
   170 				ecmd->speed = 1000;
       
   171 			else if (status & E1000_STATUS_SPEED_100)
       
   172 				ecmd->speed = 100;
       
   173 			else
       
   174 				ecmd->speed = 10;
       
   175 
       
   176 			if (status & E1000_STATUS_FD)
       
   177 				ecmd->duplex = DUPLEX_FULL;
       
   178 			else
       
   179 				ecmd->duplex = DUPLEX_HALF;
       
   180 		}
       
   181 	}
       
   182 
       
   183 	ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
       
   184 			 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
       
   185 
       
   186 	/* MDI-X => 2; MDI =>1; Invalid =>0 */
       
   187 	if ((hw->phy.media_type == e1000_media_type_copper) &&
       
   188 	    netif_carrier_ok(netdev))
       
   189 		ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
       
   190 		                                      ETH_TP_MDI;
       
   191 	else
       
   192 		ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
       
   193 
       
   194 	return 0;
       
   195 }
       
   196 
       
   197 static u32 e1000_get_link(struct net_device *netdev)
       
   198 {
       
   199 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   200 	struct e1000_hw *hw = &adapter->hw;
       
   201 
       
   202 	/*
       
   203 	 * Avoid touching hardware registers when possible, otherwise
       
   204 	 * link negotiation can get messed up when user-level scripts
       
   205 	 * are rapidly polling the driver to see if link is up.
       
   206 	 */
       
   207 	return netif_running(netdev) ? netif_carrier_ok(netdev) :
       
   208 	    !!(er32(STATUS) & E1000_STATUS_LU);
       
   209 }
       
   210 
       
   211 static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
       
   212 {
       
   213 	struct e1000_mac_info *mac = &adapter->hw.mac;
       
   214 
       
   215 	mac->autoneg = 0;
       
   216 
       
   217 	/* Fiber NICs only allow 1000 gbps Full duplex */
       
   218 	if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
       
   219 		spddplx != (SPEED_1000 + DUPLEX_FULL)) {
       
   220 		e_err("Unsupported Speed/Duplex configuration\n");
       
   221 		return -EINVAL;
       
   222 	}
       
   223 
       
   224 	switch (spddplx) {
       
   225 	case SPEED_10 + DUPLEX_HALF:
       
   226 		mac->forced_speed_duplex = ADVERTISE_10_HALF;
       
   227 		break;
       
   228 	case SPEED_10 + DUPLEX_FULL:
       
   229 		mac->forced_speed_duplex = ADVERTISE_10_FULL;
       
   230 		break;
       
   231 	case SPEED_100 + DUPLEX_HALF:
       
   232 		mac->forced_speed_duplex = ADVERTISE_100_HALF;
       
   233 		break;
       
   234 	case SPEED_100 + DUPLEX_FULL:
       
   235 		mac->forced_speed_duplex = ADVERTISE_100_FULL;
       
   236 		break;
       
   237 	case SPEED_1000 + DUPLEX_FULL:
       
   238 		mac->autoneg = 1;
       
   239 		adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
       
   240 		break;
       
   241 	case SPEED_1000 + DUPLEX_HALF: /* not supported */
       
   242 	default:
       
   243 		e_err("Unsupported Speed/Duplex configuration\n");
       
   244 		return -EINVAL;
       
   245 	}
       
   246 	return 0;
       
   247 }
       
   248 
       
   249 static int e1000_set_settings(struct net_device *netdev,
       
   250 			      struct ethtool_cmd *ecmd)
       
   251 {
       
   252 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   253 	struct e1000_hw *hw = &adapter->hw;
       
   254 
       
   255 	/*
       
   256 	 * When SoL/IDER sessions are active, autoneg/speed/duplex
       
   257 	 * cannot be changed
       
   258 	 */
       
   259 	if (e1000_check_reset_block(hw)) {
       
   260 		e_err("Cannot change link characteristics when SoL/IDER is "
       
   261 		      "active.\n");
       
   262 		return -EINVAL;
       
   263 	}
       
   264 
       
   265 	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
       
   266 		msleep(1);
       
   267 
       
   268 	if (ecmd->autoneg == AUTONEG_ENABLE) {
       
   269 		hw->mac.autoneg = 1;
       
   270 		if (hw->phy.media_type == e1000_media_type_fiber)
       
   271 			hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
       
   272 						     ADVERTISED_FIBRE |
       
   273 						     ADVERTISED_Autoneg;
       
   274 		else
       
   275 			hw->phy.autoneg_advertised = ecmd->advertising |
       
   276 						     ADVERTISED_TP |
       
   277 						     ADVERTISED_Autoneg;
       
   278 		ecmd->advertising = hw->phy.autoneg_advertised;
       
   279 		if (adapter->fc_autoneg)
       
   280 			hw->fc.requested_mode = e1000_fc_default;
       
   281 	} else {
       
   282 		if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
       
   283 			clear_bit(__E1000_RESETTING, &adapter->state);
       
   284 			return -EINVAL;
       
   285 		}
       
   286 	}
       
   287 
       
   288 	/* reset the link */
       
   289 
       
   290 	if (netif_running(adapter->netdev)) {
       
   291 		e1000e_down(adapter);
       
   292 		e1000e_up(adapter);
       
   293 	} else {
       
   294 		e1000e_reset(adapter);
       
   295 	}
       
   296 
       
   297 	clear_bit(__E1000_RESETTING, &adapter->state);
       
   298 	return 0;
       
   299 }
       
   300 
       
   301 static void e1000_get_pauseparam(struct net_device *netdev,
       
   302 				 struct ethtool_pauseparam *pause)
       
   303 {
       
   304 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   305 	struct e1000_hw *hw = &adapter->hw;
       
   306 
       
   307 	pause->autoneg =
       
   308 		(adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
       
   309 
       
   310 	if (hw->fc.current_mode == e1000_fc_rx_pause) {
       
   311 		pause->rx_pause = 1;
       
   312 	} else if (hw->fc.current_mode == e1000_fc_tx_pause) {
       
   313 		pause->tx_pause = 1;
       
   314 	} else if (hw->fc.current_mode == e1000_fc_full) {
       
   315 		pause->rx_pause = 1;
       
   316 		pause->tx_pause = 1;
       
   317 	}
       
   318 }
       
   319 
       
   320 static int e1000_set_pauseparam(struct net_device *netdev,
       
   321 				struct ethtool_pauseparam *pause)
       
   322 {
       
   323 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   324 	struct e1000_hw *hw = &adapter->hw;
       
   325 	int retval = 0;
       
   326 
       
   327 	adapter->fc_autoneg = pause->autoneg;
       
   328 
       
   329 	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
       
   330 		msleep(1);
       
   331 
       
   332 	if (adapter->fc_autoneg == AUTONEG_ENABLE) {
       
   333 		hw->fc.requested_mode = e1000_fc_default;
       
   334 		if (netif_running(adapter->netdev)) {
       
   335 			e1000e_down(adapter);
       
   336 			e1000e_up(adapter);
       
   337 		} else {
       
   338 			e1000e_reset(adapter);
       
   339 		}
       
   340 	} else {
       
   341 		if (pause->rx_pause && pause->tx_pause)
       
   342 			hw->fc.requested_mode = e1000_fc_full;
       
   343 		else if (pause->rx_pause && !pause->tx_pause)
       
   344 			hw->fc.requested_mode = e1000_fc_rx_pause;
       
   345 		else if (!pause->rx_pause && pause->tx_pause)
       
   346 			hw->fc.requested_mode = e1000_fc_tx_pause;
       
   347 		else if (!pause->rx_pause && !pause->tx_pause)
       
   348 			hw->fc.requested_mode = e1000_fc_none;
       
   349 
       
   350 		hw->fc.current_mode = hw->fc.requested_mode;
       
   351 
       
   352 		if (hw->phy.media_type == e1000_media_type_fiber) {
       
   353 			retval = hw->mac.ops.setup_link(hw);
       
   354 			/* implicit goto out */
       
   355 		} else {
       
   356 			retval = e1000e_force_mac_fc(hw);
       
   357 			if (retval)
       
   358 				goto out;
       
   359 			e1000e_set_fc_watermarks(hw);
       
   360 		}
       
   361 	}
       
   362 
       
   363 out:
       
   364 	clear_bit(__E1000_RESETTING, &adapter->state);
       
   365 	return retval;
       
   366 }
       
   367 
       
   368 static u32 e1000_get_rx_csum(struct net_device *netdev)
       
   369 {
       
   370 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   371 	return adapter->flags & FLAG_RX_CSUM_ENABLED;
       
   372 }
       
   373 
       
   374 static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
       
   375 {
       
   376 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   377 
       
   378 	if (data)
       
   379 		adapter->flags |= FLAG_RX_CSUM_ENABLED;
       
   380 	else
       
   381 		adapter->flags &= ~FLAG_RX_CSUM_ENABLED;
       
   382 
       
   383 	if (netif_running(netdev))
       
   384 		e1000e_reinit_locked(adapter);
       
   385 	else
       
   386 		e1000e_reset(adapter);
       
   387 	return 0;
       
   388 }
       
   389 
       
   390 static u32 e1000_get_tx_csum(struct net_device *netdev)
       
   391 {
       
   392 	return (netdev->features & NETIF_F_HW_CSUM) != 0;
       
   393 }
       
   394 
       
   395 static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
       
   396 {
       
   397 	if (data)
       
   398 		netdev->features |= NETIF_F_HW_CSUM;
       
   399 	else
       
   400 		netdev->features &= ~NETIF_F_HW_CSUM;
       
   401 
       
   402 	return 0;
       
   403 }
       
   404 
       
   405 static int e1000_set_tso(struct net_device *netdev, u32 data)
       
   406 {
       
   407 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   408 
       
   409 	if (data) {
       
   410 		netdev->features |= NETIF_F_TSO;
       
   411 		netdev->features |= NETIF_F_TSO6;
       
   412 	} else {
       
   413 		netdev->features &= ~NETIF_F_TSO;
       
   414 		netdev->features &= ~NETIF_F_TSO6;
       
   415 	}
       
   416 
       
   417 	adapter->flags |= FLAG_TSO_FORCE;
       
   418 	return 0;
       
   419 }
       
   420 
       
   421 static u32 e1000_get_msglevel(struct net_device *netdev)
       
   422 {
       
   423 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   424 	return adapter->msg_enable;
       
   425 }
       
   426 
       
   427 static void e1000_set_msglevel(struct net_device *netdev, u32 data)
       
   428 {
       
   429 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   430 	adapter->msg_enable = data;
       
   431 }
       
   432 
       
   433 static int e1000_get_regs_len(struct net_device *netdev)
       
   434 {
       
   435 #define E1000_REGS_LEN 32 /* overestimate */
       
   436 	return E1000_REGS_LEN * sizeof(u32);
       
   437 }
       
   438 
       
   439 static void e1000_get_regs(struct net_device *netdev,
       
   440 			   struct ethtool_regs *regs, void *p)
       
   441 {
       
   442 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   443 	struct e1000_hw *hw = &adapter->hw;
       
   444 	u32 *regs_buff = p;
       
   445 	u16 phy_data;
       
   446 	u8 revision_id;
       
   447 
       
   448 	memset(p, 0, E1000_REGS_LEN * sizeof(u32));
       
   449 
       
   450 	pci_read_config_byte(adapter->pdev, PCI_REVISION_ID, &revision_id);
       
   451 
       
   452 	regs->version = (1 << 24) | (revision_id << 16) | adapter->pdev->device;
       
   453 
       
   454 	regs_buff[0]  = er32(CTRL);
       
   455 	regs_buff[1]  = er32(STATUS);
       
   456 
       
   457 	regs_buff[2]  = er32(RCTL);
       
   458 	regs_buff[3]  = er32(RDLEN);
       
   459 	regs_buff[4]  = er32(RDH);
       
   460 	regs_buff[5]  = er32(RDT);
       
   461 	regs_buff[6]  = er32(RDTR);
       
   462 
       
   463 	regs_buff[7]  = er32(TCTL);
       
   464 	regs_buff[8]  = er32(TDLEN);
       
   465 	regs_buff[9]  = er32(TDH);
       
   466 	regs_buff[10] = er32(TDT);
       
   467 	regs_buff[11] = er32(TIDV);
       
   468 
       
   469 	regs_buff[12] = adapter->hw.phy.type;  /* PHY type (IGP=1, M88=0) */
       
   470 
       
   471 	/* ethtool doesn't use anything past this point, so all this
       
   472 	 * code is likely legacy junk for apps that may or may not
       
   473 	 * exist */
       
   474 	if (hw->phy.type == e1000_phy_m88) {
       
   475 		e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
       
   476 		regs_buff[13] = (u32)phy_data; /* cable length */
       
   477 		regs_buff[14] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
       
   478 		regs_buff[15] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
       
   479 		regs_buff[16] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
       
   480 		e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
       
   481 		regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
       
   482 		regs_buff[18] = regs_buff[13]; /* cable polarity */
       
   483 		regs_buff[19] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
       
   484 		regs_buff[20] = regs_buff[17]; /* polarity correction */
       
   485 		/* phy receive errors */
       
   486 		regs_buff[22] = adapter->phy_stats.receive_errors;
       
   487 		regs_buff[23] = regs_buff[13]; /* mdix mode */
       
   488 	}
       
   489 	regs_buff[21] = 0; /* was idle_errors */
       
   490 	e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
       
   491 	regs_buff[24] = (u32)phy_data;  /* phy local receiver status */
       
   492 	regs_buff[25] = regs_buff[24];  /* phy remote receiver status */
       
   493 }
       
   494 
       
   495 static int e1000_get_eeprom_len(struct net_device *netdev)
       
   496 {
       
   497 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   498 	return adapter->hw.nvm.word_size * 2;
       
   499 }
       
   500 
       
   501 static int e1000_get_eeprom(struct net_device *netdev,
       
   502 			    struct ethtool_eeprom *eeprom, u8 *bytes)
       
   503 {
       
   504 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   505 	struct e1000_hw *hw = &adapter->hw;
       
   506 	u16 *eeprom_buff;
       
   507 	int first_word;
       
   508 	int last_word;
       
   509 	int ret_val = 0;
       
   510 	u16 i;
       
   511 
       
   512 	if (eeprom->len == 0)
       
   513 		return -EINVAL;
       
   514 
       
   515 	eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
       
   516 
       
   517 	first_word = eeprom->offset >> 1;
       
   518 	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
       
   519 
       
   520 	eeprom_buff = kmalloc(sizeof(u16) *
       
   521 			(last_word - first_word + 1), GFP_KERNEL);
       
   522 	if (!eeprom_buff)
       
   523 		return -ENOMEM;
       
   524 
       
   525 	if (hw->nvm.type == e1000_nvm_eeprom_spi) {
       
   526 		ret_val = e1000_read_nvm(hw, first_word,
       
   527 					 last_word - first_word + 1,
       
   528 					 eeprom_buff);
       
   529 	} else {
       
   530 		for (i = 0; i < last_word - first_word + 1; i++) {
       
   531 			ret_val = e1000_read_nvm(hw, first_word + i, 1,
       
   532 						      &eeprom_buff[i]);
       
   533 			if (ret_val)
       
   534 				break;
       
   535 		}
       
   536 	}
       
   537 
       
   538 	if (ret_val) {
       
   539 		/* a read error occurred, throw away the result */
       
   540 		memset(eeprom_buff, 0xff, sizeof(u16) *
       
   541 		       (last_word - first_word + 1));
       
   542 	} else {
       
   543 		/* Device's eeprom is always little-endian, word addressable */
       
   544 		for (i = 0; i < last_word - first_word + 1; i++)
       
   545 			le16_to_cpus(&eeprom_buff[i]);
       
   546 	}
       
   547 
       
   548 	memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
       
   549 	kfree(eeprom_buff);
       
   550 
       
   551 	return ret_val;
       
   552 }
       
   553 
       
   554 static int e1000_set_eeprom(struct net_device *netdev,
       
   555 			    struct ethtool_eeprom *eeprom, u8 *bytes)
       
   556 {
       
   557 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   558 	struct e1000_hw *hw = &adapter->hw;
       
   559 	u16 *eeprom_buff;
       
   560 	void *ptr;
       
   561 	int max_len;
       
   562 	int first_word;
       
   563 	int last_word;
       
   564 	int ret_val = 0;
       
   565 	u16 i;
       
   566 
       
   567 	if (eeprom->len == 0)
       
   568 		return -EOPNOTSUPP;
       
   569 
       
   570 	if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
       
   571 		return -EFAULT;
       
   572 
       
   573 	if (adapter->flags & FLAG_READ_ONLY_NVM)
       
   574 		return -EINVAL;
       
   575 
       
   576 	max_len = hw->nvm.word_size * 2;
       
   577 
       
   578 	first_word = eeprom->offset >> 1;
       
   579 	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
       
   580 	eeprom_buff = kmalloc(max_len, GFP_KERNEL);
       
   581 	if (!eeprom_buff)
       
   582 		return -ENOMEM;
       
   583 
       
   584 	ptr = (void *)eeprom_buff;
       
   585 
       
   586 	if (eeprom->offset & 1) {
       
   587 		/* need read/modify/write of first changed EEPROM word */
       
   588 		/* only the second byte of the word is being modified */
       
   589 		ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
       
   590 		ptr++;
       
   591 	}
       
   592 	if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
       
   593 		/* need read/modify/write of last changed EEPROM word */
       
   594 		/* only the first byte of the word is being modified */
       
   595 		ret_val = e1000_read_nvm(hw, last_word, 1,
       
   596 				  &eeprom_buff[last_word - first_word]);
       
   597 
       
   598 	if (ret_val)
       
   599 		goto out;
       
   600 
       
   601 	/* Device's eeprom is always little-endian, word addressable */
       
   602 	for (i = 0; i < last_word - first_word + 1; i++)
       
   603 		le16_to_cpus(&eeprom_buff[i]);
       
   604 
       
   605 	memcpy(ptr, bytes, eeprom->len);
       
   606 
       
   607 	for (i = 0; i < last_word - first_word + 1; i++)
       
   608 		eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
       
   609 
       
   610 	ret_val = e1000_write_nvm(hw, first_word,
       
   611 				  last_word - first_word + 1, eeprom_buff);
       
   612 
       
   613 	if (ret_val)
       
   614 		goto out;
       
   615 
       
   616 	/*
       
   617 	 * Update the checksum over the first part of the EEPROM if needed
       
   618 	 * and flush shadow RAM for applicable controllers
       
   619 	 */
       
   620 	if ((first_word <= NVM_CHECKSUM_REG) ||
       
   621 	    (hw->mac.type == e1000_82583) ||
       
   622 	    (hw->mac.type == e1000_82574) ||
       
   623 	    (hw->mac.type == e1000_82573))
       
   624 		ret_val = e1000e_update_nvm_checksum(hw);
       
   625 
       
   626 out:
       
   627 	kfree(eeprom_buff);
       
   628 	return ret_val;
       
   629 }
       
   630 
       
   631 static void e1000_get_drvinfo(struct net_device *netdev,
       
   632 			      struct ethtool_drvinfo *drvinfo)
       
   633 {
       
   634 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   635 	char firmware_version[32];
       
   636 
       
   637 	strncpy(drvinfo->driver,  e1000e_driver_name, 32);
       
   638 	strncpy(drvinfo->version, e1000e_driver_version, 32);
       
   639 
       
   640 	/*
       
   641 	 * EEPROM image version # is reported as firmware version # for
       
   642 	 * PCI-E controllers
       
   643 	 */
       
   644 	sprintf(firmware_version, "%d.%d-%d",
       
   645 		(adapter->eeprom_vers & 0xF000) >> 12,
       
   646 		(adapter->eeprom_vers & 0x0FF0) >> 4,
       
   647 		(adapter->eeprom_vers & 0x000F));
       
   648 
       
   649 	strncpy(drvinfo->fw_version, firmware_version, 32);
       
   650 	strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
       
   651 	drvinfo->regdump_len = e1000_get_regs_len(netdev);
       
   652 	drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
       
   653 }
       
   654 
       
   655 static void e1000_get_ringparam(struct net_device *netdev,
       
   656 				struct ethtool_ringparam *ring)
       
   657 {
       
   658 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   659 	struct e1000_ring *tx_ring = adapter->tx_ring;
       
   660 	struct e1000_ring *rx_ring = adapter->rx_ring;
       
   661 
       
   662 	ring->rx_max_pending = E1000_MAX_RXD;
       
   663 	ring->tx_max_pending = E1000_MAX_TXD;
       
   664 	ring->rx_mini_max_pending = 0;
       
   665 	ring->rx_jumbo_max_pending = 0;
       
   666 	ring->rx_pending = rx_ring->count;
       
   667 	ring->tx_pending = tx_ring->count;
       
   668 	ring->rx_mini_pending = 0;
       
   669 	ring->rx_jumbo_pending = 0;
       
   670 }
       
   671 
       
   672 static int e1000_set_ringparam(struct net_device *netdev,
       
   673 			       struct ethtool_ringparam *ring)
       
   674 {
       
   675 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   676 	struct e1000_ring *tx_ring, *tx_old;
       
   677 	struct e1000_ring *rx_ring, *rx_old;
       
   678 	int err;
       
   679 
       
   680 	if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
       
   681 		return -EINVAL;
       
   682 
       
   683 	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
       
   684 		msleep(1);
       
   685 
       
   686 	if (netif_running(adapter->netdev))
       
   687 		e1000e_down(adapter);
       
   688 
       
   689 	tx_old = adapter->tx_ring;
       
   690 	rx_old = adapter->rx_ring;
       
   691 
       
   692 	err = -ENOMEM;
       
   693 	tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
       
   694 	if (!tx_ring)
       
   695 		goto err_alloc_tx;
       
   696 	/*
       
   697 	 * use a memcpy to save any previously configured
       
   698 	 * items like napi structs from having to be
       
   699 	 * reinitialized
       
   700 	 */
       
   701 	memcpy(tx_ring, tx_old, sizeof(struct e1000_ring));
       
   702 
       
   703 	rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
       
   704 	if (!rx_ring)
       
   705 		goto err_alloc_rx;
       
   706 	memcpy(rx_ring, rx_old, sizeof(struct e1000_ring));
       
   707 
       
   708 	adapter->tx_ring = tx_ring;
       
   709 	adapter->rx_ring = rx_ring;
       
   710 
       
   711 	rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
       
   712 	rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
       
   713 	rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
       
   714 
       
   715 	tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
       
   716 	tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
       
   717 	tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
       
   718 
       
   719 	if (netif_running(adapter->netdev)) {
       
   720 		/* Try to get new resources before deleting old */
       
   721 		err = e1000e_setup_rx_resources(adapter);
       
   722 		if (err)
       
   723 			goto err_setup_rx;
       
   724 		err = e1000e_setup_tx_resources(adapter);
       
   725 		if (err)
       
   726 			goto err_setup_tx;
       
   727 
       
   728 		/*
       
   729 		 * restore the old in order to free it,
       
   730 		 * then add in the new
       
   731 		 */
       
   732 		adapter->rx_ring = rx_old;
       
   733 		adapter->tx_ring = tx_old;
       
   734 		e1000e_free_rx_resources(adapter);
       
   735 		e1000e_free_tx_resources(adapter);
       
   736 		kfree(tx_old);
       
   737 		kfree(rx_old);
       
   738 		adapter->rx_ring = rx_ring;
       
   739 		adapter->tx_ring = tx_ring;
       
   740 		err = e1000e_up(adapter);
       
   741 		if (err)
       
   742 			goto err_setup;
       
   743 	}
       
   744 
       
   745 	clear_bit(__E1000_RESETTING, &adapter->state);
       
   746 	return 0;
       
   747 err_setup_tx:
       
   748 	e1000e_free_rx_resources(adapter);
       
   749 err_setup_rx:
       
   750 	adapter->rx_ring = rx_old;
       
   751 	adapter->tx_ring = tx_old;
       
   752 	kfree(rx_ring);
       
   753 err_alloc_rx:
       
   754 	kfree(tx_ring);
       
   755 err_alloc_tx:
       
   756 	e1000e_up(adapter);
       
   757 err_setup:
       
   758 	clear_bit(__E1000_RESETTING, &adapter->state);
       
   759 	return err;
       
   760 }
       
   761 
       
   762 static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
       
   763 			     int reg, int offset, u32 mask, u32 write)
       
   764 {
       
   765 	u32 pat, val;
       
   766 	static const u32 test[] =
       
   767 		{0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
       
   768 	for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
       
   769 		E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
       
   770 				      (test[pat] & write));
       
   771 		val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
       
   772 		if (val != (test[pat] & write & mask)) {
       
   773 			e_err("pattern test reg %04X failed: got 0x%08X "
       
   774 			      "expected 0x%08X\n", reg + offset, val,
       
   775 			      (test[pat] & write & mask));
       
   776 			*data = reg;
       
   777 			return 1;
       
   778 		}
       
   779 	}
       
   780 	return 0;
       
   781 }
       
   782 
       
   783 static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
       
   784 			      int reg, u32 mask, u32 write)
       
   785 {
       
   786 	u32 val;
       
   787 	__ew32(&adapter->hw, reg, write & mask);
       
   788 	val = __er32(&adapter->hw, reg);
       
   789 	if ((write & mask) != (val & mask)) {
       
   790 		e_err("set/check reg %04X test failed: got 0x%08X "
       
   791 		      "expected 0x%08X\n", reg, (val & mask), (write & mask));
       
   792 		*data = reg;
       
   793 		return 1;
       
   794 	}
       
   795 	return 0;
       
   796 }
       
   797 #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write)                       \
       
   798 	do {                                                                   \
       
   799 		if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
       
   800 			return 1;                                              \
       
   801 	} while (0)
       
   802 #define REG_PATTERN_TEST(reg, mask, write)                                     \
       
   803 	REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
       
   804 
       
   805 #define REG_SET_AND_CHECK(reg, mask, write)                                    \
       
   806 	do {                                                                   \
       
   807 		if (reg_set_and_check(adapter, data, reg, mask, write))        \
       
   808 			return 1;                                              \
       
   809 	} while (0)
       
   810 
       
   811 static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
       
   812 {
       
   813 	struct e1000_hw *hw = &adapter->hw;
       
   814 	struct e1000_mac_info *mac = &adapter->hw.mac;
       
   815 	u32 value;
       
   816 	u32 before;
       
   817 	u32 after;
       
   818 	u32 i;
       
   819 	u32 toggle;
       
   820 	u32 mask;
       
   821 
       
   822 	/*
       
   823 	 * The status register is Read Only, so a write should fail.
       
   824 	 * Some bits that get toggled are ignored.
       
   825 	 */
       
   826 	switch (mac->type) {
       
   827 	/* there are several bits on newer hardware that are r/w */
       
   828 	case e1000_82571:
       
   829 	case e1000_82572:
       
   830 	case e1000_80003es2lan:
       
   831 		toggle = 0x7FFFF3FF;
       
   832 		break;
       
   833         default:
       
   834 		toggle = 0x7FFFF033;
       
   835 		break;
       
   836 	}
       
   837 
       
   838 	before = er32(STATUS);
       
   839 	value = (er32(STATUS) & toggle);
       
   840 	ew32(STATUS, toggle);
       
   841 	after = er32(STATUS) & toggle;
       
   842 	if (value != after) {
       
   843 		e_err("failed STATUS register test got: 0x%08X expected: "
       
   844 		      "0x%08X\n", after, value);
       
   845 		*data = 1;
       
   846 		return 1;
       
   847 	}
       
   848 	/* restore previous status */
       
   849 	ew32(STATUS, before);
       
   850 
       
   851 	if (!(adapter->flags & FLAG_IS_ICH)) {
       
   852 		REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
       
   853 		REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
       
   854 		REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
       
   855 		REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
       
   856 	}
       
   857 
       
   858 	REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
       
   859 	REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
       
   860 	REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
       
   861 	REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
       
   862 	REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
       
   863 	REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
       
   864 	REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
       
   865 	REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
       
   866 	REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
       
   867 	REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
       
   868 
       
   869 	REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
       
   870 
       
   871 	before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
       
   872 	REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
       
   873 	REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
       
   874 
       
   875 	REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
       
   876 	REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
       
   877 	if (!(adapter->flags & FLAG_IS_ICH))
       
   878 		REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
       
   879 	REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
       
   880 	REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
       
   881 	mask = 0x8003FFFF;
       
   882 	switch (mac->type) {
       
   883 	case e1000_ich10lan:
       
   884 	case e1000_pchlan:
       
   885 	case e1000_pch2lan:
       
   886 		mask |= (1 << 18);
       
   887 		break;
       
   888 	default:
       
   889 		break;
       
   890 	}
       
   891 	for (i = 0; i < mac->rar_entry_count; i++)
       
   892 		REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
       
   893 		                       mask, 0xFFFFFFFF);
       
   894 
       
   895 	for (i = 0; i < mac->mta_reg_count; i++)
       
   896 		REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
       
   897 
       
   898 	*data = 0;
       
   899 	return 0;
       
   900 }
       
   901 
       
   902 static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
       
   903 {
       
   904 	u16 temp;
       
   905 	u16 checksum = 0;
       
   906 	u16 i;
       
   907 
       
   908 	*data = 0;
       
   909 	/* Read and add up the contents of the EEPROM */
       
   910 	for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
       
   911 		if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
       
   912 			*data = 1;
       
   913 			return *data;
       
   914 		}
       
   915 		checksum += temp;
       
   916 	}
       
   917 
       
   918 	/* If Checksum is not Correct return error else test passed */
       
   919 	if ((checksum != (u16) NVM_SUM) && !(*data))
       
   920 		*data = 2;
       
   921 
       
   922 	return *data;
       
   923 }
       
   924 
       
   925 static irqreturn_t e1000_test_intr(int irq, void *data)
       
   926 {
       
   927 	struct net_device *netdev = (struct net_device *) data;
       
   928 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
   929 	struct e1000_hw *hw = &adapter->hw;
       
   930 
       
   931 	adapter->test_icr |= er32(ICR);
       
   932 
       
   933 	return IRQ_HANDLED;
       
   934 }
       
   935 
       
   936 static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
       
   937 {
       
   938 	struct net_device *netdev = adapter->netdev;
       
   939 	struct e1000_hw *hw = &adapter->hw;
       
   940 	u32 mask;
       
   941 	u32 shared_int = 1;
       
   942 	u32 irq = adapter->pdev->irq;
       
   943 	int i;
       
   944 	int ret_val = 0;
       
   945 	int int_mode = E1000E_INT_MODE_LEGACY;
       
   946 
       
   947 	*data = 0;
       
   948 
       
   949 	/* NOTE: we don't test MSI/MSI-X interrupts here, yet */
       
   950 	if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
       
   951 		int_mode = adapter->int_mode;
       
   952 		e1000e_reset_interrupt_capability(adapter);
       
   953 		adapter->int_mode = E1000E_INT_MODE_LEGACY;
       
   954 		e1000e_set_interrupt_capability(adapter);
       
   955 	}
       
   956 	/* Hook up test interrupt handler just for this test */
       
   957 	if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
       
   958 			 netdev)) {
       
   959 		shared_int = 0;
       
   960 	} else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
       
   961 		 netdev->name, netdev)) {
       
   962 		*data = 1;
       
   963 		ret_val = -1;
       
   964 		goto out;
       
   965 	}
       
   966 	e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
       
   967 
       
   968 	/* Disable all the interrupts */
       
   969 	ew32(IMC, 0xFFFFFFFF);
       
   970 	msleep(10);
       
   971 
       
   972 	/* Test each interrupt */
       
   973 	for (i = 0; i < 10; i++) {
       
   974 		/* Interrupt to test */
       
   975 		mask = 1 << i;
       
   976 
       
   977 		if (adapter->flags & FLAG_IS_ICH) {
       
   978 			switch (mask) {
       
   979 			case E1000_ICR_RXSEQ:
       
   980 				continue;
       
   981 			case 0x00000100:
       
   982 				if (adapter->hw.mac.type == e1000_ich8lan ||
       
   983 				    adapter->hw.mac.type == e1000_ich9lan)
       
   984 					continue;
       
   985 				break;
       
   986 			default:
       
   987 				break;
       
   988 			}
       
   989 		}
       
   990 
       
   991 		if (!shared_int) {
       
   992 			/*
       
   993 			 * Disable the interrupt to be reported in
       
   994 			 * the cause register and then force the same
       
   995 			 * interrupt and see if one gets posted.  If
       
   996 			 * an interrupt was posted to the bus, the
       
   997 			 * test failed.
       
   998 			 */
       
   999 			adapter->test_icr = 0;
       
  1000 			ew32(IMC, mask);
       
  1001 			ew32(ICS, mask);
       
  1002 			msleep(10);
       
  1003 
       
  1004 			if (adapter->test_icr & mask) {
       
  1005 				*data = 3;
       
  1006 				break;
       
  1007 			}
       
  1008 		}
       
  1009 
       
  1010 		/*
       
  1011 		 * Enable the interrupt to be reported in
       
  1012 		 * the cause register and then force the same
       
  1013 		 * interrupt and see if one gets posted.  If
       
  1014 		 * an interrupt was not posted to the bus, the
       
  1015 		 * test failed.
       
  1016 		 */
       
  1017 		adapter->test_icr = 0;
       
  1018 		ew32(IMS, mask);
       
  1019 		ew32(ICS, mask);
       
  1020 		msleep(10);
       
  1021 
       
  1022 		if (!(adapter->test_icr & mask)) {
       
  1023 			*data = 4;
       
  1024 			break;
       
  1025 		}
       
  1026 
       
  1027 		if (!shared_int) {
       
  1028 			/*
       
  1029 			 * Disable the other interrupts to be reported in
       
  1030 			 * the cause register and then force the other
       
  1031 			 * interrupts and see if any get posted.  If
       
  1032 			 * an interrupt was posted to the bus, the
       
  1033 			 * test failed.
       
  1034 			 */
       
  1035 			adapter->test_icr = 0;
       
  1036 			ew32(IMC, ~mask & 0x00007FFF);
       
  1037 			ew32(ICS, ~mask & 0x00007FFF);
       
  1038 			msleep(10);
       
  1039 
       
  1040 			if (adapter->test_icr) {
       
  1041 				*data = 5;
       
  1042 				break;
       
  1043 			}
       
  1044 		}
       
  1045 	}
       
  1046 
       
  1047 	/* Disable all the interrupts */
       
  1048 	ew32(IMC, 0xFFFFFFFF);
       
  1049 	msleep(10);
       
  1050 
       
  1051 	/* Unhook test interrupt handler */
       
  1052 	free_irq(irq, netdev);
       
  1053 
       
  1054 out:
       
  1055 	if (int_mode == E1000E_INT_MODE_MSIX) {
       
  1056 		e1000e_reset_interrupt_capability(adapter);
       
  1057 		adapter->int_mode = int_mode;
       
  1058 		e1000e_set_interrupt_capability(adapter);
       
  1059 	}
       
  1060 
       
  1061 	return ret_val;
       
  1062 }
       
  1063 
       
  1064 static void e1000_free_desc_rings(struct e1000_adapter *adapter)
       
  1065 {
       
  1066 	struct e1000_ring *tx_ring = &adapter->test_tx_ring;
       
  1067 	struct e1000_ring *rx_ring = &adapter->test_rx_ring;
       
  1068 	struct pci_dev *pdev = adapter->pdev;
       
  1069 	int i;
       
  1070 
       
  1071 	if (tx_ring->desc && tx_ring->buffer_info) {
       
  1072 		for (i = 0; i < tx_ring->count; i++) {
       
  1073 			if (tx_ring->buffer_info[i].dma)
       
  1074 				dma_unmap_single(&pdev->dev,
       
  1075 					tx_ring->buffer_info[i].dma,
       
  1076 					tx_ring->buffer_info[i].length,
       
  1077 					DMA_TO_DEVICE);
       
  1078 			if (tx_ring->buffer_info[i].skb)
       
  1079 				dev_kfree_skb(tx_ring->buffer_info[i].skb);
       
  1080 		}
       
  1081 	}
       
  1082 
       
  1083 	if (rx_ring->desc && rx_ring->buffer_info) {
       
  1084 		for (i = 0; i < rx_ring->count; i++) {
       
  1085 			if (rx_ring->buffer_info[i].dma)
       
  1086 				dma_unmap_single(&pdev->dev,
       
  1087 					rx_ring->buffer_info[i].dma,
       
  1088 					2048, DMA_FROM_DEVICE);
       
  1089 			if (rx_ring->buffer_info[i].skb)
       
  1090 				dev_kfree_skb(rx_ring->buffer_info[i].skb);
       
  1091 		}
       
  1092 	}
       
  1093 
       
  1094 	if (tx_ring->desc) {
       
  1095 		dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
       
  1096 				  tx_ring->dma);
       
  1097 		tx_ring->desc = NULL;
       
  1098 	}
       
  1099 	if (rx_ring->desc) {
       
  1100 		dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
       
  1101 				  rx_ring->dma);
       
  1102 		rx_ring->desc = NULL;
       
  1103 	}
       
  1104 
       
  1105 	kfree(tx_ring->buffer_info);
       
  1106 	tx_ring->buffer_info = NULL;
       
  1107 	kfree(rx_ring->buffer_info);
       
  1108 	rx_ring->buffer_info = NULL;
       
  1109 }
       
  1110 
       
  1111 static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
       
  1112 {
       
  1113 	struct e1000_ring *tx_ring = &adapter->test_tx_ring;
       
  1114 	struct e1000_ring *rx_ring = &adapter->test_rx_ring;
       
  1115 	struct pci_dev *pdev = adapter->pdev;
       
  1116 	struct e1000_hw *hw = &adapter->hw;
       
  1117 	u32 rctl;
       
  1118 	int i;
       
  1119 	int ret_val;
       
  1120 
       
  1121 	/* Setup Tx descriptor ring and Tx buffers */
       
  1122 
       
  1123 	if (!tx_ring->count)
       
  1124 		tx_ring->count = E1000_DEFAULT_TXD;
       
  1125 
       
  1126 	tx_ring->buffer_info = kcalloc(tx_ring->count,
       
  1127 				       sizeof(struct e1000_buffer),
       
  1128 				       GFP_KERNEL);
       
  1129 	if (!(tx_ring->buffer_info)) {
       
  1130 		ret_val = 1;
       
  1131 		goto err_nomem;
       
  1132 	}
       
  1133 
       
  1134 	tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
       
  1135 	tx_ring->size = ALIGN(tx_ring->size, 4096);
       
  1136 	tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
       
  1137 					   &tx_ring->dma, GFP_KERNEL);
       
  1138 	if (!tx_ring->desc) {
       
  1139 		ret_val = 2;
       
  1140 		goto err_nomem;
       
  1141 	}
       
  1142 	tx_ring->next_to_use = 0;
       
  1143 	tx_ring->next_to_clean = 0;
       
  1144 
       
  1145 	ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
       
  1146 	ew32(TDBAH, ((u64) tx_ring->dma >> 32));
       
  1147 	ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
       
  1148 	ew32(TDH, 0);
       
  1149 	ew32(TDT, 0);
       
  1150 	ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
       
  1151 	     E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
       
  1152 	     E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
       
  1153 
       
  1154 	for (i = 0; i < tx_ring->count; i++) {
       
  1155 		struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
       
  1156 		struct sk_buff *skb;
       
  1157 		unsigned int skb_size = 1024;
       
  1158 
       
  1159 		skb = alloc_skb(skb_size, GFP_KERNEL);
       
  1160 		if (!skb) {
       
  1161 			ret_val = 3;
       
  1162 			goto err_nomem;
       
  1163 		}
       
  1164 		skb_put(skb, skb_size);
       
  1165 		tx_ring->buffer_info[i].skb = skb;
       
  1166 		tx_ring->buffer_info[i].length = skb->len;
       
  1167 		tx_ring->buffer_info[i].dma =
       
  1168 			dma_map_single(&pdev->dev, skb->data, skb->len,
       
  1169 				       DMA_TO_DEVICE);
       
  1170 		if (dma_mapping_error(&pdev->dev,
       
  1171 				      tx_ring->buffer_info[i].dma)) {
       
  1172 			ret_val = 4;
       
  1173 			goto err_nomem;
       
  1174 		}
       
  1175 		tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
       
  1176 		tx_desc->lower.data = cpu_to_le32(skb->len);
       
  1177 		tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
       
  1178 						   E1000_TXD_CMD_IFCS |
       
  1179 						   E1000_TXD_CMD_RS);
       
  1180 		tx_desc->upper.data = 0;
       
  1181 	}
       
  1182 
       
  1183 	/* Setup Rx descriptor ring and Rx buffers */
       
  1184 
       
  1185 	if (!rx_ring->count)
       
  1186 		rx_ring->count = E1000_DEFAULT_RXD;
       
  1187 
       
  1188 	rx_ring->buffer_info = kcalloc(rx_ring->count,
       
  1189 				       sizeof(struct e1000_buffer),
       
  1190 				       GFP_KERNEL);
       
  1191 	if (!(rx_ring->buffer_info)) {
       
  1192 		ret_val = 5;
       
  1193 		goto err_nomem;
       
  1194 	}
       
  1195 
       
  1196 	rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
       
  1197 	rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
       
  1198 					   &rx_ring->dma, GFP_KERNEL);
       
  1199 	if (!rx_ring->desc) {
       
  1200 		ret_val = 6;
       
  1201 		goto err_nomem;
       
  1202 	}
       
  1203 	rx_ring->next_to_use = 0;
       
  1204 	rx_ring->next_to_clean = 0;
       
  1205 
       
  1206 	rctl = er32(RCTL);
       
  1207 	ew32(RCTL, rctl & ~E1000_RCTL_EN);
       
  1208 	ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
       
  1209 	ew32(RDBAH, ((u64) rx_ring->dma >> 32));
       
  1210 	ew32(RDLEN, rx_ring->size);
       
  1211 	ew32(RDH, 0);
       
  1212 	ew32(RDT, 0);
       
  1213 	rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
       
  1214 		E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
       
  1215 		E1000_RCTL_SBP | E1000_RCTL_SECRC |
       
  1216 		E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
       
  1217 		(adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
       
  1218 	ew32(RCTL, rctl);
       
  1219 
       
  1220 	for (i = 0; i < rx_ring->count; i++) {
       
  1221 		struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
       
  1222 		struct sk_buff *skb;
       
  1223 
       
  1224 		skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
       
  1225 		if (!skb) {
       
  1226 			ret_val = 7;
       
  1227 			goto err_nomem;
       
  1228 		}
       
  1229 		skb_reserve(skb, NET_IP_ALIGN);
       
  1230 		rx_ring->buffer_info[i].skb = skb;
       
  1231 		rx_ring->buffer_info[i].dma =
       
  1232 			dma_map_single(&pdev->dev, skb->data, 2048,
       
  1233 				       DMA_FROM_DEVICE);
       
  1234 		if (dma_mapping_error(&pdev->dev,
       
  1235 				      rx_ring->buffer_info[i].dma)) {
       
  1236 			ret_val = 8;
       
  1237 			goto err_nomem;
       
  1238 		}
       
  1239 		rx_desc->buffer_addr =
       
  1240 			cpu_to_le64(rx_ring->buffer_info[i].dma);
       
  1241 		memset(skb->data, 0x00, skb->len);
       
  1242 	}
       
  1243 
       
  1244 	return 0;
       
  1245 
       
  1246 err_nomem:
       
  1247 	e1000_free_desc_rings(adapter);
       
  1248 	return ret_val;
       
  1249 }
       
  1250 
       
  1251 static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
       
  1252 {
       
  1253 	/* Write out to PHY registers 29 and 30 to disable the Receiver. */
       
  1254 	e1e_wphy(&adapter->hw, 29, 0x001F);
       
  1255 	e1e_wphy(&adapter->hw, 30, 0x8FFC);
       
  1256 	e1e_wphy(&adapter->hw, 29, 0x001A);
       
  1257 	e1e_wphy(&adapter->hw, 30, 0x8FF0);
       
  1258 }
       
  1259 
       
  1260 static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
       
  1261 {
       
  1262 	struct e1000_hw *hw = &adapter->hw;
       
  1263 	u32 ctrl_reg = 0;
       
  1264 	u32 stat_reg = 0;
       
  1265 	u16 phy_reg = 0;
       
  1266 
       
  1267 	hw->mac.autoneg = 0;
       
  1268 
       
  1269 	if (hw->phy.type == e1000_phy_ife) {
       
  1270 		/* force 100, set loopback */
       
  1271 		e1e_wphy(hw, PHY_CONTROL, 0x6100);
       
  1272 
       
  1273 		/* Now set up the MAC to the same speed/duplex as the PHY. */
       
  1274 		ctrl_reg = er32(CTRL);
       
  1275 		ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
       
  1276 		ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
       
  1277 			     E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
       
  1278 			     E1000_CTRL_SPD_100 |/* Force Speed to 100 */
       
  1279 			     E1000_CTRL_FD);	 /* Force Duplex to FULL */
       
  1280 
       
  1281 		ew32(CTRL, ctrl_reg);
       
  1282 		udelay(500);
       
  1283 
       
  1284 		return 0;
       
  1285 	}
       
  1286 
       
  1287 	/* Specific PHY configuration for loopback */
       
  1288 	switch (hw->phy.type) {
       
  1289 	case e1000_phy_m88:
       
  1290 		/* Auto-MDI/MDIX Off */
       
  1291 		e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
       
  1292 		/* reset to update Auto-MDI/MDIX */
       
  1293 		e1e_wphy(hw, PHY_CONTROL, 0x9140);
       
  1294 		/* autoneg off */
       
  1295 		e1e_wphy(hw, PHY_CONTROL, 0x8140);
       
  1296 		break;
       
  1297 	case e1000_phy_gg82563:
       
  1298 		e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
       
  1299 		break;
       
  1300 	case e1000_phy_bm:
       
  1301 		/* Set Default MAC Interface speed to 1GB */
       
  1302 		e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
       
  1303 		phy_reg &= ~0x0007;
       
  1304 		phy_reg |= 0x006;
       
  1305 		e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
       
  1306 		/* Assert SW reset for above settings to take effect */
       
  1307 		e1000e_commit_phy(hw);
       
  1308 		mdelay(1);
       
  1309 		/* Force Full Duplex */
       
  1310 		e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
       
  1311 		e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
       
  1312 		/* Set Link Up (in force link) */
       
  1313 		e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
       
  1314 		e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
       
  1315 		/* Force Link */
       
  1316 		e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
       
  1317 		e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
       
  1318 		/* Set Early Link Enable */
       
  1319 		e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
       
  1320 		e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
       
  1321 		break;
       
  1322 	case e1000_phy_82577:
       
  1323 	case e1000_phy_82578:
       
  1324 		/* Workaround: K1 must be disabled for stable 1Gbps operation */
       
  1325 		e1000_configure_k1_ich8lan(hw, false);
       
  1326 		break;
       
  1327 	case e1000_phy_82579:
       
  1328 		/* Disable PHY energy detect power down */
       
  1329 		e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
       
  1330 		e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
       
  1331 		/* Disable full chip energy detect */
       
  1332 		e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
       
  1333 		e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
       
  1334 		/* Enable loopback on the PHY */
       
  1335 #define I82577_PHY_LBK_CTRL          19
       
  1336 		e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
       
  1337 		break;
       
  1338 	default:
       
  1339 		break;
       
  1340 	}
       
  1341 
       
  1342 	/* force 1000, set loopback */
       
  1343 	e1e_wphy(hw, PHY_CONTROL, 0x4140);
       
  1344 	mdelay(250);
       
  1345 
       
  1346 	/* Now set up the MAC to the same speed/duplex as the PHY. */
       
  1347 	ctrl_reg = er32(CTRL);
       
  1348 	ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
       
  1349 	ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
       
  1350 		     E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
       
  1351 		     E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
       
  1352 		     E1000_CTRL_FD);	 /* Force Duplex to FULL */
       
  1353 
       
  1354 	if (adapter->flags & FLAG_IS_ICH)
       
  1355 		ctrl_reg |= E1000_CTRL_SLU;	/* Set Link Up */
       
  1356 
       
  1357 	if (hw->phy.media_type == e1000_media_type_copper &&
       
  1358 	    hw->phy.type == e1000_phy_m88) {
       
  1359 		ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
       
  1360 	} else {
       
  1361 		/*
       
  1362 		 * Set the ILOS bit on the fiber Nic if half duplex link is
       
  1363 		 * detected.
       
  1364 		 */
       
  1365 		stat_reg = er32(STATUS);
       
  1366 		if ((stat_reg & E1000_STATUS_FD) == 0)
       
  1367 			ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
       
  1368 	}
       
  1369 
       
  1370 	ew32(CTRL, ctrl_reg);
       
  1371 
       
  1372 	/*
       
  1373 	 * Disable the receiver on the PHY so when a cable is plugged in, the
       
  1374 	 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
       
  1375 	 */
       
  1376 	if (hw->phy.type == e1000_phy_m88)
       
  1377 		e1000_phy_disable_receiver(adapter);
       
  1378 
       
  1379 	udelay(500);
       
  1380 
       
  1381 	return 0;
       
  1382 }
       
  1383 
       
  1384 static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
       
  1385 {
       
  1386 	struct e1000_hw *hw = &adapter->hw;
       
  1387 	u32 ctrl = er32(CTRL);
       
  1388 	int link = 0;
       
  1389 
       
  1390 	/* special requirements for 82571/82572 fiber adapters */
       
  1391 
       
  1392 	/*
       
  1393 	 * jump through hoops to make sure link is up because serdes
       
  1394 	 * link is hardwired up
       
  1395 	 */
       
  1396 	ctrl |= E1000_CTRL_SLU;
       
  1397 	ew32(CTRL, ctrl);
       
  1398 
       
  1399 	/* disable autoneg */
       
  1400 	ctrl = er32(TXCW);
       
  1401 	ctrl &= ~(1 << 31);
       
  1402 	ew32(TXCW, ctrl);
       
  1403 
       
  1404 	link = (er32(STATUS) & E1000_STATUS_LU);
       
  1405 
       
  1406 	if (!link) {
       
  1407 		/* set invert loss of signal */
       
  1408 		ctrl = er32(CTRL);
       
  1409 		ctrl |= E1000_CTRL_ILOS;
       
  1410 		ew32(CTRL, ctrl);
       
  1411 	}
       
  1412 
       
  1413 	/*
       
  1414 	 * special write to serdes control register to enable SerDes analog
       
  1415 	 * loopback
       
  1416 	 */
       
  1417 #define E1000_SERDES_LB_ON 0x410
       
  1418 	ew32(SCTL, E1000_SERDES_LB_ON);
       
  1419 	msleep(10);
       
  1420 
       
  1421 	return 0;
       
  1422 }
       
  1423 
       
  1424 /* only call this for fiber/serdes connections to es2lan */
       
  1425 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
       
  1426 {
       
  1427 	struct e1000_hw *hw = &adapter->hw;
       
  1428 	u32 ctrlext = er32(CTRL_EXT);
       
  1429 	u32 ctrl = er32(CTRL);
       
  1430 
       
  1431 	/*
       
  1432 	 * save CTRL_EXT to restore later, reuse an empty variable (unused
       
  1433 	 * on mac_type 80003es2lan)
       
  1434 	 */
       
  1435 	adapter->tx_fifo_head = ctrlext;
       
  1436 
       
  1437 	/* clear the serdes mode bits, putting the device into mac loopback */
       
  1438 	ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
       
  1439 	ew32(CTRL_EXT, ctrlext);
       
  1440 
       
  1441 	/* force speed to 1000/FD, link up */
       
  1442 	ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
       
  1443 	ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
       
  1444 		 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
       
  1445 	ew32(CTRL, ctrl);
       
  1446 
       
  1447 	/* set mac loopback */
       
  1448 	ctrl = er32(RCTL);
       
  1449 	ctrl |= E1000_RCTL_LBM_MAC;
       
  1450 	ew32(RCTL, ctrl);
       
  1451 
       
  1452 	/* set testing mode parameters (no need to reset later) */
       
  1453 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
       
  1454 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
       
  1455 	ew32(KMRNCTRLSTA,
       
  1456 	     (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
       
  1457 
       
  1458 	return 0;
       
  1459 }
       
  1460 
       
  1461 static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
       
  1462 {
       
  1463 	struct e1000_hw *hw = &adapter->hw;
       
  1464 	u32 rctl;
       
  1465 
       
  1466 	if (hw->phy.media_type == e1000_media_type_fiber ||
       
  1467 	    hw->phy.media_type == e1000_media_type_internal_serdes) {
       
  1468 		switch (hw->mac.type) {
       
  1469 		case e1000_80003es2lan:
       
  1470 			return e1000_set_es2lan_mac_loopback(adapter);
       
  1471 			break;
       
  1472 		case e1000_82571:
       
  1473 		case e1000_82572:
       
  1474 			return e1000_set_82571_fiber_loopback(adapter);
       
  1475 			break;
       
  1476 		default:
       
  1477 			rctl = er32(RCTL);
       
  1478 			rctl |= E1000_RCTL_LBM_TCVR;
       
  1479 			ew32(RCTL, rctl);
       
  1480 			return 0;
       
  1481 		}
       
  1482 	} else if (hw->phy.media_type == e1000_media_type_copper) {
       
  1483 		return e1000_integrated_phy_loopback(adapter);
       
  1484 	}
       
  1485 
       
  1486 	return 7;
       
  1487 }
       
  1488 
       
  1489 static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
       
  1490 {
       
  1491 	struct e1000_hw *hw = &adapter->hw;
       
  1492 	u32 rctl;
       
  1493 	u16 phy_reg;
       
  1494 
       
  1495 	rctl = er32(RCTL);
       
  1496 	rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
       
  1497 	ew32(RCTL, rctl);
       
  1498 
       
  1499 	switch (hw->mac.type) {
       
  1500 	case e1000_80003es2lan:
       
  1501 		if (hw->phy.media_type == e1000_media_type_fiber ||
       
  1502 		    hw->phy.media_type == e1000_media_type_internal_serdes) {
       
  1503 			/* restore CTRL_EXT, stealing space from tx_fifo_head */
       
  1504 			ew32(CTRL_EXT, adapter->tx_fifo_head);
       
  1505 			adapter->tx_fifo_head = 0;
       
  1506 		}
       
  1507 		/* fall through */
       
  1508 	case e1000_82571:
       
  1509 	case e1000_82572:
       
  1510 		if (hw->phy.media_type == e1000_media_type_fiber ||
       
  1511 		    hw->phy.media_type == e1000_media_type_internal_serdes) {
       
  1512 #define E1000_SERDES_LB_OFF 0x400
       
  1513 			ew32(SCTL, E1000_SERDES_LB_OFF);
       
  1514 			msleep(10);
       
  1515 			break;
       
  1516 		}
       
  1517 		/* Fall Through */
       
  1518 	default:
       
  1519 		hw->mac.autoneg = 1;
       
  1520 		if (hw->phy.type == e1000_phy_gg82563)
       
  1521 			e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
       
  1522 		e1e_rphy(hw, PHY_CONTROL, &phy_reg);
       
  1523 		if (phy_reg & MII_CR_LOOPBACK) {
       
  1524 			phy_reg &= ~MII_CR_LOOPBACK;
       
  1525 			e1e_wphy(hw, PHY_CONTROL, phy_reg);
       
  1526 			e1000e_commit_phy(hw);
       
  1527 		}
       
  1528 		break;
       
  1529 	}
       
  1530 }
       
  1531 
       
  1532 static void e1000_create_lbtest_frame(struct sk_buff *skb,
       
  1533 				      unsigned int frame_size)
       
  1534 {
       
  1535 	memset(skb->data, 0xFF, frame_size);
       
  1536 	frame_size &= ~1;
       
  1537 	memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
       
  1538 	memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
       
  1539 	memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
       
  1540 }
       
  1541 
       
  1542 static int e1000_check_lbtest_frame(struct sk_buff *skb,
       
  1543 				    unsigned int frame_size)
       
  1544 {
       
  1545 	frame_size &= ~1;
       
  1546 	if (*(skb->data + 3) == 0xFF)
       
  1547 		if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
       
  1548 		   (*(skb->data + frame_size / 2 + 12) == 0xAF))
       
  1549 			return 0;
       
  1550 	return 13;
       
  1551 }
       
  1552 
       
  1553 static int e1000_run_loopback_test(struct e1000_adapter *adapter)
       
  1554 {
       
  1555 	struct e1000_ring *tx_ring = &adapter->test_tx_ring;
       
  1556 	struct e1000_ring *rx_ring = &adapter->test_rx_ring;
       
  1557 	struct pci_dev *pdev = adapter->pdev;
       
  1558 	struct e1000_hw *hw = &adapter->hw;
       
  1559 	int i, j, k, l;
       
  1560 	int lc;
       
  1561 	int good_cnt;
       
  1562 	int ret_val = 0;
       
  1563 	unsigned long time;
       
  1564 
       
  1565 	ew32(RDT, rx_ring->count - 1);
       
  1566 
       
  1567 	/*
       
  1568 	 * Calculate the loop count based on the largest descriptor ring
       
  1569 	 * The idea is to wrap the largest ring a number of times using 64
       
  1570 	 * send/receive pairs during each loop
       
  1571 	 */
       
  1572 
       
  1573 	if (rx_ring->count <= tx_ring->count)
       
  1574 		lc = ((tx_ring->count / 64) * 2) + 1;
       
  1575 	else
       
  1576 		lc = ((rx_ring->count / 64) * 2) + 1;
       
  1577 
       
  1578 	k = 0;
       
  1579 	l = 0;
       
  1580 	for (j = 0; j <= lc; j++) { /* loop count loop */
       
  1581 		for (i = 0; i < 64; i++) { /* send the packets */
       
  1582 			e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
       
  1583 						  1024);
       
  1584 			dma_sync_single_for_device(&pdev->dev,
       
  1585 					tx_ring->buffer_info[k].dma,
       
  1586 					tx_ring->buffer_info[k].length,
       
  1587 					DMA_TO_DEVICE);
       
  1588 			k++;
       
  1589 			if (k == tx_ring->count)
       
  1590 				k = 0;
       
  1591 		}
       
  1592 		ew32(TDT, k);
       
  1593 		msleep(200);
       
  1594 		time = jiffies; /* set the start time for the receive */
       
  1595 		good_cnt = 0;
       
  1596 		do { /* receive the sent packets */
       
  1597 			dma_sync_single_for_cpu(&pdev->dev,
       
  1598 					rx_ring->buffer_info[l].dma, 2048,
       
  1599 					DMA_FROM_DEVICE);
       
  1600 
       
  1601 			ret_val = e1000_check_lbtest_frame(
       
  1602 					rx_ring->buffer_info[l].skb, 1024);
       
  1603 			if (!ret_val)
       
  1604 				good_cnt++;
       
  1605 			l++;
       
  1606 			if (l == rx_ring->count)
       
  1607 				l = 0;
       
  1608 			/*
       
  1609 			 * time + 20 msecs (200 msecs on 2.4) is more than
       
  1610 			 * enough time to complete the receives, if it's
       
  1611 			 * exceeded, break and error off
       
  1612 			 */
       
  1613 		} while ((good_cnt < 64) && !time_after(jiffies, time + 20));
       
  1614 		if (good_cnt != 64) {
       
  1615 			ret_val = 13; /* ret_val is the same as mis-compare */
       
  1616 			break;
       
  1617 		}
       
  1618 		if (jiffies >= (time + 20)) {
       
  1619 			ret_val = 14; /* error code for time out error */
       
  1620 			break;
       
  1621 		}
       
  1622 	} /* end loop count loop */
       
  1623 	return ret_val;
       
  1624 }
       
  1625 
       
  1626 static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
       
  1627 {
       
  1628 	/*
       
  1629 	 * PHY loopback cannot be performed if SoL/IDER
       
  1630 	 * sessions are active
       
  1631 	 */
       
  1632 	if (e1000_check_reset_block(&adapter->hw)) {
       
  1633 		e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
       
  1634 		*data = 0;
       
  1635 		goto out;
       
  1636 	}
       
  1637 
       
  1638 	*data = e1000_setup_desc_rings(adapter);
       
  1639 	if (*data)
       
  1640 		goto out;
       
  1641 
       
  1642 	*data = e1000_setup_loopback_test(adapter);
       
  1643 	if (*data)
       
  1644 		goto err_loopback;
       
  1645 
       
  1646 	*data = e1000_run_loopback_test(adapter);
       
  1647 	e1000_loopback_cleanup(adapter);
       
  1648 
       
  1649 err_loopback:
       
  1650 	e1000_free_desc_rings(adapter);
       
  1651 out:
       
  1652 	return *data;
       
  1653 }
       
  1654 
       
  1655 static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
       
  1656 {
       
  1657 	struct e1000_hw *hw = &adapter->hw;
       
  1658 
       
  1659 	*data = 0;
       
  1660 	if (hw->phy.media_type == e1000_media_type_internal_serdes) {
       
  1661 		int i = 0;
       
  1662 		hw->mac.serdes_has_link = false;
       
  1663 
       
  1664 		/*
       
  1665 		 * On some blade server designs, link establishment
       
  1666 		 * could take as long as 2-3 minutes
       
  1667 		 */
       
  1668 		do {
       
  1669 			hw->mac.ops.check_for_link(hw);
       
  1670 			if (hw->mac.serdes_has_link)
       
  1671 				return *data;
       
  1672 			msleep(20);
       
  1673 		} while (i++ < 3750);
       
  1674 
       
  1675 		*data = 1;
       
  1676 	} else {
       
  1677 		hw->mac.ops.check_for_link(hw);
       
  1678 		if (hw->mac.autoneg)
       
  1679 			msleep(4000);
       
  1680 
       
  1681 		if (!(er32(STATUS) &
       
  1682 		      E1000_STATUS_LU))
       
  1683 			*data = 1;
       
  1684 	}
       
  1685 	return *data;
       
  1686 }
       
  1687 
       
  1688 static int e1000e_get_sset_count(struct net_device *netdev, int sset)
       
  1689 {
       
  1690 	switch (sset) {
       
  1691 	case ETH_SS_TEST:
       
  1692 		return E1000_TEST_LEN;
       
  1693 	case ETH_SS_STATS:
       
  1694 		return E1000_STATS_LEN;
       
  1695 	default:
       
  1696 		return -EOPNOTSUPP;
       
  1697 	}
       
  1698 }
       
  1699 
       
  1700 static void e1000_diag_test(struct net_device *netdev,
       
  1701 			    struct ethtool_test *eth_test, u64 *data)
       
  1702 {
       
  1703 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1704 	u16 autoneg_advertised;
       
  1705 	u8 forced_speed_duplex;
       
  1706 	u8 autoneg;
       
  1707 	bool if_running = netif_running(netdev);
       
  1708 
       
  1709 	set_bit(__E1000_TESTING, &adapter->state);
       
  1710 	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
       
  1711 		/* Offline tests */
       
  1712 
       
  1713 		/* save speed, duplex, autoneg settings */
       
  1714 		autoneg_advertised = adapter->hw.phy.autoneg_advertised;
       
  1715 		forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
       
  1716 		autoneg = adapter->hw.mac.autoneg;
       
  1717 
       
  1718 		e_info("offline testing starting\n");
       
  1719 
       
  1720 		if (if_running)
       
  1721 			/* indicate we're in test mode */
       
  1722 			dev_close(netdev);
       
  1723 		else
       
  1724 			e1000e_reset(adapter);
       
  1725 
       
  1726 		if (e1000_reg_test(adapter, &data[0]))
       
  1727 			eth_test->flags |= ETH_TEST_FL_FAILED;
       
  1728 
       
  1729 		e1000e_reset(adapter);
       
  1730 		if (e1000_eeprom_test(adapter, &data[1]))
       
  1731 			eth_test->flags |= ETH_TEST_FL_FAILED;
       
  1732 
       
  1733 		e1000e_reset(adapter);
       
  1734 		if (e1000_intr_test(adapter, &data[2]))
       
  1735 			eth_test->flags |= ETH_TEST_FL_FAILED;
       
  1736 
       
  1737 		e1000e_reset(adapter);
       
  1738 		/* make sure the phy is powered up */
       
  1739 		e1000e_power_up_phy(adapter);
       
  1740 		if (e1000_loopback_test(adapter, &data[3]))
       
  1741 			eth_test->flags |= ETH_TEST_FL_FAILED;
       
  1742 
       
  1743 		/* force this routine to wait until autoneg complete/timeout */
       
  1744 		adapter->hw.phy.autoneg_wait_to_complete = 1;
       
  1745 		e1000e_reset(adapter);
       
  1746 		adapter->hw.phy.autoneg_wait_to_complete = 0;
       
  1747 
       
  1748 		if (e1000_link_test(adapter, &data[4]))
       
  1749 			eth_test->flags |= ETH_TEST_FL_FAILED;
       
  1750 
       
  1751 		/* restore speed, duplex, autoneg settings */
       
  1752 		adapter->hw.phy.autoneg_advertised = autoneg_advertised;
       
  1753 		adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
       
  1754 		adapter->hw.mac.autoneg = autoneg;
       
  1755 		e1000e_reset(adapter);
       
  1756 
       
  1757 		clear_bit(__E1000_TESTING, &adapter->state);
       
  1758 		if (if_running)
       
  1759 			dev_open(netdev);
       
  1760 	} else {
       
  1761 		if (!if_running && (adapter->flags & FLAG_HAS_AMT)) {
       
  1762 			clear_bit(__E1000_TESTING, &adapter->state);
       
  1763 			dev_open(netdev);
       
  1764 			set_bit(__E1000_TESTING, &adapter->state);
       
  1765 		}
       
  1766 
       
  1767 		e_info("online testing starting\n");
       
  1768 		/* Online tests */
       
  1769 		if (e1000_link_test(adapter, &data[4]))
       
  1770 			eth_test->flags |= ETH_TEST_FL_FAILED;
       
  1771 
       
  1772 		/* Online tests aren't run; pass by default */
       
  1773 		data[0] = 0;
       
  1774 		data[1] = 0;
       
  1775 		data[2] = 0;
       
  1776 		data[3] = 0;
       
  1777 
       
  1778 		if (!if_running && (adapter->flags & FLAG_HAS_AMT))
       
  1779 			dev_close(netdev);
       
  1780 
       
  1781 		clear_bit(__E1000_TESTING, &adapter->state);
       
  1782 	}
       
  1783 	msleep_interruptible(4 * 1000);
       
  1784 }
       
  1785 
       
  1786 static void e1000_get_wol(struct net_device *netdev,
       
  1787 			  struct ethtool_wolinfo *wol)
       
  1788 {
       
  1789 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1790 
       
  1791 	wol->supported = 0;
       
  1792 	wol->wolopts = 0;
       
  1793 
       
  1794 	if (!(adapter->flags & FLAG_HAS_WOL) ||
       
  1795 	    !device_can_wakeup(&adapter->pdev->dev))
       
  1796 		return;
       
  1797 
       
  1798 	wol->supported = WAKE_UCAST | WAKE_MCAST |
       
  1799 	                 WAKE_BCAST | WAKE_MAGIC |
       
  1800 	                 WAKE_PHY | WAKE_ARP;
       
  1801 
       
  1802 	/* apply any specific unsupported masks here */
       
  1803 	if (adapter->flags & FLAG_NO_WAKE_UCAST) {
       
  1804 		wol->supported &= ~WAKE_UCAST;
       
  1805 
       
  1806 		if (adapter->wol & E1000_WUFC_EX)
       
  1807 			e_err("Interface does not support directed (unicast) "
       
  1808 			      "frame wake-up packets\n");
       
  1809 	}
       
  1810 
       
  1811 	if (adapter->wol & E1000_WUFC_EX)
       
  1812 		wol->wolopts |= WAKE_UCAST;
       
  1813 	if (adapter->wol & E1000_WUFC_MC)
       
  1814 		wol->wolopts |= WAKE_MCAST;
       
  1815 	if (adapter->wol & E1000_WUFC_BC)
       
  1816 		wol->wolopts |= WAKE_BCAST;
       
  1817 	if (adapter->wol & E1000_WUFC_MAG)
       
  1818 		wol->wolopts |= WAKE_MAGIC;
       
  1819 	if (adapter->wol & E1000_WUFC_LNKC)
       
  1820 		wol->wolopts |= WAKE_PHY;
       
  1821 	if (adapter->wol & E1000_WUFC_ARP)
       
  1822 		wol->wolopts |= WAKE_ARP;
       
  1823 }
       
  1824 
       
  1825 static int e1000_set_wol(struct net_device *netdev,
       
  1826 			 struct ethtool_wolinfo *wol)
       
  1827 {
       
  1828 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1829 
       
  1830 	if (!(adapter->flags & FLAG_HAS_WOL) ||
       
  1831 	    !device_can_wakeup(&adapter->pdev->dev) ||
       
  1832 	    (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
       
  1833 	                      WAKE_MAGIC | WAKE_PHY | WAKE_ARP)))
       
  1834 		return -EOPNOTSUPP;
       
  1835 
       
  1836 	/* these settings will always override what we currently have */
       
  1837 	adapter->wol = 0;
       
  1838 
       
  1839 	if (wol->wolopts & WAKE_UCAST)
       
  1840 		adapter->wol |= E1000_WUFC_EX;
       
  1841 	if (wol->wolopts & WAKE_MCAST)
       
  1842 		adapter->wol |= E1000_WUFC_MC;
       
  1843 	if (wol->wolopts & WAKE_BCAST)
       
  1844 		adapter->wol |= E1000_WUFC_BC;
       
  1845 	if (wol->wolopts & WAKE_MAGIC)
       
  1846 		adapter->wol |= E1000_WUFC_MAG;
       
  1847 	if (wol->wolopts & WAKE_PHY)
       
  1848 		adapter->wol |= E1000_WUFC_LNKC;
       
  1849 	if (wol->wolopts & WAKE_ARP)
       
  1850 		adapter->wol |= E1000_WUFC_ARP;
       
  1851 
       
  1852 	device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
       
  1853 
       
  1854 	return 0;
       
  1855 }
       
  1856 
       
  1857 /* toggle LED 4 times per second = 2 "blinks" per second */
       
  1858 #define E1000_ID_INTERVAL	(HZ/4)
       
  1859 
       
  1860 /* bit defines for adapter->led_status */
       
  1861 #define E1000_LED_ON		0
       
  1862 
       
  1863 static void e1000e_led_blink_task(struct work_struct *work)
       
  1864 {
       
  1865 	struct e1000_adapter *adapter = container_of(work,
       
  1866 	                                struct e1000_adapter, led_blink_task);
       
  1867 
       
  1868 	if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
       
  1869 		adapter->hw.mac.ops.led_off(&adapter->hw);
       
  1870 	else
       
  1871 		adapter->hw.mac.ops.led_on(&adapter->hw);
       
  1872 }
       
  1873 
       
  1874 static void e1000_led_blink_callback(unsigned long data)
       
  1875 {
       
  1876 	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
       
  1877 
       
  1878 	schedule_work(&adapter->led_blink_task);
       
  1879 	mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
       
  1880 }
       
  1881 
       
  1882 static int e1000_phys_id(struct net_device *netdev, u32 data)
       
  1883 {
       
  1884 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1885 	struct e1000_hw *hw = &adapter->hw;
       
  1886 
       
  1887 	if (!data)
       
  1888 		data = INT_MAX;
       
  1889 
       
  1890 	if ((hw->phy.type == e1000_phy_ife) ||
       
  1891 	    (hw->mac.type == e1000_pchlan) ||
       
  1892 	    (hw->mac.type == e1000_pch2lan) ||
       
  1893 	    (hw->mac.type == e1000_82583) ||
       
  1894 	    (hw->mac.type == e1000_82574)) {
       
  1895 		INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
       
  1896 		if (!adapter->blink_timer.function) {
       
  1897 			init_timer(&adapter->blink_timer);
       
  1898 			adapter->blink_timer.function =
       
  1899 				e1000_led_blink_callback;
       
  1900 			adapter->blink_timer.data = (unsigned long) adapter;
       
  1901 		}
       
  1902 		mod_timer(&adapter->blink_timer, jiffies);
       
  1903 		msleep_interruptible(data * 1000);
       
  1904 		del_timer_sync(&adapter->blink_timer);
       
  1905 		if (hw->phy.type == e1000_phy_ife)
       
  1906 			e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
       
  1907 	} else {
       
  1908 		e1000e_blink_led(hw);
       
  1909 		msleep_interruptible(data * 1000);
       
  1910 	}
       
  1911 
       
  1912 	hw->mac.ops.led_off(hw);
       
  1913 	clear_bit(E1000_LED_ON, &adapter->led_status);
       
  1914 	hw->mac.ops.cleanup_led(hw);
       
  1915 
       
  1916 	return 0;
       
  1917 }
       
  1918 
       
  1919 static int e1000_get_coalesce(struct net_device *netdev,
       
  1920 			      struct ethtool_coalesce *ec)
       
  1921 {
       
  1922 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1923 
       
  1924 	if (adapter->itr_setting <= 4)
       
  1925 		ec->rx_coalesce_usecs = adapter->itr_setting;
       
  1926 	else
       
  1927 		ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
       
  1928 
       
  1929 	return 0;
       
  1930 }
       
  1931 
       
  1932 static int e1000_set_coalesce(struct net_device *netdev,
       
  1933 			      struct ethtool_coalesce *ec)
       
  1934 {
       
  1935 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1936 	struct e1000_hw *hw = &adapter->hw;
       
  1937 
       
  1938 	if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
       
  1939 	    ((ec->rx_coalesce_usecs > 4) &&
       
  1940 	     (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
       
  1941 	    (ec->rx_coalesce_usecs == 2))
       
  1942 		return -EINVAL;
       
  1943 
       
  1944 	if (ec->rx_coalesce_usecs == 4) {
       
  1945 		adapter->itr = adapter->itr_setting = 4;
       
  1946 	} else if (ec->rx_coalesce_usecs <= 3) {
       
  1947 		adapter->itr = 20000;
       
  1948 		adapter->itr_setting = ec->rx_coalesce_usecs;
       
  1949 	} else {
       
  1950 		adapter->itr = (1000000 / ec->rx_coalesce_usecs);
       
  1951 		adapter->itr_setting = adapter->itr & ~3;
       
  1952 	}
       
  1953 
       
  1954 	if (adapter->itr_setting != 0)
       
  1955 		ew32(ITR, 1000000000 / (adapter->itr * 256));
       
  1956 	else
       
  1957 		ew32(ITR, 0);
       
  1958 
       
  1959 	return 0;
       
  1960 }
       
  1961 
       
  1962 static int e1000_nway_reset(struct net_device *netdev)
       
  1963 {
       
  1964 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1965 	if (netif_running(netdev))
       
  1966 		e1000e_reinit_locked(adapter);
       
  1967 	return 0;
       
  1968 }
       
  1969 
       
  1970 static void e1000_get_ethtool_stats(struct net_device *netdev,
       
  1971 				    struct ethtool_stats *stats,
       
  1972 				    u64 *data)
       
  1973 {
       
  1974 	struct e1000_adapter *adapter = netdev_priv(netdev);
       
  1975 	int i;
       
  1976 	char *p = NULL;
       
  1977 
       
  1978 	e1000e_update_stats(adapter);
       
  1979 	for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
       
  1980 		switch (e1000_gstrings_stats[i].type) {
       
  1981 		case NETDEV_STATS:
       
  1982 			p = (char *) netdev +
       
  1983 					e1000_gstrings_stats[i].stat_offset;
       
  1984 			break;
       
  1985 		case E1000_STATS:
       
  1986 			p = (char *) adapter +
       
  1987 					e1000_gstrings_stats[i].stat_offset;
       
  1988 			break;
       
  1989 		}
       
  1990 
       
  1991 		data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
       
  1992 			sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
       
  1993 	}
       
  1994 }
       
  1995 
       
  1996 static void e1000_get_strings(struct net_device *netdev, u32 stringset,
       
  1997 			      u8 *data)
       
  1998 {
       
  1999 	u8 *p = data;
       
  2000 	int i;
       
  2001 
       
  2002 	switch (stringset) {
       
  2003 	case ETH_SS_TEST:
       
  2004 		memcpy(data, *e1000_gstrings_test, sizeof(e1000_gstrings_test));
       
  2005 		break;
       
  2006 	case ETH_SS_STATS:
       
  2007 		for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
       
  2008 			memcpy(p, e1000_gstrings_stats[i].stat_string,
       
  2009 			       ETH_GSTRING_LEN);
       
  2010 			p += ETH_GSTRING_LEN;
       
  2011 		}
       
  2012 		break;
       
  2013 	}
       
  2014 }
       
  2015 
       
  2016 static const struct ethtool_ops e1000_ethtool_ops = {
       
  2017 	.get_settings		= e1000_get_settings,
       
  2018 	.set_settings		= e1000_set_settings,
       
  2019 	.get_drvinfo		= e1000_get_drvinfo,
       
  2020 	.get_regs_len		= e1000_get_regs_len,
       
  2021 	.get_regs		= e1000_get_regs,
       
  2022 	.get_wol		= e1000_get_wol,
       
  2023 	.set_wol		= e1000_set_wol,
       
  2024 	.get_msglevel		= e1000_get_msglevel,
       
  2025 	.set_msglevel		= e1000_set_msglevel,
       
  2026 	.nway_reset		= e1000_nway_reset,
       
  2027 	.get_link		= e1000_get_link,
       
  2028 	.get_eeprom_len		= e1000_get_eeprom_len,
       
  2029 	.get_eeprom		= e1000_get_eeprom,
       
  2030 	.set_eeprom		= e1000_set_eeprom,
       
  2031 	.get_ringparam		= e1000_get_ringparam,
       
  2032 	.set_ringparam		= e1000_set_ringparam,
       
  2033 	.get_pauseparam		= e1000_get_pauseparam,
       
  2034 	.set_pauseparam		= e1000_set_pauseparam,
       
  2035 	.get_rx_csum		= e1000_get_rx_csum,
       
  2036 	.set_rx_csum		= e1000_set_rx_csum,
       
  2037 	.get_tx_csum		= e1000_get_tx_csum,
       
  2038 	.set_tx_csum		= e1000_set_tx_csum,
       
  2039 	.get_sg			= ethtool_op_get_sg,
       
  2040 	.set_sg			= ethtool_op_set_sg,
       
  2041 	.get_tso		= ethtool_op_get_tso,
       
  2042 	.set_tso		= e1000_set_tso,
       
  2043 	.self_test		= e1000_diag_test,
       
  2044 	.get_strings		= e1000_get_strings,
       
  2045 	.phys_id		= e1000_phys_id,
       
  2046 	.get_ethtool_stats	= e1000_get_ethtool_stats,
       
  2047 	.get_sset_count		= e1000e_get_sset_count,
       
  2048 	.get_coalesce		= e1000_get_coalesce,
       
  2049 	.set_coalesce		= e1000_set_coalesce,
       
  2050 	.get_flags		= ethtool_op_get_flags,
       
  2051 };
       
  2052 
       
  2053 void e1000e_set_ethtool_ops(struct net_device *netdev)
       
  2054 {
       
  2055 	SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
       
  2056 }