ethtool.c 61.4 KB
Newer Older
1 2 3
/*******************************************************************************

  Intel PRO/1000 Linux driver
B
Bruce Allan 已提交
4
  Copyright(c) 1999 - 2013 Intel Corporation.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

  This program is free software; you can redistribute it and/or modify it
  under the terms and conditions of the GNU General Public License,
  version 2, as published by the Free Software Foundation.

  This program is distributed in the hope it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

  The full GNU General Public License is included in this distribution in
  the file called "COPYING".

  Contact Information:
  Linux NICS <linux.nics@intel.com>
  e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497

*******************************************************************************/

/* ethtool support for e1000 */

#include <linux/netdevice.h>
32
#include <linux/interrupt.h>
33 34
#include <linux/ethtool.h>
#include <linux/pci.h>
35
#include <linux/slab.h>
36
#include <linux/delay.h>
37
#include <linux/vmalloc.h>
38
#include <linux/mdio.h>
39 40 41

#include "e1000.h"

42
enum { NETDEV_STATS, E1000_STATS };
43

44 45
struct e1000_stats {
	char stat_string[ETH_GSTRING_LEN];
46
	int type;
47 48 49 50
	int sizeof_stat;
	int stat_offset;
};

51
#define E1000_STAT(str, m) { \
J
Jeff Kirsher 已提交
52 53 54 55
		.stat_string = str, \
		.type = E1000_STATS, \
		.sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
		.stat_offset = offsetof(struct e1000_adapter, m) }
56
#define E1000_NETDEV_STAT(str, m) { \
J
Jeff Kirsher 已提交
57 58 59 60
		.stat_string = str, \
		.type = NETDEV_STATS, \
		.sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
		.stat_offset = offsetof(struct rtnl_link_stats64, m) }
61

62
static const struct e1000_stats e1000_gstrings_stats[] = {
63 64 65 66 67 68 69 70
	E1000_STAT("rx_packets", stats.gprc),
	E1000_STAT("tx_packets", stats.gptc),
	E1000_STAT("rx_bytes", stats.gorc),
	E1000_STAT("tx_bytes", stats.gotc),
	E1000_STAT("rx_broadcast", stats.bprc),
	E1000_STAT("tx_broadcast", stats.bptc),
	E1000_STAT("rx_multicast", stats.mprc),
	E1000_STAT("tx_multicast", stats.mptc),
J
Jeff Kirsher 已提交
71 72 73
	E1000_NETDEV_STAT("rx_errors", rx_errors),
	E1000_NETDEV_STAT("tx_errors", tx_errors),
	E1000_NETDEV_STAT("tx_dropped", tx_dropped),
74 75
	E1000_STAT("multicast", stats.mprc),
	E1000_STAT("collisions", stats.colc),
J
Jeff Kirsher 已提交
76 77
	E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
	E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
78
	E1000_STAT("rx_crc_errors", stats.crcerrs),
J
Jeff Kirsher 已提交
79
	E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
80 81 82 83
	E1000_STAT("rx_no_buffer_count", stats.rnbc),
	E1000_STAT("rx_missed_errors", stats.mpc),
	E1000_STAT("tx_aborted_errors", stats.ecol),
	E1000_STAT("tx_carrier_errors", stats.tncrs),
J
Jeff Kirsher 已提交
84 85
	E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
	E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
	E1000_STAT("tx_window_errors", stats.latecol),
	E1000_STAT("tx_abort_late_coll", stats.latecol),
	E1000_STAT("tx_deferred_ok", stats.dc),
	E1000_STAT("tx_single_coll_ok", stats.scc),
	E1000_STAT("tx_multi_coll_ok", stats.mcc),
	E1000_STAT("tx_timeout_count", tx_timeout_count),
	E1000_STAT("tx_restart_queue", restart_queue),
	E1000_STAT("rx_long_length_errors", stats.roc),
	E1000_STAT("rx_short_length_errors", stats.ruc),
	E1000_STAT("rx_align_errors", stats.algnerrc),
	E1000_STAT("tx_tcp_seg_good", stats.tsctc),
	E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
	E1000_STAT("rx_flow_control_xon", stats.xonrxc),
	E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
	E1000_STAT("tx_flow_control_xon", stats.xontxc),
	E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
	E1000_STAT("rx_csum_offload_good", hw_csum_good),
	E1000_STAT("rx_csum_offload_errors", hw_csum_err),
	E1000_STAT("rx_header_split", rx_hdr_split),
	E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
	E1000_STAT("tx_smbus", stats.mgptc),
	E1000_STAT("rx_smbus", stats.mgprc),
	E1000_STAT("dropped_smbus", stats.mgpdc),
	E1000_STAT("rx_dma_failed", rx_dma_failed),
	E1000_STAT("tx_dma_failed", tx_dma_failed),
111
	E1000_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
112 113
	E1000_STAT("uncorr_ecc_errors", uncorr_errors),
	E1000_STAT("corr_ecc_errors", corr_errors),
114 115
};

116
#define E1000_GLOBAL_STATS_LEN	ARRAY_SIZE(e1000_gstrings_stats)
117 118 119 120 121 122
#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
	"Register test  (offline)", "Eeprom test    (offline)",
	"Interrupt test (offline)", "Loopback test  (offline)",
	"Link test   (on/offline)"
};
123

124
#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
125 126 127 128 129 130

static int e1000_get_settings(struct net_device *netdev,
			      struct ethtool_cmd *ecmd)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	struct e1000_hw *hw = &adapter->hw;
131
	u32 speed;
132

133
	if (hw->phy.media_type == e1000_media_type_copper) {
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
		ecmd->supported = (SUPPORTED_10baseT_Half |
				   SUPPORTED_10baseT_Full |
				   SUPPORTED_100baseT_Half |
				   SUPPORTED_100baseT_Full |
				   SUPPORTED_1000baseT_Full |
				   SUPPORTED_Autoneg |
				   SUPPORTED_TP);
		if (hw->phy.type == e1000_phy_ife)
			ecmd->supported &= ~SUPPORTED_1000baseT_Full;
		ecmd->advertising = ADVERTISED_TP;

		if (hw->mac.autoneg == 1) {
			ecmd->advertising |= ADVERTISED_Autoneg;
			/* the e1000 autoneg seems to match ethtool nicely */
			ecmd->advertising |= hw->phy.autoneg_advertised;
		}

		ecmd->port = PORT_TP;
		ecmd->phy_address = hw->phy.addr;
		ecmd->transceiver = XCVR_INTERNAL;

	} else {
		ecmd->supported   = (SUPPORTED_1000baseT_Full |
				     SUPPORTED_FIBRE |
				     SUPPORTED_Autoneg);

		ecmd->advertising = (ADVERTISED_1000baseT_Full |
				     ADVERTISED_FIBRE |
				     ADVERTISED_Autoneg);

		ecmd->port = PORT_FIBRE;
		ecmd->transceiver = XCVR_EXTERNAL;
	}

168
	speed = -1;
169 170 171 172
	ecmd->duplex = -1;

	if (netif_running(netdev)) {
		if (netif_carrier_ok(netdev)) {
173
			speed = adapter->link_speed;
174 175
			ecmd->duplex = adapter->link_duplex - 1;
		}
176
	} else {
177 178 179
		u32 status = er32(STATUS);
		if (status & E1000_STATUS_LU) {
			if (status & E1000_STATUS_SPEED_1000)
180
				speed = SPEED_1000;
181
			else if (status & E1000_STATUS_SPEED_100)
182
				speed = SPEED_100;
183
			else
184
				speed = SPEED_10;
185 186 187 188 189 190

			if (status & E1000_STATUS_FD)
				ecmd->duplex = DUPLEX_FULL;
			else
				ecmd->duplex = DUPLEX_HALF;
		}
191 192
	}

193
	ethtool_cmd_speed_set(ecmd, speed);
194
	ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
195
			 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
196 197 198

	/* MDI-X => 2; MDI =>1; Invalid =>0 */
	if ((hw->phy.media_type == e1000_media_type_copper) &&
199
	    netif_carrier_ok(netdev))
200
		ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X : ETH_TP_MDI;
201 202 203
	else
		ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;

204 205 206 207 208
	if (hw->phy.mdix == AUTO_ALL_MODES)
		ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
	else
		ecmd->eth_tp_mdix_ctrl = hw->phy.mdix;

209 210 211
	return 0;
}

212
static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
213 214 215 216 217
{
	struct e1000_mac_info *mac = &adapter->hw.mac;

	mac->autoneg = 0;

218
	/* Make sure dplx is at most 1 bit and lsb of speed is not set
B
Bruce Allan 已提交
219 220
	 * for the switch() below to work
	 */
221 222 223
	if ((spd & 1) || (dplx & ~1))
		goto err_inval;

224
	/* Fiber NICs only allow 1000 gbps Full duplex */
225
	if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
226
	    (spd != SPEED_1000) && (dplx != DUPLEX_FULL)) {
227
		goto err_inval;
228 229
	}

230
	switch (spd + dplx) {
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
	case SPEED_10 + DUPLEX_HALF:
		mac->forced_speed_duplex = ADVERTISE_10_HALF;
		break;
	case SPEED_10 + DUPLEX_FULL:
		mac->forced_speed_duplex = ADVERTISE_10_FULL;
		break;
	case SPEED_100 + DUPLEX_HALF:
		mac->forced_speed_duplex = ADVERTISE_100_HALF;
		break;
	case SPEED_100 + DUPLEX_FULL:
		mac->forced_speed_duplex = ADVERTISE_100_FULL;
		break;
	case SPEED_1000 + DUPLEX_FULL:
		mac->autoneg = 1;
		adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
		break;
	case SPEED_1000 + DUPLEX_HALF: /* not supported */
	default:
249
		goto err_inval;
250
	}
251 252 253 254

	/* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
	adapter->hw.phy.mdix = AUTO_ALL_MODES;

255
	return 0;
256 257 258 259

err_inval:
	e_err("Unsupported Speed/Duplex configuration\n");
	return -EINVAL;
260 261 262 263 264 265 266 267
}

static int e1000_set_settings(struct net_device *netdev,
			      struct ethtool_cmd *ecmd)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	struct e1000_hw *hw = &adapter->hw;

B
Bruce Allan 已提交
268
	/* When SoL/IDER sessions are active, autoneg/speed/duplex
269 270
	 * cannot be changed
	 */
271 272
	if (hw->phy.ops.check_reset_block &&
	    hw->phy.ops.check_reset_block(hw)) {
273
		e_err("Cannot change link characteristics when SoL/IDER is active.\n");
274 275 276
		return -EINVAL;
	}

B
Bruce Allan 已提交
277
	/* MDI setting is only allowed when autoneg enabled because
278 279 280 281 282 283 284 285 286 287 288 289 290 291
	 * some hardware doesn't allow MDI setting when speed or
	 * duplex is forced.
	 */
	if (ecmd->eth_tp_mdix_ctrl) {
		if (hw->phy.media_type != e1000_media_type_copper)
			return -EOPNOTSUPP;

		if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
		    (ecmd->autoneg != AUTONEG_ENABLE)) {
			e_err("forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
			return -EINVAL;
		}
	}

292
	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
293
		usleep_range(1000, 2000);
294 295 296

	if (ecmd->autoneg == AUTONEG_ENABLE) {
		hw->mac.autoneg = 1;
297
		if (hw->phy.media_type == e1000_media_type_fiber)
298
			hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
299
			    ADVERTISED_FIBRE | ADVERTISED_Autoneg;
300 301
		else
			hw->phy.autoneg_advertised = ecmd->advertising |
302
			    ADVERTISED_TP | ADVERTISED_Autoneg;
303
		ecmd->advertising = hw->phy.autoneg_advertised;
304
		if (adapter->fc_autoneg)
305
			hw->fc.requested_mode = e1000_fc_default;
306
	} else {
307
		u32 speed = ethtool_cmd_speed(ecmd);
308
		/* calling this overrides forced MDI setting */
309
		if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
310 311 312 313 314
			clear_bit(__E1000_RESETTING, &adapter->state);
			return -EINVAL;
		}
	}

315 316
	/* MDI-X => 2; MDI => 1; Auto => 3 */
	if (ecmd->eth_tp_mdix_ctrl) {
B
Bruce Allan 已提交
317
		/* fix up the value for auto (3 => 0) as zero is mapped
318 319 320 321 322 323 324 325
		 * internally to auto
		 */
		if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
			hw->phy.mdix = AUTO_ALL_MODES;
		else
			hw->phy.mdix = ecmd->eth_tp_mdix_ctrl;
	}

326 327 328 329
	/* reset the link */
	if (netif_running(adapter->netdev)) {
		e1000e_down(adapter);
		e1000e_up(adapter);
330
	} else {
331
		e1000e_reset(adapter);
332
	}
333 334 335 336 337 338 339 340 341 342 343 344

	clear_bit(__E1000_RESETTING, &adapter->state);
	return 0;
}

static void e1000_get_pauseparam(struct net_device *netdev,
				 struct ethtool_pauseparam *pause)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	struct e1000_hw *hw = &adapter->hw;

	pause->autoneg =
345
	    (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
346

347
	if (hw->fc.current_mode == e1000_fc_rx_pause) {
348
		pause->rx_pause = 1;
349
	} else if (hw->fc.current_mode == e1000_fc_tx_pause) {
350
		pause->tx_pause = 1;
351
	} else if (hw->fc.current_mode == e1000_fc_full) {
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
		pause->rx_pause = 1;
		pause->tx_pause = 1;
	}
}

static int e1000_set_pauseparam(struct net_device *netdev,
				struct ethtool_pauseparam *pause)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	struct e1000_hw *hw = &adapter->hw;
	int retval = 0;

	adapter->fc_autoneg = pause->autoneg;

	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
367
		usleep_range(1000, 2000);
368 369

	if (adapter->fc_autoneg == AUTONEG_ENABLE) {
370
		hw->fc.requested_mode = e1000_fc_default;
371 372 373 374 375 376 377
		if (netif_running(adapter->netdev)) {
			e1000e_down(adapter);
			e1000e_up(adapter);
		} else {
			e1000e_reset(adapter);
		}
	} else {
378 379 380 381 382 383 384 385 386 387 388
		if (pause->rx_pause && pause->tx_pause)
			hw->fc.requested_mode = e1000_fc_full;
		else if (pause->rx_pause && !pause->tx_pause)
			hw->fc.requested_mode = e1000_fc_rx_pause;
		else if (!pause->rx_pause && pause->tx_pause)
			hw->fc.requested_mode = e1000_fc_tx_pause;
		else if (!pause->rx_pause && !pause->tx_pause)
			hw->fc.requested_mode = e1000_fc_none;

		hw->fc.current_mode = hw->fc.requested_mode;

389 390 391 392 393 394 395 396 397
		if (hw->phy.media_type == e1000_media_type_fiber) {
			retval = hw->mac.ops.setup_link(hw);
			/* implicit goto out */
		} else {
			retval = e1000e_force_mac_fc(hw);
			if (retval)
				goto out;
			e1000e_set_fc_watermarks(hw);
		}
398 399
	}

400
out:
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
	clear_bit(__E1000_RESETTING, &adapter->state);
	return retval;
}

static u32 e1000_get_msglevel(struct net_device *netdev)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	return adapter->msg_enable;
}

static void e1000_set_msglevel(struct net_device *netdev, u32 data)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	adapter->msg_enable = data;
}

417
static int e1000_get_regs_len(struct net_device __always_unused *netdev)
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
{
#define E1000_REGS_LEN 32 /* overestimate */
	return E1000_REGS_LEN * sizeof(u32);
}

static void e1000_get_regs(struct net_device *netdev,
			   struct ethtool_regs *regs, void *p)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	struct e1000_hw *hw = &adapter->hw;
	u32 *regs_buff = p;
	u16 phy_data;

	memset(p, 0, E1000_REGS_LEN * sizeof(u32));

433
	regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
434
	    adapter->pdev->device;
435 436 437 438 439

	regs_buff[0]  = er32(CTRL);
	regs_buff[1]  = er32(STATUS);

	regs_buff[2]  = er32(RCTL);
440 441 442
	regs_buff[3]  = er32(RDLEN(0));
	regs_buff[4]  = er32(RDH(0));
	regs_buff[5]  = er32(RDT(0));
443 444 445
	regs_buff[6]  = er32(RDTR);

	regs_buff[7]  = er32(TCTL);
446 447 448
	regs_buff[8]  = er32(TDLEN(0));
	regs_buff[9]  = er32(TDH(0));
	regs_buff[10] = er32(TDT(0));
449 450 451
	regs_buff[11] = er32(TIDV);

	regs_buff[12] = adapter->hw.phy.type;  /* PHY type (IGP=1, M88=0) */
452 453

	/* ethtool doesn't use anything past this point, so all this
B
Bruce Allan 已提交
454 455
	 * code is likely legacy junk for apps that may or may not exist
	 */
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
	if (hw->phy.type == e1000_phy_m88) {
		e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
		regs_buff[13] = (u32)phy_data; /* cable length */
		regs_buff[14] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
		regs_buff[15] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
		regs_buff[16] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
		e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
		regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
		regs_buff[18] = regs_buff[13]; /* cable polarity */
		regs_buff[19] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
		regs_buff[20] = regs_buff[17]; /* polarity correction */
		/* phy receive errors */
		regs_buff[22] = adapter->phy_stats.receive_errors;
		regs_buff[23] = regs_buff[13]; /* mdix mode */
	}
471 472 473 474
	regs_buff[21] = 0;	/* was idle_errors */
	e1e_rphy(hw, MII_STAT1000, &phy_data);
	regs_buff[24] = (u32)phy_data;	/* phy local receiver status */
	regs_buff[25] = regs_buff[24];	/* phy remote receiver status */
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
}

static int e1000_get_eeprom_len(struct net_device *netdev)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	return adapter->hw.nvm.word_size * 2;
}

static int e1000_get_eeprom(struct net_device *netdev,
			    struct ethtool_eeprom *eeprom, u8 *bytes)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	struct e1000_hw *hw = &adapter->hw;
	u16 *eeprom_buff;
	int first_word;
	int last_word;
	int ret_val = 0;
	u16 i;

	if (eeprom->len == 0)
		return -EINVAL;

	eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);

	first_word = eeprom->offset >> 1;
	last_word = (eeprom->offset + eeprom->len - 1) >> 1;

502 503
	eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
			      GFP_KERNEL);
504 505 506 507 508 509 510 511 512 513
	if (!eeprom_buff)
		return -ENOMEM;

	if (hw->nvm.type == e1000_nvm_eeprom_spi) {
		ret_val = e1000_read_nvm(hw, first_word,
					 last_word - first_word + 1,
					 eeprom_buff);
	} else {
		for (i = 0; i < last_word - first_word + 1; i++) {
			ret_val = e1000_read_nvm(hw, first_word + i, 1,
514
						 &eeprom_buff[i]);
515
			if (ret_val)
516 517 518 519
				break;
		}
	}

520 521
	if (ret_val) {
		/* a read error occurred, throw away the result */
522 523
		memset(eeprom_buff, 0xff, sizeof(u16) *
		       (last_word - first_word + 1));
524 525 526 527 528
	} else {
		/* Device's eeprom is always little-endian, word addressable */
		for (i = 0; i < last_word - first_word + 1; i++)
			le16_to_cpus(&eeprom_buff[i]);
	}
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551

	memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
	kfree(eeprom_buff);

	return ret_val;
}

static int e1000_set_eeprom(struct net_device *netdev,
			    struct ethtool_eeprom *eeprom, u8 *bytes)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	struct e1000_hw *hw = &adapter->hw;
	u16 *eeprom_buff;
	void *ptr;
	int max_len;
	int first_word;
	int last_word;
	int ret_val = 0;
	u16 i;

	if (eeprom->len == 0)
		return -EOPNOTSUPP;

552 553
	if (eeprom->magic !=
	    (adapter->pdev->vendor | (adapter->pdev->device << 16)))
554 555
		return -EFAULT;

556 557 558
	if (adapter->flags & FLAG_READ_ONLY_NVM)
		return -EINVAL;

559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
	max_len = hw->nvm.word_size * 2;

	first_word = eeprom->offset >> 1;
	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
	eeprom_buff = kmalloc(max_len, GFP_KERNEL);
	if (!eeprom_buff)
		return -ENOMEM;

	ptr = (void *)eeprom_buff;

	if (eeprom->offset & 1) {
		/* need read/modify/write of first changed EEPROM word */
		/* only the second byte of the word is being modified */
		ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
		ptr++;
	}
575
	if (((eeprom->offset + eeprom->len) & 1) && (!ret_val))
576 577 578
		/* need read/modify/write of last changed EEPROM word */
		/* only the first byte of the word is being modified */
		ret_val = e1000_read_nvm(hw, last_word, 1,
579
					 &eeprom_buff[last_word - first_word]);
580

581 582 583
	if (ret_val)
		goto out;

584 585 586 587 588 589 590
	/* Device's eeprom is always little-endian, word addressable */
	for (i = 0; i < last_word - first_word + 1; i++)
		le16_to_cpus(&eeprom_buff[i]);

	memcpy(ptr, bytes, eeprom->len);

	for (i = 0; i < last_word - first_word + 1; i++)
591
		cpu_to_le16s(&eeprom_buff[i]);
592 593 594 595

	ret_val = e1000_write_nvm(hw, first_word,
				  last_word - first_word + 1, eeprom_buff);

596 597 598
	if (ret_val)
		goto out;

B
Bruce Allan 已提交
599
	/* Update the checksum over the first part of the EEPROM if needed
600
	 * and flush shadow RAM for applicable controllers
601
	 */
602
	if ((first_word <= NVM_CHECKSUM_REG) ||
603 604 605
	    (hw->mac.type == e1000_82583) ||
	    (hw->mac.type == e1000_82574) ||
	    (hw->mac.type == e1000_82573))
606
		ret_val = e1000e_update_nvm_checksum(hw);
607

608
out:
609 610 611 612 613 614 615 616 617
	kfree(eeprom_buff);
	return ret_val;
}

static void e1000_get_drvinfo(struct net_device *netdev,
			      struct ethtool_drvinfo *drvinfo)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);

618
	strlcpy(drvinfo->driver, e1000e_driver_name, sizeof(drvinfo->driver));
619
	strlcpy(drvinfo->version, e1000e_driver_version,
620
		sizeof(drvinfo->version));
621

B
Bruce Allan 已提交
622
	/* EEPROM image version # is reported as firmware version # for
623 624
	 * PCI-E controllers
	 */
625
	snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
626 627 628 629
		 "%d.%d-%d",
		 (adapter->eeprom_vers & 0xF000) >> 12,
		 (adapter->eeprom_vers & 0x0FF0) >> 4,
		 (adapter->eeprom_vers & 0x000F));
630

631 632
	strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
		sizeof(drvinfo->bus_info));
633 634 635 636 637 638 639 640 641 642 643
	drvinfo->regdump_len = e1000_get_regs_len(netdev);
	drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
}

static void e1000_get_ringparam(struct net_device *netdev,
				struct ethtool_ringparam *ring)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);

	ring->rx_max_pending = E1000_MAX_RXD;
	ring->tx_max_pending = E1000_MAX_TXD;
644 645
	ring->rx_pending = adapter->rx_ring_count;
	ring->tx_pending = adapter->tx_ring_count;
646 647 648 649 650 651
}

static int e1000_set_ringparam(struct net_device *netdev,
			       struct ethtool_ringparam *ring)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
652 653 654 655
	struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
	int err = 0, size = sizeof(struct e1000_ring);
	bool set_tx = false, set_rx = false;
	u16 new_rx_count, new_tx_count;
656 657 658 659

	if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
		return -EINVAL;

660 661 662
	new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
			       E1000_MAX_RXD);
	new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
663

664 665 666
	new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
			       E1000_MAX_TXD);
	new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
667

668 669 670 671
	if ((new_tx_count == adapter->tx_ring_count) &&
	    (new_rx_count == adapter->rx_ring_count))
		/* nothing to do */
		return 0;
672

673 674
	while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
		usleep_range(1000, 2000);
675

676 677 678 679 680 681 682 683
	if (!netif_running(adapter->netdev)) {
		/* Set counts now and allocate resources during open() */
		adapter->tx_ring->count = new_tx_count;
		adapter->rx_ring->count = new_rx_count;
		adapter->tx_ring_count = new_tx_count;
		adapter->rx_ring_count = new_rx_count;
		goto clear_reset;
	}
684

685 686
	set_tx = (new_tx_count != adapter->tx_ring_count);
	set_rx = (new_rx_count != adapter->rx_ring_count);
687

688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
	/* Allocate temporary storage for ring updates */
	if (set_tx) {
		temp_tx = vmalloc(size);
		if (!temp_tx) {
			err = -ENOMEM;
			goto free_temp;
		}
	}
	if (set_rx) {
		temp_rx = vmalloc(size);
		if (!temp_rx) {
			err = -ENOMEM;
			goto free_temp;
		}
	}
703

704
	e1000e_down(adapter);
705

B
Bruce Allan 已提交
706
	/* We can't just free everything and then setup again, because the
707 708 709 710 711 712 713
	 * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
	 * structs.  First, attempt to allocate new resources...
	 */
	if (set_tx) {
		memcpy(temp_tx, adapter->tx_ring, size);
		temp_tx->count = new_tx_count;
		err = e1000e_setup_tx_resources(temp_tx);
714
		if (err)
715 716 717 718 719 720
			goto err_setup;
	}
	if (set_rx) {
		memcpy(temp_rx, adapter->rx_ring, size);
		temp_rx->count = new_rx_count;
		err = e1000e_setup_rx_resources(temp_rx);
721
		if (err)
722 723 724 725 726
			goto err_setup_rx;
	}

	/* ...then free the old resources and copy back any new ring data */
	if (set_tx) {
727
		e1000e_free_tx_resources(adapter->tx_ring);
728 729 730 731 732 733 734
		memcpy(adapter->tx_ring, temp_tx, size);
		adapter->tx_ring_count = new_tx_count;
	}
	if (set_rx) {
		e1000e_free_rx_resources(adapter->rx_ring);
		memcpy(adapter->rx_ring, temp_rx, size);
		adapter->rx_ring_count = new_rx_count;
735 736 737
	}

err_setup_rx:
738 739
	if (err && set_tx)
		e1000e_free_tx_resources(temp_tx);
740
err_setup:
741 742 743 744 745
	e1000e_up(adapter);
free_temp:
	vfree(temp_tx);
	vfree(temp_rx);
clear_reset:
746 747 748 749
	clear_bit(__E1000_RESETTING, &adapter->state);
	return err;
}

750 751
static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
			     int reg, int offset, u32 mask, u32 write)
752
{
753
	u32 pat, val;
754
	static const u32 test[] = {
755 756
		0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
	};
757
	for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
758
		E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
759 760 761
				      (test[pat] & write));
		val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
		if (val != (test[pat] & write & mask)) {
762 763 764
			e_err("pattern test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
			      reg + (offset << 2), val,
			      (test[pat] & write & mask));
765
			*data = reg;
766
			return 1;
767 768
		}
	}
769
	return 0;
770 771
}

772 773 774
static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
			      int reg, u32 mask, u32 write)
{
775
	u32 val;
776
	__ew32(&adapter->hw, reg, write & mask);
777 778
	val = __er32(&adapter->hw, reg);
	if ((write & mask) != (val & mask)) {
779
		e_err("set/check test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
780
		      reg, (val & mask), (write & mask));
781
		*data = reg;
782
		return 1;
783
	}
784
	return 0;
785
}
786

787 788 789 790
#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write)                       \
	do {                                                                   \
		if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
			return 1;                                              \
791
	} while (0)
792 793
#define REG_PATTERN_TEST(reg, mask, write)                                     \
	REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
794

795 796 797 798
#define REG_SET_AND_CHECK(reg, mask, write)                                    \
	do {                                                                   \
		if (reg_set_and_check(adapter, data, reg, mask, write))        \
			return 1;                                              \
799 800
	} while (0)

801 802 803 804 805 806 807 808 809
static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
{
	struct e1000_hw *hw = &adapter->hw;
	struct e1000_mac_info *mac = &adapter->hw.mac;
	u32 value;
	u32 before;
	u32 after;
	u32 i;
	u32 toggle;
810
	u32 mask;
B
Bruce Allan 已提交
811
	u32 wlock_mac = 0;
812

B
Bruce Allan 已提交
813
	/* The status register is Read Only, so a write should fail.
814 815
	 * Some bits that get toggled are ignored.  There are several bits
	 * on newer hardware that are r/w.
816 817 818 819 820 821 822
	 */
	switch (mac->type) {
	case e1000_82571:
	case e1000_82572:
	case e1000_80003es2lan:
		toggle = 0x7FFFF3FF;
		break;
823
	default:
824 825 826 827 828 829 830 831 832
		toggle = 0x7FFFF033;
		break;
	}

	before = er32(STATUS);
	value = (er32(STATUS) & toggle);
	ew32(STATUS, toggle);
	after = er32(STATUS) & toggle;
	if (value != after) {
833 834
		e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
		      after, value);
835 836 837 838 839 840
		*data = 1;
		return 1;
	}
	/* restore previous status */
	ew32(STATUS, before);

841
	if (!(adapter->flags & FLAG_IS_ICH)) {
842 843 844 845 846 847 848
		REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
		REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
		REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
		REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
	}

	REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
849 850 851 852
	REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
	REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
	REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
	REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
853 854 855
	REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
	REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
	REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
856 857
	REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
	REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
858 859 860

	REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);

861
	before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
862 863 864
	REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
	REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);

A
Auke Kok 已提交
865
	REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
866
	REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
867
	if (!(adapter->flags & FLAG_IS_ICH))
A
Auke Kok 已提交
868
		REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
869
	REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
A
Auke Kok 已提交
870
	REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
871 872 873 874
	mask = 0x8003FFFF;
	switch (mac->type) {
	case e1000_ich10lan:
	case e1000_pchlan:
875
	case e1000_pch2lan:
B
Bruce Allan 已提交
876
	case e1000_pch_lpt:
877 878 879 880 881
		mask |= (1 << 18);
		break;
	default:
		break;
	}
B
Bruce Allan 已提交
882 883 884 885 886 887

	if (mac->type == e1000_pch_lpt)
		wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
		    E1000_FWSM_WLOCK_MAC_SHIFT;

	for (i = 0; i < mac->rar_entry_count; i++) {
888 889 890 891 892 893 894 895 896 897 898
		if (mac->type == e1000_pch_lpt) {
			/* Cannot test write-protected SHRAL[n] registers */
			if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
				continue;

			/* SHRAH[9] different than the others */
			if (i == 10)
				mask |= (1 << 30);
			else
				mask &= ~(1 << 30);
		}
B
Bruce Allan 已提交
899

900 901
		REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), mask,
				       0xFFFFFFFF);
B
Bruce Allan 已提交
902
	}
903 904 905 906 907

	for (i = 0; i < mac->mta_reg_count; i++)
		REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);

	*data = 0;
B
Bruce Allan 已提交
908

909 910 911 912 913 914 915 916 917 918 919 920 921 922
	return 0;
}

static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
{
	u16 temp;
	u16 checksum = 0;
	u16 i;

	*data = 0;
	/* Read and add up the contents of the EEPROM */
	for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
		if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
			*data = 1;
923
			return *data;
924 925 926 927 928
		}
		checksum += temp;
	}

	/* If Checksum is not Correct return error else test passed */
929
	if ((checksum != (u16)NVM_SUM) && !(*data))
930 931 932 933 934
		*data = 2;

	return *data;
}

935
static irqreturn_t e1000_test_intr(int __always_unused irq, void *data)
936
{
937
	struct net_device *netdev = (struct net_device *)data;
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
	struct e1000_adapter *adapter = netdev_priv(netdev);
	struct e1000_hw *hw = &adapter->hw;

	adapter->test_icr |= er32(ICR);

	return IRQ_HANDLED;
}

static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
{
	struct net_device *netdev = adapter->netdev;
	struct e1000_hw *hw = &adapter->hw;
	u32 mask;
	u32 shared_int = 1;
	u32 irq = adapter->pdev->irq;
	int i;
954 955
	int ret_val = 0;
	int int_mode = E1000E_INT_MODE_LEGACY;
956 957 958

	*data = 0;

959 960 961 962 963 964 965
	/* NOTE: we don't test MSI/MSI-X interrupts here, yet */
	if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
		int_mode = adapter->int_mode;
		e1000e_reset_interrupt_capability(adapter);
		adapter->int_mode = E1000E_INT_MODE_LEGACY;
		e1000e_set_interrupt_capability(adapter);
	}
966
	/* Hook up test interrupt handler just for this test */
967
	if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
968 969
			 netdev)) {
		shared_int = 0;
970 971
	} else if (request_irq(irq, e1000_test_intr, IRQF_SHARED, netdev->name,
			       netdev)) {
972
		*data = 1;
973 974
		ret_val = -1;
		goto out;
975
	}
976
	e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
977 978 979

	/* Disable all the interrupts */
	ew32(IMC, 0xFFFFFFFF);
980
	e1e_flush();
981
	usleep_range(10000, 20000);
982 983 984 985 986 987

	/* Test each interrupt */
	for (i = 0; i < 10; i++) {
		/* Interrupt to test */
		mask = 1 << i;

988 989 990 991 992 993 994 995 996 997 998 999 1000 1001
		if (adapter->flags & FLAG_IS_ICH) {
			switch (mask) {
			case E1000_ICR_RXSEQ:
				continue;
			case 0x00000100:
				if (adapter->hw.mac.type == e1000_ich8lan ||
				    adapter->hw.mac.type == e1000_ich9lan)
					continue;
				break;
			default:
				break;
			}
		}

1002
		if (!shared_int) {
B
Bruce Allan 已提交
1003
			/* Disable the interrupt to be reported in
1004 1005 1006 1007 1008 1009 1010 1011
			 * the cause register and then force the same
			 * interrupt and see if one gets posted.  If
			 * an interrupt was posted to the bus, the
			 * test failed.
			 */
			adapter->test_icr = 0;
			ew32(IMC, mask);
			ew32(ICS, mask);
1012
			e1e_flush();
1013
			usleep_range(10000, 20000);
1014 1015 1016 1017 1018 1019 1020

			if (adapter->test_icr & mask) {
				*data = 3;
				break;
			}
		}

B
Bruce Allan 已提交
1021
		/* Enable the interrupt to be reported in
1022 1023 1024 1025 1026 1027 1028 1029
		 * the cause register and then force the same
		 * interrupt and see if one gets posted.  If
		 * an interrupt was not posted to the bus, the
		 * test failed.
		 */
		adapter->test_icr = 0;
		ew32(IMS, mask);
		ew32(ICS, mask);
1030
		e1e_flush();
1031
		usleep_range(10000, 20000);
1032 1033 1034 1035 1036 1037 1038

		if (!(adapter->test_icr & mask)) {
			*data = 4;
			break;
		}

		if (!shared_int) {
B
Bruce Allan 已提交
1039
			/* Disable the other interrupts to be reported in
1040 1041 1042 1043 1044 1045 1046 1047
			 * the cause register and then force the other
			 * interrupts and see if any get posted.  If
			 * an interrupt was posted to the bus, the
			 * test failed.
			 */
			adapter->test_icr = 0;
			ew32(IMC, ~mask & 0x00007FFF);
			ew32(ICS, ~mask & 0x00007FFF);
1048
			e1e_flush();
1049
			usleep_range(10000, 20000);
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059

			if (adapter->test_icr) {
				*data = 5;
				break;
			}
		}
	}

	/* Disable all the interrupts */
	ew32(IMC, 0xFFFFFFFF);
1060
	e1e_flush();
1061
	usleep_range(10000, 20000);
1062 1063 1064 1065

	/* Unhook test interrupt handler */
	free_irq(irq, netdev);

1066 1067 1068 1069 1070 1071 1072 1073
out:
	if (int_mode == E1000E_INT_MODE_MSIX) {
		e1000e_reset_interrupt_capability(adapter);
		adapter->int_mode = int_mode;
		e1000e_set_interrupt_capability(adapter);
	}

	return ret_val;
1074 1075 1076 1077 1078 1079 1080
}

static void e1000_free_desc_rings(struct e1000_adapter *adapter)
{
	struct e1000_ring *tx_ring = &adapter->test_tx_ring;
	struct e1000_ring *rx_ring = &adapter->test_rx_ring;
	struct pci_dev *pdev = adapter->pdev;
1081
	struct e1000_buffer *buffer_info;
1082 1083 1084 1085
	int i;

	if (tx_ring->desc && tx_ring->buffer_info) {
		for (i = 0; i < tx_ring->count; i++) {
1086 1087 1088
			buffer_info = &tx_ring->buffer_info[i];

			if (buffer_info->dma)
1089
				dma_unmap_single(&pdev->dev,
1090 1091 1092 1093 1094
						 buffer_info->dma,
						 buffer_info->length,
						 DMA_TO_DEVICE);
			if (buffer_info->skb)
				dev_kfree_skb(buffer_info->skb);
1095 1096 1097 1098 1099
		}
	}

	if (rx_ring->desc && rx_ring->buffer_info) {
		for (i = 0; i < rx_ring->count; i++) {
1100 1101 1102
			buffer_info = &rx_ring->buffer_info[i];

			if (buffer_info->dma)
1103
				dma_unmap_single(&pdev->dev,
1104 1105 1106 1107
						 buffer_info->dma,
						 2048, DMA_FROM_DEVICE);
			if (buffer_info->skb)
				dev_kfree_skb(buffer_info->skb);
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
		}
	}

	if (tx_ring->desc) {
		dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
				  tx_ring->dma);
		tx_ring->desc = NULL;
	}
	if (rx_ring->desc) {
		dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
				  rx_ring->dma);
		rx_ring->desc = NULL;
	}

	kfree(tx_ring->buffer_info);
	tx_ring->buffer_info = NULL;
	kfree(rx_ring->buffer_info);
	rx_ring->buffer_info = NULL;
}

static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
{
	struct e1000_ring *tx_ring = &adapter->test_tx_ring;
	struct e1000_ring *rx_ring = &adapter->test_rx_ring;
	struct pci_dev *pdev = adapter->pdev;
	struct e1000_hw *hw = &adapter->hw;
	u32 rctl;
	int i;
	int ret_val;

	/* Setup Tx descriptor ring and Tx buffers */

	if (!tx_ring->count)
		tx_ring->count = E1000_DEFAULT_TXD;

1143
	tx_ring->buffer_info = kcalloc(tx_ring->count,
1144
				       sizeof(struct e1000_buffer), GFP_KERNEL);
1145
	if (!tx_ring->buffer_info) {
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
		ret_val = 1;
		goto err_nomem;
	}

	tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
	tx_ring->size = ALIGN(tx_ring->size, 4096);
	tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
					   &tx_ring->dma, GFP_KERNEL);
	if (!tx_ring->desc) {
		ret_val = 2;
		goto err_nomem;
	}
	tx_ring->next_to_use = 0;
	tx_ring->next_to_clean = 0;

1161 1162
	ew32(TDBAL(0), ((u64)tx_ring->dma & 0x00000000FFFFFFFF));
	ew32(TDBAH(0), ((u64)tx_ring->dma >> 32));
1163 1164 1165
	ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
	ew32(TDH(0), 0);
	ew32(TDT(0), 0);
1166 1167 1168
	ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
	     E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
	     E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183

	for (i = 0; i < tx_ring->count; i++) {
		struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
		struct sk_buff *skb;
		unsigned int skb_size = 1024;

		skb = alloc_skb(skb_size, GFP_KERNEL);
		if (!skb) {
			ret_val = 3;
			goto err_nomem;
		}
		skb_put(skb, skb_size);
		tx_ring->buffer_info[i].skb = skb;
		tx_ring->buffer_info[i].length = skb->len;
		tx_ring->buffer_info[i].dma =
1184 1185
		    dma_map_single(&pdev->dev, skb->data, skb->len,
				   DMA_TO_DEVICE);
1186 1187
		if (dma_mapping_error(&pdev->dev,
				      tx_ring->buffer_info[i].dma)) {
1188 1189 1190
			ret_val = 4;
			goto err_nomem;
		}
1191
		tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
1192 1193 1194
		tx_desc->lower.data = cpu_to_le32(skb->len);
		tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
						   E1000_TXD_CMD_IFCS |
1195
						   E1000_TXD_CMD_RS);
1196 1197 1198 1199 1200 1201 1202 1203
		tx_desc->upper.data = 0;
	}

	/* Setup Rx descriptor ring and Rx buffers */

	if (!rx_ring->count)
		rx_ring->count = E1000_DEFAULT_RXD;

1204
	rx_ring->buffer_info = kcalloc(rx_ring->count,
1205
				       sizeof(struct e1000_buffer), GFP_KERNEL);
1206
	if (!rx_ring->buffer_info) {
1207 1208 1209 1210
		ret_val = 5;
		goto err_nomem;
	}

1211
	rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
	rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
					   &rx_ring->dma, GFP_KERNEL);
	if (!rx_ring->desc) {
		ret_val = 6;
		goto err_nomem;
	}
	rx_ring->next_to_use = 0;
	rx_ring->next_to_clean = 0;

	rctl = er32(RCTL);
1222 1223
	if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
		ew32(RCTL, rctl & ~E1000_RCTL_EN);
1224 1225
	ew32(RDBAL(0), ((u64)rx_ring->dma & 0xFFFFFFFF));
	ew32(RDBAH(0), ((u64)rx_ring->dma >> 32));
1226 1227 1228
	ew32(RDLEN(0), rx_ring->size);
	ew32(RDH(0), 0);
	ew32(RDT(0), 0);
1229
	rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1230 1231 1232 1233
	    E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
	    E1000_RCTL_SBP | E1000_RCTL_SECRC |
	    E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
	    (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1234 1235 1236
	ew32(RCTL, rctl);

	for (i = 0; i < rx_ring->count; i++) {
1237
		union e1000_rx_desc_extended *rx_desc;
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
		struct sk_buff *skb;

		skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
		if (!skb) {
			ret_val = 7;
			goto err_nomem;
		}
		skb_reserve(skb, NET_IP_ALIGN);
		rx_ring->buffer_info[i].skb = skb;
		rx_ring->buffer_info[i].dma =
1248 1249
		    dma_map_single(&pdev->dev, skb->data, 2048,
				   DMA_FROM_DEVICE);
1250 1251
		if (dma_mapping_error(&pdev->dev,
				      rx_ring->buffer_info[i].dma)) {
1252 1253 1254
			ret_val = 8;
			goto err_nomem;
		}
1255 1256 1257
		rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
		rx_desc->read.buffer_addr =
		    cpu_to_le64(rx_ring->buffer_info[i].dma);
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
		memset(skb->data, 0x00, skb->len);
	}

	return 0;

err_nomem:
	e1000_free_desc_rings(adapter);
	return ret_val;
}

static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
{
	/* Write out to PHY registers 29 and 30 to disable the Receiver. */
	e1e_wphy(&adapter->hw, 29, 0x001F);
	e1e_wphy(&adapter->hw, 30, 0x8FFC);
	e1e_wphy(&adapter->hw, 29, 0x001A);
	e1e_wphy(&adapter->hw, 30, 0x8FF0);
}

static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
{
	struct e1000_hw *hw = &adapter->hw;
	u32 ctrl_reg = 0;
1281
	u16 phy_reg = 0;
1282
	s32 ret_val = 0;
1283

1284
	hw->mac.autoneg = 0;
1285

1286
	if (hw->phy.type == e1000_phy_ife) {
1287
		/* force 100, set loopback */
1288
		e1e_wphy(hw, MII_BMCR, 0x6100);
1289 1290

		/* Now set up the MAC to the same speed/duplex as the PHY. */
1291
		ctrl_reg = er32(CTRL);
1292 1293 1294 1295 1296
		ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
		ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
			     E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
			     E1000_CTRL_SPD_100 |/* Force Speed to 100 */
			     E1000_CTRL_FD);	 /* Force Duplex to FULL */
1297 1298

		ew32(CTRL, ctrl_reg);
1299
		e1e_flush();
1300
		usleep_range(500, 1000);
1301 1302 1303 1304 1305 1306 1307 1308 1309 1310

		return 0;
	}

	/* Specific PHY configuration for loopback */
	switch (hw->phy.type) {
	case e1000_phy_m88:
		/* Auto-MDI/MDIX Off */
		e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
		/* reset to update Auto-MDI/MDIX */
1311
		e1e_wphy(hw, MII_BMCR, 0x9140);
1312
		/* autoneg off */
1313
		e1e_wphy(hw, MII_BMCR, 0x8140);
1314 1315 1316
		break;
	case e1000_phy_gg82563:
		e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
1317
		break;
1318 1319 1320 1321 1322 1323 1324
	case e1000_phy_bm:
		/* Set Default MAC Interface speed to 1GB */
		e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
		phy_reg &= ~0x0007;
		phy_reg |= 0x006;
		e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
		/* Assert SW reset for above settings to take effect */
1325
		hw->phy.ops.commit(hw);
1326
		usleep_range(1000, 2000);
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338
		/* Force Full Duplex */
		e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
		e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
		/* Set Link Up (in force link) */
		e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
		e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
		/* Force Link */
		e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
		e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
		/* Set Early Link Enable */
		e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
		e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
1339 1340 1341 1342
		break;
	case e1000_phy_82577:
	case e1000_phy_82578:
		/* Workaround: K1 must be disabled for stable 1Gbps operation */
1343 1344 1345 1346 1347
		ret_val = hw->phy.ops.acquire(hw);
		if (ret_val) {
			e_err("Cannot setup 1Gbps loopback.\n");
			return ret_val;
		}
1348
		e1000_configure_k1_ich8lan(hw, false);
1349
		hw->phy.ops.release(hw);
1350
		break;
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
	case e1000_phy_82579:
		/* Disable PHY energy detect power down */
		e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
		e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
		/* Disable full chip energy detect */
		e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
		e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
		/* Enable loopback on the PHY */
		e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
		break;
1361
	default:
1362 1363
		break;
	}
1364

1365
	/* force 1000, set loopback */
1366
	e1e_wphy(hw, MII_BMCR, 0x4140);
1367
	msleep(250);
1368

1369 1370 1371 1372 1373 1374 1375 1376 1377 1378
	/* Now set up the MAC to the same speed/duplex as the PHY. */
	ctrl_reg = er32(CTRL);
	ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
	ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
		     E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
		     E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
		     E1000_CTRL_FD);	 /* Force Duplex to FULL */

	if (adapter->flags & FLAG_IS_ICH)
		ctrl_reg |= E1000_CTRL_SLU;	/* Set Link Up */
1379

1380 1381
	if (hw->phy.media_type == e1000_media_type_copper &&
	    hw->phy.type == e1000_phy_m88) {
1382 1383
		ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
	} else {
B
Bruce Allan 已提交
1384
		/* Set the ILOS bit on the fiber Nic if half duplex link is
1385 1386
		 * detected.
		 */
1387
		if ((er32(STATUS) & E1000_STATUS_FD) == 0)
1388 1389 1390 1391 1392
			ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
	}

	ew32(CTRL, ctrl_reg);

B
Bruce Allan 已提交
1393
	/* Disable the receiver on the PHY so when a cable is plugged in, the
1394 1395
	 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
	 */
1396
	if (hw->phy.type == e1000_phy_m88)
1397 1398
		e1000_phy_disable_receiver(adapter);

1399
	usleep_range(500, 1000);
1400 1401 1402 1403 1404 1405 1406 1407

	return 0;
}

static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
{
	struct e1000_hw *hw = &adapter->hw;
	u32 ctrl = er32(CTRL);
1408
	int link;
1409 1410 1411

	/* special requirements for 82571/82572 fiber adapters */

B
Bruce Allan 已提交
1412
	/* jump through hoops to make sure link is up because serdes
1413 1414
	 * link is hardwired up
	 */
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
	ctrl |= E1000_CTRL_SLU;
	ew32(CTRL, ctrl);

	/* disable autoneg */
	ctrl = er32(TXCW);
	ctrl &= ~(1 << 31);
	ew32(TXCW, ctrl);

	link = (er32(STATUS) & E1000_STATUS_LU);

	if (!link) {
		/* set invert loss of signal */
		ctrl = er32(CTRL);
		ctrl |= E1000_CTRL_ILOS;
		ew32(CTRL, ctrl);
	}

B
Bruce Allan 已提交
1432
	/* special write to serdes control register to enable SerDes analog
1433 1434
	 * loopback
	 */
1435
	ew32(SCTL, E1000_SCTL_ENABLE_SERDES_LOOPBACK);
1436
	e1e_flush();
1437
	usleep_range(10000, 20000);
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448

	return 0;
}

/* only call this for fiber/serdes connections to es2lan */
static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
{
	struct e1000_hw *hw = &adapter->hw;
	u32 ctrlext = er32(CTRL_EXT);
	u32 ctrl = er32(CTRL);

B
Bruce Allan 已提交
1449
	/* save CTRL_EXT to restore later, reuse an empty variable (unused
1450 1451
	 * on mac_type 80003es2lan)
	 */
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472
	adapter->tx_fifo_head = ctrlext;

	/* clear the serdes mode bits, putting the device into mac loopback */
	ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
	ew32(CTRL_EXT, ctrlext);

	/* force speed to 1000/FD, link up */
	ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
	ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
		 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
	ew32(CTRL, ctrl);

	/* set mac loopback */
	ctrl = er32(RCTL);
	ctrl |= E1000_RCTL_LBM_MAC;
	ew32(RCTL, ctrl);

	/* set testing mode parameters (no need to reset later) */
#define KMRNCTRLSTA_OPMODE (0x1F << 16)
#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
	ew32(KMRNCTRLSTA,
1473
	     (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
1474 1475 1476 1477 1478 1479 1480 1481 1482

	return 0;
}

static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
{
	struct e1000_hw *hw = &adapter->hw;
	u32 rctl;

1483 1484
	if (hw->phy.media_type == e1000_media_type_fiber ||
	    hw->phy.media_type == e1000_media_type_internal_serdes) {
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498
		switch (hw->mac.type) {
		case e1000_80003es2lan:
			return e1000_set_es2lan_mac_loopback(adapter);
			break;
		case e1000_82571:
		case e1000_82572:
			return e1000_set_82571_fiber_loopback(adapter);
			break;
		default:
			rctl = er32(RCTL);
			rctl |= E1000_RCTL_LBM_TCVR;
			ew32(RCTL, rctl);
			return 0;
		}
1499
	} else if (hw->phy.media_type == e1000_media_type_copper) {
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517
		return e1000_integrated_phy_loopback(adapter);
	}

	return 7;
}

static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
{
	struct e1000_hw *hw = &adapter->hw;
	u32 rctl;
	u16 phy_reg;

	rctl = er32(RCTL);
	rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
	ew32(RCTL, rctl);

	switch (hw->mac.type) {
	case e1000_80003es2lan:
1518 1519
		if (hw->phy.media_type == e1000_media_type_fiber ||
		    hw->phy.media_type == e1000_media_type_internal_serdes) {
1520
			/* restore CTRL_EXT, stealing space from tx_fifo_head */
1521
			ew32(CTRL_EXT, adapter->tx_fifo_head);
1522 1523 1524 1525 1526
			adapter->tx_fifo_head = 0;
		}
		/* fall through */
	case e1000_82571:
	case e1000_82572:
1527 1528
		if (hw->phy.media_type == e1000_media_type_fiber ||
		    hw->phy.media_type == e1000_media_type_internal_serdes) {
1529
			ew32(SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1530
			e1e_flush();
1531
			usleep_range(10000, 20000);
1532 1533 1534 1535 1536 1537 1538
			break;
		}
		/* Fall Through */
	default:
		hw->mac.autoneg = 1;
		if (hw->phy.type == e1000_phy_gg82563)
			e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1539 1540 1541 1542
		e1e_rphy(hw, MII_BMCR, &phy_reg);
		if (phy_reg & BMCR_LOOPBACK) {
			phy_reg &= ~BMCR_LOOPBACK;
			e1e_wphy(hw, MII_BMCR, phy_reg);
1543 1544
			if (hw->phy.ops.commit)
				hw->phy.ops.commit(hw);
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565
		}
		break;
	}
}

static void e1000_create_lbtest_frame(struct sk_buff *skb,
				      unsigned int frame_size)
{
	memset(skb->data, 0xFF, frame_size);
	frame_size &= ~1;
	memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
	memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
	memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
}

static int e1000_check_lbtest_frame(struct sk_buff *skb,
				    unsigned int frame_size)
{
	frame_size &= ~1;
	if (*(skb->data + 3) == 0xFF)
		if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1566
		    (*(skb->data + frame_size / 2 + 12) == 0xAF))
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576
			return 0;
	return 13;
}

static int e1000_run_loopback_test(struct e1000_adapter *adapter)
{
	struct e1000_ring *tx_ring = &adapter->test_tx_ring;
	struct e1000_ring *rx_ring = &adapter->test_rx_ring;
	struct pci_dev *pdev = adapter->pdev;
	struct e1000_hw *hw = &adapter->hw;
1577
	struct e1000_buffer *buffer_info;
1578 1579 1580 1581 1582 1583
	int i, j, k, l;
	int lc;
	int good_cnt;
	int ret_val = 0;
	unsigned long time;

1584
	ew32(RDT(0), rx_ring->count - 1);
1585

B
Bruce Allan 已提交
1586
	/* Calculate the loop count based on the largest descriptor ring
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597
	 * The idea is to wrap the largest ring a number of times using 64
	 * send/receive pairs during each loop
	 */

	if (rx_ring->count <= tx_ring->count)
		lc = ((tx_ring->count / 64) * 2) + 1;
	else
		lc = ((rx_ring->count / 64) * 2) + 1;

	k = 0;
	l = 0;
1598 1599 1600 1601
	/* loop count loop */
	for (j = 0; j <= lc; j++) {
		/* send the packets */
		for (i = 0; i < 64; i++) {
1602 1603 1604
			buffer_info = &tx_ring->buffer_info[k];

			e1000_create_lbtest_frame(buffer_info->skb, 1024);
1605
			dma_sync_single_for_device(&pdev->dev,
1606 1607 1608
						   buffer_info->dma,
						   buffer_info->length,
						   DMA_TO_DEVICE);
1609 1610 1611 1612
			k++;
			if (k == tx_ring->count)
				k = 0;
		}
1613
		ew32(TDT(0), k);
1614
		e1e_flush();
1615 1616 1617
		msleep(200);
		time = jiffies; /* set the start time for the receive */
		good_cnt = 0;
1618 1619
		/* receive the sent packets */
		do {
1620 1621
			buffer_info = &rx_ring->buffer_info[l];

1622
			dma_sync_single_for_cpu(&pdev->dev,
1623 1624
						buffer_info->dma, 2048,
						DMA_FROM_DEVICE);
1625

1626 1627
			ret_val = e1000_check_lbtest_frame(buffer_info->skb,
							   1024);
1628 1629 1630 1631 1632
			if (!ret_val)
				good_cnt++;
			l++;
			if (l == rx_ring->count)
				l = 0;
B
Bruce Allan 已提交
1633
			/* time + 20 msecs (200 msecs on 2.4) is more than
1634 1635 1636 1637 1638 1639 1640 1641
			 * enough time to complete the receives, if it's
			 * exceeded, break and error off
			 */
		} while ((good_cnt < 64) && !time_after(jiffies, time + 20));
		if (good_cnt != 64) {
			ret_val = 13; /* ret_val is the same as mis-compare */
			break;
		}
1642
		if (jiffies >= (time + 20)) {
1643 1644 1645
			ret_val = 14; /* error code for time out error */
			break;
		}
1646
	}
1647 1648 1649 1650 1651
	return ret_val;
}

static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
{
1652 1653
	struct e1000_hw *hw = &adapter->hw;

B
Bruce Allan 已提交
1654
	/* PHY loopback cannot be performed if SoL/IDER sessions are active */
1655 1656
	if (hw->phy.ops.check_reset_block &&
	    hw->phy.ops.check_reset_block(hw)) {
1657
		e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
1658 1659 1660 1661 1662
		*data = 0;
		goto out;
	}

	*data = e1000_setup_desc_rings(adapter);
A
Adrian Bunk 已提交
1663
	if (*data)
1664 1665 1666
		goto out;

	*data = e1000_setup_loopback_test(adapter);
A
Adrian Bunk 已提交
1667
	if (*data)
1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683
		goto err_loopback;

	*data = e1000_run_loopback_test(adapter);
	e1000_loopback_cleanup(adapter);

err_loopback:
	e1000_free_desc_rings(adapter);
out:
	return *data;
}

static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
{
	struct e1000_hw *hw = &adapter->hw;

	*data = 0;
1684
	if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1685
		int i = 0;
1686
		hw->mac.serdes_has_link = false;
1687

B
Bruce Allan 已提交
1688
		/* On some blade server designs, link establishment
1689 1690
		 * could take as long as 2-3 minutes
		 */
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701
		do {
			hw->mac.ops.check_for_link(hw);
			if (hw->mac.serdes_has_link)
				return *data;
			msleep(20);
		} while (i++ < 3750);

		*data = 1;
	} else {
		hw->mac.ops.check_for_link(hw);
		if (hw->mac.autoneg)
B
Bruce Allan 已提交
1702
			/* On some Phy/switch combinations, link establishment
1703 1704
			 * can take a few seconds more than expected.
			 */
1705
			msleep_interruptible(5000);
1706

1707
		if (!(er32(STATUS) & E1000_STATUS_LU))
1708 1709 1710 1711 1712
			*data = 1;
	}
	return *data;
}

1713 1714
static int e1000e_get_sset_count(struct net_device __always_unused *netdev,
				 int sset)
1715
{
1716 1717 1718 1719 1720 1721 1722 1723
	switch (sset) {
	case ETH_SS_TEST:
		return E1000_TEST_LEN;
	case ETH_SS_STATS:
		return E1000_STATS_LEN;
	default:
		return -EOPNOTSUPP;
	}
1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735
}

static void e1000_diag_test(struct net_device *netdev,
			    struct ethtool_test *eth_test, u64 *data)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	u16 autoneg_advertised;
	u8 forced_speed_duplex;
	u8 autoneg;
	bool if_running = netif_running(netdev);

	set_bit(__E1000_TESTING, &adapter->state);
1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748

	if (!if_running) {
		/* Get control of and reset hardware */
		if (adapter->flags & FLAG_HAS_AMT)
			e1000e_get_hw_control(adapter);

		e1000e_power_up_phy(adapter);

		adapter->hw.phy.autoneg_wait_to_complete = 1;
		e1000e_reset(adapter);
		adapter->hw.phy.autoneg_wait_to_complete = 0;
	}

1749 1750 1751 1752 1753 1754 1755 1756
	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
		/* Offline tests */

		/* save speed, duplex, autoneg settings */
		autoneg_advertised = adapter->hw.phy.autoneg_advertised;
		forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
		autoneg = adapter->hw.mac.autoneg;

1757
		e_info("offline testing starting\n");
1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777

		if (if_running)
			/* indicate we're in test mode */
			dev_close(netdev);

		if (e1000_reg_test(adapter, &data[0]))
			eth_test->flags |= ETH_TEST_FL_FAILED;

		e1000e_reset(adapter);
		if (e1000_eeprom_test(adapter, &data[1]))
			eth_test->flags |= ETH_TEST_FL_FAILED;

		e1000e_reset(adapter);
		if (e1000_intr_test(adapter, &data[2]))
			eth_test->flags |= ETH_TEST_FL_FAILED;

		e1000e_reset(adapter);
		if (e1000_loopback_test(adapter, &data[3]))
			eth_test->flags |= ETH_TEST_FL_FAILED;

1778 1779 1780 1781 1782 1783 1784 1785
		/* force this routine to wait until autoneg complete/timeout */
		adapter->hw.phy.autoneg_wait_to_complete = 1;
		e1000e_reset(adapter);
		adapter->hw.phy.autoneg_wait_to_complete = 0;

		if (e1000_link_test(adapter, &data[4]))
			eth_test->flags |= ETH_TEST_FL_FAILED;

1786 1787 1788 1789 1790 1791 1792 1793 1794 1795
		/* restore speed, duplex, autoneg settings */
		adapter->hw.phy.autoneg_advertised = autoneg_advertised;
		adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
		adapter->hw.mac.autoneg = autoneg;
		e1000e_reset(adapter);

		clear_bit(__E1000_TESTING, &adapter->state);
		if (if_running)
			dev_open(netdev);
	} else {
1796
		/* Online tests */
1797

1798
		e_info("online testing starting\n");
1799

1800
		/* register, eeprom, intr and loopback tests not run online */
1801 1802 1803 1804 1805
		data[0] = 0;
		data[1] = 0;
		data[2] = 0;
		data[3] = 0;

1806 1807
		if (e1000_link_test(adapter, &data[4]))
			eth_test->flags |= ETH_TEST_FL_FAILED;
1808

1809 1810
		clear_bit(__E1000_TESTING, &adapter->state);
	}
1811 1812 1813 1814 1815 1816 1817 1818

	if (!if_running) {
		e1000e_reset(adapter);

		if (adapter->flags & FLAG_HAS_AMT)
			e1000e_release_hw_control(adapter);
	}

1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829
	msleep_interruptible(4 * 1000);
}

static void e1000_get_wol(struct net_device *netdev,
			  struct ethtool_wolinfo *wol)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);

	wol->supported = 0;
	wol->wolopts = 0;

1830 1831
	if (!(adapter->flags & FLAG_HAS_WOL) ||
	    !device_can_wakeup(&adapter->pdev->dev))
1832 1833 1834
		return;

	wol->supported = WAKE_UCAST | WAKE_MCAST |
1835
	    WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
1836 1837 1838 1839 1840 1841

	/* apply any specific unsupported masks here */
	if (adapter->flags & FLAG_NO_WAKE_UCAST) {
		wol->supported &= ~WAKE_UCAST;

		if (adapter->wol & E1000_WUFC_EX)
1842
			e_err("Interface does not support directed (unicast) frame wake-up packets\n");
1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
	}

	if (adapter->wol & E1000_WUFC_EX)
		wol->wolopts |= WAKE_UCAST;
	if (adapter->wol & E1000_WUFC_MC)
		wol->wolopts |= WAKE_MCAST;
	if (adapter->wol & E1000_WUFC_BC)
		wol->wolopts |= WAKE_BCAST;
	if (adapter->wol & E1000_WUFC_MAG)
		wol->wolopts |= WAKE_MAGIC;
1853 1854
	if (adapter->wol & E1000_WUFC_LNKC)
		wol->wolopts |= WAKE_PHY;
1855 1856
}

1857
static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1858 1859 1860
{
	struct e1000_adapter *adapter = netdev_priv(netdev);

1861
	if (!(adapter->flags & FLAG_HAS_WOL) ||
1862 1863
	    !device_can_wakeup(&adapter->pdev->dev) ||
	    (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
1864
			      WAKE_MAGIC | WAKE_PHY)))
1865
		return -EOPNOTSUPP;
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877

	/* these settings will always override what we currently have */
	adapter->wol = 0;

	if (wol->wolopts & WAKE_UCAST)
		adapter->wol |= E1000_WUFC_EX;
	if (wol->wolopts & WAKE_MCAST)
		adapter->wol |= E1000_WUFC_MC;
	if (wol->wolopts & WAKE_BCAST)
		adapter->wol |= E1000_WUFC_BC;
	if (wol->wolopts & WAKE_MAGIC)
		adapter->wol |= E1000_WUFC_MAG;
1878 1879
	if (wol->wolopts & WAKE_PHY)
		adapter->wol |= E1000_WUFC_LNKC;
1880

1881 1882
	device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);

1883 1884 1885
	return 0;
}

1886 1887
static int e1000_set_phys_id(struct net_device *netdev,
			     enum ethtool_phys_id_state state)
1888 1889
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
1890
	struct e1000_hw *hw = &adapter->hw;
1891

1892 1893 1894 1895
	switch (state) {
	case ETHTOOL_ID_ACTIVE:
		if (!hw->mac.ops.blink_led)
			return 2;	/* cycle on/off twice per second */
1896

1897 1898 1899 1900
		hw->mac.ops.blink_led(hw);
		break;

	case ETHTOOL_ID_INACTIVE:
1901 1902
		if (hw->phy.type == e1000_phy_ife)
			e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
1903 1904 1905
		hw->mac.ops.led_off(hw);
		hw->mac.ops.cleanup_led(hw);
		break;
1906

1907
	case ETHTOOL_ID_ON:
B
Bruce Allan 已提交
1908
		hw->mac.ops.led_on(hw);
1909
		break;
1910

1911
	case ETHTOOL_ID_OFF:
B
Bruce Allan 已提交
1912
		hw->mac.ops.led_off(hw);
1913 1914
		break;
	}
1915 1916 1917
	return 0;
}

1918 1919 1920 1921 1922
static int e1000_get_coalesce(struct net_device *netdev,
			      struct ethtool_coalesce *ec)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);

1923
	if (adapter->itr_setting <= 4)
1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936
		ec->rx_coalesce_usecs = adapter->itr_setting;
	else
		ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;

	return 0;
}

static int e1000_set_coalesce(struct net_device *netdev,
			      struct ethtool_coalesce *ec)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);

	if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
1937
	    ((ec->rx_coalesce_usecs > 4) &&
1938 1939 1940 1941
	     (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
	    (ec->rx_coalesce_usecs == 2))
		return -EINVAL;

1942
	if (ec->rx_coalesce_usecs == 4) {
1943 1944
		adapter->itr_setting = 4;
		adapter->itr = adapter->itr_setting;
1945
	} else if (ec->rx_coalesce_usecs <= 3) {
1946 1947 1948 1949 1950 1951 1952 1953
		adapter->itr = 20000;
		adapter->itr_setting = ec->rx_coalesce_usecs;
	} else {
		adapter->itr = (1000000 / ec->rx_coalesce_usecs);
		adapter->itr_setting = adapter->itr & ~3;
	}

	if (adapter->itr_setting != 0)
1954
		e1000e_write_itr(adapter, adapter->itr);
1955
	else
1956
		e1000e_write_itr(adapter, 0);
1957 1958 1959 1960

	return 0;
}

1961 1962 1963
static int e1000_nway_reset(struct net_device *netdev)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
1964 1965 1966 1967 1968 1969 1970 1971 1972

	if (!netif_running(netdev))
		return -EAGAIN;

	if (!adapter->hw.mac.autoneg)
		return -EINVAL;

	e1000e_reinit_locked(adapter);

1973 1974 1975 1976
	return 0;
}

static void e1000_get_ethtool_stats(struct net_device *netdev,
1977
				    struct ethtool_stats __always_unused *stats,
1978 1979 1980
				    u64 *data)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
J
Jeff Kirsher 已提交
1981
	struct rtnl_link_stats64 net_stats;
1982
	int i;
1983
	char *p = NULL;
1984

J
Jeff Kirsher 已提交
1985
	e1000e_get_stats64(netdev, &net_stats);
1986
	for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1987 1988
		switch (e1000_gstrings_stats[i].type) {
		case NETDEV_STATS:
1989
			p = (char *)&net_stats +
1990
			    e1000_gstrings_stats[i].stat_offset;
1991 1992
			break;
		case E1000_STATS:
1993
			p = (char *)adapter +
1994
			    e1000_gstrings_stats[i].stat_offset;
1995
			break;
1996 1997 1998
		default:
			data[i] = 0;
			continue;
1999 2000
		}

2001
		data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
2002
			   sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2003 2004 2005
	}
}

2006 2007
static void e1000_get_strings(struct net_device __always_unused *netdev,
			      u32 stringset, u8 *data)
2008 2009 2010 2011 2012 2013
{
	u8 *p = data;
	int i;

	switch (stringset) {
	case ETH_SS_TEST:
2014
		memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025
		break;
	case ETH_SS_STATS:
		for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
			memcpy(p, e1000_gstrings_stats[i].stat_string,
			       ETH_GSTRING_LEN);
			p += ETH_GSTRING_LEN;
		}
		break;
	}
}

2026
static int e1000_get_rxnfc(struct net_device *netdev,
2027 2028
			   struct ethtool_rxnfc *info,
			   u32 __always_unused *rule_locs)
2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073
{
	info->data = 0;

	switch (info->cmd) {
	case ETHTOOL_GRXFH: {
		struct e1000_adapter *adapter = netdev_priv(netdev);
		struct e1000_hw *hw = &adapter->hw;
		u32 mrqc = er32(MRQC);

		if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
			return 0;

		switch (info->flow_type) {
		case TCP_V4_FLOW:
			if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
				info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
			/* fall through */
		case UDP_V4_FLOW:
		case SCTP_V4_FLOW:
		case AH_ESP_V4_FLOW:
		case IPV4_FLOW:
			if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
				info->data |= RXH_IP_SRC | RXH_IP_DST;
			break;
		case TCP_V6_FLOW:
			if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
				info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
			/* fall through */
		case UDP_V6_FLOW:
		case SCTP_V6_FLOW:
		case AH_ESP_V6_FLOW:
		case IPV6_FLOW:
			if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
				info->data |= RXH_IP_SRC | RXH_IP_DST;
			break;
		default:
			break;
		}
		return 0;
	}
	default:
		return -EOPNOTSUPP;
	}
}

2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204
static int e1000e_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	struct e1000_hw *hw = &adapter->hw;
	u16 cap_addr, adv_addr, lpa_addr, pcs_stat_addr, phy_data, lpi_ctrl;
	u32 status, ret_val;

	if (!(adapter->flags & FLAG_IS_ICH) ||
	    !(adapter->flags2 & FLAG2_HAS_EEE))
		return -EOPNOTSUPP;

	switch (hw->phy.type) {
	case e1000_phy_82579:
		cap_addr = I82579_EEE_CAPABILITY;
		adv_addr = I82579_EEE_ADVERTISEMENT;
		lpa_addr = I82579_EEE_LP_ABILITY;
		pcs_stat_addr = I82579_EEE_PCS_STATUS;
		break;
	case e1000_phy_i217:
		cap_addr = I217_EEE_CAPABILITY;
		adv_addr = I217_EEE_ADVERTISEMENT;
		lpa_addr = I217_EEE_LP_ABILITY;
		pcs_stat_addr = I217_EEE_PCS_STATUS;
		break;
	default:
		return -EOPNOTSUPP;
	}

	ret_val = hw->phy.ops.acquire(hw);
	if (ret_val)
		return -EBUSY;

	/* EEE Capability */
	ret_val = e1000_read_emi_reg_locked(hw, cap_addr, &phy_data);
	if (ret_val)
		goto release;
	edata->supported = mmd_eee_cap_to_ethtool_sup_t(phy_data);

	/* EEE Advertised */
	ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &phy_data);
	if (ret_val)
		goto release;
	edata->advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);

	/* EEE Link Partner Advertised */
	ret_val = e1000_read_emi_reg_locked(hw, lpa_addr, &phy_data);
	if (ret_val)
		goto release;
	edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);

	/* EEE PCS Status */
	ret_val = e1000_read_emi_reg_locked(hw, pcs_stat_addr, &phy_data);
	if (hw->phy.type == e1000_phy_82579)
		phy_data <<= 8;

release:
	hw->phy.ops.release(hw);
	if (ret_val)
		return -ENODATA;

	e1e_rphy(hw, I82579_LPI_CTRL, &lpi_ctrl);
	status = er32(STATUS);

	/* Result of the EEE auto negotiation - there is no register that
	 * has the status of the EEE negotiation so do a best-guess based
	 * on whether both Tx and Rx LPI indications have been received or
	 * base it on the link speed, the EEE advertised speeds on both ends
	 * and the speeds on which EEE is enabled locally.
	 */
	if (((phy_data & E1000_EEE_TX_LPI_RCVD) &&
	     (phy_data & E1000_EEE_RX_LPI_RCVD)) ||
	    ((status & E1000_STATUS_SPEED_100) &&
	     (edata->advertised & ADVERTISED_100baseT_Full) &&
	     (edata->lp_advertised & ADVERTISED_100baseT_Full) &&
	     (lpi_ctrl & I82579_LPI_CTRL_100_ENABLE)) ||
	    ((status & E1000_STATUS_SPEED_1000) &&
	     (edata->advertised & ADVERTISED_1000baseT_Full) &&
	     (edata->lp_advertised & ADVERTISED_1000baseT_Full) &&
	     (lpi_ctrl & I82579_LPI_CTRL_1000_ENABLE)))
		edata->eee_active = true;

	edata->eee_enabled = !hw->dev_spec.ich8lan.eee_disable;
	edata->tx_lpi_enabled = true;
	edata->tx_lpi_timer = er32(LPIC) >> E1000_LPIC_LPIET_SHIFT;

	return 0;
}

static int e1000e_set_eee(struct net_device *netdev, struct ethtool_eee *edata)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);
	struct e1000_hw *hw = &adapter->hw;
	struct ethtool_eee eee_curr;
	s32 ret_val;

	if (!(adapter->flags & FLAG_IS_ICH) ||
	    !(adapter->flags2 & FLAG2_HAS_EEE))
		return -EOPNOTSUPP;

	ret_val = e1000e_get_eee(netdev, &eee_curr);
	if (ret_val)
		return ret_val;

	if (eee_curr.advertised != edata->advertised) {
		e_err("Setting EEE advertisement is not supported\n");
		return -EINVAL;
	}

	if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
		e_err("Setting EEE tx-lpi is not supported\n");
		return -EINVAL;
	}

	if (eee_curr.tx_lpi_timer != edata->tx_lpi_timer) {
		e_err("Setting EEE Tx LPI timer is not supported\n");
		return -EINVAL;
	}

	if (hw->dev_spec.ich8lan.eee_disable != !edata->eee_enabled) {
		hw->dev_spec.ich8lan.eee_disable = !edata->eee_enabled;

		/* reset the link */
		if (netif_running(netdev))
			e1000e_reinit_locked(adapter);
		else
			e1000e_reset(adapter);
	}

	return 0;
}

2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221
static int e1000e_get_ts_info(struct net_device *netdev,
			      struct ethtool_ts_info *info)
{
	struct e1000_adapter *adapter = netdev_priv(netdev);

	ethtool_op_get_ts_info(netdev, info);

	if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
		return 0;

	info->so_timestamping |= (SOF_TIMESTAMPING_TX_HARDWARE |
				  SOF_TIMESTAMPING_RX_HARDWARE |
				  SOF_TIMESTAMPING_RAW_HARDWARE);

	info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);

	info->rx_filters = ((1 << HWTSTAMP_FILTER_NONE) |
2222 2223 2224 2225 2226 2227 2228 2229 2230
			    (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
			    (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
			    (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
			    (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
			    (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
			    (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
			    (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
			    (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
			    (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
2231 2232
			    (1 << HWTSTAMP_FILTER_ALL));

2233 2234 2235
	if (adapter->ptp_clock)
		info->phc_index = ptp_clock_index(adapter->ptp_clock);

2236 2237 2238
	return 0;
}

2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249
static const struct ethtool_ops e1000_ethtool_ops = {
	.get_settings		= e1000_get_settings,
	.set_settings		= e1000_set_settings,
	.get_drvinfo		= e1000_get_drvinfo,
	.get_regs_len		= e1000_get_regs_len,
	.get_regs		= e1000_get_regs,
	.get_wol		= e1000_get_wol,
	.set_wol		= e1000_set_wol,
	.get_msglevel		= e1000_get_msglevel,
	.set_msglevel		= e1000_set_msglevel,
	.nway_reset		= e1000_nway_reset,
2250
	.get_link		= ethtool_op_get_link,
2251 2252 2253 2254 2255 2256 2257 2258 2259
	.get_eeprom_len		= e1000_get_eeprom_len,
	.get_eeprom		= e1000_get_eeprom,
	.set_eeprom		= e1000_set_eeprom,
	.get_ringparam		= e1000_get_ringparam,
	.set_ringparam		= e1000_set_ringparam,
	.get_pauseparam		= e1000_get_pauseparam,
	.set_pauseparam		= e1000_set_pauseparam,
	.self_test		= e1000_diag_test,
	.get_strings		= e1000_get_strings,
2260
	.set_phys_id		= e1000_set_phys_id,
2261
	.get_ethtool_stats	= e1000_get_ethtool_stats,
2262
	.get_sset_count		= e1000e_get_sset_count,
2263 2264
	.get_coalesce		= e1000_get_coalesce,
	.set_coalesce		= e1000_set_coalesce,
2265
	.get_rxnfc		= e1000_get_rxnfc,
2266
	.get_ts_info		= e1000e_get_ts_info,
2267 2268
	.get_eee		= e1000e_get_eee,
	.set_eee		= e1000e_set_eee,
2269 2270 2271 2272 2273 2274
};

void e1000e_set_ethtool_ops(struct net_device *netdev)
{
	SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
}