spi-topcliff-pch: supports a spi mode setup and bit order setup by IO control
[zen-stable.git] / drivers / net / ethernet / intel / e1000e / ethtool.c
blobfb2c28e799a2d6ad80ef5eeb88d2fb6e058ec866
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);
583 strlcpy(drvinfo->driver, e1000e_driver_name,
584 sizeof(drvinfo->driver));
585 strlcpy(drvinfo->version, e1000e_driver_version,
586 sizeof(drvinfo->version));
589 * EEPROM image version # is reported as firmware version # for
590 * PCI-E controllers
592 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
593 "%d.%d-%d",
594 (adapter->eeprom_vers & 0xF000) >> 12,
595 (adapter->eeprom_vers & 0x0FF0) >> 4,
596 (adapter->eeprom_vers & 0x000F));
598 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
599 sizeof(drvinfo->bus_info));
600 drvinfo->regdump_len = e1000_get_regs_len(netdev);
601 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
604 static void e1000_get_ringparam(struct net_device *netdev,
605 struct ethtool_ringparam *ring)
607 struct e1000_adapter *adapter = netdev_priv(netdev);
608 struct e1000_ring *tx_ring = adapter->tx_ring;
609 struct e1000_ring *rx_ring = adapter->rx_ring;
611 ring->rx_max_pending = E1000_MAX_RXD;
612 ring->tx_max_pending = E1000_MAX_TXD;
613 ring->rx_pending = rx_ring->count;
614 ring->tx_pending = tx_ring->count;
617 static int e1000_set_ringparam(struct net_device *netdev,
618 struct ethtool_ringparam *ring)
620 struct e1000_adapter *adapter = netdev_priv(netdev);
621 struct e1000_ring *tx_ring, *tx_old;
622 struct e1000_ring *rx_ring, *rx_old;
623 int err;
625 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
626 return -EINVAL;
628 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
629 usleep_range(1000, 2000);
631 if (netif_running(adapter->netdev))
632 e1000e_down(adapter);
634 tx_old = adapter->tx_ring;
635 rx_old = adapter->rx_ring;
637 err = -ENOMEM;
638 tx_ring = kmemdup(tx_old, sizeof(struct e1000_ring), GFP_KERNEL);
639 if (!tx_ring)
640 goto err_alloc_tx;
642 rx_ring = kmemdup(rx_old, sizeof(struct e1000_ring), GFP_KERNEL);
643 if (!rx_ring)
644 goto err_alloc_rx;
646 adapter->tx_ring = tx_ring;
647 adapter->rx_ring = rx_ring;
649 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
650 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
651 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
653 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
654 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
655 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
657 if (netif_running(adapter->netdev)) {
658 /* Try to get new resources before deleting old */
659 err = e1000e_setup_rx_resources(adapter);
660 if (err)
661 goto err_setup_rx;
662 err = e1000e_setup_tx_resources(adapter);
663 if (err)
664 goto err_setup_tx;
667 * restore the old in order to free it,
668 * then add in the new
670 adapter->rx_ring = rx_old;
671 adapter->tx_ring = tx_old;
672 e1000e_free_rx_resources(adapter);
673 e1000e_free_tx_resources(adapter);
674 kfree(tx_old);
675 kfree(rx_old);
676 adapter->rx_ring = rx_ring;
677 adapter->tx_ring = tx_ring;
678 err = e1000e_up(adapter);
679 if (err)
680 goto err_setup;
683 clear_bit(__E1000_RESETTING, &adapter->state);
684 return 0;
685 err_setup_tx:
686 e1000e_free_rx_resources(adapter);
687 err_setup_rx:
688 adapter->rx_ring = rx_old;
689 adapter->tx_ring = tx_old;
690 kfree(rx_ring);
691 err_alloc_rx:
692 kfree(tx_ring);
693 err_alloc_tx:
694 e1000e_up(adapter);
695 err_setup:
696 clear_bit(__E1000_RESETTING, &adapter->state);
697 return err;
700 static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
701 int reg, int offset, u32 mask, u32 write)
703 u32 pat, val;
704 static const u32 test[] = {
705 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
706 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
707 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
708 (test[pat] & write));
709 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
710 if (val != (test[pat] & write & mask)) {
711 e_err("pattern test reg %04X failed: got 0x%08X "
712 "expected 0x%08X\n", reg + offset, val,
713 (test[pat] & write & mask));
714 *data = reg;
715 return 1;
718 return 0;
721 static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
722 int reg, u32 mask, u32 write)
724 u32 val;
725 __ew32(&adapter->hw, reg, write & mask);
726 val = __er32(&adapter->hw, reg);
727 if ((write & mask) != (val & mask)) {
728 e_err("set/check reg %04X test failed: got 0x%08X "
729 "expected 0x%08X\n", reg, (val & mask), (write & mask));
730 *data = reg;
731 return 1;
733 return 0;
735 #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
736 do { \
737 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
738 return 1; \
739 } while (0)
740 #define REG_PATTERN_TEST(reg, mask, write) \
741 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
743 #define REG_SET_AND_CHECK(reg, mask, write) \
744 do { \
745 if (reg_set_and_check(adapter, data, reg, mask, write)) \
746 return 1; \
747 } while (0)
749 static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
751 struct e1000_hw *hw = &adapter->hw;
752 struct e1000_mac_info *mac = &adapter->hw.mac;
753 u32 value;
754 u32 before;
755 u32 after;
756 u32 i;
757 u32 toggle;
758 u32 mask;
761 * The status register is Read Only, so a write should fail.
762 * Some bits that get toggled are ignored.
764 switch (mac->type) {
765 /* there are several bits on newer hardware that are r/w */
766 case e1000_82571:
767 case e1000_82572:
768 case e1000_80003es2lan:
769 toggle = 0x7FFFF3FF;
770 break;
771 default:
772 toggle = 0x7FFFF033;
773 break;
776 before = er32(STATUS);
777 value = (er32(STATUS) & toggle);
778 ew32(STATUS, toggle);
779 after = er32(STATUS) & toggle;
780 if (value != after) {
781 e_err("failed STATUS register test got: 0x%08X expected: "
782 "0x%08X\n", after, value);
783 *data = 1;
784 return 1;
786 /* restore previous status */
787 ew32(STATUS, before);
789 if (!(adapter->flags & FLAG_IS_ICH)) {
790 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
791 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
792 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
793 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
796 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
797 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
798 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
799 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
800 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
801 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
802 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
803 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
804 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
805 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
807 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
809 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
810 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
811 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
813 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
814 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
815 if (!(adapter->flags & FLAG_IS_ICH))
816 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
817 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
818 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
819 mask = 0x8003FFFF;
820 switch (mac->type) {
821 case e1000_ich10lan:
822 case e1000_pchlan:
823 case e1000_pch2lan:
824 mask |= (1 << 18);
825 break;
826 default:
827 break;
829 for (i = 0; i < mac->rar_entry_count; i++)
830 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
831 mask, 0xFFFFFFFF);
833 for (i = 0; i < mac->mta_reg_count; i++)
834 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
836 *data = 0;
837 return 0;
840 static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
842 u16 temp;
843 u16 checksum = 0;
844 u16 i;
846 *data = 0;
847 /* Read and add up the contents of the EEPROM */
848 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
849 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
850 *data = 1;
851 return *data;
853 checksum += temp;
856 /* If Checksum is not Correct return error else test passed */
857 if ((checksum != (u16) NVM_SUM) && !(*data))
858 *data = 2;
860 return *data;
863 static irqreturn_t e1000_test_intr(int irq, void *data)
865 struct net_device *netdev = (struct net_device *) data;
866 struct e1000_adapter *adapter = netdev_priv(netdev);
867 struct e1000_hw *hw = &adapter->hw;
869 adapter->test_icr |= er32(ICR);
871 return IRQ_HANDLED;
874 static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
876 struct net_device *netdev = adapter->netdev;
877 struct e1000_hw *hw = &adapter->hw;
878 u32 mask;
879 u32 shared_int = 1;
880 u32 irq = adapter->pdev->irq;
881 int i;
882 int ret_val = 0;
883 int int_mode = E1000E_INT_MODE_LEGACY;
885 *data = 0;
887 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
888 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
889 int_mode = adapter->int_mode;
890 e1000e_reset_interrupt_capability(adapter);
891 adapter->int_mode = E1000E_INT_MODE_LEGACY;
892 e1000e_set_interrupt_capability(adapter);
894 /* Hook up test interrupt handler just for this test */
895 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
896 netdev)) {
897 shared_int = 0;
898 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
899 netdev->name, netdev)) {
900 *data = 1;
901 ret_val = -1;
902 goto out;
904 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
906 /* Disable all the interrupts */
907 ew32(IMC, 0xFFFFFFFF);
908 e1e_flush();
909 usleep_range(10000, 20000);
911 /* Test each interrupt */
912 for (i = 0; i < 10; i++) {
913 /* Interrupt to test */
914 mask = 1 << i;
916 if (adapter->flags & FLAG_IS_ICH) {
917 switch (mask) {
918 case E1000_ICR_RXSEQ:
919 continue;
920 case 0x00000100:
921 if (adapter->hw.mac.type == e1000_ich8lan ||
922 adapter->hw.mac.type == e1000_ich9lan)
923 continue;
924 break;
925 default:
926 break;
930 if (!shared_int) {
932 * Disable the interrupt to be reported in
933 * the cause register and then force the same
934 * interrupt and see if one gets posted. If
935 * an interrupt was posted to the bus, the
936 * test failed.
938 adapter->test_icr = 0;
939 ew32(IMC, mask);
940 ew32(ICS, mask);
941 e1e_flush();
942 usleep_range(10000, 20000);
944 if (adapter->test_icr & mask) {
945 *data = 3;
946 break;
951 * Enable the interrupt to be reported in
952 * the cause register and then force the same
953 * interrupt and see if one gets posted. If
954 * an interrupt was not posted to the bus, the
955 * test failed.
957 adapter->test_icr = 0;
958 ew32(IMS, mask);
959 ew32(ICS, mask);
960 e1e_flush();
961 usleep_range(10000, 20000);
963 if (!(adapter->test_icr & mask)) {
964 *data = 4;
965 break;
968 if (!shared_int) {
970 * Disable the other interrupts to be reported in
971 * the cause register and then force the other
972 * interrupts and see if any get posted. If
973 * an interrupt was posted to the bus, the
974 * test failed.
976 adapter->test_icr = 0;
977 ew32(IMC, ~mask & 0x00007FFF);
978 ew32(ICS, ~mask & 0x00007FFF);
979 e1e_flush();
980 usleep_range(10000, 20000);
982 if (adapter->test_icr) {
983 *data = 5;
984 break;
989 /* Disable all the interrupts */
990 ew32(IMC, 0xFFFFFFFF);
991 e1e_flush();
992 usleep_range(10000, 20000);
994 /* Unhook test interrupt handler */
995 free_irq(irq, netdev);
997 out:
998 if (int_mode == E1000E_INT_MODE_MSIX) {
999 e1000e_reset_interrupt_capability(adapter);
1000 adapter->int_mode = int_mode;
1001 e1000e_set_interrupt_capability(adapter);
1004 return ret_val;
1007 static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1009 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1010 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1011 struct pci_dev *pdev = adapter->pdev;
1012 int i;
1014 if (tx_ring->desc && tx_ring->buffer_info) {
1015 for (i = 0; i < tx_ring->count; i++) {
1016 if (tx_ring->buffer_info[i].dma)
1017 dma_unmap_single(&pdev->dev,
1018 tx_ring->buffer_info[i].dma,
1019 tx_ring->buffer_info[i].length,
1020 DMA_TO_DEVICE);
1021 if (tx_ring->buffer_info[i].skb)
1022 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1026 if (rx_ring->desc && rx_ring->buffer_info) {
1027 for (i = 0; i < rx_ring->count; i++) {
1028 if (rx_ring->buffer_info[i].dma)
1029 dma_unmap_single(&pdev->dev,
1030 rx_ring->buffer_info[i].dma,
1031 2048, DMA_FROM_DEVICE);
1032 if (rx_ring->buffer_info[i].skb)
1033 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1037 if (tx_ring->desc) {
1038 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1039 tx_ring->dma);
1040 tx_ring->desc = NULL;
1042 if (rx_ring->desc) {
1043 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1044 rx_ring->dma);
1045 rx_ring->desc = NULL;
1048 kfree(tx_ring->buffer_info);
1049 tx_ring->buffer_info = NULL;
1050 kfree(rx_ring->buffer_info);
1051 rx_ring->buffer_info = NULL;
1054 static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1056 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1057 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1058 struct pci_dev *pdev = adapter->pdev;
1059 struct e1000_hw *hw = &adapter->hw;
1060 u32 rctl;
1061 int i;
1062 int ret_val;
1064 /* Setup Tx descriptor ring and Tx buffers */
1066 if (!tx_ring->count)
1067 tx_ring->count = E1000_DEFAULT_TXD;
1069 tx_ring->buffer_info = kcalloc(tx_ring->count,
1070 sizeof(struct e1000_buffer),
1071 GFP_KERNEL);
1072 if (!(tx_ring->buffer_info)) {
1073 ret_val = 1;
1074 goto err_nomem;
1077 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1078 tx_ring->size = ALIGN(tx_ring->size, 4096);
1079 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1080 &tx_ring->dma, GFP_KERNEL);
1081 if (!tx_ring->desc) {
1082 ret_val = 2;
1083 goto err_nomem;
1085 tx_ring->next_to_use = 0;
1086 tx_ring->next_to_clean = 0;
1088 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
1089 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
1090 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
1091 ew32(TDH, 0);
1092 ew32(TDT, 0);
1093 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1094 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1095 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1097 for (i = 0; i < tx_ring->count; i++) {
1098 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1099 struct sk_buff *skb;
1100 unsigned int skb_size = 1024;
1102 skb = alloc_skb(skb_size, GFP_KERNEL);
1103 if (!skb) {
1104 ret_val = 3;
1105 goto err_nomem;
1107 skb_put(skb, skb_size);
1108 tx_ring->buffer_info[i].skb = skb;
1109 tx_ring->buffer_info[i].length = skb->len;
1110 tx_ring->buffer_info[i].dma =
1111 dma_map_single(&pdev->dev, skb->data, skb->len,
1112 DMA_TO_DEVICE);
1113 if (dma_mapping_error(&pdev->dev,
1114 tx_ring->buffer_info[i].dma)) {
1115 ret_val = 4;
1116 goto err_nomem;
1118 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
1119 tx_desc->lower.data = cpu_to_le32(skb->len);
1120 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1121 E1000_TXD_CMD_IFCS |
1122 E1000_TXD_CMD_RS);
1123 tx_desc->upper.data = 0;
1126 /* Setup Rx descriptor ring and Rx buffers */
1128 if (!rx_ring->count)
1129 rx_ring->count = E1000_DEFAULT_RXD;
1131 rx_ring->buffer_info = kcalloc(rx_ring->count,
1132 sizeof(struct e1000_buffer),
1133 GFP_KERNEL);
1134 if (!(rx_ring->buffer_info)) {
1135 ret_val = 5;
1136 goto err_nomem;
1139 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
1140 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1141 &rx_ring->dma, GFP_KERNEL);
1142 if (!rx_ring->desc) {
1143 ret_val = 6;
1144 goto err_nomem;
1146 rx_ring->next_to_use = 0;
1147 rx_ring->next_to_clean = 0;
1149 rctl = er32(RCTL);
1150 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1151 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1152 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1153 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1154 ew32(RDLEN, rx_ring->size);
1155 ew32(RDH, 0);
1156 ew32(RDT, 0);
1157 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1158 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1159 E1000_RCTL_SBP | E1000_RCTL_SECRC |
1160 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1161 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1162 ew32(RCTL, rctl);
1164 for (i = 0; i < rx_ring->count; i++) {
1165 union e1000_rx_desc_extended *rx_desc;
1166 struct sk_buff *skb;
1168 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1169 if (!skb) {
1170 ret_val = 7;
1171 goto err_nomem;
1173 skb_reserve(skb, NET_IP_ALIGN);
1174 rx_ring->buffer_info[i].skb = skb;
1175 rx_ring->buffer_info[i].dma =
1176 dma_map_single(&pdev->dev, skb->data, 2048,
1177 DMA_FROM_DEVICE);
1178 if (dma_mapping_error(&pdev->dev,
1179 rx_ring->buffer_info[i].dma)) {
1180 ret_val = 8;
1181 goto err_nomem;
1183 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1184 rx_desc->read.buffer_addr =
1185 cpu_to_le64(rx_ring->buffer_info[i].dma);
1186 memset(skb->data, 0x00, skb->len);
1189 return 0;
1191 err_nomem:
1192 e1000_free_desc_rings(adapter);
1193 return ret_val;
1196 static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1198 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1199 e1e_wphy(&adapter->hw, 29, 0x001F);
1200 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1201 e1e_wphy(&adapter->hw, 29, 0x001A);
1202 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1205 static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1207 struct e1000_hw *hw = &adapter->hw;
1208 u32 ctrl_reg = 0;
1209 u16 phy_reg = 0;
1210 s32 ret_val = 0;
1212 hw->mac.autoneg = 0;
1214 if (hw->phy.type == e1000_phy_ife) {
1215 /* force 100, set loopback */
1216 e1e_wphy(hw, PHY_CONTROL, 0x6100);
1218 /* Now set up the MAC to the same speed/duplex as the PHY. */
1219 ctrl_reg = er32(CTRL);
1220 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1221 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1222 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1223 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1224 E1000_CTRL_FD); /* Force Duplex to FULL */
1226 ew32(CTRL, ctrl_reg);
1227 e1e_flush();
1228 udelay(500);
1230 return 0;
1233 /* Specific PHY configuration for loopback */
1234 switch (hw->phy.type) {
1235 case e1000_phy_m88:
1236 /* Auto-MDI/MDIX Off */
1237 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1238 /* reset to update Auto-MDI/MDIX */
1239 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1240 /* autoneg off */
1241 e1e_wphy(hw, PHY_CONTROL, 0x8140);
1242 break;
1243 case e1000_phy_gg82563:
1244 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
1245 break;
1246 case e1000_phy_bm:
1247 /* Set Default MAC Interface speed to 1GB */
1248 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1249 phy_reg &= ~0x0007;
1250 phy_reg |= 0x006;
1251 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1252 /* Assert SW reset for above settings to take effect */
1253 e1000e_commit_phy(hw);
1254 mdelay(1);
1255 /* Force Full Duplex */
1256 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1257 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1258 /* Set Link Up (in force link) */
1259 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1260 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1261 /* Force Link */
1262 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1263 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1264 /* Set Early Link Enable */
1265 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1266 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
1267 break;
1268 case e1000_phy_82577:
1269 case e1000_phy_82578:
1270 /* Workaround: K1 must be disabled for stable 1Gbps operation */
1271 ret_val = hw->phy.ops.acquire(hw);
1272 if (ret_val) {
1273 e_err("Cannot setup 1Gbps loopback.\n");
1274 return ret_val;
1276 e1000_configure_k1_ich8lan(hw, false);
1277 hw->phy.ops.release(hw);
1278 break;
1279 case e1000_phy_82579:
1280 /* Disable PHY energy detect power down */
1281 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1282 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1283 /* Disable full chip energy detect */
1284 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1285 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1286 /* Enable loopback on the PHY */
1287 #define I82577_PHY_LBK_CTRL 19
1288 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1289 break;
1290 default:
1291 break;
1294 /* force 1000, set loopback */
1295 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1296 mdelay(250);
1298 /* Now set up the MAC to the same speed/duplex as the PHY. */
1299 ctrl_reg = er32(CTRL);
1300 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1301 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1302 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1303 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1304 E1000_CTRL_FD); /* Force Duplex to FULL */
1306 if (adapter->flags & FLAG_IS_ICH)
1307 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1309 if (hw->phy.media_type == e1000_media_type_copper &&
1310 hw->phy.type == e1000_phy_m88) {
1311 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1312 } else {
1314 * Set the ILOS bit on the fiber Nic if half duplex link is
1315 * detected.
1317 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
1318 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1321 ew32(CTRL, ctrl_reg);
1324 * Disable the receiver on the PHY so when a cable is plugged in, the
1325 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1327 if (hw->phy.type == e1000_phy_m88)
1328 e1000_phy_disable_receiver(adapter);
1330 udelay(500);
1332 return 0;
1335 static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1337 struct e1000_hw *hw = &adapter->hw;
1338 u32 ctrl = er32(CTRL);
1339 int link = 0;
1341 /* special requirements for 82571/82572 fiber adapters */
1344 * jump through hoops to make sure link is up because serdes
1345 * link is hardwired up
1347 ctrl |= E1000_CTRL_SLU;
1348 ew32(CTRL, ctrl);
1350 /* disable autoneg */
1351 ctrl = er32(TXCW);
1352 ctrl &= ~(1 << 31);
1353 ew32(TXCW, ctrl);
1355 link = (er32(STATUS) & E1000_STATUS_LU);
1357 if (!link) {
1358 /* set invert loss of signal */
1359 ctrl = er32(CTRL);
1360 ctrl |= E1000_CTRL_ILOS;
1361 ew32(CTRL, ctrl);
1365 * special write to serdes control register to enable SerDes analog
1366 * loopback
1368 #define E1000_SERDES_LB_ON 0x410
1369 ew32(SCTL, E1000_SERDES_LB_ON);
1370 e1e_flush();
1371 usleep_range(10000, 20000);
1373 return 0;
1376 /* only call this for fiber/serdes connections to es2lan */
1377 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1379 struct e1000_hw *hw = &adapter->hw;
1380 u32 ctrlext = er32(CTRL_EXT);
1381 u32 ctrl = er32(CTRL);
1384 * save CTRL_EXT to restore later, reuse an empty variable (unused
1385 * on mac_type 80003es2lan)
1387 adapter->tx_fifo_head = ctrlext;
1389 /* clear the serdes mode bits, putting the device into mac loopback */
1390 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1391 ew32(CTRL_EXT, ctrlext);
1393 /* force speed to 1000/FD, link up */
1394 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1395 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1396 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1397 ew32(CTRL, ctrl);
1399 /* set mac loopback */
1400 ctrl = er32(RCTL);
1401 ctrl |= E1000_RCTL_LBM_MAC;
1402 ew32(RCTL, ctrl);
1404 /* set testing mode parameters (no need to reset later) */
1405 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
1406 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1407 ew32(KMRNCTRLSTA,
1408 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
1410 return 0;
1413 static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1415 struct e1000_hw *hw = &adapter->hw;
1416 u32 rctl;
1418 if (hw->phy.media_type == e1000_media_type_fiber ||
1419 hw->phy.media_type == e1000_media_type_internal_serdes) {
1420 switch (hw->mac.type) {
1421 case e1000_80003es2lan:
1422 return e1000_set_es2lan_mac_loopback(adapter);
1423 break;
1424 case e1000_82571:
1425 case e1000_82572:
1426 return e1000_set_82571_fiber_loopback(adapter);
1427 break;
1428 default:
1429 rctl = er32(RCTL);
1430 rctl |= E1000_RCTL_LBM_TCVR;
1431 ew32(RCTL, rctl);
1432 return 0;
1434 } else if (hw->phy.media_type == e1000_media_type_copper) {
1435 return e1000_integrated_phy_loopback(adapter);
1438 return 7;
1441 static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1443 struct e1000_hw *hw = &adapter->hw;
1444 u32 rctl;
1445 u16 phy_reg;
1447 rctl = er32(RCTL);
1448 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1449 ew32(RCTL, rctl);
1451 switch (hw->mac.type) {
1452 case e1000_80003es2lan:
1453 if (hw->phy.media_type == e1000_media_type_fiber ||
1454 hw->phy.media_type == e1000_media_type_internal_serdes) {
1455 /* restore CTRL_EXT, stealing space from tx_fifo_head */
1456 ew32(CTRL_EXT, adapter->tx_fifo_head);
1457 adapter->tx_fifo_head = 0;
1459 /* fall through */
1460 case e1000_82571:
1461 case e1000_82572:
1462 if (hw->phy.media_type == e1000_media_type_fiber ||
1463 hw->phy.media_type == e1000_media_type_internal_serdes) {
1464 #define E1000_SERDES_LB_OFF 0x400
1465 ew32(SCTL, E1000_SERDES_LB_OFF);
1466 e1e_flush();
1467 usleep_range(10000, 20000);
1468 break;
1470 /* Fall Through */
1471 default:
1472 hw->mac.autoneg = 1;
1473 if (hw->phy.type == e1000_phy_gg82563)
1474 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1475 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1476 if (phy_reg & MII_CR_LOOPBACK) {
1477 phy_reg &= ~MII_CR_LOOPBACK;
1478 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1479 e1000e_commit_phy(hw);
1481 break;
1485 static void e1000_create_lbtest_frame(struct sk_buff *skb,
1486 unsigned int frame_size)
1488 memset(skb->data, 0xFF, frame_size);
1489 frame_size &= ~1;
1490 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1491 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1492 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1495 static int e1000_check_lbtest_frame(struct sk_buff *skb,
1496 unsigned int frame_size)
1498 frame_size &= ~1;
1499 if (*(skb->data + 3) == 0xFF)
1500 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1501 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1502 return 0;
1503 return 13;
1506 static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1508 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1509 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1510 struct pci_dev *pdev = adapter->pdev;
1511 struct e1000_hw *hw = &adapter->hw;
1512 int i, j, k, l;
1513 int lc;
1514 int good_cnt;
1515 int ret_val = 0;
1516 unsigned long time;
1518 ew32(RDT, rx_ring->count - 1);
1521 * Calculate the loop count based on the largest descriptor ring
1522 * The idea is to wrap the largest ring a number of times using 64
1523 * send/receive pairs during each loop
1526 if (rx_ring->count <= tx_ring->count)
1527 lc = ((tx_ring->count / 64) * 2) + 1;
1528 else
1529 lc = ((rx_ring->count / 64) * 2) + 1;
1531 k = 0;
1532 l = 0;
1533 for (j = 0; j <= lc; j++) { /* loop count loop */
1534 for (i = 0; i < 64; i++) { /* send the packets */
1535 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1536 1024);
1537 dma_sync_single_for_device(&pdev->dev,
1538 tx_ring->buffer_info[k].dma,
1539 tx_ring->buffer_info[k].length,
1540 DMA_TO_DEVICE);
1541 k++;
1542 if (k == tx_ring->count)
1543 k = 0;
1545 ew32(TDT, k);
1546 e1e_flush();
1547 msleep(200);
1548 time = jiffies; /* set the start time for the receive */
1549 good_cnt = 0;
1550 do { /* receive the sent packets */
1551 dma_sync_single_for_cpu(&pdev->dev,
1552 rx_ring->buffer_info[l].dma, 2048,
1553 DMA_FROM_DEVICE);
1555 ret_val = e1000_check_lbtest_frame(
1556 rx_ring->buffer_info[l].skb, 1024);
1557 if (!ret_val)
1558 good_cnt++;
1559 l++;
1560 if (l == rx_ring->count)
1561 l = 0;
1563 * time + 20 msecs (200 msecs on 2.4) is more than
1564 * enough time to complete the receives, if it's
1565 * exceeded, break and error off
1567 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1568 if (good_cnt != 64) {
1569 ret_val = 13; /* ret_val is the same as mis-compare */
1570 break;
1572 if (jiffies >= (time + 20)) {
1573 ret_val = 14; /* error code for time out error */
1574 break;
1576 } /* end loop count loop */
1577 return ret_val;
1580 static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1583 * PHY loopback cannot be performed if SoL/IDER
1584 * sessions are active
1586 if (e1000_check_reset_block(&adapter->hw)) {
1587 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
1588 *data = 0;
1589 goto out;
1592 *data = e1000_setup_desc_rings(adapter);
1593 if (*data)
1594 goto out;
1596 *data = e1000_setup_loopback_test(adapter);
1597 if (*data)
1598 goto err_loopback;
1600 *data = e1000_run_loopback_test(adapter);
1601 e1000_loopback_cleanup(adapter);
1603 err_loopback:
1604 e1000_free_desc_rings(adapter);
1605 out:
1606 return *data;
1609 static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1611 struct e1000_hw *hw = &adapter->hw;
1613 *data = 0;
1614 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1615 int i = 0;
1616 hw->mac.serdes_has_link = false;
1619 * On some blade server designs, link establishment
1620 * could take as long as 2-3 minutes
1622 do {
1623 hw->mac.ops.check_for_link(hw);
1624 if (hw->mac.serdes_has_link)
1625 return *data;
1626 msleep(20);
1627 } while (i++ < 3750);
1629 *data = 1;
1630 } else {
1631 hw->mac.ops.check_for_link(hw);
1632 if (hw->mac.autoneg)
1634 * On some Phy/switch combinations, link establishment
1635 * can take a few seconds more than expected.
1637 msleep(5000);
1639 if (!(er32(STATUS) & E1000_STATUS_LU))
1640 *data = 1;
1642 return *data;
1645 static int e1000e_get_sset_count(struct net_device *netdev, int sset)
1647 switch (sset) {
1648 case ETH_SS_TEST:
1649 return E1000_TEST_LEN;
1650 case ETH_SS_STATS:
1651 return E1000_STATS_LEN;
1652 default:
1653 return -EOPNOTSUPP;
1657 static void e1000_diag_test(struct net_device *netdev,
1658 struct ethtool_test *eth_test, u64 *data)
1660 struct e1000_adapter *adapter = netdev_priv(netdev);
1661 u16 autoneg_advertised;
1662 u8 forced_speed_duplex;
1663 u8 autoneg;
1664 bool if_running = netif_running(netdev);
1666 set_bit(__E1000_TESTING, &adapter->state);
1668 if (!if_running) {
1669 /* Get control of and reset hardware */
1670 if (adapter->flags & FLAG_HAS_AMT)
1671 e1000e_get_hw_control(adapter);
1673 e1000e_power_up_phy(adapter);
1675 adapter->hw.phy.autoneg_wait_to_complete = 1;
1676 e1000e_reset(adapter);
1677 adapter->hw.phy.autoneg_wait_to_complete = 0;
1680 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1681 /* Offline tests */
1683 /* save speed, duplex, autoneg settings */
1684 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1685 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1686 autoneg = adapter->hw.mac.autoneg;
1688 e_info("offline testing starting\n");
1690 if (if_running)
1691 /* indicate we're in test mode */
1692 dev_close(netdev);
1694 if (e1000_reg_test(adapter, &data[0]))
1695 eth_test->flags |= ETH_TEST_FL_FAILED;
1697 e1000e_reset(adapter);
1698 if (e1000_eeprom_test(adapter, &data[1]))
1699 eth_test->flags |= ETH_TEST_FL_FAILED;
1701 e1000e_reset(adapter);
1702 if (e1000_intr_test(adapter, &data[2]))
1703 eth_test->flags |= ETH_TEST_FL_FAILED;
1705 e1000e_reset(adapter);
1706 if (e1000_loopback_test(adapter, &data[3]))
1707 eth_test->flags |= ETH_TEST_FL_FAILED;
1709 /* force this routine to wait until autoneg complete/timeout */
1710 adapter->hw.phy.autoneg_wait_to_complete = 1;
1711 e1000e_reset(adapter);
1712 adapter->hw.phy.autoneg_wait_to_complete = 0;
1714 if (e1000_link_test(adapter, &data[4]))
1715 eth_test->flags |= ETH_TEST_FL_FAILED;
1717 /* restore speed, duplex, autoneg settings */
1718 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1719 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1720 adapter->hw.mac.autoneg = autoneg;
1721 e1000e_reset(adapter);
1723 clear_bit(__E1000_TESTING, &adapter->state);
1724 if (if_running)
1725 dev_open(netdev);
1726 } else {
1727 /* Online tests */
1729 e_info("online testing starting\n");
1731 /* register, eeprom, intr and loopback tests not run online */
1732 data[0] = 0;
1733 data[1] = 0;
1734 data[2] = 0;
1735 data[3] = 0;
1737 if (e1000_link_test(adapter, &data[4]))
1738 eth_test->flags |= ETH_TEST_FL_FAILED;
1740 clear_bit(__E1000_TESTING, &adapter->state);
1743 if (!if_running) {
1744 e1000e_reset(adapter);
1746 if (adapter->flags & FLAG_HAS_AMT)
1747 e1000e_release_hw_control(adapter);
1750 msleep_interruptible(4 * 1000);
1753 static void e1000_get_wol(struct net_device *netdev,
1754 struct ethtool_wolinfo *wol)
1756 struct e1000_adapter *adapter = netdev_priv(netdev);
1758 wol->supported = 0;
1759 wol->wolopts = 0;
1761 if (!(adapter->flags & FLAG_HAS_WOL) ||
1762 !device_can_wakeup(&adapter->pdev->dev))
1763 return;
1765 wol->supported = WAKE_UCAST | WAKE_MCAST |
1766 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
1768 /* apply any specific unsupported masks here */
1769 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1770 wol->supported &= ~WAKE_UCAST;
1772 if (adapter->wol & E1000_WUFC_EX)
1773 e_err("Interface does not support directed (unicast) "
1774 "frame wake-up packets\n");
1777 if (adapter->wol & E1000_WUFC_EX)
1778 wol->wolopts |= WAKE_UCAST;
1779 if (adapter->wol & E1000_WUFC_MC)
1780 wol->wolopts |= WAKE_MCAST;
1781 if (adapter->wol & E1000_WUFC_BC)
1782 wol->wolopts |= WAKE_BCAST;
1783 if (adapter->wol & E1000_WUFC_MAG)
1784 wol->wolopts |= WAKE_MAGIC;
1785 if (adapter->wol & E1000_WUFC_LNKC)
1786 wol->wolopts |= WAKE_PHY;
1789 static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1791 struct e1000_adapter *adapter = netdev_priv(netdev);
1793 if (!(adapter->flags & FLAG_HAS_WOL) ||
1794 !device_can_wakeup(&adapter->pdev->dev) ||
1795 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
1796 WAKE_MAGIC | WAKE_PHY)))
1797 return -EOPNOTSUPP;
1799 /* these settings will always override what we currently have */
1800 adapter->wol = 0;
1802 if (wol->wolopts & WAKE_UCAST)
1803 adapter->wol |= E1000_WUFC_EX;
1804 if (wol->wolopts & WAKE_MCAST)
1805 adapter->wol |= E1000_WUFC_MC;
1806 if (wol->wolopts & WAKE_BCAST)
1807 adapter->wol |= E1000_WUFC_BC;
1808 if (wol->wolopts & WAKE_MAGIC)
1809 adapter->wol |= E1000_WUFC_MAG;
1810 if (wol->wolopts & WAKE_PHY)
1811 adapter->wol |= E1000_WUFC_LNKC;
1813 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1815 return 0;
1818 static int e1000_set_phys_id(struct net_device *netdev,
1819 enum ethtool_phys_id_state state)
1821 struct e1000_adapter *adapter = netdev_priv(netdev);
1822 struct e1000_hw *hw = &adapter->hw;
1824 switch (state) {
1825 case ETHTOOL_ID_ACTIVE:
1826 if (!hw->mac.ops.blink_led)
1827 return 2; /* cycle on/off twice per second */
1829 hw->mac.ops.blink_led(hw);
1830 break;
1832 case ETHTOOL_ID_INACTIVE:
1833 if (hw->phy.type == e1000_phy_ife)
1834 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
1835 hw->mac.ops.led_off(hw);
1836 hw->mac.ops.cleanup_led(hw);
1837 break;
1839 case ETHTOOL_ID_ON:
1840 adapter->hw.mac.ops.led_on(&adapter->hw);
1841 break;
1843 case ETHTOOL_ID_OFF:
1844 adapter->hw.mac.ops.led_off(&adapter->hw);
1845 break;
1847 return 0;
1850 static int e1000_get_coalesce(struct net_device *netdev,
1851 struct ethtool_coalesce *ec)
1853 struct e1000_adapter *adapter = netdev_priv(netdev);
1855 if (adapter->itr_setting <= 4)
1856 ec->rx_coalesce_usecs = adapter->itr_setting;
1857 else
1858 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1860 return 0;
1863 static int e1000_set_coalesce(struct net_device *netdev,
1864 struct ethtool_coalesce *ec)
1866 struct e1000_adapter *adapter = netdev_priv(netdev);
1867 struct e1000_hw *hw = &adapter->hw;
1869 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
1870 ((ec->rx_coalesce_usecs > 4) &&
1871 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1872 (ec->rx_coalesce_usecs == 2))
1873 return -EINVAL;
1875 if (ec->rx_coalesce_usecs == 4) {
1876 adapter->itr = adapter->itr_setting = 4;
1877 } else if (ec->rx_coalesce_usecs <= 3) {
1878 adapter->itr = 20000;
1879 adapter->itr_setting = ec->rx_coalesce_usecs;
1880 } else {
1881 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1882 adapter->itr_setting = adapter->itr & ~3;
1885 if (adapter->itr_setting != 0)
1886 ew32(ITR, 1000000000 / (adapter->itr * 256));
1887 else
1888 ew32(ITR, 0);
1890 return 0;
1893 static int e1000_nway_reset(struct net_device *netdev)
1895 struct e1000_adapter *adapter = netdev_priv(netdev);
1897 if (!netif_running(netdev))
1898 return -EAGAIN;
1900 if (!adapter->hw.mac.autoneg)
1901 return -EINVAL;
1903 e1000e_reinit_locked(adapter);
1905 return 0;
1908 static void e1000_get_ethtool_stats(struct net_device *netdev,
1909 struct ethtool_stats *stats,
1910 u64 *data)
1912 struct e1000_adapter *adapter = netdev_priv(netdev);
1913 struct rtnl_link_stats64 net_stats;
1914 int i;
1915 char *p = NULL;
1917 e1000e_get_stats64(netdev, &net_stats);
1918 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1919 switch (e1000_gstrings_stats[i].type) {
1920 case NETDEV_STATS:
1921 p = (char *) &net_stats +
1922 e1000_gstrings_stats[i].stat_offset;
1923 break;
1924 case E1000_STATS:
1925 p = (char *) adapter +
1926 e1000_gstrings_stats[i].stat_offset;
1927 break;
1928 default:
1929 data[i] = 0;
1930 continue;
1933 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1934 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1938 static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1939 u8 *data)
1941 u8 *p = data;
1942 int i;
1944 switch (stringset) {
1945 case ETH_SS_TEST:
1946 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
1947 break;
1948 case ETH_SS_STATS:
1949 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1950 memcpy(p, e1000_gstrings_stats[i].stat_string,
1951 ETH_GSTRING_LEN);
1952 p += ETH_GSTRING_LEN;
1954 break;
1958 static const struct ethtool_ops e1000_ethtool_ops = {
1959 .get_settings = e1000_get_settings,
1960 .set_settings = e1000_set_settings,
1961 .get_drvinfo = e1000_get_drvinfo,
1962 .get_regs_len = e1000_get_regs_len,
1963 .get_regs = e1000_get_regs,
1964 .get_wol = e1000_get_wol,
1965 .set_wol = e1000_set_wol,
1966 .get_msglevel = e1000_get_msglevel,
1967 .set_msglevel = e1000_set_msglevel,
1968 .nway_reset = e1000_nway_reset,
1969 .get_link = ethtool_op_get_link,
1970 .get_eeprom_len = e1000_get_eeprom_len,
1971 .get_eeprom = e1000_get_eeprom,
1972 .set_eeprom = e1000_set_eeprom,
1973 .get_ringparam = e1000_get_ringparam,
1974 .set_ringparam = e1000_set_ringparam,
1975 .get_pauseparam = e1000_get_pauseparam,
1976 .set_pauseparam = e1000_set_pauseparam,
1977 .self_test = e1000_diag_test,
1978 .get_strings = e1000_get_strings,
1979 .set_phys_id = e1000_set_phys_id,
1980 .get_ethtool_stats = e1000_get_ethtool_stats,
1981 .get_sset_count = e1000e_get_sset_count,
1982 .get_coalesce = e1000_get_coalesce,
1983 .set_coalesce = e1000_set_coalesce,
1986 void e1000e_set_ethtool_ops(struct net_device *netdev)
1988 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);