1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2008 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
.gorc
) },
50 { "tx_bytes", E1000_STAT(stats
.gotc
) },
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
.gorc
) },
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
->phy
.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
->phy
.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
) ? 1 : 0;
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
.phy
.media_type
== e1000_media_type_fiber
) &&
191 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
192 e_err("Unsupported Speed/Duplex configuration\n");
197 case SPEED_10
+ DUPLEX_HALF
:
198 mac
->forced_speed_duplex
= ADVERTISE_10_HALF
;
200 case SPEED_10
+ DUPLEX_FULL
:
201 mac
->forced_speed_duplex
= ADVERTISE_10_FULL
;
203 case SPEED_100
+ DUPLEX_HALF
:
204 mac
->forced_speed_duplex
= ADVERTISE_100_HALF
;
206 case SPEED_100
+ DUPLEX_FULL
:
207 mac
->forced_speed_duplex
= ADVERTISE_100_FULL
;
209 case SPEED_1000
+ DUPLEX_FULL
:
211 adapter
->hw
.phy
.autoneg_advertised
= ADVERTISE_1000_FULL
;
213 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
215 e_err("Unsupported Speed/Duplex configuration\n");
221 static int e1000_set_settings(struct net_device
*netdev
,
222 struct ethtool_cmd
*ecmd
)
224 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
225 struct e1000_hw
*hw
= &adapter
->hw
;
228 * When SoL/IDER sessions are active, autoneg/speed/duplex
231 if (e1000_check_reset_block(hw
)) {
232 e_err("Cannot change link characteristics when SoL/IDER is "
237 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
240 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
242 if (hw
->phy
.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
;
251 if (adapter
->fc_autoneg
)
252 hw
->fc
.requested_mode
= e1000_fc_default
;
254 if (e1000_set_spd_dplx(adapter
, ecmd
->speed
+ ecmd
->duplex
)) {
255 clear_bit(__E1000_RESETTING
, &adapter
->state
);
262 if (netif_running(adapter
->netdev
)) {
263 e1000e_down(adapter
);
266 e1000e_reset(adapter
);
269 clear_bit(__E1000_RESETTING
, &adapter
->state
);
273 static void e1000_get_pauseparam(struct net_device
*netdev
,
274 struct ethtool_pauseparam
*pause
)
276 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
277 struct e1000_hw
*hw
= &adapter
->hw
;
280 (adapter
->fc_autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
);
282 if (hw
->fc
.current_mode
== e1000_fc_rx_pause
) {
284 } else if (hw
->fc
.current_mode
== e1000_fc_tx_pause
) {
286 } else if (hw
->fc
.current_mode
== e1000_fc_full
) {
292 static int e1000_set_pauseparam(struct net_device
*netdev
,
293 struct ethtool_pauseparam
*pause
)
295 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
296 struct e1000_hw
*hw
= &adapter
->hw
;
299 adapter
->fc_autoneg
= pause
->autoneg
;
301 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
304 if (adapter
->fc_autoneg
== AUTONEG_ENABLE
) {
305 hw
->fc
.requested_mode
= e1000_fc_default
;
306 if (netif_running(adapter
->netdev
)) {
307 e1000e_down(adapter
);
310 e1000e_reset(adapter
);
313 if (pause
->rx_pause
&& pause
->tx_pause
)
314 hw
->fc
.requested_mode
= e1000_fc_full
;
315 else if (pause
->rx_pause
&& !pause
->tx_pause
)
316 hw
->fc
.requested_mode
= e1000_fc_rx_pause
;
317 else if (!pause
->rx_pause
&& pause
->tx_pause
)
318 hw
->fc
.requested_mode
= e1000_fc_tx_pause
;
319 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
320 hw
->fc
.requested_mode
= e1000_fc_none
;
322 hw
->fc
.current_mode
= hw
->fc
.requested_mode
;
324 retval
= ((hw
->phy
.media_type
== e1000_media_type_fiber
) ?
325 hw
->mac
.ops
.setup_link(hw
) : e1000e_force_mac_fc(hw
));
328 clear_bit(__E1000_RESETTING
, &adapter
->state
);
332 static u32
e1000_get_rx_csum(struct net_device
*netdev
)
334 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
335 return (adapter
->flags
& FLAG_RX_CSUM_ENABLED
);
338 static int e1000_set_rx_csum(struct net_device
*netdev
, u32 data
)
340 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
343 adapter
->flags
|= FLAG_RX_CSUM_ENABLED
;
345 adapter
->flags
&= ~FLAG_RX_CSUM_ENABLED
;
347 if (netif_running(netdev
))
348 e1000e_reinit_locked(adapter
);
350 e1000e_reset(adapter
);
354 static u32
e1000_get_tx_csum(struct net_device
*netdev
)
356 return ((netdev
->features
& NETIF_F_HW_CSUM
) != 0);
359 static int e1000_set_tx_csum(struct net_device
*netdev
, u32 data
)
362 netdev
->features
|= NETIF_F_HW_CSUM
;
364 netdev
->features
&= ~NETIF_F_HW_CSUM
;
369 static int e1000_set_tso(struct net_device
*netdev
, u32 data
)
371 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
374 netdev
->features
|= NETIF_F_TSO
;
375 netdev
->features
|= NETIF_F_TSO6
;
377 netdev
->features
&= ~NETIF_F_TSO
;
378 netdev
->features
&= ~NETIF_F_TSO6
;
381 e_info("TSO is %s\n", data
? "Enabled" : "Disabled");
382 adapter
->flags
|= FLAG_TSO_FORCE
;
386 static u32
e1000_get_msglevel(struct net_device
*netdev
)
388 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
389 return adapter
->msg_enable
;
392 static void e1000_set_msglevel(struct net_device
*netdev
, u32 data
)
394 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
395 adapter
->msg_enable
= data
;
398 static int e1000_get_regs_len(struct net_device
*netdev
)
400 #define E1000_REGS_LEN 32 /* overestimate */
401 return E1000_REGS_LEN
* sizeof(u32
);
404 static void e1000_get_regs(struct net_device
*netdev
,
405 struct ethtool_regs
*regs
, void *p
)
407 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
408 struct e1000_hw
*hw
= &adapter
->hw
;
413 memset(p
, 0, E1000_REGS_LEN
* sizeof(u32
));
415 pci_read_config_byte(adapter
->pdev
, PCI_REVISION_ID
, &revision_id
);
417 regs
->version
= (1 << 24) | (revision_id
<< 16) | adapter
->pdev
->device
;
419 regs_buff
[0] = er32(CTRL
);
420 regs_buff
[1] = er32(STATUS
);
422 regs_buff
[2] = er32(RCTL
);
423 regs_buff
[3] = er32(RDLEN
);
424 regs_buff
[4] = er32(RDH
);
425 regs_buff
[5] = er32(RDT
);
426 regs_buff
[6] = er32(RDTR
);
428 regs_buff
[7] = er32(TCTL
);
429 regs_buff
[8] = er32(TDLEN
);
430 regs_buff
[9] = er32(TDH
);
431 regs_buff
[10] = er32(TDT
);
432 regs_buff
[11] = er32(TIDV
);
434 regs_buff
[12] = adapter
->hw
.phy
.type
; /* PHY type (IGP=1, M88=0) */
436 /* ethtool doesn't use anything past this point, so all this
437 * code is likely legacy junk for apps that may or may not
439 if (hw
->phy
.type
== e1000_phy_m88
) {
440 e1e_rphy(hw
, M88E1000_PHY_SPEC_STATUS
, &phy_data
);
441 regs_buff
[13] = (u32
)phy_data
; /* cable length */
442 regs_buff
[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
443 regs_buff
[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
444 regs_buff
[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
445 e1e_rphy(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
446 regs_buff
[17] = (u32
)phy_data
; /* extended 10bt distance */
447 regs_buff
[18] = regs_buff
[13]; /* cable polarity */
448 regs_buff
[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
449 regs_buff
[20] = regs_buff
[17]; /* polarity correction */
450 /* phy receive errors */
451 regs_buff
[22] = adapter
->phy_stats
.receive_errors
;
452 regs_buff
[23] = regs_buff
[13]; /* mdix mode */
454 regs_buff
[21] = 0; /* was idle_errors */
455 e1e_rphy(hw
, PHY_1000T_STATUS
, &phy_data
);
456 regs_buff
[24] = (u32
)phy_data
; /* phy local receiver status */
457 regs_buff
[25] = regs_buff
[24]; /* phy remote receiver status */
460 static int e1000_get_eeprom_len(struct net_device
*netdev
)
462 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
463 return adapter
->hw
.nvm
.word_size
* 2;
466 static int e1000_get_eeprom(struct net_device
*netdev
,
467 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
469 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
470 struct e1000_hw
*hw
= &adapter
->hw
;
477 if (eeprom
->len
== 0)
480 eeprom
->magic
= adapter
->pdev
->vendor
| (adapter
->pdev
->device
<< 16);
482 first_word
= eeprom
->offset
>> 1;
483 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
485 eeprom_buff
= kmalloc(sizeof(u16
) *
486 (last_word
- first_word
+ 1), GFP_KERNEL
);
490 if (hw
->nvm
.type
== e1000_nvm_eeprom_spi
) {
491 ret_val
= e1000_read_nvm(hw
, first_word
,
492 last_word
- first_word
+ 1,
495 for (i
= 0; i
< last_word
- first_word
+ 1; i
++) {
496 ret_val
= e1000_read_nvm(hw
, first_word
+ i
, 1,
499 /* a read error occurred, throw away the
501 memset(eeprom_buff
, 0xff, sizeof(eeprom_buff
));
507 /* Device's eeprom is always little-endian, word addressable */
508 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
509 le16_to_cpus(&eeprom_buff
[i
]);
511 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 1), eeprom
->len
);
517 static int e1000_set_eeprom(struct net_device
*netdev
,
518 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
520 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
521 struct e1000_hw
*hw
= &adapter
->hw
;
530 if (eeprom
->len
== 0)
533 if (eeprom
->magic
!= (adapter
->pdev
->vendor
| (adapter
->pdev
->device
<< 16)))
536 if (adapter
->flags
& FLAG_READ_ONLY_NVM
)
539 max_len
= hw
->nvm
.word_size
* 2;
541 first_word
= eeprom
->offset
>> 1;
542 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
543 eeprom_buff
= kmalloc(max_len
, GFP_KERNEL
);
547 ptr
= (void *)eeprom_buff
;
549 if (eeprom
->offset
& 1) {
550 /* need read/modify/write of first changed EEPROM word */
551 /* only the second byte of the word is being modified */
552 ret_val
= e1000_read_nvm(hw
, first_word
, 1, &eeprom_buff
[0]);
555 if (((eeprom
->offset
+ eeprom
->len
) & 1) && (ret_val
== 0))
556 /* need read/modify/write of last changed EEPROM word */
557 /* only the first byte of the word is being modified */
558 ret_val
= e1000_read_nvm(hw
, last_word
, 1,
559 &eeprom_buff
[last_word
- first_word
]);
561 /* Device's eeprom is always little-endian, word addressable */
562 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
563 le16_to_cpus(&eeprom_buff
[i
]);
565 memcpy(ptr
, bytes
, eeprom
->len
);
567 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
568 eeprom_buff
[i
] = cpu_to_le16(eeprom_buff
[i
]);
570 ret_val
= e1000_write_nvm(hw
, first_word
,
571 last_word
- first_word
+ 1, eeprom_buff
);
574 * Update the checksum over the first part of the EEPROM if needed
575 * and flush shadow RAM for 82573 controllers
577 if ((ret_val
== 0) && ((first_word
<= NVM_CHECKSUM_REG
) ||
578 (hw
->mac
.type
== e1000_82574
) ||
579 (hw
->mac
.type
== e1000_82573
)))
580 e1000e_update_nvm_checksum(hw
);
586 static void e1000_get_drvinfo(struct net_device
*netdev
,
587 struct ethtool_drvinfo
*drvinfo
)
589 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
590 char firmware_version
[32];
593 strncpy(drvinfo
->driver
, e1000e_driver_name
, 32);
594 strncpy(drvinfo
->version
, e1000e_driver_version
, 32);
597 * EEPROM image version # is reported as firmware version # for
600 e1000_read_nvm(&adapter
->hw
, 5, 1, &eeprom_data
);
601 sprintf(firmware_version
, "%d.%d-%d",
602 (eeprom_data
& 0xF000) >> 12,
603 (eeprom_data
& 0x0FF0) >> 4,
604 eeprom_data
& 0x000F);
606 strncpy(drvinfo
->fw_version
, firmware_version
, 32);
607 strncpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
), 32);
608 drvinfo
->regdump_len
= e1000_get_regs_len(netdev
);
609 drvinfo
->eedump_len
= e1000_get_eeprom_len(netdev
);
612 static void e1000_get_ringparam(struct net_device
*netdev
,
613 struct ethtool_ringparam
*ring
)
615 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
616 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
617 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
619 ring
->rx_max_pending
= E1000_MAX_RXD
;
620 ring
->tx_max_pending
= E1000_MAX_TXD
;
621 ring
->rx_mini_max_pending
= 0;
622 ring
->rx_jumbo_max_pending
= 0;
623 ring
->rx_pending
= rx_ring
->count
;
624 ring
->tx_pending
= tx_ring
->count
;
625 ring
->rx_mini_pending
= 0;
626 ring
->rx_jumbo_pending
= 0;
629 static int e1000_set_ringparam(struct net_device
*netdev
,
630 struct ethtool_ringparam
*ring
)
632 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
633 struct e1000_ring
*tx_ring
, *tx_old
;
634 struct e1000_ring
*rx_ring
, *rx_old
;
637 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
640 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
643 if (netif_running(adapter
->netdev
))
644 e1000e_down(adapter
);
646 tx_old
= adapter
->tx_ring
;
647 rx_old
= adapter
->rx_ring
;
650 tx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
654 * use a memcpy to save any previously configured
655 * items like napi structs from having to be
658 memcpy(tx_ring
, tx_old
, sizeof(struct e1000_ring
));
660 rx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
663 memcpy(rx_ring
, rx_old
, sizeof(struct e1000_ring
));
665 adapter
->tx_ring
= tx_ring
;
666 adapter
->rx_ring
= rx_ring
;
668 rx_ring
->count
= max(ring
->rx_pending
, (u32
)E1000_MIN_RXD
);
669 rx_ring
->count
= min(rx_ring
->count
, (u32
)(E1000_MAX_RXD
));
670 rx_ring
->count
= ALIGN(rx_ring
->count
, REQ_RX_DESCRIPTOR_MULTIPLE
);
672 tx_ring
->count
= max(ring
->tx_pending
, (u32
)E1000_MIN_TXD
);
673 tx_ring
->count
= min(tx_ring
->count
, (u32
)(E1000_MAX_TXD
));
674 tx_ring
->count
= ALIGN(tx_ring
->count
, REQ_TX_DESCRIPTOR_MULTIPLE
);
676 if (netif_running(adapter
->netdev
)) {
677 /* Try to get new resources before deleting old */
678 err
= e1000e_setup_rx_resources(adapter
);
681 err
= e1000e_setup_tx_resources(adapter
);
686 * restore the old in order to free it,
687 * then add in the new
689 adapter
->rx_ring
= rx_old
;
690 adapter
->tx_ring
= tx_old
;
691 e1000e_free_rx_resources(adapter
);
692 e1000e_free_tx_resources(adapter
);
695 adapter
->rx_ring
= rx_ring
;
696 adapter
->tx_ring
= tx_ring
;
697 err
= e1000e_up(adapter
);
702 clear_bit(__E1000_RESETTING
, &adapter
->state
);
705 e1000e_free_rx_resources(adapter
);
707 adapter
->rx_ring
= rx_old
;
708 adapter
->tx_ring
= tx_old
;
715 clear_bit(__E1000_RESETTING
, &adapter
->state
);
719 static bool reg_pattern_test(struct e1000_adapter
*adapter
, u64
*data
,
720 int reg
, int offset
, u32 mask
, u32 write
)
723 static const u32 test
[] =
724 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
725 for (pat
= 0; pat
< ARRAY_SIZE(test
); pat
++) {
726 E1000_WRITE_REG_ARRAY(&adapter
->hw
, reg
, offset
,
727 (test
[pat
] & write
));
728 val
= E1000_READ_REG_ARRAY(&adapter
->hw
, reg
, offset
);
729 if (val
!= (test
[pat
] & write
& mask
)) {
730 e_err("pattern test reg %04X failed: got 0x%08X "
731 "expected 0x%08X\n", reg
+ offset
, val
,
732 (test
[pat
] & write
& mask
));
740 static bool reg_set_and_check(struct e1000_adapter
*adapter
, u64
*data
,
741 int reg
, u32 mask
, u32 write
)
744 __ew32(&adapter
->hw
, reg
, write
& mask
);
745 val
= __er32(&adapter
->hw
, reg
);
746 if ((write
& mask
) != (val
& mask
)) {
747 e_err("set/check reg %04X test failed: got 0x%08X "
748 "expected 0x%08X\n", reg
, (val
& mask
), (write
& mask
));
754 #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
756 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
759 #define REG_PATTERN_TEST(reg, mask, write) \
760 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
762 #define REG_SET_AND_CHECK(reg, mask, write) \
764 if (reg_set_and_check(adapter, data, reg, mask, write)) \
768 static int e1000_reg_test(struct e1000_adapter
*adapter
, u64
*data
)
770 struct e1000_hw
*hw
= &adapter
->hw
;
771 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
779 * The status register is Read Only, so a write should fail.
780 * Some bits that get toggled are ignored.
783 /* there are several bits on newer hardware that are r/w */
786 case e1000_80003es2lan
:
801 before
= er32(STATUS
);
802 value
= (er32(STATUS
) & toggle
);
803 ew32(STATUS
, toggle
);
804 after
= er32(STATUS
) & toggle
;
805 if (value
!= after
) {
806 e_err("failed STATUS register test got: 0x%08X expected: "
807 "0x%08X\n", after
, value
);
811 /* restore previous status */
812 ew32(STATUS
, before
);
814 if (!(adapter
->flags
& FLAG_IS_ICH
)) {
815 REG_PATTERN_TEST(E1000_FCAL
, 0xFFFFFFFF, 0xFFFFFFFF);
816 REG_PATTERN_TEST(E1000_FCAH
, 0x0000FFFF, 0xFFFFFFFF);
817 REG_PATTERN_TEST(E1000_FCT
, 0x0000FFFF, 0xFFFFFFFF);
818 REG_PATTERN_TEST(E1000_VET
, 0x0000FFFF, 0xFFFFFFFF);
821 REG_PATTERN_TEST(E1000_RDTR
, 0x0000FFFF, 0xFFFFFFFF);
822 REG_PATTERN_TEST(E1000_RDBAH
, 0xFFFFFFFF, 0xFFFFFFFF);
823 REG_PATTERN_TEST(E1000_RDLEN
, 0x000FFF80, 0x000FFFFF);
824 REG_PATTERN_TEST(E1000_RDH
, 0x0000FFFF, 0x0000FFFF);
825 REG_PATTERN_TEST(E1000_RDT
, 0x0000FFFF, 0x0000FFFF);
826 REG_PATTERN_TEST(E1000_FCRTH
, 0x0000FFF8, 0x0000FFF8);
827 REG_PATTERN_TEST(E1000_FCTTV
, 0x0000FFFF, 0x0000FFFF);
828 REG_PATTERN_TEST(E1000_TIPG
, 0x3FFFFFFF, 0x3FFFFFFF);
829 REG_PATTERN_TEST(E1000_TDBAH
, 0xFFFFFFFF, 0xFFFFFFFF);
830 REG_PATTERN_TEST(E1000_TDLEN
, 0x000FFF80, 0x000FFFFF);
832 REG_SET_AND_CHECK(E1000_RCTL
, 0xFFFFFFFF, 0x00000000);
834 before
= ((adapter
->flags
& FLAG_IS_ICH
) ? 0x06C3B33E : 0x06DFB3FE);
835 REG_SET_AND_CHECK(E1000_RCTL
, before
, 0x003FFFFB);
836 REG_SET_AND_CHECK(E1000_TCTL
, 0xFFFFFFFF, 0x00000000);
838 REG_SET_AND_CHECK(E1000_RCTL
, before
, 0xFFFFFFFF);
839 REG_PATTERN_TEST(E1000_RDBAL
, 0xFFFFFFF0, 0xFFFFFFFF);
840 if (!(adapter
->flags
& FLAG_IS_ICH
))
841 REG_PATTERN_TEST(E1000_TXCW
, 0xC000FFFF, 0x0000FFFF);
842 REG_PATTERN_TEST(E1000_TDBAL
, 0xFFFFFFF0, 0xFFFFFFFF);
843 REG_PATTERN_TEST(E1000_TIDV
, 0x0000FFFF, 0x0000FFFF);
844 for (i
= 0; i
< mac
->rar_entry_count
; i
++)
845 REG_PATTERN_TEST_ARRAY(E1000_RA
, ((i
<< 1) + 1),
846 ((mac
->type
== e1000_ich10lan
) ?
847 0x8007FFFF : 0x8003FFFF),
850 for (i
= 0; i
< mac
->mta_reg_count
; i
++)
851 REG_PATTERN_TEST_ARRAY(E1000_MTA
, i
, 0xFFFFFFFF, 0xFFFFFFFF);
857 static int e1000_eeprom_test(struct e1000_adapter
*adapter
, u64
*data
)
864 /* Read and add up the contents of the EEPROM */
865 for (i
= 0; i
< (NVM_CHECKSUM_REG
+ 1); i
++) {
866 if ((e1000_read_nvm(&adapter
->hw
, i
, 1, &temp
)) < 0) {
873 /* If Checksum is not Correct return error else test passed */
874 if ((checksum
!= (u16
) NVM_SUM
) && !(*data
))
880 static irqreturn_t
e1000_test_intr(int irq
, void *data
)
882 struct net_device
*netdev
= (struct net_device
*) data
;
883 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
884 struct e1000_hw
*hw
= &adapter
->hw
;
886 adapter
->test_icr
|= er32(ICR
);
891 static int e1000_intr_test(struct e1000_adapter
*adapter
, u64
*data
)
893 struct net_device
*netdev
= adapter
->netdev
;
894 struct e1000_hw
*hw
= &adapter
->hw
;
897 u32 irq
= adapter
->pdev
->irq
;
900 int int_mode
= E1000E_INT_MODE_LEGACY
;
904 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
905 if (adapter
->int_mode
== E1000E_INT_MODE_MSIX
) {
906 int_mode
= adapter
->int_mode
;
907 e1000e_reset_interrupt_capability(adapter
);
908 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
909 e1000e_set_interrupt_capability(adapter
);
911 /* Hook up test interrupt handler just for this test */
912 if (!request_irq(irq
, &e1000_test_intr
, IRQF_PROBE_SHARED
, netdev
->name
,
915 } else if (request_irq(irq
, &e1000_test_intr
, IRQF_SHARED
,
916 netdev
->name
, netdev
)) {
921 e_info("testing %s interrupt\n", (shared_int
? "shared" : "unshared"));
923 /* Disable all the interrupts */
924 ew32(IMC
, 0xFFFFFFFF);
927 /* Test each interrupt */
928 for (i
= 0; i
< 10; i
++) {
929 /* Interrupt to test */
932 if (adapter
->flags
& FLAG_IS_ICH
) {
934 case E1000_ICR_RXSEQ
:
937 if (adapter
->hw
.mac
.type
== e1000_ich8lan
||
938 adapter
->hw
.mac
.type
== e1000_ich9lan
)
948 * Disable the interrupt to be reported in
949 * the cause register and then force the same
950 * interrupt and see if one gets posted. If
951 * an interrupt was posted to the bus, the
954 adapter
->test_icr
= 0;
959 if (adapter
->test_icr
& mask
) {
966 * Enable the interrupt to be reported in
967 * the cause register and then force the same
968 * interrupt and see if one gets posted. If
969 * an interrupt was not posted to the bus, the
972 adapter
->test_icr
= 0;
977 if (!(adapter
->test_icr
& mask
)) {
984 * Disable the other interrupts to be reported in
985 * the cause register and then force the other
986 * interrupts and see if any get posted. If
987 * an interrupt was posted to the bus, the
990 adapter
->test_icr
= 0;
991 ew32(IMC
, ~mask
& 0x00007FFF);
992 ew32(ICS
, ~mask
& 0x00007FFF);
995 if (adapter
->test_icr
) {
1002 /* Disable all the interrupts */
1003 ew32(IMC
, 0xFFFFFFFF);
1006 /* Unhook test interrupt handler */
1007 free_irq(irq
, netdev
);
1010 if (int_mode
== E1000E_INT_MODE_MSIX
) {
1011 e1000e_reset_interrupt_capability(adapter
);
1012 adapter
->int_mode
= int_mode
;
1013 e1000e_set_interrupt_capability(adapter
);
1019 static void e1000_free_desc_rings(struct e1000_adapter
*adapter
)
1021 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1022 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1023 struct pci_dev
*pdev
= adapter
->pdev
;
1026 if (tx_ring
->desc
&& tx_ring
->buffer_info
) {
1027 for (i
= 0; i
< tx_ring
->count
; i
++) {
1028 if (tx_ring
->buffer_info
[i
].dma
)
1029 pci_unmap_single(pdev
,
1030 tx_ring
->buffer_info
[i
].dma
,
1031 tx_ring
->buffer_info
[i
].length
,
1033 if (tx_ring
->buffer_info
[i
].skb
)
1034 dev_kfree_skb(tx_ring
->buffer_info
[i
].skb
);
1038 if (rx_ring
->desc
&& rx_ring
->buffer_info
) {
1039 for (i
= 0; i
< rx_ring
->count
; i
++) {
1040 if (rx_ring
->buffer_info
[i
].dma
)
1041 pci_unmap_single(pdev
,
1042 rx_ring
->buffer_info
[i
].dma
,
1043 2048, PCI_DMA_FROMDEVICE
);
1044 if (rx_ring
->buffer_info
[i
].skb
)
1045 dev_kfree_skb(rx_ring
->buffer_info
[i
].skb
);
1049 if (tx_ring
->desc
) {
1050 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
1052 tx_ring
->desc
= NULL
;
1054 if (rx_ring
->desc
) {
1055 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
1057 rx_ring
->desc
= NULL
;
1060 kfree(tx_ring
->buffer_info
);
1061 tx_ring
->buffer_info
= NULL
;
1062 kfree(rx_ring
->buffer_info
);
1063 rx_ring
->buffer_info
= NULL
;
1066 static int e1000_setup_desc_rings(struct e1000_adapter
*adapter
)
1068 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1069 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1070 struct pci_dev
*pdev
= adapter
->pdev
;
1071 struct e1000_hw
*hw
= &adapter
->hw
;
1076 /* Setup Tx descriptor ring and Tx buffers */
1078 if (!tx_ring
->count
)
1079 tx_ring
->count
= E1000_DEFAULT_TXD
;
1081 tx_ring
->buffer_info
= kcalloc(tx_ring
->count
,
1082 sizeof(struct e1000_buffer
),
1084 if (!(tx_ring
->buffer_info
)) {
1089 tx_ring
->size
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
1090 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1091 tx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, tx_ring
->size
,
1092 &tx_ring
->dma
, GFP_KERNEL
);
1093 if (!tx_ring
->desc
) {
1097 tx_ring
->next_to_use
= 0;
1098 tx_ring
->next_to_clean
= 0;
1100 ew32(TDBAL
, ((u64
) tx_ring
->dma
& 0x00000000FFFFFFFF));
1101 ew32(TDBAH
, ((u64
) tx_ring
->dma
>> 32));
1102 ew32(TDLEN
, tx_ring
->count
* sizeof(struct e1000_tx_desc
));
1105 ew32(TCTL
, E1000_TCTL_PSP
| E1000_TCTL_EN
| E1000_TCTL_MULR
|
1106 E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
|
1107 E1000_COLLISION_DISTANCE
<< E1000_COLD_SHIFT
);
1109 for (i
= 0; i
< tx_ring
->count
; i
++) {
1110 struct e1000_tx_desc
*tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
1111 struct sk_buff
*skb
;
1112 unsigned int skb_size
= 1024;
1114 skb
= alloc_skb(skb_size
, GFP_KERNEL
);
1119 skb_put(skb
, skb_size
);
1120 tx_ring
->buffer_info
[i
].skb
= skb
;
1121 tx_ring
->buffer_info
[i
].length
= skb
->len
;
1122 tx_ring
->buffer_info
[i
].dma
=
1123 pci_map_single(pdev
, skb
->data
, skb
->len
,
1125 if (pci_dma_mapping_error(pdev
, tx_ring
->buffer_info
[i
].dma
)) {
1129 tx_desc
->buffer_addr
= cpu_to_le64(tx_ring
->buffer_info
[i
].dma
);
1130 tx_desc
->lower
.data
= cpu_to_le32(skb
->len
);
1131 tx_desc
->lower
.data
|= cpu_to_le32(E1000_TXD_CMD_EOP
|
1132 E1000_TXD_CMD_IFCS
|
1134 tx_desc
->upper
.data
= 0;
1137 /* Setup Rx descriptor ring and Rx buffers */
1139 if (!rx_ring
->count
)
1140 rx_ring
->count
= E1000_DEFAULT_RXD
;
1142 rx_ring
->buffer_info
= kcalloc(rx_ring
->count
,
1143 sizeof(struct e1000_buffer
),
1145 if (!(rx_ring
->buffer_info
)) {
1150 rx_ring
->size
= rx_ring
->count
* sizeof(struct e1000_rx_desc
);
1151 rx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, rx_ring
->size
,
1152 &rx_ring
->dma
, GFP_KERNEL
);
1153 if (!rx_ring
->desc
) {
1157 rx_ring
->next_to_use
= 0;
1158 rx_ring
->next_to_clean
= 0;
1161 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1162 ew32(RDBAL
, ((u64
) rx_ring
->dma
& 0xFFFFFFFF));
1163 ew32(RDBAH
, ((u64
) rx_ring
->dma
>> 32));
1164 ew32(RDLEN
, rx_ring
->size
);
1167 rctl
= E1000_RCTL_EN
| E1000_RCTL_BAM
| E1000_RCTL_SZ_2048
|
1168 E1000_RCTL_UPE
| E1000_RCTL_MPE
| E1000_RCTL_LPE
|
1169 E1000_RCTL_SBP
| E1000_RCTL_SECRC
|
1170 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1171 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1174 for (i
= 0; i
< rx_ring
->count
; i
++) {
1175 struct e1000_rx_desc
*rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
1176 struct sk_buff
*skb
;
1178 skb
= alloc_skb(2048 + NET_IP_ALIGN
, GFP_KERNEL
);
1183 skb_reserve(skb
, NET_IP_ALIGN
);
1184 rx_ring
->buffer_info
[i
].skb
= skb
;
1185 rx_ring
->buffer_info
[i
].dma
=
1186 pci_map_single(pdev
, skb
->data
, 2048,
1187 PCI_DMA_FROMDEVICE
);
1188 if (pci_dma_mapping_error(pdev
, rx_ring
->buffer_info
[i
].dma
)) {
1192 rx_desc
->buffer_addr
=
1193 cpu_to_le64(rx_ring
->buffer_info
[i
].dma
);
1194 memset(skb
->data
, 0x00, skb
->len
);
1200 e1000_free_desc_rings(adapter
);
1204 static void e1000_phy_disable_receiver(struct e1000_adapter
*adapter
)
1206 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1207 e1e_wphy(&adapter
->hw
, 29, 0x001F);
1208 e1e_wphy(&adapter
->hw
, 30, 0x8FFC);
1209 e1e_wphy(&adapter
->hw
, 29, 0x001A);
1210 e1e_wphy(&adapter
->hw
, 30, 0x8FF0);
1213 static int e1000_integrated_phy_loopback(struct e1000_adapter
*adapter
)
1215 struct e1000_hw
*hw
= &adapter
->hw
;
1220 hw
->mac
.autoneg
= 0;
1222 if (hw
->phy
.type
== e1000_phy_m88
) {
1223 /* Auto-MDI/MDIX Off */
1224 e1e_wphy(hw
, M88E1000_PHY_SPEC_CTRL
, 0x0808);
1225 /* reset to update Auto-MDI/MDIX */
1226 e1e_wphy(hw
, PHY_CONTROL
, 0x9140);
1228 e1e_wphy(hw
, PHY_CONTROL
, 0x8140);
1229 } else if (hw
->phy
.type
== e1000_phy_gg82563
)
1230 e1e_wphy(hw
, GG82563_PHY_KMRN_MODE_CTRL
, 0x1CC);
1232 ctrl_reg
= er32(CTRL
);
1234 switch (hw
->phy
.type
) {
1236 /* force 100, set loopback */
1237 e1e_wphy(hw
, PHY_CONTROL
, 0x6100);
1239 /* Now set up the MAC to the same speed/duplex as the PHY. */
1240 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1241 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1242 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1243 E1000_CTRL_SPD_100
|/* Force Speed to 100 */
1244 E1000_CTRL_FD
); /* Force Duplex to FULL */
1247 /* Set Default MAC Interface speed to 1GB */
1248 e1e_rphy(hw
, PHY_REG(2, 21), &phy_reg
);
1251 e1e_wphy(hw
, PHY_REG(2, 21), phy_reg
);
1252 /* Assert SW reset for above settings to take effect */
1253 e1000e_commit_phy(hw
);
1255 /* Force Full Duplex */
1256 e1e_rphy(hw
, PHY_REG(769, 16), &phy_reg
);
1257 e1e_wphy(hw
, PHY_REG(769, 16), phy_reg
| 0x000C);
1258 /* Set Link Up (in force link) */
1259 e1e_rphy(hw
, PHY_REG(776, 16), &phy_reg
);
1260 e1e_wphy(hw
, PHY_REG(776, 16), phy_reg
| 0x0040);
1262 e1e_rphy(hw
, PHY_REG(769, 16), &phy_reg
);
1263 e1e_wphy(hw
, PHY_REG(769, 16), phy_reg
| 0x0040);
1264 /* Set Early Link Enable */
1265 e1e_rphy(hw
, PHY_REG(769, 20), &phy_reg
);
1266 e1e_wphy(hw
, PHY_REG(769, 20), phy_reg
| 0x0400);
1269 /* force 1000, set loopback */
1270 e1e_wphy(hw
, PHY_CONTROL
, 0x4140);
1273 /* Now set up the MAC to the same speed/duplex as the PHY. */
1274 ctrl_reg
= er32(CTRL
);
1275 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1276 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1277 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1278 E1000_CTRL_SPD_1000
|/* Force Speed to 1000 */
1279 E1000_CTRL_FD
); /* Force Duplex to FULL */
1281 if (adapter
->flags
& FLAG_IS_ICH
)
1282 ctrl_reg
|= E1000_CTRL_SLU
; /* Set Link Up */
1285 if (hw
->phy
.media_type
== e1000_media_type_copper
&&
1286 hw
->phy
.type
== e1000_phy_m88
) {
1287 ctrl_reg
|= E1000_CTRL_ILOS
; /* Invert Loss of Signal */
1290 * Set the ILOS bit on the fiber Nic if half duplex link is
1293 stat_reg
= er32(STATUS
);
1294 if ((stat_reg
& E1000_STATUS_FD
) == 0)
1295 ctrl_reg
|= (E1000_CTRL_ILOS
| E1000_CTRL_SLU
);
1298 ew32(CTRL
, ctrl_reg
);
1301 * Disable the receiver on the PHY so when a cable is plugged in, the
1302 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1304 if (hw
->phy
.type
== e1000_phy_m88
)
1305 e1000_phy_disable_receiver(adapter
);
1312 static int e1000_set_82571_fiber_loopback(struct e1000_adapter
*adapter
)
1314 struct e1000_hw
*hw
= &adapter
->hw
;
1315 u32 ctrl
= er32(CTRL
);
1318 /* special requirements for 82571/82572 fiber adapters */
1321 * jump through hoops to make sure link is up because serdes
1322 * link is hardwired up
1324 ctrl
|= E1000_CTRL_SLU
;
1327 /* disable autoneg */
1332 link
= (er32(STATUS
) & E1000_STATUS_LU
);
1335 /* set invert loss of signal */
1337 ctrl
|= E1000_CTRL_ILOS
;
1342 * special write to serdes control register to enable SerDes analog
1345 #define E1000_SERDES_LB_ON 0x410
1346 ew32(SCTL
, E1000_SERDES_LB_ON
);
1352 /* only call this for fiber/serdes connections to es2lan */
1353 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter
*adapter
)
1355 struct e1000_hw
*hw
= &adapter
->hw
;
1356 u32 ctrlext
= er32(CTRL_EXT
);
1357 u32 ctrl
= er32(CTRL
);
1360 * save CTRL_EXT to restore later, reuse an empty variable (unused
1361 * on mac_type 80003es2lan)
1363 adapter
->tx_fifo_head
= ctrlext
;
1365 /* clear the serdes mode bits, putting the device into mac loopback */
1366 ctrlext
&= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES
;
1367 ew32(CTRL_EXT
, ctrlext
);
1369 /* force speed to 1000/FD, link up */
1370 ctrl
&= ~(E1000_CTRL_SPD_1000
| E1000_CTRL_SPD_100
);
1371 ctrl
|= (E1000_CTRL_SLU
| E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
|
1372 E1000_CTRL_SPD_1000
| E1000_CTRL_FD
);
1375 /* set mac loopback */
1377 ctrl
|= E1000_RCTL_LBM_MAC
;
1380 /* set testing mode parameters (no need to reset later) */
1381 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
1382 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1384 (KMRNCTRLSTA_OPMODE
| KMRNCTRLSTA_OPMODE_1GB_FD_GMII
));
1389 static int e1000_setup_loopback_test(struct e1000_adapter
*adapter
)
1391 struct e1000_hw
*hw
= &adapter
->hw
;
1394 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1395 hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1396 switch (hw
->mac
.type
) {
1397 case e1000_80003es2lan
:
1398 return e1000_set_es2lan_mac_loopback(adapter
);
1402 return e1000_set_82571_fiber_loopback(adapter
);
1406 rctl
|= E1000_RCTL_LBM_TCVR
;
1410 } else if (hw
->phy
.media_type
== e1000_media_type_copper
) {
1411 return e1000_integrated_phy_loopback(adapter
);
1417 static void e1000_loopback_cleanup(struct e1000_adapter
*adapter
)
1419 struct e1000_hw
*hw
= &adapter
->hw
;
1424 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
1427 switch (hw
->mac
.type
) {
1428 case e1000_80003es2lan
:
1429 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1430 hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1431 /* restore CTRL_EXT, stealing space from tx_fifo_head */
1432 ew32(CTRL_EXT
, adapter
->tx_fifo_head
);
1433 adapter
->tx_fifo_head
= 0;
1438 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1439 hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1440 #define E1000_SERDES_LB_OFF 0x400
1441 ew32(SCTL
, E1000_SERDES_LB_OFF
);
1447 hw
->mac
.autoneg
= 1;
1448 if (hw
->phy
.type
== e1000_phy_gg82563
)
1449 e1e_wphy(hw
, GG82563_PHY_KMRN_MODE_CTRL
, 0x180);
1450 e1e_rphy(hw
, PHY_CONTROL
, &phy_reg
);
1451 if (phy_reg
& MII_CR_LOOPBACK
) {
1452 phy_reg
&= ~MII_CR_LOOPBACK
;
1453 e1e_wphy(hw
, PHY_CONTROL
, phy_reg
);
1454 e1000e_commit_phy(hw
);
1460 static void e1000_create_lbtest_frame(struct sk_buff
*skb
,
1461 unsigned int frame_size
)
1463 memset(skb
->data
, 0xFF, frame_size
);
1465 memset(&skb
->data
[frame_size
/ 2], 0xAA, frame_size
/ 2 - 1);
1466 memset(&skb
->data
[frame_size
/ 2 + 10], 0xBE, 1);
1467 memset(&skb
->data
[frame_size
/ 2 + 12], 0xAF, 1);
1470 static int e1000_check_lbtest_frame(struct sk_buff
*skb
,
1471 unsigned int frame_size
)
1474 if (*(skb
->data
+ 3) == 0xFF)
1475 if ((*(skb
->data
+ frame_size
/ 2 + 10) == 0xBE) &&
1476 (*(skb
->data
+ frame_size
/ 2 + 12) == 0xAF))
1481 static int e1000_run_loopback_test(struct e1000_adapter
*adapter
)
1483 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1484 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1485 struct pci_dev
*pdev
= adapter
->pdev
;
1486 struct e1000_hw
*hw
= &adapter
->hw
;
1493 ew32(RDT
, rx_ring
->count
- 1);
1496 * Calculate the loop count based on the largest descriptor ring
1497 * The idea is to wrap the largest ring a number of times using 64
1498 * send/receive pairs during each loop
1501 if (rx_ring
->count
<= tx_ring
->count
)
1502 lc
= ((tx_ring
->count
/ 64) * 2) + 1;
1504 lc
= ((rx_ring
->count
/ 64) * 2) + 1;
1508 for (j
= 0; j
<= lc
; j
++) { /* loop count loop */
1509 for (i
= 0; i
< 64; i
++) { /* send the packets */
1510 e1000_create_lbtest_frame(tx_ring
->buffer_info
[k
].skb
,
1512 pci_dma_sync_single_for_device(pdev
,
1513 tx_ring
->buffer_info
[k
].dma
,
1514 tx_ring
->buffer_info
[k
].length
,
1517 if (k
== tx_ring
->count
)
1522 time
= jiffies
; /* set the start time for the receive */
1524 do { /* receive the sent packets */
1525 pci_dma_sync_single_for_cpu(pdev
,
1526 rx_ring
->buffer_info
[l
].dma
, 2048,
1527 PCI_DMA_FROMDEVICE
);
1529 ret_val
= e1000_check_lbtest_frame(
1530 rx_ring
->buffer_info
[l
].skb
, 1024);
1534 if (l
== rx_ring
->count
)
1537 * time + 20 msecs (200 msecs on 2.4) is more than
1538 * enough time to complete the receives, if it's
1539 * exceeded, break and error off
1541 } while ((good_cnt
< 64) && !time_after(jiffies
, time
+ 20));
1542 if (good_cnt
!= 64) {
1543 ret_val
= 13; /* ret_val is the same as mis-compare */
1546 if (jiffies
>= (time
+ 20)) {
1547 ret_val
= 14; /* error code for time out error */
1550 } /* end loop count loop */
1554 static int e1000_loopback_test(struct e1000_adapter
*adapter
, u64
*data
)
1557 * PHY loopback cannot be performed if SoL/IDER
1558 * sessions are active
1560 if (e1000_check_reset_block(&adapter
->hw
)) {
1561 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
1566 *data
= e1000_setup_desc_rings(adapter
);
1570 *data
= e1000_setup_loopback_test(adapter
);
1574 *data
= e1000_run_loopback_test(adapter
);
1575 e1000_loopback_cleanup(adapter
);
1578 e1000_free_desc_rings(adapter
);
1583 static int e1000_link_test(struct e1000_adapter
*adapter
, u64
*data
)
1585 struct e1000_hw
*hw
= &adapter
->hw
;
1588 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1590 hw
->mac
.serdes_has_link
= 0;
1593 * On some blade server designs, link establishment
1594 * could take as long as 2-3 minutes
1597 hw
->mac
.ops
.check_for_link(hw
);
1598 if (hw
->mac
.serdes_has_link
)
1601 } while (i
++ < 3750);
1605 hw
->mac
.ops
.check_for_link(hw
);
1606 if (hw
->mac
.autoneg
)
1609 if (!(er32(STATUS
) &
1616 static int e1000e_get_sset_count(struct net_device
*netdev
, int sset
)
1620 return E1000_TEST_LEN
;
1622 return E1000_STATS_LEN
;
1628 static void e1000_diag_test(struct net_device
*netdev
,
1629 struct ethtool_test
*eth_test
, u64
*data
)
1631 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1632 u16 autoneg_advertised
;
1633 u8 forced_speed_duplex
;
1635 bool if_running
= netif_running(netdev
);
1637 set_bit(__E1000_TESTING
, &adapter
->state
);
1638 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1641 /* save speed, duplex, autoneg settings */
1642 autoneg_advertised
= adapter
->hw
.phy
.autoneg_advertised
;
1643 forced_speed_duplex
= adapter
->hw
.mac
.forced_speed_duplex
;
1644 autoneg
= adapter
->hw
.mac
.autoneg
;
1646 e_info("offline testing starting\n");
1649 * Link test performed before hardware reset so autoneg doesn't
1650 * interfere with test result
1652 if (e1000_link_test(adapter
, &data
[4]))
1653 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1656 /* indicate we're in test mode */
1659 e1000e_reset(adapter
);
1661 if (e1000_reg_test(adapter
, &data
[0]))
1662 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1664 e1000e_reset(adapter
);
1665 if (e1000_eeprom_test(adapter
, &data
[1]))
1666 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1668 e1000e_reset(adapter
);
1669 if (e1000_intr_test(adapter
, &data
[2]))
1670 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1672 e1000e_reset(adapter
);
1673 /* make sure the phy is powered up */
1674 e1000e_power_up_phy(adapter
);
1675 if (e1000_loopback_test(adapter
, &data
[3]))
1676 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1678 /* restore speed, duplex, autoneg settings */
1679 adapter
->hw
.phy
.autoneg_advertised
= autoneg_advertised
;
1680 adapter
->hw
.mac
.forced_speed_duplex
= forced_speed_duplex
;
1681 adapter
->hw
.mac
.autoneg
= autoneg
;
1683 /* force this routine to wait until autoneg complete/timeout */
1684 adapter
->hw
.phy
.autoneg_wait_to_complete
= 1;
1685 e1000e_reset(adapter
);
1686 adapter
->hw
.phy
.autoneg_wait_to_complete
= 0;
1688 clear_bit(__E1000_TESTING
, &adapter
->state
);
1692 e_info("online testing starting\n");
1694 if (e1000_link_test(adapter
, &data
[4]))
1695 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1697 /* Online tests aren't run; pass by default */
1703 clear_bit(__E1000_TESTING
, &adapter
->state
);
1705 msleep_interruptible(4 * 1000);
1708 static void e1000_get_wol(struct net_device
*netdev
,
1709 struct ethtool_wolinfo
*wol
)
1711 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1716 if (!(adapter
->flags
& FLAG_HAS_WOL
) ||
1717 !device_can_wakeup(&adapter
->pdev
->dev
))
1720 wol
->supported
= WAKE_UCAST
| WAKE_MCAST
|
1721 WAKE_BCAST
| WAKE_MAGIC
|
1722 WAKE_PHY
| WAKE_ARP
;
1724 /* apply any specific unsupported masks here */
1725 if (adapter
->flags
& FLAG_NO_WAKE_UCAST
) {
1726 wol
->supported
&= ~WAKE_UCAST
;
1728 if (adapter
->wol
& E1000_WUFC_EX
)
1729 e_err("Interface does not support directed (unicast) "
1730 "frame wake-up packets\n");
1733 if (adapter
->wol
& E1000_WUFC_EX
)
1734 wol
->wolopts
|= WAKE_UCAST
;
1735 if (adapter
->wol
& E1000_WUFC_MC
)
1736 wol
->wolopts
|= WAKE_MCAST
;
1737 if (adapter
->wol
& E1000_WUFC_BC
)
1738 wol
->wolopts
|= WAKE_BCAST
;
1739 if (adapter
->wol
& E1000_WUFC_MAG
)
1740 wol
->wolopts
|= WAKE_MAGIC
;
1741 if (adapter
->wol
& E1000_WUFC_LNKC
)
1742 wol
->wolopts
|= WAKE_PHY
;
1743 if (adapter
->wol
& E1000_WUFC_ARP
)
1744 wol
->wolopts
|= WAKE_ARP
;
1747 static int e1000_set_wol(struct net_device
*netdev
,
1748 struct ethtool_wolinfo
*wol
)
1750 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1752 if (wol
->wolopts
& WAKE_MAGICSECURE
)
1755 if (!(adapter
->flags
& FLAG_HAS_WOL
) ||
1756 !device_can_wakeup(&adapter
->pdev
->dev
))
1757 return wol
->wolopts
? -EOPNOTSUPP
: 0;
1759 /* these settings will always override what we currently have */
1762 if (wol
->wolopts
& WAKE_UCAST
)
1763 adapter
->wol
|= E1000_WUFC_EX
;
1764 if (wol
->wolopts
& WAKE_MCAST
)
1765 adapter
->wol
|= E1000_WUFC_MC
;
1766 if (wol
->wolopts
& WAKE_BCAST
)
1767 adapter
->wol
|= E1000_WUFC_BC
;
1768 if (wol
->wolopts
& WAKE_MAGIC
)
1769 adapter
->wol
|= E1000_WUFC_MAG
;
1770 if (wol
->wolopts
& WAKE_PHY
)
1771 adapter
->wol
|= E1000_WUFC_LNKC
;
1772 if (wol
->wolopts
& WAKE_ARP
)
1773 adapter
->wol
|= E1000_WUFC_ARP
;
1775 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
1780 /* toggle LED 4 times per second = 2 "blinks" per second */
1781 #define E1000_ID_INTERVAL (HZ/4)
1783 /* bit defines for adapter->led_status */
1784 #define E1000_LED_ON 0
1786 static void e1000_led_blink_callback(unsigned long data
)
1788 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
1790 if (test_and_change_bit(E1000_LED_ON
, &adapter
->led_status
))
1791 adapter
->hw
.mac
.ops
.led_off(&adapter
->hw
);
1793 adapter
->hw
.mac
.ops
.led_on(&adapter
->hw
);
1795 mod_timer(&adapter
->blink_timer
, jiffies
+ E1000_ID_INTERVAL
);
1798 static int e1000_phys_id(struct net_device
*netdev
, u32 data
)
1800 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1801 struct e1000_hw
*hw
= &adapter
->hw
;
1806 if ((hw
->phy
.type
== e1000_phy_ife
) ||
1807 (hw
->mac
.type
== e1000_82574
)) {
1808 if (!adapter
->blink_timer
.function
) {
1809 init_timer(&adapter
->blink_timer
);
1810 adapter
->blink_timer
.function
=
1811 e1000_led_blink_callback
;
1812 adapter
->blink_timer
.data
= (unsigned long) adapter
;
1814 mod_timer(&adapter
->blink_timer
, jiffies
);
1815 msleep_interruptible(data
* 1000);
1816 del_timer_sync(&adapter
->blink_timer
);
1817 if (hw
->phy
.type
== e1000_phy_ife
)
1818 e1e_wphy(hw
, IFE_PHY_SPECIAL_CONTROL_LED
, 0);
1820 e1000e_blink_led(hw
);
1821 msleep_interruptible(data
* 1000);
1824 hw
->mac
.ops
.led_off(hw
);
1825 clear_bit(E1000_LED_ON
, &adapter
->led_status
);
1826 hw
->mac
.ops
.cleanup_led(hw
);
1831 static int e1000_get_coalesce(struct net_device
*netdev
,
1832 struct ethtool_coalesce
*ec
)
1834 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1836 if (adapter
->itr_setting
<= 3)
1837 ec
->rx_coalesce_usecs
= adapter
->itr_setting
;
1839 ec
->rx_coalesce_usecs
= 1000000 / adapter
->itr_setting
;
1844 static int e1000_set_coalesce(struct net_device
*netdev
,
1845 struct ethtool_coalesce
*ec
)
1847 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1848 struct e1000_hw
*hw
= &adapter
->hw
;
1850 if ((ec
->rx_coalesce_usecs
> E1000_MAX_ITR_USECS
) ||
1851 ((ec
->rx_coalesce_usecs
> 3) &&
1852 (ec
->rx_coalesce_usecs
< E1000_MIN_ITR_USECS
)) ||
1853 (ec
->rx_coalesce_usecs
== 2))
1856 if (ec
->rx_coalesce_usecs
<= 3) {
1857 adapter
->itr
= 20000;
1858 adapter
->itr_setting
= ec
->rx_coalesce_usecs
;
1860 adapter
->itr
= (1000000 / ec
->rx_coalesce_usecs
);
1861 adapter
->itr_setting
= adapter
->itr
& ~3;
1864 if (adapter
->itr_setting
!= 0)
1865 ew32(ITR
, 1000000000 / (adapter
->itr
* 256));
1872 static int e1000_nway_reset(struct net_device
*netdev
)
1874 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1875 if (netif_running(netdev
))
1876 e1000e_reinit_locked(adapter
);
1880 static void e1000_get_ethtool_stats(struct net_device
*netdev
,
1881 struct ethtool_stats
*stats
,
1884 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1887 e1000e_update_stats(adapter
);
1888 for (i
= 0; i
< E1000_GLOBAL_STATS_LEN
; i
++) {
1889 char *p
= (char *)adapter
+e1000_gstrings_stats
[i
].stat_offset
;
1890 data
[i
] = (e1000_gstrings_stats
[i
].sizeof_stat
==
1891 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1895 static void e1000_get_strings(struct net_device
*netdev
, u32 stringset
,
1901 switch (stringset
) {
1903 memcpy(data
, *e1000_gstrings_test
, sizeof(e1000_gstrings_test
));
1906 for (i
= 0; i
< E1000_GLOBAL_STATS_LEN
; i
++) {
1907 memcpy(p
, e1000_gstrings_stats
[i
].stat_string
,
1909 p
+= ETH_GSTRING_LEN
;
1915 static const struct ethtool_ops e1000_ethtool_ops
= {
1916 .get_settings
= e1000_get_settings
,
1917 .set_settings
= e1000_set_settings
,
1918 .get_drvinfo
= e1000_get_drvinfo
,
1919 .get_regs_len
= e1000_get_regs_len
,
1920 .get_regs
= e1000_get_regs
,
1921 .get_wol
= e1000_get_wol
,
1922 .set_wol
= e1000_set_wol
,
1923 .get_msglevel
= e1000_get_msglevel
,
1924 .set_msglevel
= e1000_set_msglevel
,
1925 .nway_reset
= e1000_nway_reset
,
1926 .get_link
= e1000_get_link
,
1927 .get_eeprom_len
= e1000_get_eeprom_len
,
1928 .get_eeprom
= e1000_get_eeprom
,
1929 .set_eeprom
= e1000_set_eeprom
,
1930 .get_ringparam
= e1000_get_ringparam
,
1931 .set_ringparam
= e1000_set_ringparam
,
1932 .get_pauseparam
= e1000_get_pauseparam
,
1933 .set_pauseparam
= e1000_set_pauseparam
,
1934 .get_rx_csum
= e1000_get_rx_csum
,
1935 .set_rx_csum
= e1000_set_rx_csum
,
1936 .get_tx_csum
= e1000_get_tx_csum
,
1937 .set_tx_csum
= e1000_set_tx_csum
,
1938 .get_sg
= ethtool_op_get_sg
,
1939 .set_sg
= ethtool_op_set_sg
,
1940 .get_tso
= ethtool_op_get_tso
,
1941 .set_tso
= e1000_set_tso
,
1942 .self_test
= e1000_diag_test
,
1943 .get_strings
= e1000_get_strings
,
1944 .phys_id
= e1000_phys_id
,
1945 .get_ethtool_stats
= e1000_get_ethtool_stats
,
1946 .get_sset_count
= e1000e_get_sset_count
,
1947 .get_coalesce
= e1000_get_coalesce
,
1948 .set_coalesce
= e1000_set_coalesce
,
1951 void e1000e_set_ethtool_ops(struct net_device
*netdev
)
1953 SET_ETHTOOL_OPS(netdev
, &e1000_ethtool_ops
);