1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2007 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 /* ethtool support for e1000 */
31 #include <linux/netdevice.h>
32 #include <linux/ethtool.h>
33 #include <linux/pci.h>
34 #include <linux/delay.h>
39 char stat_string
[ETH_GSTRING_LEN
];
44 #define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
45 offsetof(struct e1000_adapter, m)
46 static const struct e1000_stats e1000_gstrings_stats
[] = {
47 { "rx_packets", E1000_STAT(stats
.gprc
) },
48 { "tx_packets", E1000_STAT(stats
.gptc
) },
49 { "rx_bytes", E1000_STAT(stats
.gorcl
) },
50 { "tx_bytes", E1000_STAT(stats
.gotcl
) },
51 { "rx_broadcast", E1000_STAT(stats
.bprc
) },
52 { "tx_broadcast", E1000_STAT(stats
.bptc
) },
53 { "rx_multicast", E1000_STAT(stats
.mprc
) },
54 { "tx_multicast", E1000_STAT(stats
.mptc
) },
55 { "rx_errors", E1000_STAT(net_stats
.rx_errors
) },
56 { "tx_errors", E1000_STAT(net_stats
.tx_errors
) },
57 { "tx_dropped", E1000_STAT(net_stats
.tx_dropped
) },
58 { "multicast", E1000_STAT(stats
.mprc
) },
59 { "collisions", E1000_STAT(stats
.colc
) },
60 { "rx_length_errors", E1000_STAT(net_stats
.rx_length_errors
) },
61 { "rx_over_errors", E1000_STAT(net_stats
.rx_over_errors
) },
62 { "rx_crc_errors", E1000_STAT(stats
.crcerrs
) },
63 { "rx_frame_errors", E1000_STAT(net_stats
.rx_frame_errors
) },
64 { "rx_no_buffer_count", E1000_STAT(stats
.rnbc
) },
65 { "rx_missed_errors", E1000_STAT(stats
.mpc
) },
66 { "tx_aborted_errors", E1000_STAT(stats
.ecol
) },
67 { "tx_carrier_errors", E1000_STAT(stats
.tncrs
) },
68 { "tx_fifo_errors", E1000_STAT(net_stats
.tx_fifo_errors
) },
69 { "tx_heartbeat_errors", E1000_STAT(net_stats
.tx_heartbeat_errors
) },
70 { "tx_window_errors", E1000_STAT(stats
.latecol
) },
71 { "tx_abort_late_coll", E1000_STAT(stats
.latecol
) },
72 { "tx_deferred_ok", E1000_STAT(stats
.dc
) },
73 { "tx_single_coll_ok", E1000_STAT(stats
.scc
) },
74 { "tx_multi_coll_ok", E1000_STAT(stats
.mcc
) },
75 { "tx_timeout_count", E1000_STAT(tx_timeout_count
) },
76 { "tx_restart_queue", E1000_STAT(restart_queue
) },
77 { "rx_long_length_errors", E1000_STAT(stats
.roc
) },
78 { "rx_short_length_errors", E1000_STAT(stats
.ruc
) },
79 { "rx_align_errors", E1000_STAT(stats
.algnerrc
) },
80 { "tx_tcp_seg_good", E1000_STAT(stats
.tsctc
) },
81 { "tx_tcp_seg_failed", E1000_STAT(stats
.tsctfc
) },
82 { "rx_flow_control_xon", E1000_STAT(stats
.xonrxc
) },
83 { "rx_flow_control_xoff", E1000_STAT(stats
.xoffrxc
) },
84 { "tx_flow_control_xon", E1000_STAT(stats
.xontxc
) },
85 { "tx_flow_control_xoff", E1000_STAT(stats
.xofftxc
) },
86 { "rx_long_byte_count", E1000_STAT(stats
.gorcl
) },
87 { "rx_csum_offload_good", E1000_STAT(hw_csum_good
) },
88 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err
) },
89 { "rx_header_split", E1000_STAT(rx_hdr_split
) },
90 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed
) },
91 { "tx_smbus", E1000_STAT(stats
.mgptc
) },
92 { "rx_smbus", E1000_STAT(stats
.mgprc
) },
93 { "dropped_smbus", E1000_STAT(stats
.mgpdc
) },
94 { "rx_dma_failed", E1000_STAT(rx_dma_failed
) },
95 { "tx_dma_failed", E1000_STAT(tx_dma_failed
) },
98 #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
99 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
100 static const char e1000_gstrings_test
[][ETH_GSTRING_LEN
] = {
101 "Register test (offline)", "Eeprom test (offline)",
102 "Interrupt test (offline)", "Loopback test (offline)",
103 "Link test (on/offline)"
105 #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
107 static int e1000_get_settings(struct net_device
*netdev
,
108 struct ethtool_cmd
*ecmd
)
110 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
111 struct e1000_hw
*hw
= &adapter
->hw
;
114 if (hw
->media_type
== e1000_media_type_copper
) {
116 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
117 SUPPORTED_10baseT_Full
|
118 SUPPORTED_100baseT_Half
|
119 SUPPORTED_100baseT_Full
|
120 SUPPORTED_1000baseT_Full
|
123 if (hw
->phy
.type
== e1000_phy_ife
)
124 ecmd
->supported
&= ~SUPPORTED_1000baseT_Full
;
125 ecmd
->advertising
= ADVERTISED_TP
;
127 if (hw
->mac
.autoneg
== 1) {
128 ecmd
->advertising
|= ADVERTISED_Autoneg
;
129 /* the e1000 autoneg seems to match ethtool nicely */
130 ecmd
->advertising
|= hw
->phy
.autoneg_advertised
;
133 ecmd
->port
= PORT_TP
;
134 ecmd
->phy_address
= hw
->phy
.addr
;
135 ecmd
->transceiver
= XCVR_INTERNAL
;
138 ecmd
->supported
= (SUPPORTED_1000baseT_Full
|
142 ecmd
->advertising
= (ADVERTISED_1000baseT_Full
|
146 ecmd
->port
= PORT_FIBRE
;
147 ecmd
->transceiver
= XCVR_EXTERNAL
;
150 status
= er32(STATUS
);
151 if (status
& E1000_STATUS_LU
) {
152 if (status
& E1000_STATUS_SPEED_1000
)
154 else if (status
& E1000_STATUS_SPEED_100
)
159 if (status
& E1000_STATUS_FD
)
160 ecmd
->duplex
= DUPLEX_FULL
;
162 ecmd
->duplex
= DUPLEX_HALF
;
168 ecmd
->autoneg
= ((hw
->media_type
== e1000_media_type_fiber
) ||
169 hw
->mac
.autoneg
) ? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
173 static u32
e1000_get_link(struct net_device
*netdev
)
175 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
176 struct e1000_hw
*hw
= &adapter
->hw
;
179 status
= er32(STATUS
);
180 return (status
& E1000_STATUS_LU
);
183 static int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, u16 spddplx
)
185 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
189 /* Fiber NICs only allow 1000 gbps Full duplex */
190 if ((adapter
->hw
.media_type
== e1000_media_type_fiber
) &&
191 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
192 ndev_err(adapter
->netdev
, "Unsupported Speed/Duplex "
198 case SPEED_10
+ DUPLEX_HALF
:
199 mac
->forced_speed_duplex
= ADVERTISE_10_HALF
;
201 case SPEED_10
+ DUPLEX_FULL
:
202 mac
->forced_speed_duplex
= ADVERTISE_10_FULL
;
204 case SPEED_100
+ DUPLEX_HALF
:
205 mac
->forced_speed_duplex
= ADVERTISE_100_HALF
;
207 case SPEED_100
+ DUPLEX_FULL
:
208 mac
->forced_speed_duplex
= ADVERTISE_100_FULL
;
210 case SPEED_1000
+ DUPLEX_FULL
:
212 adapter
->hw
.phy
.autoneg_advertised
= ADVERTISE_1000_FULL
;
214 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
216 ndev_err(adapter
->netdev
, "Unsupported Speed/Duplex "
223 static int e1000_set_settings(struct net_device
*netdev
,
224 struct ethtool_cmd
*ecmd
)
226 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
227 struct e1000_hw
*hw
= &adapter
->hw
;
229 /* When SoL/IDER sessions are active, autoneg/speed/duplex
230 * cannot be changed */
231 if (e1000_check_reset_block(hw
)) {
232 ndev_err(netdev
, "Cannot change link "
233 "characteristics when SoL/IDER is active.\n");
237 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
240 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
242 if (hw
->media_type
== e1000_media_type_fiber
)
243 hw
->phy
.autoneg_advertised
= ADVERTISED_1000baseT_Full
|
247 hw
->phy
.autoneg_advertised
= ecmd
->advertising
|
250 ecmd
->advertising
= hw
->phy
.autoneg_advertised
;
252 if (e1000_set_spd_dplx(adapter
, ecmd
->speed
+ ecmd
->duplex
)) {
253 clear_bit(__E1000_RESETTING
, &adapter
->state
);
260 if (netif_running(adapter
->netdev
)) {
261 e1000e_down(adapter
);
264 e1000e_reset(adapter
);
267 clear_bit(__E1000_RESETTING
, &adapter
->state
);
271 static void e1000_get_pauseparam(struct net_device
*netdev
,
272 struct ethtool_pauseparam
*pause
)
274 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
275 struct e1000_hw
*hw
= &adapter
->hw
;
278 (adapter
->fc_autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
);
280 if (hw
->mac
.fc
== e1000_fc_rx_pause
) {
282 } else if (hw
->mac
.fc
== e1000_fc_tx_pause
) {
284 } else if (hw
->mac
.fc
== e1000_fc_full
) {
290 static int e1000_set_pauseparam(struct net_device
*netdev
,
291 struct ethtool_pauseparam
*pause
)
293 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
294 struct e1000_hw
*hw
= &adapter
->hw
;
297 adapter
->fc_autoneg
= pause
->autoneg
;
299 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
302 if (pause
->rx_pause
&& pause
->tx_pause
)
303 hw
->mac
.fc
= e1000_fc_full
;
304 else if (pause
->rx_pause
&& !pause
->tx_pause
)
305 hw
->mac
.fc
= e1000_fc_rx_pause
;
306 else if (!pause
->rx_pause
&& pause
->tx_pause
)
307 hw
->mac
.fc
= e1000_fc_tx_pause
;
308 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
309 hw
->mac
.fc
= e1000_fc_none
;
311 hw
->mac
.original_fc
= hw
->mac
.fc
;
313 if (adapter
->fc_autoneg
== AUTONEG_ENABLE
) {
314 hw
->mac
.fc
= e1000_fc_default
;
315 if (netif_running(adapter
->netdev
)) {
316 e1000e_down(adapter
);
319 e1000e_reset(adapter
);
322 retval
= ((hw
->media_type
== e1000_media_type_fiber
) ?
323 hw
->mac
.ops
.setup_link(hw
) : e1000e_force_mac_fc(hw
));
326 clear_bit(__E1000_RESETTING
, &adapter
->state
);
330 static u32
e1000_get_rx_csum(struct net_device
*netdev
)
332 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
333 return (adapter
->flags
& FLAG_RX_CSUM_ENABLED
);
336 static int e1000_set_rx_csum(struct net_device
*netdev
, u32 data
)
338 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
341 adapter
->flags
|= FLAG_RX_CSUM_ENABLED
;
343 adapter
->flags
&= ~FLAG_RX_CSUM_ENABLED
;
345 if (netif_running(netdev
))
346 e1000e_reinit_locked(adapter
);
348 e1000e_reset(adapter
);
352 static u32
e1000_get_tx_csum(struct net_device
*netdev
)
354 return ((netdev
->features
& NETIF_F_HW_CSUM
) != 0);
357 static int e1000_set_tx_csum(struct net_device
*netdev
, u32 data
)
360 netdev
->features
|= NETIF_F_HW_CSUM
;
362 netdev
->features
&= ~NETIF_F_HW_CSUM
;
367 static int e1000_set_tso(struct net_device
*netdev
, u32 data
)
369 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
372 netdev
->features
|= NETIF_F_TSO
;
373 netdev
->features
|= NETIF_F_TSO6
;
375 netdev
->features
&= ~NETIF_F_TSO
;
376 netdev
->features
&= ~NETIF_F_TSO6
;
379 ndev_info(netdev
, "TSO is %s\n",
380 data
? "Enabled" : "Disabled");
381 adapter
->flags
|= FLAG_TSO_FORCE
;
385 static u32
e1000_get_msglevel(struct net_device
*netdev
)
387 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
388 return adapter
->msg_enable
;
391 static void e1000_set_msglevel(struct net_device
*netdev
, u32 data
)
393 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
394 adapter
->msg_enable
= data
;
397 static int e1000_get_regs_len(struct net_device
*netdev
)
399 #define E1000_REGS_LEN 32 /* overestimate */
400 return E1000_REGS_LEN
* sizeof(u32
);
403 static void e1000_get_regs(struct net_device
*netdev
,
404 struct ethtool_regs
*regs
, void *p
)
406 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
407 struct e1000_hw
*hw
= &adapter
->hw
;
412 memset(p
, 0, E1000_REGS_LEN
* sizeof(u32
));
414 pci_read_config_byte(adapter
->pdev
, PCI_REVISION_ID
, &revision_id
);
416 regs
->version
= (1 << 24) | (revision_id
<< 16) | adapter
->pdev
->device
;
418 regs_buff
[0] = er32(CTRL
);
419 regs_buff
[1] = er32(STATUS
);
421 regs_buff
[2] = er32(RCTL
);
422 regs_buff
[3] = er32(RDLEN
);
423 regs_buff
[4] = er32(RDH
);
424 regs_buff
[5] = er32(RDT
);
425 regs_buff
[6] = er32(RDTR
);
427 regs_buff
[7] = er32(TCTL
);
428 regs_buff
[8] = er32(TDLEN
);
429 regs_buff
[9] = er32(TDH
);
430 regs_buff
[10] = er32(TDT
);
431 regs_buff
[11] = er32(TIDV
);
433 regs_buff
[12] = adapter
->hw
.phy
.type
; /* PHY type (IGP=1, M88=0) */
434 if (hw
->phy
.type
== e1000_phy_m88
) {
435 e1e_rphy(hw
, M88E1000_PHY_SPEC_STATUS
, &phy_data
);
436 regs_buff
[13] = (u32
)phy_data
; /* cable length */
437 regs_buff
[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
438 regs_buff
[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
439 regs_buff
[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
440 e1e_rphy(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
441 regs_buff
[17] = (u32
)phy_data
; /* extended 10bt distance */
442 regs_buff
[18] = regs_buff
[13]; /* cable polarity */
443 regs_buff
[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
444 regs_buff
[20] = regs_buff
[17]; /* polarity correction */
445 /* phy receive errors */
446 regs_buff
[22] = adapter
->phy_stats
.receive_errors
;
447 regs_buff
[23] = regs_buff
[13]; /* mdix mode */
449 regs_buff
[21] = adapter
->phy_stats
.idle_errors
; /* phy idle errors */
450 e1e_rphy(hw
, PHY_1000T_STATUS
, &phy_data
);
451 regs_buff
[24] = (u32
)phy_data
; /* phy local receiver status */
452 regs_buff
[25] = regs_buff
[24]; /* phy remote receiver status */
455 static int e1000_get_eeprom_len(struct net_device
*netdev
)
457 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
458 return adapter
->hw
.nvm
.word_size
* 2;
461 static int e1000_get_eeprom(struct net_device
*netdev
,
462 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
464 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
465 struct e1000_hw
*hw
= &adapter
->hw
;
472 if (eeprom
->len
== 0)
475 eeprom
->magic
= adapter
->pdev
->vendor
| (adapter
->pdev
->device
<< 16);
477 first_word
= eeprom
->offset
>> 1;
478 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
480 eeprom_buff
= kmalloc(sizeof(u16
) *
481 (last_word
- first_word
+ 1), GFP_KERNEL
);
485 if (hw
->nvm
.type
== e1000_nvm_eeprom_spi
) {
486 ret_val
= e1000_read_nvm(hw
, first_word
,
487 last_word
- first_word
+ 1,
490 for (i
= 0; i
< last_word
- first_word
+ 1; i
++) {
491 ret_val
= e1000_read_nvm(hw
, first_word
+ i
, 1,
498 /* Device's eeprom is always little-endian, word addressable */
499 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
500 le16_to_cpus(&eeprom_buff
[i
]);
502 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 1), eeprom
->len
);
508 static int e1000_set_eeprom(struct net_device
*netdev
,
509 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
511 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
512 struct e1000_hw
*hw
= &adapter
->hw
;
521 if (eeprom
->len
== 0)
524 if (eeprom
->magic
!= (adapter
->pdev
->vendor
| (adapter
->pdev
->device
<< 16)))
527 max_len
= hw
->nvm
.word_size
* 2;
529 first_word
= eeprom
->offset
>> 1;
530 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
531 eeprom_buff
= kmalloc(max_len
, GFP_KERNEL
);
535 ptr
= (void *)eeprom_buff
;
537 if (eeprom
->offset
& 1) {
538 /* need read/modify/write of first changed EEPROM word */
539 /* only the second byte of the word is being modified */
540 ret_val
= e1000_read_nvm(hw
, first_word
, 1, &eeprom_buff
[0]);
543 if (((eeprom
->offset
+ eeprom
->len
) & 1) && (ret_val
== 0))
544 /* need read/modify/write of last changed EEPROM word */
545 /* only the first byte of the word is being modified */
546 ret_val
= e1000_read_nvm(hw
, last_word
, 1,
547 &eeprom_buff
[last_word
- first_word
]);
549 /* Device's eeprom is always little-endian, word addressable */
550 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
551 le16_to_cpus(&eeprom_buff
[i
]);
553 memcpy(ptr
, bytes
, eeprom
->len
);
555 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
556 eeprom_buff
[i
] = cpu_to_le16(eeprom_buff
[i
]);
558 ret_val
= e1000_write_nvm(hw
, first_word
,
559 last_word
- first_word
+ 1, eeprom_buff
);
561 /* Update the checksum over the first part of the EEPROM if needed
562 * and flush shadow RAM for 82573 controllers */
563 if ((ret_val
== 0) && ((first_word
<= NVM_CHECKSUM_REG
) ||
564 (hw
->mac
.type
== e1000_82573
)))
565 e1000e_update_nvm_checksum(hw
);
571 static void e1000_get_drvinfo(struct net_device
*netdev
,
572 struct ethtool_drvinfo
*drvinfo
)
574 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
575 char firmware_version
[32];
578 strncpy(drvinfo
->driver
, e1000e_driver_name
, 32);
579 strncpy(drvinfo
->version
, e1000e_driver_version
, 32);
581 /* EEPROM image version # is reported as firmware version # for
582 * PCI-E controllers */
583 e1000_read_nvm(&adapter
->hw
, 5, 1, &eeprom_data
);
584 sprintf(firmware_version
, "%d.%d-%d",
585 (eeprom_data
& 0xF000) >> 12,
586 (eeprom_data
& 0x0FF0) >> 4,
587 eeprom_data
& 0x000F);
589 strncpy(drvinfo
->fw_version
, firmware_version
, 32);
590 strncpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
), 32);
591 drvinfo
->regdump_len
= e1000_get_regs_len(netdev
);
592 drvinfo
->eedump_len
= e1000_get_eeprom_len(netdev
);
595 static void e1000_get_ringparam(struct net_device
*netdev
,
596 struct ethtool_ringparam
*ring
)
598 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
599 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
600 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
602 ring
->rx_max_pending
= E1000_MAX_RXD
;
603 ring
->tx_max_pending
= E1000_MAX_TXD
;
604 ring
->rx_mini_max_pending
= 0;
605 ring
->rx_jumbo_max_pending
= 0;
606 ring
->rx_pending
= rx_ring
->count
;
607 ring
->tx_pending
= tx_ring
->count
;
608 ring
->rx_mini_pending
= 0;
609 ring
->rx_jumbo_pending
= 0;
612 static int e1000_set_ringparam(struct net_device
*netdev
,
613 struct ethtool_ringparam
*ring
)
615 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
616 struct e1000_ring
*tx_ring
, *tx_old
;
617 struct e1000_ring
*rx_ring
, *rx_old
;
620 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
623 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
626 if (netif_running(adapter
->netdev
))
627 e1000e_down(adapter
);
629 tx_old
= adapter
->tx_ring
;
630 rx_old
= adapter
->rx_ring
;
633 tx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
637 rx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
641 adapter
->tx_ring
= tx_ring
;
642 adapter
->rx_ring
= rx_ring
;
644 rx_ring
->count
= max(ring
->rx_pending
, (u32
)E1000_MIN_RXD
);
645 rx_ring
->count
= min(rx_ring
->count
, (u32
)(E1000_MAX_RXD
));
646 rx_ring
->count
= ALIGN(rx_ring
->count
, REQ_RX_DESCRIPTOR_MULTIPLE
);
648 tx_ring
->count
= max(ring
->tx_pending
, (u32
)E1000_MIN_TXD
);
649 tx_ring
->count
= min(tx_ring
->count
, (u32
)(E1000_MAX_TXD
));
650 tx_ring
->count
= ALIGN(tx_ring
->count
, REQ_TX_DESCRIPTOR_MULTIPLE
);
652 if (netif_running(adapter
->netdev
)) {
653 /* Try to get new resources before deleting old */
654 err
= e1000e_setup_rx_resources(adapter
);
657 err
= e1000e_setup_tx_resources(adapter
);
661 /* save the new, restore the old in order to free it,
662 * then restore the new back again */
663 adapter
->rx_ring
= rx_old
;
664 adapter
->tx_ring
= tx_old
;
665 e1000e_free_rx_resources(adapter
);
666 e1000e_free_tx_resources(adapter
);
669 adapter
->rx_ring
= rx_ring
;
670 adapter
->tx_ring
= tx_ring
;
671 err
= e1000e_up(adapter
);
676 clear_bit(__E1000_RESETTING
, &adapter
->state
);
679 e1000e_free_rx_resources(adapter
);
681 adapter
->rx_ring
= rx_old
;
682 adapter
->tx_ring
= tx_old
;
689 clear_bit(__E1000_RESETTING
, &adapter
->state
);
693 #define REG_PATTERN_TEST(R, M, W) REG_PATTERN_TEST_ARRAY(R, 0, M, W)
694 #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, writeable) \
698 u32 _test[] = {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; \
699 for (_pat = 0; _pat < ARRAY_SIZE(_test); _pat++) { \
700 E1000_WRITE_REG_ARRAY(hw, reg, offset, \
701 (_test[_pat] & writeable)); \
702 _value = E1000_READ_REG_ARRAY(hw, reg, offset); \
703 if (_value != (_test[_pat] & writeable & mask)) { \
704 ndev_err(netdev, "pattern test reg %04X " \
705 "failed: got 0x%08X expected 0x%08X\n", \
707 value, (_test[_pat] & writeable & mask)); \
714 #define REG_SET_AND_CHECK(R, M, W) \
717 __ew32(hw, R, W & M); \
718 _value = __er32(hw, R); \
719 if ((W & M) != (_value & M)) { \
720 ndev_err(netdev, "set/check reg %04X test failed: " \
721 "got 0x%08X expected 0x%08X\n", R, (_value & M), \
728 static int e1000_reg_test(struct e1000_adapter
*adapter
, u64
*data
)
730 struct e1000_hw
*hw
= &adapter
->hw
;
731 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
732 struct net_device
*netdev
= adapter
->netdev
;
739 /* The status register is Read Only, so a write should fail.
740 * Some bits that get toggled are ignored.
743 /* there are several bits on newer hardware that are r/w */
746 case e1000_80003es2lan
:
759 before
= er32(STATUS
);
760 value
= (er32(STATUS
) & toggle
);
761 ew32(STATUS
, toggle
);
762 after
= er32(STATUS
) & toggle
;
763 if (value
!= after
) {
764 ndev_err(netdev
, "failed STATUS register test got: "
765 "0x%08X expected: 0x%08X\n", after
, value
);
769 /* restore previous status */
770 ew32(STATUS
, before
);
772 if ((mac
->type
!= e1000_ich8lan
) &&
773 (mac
->type
!= e1000_ich9lan
)) {
774 REG_PATTERN_TEST(E1000_FCAL
, 0xFFFFFFFF, 0xFFFFFFFF);
775 REG_PATTERN_TEST(E1000_FCAH
, 0x0000FFFF, 0xFFFFFFFF);
776 REG_PATTERN_TEST(E1000_FCT
, 0x0000FFFF, 0xFFFFFFFF);
777 REG_PATTERN_TEST(E1000_VET
, 0x0000FFFF, 0xFFFFFFFF);
780 REG_PATTERN_TEST(E1000_RDTR
, 0x0000FFFF, 0xFFFFFFFF);
781 REG_PATTERN_TEST(E1000_RDBAH
, 0xFFFFFFFF, 0xFFFFFFFF);
782 REG_PATTERN_TEST(E1000_RDLEN
, 0x000FFF80, 0x000FFFFF);
783 REG_PATTERN_TEST(E1000_RDH
, 0x0000FFFF, 0x0000FFFF);
784 REG_PATTERN_TEST(E1000_RDT
, 0x0000FFFF, 0x0000FFFF);
785 REG_PATTERN_TEST(E1000_FCRTH
, 0x0000FFF8, 0x0000FFF8);
786 REG_PATTERN_TEST(E1000_FCTTV
, 0x0000FFFF, 0x0000FFFF);
787 REG_PATTERN_TEST(E1000_TIPG
, 0x3FFFFFFF, 0x3FFFFFFF);
788 REG_PATTERN_TEST(E1000_TDBAH
, 0xFFFFFFFF, 0xFFFFFFFF);
789 REG_PATTERN_TEST(E1000_TDLEN
, 0x000FFF80, 0x000FFFFF);
791 REG_SET_AND_CHECK(E1000_RCTL
, 0xFFFFFFFF, 0x00000000);
793 before
= (((mac
->type
== e1000_ich8lan
) ||
794 (mac
->type
== e1000_ich9lan
)) ? 0x06C3B33E : 0x06DFB3FE);
795 REG_SET_AND_CHECK(E1000_RCTL
, before
, 0x003FFFFB);
796 REG_SET_AND_CHECK(E1000_TCTL
, 0xFFFFFFFF, 0x00000000);
798 REG_SET_AND_CHECK(E1000_RCTL
, before
, 0xFFFFFFFF);
799 REG_PATTERN_TEST(E1000_RDBAL
, 0xFFFFFFF0, 0xFFFFFFFF);
800 if ((mac
->type
!= e1000_ich8lan
) &&
801 (mac
->type
!= e1000_ich9lan
))
802 REG_PATTERN_TEST(E1000_TXCW
, 0xC000FFFF, 0x0000FFFF);
803 REG_PATTERN_TEST(E1000_TDBAL
, 0xFFFFFFF0, 0xFFFFFFFF);
804 REG_PATTERN_TEST(E1000_TIDV
, 0x0000FFFF, 0x0000FFFF);
805 for (i
= 0; i
< mac
->rar_entry_count
; i
++)
806 REG_PATTERN_TEST_ARRAY(E1000_RA
, ((i
<< 1) + 1),
807 0x8003FFFF, 0xFFFFFFFF);
809 for (i
= 0; i
< mac
->mta_reg_count
; i
++)
810 REG_PATTERN_TEST_ARRAY(E1000_MTA
, i
, 0xFFFFFFFF, 0xFFFFFFFF);
816 static int e1000_eeprom_test(struct e1000_adapter
*adapter
, u64
*data
)
823 /* Read and add up the contents of the EEPROM */
824 for (i
= 0; i
< (NVM_CHECKSUM_REG
+ 1); i
++) {
825 if ((e1000_read_nvm(&adapter
->hw
, i
, 1, &temp
)) < 0) {
832 /* If Checksum is not Correct return error else test passed */
833 if ((checksum
!= (u16
) NVM_SUM
) && !(*data
))
839 static irqreturn_t
e1000_test_intr(int irq
, void *data
)
841 struct net_device
*netdev
= (struct net_device
*) data
;
842 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
843 struct e1000_hw
*hw
= &adapter
->hw
;
845 adapter
->test_icr
|= er32(ICR
);
850 static int e1000_intr_test(struct e1000_adapter
*adapter
, u64
*data
)
852 struct net_device
*netdev
= adapter
->netdev
;
853 struct e1000_hw
*hw
= &adapter
->hw
;
856 u32 irq
= adapter
->pdev
->irq
;
861 /* NOTE: we don't test MSI interrupts here, yet */
862 /* Hook up test interrupt handler just for this test */
863 if (!request_irq(irq
, &e1000_test_intr
, IRQF_PROBE_SHARED
, netdev
->name
,
866 } else if (request_irq(irq
, &e1000_test_intr
, IRQF_SHARED
,
867 netdev
->name
, netdev
)) {
871 ndev_info(netdev
, "testing %s interrupt\n",
872 (shared_int
? "shared" : "unshared"));
874 /* Disable all the interrupts */
875 ew32(IMC
, 0xFFFFFFFF);
878 /* Test each interrupt */
879 for (i
= 0; i
< 10; i
++) {
881 if (((adapter
->hw
.mac
.type
== e1000_ich8lan
) ||
882 (adapter
->hw
.mac
.type
== e1000_ich9lan
)) && i
== 8)
885 /* Interrupt to test */
889 /* Disable the interrupt to be reported in
890 * the cause register and then force the same
891 * interrupt and see if one gets posted. If
892 * an interrupt was posted to the bus, the
895 adapter
->test_icr
= 0;
900 if (adapter
->test_icr
& mask
) {
906 /* Enable the interrupt to be reported in
907 * the cause register and then force the same
908 * interrupt and see if one gets posted. If
909 * an interrupt was not posted to the bus, the
912 adapter
->test_icr
= 0;
917 if (!(adapter
->test_icr
& mask
)) {
923 /* Disable the other interrupts to be reported in
924 * the cause register and then force the other
925 * interrupts and see if any get posted. If
926 * an interrupt was posted to the bus, the
929 adapter
->test_icr
= 0;
930 ew32(IMC
, ~mask
& 0x00007FFF);
931 ew32(ICS
, ~mask
& 0x00007FFF);
934 if (adapter
->test_icr
) {
941 /* Disable all the interrupts */
942 ew32(IMC
, 0xFFFFFFFF);
945 /* Unhook test interrupt handler */
946 free_irq(irq
, netdev
);
951 static void e1000_free_desc_rings(struct e1000_adapter
*adapter
)
953 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
954 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
955 struct pci_dev
*pdev
= adapter
->pdev
;
958 if (tx_ring
->desc
&& tx_ring
->buffer_info
) {
959 for (i
= 0; i
< tx_ring
->count
; i
++) {
960 if (tx_ring
->buffer_info
[i
].dma
)
961 pci_unmap_single(pdev
,
962 tx_ring
->buffer_info
[i
].dma
,
963 tx_ring
->buffer_info
[i
].length
,
965 if (tx_ring
->buffer_info
[i
].skb
)
966 dev_kfree_skb(tx_ring
->buffer_info
[i
].skb
);
970 if (rx_ring
->desc
&& rx_ring
->buffer_info
) {
971 for (i
= 0; i
< rx_ring
->count
; i
++) {
972 if (rx_ring
->buffer_info
[i
].dma
)
973 pci_unmap_single(pdev
,
974 rx_ring
->buffer_info
[i
].dma
,
975 2048, PCI_DMA_FROMDEVICE
);
976 if (rx_ring
->buffer_info
[i
].skb
)
977 dev_kfree_skb(rx_ring
->buffer_info
[i
].skb
);
982 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
984 tx_ring
->desc
= NULL
;
987 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
989 rx_ring
->desc
= NULL
;
992 kfree(tx_ring
->buffer_info
);
993 tx_ring
->buffer_info
= NULL
;
994 kfree(rx_ring
->buffer_info
);
995 rx_ring
->buffer_info
= NULL
;
998 static int e1000_setup_desc_rings(struct e1000_adapter
*adapter
)
1000 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1001 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1002 struct pci_dev
*pdev
= adapter
->pdev
;
1003 struct e1000_hw
*hw
= &adapter
->hw
;
1009 /* Setup Tx descriptor ring and Tx buffers */
1011 if (!tx_ring
->count
)
1012 tx_ring
->count
= E1000_DEFAULT_TXD
;
1014 size
= tx_ring
->count
* sizeof(struct e1000_buffer
);
1015 tx_ring
->buffer_info
= kmalloc(size
, GFP_KERNEL
);
1016 if (!tx_ring
->buffer_info
) {
1020 memset(tx_ring
->buffer_info
, 0, size
);
1022 tx_ring
->size
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
1023 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1024 tx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, tx_ring
->size
,
1025 &tx_ring
->dma
, GFP_KERNEL
);
1026 if (!tx_ring
->desc
) {
1030 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1031 tx_ring
->next_to_use
= 0;
1032 tx_ring
->next_to_clean
= 0;
1035 ((u64
) tx_ring
->dma
& 0x00000000FFFFFFFF));
1036 ew32(TDBAH
, ((u64
) tx_ring
->dma
>> 32));
1038 tx_ring
->count
* sizeof(struct e1000_tx_desc
));
1042 E1000_TCTL_PSP
| E1000_TCTL_EN
|
1043 E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
|
1044 E1000_COLLISION_DISTANCE
<< E1000_COLD_SHIFT
);
1046 for (i
= 0; i
< tx_ring
->count
; i
++) {
1047 struct e1000_tx_desc
*tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
1048 struct sk_buff
*skb
;
1049 unsigned int skb_size
= 1024;
1051 skb
= alloc_skb(skb_size
, GFP_KERNEL
);
1056 skb_put(skb
, skb_size
);
1057 tx_ring
->buffer_info
[i
].skb
= skb
;
1058 tx_ring
->buffer_info
[i
].length
= skb
->len
;
1059 tx_ring
->buffer_info
[i
].dma
=
1060 pci_map_single(pdev
, skb
->data
, skb
->len
,
1062 if (pci_dma_mapping_error(tx_ring
->buffer_info
[i
].dma
)) {
1066 tx_desc
->buffer_addr
= cpu_to_le64(
1067 tx_ring
->buffer_info
[i
].dma
);
1068 tx_desc
->lower
.data
= cpu_to_le32(skb
->len
);
1069 tx_desc
->lower
.data
|= cpu_to_le32(E1000_TXD_CMD_EOP
|
1070 E1000_TXD_CMD_IFCS
|
1072 tx_desc
->upper
.data
= 0;
1075 /* Setup Rx descriptor ring and Rx buffers */
1077 if (!rx_ring
->count
)
1078 rx_ring
->count
= E1000_DEFAULT_RXD
;
1080 size
= rx_ring
->count
* sizeof(struct e1000_buffer
);
1081 rx_ring
->buffer_info
= kmalloc(size
, GFP_KERNEL
);
1082 if (!rx_ring
->buffer_info
) {
1086 memset(rx_ring
->buffer_info
, 0, size
);
1088 rx_ring
->size
= rx_ring
->count
* sizeof(struct e1000_rx_desc
);
1089 rx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, rx_ring
->size
,
1090 &rx_ring
->dma
, GFP_KERNEL
);
1091 if (!rx_ring
->desc
) {
1095 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1096 rx_ring
->next_to_use
= 0;
1097 rx_ring
->next_to_clean
= 0;
1100 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1101 ew32(RDBAL
, ((u64
) rx_ring
->dma
& 0xFFFFFFFF));
1102 ew32(RDBAH
, ((u64
) rx_ring
->dma
>> 32));
1103 ew32(RDLEN
, rx_ring
->size
);
1106 rctl
= E1000_RCTL_EN
| E1000_RCTL_BAM
| E1000_RCTL_SZ_2048
|
1107 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1108 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1111 for (i
= 0; i
< rx_ring
->count
; i
++) {
1112 struct e1000_rx_desc
*rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
1113 struct sk_buff
*skb
;
1115 skb
= alloc_skb(2048 + NET_IP_ALIGN
, GFP_KERNEL
);
1120 skb_reserve(skb
, NET_IP_ALIGN
);
1121 rx_ring
->buffer_info
[i
].skb
= skb
;
1122 rx_ring
->buffer_info
[i
].dma
=
1123 pci_map_single(pdev
, skb
->data
, 2048,
1124 PCI_DMA_FROMDEVICE
);
1125 if (pci_dma_mapping_error(rx_ring
->buffer_info
[i
].dma
)) {
1129 rx_desc
->buffer_addr
=
1130 cpu_to_le64(rx_ring
->buffer_info
[i
].dma
);
1131 memset(skb
->data
, 0x00, skb
->len
);
1137 e1000_free_desc_rings(adapter
);
1141 static void e1000_phy_disable_receiver(struct e1000_adapter
*adapter
)
1143 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1144 e1e_wphy(&adapter
->hw
, 29, 0x001F);
1145 e1e_wphy(&adapter
->hw
, 30, 0x8FFC);
1146 e1e_wphy(&adapter
->hw
, 29, 0x001A);
1147 e1e_wphy(&adapter
->hw
, 30, 0x8FF0);
1150 static int e1000_integrated_phy_loopback(struct e1000_adapter
*adapter
)
1152 struct e1000_hw
*hw
= &adapter
->hw
;
1156 adapter
->hw
.mac
.autoneg
= 0;
1158 if (adapter
->hw
.phy
.type
== e1000_phy_m88
) {
1159 /* Auto-MDI/MDIX Off */
1160 e1e_wphy(hw
, M88E1000_PHY_SPEC_CTRL
, 0x0808);
1161 /* reset to update Auto-MDI/MDIX */
1162 e1e_wphy(hw
, PHY_CONTROL
, 0x9140);
1164 e1e_wphy(hw
, PHY_CONTROL
, 0x8140);
1165 } else if (adapter
->hw
.phy
.type
== e1000_phy_gg82563
)
1166 e1e_wphy(hw
, GG82563_PHY_KMRN_MODE_CTRL
, 0x1CC);
1168 ctrl_reg
= er32(CTRL
);
1170 if (adapter
->hw
.phy
.type
== e1000_phy_ife
) {
1171 /* force 100, set loopback */
1172 e1e_wphy(hw
, PHY_CONTROL
, 0x6100);
1174 /* Now set up the MAC to the same speed/duplex as the PHY. */
1175 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1176 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1177 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1178 E1000_CTRL_SPD_100
|/* Force Speed to 100 */
1179 E1000_CTRL_FD
); /* Force Duplex to FULL */
1181 /* force 1000, set loopback */
1182 e1e_wphy(hw
, PHY_CONTROL
, 0x4140);
1184 /* Now set up the MAC to the same speed/duplex as the PHY. */
1185 ctrl_reg
= er32(CTRL
);
1186 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1187 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1188 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1189 E1000_CTRL_SPD_1000
|/* Force Speed to 1000 */
1190 E1000_CTRL_FD
); /* Force Duplex to FULL */
1193 if (adapter
->hw
.media_type
== e1000_media_type_copper
&&
1194 adapter
->hw
.phy
.type
== e1000_phy_m88
) {
1195 ctrl_reg
|= E1000_CTRL_ILOS
; /* Invert Loss of Signal */
1197 /* Set the ILOS bit on the fiber Nic if half duplex link is
1199 stat_reg
= er32(STATUS
);
1200 if ((stat_reg
& E1000_STATUS_FD
) == 0)
1201 ctrl_reg
|= (E1000_CTRL_ILOS
| E1000_CTRL_SLU
);
1204 ew32(CTRL
, ctrl_reg
);
1206 /* Disable the receiver on the PHY so when a cable is plugged in, the
1207 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1209 if (adapter
->hw
.phy
.type
== e1000_phy_m88
)
1210 e1000_phy_disable_receiver(adapter
);
1217 static int e1000_set_82571_fiber_loopback(struct e1000_adapter
*adapter
)
1219 struct e1000_hw
*hw
= &adapter
->hw
;
1220 u32 ctrl
= er32(CTRL
);
1223 /* special requirements for 82571/82572 fiber adapters */
1225 /* jump through hoops to make sure link is up because serdes
1226 * link is hardwired up */
1227 ctrl
|= E1000_CTRL_SLU
;
1230 /* disable autoneg */
1235 link
= (er32(STATUS
) & E1000_STATUS_LU
);
1238 /* set invert loss of signal */
1240 ctrl
|= E1000_CTRL_ILOS
;
1244 /* special write to serdes control register to enable SerDes analog
1246 #define E1000_SERDES_LB_ON 0x410
1247 ew32(SCTL
, E1000_SERDES_LB_ON
);
1253 /* only call this for fiber/serdes connections to es2lan */
1254 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter
*adapter
)
1256 struct e1000_hw
*hw
= &adapter
->hw
;
1257 u32 ctrlext
= er32(CTRL_EXT
);
1258 u32 ctrl
= er32(CTRL
);
1260 /* save CTRL_EXT to restore later, reuse an empty variable (unused
1261 on mac_type 80003es2lan) */
1262 adapter
->tx_fifo_head
= ctrlext
;
1264 /* clear the serdes mode bits, putting the device into mac loopback */
1265 ctrlext
&= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES
;
1266 ew32(CTRL_EXT
, ctrlext
);
1268 /* force speed to 1000/FD, link up */
1269 ctrl
&= ~(E1000_CTRL_SPD_1000
| E1000_CTRL_SPD_100
);
1270 ctrl
|= (E1000_CTRL_SLU
| E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
|
1271 E1000_CTRL_SPD_1000
| E1000_CTRL_FD
);
1274 /* set mac loopback */
1276 ctrl
|= E1000_RCTL_LBM_MAC
;
1279 /* set testing mode parameters (no need to reset later) */
1280 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
1281 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1283 (KMRNCTRLSTA_OPMODE
| KMRNCTRLSTA_OPMODE_1GB_FD_GMII
));
1288 static int e1000_setup_loopback_test(struct e1000_adapter
*adapter
)
1290 struct e1000_hw
*hw
= &adapter
->hw
;
1293 if (hw
->media_type
== e1000_media_type_fiber
||
1294 hw
->media_type
== e1000_media_type_internal_serdes
) {
1295 switch (hw
->mac
.type
) {
1296 case e1000_80003es2lan
:
1297 return e1000_set_es2lan_mac_loopback(adapter
);
1301 return e1000_set_82571_fiber_loopback(adapter
);
1305 rctl
|= E1000_RCTL_LBM_TCVR
;
1309 } else if (hw
->media_type
== e1000_media_type_copper
) {
1310 return e1000_integrated_phy_loopback(adapter
);
1316 static void e1000_loopback_cleanup(struct e1000_adapter
*adapter
)
1318 struct e1000_hw
*hw
= &adapter
->hw
;
1323 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
1326 switch (hw
->mac
.type
) {
1327 case e1000_80003es2lan
:
1328 if (hw
->media_type
== e1000_media_type_fiber
||
1329 hw
->media_type
== e1000_media_type_internal_serdes
) {
1330 /* restore CTRL_EXT, stealing space from tx_fifo_head */
1332 adapter
->tx_fifo_head
);
1333 adapter
->tx_fifo_head
= 0;
1338 if (hw
->media_type
== e1000_media_type_fiber
||
1339 hw
->media_type
== e1000_media_type_internal_serdes
) {
1340 #define E1000_SERDES_LB_OFF 0x400
1341 ew32(SCTL
, E1000_SERDES_LB_OFF
);
1347 hw
->mac
.autoneg
= 1;
1348 if (hw
->phy
.type
== e1000_phy_gg82563
)
1349 e1e_wphy(hw
, GG82563_PHY_KMRN_MODE_CTRL
, 0x180);
1350 e1e_rphy(hw
, PHY_CONTROL
, &phy_reg
);
1351 if (phy_reg
& MII_CR_LOOPBACK
) {
1352 phy_reg
&= ~MII_CR_LOOPBACK
;
1353 e1e_wphy(hw
, PHY_CONTROL
, phy_reg
);
1354 e1000e_commit_phy(hw
);
1360 static void e1000_create_lbtest_frame(struct sk_buff
*skb
,
1361 unsigned int frame_size
)
1363 memset(skb
->data
, 0xFF, frame_size
);
1365 memset(&skb
->data
[frame_size
/ 2], 0xAA, frame_size
/ 2 - 1);
1366 memset(&skb
->data
[frame_size
/ 2 + 10], 0xBE, 1);
1367 memset(&skb
->data
[frame_size
/ 2 + 12], 0xAF, 1);
1370 static int e1000_check_lbtest_frame(struct sk_buff
*skb
,
1371 unsigned int frame_size
)
1374 if (*(skb
->data
+ 3) == 0xFF)
1375 if ((*(skb
->data
+ frame_size
/ 2 + 10) == 0xBE) &&
1376 (*(skb
->data
+ frame_size
/ 2 + 12) == 0xAF))
1381 static int e1000_run_loopback_test(struct e1000_adapter
*adapter
)
1383 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1384 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1385 struct pci_dev
*pdev
= adapter
->pdev
;
1386 struct e1000_hw
*hw
= &adapter
->hw
;
1393 ew32(RDT
, rx_ring
->count
- 1);
1395 /* Calculate the loop count based on the largest descriptor ring
1396 * The idea is to wrap the largest ring a number of times using 64
1397 * send/receive pairs during each loop
1400 if (rx_ring
->count
<= tx_ring
->count
)
1401 lc
= ((tx_ring
->count
/ 64) * 2) + 1;
1403 lc
= ((rx_ring
->count
/ 64) * 2) + 1;
1407 for (j
= 0; j
<= lc
; j
++) { /* loop count loop */
1408 for (i
= 0; i
< 64; i
++) { /* send the packets */
1409 e1000_create_lbtest_frame(
1410 tx_ring
->buffer_info
[i
].skb
, 1024);
1411 pci_dma_sync_single_for_device(pdev
,
1412 tx_ring
->buffer_info
[k
].dma
,
1413 tx_ring
->buffer_info
[k
].length
,
1416 if (k
== tx_ring
->count
)
1421 time
= jiffies
; /* set the start time for the receive */
1423 do { /* receive the sent packets */
1424 pci_dma_sync_single_for_cpu(pdev
,
1425 rx_ring
->buffer_info
[l
].dma
, 2048,
1426 PCI_DMA_FROMDEVICE
);
1428 ret_val
= e1000_check_lbtest_frame(
1429 rx_ring
->buffer_info
[l
].skb
, 1024);
1433 if (l
== rx_ring
->count
)
1435 /* time + 20 msecs (200 msecs on 2.4) is more than
1436 * enough time to complete the receives, if it's
1437 * exceeded, break and error off
1439 } while ((good_cnt
< 64) && !time_after(jiffies
, time
+ 20));
1440 if (good_cnt
!= 64) {
1441 ret_val
= 13; /* ret_val is the same as mis-compare */
1444 if (jiffies
>= (time
+ 2)) {
1445 ret_val
= 14; /* error code for time out error */
1448 } /* end loop count loop */
1452 static int e1000_loopback_test(struct e1000_adapter
*adapter
, u64
*data
)
1454 /* PHY loopback cannot be performed if SoL/IDER
1455 * sessions are active */
1456 if (e1000_check_reset_block(&adapter
->hw
)) {
1457 ndev_err(adapter
->netdev
, "Cannot do PHY loopback test "
1458 "when SoL/IDER is active.\n");
1463 *data
= e1000_setup_desc_rings(adapter
);
1467 *data
= e1000_setup_loopback_test(adapter
);
1471 *data
= e1000_run_loopback_test(adapter
);
1472 e1000_loopback_cleanup(adapter
);
1475 e1000_free_desc_rings(adapter
);
1480 static int e1000_link_test(struct e1000_adapter
*adapter
, u64
*data
)
1482 struct e1000_hw
*hw
= &adapter
->hw
;
1485 if (hw
->media_type
== e1000_media_type_internal_serdes
) {
1487 hw
->mac
.serdes_has_link
= 0;
1489 /* On some blade server designs, link establishment
1490 * could take as long as 2-3 minutes */
1492 hw
->mac
.ops
.check_for_link(hw
);
1493 if (hw
->mac
.serdes_has_link
)
1496 } while (i
++ < 3750);
1500 hw
->mac
.ops
.check_for_link(hw
);
1501 if (hw
->mac
.autoneg
)
1504 if (!(er32(STATUS
) &
1511 static int e1000e_get_sset_count(struct net_device
*netdev
, int sset
)
1515 return E1000_TEST_LEN
;
1517 return E1000_STATS_LEN
;
1523 static void e1000_diag_test(struct net_device
*netdev
,
1524 struct ethtool_test
*eth_test
, u64
*data
)
1526 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1527 u16 autoneg_advertised
;
1528 u8 forced_speed_duplex
;
1530 bool if_running
= netif_running(netdev
);
1532 set_bit(__E1000_TESTING
, &adapter
->state
);
1533 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1536 /* save speed, duplex, autoneg settings */
1537 autoneg_advertised
= adapter
->hw
.phy
.autoneg_advertised
;
1538 forced_speed_duplex
= adapter
->hw
.mac
.forced_speed_duplex
;
1539 autoneg
= adapter
->hw
.mac
.autoneg
;
1541 ndev_info(netdev
, "offline testing starting\n");
1543 /* Link test performed before hardware reset so autoneg doesn't
1544 * interfere with test result */
1545 if (e1000_link_test(adapter
, &data
[4]))
1546 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1549 /* indicate we're in test mode */
1552 e1000e_reset(adapter
);
1554 if (e1000_reg_test(adapter
, &data
[0]))
1555 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1557 e1000e_reset(adapter
);
1558 if (e1000_eeprom_test(adapter
, &data
[1]))
1559 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1561 e1000e_reset(adapter
);
1562 if (e1000_intr_test(adapter
, &data
[2]))
1563 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1565 e1000e_reset(adapter
);
1566 /* make sure the phy is powered up */
1567 e1000e_power_up_phy(adapter
);
1568 if (e1000_loopback_test(adapter
, &data
[3]))
1569 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1571 /* restore speed, duplex, autoneg settings */
1572 adapter
->hw
.phy
.autoneg_advertised
= autoneg_advertised
;
1573 adapter
->hw
.mac
.forced_speed_duplex
= forced_speed_duplex
;
1574 adapter
->hw
.mac
.autoneg
= autoneg
;
1576 /* force this routine to wait until autoneg complete/timeout */
1577 adapter
->hw
.phy
.wait_for_link
= 1;
1578 e1000e_reset(adapter
);
1579 adapter
->hw
.phy
.wait_for_link
= 0;
1581 clear_bit(__E1000_TESTING
, &adapter
->state
);
1585 ndev_info(netdev
, "online testing starting\n");
1587 if (e1000_link_test(adapter
, &data
[4]))
1588 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1590 /* Online tests aren't run; pass by default */
1596 clear_bit(__E1000_TESTING
, &adapter
->state
);
1598 msleep_interruptible(4 * 1000);
1601 static void e1000_get_wol(struct net_device
*netdev
,
1602 struct ethtool_wolinfo
*wol
)
1604 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1609 if (!(adapter
->flags
& FLAG_HAS_WOL
))
1612 wol
->supported
= WAKE_UCAST
| WAKE_MCAST
|
1613 WAKE_BCAST
| WAKE_MAGIC
;
1615 /* apply any specific unsupported masks here */
1616 if (adapter
->flags
& FLAG_NO_WAKE_UCAST
) {
1617 wol
->supported
&= ~WAKE_UCAST
;
1619 if (adapter
->wol
& E1000_WUFC_EX
)
1620 ndev_err(netdev
, "Interface does not support "
1621 "directed (unicast) frame wake-up packets\n");
1624 if (adapter
->wol
& E1000_WUFC_EX
)
1625 wol
->wolopts
|= WAKE_UCAST
;
1626 if (adapter
->wol
& E1000_WUFC_MC
)
1627 wol
->wolopts
|= WAKE_MCAST
;
1628 if (adapter
->wol
& E1000_WUFC_BC
)
1629 wol
->wolopts
|= WAKE_BCAST
;
1630 if (adapter
->wol
& E1000_WUFC_MAG
)
1631 wol
->wolopts
|= WAKE_MAGIC
;
1634 static int e1000_set_wol(struct net_device
*netdev
,
1635 struct ethtool_wolinfo
*wol
)
1637 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1639 if (wol
->wolopts
& (WAKE_PHY
| WAKE_ARP
| WAKE_MAGICSECURE
))
1642 if (!(adapter
->flags
& FLAG_HAS_WOL
))
1643 return wol
->wolopts
? -EOPNOTSUPP
: 0;
1645 /* these settings will always override what we currently have */
1648 if (wol
->wolopts
& WAKE_UCAST
)
1649 adapter
->wol
|= E1000_WUFC_EX
;
1650 if (wol
->wolopts
& WAKE_MCAST
)
1651 adapter
->wol
|= E1000_WUFC_MC
;
1652 if (wol
->wolopts
& WAKE_BCAST
)
1653 adapter
->wol
|= E1000_WUFC_BC
;
1654 if (wol
->wolopts
& WAKE_MAGIC
)
1655 adapter
->wol
|= E1000_WUFC_MAG
;
1660 /* toggle LED 4 times per second = 2 "blinks" per second */
1661 #define E1000_ID_INTERVAL (HZ/4)
1663 /* bit defines for adapter->led_status */
1664 #define E1000_LED_ON 0
1666 static void e1000_led_blink_callback(unsigned long data
)
1668 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
1670 if (test_and_change_bit(E1000_LED_ON
, &adapter
->led_status
))
1671 adapter
->hw
.mac
.ops
.led_off(&adapter
->hw
);
1673 adapter
->hw
.mac
.ops
.led_on(&adapter
->hw
);
1675 mod_timer(&adapter
->blink_timer
, jiffies
+ E1000_ID_INTERVAL
);
1678 static int e1000_phys_id(struct net_device
*netdev
, u32 data
)
1680 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1685 if (adapter
->hw
.phy
.type
== e1000_phy_ife
) {
1686 if (!adapter
->blink_timer
.function
) {
1687 init_timer(&adapter
->blink_timer
);
1688 adapter
->blink_timer
.function
=
1689 e1000_led_blink_callback
;
1690 adapter
->blink_timer
.data
= (unsigned long) adapter
;
1692 mod_timer(&adapter
->blink_timer
, jiffies
);
1693 msleep_interruptible(data
* 1000);
1694 del_timer_sync(&adapter
->blink_timer
);
1695 e1e_wphy(&adapter
->hw
,
1696 IFE_PHY_SPECIAL_CONTROL_LED
, 0);
1698 e1000e_blink_led(&adapter
->hw
);
1699 msleep_interruptible(data
* 1000);
1702 adapter
->hw
.mac
.ops
.led_off(&adapter
->hw
);
1703 clear_bit(E1000_LED_ON
, &adapter
->led_status
);
1704 adapter
->hw
.mac
.ops
.cleanup_led(&adapter
->hw
);
1709 static int e1000_nway_reset(struct net_device
*netdev
)
1711 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1712 if (netif_running(netdev
))
1713 e1000e_reinit_locked(adapter
);
1717 static void e1000_get_ethtool_stats(struct net_device
*netdev
,
1718 struct ethtool_stats
*stats
,
1721 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1724 e1000e_update_stats(adapter
);
1725 for (i
= 0; i
< E1000_GLOBAL_STATS_LEN
; i
++) {
1726 char *p
= (char *)adapter
+e1000_gstrings_stats
[i
].stat_offset
;
1727 data
[i
] = (e1000_gstrings_stats
[i
].sizeof_stat
==
1728 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1732 static void e1000_get_strings(struct net_device
*netdev
, u32 stringset
,
1738 switch (stringset
) {
1740 memcpy(data
, *e1000_gstrings_test
,
1741 sizeof(e1000_gstrings_test
));
1744 for (i
= 0; i
< E1000_GLOBAL_STATS_LEN
; i
++) {
1745 memcpy(p
, e1000_gstrings_stats
[i
].stat_string
,
1747 p
+= ETH_GSTRING_LEN
;
1753 static const struct ethtool_ops e1000_ethtool_ops
= {
1754 .get_settings
= e1000_get_settings
,
1755 .set_settings
= e1000_set_settings
,
1756 .get_drvinfo
= e1000_get_drvinfo
,
1757 .get_regs_len
= e1000_get_regs_len
,
1758 .get_regs
= e1000_get_regs
,
1759 .get_wol
= e1000_get_wol
,
1760 .set_wol
= e1000_set_wol
,
1761 .get_msglevel
= e1000_get_msglevel
,
1762 .set_msglevel
= e1000_set_msglevel
,
1763 .nway_reset
= e1000_nway_reset
,
1764 .get_link
= e1000_get_link
,
1765 .get_eeprom_len
= e1000_get_eeprom_len
,
1766 .get_eeprom
= e1000_get_eeprom
,
1767 .set_eeprom
= e1000_set_eeprom
,
1768 .get_ringparam
= e1000_get_ringparam
,
1769 .set_ringparam
= e1000_set_ringparam
,
1770 .get_pauseparam
= e1000_get_pauseparam
,
1771 .set_pauseparam
= e1000_set_pauseparam
,
1772 .get_rx_csum
= e1000_get_rx_csum
,
1773 .set_rx_csum
= e1000_set_rx_csum
,
1774 .get_tx_csum
= e1000_get_tx_csum
,
1775 .set_tx_csum
= e1000_set_tx_csum
,
1776 .get_sg
= ethtool_op_get_sg
,
1777 .set_sg
= ethtool_op_set_sg
,
1778 .get_tso
= ethtool_op_get_tso
,
1779 .set_tso
= e1000_set_tso
,
1780 .self_test
= e1000_diag_test
,
1781 .get_strings
= e1000_get_strings
,
1782 .phys_id
= e1000_phys_id
,
1783 .get_ethtool_stats
= e1000_get_ethtool_stats
,
1784 .get_sset_count
= e1000e_get_sset_count
,
1787 void e1000e_set_ethtool_ops(struct net_device
*netdev
)
1789 SET_ETHTOOL_OPS(netdev
, &e1000_ethtool_ops
);