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 = ADVERTISED_10baseT_Half |
215 ADVERTISED_10baseT_Full |
216 ADVERTISED_100baseT_Half |
217 ADVERTISED_100baseT_Full |
218 ADVERTISED_1000baseT_Full|
221 ecmd->advertising = hw->autoneg_advertised;
223 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
224 clear_bit(__E1000_RESETTING, &adapter->flags);
230 if (netif_running(adapter->netdev)) {
234 e1000_reset(adapter);
236 clear_bit(__E1000_RESETTING, &adapter->flags);
241 e1000_get_pauseparam(struct net_device *netdev,
242 struct ethtool_pauseparam *pause)
244 struct e1000_adapter *adapter = netdev_priv(netdev);
245 struct e1000_hw *hw = &adapter->hw;
248 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
250 if (hw->fc == E1000_FC_RX_PAUSE)
252 else if (hw->fc == E1000_FC_TX_PAUSE)
254 else if (hw->fc == E1000_FC_FULL) {
261 e1000_set_pauseparam(struct net_device *netdev,
262 struct ethtool_pauseparam *pause)
264 struct e1000_adapter *adapter = netdev_priv(netdev);
265 struct e1000_hw *hw = &adapter->hw;
268 adapter->fc_autoneg = pause->autoneg;
270 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
273 if (pause->rx_pause && pause->tx_pause)
274 hw->fc = E1000_FC_FULL;
275 else if (pause->rx_pause && !pause->tx_pause)
276 hw->fc = E1000_FC_RX_PAUSE;
277 else if (!pause->rx_pause && pause->tx_pause)
278 hw->fc = E1000_FC_TX_PAUSE;
279 else if (!pause->rx_pause && !pause->tx_pause)
280 hw->fc = E1000_FC_NONE;
282 hw->original_fc = hw->fc;
284 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
285 if (netif_running(adapter->netdev)) {
289 e1000_reset(adapter);
291 retval = ((hw->media_type == e1000_media_type_fiber) ?
292 e1000_setup_link(hw) : e1000_force_mac_fc(hw));
294 clear_bit(__E1000_RESETTING, &adapter->flags);
299 e1000_get_rx_csum(struct net_device *netdev)
301 struct e1000_adapter *adapter = netdev_priv(netdev);
302 return adapter->rx_csum;
306 e1000_set_rx_csum(struct net_device *netdev, uint32_t data)
308 struct e1000_adapter *adapter = netdev_priv(netdev);
309 adapter->rx_csum = data;
311 if (netif_running(netdev))
312 e1000_reinit_locked(adapter);
314 e1000_reset(adapter);
319 e1000_get_tx_csum(struct net_device *netdev)
321 return (netdev->features & NETIF_F_HW_CSUM) != 0;
325 e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
327 struct e1000_adapter *adapter = netdev_priv(netdev);
329 if (adapter->hw.mac_type < e1000_82543) {
336 netdev->features |= NETIF_F_HW_CSUM;
338 netdev->features &= ~NETIF_F_HW_CSUM;
345 e1000_set_tso(struct net_device *netdev, uint32_t data)
347 struct e1000_adapter *adapter = netdev_priv(netdev);
348 if ((adapter->hw.mac_type < e1000_82544) ||
349 (adapter->hw.mac_type == e1000_82547))
350 return data ? -EINVAL : 0;
353 netdev->features |= NETIF_F_TSO;
355 netdev->features &= ~NETIF_F_TSO;
357 DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
358 adapter->tso_force = TRUE;
361 #endif /* NETIF_F_TSO */
364 e1000_get_msglevel(struct net_device *netdev)
366 struct e1000_adapter *adapter = netdev_priv(netdev);
367 return adapter->msg_enable;
371 e1000_set_msglevel(struct net_device *netdev, uint32_t data)
373 struct e1000_adapter *adapter = netdev_priv(netdev);
374 adapter->msg_enable = data;
378 e1000_get_regs_len(struct net_device *netdev)
380 #define E1000_REGS_LEN 32
381 return E1000_REGS_LEN * sizeof(uint32_t);
385 e1000_get_regs(struct net_device *netdev,
386 struct ethtool_regs *regs, void *p)
388 struct e1000_adapter *adapter = netdev_priv(netdev);
389 struct e1000_hw *hw = &adapter->hw;
390 uint32_t *regs_buff = p;
393 memset(p, 0, E1000_REGS_LEN * sizeof(uint32_t));
395 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
397 regs_buff[0] = E1000_READ_REG(hw, CTRL);
398 regs_buff[1] = E1000_READ_REG(hw, STATUS);
400 regs_buff[2] = E1000_READ_REG(hw, RCTL);
401 regs_buff[3] = E1000_READ_REG(hw, RDLEN);
402 regs_buff[4] = E1000_READ_REG(hw, RDH);
403 regs_buff[5] = E1000_READ_REG(hw, RDT);
404 regs_buff[6] = E1000_READ_REG(hw, RDTR);
406 regs_buff[7] = E1000_READ_REG(hw, TCTL);
407 regs_buff[8] = E1000_READ_REG(hw, TDLEN);
408 regs_buff[9] = E1000_READ_REG(hw, TDH);
409 regs_buff[10] = E1000_READ_REG(hw, TDT);
410 regs_buff[11] = E1000_READ_REG(hw, TIDV);
412 regs_buff[12] = adapter->hw.phy_type; /* PHY type (IGP=1, M88=0) */
413 if (hw->phy_type == e1000_phy_igp) {
414 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
415 IGP01E1000_PHY_AGC_A);
416 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
417 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
418 regs_buff[13] = (uint32_t)phy_data; /* cable length */
419 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
420 IGP01E1000_PHY_AGC_B);
421 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
422 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
423 regs_buff[14] = (uint32_t)phy_data; /* cable length */
424 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
425 IGP01E1000_PHY_AGC_C);
426 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
427 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
428 regs_buff[15] = (uint32_t)phy_data; /* cable length */
429 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
430 IGP01E1000_PHY_AGC_D);
431 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
432 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
433 regs_buff[16] = (uint32_t)phy_data; /* cable length */
434 regs_buff[17] = 0; /* extended 10bt distance (not needed) */
435 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
436 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
437 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
438 regs_buff[18] = (uint32_t)phy_data; /* cable polarity */
439 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
440 IGP01E1000_PHY_PCS_INIT_REG);
441 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
442 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
443 regs_buff[19] = (uint32_t)phy_data; /* cable polarity */
444 regs_buff[20] = 0; /* polarity correction enabled (always) */
445 regs_buff[22] = 0; /* phy receive errors (unavailable) */
446 regs_buff[23] = regs_buff[18]; /* mdix mode */
447 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
449 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
450 regs_buff[13] = (uint32_t)phy_data; /* cable length */
451 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
452 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
453 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
454 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
455 regs_buff[17] = (uint32_t)phy_data; /* extended 10bt distance */
456 regs_buff[18] = regs_buff[13]; /* cable polarity */
457 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
458 regs_buff[20] = regs_buff[17]; /* polarity correction */
459 /* phy receive errors */
460 regs_buff[22] = adapter->phy_stats.receive_errors;
461 regs_buff[23] = regs_buff[13]; /* mdix mode */
463 regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
464 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
465 regs_buff[24] = (uint32_t)phy_data; /* phy local receiver status */
466 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
467 if (hw->mac_type >= e1000_82540 &&
468 hw->media_type == e1000_media_type_copper) {
469 regs_buff[26] = E1000_READ_REG(hw, MANC);
474 e1000_get_eeprom_len(struct net_device *netdev)
476 struct e1000_adapter *adapter = netdev_priv(netdev);
477 return adapter->hw.eeprom.word_size * 2;
481 e1000_get_eeprom(struct net_device *netdev,
482 struct ethtool_eeprom *eeprom, uint8_t *bytes)
484 struct e1000_adapter *adapter = netdev_priv(netdev);
485 struct e1000_hw *hw = &adapter->hw;
486 uint16_t *eeprom_buff;
487 int first_word, last_word;
491 if (eeprom->len == 0)
494 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
496 first_word = eeprom->offset >> 1;
497 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
499 eeprom_buff = kmalloc(sizeof(uint16_t) *
500 (last_word - first_word + 1), GFP_KERNEL);
504 if (hw->eeprom.type == e1000_eeprom_spi)
505 ret_val = e1000_read_eeprom(hw, first_word,
506 last_word - first_word + 1,
509 for (i = 0; i < last_word - first_word + 1; i++)
510 if ((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
515 /* Device's eeprom is always little-endian, word addressable */
516 for (i = 0; i < last_word - first_word + 1; i++)
517 le16_to_cpus(&eeprom_buff[i]);
519 memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset & 1),
527 e1000_set_eeprom(struct net_device *netdev,
528 struct ethtool_eeprom *eeprom, uint8_t *bytes)
530 struct e1000_adapter *adapter = netdev_priv(netdev);
531 struct e1000_hw *hw = &adapter->hw;
532 uint16_t *eeprom_buff;
534 int max_len, first_word, last_word, ret_val = 0;
537 if (eeprom->len == 0)
540 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
543 max_len = hw->eeprom.word_size * 2;
545 first_word = eeprom->offset >> 1;
546 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
547 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
551 ptr = (void *)eeprom_buff;
553 if (eeprom->offset & 1) {
554 /* need read/modify/write of first changed EEPROM word */
555 /* only the second byte of the word is being modified */
556 ret_val = e1000_read_eeprom(hw, first_word, 1,
560 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
561 /* need read/modify/write of last changed EEPROM word */
562 /* only the first byte of the word is being modified */
563 ret_val = e1000_read_eeprom(hw, last_word, 1,
564 &eeprom_buff[last_word - first_word]);
567 /* Device's eeprom is always little-endian, word addressable */
568 for (i = 0; i < last_word - first_word + 1; i++)
569 le16_to_cpus(&eeprom_buff[i]);
571 memcpy(ptr, bytes, eeprom->len);
573 for (i = 0; i < last_word - first_word + 1; i++)
574 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
576 ret_val = e1000_write_eeprom(hw, first_word,
577 last_word - first_word + 1, eeprom_buff);
579 /* Update the checksum over the first part of the EEPROM if needed
580 * and flush shadow RAM for 82573 conrollers */
581 if ((ret_val == 0) && ((first_word <= EEPROM_CHECKSUM_REG) ||
582 (hw->mac_type == e1000_82573)))
583 e1000_update_eeprom_checksum(hw);
590 e1000_get_drvinfo(struct net_device *netdev,
591 struct ethtool_drvinfo *drvinfo)
593 struct e1000_adapter *adapter = netdev_priv(netdev);
594 char firmware_version[32];
595 uint16_t eeprom_data;
597 strncpy(drvinfo->driver, e1000_driver_name, 32);
598 strncpy(drvinfo->version, e1000_driver_version, 32);
600 /* EEPROM image version # is reported as firmware version # for
601 * 8257{1|2|3} controllers */
602 e1000_read_eeprom(&adapter->hw, 5, 1, &eeprom_data);
603 switch (adapter->hw.mac_type) {
607 case e1000_80003es2lan:
609 sprintf(firmware_version, "%d.%d-%d",
610 (eeprom_data & 0xF000) >> 12,
611 (eeprom_data & 0x0FF0) >> 4,
612 eeprom_data & 0x000F);
615 sprintf(firmware_version, "N/A");
618 strncpy(drvinfo->fw_version, firmware_version, 32);
619 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
620 drvinfo->n_stats = E1000_STATS_LEN;
621 drvinfo->testinfo_len = E1000_TEST_LEN;
622 drvinfo->regdump_len = e1000_get_regs_len(netdev);
623 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
627 e1000_get_ringparam(struct net_device *netdev,
628 struct ethtool_ringparam *ring)
630 struct e1000_adapter *adapter = netdev_priv(netdev);
631 e1000_mac_type mac_type = adapter->hw.mac_type;
632 struct e1000_tx_ring *txdr = adapter->tx_ring;
633 struct e1000_rx_ring *rxdr = adapter->rx_ring;
635 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
637 ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
639 ring->rx_mini_max_pending = 0;
640 ring->rx_jumbo_max_pending = 0;
641 ring->rx_pending = rxdr->count;
642 ring->tx_pending = txdr->count;
643 ring->rx_mini_pending = 0;
644 ring->rx_jumbo_pending = 0;
648 e1000_set_ringparam(struct net_device *netdev,
649 struct ethtool_ringparam *ring)
651 struct e1000_adapter *adapter = netdev_priv(netdev);
652 e1000_mac_type mac_type = adapter->hw.mac_type;
653 struct e1000_tx_ring *txdr, *tx_old, *tx_new;
654 struct e1000_rx_ring *rxdr, *rx_old, *rx_new;
655 int i, err, tx_ring_size, rx_ring_size;
657 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
660 tx_ring_size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
661 rx_ring_size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
663 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
666 if (netif_running(adapter->netdev))
669 tx_old = adapter->tx_ring;
670 rx_old = adapter->rx_ring;
672 adapter->tx_ring = kmalloc(tx_ring_size, GFP_KERNEL);
673 if (!adapter->tx_ring) {
677 memset(adapter->tx_ring, 0, tx_ring_size);
679 adapter->rx_ring = kmalloc(rx_ring_size, GFP_KERNEL);
680 if (!adapter->rx_ring) {
681 kfree(adapter->tx_ring);
685 memset(adapter->rx_ring, 0, rx_ring_size);
687 txdr = adapter->tx_ring;
688 rxdr = adapter->rx_ring;
690 rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD);
691 rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ?
692 E1000_MAX_RXD : E1000_MAX_82544_RXD));
693 E1000_ROUNDUP(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
695 txdr->count = max(ring->tx_pending,(uint32_t)E1000_MIN_TXD);
696 txdr->count = min(txdr->count,(uint32_t)(mac_type < e1000_82544 ?
697 E1000_MAX_TXD : E1000_MAX_82544_TXD));
698 E1000_ROUNDUP(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
700 for (i = 0; i < adapter->num_tx_queues; i++)
701 txdr[i].count = txdr->count;
702 for (i = 0; i < adapter->num_rx_queues; i++)
703 rxdr[i].count = rxdr->count;
705 if (netif_running(adapter->netdev)) {
706 /* Try to get new resources before deleting old */
707 if ((err = e1000_setup_all_rx_resources(adapter)))
709 if ((err = e1000_setup_all_tx_resources(adapter)))
712 /* save the new, restore the old in order to free it,
713 * then restore the new back again */
715 rx_new = adapter->rx_ring;
716 tx_new = adapter->tx_ring;
717 adapter->rx_ring = rx_old;
718 adapter->tx_ring = tx_old;
719 e1000_free_all_rx_resources(adapter);
720 e1000_free_all_tx_resources(adapter);
723 adapter->rx_ring = rx_new;
724 adapter->tx_ring = tx_new;
725 if ((err = e1000_up(adapter)))
729 clear_bit(__E1000_RESETTING, &adapter->flags);
732 e1000_free_all_rx_resources(adapter);
734 adapter->rx_ring = rx_old;
735 adapter->tx_ring = tx_old;
738 clear_bit(__E1000_RESETTING, &adapter->flags);
742 #define REG_PATTERN_TEST(R, M, W) \
744 uint32_t pat, value; \
746 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; \
747 for (pat = 0; pat < sizeof(test)/sizeof(test[0]); pat++) { \
748 E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W)); \
749 value = E1000_READ_REG(&adapter->hw, R); \
750 if (value != (test[pat] & W & M)) { \
751 DPRINTK(DRV, ERR, "pattern test reg %04X failed: got " \
752 "0x%08X expected 0x%08X\n", \
753 E1000_##R, value, (test[pat] & W & M)); \
754 *data = (adapter->hw.mac_type < e1000_82543) ? \
755 E1000_82542_##R : E1000_##R; \
761 #define REG_SET_AND_CHECK(R, M, W) \
764 E1000_WRITE_REG(&adapter->hw, R, W & M); \
765 value = E1000_READ_REG(&adapter->hw, R); \
766 if ((W & M) != (value & M)) { \
767 DPRINTK(DRV, ERR, "set/check reg %04X test failed: got 0x%08X "\
768 "expected 0x%08X\n", E1000_##R, (value & M), (W & M)); \
769 *data = (adapter->hw.mac_type < e1000_82543) ? \
770 E1000_82542_##R : E1000_##R; \
776 e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
778 uint32_t value, before, after;
781 /* The status register is Read Only, so a write should fail.
782 * Some bits that get toggled are ignored.
784 switch (adapter->hw.mac_type) {
785 /* there are several bits on newer hardware that are r/w */
788 case e1000_80003es2lan:
800 before = E1000_READ_REG(&adapter->hw, STATUS);
801 value = (E1000_READ_REG(&adapter->hw, STATUS) & toggle);
802 E1000_WRITE_REG(&adapter->hw, STATUS, toggle);
803 after = E1000_READ_REG(&adapter->hw, STATUS) & toggle;
804 if (value != after) {
805 DPRINTK(DRV, ERR, "failed STATUS register test got: "
806 "0x%08X expected: 0x%08X\n", after, value);
810 /* restore previous status */
811 E1000_WRITE_REG(&adapter->hw, STATUS, before);
812 if (adapter->hw.mac_type != e1000_ich8lan) {
813 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
814 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
815 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
816 REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
818 REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
819 REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
820 REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
821 REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
822 REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
823 REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
824 REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
825 REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
826 REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
827 REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
829 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
830 before = (adapter->hw.mac_type == e1000_ich8lan ?
831 0x06C3B33E : 0x06DFB3FE);
832 REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
833 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
835 if (adapter->hw.mac_type >= e1000_82543) {
837 REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
838 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
839 if (adapter->hw.mac_type != e1000_ich8lan)
840 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
841 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
842 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
843 value = (adapter->hw.mac_type == e1000_ich8lan ?
844 E1000_RAR_ENTRIES_ICH8LAN : E1000_RAR_ENTRIES);
845 for (i = 0; i < value; i++) {
846 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
852 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
853 REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
854 REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
855 REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
859 value = (adapter->hw.mac_type == e1000_ich8lan ?
860 E1000_MC_TBL_SIZE_ICH8LAN : E1000_MC_TBL_SIZE);
861 for (i = 0; i < value; i++)
862 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
869 e1000_eeprom_test(struct e1000_adapter *adapter, uint64_t *data)
872 uint16_t checksum = 0;
876 /* Read and add up the contents of the EEPROM */
877 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
878 if ((e1000_read_eeprom(&adapter->hw, i, 1, &temp)) < 0) {
885 /* If Checksum is not Correct return error else test passed */
886 if ((checksum != (uint16_t) EEPROM_SUM) && !(*data))
893 e1000_test_intr(int irq,
895 struct pt_regs *regs)
897 struct net_device *netdev = (struct net_device *) data;
898 struct e1000_adapter *adapter = netdev_priv(netdev);
900 adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR);
906 e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
908 struct net_device *netdev = adapter->netdev;
909 uint32_t mask, i=0, shared_int = TRUE;
910 uint32_t irq = adapter->pdev->irq;
914 /* NOTE: we don't test MSI interrupts here, yet */
915 /* Hook up test interrupt handler just for this test */
916 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED,
917 netdev->name, netdev))
919 else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
920 netdev->name, netdev)) {
924 DPRINTK(HW, INFO, "testing %s interrupt\n",
925 (shared_int ? "shared" : "unshared"));
927 /* Disable all the interrupts */
928 E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
931 /* Test each interrupt */
932 for (; i < 10; i++) {
934 if (adapter->hw.mac_type == e1000_ich8lan && i == 8)
936 /* Interrupt to test */
940 /* Disable the interrupt to be reported in
941 * the cause register and then force the same
942 * interrupt and see if one gets posted. If
943 * an interrupt was posted to the bus, the
946 adapter->test_icr = 0;
947 E1000_WRITE_REG(&adapter->hw, IMC, mask);
948 E1000_WRITE_REG(&adapter->hw, ICS, mask);
951 if (adapter->test_icr & mask) {
957 /* Enable the interrupt to be reported in
958 * the cause register and then force the same
959 * interrupt and see if one gets posted. If
960 * an interrupt was not posted to the bus, the
963 adapter->test_icr = 0;
964 E1000_WRITE_REG(&adapter->hw, IMS, mask);
965 E1000_WRITE_REG(&adapter->hw, ICS, mask);
968 if (!(adapter->test_icr & mask)) {
974 /* Disable the other interrupts to be reported in
975 * the cause register and then force the other
976 * interrupts and see if any get posted. If
977 * an interrupt was posted to the bus, the
980 adapter->test_icr = 0;
981 E1000_WRITE_REG(&adapter->hw, IMC, ~mask & 0x00007FFF);
982 E1000_WRITE_REG(&adapter->hw, ICS, ~mask & 0x00007FFF);
985 if (adapter->test_icr) {
992 /* Disable all the interrupts */
993 E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
996 /* Unhook test interrupt handler */
997 free_irq(irq, netdev);
1003 e1000_free_desc_rings(struct e1000_adapter *adapter)
1005 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1006 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1007 struct pci_dev *pdev = adapter->pdev;
1010 if (txdr->desc && txdr->buffer_info) {
1011 for (i = 0; i < txdr->count; i++) {
1012 if (txdr->buffer_info[i].dma)
1013 pci_unmap_single(pdev, txdr->buffer_info[i].dma,
1014 txdr->buffer_info[i].length,
1016 if (txdr->buffer_info[i].skb)
1017 dev_kfree_skb(txdr->buffer_info[i].skb);
1021 if (rxdr->desc && rxdr->buffer_info) {
1022 for (i = 0; i < rxdr->count; i++) {
1023 if (rxdr->buffer_info[i].dma)
1024 pci_unmap_single(pdev, rxdr->buffer_info[i].dma,
1025 rxdr->buffer_info[i].length,
1026 PCI_DMA_FROMDEVICE);
1027 if (rxdr->buffer_info[i].skb)
1028 dev_kfree_skb(rxdr->buffer_info[i].skb);
1033 pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
1037 pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
1041 kfree(txdr->buffer_info);
1042 txdr->buffer_info = NULL;
1043 kfree(rxdr->buffer_info);
1044 rxdr->buffer_info = NULL;
1050 e1000_setup_desc_rings(struct e1000_adapter *adapter)
1052 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1053 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1054 struct pci_dev *pdev = adapter->pdev;
1056 int size, i, ret_val;
1058 /* Setup Tx descriptor ring and Tx buffers */
1061 txdr->count = E1000_DEFAULT_TXD;
1063 size = txdr->count * sizeof(struct e1000_buffer);
1064 if (!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
1068 memset(txdr->buffer_info, 0, size);
1070 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1071 E1000_ROUNDUP(txdr->size, 4096);
1072 if (!(txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma))) {
1076 memset(txdr->desc, 0, txdr->size);
1077 txdr->next_to_use = txdr->next_to_clean = 0;
1079 E1000_WRITE_REG(&adapter->hw, TDBAL,
1080 ((uint64_t) txdr->dma & 0x00000000FFFFFFFF));
1081 E1000_WRITE_REG(&adapter->hw, TDBAH, ((uint64_t) txdr->dma >> 32));
1082 E1000_WRITE_REG(&adapter->hw, TDLEN,
1083 txdr->count * sizeof(struct e1000_tx_desc));
1084 E1000_WRITE_REG(&adapter->hw, TDH, 0);
1085 E1000_WRITE_REG(&adapter->hw, TDT, 0);
1086 E1000_WRITE_REG(&adapter->hw, TCTL,
1087 E1000_TCTL_PSP | E1000_TCTL_EN |
1088 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1089 E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1091 for (i = 0; i < txdr->count; i++) {
1092 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
1093 struct sk_buff *skb;
1094 unsigned int size = 1024;
1096 if (!(skb = alloc_skb(size, GFP_KERNEL))) {
1101 txdr->buffer_info[i].skb = skb;
1102 txdr->buffer_info[i].length = skb->len;
1103 txdr->buffer_info[i].dma =
1104 pci_map_single(pdev, skb->data, skb->len,
1106 tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
1107 tx_desc->lower.data = cpu_to_le32(skb->len);
1108 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1109 E1000_TXD_CMD_IFCS |
1111 tx_desc->upper.data = 0;
1114 /* Setup Rx descriptor ring and Rx buffers */
1117 rxdr->count = E1000_DEFAULT_RXD;
1119 size = rxdr->count * sizeof(struct e1000_buffer);
1120 if (!(rxdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
1124 memset(rxdr->buffer_info, 0, size);
1126 rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
1127 if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) {
1131 memset(rxdr->desc, 0, rxdr->size);
1132 rxdr->next_to_use = rxdr->next_to_clean = 0;
1134 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1135 E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN);
1136 E1000_WRITE_REG(&adapter->hw, RDBAL,
1137 ((uint64_t) rxdr->dma & 0xFFFFFFFF));
1138 E1000_WRITE_REG(&adapter->hw, RDBAH, ((uint64_t) rxdr->dma >> 32));
1139 E1000_WRITE_REG(&adapter->hw, RDLEN, rxdr->size);
1140 E1000_WRITE_REG(&adapter->hw, RDH, 0);
1141 E1000_WRITE_REG(&adapter->hw, RDT, 0);
1142 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1143 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1144 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1145 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1147 for (i = 0; i < rxdr->count; i++) {
1148 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
1149 struct sk_buff *skb;
1151 if (!(skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN,
1156 skb_reserve(skb, NET_IP_ALIGN);
1157 rxdr->buffer_info[i].skb = skb;
1158 rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
1159 rxdr->buffer_info[i].dma =
1160 pci_map_single(pdev, skb->data, E1000_RXBUFFER_2048,
1161 PCI_DMA_FROMDEVICE);
1162 rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
1163 memset(skb->data, 0x00, skb->len);
1169 e1000_free_desc_rings(adapter);
1174 e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1176 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1177 e1000_write_phy_reg(&adapter->hw, 29, 0x001F);
1178 e1000_write_phy_reg(&adapter->hw, 30, 0x8FFC);
1179 e1000_write_phy_reg(&adapter->hw, 29, 0x001A);
1180 e1000_write_phy_reg(&adapter->hw, 30, 0x8FF0);
1184 e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
1188 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1189 * Extended PHY Specific Control Register to 25MHz clock. This
1190 * value defaults back to a 2.5MHz clock when the PHY is reset.
1192 e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
1193 phy_reg |= M88E1000_EPSCR_TX_CLK_25;
1194 e1000_write_phy_reg(&adapter->hw,
1195 M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
1197 /* In addition, because of the s/w reset above, we need to enable
1198 * CRS on TX. This must be set for both full and half duplex
1201 e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
1202 phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1203 e1000_write_phy_reg(&adapter->hw,
1204 M88E1000_PHY_SPEC_CTRL, phy_reg);
1208 e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
1213 /* Setup the Device Control Register for PHY loopback test. */
1215 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1216 ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */
1217 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1218 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1219 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
1220 E1000_CTRL_FD); /* Force Duplex to FULL */
1222 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg);
1224 /* Read the PHY Specific Control Register (0x10) */
1225 e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
1227 /* Clear Auto-Crossover bits in PHY Specific Control Register
1230 phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
1231 e1000_write_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
1233 /* Perform software reset on the PHY */
1234 e1000_phy_reset(&adapter->hw);
1236 /* Have to setup TX_CLK and TX_CRS after software reset */
1237 e1000_phy_reset_clk_and_crs(adapter);
1239 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8100);
1241 /* Wait for reset to complete. */
1244 /* Have to setup TX_CLK and TX_CRS after software reset */
1245 e1000_phy_reset_clk_and_crs(adapter);
1247 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1248 e1000_phy_disable_receiver(adapter);
1250 /* Set the loopback bit in the PHY control register. */
1251 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1252 phy_reg |= MII_CR_LOOPBACK;
1253 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
1255 /* Setup TX_CLK and TX_CRS one more time. */
1256 e1000_phy_reset_clk_and_crs(adapter);
1258 /* Check Phy Configuration */
1259 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1260 if (phy_reg != 0x4100)
1263 e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
1264 if (phy_reg != 0x0070)
1267 e1000_read_phy_reg(&adapter->hw, 29, &phy_reg);
1268 if (phy_reg != 0x001A)
1275 e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1277 uint32_t ctrl_reg = 0;
1278 uint32_t stat_reg = 0;
1280 adapter->hw.autoneg = FALSE;
1282 if (adapter->hw.phy_type == e1000_phy_m88) {
1283 /* Auto-MDI/MDIX Off */
1284 e1000_write_phy_reg(&adapter->hw,
1285 M88E1000_PHY_SPEC_CTRL, 0x0808);
1286 /* reset to update Auto-MDI/MDIX */
1287 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x9140);
1289 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8140);
1290 } else if (adapter->hw.phy_type == e1000_phy_gg82563)
1291 e1000_write_phy_reg(&adapter->hw,
1292 GG82563_PHY_KMRN_MODE_CTRL,
1295 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1297 if (adapter->hw.phy_type == e1000_phy_ife) {
1298 /* force 100, set loopback */
1299 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x6100);
1301 /* Now set up the MAC to the same speed/duplex as the PHY. */
1302 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1303 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1304 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1305 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1306 E1000_CTRL_FD); /* Force Duplex to FULL */
1308 /* force 1000, set loopback */
1309 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x4140);
1311 /* Now set up the MAC to the same speed/duplex as the PHY. */
1312 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1313 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1314 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1315 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1316 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1317 E1000_CTRL_FD); /* Force Duplex to FULL */
1320 if (adapter->hw.media_type == e1000_media_type_copper &&
1321 adapter->hw.phy_type == e1000_phy_m88)
1322 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1324 /* Set the ILOS bit on the fiber Nic is half
1325 * duplex link is detected. */
1326 stat_reg = E1000_READ_REG(&adapter->hw, STATUS);
1327 if ((stat_reg & E1000_STATUS_FD) == 0)
1328 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1331 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg);
1333 /* Disable the receiver on the PHY so when a cable is plugged in, the
1334 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1336 if (adapter->hw.phy_type == e1000_phy_m88)
1337 e1000_phy_disable_receiver(adapter);
1345 e1000_set_phy_loopback(struct e1000_adapter *adapter)
1347 uint16_t phy_reg = 0;
1350 switch (adapter->hw.mac_type) {
1352 if (adapter->hw.media_type == e1000_media_type_copper) {
1353 /* Attempt to setup Loopback mode on Non-integrated PHY.
1354 * Some PHY registers get corrupted at random, so
1355 * attempt this 10 times.
1357 while (e1000_nonintegrated_phy_loopback(adapter) &&
1367 case e1000_82545_rev_3:
1369 case e1000_82546_rev_3:
1371 case e1000_82541_rev_2:
1373 case e1000_82547_rev_2:
1377 case e1000_80003es2lan:
1379 return e1000_integrated_phy_loopback(adapter);
1383 /* Default PHY loopback work is to read the MII
1384 * control register and assert bit 14 (loopback mode).
1386 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1387 phy_reg |= MII_CR_LOOPBACK;
1388 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
1397 e1000_setup_loopback_test(struct e1000_adapter *adapter)
1399 struct e1000_hw *hw = &adapter->hw;
1402 if (hw->media_type == e1000_media_type_fiber ||
1403 hw->media_type == e1000_media_type_internal_serdes) {
1404 switch (hw->mac_type) {
1407 case e1000_82545_rev_3:
1408 case e1000_82546_rev_3:
1409 return e1000_set_phy_loopback(adapter);
1413 #define E1000_SERDES_LB_ON 0x410
1414 e1000_set_phy_loopback(adapter);
1415 E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_ON);
1420 rctl = E1000_READ_REG(hw, RCTL);
1421 rctl |= E1000_RCTL_LBM_TCVR;
1422 E1000_WRITE_REG(hw, RCTL, rctl);
1425 } else if (hw->media_type == e1000_media_type_copper)
1426 return e1000_set_phy_loopback(adapter);
1432 e1000_loopback_cleanup(struct e1000_adapter *adapter)
1434 struct e1000_hw *hw = &adapter->hw;
1438 rctl = E1000_READ_REG(hw, RCTL);
1439 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1440 E1000_WRITE_REG(hw, RCTL, rctl);
1442 switch (hw->mac_type) {
1445 if (hw->media_type == e1000_media_type_fiber ||
1446 hw->media_type == e1000_media_type_internal_serdes) {
1447 #define E1000_SERDES_LB_OFF 0x400
1448 E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_OFF);
1455 case e1000_82545_rev_3:
1456 case e1000_82546_rev_3:
1459 if (hw->phy_type == e1000_phy_gg82563)
1460 e1000_write_phy_reg(hw,
1461 GG82563_PHY_KMRN_MODE_CTRL,
1463 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
1464 if (phy_reg & MII_CR_LOOPBACK) {
1465 phy_reg &= ~MII_CR_LOOPBACK;
1466 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
1467 e1000_phy_reset(hw);
1474 e1000_create_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1476 memset(skb->data, 0xFF, frame_size);
1478 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1479 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1480 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1484 e1000_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1487 if (*(skb->data + 3) == 0xFF) {
1488 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1489 (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
1497 e1000_run_loopback_test(struct e1000_adapter *adapter)
1499 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1500 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1501 struct pci_dev *pdev = adapter->pdev;
1502 int i, j, k, l, lc, good_cnt, ret_val=0;
1505 E1000_WRITE_REG(&adapter->hw, RDT, rxdr->count - 1);
1507 /* Calculate the loop count based on the largest descriptor ring
1508 * The idea is to wrap the largest ring a number of times using 64
1509 * send/receive pairs during each loop
1512 if (rxdr->count <= txdr->count)
1513 lc = ((txdr->count / 64) * 2) + 1;
1515 lc = ((rxdr->count / 64) * 2) + 1;
1518 for (j = 0; j <= lc; j++) { /* loop count loop */
1519 for (i = 0; i < 64; i++) { /* send the packets */
1520 e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
1522 pci_dma_sync_single_for_device(pdev,
1523 txdr->buffer_info[k].dma,
1524 txdr->buffer_info[k].length,
1526 if (unlikely(++k == txdr->count)) k = 0;
1528 E1000_WRITE_REG(&adapter->hw, TDT, k);
1530 time = jiffies; /* set the start time for the receive */
1532 do { /* receive the sent packets */
1533 pci_dma_sync_single_for_cpu(pdev,
1534 rxdr->buffer_info[l].dma,
1535 rxdr->buffer_info[l].length,
1536 PCI_DMA_FROMDEVICE);
1538 ret_val = e1000_check_lbtest_frame(
1539 rxdr->buffer_info[l].skb,
1543 if (unlikely(++l == rxdr->count)) l = 0;
1544 /* time + 20 msecs (200 msecs on 2.4) is more than
1545 * enough time to complete the receives, if it's
1546 * exceeded, break and error off
1548 } while (good_cnt < 64 && jiffies < (time + 20));
1549 if (good_cnt != 64) {
1550 ret_val = 13; /* ret_val is the same as mis-compare */
1553 if (jiffies >= (time + 2)) {
1554 ret_val = 14; /* error code for time out error */
1557 } /* end loop count loop */
1562 e1000_loopback_test(struct e1000_adapter *adapter, uint64_t *data)
1564 /* PHY loopback cannot be performed if SoL/IDER
1565 * sessions are active */
1566 if (e1000_check_phy_reset_block(&adapter->hw)) {
1567 DPRINTK(DRV, ERR, "Cannot do PHY loopback test "
1568 "when SoL/IDER is active.\n");
1573 if ((*data = e1000_setup_desc_rings(adapter)))
1575 if ((*data = e1000_setup_loopback_test(adapter)))
1577 *data = e1000_run_loopback_test(adapter);
1578 e1000_loopback_cleanup(adapter);
1581 e1000_free_desc_rings(adapter);
1587 e1000_link_test(struct e1000_adapter *adapter, uint64_t *data)
1590 if (adapter->hw.media_type == e1000_media_type_internal_serdes) {
1592 adapter->hw.serdes_link_down = TRUE;
1594 /* On some blade server designs, link establishment
1595 * could take as long as 2-3 minutes */
1597 e1000_check_for_link(&adapter->hw);
1598 if (adapter->hw.serdes_link_down == FALSE)
1601 } while (i++ < 3750);
1605 e1000_check_for_link(&adapter->hw);
1606 if (adapter->hw.autoneg) /* if auto_neg is set wait for it */
1609 if (!(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU)) {
1617 e1000_diag_test_count(struct net_device *netdev)
1619 return E1000_TEST_LEN;
1622 extern void e1000_power_up_phy(struct e1000_adapter *);
1625 e1000_diag_test(struct net_device *netdev,
1626 struct ethtool_test *eth_test, uint64_t *data)
1628 struct e1000_adapter *adapter = netdev_priv(netdev);
1629 boolean_t if_running = netif_running(netdev);
1631 set_bit(__E1000_DRIVER_TESTING, &adapter->flags);
1632 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1635 /* save speed, duplex, autoneg settings */
1636 uint16_t autoneg_advertised = adapter->hw.autoneg_advertised;
1637 uint8_t forced_speed_duplex = adapter->hw.forced_speed_duplex;
1638 uint8_t autoneg = adapter->hw.autoneg;
1640 DPRINTK(HW, INFO, "offline testing starting\n");
1642 /* Link test performed before hardware reset so autoneg doesn't
1643 * interfere with test result */
1644 if (e1000_link_test(adapter, &data[4]))
1645 eth_test->flags |= ETH_TEST_FL_FAILED;
1648 /* indicate we're in test mode */
1651 e1000_reset(adapter);
1653 if (e1000_reg_test(adapter, &data[0]))
1654 eth_test->flags |= ETH_TEST_FL_FAILED;
1656 e1000_reset(adapter);
1657 if (e1000_eeprom_test(adapter, &data[1]))
1658 eth_test->flags |= ETH_TEST_FL_FAILED;
1660 e1000_reset(adapter);
1661 if (e1000_intr_test(adapter, &data[2]))
1662 eth_test->flags |= ETH_TEST_FL_FAILED;
1664 e1000_reset(adapter);
1665 /* make sure the phy is powered up */
1666 e1000_power_up_phy(adapter);
1667 if (e1000_loopback_test(adapter, &data[3]))
1668 eth_test->flags |= ETH_TEST_FL_FAILED;
1670 /* restore speed, duplex, autoneg settings */
1671 adapter->hw.autoneg_advertised = autoneg_advertised;
1672 adapter->hw.forced_speed_duplex = forced_speed_duplex;
1673 adapter->hw.autoneg = autoneg;
1675 e1000_reset(adapter);
1676 clear_bit(__E1000_DRIVER_TESTING, &adapter->flags);
1680 DPRINTK(HW, INFO, "online testing starting\n");
1682 if (e1000_link_test(adapter, &data[4]))
1683 eth_test->flags |= ETH_TEST_FL_FAILED;
1685 /* Offline tests aren't run; pass by default */
1691 clear_bit(__E1000_DRIVER_TESTING, &adapter->flags);
1693 msleep_interruptible(4 * 1000);
1696 static int e1000_wol_exclusion(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol)
1698 struct e1000_hw *hw = &adapter->hw;
1699 int retval = 1; /* fail by default */
1701 switch (hw->device_id) {
1702 case E1000_DEV_ID_82543GC_FIBER:
1703 case E1000_DEV_ID_82543GC_COPPER:
1704 case E1000_DEV_ID_82544EI_FIBER:
1705 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1706 case E1000_DEV_ID_82545EM_FIBER:
1707 case E1000_DEV_ID_82545EM_COPPER:
1708 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1709 case E1000_DEV_ID_82546GB_PCIE:
1710 /* these don't support WoL at all */
1713 case E1000_DEV_ID_82546EB_FIBER:
1714 case E1000_DEV_ID_82546GB_FIBER:
1715 case E1000_DEV_ID_82571EB_FIBER:
1716 case E1000_DEV_ID_82571EB_SERDES:
1717 case E1000_DEV_ID_82571EB_COPPER:
1718 /* Wake events not supported on port B */
1719 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) {
1723 /* return success for non excluded adapter ports */
1726 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1727 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1728 /* quad port adapters only support WoL on port A */
1729 if (!adapter->quad_port_a) {
1733 /* return success for non excluded adapter ports */
1737 /* dual port cards only support WoL on port A from now on
1738 * unless it was enabled in the eeprom for port B
1739 * so exclude FUNC_1 ports from having WoL enabled */
1740 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1 &&
1741 !adapter->eeprom_wol) {
1753 e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1755 struct e1000_adapter *adapter = netdev_priv(netdev);
1757 wol->supported = WAKE_UCAST | WAKE_MCAST |
1758 WAKE_BCAST | WAKE_MAGIC;
1761 /* this function will set ->supported = 0 and return 1 if wol is not
1762 * supported by this hardware */
1763 if (e1000_wol_exclusion(adapter, wol))
1766 /* apply any specific unsupported masks here */
1767 switch (adapter->hw.device_id) {
1768 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1769 /* KSP3 does not suppport UCAST wake-ups */
1770 wol->supported &= ~WAKE_UCAST;
1772 if (adapter->wol & E1000_WUFC_EX)
1773 DPRINTK(DRV, ERR, "Interface does not support "
1774 "directed (unicast) frame wake-up packets\n");
1780 if (adapter->wol & E1000_WUFC_EX)
1781 wol->wolopts |= WAKE_UCAST;
1782 if (adapter->wol & E1000_WUFC_MC)
1783 wol->wolopts |= WAKE_MCAST;
1784 if (adapter->wol & E1000_WUFC_BC)
1785 wol->wolopts |= WAKE_BCAST;
1786 if (adapter->wol & E1000_WUFC_MAG)
1787 wol->wolopts |= WAKE_MAGIC;
1793 e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1795 struct e1000_adapter *adapter = netdev_priv(netdev);
1796 struct e1000_hw *hw = &adapter->hw;
1798 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1801 if (e1000_wol_exclusion(adapter, wol))
1802 return wol->wolopts ? -EOPNOTSUPP : 0;
1804 switch (hw->device_id) {
1805 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1806 if (wol->wolopts & WAKE_UCAST) {
1807 DPRINTK(DRV, ERR, "Interface does not support "
1808 "directed (unicast) frame wake-up packets\n");
1816 /* these settings will always override what we currently have */
1819 if (wol->wolopts & WAKE_UCAST)
1820 adapter->wol |= E1000_WUFC_EX;
1821 if (wol->wolopts & WAKE_MCAST)
1822 adapter->wol |= E1000_WUFC_MC;
1823 if (wol->wolopts & WAKE_BCAST)
1824 adapter->wol |= E1000_WUFC_BC;
1825 if (wol->wolopts & WAKE_MAGIC)
1826 adapter->wol |= E1000_WUFC_MAG;
1831 /* toggle LED 4 times per second = 2 "blinks" per second */
1832 #define E1000_ID_INTERVAL (HZ/4)
1834 /* bit defines for adapter->led_status */
1835 #define E1000_LED_ON 0
1838 e1000_led_blink_callback(unsigned long data)
1840 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1842 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1843 e1000_led_off(&adapter->hw);
1845 e1000_led_on(&adapter->hw);
1847 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1851 e1000_phys_id(struct net_device *netdev, uint32_t data)
1853 struct e1000_adapter *adapter = netdev_priv(netdev);
1855 if (!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
1856 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
1858 if (adapter->hw.mac_type < e1000_82571) {
1859 if (!adapter->blink_timer.function) {
1860 init_timer(&adapter->blink_timer);
1861 adapter->blink_timer.function = e1000_led_blink_callback;
1862 adapter->blink_timer.data = (unsigned long) adapter;
1864 e1000_setup_led(&adapter->hw);
1865 mod_timer(&adapter->blink_timer, jiffies);
1866 msleep_interruptible(data * 1000);
1867 del_timer_sync(&adapter->blink_timer);
1868 } else if (adapter->hw.phy_type == e1000_phy_ife) {
1869 if (!adapter->blink_timer.function) {
1870 init_timer(&adapter->blink_timer);
1871 adapter->blink_timer.function = e1000_led_blink_callback;
1872 adapter->blink_timer.data = (unsigned long) adapter;
1874 mod_timer(&adapter->blink_timer, jiffies);
1875 msleep_interruptible(data * 1000);
1876 del_timer_sync(&adapter->blink_timer);
1877 e1000_write_phy_reg(&(adapter->hw), IFE_PHY_SPECIAL_CONTROL_LED, 0);
1879 e1000_blink_led_start(&adapter->hw);
1880 msleep_interruptible(data * 1000);
1883 e1000_led_off(&adapter->hw);
1884 clear_bit(E1000_LED_ON, &adapter->led_status);
1885 e1000_cleanup_led(&adapter->hw);
1891 e1000_nway_reset(struct net_device *netdev)
1893 struct e1000_adapter *adapter = netdev_priv(netdev);
1894 if (netif_running(netdev))
1895 e1000_reinit_locked(adapter);
1900 e1000_get_stats_count(struct net_device *netdev)
1902 return E1000_STATS_LEN;
1906 e1000_get_ethtool_stats(struct net_device *netdev,
1907 struct ethtool_stats *stats, uint64_t *data)
1909 struct e1000_adapter *adapter = netdev_priv(netdev);
1912 e1000_update_stats(adapter);
1913 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1914 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1915 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1916 sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
1918 /* BUG_ON(i != E1000_STATS_LEN); */
1922 e1000_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
1927 switch (stringset) {
1929 memcpy(data, *e1000_gstrings_test,
1930 E1000_TEST_LEN*ETH_GSTRING_LEN);
1933 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1934 memcpy(p, e1000_gstrings_stats[i].stat_string,
1936 p += ETH_GSTRING_LEN;
1938 /* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
1943 static const struct ethtool_ops e1000_ethtool_ops = {
1944 .get_settings = e1000_get_settings,
1945 .set_settings = e1000_set_settings,
1946 .get_drvinfo = e1000_get_drvinfo,
1947 .get_regs_len = e1000_get_regs_len,
1948 .get_regs = e1000_get_regs,
1949 .get_wol = e1000_get_wol,
1950 .set_wol = e1000_set_wol,
1951 .get_msglevel = e1000_get_msglevel,
1952 .set_msglevel = e1000_set_msglevel,
1953 .nway_reset = e1000_nway_reset,
1954 .get_link = ethtool_op_get_link,
1955 .get_eeprom_len = e1000_get_eeprom_len,
1956 .get_eeprom = e1000_get_eeprom,
1957 .set_eeprom = e1000_set_eeprom,
1958 .get_ringparam = e1000_get_ringparam,
1959 .set_ringparam = e1000_set_ringparam,
1960 .get_pauseparam = e1000_get_pauseparam,
1961 .set_pauseparam = e1000_set_pauseparam,
1962 .get_rx_csum = e1000_get_rx_csum,
1963 .set_rx_csum = e1000_set_rx_csum,
1964 .get_tx_csum = e1000_get_tx_csum,
1965 .set_tx_csum = e1000_set_tx_csum,
1966 .get_sg = ethtool_op_get_sg,
1967 .set_sg = ethtool_op_set_sg,
1969 .get_tso = ethtool_op_get_tso,
1970 .set_tso = e1000_set_tso,
1972 .self_test_count = e1000_diag_test_count,
1973 .self_test = e1000_diag_test,
1974 .get_strings = e1000_get_strings,
1975 .phys_id = e1000_phys_id,
1976 .get_stats_count = e1000_get_stats_count,
1977 .get_ethtool_stats = e1000_get_ethtool_stats,
1978 .get_perm_addr = ethtool_op_get_perm_addr,
1981 void e1000_set_ethtool_ops(struct net_device *netdev)
1983 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);