e1000_ethtool.c 57.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2
/*******************************************************************************

3 4 5 6 7 8 9 10 11 12
  Intel PRO/1000 Linux driver
  Copyright(c) 1999 - 2006 Intel Corporation.

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

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

L
Linus Torvalds 已提交
15
  You should have received a copy of the GNU General Public License along with
16 17 18 19 20 21
  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".

L
Linus Torvalds 已提交
22 23
  Contact Information:
  Linux NICS <linux.nics@intel.com>
24
  e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
L
Linus Torvalds 已提交
25 26 27 28 29 30 31 32 33 34
  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497

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

/* ethtool support for e1000 */

#include "e1000.h"

#include <asm/uaccess.h>

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
extern char e1000_driver_name[];
extern char e1000_driver_version[];

extern int e1000_up(struct e1000_adapter *adapter);
extern void e1000_down(struct e1000_adapter *adapter);
extern void e1000_reinit_locked(struct e1000_adapter *adapter);
extern void e1000_reset(struct e1000_adapter *adapter);
extern int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
extern int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
extern int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
extern void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
extern void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
extern void e1000_update_stats(struct e1000_adapter *adapter);


L
Linus Torvalds 已提交
50 51 52 53 54 55 56 57 58
struct e1000_stats {
	char stat_string[ETH_GSTRING_LEN];
	int sizeof_stat;
	int stat_offset;
};

#define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
		      offsetof(struct e1000_adapter, m)
static const struct e1000_stats e1000_gstrings_stats[] = {
59 60 61 62 63 64 65 66 67 68
	{ "rx_packets", E1000_STAT(stats.gprc) },
	{ "tx_packets", E1000_STAT(stats.gptc) },
	{ "rx_bytes", E1000_STAT(stats.gorcl) },
	{ "tx_bytes", E1000_STAT(stats.gotcl) },
	{ "rx_broadcast", E1000_STAT(stats.bprc) },
	{ "tx_broadcast", E1000_STAT(stats.bptc) },
	{ "rx_multicast", E1000_STAT(stats.mprc) },
	{ "tx_multicast", E1000_STAT(stats.mptc) },
	{ "rx_errors", E1000_STAT(stats.rxerrc) },
	{ "tx_errors", E1000_STAT(stats.txerrc) },
L
Linus Torvalds 已提交
69
	{ "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
70 71 72
	{ "multicast", E1000_STAT(stats.mprc) },
	{ "collisions", E1000_STAT(stats.colc) },
	{ "rx_length_errors", E1000_STAT(stats.rlerrc) },
L
Linus Torvalds 已提交
73
	{ "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
74
	{ "rx_crc_errors", E1000_STAT(stats.crcerrs) },
L
Linus Torvalds 已提交
75
	{ "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
76
	{ "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
77 78 79
	{ "rx_missed_errors", E1000_STAT(stats.mpc) },
	{ "tx_aborted_errors", E1000_STAT(stats.ecol) },
	{ "tx_carrier_errors", E1000_STAT(stats.tncrs) },
L
Linus Torvalds 已提交
80 81
	{ "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) },
	{ "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) },
82
	{ "tx_window_errors", E1000_STAT(stats.latecol) },
L
Linus Torvalds 已提交
83 84 85 86
	{ "tx_abort_late_coll", E1000_STAT(stats.latecol) },
	{ "tx_deferred_ok", E1000_STAT(stats.dc) },
	{ "tx_single_coll_ok", E1000_STAT(stats.scc) },
	{ "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
J
Jeff Kirsher 已提交
87
	{ "tx_timeout_count", E1000_STAT(tx_timeout_count) },
L
Linus Torvalds 已提交
88 89 90 91 92 93 94 95 96 97 98
	{ "rx_long_length_errors", E1000_STAT(stats.roc) },
	{ "rx_short_length_errors", E1000_STAT(stats.ruc) },
	{ "rx_align_errors", E1000_STAT(stats.algnerrc) },
	{ "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
	{ "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
	{ "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
	{ "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
	{ "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
	{ "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
	{ "rx_long_byte_count", E1000_STAT(stats.gorcl) },
	{ "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
99 100
	{ "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
	{ "rx_header_split", E1000_STAT(rx_hdr_split) },
J
Jeff Kirsher 已提交
101
	{ "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
L
Linus Torvalds 已提交
102
};
103 104 105

#define E1000_QUEUE_STATS_LEN 0
#define E1000_GLOBAL_STATS_LEN	\
L
Linus Torvalds 已提交
106
	sizeof(e1000_gstrings_stats) / sizeof(struct e1000_stats)
107
#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
L
Linus Torvalds 已提交
108 109 110 111 112 113 114 115 116 117
static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
	"Register test  (offline)", "Eeprom test    (offline)",
	"Interrupt test (offline)", "Loopback test  (offline)",
	"Link test   (on/offline)"
};
#define E1000_TEST_LEN sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN

static int
e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
{
118
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
119 120
	struct e1000_hw *hw = &adapter->hw;

J
Jesse Brandeburg 已提交
121
	if (hw->media_type == e1000_media_type_copper) {
L
Linus Torvalds 已提交
122 123 124 125 126 127 128 129

		ecmd->supported = (SUPPORTED_10baseT_Half |
		                   SUPPORTED_10baseT_Full |
		                   SUPPORTED_100baseT_Half |
		                   SUPPORTED_100baseT_Full |
		                   SUPPORTED_1000baseT_Full|
		                   SUPPORTED_Autoneg |
		                   SUPPORTED_TP);
130 131
		if (hw->phy_type == e1000_phy_ife)
			ecmd->supported &= ~SUPPORTED_1000baseT_Full;
L
Linus Torvalds 已提交
132 133
		ecmd->advertising = ADVERTISED_TP;

J
Jesse Brandeburg 已提交
134
		if (hw->autoneg == 1) {
L
Linus Torvalds 已提交
135 136 137 138 139 140 141 142 143 144
			ecmd->advertising |= ADVERTISED_Autoneg;

			/* the e1000 autoneg seems to match ethtool nicely */

			ecmd->advertising |= hw->autoneg_advertised;
		}

		ecmd->port = PORT_TP;
		ecmd->phy_address = hw->phy_addr;

J
Jesse Brandeburg 已提交
145
		if (hw->mac_type == e1000_82543)
L
Linus Torvalds 已提交
146 147 148 149 150 151 152 153 154
			ecmd->transceiver = XCVR_EXTERNAL;
		else
			ecmd->transceiver = XCVR_INTERNAL;

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

155 156 157
		ecmd->advertising = (ADVERTISED_1000baseT_Full |
				     ADVERTISED_FIBRE |
				     ADVERTISED_Autoneg);
L
Linus Torvalds 已提交
158 159 160

		ecmd->port = PORT_FIBRE;

J
Jesse Brandeburg 已提交
161
		if (hw->mac_type >= e1000_82545)
L
Linus Torvalds 已提交
162 163 164 165 166
			ecmd->transceiver = XCVR_INTERNAL;
		else
			ecmd->transceiver = XCVR_EXTERNAL;
	}

J
Jesse Brandeburg 已提交
167
	if (netif_carrier_ok(adapter->netdev)) {
L
Linus Torvalds 已提交
168 169 170 171 172 173 174 175

		e1000_get_speed_and_duplex(hw, &adapter->link_speed,
		                                   &adapter->link_duplex);
		ecmd->speed = adapter->link_speed;

		/* unfortunatly FULL_DUPLEX != DUPLEX_FULL
		 *          and HALF_DUPLEX != DUPLEX_HALF */

J
Jesse Brandeburg 已提交
176
		if (adapter->link_duplex == FULL_DUPLEX)
L
Linus Torvalds 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
			ecmd->duplex = DUPLEX_FULL;
		else
			ecmd->duplex = DUPLEX_HALF;
	} else {
		ecmd->speed = -1;
		ecmd->duplex = -1;
	}

	ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
			 hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
	return 0;
}

static int
e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
{
193
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
194 195
	struct e1000_hw *hw = &adapter->hw;

196 197 198 199 200 201 202 203
	/* When SoL/IDER sessions are active, autoneg/speed/duplex
	 * cannot be changed */
	if (e1000_check_phy_reset_block(hw)) {
		DPRINTK(DRV, ERR, "Cannot change link characteristics "
		        "when SoL/IDER is active.\n");
		return -EINVAL;
	}

204 205 206
	while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
		msleep(1);

207
	if (ecmd->autoneg == AUTONEG_ENABLE) {
L
Linus Torvalds 已提交
208
		hw->autoneg = 1;
J
Jesse Brandeburg 已提交
209
		if (hw->media_type == e1000_media_type_fiber)
210 211 212
			hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
				     ADVERTISED_FIBRE |
				     ADVERTISED_Autoneg;
J
Jesse Brandeburg 已提交
213
		else
214 215 216
			hw->autoneg_advertised = ecmd->advertising |
			                         ADVERTISED_TP |
			                         ADVERTISED_Autoneg;
217
		ecmd->advertising = hw->autoneg_advertised;
L
Linus Torvalds 已提交
218
	} else
219 220
		if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
			clear_bit(__E1000_RESETTING, &adapter->flags);
L
Linus Torvalds 已提交
221
			return -EINVAL;
222
		}
L
Linus Torvalds 已提交
223 224 225

	/* reset the link */

226 227 228 229
	if (netif_running(adapter->netdev)) {
		e1000_down(adapter);
		e1000_up(adapter);
	} else
L
Linus Torvalds 已提交
230 231
		e1000_reset(adapter);

232
	clear_bit(__E1000_RESETTING, &adapter->flags);
L
Linus Torvalds 已提交
233 234 235 236 237 238 239
	return 0;
}

static void
e1000_get_pauseparam(struct net_device *netdev,
                     struct ethtool_pauseparam *pause)
{
240
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
241 242
	struct e1000_hw *hw = &adapter->hw;

J
Jesse Brandeburg 已提交
243
	pause->autoneg =
L
Linus Torvalds 已提交
244
		(adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
J
Jesse Brandeburg 已提交
245

246
	if (hw->fc == E1000_FC_RX_PAUSE)
L
Linus Torvalds 已提交
247
		pause->rx_pause = 1;
248
	else if (hw->fc == E1000_FC_TX_PAUSE)
L
Linus Torvalds 已提交
249
		pause->tx_pause = 1;
250
	else if (hw->fc == E1000_FC_FULL) {
L
Linus Torvalds 已提交
251 252 253 254 255 256 257 258 259
		pause->rx_pause = 1;
		pause->tx_pause = 1;
	}
}

static int
e1000_set_pauseparam(struct net_device *netdev,
                     struct ethtool_pauseparam *pause)
{
260
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
261
	struct e1000_hw *hw = &adapter->hw;
262
	int retval = 0;
J
Jesse Brandeburg 已提交
263

L
Linus Torvalds 已提交
264 265
	adapter->fc_autoneg = pause->autoneg;

266 267 268
	while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
		msleep(1);

J
Jesse Brandeburg 已提交
269
	if (pause->rx_pause && pause->tx_pause)
270
		hw->fc = E1000_FC_FULL;
J
Jesse Brandeburg 已提交
271
	else if (pause->rx_pause && !pause->tx_pause)
272
		hw->fc = E1000_FC_RX_PAUSE;
J
Jesse Brandeburg 已提交
273
	else if (!pause->rx_pause && pause->tx_pause)
274
		hw->fc = E1000_FC_TX_PAUSE;
J
Jesse Brandeburg 已提交
275
	else if (!pause->rx_pause && !pause->tx_pause)
276
		hw->fc = E1000_FC_NONE;
L
Linus Torvalds 已提交
277 278 279

	hw->original_fc = hw->fc;

J
Jesse Brandeburg 已提交
280
	if (adapter->fc_autoneg == AUTONEG_ENABLE) {
281 282 283 284
		if (netif_running(adapter->netdev)) {
			e1000_down(adapter);
			e1000_up(adapter);
		} else
L
Linus Torvalds 已提交
285
			e1000_reset(adapter);
J
Jesse Brandeburg 已提交
286
	} else
287 288
		retval = ((hw->media_type == e1000_media_type_fiber) ?
			   e1000_setup_link(hw) : e1000_force_mac_fc(hw));
J
Jesse Brandeburg 已提交
289

290 291
	clear_bit(__E1000_RESETTING, &adapter->flags);
	return retval;
L
Linus Torvalds 已提交
292 293 294 295 296
}

static uint32_t
e1000_get_rx_csum(struct net_device *netdev)
{
297
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
298 299 300 301 302 303
	return adapter->rx_csum;
}

static int
e1000_set_rx_csum(struct net_device *netdev, uint32_t data)
{
304
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
305 306
	adapter->rx_csum = data;

307 308 309
	if (netif_running(netdev))
		e1000_reinit_locked(adapter);
	else
L
Linus Torvalds 已提交
310 311 312
		e1000_reset(adapter);
	return 0;
}
J
Jesse Brandeburg 已提交
313

L
Linus Torvalds 已提交
314 315 316 317 318 319 320 321 322
static uint32_t
e1000_get_tx_csum(struct net_device *netdev)
{
	return (netdev->features & NETIF_F_HW_CSUM) != 0;
}

static int
e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
{
323
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
324

J
Jesse Brandeburg 已提交
325
	if (adapter->hw.mac_type < e1000_82543) {
L
Linus Torvalds 已提交
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
		if (!data)
			return -EINVAL;
		return 0;
	}

	if (data)
		netdev->features |= NETIF_F_HW_CSUM;
	else
		netdev->features &= ~NETIF_F_HW_CSUM;

	return 0;
}

#ifdef NETIF_F_TSO
static int
e1000_set_tso(struct net_device *netdev, uint32_t data)
{
343
	struct e1000_adapter *adapter = netdev_priv(netdev);
J
Jesse Brandeburg 已提交
344 345
	if ((adapter->hw.mac_type < e1000_82544) ||
	    (adapter->hw.mac_type == e1000_82547))
L
Linus Torvalds 已提交
346 347 348 349 350 351
		return data ? -EINVAL : 0;

	if (data)
		netdev->features |= NETIF_F_TSO;
	else
		netdev->features &= ~NETIF_F_TSO;
352 353 354

	DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
	adapter->tso_force = TRUE;
L
Linus Torvalds 已提交
355
	return 0;
J
Jesse Brandeburg 已提交
356
}
L
Linus Torvalds 已提交
357 358 359 360 361
#endif /* NETIF_F_TSO */

static uint32_t
e1000_get_msglevel(struct net_device *netdev)
{
362
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
363 364 365 366 367 368
	return adapter->msg_enable;
}

static void
e1000_set_msglevel(struct net_device *netdev, uint32_t data)
{
369
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
370 371 372
	adapter->msg_enable = data;
}

J
Jesse Brandeburg 已提交
373
static int
L
Linus Torvalds 已提交
374 375 376 377 378 379 380 381 382 383
e1000_get_regs_len(struct net_device *netdev)
{
#define E1000_REGS_LEN 32
	return E1000_REGS_LEN * sizeof(uint32_t);
}

static void
e1000_get_regs(struct net_device *netdev,
	       struct ethtool_regs *regs, void *p)
{
384
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
	struct e1000_hw *hw = &adapter->hw;
	uint32_t *regs_buff = p;
	uint16_t phy_data;

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

	regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;

	regs_buff[0]  = E1000_READ_REG(hw, CTRL);
	regs_buff[1]  = E1000_READ_REG(hw, STATUS);

	regs_buff[2]  = E1000_READ_REG(hw, RCTL);
	regs_buff[3]  = E1000_READ_REG(hw, RDLEN);
	regs_buff[4]  = E1000_READ_REG(hw, RDH);
	regs_buff[5]  = E1000_READ_REG(hw, RDT);
	regs_buff[6]  = E1000_READ_REG(hw, RDTR);

	regs_buff[7]  = E1000_READ_REG(hw, TCTL);
	regs_buff[8]  = E1000_READ_REG(hw, TDLEN);
	regs_buff[9]  = E1000_READ_REG(hw, TDH);
	regs_buff[10] = E1000_READ_REG(hw, TDT);
	regs_buff[11] = E1000_READ_REG(hw, TIDV);

	regs_buff[12] = adapter->hw.phy_type;  /* PHY type (IGP=1, M88=0) */
J
Jesse Brandeburg 已提交
409
	if (hw->phy_type == e1000_phy_igp) {
L
Linus Torvalds 已提交
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
				    IGP01E1000_PHY_AGC_A);
		e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
				   IGP01E1000_PHY_PAGE_SELECT, &phy_data);
		regs_buff[13] = (uint32_t)phy_data; /* cable length */
		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
				    IGP01E1000_PHY_AGC_B);
		e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
				   IGP01E1000_PHY_PAGE_SELECT, &phy_data);
		regs_buff[14] = (uint32_t)phy_data; /* cable length */
		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
				    IGP01E1000_PHY_AGC_C);
		e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
				   IGP01E1000_PHY_PAGE_SELECT, &phy_data);
		regs_buff[15] = (uint32_t)phy_data; /* cable length */
		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
				    IGP01E1000_PHY_AGC_D);
		e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
				   IGP01E1000_PHY_PAGE_SELECT, &phy_data);
		regs_buff[16] = (uint32_t)phy_data; /* cable length */
		regs_buff[17] = 0; /* extended 10bt distance (not needed) */
		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
		e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
				   IGP01E1000_PHY_PAGE_SELECT, &phy_data);
		regs_buff[18] = (uint32_t)phy_data; /* cable polarity */
		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
				    IGP01E1000_PHY_PCS_INIT_REG);
		e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
				   IGP01E1000_PHY_PAGE_SELECT, &phy_data);
		regs_buff[19] = (uint32_t)phy_data; /* cable polarity */
		regs_buff[20] = 0; /* polarity correction enabled (always) */
		regs_buff[22] = 0; /* phy receive errors (unavailable) */
		regs_buff[23] = regs_buff[18]; /* mdix mode */
		e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
	} else {
445
		e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
L
Linus Torvalds 已提交
446 447 448 449
		regs_buff[13] = (uint32_t)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) */
450
		e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
L
Linus Torvalds 已提交
451 452 453 454 455 456 457 458 459 460 461 462
		regs_buff[17] = (uint32_t)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 */
	}
	regs_buff[21] = adapter->phy_stats.idle_errors;  /* phy idle errors */
	e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
	regs_buff[24] = (uint32_t)phy_data;  /* phy local receiver status */
	regs_buff[25] = regs_buff[24];  /* phy remote receiver status */
J
Jesse Brandeburg 已提交
463
	if (hw->mac_type >= e1000_82540 &&
464 465
	    hw->mac_type < e1000_82571 &&
	    hw->media_type == e1000_media_type_copper) {
L
Linus Torvalds 已提交
466 467 468 469 470 471 472
		regs_buff[26] = E1000_READ_REG(hw, MANC);
	}
}

static int
e1000_get_eeprom_len(struct net_device *netdev)
{
473
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
474 475 476 477 478 479 480
	return adapter->hw.eeprom.word_size * 2;
}

static int
e1000_get_eeprom(struct net_device *netdev,
                      struct ethtool_eeprom *eeprom, uint8_t *bytes)
{
481
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
482 483 484 485 486 487
	struct e1000_hw *hw = &adapter->hw;
	uint16_t *eeprom_buff;
	int first_word, last_word;
	int ret_val = 0;
	uint16_t i;

J
Jesse Brandeburg 已提交
488
	if (eeprom->len == 0)
L
Linus Torvalds 已提交
489 490 491 492 493 494 495 496 497
		return -EINVAL;

	eeprom->magic = hw->vendor_id | (hw->device_id << 16);

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

	eeprom_buff = kmalloc(sizeof(uint16_t) *
			(last_word - first_word + 1), GFP_KERNEL);
J
Jesse Brandeburg 已提交
498
	if (!eeprom_buff)
L
Linus Torvalds 已提交
499 500
		return -ENOMEM;

J
Jesse Brandeburg 已提交
501
	if (hw->eeprom.type == e1000_eeprom_spi)
L
Linus Torvalds 已提交
502 503 504 505 506
		ret_val = e1000_read_eeprom(hw, first_word,
					    last_word - first_word + 1,
					    eeprom_buff);
	else {
		for (i = 0; i < last_word - first_word + 1; i++)
J
Jesse Brandeburg 已提交
507
			if ((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
L
Linus Torvalds 已提交
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
							&eeprom_buff[i])))
				break;
	}

	/* 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(bytes, (uint8_t *)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, uint8_t *bytes)
{
527
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
528 529 530 531 532 533
	struct e1000_hw *hw = &adapter->hw;
	uint16_t *eeprom_buff;
	void *ptr;
	int max_len, first_word, last_word, ret_val = 0;
	uint16_t i;

J
Jesse Brandeburg 已提交
534
	if (eeprom->len == 0)
L
Linus Torvalds 已提交
535 536
		return -EOPNOTSUPP;

J
Jesse Brandeburg 已提交
537
	if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
L
Linus Torvalds 已提交
538 539 540 541 542 543 544
		return -EFAULT;

	max_len = hw->eeprom.word_size * 2;

	first_word = eeprom->offset >> 1;
	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
	eeprom_buff = kmalloc(max_len, GFP_KERNEL);
J
Jesse Brandeburg 已提交
545
	if (!eeprom_buff)
L
Linus Torvalds 已提交
546 547 548 549
		return -ENOMEM;

	ptr = (void *)eeprom_buff;

J
Jesse Brandeburg 已提交
550
	if (eeprom->offset & 1) {
L
Linus Torvalds 已提交
551 552 553 554 555 556
		/* need read/modify/write of first changed EEPROM word */
		/* only the second byte of the word is being modified */
		ret_val = e1000_read_eeprom(hw, first_word, 1,
					    &eeprom_buff[0]);
		ptr++;
	}
J
Jesse Brandeburg 已提交
557
	if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
L
Linus Torvalds 已提交
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
		/* need read/modify/write of last changed EEPROM word */
		/* only the first byte of the word is being modified */
		ret_val = e1000_read_eeprom(hw, last_word, 1,
		                  &eeprom_buff[last_word - first_word]);
	}

	/* 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++)
		eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);

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

J
Jesse Brandeburg 已提交
576
	/* Update the checksum over the first part of the EEPROM if needed
M
Mallikarjuna R Chilakala 已提交
577
	 * and flush shadow RAM for 82573 conrollers */
J
Jesse Brandeburg 已提交
578
	if ((ret_val == 0) && ((first_word <= EEPROM_CHECKSUM_REG) ||
M
Mallikarjuna R Chilakala 已提交
579
				(hw->mac_type == e1000_82573)))
L
Linus Torvalds 已提交
580 581 582 583 584 585 586 587 588 589
		e1000_update_eeprom_checksum(hw);

	kfree(eeprom_buff);
	return ret_val;
}

static void
e1000_get_drvinfo(struct net_device *netdev,
                       struct ethtool_drvinfo *drvinfo)
{
590
	struct e1000_adapter *adapter = netdev_priv(netdev);
591 592
	char firmware_version[32];
	uint16_t eeprom_data;
L
Linus Torvalds 已提交
593 594 595

	strncpy(drvinfo->driver,  e1000_driver_name, 32);
	strncpy(drvinfo->version, e1000_driver_version, 32);
596 597 598 599 600 601 602 603

	/* EEPROM image version # is reported as firmware version # for
	 * 8257{1|2|3} controllers */
	e1000_read_eeprom(&adapter->hw, 5, 1, &eeprom_data);
	switch (adapter->hw.mac_type) {
	case e1000_82571:
	case e1000_82572:
	case e1000_82573:
604
	case e1000_80003es2lan:
605
	case e1000_ich8lan:
606 607 608 609 610 611 612 613 614 615
		sprintf(firmware_version, "%d.%d-%d",
			(eeprom_data & 0xF000) >> 12,
			(eeprom_data & 0x0FF0) >> 4,
			eeprom_data & 0x000F);
		break;
	default:
		sprintf(firmware_version, "N/A");
	}

	strncpy(drvinfo->fw_version, firmware_version, 32);
L
Linus Torvalds 已提交
616 617 618 619 620 621 622 623 624 625 626
	strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
	drvinfo->n_stats = E1000_STATS_LEN;
	drvinfo->testinfo_len = E1000_TEST_LEN;
	drvinfo->regdump_len = e1000_get_regs_len(netdev);
	drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
}

static void
e1000_get_ringparam(struct net_device *netdev,
                    struct ethtool_ringparam *ring)
{
627
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
628
	e1000_mac_type mac_type = adapter->hw.mac_type;
629 630
	struct e1000_tx_ring *txdr = adapter->tx_ring;
	struct e1000_rx_ring *rxdr = adapter->rx_ring;
L
Linus Torvalds 已提交
631 632 633 634 635 636 637 638 639 640 641 642 643

	ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
		E1000_MAX_82544_RXD;
	ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
		E1000_MAX_82544_TXD;
	ring->rx_mini_max_pending = 0;
	ring->rx_jumbo_max_pending = 0;
	ring->rx_pending = rxdr->count;
	ring->tx_pending = txdr->count;
	ring->rx_mini_pending = 0;
	ring->rx_jumbo_pending = 0;
}

J
Jesse Brandeburg 已提交
644
static int
L
Linus Torvalds 已提交
645 646 647
e1000_set_ringparam(struct net_device *netdev,
                    struct ethtool_ringparam *ring)
{
648
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
649
	e1000_mac_type mac_type = adapter->hw.mac_type;
650 651
	struct e1000_tx_ring *txdr, *tx_old;
	struct e1000_rx_ring *rxdr, *rx_old;
652 653
	int i, err, tx_ring_size, rx_ring_size;

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

657 658
	tx_ring_size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
	rx_ring_size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
659

660 661 662
	while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
		msleep(1);

663 664
	if (netif_running(adapter->netdev))
		e1000_down(adapter);
L
Linus Torvalds 已提交
665 666 667 668

	tx_old = adapter->tx_ring;
	rx_old = adapter->rx_ring;

669 670 671 672
	err = -ENOMEM;
	txdr = kzalloc(tx_ring_size, GFP_KERNEL);
	if (!txdr)
		goto err_alloc_tx;
673

674 675 676
	rxdr = kzalloc(rx_ring_size, GFP_KERNEL);
	if (!rxdr)
		goto err_alloc_rx;
677

678 679
	adapter->tx_ring = txdr;
	adapter->rx_ring = rxdr;
680

L
Linus Torvalds 已提交
681 682 683
	rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD);
	rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ?
		E1000_MAX_RXD : E1000_MAX_82544_RXD));
J
Jesse Brandeburg 已提交
684
	E1000_ROUNDUP(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
L
Linus Torvalds 已提交
685 686 687 688

	txdr->count = max(ring->tx_pending,(uint32_t)E1000_MIN_TXD);
	txdr->count = min(txdr->count,(uint32_t)(mac_type < e1000_82544 ?
		E1000_MAX_TXD : E1000_MAX_82544_TXD));
J
Jesse Brandeburg 已提交
689
	E1000_ROUNDUP(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
L
Linus Torvalds 已提交
690

691
	for (i = 0; i < adapter->num_tx_queues; i++)
692
		txdr[i].count = txdr->count;
693
	for (i = 0; i < adapter->num_rx_queues; i++)
694 695
		rxdr[i].count = rxdr->count;

J
Jesse Brandeburg 已提交
696
	if (netif_running(adapter->netdev)) {
L
Linus Torvalds 已提交
697
		/* Try to get new resources before deleting old */
698
		if ((err = e1000_setup_all_rx_resources(adapter)))
L
Linus Torvalds 已提交
699
			goto err_setup_rx;
700
		if ((err = e1000_setup_all_tx_resources(adapter)))
L
Linus Torvalds 已提交
701 702 703 704 705 706 707
			goto err_setup_tx;

		/* save the new, restore the old in order to free it,
		 * then restore the new back again */

		adapter->rx_ring = rx_old;
		adapter->tx_ring = tx_old;
708 709 710 711
		e1000_free_all_rx_resources(adapter);
		e1000_free_all_tx_resources(adapter);
		kfree(tx_old);
		kfree(rx_old);
712 713
		adapter->rx_ring = rxdr;
		adapter->tx_ring = txdr;
J
Jesse Brandeburg 已提交
714
		if ((err = e1000_up(adapter)))
715
			goto err_setup;
L
Linus Torvalds 已提交
716 717
	}

718
	clear_bit(__E1000_RESETTING, &adapter->flags);
L
Linus Torvalds 已提交
719 720
	return 0;
err_setup_tx:
721
	e1000_free_all_rx_resources(adapter);
L
Linus Torvalds 已提交
722 723 724
err_setup_rx:
	adapter->rx_ring = rx_old;
	adapter->tx_ring = tx_old;
725 726 727 728
	kfree(rxdr);
err_alloc_rx:
	kfree(txdr);
err_alloc_tx:
L
Linus Torvalds 已提交
729
	e1000_up(adapter);
730 731
err_setup:
	clear_bit(__E1000_RESETTING, &adapter->flags);
L
Linus Torvalds 已提交
732 733 734 735 736 737 738 739
	return err;
}

#define REG_PATTERN_TEST(R, M, W)                                              \
{                                                                              \
	uint32_t pat, value;                                                   \
	uint32_t test[] =                                                      \
		{0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};              \
J
Jesse Brandeburg 已提交
740
	for (pat = 0; pat < sizeof(test)/sizeof(test[0]); pat++) {              \
L
Linus Torvalds 已提交
741 742
		E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W));             \
		value = E1000_READ_REG(&adapter->hw, R);                       \
J
Jesse Brandeburg 已提交
743
		if (value != (test[pat] & W & M)) {                             \
744 745 746
			DPRINTK(DRV, ERR, "pattern test reg %04X failed: got " \
			        "0x%08X expected 0x%08X\n",                    \
			        E1000_##R, value, (test[pat] & W & M));        \
L
Linus Torvalds 已提交
747 748 749 750 751 752 753 754 755 756 757 758
			*data = (adapter->hw.mac_type < e1000_82543) ?         \
				E1000_82542_##R : E1000_##R;                   \
			return 1;                                              \
		}                                                              \
	}                                                                      \
}

#define REG_SET_AND_CHECK(R, M, W)                                             \
{                                                                              \
	uint32_t value;                                                        \
	E1000_WRITE_REG(&adapter->hw, R, W & M);                               \
	value = E1000_READ_REG(&adapter->hw, R);                               \
J
Jesse Brandeburg 已提交
759
	if ((W & M) != (value & M)) {                                          \
760 761
		DPRINTK(DRV, ERR, "set/check reg %04X test failed: got 0x%08X "\
		        "expected 0x%08X\n", E1000_##R, (value & M), (W & M)); \
L
Linus Torvalds 已提交
762 763 764 765 766 767 768 769 770
		*data = (adapter->hw.mac_type < e1000_82543) ?                 \
			E1000_82542_##R : E1000_##R;                           \
		return 1;                                                      \
	}                                                                      \
}

static int
e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
{
771 772
	uint32_t value, before, after;
	uint32_t i, toggle;
L
Linus Torvalds 已提交
773 774 775 776

	/* The status register is Read Only, so a write should fail.
	 * Some bits that get toggled are ignored.
	 */
777
        switch (adapter->hw.mac_type) {
778 779 780
	/* there are several bits on newer hardware that are r/w */
	case e1000_82571:
	case e1000_82572:
781
	case e1000_80003es2lan:
782 783
		toggle = 0x7FFFF3FF;
		break;
784
	case e1000_82573:
785
	case e1000_ich8lan:
786 787 788 789 790 791 792 793 794 795 796
		toggle = 0x7FFFF033;
		break;
	default:
		toggle = 0xFFFFF833;
		break;
	}

	before = E1000_READ_REG(&adapter->hw, STATUS);
	value = (E1000_READ_REG(&adapter->hw, STATUS) & toggle);
	E1000_WRITE_REG(&adapter->hw, STATUS, toggle);
	after = E1000_READ_REG(&adapter->hw, STATUS) & toggle;
J
Jesse Brandeburg 已提交
797
	if (value != after) {
798 799
		DPRINTK(DRV, ERR, "failed STATUS register test got: "
		        "0x%08X expected: 0x%08X\n", after, value);
L
Linus Torvalds 已提交
800 801 802
		*data = 1;
		return 1;
	}
803 804
	/* restore previous status */
	E1000_WRITE_REG(&adapter->hw, STATUS, before);
805 806 807 808 809 810
	if (adapter->hw.mac_type != e1000_ich8lan) {
		REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
		REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
		REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
		REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
	}
L
Linus Torvalds 已提交
811 812 813 814 815 816 817 818 819 820 821 822
	REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
	REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
	REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
	REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
	REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
	REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
	REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
	REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
	REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
	REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);

	REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
823 824 825
	before = (adapter->hw.mac_type == e1000_ich8lan ?
			0x06C3B33E : 0x06DFB3FE);
	REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
L
Linus Torvalds 已提交
826 827
	REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);

J
Jesse Brandeburg 已提交
828
	if (adapter->hw.mac_type >= e1000_82543) {
L
Linus Torvalds 已提交
829

830
		REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
L
Linus Torvalds 已提交
831
		REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
832 833
		if (adapter->hw.mac_type != e1000_ich8lan)
			REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
L
Linus Torvalds 已提交
834 835
		REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
		REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
836 837 838
		value = (adapter->hw.mac_type == e1000_ich8lan ?
				E1000_RAR_ENTRIES_ICH8LAN : E1000_RAR_ENTRIES);
		for (i = 0; i < value; i++) {
L
Linus Torvalds 已提交
839 840 841 842 843 844 845 846 847 848 849 850 851
			REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
					 0xFFFFFFFF);
		}

	} else {

		REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
		REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
		REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
		REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);

	}

852 853 854
	value = (adapter->hw.mac_type == e1000_ich8lan ?
			E1000_MC_TBL_SIZE_ICH8LAN : E1000_MC_TBL_SIZE);
	for (i = 0; i < value; i++)
L
Linus Torvalds 已提交
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
		REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);

	*data = 0;
	return 0;
}

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

	*data = 0;
	/* Read and add up the contents of the EEPROM */
J
Jesse Brandeburg 已提交
870 871
	for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
		if ((e1000_read_eeprom(&adapter->hw, i, 1, &temp)) < 0) {
L
Linus Torvalds 已提交
872 873 874 875 876 877 878
			*data = 1;
			break;
		}
		checksum += temp;
	}

	/* If Checksum is not Correct return error else test passed */
J
Jesse Brandeburg 已提交
879
	if ((checksum != (uint16_t) EEPROM_SUM) && !(*data))
L
Linus Torvalds 已提交
880 881 882 883 884 885 886
		*data = 2;

	return *data;
}

static irqreturn_t
e1000_test_intr(int irq,
887
		void *data)
L
Linus Torvalds 已提交
888 889
{
	struct net_device *netdev = (struct net_device *) data;
890
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
891 892 893 894 895 896 897 898 899 900

	adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR);

	return IRQ_HANDLED;
}

static int
e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
{
	struct net_device *netdev = adapter->netdev;
901 902
	uint32_t mask, i=0, shared_int = TRUE;
	uint32_t irq = adapter->pdev->irq;
L
Linus Torvalds 已提交
903 904 905

	*data = 0;

906
	/* NOTE: we don't test MSI interrupts here, yet */
L
Linus Torvalds 已提交
907
	/* Hook up test interrupt handler just for this test */
908
	if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED,
909 910 911 912
			 netdev->name, netdev))
		shared_int = FALSE;
	else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
			      netdev->name, netdev)) {
L
Linus Torvalds 已提交
913 914 915
		*data = 1;
		return -1;
	}
916
	DPRINTK(HW, INFO, "testing %s interrupt\n",
917
	        (shared_int ? "shared" : "unshared"));
L
Linus Torvalds 已提交
918 919 920

	/* Disable all the interrupts */
	E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
921
	msleep(10);
L
Linus Torvalds 已提交
922 923

	/* Test each interrupt */
J
Jesse Brandeburg 已提交
924
	for (; i < 10; i++) {
L
Linus Torvalds 已提交
925

926 927
		if (adapter->hw.mac_type == e1000_ich8lan && i == 8)
			continue;
L
Linus Torvalds 已提交
928 929 930
		/* Interrupt to test */
		mask = 1 << i;

931 932 933 934 935 936 937 938 939 940
		if (!shared_int) {
			/* Disable the interrupt to be reported in
			 * the cause register and then force the same
			 * interrupt and see if one gets posted.  If
			 * an interrupt was posted to the bus, the
			 * test failed.
			 */
			adapter->test_icr = 0;
			E1000_WRITE_REG(&adapter->hw, IMC, mask);
			E1000_WRITE_REG(&adapter->hw, ICS, mask);
941
			msleep(10);
942 943 944 945 946

			if (adapter->test_icr & mask) {
				*data = 3;
				break;
			}
L
Linus Torvalds 已提交
947 948 949 950 951 952 953 954 955 956 957
		}

		/* Enable the interrupt to be reported in
		 * the cause register and then force the same
		 * interrupt and see if one gets posted.  If
		 * an interrupt was not posted to the bus, the
		 * test failed.
		 */
		adapter->test_icr = 0;
		E1000_WRITE_REG(&adapter->hw, IMS, mask);
		E1000_WRITE_REG(&adapter->hw, ICS, mask);
958
		msleep(10);
L
Linus Torvalds 已提交
959

J
Jesse Brandeburg 已提交
960
		if (!(adapter->test_icr & mask)) {
L
Linus Torvalds 已提交
961 962 963 964
			*data = 4;
			break;
		}

965
		if (!shared_int) {
L
Linus Torvalds 已提交
966 967 968 969 970 971 972
			/* Disable the other interrupts to be reported in
			 * the cause register and then force the other
			 * interrupts and see if any get posted.  If
			 * an interrupt was posted to the bus, the
			 * test failed.
			 */
			adapter->test_icr = 0;
973 974
			E1000_WRITE_REG(&adapter->hw, IMC, ~mask & 0x00007FFF);
			E1000_WRITE_REG(&adapter->hw, ICS, ~mask & 0x00007FFF);
975
			msleep(10);
L
Linus Torvalds 已提交
976

J
Jesse Brandeburg 已提交
977
			if (adapter->test_icr) {
L
Linus Torvalds 已提交
978 979 980 981 982 983 984 985
				*data = 5;
				break;
			}
		}
	}

	/* Disable all the interrupts */
	E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
986
	msleep(10);
L
Linus Torvalds 已提交
987 988 989 990 991 992 993 994 995 996

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

	return *data;
}

static void
e1000_free_desc_rings(struct e1000_adapter *adapter)
{
997 998
	struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
	struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
L
Linus Torvalds 已提交
999 1000 1001
	struct pci_dev *pdev = adapter->pdev;
	int i;

J
Jesse Brandeburg 已提交
1002 1003 1004
	if (txdr->desc && txdr->buffer_info) {
		for (i = 0; i < txdr->count; i++) {
			if (txdr->buffer_info[i].dma)
L
Linus Torvalds 已提交
1005 1006 1007
				pci_unmap_single(pdev, txdr->buffer_info[i].dma,
						 txdr->buffer_info[i].length,
						 PCI_DMA_TODEVICE);
J
Jesse Brandeburg 已提交
1008
			if (txdr->buffer_info[i].skb)
L
Linus Torvalds 已提交
1009 1010 1011 1012
				dev_kfree_skb(txdr->buffer_info[i].skb);
		}
	}

J
Jesse Brandeburg 已提交
1013 1014 1015
	if (rxdr->desc && rxdr->buffer_info) {
		for (i = 0; i < rxdr->count; i++) {
			if (rxdr->buffer_info[i].dma)
L
Linus Torvalds 已提交
1016 1017 1018
				pci_unmap_single(pdev, rxdr->buffer_info[i].dma,
						 rxdr->buffer_info[i].length,
						 PCI_DMA_FROMDEVICE);
J
Jesse Brandeburg 已提交
1019
			if (rxdr->buffer_info[i].skb)
L
Linus Torvalds 已提交
1020 1021 1022 1023
				dev_kfree_skb(rxdr->buffer_info[i].skb);
		}
	}

J
Jeff Kirsher 已提交
1024
	if (txdr->desc) {
L
Linus Torvalds 已提交
1025
		pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
1026 1027
		txdr->desc = NULL;
	}
J
Jeff Kirsher 已提交
1028
	if (rxdr->desc) {
L
Linus Torvalds 已提交
1029
		pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
1030 1031
		rxdr->desc = NULL;
	}
L
Linus Torvalds 已提交
1032

1033
	kfree(txdr->buffer_info);
1034
	txdr->buffer_info = NULL;
1035
	kfree(rxdr->buffer_info);
1036
	rxdr->buffer_info = NULL;
J
Jeff Kirsher 已提交
1037

L
Linus Torvalds 已提交
1038 1039 1040 1041 1042 1043
	return;
}

static int
e1000_setup_desc_rings(struct e1000_adapter *adapter)
{
1044 1045
	struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
	struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
L
Linus Torvalds 已提交
1046 1047 1048 1049 1050 1051
	struct pci_dev *pdev = adapter->pdev;
	uint32_t rctl;
	int size, i, ret_val;

	/* Setup Tx descriptor ring and Tx buffers */

J
Jesse Brandeburg 已提交
1052 1053
	if (!txdr->count)
		txdr->count = E1000_DEFAULT_TXD;
L
Linus Torvalds 已提交
1054 1055

	size = txdr->count * sizeof(struct e1000_buffer);
J
Jesse Brandeburg 已提交
1056
	if (!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
L
Linus Torvalds 已提交
1057 1058 1059 1060 1061 1062 1063
		ret_val = 1;
		goto err_nomem;
	}
	memset(txdr->buffer_info, 0, size);

	txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
	E1000_ROUNDUP(txdr->size, 4096);
J
Jesse Brandeburg 已提交
1064
	if (!(txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma))) {
L
Linus Torvalds 已提交
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
		ret_val = 2;
		goto err_nomem;
	}
	memset(txdr->desc, 0, txdr->size);
	txdr->next_to_use = txdr->next_to_clean = 0;

	E1000_WRITE_REG(&adapter->hw, TDBAL,
			((uint64_t) txdr->dma & 0x00000000FFFFFFFF));
	E1000_WRITE_REG(&adapter->hw, TDBAH, ((uint64_t) txdr->dma >> 32));
	E1000_WRITE_REG(&adapter->hw, TDLEN,
			txdr->count * sizeof(struct e1000_tx_desc));
	E1000_WRITE_REG(&adapter->hw, TDH, 0);
	E1000_WRITE_REG(&adapter->hw, TDT, 0);
	E1000_WRITE_REG(&adapter->hw, TCTL,
			E1000_TCTL_PSP | E1000_TCTL_EN |
			E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
			E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);

J
Jesse Brandeburg 已提交
1083
	for (i = 0; i < txdr->count; i++) {
L
Linus Torvalds 已提交
1084 1085 1086 1087
		struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
		struct sk_buff *skb;
		unsigned int size = 1024;

J
Jesse Brandeburg 已提交
1088
		if (!(skb = alloc_skb(size, GFP_KERNEL))) {
L
Linus Torvalds 已提交
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
			ret_val = 3;
			goto err_nomem;
		}
		skb_put(skb, size);
		txdr->buffer_info[i].skb = skb;
		txdr->buffer_info[i].length = skb->len;
		txdr->buffer_info[i].dma =
			pci_map_single(pdev, skb->data, skb->len,
				       PCI_DMA_TODEVICE);
		tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
		tx_desc->lower.data = cpu_to_le32(skb->len);
		tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
						   E1000_TXD_CMD_IFCS |
						   E1000_TXD_CMD_RPS);
		tx_desc->upper.data = 0;
	}

	/* Setup Rx descriptor ring and Rx buffers */

J
Jesse Brandeburg 已提交
1108 1109
	if (!rxdr->count)
		rxdr->count = E1000_DEFAULT_RXD;
L
Linus Torvalds 已提交
1110 1111

	size = rxdr->count * sizeof(struct e1000_buffer);
J
Jesse Brandeburg 已提交
1112
	if (!(rxdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
L
Linus Torvalds 已提交
1113 1114 1115 1116 1117 1118
		ret_val = 4;
		goto err_nomem;
	}
	memset(rxdr->buffer_info, 0, size);

	rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
J
Jesse Brandeburg 已提交
1119
	if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) {
L
Linus Torvalds 已提交
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
		ret_val = 5;
		goto err_nomem;
	}
	memset(rxdr->desc, 0, rxdr->size);
	rxdr->next_to_use = rxdr->next_to_clean = 0;

	rctl = E1000_READ_REG(&adapter->hw, RCTL);
	E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN);
	E1000_WRITE_REG(&adapter->hw, RDBAL,
			((uint64_t) rxdr->dma & 0xFFFFFFFF));
	E1000_WRITE_REG(&adapter->hw, RDBAH, ((uint64_t) rxdr->dma >> 32));
	E1000_WRITE_REG(&adapter->hw, RDLEN, rxdr->size);
	E1000_WRITE_REG(&adapter->hw, RDH, 0);
	E1000_WRITE_REG(&adapter->hw, RDT, 0);
	rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
		E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
		(adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);

J
Jesse Brandeburg 已提交
1139
	for (i = 0; i < rxdr->count; i++) {
L
Linus Torvalds 已提交
1140 1141 1142
		struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
		struct sk_buff *skb;

J
Jesse Brandeburg 已提交
1143
		if (!(skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN,
L
Linus Torvalds 已提交
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
				GFP_KERNEL))) {
			ret_val = 6;
			goto err_nomem;
		}
		skb_reserve(skb, NET_IP_ALIGN);
		rxdr->buffer_info[i].skb = skb;
		rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
		rxdr->buffer_info[i].dma =
			pci_map_single(pdev, skb->data, E1000_RXBUFFER_2048,
				       PCI_DMA_FROMDEVICE);
		rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
		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. */
	e1000_write_phy_reg(&adapter->hw, 29, 0x001F);
	e1000_write_phy_reg(&adapter->hw, 30, 0x8FFC);
	e1000_write_phy_reg(&adapter->hw, 29, 0x001A);
	e1000_write_phy_reg(&adapter->hw, 30, 0x8FF0);
}

static void
e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
{
	uint16_t phy_reg;

	/* Because we reset the PHY above, we need to re-force TX_CLK in the
	 * Extended PHY Specific Control Register to 25MHz clock.  This
	 * value defaults back to a 2.5MHz clock when the PHY is reset.
	 */
	e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
	phy_reg |= M88E1000_EPSCR_TX_CLK_25;
	e1000_write_phy_reg(&adapter->hw,
		M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);

	/* In addition, because of the s/w reset above, we need to enable
	 * CRS on TX.  This must be set for both full and half duplex
	 * operation.
	 */
	e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
	phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
	e1000_write_phy_reg(&adapter->hw,
		M88E1000_PHY_SPEC_CTRL, phy_reg);
}

static int
e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
{
	uint32_t ctrl_reg;
	uint16_t phy_reg;

	/* Setup the Device Control Register for PHY loopback test. */

	ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
	ctrl_reg |= (E1000_CTRL_ILOS |		/* Invert Loss-Of-Signal */
		     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 */

	E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg);

	/* Read the PHY Specific Control Register (0x10) */
	e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);

	/* Clear Auto-Crossover bits in PHY Specific Control Register
	 * (bits 6:5).
	 */
	phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
	e1000_write_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, phy_reg);

	/* Perform software reset on the PHY */
	e1000_phy_reset(&adapter->hw);

	/* Have to setup TX_CLK and TX_CRS after software reset */
	e1000_phy_reset_clk_and_crs(adapter);

	e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8100);

	/* Wait for reset to complete. */
	udelay(500);

	/* Have to setup TX_CLK and TX_CRS after software reset */
	e1000_phy_reset_clk_and_crs(adapter);

	/* Write out to PHY registers 29 and 30 to disable the Receiver. */
	e1000_phy_disable_receiver(adapter);

	/* Set the loopback bit in the PHY control register. */
	e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
	phy_reg |= MII_CR_LOOPBACK;
	e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);

	/* Setup TX_CLK and TX_CRS one more time. */
	e1000_phy_reset_clk_and_crs(adapter);

	/* Check Phy Configuration */
	e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
J
Jesse Brandeburg 已提交
1252
	if (phy_reg != 0x4100)
L
Linus Torvalds 已提交
1253 1254 1255
		 return 9;

	e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
J
Jesse Brandeburg 已提交
1256
	if (phy_reg != 0x0070)
L
Linus Torvalds 已提交
1257 1258 1259
		return 10;

	e1000_read_phy_reg(&adapter->hw, 29, &phy_reg);
J
Jesse Brandeburg 已提交
1260
	if (phy_reg != 0x001A)
L
Linus Torvalds 已提交
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
		return 11;

	return 0;
}

static int
e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
{
	uint32_t ctrl_reg = 0;
	uint32_t stat_reg = 0;

	adapter->hw.autoneg = FALSE;

J
Jesse Brandeburg 已提交
1274
	if (adapter->hw.phy_type == e1000_phy_m88) {
L
Linus Torvalds 已提交
1275 1276 1277 1278 1279 1280 1281
		/* Auto-MDI/MDIX Off */
		e1000_write_phy_reg(&adapter->hw,
				    M88E1000_PHY_SPEC_CTRL, 0x0808);
		/* reset to update Auto-MDI/MDIX */
		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x9140);
		/* autoneg off */
		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8140);
1282
	} else if (adapter->hw.phy_type == e1000_phy_gg82563)
1283 1284
		e1000_write_phy_reg(&adapter->hw,
		                    GG82563_PHY_KMRN_MODE_CTRL,
A
Auke Kok 已提交
1285
		                    0x1CC);
L
Linus Torvalds 已提交
1286 1287

	ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310

	if (adapter->hw.phy_type == e1000_phy_ife) {
		/* force 100, set loopback */
		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x6100);

		/* Now set up the MAC to the same speed/duplex as the PHY. */
		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 */
	} else {
		/* force 1000, set loopback */
		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x4140);

		/* Now set up the MAC to the same speed/duplex as the PHY. */
		ctrl_reg = E1000_READ_REG(&adapter->hw, 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 */
	}
L
Linus Torvalds 已提交
1311

J
Jesse Brandeburg 已提交
1312
	if (adapter->hw.media_type == e1000_media_type_copper &&
1313
	   adapter->hw.phy_type == e1000_phy_m88)
L
Linus Torvalds 已提交
1314
		ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1315
	else {
L
Linus Torvalds 已提交
1316 1317 1318
		/* Set the ILOS bit on the fiber Nic is half
		 * duplex link is detected. */
		stat_reg = E1000_READ_REG(&adapter->hw, STATUS);
J
Jesse Brandeburg 已提交
1319
		if ((stat_reg & E1000_STATUS_FD) == 0)
L
Linus Torvalds 已提交
1320 1321 1322 1323 1324 1325 1326 1327
			ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
	}

	E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg);

	/* Disable the receiver on the PHY so when a cable is plugged in, the
	 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
	 */
J
Jesse Brandeburg 已提交
1328
	if (adapter->hw.phy_type == e1000_phy_m88)
L
Linus Torvalds 已提交
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
		e1000_phy_disable_receiver(adapter);

	udelay(500);

	return 0;
}

static int
e1000_set_phy_loopback(struct e1000_adapter *adapter)
{
	uint16_t phy_reg = 0;
	uint16_t count = 0;

	switch (adapter->hw.mac_type) {
	case e1000_82543:
J
Jesse Brandeburg 已提交
1344
		if (adapter->hw.media_type == e1000_media_type_copper) {
L
Linus Torvalds 已提交
1345 1346 1347 1348
			/* Attempt to setup Loopback mode on Non-integrated PHY.
			 * Some PHY registers get corrupted at random, so
			 * attempt this 10 times.
			 */
J
Jesse Brandeburg 已提交
1349
			while (e1000_nonintegrated_phy_loopback(adapter) &&
L
Linus Torvalds 已提交
1350
			      count++ < 10);
J
Jesse Brandeburg 已提交
1351
			if (count < 11)
L
Linus Torvalds 已提交
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
				return 0;
		}
		break;

	case e1000_82544:
	case e1000_82540:
	case e1000_82545:
	case e1000_82545_rev_3:
	case e1000_82546:
	case e1000_82546_rev_3:
	case e1000_82541:
	case e1000_82541_rev_2:
	case e1000_82547:
	case e1000_82547_rev_2:
1366 1367
	case e1000_82571:
	case e1000_82572:
1368
	case e1000_82573:
1369
	case e1000_80003es2lan:
1370
	case e1000_ich8lan:
L
Linus Torvalds 已提交
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
		return e1000_integrated_phy_loopback(adapter);
		break;

	default:
		/* Default PHY loopback work is to read the MII
		 * control register and assert bit 14 (loopback mode).
		 */
		e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
		phy_reg |= MII_CR_LOOPBACK;
		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
		return 0;
		break;
	}

	return 8;
}

static int
e1000_setup_loopback_test(struct e1000_adapter *adapter)
{
J
Jeff Kirsher 已提交
1391
	struct e1000_hw *hw = &adapter->hw;
L
Linus Torvalds 已提交
1392 1393
	uint32_t rctl;

J
Jeff Kirsher 已提交
1394 1395 1396 1397 1398 1399 1400
	if (hw->media_type == e1000_media_type_fiber ||
	    hw->media_type == e1000_media_type_internal_serdes) {
		switch (hw->mac_type) {
		case e1000_82545:
		case e1000_82546:
		case e1000_82545_rev_3:
		case e1000_82546_rev_3:
L
Linus Torvalds 已提交
1401
			return e1000_set_phy_loopback(adapter);
J
Jeff Kirsher 已提交
1402 1403 1404 1405 1406 1407
			break;
		case e1000_82571:
		case e1000_82572:
#define E1000_SERDES_LB_ON 0x410
			e1000_set_phy_loopback(adapter);
			E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_ON);
1408
			msleep(10);
J
Jeff Kirsher 已提交
1409 1410 1411 1412
			return 0;
			break;
		default:
			rctl = E1000_READ_REG(hw, RCTL);
L
Linus Torvalds 已提交
1413
			rctl |= E1000_RCTL_LBM_TCVR;
J
Jeff Kirsher 已提交
1414
			E1000_WRITE_REG(hw, RCTL, rctl);
L
Linus Torvalds 已提交
1415 1416
			return 0;
		}
J
Jeff Kirsher 已提交
1417
	} else if (hw->media_type == e1000_media_type_copper)
L
Linus Torvalds 已提交
1418 1419 1420 1421 1422 1423 1424 1425
		return e1000_set_phy_loopback(adapter);

	return 7;
}

static void
e1000_loopback_cleanup(struct e1000_adapter *adapter)
{
J
Jeff Kirsher 已提交
1426
	struct e1000_hw *hw = &adapter->hw;
L
Linus Torvalds 已提交
1427 1428 1429
	uint32_t rctl;
	uint16_t phy_reg;

J
Jeff Kirsher 已提交
1430
	rctl = E1000_READ_REG(hw, RCTL);
L
Linus Torvalds 已提交
1431
	rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
J
Jeff Kirsher 已提交
1432
	E1000_WRITE_REG(hw, RCTL, rctl);
L
Linus Torvalds 已提交
1433

J
Jeff Kirsher 已提交
1434 1435 1436 1437 1438 1439 1440
	switch (hw->mac_type) {
	case e1000_82571:
	case e1000_82572:
		if (hw->media_type == e1000_media_type_fiber ||
		    hw->media_type == e1000_media_type_internal_serdes) {
#define E1000_SERDES_LB_OFF 0x400
			E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_OFF);
1441
			msleep(10);
J
Jeff Kirsher 已提交
1442 1443 1444 1445 1446 1447 1448 1449 1450
			break;
		}
		/* Fall Through */
	case e1000_82545:
	case e1000_82546:
	case e1000_82545_rev_3:
	case e1000_82546_rev_3:
	default:
		hw->autoneg = TRUE;
1451
		if (hw->phy_type == e1000_phy_gg82563)
1452 1453 1454
			e1000_write_phy_reg(hw,
					    GG82563_PHY_KMRN_MODE_CTRL,
					    0x180);
J
Jeff Kirsher 已提交
1455 1456
		e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
		if (phy_reg & MII_CR_LOOPBACK) {
L
Linus Torvalds 已提交
1457
			phy_reg &= ~MII_CR_LOOPBACK;
J
Jeff Kirsher 已提交
1458 1459
			e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
			e1000_phy_reset(hw);
L
Linus Torvalds 已提交
1460
		}
J
Jeff Kirsher 已提交
1461
		break;
L
Linus Torvalds 已提交
1462 1463 1464 1465 1466 1467 1468
	}
}

static void
e1000_create_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
{
	memset(skb->data, 0xFF, frame_size);
1469
	frame_size &= ~1;
L
Linus Torvalds 已提交
1470 1471 1472 1473 1474 1475 1476 1477
	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)
{
1478
	frame_size &= ~1;
J
Jesse Brandeburg 已提交
1479 1480
	if (*(skb->data + 3) == 0xFF) {
		if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
L
Linus Torvalds 已提交
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
		   (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
			return 0;
		}
	}
	return 13;
}

static int
e1000_run_loopback_test(struct e1000_adapter *adapter)
{
1491 1492
	struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
	struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
L
Linus Torvalds 已提交
1493
	struct pci_dev *pdev = adapter->pdev;
1494 1495
	int i, j, k, l, lc, good_cnt, ret_val=0;
	unsigned long time;
L
Linus Torvalds 已提交
1496 1497 1498

	E1000_WRITE_REG(&adapter->hw, RDT, rxdr->count - 1);

J
Jesse Brandeburg 已提交
1499
	/* Calculate the loop count based on the largest descriptor ring
1500 1501 1502
	 * The idea is to wrap the largest ring a number of times using 64
	 * send/receive pairs during each loop
	 */
L
Linus Torvalds 已提交
1503

J
Jesse Brandeburg 已提交
1504
	if (rxdr->count <= txdr->count)
1505 1506 1507 1508 1509
		lc = ((txdr->count / 64) * 2) + 1;
	else
		lc = ((rxdr->count / 64) * 2) + 1;

	k = l = 0;
J
Jesse Brandeburg 已提交
1510 1511 1512
	for (j = 0; j <= lc; j++) { /* loop count loop */
		for (i = 0; i < 64; i++) { /* send the packets */
			e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
1513
					1024);
J
Jesse Brandeburg 已提交
1514
			pci_dma_sync_single_for_device(pdev,
1515 1516 1517
					txdr->buffer_info[k].dma,
				    	txdr->buffer_info[k].length,
				    	PCI_DMA_TODEVICE);
J
Jesse Brandeburg 已提交
1518
			if (unlikely(++k == txdr->count)) k = 0;
1519 1520
		}
		E1000_WRITE_REG(&adapter->hw, TDT, k);
1521
		msleep(200);
1522 1523 1524
		time = jiffies; /* set the start time for the receive */
		good_cnt = 0;
		do { /* receive the sent packets */
J
Jesse Brandeburg 已提交
1525
			pci_dma_sync_single_for_cpu(pdev,
1526 1527 1528
					rxdr->buffer_info[l].dma,
				    	rxdr->buffer_info[l].length,
				    	PCI_DMA_FROMDEVICE);
J
Jesse Brandeburg 已提交
1529

1530 1531 1532
			ret_val = e1000_check_lbtest_frame(
					rxdr->buffer_info[l].skb,
				   	1024);
J
Jesse Brandeburg 已提交
1533
			if (!ret_val)
1534
				good_cnt++;
J
Jesse Brandeburg 已提交
1535 1536 1537
			if (unlikely(++l == rxdr->count)) l = 0;
			/* time + 20 msecs (200 msecs on 2.4) is more than
			 * enough time to complete the receives, if it's
1538 1539 1540
			 * exceeded, break and error off
			 */
		} while (good_cnt < 64 && jiffies < (time + 20));
J
Jesse Brandeburg 已提交
1541
		if (good_cnt != 64) {
1542
			ret_val = 13; /* ret_val is the same as mis-compare */
J
Jesse Brandeburg 已提交
1543
			break;
1544
		}
J
Jesse Brandeburg 已提交
1545
		if (jiffies >= (time + 2)) {
1546 1547 1548 1549
			ret_val = 14; /* error code for time out error */
			break;
		}
	} /* end loop count loop */
L
Linus Torvalds 已提交
1550 1551 1552 1553 1554 1555
	return ret_val;
}

static int
e1000_loopback_test(struct e1000_adapter *adapter, uint64_t *data)
{
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568
	/* PHY loopback cannot be performed if SoL/IDER
	 * sessions are active */
	if (e1000_check_phy_reset_block(&adapter->hw)) {
		DPRINTK(DRV, ERR, "Cannot do PHY loopback test "
		        "when SoL/IDER is active.\n");
		*data = 0;
		goto out;
	}

	if ((*data = e1000_setup_desc_rings(adapter)))
		goto out;
	if ((*data = e1000_setup_loopback_test(adapter)))
		goto err_loopback;
L
Linus Torvalds 已提交
1569 1570
	*data = e1000_run_loopback_test(adapter);
	e1000_loopback_cleanup(adapter);
1571

L
Linus Torvalds 已提交
1572
err_loopback:
1573 1574
	e1000_free_desc_rings(adapter);
out:
L
Linus Torvalds 已提交
1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585
	return *data;
}

static int
e1000_link_test(struct e1000_adapter *adapter, uint64_t *data)
{
	*data = 0;
	if (adapter->hw.media_type == e1000_media_type_internal_serdes) {
		int i = 0;
		adapter->hw.serdes_link_down = TRUE;

1586 1587
		/* On some blade server designs, link establishment
		 * could take as long as 2-3 minutes */
L
Linus Torvalds 已提交
1588 1589 1590 1591
		do {
			e1000_check_for_link(&adapter->hw);
			if (adapter->hw.serdes_link_down == FALSE)
				return *data;
1592
			msleep(20);
L
Linus Torvalds 已提交
1593 1594
		} while (i++ < 3750);

1595
		*data = 1;
L
Linus Torvalds 已提交
1596 1597
	} else {
		e1000_check_for_link(&adapter->hw);
J
Jesse Brandeburg 已提交
1598
		if (adapter->hw.autoneg)  /* if auto_neg is set wait for it */
1599
			msleep(4000);
L
Linus Torvalds 已提交
1600

J
Jesse Brandeburg 已提交
1601
		if (!(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU)) {
L
Linus Torvalds 已提交
1602 1603 1604 1605 1606 1607
			*data = 1;
		}
	}
	return *data;
}

J
Jesse Brandeburg 已提交
1608
static int
L
Linus Torvalds 已提交
1609 1610 1611 1612 1613
e1000_diag_test_count(struct net_device *netdev)
{
	return E1000_TEST_LEN;
}

1614 1615
extern void e1000_power_up_phy(struct e1000_adapter *);

L
Linus Torvalds 已提交
1616 1617 1618 1619
static void
e1000_diag_test(struct net_device *netdev,
		   struct ethtool_test *eth_test, uint64_t *data)
{
1620
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
1621 1622
	boolean_t if_running = netif_running(netdev);

A
Auke Kok 已提交
1623
	set_bit(__E1000_TESTING, &adapter->flags);
J
Jesse Brandeburg 已提交
1624
	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
L
Linus Torvalds 已提交
1625 1626 1627 1628 1629 1630 1631
		/* Offline tests */

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

1632 1633
		DPRINTK(HW, INFO, "offline testing starting\n");

L
Linus Torvalds 已提交
1634 1635
		/* Link test performed before hardware reset so autoneg doesn't
		 * interfere with test result */
J
Jesse Brandeburg 已提交
1636
		if (e1000_link_test(adapter, &data[4]))
L
Linus Torvalds 已提交
1637 1638
			eth_test->flags |= ETH_TEST_FL_FAILED;

J
Jesse Brandeburg 已提交
1639
		if (if_running)
1640 1641
			/* indicate we're in test mode */
			dev_close(netdev);
L
Linus Torvalds 已提交
1642 1643 1644
		else
			e1000_reset(adapter);

J
Jesse Brandeburg 已提交
1645
		if (e1000_reg_test(adapter, &data[0]))
L
Linus Torvalds 已提交
1646 1647 1648
			eth_test->flags |= ETH_TEST_FL_FAILED;

		e1000_reset(adapter);
J
Jesse Brandeburg 已提交
1649
		if (e1000_eeprom_test(adapter, &data[1]))
L
Linus Torvalds 已提交
1650 1651 1652
			eth_test->flags |= ETH_TEST_FL_FAILED;

		e1000_reset(adapter);
J
Jesse Brandeburg 已提交
1653
		if (e1000_intr_test(adapter, &data[2]))
L
Linus Torvalds 已提交
1654 1655 1656
			eth_test->flags |= ETH_TEST_FL_FAILED;

		e1000_reset(adapter);
1657 1658
		/* make sure the phy is powered up */
		e1000_power_up_phy(adapter);
J
Jesse Brandeburg 已提交
1659
		if (e1000_loopback_test(adapter, &data[3]))
L
Linus Torvalds 已提交
1660 1661 1662 1663 1664 1665 1666 1667
			eth_test->flags |= ETH_TEST_FL_FAILED;

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

		e1000_reset(adapter);
A
Auke Kok 已提交
1668
		clear_bit(__E1000_TESTING, &adapter->flags);
J
Jesse Brandeburg 已提交
1669
		if (if_running)
1670
			dev_open(netdev);
L
Linus Torvalds 已提交
1671
	} else {
1672
		DPRINTK(HW, INFO, "online testing starting\n");
L
Linus Torvalds 已提交
1673
		/* Online tests */
J
Jesse Brandeburg 已提交
1674
		if (e1000_link_test(adapter, &data[4]))
L
Linus Torvalds 已提交
1675 1676 1677 1678 1679 1680 1681
			eth_test->flags |= ETH_TEST_FL_FAILED;

		/* Offline tests aren't run; pass by default */
		data[0] = 0;
		data[1] = 0;
		data[2] = 0;
		data[3] = 0;
1682

A
Auke Kok 已提交
1683
		clear_bit(__E1000_TESTING, &adapter->flags);
L
Linus Torvalds 已提交
1684
	}
1685
	msleep_interruptible(4 * 1000);
L
Linus Torvalds 已提交
1686 1687
}

1688
static int e1000_wol_exclusion(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol)
L
Linus Torvalds 已提交
1689 1690
{
	struct e1000_hw *hw = &adapter->hw;
1691
	int retval = 1; /* fail by default */
L
Linus Torvalds 已提交
1692

1693
	switch (hw->device_id) {
A
Auke Kok 已提交
1694
	case E1000_DEV_ID_82542:
L
Linus Torvalds 已提交
1695 1696 1697 1698 1699 1700
	case E1000_DEV_ID_82543GC_FIBER:
	case E1000_DEV_ID_82543GC_COPPER:
	case E1000_DEV_ID_82544EI_FIBER:
	case E1000_DEV_ID_82546EB_QUAD_COPPER:
	case E1000_DEV_ID_82545EM_FIBER:
	case E1000_DEV_ID_82545EM_COPPER:
J
Jeff Kirsher 已提交
1701
	case E1000_DEV_ID_82546GB_QUAD_COPPER:
1702 1703
	case E1000_DEV_ID_82546GB_PCIE:
		/* these don't support WoL at all */
L
Linus Torvalds 已提交
1704
		wol->supported = 0;
1705
		break;
L
Linus Torvalds 已提交
1706 1707
	case E1000_DEV_ID_82546EB_FIBER:
	case E1000_DEV_ID_82546GB_FIBER:
1708
	case E1000_DEV_ID_82571EB_FIBER:
1709 1710 1711
	case E1000_DEV_ID_82571EB_SERDES:
	case E1000_DEV_ID_82571EB_COPPER:
		/* Wake events not supported on port B */
J
Jesse Brandeburg 已提交
1712
		if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) {
L
Linus Torvalds 已提交
1713
			wol->supported = 0;
1714
			break;
L
Linus Torvalds 已提交
1715
		}
1716 1717 1718
		/* return success for non excluded adapter ports */
		retval = 0;
		break;
1719
	case E1000_DEV_ID_82571EB_QUAD_COPPER:
1720 1721 1722 1723 1724 1725 1726 1727 1728
	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
		/* quad port adapters only support WoL on port A */
		if (!adapter->quad_port_a) {
			wol->supported = 0;
			break;
		}
		/* return success for non excluded adapter ports */
		retval = 0;
		break;
L
Linus Torvalds 已提交
1729
	default:
1730 1731 1732 1733 1734 1735 1736 1737
		/* dual port cards only support WoL on port A from now on
		 * unless it was enabled in the eeprom for port B
		 * so exclude FUNC_1 ports from having WoL enabled */
		if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1 &&
		    !adapter->eeprom_wol) {
			wol->supported = 0;
			break;
		}
J
Jeff Kirsher 已提交
1738

1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
		retval = 0;
	}

	return retval;
}

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

	wol->supported = WAKE_UCAST | WAKE_MCAST |
	                 WAKE_BCAST | WAKE_MAGIC;
	wol->wolopts = 0;

	/* this function will set ->supported = 0 and return 1 if wol is not
	 * supported by this hardware */
	if (e1000_wol_exclusion(adapter, wol))
L
Linus Torvalds 已提交
1757
		return;
1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770

	/* apply any specific unsupported masks here */
	switch (adapter->hw.device_id) {
	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
		/* KSP3 does not suppport UCAST wake-ups */
		wol->supported &= ~WAKE_UCAST;

		if (adapter->wol & E1000_WUFC_EX)
			DPRINTK(DRV, ERR, "Interface does not support "
		        "directed (unicast) frame wake-up packets\n");
		break;
	default:
		break;
L
Linus Torvalds 已提交
1771
	}
1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782

	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;

	return;
L
Linus Torvalds 已提交
1783 1784 1785 1786 1787
}

static int
e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
{
1788
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
1789 1790
	struct e1000_hw *hw = &adapter->hw;

1791 1792 1793 1794
	if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
		return -EOPNOTSUPP;

	if (e1000_wol_exclusion(adapter, wol))
L
Linus Torvalds 已提交
1795 1796
		return wol->wolopts ? -EOPNOTSUPP : 0;

1797
	switch (hw->device_id) {
J
Jeff Kirsher 已提交
1798 1799 1800 1801 1802 1803
	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
		if (wol->wolopts & WAKE_UCAST) {
			DPRINTK(DRV, ERR, "Interface does not support "
		        "directed (unicast) frame wake-up packets\n");
			return -EOPNOTSUPP;
		}
1804
		break;
L
Linus Torvalds 已提交
1805
	default:
1806
		break;
L
Linus Torvalds 已提交
1807 1808
	}

1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820
	/* 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;

L
Linus Torvalds 已提交
1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834
	return 0;
}

/* toggle LED 4 times per second = 2 "blinks" per second */
#define E1000_ID_INTERVAL	(HZ/4)

/* bit defines for adapter->led_status */
#define E1000_LED_ON		0

static void
e1000_led_blink_callback(unsigned long data)
{
	struct e1000_adapter *adapter = (struct e1000_adapter *) data;

J
Jesse Brandeburg 已提交
1835
	if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
L
Linus Torvalds 已提交
1836 1837 1838 1839 1840 1841 1842 1843 1844 1845
		e1000_led_off(&adapter->hw);
	else
		e1000_led_on(&adapter->hw);

	mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
}

static int
e1000_phys_id(struct net_device *netdev, uint32_t data)
{
1846
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
1847

J
Jesse Brandeburg 已提交
1848
	if (!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
L
Linus Torvalds 已提交
1849 1850
		data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);

J
Jesse Brandeburg 已提交
1851 1852
	if (adapter->hw.mac_type < e1000_82571) {
		if (!adapter->blink_timer.function) {
1853 1854 1855 1856 1857 1858 1859 1860
			init_timer(&adapter->blink_timer);
			adapter->blink_timer.function = e1000_led_blink_callback;
			adapter->blink_timer.data = (unsigned long) adapter;
		}
		e1000_setup_led(&adapter->hw);
		mod_timer(&adapter->blink_timer, jiffies);
		msleep_interruptible(data * 1000);
		del_timer_sync(&adapter->blink_timer);
1861 1862 1863 1864 1865 1866 1867
	} else if (adapter->hw.phy_type == e1000_phy_ife) {
		if (!adapter->blink_timer.function) {
			init_timer(&adapter->blink_timer);
			adapter->blink_timer.function = e1000_led_blink_callback;
			adapter->blink_timer.data = (unsigned long) adapter;
		}
		mod_timer(&adapter->blink_timer, jiffies);
1868
		msleep_interruptible(data * 1000);
1869 1870
		del_timer_sync(&adapter->blink_timer);
		e1000_write_phy_reg(&(adapter->hw), IFE_PHY_SPECIAL_CONTROL_LED, 0);
1871
	} else {
1872
		e1000_blink_led_start(&adapter->hw);
1873
		msleep_interruptible(data * 1000);
L
Linus Torvalds 已提交
1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885
	}

	e1000_led_off(&adapter->hw);
	clear_bit(E1000_LED_ON, &adapter->led_status);
	e1000_cleanup_led(&adapter->hw);

	return 0;
}

static int
e1000_nway_reset(struct net_device *netdev)
{
1886
	struct e1000_adapter *adapter = netdev_priv(netdev);
1887 1888
	if (netif_running(netdev))
		e1000_reinit_locked(adapter);
L
Linus Torvalds 已提交
1889 1890 1891
	return 0;
}

J
Jesse Brandeburg 已提交
1892
static int
L
Linus Torvalds 已提交
1893 1894 1895 1896 1897
e1000_get_stats_count(struct net_device *netdev)
{
	return E1000_STATS_LEN;
}

J
Jesse Brandeburg 已提交
1898 1899
static void
e1000_get_ethtool_stats(struct net_device *netdev,
L
Linus Torvalds 已提交
1900 1901
		struct ethtool_stats *stats, uint64_t *data)
{
1902
	struct e1000_adapter *adapter = netdev_priv(netdev);
L
Linus Torvalds 已提交
1903 1904 1905
	int i;

	e1000_update_stats(adapter);
1906 1907 1908
	for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
		char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
		data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
L
Linus Torvalds 已提交
1909 1910
			sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
	}
1911
/*	BUG_ON(i != E1000_STATS_LEN); */
L
Linus Torvalds 已提交
1912 1913
}

J
Jesse Brandeburg 已提交
1914
static void
L
Linus Torvalds 已提交
1915 1916
e1000_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
{
1917
	uint8_t *p = data;
L
Linus Torvalds 已提交
1918 1919
	int i;

J
Jesse Brandeburg 已提交
1920
	switch (stringset) {
L
Linus Torvalds 已提交
1921
	case ETH_SS_TEST:
J
Jesse Brandeburg 已提交
1922
		memcpy(data, *e1000_gstrings_test,
L
Linus Torvalds 已提交
1923 1924 1925
			E1000_TEST_LEN*ETH_GSTRING_LEN);
		break;
	case ETH_SS_STATS:
1926 1927 1928 1929 1930 1931
		for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
			memcpy(p, e1000_gstrings_stats[i].stat_string,
			       ETH_GSTRING_LEN);
			p += ETH_GSTRING_LEN;
		}
/*		BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
L
Linus Torvalds 已提交
1932 1933 1934 1935
		break;
	}
}

1936
static const struct ethtool_ops e1000_ethtool_ops = {
L
Linus Torvalds 已提交
1937 1938 1939 1940 1941 1942 1943
	.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,
1944 1945
	.get_msglevel           = e1000_get_msglevel,
	.set_msglevel           = e1000_set_msglevel,
L
Linus Torvalds 已提交
1946 1947 1948 1949 1950 1951 1952
	.nway_reset             = e1000_nway_reset,
	.get_link               = ethtool_op_get_link,
	.get_eeprom_len         = e1000_get_eeprom_len,
	.get_eeprom             = e1000_get_eeprom,
	.set_eeprom             = e1000_set_eeprom,
	.get_ringparam          = e1000_get_ringparam,
	.set_ringparam          = e1000_set_ringparam,
1953 1954 1955 1956 1957 1958 1959 1960
	.get_pauseparam         = e1000_get_pauseparam,
	.set_pauseparam         = e1000_set_pauseparam,
	.get_rx_csum            = e1000_get_rx_csum,
	.set_rx_csum            = e1000_set_rx_csum,
	.get_tx_csum            = e1000_get_tx_csum,
	.set_tx_csum            = e1000_set_tx_csum,
	.get_sg                 = ethtool_op_get_sg,
	.set_sg                 = ethtool_op_set_sg,
L
Linus Torvalds 已提交
1961
#ifdef NETIF_F_TSO
1962 1963
	.get_tso                = ethtool_op_get_tso,
	.set_tso                = e1000_set_tso,
L
Linus Torvalds 已提交
1964 1965 1966 1967 1968 1969 1970
#endif
	.self_test_count        = e1000_diag_test_count,
	.self_test              = e1000_diag_test,
	.get_strings            = e1000_get_strings,
	.phys_id                = e1000_phys_id,
	.get_stats_count        = e1000_get_stats_count,
	.get_ethtool_stats      = e1000_get_ethtool_stats,
1971
	.get_perm_addr          = ethtool_op_get_perm_addr,
L
Linus Torvalds 已提交
1972 1973 1974 1975 1976 1977
};

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