net: Remove unnecessary driver assignments of ethtool_ringparam fields to zero
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / ethernet / intel / e1000e / ethtool.c
blob69c9d2199140a94b4f754bdc1fc43d93bd00b6ea
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2011 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 /* ethtool support for e1000 */
31 #include <linux/netdevice.h>
32 #include <linux/interrupt.h>
33 #include <linux/ethtool.h>
34 #include <linux/pci.h>
35 #include <linux/slab.h>
36 #include <linux/delay.h>
38 #include "e1000.h"
40 enum {NETDEV_STATS, E1000_STATS};
42 struct e1000_stats {
43 char stat_string[ETH_GSTRING_LEN];
44 int type;
45 int sizeof_stat;
46 int stat_offset;
49 #define E1000_STAT(str, m) { \
50 .stat_string = str, \
51 .type = E1000_STATS, \
52 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
53 .stat_offset = offsetof(struct e1000_adapter, m) }
54 #define E1000_NETDEV_STAT(str, m) { \
55 .stat_string = str, \
56 .type = NETDEV_STATS, \
57 .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
58 .stat_offset = offsetof(struct rtnl_link_stats64, m) }
60 static const struct e1000_stats e1000_gstrings_stats[] = {
61 E1000_STAT("rx_packets", stats.gprc),
62 E1000_STAT("tx_packets", stats.gptc),
63 E1000_STAT("rx_bytes", stats.gorc),
64 E1000_STAT("tx_bytes", stats.gotc),
65 E1000_STAT("rx_broadcast", stats.bprc),
66 E1000_STAT("tx_broadcast", stats.bptc),
67 E1000_STAT("rx_multicast", stats.mprc),
68 E1000_STAT("tx_multicast", stats.mptc),
69 E1000_NETDEV_STAT("rx_errors", rx_errors),
70 E1000_NETDEV_STAT("tx_errors", tx_errors),
71 E1000_NETDEV_STAT("tx_dropped", tx_dropped),
72 E1000_STAT("multicast", stats.mprc),
73 E1000_STAT("collisions", stats.colc),
74 E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
75 E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
76 E1000_STAT("rx_crc_errors", stats.crcerrs),
77 E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
78 E1000_STAT("rx_no_buffer_count", stats.rnbc),
79 E1000_STAT("rx_missed_errors", stats.mpc),
80 E1000_STAT("tx_aborted_errors", stats.ecol),
81 E1000_STAT("tx_carrier_errors", stats.tncrs),
82 E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
83 E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
84 E1000_STAT("tx_window_errors", stats.latecol),
85 E1000_STAT("tx_abort_late_coll", stats.latecol),
86 E1000_STAT("tx_deferred_ok", stats.dc),
87 E1000_STAT("tx_single_coll_ok", stats.scc),
88 E1000_STAT("tx_multi_coll_ok", stats.mcc),
89 E1000_STAT("tx_timeout_count", tx_timeout_count),
90 E1000_STAT("tx_restart_queue", restart_queue),
91 E1000_STAT("rx_long_length_errors", stats.roc),
92 E1000_STAT("rx_short_length_errors", stats.ruc),
93 E1000_STAT("rx_align_errors", stats.algnerrc),
94 E1000_STAT("tx_tcp_seg_good", stats.tsctc),
95 E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
96 E1000_STAT("rx_flow_control_xon", stats.xonrxc),
97 E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
98 E1000_STAT("tx_flow_control_xon", stats.xontxc),
99 E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
100 E1000_STAT("rx_long_byte_count", stats.gorc),
101 E1000_STAT("rx_csum_offload_good", hw_csum_good),
102 E1000_STAT("rx_csum_offload_errors", hw_csum_err),
103 E1000_STAT("rx_header_split", rx_hdr_split),
104 E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
105 E1000_STAT("tx_smbus", stats.mgptc),
106 E1000_STAT("rx_smbus", stats.mgprc),
107 E1000_STAT("dropped_smbus", stats.mgpdc),
108 E1000_STAT("rx_dma_failed", rx_dma_failed),
109 E1000_STAT("tx_dma_failed", tx_dma_failed),
112 #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
113 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
114 static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
115 "Register test (offline)", "Eeprom test (offline)",
116 "Interrupt test (offline)", "Loopback test (offline)",
117 "Link test (on/offline)"
119 #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
121 static int e1000_get_settings(struct net_device *netdev,
122 struct ethtool_cmd *ecmd)
124 struct e1000_adapter *adapter = netdev_priv(netdev);
125 struct e1000_hw *hw = &adapter->hw;
126 u32 speed;
128 if (hw->phy.media_type == e1000_media_type_copper) {
130 ecmd->supported = (SUPPORTED_10baseT_Half |
131 SUPPORTED_10baseT_Full |
132 SUPPORTED_100baseT_Half |
133 SUPPORTED_100baseT_Full |
134 SUPPORTED_1000baseT_Full |
135 SUPPORTED_Autoneg |
136 SUPPORTED_TP);
137 if (hw->phy.type == e1000_phy_ife)
138 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
139 ecmd->advertising = ADVERTISED_TP;
141 if (hw->mac.autoneg == 1) {
142 ecmd->advertising |= ADVERTISED_Autoneg;
143 /* the e1000 autoneg seems to match ethtool nicely */
144 ecmd->advertising |= hw->phy.autoneg_advertised;
147 ecmd->port = PORT_TP;
148 ecmd->phy_address = hw->phy.addr;
149 ecmd->transceiver = XCVR_INTERNAL;
151 } else {
152 ecmd->supported = (SUPPORTED_1000baseT_Full |
153 SUPPORTED_FIBRE |
154 SUPPORTED_Autoneg);
156 ecmd->advertising = (ADVERTISED_1000baseT_Full |
157 ADVERTISED_FIBRE |
158 ADVERTISED_Autoneg);
160 ecmd->port = PORT_FIBRE;
161 ecmd->transceiver = XCVR_EXTERNAL;
164 speed = -1;
165 ecmd->duplex = -1;
167 if (netif_running(netdev)) {
168 if (netif_carrier_ok(netdev)) {
169 speed = adapter->link_speed;
170 ecmd->duplex = adapter->link_duplex - 1;
172 } else {
173 u32 status = er32(STATUS);
174 if (status & E1000_STATUS_LU) {
175 if (status & E1000_STATUS_SPEED_1000)
176 speed = SPEED_1000;
177 else if (status & E1000_STATUS_SPEED_100)
178 speed = SPEED_100;
179 else
180 speed = SPEED_10;
182 if (status & E1000_STATUS_FD)
183 ecmd->duplex = DUPLEX_FULL;
184 else
185 ecmd->duplex = DUPLEX_HALF;
189 ethtool_cmd_speed_set(ecmd, speed);
190 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
191 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
193 /* MDI-X => 2; MDI =>1; Invalid =>0 */
194 if ((hw->phy.media_type == e1000_media_type_copper) &&
195 netif_carrier_ok(netdev))
196 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
197 ETH_TP_MDI;
198 else
199 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
201 return 0;
204 static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
206 struct e1000_mac_info *mac = &adapter->hw.mac;
208 mac->autoneg = 0;
210 /* Make sure dplx is at most 1 bit and lsb of speed is not set
211 * for the switch() below to work */
212 if ((spd & 1) || (dplx & ~1))
213 goto err_inval;
215 /* Fiber NICs only allow 1000 gbps Full duplex */
216 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
217 spd != SPEED_1000 &&
218 dplx != DUPLEX_FULL) {
219 goto err_inval;
222 switch (spd + dplx) {
223 case SPEED_10 + DUPLEX_HALF:
224 mac->forced_speed_duplex = ADVERTISE_10_HALF;
225 break;
226 case SPEED_10 + DUPLEX_FULL:
227 mac->forced_speed_duplex = ADVERTISE_10_FULL;
228 break;
229 case SPEED_100 + DUPLEX_HALF:
230 mac->forced_speed_duplex = ADVERTISE_100_HALF;
231 break;
232 case SPEED_100 + DUPLEX_FULL:
233 mac->forced_speed_duplex = ADVERTISE_100_FULL;
234 break;
235 case SPEED_1000 + DUPLEX_FULL:
236 mac->autoneg = 1;
237 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
238 break;
239 case SPEED_1000 + DUPLEX_HALF: /* not supported */
240 default:
241 goto err_inval;
243 return 0;
245 err_inval:
246 e_err("Unsupported Speed/Duplex configuration\n");
247 return -EINVAL;
250 static int e1000_set_settings(struct net_device *netdev,
251 struct ethtool_cmd *ecmd)
253 struct e1000_adapter *adapter = netdev_priv(netdev);
254 struct e1000_hw *hw = &adapter->hw;
257 * When SoL/IDER sessions are active, autoneg/speed/duplex
258 * cannot be changed
260 if (e1000_check_reset_block(hw)) {
261 e_err("Cannot change link characteristics when SoL/IDER is "
262 "active.\n");
263 return -EINVAL;
266 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
267 usleep_range(1000, 2000);
269 if (ecmd->autoneg == AUTONEG_ENABLE) {
270 hw->mac.autoneg = 1;
271 if (hw->phy.media_type == e1000_media_type_fiber)
272 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
273 ADVERTISED_FIBRE |
274 ADVERTISED_Autoneg;
275 else
276 hw->phy.autoneg_advertised = ecmd->advertising |
277 ADVERTISED_TP |
278 ADVERTISED_Autoneg;
279 ecmd->advertising = hw->phy.autoneg_advertised;
280 if (adapter->fc_autoneg)
281 hw->fc.requested_mode = e1000_fc_default;
282 } else {
283 u32 speed = ethtool_cmd_speed(ecmd);
284 if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
285 clear_bit(__E1000_RESETTING, &adapter->state);
286 return -EINVAL;
290 /* reset the link */
292 if (netif_running(adapter->netdev)) {
293 e1000e_down(adapter);
294 e1000e_up(adapter);
295 } else {
296 e1000e_reset(adapter);
299 clear_bit(__E1000_RESETTING, &adapter->state);
300 return 0;
303 static void e1000_get_pauseparam(struct net_device *netdev,
304 struct ethtool_pauseparam *pause)
306 struct e1000_adapter *adapter = netdev_priv(netdev);
307 struct e1000_hw *hw = &adapter->hw;
309 pause->autoneg =
310 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
312 if (hw->fc.current_mode == e1000_fc_rx_pause) {
313 pause->rx_pause = 1;
314 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
315 pause->tx_pause = 1;
316 } else if (hw->fc.current_mode == e1000_fc_full) {
317 pause->rx_pause = 1;
318 pause->tx_pause = 1;
322 static int e1000_set_pauseparam(struct net_device *netdev,
323 struct ethtool_pauseparam *pause)
325 struct e1000_adapter *adapter = netdev_priv(netdev);
326 struct e1000_hw *hw = &adapter->hw;
327 int retval = 0;
329 adapter->fc_autoneg = pause->autoneg;
331 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
332 usleep_range(1000, 2000);
334 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
335 hw->fc.requested_mode = e1000_fc_default;
336 if (netif_running(adapter->netdev)) {
337 e1000e_down(adapter);
338 e1000e_up(adapter);
339 } else {
340 e1000e_reset(adapter);
342 } else {
343 if (pause->rx_pause && pause->tx_pause)
344 hw->fc.requested_mode = e1000_fc_full;
345 else if (pause->rx_pause && !pause->tx_pause)
346 hw->fc.requested_mode = e1000_fc_rx_pause;
347 else if (!pause->rx_pause && pause->tx_pause)
348 hw->fc.requested_mode = e1000_fc_tx_pause;
349 else if (!pause->rx_pause && !pause->tx_pause)
350 hw->fc.requested_mode = e1000_fc_none;
352 hw->fc.current_mode = hw->fc.requested_mode;
354 if (hw->phy.media_type == e1000_media_type_fiber) {
355 retval = hw->mac.ops.setup_link(hw);
356 /* implicit goto out */
357 } else {
358 retval = e1000e_force_mac_fc(hw);
359 if (retval)
360 goto out;
361 e1000e_set_fc_watermarks(hw);
365 out:
366 clear_bit(__E1000_RESETTING, &adapter->state);
367 return retval;
370 static u32 e1000_get_msglevel(struct net_device *netdev)
372 struct e1000_adapter *adapter = netdev_priv(netdev);
373 return adapter->msg_enable;
376 static void e1000_set_msglevel(struct net_device *netdev, u32 data)
378 struct e1000_adapter *adapter = netdev_priv(netdev);
379 adapter->msg_enable = data;
382 static int e1000_get_regs_len(struct net_device *netdev)
384 #define E1000_REGS_LEN 32 /* overestimate */
385 return E1000_REGS_LEN * sizeof(u32);
388 static void e1000_get_regs(struct net_device *netdev,
389 struct ethtool_regs *regs, void *p)
391 struct e1000_adapter *adapter = netdev_priv(netdev);
392 struct e1000_hw *hw = &adapter->hw;
393 u32 *regs_buff = p;
394 u16 phy_data;
396 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
398 regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
399 adapter->pdev->device;
401 regs_buff[0] = er32(CTRL);
402 regs_buff[1] = er32(STATUS);
404 regs_buff[2] = er32(RCTL);
405 regs_buff[3] = er32(RDLEN);
406 regs_buff[4] = er32(RDH);
407 regs_buff[5] = er32(RDT);
408 regs_buff[6] = er32(RDTR);
410 regs_buff[7] = er32(TCTL);
411 regs_buff[8] = er32(TDLEN);
412 regs_buff[9] = er32(TDH);
413 regs_buff[10] = er32(TDT);
414 regs_buff[11] = er32(TIDV);
416 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
418 /* ethtool doesn't use anything past this point, so all this
419 * code is likely legacy junk for apps that may or may not
420 * exist */
421 if (hw->phy.type == e1000_phy_m88) {
422 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
423 regs_buff[13] = (u32)phy_data; /* cable length */
424 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
425 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
426 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
427 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
428 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
429 regs_buff[18] = regs_buff[13]; /* cable polarity */
430 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
431 regs_buff[20] = regs_buff[17]; /* polarity correction */
432 /* phy receive errors */
433 regs_buff[22] = adapter->phy_stats.receive_errors;
434 regs_buff[23] = regs_buff[13]; /* mdix mode */
436 regs_buff[21] = 0; /* was idle_errors */
437 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
438 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
439 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
442 static int e1000_get_eeprom_len(struct net_device *netdev)
444 struct e1000_adapter *adapter = netdev_priv(netdev);
445 return adapter->hw.nvm.word_size * 2;
448 static int e1000_get_eeprom(struct net_device *netdev,
449 struct ethtool_eeprom *eeprom, u8 *bytes)
451 struct e1000_adapter *adapter = netdev_priv(netdev);
452 struct e1000_hw *hw = &adapter->hw;
453 u16 *eeprom_buff;
454 int first_word;
455 int last_word;
456 int ret_val = 0;
457 u16 i;
459 if (eeprom->len == 0)
460 return -EINVAL;
462 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
464 first_word = eeprom->offset >> 1;
465 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
467 eeprom_buff = kmalloc(sizeof(u16) *
468 (last_word - first_word + 1), GFP_KERNEL);
469 if (!eeprom_buff)
470 return -ENOMEM;
472 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
473 ret_val = e1000_read_nvm(hw, first_word,
474 last_word - first_word + 1,
475 eeprom_buff);
476 } else {
477 for (i = 0; i < last_word - first_word + 1; i++) {
478 ret_val = e1000_read_nvm(hw, first_word + i, 1,
479 &eeprom_buff[i]);
480 if (ret_val)
481 break;
485 if (ret_val) {
486 /* a read error occurred, throw away the result */
487 memset(eeprom_buff, 0xff, sizeof(u16) *
488 (last_word - first_word + 1));
489 } else {
490 /* Device's eeprom is always little-endian, word addressable */
491 for (i = 0; i < last_word - first_word + 1; i++)
492 le16_to_cpus(&eeprom_buff[i]);
495 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
496 kfree(eeprom_buff);
498 return ret_val;
501 static int e1000_set_eeprom(struct net_device *netdev,
502 struct ethtool_eeprom *eeprom, u8 *bytes)
504 struct e1000_adapter *adapter = netdev_priv(netdev);
505 struct e1000_hw *hw = &adapter->hw;
506 u16 *eeprom_buff;
507 void *ptr;
508 int max_len;
509 int first_word;
510 int last_word;
511 int ret_val = 0;
512 u16 i;
514 if (eeprom->len == 0)
515 return -EOPNOTSUPP;
517 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
518 return -EFAULT;
520 if (adapter->flags & FLAG_READ_ONLY_NVM)
521 return -EINVAL;
523 max_len = hw->nvm.word_size * 2;
525 first_word = eeprom->offset >> 1;
526 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
527 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
528 if (!eeprom_buff)
529 return -ENOMEM;
531 ptr = (void *)eeprom_buff;
533 if (eeprom->offset & 1) {
534 /* need read/modify/write of first changed EEPROM word */
535 /* only the second byte of the word is being modified */
536 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
537 ptr++;
539 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
540 /* need read/modify/write of last changed EEPROM word */
541 /* only the first byte of the word is being modified */
542 ret_val = e1000_read_nvm(hw, last_word, 1,
543 &eeprom_buff[last_word - first_word]);
545 if (ret_val)
546 goto out;
548 /* Device's eeprom is always little-endian, word addressable */
549 for (i = 0; i < last_word - first_word + 1; i++)
550 le16_to_cpus(&eeprom_buff[i]);
552 memcpy(ptr, bytes, eeprom->len);
554 for (i = 0; i < last_word - first_word + 1; i++)
555 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
557 ret_val = e1000_write_nvm(hw, first_word,
558 last_word - first_word + 1, eeprom_buff);
560 if (ret_val)
561 goto out;
564 * Update the checksum over the first part of the EEPROM if needed
565 * and flush shadow RAM for applicable controllers
567 if ((first_word <= NVM_CHECKSUM_REG) ||
568 (hw->mac.type == e1000_82583) ||
569 (hw->mac.type == e1000_82574) ||
570 (hw->mac.type == e1000_82573))
571 ret_val = e1000e_update_nvm_checksum(hw);
573 out:
574 kfree(eeprom_buff);
575 return ret_val;
578 static void e1000_get_drvinfo(struct net_device *netdev,
579 struct ethtool_drvinfo *drvinfo)
581 struct e1000_adapter *adapter = netdev_priv(netdev);
582 char firmware_version[32];
584 strncpy(drvinfo->driver, e1000e_driver_name,
585 sizeof(drvinfo->driver) - 1);
586 strncpy(drvinfo->version, e1000e_driver_version,
587 sizeof(drvinfo->version) - 1);
590 * EEPROM image version # is reported as firmware version # for
591 * PCI-E controllers
593 snprintf(firmware_version, sizeof(firmware_version), "%d.%d-%d",
594 (adapter->eeprom_vers & 0xF000) >> 12,
595 (adapter->eeprom_vers & 0x0FF0) >> 4,
596 (adapter->eeprom_vers & 0x000F));
598 strncpy(drvinfo->fw_version, firmware_version,
599 sizeof(drvinfo->fw_version) - 1);
600 strncpy(drvinfo->bus_info, pci_name(adapter->pdev),
601 sizeof(drvinfo->bus_info) - 1);
602 drvinfo->regdump_len = e1000_get_regs_len(netdev);
603 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
606 static void e1000_get_ringparam(struct net_device *netdev,
607 struct ethtool_ringparam *ring)
609 struct e1000_adapter *adapter = netdev_priv(netdev);
610 struct e1000_ring *tx_ring = adapter->tx_ring;
611 struct e1000_ring *rx_ring = adapter->rx_ring;
613 ring->rx_max_pending = E1000_MAX_RXD;
614 ring->tx_max_pending = E1000_MAX_TXD;
615 ring->rx_pending = rx_ring->count;
616 ring->tx_pending = tx_ring->count;
619 static int e1000_set_ringparam(struct net_device *netdev,
620 struct ethtool_ringparam *ring)
622 struct e1000_adapter *adapter = netdev_priv(netdev);
623 struct e1000_ring *tx_ring, *tx_old;
624 struct e1000_ring *rx_ring, *rx_old;
625 int err;
627 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
628 return -EINVAL;
630 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
631 usleep_range(1000, 2000);
633 if (netif_running(adapter->netdev))
634 e1000e_down(adapter);
636 tx_old = adapter->tx_ring;
637 rx_old = adapter->rx_ring;
639 err = -ENOMEM;
640 tx_ring = kmemdup(tx_old, sizeof(struct e1000_ring), GFP_KERNEL);
641 if (!tx_ring)
642 goto err_alloc_tx;
644 rx_ring = kmemdup(rx_old, sizeof(struct e1000_ring), GFP_KERNEL);
645 if (!rx_ring)
646 goto err_alloc_rx;
648 adapter->tx_ring = tx_ring;
649 adapter->rx_ring = rx_ring;
651 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
652 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
653 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
655 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
656 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
657 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
659 if (netif_running(adapter->netdev)) {
660 /* Try to get new resources before deleting old */
661 err = e1000e_setup_rx_resources(adapter);
662 if (err)
663 goto err_setup_rx;
664 err = e1000e_setup_tx_resources(adapter);
665 if (err)
666 goto err_setup_tx;
669 * restore the old in order to free it,
670 * then add in the new
672 adapter->rx_ring = rx_old;
673 adapter->tx_ring = tx_old;
674 e1000e_free_rx_resources(adapter);
675 e1000e_free_tx_resources(adapter);
676 kfree(tx_old);
677 kfree(rx_old);
678 adapter->rx_ring = rx_ring;
679 adapter->tx_ring = tx_ring;
680 err = e1000e_up(adapter);
681 if (err)
682 goto err_setup;
685 clear_bit(__E1000_RESETTING, &adapter->state);
686 return 0;
687 err_setup_tx:
688 e1000e_free_rx_resources(adapter);
689 err_setup_rx:
690 adapter->rx_ring = rx_old;
691 adapter->tx_ring = tx_old;
692 kfree(rx_ring);
693 err_alloc_rx:
694 kfree(tx_ring);
695 err_alloc_tx:
696 e1000e_up(adapter);
697 err_setup:
698 clear_bit(__E1000_RESETTING, &adapter->state);
699 return err;
702 static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
703 int reg, int offset, u32 mask, u32 write)
705 u32 pat, val;
706 static const u32 test[] = {
707 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
708 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
709 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
710 (test[pat] & write));
711 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
712 if (val != (test[pat] & write & mask)) {
713 e_err("pattern test reg %04X failed: got 0x%08X "
714 "expected 0x%08X\n", reg + offset, val,
715 (test[pat] & write & mask));
716 *data = reg;
717 return 1;
720 return 0;
723 static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
724 int reg, u32 mask, u32 write)
726 u32 val;
727 __ew32(&adapter->hw, reg, write & mask);
728 val = __er32(&adapter->hw, reg);
729 if ((write & mask) != (val & mask)) {
730 e_err("set/check reg %04X test failed: got 0x%08X "
731 "expected 0x%08X\n", reg, (val & mask), (write & mask));
732 *data = reg;
733 return 1;
735 return 0;
737 #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
738 do { \
739 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
740 return 1; \
741 } while (0)
742 #define REG_PATTERN_TEST(reg, mask, write) \
743 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
745 #define REG_SET_AND_CHECK(reg, mask, write) \
746 do { \
747 if (reg_set_and_check(adapter, data, reg, mask, write)) \
748 return 1; \
749 } while (0)
751 static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
753 struct e1000_hw *hw = &adapter->hw;
754 struct e1000_mac_info *mac = &adapter->hw.mac;
755 u32 value;
756 u32 before;
757 u32 after;
758 u32 i;
759 u32 toggle;
760 u32 mask;
763 * The status register is Read Only, so a write should fail.
764 * Some bits that get toggled are ignored.
766 switch (mac->type) {
767 /* there are several bits on newer hardware that are r/w */
768 case e1000_82571:
769 case e1000_82572:
770 case e1000_80003es2lan:
771 toggle = 0x7FFFF3FF;
772 break;
773 default:
774 toggle = 0x7FFFF033;
775 break;
778 before = er32(STATUS);
779 value = (er32(STATUS) & toggle);
780 ew32(STATUS, toggle);
781 after = er32(STATUS) & toggle;
782 if (value != after) {
783 e_err("failed STATUS register test got: 0x%08X expected: "
784 "0x%08X\n", after, value);
785 *data = 1;
786 return 1;
788 /* restore previous status */
789 ew32(STATUS, before);
791 if (!(adapter->flags & FLAG_IS_ICH)) {
792 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
793 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
794 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
795 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
798 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
799 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
800 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
801 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
802 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
803 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
804 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
805 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
806 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
807 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
809 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
811 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
812 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
813 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
815 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
816 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
817 if (!(adapter->flags & FLAG_IS_ICH))
818 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
819 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
820 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
821 mask = 0x8003FFFF;
822 switch (mac->type) {
823 case e1000_ich10lan:
824 case e1000_pchlan:
825 case e1000_pch2lan:
826 mask |= (1 << 18);
827 break;
828 default:
829 break;
831 for (i = 0; i < mac->rar_entry_count; i++)
832 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
833 mask, 0xFFFFFFFF);
835 for (i = 0; i < mac->mta_reg_count; i++)
836 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
838 *data = 0;
839 return 0;
842 static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
844 u16 temp;
845 u16 checksum = 0;
846 u16 i;
848 *data = 0;
849 /* Read and add up the contents of the EEPROM */
850 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
851 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
852 *data = 1;
853 return *data;
855 checksum += temp;
858 /* If Checksum is not Correct return error else test passed */
859 if ((checksum != (u16) NVM_SUM) && !(*data))
860 *data = 2;
862 return *data;
865 static irqreturn_t e1000_test_intr(int irq, void *data)
867 struct net_device *netdev = (struct net_device *) data;
868 struct e1000_adapter *adapter = netdev_priv(netdev);
869 struct e1000_hw *hw = &adapter->hw;
871 adapter->test_icr |= er32(ICR);
873 return IRQ_HANDLED;
876 static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
878 struct net_device *netdev = adapter->netdev;
879 struct e1000_hw *hw = &adapter->hw;
880 u32 mask;
881 u32 shared_int = 1;
882 u32 irq = adapter->pdev->irq;
883 int i;
884 int ret_val = 0;
885 int int_mode = E1000E_INT_MODE_LEGACY;
887 *data = 0;
889 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
890 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
891 int_mode = adapter->int_mode;
892 e1000e_reset_interrupt_capability(adapter);
893 adapter->int_mode = E1000E_INT_MODE_LEGACY;
894 e1000e_set_interrupt_capability(adapter);
896 /* Hook up test interrupt handler just for this test */
897 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
898 netdev)) {
899 shared_int = 0;
900 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
901 netdev->name, netdev)) {
902 *data = 1;
903 ret_val = -1;
904 goto out;
906 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
908 /* Disable all the interrupts */
909 ew32(IMC, 0xFFFFFFFF);
910 e1e_flush();
911 usleep_range(10000, 20000);
913 /* Test each interrupt */
914 for (i = 0; i < 10; i++) {
915 /* Interrupt to test */
916 mask = 1 << i;
918 if (adapter->flags & FLAG_IS_ICH) {
919 switch (mask) {
920 case E1000_ICR_RXSEQ:
921 continue;
922 case 0x00000100:
923 if (adapter->hw.mac.type == e1000_ich8lan ||
924 adapter->hw.mac.type == e1000_ich9lan)
925 continue;
926 break;
927 default:
928 break;
932 if (!shared_int) {
934 * Disable the interrupt to be reported in
935 * the cause register and then force the same
936 * interrupt and see if one gets posted. If
937 * an interrupt was posted to the bus, the
938 * test failed.
940 adapter->test_icr = 0;
941 ew32(IMC, mask);
942 ew32(ICS, mask);
943 e1e_flush();
944 usleep_range(10000, 20000);
946 if (adapter->test_icr & mask) {
947 *data = 3;
948 break;
953 * Enable the interrupt to be reported in
954 * the cause register and then force the same
955 * interrupt and see if one gets posted. If
956 * an interrupt was not posted to the bus, the
957 * test failed.
959 adapter->test_icr = 0;
960 ew32(IMS, mask);
961 ew32(ICS, mask);
962 e1e_flush();
963 usleep_range(10000, 20000);
965 if (!(adapter->test_icr & mask)) {
966 *data = 4;
967 break;
970 if (!shared_int) {
972 * Disable the other interrupts to be reported in
973 * the cause register and then force the other
974 * interrupts and see if any get posted. If
975 * an interrupt was posted to the bus, the
976 * test failed.
978 adapter->test_icr = 0;
979 ew32(IMC, ~mask & 0x00007FFF);
980 ew32(ICS, ~mask & 0x00007FFF);
981 e1e_flush();
982 usleep_range(10000, 20000);
984 if (adapter->test_icr) {
985 *data = 5;
986 break;
991 /* Disable all the interrupts */
992 ew32(IMC, 0xFFFFFFFF);
993 e1e_flush();
994 usleep_range(10000, 20000);
996 /* Unhook test interrupt handler */
997 free_irq(irq, netdev);
999 out:
1000 if (int_mode == E1000E_INT_MODE_MSIX) {
1001 e1000e_reset_interrupt_capability(adapter);
1002 adapter->int_mode = int_mode;
1003 e1000e_set_interrupt_capability(adapter);
1006 return ret_val;
1009 static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1011 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1012 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1013 struct pci_dev *pdev = adapter->pdev;
1014 int i;
1016 if (tx_ring->desc && tx_ring->buffer_info) {
1017 for (i = 0; i < tx_ring->count; i++) {
1018 if (tx_ring->buffer_info[i].dma)
1019 dma_unmap_single(&pdev->dev,
1020 tx_ring->buffer_info[i].dma,
1021 tx_ring->buffer_info[i].length,
1022 DMA_TO_DEVICE);
1023 if (tx_ring->buffer_info[i].skb)
1024 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1028 if (rx_ring->desc && rx_ring->buffer_info) {
1029 for (i = 0; i < rx_ring->count; i++) {
1030 if (rx_ring->buffer_info[i].dma)
1031 dma_unmap_single(&pdev->dev,
1032 rx_ring->buffer_info[i].dma,
1033 2048, DMA_FROM_DEVICE);
1034 if (rx_ring->buffer_info[i].skb)
1035 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1039 if (tx_ring->desc) {
1040 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1041 tx_ring->dma);
1042 tx_ring->desc = NULL;
1044 if (rx_ring->desc) {
1045 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1046 rx_ring->dma);
1047 rx_ring->desc = NULL;
1050 kfree(tx_ring->buffer_info);
1051 tx_ring->buffer_info = NULL;
1052 kfree(rx_ring->buffer_info);
1053 rx_ring->buffer_info = NULL;
1056 static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1058 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1059 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1060 struct pci_dev *pdev = adapter->pdev;
1061 struct e1000_hw *hw = &adapter->hw;
1062 u32 rctl;
1063 int i;
1064 int ret_val;
1066 /* Setup Tx descriptor ring and Tx buffers */
1068 if (!tx_ring->count)
1069 tx_ring->count = E1000_DEFAULT_TXD;
1071 tx_ring->buffer_info = kcalloc(tx_ring->count,
1072 sizeof(struct e1000_buffer),
1073 GFP_KERNEL);
1074 if (!(tx_ring->buffer_info)) {
1075 ret_val = 1;
1076 goto err_nomem;
1079 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1080 tx_ring->size = ALIGN(tx_ring->size, 4096);
1081 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1082 &tx_ring->dma, GFP_KERNEL);
1083 if (!tx_ring->desc) {
1084 ret_val = 2;
1085 goto err_nomem;
1087 tx_ring->next_to_use = 0;
1088 tx_ring->next_to_clean = 0;
1090 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
1091 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
1092 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
1093 ew32(TDH, 0);
1094 ew32(TDT, 0);
1095 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1096 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1097 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1099 for (i = 0; i < tx_ring->count; i++) {
1100 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1101 struct sk_buff *skb;
1102 unsigned int skb_size = 1024;
1104 skb = alloc_skb(skb_size, GFP_KERNEL);
1105 if (!skb) {
1106 ret_val = 3;
1107 goto err_nomem;
1109 skb_put(skb, skb_size);
1110 tx_ring->buffer_info[i].skb = skb;
1111 tx_ring->buffer_info[i].length = skb->len;
1112 tx_ring->buffer_info[i].dma =
1113 dma_map_single(&pdev->dev, skb->data, skb->len,
1114 DMA_TO_DEVICE);
1115 if (dma_mapping_error(&pdev->dev,
1116 tx_ring->buffer_info[i].dma)) {
1117 ret_val = 4;
1118 goto err_nomem;
1120 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
1121 tx_desc->lower.data = cpu_to_le32(skb->len);
1122 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1123 E1000_TXD_CMD_IFCS |
1124 E1000_TXD_CMD_RS);
1125 tx_desc->upper.data = 0;
1128 /* Setup Rx descriptor ring and Rx buffers */
1130 if (!rx_ring->count)
1131 rx_ring->count = E1000_DEFAULT_RXD;
1133 rx_ring->buffer_info = kcalloc(rx_ring->count,
1134 sizeof(struct e1000_buffer),
1135 GFP_KERNEL);
1136 if (!(rx_ring->buffer_info)) {
1137 ret_val = 5;
1138 goto err_nomem;
1141 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
1142 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1143 &rx_ring->dma, GFP_KERNEL);
1144 if (!rx_ring->desc) {
1145 ret_val = 6;
1146 goto err_nomem;
1148 rx_ring->next_to_use = 0;
1149 rx_ring->next_to_clean = 0;
1151 rctl = er32(RCTL);
1152 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1153 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1154 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1155 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1156 ew32(RDLEN, rx_ring->size);
1157 ew32(RDH, 0);
1158 ew32(RDT, 0);
1159 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1160 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1161 E1000_RCTL_SBP | E1000_RCTL_SECRC |
1162 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1163 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1164 ew32(RCTL, rctl);
1166 for (i = 0; i < rx_ring->count; i++) {
1167 union e1000_rx_desc_extended *rx_desc;
1168 struct sk_buff *skb;
1170 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1171 if (!skb) {
1172 ret_val = 7;
1173 goto err_nomem;
1175 skb_reserve(skb, NET_IP_ALIGN);
1176 rx_ring->buffer_info[i].skb = skb;
1177 rx_ring->buffer_info[i].dma =
1178 dma_map_single(&pdev->dev, skb->data, 2048,
1179 DMA_FROM_DEVICE);
1180 if (dma_mapping_error(&pdev->dev,
1181 rx_ring->buffer_info[i].dma)) {
1182 ret_val = 8;
1183 goto err_nomem;
1185 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1186 rx_desc->read.buffer_addr =
1187 cpu_to_le64(rx_ring->buffer_info[i].dma);
1188 memset(skb->data, 0x00, skb->len);
1191 return 0;
1193 err_nomem:
1194 e1000_free_desc_rings(adapter);
1195 return ret_val;
1198 static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1200 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1201 e1e_wphy(&adapter->hw, 29, 0x001F);
1202 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1203 e1e_wphy(&adapter->hw, 29, 0x001A);
1204 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1207 static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1209 struct e1000_hw *hw = &adapter->hw;
1210 u32 ctrl_reg = 0;
1211 u16 phy_reg = 0;
1212 s32 ret_val = 0;
1214 hw->mac.autoneg = 0;
1216 if (hw->phy.type == e1000_phy_ife) {
1217 /* force 100, set loopback */
1218 e1e_wphy(hw, PHY_CONTROL, 0x6100);
1220 /* Now set up the MAC to the same speed/duplex as the PHY. */
1221 ctrl_reg = er32(CTRL);
1222 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1223 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1224 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1225 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1226 E1000_CTRL_FD); /* Force Duplex to FULL */
1228 ew32(CTRL, ctrl_reg);
1229 e1e_flush();
1230 udelay(500);
1232 return 0;
1235 /* Specific PHY configuration for loopback */
1236 switch (hw->phy.type) {
1237 case e1000_phy_m88:
1238 /* Auto-MDI/MDIX Off */
1239 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1240 /* reset to update Auto-MDI/MDIX */
1241 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1242 /* autoneg off */
1243 e1e_wphy(hw, PHY_CONTROL, 0x8140);
1244 break;
1245 case e1000_phy_gg82563:
1246 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
1247 break;
1248 case e1000_phy_bm:
1249 /* Set Default MAC Interface speed to 1GB */
1250 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1251 phy_reg &= ~0x0007;
1252 phy_reg |= 0x006;
1253 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1254 /* Assert SW reset for above settings to take effect */
1255 e1000e_commit_phy(hw);
1256 mdelay(1);
1257 /* Force Full Duplex */
1258 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1259 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1260 /* Set Link Up (in force link) */
1261 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1262 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1263 /* Force Link */
1264 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1265 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1266 /* Set Early Link Enable */
1267 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1268 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
1269 break;
1270 case e1000_phy_82577:
1271 case e1000_phy_82578:
1272 /* Workaround: K1 must be disabled for stable 1Gbps operation */
1273 ret_val = hw->phy.ops.acquire(hw);
1274 if (ret_val) {
1275 e_err("Cannot setup 1Gbps loopback.\n");
1276 return ret_val;
1278 e1000_configure_k1_ich8lan(hw, false);
1279 hw->phy.ops.release(hw);
1280 break;
1281 case e1000_phy_82579:
1282 /* Disable PHY energy detect power down */
1283 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1284 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1285 /* Disable full chip energy detect */
1286 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1287 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1288 /* Enable loopback on the PHY */
1289 #define I82577_PHY_LBK_CTRL 19
1290 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1291 break;
1292 default:
1293 break;
1296 /* force 1000, set loopback */
1297 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1298 mdelay(250);
1300 /* Now set up the MAC to the same speed/duplex as the PHY. */
1301 ctrl_reg = er32(CTRL);
1302 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1303 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1304 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1305 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1306 E1000_CTRL_FD); /* Force Duplex to FULL */
1308 if (adapter->flags & FLAG_IS_ICH)
1309 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1311 if (hw->phy.media_type == e1000_media_type_copper &&
1312 hw->phy.type == e1000_phy_m88) {
1313 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1314 } else {
1316 * Set the ILOS bit on the fiber Nic if half duplex link is
1317 * detected.
1319 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
1320 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1323 ew32(CTRL, ctrl_reg);
1326 * Disable the receiver on the PHY so when a cable is plugged in, the
1327 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1329 if (hw->phy.type == e1000_phy_m88)
1330 e1000_phy_disable_receiver(adapter);
1332 udelay(500);
1334 return 0;
1337 static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1339 struct e1000_hw *hw = &adapter->hw;
1340 u32 ctrl = er32(CTRL);
1341 int link = 0;
1343 /* special requirements for 82571/82572 fiber adapters */
1346 * jump through hoops to make sure link is up because serdes
1347 * link is hardwired up
1349 ctrl |= E1000_CTRL_SLU;
1350 ew32(CTRL, ctrl);
1352 /* disable autoneg */
1353 ctrl = er32(TXCW);
1354 ctrl &= ~(1 << 31);
1355 ew32(TXCW, ctrl);
1357 link = (er32(STATUS) & E1000_STATUS_LU);
1359 if (!link) {
1360 /* set invert loss of signal */
1361 ctrl = er32(CTRL);
1362 ctrl |= E1000_CTRL_ILOS;
1363 ew32(CTRL, ctrl);
1367 * special write to serdes control register to enable SerDes analog
1368 * loopback
1370 #define E1000_SERDES_LB_ON 0x410
1371 ew32(SCTL, E1000_SERDES_LB_ON);
1372 e1e_flush();
1373 usleep_range(10000, 20000);
1375 return 0;
1378 /* only call this for fiber/serdes connections to es2lan */
1379 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1381 struct e1000_hw *hw = &adapter->hw;
1382 u32 ctrlext = er32(CTRL_EXT);
1383 u32 ctrl = er32(CTRL);
1386 * save CTRL_EXT to restore later, reuse an empty variable (unused
1387 * on mac_type 80003es2lan)
1389 adapter->tx_fifo_head = ctrlext;
1391 /* clear the serdes mode bits, putting the device into mac loopback */
1392 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1393 ew32(CTRL_EXT, ctrlext);
1395 /* force speed to 1000/FD, link up */
1396 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1397 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1398 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1399 ew32(CTRL, ctrl);
1401 /* set mac loopback */
1402 ctrl = er32(RCTL);
1403 ctrl |= E1000_RCTL_LBM_MAC;
1404 ew32(RCTL, ctrl);
1406 /* set testing mode parameters (no need to reset later) */
1407 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
1408 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1409 ew32(KMRNCTRLSTA,
1410 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
1412 return 0;
1415 static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1417 struct e1000_hw *hw = &adapter->hw;
1418 u32 rctl;
1420 if (hw->phy.media_type == e1000_media_type_fiber ||
1421 hw->phy.media_type == e1000_media_type_internal_serdes) {
1422 switch (hw->mac.type) {
1423 case e1000_80003es2lan:
1424 return e1000_set_es2lan_mac_loopback(adapter);
1425 break;
1426 case e1000_82571:
1427 case e1000_82572:
1428 return e1000_set_82571_fiber_loopback(adapter);
1429 break;
1430 default:
1431 rctl = er32(RCTL);
1432 rctl |= E1000_RCTL_LBM_TCVR;
1433 ew32(RCTL, rctl);
1434 return 0;
1436 } else if (hw->phy.media_type == e1000_media_type_copper) {
1437 return e1000_integrated_phy_loopback(adapter);
1440 return 7;
1443 static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1445 struct e1000_hw *hw = &adapter->hw;
1446 u32 rctl;
1447 u16 phy_reg;
1449 rctl = er32(RCTL);
1450 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1451 ew32(RCTL, rctl);
1453 switch (hw->mac.type) {
1454 case e1000_80003es2lan:
1455 if (hw->phy.media_type == e1000_media_type_fiber ||
1456 hw->phy.media_type == e1000_media_type_internal_serdes) {
1457 /* restore CTRL_EXT, stealing space from tx_fifo_head */
1458 ew32(CTRL_EXT, adapter->tx_fifo_head);
1459 adapter->tx_fifo_head = 0;
1461 /* fall through */
1462 case e1000_82571:
1463 case e1000_82572:
1464 if (hw->phy.media_type == e1000_media_type_fiber ||
1465 hw->phy.media_type == e1000_media_type_internal_serdes) {
1466 #define E1000_SERDES_LB_OFF 0x400
1467 ew32(SCTL, E1000_SERDES_LB_OFF);
1468 e1e_flush();
1469 usleep_range(10000, 20000);
1470 break;
1472 /* Fall Through */
1473 default:
1474 hw->mac.autoneg = 1;
1475 if (hw->phy.type == e1000_phy_gg82563)
1476 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1477 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1478 if (phy_reg & MII_CR_LOOPBACK) {
1479 phy_reg &= ~MII_CR_LOOPBACK;
1480 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1481 e1000e_commit_phy(hw);
1483 break;
1487 static void e1000_create_lbtest_frame(struct sk_buff *skb,
1488 unsigned int frame_size)
1490 memset(skb->data, 0xFF, frame_size);
1491 frame_size &= ~1;
1492 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1493 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1494 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1497 static int e1000_check_lbtest_frame(struct sk_buff *skb,
1498 unsigned int frame_size)
1500 frame_size &= ~1;
1501 if (*(skb->data + 3) == 0xFF)
1502 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1503 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1504 return 0;
1505 return 13;
1508 static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1510 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1511 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1512 struct pci_dev *pdev = adapter->pdev;
1513 struct e1000_hw *hw = &adapter->hw;
1514 int i, j, k, l;
1515 int lc;
1516 int good_cnt;
1517 int ret_val = 0;
1518 unsigned long time;
1520 ew32(RDT, rx_ring->count - 1);
1523 * Calculate the loop count based on the largest descriptor ring
1524 * The idea is to wrap the largest ring a number of times using 64
1525 * send/receive pairs during each loop
1528 if (rx_ring->count <= tx_ring->count)
1529 lc = ((tx_ring->count / 64) * 2) + 1;
1530 else
1531 lc = ((rx_ring->count / 64) * 2) + 1;
1533 k = 0;
1534 l = 0;
1535 for (j = 0; j <= lc; j++) { /* loop count loop */
1536 for (i = 0; i < 64; i++) { /* send the packets */
1537 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1538 1024);
1539 dma_sync_single_for_device(&pdev->dev,
1540 tx_ring->buffer_info[k].dma,
1541 tx_ring->buffer_info[k].length,
1542 DMA_TO_DEVICE);
1543 k++;
1544 if (k == tx_ring->count)
1545 k = 0;
1547 ew32(TDT, k);
1548 e1e_flush();
1549 msleep(200);
1550 time = jiffies; /* set the start time for the receive */
1551 good_cnt = 0;
1552 do { /* receive the sent packets */
1553 dma_sync_single_for_cpu(&pdev->dev,
1554 rx_ring->buffer_info[l].dma, 2048,
1555 DMA_FROM_DEVICE);
1557 ret_val = e1000_check_lbtest_frame(
1558 rx_ring->buffer_info[l].skb, 1024);
1559 if (!ret_val)
1560 good_cnt++;
1561 l++;
1562 if (l == rx_ring->count)
1563 l = 0;
1565 * time + 20 msecs (200 msecs on 2.4) is more than
1566 * enough time to complete the receives, if it's
1567 * exceeded, break and error off
1569 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1570 if (good_cnt != 64) {
1571 ret_val = 13; /* ret_val is the same as mis-compare */
1572 break;
1574 if (jiffies >= (time + 20)) {
1575 ret_val = 14; /* error code for time out error */
1576 break;
1578 } /* end loop count loop */
1579 return ret_val;
1582 static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1585 * PHY loopback cannot be performed if SoL/IDER
1586 * sessions are active
1588 if (e1000_check_reset_block(&adapter->hw)) {
1589 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
1590 *data = 0;
1591 goto out;
1594 *data = e1000_setup_desc_rings(adapter);
1595 if (*data)
1596 goto out;
1598 *data = e1000_setup_loopback_test(adapter);
1599 if (*data)
1600 goto err_loopback;
1602 *data = e1000_run_loopback_test(adapter);
1603 e1000_loopback_cleanup(adapter);
1605 err_loopback:
1606 e1000_free_desc_rings(adapter);
1607 out:
1608 return *data;
1611 static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1613 struct e1000_hw *hw = &adapter->hw;
1615 *data = 0;
1616 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1617 int i = 0;
1618 hw->mac.serdes_has_link = false;
1621 * On some blade server designs, link establishment
1622 * could take as long as 2-3 minutes
1624 do {
1625 hw->mac.ops.check_for_link(hw);
1626 if (hw->mac.serdes_has_link)
1627 return *data;
1628 msleep(20);
1629 } while (i++ < 3750);
1631 *data = 1;
1632 } else {
1633 hw->mac.ops.check_for_link(hw);
1634 if (hw->mac.autoneg)
1636 * On some Phy/switch combinations, link establishment
1637 * can take a few seconds more than expected.
1639 msleep(5000);
1641 if (!(er32(STATUS) & E1000_STATUS_LU))
1642 *data = 1;
1644 return *data;
1647 static int e1000e_get_sset_count(struct net_device *netdev, int sset)
1649 switch (sset) {
1650 case ETH_SS_TEST:
1651 return E1000_TEST_LEN;
1652 case ETH_SS_STATS:
1653 return E1000_STATS_LEN;
1654 default:
1655 return -EOPNOTSUPP;
1659 static void e1000_diag_test(struct net_device *netdev,
1660 struct ethtool_test *eth_test, u64 *data)
1662 struct e1000_adapter *adapter = netdev_priv(netdev);
1663 u16 autoneg_advertised;
1664 u8 forced_speed_duplex;
1665 u8 autoneg;
1666 bool if_running = netif_running(netdev);
1668 set_bit(__E1000_TESTING, &adapter->state);
1670 if (!if_running) {
1671 /* Get control of and reset hardware */
1672 if (adapter->flags & FLAG_HAS_AMT)
1673 e1000e_get_hw_control(adapter);
1675 e1000e_power_up_phy(adapter);
1677 adapter->hw.phy.autoneg_wait_to_complete = 1;
1678 e1000e_reset(adapter);
1679 adapter->hw.phy.autoneg_wait_to_complete = 0;
1682 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1683 /* Offline tests */
1685 /* save speed, duplex, autoneg settings */
1686 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1687 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1688 autoneg = adapter->hw.mac.autoneg;
1690 e_info("offline testing starting\n");
1692 if (if_running)
1693 /* indicate we're in test mode */
1694 dev_close(netdev);
1696 if (e1000_reg_test(adapter, &data[0]))
1697 eth_test->flags |= ETH_TEST_FL_FAILED;
1699 e1000e_reset(adapter);
1700 if (e1000_eeprom_test(adapter, &data[1]))
1701 eth_test->flags |= ETH_TEST_FL_FAILED;
1703 e1000e_reset(adapter);
1704 if (e1000_intr_test(adapter, &data[2]))
1705 eth_test->flags |= ETH_TEST_FL_FAILED;
1707 e1000e_reset(adapter);
1708 if (e1000_loopback_test(adapter, &data[3]))
1709 eth_test->flags |= ETH_TEST_FL_FAILED;
1711 /* force this routine to wait until autoneg complete/timeout */
1712 adapter->hw.phy.autoneg_wait_to_complete = 1;
1713 e1000e_reset(adapter);
1714 adapter->hw.phy.autoneg_wait_to_complete = 0;
1716 if (e1000_link_test(adapter, &data[4]))
1717 eth_test->flags |= ETH_TEST_FL_FAILED;
1719 /* restore speed, duplex, autoneg settings */
1720 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1721 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1722 adapter->hw.mac.autoneg = autoneg;
1723 e1000e_reset(adapter);
1725 clear_bit(__E1000_TESTING, &adapter->state);
1726 if (if_running)
1727 dev_open(netdev);
1728 } else {
1729 /* Online tests */
1731 e_info("online testing starting\n");
1733 /* register, eeprom, intr and loopback tests not run online */
1734 data[0] = 0;
1735 data[1] = 0;
1736 data[2] = 0;
1737 data[3] = 0;
1739 if (e1000_link_test(adapter, &data[4]))
1740 eth_test->flags |= ETH_TEST_FL_FAILED;
1742 clear_bit(__E1000_TESTING, &adapter->state);
1745 if (!if_running) {
1746 e1000e_reset(adapter);
1748 if (adapter->flags & FLAG_HAS_AMT)
1749 e1000e_release_hw_control(adapter);
1752 msleep_interruptible(4 * 1000);
1755 static void e1000_get_wol(struct net_device *netdev,
1756 struct ethtool_wolinfo *wol)
1758 struct e1000_adapter *adapter = netdev_priv(netdev);
1760 wol->supported = 0;
1761 wol->wolopts = 0;
1763 if (!(adapter->flags & FLAG_HAS_WOL) ||
1764 !device_can_wakeup(&adapter->pdev->dev))
1765 return;
1767 wol->supported = WAKE_UCAST | WAKE_MCAST |
1768 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
1770 /* apply any specific unsupported masks here */
1771 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1772 wol->supported &= ~WAKE_UCAST;
1774 if (adapter->wol & E1000_WUFC_EX)
1775 e_err("Interface does not support directed (unicast) "
1776 "frame wake-up packets\n");
1779 if (adapter->wol & E1000_WUFC_EX)
1780 wol->wolopts |= WAKE_UCAST;
1781 if (adapter->wol & E1000_WUFC_MC)
1782 wol->wolopts |= WAKE_MCAST;
1783 if (adapter->wol & E1000_WUFC_BC)
1784 wol->wolopts |= WAKE_BCAST;
1785 if (adapter->wol & E1000_WUFC_MAG)
1786 wol->wolopts |= WAKE_MAGIC;
1787 if (adapter->wol & E1000_WUFC_LNKC)
1788 wol->wolopts |= WAKE_PHY;
1791 static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1793 struct e1000_adapter *adapter = netdev_priv(netdev);
1795 if (!(adapter->flags & FLAG_HAS_WOL) ||
1796 !device_can_wakeup(&adapter->pdev->dev) ||
1797 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
1798 WAKE_MAGIC | WAKE_PHY)))
1799 return -EOPNOTSUPP;
1801 /* these settings will always override what we currently have */
1802 adapter->wol = 0;
1804 if (wol->wolopts & WAKE_UCAST)
1805 adapter->wol |= E1000_WUFC_EX;
1806 if (wol->wolopts & WAKE_MCAST)
1807 adapter->wol |= E1000_WUFC_MC;
1808 if (wol->wolopts & WAKE_BCAST)
1809 adapter->wol |= E1000_WUFC_BC;
1810 if (wol->wolopts & WAKE_MAGIC)
1811 adapter->wol |= E1000_WUFC_MAG;
1812 if (wol->wolopts & WAKE_PHY)
1813 adapter->wol |= E1000_WUFC_LNKC;
1815 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1817 return 0;
1820 static int e1000_set_phys_id(struct net_device *netdev,
1821 enum ethtool_phys_id_state state)
1823 struct e1000_adapter *adapter = netdev_priv(netdev);
1824 struct e1000_hw *hw = &adapter->hw;
1826 switch (state) {
1827 case ETHTOOL_ID_ACTIVE:
1828 if (!hw->mac.ops.blink_led)
1829 return 2; /* cycle on/off twice per second */
1831 hw->mac.ops.blink_led(hw);
1832 break;
1834 case ETHTOOL_ID_INACTIVE:
1835 if (hw->phy.type == e1000_phy_ife)
1836 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
1837 hw->mac.ops.led_off(hw);
1838 hw->mac.ops.cleanup_led(hw);
1839 break;
1841 case ETHTOOL_ID_ON:
1842 adapter->hw.mac.ops.led_on(&adapter->hw);
1843 break;
1845 case ETHTOOL_ID_OFF:
1846 adapter->hw.mac.ops.led_off(&adapter->hw);
1847 break;
1849 return 0;
1852 static int e1000_get_coalesce(struct net_device *netdev,
1853 struct ethtool_coalesce *ec)
1855 struct e1000_adapter *adapter = netdev_priv(netdev);
1857 if (adapter->itr_setting <= 4)
1858 ec->rx_coalesce_usecs = adapter->itr_setting;
1859 else
1860 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1862 return 0;
1865 static int e1000_set_coalesce(struct net_device *netdev,
1866 struct ethtool_coalesce *ec)
1868 struct e1000_adapter *adapter = netdev_priv(netdev);
1869 struct e1000_hw *hw = &adapter->hw;
1871 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
1872 ((ec->rx_coalesce_usecs > 4) &&
1873 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1874 (ec->rx_coalesce_usecs == 2))
1875 return -EINVAL;
1877 if (ec->rx_coalesce_usecs == 4) {
1878 adapter->itr = adapter->itr_setting = 4;
1879 } else if (ec->rx_coalesce_usecs <= 3) {
1880 adapter->itr = 20000;
1881 adapter->itr_setting = ec->rx_coalesce_usecs;
1882 } else {
1883 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1884 adapter->itr_setting = adapter->itr & ~3;
1887 if (adapter->itr_setting != 0)
1888 ew32(ITR, 1000000000 / (adapter->itr * 256));
1889 else
1890 ew32(ITR, 0);
1892 return 0;
1895 static int e1000_nway_reset(struct net_device *netdev)
1897 struct e1000_adapter *adapter = netdev_priv(netdev);
1899 if (!netif_running(netdev))
1900 return -EAGAIN;
1902 if (!adapter->hw.mac.autoneg)
1903 return -EINVAL;
1905 e1000e_reinit_locked(adapter);
1907 return 0;
1910 static void e1000_get_ethtool_stats(struct net_device *netdev,
1911 struct ethtool_stats *stats,
1912 u64 *data)
1914 struct e1000_adapter *adapter = netdev_priv(netdev);
1915 struct rtnl_link_stats64 net_stats;
1916 int i;
1917 char *p = NULL;
1919 e1000e_get_stats64(netdev, &net_stats);
1920 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1921 switch (e1000_gstrings_stats[i].type) {
1922 case NETDEV_STATS:
1923 p = (char *) &net_stats +
1924 e1000_gstrings_stats[i].stat_offset;
1925 break;
1926 case E1000_STATS:
1927 p = (char *) adapter +
1928 e1000_gstrings_stats[i].stat_offset;
1929 break;
1930 default:
1931 data[i] = 0;
1932 continue;
1935 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1936 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1940 static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1941 u8 *data)
1943 u8 *p = data;
1944 int i;
1946 switch (stringset) {
1947 case ETH_SS_TEST:
1948 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
1949 break;
1950 case ETH_SS_STATS:
1951 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1952 memcpy(p, e1000_gstrings_stats[i].stat_string,
1953 ETH_GSTRING_LEN);
1954 p += ETH_GSTRING_LEN;
1956 break;
1960 static const struct ethtool_ops e1000_ethtool_ops = {
1961 .get_settings = e1000_get_settings,
1962 .set_settings = e1000_set_settings,
1963 .get_drvinfo = e1000_get_drvinfo,
1964 .get_regs_len = e1000_get_regs_len,
1965 .get_regs = e1000_get_regs,
1966 .get_wol = e1000_get_wol,
1967 .set_wol = e1000_set_wol,
1968 .get_msglevel = e1000_get_msglevel,
1969 .set_msglevel = e1000_set_msglevel,
1970 .nway_reset = e1000_nway_reset,
1971 .get_link = ethtool_op_get_link,
1972 .get_eeprom_len = e1000_get_eeprom_len,
1973 .get_eeprom = e1000_get_eeprom,
1974 .set_eeprom = e1000_set_eeprom,
1975 .get_ringparam = e1000_get_ringparam,
1976 .set_ringparam = e1000_set_ringparam,
1977 .get_pauseparam = e1000_get_pauseparam,
1978 .set_pauseparam = e1000_set_pauseparam,
1979 .self_test = e1000_diag_test,
1980 .get_strings = e1000_get_strings,
1981 .set_phys_id = e1000_set_phys_id,
1982 .get_ethtool_stats = e1000_get_ethtool_stats,
1983 .get_sset_count = e1000e_get_sset_count,
1984 .get_coalesce = e1000_get_coalesce,
1985 .set_coalesce = e1000_set_coalesce,
1988 void e1000e_set_ethtool_ops(struct net_device *netdev)
1990 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);