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