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 { "tx_restart_queue", E1000_STAT(restart_queue) },
89 { "rx_long_length_errors", E1000_STAT(stats.roc) },
90 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
91 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
92 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
93 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
94 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
95 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
96 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
97 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
98 { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
99 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
100 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
101 { "rx_header_split", E1000_STAT(rx_hdr_split) },
102 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
103 { "tx_smbus", E1000_STAT(stats.mgptc) },
104 { "rx_smbus", E1000_STAT(stats.mgprc) },
105 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
108 #define E1000_QUEUE_STATS_LEN 0
109 #define E1000_GLOBAL_STATS_LEN \
110 sizeof(e1000_gstrings_stats) / sizeof(struct e1000_stats)
111 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
112 static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
113 "Register test (offline)", "Eeprom test (offline)",
114 "Interrupt test (offline)", "Loopback test (offline)",
115 "Link test (on/offline)"
117 #define E1000_TEST_LEN sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN
120 e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
122 struct e1000_adapter *adapter = netdev_priv(netdev);
123 struct e1000_hw *hw = &adapter->hw;
125 if (hw->media_type == e1000_media_type_copper) {
127 ecmd->supported = (SUPPORTED_10baseT_Half |
128 SUPPORTED_10baseT_Full |
129 SUPPORTED_100baseT_Half |
130 SUPPORTED_100baseT_Full |
131 SUPPORTED_1000baseT_Full|
134 if (hw->phy_type == e1000_phy_ife)
135 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
136 ecmd->advertising = ADVERTISED_TP;
138 if (hw->autoneg == 1) {
139 ecmd->advertising |= ADVERTISED_Autoneg;
140 /* the e1000 autoneg seems to match ethtool nicely */
141 ecmd->advertising |= hw->autoneg_advertised;
144 ecmd->port = PORT_TP;
145 ecmd->phy_address = hw->phy_addr;
147 if (hw->mac_type == e1000_82543)
148 ecmd->transceiver = XCVR_EXTERNAL;
150 ecmd->transceiver = XCVR_INTERNAL;
153 ecmd->supported = (SUPPORTED_1000baseT_Full |
157 ecmd->advertising = (ADVERTISED_1000baseT_Full |
161 ecmd->port = PORT_FIBRE;
163 if (hw->mac_type >= e1000_82545)
164 ecmd->transceiver = XCVR_INTERNAL;
166 ecmd->transceiver = XCVR_EXTERNAL;
169 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU) {
171 e1000_get_speed_and_duplex(hw, &adapter->link_speed,
172 &adapter->link_duplex);
173 ecmd->speed = adapter->link_speed;
175 /* unfortunatly FULL_DUPLEX != DUPLEX_FULL
176 * and HALF_DUPLEX != DUPLEX_HALF */
178 if (adapter->link_duplex == FULL_DUPLEX)
179 ecmd->duplex = DUPLEX_FULL;
181 ecmd->duplex = DUPLEX_HALF;
187 ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
188 hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
193 e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
195 struct e1000_adapter *adapter = netdev_priv(netdev);
196 struct e1000_hw *hw = &adapter->hw;
198 /* When SoL/IDER sessions are active, autoneg/speed/duplex
199 * cannot be changed */
200 if (e1000_check_phy_reset_block(hw)) {
201 DPRINTK(DRV, ERR, "Cannot change link characteristics "
202 "when SoL/IDER is active.\n");
206 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
209 if (ecmd->autoneg == AUTONEG_ENABLE) {
211 if (hw->media_type == e1000_media_type_fiber)
212 hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
216 hw->autoneg_advertised = ecmd->advertising |
219 ecmd->advertising = hw->autoneg_advertised;
221 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
222 clear_bit(__E1000_RESETTING, &adapter->flags);
228 if (netif_running(adapter->netdev)) {
232 e1000_reset(adapter);
234 clear_bit(__E1000_RESETTING, &adapter->flags);
239 e1000_get_pauseparam(struct net_device *netdev,
240 struct ethtool_pauseparam *pause)
242 struct e1000_adapter *adapter = netdev_priv(netdev);
243 struct e1000_hw *hw = &adapter->hw;
246 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
248 if (hw->fc == E1000_FC_RX_PAUSE)
250 else if (hw->fc == E1000_FC_TX_PAUSE)
252 else if (hw->fc == E1000_FC_FULL) {
259 e1000_set_pauseparam(struct net_device *netdev,
260 struct ethtool_pauseparam *pause)
262 struct e1000_adapter *adapter = netdev_priv(netdev);
263 struct e1000_hw *hw = &adapter->hw;
266 adapter->fc_autoneg = pause->autoneg;
268 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
271 if (pause->rx_pause && pause->tx_pause)
272 hw->fc = E1000_FC_FULL;
273 else if (pause->rx_pause && !pause->tx_pause)
274 hw->fc = E1000_FC_RX_PAUSE;
275 else if (!pause->rx_pause && pause->tx_pause)
276 hw->fc = E1000_FC_TX_PAUSE;
277 else if (!pause->rx_pause && !pause->tx_pause)
278 hw->fc = E1000_FC_NONE;
280 hw->original_fc = hw->fc;
282 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
283 if (netif_running(adapter->netdev)) {
287 e1000_reset(adapter);
289 retval = ((hw->media_type == e1000_media_type_fiber) ?
290 e1000_setup_link(hw) : e1000_force_mac_fc(hw));
292 clear_bit(__E1000_RESETTING, &adapter->flags);
297 e1000_get_rx_csum(struct net_device *netdev)
299 struct e1000_adapter *adapter = netdev_priv(netdev);
300 return adapter->rx_csum;
304 e1000_set_rx_csum(struct net_device *netdev, uint32_t data)
306 struct e1000_adapter *adapter = netdev_priv(netdev);
307 adapter->rx_csum = data;
309 if (netif_running(netdev))
310 e1000_reinit_locked(adapter);
312 e1000_reset(adapter);
317 e1000_get_tx_csum(struct net_device *netdev)
319 return (netdev->features & NETIF_F_HW_CSUM) != 0;
323 e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
325 struct e1000_adapter *adapter = netdev_priv(netdev);
327 if (adapter->hw.mac_type < e1000_82543) {
334 netdev->features |= NETIF_F_HW_CSUM;
336 netdev->features &= ~NETIF_F_HW_CSUM;
342 e1000_set_tso(struct net_device *netdev, uint32_t data)
344 struct e1000_adapter *adapter = netdev_priv(netdev);
345 if ((adapter->hw.mac_type < e1000_82544) ||
346 (adapter->hw.mac_type == e1000_82547))
347 return data ? -EINVAL : 0;
350 netdev->features |= NETIF_F_TSO;
352 netdev->features &= ~NETIF_F_TSO;
355 netdev->features |= NETIF_F_TSO6;
357 netdev->features &= ~NETIF_F_TSO6;
359 DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
360 adapter->tso_force = TRUE;
365 e1000_get_msglevel(struct net_device *netdev)
367 struct e1000_adapter *adapter = netdev_priv(netdev);
368 return adapter->msg_enable;
372 e1000_set_msglevel(struct net_device *netdev, uint32_t data)
374 struct e1000_adapter *adapter = netdev_priv(netdev);
375 adapter->msg_enable = data;
379 e1000_get_regs_len(struct net_device *netdev)
381 #define E1000_REGS_LEN 32
382 return E1000_REGS_LEN * sizeof(uint32_t);
386 e1000_get_regs(struct net_device *netdev,
387 struct ethtool_regs *regs, void *p)
389 struct e1000_adapter *adapter = netdev_priv(netdev);
390 struct e1000_hw *hw = &adapter->hw;
391 uint32_t *regs_buff = p;
394 memset(p, 0, E1000_REGS_LEN * sizeof(uint32_t));
396 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
398 regs_buff[0] = E1000_READ_REG(hw, CTRL);
399 regs_buff[1] = E1000_READ_REG(hw, STATUS);
401 regs_buff[2] = E1000_READ_REG(hw, RCTL);
402 regs_buff[3] = E1000_READ_REG(hw, RDLEN);
403 regs_buff[4] = E1000_READ_REG(hw, RDH);
404 regs_buff[5] = E1000_READ_REG(hw, RDT);
405 regs_buff[6] = E1000_READ_REG(hw, RDTR);
407 regs_buff[7] = E1000_READ_REG(hw, TCTL);
408 regs_buff[8] = E1000_READ_REG(hw, TDLEN);
409 regs_buff[9] = E1000_READ_REG(hw, TDH);
410 regs_buff[10] = E1000_READ_REG(hw, TDT);
411 regs_buff[11] = E1000_READ_REG(hw, TIDV);
413 regs_buff[12] = adapter->hw.phy_type; /* PHY type (IGP=1, M88=0) */
414 if (hw->phy_type == e1000_phy_igp) {
415 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
416 IGP01E1000_PHY_AGC_A);
417 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
418 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
419 regs_buff[13] = (uint32_t)phy_data; /* cable length */
420 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
421 IGP01E1000_PHY_AGC_B);
422 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
423 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
424 regs_buff[14] = (uint32_t)phy_data; /* cable length */
425 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
426 IGP01E1000_PHY_AGC_C);
427 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
428 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
429 regs_buff[15] = (uint32_t)phy_data; /* cable length */
430 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
431 IGP01E1000_PHY_AGC_D);
432 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
433 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
434 regs_buff[16] = (uint32_t)phy_data; /* cable length */
435 regs_buff[17] = 0; /* extended 10bt distance (not needed) */
436 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
437 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
438 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
439 regs_buff[18] = (uint32_t)phy_data; /* cable polarity */
440 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
441 IGP01E1000_PHY_PCS_INIT_REG);
442 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
443 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
444 regs_buff[19] = (uint32_t)phy_data; /* cable polarity */
445 regs_buff[20] = 0; /* polarity correction enabled (always) */
446 regs_buff[22] = 0; /* phy receive errors (unavailable) */
447 regs_buff[23] = regs_buff[18]; /* mdix mode */
448 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
450 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
451 regs_buff[13] = (uint32_t)phy_data; /* cable length */
452 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
453 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
454 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
455 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
456 regs_buff[17] = (uint32_t)phy_data; /* extended 10bt distance */
457 regs_buff[18] = regs_buff[13]; /* cable polarity */
458 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
459 regs_buff[20] = regs_buff[17]; /* polarity correction */
460 /* phy receive errors */
461 regs_buff[22] = adapter->phy_stats.receive_errors;
462 regs_buff[23] = regs_buff[13]; /* mdix mode */
464 regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
465 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
466 regs_buff[24] = (uint32_t)phy_data; /* phy local receiver status */
467 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
468 if (hw->mac_type >= e1000_82540 &&
469 hw->mac_type < e1000_82571 &&
470 hw->media_type == e1000_media_type_copper) {
471 regs_buff[26] = E1000_READ_REG(hw, MANC);
476 e1000_get_eeprom_len(struct net_device *netdev)
478 struct e1000_adapter *adapter = netdev_priv(netdev);
479 return adapter->hw.eeprom.word_size * 2;
483 e1000_get_eeprom(struct net_device *netdev,
484 struct ethtool_eeprom *eeprom, uint8_t *bytes)
486 struct e1000_adapter *adapter = netdev_priv(netdev);
487 struct e1000_hw *hw = &adapter->hw;
488 uint16_t *eeprom_buff;
489 int first_word, last_word;
493 if (eeprom->len == 0)
496 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
498 first_word = eeprom->offset >> 1;
499 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
501 eeprom_buff = kmalloc(sizeof(uint16_t) *
502 (last_word - first_word + 1), GFP_KERNEL);
506 if (hw->eeprom.type == e1000_eeprom_spi)
507 ret_val = e1000_read_eeprom(hw, first_word,
508 last_word - first_word + 1,
511 for (i = 0; i < last_word - first_word + 1; i++)
512 if ((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
517 /* Device's eeprom is always little-endian, word addressable */
518 for (i = 0; i < last_word - first_word + 1; i++)
519 le16_to_cpus(&eeprom_buff[i]);
521 memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset & 1),
529 e1000_set_eeprom(struct net_device *netdev,
530 struct ethtool_eeprom *eeprom, uint8_t *bytes)
532 struct e1000_adapter *adapter = netdev_priv(netdev);
533 struct e1000_hw *hw = &adapter->hw;
534 uint16_t *eeprom_buff;
536 int max_len, first_word, last_word, ret_val = 0;
539 if (eeprom->len == 0)
542 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
545 max_len = hw->eeprom.word_size * 2;
547 first_word = eeprom->offset >> 1;
548 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
549 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
553 ptr = (void *)eeprom_buff;
555 if (eeprom->offset & 1) {
556 /* need read/modify/write of first changed EEPROM word */
557 /* only the second byte of the word is being modified */
558 ret_val = e1000_read_eeprom(hw, first_word, 1,
562 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
563 /* need read/modify/write of last changed EEPROM word */
564 /* only the first byte of the word is being modified */
565 ret_val = e1000_read_eeprom(hw, last_word, 1,
566 &eeprom_buff[last_word - first_word]);
569 /* Device's eeprom is always little-endian, word addressable */
570 for (i = 0; i < last_word - first_word + 1; i++)
571 le16_to_cpus(&eeprom_buff[i]);
573 memcpy(ptr, bytes, eeprom->len);
575 for (i = 0; i < last_word - first_word + 1; i++)
576 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
578 ret_val = e1000_write_eeprom(hw, first_word,
579 last_word - first_word + 1, eeprom_buff);
581 /* Update the checksum over the first part of the EEPROM if needed
582 * and flush shadow RAM for 82573 conrollers */
583 if ((ret_val == 0) && ((first_word <= EEPROM_CHECKSUM_REG) ||
584 (hw->mac_type == e1000_82573)))
585 e1000_update_eeprom_checksum(hw);
592 e1000_get_drvinfo(struct net_device *netdev,
593 struct ethtool_drvinfo *drvinfo)
595 struct e1000_adapter *adapter = netdev_priv(netdev);
596 char firmware_version[32];
597 uint16_t eeprom_data;
599 strncpy(drvinfo->driver, e1000_driver_name, 32);
600 strncpy(drvinfo->version, e1000_driver_version, 32);
602 /* EEPROM image version # is reported as firmware version # for
603 * 8257{1|2|3} controllers */
604 e1000_read_eeprom(&adapter->hw, 5, 1, &eeprom_data);
605 switch (adapter->hw.mac_type) {
609 case e1000_80003es2lan:
611 sprintf(firmware_version, "%d.%d-%d",
612 (eeprom_data & 0xF000) >> 12,
613 (eeprom_data & 0x0FF0) >> 4,
614 eeprom_data & 0x000F);
617 sprintf(firmware_version, "N/A");
620 strncpy(drvinfo->fw_version, firmware_version, 32);
621 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
622 drvinfo->n_stats = E1000_STATS_LEN;
623 drvinfo->testinfo_len = E1000_TEST_LEN;
624 drvinfo->regdump_len = e1000_get_regs_len(netdev);
625 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
629 e1000_get_ringparam(struct net_device *netdev,
630 struct ethtool_ringparam *ring)
632 struct e1000_adapter *adapter = netdev_priv(netdev);
633 e1000_mac_type mac_type = adapter->hw.mac_type;
634 struct e1000_tx_ring *txdr = adapter->tx_ring;
635 struct e1000_rx_ring *rxdr = adapter->rx_ring;
637 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
639 ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
641 ring->rx_mini_max_pending = 0;
642 ring->rx_jumbo_max_pending = 0;
643 ring->rx_pending = rxdr->count;
644 ring->tx_pending = txdr->count;
645 ring->rx_mini_pending = 0;
646 ring->rx_jumbo_pending = 0;
650 e1000_set_ringparam(struct net_device *netdev,
651 struct ethtool_ringparam *ring)
653 struct e1000_adapter *adapter = netdev_priv(netdev);
654 e1000_mac_type mac_type = adapter->hw.mac_type;
655 struct e1000_tx_ring *txdr, *tx_old;
656 struct e1000_rx_ring *rxdr, *rx_old;
657 int i, err, tx_ring_size, rx_ring_size;
659 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
662 tx_ring_size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
663 rx_ring_size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
665 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
668 if (netif_running(adapter->netdev))
671 tx_old = adapter->tx_ring;
672 rx_old = adapter->rx_ring;
675 txdr = kzalloc(tx_ring_size, GFP_KERNEL);
679 rxdr = kzalloc(rx_ring_size, GFP_KERNEL);
683 adapter->tx_ring = txdr;
684 adapter->rx_ring = rxdr;
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 adapter->rx_ring = rx_old;
712 adapter->tx_ring = tx_old;
713 e1000_free_all_rx_resources(adapter);
714 e1000_free_all_tx_resources(adapter);
717 adapter->rx_ring = rxdr;
718 adapter->tx_ring = txdr;
719 if ((err = e1000_up(adapter)))
723 clear_bit(__E1000_RESETTING, &adapter->flags);
726 e1000_free_all_rx_resources(adapter);
728 adapter->rx_ring = rx_old;
729 adapter->tx_ring = tx_old;
736 clear_bit(__E1000_RESETTING, &adapter->flags);
740 #define REG_PATTERN_TEST(R, M, W) \
742 uint32_t pat, value; \
744 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; \
745 for (pat = 0; pat < sizeof(test)/sizeof(test[0]); pat++) { \
746 E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W)); \
747 value = E1000_READ_REG(&adapter->hw, R); \
748 if (value != (test[pat] & W & M)) { \
749 DPRINTK(DRV, ERR, "pattern test reg %04X failed: got " \
750 "0x%08X expected 0x%08X\n", \
751 E1000_##R, value, (test[pat] & W & M)); \
752 *data = (adapter->hw.mac_type < e1000_82543) ? \
753 E1000_82542_##R : E1000_##R; \
759 #define REG_SET_AND_CHECK(R, M, W) \
762 E1000_WRITE_REG(&adapter->hw, R, W & M); \
763 value = E1000_READ_REG(&adapter->hw, R); \
764 if ((W & M) != (value & M)) { \
765 DPRINTK(DRV, ERR, "set/check reg %04X test failed: got 0x%08X "\
766 "expected 0x%08X\n", E1000_##R, (value & M), (W & M)); \
767 *data = (adapter->hw.mac_type < e1000_82543) ? \
768 E1000_82542_##R : E1000_##R; \
774 e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
776 uint32_t value, before, after;
779 /* The status register is Read Only, so a write should fail.
780 * Some bits that get toggled are ignored.
782 switch (adapter->hw.mac_type) {
783 /* there are several bits on newer hardware that are r/w */
786 case e1000_80003es2lan:
798 before = E1000_READ_REG(&adapter->hw, STATUS);
799 value = (E1000_READ_REG(&adapter->hw, STATUS) & toggle);
800 E1000_WRITE_REG(&adapter->hw, STATUS, toggle);
801 after = E1000_READ_REG(&adapter->hw, STATUS) & toggle;
802 if (value != after) {
803 DPRINTK(DRV, ERR, "failed STATUS register test got: "
804 "0x%08X expected: 0x%08X\n", after, value);
808 /* restore previous status */
809 E1000_WRITE_REG(&adapter->hw, STATUS, before);
811 if (adapter->hw.mac_type != e1000_ich8lan) {
812 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
813 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
814 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
815 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);
831 before = (adapter->hw.mac_type == e1000_ich8lan ?
832 0x06C3B33E : 0x06DFB3FE);
833 REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
834 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
836 if (adapter->hw.mac_type >= e1000_82543) {
838 REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
839 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
840 if (adapter->hw.mac_type != e1000_ich8lan)
841 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
842 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
843 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
844 value = (adapter->hw.mac_type == e1000_ich8lan ?
845 E1000_RAR_ENTRIES_ICH8LAN : E1000_RAR_ENTRIES);
846 for (i = 0; i < value; i++) {
847 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
853 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
854 REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
855 REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
856 REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
860 value = (adapter->hw.mac_type == e1000_ich8lan ?
861 E1000_MC_TBL_SIZE_ICH8LAN : E1000_MC_TBL_SIZE);
862 for (i = 0; i < value; i++)
863 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
870 e1000_eeprom_test(struct e1000_adapter *adapter, uint64_t *data)
873 uint16_t checksum = 0;
877 /* Read and add up the contents of the EEPROM */
878 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
879 if ((e1000_read_eeprom(&adapter->hw, i, 1, &temp)) < 0) {
886 /* If Checksum is not Correct return error else test passed */
887 if ((checksum != (uint16_t) EEPROM_SUM) && !(*data))
894 e1000_test_intr(int irq, void *data)
896 struct net_device *netdev = (struct net_device *) data;
897 struct e1000_adapter *adapter = netdev_priv(netdev);
899 adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR);
905 e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
907 struct net_device *netdev = adapter->netdev;
908 uint32_t mask, i=0, shared_int = TRUE;
909 uint32_t irq = adapter->pdev->irq;
913 /* NOTE: we don't test MSI interrupts here, yet */
914 /* Hook up test interrupt handler just for this test */
915 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
918 else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
919 netdev->name, netdev)) {
923 DPRINTK(HW, INFO, "testing %s interrupt\n",
924 (shared_int ? "shared" : "unshared"));
926 /* Disable all the interrupts */
927 E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
930 /* Test each interrupt */
931 for (; i < 10; i++) {
933 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_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_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 /* Online tests aren't run; pass by default */
1691 clear_bit(__E1000_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_82542:
1703 case E1000_DEV_ID_82543GC_FIBER:
1704 case E1000_DEV_ID_82543GC_COPPER:
1705 case E1000_DEV_ID_82544EI_FIBER:
1706 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1707 case E1000_DEV_ID_82545EM_FIBER:
1708 case E1000_DEV_ID_82545EM_COPPER:
1709 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1710 case E1000_DEV_ID_82546GB_PCIE:
1711 /* these don't support WoL at all */
1714 case E1000_DEV_ID_82546EB_FIBER:
1715 case E1000_DEV_ID_82546GB_FIBER:
1716 case E1000_DEV_ID_82571EB_FIBER:
1717 case E1000_DEV_ID_82571EB_SERDES:
1718 case E1000_DEV_ID_82571EB_COPPER:
1719 /* Wake events not supported on port B */
1720 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) {
1724 /* return success for non excluded adapter ports */
1727 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1728 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1729 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1730 /* quad port adapters only support WoL on port A */
1731 if (!adapter->quad_port_a) {
1735 /* return success for non excluded adapter ports */
1739 /* dual port cards only support WoL on port A from now on
1740 * unless it was enabled in the eeprom for port B
1741 * so exclude FUNC_1 ports from having WoL enabled */
1742 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1 &&
1743 !adapter->eeprom_wol) {
1755 e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1757 struct e1000_adapter *adapter = netdev_priv(netdev);
1759 wol->supported = WAKE_UCAST | WAKE_MCAST |
1760 WAKE_BCAST | WAKE_MAGIC;
1763 /* this function will set ->supported = 0 and return 1 if wol is not
1764 * supported by this hardware */
1765 if (e1000_wol_exclusion(adapter, wol))
1768 /* apply any specific unsupported masks here */
1769 switch (adapter->hw.device_id) {
1770 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1771 /* KSP3 does not suppport UCAST wake-ups */
1772 wol->supported &= ~WAKE_UCAST;
1774 if (adapter->wol & E1000_WUFC_EX)
1775 DPRINTK(DRV, ERR, "Interface does not support "
1776 "directed (unicast) frame wake-up packets\n");
1782 if (adapter->wol & E1000_WUFC_EX)
1783 wol->wolopts |= WAKE_UCAST;
1784 if (adapter->wol & E1000_WUFC_MC)
1785 wol->wolopts |= WAKE_MCAST;
1786 if (adapter->wol & E1000_WUFC_BC)
1787 wol->wolopts |= WAKE_BCAST;
1788 if (adapter->wol & E1000_WUFC_MAG)
1789 wol->wolopts |= WAKE_MAGIC;
1795 e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1797 struct e1000_adapter *adapter = netdev_priv(netdev);
1798 struct e1000_hw *hw = &adapter->hw;
1800 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1803 if (e1000_wol_exclusion(adapter, wol))
1804 return wol->wolopts ? -EOPNOTSUPP : 0;
1806 switch (hw->device_id) {
1807 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1808 if (wol->wolopts & WAKE_UCAST) {
1809 DPRINTK(DRV, ERR, "Interface does not support "
1810 "directed (unicast) frame wake-up packets\n");
1818 /* these settings will always override what we currently have */
1821 if (wol->wolopts & WAKE_UCAST)
1822 adapter->wol |= E1000_WUFC_EX;
1823 if (wol->wolopts & WAKE_MCAST)
1824 adapter->wol |= E1000_WUFC_MC;
1825 if (wol->wolopts & WAKE_BCAST)
1826 adapter->wol |= E1000_WUFC_BC;
1827 if (wol->wolopts & WAKE_MAGIC)
1828 adapter->wol |= E1000_WUFC_MAG;
1833 /* toggle LED 4 times per second = 2 "blinks" per second */
1834 #define E1000_ID_INTERVAL (HZ/4)
1836 /* bit defines for adapter->led_status */
1837 #define E1000_LED_ON 0
1840 e1000_led_blink_callback(unsigned long data)
1842 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1844 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1845 e1000_led_off(&adapter->hw);
1847 e1000_led_on(&adapter->hw);
1849 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1853 e1000_phys_id(struct net_device *netdev, uint32_t data)
1855 struct e1000_adapter *adapter = netdev_priv(netdev);
1857 if (!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
1858 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
1860 if (adapter->hw.mac_type < e1000_82571) {
1861 if (!adapter->blink_timer.function) {
1862 init_timer(&adapter->blink_timer);
1863 adapter->blink_timer.function = e1000_led_blink_callback;
1864 adapter->blink_timer.data = (unsigned long) adapter;
1866 e1000_setup_led(&adapter->hw);
1867 mod_timer(&adapter->blink_timer, jiffies);
1868 msleep_interruptible(data * 1000);
1869 del_timer_sync(&adapter->blink_timer);
1870 } else if (adapter->hw.phy_type == e1000_phy_ife) {
1871 if (!adapter->blink_timer.function) {
1872 init_timer(&adapter->blink_timer);
1873 adapter->blink_timer.function = e1000_led_blink_callback;
1874 adapter->blink_timer.data = (unsigned long) adapter;
1876 mod_timer(&adapter->blink_timer, jiffies);
1877 msleep_interruptible(data * 1000);
1878 del_timer_sync(&adapter->blink_timer);
1879 e1000_write_phy_reg(&(adapter->hw), IFE_PHY_SPECIAL_CONTROL_LED, 0);
1881 e1000_blink_led_start(&adapter->hw);
1882 msleep_interruptible(data * 1000);
1885 e1000_led_off(&adapter->hw);
1886 clear_bit(E1000_LED_ON, &adapter->led_status);
1887 e1000_cleanup_led(&adapter->hw);
1893 e1000_nway_reset(struct net_device *netdev)
1895 struct e1000_adapter *adapter = netdev_priv(netdev);
1896 if (netif_running(netdev))
1897 e1000_reinit_locked(adapter);
1902 e1000_get_stats_count(struct net_device *netdev)
1904 return E1000_STATS_LEN;
1908 e1000_get_ethtool_stats(struct net_device *netdev,
1909 struct ethtool_stats *stats, uint64_t *data)
1911 struct e1000_adapter *adapter = netdev_priv(netdev);
1914 e1000_update_stats(adapter);
1915 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1916 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1917 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1918 sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
1920 /* BUG_ON(i != E1000_STATS_LEN); */
1924 e1000_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
1929 switch (stringset) {
1931 memcpy(data, *e1000_gstrings_test,
1932 E1000_TEST_LEN*ETH_GSTRING_LEN);
1935 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1936 memcpy(p, e1000_gstrings_stats[i].stat_string,
1938 p += ETH_GSTRING_LEN;
1940 /* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
1945 static const struct ethtool_ops e1000_ethtool_ops = {
1946 .get_settings = e1000_get_settings,
1947 .set_settings = e1000_set_settings,
1948 .get_drvinfo = e1000_get_drvinfo,
1949 .get_regs_len = e1000_get_regs_len,
1950 .get_regs = e1000_get_regs,
1951 .get_wol = e1000_get_wol,
1952 .set_wol = e1000_set_wol,
1953 .get_msglevel = e1000_get_msglevel,
1954 .set_msglevel = e1000_set_msglevel,
1955 .nway_reset = e1000_nway_reset,
1956 .get_link = ethtool_op_get_link,
1957 .get_eeprom_len = e1000_get_eeprom_len,
1958 .get_eeprom = e1000_get_eeprom,
1959 .set_eeprom = e1000_set_eeprom,
1960 .get_ringparam = e1000_get_ringparam,
1961 .set_ringparam = e1000_set_ringparam,
1962 .get_pauseparam = e1000_get_pauseparam,
1963 .set_pauseparam = e1000_set_pauseparam,
1964 .get_rx_csum = e1000_get_rx_csum,
1965 .set_rx_csum = e1000_set_rx_csum,
1966 .get_tx_csum = e1000_get_tx_csum,
1967 .set_tx_csum = e1000_set_tx_csum,
1968 .get_sg = ethtool_op_get_sg,
1969 .set_sg = ethtool_op_set_sg,
1970 .get_tso = ethtool_op_get_tso,
1971 .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);