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 char e1000_driver_name[];
36 extern char e1000_driver_version[];
38 extern int e1000_up(struct e1000_adapter *adapter);
39 extern void e1000_down(struct e1000_adapter *adapter);
40 extern void e1000_reinit_locked(struct e1000_adapter *adapter);
41 extern void e1000_reset(struct e1000_adapter *adapter);
42 extern int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
43 extern int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
44 extern int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
45 extern void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
46 extern void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
47 extern void e1000_update_stats(struct e1000_adapter *adapter);
51 char stat_string[ETH_GSTRING_LEN];
56 #define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
57 offsetof(struct e1000_adapter, m)
58 static const struct e1000_stats e1000_gstrings_stats[] = {
59 { "rx_packets", E1000_STAT(stats.gprc) },
60 { "tx_packets", E1000_STAT(stats.gptc) },
61 { "rx_bytes", E1000_STAT(stats.gorcl) },
62 { "tx_bytes", E1000_STAT(stats.gotcl) },
63 { "rx_broadcast", E1000_STAT(stats.bprc) },
64 { "tx_broadcast", E1000_STAT(stats.bptc) },
65 { "rx_multicast", E1000_STAT(stats.mprc) },
66 { "tx_multicast", E1000_STAT(stats.mptc) },
67 { "rx_errors", E1000_STAT(stats.rxerrc) },
68 { "tx_errors", E1000_STAT(stats.txerrc) },
69 { "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
70 { "multicast", E1000_STAT(stats.mprc) },
71 { "collisions", E1000_STAT(stats.colc) },
72 { "rx_length_errors", E1000_STAT(stats.rlerrc) },
73 { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
74 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
75 { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
76 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
77 { "rx_missed_errors", E1000_STAT(stats.mpc) },
78 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
79 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
80 { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) },
81 { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) },
82 { "tx_window_errors", E1000_STAT(stats.latecol) },
83 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
84 { "tx_deferred_ok", E1000_STAT(stats.dc) },
85 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
86 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
87 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
88 { "rx_long_length_errors", E1000_STAT(stats.roc) },
89 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
90 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
91 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
92 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
93 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
94 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
95 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
96 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
97 { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
98 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
99 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
100 { "rx_header_split", E1000_STAT(rx_hdr_split) },
101 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
104 #define E1000_QUEUE_STATS_LEN 0
105 #define E1000_GLOBAL_STATS_LEN \
106 sizeof(e1000_gstrings_stats) / sizeof(struct e1000_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 sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN
116 e1000_get_settings(struct net_device *netdev, 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;
137 /* the e1000 autoneg seems to match ethtool nicely */
139 ecmd->advertising |= hw->autoneg_advertised;
142 ecmd->port = PORT_TP;
143 ecmd->phy_address = hw->phy_addr;
145 if (hw->mac_type == e1000_82543)
146 ecmd->transceiver = XCVR_EXTERNAL;
148 ecmd->transceiver = XCVR_INTERNAL;
151 ecmd->supported = (SUPPORTED_1000baseT_Full |
155 ecmd->advertising = (ADVERTISED_1000baseT_Full |
159 ecmd->port = PORT_FIBRE;
161 if (hw->mac_type >= e1000_82545)
162 ecmd->transceiver = XCVR_INTERNAL;
164 ecmd->transceiver = XCVR_EXTERNAL;
167 if (netif_carrier_ok(adapter->netdev)) {
169 e1000_get_speed_and_duplex(hw, &adapter->link_speed,
170 &adapter->link_duplex);
171 ecmd->speed = adapter->link_speed;
173 /* unfortunatly FULL_DUPLEX != DUPLEX_FULL
174 * and HALF_DUPLEX != DUPLEX_HALF */
176 if (adapter->link_duplex == FULL_DUPLEX)
177 ecmd->duplex = DUPLEX_FULL;
179 ecmd->duplex = DUPLEX_HALF;
185 ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
186 hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
191 e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
193 struct e1000_adapter *adapter = netdev_priv(netdev);
194 struct e1000_hw *hw = &adapter->hw;
196 /* When SoL/IDER sessions are active, autoneg/speed/duplex
197 * cannot be changed */
198 if (e1000_check_phy_reset_block(hw)) {
199 DPRINTK(DRV, ERR, "Cannot change link characteristics "
200 "when SoL/IDER is active.\n");
204 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
207 if (ecmd->autoneg == AUTONEG_ENABLE) {
209 if (hw->media_type == e1000_media_type_fiber)
210 hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
214 hw->autoneg_advertised = ecmd->advertising |
217 ecmd->advertising = hw->autoneg_advertised;
219 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
220 clear_bit(__E1000_RESETTING, &adapter->flags);
226 if (netif_running(adapter->netdev)) {
230 e1000_reset(adapter);
232 clear_bit(__E1000_RESETTING, &adapter->flags);
237 e1000_get_pauseparam(struct net_device *netdev,
238 struct ethtool_pauseparam *pause)
240 struct e1000_adapter *adapter = netdev_priv(netdev);
241 struct e1000_hw *hw = &adapter->hw;
244 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
246 if (hw->fc == E1000_FC_RX_PAUSE)
248 else if (hw->fc == E1000_FC_TX_PAUSE)
250 else if (hw->fc == E1000_FC_FULL) {
257 e1000_set_pauseparam(struct net_device *netdev,
258 struct ethtool_pauseparam *pause)
260 struct e1000_adapter *adapter = netdev_priv(netdev);
261 struct e1000_hw *hw = &adapter->hw;
264 adapter->fc_autoneg = pause->autoneg;
266 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
269 if (pause->rx_pause && pause->tx_pause)
270 hw->fc = E1000_FC_FULL;
271 else if (pause->rx_pause && !pause->tx_pause)
272 hw->fc = E1000_FC_RX_PAUSE;
273 else if (!pause->rx_pause && pause->tx_pause)
274 hw->fc = E1000_FC_TX_PAUSE;
275 else if (!pause->rx_pause && !pause->tx_pause)
276 hw->fc = E1000_FC_NONE;
278 hw->original_fc = hw->fc;
280 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
281 if (netif_running(adapter->netdev)) {
285 e1000_reset(adapter);
287 retval = ((hw->media_type == e1000_media_type_fiber) ?
288 e1000_setup_link(hw) : e1000_force_mac_fc(hw));
290 clear_bit(__E1000_RESETTING, &adapter->flags);
295 e1000_get_rx_csum(struct net_device *netdev)
297 struct e1000_adapter *adapter = netdev_priv(netdev);
298 return adapter->rx_csum;
302 e1000_set_rx_csum(struct net_device *netdev, uint32_t data)
304 struct e1000_adapter *adapter = netdev_priv(netdev);
305 adapter->rx_csum = data;
307 if (netif_running(netdev))
308 e1000_reinit_locked(adapter);
310 e1000_reset(adapter);
315 e1000_get_tx_csum(struct net_device *netdev)
317 return (netdev->features & NETIF_F_HW_CSUM) != 0;
321 e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
323 struct e1000_adapter *adapter = netdev_priv(netdev);
325 if (adapter->hw.mac_type < e1000_82543) {
332 netdev->features |= NETIF_F_HW_CSUM;
334 netdev->features &= ~NETIF_F_HW_CSUM;
341 e1000_set_tso(struct net_device *netdev, uint32_t data)
343 struct e1000_adapter *adapter = netdev_priv(netdev);
344 if ((adapter->hw.mac_type < e1000_82544) ||
345 (adapter->hw.mac_type == e1000_82547))
346 return data ? -EINVAL : 0;
349 netdev->features |= NETIF_F_TSO;
351 netdev->features &= ~NETIF_F_TSO;
353 DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
354 adapter->tso_force = TRUE;
357 #endif /* NETIF_F_TSO */
360 e1000_get_msglevel(struct net_device *netdev)
362 struct e1000_adapter *adapter = netdev_priv(netdev);
363 return adapter->msg_enable;
367 e1000_set_msglevel(struct net_device *netdev, uint32_t data)
369 struct e1000_adapter *adapter = netdev_priv(netdev);
370 adapter->msg_enable = data;
374 e1000_get_regs_len(struct net_device *netdev)
376 #define E1000_REGS_LEN 32
377 return E1000_REGS_LEN * sizeof(uint32_t);
381 e1000_get_regs(struct net_device *netdev,
382 struct ethtool_regs *regs, void *p)
384 struct e1000_adapter *adapter = netdev_priv(netdev);
385 struct e1000_hw *hw = &adapter->hw;
386 uint32_t *regs_buff = p;
389 memset(p, 0, E1000_REGS_LEN * sizeof(uint32_t));
391 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
393 regs_buff[0] = E1000_READ_REG(hw, CTRL);
394 regs_buff[1] = E1000_READ_REG(hw, STATUS);
396 regs_buff[2] = E1000_READ_REG(hw, RCTL);
397 regs_buff[3] = E1000_READ_REG(hw, RDLEN);
398 regs_buff[4] = E1000_READ_REG(hw, RDH);
399 regs_buff[5] = E1000_READ_REG(hw, RDT);
400 regs_buff[6] = E1000_READ_REG(hw, RDTR);
402 regs_buff[7] = E1000_READ_REG(hw, TCTL);
403 regs_buff[8] = E1000_READ_REG(hw, TDLEN);
404 regs_buff[9] = E1000_READ_REG(hw, TDH);
405 regs_buff[10] = E1000_READ_REG(hw, TDT);
406 regs_buff[11] = E1000_READ_REG(hw, TIDV);
408 regs_buff[12] = adapter->hw.phy_type; /* PHY type (IGP=1, M88=0) */
409 if (hw->phy_type == e1000_phy_igp) {
410 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
411 IGP01E1000_PHY_AGC_A);
412 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
413 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
414 regs_buff[13] = (uint32_t)phy_data; /* cable length */
415 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
416 IGP01E1000_PHY_AGC_B);
417 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
418 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
419 regs_buff[14] = (uint32_t)phy_data; /* cable length */
420 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
421 IGP01E1000_PHY_AGC_C);
422 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
423 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
424 regs_buff[15] = (uint32_t)phy_data; /* cable length */
425 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
426 IGP01E1000_PHY_AGC_D);
427 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
428 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
429 regs_buff[16] = (uint32_t)phy_data; /* cable length */
430 regs_buff[17] = 0; /* extended 10bt distance (not needed) */
431 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
432 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
433 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
434 regs_buff[18] = (uint32_t)phy_data; /* cable polarity */
435 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
436 IGP01E1000_PHY_PCS_INIT_REG);
437 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
438 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
439 regs_buff[19] = (uint32_t)phy_data; /* cable polarity */
440 regs_buff[20] = 0; /* polarity correction enabled (always) */
441 regs_buff[22] = 0; /* phy receive errors (unavailable) */
442 regs_buff[23] = regs_buff[18]; /* mdix mode */
443 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
445 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
446 regs_buff[13] = (uint32_t)phy_data; /* cable length */
447 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
448 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
449 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
450 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
451 regs_buff[17] = (uint32_t)phy_data; /* extended 10bt distance */
452 regs_buff[18] = regs_buff[13]; /* cable polarity */
453 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
454 regs_buff[20] = regs_buff[17]; /* polarity correction */
455 /* phy receive errors */
456 regs_buff[22] = adapter->phy_stats.receive_errors;
457 regs_buff[23] = regs_buff[13]; /* mdix mode */
459 regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
460 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
461 regs_buff[24] = (uint32_t)phy_data; /* phy local receiver status */
462 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
463 if (hw->mac_type >= e1000_82540 &&
464 hw->media_type == e1000_media_type_copper) {
465 regs_buff[26] = E1000_READ_REG(hw, MANC);
470 e1000_get_eeprom_len(struct net_device *netdev)
472 struct e1000_adapter *adapter = netdev_priv(netdev);
473 return adapter->hw.eeprom.word_size * 2;
477 e1000_get_eeprom(struct net_device *netdev,
478 struct ethtool_eeprom *eeprom, uint8_t *bytes)
480 struct e1000_adapter *adapter = netdev_priv(netdev);
481 struct e1000_hw *hw = &adapter->hw;
482 uint16_t *eeprom_buff;
483 int first_word, last_word;
487 if (eeprom->len == 0)
490 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
492 first_word = eeprom->offset >> 1;
493 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
495 eeprom_buff = kmalloc(sizeof(uint16_t) *
496 (last_word - first_word + 1), GFP_KERNEL);
500 if (hw->eeprom.type == e1000_eeprom_spi)
501 ret_val = e1000_read_eeprom(hw, first_word,
502 last_word - first_word + 1,
505 for (i = 0; i < last_word - first_word + 1; i++)
506 if ((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
511 /* Device's eeprom is always little-endian, word addressable */
512 for (i = 0; i < last_word - first_word + 1; i++)
513 le16_to_cpus(&eeprom_buff[i]);
515 memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset & 1),
523 e1000_set_eeprom(struct net_device *netdev,
524 struct ethtool_eeprom *eeprom, uint8_t *bytes)
526 struct e1000_adapter *adapter = netdev_priv(netdev);
527 struct e1000_hw *hw = &adapter->hw;
528 uint16_t *eeprom_buff;
530 int max_len, first_word, last_word, ret_val = 0;
533 if (eeprom->len == 0)
536 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
539 max_len = hw->eeprom.word_size * 2;
541 first_word = eeprom->offset >> 1;
542 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
543 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
547 ptr = (void *)eeprom_buff;
549 if (eeprom->offset & 1) {
550 /* need read/modify/write of first changed EEPROM word */
551 /* only the second byte of the word is being modified */
552 ret_val = e1000_read_eeprom(hw, first_word, 1,
556 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
557 /* need read/modify/write of last changed EEPROM word */
558 /* only the first byte of the word is being modified */
559 ret_val = e1000_read_eeprom(hw, last_word, 1,
560 &eeprom_buff[last_word - first_word]);
563 /* Device's eeprom is always little-endian, word addressable */
564 for (i = 0; i < last_word - first_word + 1; i++)
565 le16_to_cpus(&eeprom_buff[i]);
567 memcpy(ptr, bytes, eeprom->len);
569 for (i = 0; i < last_word - first_word + 1; i++)
570 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
572 ret_val = e1000_write_eeprom(hw, first_word,
573 last_word - first_word + 1, eeprom_buff);
575 /* Update the checksum over the first part of the EEPROM if needed
576 * and flush shadow RAM for 82573 conrollers */
577 if ((ret_val == 0) && ((first_word <= EEPROM_CHECKSUM_REG) ||
578 (hw->mac_type == e1000_82573)))
579 e1000_update_eeprom_checksum(hw);
586 e1000_get_drvinfo(struct net_device *netdev,
587 struct ethtool_drvinfo *drvinfo)
589 struct e1000_adapter *adapter = netdev_priv(netdev);
590 char firmware_version[32];
591 uint16_t eeprom_data;
593 strncpy(drvinfo->driver, e1000_driver_name, 32);
594 strncpy(drvinfo->version, e1000_driver_version, 32);
596 /* EEPROM image version # is reported as firmware version # for
597 * 8257{1|2|3} controllers */
598 e1000_read_eeprom(&adapter->hw, 5, 1, &eeprom_data);
599 switch (adapter->hw.mac_type) {
603 case e1000_80003es2lan:
605 sprintf(firmware_version, "%d.%d-%d",
606 (eeprom_data & 0xF000) >> 12,
607 (eeprom_data & 0x0FF0) >> 4,
608 eeprom_data & 0x000F);
611 sprintf(firmware_version, "N/A");
614 strncpy(drvinfo->fw_version, firmware_version, 32);
615 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
616 drvinfo->n_stats = E1000_STATS_LEN;
617 drvinfo->testinfo_len = E1000_TEST_LEN;
618 drvinfo->regdump_len = e1000_get_regs_len(netdev);
619 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
623 e1000_get_ringparam(struct net_device *netdev,
624 struct ethtool_ringparam *ring)
626 struct e1000_adapter *adapter = netdev_priv(netdev);
627 e1000_mac_type mac_type = adapter->hw.mac_type;
628 struct e1000_tx_ring *txdr = adapter->tx_ring;
629 struct e1000_rx_ring *rxdr = adapter->rx_ring;
631 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
633 ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
635 ring->rx_mini_max_pending = 0;
636 ring->rx_jumbo_max_pending = 0;
637 ring->rx_pending = rxdr->count;
638 ring->tx_pending = txdr->count;
639 ring->rx_mini_pending = 0;
640 ring->rx_jumbo_pending = 0;
644 e1000_set_ringparam(struct net_device *netdev,
645 struct ethtool_ringparam *ring)
647 struct e1000_adapter *adapter = netdev_priv(netdev);
648 e1000_mac_type mac_type = adapter->hw.mac_type;
649 struct e1000_tx_ring *txdr, *tx_old, *tx_new;
650 struct e1000_rx_ring *rxdr, *rx_old, *rx_new;
651 int i, err, tx_ring_size, rx_ring_size;
653 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
656 tx_ring_size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
657 rx_ring_size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
659 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
662 if (netif_running(adapter->netdev))
665 tx_old = adapter->tx_ring;
666 rx_old = adapter->rx_ring;
668 adapter->tx_ring = kmalloc(tx_ring_size, GFP_KERNEL);
669 if (!adapter->tx_ring) {
673 memset(adapter->tx_ring, 0, tx_ring_size);
675 adapter->rx_ring = kmalloc(rx_ring_size, GFP_KERNEL);
676 if (!adapter->rx_ring) {
677 kfree(adapter->tx_ring);
681 memset(adapter->rx_ring, 0, rx_ring_size);
683 txdr = adapter->tx_ring;
684 rxdr = adapter->rx_ring;
686 rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD);
687 rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ?
688 E1000_MAX_RXD : E1000_MAX_82544_RXD));
689 E1000_ROUNDUP(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
691 txdr->count = max(ring->tx_pending,(uint32_t)E1000_MIN_TXD);
692 txdr->count = min(txdr->count,(uint32_t)(mac_type < e1000_82544 ?
693 E1000_MAX_TXD : E1000_MAX_82544_TXD));
694 E1000_ROUNDUP(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
696 for (i = 0; i < adapter->num_tx_queues; i++)
697 txdr[i].count = txdr->count;
698 for (i = 0; i < adapter->num_rx_queues; i++)
699 rxdr[i].count = rxdr->count;
701 if (netif_running(adapter->netdev)) {
702 /* Try to get new resources before deleting old */
703 if ((err = e1000_setup_all_rx_resources(adapter)))
705 if ((err = e1000_setup_all_tx_resources(adapter)))
708 /* save the new, restore the old in order to free it,
709 * then restore the new back again */
711 rx_new = adapter->rx_ring;
712 tx_new = adapter->tx_ring;
713 adapter->rx_ring = rx_old;
714 adapter->tx_ring = tx_old;
715 e1000_free_all_rx_resources(adapter);
716 e1000_free_all_tx_resources(adapter);
719 adapter->rx_ring = rx_new;
720 adapter->tx_ring = tx_new;
721 if ((err = e1000_up(adapter)))
725 clear_bit(__E1000_RESETTING, &adapter->flags);
728 e1000_free_all_rx_resources(adapter);
730 adapter->rx_ring = rx_old;
731 adapter->tx_ring = tx_old;
734 clear_bit(__E1000_RESETTING, &adapter->flags);
738 #define REG_PATTERN_TEST(R, M, W) \
740 uint32_t pat, value; \
742 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; \
743 for (pat = 0; pat < sizeof(test)/sizeof(test[0]); pat++) { \
744 E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W)); \
745 value = E1000_READ_REG(&adapter->hw, R); \
746 if (value != (test[pat] & W & M)) { \
747 DPRINTK(DRV, ERR, "pattern test reg %04X failed: got " \
748 "0x%08X expected 0x%08X\n", \
749 E1000_##R, value, (test[pat] & W & M)); \
750 *data = (adapter->hw.mac_type < e1000_82543) ? \
751 E1000_82542_##R : E1000_##R; \
757 #define REG_SET_AND_CHECK(R, M, W) \
760 E1000_WRITE_REG(&adapter->hw, R, W & M); \
761 value = E1000_READ_REG(&adapter->hw, R); \
762 if ((W & M) != (value & M)) { \
763 DPRINTK(DRV, ERR, "set/check reg %04X test failed: got 0x%08X "\
764 "expected 0x%08X\n", E1000_##R, (value & M), (W & M)); \
765 *data = (adapter->hw.mac_type < e1000_82543) ? \
766 E1000_82542_##R : E1000_##R; \
772 e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
774 uint32_t value, before, after;
777 /* The status register is Read Only, so a write should fail.
778 * Some bits that get toggled are ignored.
780 switch (adapter->hw.mac_type) {
781 /* there are several bits on newer hardware that are r/w */
784 case e1000_80003es2lan:
796 before = E1000_READ_REG(&adapter->hw, STATUS);
797 value = (E1000_READ_REG(&adapter->hw, STATUS) & toggle);
798 E1000_WRITE_REG(&adapter->hw, STATUS, toggle);
799 after = E1000_READ_REG(&adapter->hw, STATUS) & toggle;
800 if (value != after) {
801 DPRINTK(DRV, ERR, "failed STATUS register test got: "
802 "0x%08X expected: 0x%08X\n", after, value);
806 /* restore previous status */
807 E1000_WRITE_REG(&adapter->hw, STATUS, before);
808 if (adapter->hw.mac_type != e1000_ich8lan) {
809 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
810 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
811 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
812 REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
814 REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
815 REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
816 REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
817 REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
818 REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
819 REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
820 REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
821 REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
822 REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
823 REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
825 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
826 before = (adapter->hw.mac_type == e1000_ich8lan ?
827 0x06C3B33E : 0x06DFB3FE);
828 REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
829 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
831 if (adapter->hw.mac_type >= e1000_82543) {
833 REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
834 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
835 if (adapter->hw.mac_type != e1000_ich8lan)
836 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
837 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
838 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
839 value = (adapter->hw.mac_type == e1000_ich8lan ?
840 E1000_RAR_ENTRIES_ICH8LAN : E1000_RAR_ENTRIES);
841 for (i = 0; i < value; i++) {
842 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
848 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
849 REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
850 REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
851 REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
855 value = (adapter->hw.mac_type == e1000_ich8lan ?
856 E1000_MC_TBL_SIZE_ICH8LAN : E1000_MC_TBL_SIZE);
857 for (i = 0; i < value; i++)
858 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
865 e1000_eeprom_test(struct e1000_adapter *adapter, uint64_t *data)
868 uint16_t checksum = 0;
872 /* Read and add up the contents of the EEPROM */
873 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
874 if ((e1000_read_eeprom(&adapter->hw, i, 1, &temp)) < 0) {
881 /* If Checksum is not Correct return error else test passed */
882 if ((checksum != (uint16_t) EEPROM_SUM) && !(*data))
889 e1000_test_intr(int irq,
891 struct pt_regs *regs)
893 struct net_device *netdev = (struct net_device *) data;
894 struct e1000_adapter *adapter = netdev_priv(netdev);
896 adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR);
902 e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
904 struct net_device *netdev = adapter->netdev;
905 uint32_t mask, i=0, shared_int = TRUE;
906 uint32_t irq = adapter->pdev->irq;
910 /* NOTE: we don't test MSI interrupts here, yet */
911 /* Hook up test interrupt handler just for this test */
912 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED,
913 netdev->name, netdev))
915 else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
916 netdev->name, netdev)) {
920 DPRINTK(HW, INFO, "testing %s interrupt\n",
921 (shared_int ? "shared" : "unshared"));
923 /* Disable all the interrupts */
924 E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
927 /* Test each interrupt */
928 for (; i < 10; i++) {
930 if (adapter->hw.mac_type == e1000_ich8lan && i == 8)
932 /* Interrupt to test */
936 /* Disable the interrupt to be reported in
937 * the cause register and then force the same
938 * interrupt and see if one gets posted. If
939 * an interrupt was posted to the bus, the
942 adapter->test_icr = 0;
943 E1000_WRITE_REG(&adapter->hw, IMC, mask);
944 E1000_WRITE_REG(&adapter->hw, ICS, mask);
947 if (adapter->test_icr & mask) {
953 /* Enable the interrupt to be reported in
954 * the cause register and then force the same
955 * interrupt and see if one gets posted. If
956 * an interrupt was not posted to the bus, the
959 adapter->test_icr = 0;
960 E1000_WRITE_REG(&adapter->hw, IMS, mask);
961 E1000_WRITE_REG(&adapter->hw, ICS, mask);
964 if (!(adapter->test_icr & mask)) {
970 /* Disable the other interrupts to be reported in
971 * the cause register and then force the other
972 * interrupts and see if any get posted. If
973 * an interrupt was posted to the bus, the
976 adapter->test_icr = 0;
977 E1000_WRITE_REG(&adapter->hw, IMC, ~mask & 0x00007FFF);
978 E1000_WRITE_REG(&adapter->hw, ICS, ~mask & 0x00007FFF);
981 if (adapter->test_icr) {
988 /* Disable all the interrupts */
989 E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
992 /* Unhook test interrupt handler */
993 free_irq(irq, netdev);
999 e1000_free_desc_rings(struct e1000_adapter *adapter)
1001 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1002 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1003 struct pci_dev *pdev = adapter->pdev;
1006 if (txdr->desc && txdr->buffer_info) {
1007 for (i = 0; i < txdr->count; i++) {
1008 if (txdr->buffer_info[i].dma)
1009 pci_unmap_single(pdev, txdr->buffer_info[i].dma,
1010 txdr->buffer_info[i].length,
1012 if (txdr->buffer_info[i].skb)
1013 dev_kfree_skb(txdr->buffer_info[i].skb);
1017 if (rxdr->desc && rxdr->buffer_info) {
1018 for (i = 0; i < rxdr->count; i++) {
1019 if (rxdr->buffer_info[i].dma)
1020 pci_unmap_single(pdev, rxdr->buffer_info[i].dma,
1021 rxdr->buffer_info[i].length,
1022 PCI_DMA_FROMDEVICE);
1023 if (rxdr->buffer_info[i].skb)
1024 dev_kfree_skb(rxdr->buffer_info[i].skb);
1029 pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
1033 pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
1037 kfree(txdr->buffer_info);
1038 txdr->buffer_info = NULL;
1039 kfree(rxdr->buffer_info);
1040 rxdr->buffer_info = NULL;
1046 e1000_setup_desc_rings(struct e1000_adapter *adapter)
1048 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1049 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1050 struct pci_dev *pdev = adapter->pdev;
1052 int size, i, ret_val;
1054 /* Setup Tx descriptor ring and Tx buffers */
1057 txdr->count = E1000_DEFAULT_TXD;
1059 size = txdr->count * sizeof(struct e1000_buffer);
1060 if (!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
1064 memset(txdr->buffer_info, 0, size);
1066 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1067 E1000_ROUNDUP(txdr->size, 4096);
1068 if (!(txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma))) {
1072 memset(txdr->desc, 0, txdr->size);
1073 txdr->next_to_use = txdr->next_to_clean = 0;
1075 E1000_WRITE_REG(&adapter->hw, TDBAL,
1076 ((uint64_t) txdr->dma & 0x00000000FFFFFFFF));
1077 E1000_WRITE_REG(&adapter->hw, TDBAH, ((uint64_t) txdr->dma >> 32));
1078 E1000_WRITE_REG(&adapter->hw, TDLEN,
1079 txdr->count * sizeof(struct e1000_tx_desc));
1080 E1000_WRITE_REG(&adapter->hw, TDH, 0);
1081 E1000_WRITE_REG(&adapter->hw, TDT, 0);
1082 E1000_WRITE_REG(&adapter->hw, TCTL,
1083 E1000_TCTL_PSP | E1000_TCTL_EN |
1084 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1085 E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1087 for (i = 0; i < txdr->count; i++) {
1088 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
1089 struct sk_buff *skb;
1090 unsigned int size = 1024;
1092 if (!(skb = alloc_skb(size, GFP_KERNEL))) {
1097 txdr->buffer_info[i].skb = skb;
1098 txdr->buffer_info[i].length = skb->len;
1099 txdr->buffer_info[i].dma =
1100 pci_map_single(pdev, skb->data, skb->len,
1102 tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
1103 tx_desc->lower.data = cpu_to_le32(skb->len);
1104 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1105 E1000_TXD_CMD_IFCS |
1107 tx_desc->upper.data = 0;
1110 /* Setup Rx descriptor ring and Rx buffers */
1113 rxdr->count = E1000_DEFAULT_RXD;
1115 size = rxdr->count * sizeof(struct e1000_buffer);
1116 if (!(rxdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
1120 memset(rxdr->buffer_info, 0, size);
1122 rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
1123 if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) {
1127 memset(rxdr->desc, 0, rxdr->size);
1128 rxdr->next_to_use = rxdr->next_to_clean = 0;
1130 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1131 E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN);
1132 E1000_WRITE_REG(&adapter->hw, RDBAL,
1133 ((uint64_t) rxdr->dma & 0xFFFFFFFF));
1134 E1000_WRITE_REG(&adapter->hw, RDBAH, ((uint64_t) rxdr->dma >> 32));
1135 E1000_WRITE_REG(&adapter->hw, RDLEN, rxdr->size);
1136 E1000_WRITE_REG(&adapter->hw, RDH, 0);
1137 E1000_WRITE_REG(&adapter->hw, RDT, 0);
1138 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1139 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1140 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1141 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1143 for (i = 0; i < rxdr->count; i++) {
1144 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
1145 struct sk_buff *skb;
1147 if (!(skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN,
1152 skb_reserve(skb, NET_IP_ALIGN);
1153 rxdr->buffer_info[i].skb = skb;
1154 rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
1155 rxdr->buffer_info[i].dma =
1156 pci_map_single(pdev, skb->data, E1000_RXBUFFER_2048,
1157 PCI_DMA_FROMDEVICE);
1158 rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
1159 memset(skb->data, 0x00, skb->len);
1165 e1000_free_desc_rings(adapter);
1170 e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1172 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1173 e1000_write_phy_reg(&adapter->hw, 29, 0x001F);
1174 e1000_write_phy_reg(&adapter->hw, 30, 0x8FFC);
1175 e1000_write_phy_reg(&adapter->hw, 29, 0x001A);
1176 e1000_write_phy_reg(&adapter->hw, 30, 0x8FF0);
1180 e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
1184 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1185 * Extended PHY Specific Control Register to 25MHz clock. This
1186 * value defaults back to a 2.5MHz clock when the PHY is reset.
1188 e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
1189 phy_reg |= M88E1000_EPSCR_TX_CLK_25;
1190 e1000_write_phy_reg(&adapter->hw,
1191 M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
1193 /* In addition, because of the s/w reset above, we need to enable
1194 * CRS on TX. This must be set for both full and half duplex
1197 e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
1198 phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1199 e1000_write_phy_reg(&adapter->hw,
1200 M88E1000_PHY_SPEC_CTRL, phy_reg);
1204 e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
1209 /* Setup the Device Control Register for PHY loopback test. */
1211 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1212 ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */
1213 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1214 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1215 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
1216 E1000_CTRL_FD); /* Force Duplex to FULL */
1218 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg);
1220 /* Read the PHY Specific Control Register (0x10) */
1221 e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
1223 /* Clear Auto-Crossover bits in PHY Specific Control Register
1226 phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
1227 e1000_write_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
1229 /* Perform software reset on the PHY */
1230 e1000_phy_reset(&adapter->hw);
1232 /* Have to setup TX_CLK and TX_CRS after software reset */
1233 e1000_phy_reset_clk_and_crs(adapter);
1235 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8100);
1237 /* Wait for reset to complete. */
1240 /* Have to setup TX_CLK and TX_CRS after software reset */
1241 e1000_phy_reset_clk_and_crs(adapter);
1243 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1244 e1000_phy_disable_receiver(adapter);
1246 /* Set the loopback bit in the PHY control register. */
1247 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1248 phy_reg |= MII_CR_LOOPBACK;
1249 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
1251 /* Setup TX_CLK and TX_CRS one more time. */
1252 e1000_phy_reset_clk_and_crs(adapter);
1254 /* Check Phy Configuration */
1255 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1256 if (phy_reg != 0x4100)
1259 e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
1260 if (phy_reg != 0x0070)
1263 e1000_read_phy_reg(&adapter->hw, 29, &phy_reg);
1264 if (phy_reg != 0x001A)
1271 e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1273 uint32_t ctrl_reg = 0;
1274 uint32_t stat_reg = 0;
1276 adapter->hw.autoneg = FALSE;
1278 if (adapter->hw.phy_type == e1000_phy_m88) {
1279 /* Auto-MDI/MDIX Off */
1280 e1000_write_phy_reg(&adapter->hw,
1281 M88E1000_PHY_SPEC_CTRL, 0x0808);
1282 /* reset to update Auto-MDI/MDIX */
1283 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x9140);
1285 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8140);
1286 } else if (adapter->hw.phy_type == e1000_phy_gg82563)
1287 e1000_write_phy_reg(&adapter->hw,
1288 GG82563_PHY_KMRN_MODE_CTRL,
1291 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1293 if (adapter->hw.phy_type == e1000_phy_ife) {
1294 /* force 100, set loopback */
1295 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x6100);
1297 /* Now set up the MAC to the same speed/duplex as the PHY. */
1298 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1299 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1300 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1301 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1302 E1000_CTRL_FD); /* Force Duplex to FULL */
1304 /* force 1000, set loopback */
1305 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x4140);
1307 /* Now set up the MAC to the same speed/duplex as the PHY. */
1308 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1309 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1310 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1311 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1312 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1313 E1000_CTRL_FD); /* Force Duplex to FULL */
1316 if (adapter->hw.media_type == e1000_media_type_copper &&
1317 adapter->hw.phy_type == e1000_phy_m88)
1318 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1320 /* Set the ILOS bit on the fiber Nic is half
1321 * duplex link is detected. */
1322 stat_reg = E1000_READ_REG(&adapter->hw, STATUS);
1323 if ((stat_reg & E1000_STATUS_FD) == 0)
1324 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1327 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg);
1329 /* Disable the receiver on the PHY so when a cable is plugged in, the
1330 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1332 if (adapter->hw.phy_type == e1000_phy_m88)
1333 e1000_phy_disable_receiver(adapter);
1341 e1000_set_phy_loopback(struct e1000_adapter *adapter)
1343 uint16_t phy_reg = 0;
1346 switch (adapter->hw.mac_type) {
1348 if (adapter->hw.media_type == e1000_media_type_copper) {
1349 /* Attempt to setup Loopback mode on Non-integrated PHY.
1350 * Some PHY registers get corrupted at random, so
1351 * attempt this 10 times.
1353 while (e1000_nonintegrated_phy_loopback(adapter) &&
1363 case e1000_82545_rev_3:
1365 case e1000_82546_rev_3:
1367 case e1000_82541_rev_2:
1369 case e1000_82547_rev_2:
1373 case e1000_80003es2lan:
1375 return e1000_integrated_phy_loopback(adapter);
1379 /* Default PHY loopback work is to read the MII
1380 * control register and assert bit 14 (loopback mode).
1382 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1383 phy_reg |= MII_CR_LOOPBACK;
1384 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
1393 e1000_setup_loopback_test(struct e1000_adapter *adapter)
1395 struct e1000_hw *hw = &adapter->hw;
1398 if (hw->media_type == e1000_media_type_fiber ||
1399 hw->media_type == e1000_media_type_internal_serdes) {
1400 switch (hw->mac_type) {
1403 case e1000_82545_rev_3:
1404 case e1000_82546_rev_3:
1405 return e1000_set_phy_loopback(adapter);
1409 #define E1000_SERDES_LB_ON 0x410
1410 e1000_set_phy_loopback(adapter);
1411 E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_ON);
1416 rctl = E1000_READ_REG(hw, RCTL);
1417 rctl |= E1000_RCTL_LBM_TCVR;
1418 E1000_WRITE_REG(hw, RCTL, rctl);
1421 } else if (hw->media_type == e1000_media_type_copper)
1422 return e1000_set_phy_loopback(adapter);
1428 e1000_loopback_cleanup(struct e1000_adapter *adapter)
1430 struct e1000_hw *hw = &adapter->hw;
1434 rctl = E1000_READ_REG(hw, RCTL);
1435 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1436 E1000_WRITE_REG(hw, RCTL, rctl);
1438 switch (hw->mac_type) {
1441 if (hw->media_type == e1000_media_type_fiber ||
1442 hw->media_type == e1000_media_type_internal_serdes) {
1443 #define E1000_SERDES_LB_OFF 0x400
1444 E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_OFF);
1451 case e1000_82545_rev_3:
1452 case e1000_82546_rev_3:
1455 if (hw->phy_type == e1000_phy_gg82563)
1456 e1000_write_phy_reg(hw,
1457 GG82563_PHY_KMRN_MODE_CTRL,
1459 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
1460 if (phy_reg & MII_CR_LOOPBACK) {
1461 phy_reg &= ~MII_CR_LOOPBACK;
1462 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
1463 e1000_phy_reset(hw);
1470 e1000_create_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1472 memset(skb->data, 0xFF, frame_size);
1474 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1475 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1476 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1480 e1000_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1483 if (*(skb->data + 3) == 0xFF) {
1484 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1485 (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
1493 e1000_run_loopback_test(struct e1000_adapter *adapter)
1495 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1496 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1497 struct pci_dev *pdev = adapter->pdev;
1498 int i, j, k, l, lc, good_cnt, ret_val=0;
1501 E1000_WRITE_REG(&adapter->hw, RDT, rxdr->count - 1);
1503 /* Calculate the loop count based on the largest descriptor ring
1504 * The idea is to wrap the largest ring a number of times using 64
1505 * send/receive pairs during each loop
1508 if (rxdr->count <= txdr->count)
1509 lc = ((txdr->count / 64) * 2) + 1;
1511 lc = ((rxdr->count / 64) * 2) + 1;
1514 for (j = 0; j <= lc; j++) { /* loop count loop */
1515 for (i = 0; i < 64; i++) { /* send the packets */
1516 e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
1518 pci_dma_sync_single_for_device(pdev,
1519 txdr->buffer_info[k].dma,
1520 txdr->buffer_info[k].length,
1522 if (unlikely(++k == txdr->count)) k = 0;
1524 E1000_WRITE_REG(&adapter->hw, TDT, k);
1526 time = jiffies; /* set the start time for the receive */
1528 do { /* receive the sent packets */
1529 pci_dma_sync_single_for_cpu(pdev,
1530 rxdr->buffer_info[l].dma,
1531 rxdr->buffer_info[l].length,
1532 PCI_DMA_FROMDEVICE);
1534 ret_val = e1000_check_lbtest_frame(
1535 rxdr->buffer_info[l].skb,
1539 if (unlikely(++l == rxdr->count)) l = 0;
1540 /* time + 20 msecs (200 msecs on 2.4) is more than
1541 * enough time to complete the receives, if it's
1542 * exceeded, break and error off
1544 } while (good_cnt < 64 && jiffies < (time + 20));
1545 if (good_cnt != 64) {
1546 ret_val = 13; /* ret_val is the same as mis-compare */
1549 if (jiffies >= (time + 2)) {
1550 ret_val = 14; /* error code for time out error */
1553 } /* end loop count loop */
1558 e1000_loopback_test(struct e1000_adapter *adapter, uint64_t *data)
1560 /* PHY loopback cannot be performed if SoL/IDER
1561 * sessions are active */
1562 if (e1000_check_phy_reset_block(&adapter->hw)) {
1563 DPRINTK(DRV, ERR, "Cannot do PHY loopback test "
1564 "when SoL/IDER is active.\n");
1569 if ((*data = e1000_setup_desc_rings(adapter)))
1571 if ((*data = e1000_setup_loopback_test(adapter)))
1573 *data = e1000_run_loopback_test(adapter);
1574 e1000_loopback_cleanup(adapter);
1577 e1000_free_desc_rings(adapter);
1583 e1000_link_test(struct e1000_adapter *adapter, uint64_t *data)
1586 if (adapter->hw.media_type == e1000_media_type_internal_serdes) {
1588 adapter->hw.serdes_link_down = TRUE;
1590 /* On some blade server designs, link establishment
1591 * could take as long as 2-3 minutes */
1593 e1000_check_for_link(&adapter->hw);
1594 if (adapter->hw.serdes_link_down == FALSE)
1597 } while (i++ < 3750);
1601 e1000_check_for_link(&adapter->hw);
1602 if (adapter->hw.autoneg) /* if auto_neg is set wait for it */
1605 if (!(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU)) {
1613 e1000_diag_test_count(struct net_device *netdev)
1615 return E1000_TEST_LEN;
1618 extern void e1000_power_up_phy(struct e1000_adapter *);
1621 e1000_diag_test(struct net_device *netdev,
1622 struct ethtool_test *eth_test, uint64_t *data)
1624 struct e1000_adapter *adapter = netdev_priv(netdev);
1625 boolean_t if_running = netif_running(netdev);
1627 set_bit(__E1000_TESTING, &adapter->flags);
1628 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1631 /* save speed, duplex, autoneg settings */
1632 uint16_t autoneg_advertised = adapter->hw.autoneg_advertised;
1633 uint8_t forced_speed_duplex = adapter->hw.forced_speed_duplex;
1634 uint8_t autoneg = adapter->hw.autoneg;
1636 DPRINTK(HW, INFO, "offline testing starting\n");
1638 /* Link test performed before hardware reset so autoneg doesn't
1639 * interfere with test result */
1640 if (e1000_link_test(adapter, &data[4]))
1641 eth_test->flags |= ETH_TEST_FL_FAILED;
1644 /* indicate we're in test mode */
1647 e1000_reset(adapter);
1649 if (e1000_reg_test(adapter, &data[0]))
1650 eth_test->flags |= ETH_TEST_FL_FAILED;
1652 e1000_reset(adapter);
1653 if (e1000_eeprom_test(adapter, &data[1]))
1654 eth_test->flags |= ETH_TEST_FL_FAILED;
1656 e1000_reset(adapter);
1657 if (e1000_intr_test(adapter, &data[2]))
1658 eth_test->flags |= ETH_TEST_FL_FAILED;
1660 e1000_reset(adapter);
1661 /* make sure the phy is powered up */
1662 e1000_power_up_phy(adapter);
1663 if (e1000_loopback_test(adapter, &data[3]))
1664 eth_test->flags |= ETH_TEST_FL_FAILED;
1666 /* restore speed, duplex, autoneg settings */
1667 adapter->hw.autoneg_advertised = autoneg_advertised;
1668 adapter->hw.forced_speed_duplex = forced_speed_duplex;
1669 adapter->hw.autoneg = autoneg;
1671 e1000_reset(adapter);
1672 clear_bit(__E1000_TESTING, &adapter->flags);
1676 DPRINTK(HW, INFO, "online testing starting\n");
1678 if (e1000_link_test(adapter, &data[4]))
1679 eth_test->flags |= ETH_TEST_FL_FAILED;
1681 /* Offline tests aren't run; pass by default */
1687 clear_bit(__E1000_TESTING, &adapter->flags);
1689 msleep_interruptible(4 * 1000);
1692 static int e1000_wol_exclusion(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol)
1694 struct e1000_hw *hw = &adapter->hw;
1695 int retval = 1; /* fail by default */
1697 switch (hw->device_id) {
1698 case E1000_DEV_ID_82543GC_FIBER:
1699 case E1000_DEV_ID_82543GC_COPPER:
1700 case E1000_DEV_ID_82544EI_FIBER:
1701 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1702 case E1000_DEV_ID_82545EM_FIBER:
1703 case E1000_DEV_ID_82545EM_COPPER:
1704 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1705 case E1000_DEV_ID_82546GB_PCIE:
1706 /* these don't support WoL at all */
1709 case E1000_DEV_ID_82546EB_FIBER:
1710 case E1000_DEV_ID_82546GB_FIBER:
1711 case E1000_DEV_ID_82571EB_FIBER:
1712 case E1000_DEV_ID_82571EB_SERDES:
1713 case E1000_DEV_ID_82571EB_COPPER:
1714 /* Wake events not supported on port B */
1715 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) {
1719 /* return success for non excluded adapter ports */
1722 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1723 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1724 /* quad port adapters only support WoL on port A */
1725 if (!adapter->quad_port_a) {
1729 /* return success for non excluded adapter ports */
1733 /* dual port cards only support WoL on port A from now on
1734 * unless it was enabled in the eeprom for port B
1735 * so exclude FUNC_1 ports from having WoL enabled */
1736 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1 &&
1737 !adapter->eeprom_wol) {
1749 e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1751 struct e1000_adapter *adapter = netdev_priv(netdev);
1753 wol->supported = WAKE_UCAST | WAKE_MCAST |
1754 WAKE_BCAST | WAKE_MAGIC;
1757 /* this function will set ->supported = 0 and return 1 if wol is not
1758 * supported by this hardware */
1759 if (e1000_wol_exclusion(adapter, wol))
1762 /* apply any specific unsupported masks here */
1763 switch (adapter->hw.device_id) {
1764 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1765 /* KSP3 does not suppport UCAST wake-ups */
1766 wol->supported &= ~WAKE_UCAST;
1768 if (adapter->wol & E1000_WUFC_EX)
1769 DPRINTK(DRV, ERR, "Interface does not support "
1770 "directed (unicast) frame wake-up packets\n");
1776 if (adapter->wol & E1000_WUFC_EX)
1777 wol->wolopts |= WAKE_UCAST;
1778 if (adapter->wol & E1000_WUFC_MC)
1779 wol->wolopts |= WAKE_MCAST;
1780 if (adapter->wol & E1000_WUFC_BC)
1781 wol->wolopts |= WAKE_BCAST;
1782 if (adapter->wol & E1000_WUFC_MAG)
1783 wol->wolopts |= WAKE_MAGIC;
1789 e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1791 struct e1000_adapter *adapter = netdev_priv(netdev);
1792 struct e1000_hw *hw = &adapter->hw;
1794 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1797 if (e1000_wol_exclusion(adapter, wol))
1798 return wol->wolopts ? -EOPNOTSUPP : 0;
1800 switch (hw->device_id) {
1801 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1802 if (wol->wolopts & WAKE_UCAST) {
1803 DPRINTK(DRV, ERR, "Interface does not support "
1804 "directed (unicast) frame wake-up packets\n");
1812 /* these settings will always override what we currently have */
1815 if (wol->wolopts & WAKE_UCAST)
1816 adapter->wol |= E1000_WUFC_EX;
1817 if (wol->wolopts & WAKE_MCAST)
1818 adapter->wol |= E1000_WUFC_MC;
1819 if (wol->wolopts & WAKE_BCAST)
1820 adapter->wol |= E1000_WUFC_BC;
1821 if (wol->wolopts & WAKE_MAGIC)
1822 adapter->wol |= E1000_WUFC_MAG;
1827 /* toggle LED 4 times per second = 2 "blinks" per second */
1828 #define E1000_ID_INTERVAL (HZ/4)
1830 /* bit defines for adapter->led_status */
1831 #define E1000_LED_ON 0
1834 e1000_led_blink_callback(unsigned long data)
1836 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1838 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1839 e1000_led_off(&adapter->hw);
1841 e1000_led_on(&adapter->hw);
1843 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1847 e1000_phys_id(struct net_device *netdev, uint32_t data)
1849 struct e1000_adapter *adapter = netdev_priv(netdev);
1851 if (!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
1852 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
1854 if (adapter->hw.mac_type < e1000_82571) {
1855 if (!adapter->blink_timer.function) {
1856 init_timer(&adapter->blink_timer);
1857 adapter->blink_timer.function = e1000_led_blink_callback;
1858 adapter->blink_timer.data = (unsigned long) adapter;
1860 e1000_setup_led(&adapter->hw);
1861 mod_timer(&adapter->blink_timer, jiffies);
1862 msleep_interruptible(data * 1000);
1863 del_timer_sync(&adapter->blink_timer);
1864 } else if (adapter->hw.phy_type == e1000_phy_ife) {
1865 if (!adapter->blink_timer.function) {
1866 init_timer(&adapter->blink_timer);
1867 adapter->blink_timer.function = e1000_led_blink_callback;
1868 adapter->blink_timer.data = (unsigned long) adapter;
1870 mod_timer(&adapter->blink_timer, jiffies);
1871 msleep_interruptible(data * 1000);
1872 del_timer_sync(&adapter->blink_timer);
1873 e1000_write_phy_reg(&(adapter->hw), IFE_PHY_SPECIAL_CONTROL_LED, 0);
1875 e1000_blink_led_start(&adapter->hw);
1876 msleep_interruptible(data * 1000);
1879 e1000_led_off(&adapter->hw);
1880 clear_bit(E1000_LED_ON, &adapter->led_status);
1881 e1000_cleanup_led(&adapter->hw);
1887 e1000_nway_reset(struct net_device *netdev)
1889 struct e1000_adapter *adapter = netdev_priv(netdev);
1890 if (netif_running(netdev))
1891 e1000_reinit_locked(adapter);
1896 e1000_get_stats_count(struct net_device *netdev)
1898 return E1000_STATS_LEN;
1902 e1000_get_ethtool_stats(struct net_device *netdev,
1903 struct ethtool_stats *stats, uint64_t *data)
1905 struct e1000_adapter *adapter = netdev_priv(netdev);
1908 e1000_update_stats(adapter);
1909 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1910 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1911 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1912 sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
1914 /* BUG_ON(i != E1000_STATS_LEN); */
1918 e1000_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
1923 switch (stringset) {
1925 memcpy(data, *e1000_gstrings_test,
1926 E1000_TEST_LEN*ETH_GSTRING_LEN);
1929 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1930 memcpy(p, e1000_gstrings_stats[i].stat_string,
1932 p += ETH_GSTRING_LEN;
1934 /* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
1939 static const struct ethtool_ops e1000_ethtool_ops = {
1940 .get_settings = e1000_get_settings,
1941 .set_settings = e1000_set_settings,
1942 .get_drvinfo = e1000_get_drvinfo,
1943 .get_regs_len = e1000_get_regs_len,
1944 .get_regs = e1000_get_regs,
1945 .get_wol = e1000_get_wol,
1946 .set_wol = e1000_set_wol,
1947 .get_msglevel = e1000_get_msglevel,
1948 .set_msglevel = e1000_set_msglevel,
1949 .nway_reset = e1000_nway_reset,
1950 .get_link = ethtool_op_get_link,
1951 .get_eeprom_len = e1000_get_eeprom_len,
1952 .get_eeprom = e1000_get_eeprom,
1953 .set_eeprom = e1000_set_eeprom,
1954 .get_ringparam = e1000_get_ringparam,
1955 .set_ringparam = e1000_set_ringparam,
1956 .get_pauseparam = e1000_get_pauseparam,
1957 .set_pauseparam = e1000_set_pauseparam,
1958 .get_rx_csum = e1000_get_rx_csum,
1959 .set_rx_csum = e1000_set_rx_csum,
1960 .get_tx_csum = e1000_get_tx_csum,
1961 .set_tx_csum = e1000_set_tx_csum,
1962 .get_sg = ethtool_op_get_sg,
1963 .set_sg = ethtool_op_set_sg,
1965 .get_tso = ethtool_op_get_tso,
1966 .set_tso = e1000_set_tso,
1968 .self_test_count = e1000_diag_test_count,
1969 .self_test = e1000_diag_test,
1970 .get_strings = e1000_get_strings,
1971 .phys_id = e1000_phys_id,
1972 .get_stats_count = e1000_get_stats_count,
1973 .get_ethtool_stats = e1000_get_ethtool_stats,
1974 .get_perm_addr = ethtool_op_get_perm_addr,
1977 void e1000_set_ethtool_ops(struct net_device *netdev)
1979 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);