1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 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 */
33 #include <asm/uaccess.h>
35 extern int e1000_up(struct e1000_adapter *adapter);
36 extern void e1000_down(struct e1000_adapter *adapter);
37 extern void e1000_reinit_locked(struct e1000_adapter *adapter);
38 extern void e1000_reset(struct e1000_adapter *adapter);
39 extern int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx);
40 extern int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
41 extern int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
42 extern void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
43 extern void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
44 extern void e1000_update_stats(struct e1000_adapter *adapter);
48 char stat_string[ETH_GSTRING_LEN];
53 #define E1000_STAT(m) FIELD_SIZEOF(struct e1000_adapter, m), \
54 offsetof(struct e1000_adapter, m)
55 static const struct e1000_stats e1000_gstrings_stats[] = {
56 { "rx_packets", E1000_STAT(stats.gprc) },
57 { "tx_packets", E1000_STAT(stats.gptc) },
58 { "rx_bytes", E1000_STAT(stats.gorcl) },
59 { "tx_bytes", E1000_STAT(stats.gotcl) },
60 { "rx_broadcast", E1000_STAT(stats.bprc) },
61 { "tx_broadcast", E1000_STAT(stats.bptc) },
62 { "rx_multicast", E1000_STAT(stats.mprc) },
63 { "tx_multicast", E1000_STAT(stats.mptc) },
64 { "rx_errors", E1000_STAT(stats.rxerrc) },
65 { "tx_errors", E1000_STAT(stats.txerrc) },
66 { "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
67 { "multicast", E1000_STAT(stats.mprc) },
68 { "collisions", E1000_STAT(stats.colc) },
69 { "rx_length_errors", E1000_STAT(stats.rlerrc) },
70 { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
71 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
72 { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
73 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
74 { "rx_missed_errors", E1000_STAT(stats.mpc) },
75 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
76 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
77 { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) },
78 { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) },
79 { "tx_window_errors", E1000_STAT(stats.latecol) },
80 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
81 { "tx_deferred_ok", E1000_STAT(stats.dc) },
82 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
83 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
84 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
85 { "tx_restart_queue", E1000_STAT(restart_queue) },
86 { "rx_long_length_errors", E1000_STAT(stats.roc) },
87 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
88 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
89 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
90 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
91 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
92 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
93 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
94 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
95 { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
96 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
97 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
98 { "rx_header_split", E1000_STAT(rx_hdr_split) },
99 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
100 { "tx_smbus", E1000_STAT(stats.mgptc) },
101 { "rx_smbus", E1000_STAT(stats.mgprc) },
102 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
105 #define E1000_QUEUE_STATS_LEN 0
106 #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
107 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
108 static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
109 "Register test (offline)", "Eeprom test (offline)",
110 "Interrupt test (offline)", "Loopback test (offline)",
111 "Link test (on/offline)"
113 #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
115 static int e1000_get_settings(struct net_device *netdev,
116 struct ethtool_cmd *ecmd)
118 struct e1000_adapter *adapter = netdev_priv(netdev);
119 struct e1000_hw *hw = &adapter->hw;
121 if (hw->media_type == e1000_media_type_copper) {
123 ecmd->supported = (SUPPORTED_10baseT_Half |
124 SUPPORTED_10baseT_Full |
125 SUPPORTED_100baseT_Half |
126 SUPPORTED_100baseT_Full |
127 SUPPORTED_1000baseT_Full|
130 if (hw->phy_type == e1000_phy_ife)
131 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
132 ecmd->advertising = ADVERTISED_TP;
134 if (hw->autoneg == 1) {
135 ecmd->advertising |= ADVERTISED_Autoneg;
136 /* the e1000 autoneg seems to match ethtool nicely */
137 ecmd->advertising |= hw->autoneg_advertised;
140 ecmd->port = PORT_TP;
141 ecmd->phy_address = hw->phy_addr;
143 if (hw->mac_type == e1000_82543)
144 ecmd->transceiver = XCVR_EXTERNAL;
146 ecmd->transceiver = XCVR_INTERNAL;
149 ecmd->supported = (SUPPORTED_1000baseT_Full |
153 ecmd->advertising = (ADVERTISED_1000baseT_Full |
157 ecmd->port = PORT_FIBRE;
159 if (hw->mac_type >= e1000_82545)
160 ecmd->transceiver = XCVR_INTERNAL;
162 ecmd->transceiver = XCVR_EXTERNAL;
165 if (er32(STATUS) & E1000_STATUS_LU) {
167 e1000_get_speed_and_duplex(hw, &adapter->link_speed,
168 &adapter->link_duplex);
169 ecmd->speed = adapter->link_speed;
171 /* unfortunatly FULL_DUPLEX != DUPLEX_FULL
172 * and HALF_DUPLEX != DUPLEX_HALF */
174 if (adapter->link_duplex == FULL_DUPLEX)
175 ecmd->duplex = DUPLEX_FULL;
177 ecmd->duplex = DUPLEX_HALF;
183 ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
184 hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
188 static int e1000_set_settings(struct net_device *netdev,
189 struct ethtool_cmd *ecmd)
191 struct e1000_adapter *adapter = netdev_priv(netdev);
192 struct e1000_hw *hw = &adapter->hw;
194 /* When SoL/IDER sessions are active, autoneg/speed/duplex
195 * cannot be changed */
196 if (e1000_check_phy_reset_block(hw)) {
197 DPRINTK(DRV, ERR, "Cannot change link characteristics "
198 "when SoL/IDER is active.\n");
202 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
205 if (ecmd->autoneg == AUTONEG_ENABLE) {
207 if (hw->media_type == e1000_media_type_fiber)
208 hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
212 hw->autoneg_advertised = ecmd->advertising |
215 ecmd->advertising = hw->autoneg_advertised;
217 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
218 clear_bit(__E1000_RESETTING, &adapter->flags);
224 if (netif_running(adapter->netdev)) {
228 e1000_reset(adapter);
230 clear_bit(__E1000_RESETTING, &adapter->flags);
234 static void e1000_get_pauseparam(struct net_device *netdev,
235 struct ethtool_pauseparam *pause)
237 struct e1000_adapter *adapter = netdev_priv(netdev);
238 struct e1000_hw *hw = &adapter->hw;
241 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
243 if (hw->fc == E1000_FC_RX_PAUSE)
245 else if (hw->fc == E1000_FC_TX_PAUSE)
247 else if (hw->fc == E1000_FC_FULL) {
253 static int e1000_set_pauseparam(struct net_device *netdev,
254 struct ethtool_pauseparam *pause)
256 struct e1000_adapter *adapter = netdev_priv(netdev);
257 struct e1000_hw *hw = &adapter->hw;
260 adapter->fc_autoneg = pause->autoneg;
262 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
265 if (pause->rx_pause && pause->tx_pause)
266 hw->fc = E1000_FC_FULL;
267 else if (pause->rx_pause && !pause->tx_pause)
268 hw->fc = E1000_FC_RX_PAUSE;
269 else if (!pause->rx_pause && pause->tx_pause)
270 hw->fc = E1000_FC_TX_PAUSE;
271 else if (!pause->rx_pause && !pause->tx_pause)
272 hw->fc = E1000_FC_NONE;
274 hw->original_fc = hw->fc;
276 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
277 if (netif_running(adapter->netdev)) {
281 e1000_reset(adapter);
283 retval = ((hw->media_type == e1000_media_type_fiber) ?
284 e1000_setup_link(hw) : e1000_force_mac_fc(hw));
286 clear_bit(__E1000_RESETTING, &adapter->flags);
290 static u32 e1000_get_rx_csum(struct net_device *netdev)
292 struct e1000_adapter *adapter = netdev_priv(netdev);
293 return adapter->rx_csum;
296 static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
298 struct e1000_adapter *adapter = netdev_priv(netdev);
299 adapter->rx_csum = data;
301 if (netif_running(netdev))
302 e1000_reinit_locked(adapter);
304 e1000_reset(adapter);
308 static u32 e1000_get_tx_csum(struct net_device *netdev)
310 return (netdev->features & NETIF_F_HW_CSUM) != 0;
313 static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
315 struct e1000_adapter *adapter = netdev_priv(netdev);
316 struct e1000_hw *hw = &adapter->hw;
318 if (hw->mac_type < e1000_82543) {
325 netdev->features |= NETIF_F_HW_CSUM;
327 netdev->features &= ~NETIF_F_HW_CSUM;
332 static int e1000_set_tso(struct net_device *netdev, u32 data)
334 struct e1000_adapter *adapter = netdev_priv(netdev);
335 struct e1000_hw *hw = &adapter->hw;
337 if ((hw->mac_type < e1000_82544) ||
338 (hw->mac_type == e1000_82547))
339 return data ? -EINVAL : 0;
342 netdev->features |= NETIF_F_TSO;
344 netdev->features &= ~NETIF_F_TSO;
346 if (data && (adapter->hw.mac_type > e1000_82547_rev_2))
347 netdev->features |= NETIF_F_TSO6;
349 netdev->features &= ~NETIF_F_TSO6;
351 DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
352 adapter->tso_force = true;
356 static u32 e1000_get_msglevel(struct net_device *netdev)
358 struct e1000_adapter *adapter = netdev_priv(netdev);
359 return adapter->msg_enable;
362 static void e1000_set_msglevel(struct net_device *netdev, u32 data)
364 struct e1000_adapter *adapter = netdev_priv(netdev);
365 adapter->msg_enable = data;
368 static int e1000_get_regs_len(struct net_device *netdev)
370 #define E1000_REGS_LEN 32
371 return E1000_REGS_LEN * sizeof(u32);
374 static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
377 struct e1000_adapter *adapter = netdev_priv(netdev);
378 struct e1000_hw *hw = &adapter->hw;
382 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
384 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
386 regs_buff[0] = er32(CTRL);
387 regs_buff[1] = er32(STATUS);
389 regs_buff[2] = er32(RCTL);
390 regs_buff[3] = er32(RDLEN);
391 regs_buff[4] = er32(RDH);
392 regs_buff[5] = er32(RDT);
393 regs_buff[6] = er32(RDTR);
395 regs_buff[7] = er32(TCTL);
396 regs_buff[8] = er32(TDLEN);
397 regs_buff[9] = er32(TDH);
398 regs_buff[10] = er32(TDT);
399 regs_buff[11] = er32(TIDV);
401 regs_buff[12] = hw->phy_type; /* PHY type (IGP=1, M88=0) */
402 if (hw->phy_type == e1000_phy_igp) {
403 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
404 IGP01E1000_PHY_AGC_A);
405 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
406 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
407 regs_buff[13] = (u32)phy_data; /* cable length */
408 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
409 IGP01E1000_PHY_AGC_B);
410 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
411 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
412 regs_buff[14] = (u32)phy_data; /* cable length */
413 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
414 IGP01E1000_PHY_AGC_C);
415 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
416 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
417 regs_buff[15] = (u32)phy_data; /* cable length */
418 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
419 IGP01E1000_PHY_AGC_D);
420 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
421 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
422 regs_buff[16] = (u32)phy_data; /* cable length */
423 regs_buff[17] = 0; /* extended 10bt distance (not needed) */
424 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
425 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
426 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
427 regs_buff[18] = (u32)phy_data; /* cable polarity */
428 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
429 IGP01E1000_PHY_PCS_INIT_REG);
430 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
431 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
432 regs_buff[19] = (u32)phy_data; /* cable polarity */
433 regs_buff[20] = 0; /* polarity correction enabled (always) */
434 regs_buff[22] = 0; /* phy receive errors (unavailable) */
435 regs_buff[23] = regs_buff[18]; /* mdix mode */
436 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
438 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
439 regs_buff[13] = (u32)phy_data; /* cable length */
440 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
441 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
442 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
443 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
444 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
445 regs_buff[18] = regs_buff[13]; /* cable polarity */
446 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
447 regs_buff[20] = regs_buff[17]; /* polarity correction */
448 /* phy receive errors */
449 regs_buff[22] = adapter->phy_stats.receive_errors;
450 regs_buff[23] = regs_buff[13]; /* mdix mode */
452 regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
453 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
454 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
455 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
456 if (hw->mac_type >= e1000_82540 &&
457 hw->mac_type < e1000_82571 &&
458 hw->media_type == e1000_media_type_copper) {
459 regs_buff[26] = er32(MANC);
463 static int e1000_get_eeprom_len(struct net_device *netdev)
465 struct e1000_adapter *adapter = netdev_priv(netdev);
466 struct e1000_hw *hw = &adapter->hw;
468 return hw->eeprom.word_size * 2;
471 static int e1000_get_eeprom(struct net_device *netdev,
472 struct ethtool_eeprom *eeprom, u8 *bytes)
474 struct e1000_adapter *adapter = netdev_priv(netdev);
475 struct e1000_hw *hw = &adapter->hw;
477 int first_word, last_word;
481 if (eeprom->len == 0)
484 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
486 first_word = eeprom->offset >> 1;
487 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
489 eeprom_buff = kmalloc(sizeof(u16) *
490 (last_word - first_word + 1), GFP_KERNEL);
494 if (hw->eeprom.type == e1000_eeprom_spi)
495 ret_val = e1000_read_eeprom(hw, first_word,
496 last_word - first_word + 1,
499 for (i = 0; i < last_word - first_word + 1; i++)
500 if ((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
505 /* Device's eeprom is always little-endian, word addressable */
506 for (i = 0; i < last_word - first_word + 1; i++)
507 le16_to_cpus(&eeprom_buff[i]);
509 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
516 static int e1000_set_eeprom(struct net_device *netdev,
517 struct ethtool_eeprom *eeprom, u8 *bytes)
519 struct e1000_adapter *adapter = netdev_priv(netdev);
520 struct e1000_hw *hw = &adapter->hw;
523 int max_len, first_word, last_word, ret_val = 0;
526 if (eeprom->len == 0)
529 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
532 max_len = hw->eeprom.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_eeprom(hw, first_word, 1,
549 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
550 /* need read/modify/write of last changed EEPROM word */
551 /* only the first byte of the word is being modified */
552 ret_val = e1000_read_eeprom(hw, last_word, 1,
553 &eeprom_buff[last_word - first_word]);
556 /* Device's eeprom is always little-endian, word addressable */
557 for (i = 0; i < last_word - first_word + 1; i++)
558 le16_to_cpus(&eeprom_buff[i]);
560 memcpy(ptr, bytes, eeprom->len);
562 for (i = 0; i < last_word - first_word + 1; i++)
563 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
565 ret_val = e1000_write_eeprom(hw, first_word,
566 last_word - first_word + 1, eeprom_buff);
568 /* Update the checksum over the first part of the EEPROM if needed
569 * and flush shadow RAM for 82573 conrollers */
570 if ((ret_val == 0) && ((first_word <= EEPROM_CHECKSUM_REG) ||
571 (hw->mac_type == e1000_82573)))
572 e1000_update_eeprom_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 struct e1000_hw *hw = &adapter->hw;
583 char firmware_version[32];
586 strncpy(drvinfo->driver, e1000_driver_name, 32);
587 strncpy(drvinfo->version, e1000_driver_version, 32);
589 /* EEPROM image version # is reported as firmware version # for
590 * 8257{1|2|3} controllers */
591 e1000_read_eeprom(hw, 5, 1, &eeprom_data);
592 switch (hw->mac_type) {
596 case e1000_80003es2lan:
598 sprintf(firmware_version, "%d.%d-%d",
599 (eeprom_data & 0xF000) >> 12,
600 (eeprom_data & 0x0FF0) >> 4,
601 eeprom_data & 0x000F);
604 sprintf(firmware_version, "N/A");
607 strncpy(drvinfo->fw_version, firmware_version, 32);
608 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
609 drvinfo->regdump_len = e1000_get_regs_len(netdev);
610 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
613 static void e1000_get_ringparam(struct net_device *netdev,
614 struct ethtool_ringparam *ring)
616 struct e1000_adapter *adapter = netdev_priv(netdev);
617 struct e1000_hw *hw = &adapter->hw;
618 e1000_mac_type mac_type = hw->mac_type;
619 struct e1000_tx_ring *txdr = adapter->tx_ring;
620 struct e1000_rx_ring *rxdr = adapter->rx_ring;
622 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
624 ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
626 ring->rx_mini_max_pending = 0;
627 ring->rx_jumbo_max_pending = 0;
628 ring->rx_pending = rxdr->count;
629 ring->tx_pending = txdr->count;
630 ring->rx_mini_pending = 0;
631 ring->rx_jumbo_pending = 0;
634 static int e1000_set_ringparam(struct net_device *netdev,
635 struct ethtool_ringparam *ring)
637 struct e1000_adapter *adapter = netdev_priv(netdev);
638 struct e1000_hw *hw = &adapter->hw;
639 e1000_mac_type mac_type = hw->mac_type;
640 struct e1000_tx_ring *txdr, *tx_old;
641 struct e1000_rx_ring *rxdr, *rx_old;
644 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
647 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
650 if (netif_running(adapter->netdev))
653 tx_old = adapter->tx_ring;
654 rx_old = adapter->rx_ring;
657 txdr = kcalloc(adapter->num_tx_queues, sizeof(struct e1000_tx_ring), GFP_KERNEL);
661 rxdr = kcalloc(adapter->num_rx_queues, sizeof(struct e1000_rx_ring), GFP_KERNEL);
665 adapter->tx_ring = txdr;
666 adapter->rx_ring = rxdr;
668 rxdr->count = max(ring->rx_pending,(u32)E1000_MIN_RXD);
669 rxdr->count = min(rxdr->count,(u32)(mac_type < e1000_82544 ?
670 E1000_MAX_RXD : E1000_MAX_82544_RXD));
671 rxdr->count = ALIGN(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
673 txdr->count = max(ring->tx_pending,(u32)E1000_MIN_TXD);
674 txdr->count = min(txdr->count,(u32)(mac_type < e1000_82544 ?
675 E1000_MAX_TXD : E1000_MAX_82544_TXD));
676 txdr->count = ALIGN(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
678 for (i = 0; i < adapter->num_tx_queues; i++)
679 txdr[i].count = txdr->count;
680 for (i = 0; i < adapter->num_rx_queues; i++)
681 rxdr[i].count = rxdr->count;
683 if (netif_running(adapter->netdev)) {
684 /* Try to get new resources before deleting old */
685 if ((err = e1000_setup_all_rx_resources(adapter)))
687 if ((err = e1000_setup_all_tx_resources(adapter)))
690 /* save the new, restore the old in order to free it,
691 * then restore the new back again */
693 adapter->rx_ring = rx_old;
694 adapter->tx_ring = tx_old;
695 e1000_free_all_rx_resources(adapter);
696 e1000_free_all_tx_resources(adapter);
699 adapter->rx_ring = rxdr;
700 adapter->tx_ring = txdr;
701 if ((err = e1000_up(adapter)))
705 clear_bit(__E1000_RESETTING, &adapter->flags);
708 e1000_free_all_rx_resources(adapter);
710 adapter->rx_ring = rx_old;
711 adapter->tx_ring = tx_old;
718 clear_bit(__E1000_RESETTING, &adapter->flags);
722 static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data, int reg,
725 struct e1000_hw *hw = &adapter->hw;
726 static const u32 test[] =
727 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
728 u8 __iomem *address = hw->hw_addr + reg;
732 for (i = 0; i < ARRAY_SIZE(test); i++) {
733 writel(write & test[i], address);
734 read = readl(address);
735 if (read != (write & test[i] & mask)) {
736 DPRINTK(DRV, ERR, "pattern test reg %04X failed: "
737 "got 0x%08X expected 0x%08X\n",
738 reg, read, (write & test[i] & mask));
746 static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data, int reg,
749 struct e1000_hw *hw = &adapter->hw;
750 u8 __iomem *address = hw->hw_addr + reg;
753 writel(write & mask, address);
754 read = readl(address);
755 if ((read & mask) != (write & mask)) {
756 DPRINTK(DRV, ERR, "set/check reg %04X test failed: "
757 "got 0x%08X expected 0x%08X\n",
758 reg, (read & mask), (write & mask));
765 #define REG_PATTERN_TEST(reg, mask, write) \
767 if (reg_pattern_test(adapter, data, \
768 (hw->mac_type >= e1000_82543) \
769 ? E1000_##reg : E1000_82542_##reg, \
774 #define REG_SET_AND_CHECK(reg, mask, write) \
776 if (reg_set_and_check(adapter, data, \
777 (hw->mac_type >= e1000_82543) \
778 ? E1000_##reg : E1000_82542_##reg, \
783 static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
785 u32 value, before, after;
787 struct e1000_hw *hw = &adapter->hw;
789 /* The status register is Read Only, so a write should fail.
790 * Some bits that get toggled are ignored.
792 switch (hw->mac_type) {
793 /* there are several bits on newer hardware that are r/w */
796 case e1000_80003es2lan:
808 before = er32(STATUS);
809 value = (er32(STATUS) & toggle);
810 ew32(STATUS, toggle);
811 after = er32(STATUS) & toggle;
812 if (value != after) {
813 DPRINTK(DRV, ERR, "failed STATUS register test got: "
814 "0x%08X expected: 0x%08X\n", after, value);
818 /* restore previous status */
819 ew32(STATUS, before);
821 if (hw->mac_type != e1000_ich8lan) {
822 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
823 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
824 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
825 REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
828 REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
829 REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
830 REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
831 REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
832 REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
833 REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
834 REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
835 REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
836 REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
837 REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
839 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
841 before = (hw->mac_type == e1000_ich8lan ?
842 0x06C3B33E : 0x06DFB3FE);
843 REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
844 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
846 if (hw->mac_type >= e1000_82543) {
848 REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
849 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
850 if (hw->mac_type != e1000_ich8lan)
851 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
852 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
853 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
854 value = (hw->mac_type == e1000_ich8lan ?
855 E1000_RAR_ENTRIES_ICH8LAN : E1000_RAR_ENTRIES);
856 for (i = 0; i < value; i++) {
857 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
863 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
864 REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
865 REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
866 REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
870 value = (hw->mac_type == e1000_ich8lan ?
871 E1000_MC_TBL_SIZE_ICH8LAN : E1000_MC_TBL_SIZE);
872 for (i = 0; i < value; i++)
873 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
879 static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
881 struct e1000_hw *hw = &adapter->hw;
887 /* Read and add up the contents of the EEPROM */
888 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
889 if ((e1000_read_eeprom(hw, i, 1, &temp)) < 0) {
896 /* If Checksum is not Correct return error else test passed */
897 if ((checksum != (u16) EEPROM_SUM) && !(*data))
903 static irqreturn_t e1000_test_intr(int irq, void *data)
905 struct net_device *netdev = (struct net_device *) data;
906 struct e1000_adapter *adapter = netdev_priv(netdev);
907 struct e1000_hw *hw = &adapter->hw;
909 adapter->test_icr |= er32(ICR);
914 static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
916 struct net_device *netdev = adapter->netdev;
918 bool shared_int = true;
919 u32 irq = adapter->pdev->irq;
920 struct e1000_hw *hw = &adapter->hw;
924 /* NOTE: we don't test MSI interrupts here, yet */
925 /* Hook up test interrupt handler just for this test */
926 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
929 else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
930 netdev->name, netdev)) {
934 DPRINTK(HW, INFO, "testing %s interrupt\n",
935 (shared_int ? "shared" : "unshared"));
937 /* Disable all the interrupts */
938 ew32(IMC, 0xFFFFFFFF);
941 /* Test each interrupt */
942 for (; i < 10; i++) {
944 if (hw->mac_type == e1000_ich8lan && i == 8)
947 /* Interrupt to test */
951 /* Disable 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 posted to the bus, the
957 adapter->test_icr = 0;
962 if (adapter->test_icr & mask) {
968 /* Enable the interrupt to be reported in
969 * the cause register and then force the same
970 * interrupt and see if one gets posted. If
971 * an interrupt was not posted to the bus, the
974 adapter->test_icr = 0;
979 if (!(adapter->test_icr & mask)) {
985 /* Disable the other interrupts to be reported in
986 * the cause register and then force the other
987 * interrupts and see if any get posted. If
988 * an interrupt was posted to the bus, the
991 adapter->test_icr = 0;
992 ew32(IMC, ~mask & 0x00007FFF);
993 ew32(ICS, ~mask & 0x00007FFF);
996 if (adapter->test_icr) {
1003 /* Disable all the interrupts */
1004 ew32(IMC, 0xFFFFFFFF);
1007 /* Unhook test interrupt handler */
1008 free_irq(irq, netdev);
1013 static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1015 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1016 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1017 struct pci_dev *pdev = adapter->pdev;
1020 if (txdr->desc && txdr->buffer_info) {
1021 for (i = 0; i < txdr->count; i++) {
1022 if (txdr->buffer_info[i].dma)
1023 pci_unmap_single(pdev, txdr->buffer_info[i].dma,
1024 txdr->buffer_info[i].length,
1026 if (txdr->buffer_info[i].skb)
1027 dev_kfree_skb(txdr->buffer_info[i].skb);
1031 if (rxdr->desc && rxdr->buffer_info) {
1032 for (i = 0; i < rxdr->count; i++) {
1033 if (rxdr->buffer_info[i].dma)
1034 pci_unmap_single(pdev, rxdr->buffer_info[i].dma,
1035 rxdr->buffer_info[i].length,
1036 PCI_DMA_FROMDEVICE);
1037 if (rxdr->buffer_info[i].skb)
1038 dev_kfree_skb(rxdr->buffer_info[i].skb);
1043 pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
1047 pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
1051 kfree(txdr->buffer_info);
1052 txdr->buffer_info = NULL;
1053 kfree(rxdr->buffer_info);
1054 rxdr->buffer_info = NULL;
1059 static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1061 struct e1000_hw *hw = &adapter->hw;
1062 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1063 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1064 struct pci_dev *pdev = adapter->pdev;
1068 /* Setup Tx descriptor ring and Tx buffers */
1071 txdr->count = E1000_DEFAULT_TXD;
1073 if (!(txdr->buffer_info = kcalloc(txdr->count,
1074 sizeof(struct e1000_buffer),
1080 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1081 txdr->size = ALIGN(txdr->size, 4096);
1082 if (!(txdr->desc = pci_alloc_consistent(pdev, txdr->size,
1087 memset(txdr->desc, 0, txdr->size);
1088 txdr->next_to_use = txdr->next_to_clean = 0;
1090 ew32(TDBAL, ((u64) txdr->dma & 0x00000000FFFFFFFF));
1091 ew32(TDBAH, ((u64) txdr->dma >> 32));
1092 ew32(TDLEN, txdr->count * sizeof(struct e1000_tx_desc));
1095 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN |
1096 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1097 E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1099 for (i = 0; i < txdr->count; i++) {
1100 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
1101 struct sk_buff *skb;
1102 unsigned int size = 1024;
1104 if (!(skb = alloc_skb(size, GFP_KERNEL))) {
1109 txdr->buffer_info[i].skb = skb;
1110 txdr->buffer_info[i].length = skb->len;
1111 txdr->buffer_info[i].dma =
1112 pci_map_single(pdev, skb->data, skb->len,
1114 tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
1115 tx_desc->lower.data = cpu_to_le32(skb->len);
1116 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1117 E1000_TXD_CMD_IFCS |
1119 tx_desc->upper.data = 0;
1122 /* Setup Rx descriptor ring and Rx buffers */
1125 rxdr->count = E1000_DEFAULT_RXD;
1127 if (!(rxdr->buffer_info = kcalloc(rxdr->count,
1128 sizeof(struct e1000_buffer),
1134 rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
1135 if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) {
1139 memset(rxdr->desc, 0, rxdr->size);
1140 rxdr->next_to_use = rxdr->next_to_clean = 0;
1143 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1144 ew32(RDBAL, ((u64) rxdr->dma & 0xFFFFFFFF));
1145 ew32(RDBAH, ((u64) rxdr->dma >> 32));
1146 ew32(RDLEN, rxdr->size);
1149 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1150 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1151 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1154 for (i = 0; i < rxdr->count; i++) {
1155 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
1156 struct sk_buff *skb;
1158 if (!(skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN,
1163 skb_reserve(skb, NET_IP_ALIGN);
1164 rxdr->buffer_info[i].skb = skb;
1165 rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
1166 rxdr->buffer_info[i].dma =
1167 pci_map_single(pdev, skb->data, E1000_RXBUFFER_2048,
1168 PCI_DMA_FROMDEVICE);
1169 rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
1170 memset(skb->data, 0x00, skb->len);
1176 e1000_free_desc_rings(adapter);
1180 static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1182 struct e1000_hw *hw = &adapter->hw;
1184 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1185 e1000_write_phy_reg(hw, 29, 0x001F);
1186 e1000_write_phy_reg(hw, 30, 0x8FFC);
1187 e1000_write_phy_reg(hw, 29, 0x001A);
1188 e1000_write_phy_reg(hw, 30, 0x8FF0);
1191 static void e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
1193 struct e1000_hw *hw = &adapter->hw;
1196 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1197 * Extended PHY Specific Control Register to 25MHz clock. This
1198 * value defaults back to a 2.5MHz clock when the PHY is reset.
1200 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
1201 phy_reg |= M88E1000_EPSCR_TX_CLK_25;
1202 e1000_write_phy_reg(hw,
1203 M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
1205 /* In addition, because of the s/w reset above, we need to enable
1206 * CRS on TX. This must be set for both full and half duplex
1209 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
1210 phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1211 e1000_write_phy_reg(hw,
1212 M88E1000_PHY_SPEC_CTRL, phy_reg);
1215 static int e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
1217 struct e1000_hw *hw = &adapter->hw;
1221 /* Setup the Device Control Register for PHY loopback test. */
1223 ctrl_reg = er32(CTRL);
1224 ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */
1225 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1226 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1227 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
1228 E1000_CTRL_FD); /* Force Duplex to FULL */
1230 ew32(CTRL, ctrl_reg);
1232 /* Read the PHY Specific Control Register (0x10) */
1233 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
1235 /* Clear Auto-Crossover bits in PHY Specific Control Register
1238 phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
1239 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
1241 /* Perform software reset on the PHY */
1242 e1000_phy_reset(hw);
1244 /* Have to setup TX_CLK and TX_CRS after software reset */
1245 e1000_phy_reset_clk_and_crs(adapter);
1247 e1000_write_phy_reg(hw, PHY_CTRL, 0x8100);
1249 /* Wait for reset to complete. */
1252 /* Have to setup TX_CLK and TX_CRS after software reset */
1253 e1000_phy_reset_clk_and_crs(adapter);
1255 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1256 e1000_phy_disable_receiver(adapter);
1258 /* Set the loopback bit in the PHY control register. */
1259 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
1260 phy_reg |= MII_CR_LOOPBACK;
1261 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
1263 /* Setup TX_CLK and TX_CRS one more time. */
1264 e1000_phy_reset_clk_and_crs(adapter);
1266 /* Check Phy Configuration */
1267 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
1268 if (phy_reg != 0x4100)
1271 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
1272 if (phy_reg != 0x0070)
1275 e1000_read_phy_reg(hw, 29, &phy_reg);
1276 if (phy_reg != 0x001A)
1282 static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1284 struct e1000_hw *hw = &adapter->hw;
1288 hw->autoneg = false;
1290 if (hw->phy_type == e1000_phy_m88) {
1291 /* Auto-MDI/MDIX Off */
1292 e1000_write_phy_reg(hw,
1293 M88E1000_PHY_SPEC_CTRL, 0x0808);
1294 /* reset to update Auto-MDI/MDIX */
1295 e1000_write_phy_reg(hw, PHY_CTRL, 0x9140);
1297 e1000_write_phy_reg(hw, PHY_CTRL, 0x8140);
1298 } else if (hw->phy_type == e1000_phy_gg82563)
1299 e1000_write_phy_reg(hw,
1300 GG82563_PHY_KMRN_MODE_CTRL,
1303 ctrl_reg = er32(CTRL);
1305 if (hw->phy_type == e1000_phy_ife) {
1306 /* force 100, set loopback */
1307 e1000_write_phy_reg(hw, PHY_CTRL, 0x6100);
1309 /* Now set up the MAC to the same speed/duplex as the PHY. */
1310 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1311 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1312 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1313 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1314 E1000_CTRL_FD); /* Force Duplex to FULL */
1316 /* force 1000, set loopback */
1317 e1000_write_phy_reg(hw, PHY_CTRL, 0x4140);
1319 /* Now set up the MAC to the same speed/duplex as the PHY. */
1320 ctrl_reg = er32(CTRL);
1321 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1322 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1323 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1324 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1325 E1000_CTRL_FD); /* Force Duplex to FULL */
1328 if (hw->media_type == e1000_media_type_copper &&
1329 hw->phy_type == e1000_phy_m88)
1330 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1332 /* Set the ILOS bit on the fiber Nic is half
1333 * duplex link is detected. */
1334 stat_reg = er32(STATUS);
1335 if ((stat_reg & E1000_STATUS_FD) == 0)
1336 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1339 ew32(CTRL, ctrl_reg);
1341 /* Disable the receiver on the PHY so when a cable is plugged in, the
1342 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1344 if (hw->phy_type == e1000_phy_m88)
1345 e1000_phy_disable_receiver(adapter);
1352 static int e1000_set_phy_loopback(struct e1000_adapter *adapter)
1354 struct e1000_hw *hw = &adapter->hw;
1358 switch (hw->mac_type) {
1360 if (hw->media_type == e1000_media_type_copper) {
1361 /* Attempt to setup Loopback mode on Non-integrated PHY.
1362 * Some PHY registers get corrupted at random, so
1363 * attempt this 10 times.
1365 while (e1000_nonintegrated_phy_loopback(adapter) &&
1375 case e1000_82545_rev_3:
1377 case e1000_82546_rev_3:
1379 case e1000_82541_rev_2:
1381 case e1000_82547_rev_2:
1385 case e1000_80003es2lan:
1387 return e1000_integrated_phy_loopback(adapter);
1391 /* Default PHY loopback work is to read the MII
1392 * control register and assert bit 14 (loopback mode).
1394 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
1395 phy_reg |= MII_CR_LOOPBACK;
1396 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
1404 static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1406 struct e1000_hw *hw = &adapter->hw;
1409 if (hw->media_type == e1000_media_type_fiber ||
1410 hw->media_type == e1000_media_type_internal_serdes) {
1411 switch (hw->mac_type) {
1414 case e1000_82545_rev_3:
1415 case e1000_82546_rev_3:
1416 return e1000_set_phy_loopback(adapter);
1420 #define E1000_SERDES_LB_ON 0x410
1421 e1000_set_phy_loopback(adapter);
1422 ew32(SCTL, E1000_SERDES_LB_ON);
1428 rctl |= E1000_RCTL_LBM_TCVR;
1432 } else if (hw->media_type == e1000_media_type_copper)
1433 return e1000_set_phy_loopback(adapter);
1438 static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1440 struct e1000_hw *hw = &adapter->hw;
1445 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1448 switch (hw->mac_type) {
1451 if (hw->media_type == e1000_media_type_fiber ||
1452 hw->media_type == e1000_media_type_internal_serdes) {
1453 #define E1000_SERDES_LB_OFF 0x400
1454 ew32(SCTL, E1000_SERDES_LB_OFF);
1461 case e1000_82545_rev_3:
1462 case e1000_82546_rev_3:
1465 if (hw->phy_type == e1000_phy_gg82563)
1466 e1000_write_phy_reg(hw,
1467 GG82563_PHY_KMRN_MODE_CTRL,
1469 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
1470 if (phy_reg & MII_CR_LOOPBACK) {
1471 phy_reg &= ~MII_CR_LOOPBACK;
1472 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
1473 e1000_phy_reset(hw);
1479 static void e1000_create_lbtest_frame(struct sk_buff *skb,
1480 unsigned int frame_size)
1482 memset(skb->data, 0xFF, frame_size);
1484 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1485 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1486 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1489 static int e1000_check_lbtest_frame(struct sk_buff *skb,
1490 unsigned int frame_size)
1493 if (*(skb->data + 3) == 0xFF) {
1494 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1495 (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
1502 static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1504 struct e1000_hw *hw = &adapter->hw;
1505 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1506 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1507 struct pci_dev *pdev = adapter->pdev;
1508 int i, j, k, l, lc, good_cnt, ret_val=0;
1511 ew32(RDT, rxdr->count - 1);
1513 /* Calculate the loop count based on the largest descriptor ring
1514 * The idea is to wrap the largest ring a number of times using 64
1515 * send/receive pairs during each loop
1518 if (rxdr->count <= txdr->count)
1519 lc = ((txdr->count / 64) * 2) + 1;
1521 lc = ((rxdr->count / 64) * 2) + 1;
1524 for (j = 0; j <= lc; j++) { /* loop count loop */
1525 for (i = 0; i < 64; i++) { /* send the packets */
1526 e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
1528 pci_dma_sync_single_for_device(pdev,
1529 txdr->buffer_info[k].dma,
1530 txdr->buffer_info[k].length,
1532 if (unlikely(++k == txdr->count)) k = 0;
1536 time = jiffies; /* set the start time for the receive */
1538 do { /* receive the sent packets */
1539 pci_dma_sync_single_for_cpu(pdev,
1540 rxdr->buffer_info[l].dma,
1541 rxdr->buffer_info[l].length,
1542 PCI_DMA_FROMDEVICE);
1544 ret_val = e1000_check_lbtest_frame(
1545 rxdr->buffer_info[l].skb,
1549 if (unlikely(++l == rxdr->count)) l = 0;
1550 /* time + 20 msecs (200 msecs on 2.4) is more than
1551 * enough time to complete the receives, if it's
1552 * exceeded, break and error off
1554 } while (good_cnt < 64 && jiffies < (time + 20));
1555 if (good_cnt != 64) {
1556 ret_val = 13; /* ret_val is the same as mis-compare */
1559 if (jiffies >= (time + 2)) {
1560 ret_val = 14; /* error code for time out error */
1563 } /* end loop count loop */
1567 static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1569 struct e1000_hw *hw = &adapter->hw;
1571 /* PHY loopback cannot be performed if SoL/IDER
1572 * sessions are active */
1573 if (e1000_check_phy_reset_block(hw)) {
1574 DPRINTK(DRV, ERR, "Cannot do PHY loopback test "
1575 "when SoL/IDER is active.\n");
1580 if ((*data = e1000_setup_desc_rings(adapter)))
1582 if ((*data = e1000_setup_loopback_test(adapter)))
1584 *data = e1000_run_loopback_test(adapter);
1585 e1000_loopback_cleanup(adapter);
1588 e1000_free_desc_rings(adapter);
1593 static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1595 struct e1000_hw *hw = &adapter->hw;
1597 if (hw->media_type == e1000_media_type_internal_serdes) {
1599 hw->serdes_link_down = true;
1601 /* On some blade server designs, link establishment
1602 * could take as long as 2-3 minutes */
1604 e1000_check_for_link(hw);
1605 if (!hw->serdes_link_down)
1608 } while (i++ < 3750);
1612 e1000_check_for_link(hw);
1613 if (hw->autoneg) /* if auto_neg is set wait for it */
1616 if (!(er32(STATUS) & E1000_STATUS_LU)) {
1623 static int e1000_get_sset_count(struct net_device *netdev, int sset)
1627 return E1000_TEST_LEN;
1629 return E1000_STATS_LEN;
1635 static void e1000_diag_test(struct net_device *netdev,
1636 struct ethtool_test *eth_test, u64 *data)
1638 struct e1000_adapter *adapter = netdev_priv(netdev);
1639 struct e1000_hw *hw = &adapter->hw;
1640 bool if_running = netif_running(netdev);
1642 set_bit(__E1000_TESTING, &adapter->flags);
1643 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1646 /* save speed, duplex, autoneg settings */
1647 u16 autoneg_advertised = hw->autoneg_advertised;
1648 u8 forced_speed_duplex = hw->forced_speed_duplex;
1649 u8 autoneg = hw->autoneg;
1651 DPRINTK(HW, INFO, "offline testing starting\n");
1653 /* Link test performed before hardware reset so autoneg doesn't
1654 * interfere with test result */
1655 if (e1000_link_test(adapter, &data[4]))
1656 eth_test->flags |= ETH_TEST_FL_FAILED;
1659 /* indicate we're in test mode */
1662 e1000_reset(adapter);
1664 if (e1000_reg_test(adapter, &data[0]))
1665 eth_test->flags |= ETH_TEST_FL_FAILED;
1667 e1000_reset(adapter);
1668 if (e1000_eeprom_test(adapter, &data[1]))
1669 eth_test->flags |= ETH_TEST_FL_FAILED;
1671 e1000_reset(adapter);
1672 if (e1000_intr_test(adapter, &data[2]))
1673 eth_test->flags |= ETH_TEST_FL_FAILED;
1675 e1000_reset(adapter);
1676 /* make sure the phy is powered up */
1677 e1000_power_up_phy(adapter);
1678 if (e1000_loopback_test(adapter, &data[3]))
1679 eth_test->flags |= ETH_TEST_FL_FAILED;
1681 /* restore speed, duplex, autoneg settings */
1682 hw->autoneg_advertised = autoneg_advertised;
1683 hw->forced_speed_duplex = forced_speed_duplex;
1684 hw->autoneg = autoneg;
1686 e1000_reset(adapter);
1687 clear_bit(__E1000_TESTING, &adapter->flags);
1691 DPRINTK(HW, INFO, "online testing starting\n");
1693 if (e1000_link_test(adapter, &data[4]))
1694 eth_test->flags |= ETH_TEST_FL_FAILED;
1696 /* Online tests aren't run; pass by default */
1702 clear_bit(__E1000_TESTING, &adapter->flags);
1704 msleep_interruptible(4 * 1000);
1707 static int e1000_wol_exclusion(struct e1000_adapter *adapter,
1708 struct ethtool_wolinfo *wol)
1710 struct e1000_hw *hw = &adapter->hw;
1711 int retval = 1; /* fail by default */
1713 switch (hw->device_id) {
1714 case E1000_DEV_ID_82542:
1715 case E1000_DEV_ID_82543GC_FIBER:
1716 case E1000_DEV_ID_82543GC_COPPER:
1717 case E1000_DEV_ID_82544EI_FIBER:
1718 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1719 case E1000_DEV_ID_82545EM_FIBER:
1720 case E1000_DEV_ID_82545EM_COPPER:
1721 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1722 case E1000_DEV_ID_82546GB_PCIE:
1723 case E1000_DEV_ID_82571EB_SERDES_QUAD:
1724 /* these don't support WoL at all */
1727 case E1000_DEV_ID_82546EB_FIBER:
1728 case E1000_DEV_ID_82546GB_FIBER:
1729 case E1000_DEV_ID_82571EB_FIBER:
1730 case E1000_DEV_ID_82571EB_SERDES:
1731 case E1000_DEV_ID_82571EB_COPPER:
1732 /* Wake events not supported on port B */
1733 if (er32(STATUS) & E1000_STATUS_FUNC_1) {
1737 /* return success for non excluded adapter ports */
1740 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1741 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1742 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1743 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1744 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1745 /* quad port adapters only support WoL on port A */
1746 if (!adapter->quad_port_a) {
1750 /* return success for non excluded adapter ports */
1754 /* dual port cards only support WoL on port A from now on
1755 * unless it was enabled in the eeprom for port B
1756 * so exclude FUNC_1 ports from having WoL enabled */
1757 if (er32(STATUS) & E1000_STATUS_FUNC_1 &&
1758 !adapter->eeprom_wol) {
1769 static void e1000_get_wol(struct net_device *netdev,
1770 struct ethtool_wolinfo *wol)
1772 struct e1000_adapter *adapter = netdev_priv(netdev);
1773 struct e1000_hw *hw = &adapter->hw;
1775 wol->supported = WAKE_UCAST | WAKE_MCAST |
1776 WAKE_BCAST | WAKE_MAGIC;
1779 /* this function will set ->supported = 0 and return 1 if wol is not
1780 * supported by this hardware */
1781 if (e1000_wol_exclusion(adapter, wol))
1784 /* apply any specific unsupported masks here */
1785 switch (hw->device_id) {
1786 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1787 /* KSP3 does not suppport UCAST wake-ups */
1788 wol->supported &= ~WAKE_UCAST;
1790 if (adapter->wol & E1000_WUFC_EX)
1791 DPRINTK(DRV, ERR, "Interface does not support "
1792 "directed (unicast) frame wake-up packets\n");
1798 if (adapter->wol & E1000_WUFC_EX)
1799 wol->wolopts |= WAKE_UCAST;
1800 if (adapter->wol & E1000_WUFC_MC)
1801 wol->wolopts |= WAKE_MCAST;
1802 if (adapter->wol & E1000_WUFC_BC)
1803 wol->wolopts |= WAKE_BCAST;
1804 if (adapter->wol & E1000_WUFC_MAG)
1805 wol->wolopts |= WAKE_MAGIC;
1810 static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1812 struct e1000_adapter *adapter = netdev_priv(netdev);
1813 struct e1000_hw *hw = &adapter->hw;
1815 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1818 if (e1000_wol_exclusion(adapter, wol))
1819 return wol->wolopts ? -EOPNOTSUPP : 0;
1821 switch (hw->device_id) {
1822 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1823 if (wol->wolopts & WAKE_UCAST) {
1824 DPRINTK(DRV, ERR, "Interface does not support "
1825 "directed (unicast) frame wake-up packets\n");
1833 /* these settings will always override what we currently have */
1836 if (wol->wolopts & WAKE_UCAST)
1837 adapter->wol |= E1000_WUFC_EX;
1838 if (wol->wolopts & WAKE_MCAST)
1839 adapter->wol |= E1000_WUFC_MC;
1840 if (wol->wolopts & WAKE_BCAST)
1841 adapter->wol |= E1000_WUFC_BC;
1842 if (wol->wolopts & WAKE_MAGIC)
1843 adapter->wol |= E1000_WUFC_MAG;
1848 /* toggle LED 4 times per second = 2 "blinks" per second */
1849 #define E1000_ID_INTERVAL (HZ/4)
1851 /* bit defines for adapter->led_status */
1852 #define E1000_LED_ON 0
1854 static void e1000_led_blink_callback(unsigned long data)
1856 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1857 struct e1000_hw *hw = &adapter->hw;
1859 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1864 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1867 static int e1000_phys_id(struct net_device *netdev, u32 data)
1869 struct e1000_adapter *adapter = netdev_priv(netdev);
1870 struct e1000_hw *hw = &adapter->hw;
1875 if (hw->mac_type < e1000_82571) {
1876 if (!adapter->blink_timer.function) {
1877 init_timer(&adapter->blink_timer);
1878 adapter->blink_timer.function = e1000_led_blink_callback;
1879 adapter->blink_timer.data = (unsigned long) adapter;
1881 e1000_setup_led(hw);
1882 mod_timer(&adapter->blink_timer, jiffies);
1883 msleep_interruptible(data * 1000);
1884 del_timer_sync(&adapter->blink_timer);
1885 } else if (hw->phy_type == e1000_phy_ife) {
1886 if (!adapter->blink_timer.function) {
1887 init_timer(&adapter->blink_timer);
1888 adapter->blink_timer.function = e1000_led_blink_callback;
1889 adapter->blink_timer.data = (unsigned long) adapter;
1891 mod_timer(&adapter->blink_timer, jiffies);
1892 msleep_interruptible(data * 1000);
1893 del_timer_sync(&adapter->blink_timer);
1894 e1000_write_phy_reg(&(adapter->hw), IFE_PHY_SPECIAL_CONTROL_LED, 0);
1896 e1000_blink_led_start(hw);
1897 msleep_interruptible(data * 1000);
1901 clear_bit(E1000_LED_ON, &adapter->led_status);
1902 e1000_cleanup_led(hw);
1907 static int e1000_nway_reset(struct net_device *netdev)
1909 struct e1000_adapter *adapter = netdev_priv(netdev);
1910 if (netif_running(netdev))
1911 e1000_reinit_locked(adapter);
1915 static void e1000_get_ethtool_stats(struct net_device *netdev,
1916 struct ethtool_stats *stats, u64 *data)
1918 struct e1000_adapter *adapter = netdev_priv(netdev);
1921 e1000_update_stats(adapter);
1922 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1923 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1924 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1925 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1927 /* BUG_ON(i != E1000_STATS_LEN); */
1930 static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1936 switch (stringset) {
1938 memcpy(data, *e1000_gstrings_test,
1939 sizeof(e1000_gstrings_test));
1942 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1943 memcpy(p, e1000_gstrings_stats[i].stat_string,
1945 p += ETH_GSTRING_LEN;
1947 /* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
1952 static const struct ethtool_ops e1000_ethtool_ops = {
1953 .get_settings = e1000_get_settings,
1954 .set_settings = e1000_set_settings,
1955 .get_drvinfo = e1000_get_drvinfo,
1956 .get_regs_len = e1000_get_regs_len,
1957 .get_regs = e1000_get_regs,
1958 .get_wol = e1000_get_wol,
1959 .set_wol = e1000_set_wol,
1960 .get_msglevel = e1000_get_msglevel,
1961 .set_msglevel = e1000_set_msglevel,
1962 .nway_reset = e1000_nway_reset,
1963 .get_link = ethtool_op_get_link,
1964 .get_eeprom_len = e1000_get_eeprom_len,
1965 .get_eeprom = e1000_get_eeprom,
1966 .set_eeprom = e1000_set_eeprom,
1967 .get_ringparam = e1000_get_ringparam,
1968 .set_ringparam = e1000_set_ringparam,
1969 .get_pauseparam = e1000_get_pauseparam,
1970 .set_pauseparam = e1000_set_pauseparam,
1971 .get_rx_csum = e1000_get_rx_csum,
1972 .set_rx_csum = e1000_set_rx_csum,
1973 .get_tx_csum = e1000_get_tx_csum,
1974 .set_tx_csum = e1000_set_tx_csum,
1975 .set_sg = ethtool_op_set_sg,
1976 .set_tso = e1000_set_tso,
1977 .self_test = e1000_diag_test,
1978 .get_strings = e1000_get_strings,
1979 .phys_id = e1000_phys_id,
1980 .get_ethtool_stats = e1000_get_ethtool_stats,
1981 .get_sset_count = e1000_get_sset_count,
1984 void e1000_set_ethtool_ops(struct net_device *netdev)
1986 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);