1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2008 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
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".
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/ethtool.h>
33 #include <linux/pci.h>
34 #include <linux/delay.h>
39 char stat_string[ETH_GSTRING_LEN];
44 #define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
45 offsetof(struct e1000_adapter, m)
46 static const struct e1000_stats e1000_gstrings_stats[] = {
47 { "rx_packets", E1000_STAT(stats.gprc) },
48 { "tx_packets", E1000_STAT(stats.gptc) },
49 { "rx_bytes", E1000_STAT(stats.gorc) },
50 { "tx_bytes", E1000_STAT(stats.gotc) },
51 { "rx_broadcast", E1000_STAT(stats.bprc) },
52 { "tx_broadcast", E1000_STAT(stats.bptc) },
53 { "rx_multicast", E1000_STAT(stats.mprc) },
54 { "tx_multicast", E1000_STAT(stats.mptc) },
55 { "rx_errors", E1000_STAT(net_stats.rx_errors) },
56 { "tx_errors", E1000_STAT(net_stats.tx_errors) },
57 { "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
58 { "multicast", E1000_STAT(stats.mprc) },
59 { "collisions", E1000_STAT(stats.colc) },
60 { "rx_length_errors", E1000_STAT(net_stats.rx_length_errors) },
61 { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
62 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
63 { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
64 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
65 { "rx_missed_errors", E1000_STAT(stats.mpc) },
66 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
67 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
68 { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) },
69 { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) },
70 { "tx_window_errors", E1000_STAT(stats.latecol) },
71 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
72 { "tx_deferred_ok", E1000_STAT(stats.dc) },
73 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
74 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
75 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
76 { "tx_restart_queue", E1000_STAT(restart_queue) },
77 { "rx_long_length_errors", E1000_STAT(stats.roc) },
78 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
79 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
80 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
81 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
82 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
83 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
84 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
85 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
86 { "rx_long_byte_count", E1000_STAT(stats.gorc) },
87 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
88 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
89 { "rx_header_split", E1000_STAT(rx_hdr_split) },
90 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
91 { "tx_smbus", E1000_STAT(stats.mgptc) },
92 { "rx_smbus", E1000_STAT(stats.mgprc) },
93 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
94 { "rx_dma_failed", E1000_STAT(rx_dma_failed) },
95 { "tx_dma_failed", E1000_STAT(tx_dma_failed) },
98 #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
99 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
100 static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
101 "Register test (offline)", "Eeprom test (offline)",
102 "Interrupt test (offline)", "Loopback test (offline)",
103 "Link test (on/offline)"
105 #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
107 static int e1000_get_settings(struct net_device *netdev,
108 struct ethtool_cmd *ecmd)
110 struct e1000_adapter *adapter = netdev_priv(netdev);
111 struct e1000_hw *hw = &adapter->hw;
114 if (hw->phy.media_type == e1000_media_type_copper) {
116 ecmd->supported = (SUPPORTED_10baseT_Half |
117 SUPPORTED_10baseT_Full |
118 SUPPORTED_100baseT_Half |
119 SUPPORTED_100baseT_Full |
120 SUPPORTED_1000baseT_Full |
123 if (hw->phy.type == e1000_phy_ife)
124 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
125 ecmd->advertising = ADVERTISED_TP;
127 if (hw->mac.autoneg == 1) {
128 ecmd->advertising |= ADVERTISED_Autoneg;
129 /* the e1000 autoneg seems to match ethtool nicely */
130 ecmd->advertising |= hw->phy.autoneg_advertised;
133 ecmd->port = PORT_TP;
134 ecmd->phy_address = hw->phy.addr;
135 ecmd->transceiver = XCVR_INTERNAL;
138 ecmd->supported = (SUPPORTED_1000baseT_Full |
142 ecmd->advertising = (ADVERTISED_1000baseT_Full |
146 ecmd->port = PORT_FIBRE;
147 ecmd->transceiver = XCVR_EXTERNAL;
150 status = er32(STATUS);
151 if (status & E1000_STATUS_LU) {
152 if (status & E1000_STATUS_SPEED_1000)
154 else if (status & E1000_STATUS_SPEED_100)
159 if (status & E1000_STATUS_FD)
160 ecmd->duplex = DUPLEX_FULL;
162 ecmd->duplex = DUPLEX_HALF;
168 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
169 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
173 static u32 e1000_get_link(struct net_device *netdev)
175 struct e1000_adapter *adapter = netdev_priv(netdev);
176 struct e1000_hw *hw = &adapter->hw;
179 status = er32(STATUS);
180 return (status & E1000_STATUS_LU) ? 1 : 0;
183 static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
185 struct e1000_mac_info *mac = &adapter->hw.mac;
189 /* Fiber NICs only allow 1000 gbps Full duplex */
190 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
191 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
192 e_err("Unsupported Speed/Duplex configuration\n");
197 case SPEED_10 + DUPLEX_HALF:
198 mac->forced_speed_duplex = ADVERTISE_10_HALF;
200 case SPEED_10 + DUPLEX_FULL:
201 mac->forced_speed_duplex = ADVERTISE_10_FULL;
203 case SPEED_100 + DUPLEX_HALF:
204 mac->forced_speed_duplex = ADVERTISE_100_HALF;
206 case SPEED_100 + DUPLEX_FULL:
207 mac->forced_speed_duplex = ADVERTISE_100_FULL;
209 case SPEED_1000 + DUPLEX_FULL:
211 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
213 case SPEED_1000 + DUPLEX_HALF: /* not supported */
215 e_err("Unsupported Speed/Duplex configuration\n");
221 static int e1000_set_settings(struct net_device *netdev,
222 struct ethtool_cmd *ecmd)
224 struct e1000_adapter *adapter = netdev_priv(netdev);
225 struct e1000_hw *hw = &adapter->hw;
228 * When SoL/IDER sessions are active, autoneg/speed/duplex
231 if (e1000_check_reset_block(hw)) {
232 e_err("Cannot change link characteristics when SoL/IDER is "
237 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
240 if (ecmd->autoneg == AUTONEG_ENABLE) {
242 if (hw->phy.media_type == e1000_media_type_fiber)
243 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
247 hw->phy.autoneg_advertised = ecmd->advertising |
250 ecmd->advertising = hw->phy.autoneg_advertised;
251 if (adapter->fc_autoneg)
252 hw->fc.original_type = e1000_fc_default;
254 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
255 clear_bit(__E1000_RESETTING, &adapter->state);
262 if (netif_running(adapter->netdev)) {
263 e1000e_down(adapter);
266 e1000e_reset(adapter);
269 clear_bit(__E1000_RESETTING, &adapter->state);
273 static void e1000_get_pauseparam(struct net_device *netdev,
274 struct ethtool_pauseparam *pause)
276 struct e1000_adapter *adapter = netdev_priv(netdev);
277 struct e1000_hw *hw = &adapter->hw;
280 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
282 if (hw->fc.type == e1000_fc_rx_pause) {
284 } else if (hw->fc.type == e1000_fc_tx_pause) {
286 } else if (hw->fc.type == e1000_fc_full) {
292 static int e1000_set_pauseparam(struct net_device *netdev,
293 struct ethtool_pauseparam *pause)
295 struct e1000_adapter *adapter = netdev_priv(netdev);
296 struct e1000_hw *hw = &adapter->hw;
299 adapter->fc_autoneg = pause->autoneg;
301 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
304 if (pause->rx_pause && pause->tx_pause)
305 hw->fc.type = e1000_fc_full;
306 else if (pause->rx_pause && !pause->tx_pause)
307 hw->fc.type = e1000_fc_rx_pause;
308 else if (!pause->rx_pause && pause->tx_pause)
309 hw->fc.type = e1000_fc_tx_pause;
310 else if (!pause->rx_pause && !pause->tx_pause)
311 hw->fc.type = e1000_fc_none;
313 hw->fc.original_type = hw->fc.type;
315 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
316 hw->fc.type = e1000_fc_default;
317 if (netif_running(adapter->netdev)) {
318 e1000e_down(adapter);
321 e1000e_reset(adapter);
324 retval = ((hw->phy.media_type == e1000_media_type_fiber) ?
325 hw->mac.ops.setup_link(hw) : e1000e_force_mac_fc(hw));
328 clear_bit(__E1000_RESETTING, &adapter->state);
332 static u32 e1000_get_rx_csum(struct net_device *netdev)
334 struct e1000_adapter *adapter = netdev_priv(netdev);
335 return (adapter->flags & FLAG_RX_CSUM_ENABLED);
338 static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
340 struct e1000_adapter *adapter = netdev_priv(netdev);
343 adapter->flags |= FLAG_RX_CSUM_ENABLED;
345 adapter->flags &= ~FLAG_RX_CSUM_ENABLED;
347 if (netif_running(netdev))
348 e1000e_reinit_locked(adapter);
350 e1000e_reset(adapter);
354 static u32 e1000_get_tx_csum(struct net_device *netdev)
356 return ((netdev->features & NETIF_F_HW_CSUM) != 0);
359 static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
362 netdev->features |= NETIF_F_HW_CSUM;
364 netdev->features &= ~NETIF_F_HW_CSUM;
369 static int e1000_set_tso(struct net_device *netdev, u32 data)
371 struct e1000_adapter *adapter = netdev_priv(netdev);
374 netdev->features |= NETIF_F_TSO;
375 netdev->features |= NETIF_F_TSO6;
377 netdev->features &= ~NETIF_F_TSO;
378 netdev->features &= ~NETIF_F_TSO6;
381 e_info("TSO is %s\n", data ? "Enabled" : "Disabled");
382 adapter->flags |= FLAG_TSO_FORCE;
386 static u32 e1000_get_msglevel(struct net_device *netdev)
388 struct e1000_adapter *adapter = netdev_priv(netdev);
389 return adapter->msg_enable;
392 static void e1000_set_msglevel(struct net_device *netdev, u32 data)
394 struct e1000_adapter *adapter = netdev_priv(netdev);
395 adapter->msg_enable = data;
398 static int e1000_get_regs_len(struct net_device *netdev)
400 #define E1000_REGS_LEN 32 /* overestimate */
401 return E1000_REGS_LEN * sizeof(u32);
404 static void e1000_get_regs(struct net_device *netdev,
405 struct ethtool_regs *regs, void *p)
407 struct e1000_adapter *adapter = netdev_priv(netdev);
408 struct e1000_hw *hw = &adapter->hw;
413 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
415 pci_read_config_byte(adapter->pdev, PCI_REVISION_ID, &revision_id);
417 regs->version = (1 << 24) | (revision_id << 16) | adapter->pdev->device;
419 regs_buff[0] = er32(CTRL);
420 regs_buff[1] = er32(STATUS);
422 regs_buff[2] = er32(RCTL);
423 regs_buff[3] = er32(RDLEN);
424 regs_buff[4] = er32(RDH);
425 regs_buff[5] = er32(RDT);
426 regs_buff[6] = er32(RDTR);
428 regs_buff[7] = er32(TCTL);
429 regs_buff[8] = er32(TDLEN);
430 regs_buff[9] = er32(TDH);
431 regs_buff[10] = er32(TDT);
432 regs_buff[11] = er32(TIDV);
434 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
435 if (hw->phy.type == e1000_phy_m88) {
436 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
437 regs_buff[13] = (u32)phy_data; /* cable length */
438 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
439 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
440 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
441 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
442 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
443 regs_buff[18] = regs_buff[13]; /* cable polarity */
444 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
445 regs_buff[20] = regs_buff[17]; /* polarity correction */
446 /* phy receive errors */
447 regs_buff[22] = adapter->phy_stats.receive_errors;
448 regs_buff[23] = regs_buff[13]; /* mdix mode */
450 regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
451 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
452 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
453 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
456 static int e1000_get_eeprom_len(struct net_device *netdev)
458 struct e1000_adapter *adapter = netdev_priv(netdev);
459 return adapter->hw.nvm.word_size * 2;
462 static int e1000_get_eeprom(struct net_device *netdev,
463 struct ethtool_eeprom *eeprom, u8 *bytes)
465 struct e1000_adapter *adapter = netdev_priv(netdev);
466 struct e1000_hw *hw = &adapter->hw;
473 if (eeprom->len == 0)
476 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
478 first_word = eeprom->offset >> 1;
479 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
481 eeprom_buff = kmalloc(sizeof(u16) *
482 (last_word - first_word + 1), GFP_KERNEL);
486 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
487 ret_val = e1000_read_nvm(hw, first_word,
488 last_word - first_word + 1,
491 for (i = 0; i < last_word - first_word + 1; i++) {
492 ret_val = e1000_read_nvm(hw, first_word + i, 1,
495 /* a read error occurred, throw away the
497 memset(eeprom_buff, 0xff, sizeof(eeprom_buff));
503 /* Device's eeprom is always little-endian, word addressable */
504 for (i = 0; i < last_word - first_word + 1; i++)
505 le16_to_cpus(&eeprom_buff[i]);
507 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
513 static int e1000_set_eeprom(struct net_device *netdev,
514 struct ethtool_eeprom *eeprom, u8 *bytes)
516 struct e1000_adapter *adapter = netdev_priv(netdev);
517 struct e1000_hw *hw = &adapter->hw;
526 if (eeprom->len == 0)
529 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
532 max_len = hw->nvm.word_size * 2;
534 first_word = eeprom->offset >> 1;
535 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
536 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
540 ptr = (void *)eeprom_buff;
542 if (eeprom->offset & 1) {
543 /* need read/modify/write of first changed EEPROM word */
544 /* only the second byte of the word is being modified */
545 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
548 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
549 /* need read/modify/write of last changed EEPROM word */
550 /* only the first byte of the word is being modified */
551 ret_val = e1000_read_nvm(hw, last_word, 1,
552 &eeprom_buff[last_word - first_word]);
554 /* Device's eeprom is always little-endian, word addressable */
555 for (i = 0; i < last_word - first_word + 1; i++)
556 le16_to_cpus(&eeprom_buff[i]);
558 memcpy(ptr, bytes, eeprom->len);
560 for (i = 0; i < last_word - first_word + 1; i++)
561 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
563 ret_val = e1000_write_nvm(hw, first_word,
564 last_word - first_word + 1, eeprom_buff);
567 * Update the checksum over the first part of the EEPROM if needed
568 * and flush shadow RAM for 82573 controllers
570 if ((ret_val == 0) && ((first_word <= NVM_CHECKSUM_REG) ||
571 (hw->mac.type == e1000_82573)))
572 e1000e_update_nvm_checksum(hw);
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];
585 strncpy(drvinfo->driver, e1000e_driver_name, 32);
586 strncpy(drvinfo->version, e1000e_driver_version, 32);
589 * EEPROM image version # is reported as firmware version # for
592 e1000_read_nvm(&adapter->hw, 5, 1, &eeprom_data);
593 sprintf(firmware_version, "%d.%d-%d",
594 (eeprom_data & 0xF000) >> 12,
595 (eeprom_data & 0x0FF0) >> 4,
596 eeprom_data & 0x000F);
598 strncpy(drvinfo->fw_version, firmware_version, 32);
599 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
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_mini_max_pending = 0;
614 ring->rx_jumbo_max_pending = 0;
615 ring->rx_pending = rx_ring->count;
616 ring->tx_pending = tx_ring->count;
617 ring->rx_mini_pending = 0;
618 ring->rx_jumbo_pending = 0;
621 static int e1000_set_ringparam(struct net_device *netdev,
622 struct ethtool_ringparam *ring)
624 struct e1000_adapter *adapter = netdev_priv(netdev);
625 struct e1000_ring *tx_ring, *tx_old;
626 struct e1000_ring *rx_ring, *rx_old;
629 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
632 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
635 if (netif_running(adapter->netdev))
636 e1000e_down(adapter);
638 tx_old = adapter->tx_ring;
639 rx_old = adapter->rx_ring;
642 tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
646 * use a memcpy to save any previously configured
647 * items like napi structs from having to be
650 memcpy(tx_ring, tx_old, sizeof(struct e1000_ring));
652 rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
655 memcpy(rx_ring, rx_old, sizeof(struct e1000_ring));
657 adapter->tx_ring = tx_ring;
658 adapter->rx_ring = rx_ring;
660 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
661 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
662 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
664 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
665 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
666 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
668 if (netif_running(adapter->netdev)) {
669 /* Try to get new resources before deleting old */
670 err = e1000e_setup_rx_resources(adapter);
673 err = e1000e_setup_tx_resources(adapter);
678 * restore the old in order to free it,
679 * then add in the new
681 adapter->rx_ring = rx_old;
682 adapter->tx_ring = tx_old;
683 e1000e_free_rx_resources(adapter);
684 e1000e_free_tx_resources(adapter);
687 adapter->rx_ring = rx_ring;
688 adapter->tx_ring = tx_ring;
689 err = e1000e_up(adapter);
694 clear_bit(__E1000_RESETTING, &adapter->state);
697 e1000e_free_rx_resources(adapter);
699 adapter->rx_ring = rx_old;
700 adapter->tx_ring = tx_old;
707 clear_bit(__E1000_RESETTING, &adapter->state);
711 static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
712 int reg, int offset, u32 mask, u32 write)
715 static const u32 test[] =
716 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
717 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
718 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
719 (test[pat] & write));
720 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
721 if (val != (test[pat] & write & mask)) {
722 e_err("pattern test reg %04X failed: got 0x%08X "
723 "expected 0x%08X\n", reg + offset, val,
724 (test[pat] & write & mask));
732 static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
733 int reg, u32 mask, u32 write)
736 __ew32(&adapter->hw, reg, write & mask);
737 val = __er32(&adapter->hw, reg);
738 if ((write & mask) != (val & mask)) {
739 e_err("set/check reg %04X test failed: got 0x%08X "
740 "expected 0x%08X\n", reg, (val & mask), (write & mask));
746 #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
748 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
751 #define REG_PATTERN_TEST(reg, mask, write) \
752 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
754 #define REG_SET_AND_CHECK(reg, mask, write) \
756 if (reg_set_and_check(adapter, data, reg, mask, write)) \
760 static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
762 struct e1000_hw *hw = &adapter->hw;
763 struct e1000_mac_info *mac = &adapter->hw.mac;
771 * The status register is Read Only, so a write should fail.
772 * Some bits that get toggled are ignored.
775 /* there are several bits on newer hardware that are r/w */
778 case e1000_80003es2lan:
791 before = er32(STATUS);
792 value = (er32(STATUS) & toggle);
793 ew32(STATUS, toggle);
794 after = er32(STATUS) & toggle;
795 if (value != after) {
796 e_err("failed STATUS register test got: 0x%08X expected: "
797 "0x%08X\n", after, value);
801 /* restore previous status */
802 ew32(STATUS, before);
804 if (!(adapter->flags & FLAG_IS_ICH)) {
805 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
806 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
807 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
808 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
811 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
812 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
813 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
814 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
815 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
816 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
817 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
818 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
819 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
820 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
822 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
824 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
825 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
826 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
828 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
829 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
830 if (!(adapter->flags & FLAG_IS_ICH))
831 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
832 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
833 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
834 for (i = 0; i < mac->rar_entry_count; i++)
835 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
836 0x8003FFFF, 0xFFFFFFFF);
838 for (i = 0; i < mac->mta_reg_count; i++)
839 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
845 static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
852 /* Read and add up the contents of the EEPROM */
853 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
854 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
861 /* If Checksum is not Correct return error else test passed */
862 if ((checksum != (u16) NVM_SUM) && !(*data))
868 static irqreturn_t e1000_test_intr(int irq, void *data)
870 struct net_device *netdev = (struct net_device *) data;
871 struct e1000_adapter *adapter = netdev_priv(netdev);
872 struct e1000_hw *hw = &adapter->hw;
874 adapter->test_icr |= er32(ICR);
879 static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
881 struct net_device *netdev = adapter->netdev;
882 struct e1000_hw *hw = &adapter->hw;
885 u32 irq = adapter->pdev->irq;
890 /* NOTE: we don't test MSI interrupts here, yet */
891 /* Hook up test interrupt handler just for this test */
892 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
895 } else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
896 netdev->name, netdev)) {
900 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
902 /* Disable all the interrupts */
903 ew32(IMC, 0xFFFFFFFF);
906 /* Test each interrupt */
907 for (i = 0; i < 10; i++) {
908 if ((adapter->flags & FLAG_IS_ICH) && (i == 8))
911 /* Interrupt to test */
916 * Disable the interrupt to be reported in
917 * the cause register and then force the same
918 * interrupt and see if one gets posted. If
919 * an interrupt was posted to the bus, the
922 adapter->test_icr = 0;
927 if (adapter->test_icr & mask) {
934 * Enable 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 not posted to the bus, the
940 adapter->test_icr = 0;
945 if (!(adapter->test_icr & mask)) {
952 * Disable the other interrupts to be reported in
953 * the cause register and then force the other
954 * interrupts and see if any get posted. If
955 * an interrupt was posted to the bus, the
958 adapter->test_icr = 0;
959 ew32(IMC, ~mask & 0x00007FFF);
960 ew32(ICS, ~mask & 0x00007FFF);
963 if (adapter->test_icr) {
970 /* Disable all the interrupts */
971 ew32(IMC, 0xFFFFFFFF);
974 /* Unhook test interrupt handler */
975 free_irq(irq, netdev);
980 static void e1000_free_desc_rings(struct e1000_adapter *adapter)
982 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
983 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
984 struct pci_dev *pdev = adapter->pdev;
987 if (tx_ring->desc && tx_ring->buffer_info) {
988 for (i = 0; i < tx_ring->count; i++) {
989 if (tx_ring->buffer_info[i].dma)
990 pci_unmap_single(pdev,
991 tx_ring->buffer_info[i].dma,
992 tx_ring->buffer_info[i].length,
994 if (tx_ring->buffer_info[i].skb)
995 dev_kfree_skb(tx_ring->buffer_info[i].skb);
999 if (rx_ring->desc && rx_ring->buffer_info) {
1000 for (i = 0; i < rx_ring->count; i++) {
1001 if (rx_ring->buffer_info[i].dma)
1002 pci_unmap_single(pdev,
1003 rx_ring->buffer_info[i].dma,
1004 2048, PCI_DMA_FROMDEVICE);
1005 if (rx_ring->buffer_info[i].skb)
1006 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1010 if (tx_ring->desc) {
1011 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1013 tx_ring->desc = NULL;
1015 if (rx_ring->desc) {
1016 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1018 rx_ring->desc = NULL;
1021 kfree(tx_ring->buffer_info);
1022 tx_ring->buffer_info = NULL;
1023 kfree(rx_ring->buffer_info);
1024 rx_ring->buffer_info = NULL;
1027 static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1029 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1030 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1031 struct pci_dev *pdev = adapter->pdev;
1032 struct e1000_hw *hw = &adapter->hw;
1037 /* Setup Tx descriptor ring and Tx buffers */
1039 if (!tx_ring->count)
1040 tx_ring->count = E1000_DEFAULT_TXD;
1042 tx_ring->buffer_info = kcalloc(tx_ring->count,
1043 sizeof(struct e1000_buffer),
1045 if (!(tx_ring->buffer_info)) {
1050 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1051 tx_ring->size = ALIGN(tx_ring->size, 4096);
1052 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1053 &tx_ring->dma, GFP_KERNEL);
1054 if (!tx_ring->desc) {
1058 tx_ring->next_to_use = 0;
1059 tx_ring->next_to_clean = 0;
1061 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
1062 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
1063 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
1066 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1067 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1068 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1070 for (i = 0; i < tx_ring->count; i++) {
1071 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1072 struct sk_buff *skb;
1073 unsigned int skb_size = 1024;
1075 skb = alloc_skb(skb_size, GFP_KERNEL);
1080 skb_put(skb, skb_size);
1081 tx_ring->buffer_info[i].skb = skb;
1082 tx_ring->buffer_info[i].length = skb->len;
1083 tx_ring->buffer_info[i].dma =
1084 pci_map_single(pdev, skb->data, skb->len,
1086 if (pci_dma_mapping_error(pdev, tx_ring->buffer_info[i].dma)) {
1090 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
1091 tx_desc->lower.data = cpu_to_le32(skb->len);
1092 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1093 E1000_TXD_CMD_IFCS |
1095 tx_desc->upper.data = 0;
1098 /* Setup Rx descriptor ring and Rx buffers */
1100 if (!rx_ring->count)
1101 rx_ring->count = E1000_DEFAULT_RXD;
1103 rx_ring->buffer_info = kcalloc(rx_ring->count,
1104 sizeof(struct e1000_buffer),
1106 if (!(rx_ring->buffer_info)) {
1111 rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
1112 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1113 &rx_ring->dma, GFP_KERNEL);
1114 if (!rx_ring->desc) {
1118 rx_ring->next_to_use = 0;
1119 rx_ring->next_to_clean = 0;
1122 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1123 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1124 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1125 ew32(RDLEN, rx_ring->size);
1128 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1129 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1130 E1000_RCTL_SBP | E1000_RCTL_SECRC |
1131 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1132 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1135 for (i = 0; i < rx_ring->count; i++) {
1136 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
1137 struct sk_buff *skb;
1139 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1144 skb_reserve(skb, NET_IP_ALIGN);
1145 rx_ring->buffer_info[i].skb = skb;
1146 rx_ring->buffer_info[i].dma =
1147 pci_map_single(pdev, skb->data, 2048,
1148 PCI_DMA_FROMDEVICE);
1149 if (pci_dma_mapping_error(pdev, rx_ring->buffer_info[i].dma)) {
1153 rx_desc->buffer_addr =
1154 cpu_to_le64(rx_ring->buffer_info[i].dma);
1155 memset(skb->data, 0x00, skb->len);
1161 e1000_free_desc_rings(adapter);
1165 static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1167 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1168 e1e_wphy(&adapter->hw, 29, 0x001F);
1169 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1170 e1e_wphy(&adapter->hw, 29, 0x001A);
1171 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1174 static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1176 struct e1000_hw *hw = &adapter->hw;
1181 hw->mac.autoneg = 0;
1183 if (hw->phy.type == e1000_phy_m88) {
1184 /* Auto-MDI/MDIX Off */
1185 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1186 /* reset to update Auto-MDI/MDIX */
1187 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1189 e1e_wphy(hw, PHY_CONTROL, 0x8140);
1190 } else if (hw->phy.type == e1000_phy_gg82563)
1191 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
1193 ctrl_reg = er32(CTRL);
1195 switch (hw->phy.type) {
1197 /* force 100, set loopback */
1198 e1e_wphy(hw, PHY_CONTROL, 0x6100);
1200 /* Now set up the MAC to the same speed/duplex as the PHY. */
1201 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1202 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1203 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1204 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1205 E1000_CTRL_FD); /* Force Duplex to FULL */
1208 /* Set Default MAC Interface speed to 1GB */
1209 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1212 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1213 /* Assert SW reset for above settings to take effect */
1214 e1000e_commit_phy(hw);
1216 /* Force Full Duplex */
1217 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1218 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1219 /* Set Link Up (in force link) */
1220 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1221 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1223 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1224 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1225 /* Set Early Link Enable */
1226 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1227 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
1230 /* force 1000, set loopback */
1231 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1234 /* Now set up the MAC to the same speed/duplex as the PHY. */
1235 ctrl_reg = er32(CTRL);
1236 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1237 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1238 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1239 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1240 E1000_CTRL_FD); /* Force Duplex to FULL */
1242 if (adapter->flags & FLAG_IS_ICH)
1243 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1246 if (hw->phy.media_type == e1000_media_type_copper &&
1247 hw->phy.type == e1000_phy_m88) {
1248 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1251 * Set the ILOS bit on the fiber Nic if half duplex link is
1254 stat_reg = er32(STATUS);
1255 if ((stat_reg & E1000_STATUS_FD) == 0)
1256 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1259 ew32(CTRL, ctrl_reg);
1262 * Disable the receiver on the PHY so when a cable is plugged in, the
1263 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1265 if (hw->phy.type == e1000_phy_m88)
1266 e1000_phy_disable_receiver(adapter);
1273 static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1275 struct e1000_hw *hw = &adapter->hw;
1276 u32 ctrl = er32(CTRL);
1279 /* special requirements for 82571/82572 fiber adapters */
1282 * jump through hoops to make sure link is up because serdes
1283 * link is hardwired up
1285 ctrl |= E1000_CTRL_SLU;
1288 /* disable autoneg */
1293 link = (er32(STATUS) & E1000_STATUS_LU);
1296 /* set invert loss of signal */
1298 ctrl |= E1000_CTRL_ILOS;
1303 * special write to serdes control register to enable SerDes analog
1306 #define E1000_SERDES_LB_ON 0x410
1307 ew32(SCTL, E1000_SERDES_LB_ON);
1313 /* only call this for fiber/serdes connections to es2lan */
1314 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1316 struct e1000_hw *hw = &adapter->hw;
1317 u32 ctrlext = er32(CTRL_EXT);
1318 u32 ctrl = er32(CTRL);
1321 * save CTRL_EXT to restore later, reuse an empty variable (unused
1322 * on mac_type 80003es2lan)
1324 adapter->tx_fifo_head = ctrlext;
1326 /* clear the serdes mode bits, putting the device into mac loopback */
1327 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1328 ew32(CTRL_EXT, ctrlext);
1330 /* force speed to 1000/FD, link up */
1331 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1332 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1333 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1336 /* set mac loopback */
1338 ctrl |= E1000_RCTL_LBM_MAC;
1341 /* set testing mode parameters (no need to reset later) */
1342 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
1343 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1345 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
1350 static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1352 struct e1000_hw *hw = &adapter->hw;
1355 if (hw->phy.media_type == e1000_media_type_fiber ||
1356 hw->phy.media_type == e1000_media_type_internal_serdes) {
1357 switch (hw->mac.type) {
1358 case e1000_80003es2lan:
1359 return e1000_set_es2lan_mac_loopback(adapter);
1363 return e1000_set_82571_fiber_loopback(adapter);
1367 rctl |= E1000_RCTL_LBM_TCVR;
1371 } else if (hw->phy.media_type == e1000_media_type_copper) {
1372 return e1000_integrated_phy_loopback(adapter);
1378 static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1380 struct e1000_hw *hw = &adapter->hw;
1385 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1388 switch (hw->mac.type) {
1389 case e1000_80003es2lan:
1390 if (hw->phy.media_type == e1000_media_type_fiber ||
1391 hw->phy.media_type == e1000_media_type_internal_serdes) {
1392 /* restore CTRL_EXT, stealing space from tx_fifo_head */
1393 ew32(CTRL_EXT, adapter->tx_fifo_head);
1394 adapter->tx_fifo_head = 0;
1399 if (hw->phy.media_type == e1000_media_type_fiber ||
1400 hw->phy.media_type == e1000_media_type_internal_serdes) {
1401 #define E1000_SERDES_LB_OFF 0x400
1402 ew32(SCTL, E1000_SERDES_LB_OFF);
1408 hw->mac.autoneg = 1;
1409 if (hw->phy.type == e1000_phy_gg82563)
1410 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1411 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1412 if (phy_reg & MII_CR_LOOPBACK) {
1413 phy_reg &= ~MII_CR_LOOPBACK;
1414 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1415 e1000e_commit_phy(hw);
1421 static void e1000_create_lbtest_frame(struct sk_buff *skb,
1422 unsigned int frame_size)
1424 memset(skb->data, 0xFF, frame_size);
1426 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1427 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1428 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1431 static int e1000_check_lbtest_frame(struct sk_buff *skb,
1432 unsigned int frame_size)
1435 if (*(skb->data + 3) == 0xFF)
1436 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1437 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1442 static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1444 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1445 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1446 struct pci_dev *pdev = adapter->pdev;
1447 struct e1000_hw *hw = &adapter->hw;
1454 ew32(RDT, rx_ring->count - 1);
1457 * Calculate the loop count based on the largest descriptor ring
1458 * The idea is to wrap the largest ring a number of times using 64
1459 * send/receive pairs during each loop
1462 if (rx_ring->count <= tx_ring->count)
1463 lc = ((tx_ring->count / 64) * 2) + 1;
1465 lc = ((rx_ring->count / 64) * 2) + 1;
1469 for (j = 0; j <= lc; j++) { /* loop count loop */
1470 for (i = 0; i < 64; i++) { /* send the packets */
1471 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1473 pci_dma_sync_single_for_device(pdev,
1474 tx_ring->buffer_info[k].dma,
1475 tx_ring->buffer_info[k].length,
1478 if (k == tx_ring->count)
1483 time = jiffies; /* set the start time for the receive */
1485 do { /* receive the sent packets */
1486 pci_dma_sync_single_for_cpu(pdev,
1487 rx_ring->buffer_info[l].dma, 2048,
1488 PCI_DMA_FROMDEVICE);
1490 ret_val = e1000_check_lbtest_frame(
1491 rx_ring->buffer_info[l].skb, 1024);
1495 if (l == rx_ring->count)
1498 * time + 20 msecs (200 msecs on 2.4) is more than
1499 * enough time to complete the receives, if it's
1500 * exceeded, break and error off
1502 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1503 if (good_cnt != 64) {
1504 ret_val = 13; /* ret_val is the same as mis-compare */
1507 if (jiffies >= (time + 20)) {
1508 ret_val = 14; /* error code for time out error */
1511 } /* end loop count loop */
1515 static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1518 * PHY loopback cannot be performed if SoL/IDER
1519 * sessions are active
1521 if (e1000_check_reset_block(&adapter->hw)) {
1522 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
1527 *data = e1000_setup_desc_rings(adapter);
1531 *data = e1000_setup_loopback_test(adapter);
1535 *data = e1000_run_loopback_test(adapter);
1536 e1000_loopback_cleanup(adapter);
1539 e1000_free_desc_rings(adapter);
1544 static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1546 struct e1000_hw *hw = &adapter->hw;
1549 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1551 hw->mac.serdes_has_link = 0;
1554 * On some blade server designs, link establishment
1555 * could take as long as 2-3 minutes
1558 hw->mac.ops.check_for_link(hw);
1559 if (hw->mac.serdes_has_link)
1562 } while (i++ < 3750);
1566 hw->mac.ops.check_for_link(hw);
1567 if (hw->mac.autoneg)
1570 if (!(er32(STATUS) &
1577 static int e1000e_get_sset_count(struct net_device *netdev, int sset)
1581 return E1000_TEST_LEN;
1583 return E1000_STATS_LEN;
1589 static void e1000_diag_test(struct net_device *netdev,
1590 struct ethtool_test *eth_test, u64 *data)
1592 struct e1000_adapter *adapter = netdev_priv(netdev);
1593 u16 autoneg_advertised;
1594 u8 forced_speed_duplex;
1596 bool if_running = netif_running(netdev);
1598 set_bit(__E1000_TESTING, &adapter->state);
1599 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1602 /* save speed, duplex, autoneg settings */
1603 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1604 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1605 autoneg = adapter->hw.mac.autoneg;
1607 e_info("offline testing starting\n");
1610 * Link test performed before hardware reset so autoneg doesn't
1611 * interfere with test result
1613 if (e1000_link_test(adapter, &data[4]))
1614 eth_test->flags |= ETH_TEST_FL_FAILED;
1617 /* indicate we're in test mode */
1620 e1000e_reset(adapter);
1622 if (e1000_reg_test(adapter, &data[0]))
1623 eth_test->flags |= ETH_TEST_FL_FAILED;
1625 e1000e_reset(adapter);
1626 if (e1000_eeprom_test(adapter, &data[1]))
1627 eth_test->flags |= ETH_TEST_FL_FAILED;
1629 e1000e_reset(adapter);
1630 if (e1000_intr_test(adapter, &data[2]))
1631 eth_test->flags |= ETH_TEST_FL_FAILED;
1633 e1000e_reset(adapter);
1634 /* make sure the phy is powered up */
1635 e1000e_power_up_phy(adapter);
1636 if (e1000_loopback_test(adapter, &data[3]))
1637 eth_test->flags |= ETH_TEST_FL_FAILED;
1639 /* restore speed, duplex, autoneg settings */
1640 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1641 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1642 adapter->hw.mac.autoneg = autoneg;
1644 /* force this routine to wait until autoneg complete/timeout */
1645 adapter->hw.phy.autoneg_wait_to_complete = 1;
1646 e1000e_reset(adapter);
1647 adapter->hw.phy.autoneg_wait_to_complete = 0;
1649 clear_bit(__E1000_TESTING, &adapter->state);
1653 e_info("online testing starting\n");
1655 if (e1000_link_test(adapter, &data[4]))
1656 eth_test->flags |= ETH_TEST_FL_FAILED;
1658 /* Online tests aren't run; pass by default */
1664 clear_bit(__E1000_TESTING, &adapter->state);
1666 msleep_interruptible(4 * 1000);
1669 static void e1000_get_wol(struct net_device *netdev,
1670 struct ethtool_wolinfo *wol)
1672 struct e1000_adapter *adapter = netdev_priv(netdev);
1677 if (!(adapter->flags & FLAG_HAS_WOL))
1680 wol->supported = WAKE_UCAST | WAKE_MCAST |
1681 WAKE_BCAST | WAKE_MAGIC |
1682 WAKE_PHY | WAKE_ARP;
1684 /* apply any specific unsupported masks here */
1685 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1686 wol->supported &= ~WAKE_UCAST;
1688 if (adapter->wol & E1000_WUFC_EX)
1689 e_err("Interface does not support directed (unicast) "
1690 "frame wake-up packets\n");
1693 if (adapter->wol & E1000_WUFC_EX)
1694 wol->wolopts |= WAKE_UCAST;
1695 if (adapter->wol & E1000_WUFC_MC)
1696 wol->wolopts |= WAKE_MCAST;
1697 if (adapter->wol & E1000_WUFC_BC)
1698 wol->wolopts |= WAKE_BCAST;
1699 if (adapter->wol & E1000_WUFC_MAG)
1700 wol->wolopts |= WAKE_MAGIC;
1701 if (adapter->wol & E1000_WUFC_LNKC)
1702 wol->wolopts |= WAKE_PHY;
1703 if (adapter->wol & E1000_WUFC_ARP)
1704 wol->wolopts |= WAKE_ARP;
1707 static int e1000_set_wol(struct net_device *netdev,
1708 struct ethtool_wolinfo *wol)
1710 struct e1000_adapter *adapter = netdev_priv(netdev);
1712 if (wol->wolopts & WAKE_MAGICSECURE)
1715 if (!(adapter->flags & FLAG_HAS_WOL))
1716 return wol->wolopts ? -EOPNOTSUPP : 0;
1718 /* these settings will always override what we currently have */
1721 if (wol->wolopts & WAKE_UCAST)
1722 adapter->wol |= E1000_WUFC_EX;
1723 if (wol->wolopts & WAKE_MCAST)
1724 adapter->wol |= E1000_WUFC_MC;
1725 if (wol->wolopts & WAKE_BCAST)
1726 adapter->wol |= E1000_WUFC_BC;
1727 if (wol->wolopts & WAKE_MAGIC)
1728 adapter->wol |= E1000_WUFC_MAG;
1729 if (wol->wolopts & WAKE_PHY)
1730 adapter->wol |= E1000_WUFC_LNKC;
1731 if (wol->wolopts & WAKE_ARP)
1732 adapter->wol |= E1000_WUFC_ARP;
1737 /* toggle LED 4 times per second = 2 "blinks" per second */
1738 #define E1000_ID_INTERVAL (HZ/4)
1740 /* bit defines for adapter->led_status */
1741 #define E1000_LED_ON 0
1743 static void e1000_led_blink_callback(unsigned long data)
1745 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1747 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1748 adapter->hw.mac.ops.led_off(&adapter->hw);
1750 adapter->hw.mac.ops.led_on(&adapter->hw);
1752 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1755 static int e1000_phys_id(struct net_device *netdev, u32 data)
1757 struct e1000_adapter *adapter = netdev_priv(netdev);
1762 if (adapter->hw.phy.type == e1000_phy_ife) {
1763 if (!adapter->blink_timer.function) {
1764 init_timer(&adapter->blink_timer);
1765 adapter->blink_timer.function =
1766 e1000_led_blink_callback;
1767 adapter->blink_timer.data = (unsigned long) adapter;
1769 mod_timer(&adapter->blink_timer, jiffies);
1770 msleep_interruptible(data * 1000);
1771 del_timer_sync(&adapter->blink_timer);
1772 e1e_wphy(&adapter->hw,
1773 IFE_PHY_SPECIAL_CONTROL_LED, 0);
1775 e1000e_blink_led(&adapter->hw);
1776 msleep_interruptible(data * 1000);
1779 adapter->hw.mac.ops.led_off(&adapter->hw);
1780 clear_bit(E1000_LED_ON, &adapter->led_status);
1781 adapter->hw.mac.ops.cleanup_led(&adapter->hw);
1786 static int e1000_get_coalesce(struct net_device *netdev,
1787 struct ethtool_coalesce *ec)
1789 struct e1000_adapter *adapter = netdev_priv(netdev);
1791 if (adapter->itr_setting <= 3)
1792 ec->rx_coalesce_usecs = adapter->itr_setting;
1794 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1799 static int e1000_set_coalesce(struct net_device *netdev,
1800 struct ethtool_coalesce *ec)
1802 struct e1000_adapter *adapter = netdev_priv(netdev);
1803 struct e1000_hw *hw = &adapter->hw;
1805 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
1806 ((ec->rx_coalesce_usecs > 3) &&
1807 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1808 (ec->rx_coalesce_usecs == 2))
1811 if (ec->rx_coalesce_usecs <= 3) {
1812 adapter->itr = 20000;
1813 adapter->itr_setting = ec->rx_coalesce_usecs;
1815 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1816 adapter->itr_setting = adapter->itr & ~3;
1819 if (adapter->itr_setting != 0)
1820 ew32(ITR, 1000000000 / (adapter->itr * 256));
1827 static int e1000_nway_reset(struct net_device *netdev)
1829 struct e1000_adapter *adapter = netdev_priv(netdev);
1830 if (netif_running(netdev))
1831 e1000e_reinit_locked(adapter);
1835 static void e1000_get_ethtool_stats(struct net_device *netdev,
1836 struct ethtool_stats *stats,
1839 struct e1000_adapter *adapter = netdev_priv(netdev);
1842 e1000e_update_stats(adapter);
1843 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1844 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1845 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1846 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1850 static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1856 switch (stringset) {
1858 memcpy(data, *e1000_gstrings_test, sizeof(e1000_gstrings_test));
1861 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1862 memcpy(p, e1000_gstrings_stats[i].stat_string,
1864 p += ETH_GSTRING_LEN;
1870 static const struct ethtool_ops e1000_ethtool_ops = {
1871 .get_settings = e1000_get_settings,
1872 .set_settings = e1000_set_settings,
1873 .get_drvinfo = e1000_get_drvinfo,
1874 .get_regs_len = e1000_get_regs_len,
1875 .get_regs = e1000_get_regs,
1876 .get_wol = e1000_get_wol,
1877 .set_wol = e1000_set_wol,
1878 .get_msglevel = e1000_get_msglevel,
1879 .set_msglevel = e1000_set_msglevel,
1880 .nway_reset = e1000_nway_reset,
1881 .get_link = e1000_get_link,
1882 .get_eeprom_len = e1000_get_eeprom_len,
1883 .get_eeprom = e1000_get_eeprom,
1884 .set_eeprom = e1000_set_eeprom,
1885 .get_ringparam = e1000_get_ringparam,
1886 .set_ringparam = e1000_set_ringparam,
1887 .get_pauseparam = e1000_get_pauseparam,
1888 .set_pauseparam = e1000_set_pauseparam,
1889 .get_rx_csum = e1000_get_rx_csum,
1890 .set_rx_csum = e1000_set_rx_csum,
1891 .get_tx_csum = e1000_get_tx_csum,
1892 .set_tx_csum = e1000_set_tx_csum,
1893 .get_sg = ethtool_op_get_sg,
1894 .set_sg = ethtool_op_set_sg,
1895 .get_tso = ethtool_op_get_tso,
1896 .set_tso = e1000_set_tso,
1897 .self_test = e1000_diag_test,
1898 .get_strings = e1000_get_strings,
1899 .phys_id = e1000_phys_id,
1900 .get_ethtool_stats = e1000_get_ethtool_stats,
1901 .get_sset_count = e1000e_get_sset_count,
1902 .get_coalesce = e1000_get_coalesce,
1903 .set_coalesce = e1000_set_coalesce,
1906 void e1000e_set_ethtool_ops(struct net_device *netdev)
1908 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);