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
.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
->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
);
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 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
;
230 * When SoL/IDER sessions are active, autoneg/speed/duplex
233 if (e1000_check_reset_block(hw
)) {
234 ndev_err(netdev
, "Cannot change link "
235 "characteristics when SoL/IDER is active.\n");
239 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
242 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
244 if (hw
->phy
.media_type
== e1000_media_type_fiber
)
245 hw
->phy
.autoneg_advertised
= ADVERTISED_1000baseT_Full
|
249 hw
->phy
.autoneg_advertised
= ecmd
->advertising
|
252 ecmd
->advertising
= hw
->phy
.autoneg_advertised
;
253 if (adapter
->fc_autoneg
)
254 hw
->fc
.original_type
= e1000_fc_default
;
256 if (e1000_set_spd_dplx(adapter
, ecmd
->speed
+ ecmd
->duplex
)) {
257 clear_bit(__E1000_RESETTING
, &adapter
->state
);
264 if (netif_running(adapter
->netdev
)) {
265 e1000e_down(adapter
);
268 e1000e_reset(adapter
);
271 clear_bit(__E1000_RESETTING
, &adapter
->state
);
275 static void e1000_get_pauseparam(struct net_device
*netdev
,
276 struct ethtool_pauseparam
*pause
)
278 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
279 struct e1000_hw
*hw
= &adapter
->hw
;
282 (adapter
->fc_autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
);
284 if (hw
->fc
.type
== e1000_fc_rx_pause
) {
286 } else if (hw
->fc
.type
== e1000_fc_tx_pause
) {
288 } else if (hw
->fc
.type
== e1000_fc_full
) {
294 static int e1000_set_pauseparam(struct net_device
*netdev
,
295 struct ethtool_pauseparam
*pause
)
297 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
298 struct e1000_hw
*hw
= &adapter
->hw
;
301 adapter
->fc_autoneg
= pause
->autoneg
;
303 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
306 if (pause
->rx_pause
&& pause
->tx_pause
)
307 hw
->fc
.type
= e1000_fc_full
;
308 else if (pause
->rx_pause
&& !pause
->tx_pause
)
309 hw
->fc
.type
= e1000_fc_rx_pause
;
310 else if (!pause
->rx_pause
&& pause
->tx_pause
)
311 hw
->fc
.type
= e1000_fc_tx_pause
;
312 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
313 hw
->fc
.type
= e1000_fc_none
;
315 hw
->fc
.original_type
= hw
->fc
.type
;
317 if (adapter
->fc_autoneg
== AUTONEG_ENABLE
) {
318 hw
->fc
.type
= e1000_fc_default
;
319 if (netif_running(adapter
->netdev
)) {
320 e1000e_down(adapter
);
323 e1000e_reset(adapter
);
326 retval
= ((hw
->phy
.media_type
== e1000_media_type_fiber
) ?
327 hw
->mac
.ops
.setup_link(hw
) : e1000e_force_mac_fc(hw
));
330 clear_bit(__E1000_RESETTING
, &adapter
->state
);
334 static u32
e1000_get_rx_csum(struct net_device
*netdev
)
336 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
337 return (adapter
->flags
& FLAG_RX_CSUM_ENABLED
);
340 static int e1000_set_rx_csum(struct net_device
*netdev
, u32 data
)
342 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
345 adapter
->flags
|= FLAG_RX_CSUM_ENABLED
;
347 adapter
->flags
&= ~FLAG_RX_CSUM_ENABLED
;
349 if (netif_running(netdev
))
350 e1000e_reinit_locked(adapter
);
352 e1000e_reset(adapter
);
356 static u32
e1000_get_tx_csum(struct net_device
*netdev
)
358 return ((netdev
->features
& NETIF_F_HW_CSUM
) != 0);
361 static int e1000_set_tx_csum(struct net_device
*netdev
, u32 data
)
364 netdev
->features
|= NETIF_F_HW_CSUM
;
366 netdev
->features
&= ~NETIF_F_HW_CSUM
;
371 static int e1000_set_tso(struct net_device
*netdev
, u32 data
)
373 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
376 netdev
->features
|= NETIF_F_TSO
;
377 netdev
->features
|= NETIF_F_TSO6
;
379 netdev
->features
&= ~NETIF_F_TSO
;
380 netdev
->features
&= ~NETIF_F_TSO6
;
383 ndev_info(netdev
, "TSO is %s\n",
384 data
? "Enabled" : "Disabled");
385 adapter
->flags
|= FLAG_TSO_FORCE
;
389 static u32
e1000_get_msglevel(struct net_device
*netdev
)
391 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
392 return adapter
->msg_enable
;
395 static void e1000_set_msglevel(struct net_device
*netdev
, u32 data
)
397 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
398 adapter
->msg_enable
= data
;
401 static int e1000_get_regs_len(struct net_device
*netdev
)
403 #define E1000_REGS_LEN 32 /* overestimate */
404 return E1000_REGS_LEN
* sizeof(u32
);
407 static void e1000_get_regs(struct net_device
*netdev
,
408 struct ethtool_regs
*regs
, void *p
)
410 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
411 struct e1000_hw
*hw
= &adapter
->hw
;
416 memset(p
, 0, E1000_REGS_LEN
* sizeof(u32
));
418 pci_read_config_byte(adapter
->pdev
, PCI_REVISION_ID
, &revision_id
);
420 regs
->version
= (1 << 24) | (revision_id
<< 16) | adapter
->pdev
->device
;
422 regs_buff
[0] = er32(CTRL
);
423 regs_buff
[1] = er32(STATUS
);
425 regs_buff
[2] = er32(RCTL
);
426 regs_buff
[3] = er32(RDLEN
);
427 regs_buff
[4] = er32(RDH
);
428 regs_buff
[5] = er32(RDT
);
429 regs_buff
[6] = er32(RDTR
);
431 regs_buff
[7] = er32(TCTL
);
432 regs_buff
[8] = er32(TDLEN
);
433 regs_buff
[9] = er32(TDH
);
434 regs_buff
[10] = er32(TDT
);
435 regs_buff
[11] = er32(TIDV
);
437 regs_buff
[12] = adapter
->hw
.phy
.type
; /* PHY type (IGP=1, M88=0) */
438 if (hw
->phy
.type
== e1000_phy_m88
) {
439 e1e_rphy(hw
, M88E1000_PHY_SPEC_STATUS
, &phy_data
);
440 regs_buff
[13] = (u32
)phy_data
; /* cable length */
441 regs_buff
[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
442 regs_buff
[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
443 regs_buff
[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
444 e1e_rphy(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
445 regs_buff
[17] = (u32
)phy_data
; /* extended 10bt distance */
446 regs_buff
[18] = regs_buff
[13]; /* cable polarity */
447 regs_buff
[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
448 regs_buff
[20] = regs_buff
[17]; /* polarity correction */
449 /* phy receive errors */
450 regs_buff
[22] = adapter
->phy_stats
.receive_errors
;
451 regs_buff
[23] = regs_buff
[13]; /* mdix mode */
453 regs_buff
[21] = adapter
->phy_stats
.idle_errors
; /* phy idle errors */
454 e1e_rphy(hw
, PHY_1000T_STATUS
, &phy_data
);
455 regs_buff
[24] = (u32
)phy_data
; /* phy local receiver status */
456 regs_buff
[25] = regs_buff
[24]; /* phy remote receiver status */
459 static int e1000_get_eeprom_len(struct net_device
*netdev
)
461 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
462 return adapter
->hw
.nvm
.word_size
* 2;
465 static int e1000_get_eeprom(struct net_device
*netdev
,
466 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
468 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
469 struct e1000_hw
*hw
= &adapter
->hw
;
476 if (eeprom
->len
== 0)
479 eeprom
->magic
= adapter
->pdev
->vendor
| (adapter
->pdev
->device
<< 16);
481 first_word
= eeprom
->offset
>> 1;
482 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
484 eeprom_buff
= kmalloc(sizeof(u16
) *
485 (last_word
- first_word
+ 1), GFP_KERNEL
);
489 if (hw
->nvm
.type
== e1000_nvm_eeprom_spi
) {
490 ret_val
= e1000_read_nvm(hw
, first_word
,
491 last_word
- first_word
+ 1,
494 for (i
= 0; i
< last_word
- first_word
+ 1; i
++) {
495 ret_val
= e1000_read_nvm(hw
, first_word
+ i
, 1,
502 /* Device's eeprom is always little-endian, word addressable */
503 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
504 le16_to_cpus(&eeprom_buff
[i
]);
506 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 1), eeprom
->len
);
512 static int e1000_set_eeprom(struct net_device
*netdev
,
513 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
515 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
516 struct e1000_hw
*hw
= &adapter
->hw
;
525 if (eeprom
->len
== 0)
528 if (eeprom
->magic
!= (adapter
->pdev
->vendor
| (adapter
->pdev
->device
<< 16)))
531 max_len
= hw
->nvm
.word_size
* 2;
533 first_word
= eeprom
->offset
>> 1;
534 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
535 eeprom_buff
= kmalloc(max_len
, GFP_KERNEL
);
539 ptr
= (void *)eeprom_buff
;
541 if (eeprom
->offset
& 1) {
542 /* need read/modify/write of first changed EEPROM word */
543 /* only the second byte of the word is being modified */
544 ret_val
= e1000_read_nvm(hw
, first_word
, 1, &eeprom_buff
[0]);
547 if (((eeprom
->offset
+ eeprom
->len
) & 1) && (ret_val
== 0))
548 /* need read/modify/write of last changed EEPROM word */
549 /* only the first byte of the word is being modified */
550 ret_val
= e1000_read_nvm(hw
, last_word
, 1,
551 &eeprom_buff
[last_word
- first_word
]);
553 /* Device's eeprom is always little-endian, word addressable */
554 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
555 le16_to_cpus(&eeprom_buff
[i
]);
557 memcpy(ptr
, bytes
, eeprom
->len
);
559 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
560 eeprom_buff
[i
] = cpu_to_le16(eeprom_buff
[i
]);
562 ret_val
= e1000_write_nvm(hw
, first_word
,
563 last_word
- first_word
+ 1, eeprom_buff
);
566 * Update the checksum over the first part of the EEPROM if needed
567 * and flush shadow RAM for 82573 controllers
569 if ((ret_val
== 0) && ((first_word
<= NVM_CHECKSUM_REG
) ||
570 (hw
->mac
.type
== e1000_82573
)))
571 e1000e_update_nvm_checksum(hw
);
577 static void e1000_get_drvinfo(struct net_device
*netdev
,
578 struct ethtool_drvinfo
*drvinfo
)
580 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
581 char firmware_version
[32];
584 strncpy(drvinfo
->driver
, e1000e_driver_name
, 32);
585 strncpy(drvinfo
->version
, e1000e_driver_version
, 32);
588 * EEPROM image version # is reported as firmware version # for
591 e1000_read_nvm(&adapter
->hw
, 5, 1, &eeprom_data
);
592 sprintf(firmware_version
, "%d.%d-%d",
593 (eeprom_data
& 0xF000) >> 12,
594 (eeprom_data
& 0x0FF0) >> 4,
595 eeprom_data
& 0x000F);
597 strncpy(drvinfo
->fw_version
, firmware_version
, 32);
598 strncpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
), 32);
599 drvinfo
->regdump_len
= e1000_get_regs_len(netdev
);
600 drvinfo
->eedump_len
= e1000_get_eeprom_len(netdev
);
603 static void e1000_get_ringparam(struct net_device
*netdev
,
604 struct ethtool_ringparam
*ring
)
606 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
607 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
608 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
610 ring
->rx_max_pending
= E1000_MAX_RXD
;
611 ring
->tx_max_pending
= E1000_MAX_TXD
;
612 ring
->rx_mini_max_pending
= 0;
613 ring
->rx_jumbo_max_pending
= 0;
614 ring
->rx_pending
= rx_ring
->count
;
615 ring
->tx_pending
= tx_ring
->count
;
616 ring
->rx_mini_pending
= 0;
617 ring
->rx_jumbo_pending
= 0;
620 static int e1000_set_ringparam(struct net_device
*netdev
,
621 struct ethtool_ringparam
*ring
)
623 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
624 struct e1000_ring
*tx_ring
, *tx_old
;
625 struct e1000_ring
*rx_ring
, *rx_old
;
628 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
631 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
634 if (netif_running(adapter
->netdev
))
635 e1000e_down(adapter
);
637 tx_old
= adapter
->tx_ring
;
638 rx_old
= adapter
->rx_ring
;
641 tx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
645 * use a memcpy to save any previously configured
646 * items like napi structs from having to be
649 memcpy(tx_ring
, tx_old
, sizeof(struct e1000_ring
));
651 rx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
654 memcpy(rx_ring
, rx_old
, sizeof(struct e1000_ring
));
656 adapter
->tx_ring
= tx_ring
;
657 adapter
->rx_ring
= rx_ring
;
659 rx_ring
->count
= max(ring
->rx_pending
, (u32
)E1000_MIN_RXD
);
660 rx_ring
->count
= min(rx_ring
->count
, (u32
)(E1000_MAX_RXD
));
661 rx_ring
->count
= ALIGN(rx_ring
->count
, REQ_RX_DESCRIPTOR_MULTIPLE
);
663 tx_ring
->count
= max(ring
->tx_pending
, (u32
)E1000_MIN_TXD
);
664 tx_ring
->count
= min(tx_ring
->count
, (u32
)(E1000_MAX_TXD
));
665 tx_ring
->count
= ALIGN(tx_ring
->count
, REQ_TX_DESCRIPTOR_MULTIPLE
);
667 if (netif_running(adapter
->netdev
)) {
668 /* Try to get new resources before deleting old */
669 err
= e1000e_setup_rx_resources(adapter
);
672 err
= e1000e_setup_tx_resources(adapter
);
677 * restore the old in order to free it,
678 * then add in the new
680 adapter
->rx_ring
= rx_old
;
681 adapter
->tx_ring
= tx_old
;
682 e1000e_free_rx_resources(adapter
);
683 e1000e_free_tx_resources(adapter
);
686 adapter
->rx_ring
= rx_ring
;
687 adapter
->tx_ring
= tx_ring
;
688 err
= e1000e_up(adapter
);
693 clear_bit(__E1000_RESETTING
, &adapter
->state
);
696 e1000e_free_rx_resources(adapter
);
698 adapter
->rx_ring
= rx_old
;
699 adapter
->tx_ring
= tx_old
;
706 clear_bit(__E1000_RESETTING
, &adapter
->state
);
710 static bool reg_pattern_test(struct e1000_adapter
*adapter
, u64
*data
,
711 int reg
, int offset
, u32 mask
, u32 write
)
714 static const u32 test
[] =
715 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
716 for (pat
= 0; pat
< ARRAY_SIZE(test
); pat
++) {
717 E1000_WRITE_REG_ARRAY(&adapter
->hw
, reg
, offset
,
718 (test
[pat
] & write
));
719 val
= E1000_READ_REG_ARRAY(&adapter
->hw
, reg
, offset
);
720 if (val
!= (test
[pat
] & write
& mask
)) {
721 ndev_err(adapter
->netdev
, "pattern test reg %04X "
722 "failed: got 0x%08X expected 0x%08X\n",
724 val
, (test
[pat
] & write
& mask
));
732 static bool reg_set_and_check(struct e1000_adapter
*adapter
, u64
*data
,
733 int reg
, u32 mask
, u32 write
)
736 __ew32(&adapter
->hw
, reg
, write
& mask
);
737 val
= __er32(&adapter
->hw
, reg
);
738 if ((write
& mask
) != (val
& mask
)) {
739 ndev_err(adapter
->netdev
, "set/check reg %04X test failed: "
740 "got 0x%08X expected 0x%08X\n", reg
, (val
& mask
),
747 #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
749 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
752 #define REG_PATTERN_TEST(reg, mask, write) \
753 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
755 #define REG_SET_AND_CHECK(reg, mask, write) \
757 if (reg_set_and_check(adapter, data, reg, mask, write)) \
761 static int e1000_reg_test(struct e1000_adapter
*adapter
, u64
*data
)
763 struct e1000_hw
*hw
= &adapter
->hw
;
764 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
765 struct net_device
*netdev
= adapter
->netdev
;
773 * The status register is Read Only, so a write should fail.
774 * Some bits that get toggled are ignored.
777 /* there are several bits on newer hardware that are r/w */
780 case e1000_80003es2lan
:
793 before
= er32(STATUS
);
794 value
= (er32(STATUS
) & toggle
);
795 ew32(STATUS
, toggle
);
796 after
= er32(STATUS
) & toggle
;
797 if (value
!= after
) {
798 ndev_err(netdev
, "failed STATUS register test got: "
799 "0x%08X expected: 0x%08X\n", after
, value
);
803 /* restore previous status */
804 ew32(STATUS
, before
);
806 if ((mac
->type
!= e1000_ich8lan
) &&
807 (mac
->type
!= e1000_ich9lan
)) {
808 REG_PATTERN_TEST(E1000_FCAL
, 0xFFFFFFFF, 0xFFFFFFFF);
809 REG_PATTERN_TEST(E1000_FCAH
, 0x0000FFFF, 0xFFFFFFFF);
810 REG_PATTERN_TEST(E1000_FCT
, 0x0000FFFF, 0xFFFFFFFF);
811 REG_PATTERN_TEST(E1000_VET
, 0x0000FFFF, 0xFFFFFFFF);
814 REG_PATTERN_TEST(E1000_RDTR
, 0x0000FFFF, 0xFFFFFFFF);
815 REG_PATTERN_TEST(E1000_RDBAH
, 0xFFFFFFFF, 0xFFFFFFFF);
816 REG_PATTERN_TEST(E1000_RDLEN
, 0x000FFF80, 0x000FFFFF);
817 REG_PATTERN_TEST(E1000_RDH
, 0x0000FFFF, 0x0000FFFF);
818 REG_PATTERN_TEST(E1000_RDT
, 0x0000FFFF, 0x0000FFFF);
819 REG_PATTERN_TEST(E1000_FCRTH
, 0x0000FFF8, 0x0000FFF8);
820 REG_PATTERN_TEST(E1000_FCTTV
, 0x0000FFFF, 0x0000FFFF);
821 REG_PATTERN_TEST(E1000_TIPG
, 0x3FFFFFFF, 0x3FFFFFFF);
822 REG_PATTERN_TEST(E1000_TDBAH
, 0xFFFFFFFF, 0xFFFFFFFF);
823 REG_PATTERN_TEST(E1000_TDLEN
, 0x000FFF80, 0x000FFFFF);
825 REG_SET_AND_CHECK(E1000_RCTL
, 0xFFFFFFFF, 0x00000000);
827 before
= (((mac
->type
== e1000_ich8lan
) ||
828 (mac
->type
== e1000_ich9lan
)) ? 0x06C3B33E : 0x06DFB3FE);
829 REG_SET_AND_CHECK(E1000_RCTL
, before
, 0x003FFFFB);
830 REG_SET_AND_CHECK(E1000_TCTL
, 0xFFFFFFFF, 0x00000000);
832 REG_SET_AND_CHECK(E1000_RCTL
, before
, 0xFFFFFFFF);
833 REG_PATTERN_TEST(E1000_RDBAL
, 0xFFFFFFF0, 0xFFFFFFFF);
834 if ((mac
->type
!= e1000_ich8lan
) &&
835 (mac
->type
!= e1000_ich9lan
))
836 REG_PATTERN_TEST(E1000_TXCW
, 0xC000FFFF, 0x0000FFFF);
837 REG_PATTERN_TEST(E1000_TDBAL
, 0xFFFFFFF0, 0xFFFFFFFF);
838 REG_PATTERN_TEST(E1000_TIDV
, 0x0000FFFF, 0x0000FFFF);
839 for (i
= 0; i
< mac
->rar_entry_count
; i
++)
840 REG_PATTERN_TEST_ARRAY(E1000_RA
, ((i
<< 1) + 1),
841 0x8003FFFF, 0xFFFFFFFF);
843 for (i
= 0; i
< mac
->mta_reg_count
; i
++)
844 REG_PATTERN_TEST_ARRAY(E1000_MTA
, i
, 0xFFFFFFFF, 0xFFFFFFFF);
850 static int e1000_eeprom_test(struct e1000_adapter
*adapter
, u64
*data
)
857 /* Read and add up the contents of the EEPROM */
858 for (i
= 0; i
< (NVM_CHECKSUM_REG
+ 1); i
++) {
859 if ((e1000_read_nvm(&adapter
->hw
, i
, 1, &temp
)) < 0) {
866 /* If Checksum is not Correct return error else test passed */
867 if ((checksum
!= (u16
) NVM_SUM
) && !(*data
))
873 static irqreturn_t
e1000_test_intr(int irq
, void *data
)
875 struct net_device
*netdev
= (struct net_device
*) data
;
876 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
877 struct e1000_hw
*hw
= &adapter
->hw
;
879 adapter
->test_icr
|= er32(ICR
);
884 static int e1000_intr_test(struct e1000_adapter
*adapter
, u64
*data
)
886 struct net_device
*netdev
= adapter
->netdev
;
887 struct e1000_hw
*hw
= &adapter
->hw
;
890 u32 irq
= adapter
->pdev
->irq
;
895 /* NOTE: we don't test MSI interrupts here, yet */
896 /* Hook up test interrupt handler just for this test */
897 if (!request_irq(irq
, &e1000_test_intr
, IRQF_PROBE_SHARED
, netdev
->name
,
900 } else if (request_irq(irq
, &e1000_test_intr
, IRQF_SHARED
,
901 netdev
->name
, netdev
)) {
905 ndev_info(netdev
, "testing %s interrupt\n",
906 (shared_int
? "shared" : "unshared"));
908 /* Disable all the interrupts */
909 ew32(IMC
, 0xFFFFFFFF);
912 /* Test each interrupt */
913 for (i
= 0; i
< 10; i
++) {
915 if (((adapter
->hw
.mac
.type
== e1000_ich8lan
) ||
916 (adapter
->hw
.mac
.type
== e1000_ich9lan
)) && i
== 8)
919 /* Interrupt to test */
924 * Disable the interrupt to be reported in
925 * the cause register and then force the same
926 * interrupt and see if one gets posted. If
927 * an interrupt was posted to the bus, the
930 adapter
->test_icr
= 0;
935 if (adapter
->test_icr
& mask
) {
942 * Enable the interrupt to be reported in
943 * the cause register and then force the same
944 * interrupt and see if one gets posted. If
945 * an interrupt was not posted to the bus, the
948 adapter
->test_icr
= 0;
953 if (!(adapter
->test_icr
& mask
)) {
960 * Disable the other interrupts to be reported in
961 * the cause register and then force the other
962 * interrupts and see if any get posted. If
963 * an interrupt was posted to the bus, the
966 adapter
->test_icr
= 0;
967 ew32(IMC
, ~mask
& 0x00007FFF);
968 ew32(ICS
, ~mask
& 0x00007FFF);
971 if (adapter
->test_icr
) {
978 /* Disable all the interrupts */
979 ew32(IMC
, 0xFFFFFFFF);
982 /* Unhook test interrupt handler */
983 free_irq(irq
, netdev
);
988 static void e1000_free_desc_rings(struct e1000_adapter
*adapter
)
990 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
991 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
992 struct pci_dev
*pdev
= adapter
->pdev
;
995 if (tx_ring
->desc
&& tx_ring
->buffer_info
) {
996 for (i
= 0; i
< tx_ring
->count
; i
++) {
997 if (tx_ring
->buffer_info
[i
].dma
)
998 pci_unmap_single(pdev
,
999 tx_ring
->buffer_info
[i
].dma
,
1000 tx_ring
->buffer_info
[i
].length
,
1002 if (tx_ring
->buffer_info
[i
].skb
)
1003 dev_kfree_skb(tx_ring
->buffer_info
[i
].skb
);
1007 if (rx_ring
->desc
&& rx_ring
->buffer_info
) {
1008 for (i
= 0; i
< rx_ring
->count
; i
++) {
1009 if (rx_ring
->buffer_info
[i
].dma
)
1010 pci_unmap_single(pdev
,
1011 rx_ring
->buffer_info
[i
].dma
,
1012 2048, PCI_DMA_FROMDEVICE
);
1013 if (rx_ring
->buffer_info
[i
].skb
)
1014 dev_kfree_skb(rx_ring
->buffer_info
[i
].skb
);
1018 if (tx_ring
->desc
) {
1019 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
1021 tx_ring
->desc
= NULL
;
1023 if (rx_ring
->desc
) {
1024 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
1026 rx_ring
->desc
= NULL
;
1029 kfree(tx_ring
->buffer_info
);
1030 tx_ring
->buffer_info
= NULL
;
1031 kfree(rx_ring
->buffer_info
);
1032 rx_ring
->buffer_info
= NULL
;
1035 static int e1000_setup_desc_rings(struct e1000_adapter
*adapter
)
1037 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1038 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1039 struct pci_dev
*pdev
= adapter
->pdev
;
1040 struct e1000_hw
*hw
= &adapter
->hw
;
1045 /* Setup Tx descriptor ring and Tx buffers */
1047 if (!tx_ring
->count
)
1048 tx_ring
->count
= E1000_DEFAULT_TXD
;
1050 tx_ring
->buffer_info
= kcalloc(tx_ring
->count
,
1051 sizeof(struct e1000_buffer
),
1053 if (!(tx_ring
->buffer_info
)) {
1058 tx_ring
->size
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
1059 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1060 tx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, tx_ring
->size
,
1061 &tx_ring
->dma
, GFP_KERNEL
);
1062 if (!tx_ring
->desc
) {
1066 tx_ring
->next_to_use
= 0;
1067 tx_ring
->next_to_clean
= 0;
1069 ew32(TDBAL
, ((u64
) tx_ring
->dma
& 0x00000000FFFFFFFF));
1070 ew32(TDBAH
, ((u64
) tx_ring
->dma
>> 32));
1071 ew32(TDLEN
, tx_ring
->count
* sizeof(struct e1000_tx_desc
));
1074 ew32(TCTL
, E1000_TCTL_PSP
| E1000_TCTL_EN
| E1000_TCTL_MULR
|
1075 E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
|
1076 E1000_COLLISION_DISTANCE
<< E1000_COLD_SHIFT
);
1078 for (i
= 0; i
< tx_ring
->count
; i
++) {
1079 struct e1000_tx_desc
*tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
1080 struct sk_buff
*skb
;
1081 unsigned int skb_size
= 1024;
1083 skb
= alloc_skb(skb_size
, GFP_KERNEL
);
1088 skb_put(skb
, skb_size
);
1089 tx_ring
->buffer_info
[i
].skb
= skb
;
1090 tx_ring
->buffer_info
[i
].length
= skb
->len
;
1091 tx_ring
->buffer_info
[i
].dma
=
1092 pci_map_single(pdev
, skb
->data
, skb
->len
,
1094 if (pci_dma_mapping_error(tx_ring
->buffer_info
[i
].dma
)) {
1098 tx_desc
->buffer_addr
= cpu_to_le64(tx_ring
->buffer_info
[i
].dma
);
1099 tx_desc
->lower
.data
= cpu_to_le32(skb
->len
);
1100 tx_desc
->lower
.data
|= cpu_to_le32(E1000_TXD_CMD_EOP
|
1101 E1000_TXD_CMD_IFCS
|
1103 tx_desc
->upper
.data
= 0;
1106 /* Setup Rx descriptor ring and Rx buffers */
1108 if (!rx_ring
->count
)
1109 rx_ring
->count
= E1000_DEFAULT_RXD
;
1111 rx_ring
->buffer_info
= kcalloc(rx_ring
->count
,
1112 sizeof(struct e1000_buffer
),
1114 if (!(rx_ring
->buffer_info
)) {
1119 rx_ring
->size
= rx_ring
->count
* sizeof(struct e1000_rx_desc
);
1120 rx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, rx_ring
->size
,
1121 &rx_ring
->dma
, GFP_KERNEL
);
1122 if (!rx_ring
->desc
) {
1126 rx_ring
->next_to_use
= 0;
1127 rx_ring
->next_to_clean
= 0;
1130 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1131 ew32(RDBAL
, ((u64
) rx_ring
->dma
& 0xFFFFFFFF));
1132 ew32(RDBAH
, ((u64
) rx_ring
->dma
>> 32));
1133 ew32(RDLEN
, rx_ring
->size
);
1136 rctl
= E1000_RCTL_EN
| E1000_RCTL_BAM
| E1000_RCTL_SZ_2048
|
1137 E1000_RCTL_UPE
| E1000_RCTL_MPE
| E1000_RCTL_LPE
|
1138 E1000_RCTL_SBP
| E1000_RCTL_SECRC
|
1139 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1140 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1143 for (i
= 0; i
< rx_ring
->count
; i
++) {
1144 struct e1000_rx_desc
*rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
1145 struct sk_buff
*skb
;
1147 skb
= alloc_skb(2048 + NET_IP_ALIGN
, GFP_KERNEL
);
1152 skb_reserve(skb
, NET_IP_ALIGN
);
1153 rx_ring
->buffer_info
[i
].skb
= skb
;
1154 rx_ring
->buffer_info
[i
].dma
=
1155 pci_map_single(pdev
, skb
->data
, 2048,
1156 PCI_DMA_FROMDEVICE
);
1157 if (pci_dma_mapping_error(rx_ring
->buffer_info
[i
].dma
)) {
1161 rx_desc
->buffer_addr
=
1162 cpu_to_le64(rx_ring
->buffer_info
[i
].dma
);
1163 memset(skb
->data
, 0x00, skb
->len
);
1169 e1000_free_desc_rings(adapter
);
1173 static void e1000_phy_disable_receiver(struct e1000_adapter
*adapter
)
1175 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1176 e1e_wphy(&adapter
->hw
, 29, 0x001F);
1177 e1e_wphy(&adapter
->hw
, 30, 0x8FFC);
1178 e1e_wphy(&adapter
->hw
, 29, 0x001A);
1179 e1e_wphy(&adapter
->hw
, 30, 0x8FF0);
1182 static int e1000_integrated_phy_loopback(struct e1000_adapter
*adapter
)
1184 struct e1000_hw
*hw
= &adapter
->hw
;
1188 hw
->mac
.autoneg
= 0;
1190 if (hw
->phy
.type
== e1000_phy_m88
) {
1191 /* Auto-MDI/MDIX Off */
1192 e1e_wphy(hw
, M88E1000_PHY_SPEC_CTRL
, 0x0808);
1193 /* reset to update Auto-MDI/MDIX */
1194 e1e_wphy(hw
, PHY_CONTROL
, 0x9140);
1196 e1e_wphy(hw
, PHY_CONTROL
, 0x8140);
1197 } else if (hw
->phy
.type
== e1000_phy_gg82563
)
1198 e1e_wphy(hw
, GG82563_PHY_KMRN_MODE_CTRL
, 0x1CC);
1200 ctrl_reg
= er32(CTRL
);
1202 switch (hw
->phy
.type
) {
1204 /* force 100, set loopback */
1205 e1e_wphy(hw
, PHY_CONTROL
, 0x6100);
1207 /* Now set up the MAC to the same speed/duplex as the PHY. */
1208 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1209 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1210 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1211 E1000_CTRL_SPD_100
|/* Force Speed to 100 */
1212 E1000_CTRL_FD
); /* Force Duplex to FULL */
1215 /* force 1000, set loopback */
1216 e1e_wphy(hw
, PHY_CONTROL
, 0x4140);
1219 /* Now set up the MAC to the same speed/duplex as the PHY. */
1220 ctrl_reg
= er32(CTRL
);
1221 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1222 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1223 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1224 E1000_CTRL_SPD_1000
|/* Force Speed to 1000 */
1225 E1000_CTRL_FD
); /* Force Duplex to FULL */
1227 if ((adapter
->hw
.mac
.type
== e1000_ich8lan
) ||
1228 (adapter
->hw
.mac
.type
== e1000_ich9lan
))
1229 ctrl_reg
|= E1000_CTRL_SLU
; /* Set Link Up */
1232 if (hw
->phy
.media_type
== e1000_media_type_copper
&&
1233 hw
->phy
.type
== e1000_phy_m88
) {
1234 ctrl_reg
|= E1000_CTRL_ILOS
; /* Invert Loss of Signal */
1237 * Set the ILOS bit on the fiber Nic if half duplex link is
1240 stat_reg
= er32(STATUS
);
1241 if ((stat_reg
& E1000_STATUS_FD
) == 0)
1242 ctrl_reg
|= (E1000_CTRL_ILOS
| E1000_CTRL_SLU
);
1245 ew32(CTRL
, ctrl_reg
);
1248 * Disable the receiver on the PHY so when a cable is plugged in, the
1249 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1251 if (hw
->phy
.type
== e1000_phy_m88
)
1252 e1000_phy_disable_receiver(adapter
);
1259 static int e1000_set_82571_fiber_loopback(struct e1000_adapter
*adapter
)
1261 struct e1000_hw
*hw
= &adapter
->hw
;
1262 u32 ctrl
= er32(CTRL
);
1265 /* special requirements for 82571/82572 fiber adapters */
1268 * jump through hoops to make sure link is up because serdes
1269 * link is hardwired up
1271 ctrl
|= E1000_CTRL_SLU
;
1274 /* disable autoneg */
1279 link
= (er32(STATUS
) & E1000_STATUS_LU
);
1282 /* set invert loss of signal */
1284 ctrl
|= E1000_CTRL_ILOS
;
1289 * special write to serdes control register to enable SerDes analog
1292 #define E1000_SERDES_LB_ON 0x410
1293 ew32(SCTL
, E1000_SERDES_LB_ON
);
1299 /* only call this for fiber/serdes connections to es2lan */
1300 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter
*adapter
)
1302 struct e1000_hw
*hw
= &adapter
->hw
;
1303 u32 ctrlext
= er32(CTRL_EXT
);
1304 u32 ctrl
= er32(CTRL
);
1307 * save CTRL_EXT to restore later, reuse an empty variable (unused
1308 * on mac_type 80003es2lan)
1310 adapter
->tx_fifo_head
= ctrlext
;
1312 /* clear the serdes mode bits, putting the device into mac loopback */
1313 ctrlext
&= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES
;
1314 ew32(CTRL_EXT
, ctrlext
);
1316 /* force speed to 1000/FD, link up */
1317 ctrl
&= ~(E1000_CTRL_SPD_1000
| E1000_CTRL_SPD_100
);
1318 ctrl
|= (E1000_CTRL_SLU
| E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
|
1319 E1000_CTRL_SPD_1000
| E1000_CTRL_FD
);
1322 /* set mac loopback */
1324 ctrl
|= E1000_RCTL_LBM_MAC
;
1327 /* set testing mode parameters (no need to reset later) */
1328 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
1329 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1331 (KMRNCTRLSTA_OPMODE
| KMRNCTRLSTA_OPMODE_1GB_FD_GMII
));
1336 static int e1000_setup_loopback_test(struct e1000_adapter
*adapter
)
1338 struct e1000_hw
*hw
= &adapter
->hw
;
1341 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1342 hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1343 switch (hw
->mac
.type
) {
1344 case e1000_80003es2lan
:
1345 return e1000_set_es2lan_mac_loopback(adapter
);
1349 return e1000_set_82571_fiber_loopback(adapter
);
1353 rctl
|= E1000_RCTL_LBM_TCVR
;
1357 } else if (hw
->phy
.media_type
== e1000_media_type_copper
) {
1358 return e1000_integrated_phy_loopback(adapter
);
1364 static void e1000_loopback_cleanup(struct e1000_adapter
*adapter
)
1366 struct e1000_hw
*hw
= &adapter
->hw
;
1371 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
1374 switch (hw
->mac
.type
) {
1375 case e1000_80003es2lan
:
1376 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1377 hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1378 /* restore CTRL_EXT, stealing space from tx_fifo_head */
1379 ew32(CTRL_EXT
, adapter
->tx_fifo_head
);
1380 adapter
->tx_fifo_head
= 0;
1385 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1386 hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1387 #define E1000_SERDES_LB_OFF 0x400
1388 ew32(SCTL
, E1000_SERDES_LB_OFF
);
1394 hw
->mac
.autoneg
= 1;
1395 if (hw
->phy
.type
== e1000_phy_gg82563
)
1396 e1e_wphy(hw
, GG82563_PHY_KMRN_MODE_CTRL
, 0x180);
1397 e1e_rphy(hw
, PHY_CONTROL
, &phy_reg
);
1398 if (phy_reg
& MII_CR_LOOPBACK
) {
1399 phy_reg
&= ~MII_CR_LOOPBACK
;
1400 e1e_wphy(hw
, PHY_CONTROL
, phy_reg
);
1401 e1000e_commit_phy(hw
);
1407 static void e1000_create_lbtest_frame(struct sk_buff
*skb
,
1408 unsigned int frame_size
)
1410 memset(skb
->data
, 0xFF, frame_size
);
1412 memset(&skb
->data
[frame_size
/ 2], 0xAA, frame_size
/ 2 - 1);
1413 memset(&skb
->data
[frame_size
/ 2 + 10], 0xBE, 1);
1414 memset(&skb
->data
[frame_size
/ 2 + 12], 0xAF, 1);
1417 static int e1000_check_lbtest_frame(struct sk_buff
*skb
,
1418 unsigned int frame_size
)
1421 if (*(skb
->data
+ 3) == 0xFF)
1422 if ((*(skb
->data
+ frame_size
/ 2 + 10) == 0xBE) &&
1423 (*(skb
->data
+ frame_size
/ 2 + 12) == 0xAF))
1428 static int e1000_run_loopback_test(struct e1000_adapter
*adapter
)
1430 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1431 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1432 struct pci_dev
*pdev
= adapter
->pdev
;
1433 struct e1000_hw
*hw
= &adapter
->hw
;
1440 ew32(RDT
, rx_ring
->count
- 1);
1443 * Calculate the loop count based on the largest descriptor ring
1444 * The idea is to wrap the largest ring a number of times using 64
1445 * send/receive pairs during each loop
1448 if (rx_ring
->count
<= tx_ring
->count
)
1449 lc
= ((tx_ring
->count
/ 64) * 2) + 1;
1451 lc
= ((rx_ring
->count
/ 64) * 2) + 1;
1455 for (j
= 0; j
<= lc
; j
++) { /* loop count loop */
1456 for (i
= 0; i
< 64; i
++) { /* send the packets */
1457 e1000_create_lbtest_frame(tx_ring
->buffer_info
[k
].skb
,
1459 pci_dma_sync_single_for_device(pdev
,
1460 tx_ring
->buffer_info
[k
].dma
,
1461 tx_ring
->buffer_info
[k
].length
,
1464 if (k
== tx_ring
->count
)
1469 time
= jiffies
; /* set the start time for the receive */
1471 do { /* receive the sent packets */
1472 pci_dma_sync_single_for_cpu(pdev
,
1473 rx_ring
->buffer_info
[l
].dma
, 2048,
1474 PCI_DMA_FROMDEVICE
);
1476 ret_val
= e1000_check_lbtest_frame(
1477 rx_ring
->buffer_info
[l
].skb
, 1024);
1481 if (l
== rx_ring
->count
)
1484 * time + 20 msecs (200 msecs on 2.4) is more than
1485 * enough time to complete the receives, if it's
1486 * exceeded, break and error off
1488 } while ((good_cnt
< 64) && !time_after(jiffies
, time
+ 20));
1489 if (good_cnt
!= 64) {
1490 ret_val
= 13; /* ret_val is the same as mis-compare */
1493 if (jiffies
>= (time
+ 20)) {
1494 ret_val
= 14; /* error code for time out error */
1497 } /* end loop count loop */
1501 static int e1000_loopback_test(struct e1000_adapter
*adapter
, u64
*data
)
1504 * PHY loopback cannot be performed if SoL/IDER
1505 * sessions are active
1507 if (e1000_check_reset_block(&adapter
->hw
)) {
1508 ndev_err(adapter
->netdev
, "Cannot do PHY loopback test "
1509 "when SoL/IDER is active.\n");
1514 *data
= e1000_setup_desc_rings(adapter
);
1518 *data
= e1000_setup_loopback_test(adapter
);
1522 *data
= e1000_run_loopback_test(adapter
);
1523 e1000_loopback_cleanup(adapter
);
1526 e1000_free_desc_rings(adapter
);
1531 static int e1000_link_test(struct e1000_adapter
*adapter
, u64
*data
)
1533 struct e1000_hw
*hw
= &adapter
->hw
;
1536 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1538 hw
->mac
.serdes_has_link
= 0;
1541 * On some blade server designs, link establishment
1542 * could take as long as 2-3 minutes
1545 hw
->mac
.ops
.check_for_link(hw
);
1546 if (hw
->mac
.serdes_has_link
)
1549 } while (i
++ < 3750);
1553 hw
->mac
.ops
.check_for_link(hw
);
1554 if (hw
->mac
.autoneg
)
1557 if (!(er32(STATUS
) &
1564 static int e1000e_get_sset_count(struct net_device
*netdev
, int sset
)
1568 return E1000_TEST_LEN
;
1570 return E1000_STATS_LEN
;
1576 static void e1000_diag_test(struct net_device
*netdev
,
1577 struct ethtool_test
*eth_test
, u64
*data
)
1579 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1580 u16 autoneg_advertised
;
1581 u8 forced_speed_duplex
;
1583 bool if_running
= netif_running(netdev
);
1585 set_bit(__E1000_TESTING
, &adapter
->state
);
1586 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1589 /* save speed, duplex, autoneg settings */
1590 autoneg_advertised
= adapter
->hw
.phy
.autoneg_advertised
;
1591 forced_speed_duplex
= adapter
->hw
.mac
.forced_speed_duplex
;
1592 autoneg
= adapter
->hw
.mac
.autoneg
;
1594 ndev_info(netdev
, "offline testing starting\n");
1597 * Link test performed before hardware reset so autoneg doesn't
1598 * interfere with test result
1600 if (e1000_link_test(adapter
, &data
[4]))
1601 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1604 /* indicate we're in test mode */
1607 e1000e_reset(adapter
);
1609 if (e1000_reg_test(adapter
, &data
[0]))
1610 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1612 e1000e_reset(adapter
);
1613 if (e1000_eeprom_test(adapter
, &data
[1]))
1614 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1616 e1000e_reset(adapter
);
1617 if (e1000_intr_test(adapter
, &data
[2]))
1618 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1620 e1000e_reset(adapter
);
1621 /* make sure the phy is powered up */
1622 e1000e_power_up_phy(adapter
);
1623 if (e1000_loopback_test(adapter
, &data
[3]))
1624 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1626 /* restore speed, duplex, autoneg settings */
1627 adapter
->hw
.phy
.autoneg_advertised
= autoneg_advertised
;
1628 adapter
->hw
.mac
.forced_speed_duplex
= forced_speed_duplex
;
1629 adapter
->hw
.mac
.autoneg
= autoneg
;
1631 /* force this routine to wait until autoneg complete/timeout */
1632 adapter
->hw
.phy
.autoneg_wait_to_complete
= 1;
1633 e1000e_reset(adapter
);
1634 adapter
->hw
.phy
.autoneg_wait_to_complete
= 0;
1636 clear_bit(__E1000_TESTING
, &adapter
->state
);
1640 ndev_info(netdev
, "online testing starting\n");
1642 if (e1000_link_test(adapter
, &data
[4]))
1643 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1645 /* Online tests aren't run; pass by default */
1651 clear_bit(__E1000_TESTING
, &adapter
->state
);
1653 msleep_interruptible(4 * 1000);
1656 static void e1000_get_wol(struct net_device
*netdev
,
1657 struct ethtool_wolinfo
*wol
)
1659 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1664 if (!(adapter
->flags
& FLAG_HAS_WOL
))
1667 wol
->supported
= WAKE_UCAST
| WAKE_MCAST
|
1668 WAKE_BCAST
| WAKE_MAGIC
|
1669 WAKE_PHY
| WAKE_ARP
;
1671 /* apply any specific unsupported masks here */
1672 if (adapter
->flags
& FLAG_NO_WAKE_UCAST
) {
1673 wol
->supported
&= ~WAKE_UCAST
;
1675 if (adapter
->wol
& E1000_WUFC_EX
)
1676 ndev_err(netdev
, "Interface does not support "
1677 "directed (unicast) frame wake-up packets\n");
1680 if (adapter
->wol
& E1000_WUFC_EX
)
1681 wol
->wolopts
|= WAKE_UCAST
;
1682 if (adapter
->wol
& E1000_WUFC_MC
)
1683 wol
->wolopts
|= WAKE_MCAST
;
1684 if (adapter
->wol
& E1000_WUFC_BC
)
1685 wol
->wolopts
|= WAKE_BCAST
;
1686 if (adapter
->wol
& E1000_WUFC_MAG
)
1687 wol
->wolopts
|= WAKE_MAGIC
;
1688 if (adapter
->wol
& E1000_WUFC_LNKC
)
1689 wol
->wolopts
|= WAKE_PHY
;
1690 if (adapter
->wol
& E1000_WUFC_ARP
)
1691 wol
->wolopts
|= WAKE_ARP
;
1694 static int e1000_set_wol(struct net_device
*netdev
,
1695 struct ethtool_wolinfo
*wol
)
1697 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1699 if (wol
->wolopts
& WAKE_MAGICSECURE
)
1702 if (!(adapter
->flags
& FLAG_HAS_WOL
))
1703 return wol
->wolopts
? -EOPNOTSUPP
: 0;
1705 /* these settings will always override what we currently have */
1708 if (wol
->wolopts
& WAKE_UCAST
)
1709 adapter
->wol
|= E1000_WUFC_EX
;
1710 if (wol
->wolopts
& WAKE_MCAST
)
1711 adapter
->wol
|= E1000_WUFC_MC
;
1712 if (wol
->wolopts
& WAKE_BCAST
)
1713 adapter
->wol
|= E1000_WUFC_BC
;
1714 if (wol
->wolopts
& WAKE_MAGIC
)
1715 adapter
->wol
|= E1000_WUFC_MAG
;
1716 if (wol
->wolopts
& WAKE_PHY
)
1717 adapter
->wol
|= E1000_WUFC_LNKC
;
1718 if (wol
->wolopts
& WAKE_ARP
)
1719 adapter
->wol
|= E1000_WUFC_ARP
;
1724 /* toggle LED 4 times per second = 2 "blinks" per second */
1725 #define E1000_ID_INTERVAL (HZ/4)
1727 /* bit defines for adapter->led_status */
1728 #define E1000_LED_ON 0
1730 static void e1000_led_blink_callback(unsigned long data
)
1732 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
1734 if (test_and_change_bit(E1000_LED_ON
, &adapter
->led_status
))
1735 adapter
->hw
.mac
.ops
.led_off(&adapter
->hw
);
1737 adapter
->hw
.mac
.ops
.led_on(&adapter
->hw
);
1739 mod_timer(&adapter
->blink_timer
, jiffies
+ E1000_ID_INTERVAL
);
1742 static int e1000_phys_id(struct net_device
*netdev
, u32 data
)
1744 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1749 if (adapter
->hw
.phy
.type
== e1000_phy_ife
) {
1750 if (!adapter
->blink_timer
.function
) {
1751 init_timer(&adapter
->blink_timer
);
1752 adapter
->blink_timer
.function
=
1753 e1000_led_blink_callback
;
1754 adapter
->blink_timer
.data
= (unsigned long) adapter
;
1756 mod_timer(&adapter
->blink_timer
, jiffies
);
1757 msleep_interruptible(data
* 1000);
1758 del_timer_sync(&adapter
->blink_timer
);
1759 e1e_wphy(&adapter
->hw
,
1760 IFE_PHY_SPECIAL_CONTROL_LED
, 0);
1762 e1000e_blink_led(&adapter
->hw
);
1763 msleep_interruptible(data
* 1000);
1766 adapter
->hw
.mac
.ops
.led_off(&adapter
->hw
);
1767 clear_bit(E1000_LED_ON
, &adapter
->led_status
);
1768 adapter
->hw
.mac
.ops
.cleanup_led(&adapter
->hw
);
1773 static int e1000_nway_reset(struct net_device
*netdev
)
1775 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1776 if (netif_running(netdev
))
1777 e1000e_reinit_locked(adapter
);
1781 static void e1000_get_ethtool_stats(struct net_device
*netdev
,
1782 struct ethtool_stats
*stats
,
1785 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1788 e1000e_update_stats(adapter
);
1789 for (i
= 0; i
< E1000_GLOBAL_STATS_LEN
; i
++) {
1790 char *p
= (char *)adapter
+e1000_gstrings_stats
[i
].stat_offset
;
1791 data
[i
] = (e1000_gstrings_stats
[i
].sizeof_stat
==
1792 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1796 static void e1000_get_strings(struct net_device
*netdev
, u32 stringset
,
1802 switch (stringset
) {
1804 memcpy(data
, *e1000_gstrings_test
, sizeof(e1000_gstrings_test
));
1807 for (i
= 0; i
< E1000_GLOBAL_STATS_LEN
; i
++) {
1808 memcpy(p
, e1000_gstrings_stats
[i
].stat_string
,
1810 p
+= ETH_GSTRING_LEN
;
1816 static const struct ethtool_ops e1000_ethtool_ops
= {
1817 .get_settings
= e1000_get_settings
,
1818 .set_settings
= e1000_set_settings
,
1819 .get_drvinfo
= e1000_get_drvinfo
,
1820 .get_regs_len
= e1000_get_regs_len
,
1821 .get_regs
= e1000_get_regs
,
1822 .get_wol
= e1000_get_wol
,
1823 .set_wol
= e1000_set_wol
,
1824 .get_msglevel
= e1000_get_msglevel
,
1825 .set_msglevel
= e1000_set_msglevel
,
1826 .nway_reset
= e1000_nway_reset
,
1827 .get_link
= e1000_get_link
,
1828 .get_eeprom_len
= e1000_get_eeprom_len
,
1829 .get_eeprom
= e1000_get_eeprom
,
1830 .set_eeprom
= e1000_set_eeprom
,
1831 .get_ringparam
= e1000_get_ringparam
,
1832 .set_ringparam
= e1000_set_ringparam
,
1833 .get_pauseparam
= e1000_get_pauseparam
,
1834 .set_pauseparam
= e1000_set_pauseparam
,
1835 .get_rx_csum
= e1000_get_rx_csum
,
1836 .set_rx_csum
= e1000_set_rx_csum
,
1837 .get_tx_csum
= e1000_get_tx_csum
,
1838 .set_tx_csum
= e1000_set_tx_csum
,
1839 .get_sg
= ethtool_op_get_sg
,
1840 .set_sg
= ethtool_op_set_sg
,
1841 .get_tso
= ethtool_op_get_tso
,
1842 .set_tso
= e1000_set_tso
,
1843 .self_test
= e1000_diag_test
,
1844 .get_strings
= e1000_get_strings
,
1845 .phys_id
= e1000_phys_id
,
1846 .get_ethtool_stats
= e1000_get_ethtool_stats
,
1847 .get_sset_count
= e1000e_get_sset_count
,
1850 void e1000e_set_ethtool_ops(struct net_device
*netdev
)
1852 SET_ETHTOOL_OPS(netdev
, &e1000_ethtool_ops
);