1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2011 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/interrupt.h>
33 #include <linux/ethtool.h>
34 #include <linux/pci.h>
35 #include <linux/slab.h>
36 #include <linux/delay.h>
40 enum {NETDEV_STATS
, E1000_STATS
};
43 char stat_string
[ETH_GSTRING_LEN
];
49 #define E1000_STAT(str, m) { \
51 .type = E1000_STATS, \
52 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
53 .stat_offset = offsetof(struct e1000_adapter, m) }
54 #define E1000_NETDEV_STAT(str, m) { \
56 .type = NETDEV_STATS, \
57 .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
58 .stat_offset = offsetof(struct rtnl_link_stats64, m) }
60 static const struct e1000_stats e1000_gstrings_stats
[] = {
61 E1000_STAT("rx_packets", stats
.gprc
),
62 E1000_STAT("tx_packets", stats
.gptc
),
63 E1000_STAT("rx_bytes", stats
.gorc
),
64 E1000_STAT("tx_bytes", stats
.gotc
),
65 E1000_STAT("rx_broadcast", stats
.bprc
),
66 E1000_STAT("tx_broadcast", stats
.bptc
),
67 E1000_STAT("rx_multicast", stats
.mprc
),
68 E1000_STAT("tx_multicast", stats
.mptc
),
69 E1000_NETDEV_STAT("rx_errors", rx_errors
),
70 E1000_NETDEV_STAT("tx_errors", tx_errors
),
71 E1000_NETDEV_STAT("tx_dropped", tx_dropped
),
72 E1000_STAT("multicast", stats
.mprc
),
73 E1000_STAT("collisions", stats
.colc
),
74 E1000_NETDEV_STAT("rx_length_errors", rx_length_errors
),
75 E1000_NETDEV_STAT("rx_over_errors", rx_over_errors
),
76 E1000_STAT("rx_crc_errors", stats
.crcerrs
),
77 E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors
),
78 E1000_STAT("rx_no_buffer_count", stats
.rnbc
),
79 E1000_STAT("rx_missed_errors", stats
.mpc
),
80 E1000_STAT("tx_aborted_errors", stats
.ecol
),
81 E1000_STAT("tx_carrier_errors", stats
.tncrs
),
82 E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors
),
83 E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors
),
84 E1000_STAT("tx_window_errors", stats
.latecol
),
85 E1000_STAT("tx_abort_late_coll", stats
.latecol
),
86 E1000_STAT("tx_deferred_ok", stats
.dc
),
87 E1000_STAT("tx_single_coll_ok", stats
.scc
),
88 E1000_STAT("tx_multi_coll_ok", stats
.mcc
),
89 E1000_STAT("tx_timeout_count", tx_timeout_count
),
90 E1000_STAT("tx_restart_queue", restart_queue
),
91 E1000_STAT("rx_long_length_errors", stats
.roc
),
92 E1000_STAT("rx_short_length_errors", stats
.ruc
),
93 E1000_STAT("rx_align_errors", stats
.algnerrc
),
94 E1000_STAT("tx_tcp_seg_good", stats
.tsctc
),
95 E1000_STAT("tx_tcp_seg_failed", stats
.tsctfc
),
96 E1000_STAT("rx_flow_control_xon", stats
.xonrxc
),
97 E1000_STAT("rx_flow_control_xoff", stats
.xoffrxc
),
98 E1000_STAT("tx_flow_control_xon", stats
.xontxc
),
99 E1000_STAT("tx_flow_control_xoff", stats
.xofftxc
),
100 E1000_STAT("rx_long_byte_count", stats
.gorc
),
101 E1000_STAT("rx_csum_offload_good", hw_csum_good
),
102 E1000_STAT("rx_csum_offload_errors", hw_csum_err
),
103 E1000_STAT("rx_header_split", rx_hdr_split
),
104 E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed
),
105 E1000_STAT("tx_smbus", stats
.mgptc
),
106 E1000_STAT("rx_smbus", stats
.mgprc
),
107 E1000_STAT("dropped_smbus", stats
.mgpdc
),
108 E1000_STAT("rx_dma_failed", rx_dma_failed
),
109 E1000_STAT("tx_dma_failed", tx_dma_failed
),
112 #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
113 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
114 static const char e1000_gstrings_test
[][ETH_GSTRING_LEN
] = {
115 "Register test (offline)", "Eeprom test (offline)",
116 "Interrupt test (offline)", "Loopback test (offline)",
117 "Link test (on/offline)"
119 #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
121 static int e1000_get_settings(struct net_device
*netdev
,
122 struct ethtool_cmd
*ecmd
)
124 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
125 struct e1000_hw
*hw
= &adapter
->hw
;
128 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
130 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
131 SUPPORTED_10baseT_Full
|
132 SUPPORTED_100baseT_Half
|
133 SUPPORTED_100baseT_Full
|
134 SUPPORTED_1000baseT_Full
|
137 if (hw
->phy
.type
== e1000_phy_ife
)
138 ecmd
->supported
&= ~SUPPORTED_1000baseT_Full
;
139 ecmd
->advertising
= ADVERTISED_TP
;
141 if (hw
->mac
.autoneg
== 1) {
142 ecmd
->advertising
|= ADVERTISED_Autoneg
;
143 /* the e1000 autoneg seems to match ethtool nicely */
144 ecmd
->advertising
|= hw
->phy
.autoneg_advertised
;
147 ecmd
->port
= PORT_TP
;
148 ecmd
->phy_address
= hw
->phy
.addr
;
149 ecmd
->transceiver
= XCVR_INTERNAL
;
152 ecmd
->supported
= (SUPPORTED_1000baseT_Full
|
156 ecmd
->advertising
= (ADVERTISED_1000baseT_Full
|
160 ecmd
->port
= PORT_FIBRE
;
161 ecmd
->transceiver
= XCVR_EXTERNAL
;
167 if (netif_running(netdev
)) {
168 if (netif_carrier_ok(netdev
)) {
169 speed
= adapter
->link_speed
;
170 ecmd
->duplex
= adapter
->link_duplex
- 1;
173 u32 status
= er32(STATUS
);
174 if (status
& E1000_STATUS_LU
) {
175 if (status
& E1000_STATUS_SPEED_1000
)
177 else if (status
& E1000_STATUS_SPEED_100
)
182 if (status
& E1000_STATUS_FD
)
183 ecmd
->duplex
= DUPLEX_FULL
;
185 ecmd
->duplex
= DUPLEX_HALF
;
189 ethtool_cmd_speed_set(ecmd
, speed
);
190 ecmd
->autoneg
= ((hw
->phy
.media_type
== e1000_media_type_fiber
) ||
191 hw
->mac
.autoneg
) ? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
193 /* MDI-X => 2; MDI =>1; Invalid =>0 */
194 if ((hw
->phy
.media_type
== e1000_media_type_copper
) &&
195 netif_carrier_ok(netdev
))
196 ecmd
->eth_tp_mdix
= hw
->phy
.is_mdix
? ETH_TP_MDI_X
:
199 ecmd
->eth_tp_mdix
= ETH_TP_MDI_INVALID
;
204 static int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, u32 spd
, u8 dplx
)
206 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
210 /* Make sure dplx is at most 1 bit and lsb of speed is not set
211 * for the switch() below to work */
212 if ((spd
& 1) || (dplx
& ~1))
215 /* Fiber NICs only allow 1000 gbps Full duplex */
216 if ((adapter
->hw
.phy
.media_type
== e1000_media_type_fiber
) &&
218 dplx
!= DUPLEX_FULL
) {
222 switch (spd
+ dplx
) {
223 case SPEED_10
+ DUPLEX_HALF
:
224 mac
->forced_speed_duplex
= ADVERTISE_10_HALF
;
226 case SPEED_10
+ DUPLEX_FULL
:
227 mac
->forced_speed_duplex
= ADVERTISE_10_FULL
;
229 case SPEED_100
+ DUPLEX_HALF
:
230 mac
->forced_speed_duplex
= ADVERTISE_100_HALF
;
232 case SPEED_100
+ DUPLEX_FULL
:
233 mac
->forced_speed_duplex
= ADVERTISE_100_FULL
;
235 case SPEED_1000
+ DUPLEX_FULL
:
237 adapter
->hw
.phy
.autoneg_advertised
= ADVERTISE_1000_FULL
;
239 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
246 e_err("Unsupported Speed/Duplex configuration\n");
250 static int e1000_set_settings(struct net_device
*netdev
,
251 struct ethtool_cmd
*ecmd
)
253 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
254 struct e1000_hw
*hw
= &adapter
->hw
;
257 * When SoL/IDER sessions are active, autoneg/speed/duplex
260 if (e1000_check_reset_block(hw
)) {
261 e_err("Cannot change link characteristics when SoL/IDER is "
266 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
267 usleep_range(1000, 2000);
269 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
271 if (hw
->phy
.media_type
== e1000_media_type_fiber
)
272 hw
->phy
.autoneg_advertised
= ADVERTISED_1000baseT_Full
|
276 hw
->phy
.autoneg_advertised
= ecmd
->advertising
|
279 ecmd
->advertising
= hw
->phy
.autoneg_advertised
;
280 if (adapter
->fc_autoneg
)
281 hw
->fc
.requested_mode
= e1000_fc_default
;
283 u32 speed
= ethtool_cmd_speed(ecmd
);
284 if (e1000_set_spd_dplx(adapter
, speed
, ecmd
->duplex
)) {
285 clear_bit(__E1000_RESETTING
, &adapter
->state
);
292 if (netif_running(adapter
->netdev
)) {
293 e1000e_down(adapter
);
296 e1000e_reset(adapter
);
299 clear_bit(__E1000_RESETTING
, &adapter
->state
);
303 static void e1000_get_pauseparam(struct net_device
*netdev
,
304 struct ethtool_pauseparam
*pause
)
306 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
307 struct e1000_hw
*hw
= &adapter
->hw
;
310 (adapter
->fc_autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
);
312 if (hw
->fc
.current_mode
== e1000_fc_rx_pause
) {
314 } else if (hw
->fc
.current_mode
== e1000_fc_tx_pause
) {
316 } else if (hw
->fc
.current_mode
== e1000_fc_full
) {
322 static int e1000_set_pauseparam(struct net_device
*netdev
,
323 struct ethtool_pauseparam
*pause
)
325 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
326 struct e1000_hw
*hw
= &adapter
->hw
;
329 adapter
->fc_autoneg
= pause
->autoneg
;
331 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
332 usleep_range(1000, 2000);
334 if (adapter
->fc_autoneg
== AUTONEG_ENABLE
) {
335 hw
->fc
.requested_mode
= e1000_fc_default
;
336 if (netif_running(adapter
->netdev
)) {
337 e1000e_down(adapter
);
340 e1000e_reset(adapter
);
343 if (pause
->rx_pause
&& pause
->tx_pause
)
344 hw
->fc
.requested_mode
= e1000_fc_full
;
345 else if (pause
->rx_pause
&& !pause
->tx_pause
)
346 hw
->fc
.requested_mode
= e1000_fc_rx_pause
;
347 else if (!pause
->rx_pause
&& pause
->tx_pause
)
348 hw
->fc
.requested_mode
= e1000_fc_tx_pause
;
349 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
350 hw
->fc
.requested_mode
= e1000_fc_none
;
352 hw
->fc
.current_mode
= hw
->fc
.requested_mode
;
354 if (hw
->phy
.media_type
== e1000_media_type_fiber
) {
355 retval
= hw
->mac
.ops
.setup_link(hw
);
356 /* implicit goto out */
358 retval
= e1000e_force_mac_fc(hw
);
361 e1000e_set_fc_watermarks(hw
);
366 clear_bit(__E1000_RESETTING
, &adapter
->state
);
370 static u32
e1000_get_msglevel(struct net_device
*netdev
)
372 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
373 return adapter
->msg_enable
;
376 static void e1000_set_msglevel(struct net_device
*netdev
, u32 data
)
378 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
379 adapter
->msg_enable
= data
;
382 static int e1000_get_regs_len(struct net_device
*netdev
)
384 #define E1000_REGS_LEN 32 /* overestimate */
385 return E1000_REGS_LEN
* sizeof(u32
);
388 static void e1000_get_regs(struct net_device
*netdev
,
389 struct ethtool_regs
*regs
, void *p
)
391 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
392 struct e1000_hw
*hw
= &adapter
->hw
;
396 memset(p
, 0, E1000_REGS_LEN
* sizeof(u32
));
398 regs
->version
= (1 << 24) | (adapter
->pdev
->revision
<< 16) |
399 adapter
->pdev
->device
;
401 regs_buff
[0] = er32(CTRL
);
402 regs_buff
[1] = er32(STATUS
);
404 regs_buff
[2] = er32(RCTL
);
405 regs_buff
[3] = er32(RDLEN
);
406 regs_buff
[4] = er32(RDH
);
407 regs_buff
[5] = er32(RDT
);
408 regs_buff
[6] = er32(RDTR
);
410 regs_buff
[7] = er32(TCTL
);
411 regs_buff
[8] = er32(TDLEN
);
412 regs_buff
[9] = er32(TDH
);
413 regs_buff
[10] = er32(TDT
);
414 regs_buff
[11] = er32(TIDV
);
416 regs_buff
[12] = adapter
->hw
.phy
.type
; /* PHY type (IGP=1, M88=0) */
418 /* ethtool doesn't use anything past this point, so all this
419 * code is likely legacy junk for apps that may or may not
421 if (hw
->phy
.type
== e1000_phy_m88
) {
422 e1e_rphy(hw
, M88E1000_PHY_SPEC_STATUS
, &phy_data
);
423 regs_buff
[13] = (u32
)phy_data
; /* cable length */
424 regs_buff
[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
425 regs_buff
[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
426 regs_buff
[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
427 e1e_rphy(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
428 regs_buff
[17] = (u32
)phy_data
; /* extended 10bt distance */
429 regs_buff
[18] = regs_buff
[13]; /* cable polarity */
430 regs_buff
[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
431 regs_buff
[20] = regs_buff
[17]; /* polarity correction */
432 /* phy receive errors */
433 regs_buff
[22] = adapter
->phy_stats
.receive_errors
;
434 regs_buff
[23] = regs_buff
[13]; /* mdix mode */
436 regs_buff
[21] = 0; /* was idle_errors */
437 e1e_rphy(hw
, PHY_1000T_STATUS
, &phy_data
);
438 regs_buff
[24] = (u32
)phy_data
; /* phy local receiver status */
439 regs_buff
[25] = regs_buff
[24]; /* phy remote receiver status */
442 static int e1000_get_eeprom_len(struct net_device
*netdev
)
444 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
445 return adapter
->hw
.nvm
.word_size
* 2;
448 static int e1000_get_eeprom(struct net_device
*netdev
,
449 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
451 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
452 struct e1000_hw
*hw
= &adapter
->hw
;
459 if (eeprom
->len
== 0)
462 eeprom
->magic
= adapter
->pdev
->vendor
| (adapter
->pdev
->device
<< 16);
464 first_word
= eeprom
->offset
>> 1;
465 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
467 eeprom_buff
= kmalloc(sizeof(u16
) *
468 (last_word
- first_word
+ 1), GFP_KERNEL
);
472 if (hw
->nvm
.type
== e1000_nvm_eeprom_spi
) {
473 ret_val
= e1000_read_nvm(hw
, first_word
,
474 last_word
- first_word
+ 1,
477 for (i
= 0; i
< last_word
- first_word
+ 1; i
++) {
478 ret_val
= e1000_read_nvm(hw
, first_word
+ i
, 1,
486 /* a read error occurred, throw away the result */
487 memset(eeprom_buff
, 0xff, sizeof(u16
) *
488 (last_word
- first_word
+ 1));
490 /* Device's eeprom is always little-endian, word addressable */
491 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
492 le16_to_cpus(&eeprom_buff
[i
]);
495 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 1), eeprom
->len
);
501 static int e1000_set_eeprom(struct net_device
*netdev
,
502 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
504 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
505 struct e1000_hw
*hw
= &adapter
->hw
;
514 if (eeprom
->len
== 0)
517 if (eeprom
->magic
!= (adapter
->pdev
->vendor
| (adapter
->pdev
->device
<< 16)))
520 if (adapter
->flags
& FLAG_READ_ONLY_NVM
)
523 max_len
= hw
->nvm
.word_size
* 2;
525 first_word
= eeprom
->offset
>> 1;
526 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
527 eeprom_buff
= kmalloc(max_len
, GFP_KERNEL
);
531 ptr
= (void *)eeprom_buff
;
533 if (eeprom
->offset
& 1) {
534 /* need read/modify/write of first changed EEPROM word */
535 /* only the second byte of the word is being modified */
536 ret_val
= e1000_read_nvm(hw
, first_word
, 1, &eeprom_buff
[0]);
539 if (((eeprom
->offset
+ eeprom
->len
) & 1) && (ret_val
== 0))
540 /* need read/modify/write of last changed EEPROM word */
541 /* only the first byte of the word is being modified */
542 ret_val
= e1000_read_nvm(hw
, last_word
, 1,
543 &eeprom_buff
[last_word
- first_word
]);
548 /* Device's eeprom is always little-endian, word addressable */
549 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
550 le16_to_cpus(&eeprom_buff
[i
]);
552 memcpy(ptr
, bytes
, eeprom
->len
);
554 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
555 eeprom_buff
[i
] = cpu_to_le16(eeprom_buff
[i
]);
557 ret_val
= e1000_write_nvm(hw
, first_word
,
558 last_word
- first_word
+ 1, eeprom_buff
);
564 * Update the checksum over the first part of the EEPROM if needed
565 * and flush shadow RAM for applicable controllers
567 if ((first_word
<= NVM_CHECKSUM_REG
) ||
568 (hw
->mac
.type
== e1000_82583
) ||
569 (hw
->mac
.type
== e1000_82574
) ||
570 (hw
->mac
.type
== e1000_82573
))
571 ret_val
= e1000e_update_nvm_checksum(hw
);
578 static void e1000_get_drvinfo(struct net_device
*netdev
,
579 struct ethtool_drvinfo
*drvinfo
)
581 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
582 char firmware_version
[32];
584 strncpy(drvinfo
->driver
, e1000e_driver_name
,
585 sizeof(drvinfo
->driver
) - 1);
586 strncpy(drvinfo
->version
, e1000e_driver_version
,
587 sizeof(drvinfo
->version
) - 1);
590 * EEPROM image version # is reported as firmware version # for
593 snprintf(firmware_version
, sizeof(firmware_version
), "%d.%d-%d",
594 (adapter
->eeprom_vers
& 0xF000) >> 12,
595 (adapter
->eeprom_vers
& 0x0FF0) >> 4,
596 (adapter
->eeprom_vers
& 0x000F));
598 strncpy(drvinfo
->fw_version
, firmware_version
,
599 sizeof(drvinfo
->fw_version
) - 1);
600 strncpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
601 sizeof(drvinfo
->bus_info
) - 1);
602 drvinfo
->regdump_len
= e1000_get_regs_len(netdev
);
603 drvinfo
->eedump_len
= e1000_get_eeprom_len(netdev
);
606 static void e1000_get_ringparam(struct net_device
*netdev
,
607 struct ethtool_ringparam
*ring
)
609 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
610 struct e1000_ring
*tx_ring
= adapter
->tx_ring
;
611 struct e1000_ring
*rx_ring
= adapter
->rx_ring
;
613 ring
->rx_max_pending
= E1000_MAX_RXD
;
614 ring
->tx_max_pending
= E1000_MAX_TXD
;
615 ring
->rx_pending
= rx_ring
->count
;
616 ring
->tx_pending
= tx_ring
->count
;
619 static int e1000_set_ringparam(struct net_device
*netdev
,
620 struct ethtool_ringparam
*ring
)
622 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
623 struct e1000_ring
*tx_ring
, *tx_old
;
624 struct e1000_ring
*rx_ring
, *rx_old
;
627 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
630 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
631 usleep_range(1000, 2000);
633 if (netif_running(adapter
->netdev
))
634 e1000e_down(adapter
);
636 tx_old
= adapter
->tx_ring
;
637 rx_old
= adapter
->rx_ring
;
640 tx_ring
= kmemdup(tx_old
, sizeof(struct e1000_ring
), GFP_KERNEL
);
644 rx_ring
= kmemdup(rx_old
, sizeof(struct e1000_ring
), GFP_KERNEL
);
648 adapter
->tx_ring
= tx_ring
;
649 adapter
->rx_ring
= rx_ring
;
651 rx_ring
->count
= max(ring
->rx_pending
, (u32
)E1000_MIN_RXD
);
652 rx_ring
->count
= min(rx_ring
->count
, (u32
)(E1000_MAX_RXD
));
653 rx_ring
->count
= ALIGN(rx_ring
->count
, REQ_RX_DESCRIPTOR_MULTIPLE
);
655 tx_ring
->count
= max(ring
->tx_pending
, (u32
)E1000_MIN_TXD
);
656 tx_ring
->count
= min(tx_ring
->count
, (u32
)(E1000_MAX_TXD
));
657 tx_ring
->count
= ALIGN(tx_ring
->count
, REQ_TX_DESCRIPTOR_MULTIPLE
);
659 if (netif_running(adapter
->netdev
)) {
660 /* Try to get new resources before deleting old */
661 err
= e1000e_setup_rx_resources(adapter
);
664 err
= e1000e_setup_tx_resources(adapter
);
669 * restore the old in order to free it,
670 * then add in the new
672 adapter
->rx_ring
= rx_old
;
673 adapter
->tx_ring
= tx_old
;
674 e1000e_free_rx_resources(adapter
);
675 e1000e_free_tx_resources(adapter
);
678 adapter
->rx_ring
= rx_ring
;
679 adapter
->tx_ring
= tx_ring
;
680 err
= e1000e_up(adapter
);
685 clear_bit(__E1000_RESETTING
, &adapter
->state
);
688 e1000e_free_rx_resources(adapter
);
690 adapter
->rx_ring
= rx_old
;
691 adapter
->tx_ring
= tx_old
;
698 clear_bit(__E1000_RESETTING
, &adapter
->state
);
702 static bool reg_pattern_test(struct e1000_adapter
*adapter
, u64
*data
,
703 int reg
, int offset
, u32 mask
, u32 write
)
706 static const u32 test
[] = {
707 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
708 for (pat
= 0; pat
< ARRAY_SIZE(test
); pat
++) {
709 E1000_WRITE_REG_ARRAY(&adapter
->hw
, reg
, offset
,
710 (test
[pat
] & write
));
711 val
= E1000_READ_REG_ARRAY(&adapter
->hw
, reg
, offset
);
712 if (val
!= (test
[pat
] & write
& mask
)) {
713 e_err("pattern test reg %04X failed: got 0x%08X "
714 "expected 0x%08X\n", reg
+ offset
, val
,
715 (test
[pat
] & write
& mask
));
723 static bool reg_set_and_check(struct e1000_adapter
*adapter
, u64
*data
,
724 int reg
, u32 mask
, u32 write
)
727 __ew32(&adapter
->hw
, reg
, write
& mask
);
728 val
= __er32(&adapter
->hw
, reg
);
729 if ((write
& mask
) != (val
& mask
)) {
730 e_err("set/check reg %04X test failed: got 0x%08X "
731 "expected 0x%08X\n", reg
, (val
& mask
), (write
& mask
));
737 #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
739 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
742 #define REG_PATTERN_TEST(reg, mask, write) \
743 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
745 #define REG_SET_AND_CHECK(reg, mask, write) \
747 if (reg_set_and_check(adapter, data, reg, mask, write)) \
751 static int e1000_reg_test(struct e1000_adapter
*adapter
, u64
*data
)
753 struct e1000_hw
*hw
= &adapter
->hw
;
754 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
763 * The status register is Read Only, so a write should fail.
764 * Some bits that get toggled are ignored.
767 /* there are several bits on newer hardware that are r/w */
770 case e1000_80003es2lan
:
778 before
= er32(STATUS
);
779 value
= (er32(STATUS
) & toggle
);
780 ew32(STATUS
, toggle
);
781 after
= er32(STATUS
) & toggle
;
782 if (value
!= after
) {
783 e_err("failed STATUS register test got: 0x%08X expected: "
784 "0x%08X\n", after
, value
);
788 /* restore previous status */
789 ew32(STATUS
, before
);
791 if (!(adapter
->flags
& FLAG_IS_ICH
)) {
792 REG_PATTERN_TEST(E1000_FCAL
, 0xFFFFFFFF, 0xFFFFFFFF);
793 REG_PATTERN_TEST(E1000_FCAH
, 0x0000FFFF, 0xFFFFFFFF);
794 REG_PATTERN_TEST(E1000_FCT
, 0x0000FFFF, 0xFFFFFFFF);
795 REG_PATTERN_TEST(E1000_VET
, 0x0000FFFF, 0xFFFFFFFF);
798 REG_PATTERN_TEST(E1000_RDTR
, 0x0000FFFF, 0xFFFFFFFF);
799 REG_PATTERN_TEST(E1000_RDBAH
, 0xFFFFFFFF, 0xFFFFFFFF);
800 REG_PATTERN_TEST(E1000_RDLEN
, 0x000FFF80, 0x000FFFFF);
801 REG_PATTERN_TEST(E1000_RDH
, 0x0000FFFF, 0x0000FFFF);
802 REG_PATTERN_TEST(E1000_RDT
, 0x0000FFFF, 0x0000FFFF);
803 REG_PATTERN_TEST(E1000_FCRTH
, 0x0000FFF8, 0x0000FFF8);
804 REG_PATTERN_TEST(E1000_FCTTV
, 0x0000FFFF, 0x0000FFFF);
805 REG_PATTERN_TEST(E1000_TIPG
, 0x3FFFFFFF, 0x3FFFFFFF);
806 REG_PATTERN_TEST(E1000_TDBAH
, 0xFFFFFFFF, 0xFFFFFFFF);
807 REG_PATTERN_TEST(E1000_TDLEN
, 0x000FFF80, 0x000FFFFF);
809 REG_SET_AND_CHECK(E1000_RCTL
, 0xFFFFFFFF, 0x00000000);
811 before
= ((adapter
->flags
& FLAG_IS_ICH
) ? 0x06C3B33E : 0x06DFB3FE);
812 REG_SET_AND_CHECK(E1000_RCTL
, before
, 0x003FFFFB);
813 REG_SET_AND_CHECK(E1000_TCTL
, 0xFFFFFFFF, 0x00000000);
815 REG_SET_AND_CHECK(E1000_RCTL
, before
, 0xFFFFFFFF);
816 REG_PATTERN_TEST(E1000_RDBAL
, 0xFFFFFFF0, 0xFFFFFFFF);
817 if (!(adapter
->flags
& FLAG_IS_ICH
))
818 REG_PATTERN_TEST(E1000_TXCW
, 0xC000FFFF, 0x0000FFFF);
819 REG_PATTERN_TEST(E1000_TDBAL
, 0xFFFFFFF0, 0xFFFFFFFF);
820 REG_PATTERN_TEST(E1000_TIDV
, 0x0000FFFF, 0x0000FFFF);
831 for (i
= 0; i
< mac
->rar_entry_count
; i
++)
832 REG_PATTERN_TEST_ARRAY(E1000_RA
, ((i
<< 1) + 1),
835 for (i
= 0; i
< mac
->mta_reg_count
; i
++)
836 REG_PATTERN_TEST_ARRAY(E1000_MTA
, i
, 0xFFFFFFFF, 0xFFFFFFFF);
842 static int e1000_eeprom_test(struct e1000_adapter
*adapter
, u64
*data
)
849 /* Read and add up the contents of the EEPROM */
850 for (i
= 0; i
< (NVM_CHECKSUM_REG
+ 1); i
++) {
851 if ((e1000_read_nvm(&adapter
->hw
, i
, 1, &temp
)) < 0) {
858 /* If Checksum is not Correct return error else test passed */
859 if ((checksum
!= (u16
) NVM_SUM
) && !(*data
))
865 static irqreturn_t
e1000_test_intr(int irq
, void *data
)
867 struct net_device
*netdev
= (struct net_device
*) data
;
868 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
869 struct e1000_hw
*hw
= &adapter
->hw
;
871 adapter
->test_icr
|= er32(ICR
);
876 static int e1000_intr_test(struct e1000_adapter
*adapter
, u64
*data
)
878 struct net_device
*netdev
= adapter
->netdev
;
879 struct e1000_hw
*hw
= &adapter
->hw
;
882 u32 irq
= adapter
->pdev
->irq
;
885 int int_mode
= E1000E_INT_MODE_LEGACY
;
889 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
890 if (adapter
->int_mode
== E1000E_INT_MODE_MSIX
) {
891 int_mode
= adapter
->int_mode
;
892 e1000e_reset_interrupt_capability(adapter
);
893 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
894 e1000e_set_interrupt_capability(adapter
);
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
)) {
906 e_info("testing %s interrupt\n", (shared_int
? "shared" : "unshared"));
908 /* Disable all the interrupts */
909 ew32(IMC
, 0xFFFFFFFF);
911 usleep_range(10000, 20000);
913 /* Test each interrupt */
914 for (i
= 0; i
< 10; i
++) {
915 /* Interrupt to test */
918 if (adapter
->flags
& FLAG_IS_ICH
) {
920 case E1000_ICR_RXSEQ
:
923 if (adapter
->hw
.mac
.type
== e1000_ich8lan
||
924 adapter
->hw
.mac
.type
== e1000_ich9lan
)
934 * Disable the interrupt to be reported in
935 * the cause register and then force the same
936 * interrupt and see if one gets posted. If
937 * an interrupt was posted to the bus, the
940 adapter
->test_icr
= 0;
944 usleep_range(10000, 20000);
946 if (adapter
->test_icr
& mask
) {
953 * Enable the interrupt to be reported in
954 * the cause register and then force the same
955 * interrupt and see if one gets posted. If
956 * an interrupt was not posted to the bus, the
959 adapter
->test_icr
= 0;
963 usleep_range(10000, 20000);
965 if (!(adapter
->test_icr
& mask
)) {
972 * Disable the other interrupts to be reported in
973 * the cause register and then force the other
974 * interrupts and see if any get posted. If
975 * an interrupt was posted to the bus, the
978 adapter
->test_icr
= 0;
979 ew32(IMC
, ~mask
& 0x00007FFF);
980 ew32(ICS
, ~mask
& 0x00007FFF);
982 usleep_range(10000, 20000);
984 if (adapter
->test_icr
) {
991 /* Disable all the interrupts */
992 ew32(IMC
, 0xFFFFFFFF);
994 usleep_range(10000, 20000);
996 /* Unhook test interrupt handler */
997 free_irq(irq
, netdev
);
1000 if (int_mode
== E1000E_INT_MODE_MSIX
) {
1001 e1000e_reset_interrupt_capability(adapter
);
1002 adapter
->int_mode
= int_mode
;
1003 e1000e_set_interrupt_capability(adapter
);
1009 static void e1000_free_desc_rings(struct e1000_adapter
*adapter
)
1011 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1012 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1013 struct pci_dev
*pdev
= adapter
->pdev
;
1016 if (tx_ring
->desc
&& tx_ring
->buffer_info
) {
1017 for (i
= 0; i
< tx_ring
->count
; i
++) {
1018 if (tx_ring
->buffer_info
[i
].dma
)
1019 dma_unmap_single(&pdev
->dev
,
1020 tx_ring
->buffer_info
[i
].dma
,
1021 tx_ring
->buffer_info
[i
].length
,
1023 if (tx_ring
->buffer_info
[i
].skb
)
1024 dev_kfree_skb(tx_ring
->buffer_info
[i
].skb
);
1028 if (rx_ring
->desc
&& rx_ring
->buffer_info
) {
1029 for (i
= 0; i
< rx_ring
->count
; i
++) {
1030 if (rx_ring
->buffer_info
[i
].dma
)
1031 dma_unmap_single(&pdev
->dev
,
1032 rx_ring
->buffer_info
[i
].dma
,
1033 2048, DMA_FROM_DEVICE
);
1034 if (rx_ring
->buffer_info
[i
].skb
)
1035 dev_kfree_skb(rx_ring
->buffer_info
[i
].skb
);
1039 if (tx_ring
->desc
) {
1040 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
1042 tx_ring
->desc
= NULL
;
1044 if (rx_ring
->desc
) {
1045 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
1047 rx_ring
->desc
= NULL
;
1050 kfree(tx_ring
->buffer_info
);
1051 tx_ring
->buffer_info
= NULL
;
1052 kfree(rx_ring
->buffer_info
);
1053 rx_ring
->buffer_info
= NULL
;
1056 static int e1000_setup_desc_rings(struct e1000_adapter
*adapter
)
1058 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1059 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1060 struct pci_dev
*pdev
= adapter
->pdev
;
1061 struct e1000_hw
*hw
= &adapter
->hw
;
1066 /* Setup Tx descriptor ring and Tx buffers */
1068 if (!tx_ring
->count
)
1069 tx_ring
->count
= E1000_DEFAULT_TXD
;
1071 tx_ring
->buffer_info
= kcalloc(tx_ring
->count
,
1072 sizeof(struct e1000_buffer
),
1074 if (!(tx_ring
->buffer_info
)) {
1079 tx_ring
->size
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
1080 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1081 tx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, tx_ring
->size
,
1082 &tx_ring
->dma
, GFP_KERNEL
);
1083 if (!tx_ring
->desc
) {
1087 tx_ring
->next_to_use
= 0;
1088 tx_ring
->next_to_clean
= 0;
1090 ew32(TDBAL
, ((u64
) tx_ring
->dma
& 0x00000000FFFFFFFF));
1091 ew32(TDBAH
, ((u64
) tx_ring
->dma
>> 32));
1092 ew32(TDLEN
, tx_ring
->count
* sizeof(struct e1000_tx_desc
));
1095 ew32(TCTL
, E1000_TCTL_PSP
| E1000_TCTL_EN
| E1000_TCTL_MULR
|
1096 E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
|
1097 E1000_COLLISION_DISTANCE
<< E1000_COLD_SHIFT
);
1099 for (i
= 0; i
< tx_ring
->count
; i
++) {
1100 struct e1000_tx_desc
*tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
1101 struct sk_buff
*skb
;
1102 unsigned int skb_size
= 1024;
1104 skb
= alloc_skb(skb_size
, GFP_KERNEL
);
1109 skb_put(skb
, skb_size
);
1110 tx_ring
->buffer_info
[i
].skb
= skb
;
1111 tx_ring
->buffer_info
[i
].length
= skb
->len
;
1112 tx_ring
->buffer_info
[i
].dma
=
1113 dma_map_single(&pdev
->dev
, skb
->data
, skb
->len
,
1115 if (dma_mapping_error(&pdev
->dev
,
1116 tx_ring
->buffer_info
[i
].dma
)) {
1120 tx_desc
->buffer_addr
= cpu_to_le64(tx_ring
->buffer_info
[i
].dma
);
1121 tx_desc
->lower
.data
= cpu_to_le32(skb
->len
);
1122 tx_desc
->lower
.data
|= cpu_to_le32(E1000_TXD_CMD_EOP
|
1123 E1000_TXD_CMD_IFCS
|
1125 tx_desc
->upper
.data
= 0;
1128 /* Setup Rx descriptor ring and Rx buffers */
1130 if (!rx_ring
->count
)
1131 rx_ring
->count
= E1000_DEFAULT_RXD
;
1133 rx_ring
->buffer_info
= kcalloc(rx_ring
->count
,
1134 sizeof(struct e1000_buffer
),
1136 if (!(rx_ring
->buffer_info
)) {
1141 rx_ring
->size
= rx_ring
->count
* sizeof(union e1000_rx_desc_extended
);
1142 rx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, rx_ring
->size
,
1143 &rx_ring
->dma
, GFP_KERNEL
);
1144 if (!rx_ring
->desc
) {
1148 rx_ring
->next_to_use
= 0;
1149 rx_ring
->next_to_clean
= 0;
1152 if (!(adapter
->flags2
& FLAG2_NO_DISABLE_RX
))
1153 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1154 ew32(RDBAL
, ((u64
) rx_ring
->dma
& 0xFFFFFFFF));
1155 ew32(RDBAH
, ((u64
) rx_ring
->dma
>> 32));
1156 ew32(RDLEN
, rx_ring
->size
);
1159 rctl
= E1000_RCTL_EN
| E1000_RCTL_BAM
| E1000_RCTL_SZ_2048
|
1160 E1000_RCTL_UPE
| E1000_RCTL_MPE
| E1000_RCTL_LPE
|
1161 E1000_RCTL_SBP
| E1000_RCTL_SECRC
|
1162 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1163 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1166 for (i
= 0; i
< rx_ring
->count
; i
++) {
1167 union e1000_rx_desc_extended
*rx_desc
;
1168 struct sk_buff
*skb
;
1170 skb
= alloc_skb(2048 + NET_IP_ALIGN
, GFP_KERNEL
);
1175 skb_reserve(skb
, NET_IP_ALIGN
);
1176 rx_ring
->buffer_info
[i
].skb
= skb
;
1177 rx_ring
->buffer_info
[i
].dma
=
1178 dma_map_single(&pdev
->dev
, skb
->data
, 2048,
1180 if (dma_mapping_error(&pdev
->dev
,
1181 rx_ring
->buffer_info
[i
].dma
)) {
1185 rx_desc
= E1000_RX_DESC_EXT(*rx_ring
, i
);
1186 rx_desc
->read
.buffer_addr
=
1187 cpu_to_le64(rx_ring
->buffer_info
[i
].dma
);
1188 memset(skb
->data
, 0x00, skb
->len
);
1194 e1000_free_desc_rings(adapter
);
1198 static void e1000_phy_disable_receiver(struct e1000_adapter
*adapter
)
1200 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1201 e1e_wphy(&adapter
->hw
, 29, 0x001F);
1202 e1e_wphy(&adapter
->hw
, 30, 0x8FFC);
1203 e1e_wphy(&adapter
->hw
, 29, 0x001A);
1204 e1e_wphy(&adapter
->hw
, 30, 0x8FF0);
1207 static int e1000_integrated_phy_loopback(struct e1000_adapter
*adapter
)
1209 struct e1000_hw
*hw
= &adapter
->hw
;
1214 hw
->mac
.autoneg
= 0;
1216 if (hw
->phy
.type
== e1000_phy_ife
) {
1217 /* force 100, set loopback */
1218 e1e_wphy(hw
, PHY_CONTROL
, 0x6100);
1220 /* Now set up the MAC to the same speed/duplex as the PHY. */
1221 ctrl_reg
= er32(CTRL
);
1222 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1223 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1224 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1225 E1000_CTRL_SPD_100
|/* Force Speed to 100 */
1226 E1000_CTRL_FD
); /* Force Duplex to FULL */
1228 ew32(CTRL
, ctrl_reg
);
1235 /* Specific PHY configuration for loopback */
1236 switch (hw
->phy
.type
) {
1238 /* Auto-MDI/MDIX Off */
1239 e1e_wphy(hw
, M88E1000_PHY_SPEC_CTRL
, 0x0808);
1240 /* reset to update Auto-MDI/MDIX */
1241 e1e_wphy(hw
, PHY_CONTROL
, 0x9140);
1243 e1e_wphy(hw
, PHY_CONTROL
, 0x8140);
1245 case e1000_phy_gg82563
:
1246 e1e_wphy(hw
, GG82563_PHY_KMRN_MODE_CTRL
, 0x1CC);
1249 /* Set Default MAC Interface speed to 1GB */
1250 e1e_rphy(hw
, PHY_REG(2, 21), &phy_reg
);
1253 e1e_wphy(hw
, PHY_REG(2, 21), phy_reg
);
1254 /* Assert SW reset for above settings to take effect */
1255 e1000e_commit_phy(hw
);
1257 /* Force Full Duplex */
1258 e1e_rphy(hw
, PHY_REG(769, 16), &phy_reg
);
1259 e1e_wphy(hw
, PHY_REG(769, 16), phy_reg
| 0x000C);
1260 /* Set Link Up (in force link) */
1261 e1e_rphy(hw
, PHY_REG(776, 16), &phy_reg
);
1262 e1e_wphy(hw
, PHY_REG(776, 16), phy_reg
| 0x0040);
1264 e1e_rphy(hw
, PHY_REG(769, 16), &phy_reg
);
1265 e1e_wphy(hw
, PHY_REG(769, 16), phy_reg
| 0x0040);
1266 /* Set Early Link Enable */
1267 e1e_rphy(hw
, PHY_REG(769, 20), &phy_reg
);
1268 e1e_wphy(hw
, PHY_REG(769, 20), phy_reg
| 0x0400);
1270 case e1000_phy_82577
:
1271 case e1000_phy_82578
:
1272 /* Workaround: K1 must be disabled for stable 1Gbps operation */
1273 ret_val
= hw
->phy
.ops
.acquire(hw
);
1275 e_err("Cannot setup 1Gbps loopback.\n");
1278 e1000_configure_k1_ich8lan(hw
, false);
1279 hw
->phy
.ops
.release(hw
);
1281 case e1000_phy_82579
:
1282 /* Disable PHY energy detect power down */
1283 e1e_rphy(hw
, PHY_REG(0, 21), &phy_reg
);
1284 e1e_wphy(hw
, PHY_REG(0, 21), phy_reg
& ~(1 << 3));
1285 /* Disable full chip energy detect */
1286 e1e_rphy(hw
, PHY_REG(776, 18), &phy_reg
);
1287 e1e_wphy(hw
, PHY_REG(776, 18), phy_reg
| 1);
1288 /* Enable loopback on the PHY */
1289 #define I82577_PHY_LBK_CTRL 19
1290 e1e_wphy(hw
, I82577_PHY_LBK_CTRL
, 0x8001);
1296 /* force 1000, set loopback */
1297 e1e_wphy(hw
, PHY_CONTROL
, 0x4140);
1300 /* Now set up the MAC to the same speed/duplex as the PHY. */
1301 ctrl_reg
= er32(CTRL
);
1302 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1303 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1304 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1305 E1000_CTRL_SPD_1000
|/* Force Speed to 1000 */
1306 E1000_CTRL_FD
); /* Force Duplex to FULL */
1308 if (adapter
->flags
& FLAG_IS_ICH
)
1309 ctrl_reg
|= E1000_CTRL_SLU
; /* Set Link Up */
1311 if (hw
->phy
.media_type
== e1000_media_type_copper
&&
1312 hw
->phy
.type
== e1000_phy_m88
) {
1313 ctrl_reg
|= E1000_CTRL_ILOS
; /* Invert Loss of Signal */
1316 * Set the ILOS bit on the fiber Nic if half duplex link is
1319 if ((er32(STATUS
) & E1000_STATUS_FD
) == 0)
1320 ctrl_reg
|= (E1000_CTRL_ILOS
| E1000_CTRL_SLU
);
1323 ew32(CTRL
, ctrl_reg
);
1326 * Disable the receiver on the PHY so when a cable is plugged in, the
1327 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1329 if (hw
->phy
.type
== e1000_phy_m88
)
1330 e1000_phy_disable_receiver(adapter
);
1337 static int e1000_set_82571_fiber_loopback(struct e1000_adapter
*adapter
)
1339 struct e1000_hw
*hw
= &adapter
->hw
;
1340 u32 ctrl
= er32(CTRL
);
1343 /* special requirements for 82571/82572 fiber adapters */
1346 * jump through hoops to make sure link is up because serdes
1347 * link is hardwired up
1349 ctrl
|= E1000_CTRL_SLU
;
1352 /* disable autoneg */
1357 link
= (er32(STATUS
) & E1000_STATUS_LU
);
1360 /* set invert loss of signal */
1362 ctrl
|= E1000_CTRL_ILOS
;
1367 * special write to serdes control register to enable SerDes analog
1370 #define E1000_SERDES_LB_ON 0x410
1371 ew32(SCTL
, E1000_SERDES_LB_ON
);
1373 usleep_range(10000, 20000);
1378 /* only call this for fiber/serdes connections to es2lan */
1379 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter
*adapter
)
1381 struct e1000_hw
*hw
= &adapter
->hw
;
1382 u32 ctrlext
= er32(CTRL_EXT
);
1383 u32 ctrl
= er32(CTRL
);
1386 * save CTRL_EXT to restore later, reuse an empty variable (unused
1387 * on mac_type 80003es2lan)
1389 adapter
->tx_fifo_head
= ctrlext
;
1391 /* clear the serdes mode bits, putting the device into mac loopback */
1392 ctrlext
&= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES
;
1393 ew32(CTRL_EXT
, ctrlext
);
1395 /* force speed to 1000/FD, link up */
1396 ctrl
&= ~(E1000_CTRL_SPD_1000
| E1000_CTRL_SPD_100
);
1397 ctrl
|= (E1000_CTRL_SLU
| E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
|
1398 E1000_CTRL_SPD_1000
| E1000_CTRL_FD
);
1401 /* set mac loopback */
1403 ctrl
|= E1000_RCTL_LBM_MAC
;
1406 /* set testing mode parameters (no need to reset later) */
1407 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
1408 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1410 (KMRNCTRLSTA_OPMODE
| KMRNCTRLSTA_OPMODE_1GB_FD_GMII
));
1415 static int e1000_setup_loopback_test(struct e1000_adapter
*adapter
)
1417 struct e1000_hw
*hw
= &adapter
->hw
;
1420 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1421 hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1422 switch (hw
->mac
.type
) {
1423 case e1000_80003es2lan
:
1424 return e1000_set_es2lan_mac_loopback(adapter
);
1428 return e1000_set_82571_fiber_loopback(adapter
);
1432 rctl
|= E1000_RCTL_LBM_TCVR
;
1436 } else if (hw
->phy
.media_type
== e1000_media_type_copper
) {
1437 return e1000_integrated_phy_loopback(adapter
);
1443 static void e1000_loopback_cleanup(struct e1000_adapter
*adapter
)
1445 struct e1000_hw
*hw
= &adapter
->hw
;
1450 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
1453 switch (hw
->mac
.type
) {
1454 case e1000_80003es2lan
:
1455 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1456 hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1457 /* restore CTRL_EXT, stealing space from tx_fifo_head */
1458 ew32(CTRL_EXT
, adapter
->tx_fifo_head
);
1459 adapter
->tx_fifo_head
= 0;
1464 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1465 hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1466 #define E1000_SERDES_LB_OFF 0x400
1467 ew32(SCTL
, E1000_SERDES_LB_OFF
);
1469 usleep_range(10000, 20000);
1474 hw
->mac
.autoneg
= 1;
1475 if (hw
->phy
.type
== e1000_phy_gg82563
)
1476 e1e_wphy(hw
, GG82563_PHY_KMRN_MODE_CTRL
, 0x180);
1477 e1e_rphy(hw
, PHY_CONTROL
, &phy_reg
);
1478 if (phy_reg
& MII_CR_LOOPBACK
) {
1479 phy_reg
&= ~MII_CR_LOOPBACK
;
1480 e1e_wphy(hw
, PHY_CONTROL
, phy_reg
);
1481 e1000e_commit_phy(hw
);
1487 static void e1000_create_lbtest_frame(struct sk_buff
*skb
,
1488 unsigned int frame_size
)
1490 memset(skb
->data
, 0xFF, frame_size
);
1492 memset(&skb
->data
[frame_size
/ 2], 0xAA, frame_size
/ 2 - 1);
1493 memset(&skb
->data
[frame_size
/ 2 + 10], 0xBE, 1);
1494 memset(&skb
->data
[frame_size
/ 2 + 12], 0xAF, 1);
1497 static int e1000_check_lbtest_frame(struct sk_buff
*skb
,
1498 unsigned int frame_size
)
1501 if (*(skb
->data
+ 3) == 0xFF)
1502 if ((*(skb
->data
+ frame_size
/ 2 + 10) == 0xBE) &&
1503 (*(skb
->data
+ frame_size
/ 2 + 12) == 0xAF))
1508 static int e1000_run_loopback_test(struct e1000_adapter
*adapter
)
1510 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1511 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1512 struct pci_dev
*pdev
= adapter
->pdev
;
1513 struct e1000_hw
*hw
= &adapter
->hw
;
1520 ew32(RDT
, rx_ring
->count
- 1);
1523 * Calculate the loop count based on the largest descriptor ring
1524 * The idea is to wrap the largest ring a number of times using 64
1525 * send/receive pairs during each loop
1528 if (rx_ring
->count
<= tx_ring
->count
)
1529 lc
= ((tx_ring
->count
/ 64) * 2) + 1;
1531 lc
= ((rx_ring
->count
/ 64) * 2) + 1;
1535 for (j
= 0; j
<= lc
; j
++) { /* loop count loop */
1536 for (i
= 0; i
< 64; i
++) { /* send the packets */
1537 e1000_create_lbtest_frame(tx_ring
->buffer_info
[k
].skb
,
1539 dma_sync_single_for_device(&pdev
->dev
,
1540 tx_ring
->buffer_info
[k
].dma
,
1541 tx_ring
->buffer_info
[k
].length
,
1544 if (k
== tx_ring
->count
)
1550 time
= jiffies
; /* set the start time for the receive */
1552 do { /* receive the sent packets */
1553 dma_sync_single_for_cpu(&pdev
->dev
,
1554 rx_ring
->buffer_info
[l
].dma
, 2048,
1557 ret_val
= e1000_check_lbtest_frame(
1558 rx_ring
->buffer_info
[l
].skb
, 1024);
1562 if (l
== rx_ring
->count
)
1565 * time + 20 msecs (200 msecs on 2.4) is more than
1566 * enough time to complete the receives, if it's
1567 * exceeded, break and error off
1569 } while ((good_cnt
< 64) && !time_after(jiffies
, time
+ 20));
1570 if (good_cnt
!= 64) {
1571 ret_val
= 13; /* ret_val is the same as mis-compare */
1574 if (jiffies
>= (time
+ 20)) {
1575 ret_val
= 14; /* error code for time out error */
1578 } /* end loop count loop */
1582 static int e1000_loopback_test(struct e1000_adapter
*adapter
, u64
*data
)
1585 * PHY loopback cannot be performed if SoL/IDER
1586 * sessions are active
1588 if (e1000_check_reset_block(&adapter
->hw
)) {
1589 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
1594 *data
= e1000_setup_desc_rings(adapter
);
1598 *data
= e1000_setup_loopback_test(adapter
);
1602 *data
= e1000_run_loopback_test(adapter
);
1603 e1000_loopback_cleanup(adapter
);
1606 e1000_free_desc_rings(adapter
);
1611 static int e1000_link_test(struct e1000_adapter
*adapter
, u64
*data
)
1613 struct e1000_hw
*hw
= &adapter
->hw
;
1616 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1618 hw
->mac
.serdes_has_link
= false;
1621 * On some blade server designs, link establishment
1622 * could take as long as 2-3 minutes
1625 hw
->mac
.ops
.check_for_link(hw
);
1626 if (hw
->mac
.serdes_has_link
)
1629 } while (i
++ < 3750);
1633 hw
->mac
.ops
.check_for_link(hw
);
1634 if (hw
->mac
.autoneg
)
1636 * On some Phy/switch combinations, link establishment
1637 * can take a few seconds more than expected.
1641 if (!(er32(STATUS
) & E1000_STATUS_LU
))
1647 static int e1000e_get_sset_count(struct net_device
*netdev
, int sset
)
1651 return E1000_TEST_LEN
;
1653 return E1000_STATS_LEN
;
1659 static void e1000_diag_test(struct net_device
*netdev
,
1660 struct ethtool_test
*eth_test
, u64
*data
)
1662 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1663 u16 autoneg_advertised
;
1664 u8 forced_speed_duplex
;
1666 bool if_running
= netif_running(netdev
);
1668 set_bit(__E1000_TESTING
, &adapter
->state
);
1671 /* Get control of and reset hardware */
1672 if (adapter
->flags
& FLAG_HAS_AMT
)
1673 e1000e_get_hw_control(adapter
);
1675 e1000e_power_up_phy(adapter
);
1677 adapter
->hw
.phy
.autoneg_wait_to_complete
= 1;
1678 e1000e_reset(adapter
);
1679 adapter
->hw
.phy
.autoneg_wait_to_complete
= 0;
1682 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1685 /* save speed, duplex, autoneg settings */
1686 autoneg_advertised
= adapter
->hw
.phy
.autoneg_advertised
;
1687 forced_speed_duplex
= adapter
->hw
.mac
.forced_speed_duplex
;
1688 autoneg
= adapter
->hw
.mac
.autoneg
;
1690 e_info("offline testing starting\n");
1693 /* indicate we're in test mode */
1696 if (e1000_reg_test(adapter
, &data
[0]))
1697 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1699 e1000e_reset(adapter
);
1700 if (e1000_eeprom_test(adapter
, &data
[1]))
1701 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1703 e1000e_reset(adapter
);
1704 if (e1000_intr_test(adapter
, &data
[2]))
1705 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1707 e1000e_reset(adapter
);
1708 if (e1000_loopback_test(adapter
, &data
[3]))
1709 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1711 /* force this routine to wait until autoneg complete/timeout */
1712 adapter
->hw
.phy
.autoneg_wait_to_complete
= 1;
1713 e1000e_reset(adapter
);
1714 adapter
->hw
.phy
.autoneg_wait_to_complete
= 0;
1716 if (e1000_link_test(adapter
, &data
[4]))
1717 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1719 /* restore speed, duplex, autoneg settings */
1720 adapter
->hw
.phy
.autoneg_advertised
= autoneg_advertised
;
1721 adapter
->hw
.mac
.forced_speed_duplex
= forced_speed_duplex
;
1722 adapter
->hw
.mac
.autoneg
= autoneg
;
1723 e1000e_reset(adapter
);
1725 clear_bit(__E1000_TESTING
, &adapter
->state
);
1731 e_info("online testing starting\n");
1733 /* register, eeprom, intr and loopback tests not run online */
1739 if (e1000_link_test(adapter
, &data
[4]))
1740 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1742 clear_bit(__E1000_TESTING
, &adapter
->state
);
1746 e1000e_reset(adapter
);
1748 if (adapter
->flags
& FLAG_HAS_AMT
)
1749 e1000e_release_hw_control(adapter
);
1752 msleep_interruptible(4 * 1000);
1755 static void e1000_get_wol(struct net_device
*netdev
,
1756 struct ethtool_wolinfo
*wol
)
1758 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1763 if (!(adapter
->flags
& FLAG_HAS_WOL
) ||
1764 !device_can_wakeup(&adapter
->pdev
->dev
))
1767 wol
->supported
= WAKE_UCAST
| WAKE_MCAST
|
1768 WAKE_BCAST
| WAKE_MAGIC
| WAKE_PHY
;
1770 /* apply any specific unsupported masks here */
1771 if (adapter
->flags
& FLAG_NO_WAKE_UCAST
) {
1772 wol
->supported
&= ~WAKE_UCAST
;
1774 if (adapter
->wol
& E1000_WUFC_EX
)
1775 e_err("Interface does not support directed (unicast) "
1776 "frame wake-up packets\n");
1779 if (adapter
->wol
& E1000_WUFC_EX
)
1780 wol
->wolopts
|= WAKE_UCAST
;
1781 if (adapter
->wol
& E1000_WUFC_MC
)
1782 wol
->wolopts
|= WAKE_MCAST
;
1783 if (adapter
->wol
& E1000_WUFC_BC
)
1784 wol
->wolopts
|= WAKE_BCAST
;
1785 if (adapter
->wol
& E1000_WUFC_MAG
)
1786 wol
->wolopts
|= WAKE_MAGIC
;
1787 if (adapter
->wol
& E1000_WUFC_LNKC
)
1788 wol
->wolopts
|= WAKE_PHY
;
1791 static int e1000_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1793 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1795 if (!(adapter
->flags
& FLAG_HAS_WOL
) ||
1796 !device_can_wakeup(&adapter
->pdev
->dev
) ||
1797 (wol
->wolopts
& ~(WAKE_UCAST
| WAKE_MCAST
| WAKE_BCAST
|
1798 WAKE_MAGIC
| WAKE_PHY
)))
1801 /* these settings will always override what we currently have */
1804 if (wol
->wolopts
& WAKE_UCAST
)
1805 adapter
->wol
|= E1000_WUFC_EX
;
1806 if (wol
->wolopts
& WAKE_MCAST
)
1807 adapter
->wol
|= E1000_WUFC_MC
;
1808 if (wol
->wolopts
& WAKE_BCAST
)
1809 adapter
->wol
|= E1000_WUFC_BC
;
1810 if (wol
->wolopts
& WAKE_MAGIC
)
1811 adapter
->wol
|= E1000_WUFC_MAG
;
1812 if (wol
->wolopts
& WAKE_PHY
)
1813 adapter
->wol
|= E1000_WUFC_LNKC
;
1815 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
1820 static int e1000_set_phys_id(struct net_device
*netdev
,
1821 enum ethtool_phys_id_state state
)
1823 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1824 struct e1000_hw
*hw
= &adapter
->hw
;
1827 case ETHTOOL_ID_ACTIVE
:
1828 if (!hw
->mac
.ops
.blink_led
)
1829 return 2; /* cycle on/off twice per second */
1831 hw
->mac
.ops
.blink_led(hw
);
1834 case ETHTOOL_ID_INACTIVE
:
1835 if (hw
->phy
.type
== e1000_phy_ife
)
1836 e1e_wphy(hw
, IFE_PHY_SPECIAL_CONTROL_LED
, 0);
1837 hw
->mac
.ops
.led_off(hw
);
1838 hw
->mac
.ops
.cleanup_led(hw
);
1842 adapter
->hw
.mac
.ops
.led_on(&adapter
->hw
);
1845 case ETHTOOL_ID_OFF
:
1846 adapter
->hw
.mac
.ops
.led_off(&adapter
->hw
);
1852 static int e1000_get_coalesce(struct net_device
*netdev
,
1853 struct ethtool_coalesce
*ec
)
1855 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1857 if (adapter
->itr_setting
<= 4)
1858 ec
->rx_coalesce_usecs
= adapter
->itr_setting
;
1860 ec
->rx_coalesce_usecs
= 1000000 / adapter
->itr_setting
;
1865 static int e1000_set_coalesce(struct net_device
*netdev
,
1866 struct ethtool_coalesce
*ec
)
1868 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1869 struct e1000_hw
*hw
= &adapter
->hw
;
1871 if ((ec
->rx_coalesce_usecs
> E1000_MAX_ITR_USECS
) ||
1872 ((ec
->rx_coalesce_usecs
> 4) &&
1873 (ec
->rx_coalesce_usecs
< E1000_MIN_ITR_USECS
)) ||
1874 (ec
->rx_coalesce_usecs
== 2))
1877 if (ec
->rx_coalesce_usecs
== 4) {
1878 adapter
->itr
= adapter
->itr_setting
= 4;
1879 } else if (ec
->rx_coalesce_usecs
<= 3) {
1880 adapter
->itr
= 20000;
1881 adapter
->itr_setting
= ec
->rx_coalesce_usecs
;
1883 adapter
->itr
= (1000000 / ec
->rx_coalesce_usecs
);
1884 adapter
->itr_setting
= adapter
->itr
& ~3;
1887 if (adapter
->itr_setting
!= 0)
1888 ew32(ITR
, 1000000000 / (adapter
->itr
* 256));
1895 static int e1000_nway_reset(struct net_device
*netdev
)
1897 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1899 if (!netif_running(netdev
))
1902 if (!adapter
->hw
.mac
.autoneg
)
1905 e1000e_reinit_locked(adapter
);
1910 static void e1000_get_ethtool_stats(struct net_device
*netdev
,
1911 struct ethtool_stats
*stats
,
1914 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1915 struct rtnl_link_stats64 net_stats
;
1919 e1000e_get_stats64(netdev
, &net_stats
);
1920 for (i
= 0; i
< E1000_GLOBAL_STATS_LEN
; i
++) {
1921 switch (e1000_gstrings_stats
[i
].type
) {
1923 p
= (char *) &net_stats
+
1924 e1000_gstrings_stats
[i
].stat_offset
;
1927 p
= (char *) adapter
+
1928 e1000_gstrings_stats
[i
].stat_offset
;
1935 data
[i
] = (e1000_gstrings_stats
[i
].sizeof_stat
==
1936 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1940 static void e1000_get_strings(struct net_device
*netdev
, u32 stringset
,
1946 switch (stringset
) {
1948 memcpy(data
, e1000_gstrings_test
, sizeof(e1000_gstrings_test
));
1951 for (i
= 0; i
< E1000_GLOBAL_STATS_LEN
; i
++) {
1952 memcpy(p
, e1000_gstrings_stats
[i
].stat_string
,
1954 p
+= ETH_GSTRING_LEN
;
1960 static const struct ethtool_ops e1000_ethtool_ops
= {
1961 .get_settings
= e1000_get_settings
,
1962 .set_settings
= e1000_set_settings
,
1963 .get_drvinfo
= e1000_get_drvinfo
,
1964 .get_regs_len
= e1000_get_regs_len
,
1965 .get_regs
= e1000_get_regs
,
1966 .get_wol
= e1000_get_wol
,
1967 .set_wol
= e1000_set_wol
,
1968 .get_msglevel
= e1000_get_msglevel
,
1969 .set_msglevel
= e1000_set_msglevel
,
1970 .nway_reset
= e1000_nway_reset
,
1971 .get_link
= ethtool_op_get_link
,
1972 .get_eeprom_len
= e1000_get_eeprom_len
,
1973 .get_eeprom
= e1000_get_eeprom
,
1974 .set_eeprom
= e1000_set_eeprom
,
1975 .get_ringparam
= e1000_get_ringparam
,
1976 .set_ringparam
= e1000_set_ringparam
,
1977 .get_pauseparam
= e1000_get_pauseparam
,
1978 .set_pauseparam
= e1000_set_pauseparam
,
1979 .self_test
= e1000_diag_test
,
1980 .get_strings
= e1000_get_strings
,
1981 .set_phys_id
= e1000_set_phys_id
,
1982 .get_ethtool_stats
= e1000_get_ethtool_stats
,
1983 .get_sset_count
= e1000e_get_sset_count
,
1984 .get_coalesce
= e1000_get_coalesce
,
1985 .set_coalesce
= e1000_set_coalesce
,
1988 void e1000e_set_ethtool_ops(struct net_device
*netdev
)
1990 SET_ETHTOOL_OPS(netdev
, &e1000_ethtool_ops
);