1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2007 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 /* ethtool support for e1000 */
31 #include <linux/netdevice.h>
32 #include <linux/ethtool.h>
33 #include <linux/pci.h>
34 #include <linux/delay.h>
39 char stat_string
[ETH_GSTRING_LEN
];
44 #define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
45 offsetof(struct e1000_adapter, m)
46 static const struct e1000_stats e1000_gstrings_stats
[] = {
47 { "rx_packets", E1000_STAT(stats
.gprc
) },
48 { "tx_packets", E1000_STAT(stats
.gptc
) },
49 { "rx_bytes", E1000_STAT(stats
.gorcl
) },
50 { "tx_bytes", E1000_STAT(stats
.gotcl
) },
51 { "rx_broadcast", E1000_STAT(stats
.bprc
) },
52 { "tx_broadcast", E1000_STAT(stats
.bptc
) },
53 { "rx_multicast", E1000_STAT(stats
.mprc
) },
54 { "tx_multicast", E1000_STAT(stats
.mptc
) },
55 { "rx_errors", E1000_STAT(net_stats
.rx_errors
) },
56 { "tx_errors", E1000_STAT(net_stats
.tx_errors
) },
57 { "tx_dropped", E1000_STAT(net_stats
.tx_dropped
) },
58 { "multicast", E1000_STAT(stats
.mprc
) },
59 { "collisions", E1000_STAT(stats
.colc
) },
60 { "rx_length_errors", E1000_STAT(net_stats
.rx_length_errors
) },
61 { "rx_over_errors", E1000_STAT(net_stats
.rx_over_errors
) },
62 { "rx_crc_errors", E1000_STAT(stats
.crcerrs
) },
63 { "rx_frame_errors", E1000_STAT(net_stats
.rx_frame_errors
) },
64 { "rx_no_buffer_count", E1000_STAT(stats
.rnbc
) },
65 { "rx_missed_errors", E1000_STAT(stats
.mpc
) },
66 { "tx_aborted_errors", E1000_STAT(stats
.ecol
) },
67 { "tx_carrier_errors", E1000_STAT(stats
.tncrs
) },
68 { "tx_fifo_errors", E1000_STAT(net_stats
.tx_fifo_errors
) },
69 { "tx_heartbeat_errors", E1000_STAT(net_stats
.tx_heartbeat_errors
) },
70 { "tx_window_errors", E1000_STAT(stats
.latecol
) },
71 { "tx_abort_late_coll", E1000_STAT(stats
.latecol
) },
72 { "tx_deferred_ok", E1000_STAT(stats
.dc
) },
73 { "tx_single_coll_ok", E1000_STAT(stats
.scc
) },
74 { "tx_multi_coll_ok", E1000_STAT(stats
.mcc
) },
75 { "tx_timeout_count", E1000_STAT(tx_timeout_count
) },
76 { "tx_restart_queue", E1000_STAT(restart_queue
) },
77 { "rx_long_length_errors", E1000_STAT(stats
.roc
) },
78 { "rx_short_length_errors", E1000_STAT(stats
.ruc
) },
79 { "rx_align_errors", E1000_STAT(stats
.algnerrc
) },
80 { "tx_tcp_seg_good", E1000_STAT(stats
.tsctc
) },
81 { "tx_tcp_seg_failed", E1000_STAT(stats
.tsctfc
) },
82 { "rx_flow_control_xon", E1000_STAT(stats
.xonrxc
) },
83 { "rx_flow_control_xoff", E1000_STAT(stats
.xoffrxc
) },
84 { "tx_flow_control_xon", E1000_STAT(stats
.xontxc
) },
85 { "tx_flow_control_xoff", E1000_STAT(stats
.xofftxc
) },
86 { "rx_long_byte_count", E1000_STAT(stats
.gorcl
) },
87 { "rx_csum_offload_good", E1000_STAT(hw_csum_good
) },
88 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err
) },
89 { "rx_header_split", E1000_STAT(rx_hdr_split
) },
90 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed
) },
91 { "tx_smbus", E1000_STAT(stats
.mgptc
) },
92 { "rx_smbus", E1000_STAT(stats
.mgprc
) },
93 { "dropped_smbus", E1000_STAT(stats
.mgpdc
) },
94 { "rx_dma_failed", E1000_STAT(rx_dma_failed
) },
95 { "tx_dma_failed", E1000_STAT(tx_dma_failed
) },
98 #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
99 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
100 static const char e1000_gstrings_test
[][ETH_GSTRING_LEN
] = {
101 "Register test (offline)", "Eeprom test (offline)",
102 "Interrupt test (offline)", "Loopback test (offline)",
103 "Link test (on/offline)"
105 #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
107 static int e1000_get_settings(struct net_device
*netdev
,
108 struct ethtool_cmd
*ecmd
)
110 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
111 struct e1000_hw
*hw
= &adapter
->hw
;
114 if (hw
->media_type
== e1000_media_type_copper
) {
116 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
117 SUPPORTED_10baseT_Full
|
118 SUPPORTED_100baseT_Half
|
119 SUPPORTED_100baseT_Full
|
120 SUPPORTED_1000baseT_Full
|
123 if (hw
->phy
.type
== e1000_phy_ife
)
124 ecmd
->supported
&= ~SUPPORTED_1000baseT_Full
;
125 ecmd
->advertising
= ADVERTISED_TP
;
127 if (hw
->mac
.autoneg
== 1) {
128 ecmd
->advertising
|= ADVERTISED_Autoneg
;
129 /* the e1000 autoneg seems to match ethtool nicely */
130 ecmd
->advertising
|= hw
->phy
.autoneg_advertised
;
133 ecmd
->port
= PORT_TP
;
134 ecmd
->phy_address
= hw
->phy
.addr
;
135 ecmd
->transceiver
= XCVR_INTERNAL
;
138 ecmd
->supported
= (SUPPORTED_1000baseT_Full
|
142 ecmd
->advertising
= (ADVERTISED_1000baseT_Full
|
146 ecmd
->port
= PORT_FIBRE
;
147 ecmd
->transceiver
= XCVR_EXTERNAL
;
150 status
= er32(STATUS
);
151 if (status
& E1000_STATUS_LU
) {
152 if (status
& E1000_STATUS_SPEED_1000
)
154 else if (status
& E1000_STATUS_SPEED_100
)
159 if (status
& E1000_STATUS_FD
)
160 ecmd
->duplex
= DUPLEX_FULL
;
162 ecmd
->duplex
= DUPLEX_HALF
;
168 ecmd
->autoneg
= ((hw
->media_type
== e1000_media_type_fiber
) ||
169 hw
->mac
.autoneg
) ? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
173 static u32
e1000_get_link(struct net_device
*netdev
)
175 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
176 struct e1000_hw
*hw
= &adapter
->hw
;
179 status
= er32(STATUS
);
180 return (status
& E1000_STATUS_LU
);
183 static int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, u16 spddplx
)
185 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
189 /* Fiber NICs only allow 1000 gbps Full duplex */
190 if ((adapter
->hw
.media_type
== e1000_media_type_fiber
) &&
191 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
192 ndev_err(adapter
->netdev
, "Unsupported Speed/Duplex "
198 case SPEED_10
+ DUPLEX_HALF
:
199 mac
->forced_speed_duplex
= ADVERTISE_10_HALF
;
201 case SPEED_10
+ DUPLEX_FULL
:
202 mac
->forced_speed_duplex
= ADVERTISE_10_FULL
;
204 case SPEED_100
+ DUPLEX_HALF
:
205 mac
->forced_speed_duplex
= ADVERTISE_100_HALF
;
207 case SPEED_100
+ DUPLEX_FULL
:
208 mac
->forced_speed_duplex
= ADVERTISE_100_FULL
;
210 case SPEED_1000
+ DUPLEX_FULL
:
212 adapter
->hw
.phy
.autoneg_advertised
= ADVERTISE_1000_FULL
;
214 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
216 ndev_err(adapter
->netdev
, "Unsupported Speed/Duplex "
223 static int e1000_set_settings(struct net_device
*netdev
,
224 struct ethtool_cmd
*ecmd
)
226 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
227 struct e1000_hw
*hw
= &adapter
->hw
;
229 /* When SoL/IDER sessions are active, autoneg/speed/duplex
230 * cannot be changed */
231 if (e1000_check_reset_block(hw
)) {
232 ndev_err(netdev
, "Cannot change link "
233 "characteristics when SoL/IDER is active.\n");
237 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
240 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
242 if (hw
->media_type
== e1000_media_type_fiber
)
243 hw
->phy
.autoneg_advertised
= ADVERTISED_1000baseT_Full
|
247 hw
->phy
.autoneg_advertised
= ecmd
->advertising
|
250 ecmd
->advertising
= hw
->phy
.autoneg_advertised
;
252 if (e1000_set_spd_dplx(adapter
, ecmd
->speed
+ ecmd
->duplex
)) {
253 clear_bit(__E1000_RESETTING
, &adapter
->state
);
260 if (netif_running(adapter
->netdev
)) {
261 e1000e_down(adapter
);
264 e1000e_reset(adapter
);
267 clear_bit(__E1000_RESETTING
, &adapter
->state
);
271 static void e1000_get_pauseparam(struct net_device
*netdev
,
272 struct ethtool_pauseparam
*pause
)
274 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
275 struct e1000_hw
*hw
= &adapter
->hw
;
278 (adapter
->fc_autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
);
280 if (hw
->mac
.fc
== e1000_fc_rx_pause
) {
282 } else if (hw
->mac
.fc
== e1000_fc_tx_pause
) {
284 } else if (hw
->mac
.fc
== e1000_fc_full
) {
290 static int e1000_set_pauseparam(struct net_device
*netdev
,
291 struct ethtool_pauseparam
*pause
)
293 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
294 struct e1000_hw
*hw
= &adapter
->hw
;
297 adapter
->fc_autoneg
= pause
->autoneg
;
299 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
302 if (pause
->rx_pause
&& pause
->tx_pause
)
303 hw
->mac
.fc
= e1000_fc_full
;
304 else if (pause
->rx_pause
&& !pause
->tx_pause
)
305 hw
->mac
.fc
= e1000_fc_rx_pause
;
306 else if (!pause
->rx_pause
&& pause
->tx_pause
)
307 hw
->mac
.fc
= e1000_fc_tx_pause
;
308 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
309 hw
->mac
.fc
= e1000_fc_none
;
311 hw
->mac
.original_fc
= hw
->mac
.fc
;
313 if (adapter
->fc_autoneg
== AUTONEG_ENABLE
) {
314 hw
->mac
.fc
= e1000_fc_default
;
315 if (netif_running(adapter
->netdev
)) {
316 e1000e_down(adapter
);
319 e1000e_reset(adapter
);
322 retval
= ((hw
->media_type
== e1000_media_type_fiber
) ?
323 hw
->mac
.ops
.setup_link(hw
) : e1000e_force_mac_fc(hw
));
326 clear_bit(__E1000_RESETTING
, &adapter
->state
);
330 static u32
e1000_get_rx_csum(struct net_device
*netdev
)
332 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
333 return (adapter
->flags
& FLAG_RX_CSUM_ENABLED
);
336 static int e1000_set_rx_csum(struct net_device
*netdev
, u32 data
)
338 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
341 adapter
->flags
|= FLAG_RX_CSUM_ENABLED
;
343 adapter
->flags
&= ~FLAG_RX_CSUM_ENABLED
;
345 if (netif_running(netdev
))
346 e1000e_reinit_locked(adapter
);
348 e1000e_reset(adapter
);
352 static u32
e1000_get_tx_csum(struct net_device
*netdev
)
354 return ((netdev
->features
& NETIF_F_HW_CSUM
) != 0);
357 static int e1000_set_tx_csum(struct net_device
*netdev
, u32 data
)
360 netdev
->features
|= NETIF_F_HW_CSUM
;
362 netdev
->features
&= ~NETIF_F_HW_CSUM
;
367 static int e1000_set_tso(struct net_device
*netdev
, u32 data
)
369 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
372 netdev
->features
|= NETIF_F_TSO
;
373 netdev
->features
|= NETIF_F_TSO6
;
375 netdev
->features
&= ~NETIF_F_TSO
;
376 netdev
->features
&= ~NETIF_F_TSO6
;
379 ndev_info(netdev
, "TSO is %s\n",
380 data
? "Enabled" : "Disabled");
381 adapter
->flags
|= FLAG_TSO_FORCE
;
385 static u32
e1000_get_msglevel(struct net_device
*netdev
)
387 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
388 return adapter
->msg_enable
;
391 static void e1000_set_msglevel(struct net_device
*netdev
, u32 data
)
393 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
394 adapter
->msg_enable
= data
;
397 static int e1000_get_regs_len(struct net_device
*netdev
)
399 #define E1000_REGS_LEN 32 /* overestimate */
400 return E1000_REGS_LEN
* sizeof(u32
);
403 static void e1000_get_regs(struct net_device
*netdev
,
404 struct ethtool_regs
*regs
, void *p
)
406 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
407 struct e1000_hw
*hw
= &adapter
->hw
;
412 memset(p
, 0, E1000_REGS_LEN
* sizeof(u32
));
414 pci_read_config_byte(adapter
->pdev
, PCI_REVISION_ID
, &revision_id
);
416 regs
->version
= (1 << 24) | (revision_id
<< 16) | adapter
->pdev
->device
;
418 regs_buff
[0] = er32(CTRL
);
419 regs_buff
[1] = er32(STATUS
);
421 regs_buff
[2] = er32(RCTL
);
422 regs_buff
[3] = er32(RDLEN
);
423 regs_buff
[4] = er32(RDH
);
424 regs_buff
[5] = er32(RDT
);
425 regs_buff
[6] = er32(RDTR
);
427 regs_buff
[7] = er32(TCTL
);
428 regs_buff
[8] = er32(TDLEN
);
429 regs_buff
[9] = er32(TDH
);
430 regs_buff
[10] = er32(TDT
);
431 regs_buff
[11] = er32(TIDV
);
433 regs_buff
[12] = adapter
->hw
.phy
.type
; /* PHY type (IGP=1, M88=0) */
434 if (hw
->phy
.type
== e1000_phy_m88
) {
435 e1e_rphy(hw
, M88E1000_PHY_SPEC_STATUS
, &phy_data
);
436 regs_buff
[13] = (u32
)phy_data
; /* cable length */
437 regs_buff
[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
438 regs_buff
[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
439 regs_buff
[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
440 e1e_rphy(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
441 regs_buff
[17] = (u32
)phy_data
; /* extended 10bt distance */
442 regs_buff
[18] = regs_buff
[13]; /* cable polarity */
443 regs_buff
[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
444 regs_buff
[20] = regs_buff
[17]; /* polarity correction */
445 /* phy receive errors */
446 regs_buff
[22] = adapter
->phy_stats
.receive_errors
;
447 regs_buff
[23] = regs_buff
[13]; /* mdix mode */
449 regs_buff
[21] = adapter
->phy_stats
.idle_errors
; /* phy idle errors */
450 e1e_rphy(hw
, PHY_1000T_STATUS
, &phy_data
);
451 regs_buff
[24] = (u32
)phy_data
; /* phy local receiver status */
452 regs_buff
[25] = regs_buff
[24]; /* phy remote receiver status */
455 static int e1000_get_eeprom_len(struct net_device
*netdev
)
457 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
458 return adapter
->hw
.nvm
.word_size
* 2;
461 static int e1000_get_eeprom(struct net_device
*netdev
,
462 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
464 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
465 struct e1000_hw
*hw
= &adapter
->hw
;
472 if (eeprom
->len
== 0)
475 eeprom
->magic
= adapter
->pdev
->vendor
| (adapter
->pdev
->device
<< 16);
477 first_word
= eeprom
->offset
>> 1;
478 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
480 eeprom_buff
= kmalloc(sizeof(u16
) *
481 (last_word
- first_word
+ 1), GFP_KERNEL
);
485 if (hw
->nvm
.type
== e1000_nvm_eeprom_spi
) {
486 ret_val
= e1000_read_nvm(hw
, first_word
,
487 last_word
- first_word
+ 1,
490 for (i
= 0; i
< last_word
- first_word
+ 1; i
++) {
491 ret_val
= e1000_read_nvm(hw
, first_word
+ i
, 1,
498 /* Device's eeprom is always little-endian, word addressable */
499 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
500 le16_to_cpus(&eeprom_buff
[i
]);
502 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 1), eeprom
->len
);
508 static int e1000_set_eeprom(struct net_device
*netdev
,
509 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
511 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
512 struct e1000_hw
*hw
= &adapter
->hw
;
521 if (eeprom
->len
== 0)
524 if (eeprom
->magic
!= (adapter
->pdev
->vendor
| (adapter
->pdev
->device
<< 16)))
527 max_len
= hw
->nvm
.word_size
* 2;
529 first_word
= eeprom
->offset
>> 1;
530 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
531 eeprom_buff
= kmalloc(max_len
, GFP_KERNEL
);
535 ptr
= (void *)eeprom_buff
;
537 if (eeprom
->offset
& 1) {
538 /* need read/modify/write of first changed EEPROM word */
539 /* only the second byte of the word is being modified */
540 ret_val
= e1000_read_nvm(hw
, first_word
, 1, &eeprom_buff
[0]);
543 if (((eeprom
->offset
+ eeprom
->len
) & 1) && (ret_val
== 0))
544 /* need read/modify/write of last changed EEPROM word */
545 /* only the first byte of the word is being modified */
546 ret_val
= e1000_read_nvm(hw
, last_word
, 1,
547 &eeprom_buff
[last_word
- first_word
]);
549 /* Device's eeprom is always little-endian, word addressable */
550 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
551 le16_to_cpus(&eeprom_buff
[i
]);
553 memcpy(ptr
, bytes
, eeprom
->len
);
555 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
556 eeprom_buff
[i
] = cpu_to_le16(eeprom_buff
[i
]);
558 ret_val
= e1000_write_nvm(hw
, first_word
,
559 last_word
- first_word
+ 1, eeprom_buff
);
561 /* Update the checksum over the first part of the EEPROM if needed
562 * and flush shadow RAM for 82573 controllers */
563 if ((ret_val
== 0) && ((first_word
<= NVM_CHECKSUM_REG
) ||
564 (hw
->mac
.type
== e1000_82573
)))
565 e1000e_update_nvm_checksum(hw
);
571 static void e1000_get_drvinfo(struct net_device
*netdev
,
572 struct ethtool_drvinfo
*drvinfo
)
574 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
575 char firmware_version
[32];
578 strncpy(drvinfo
->driver
, e1000e_driver_name
, 32);
579 strncpy(drvinfo
->version
, e1000e_driver_version
, 32);
581 /* EEPROM image version # is reported as firmware version # for
582 * PCI-E controllers */
583 e1000_read_nvm(&adapter
->hw
, 5, 1, &eeprom_data
);
584 sprintf(firmware_version
, "%d.%d-%d",
585 (eeprom_data
& 0xF000) >> 12,
586 (eeprom_data
& 0x0FF0) >> 4,
587 eeprom_data
& 0x000F);
589 strncpy(drvinfo
->fw_version
, firmware_version
, 32);
590 strncpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
), 32);
591 drvinfo
->regdump_len
= e1000_get_regs_len(netdev
);
592 drvinfo
->eedump_len
= e1000_get_eeprom_len(netdev
);
595 static void e1000_get_ringparam(struct net_device
*netdev
,
596 struct ethtool_ringparam
*ring
)
598 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
599 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
600 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
602 ring
->rx_max_pending
= E1000_MAX_RXD
;
603 ring
->tx_max_pending
= E1000_MAX_TXD
;
604 ring
->rx_mini_max_pending
= 0;
605 ring
->rx_jumbo_max_pending
= 0;
606 ring
->rx_pending
= rx_ring
->count
;
607 ring
->tx_pending
= tx_ring
->count
;
608 ring
->rx_mini_pending
= 0;
609 ring
->rx_jumbo_pending
= 0;
612 static int e1000_set_ringparam(struct net_device
*netdev
,
613 struct ethtool_ringparam
*ring
)
615 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
616 struct e1000_ring
*tx_ring
, *tx_old
;
617 struct e1000_ring
*rx_ring
, *rx_old
;
620 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
623 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
626 if (netif_running(adapter
->netdev
))
627 e1000e_down(adapter
);
629 tx_old
= adapter
->tx_ring
;
630 rx_old
= adapter
->rx_ring
;
633 tx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
637 rx_ring
= kzalloc(sizeof(struct e1000_ring
), GFP_KERNEL
);
641 adapter
->tx_ring
= tx_ring
;
642 adapter
->rx_ring
= rx_ring
;
644 rx_ring
->count
= max(ring
->rx_pending
, (u32
)E1000_MIN_RXD
);
645 rx_ring
->count
= min(rx_ring
->count
, (u32
)(E1000_MAX_RXD
));
646 rx_ring
->count
= ALIGN(rx_ring
->count
, REQ_RX_DESCRIPTOR_MULTIPLE
);
648 tx_ring
->count
= max(ring
->tx_pending
, (u32
)E1000_MIN_TXD
);
649 tx_ring
->count
= min(tx_ring
->count
, (u32
)(E1000_MAX_TXD
));
650 tx_ring
->count
= ALIGN(tx_ring
->count
, REQ_TX_DESCRIPTOR_MULTIPLE
);
652 if (netif_running(adapter
->netdev
)) {
653 /* Try to get new resources before deleting old */
654 err
= e1000e_setup_rx_resources(adapter
);
657 err
= e1000e_setup_tx_resources(adapter
);
661 /* save the new, restore the old in order to free it,
662 * then restore the new back again */
663 adapter
->rx_ring
= rx_old
;
664 adapter
->tx_ring
= tx_old
;
665 e1000e_free_rx_resources(adapter
);
666 e1000e_free_tx_resources(adapter
);
669 adapter
->rx_ring
= rx_ring
;
670 adapter
->tx_ring
= tx_ring
;
671 err
= e1000e_up(adapter
);
676 clear_bit(__E1000_RESETTING
, &adapter
->state
);
679 e1000e_free_rx_resources(adapter
);
681 adapter
->rx_ring
= rx_old
;
682 adapter
->tx_ring
= tx_old
;
689 clear_bit(__E1000_RESETTING
, &adapter
->state
);
693 static bool reg_pattern_test_array(struct e1000_adapter
*adapter
, u64
*data
,
694 int reg
, int offset
, u32 mask
, u32 write
)
698 static const u32 test
[] =
699 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
700 for (i
= 0; i
< ARRAY_SIZE(test
); i
++) {
701 E1000_WRITE_REG_ARRAY(&adapter
->hw
, reg
, offset
,
703 read
= E1000_READ_REG_ARRAY(&adapter
->hw
, reg
, offset
);
704 if (read
!= (test
[i
] & write
& mask
)) {
705 ndev_err(adapter
->netdev
, "pattern test reg %04X "
706 "failed: got 0x%08X expected 0x%08X\n",
708 read
, (test
[i
] & write
& mask
));
716 static bool reg_set_and_check(struct e1000_adapter
*adapter
, u64
*data
,
717 int reg
, u32 mask
, u32 write
)
720 __ew32(&adapter
->hw
, reg
, write
& mask
);
721 read
= __er32(&adapter
->hw
, reg
);
722 if ((write
& mask
) != (read
& mask
)) {
723 ndev_err(adapter
->netdev
, "set/check reg %04X test failed: "
724 "got 0x%08X expected 0x%08X\n", reg
, (read
& mask
),
732 #define REG_PATTERN_TEST(R, M, W) \
734 if (reg_pattern_test_array(adapter, data, R, 0, M, W)) \
738 #define REG_PATTERN_TEST_ARRAY(R, offset, M, W) \
740 if (reg_pattern_test_array(adapter, data, R, offset, M, W)) \
744 #define REG_SET_AND_CHECK(R, M, W) \
746 if (reg_set_and_check(adapter, data, R, M, W)) \
750 static int e1000_reg_test(struct e1000_adapter
*adapter
, u64
*data
)
752 struct e1000_hw
*hw
= &adapter
->hw
;
753 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
754 struct net_device
*netdev
= adapter
->netdev
;
761 /* The status register is Read Only, so a write should fail.
762 * Some bits that get toggled are ignored.
765 /* there are several bits on newer hardware that are r/w */
768 case e1000_80003es2lan
:
781 before
= er32(STATUS
);
782 value
= (er32(STATUS
) & toggle
);
783 ew32(STATUS
, toggle
);
784 after
= er32(STATUS
) & toggle
;
785 if (value
!= after
) {
786 ndev_err(netdev
, "failed STATUS register test got: "
787 "0x%08X expected: 0x%08X\n", after
, value
);
791 /* restore previous status */
792 ew32(STATUS
, before
);
794 if ((mac
->type
!= e1000_ich8lan
) &&
795 (mac
->type
!= e1000_ich9lan
)) {
796 REG_PATTERN_TEST(E1000_FCAL
, 0xFFFFFFFF, 0xFFFFFFFF);
797 REG_PATTERN_TEST(E1000_FCAH
, 0x0000FFFF, 0xFFFFFFFF);
798 REG_PATTERN_TEST(E1000_FCT
, 0x0000FFFF, 0xFFFFFFFF);
799 REG_PATTERN_TEST(E1000_VET
, 0x0000FFFF, 0xFFFFFFFF);
802 REG_PATTERN_TEST(E1000_RDTR
, 0x0000FFFF, 0xFFFFFFFF);
803 REG_PATTERN_TEST(E1000_RDBAH
, 0xFFFFFFFF, 0xFFFFFFFF);
804 REG_PATTERN_TEST(E1000_RDLEN
, 0x000FFF80, 0x000FFFFF);
805 REG_PATTERN_TEST(E1000_RDH
, 0x0000FFFF, 0x0000FFFF);
806 REG_PATTERN_TEST(E1000_RDT
, 0x0000FFFF, 0x0000FFFF);
807 REG_PATTERN_TEST(E1000_FCRTH
, 0x0000FFF8, 0x0000FFF8);
808 REG_PATTERN_TEST(E1000_FCTTV
, 0x0000FFFF, 0x0000FFFF);
809 REG_PATTERN_TEST(E1000_TIPG
, 0x3FFFFFFF, 0x3FFFFFFF);
810 REG_PATTERN_TEST(E1000_TDBAH
, 0xFFFFFFFF, 0xFFFFFFFF);
811 REG_PATTERN_TEST(E1000_TDLEN
, 0x000FFF80, 0x000FFFFF);
813 REG_SET_AND_CHECK(E1000_RCTL
, 0xFFFFFFFF, 0x00000000);
815 before
= (((mac
->type
== e1000_ich8lan
) ||
816 (mac
->type
== e1000_ich9lan
)) ? 0x06C3B33E : 0x06DFB3FE);
817 REG_SET_AND_CHECK(E1000_RCTL
, before
, 0x003FFFFB);
818 REG_SET_AND_CHECK(E1000_TCTL
, 0xFFFFFFFF, 0x00000000);
820 REG_SET_AND_CHECK(E1000_RCTL
, before
, 0xFFFFFFFF);
821 REG_PATTERN_TEST(E1000_RDBAL
, 0xFFFFFFF0, 0xFFFFFFFF);
822 if ((mac
->type
!= e1000_ich8lan
) &&
823 (mac
->type
!= e1000_ich9lan
))
824 REG_PATTERN_TEST(E1000_TXCW
, 0xC000FFFF, 0x0000FFFF);
825 REG_PATTERN_TEST(E1000_TDBAL
, 0xFFFFFFF0, 0xFFFFFFFF);
826 REG_PATTERN_TEST(E1000_TIDV
, 0x0000FFFF, 0x0000FFFF);
827 for (i
= 0; i
< mac
->rar_entry_count
; i
++)
828 REG_PATTERN_TEST_ARRAY(E1000_RA
, ((i
<< 1) + 1),
829 0x8003FFFF, 0xFFFFFFFF);
831 for (i
= 0; i
< mac
->mta_reg_count
; i
++)
832 REG_PATTERN_TEST_ARRAY(E1000_MTA
, i
, 0xFFFFFFFF, 0xFFFFFFFF);
838 static int e1000_eeprom_test(struct e1000_adapter
*adapter
, u64
*data
)
845 /* Read and add up the contents of the EEPROM */
846 for (i
= 0; i
< (NVM_CHECKSUM_REG
+ 1); i
++) {
847 if ((e1000_read_nvm(&adapter
->hw
, i
, 1, &temp
)) < 0) {
854 /* If Checksum is not Correct return error else test passed */
855 if ((checksum
!= (u16
) NVM_SUM
) && !(*data
))
861 static irqreturn_t
e1000_test_intr(int irq
, void *data
)
863 struct net_device
*netdev
= (struct net_device
*) data
;
864 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
865 struct e1000_hw
*hw
= &adapter
->hw
;
867 adapter
->test_icr
|= er32(ICR
);
872 static int e1000_intr_test(struct e1000_adapter
*adapter
, u64
*data
)
874 struct net_device
*netdev
= adapter
->netdev
;
875 struct e1000_hw
*hw
= &adapter
->hw
;
878 u32 irq
= adapter
->pdev
->irq
;
883 /* NOTE: we don't test MSI interrupts here, yet */
884 /* Hook up test interrupt handler just for this test */
885 if (!request_irq(irq
, &e1000_test_intr
, IRQF_PROBE_SHARED
, netdev
->name
,
888 } else if (request_irq(irq
, &e1000_test_intr
, IRQF_SHARED
,
889 netdev
->name
, netdev
)) {
893 ndev_info(netdev
, "testing %s interrupt\n",
894 (shared_int
? "shared" : "unshared"));
896 /* Disable all the interrupts */
897 ew32(IMC
, 0xFFFFFFFF);
900 /* Test each interrupt */
901 for (i
= 0; i
< 10; i
++) {
903 if (((adapter
->hw
.mac
.type
== e1000_ich8lan
) ||
904 (adapter
->hw
.mac
.type
== e1000_ich9lan
)) && i
== 8)
907 /* Interrupt to test */
911 /* Disable the interrupt to be reported in
912 * the cause register and then force the same
913 * interrupt and see if one gets posted. If
914 * an interrupt was posted to the bus, the
917 adapter
->test_icr
= 0;
922 if (adapter
->test_icr
& mask
) {
928 /* Enable the interrupt to be reported in
929 * the cause register and then force the same
930 * interrupt and see if one gets posted. If
931 * an interrupt was not posted to the bus, the
934 adapter
->test_icr
= 0;
939 if (!(adapter
->test_icr
& mask
)) {
945 /* Disable the other interrupts to be reported in
946 * the cause register and then force the other
947 * interrupts and see if any get posted. If
948 * an interrupt was posted to the bus, the
951 adapter
->test_icr
= 0;
952 ew32(IMC
, ~mask
& 0x00007FFF);
953 ew32(ICS
, ~mask
& 0x00007FFF);
956 if (adapter
->test_icr
) {
963 /* Disable all the interrupts */
964 ew32(IMC
, 0xFFFFFFFF);
967 /* Unhook test interrupt handler */
968 free_irq(irq
, netdev
);
973 static void e1000_free_desc_rings(struct e1000_adapter
*adapter
)
975 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
976 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
977 struct pci_dev
*pdev
= adapter
->pdev
;
980 if (tx_ring
->desc
&& tx_ring
->buffer_info
) {
981 for (i
= 0; i
< tx_ring
->count
; i
++) {
982 if (tx_ring
->buffer_info
[i
].dma
)
983 pci_unmap_single(pdev
,
984 tx_ring
->buffer_info
[i
].dma
,
985 tx_ring
->buffer_info
[i
].length
,
987 if (tx_ring
->buffer_info
[i
].skb
)
988 dev_kfree_skb(tx_ring
->buffer_info
[i
].skb
);
992 if (rx_ring
->desc
&& rx_ring
->buffer_info
) {
993 for (i
= 0; i
< rx_ring
->count
; i
++) {
994 if (rx_ring
->buffer_info
[i
].dma
)
995 pci_unmap_single(pdev
,
996 rx_ring
->buffer_info
[i
].dma
,
997 2048, PCI_DMA_FROMDEVICE
);
998 if (rx_ring
->buffer_info
[i
].skb
)
999 dev_kfree_skb(rx_ring
->buffer_info
[i
].skb
);
1003 if (tx_ring
->desc
) {
1004 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
1006 tx_ring
->desc
= NULL
;
1008 if (rx_ring
->desc
) {
1009 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
1011 rx_ring
->desc
= NULL
;
1014 kfree(tx_ring
->buffer_info
);
1015 tx_ring
->buffer_info
= NULL
;
1016 kfree(rx_ring
->buffer_info
);
1017 rx_ring
->buffer_info
= NULL
;
1020 static int e1000_setup_desc_rings(struct e1000_adapter
*adapter
)
1022 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1023 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1024 struct pci_dev
*pdev
= adapter
->pdev
;
1025 struct e1000_hw
*hw
= &adapter
->hw
;
1031 /* Setup Tx descriptor ring and Tx buffers */
1033 if (!tx_ring
->count
)
1034 tx_ring
->count
= E1000_DEFAULT_TXD
;
1036 size
= tx_ring
->count
* sizeof(struct e1000_buffer
);
1037 tx_ring
->buffer_info
= kmalloc(size
, GFP_KERNEL
);
1038 if (!tx_ring
->buffer_info
) {
1042 memset(tx_ring
->buffer_info
, 0, size
);
1044 tx_ring
->size
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
1045 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1046 tx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, tx_ring
->size
,
1047 &tx_ring
->dma
, GFP_KERNEL
);
1048 if (!tx_ring
->desc
) {
1052 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1053 tx_ring
->next_to_use
= 0;
1054 tx_ring
->next_to_clean
= 0;
1057 ((u64
) tx_ring
->dma
& 0x00000000FFFFFFFF));
1058 ew32(TDBAH
, ((u64
) tx_ring
->dma
>> 32));
1060 tx_ring
->count
* sizeof(struct e1000_tx_desc
));
1064 E1000_TCTL_PSP
| E1000_TCTL_EN
|
1065 E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
|
1066 E1000_COLLISION_DISTANCE
<< E1000_COLD_SHIFT
);
1068 for (i
= 0; i
< tx_ring
->count
; i
++) {
1069 struct e1000_tx_desc
*tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
1070 struct sk_buff
*skb
;
1071 unsigned int skb_size
= 1024;
1073 skb
= alloc_skb(skb_size
, GFP_KERNEL
);
1078 skb_put(skb
, skb_size
);
1079 tx_ring
->buffer_info
[i
].skb
= skb
;
1080 tx_ring
->buffer_info
[i
].length
= skb
->len
;
1081 tx_ring
->buffer_info
[i
].dma
=
1082 pci_map_single(pdev
, skb
->data
, skb
->len
,
1084 if (pci_dma_mapping_error(tx_ring
->buffer_info
[i
].dma
)) {
1088 tx_desc
->buffer_addr
= cpu_to_le64(
1089 tx_ring
->buffer_info
[i
].dma
);
1090 tx_desc
->lower
.data
= cpu_to_le32(skb
->len
);
1091 tx_desc
->lower
.data
|= cpu_to_le32(E1000_TXD_CMD_EOP
|
1092 E1000_TXD_CMD_IFCS
|
1094 tx_desc
->upper
.data
= 0;
1097 /* Setup Rx descriptor ring and Rx buffers */
1099 if (!rx_ring
->count
)
1100 rx_ring
->count
= E1000_DEFAULT_RXD
;
1102 size
= rx_ring
->count
* sizeof(struct e1000_buffer
);
1103 rx_ring
->buffer_info
= kmalloc(size
, GFP_KERNEL
);
1104 if (!rx_ring
->buffer_info
) {
1108 memset(rx_ring
->buffer_info
, 0, size
);
1110 rx_ring
->size
= rx_ring
->count
* sizeof(struct e1000_rx_desc
);
1111 rx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, rx_ring
->size
,
1112 &rx_ring
->dma
, GFP_KERNEL
);
1113 if (!rx_ring
->desc
) {
1117 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1118 rx_ring
->next_to_use
= 0;
1119 rx_ring
->next_to_clean
= 0;
1122 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1123 ew32(RDBAL
, ((u64
) rx_ring
->dma
& 0xFFFFFFFF));
1124 ew32(RDBAH
, ((u64
) rx_ring
->dma
>> 32));
1125 ew32(RDLEN
, rx_ring
->size
);
1128 rctl
= E1000_RCTL_EN
| E1000_RCTL_BAM
| E1000_RCTL_SZ_2048
|
1129 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1130 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1133 for (i
= 0; i
< rx_ring
->count
; i
++) {
1134 struct e1000_rx_desc
*rx_desc
= E1000_RX_DESC(*rx_ring
, i
);
1135 struct sk_buff
*skb
;
1137 skb
= alloc_skb(2048 + NET_IP_ALIGN
, GFP_KERNEL
);
1142 skb_reserve(skb
, NET_IP_ALIGN
);
1143 rx_ring
->buffer_info
[i
].skb
= skb
;
1144 rx_ring
->buffer_info
[i
].dma
=
1145 pci_map_single(pdev
, skb
->data
, 2048,
1146 PCI_DMA_FROMDEVICE
);
1147 if (pci_dma_mapping_error(rx_ring
->buffer_info
[i
].dma
)) {
1151 rx_desc
->buffer_addr
=
1152 cpu_to_le64(rx_ring
->buffer_info
[i
].dma
);
1153 memset(skb
->data
, 0x00, skb
->len
);
1159 e1000_free_desc_rings(adapter
);
1163 static void e1000_phy_disable_receiver(struct e1000_adapter
*adapter
)
1165 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1166 e1e_wphy(&adapter
->hw
, 29, 0x001F);
1167 e1e_wphy(&adapter
->hw
, 30, 0x8FFC);
1168 e1e_wphy(&adapter
->hw
, 29, 0x001A);
1169 e1e_wphy(&adapter
->hw
, 30, 0x8FF0);
1172 static int e1000_integrated_phy_loopback(struct e1000_adapter
*adapter
)
1174 struct e1000_hw
*hw
= &adapter
->hw
;
1178 adapter
->hw
.mac
.autoneg
= 0;
1180 if (adapter
->hw
.phy
.type
== e1000_phy_m88
) {
1181 /* Auto-MDI/MDIX Off */
1182 e1e_wphy(hw
, M88E1000_PHY_SPEC_CTRL
, 0x0808);
1183 /* reset to update Auto-MDI/MDIX */
1184 e1e_wphy(hw
, PHY_CONTROL
, 0x9140);
1186 e1e_wphy(hw
, PHY_CONTROL
, 0x8140);
1187 } else if (adapter
->hw
.phy
.type
== e1000_phy_gg82563
)
1188 e1e_wphy(hw
, GG82563_PHY_KMRN_MODE_CTRL
, 0x1CC);
1190 ctrl_reg
= er32(CTRL
);
1192 if (adapter
->hw
.phy
.type
== e1000_phy_ife
) {
1193 /* force 100, set loopback */
1194 e1e_wphy(hw
, PHY_CONTROL
, 0x6100);
1196 /* Now set up the MAC to the same speed/duplex as the PHY. */
1197 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1198 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1199 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1200 E1000_CTRL_SPD_100
|/* Force Speed to 100 */
1201 E1000_CTRL_FD
); /* Force Duplex to FULL */
1203 /* force 1000, set loopback */
1204 e1e_wphy(hw
, PHY_CONTROL
, 0x4140);
1206 /* Now set up the MAC to the same speed/duplex as the PHY. */
1207 ctrl_reg
= er32(CTRL
);
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_1000
|/* Force Speed to 1000 */
1212 E1000_CTRL_FD
); /* Force Duplex to FULL */
1215 if (adapter
->hw
.media_type
== e1000_media_type_copper
&&
1216 adapter
->hw
.phy
.type
== e1000_phy_m88
) {
1217 ctrl_reg
|= E1000_CTRL_ILOS
; /* Invert Loss of Signal */
1219 /* Set the ILOS bit on the fiber Nic if half duplex link is
1221 stat_reg
= er32(STATUS
);
1222 if ((stat_reg
& E1000_STATUS_FD
) == 0)
1223 ctrl_reg
|= (E1000_CTRL_ILOS
| E1000_CTRL_SLU
);
1226 ew32(CTRL
, ctrl_reg
);
1228 /* Disable the receiver on the PHY so when a cable is plugged in, the
1229 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1231 if (adapter
->hw
.phy
.type
== e1000_phy_m88
)
1232 e1000_phy_disable_receiver(adapter
);
1239 static int e1000_set_82571_fiber_loopback(struct e1000_adapter
*adapter
)
1241 struct e1000_hw
*hw
= &adapter
->hw
;
1242 u32 ctrl
= er32(CTRL
);
1245 /* special requirements for 82571/82572 fiber adapters */
1247 /* jump through hoops to make sure link is up because serdes
1248 * link is hardwired up */
1249 ctrl
|= E1000_CTRL_SLU
;
1252 /* disable autoneg */
1257 link
= (er32(STATUS
) & E1000_STATUS_LU
);
1260 /* set invert loss of signal */
1262 ctrl
|= E1000_CTRL_ILOS
;
1266 /* special write to serdes control register to enable SerDes analog
1268 #define E1000_SERDES_LB_ON 0x410
1269 ew32(SCTL
, E1000_SERDES_LB_ON
);
1275 /* only call this for fiber/serdes connections to es2lan */
1276 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter
*adapter
)
1278 struct e1000_hw
*hw
= &adapter
->hw
;
1279 u32 ctrlext
= er32(CTRL_EXT
);
1280 u32 ctrl
= er32(CTRL
);
1282 /* save CTRL_EXT to restore later, reuse an empty variable (unused
1283 on mac_type 80003es2lan) */
1284 adapter
->tx_fifo_head
= ctrlext
;
1286 /* clear the serdes mode bits, putting the device into mac loopback */
1287 ctrlext
&= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES
;
1288 ew32(CTRL_EXT
, ctrlext
);
1290 /* force speed to 1000/FD, link up */
1291 ctrl
&= ~(E1000_CTRL_SPD_1000
| E1000_CTRL_SPD_100
);
1292 ctrl
|= (E1000_CTRL_SLU
| E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
|
1293 E1000_CTRL_SPD_1000
| E1000_CTRL_FD
);
1296 /* set mac loopback */
1298 ctrl
|= E1000_RCTL_LBM_MAC
;
1301 /* set testing mode parameters (no need to reset later) */
1302 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
1303 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1305 (KMRNCTRLSTA_OPMODE
| KMRNCTRLSTA_OPMODE_1GB_FD_GMII
));
1310 static int e1000_setup_loopback_test(struct e1000_adapter
*adapter
)
1312 struct e1000_hw
*hw
= &adapter
->hw
;
1315 if (hw
->media_type
== e1000_media_type_fiber
||
1316 hw
->media_type
== e1000_media_type_internal_serdes
) {
1317 switch (hw
->mac
.type
) {
1318 case e1000_80003es2lan
:
1319 return e1000_set_es2lan_mac_loopback(adapter
);
1323 return e1000_set_82571_fiber_loopback(adapter
);
1327 rctl
|= E1000_RCTL_LBM_TCVR
;
1331 } else if (hw
->media_type
== e1000_media_type_copper
) {
1332 return e1000_integrated_phy_loopback(adapter
);
1338 static void e1000_loopback_cleanup(struct e1000_adapter
*adapter
)
1340 struct e1000_hw
*hw
= &adapter
->hw
;
1345 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
1348 switch (hw
->mac
.type
) {
1349 case e1000_80003es2lan
:
1350 if (hw
->media_type
== e1000_media_type_fiber
||
1351 hw
->media_type
== e1000_media_type_internal_serdes
) {
1352 /* restore CTRL_EXT, stealing space from tx_fifo_head */
1354 adapter
->tx_fifo_head
);
1355 adapter
->tx_fifo_head
= 0;
1360 if (hw
->media_type
== e1000_media_type_fiber
||
1361 hw
->media_type
== e1000_media_type_internal_serdes
) {
1362 #define E1000_SERDES_LB_OFF 0x400
1363 ew32(SCTL
, E1000_SERDES_LB_OFF
);
1369 hw
->mac
.autoneg
= 1;
1370 if (hw
->phy
.type
== e1000_phy_gg82563
)
1371 e1e_wphy(hw
, GG82563_PHY_KMRN_MODE_CTRL
, 0x180);
1372 e1e_rphy(hw
, PHY_CONTROL
, &phy_reg
);
1373 if (phy_reg
& MII_CR_LOOPBACK
) {
1374 phy_reg
&= ~MII_CR_LOOPBACK
;
1375 e1e_wphy(hw
, PHY_CONTROL
, phy_reg
);
1376 e1000e_commit_phy(hw
);
1382 static void e1000_create_lbtest_frame(struct sk_buff
*skb
,
1383 unsigned int frame_size
)
1385 memset(skb
->data
, 0xFF, frame_size
);
1387 memset(&skb
->data
[frame_size
/ 2], 0xAA, frame_size
/ 2 - 1);
1388 memset(&skb
->data
[frame_size
/ 2 + 10], 0xBE, 1);
1389 memset(&skb
->data
[frame_size
/ 2 + 12], 0xAF, 1);
1392 static int e1000_check_lbtest_frame(struct sk_buff
*skb
,
1393 unsigned int frame_size
)
1396 if (*(skb
->data
+ 3) == 0xFF)
1397 if ((*(skb
->data
+ frame_size
/ 2 + 10) == 0xBE) &&
1398 (*(skb
->data
+ frame_size
/ 2 + 12) == 0xAF))
1403 static int e1000_run_loopback_test(struct e1000_adapter
*adapter
)
1405 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1406 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1407 struct pci_dev
*pdev
= adapter
->pdev
;
1408 struct e1000_hw
*hw
= &adapter
->hw
;
1415 ew32(RDT
, rx_ring
->count
- 1);
1417 /* Calculate the loop count based on the largest descriptor ring
1418 * The idea is to wrap the largest ring a number of times using 64
1419 * send/receive pairs during each loop
1422 if (rx_ring
->count
<= tx_ring
->count
)
1423 lc
= ((tx_ring
->count
/ 64) * 2) + 1;
1425 lc
= ((rx_ring
->count
/ 64) * 2) + 1;
1429 for (j
= 0; j
<= lc
; j
++) { /* loop count loop */
1430 for (i
= 0; i
< 64; i
++) { /* send the packets */
1431 e1000_create_lbtest_frame(
1432 tx_ring
->buffer_info
[i
].skb
, 1024);
1433 pci_dma_sync_single_for_device(pdev
,
1434 tx_ring
->buffer_info
[k
].dma
,
1435 tx_ring
->buffer_info
[k
].length
,
1438 if (k
== tx_ring
->count
)
1443 time
= jiffies
; /* set the start time for the receive */
1445 do { /* receive the sent packets */
1446 pci_dma_sync_single_for_cpu(pdev
,
1447 rx_ring
->buffer_info
[l
].dma
, 2048,
1448 PCI_DMA_FROMDEVICE
);
1450 ret_val
= e1000_check_lbtest_frame(
1451 rx_ring
->buffer_info
[l
].skb
, 1024);
1455 if (l
== rx_ring
->count
)
1457 /* time + 20 msecs (200 msecs on 2.4) is more than
1458 * enough time to complete the receives, if it's
1459 * exceeded, break and error off
1461 } while ((good_cnt
< 64) && !time_after(jiffies
, time
+ 20));
1462 if (good_cnt
!= 64) {
1463 ret_val
= 13; /* ret_val is the same as mis-compare */
1466 if (jiffies
>= (time
+ 2)) {
1467 ret_val
= 14; /* error code for time out error */
1470 } /* end loop count loop */
1474 static int e1000_loopback_test(struct e1000_adapter
*adapter
, u64
*data
)
1476 /* PHY loopback cannot be performed if SoL/IDER
1477 * sessions are active */
1478 if (e1000_check_reset_block(&adapter
->hw
)) {
1479 ndev_err(adapter
->netdev
, "Cannot do PHY loopback test "
1480 "when SoL/IDER is active.\n");
1485 *data
= e1000_setup_desc_rings(adapter
);
1489 *data
= e1000_setup_loopback_test(adapter
);
1493 *data
= e1000_run_loopback_test(adapter
);
1494 e1000_loopback_cleanup(adapter
);
1497 e1000_free_desc_rings(adapter
);
1502 static int e1000_link_test(struct e1000_adapter
*adapter
, u64
*data
)
1504 struct e1000_hw
*hw
= &adapter
->hw
;
1507 if (hw
->media_type
== e1000_media_type_internal_serdes
) {
1509 hw
->mac
.serdes_has_link
= 0;
1511 /* On some blade server designs, link establishment
1512 * could take as long as 2-3 minutes */
1514 hw
->mac
.ops
.check_for_link(hw
);
1515 if (hw
->mac
.serdes_has_link
)
1518 } while (i
++ < 3750);
1522 hw
->mac
.ops
.check_for_link(hw
);
1523 if (hw
->mac
.autoneg
)
1526 if (!(er32(STATUS
) &
1533 static int e1000e_get_sset_count(struct net_device
*netdev
, int sset
)
1537 return E1000_TEST_LEN
;
1539 return E1000_STATS_LEN
;
1545 static void e1000_diag_test(struct net_device
*netdev
,
1546 struct ethtool_test
*eth_test
, u64
*data
)
1548 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1549 u16 autoneg_advertised
;
1550 u8 forced_speed_duplex
;
1552 bool if_running
= netif_running(netdev
);
1554 set_bit(__E1000_TESTING
, &adapter
->state
);
1555 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1558 /* save speed, duplex, autoneg settings */
1559 autoneg_advertised
= adapter
->hw
.phy
.autoneg_advertised
;
1560 forced_speed_duplex
= adapter
->hw
.mac
.forced_speed_duplex
;
1561 autoneg
= adapter
->hw
.mac
.autoneg
;
1563 ndev_info(netdev
, "offline testing starting\n");
1565 /* Link test performed before hardware reset so autoneg doesn't
1566 * interfere with test result */
1567 if (e1000_link_test(adapter
, &data
[4]))
1568 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1571 /* indicate we're in test mode */
1574 e1000e_reset(adapter
);
1576 if (e1000_reg_test(adapter
, &data
[0]))
1577 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1579 e1000e_reset(adapter
);
1580 if (e1000_eeprom_test(adapter
, &data
[1]))
1581 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1583 e1000e_reset(adapter
);
1584 if (e1000_intr_test(adapter
, &data
[2]))
1585 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1587 e1000e_reset(adapter
);
1588 /* make sure the phy is powered up */
1589 e1000e_power_up_phy(adapter
);
1590 if (e1000_loopback_test(adapter
, &data
[3]))
1591 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1593 /* restore speed, duplex, autoneg settings */
1594 adapter
->hw
.phy
.autoneg_advertised
= autoneg_advertised
;
1595 adapter
->hw
.mac
.forced_speed_duplex
= forced_speed_duplex
;
1596 adapter
->hw
.mac
.autoneg
= autoneg
;
1598 /* force this routine to wait until autoneg complete/timeout */
1599 adapter
->hw
.phy
.wait_for_link
= 1;
1600 e1000e_reset(adapter
);
1601 adapter
->hw
.phy
.wait_for_link
= 0;
1603 clear_bit(__E1000_TESTING
, &adapter
->state
);
1607 ndev_info(netdev
, "online testing starting\n");
1609 if (e1000_link_test(adapter
, &data
[4]))
1610 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1612 /* Online tests aren't run; pass by default */
1618 clear_bit(__E1000_TESTING
, &adapter
->state
);
1620 msleep_interruptible(4 * 1000);
1623 static void e1000_get_wol(struct net_device
*netdev
,
1624 struct ethtool_wolinfo
*wol
)
1626 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1631 if (!(adapter
->flags
& FLAG_HAS_WOL
))
1634 wol
->supported
= WAKE_UCAST
| WAKE_MCAST
|
1635 WAKE_BCAST
| WAKE_MAGIC
|
1636 WAKE_PHY
| WAKE_ARP
;
1638 /* apply any specific unsupported masks here */
1639 if (adapter
->flags
& FLAG_NO_WAKE_UCAST
) {
1640 wol
->supported
&= ~WAKE_UCAST
;
1642 if (adapter
->wol
& E1000_WUFC_EX
)
1643 ndev_err(netdev
, "Interface does not support "
1644 "directed (unicast) frame wake-up packets\n");
1647 if (adapter
->wol
& E1000_WUFC_EX
)
1648 wol
->wolopts
|= WAKE_UCAST
;
1649 if (adapter
->wol
& E1000_WUFC_MC
)
1650 wol
->wolopts
|= WAKE_MCAST
;
1651 if (adapter
->wol
& E1000_WUFC_BC
)
1652 wol
->wolopts
|= WAKE_BCAST
;
1653 if (adapter
->wol
& E1000_WUFC_MAG
)
1654 wol
->wolopts
|= WAKE_MAGIC
;
1655 if (adapter
->wol
& E1000_WUFC_LNKC
)
1656 wol
->wolopts
|= WAKE_PHY
;
1657 if (adapter
->wol
& E1000_WUFC_ARP
)
1658 wol
->wolopts
|= WAKE_ARP
;
1661 static int e1000_set_wol(struct net_device
*netdev
,
1662 struct ethtool_wolinfo
*wol
)
1664 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1666 if (wol
->wolopts
& WAKE_MAGICSECURE
)
1669 if (!(adapter
->flags
& FLAG_HAS_WOL
))
1670 return wol
->wolopts
? -EOPNOTSUPP
: 0;
1672 /* these settings will always override what we currently have */
1675 if (wol
->wolopts
& WAKE_UCAST
)
1676 adapter
->wol
|= E1000_WUFC_EX
;
1677 if (wol
->wolopts
& WAKE_MCAST
)
1678 adapter
->wol
|= E1000_WUFC_MC
;
1679 if (wol
->wolopts
& WAKE_BCAST
)
1680 adapter
->wol
|= E1000_WUFC_BC
;
1681 if (wol
->wolopts
& WAKE_MAGIC
)
1682 adapter
->wol
|= E1000_WUFC_MAG
;
1683 if (wol
->wolopts
& WAKE_PHY
)
1684 adapter
->wol
|= E1000_WUFC_LNKC
;
1685 if (wol
->wolopts
& WAKE_ARP
)
1686 adapter
->wol
|= E1000_WUFC_ARP
;
1691 /* toggle LED 4 times per second = 2 "blinks" per second */
1692 #define E1000_ID_INTERVAL (HZ/4)
1694 /* bit defines for adapter->led_status */
1695 #define E1000_LED_ON 0
1697 static void e1000_led_blink_callback(unsigned long data
)
1699 struct e1000_adapter
*adapter
= (struct e1000_adapter
*) data
;
1701 if (test_and_change_bit(E1000_LED_ON
, &adapter
->led_status
))
1702 adapter
->hw
.mac
.ops
.led_off(&adapter
->hw
);
1704 adapter
->hw
.mac
.ops
.led_on(&adapter
->hw
);
1706 mod_timer(&adapter
->blink_timer
, jiffies
+ E1000_ID_INTERVAL
);
1709 static int e1000_phys_id(struct net_device
*netdev
, u32 data
)
1711 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1716 if (adapter
->hw
.phy
.type
== e1000_phy_ife
) {
1717 if (!adapter
->blink_timer
.function
) {
1718 init_timer(&adapter
->blink_timer
);
1719 adapter
->blink_timer
.function
=
1720 e1000_led_blink_callback
;
1721 adapter
->blink_timer
.data
= (unsigned long) adapter
;
1723 mod_timer(&adapter
->blink_timer
, jiffies
);
1724 msleep_interruptible(data
* 1000);
1725 del_timer_sync(&adapter
->blink_timer
);
1726 e1e_wphy(&adapter
->hw
,
1727 IFE_PHY_SPECIAL_CONTROL_LED
, 0);
1729 e1000e_blink_led(&adapter
->hw
);
1730 msleep_interruptible(data
* 1000);
1733 adapter
->hw
.mac
.ops
.led_off(&adapter
->hw
);
1734 clear_bit(E1000_LED_ON
, &adapter
->led_status
);
1735 adapter
->hw
.mac
.ops
.cleanup_led(&adapter
->hw
);
1740 static int e1000_nway_reset(struct net_device
*netdev
)
1742 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1743 if (netif_running(netdev
))
1744 e1000e_reinit_locked(adapter
);
1748 static void e1000_get_ethtool_stats(struct net_device
*netdev
,
1749 struct ethtool_stats
*stats
,
1752 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1755 e1000e_update_stats(adapter
);
1756 for (i
= 0; i
< E1000_GLOBAL_STATS_LEN
; i
++) {
1757 char *p
= (char *)adapter
+e1000_gstrings_stats
[i
].stat_offset
;
1758 data
[i
] = (e1000_gstrings_stats
[i
].sizeof_stat
==
1759 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1763 static void e1000_get_strings(struct net_device
*netdev
, u32 stringset
,
1769 switch (stringset
) {
1771 memcpy(data
, *e1000_gstrings_test
,
1772 sizeof(e1000_gstrings_test
));
1775 for (i
= 0; i
< E1000_GLOBAL_STATS_LEN
; i
++) {
1776 memcpy(p
, e1000_gstrings_stats
[i
].stat_string
,
1778 p
+= ETH_GSTRING_LEN
;
1784 static const struct ethtool_ops e1000_ethtool_ops
= {
1785 .get_settings
= e1000_get_settings
,
1786 .set_settings
= e1000_set_settings
,
1787 .get_drvinfo
= e1000_get_drvinfo
,
1788 .get_regs_len
= e1000_get_regs_len
,
1789 .get_regs
= e1000_get_regs
,
1790 .get_wol
= e1000_get_wol
,
1791 .set_wol
= e1000_set_wol
,
1792 .get_msglevel
= e1000_get_msglevel
,
1793 .set_msglevel
= e1000_set_msglevel
,
1794 .nway_reset
= e1000_nway_reset
,
1795 .get_link
= e1000_get_link
,
1796 .get_eeprom_len
= e1000_get_eeprom_len
,
1797 .get_eeprom
= e1000_get_eeprom
,
1798 .set_eeprom
= e1000_set_eeprom
,
1799 .get_ringparam
= e1000_get_ringparam
,
1800 .set_ringparam
= e1000_set_ringparam
,
1801 .get_pauseparam
= e1000_get_pauseparam
,
1802 .set_pauseparam
= e1000_set_pauseparam
,
1803 .get_rx_csum
= e1000_get_rx_csum
,
1804 .set_rx_csum
= e1000_set_rx_csum
,
1805 .get_tx_csum
= e1000_get_tx_csum
,
1806 .set_tx_csum
= e1000_set_tx_csum
,
1807 .get_sg
= ethtool_op_get_sg
,
1808 .set_sg
= ethtool_op_set_sg
,
1809 .get_tso
= ethtool_op_get_tso
,
1810 .set_tso
= e1000_set_tso
,
1811 .self_test
= e1000_diag_test
,
1812 .get_strings
= e1000_get_strings
,
1813 .phys_id
= e1000_phys_id
,
1814 .get_ethtool_stats
= e1000_get_ethtool_stats
,
1815 .get_sset_count
= e1000e_get_sset_count
,
1818 void e1000e_set_ethtool_ops(struct net_device
*netdev
)
1820 SET_ETHTOOL_OPS(netdev
, &e1000_ethtool_ops
);