1 /* Intel PRO/1000 Linux driver
2 * Copyright(c) 1999 - 2015 Intel Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
16 * Contact Information:
17 * Linux NICS <linux.nics@intel.com>
18 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
19 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
22 /* ethtool support for e1000 */
24 #include <linux/netdevice.h>
25 #include <linux/interrupt.h>
26 #include <linux/ethtool.h>
27 #include <linux/pci.h>
28 #include <linux/slab.h>
29 #include <linux/delay.h>
30 #include <linux/vmalloc.h>
31 #include <linux/pm_runtime.h>
35 enum { NETDEV_STATS
, E1000_STATS
};
38 char stat_string
[ETH_GSTRING_LEN
];
44 #define E1000_STAT(str, m) { \
46 .type = E1000_STATS, \
47 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
48 .stat_offset = offsetof(struct e1000_adapter, m) }
49 #define E1000_NETDEV_STAT(str, m) { \
51 .type = NETDEV_STATS, \
52 .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
53 .stat_offset = offsetof(struct rtnl_link_stats64, m) }
55 static const struct e1000_stats e1000_gstrings_stats
[] = {
56 E1000_STAT("rx_packets", stats
.gprc
),
57 E1000_STAT("tx_packets", stats
.gptc
),
58 E1000_STAT("rx_bytes", stats
.gorc
),
59 E1000_STAT("tx_bytes", stats
.gotc
),
60 E1000_STAT("rx_broadcast", stats
.bprc
),
61 E1000_STAT("tx_broadcast", stats
.bptc
),
62 E1000_STAT("rx_multicast", stats
.mprc
),
63 E1000_STAT("tx_multicast", stats
.mptc
),
64 E1000_NETDEV_STAT("rx_errors", rx_errors
),
65 E1000_NETDEV_STAT("tx_errors", tx_errors
),
66 E1000_NETDEV_STAT("tx_dropped", tx_dropped
),
67 E1000_STAT("multicast", stats
.mprc
),
68 E1000_STAT("collisions", stats
.colc
),
69 E1000_NETDEV_STAT("rx_length_errors", rx_length_errors
),
70 E1000_NETDEV_STAT("rx_over_errors", rx_over_errors
),
71 E1000_STAT("rx_crc_errors", stats
.crcerrs
),
72 E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors
),
73 E1000_STAT("rx_no_buffer_count", stats
.rnbc
),
74 E1000_STAT("rx_missed_errors", stats
.mpc
),
75 E1000_STAT("tx_aborted_errors", stats
.ecol
),
76 E1000_STAT("tx_carrier_errors", stats
.tncrs
),
77 E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors
),
78 E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors
),
79 E1000_STAT("tx_window_errors", stats
.latecol
),
80 E1000_STAT("tx_abort_late_coll", stats
.latecol
),
81 E1000_STAT("tx_deferred_ok", stats
.dc
),
82 E1000_STAT("tx_single_coll_ok", stats
.scc
),
83 E1000_STAT("tx_multi_coll_ok", stats
.mcc
),
84 E1000_STAT("tx_timeout_count", tx_timeout_count
),
85 E1000_STAT("tx_restart_queue", restart_queue
),
86 E1000_STAT("rx_long_length_errors", stats
.roc
),
87 E1000_STAT("rx_short_length_errors", stats
.ruc
),
88 E1000_STAT("rx_align_errors", stats
.algnerrc
),
89 E1000_STAT("tx_tcp_seg_good", stats
.tsctc
),
90 E1000_STAT("tx_tcp_seg_failed", stats
.tsctfc
),
91 E1000_STAT("rx_flow_control_xon", stats
.xonrxc
),
92 E1000_STAT("rx_flow_control_xoff", stats
.xoffrxc
),
93 E1000_STAT("tx_flow_control_xon", stats
.xontxc
),
94 E1000_STAT("tx_flow_control_xoff", stats
.xofftxc
),
95 E1000_STAT("rx_csum_offload_good", hw_csum_good
),
96 E1000_STAT("rx_csum_offload_errors", hw_csum_err
),
97 E1000_STAT("rx_header_split", rx_hdr_split
),
98 E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed
),
99 E1000_STAT("tx_smbus", stats
.mgptc
),
100 E1000_STAT("rx_smbus", stats
.mgprc
),
101 E1000_STAT("dropped_smbus", stats
.mgpdc
),
102 E1000_STAT("rx_dma_failed", rx_dma_failed
),
103 E1000_STAT("tx_dma_failed", tx_dma_failed
),
104 E1000_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared
),
105 E1000_STAT("uncorr_ecc_errors", uncorr_errors
),
106 E1000_STAT("corr_ecc_errors", corr_errors
),
107 E1000_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts
),
108 E1000_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped
),
111 #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
112 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
113 static const char e1000_gstrings_test
[][ETH_GSTRING_LEN
] = {
114 "Register test (offline)", "Eeprom test (offline)",
115 "Interrupt test (offline)", "Loopback test (offline)",
116 "Link test (on/offline)"
119 #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
121 static int e1000_get_link_ksettings(struct net_device
*netdev
,
122 struct ethtool_link_ksettings
*cmd
)
124 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
125 struct e1000_hw
*hw
= &adapter
->hw
;
126 u32 speed
, supported
, advertising
;
128 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
129 supported
= (SUPPORTED_10baseT_Half
|
130 SUPPORTED_10baseT_Full
|
131 SUPPORTED_100baseT_Half
|
132 SUPPORTED_100baseT_Full
|
133 SUPPORTED_1000baseT_Full
|
136 if (hw
->phy
.type
== e1000_phy_ife
)
137 supported
&= ~SUPPORTED_1000baseT_Full
;
138 advertising
= ADVERTISED_TP
;
140 if (hw
->mac
.autoneg
== 1) {
141 advertising
|= ADVERTISED_Autoneg
;
142 /* the e1000 autoneg seems to match ethtool nicely */
143 advertising
|= hw
->phy
.autoneg_advertised
;
146 cmd
->base
.port
= PORT_TP
;
147 cmd
->base
.phy_address
= hw
->phy
.addr
;
149 supported
= (SUPPORTED_1000baseT_Full
|
153 advertising
= (ADVERTISED_1000baseT_Full
|
157 cmd
->base
.port
= PORT_FIBRE
;
160 speed
= SPEED_UNKNOWN
;
161 cmd
->base
.duplex
= DUPLEX_UNKNOWN
;
163 if (netif_running(netdev
)) {
164 if (netif_carrier_ok(netdev
)) {
165 speed
= adapter
->link_speed
;
166 cmd
->base
.duplex
= adapter
->link_duplex
- 1;
168 } else if (!pm_runtime_suspended(netdev
->dev
.parent
)) {
169 u32 status
= er32(STATUS
);
171 if (status
& E1000_STATUS_LU
) {
172 if (status
& E1000_STATUS_SPEED_1000
)
174 else if (status
& E1000_STATUS_SPEED_100
)
179 if (status
& E1000_STATUS_FD
)
180 cmd
->base
.duplex
= DUPLEX_FULL
;
182 cmd
->base
.duplex
= DUPLEX_HALF
;
186 cmd
->base
.speed
= speed
;
187 cmd
->base
.autoneg
= ((hw
->phy
.media_type
== e1000_media_type_fiber
) ||
188 hw
->mac
.autoneg
) ? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
190 /* MDI-X => 2; MDI =>1; Invalid =>0 */
191 if ((hw
->phy
.media_type
== e1000_media_type_copper
) &&
192 netif_carrier_ok(netdev
))
193 cmd
->base
.eth_tp_mdix
= hw
->phy
.is_mdix
?
194 ETH_TP_MDI_X
: ETH_TP_MDI
;
196 cmd
->base
.eth_tp_mdix
= ETH_TP_MDI_INVALID
;
198 if (hw
->phy
.mdix
== AUTO_ALL_MODES
)
199 cmd
->base
.eth_tp_mdix_ctrl
= ETH_TP_MDI_AUTO
;
201 cmd
->base
.eth_tp_mdix_ctrl
= hw
->phy
.mdix
;
203 if (hw
->phy
.media_type
!= e1000_media_type_copper
)
204 cmd
->base
.eth_tp_mdix_ctrl
= ETH_TP_MDI_INVALID
;
206 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
208 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
214 static int e1000_set_spd_dplx(struct e1000_adapter
*adapter
, u32 spd
, u8 dplx
)
216 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
220 /* Make sure dplx is at most 1 bit and lsb of speed is not set
221 * for the switch() below to work
223 if ((spd
& 1) || (dplx
& ~1))
226 /* Fiber NICs only allow 1000 gbps Full duplex */
227 if ((adapter
->hw
.phy
.media_type
== e1000_media_type_fiber
) &&
228 (spd
!= SPEED_1000
) && (dplx
!= DUPLEX_FULL
)) {
232 switch (spd
+ dplx
) {
233 case SPEED_10
+ DUPLEX_HALF
:
234 mac
->forced_speed_duplex
= ADVERTISE_10_HALF
;
236 case SPEED_10
+ DUPLEX_FULL
:
237 mac
->forced_speed_duplex
= ADVERTISE_10_FULL
;
239 case SPEED_100
+ DUPLEX_HALF
:
240 mac
->forced_speed_duplex
= ADVERTISE_100_HALF
;
242 case SPEED_100
+ DUPLEX_FULL
:
243 mac
->forced_speed_duplex
= ADVERTISE_100_FULL
;
245 case SPEED_1000
+ DUPLEX_FULL
:
246 if (adapter
->hw
.phy
.media_type
== e1000_media_type_copper
) {
248 adapter
->hw
.phy
.autoneg_advertised
=
251 mac
->forced_speed_duplex
= ADVERTISE_1000_FULL
;
254 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
259 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
260 adapter
->hw
.phy
.mdix
= AUTO_ALL_MODES
;
265 e_err("Unsupported Speed/Duplex configuration\n");
269 static int e1000_set_link_ksettings(struct net_device
*netdev
,
270 const struct ethtool_link_ksettings
*cmd
)
272 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
273 struct e1000_hw
*hw
= &adapter
->hw
;
277 ethtool_convert_link_mode_to_legacy_u32(&advertising
,
278 cmd
->link_modes
.advertising
);
280 pm_runtime_get_sync(netdev
->dev
.parent
);
282 /* When SoL/IDER sessions are active, autoneg/speed/duplex
285 if (hw
->phy
.ops
.check_reset_block
&&
286 hw
->phy
.ops
.check_reset_block(hw
)) {
287 e_err("Cannot change link characteristics when SoL/IDER is active.\n");
292 /* MDI setting is only allowed when autoneg enabled because
293 * some hardware doesn't allow MDI setting when speed or
296 if (cmd
->base
.eth_tp_mdix_ctrl
) {
297 if (hw
->phy
.media_type
!= e1000_media_type_copper
) {
298 ret_val
= -EOPNOTSUPP
;
302 if ((cmd
->base
.eth_tp_mdix_ctrl
!= ETH_TP_MDI_AUTO
) &&
303 (cmd
->base
.autoneg
!= AUTONEG_ENABLE
)) {
304 e_err("forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
310 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
311 usleep_range(1000, 2000);
313 if (cmd
->base
.autoneg
== AUTONEG_ENABLE
) {
315 if (hw
->phy
.media_type
== e1000_media_type_fiber
)
316 hw
->phy
.autoneg_advertised
= ADVERTISED_1000baseT_Full
|
317 ADVERTISED_FIBRE
| ADVERTISED_Autoneg
;
319 hw
->phy
.autoneg_advertised
= advertising
|
320 ADVERTISED_TP
| ADVERTISED_Autoneg
;
321 advertising
= hw
->phy
.autoneg_advertised
;
322 if (adapter
->fc_autoneg
)
323 hw
->fc
.requested_mode
= e1000_fc_default
;
325 u32 speed
= cmd
->base
.speed
;
326 /* calling this overrides forced MDI setting */
327 if (e1000_set_spd_dplx(adapter
, speed
, cmd
->base
.duplex
)) {
333 /* MDI-X => 2; MDI => 1; Auto => 3 */
334 if (cmd
->base
.eth_tp_mdix_ctrl
) {
335 /* fix up the value for auto (3 => 0) as zero is mapped
338 if (cmd
->base
.eth_tp_mdix_ctrl
== ETH_TP_MDI_AUTO
)
339 hw
->phy
.mdix
= AUTO_ALL_MODES
;
341 hw
->phy
.mdix
= cmd
->base
.eth_tp_mdix_ctrl
;
345 if (netif_running(adapter
->netdev
)) {
346 e1000e_down(adapter
, true);
349 e1000e_reset(adapter
);
353 pm_runtime_put_sync(netdev
->dev
.parent
);
354 clear_bit(__E1000_RESETTING
, &adapter
->state
);
358 static void e1000_get_pauseparam(struct net_device
*netdev
,
359 struct ethtool_pauseparam
*pause
)
361 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
362 struct e1000_hw
*hw
= &adapter
->hw
;
365 (adapter
->fc_autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
);
367 if (hw
->fc
.current_mode
== e1000_fc_rx_pause
) {
369 } else if (hw
->fc
.current_mode
== e1000_fc_tx_pause
) {
371 } else if (hw
->fc
.current_mode
== e1000_fc_full
) {
377 static int e1000_set_pauseparam(struct net_device
*netdev
,
378 struct ethtool_pauseparam
*pause
)
380 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
381 struct e1000_hw
*hw
= &adapter
->hw
;
384 adapter
->fc_autoneg
= pause
->autoneg
;
386 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
387 usleep_range(1000, 2000);
389 pm_runtime_get_sync(netdev
->dev
.parent
);
391 if (adapter
->fc_autoneg
== AUTONEG_ENABLE
) {
392 hw
->fc
.requested_mode
= e1000_fc_default
;
393 if (netif_running(adapter
->netdev
)) {
394 e1000e_down(adapter
, true);
397 e1000e_reset(adapter
);
400 if (pause
->rx_pause
&& pause
->tx_pause
)
401 hw
->fc
.requested_mode
= e1000_fc_full
;
402 else if (pause
->rx_pause
&& !pause
->tx_pause
)
403 hw
->fc
.requested_mode
= e1000_fc_rx_pause
;
404 else if (!pause
->rx_pause
&& pause
->tx_pause
)
405 hw
->fc
.requested_mode
= e1000_fc_tx_pause
;
406 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
407 hw
->fc
.requested_mode
= e1000_fc_none
;
409 hw
->fc
.current_mode
= hw
->fc
.requested_mode
;
411 if (hw
->phy
.media_type
== e1000_media_type_fiber
) {
412 retval
= hw
->mac
.ops
.setup_link(hw
);
413 /* implicit goto out */
415 retval
= e1000e_force_mac_fc(hw
);
418 e1000e_set_fc_watermarks(hw
);
423 pm_runtime_put_sync(netdev
->dev
.parent
);
424 clear_bit(__E1000_RESETTING
, &adapter
->state
);
428 static u32
e1000_get_msglevel(struct net_device
*netdev
)
430 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
431 return adapter
->msg_enable
;
434 static void e1000_set_msglevel(struct net_device
*netdev
, u32 data
)
436 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
437 adapter
->msg_enable
= data
;
440 static int e1000_get_regs_len(struct net_device __always_unused
*netdev
)
442 #define E1000_REGS_LEN 32 /* overestimate */
443 return E1000_REGS_LEN
* sizeof(u32
);
446 static void e1000_get_regs(struct net_device
*netdev
,
447 struct ethtool_regs
*regs
, void *p
)
449 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
450 struct e1000_hw
*hw
= &adapter
->hw
;
454 pm_runtime_get_sync(netdev
->dev
.parent
);
456 memset(p
, 0, E1000_REGS_LEN
* sizeof(u32
));
458 regs
->version
= (1u << 24) |
459 (adapter
->pdev
->revision
<< 16) |
460 adapter
->pdev
->device
;
462 regs_buff
[0] = er32(CTRL
);
463 regs_buff
[1] = er32(STATUS
);
465 regs_buff
[2] = er32(RCTL
);
466 regs_buff
[3] = er32(RDLEN(0));
467 regs_buff
[4] = er32(RDH(0));
468 regs_buff
[5] = er32(RDT(0));
469 regs_buff
[6] = er32(RDTR
);
471 regs_buff
[7] = er32(TCTL
);
472 regs_buff
[8] = er32(TDLEN(0));
473 regs_buff
[9] = er32(TDH(0));
474 regs_buff
[10] = er32(TDT(0));
475 regs_buff
[11] = er32(TIDV
);
477 regs_buff
[12] = adapter
->hw
.phy
.type
; /* PHY type (IGP=1, M88=0) */
479 /* ethtool doesn't use anything past this point, so all this
480 * code is likely legacy junk for apps that may or may not exist
482 if (hw
->phy
.type
== e1000_phy_m88
) {
483 e1e_rphy(hw
, M88E1000_PHY_SPEC_STATUS
, &phy_data
);
484 regs_buff
[13] = (u32
)phy_data
; /* cable length */
485 regs_buff
[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
486 regs_buff
[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
487 regs_buff
[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
488 e1e_rphy(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
489 regs_buff
[17] = (u32
)phy_data
; /* extended 10bt distance */
490 regs_buff
[18] = regs_buff
[13]; /* cable polarity */
491 regs_buff
[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
492 regs_buff
[20] = regs_buff
[17]; /* polarity correction */
493 /* phy receive errors */
494 regs_buff
[22] = adapter
->phy_stats
.receive_errors
;
495 regs_buff
[23] = regs_buff
[13]; /* mdix mode */
497 regs_buff
[21] = 0; /* was idle_errors */
498 e1e_rphy(hw
, MII_STAT1000
, &phy_data
);
499 regs_buff
[24] = (u32
)phy_data
; /* phy local receiver status */
500 regs_buff
[25] = regs_buff
[24]; /* phy remote receiver status */
502 pm_runtime_put_sync(netdev
->dev
.parent
);
505 static int e1000_get_eeprom_len(struct net_device
*netdev
)
507 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
508 return adapter
->hw
.nvm
.word_size
* 2;
511 static int e1000_get_eeprom(struct net_device
*netdev
,
512 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
514 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
515 struct e1000_hw
*hw
= &adapter
->hw
;
522 if (eeprom
->len
== 0)
525 eeprom
->magic
= adapter
->pdev
->vendor
| (adapter
->pdev
->device
<< 16);
527 first_word
= eeprom
->offset
>> 1;
528 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
530 eeprom_buff
= kmalloc(sizeof(u16
) * (last_word
- first_word
+ 1),
535 pm_runtime_get_sync(netdev
->dev
.parent
);
537 if (hw
->nvm
.type
== e1000_nvm_eeprom_spi
) {
538 ret_val
= e1000_read_nvm(hw
, first_word
,
539 last_word
- first_word
+ 1,
542 for (i
= 0; i
< last_word
- first_word
+ 1; i
++) {
543 ret_val
= e1000_read_nvm(hw
, first_word
+ i
, 1,
550 pm_runtime_put_sync(netdev
->dev
.parent
);
553 /* a read error occurred, throw away the result */
554 memset(eeprom_buff
, 0xff, sizeof(u16
) *
555 (last_word
- first_word
+ 1));
557 /* Device's eeprom is always little-endian, word addressable */
558 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
559 le16_to_cpus(&eeprom_buff
[i
]);
562 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 1), eeprom
->len
);
568 static int e1000_set_eeprom(struct net_device
*netdev
,
569 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
571 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
572 struct e1000_hw
*hw
= &adapter
->hw
;
581 if (eeprom
->len
== 0)
585 (adapter
->pdev
->vendor
| (adapter
->pdev
->device
<< 16)))
588 if (adapter
->flags
& FLAG_READ_ONLY_NVM
)
591 max_len
= hw
->nvm
.word_size
* 2;
593 first_word
= eeprom
->offset
>> 1;
594 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
595 eeprom_buff
= kmalloc(max_len
, GFP_KERNEL
);
599 ptr
= (void *)eeprom_buff
;
601 pm_runtime_get_sync(netdev
->dev
.parent
);
603 if (eeprom
->offset
& 1) {
604 /* need read/modify/write of first changed EEPROM word */
605 /* only the second byte of the word is being modified */
606 ret_val
= e1000_read_nvm(hw
, first_word
, 1, &eeprom_buff
[0]);
609 if (((eeprom
->offset
+ eeprom
->len
) & 1) && (!ret_val
))
610 /* need read/modify/write of last changed EEPROM word */
611 /* only the first byte of the word is being modified */
612 ret_val
= e1000_read_nvm(hw
, last_word
, 1,
613 &eeprom_buff
[last_word
- first_word
]);
618 /* Device's eeprom is always little-endian, word addressable */
619 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
620 le16_to_cpus(&eeprom_buff
[i
]);
622 memcpy(ptr
, bytes
, eeprom
->len
);
624 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
625 cpu_to_le16s(&eeprom_buff
[i
]);
627 ret_val
= e1000_write_nvm(hw
, first_word
,
628 last_word
- first_word
+ 1, eeprom_buff
);
633 /* Update the checksum over the first part of the EEPROM if needed
634 * and flush shadow RAM for applicable controllers
636 if ((first_word
<= NVM_CHECKSUM_REG
) ||
637 (hw
->mac
.type
== e1000_82583
) ||
638 (hw
->mac
.type
== e1000_82574
) ||
639 (hw
->mac
.type
== e1000_82573
))
640 ret_val
= e1000e_update_nvm_checksum(hw
);
643 pm_runtime_put_sync(netdev
->dev
.parent
);
648 static void e1000_get_drvinfo(struct net_device
*netdev
,
649 struct ethtool_drvinfo
*drvinfo
)
651 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
653 strlcpy(drvinfo
->driver
, e1000e_driver_name
, sizeof(drvinfo
->driver
));
654 strlcpy(drvinfo
->version
, e1000e_driver_version
,
655 sizeof(drvinfo
->version
));
657 /* EEPROM image version # is reported as firmware version # for
660 snprintf(drvinfo
->fw_version
, sizeof(drvinfo
->fw_version
),
662 (adapter
->eeprom_vers
& 0xF000) >> 12,
663 (adapter
->eeprom_vers
& 0x0FF0) >> 4,
664 (adapter
->eeprom_vers
& 0x000F));
666 strlcpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
667 sizeof(drvinfo
->bus_info
));
670 static void e1000_get_ringparam(struct net_device
*netdev
,
671 struct ethtool_ringparam
*ring
)
673 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
675 ring
->rx_max_pending
= E1000_MAX_RXD
;
676 ring
->tx_max_pending
= E1000_MAX_TXD
;
677 ring
->rx_pending
= adapter
->rx_ring_count
;
678 ring
->tx_pending
= adapter
->tx_ring_count
;
681 static int e1000_set_ringparam(struct net_device
*netdev
,
682 struct ethtool_ringparam
*ring
)
684 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
685 struct e1000_ring
*temp_tx
= NULL
, *temp_rx
= NULL
;
686 int err
= 0, size
= sizeof(struct e1000_ring
);
687 bool set_tx
= false, set_rx
= false;
688 u16 new_rx_count
, new_tx_count
;
690 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
693 new_rx_count
= clamp_t(u32
, ring
->rx_pending
, E1000_MIN_RXD
,
695 new_rx_count
= ALIGN(new_rx_count
, REQ_RX_DESCRIPTOR_MULTIPLE
);
697 new_tx_count
= clamp_t(u32
, ring
->tx_pending
, E1000_MIN_TXD
,
699 new_tx_count
= ALIGN(new_tx_count
, REQ_TX_DESCRIPTOR_MULTIPLE
);
701 if ((new_tx_count
== adapter
->tx_ring_count
) &&
702 (new_rx_count
== adapter
->rx_ring_count
))
706 while (test_and_set_bit(__E1000_RESETTING
, &adapter
->state
))
707 usleep_range(1000, 2000);
709 if (!netif_running(adapter
->netdev
)) {
710 /* Set counts now and allocate resources during open() */
711 adapter
->tx_ring
->count
= new_tx_count
;
712 adapter
->rx_ring
->count
= new_rx_count
;
713 adapter
->tx_ring_count
= new_tx_count
;
714 adapter
->rx_ring_count
= new_rx_count
;
718 set_tx
= (new_tx_count
!= adapter
->tx_ring_count
);
719 set_rx
= (new_rx_count
!= adapter
->rx_ring_count
);
721 /* Allocate temporary storage for ring updates */
723 temp_tx
= vmalloc(size
);
730 temp_rx
= vmalloc(size
);
737 pm_runtime_get_sync(netdev
->dev
.parent
);
739 e1000e_down(adapter
, true);
741 /* We can't just free everything and then setup again, because the
742 * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
743 * structs. First, attempt to allocate new resources...
746 memcpy(temp_tx
, adapter
->tx_ring
, size
);
747 temp_tx
->count
= new_tx_count
;
748 err
= e1000e_setup_tx_resources(temp_tx
);
753 memcpy(temp_rx
, adapter
->rx_ring
, size
);
754 temp_rx
->count
= new_rx_count
;
755 err
= e1000e_setup_rx_resources(temp_rx
);
760 /* ...then free the old resources and copy back any new ring data */
762 e1000e_free_tx_resources(adapter
->tx_ring
);
763 memcpy(adapter
->tx_ring
, temp_tx
, size
);
764 adapter
->tx_ring_count
= new_tx_count
;
767 e1000e_free_rx_resources(adapter
->rx_ring
);
768 memcpy(adapter
->rx_ring
, temp_rx
, size
);
769 adapter
->rx_ring_count
= new_rx_count
;
774 e1000e_free_tx_resources(temp_tx
);
777 pm_runtime_put_sync(netdev
->dev
.parent
);
782 clear_bit(__E1000_RESETTING
, &adapter
->state
);
786 static bool reg_pattern_test(struct e1000_adapter
*adapter
, u64
*data
,
787 int reg
, int offset
, u32 mask
, u32 write
)
790 static const u32 test
[] = {
791 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
793 for (pat
= 0; pat
< ARRAY_SIZE(test
); pat
++) {
794 E1000_WRITE_REG_ARRAY(&adapter
->hw
, reg
, offset
,
795 (test
[pat
] & write
));
796 val
= E1000_READ_REG_ARRAY(&adapter
->hw
, reg
, offset
);
797 if (val
!= (test
[pat
] & write
& mask
)) {
798 e_err("pattern test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
799 reg
+ (offset
<< 2), val
,
800 (test
[pat
] & write
& mask
));
808 static bool reg_set_and_check(struct e1000_adapter
*adapter
, u64
*data
,
809 int reg
, u32 mask
, u32 write
)
813 __ew32(&adapter
->hw
, reg
, write
& mask
);
814 val
= __er32(&adapter
->hw
, reg
);
815 if ((write
& mask
) != (val
& mask
)) {
816 e_err("set/check test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
817 reg
, (val
& mask
), (write
& mask
));
824 #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
826 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
829 #define REG_PATTERN_TEST(reg, mask, write) \
830 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
832 #define REG_SET_AND_CHECK(reg, mask, write) \
834 if (reg_set_and_check(adapter, data, reg, mask, write)) \
838 static int e1000_reg_test(struct e1000_adapter
*adapter
, u64
*data
)
840 struct e1000_hw
*hw
= &adapter
->hw
;
841 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
850 /* The status register is Read Only, so a write should fail.
851 * Some bits that get toggled are ignored. There are several bits
852 * on newer hardware that are r/w.
857 case e1000_80003es2lan
:
865 before
= er32(STATUS
);
866 value
= (er32(STATUS
) & toggle
);
867 ew32(STATUS
, toggle
);
868 after
= er32(STATUS
) & toggle
;
869 if (value
!= after
) {
870 e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
875 /* restore previous status */
876 ew32(STATUS
, before
);
878 if (!(adapter
->flags
& FLAG_IS_ICH
)) {
879 REG_PATTERN_TEST(E1000_FCAL
, 0xFFFFFFFF, 0xFFFFFFFF);
880 REG_PATTERN_TEST(E1000_FCAH
, 0x0000FFFF, 0xFFFFFFFF);
881 REG_PATTERN_TEST(E1000_FCT
, 0x0000FFFF, 0xFFFFFFFF);
882 REG_PATTERN_TEST(E1000_VET
, 0x0000FFFF, 0xFFFFFFFF);
885 REG_PATTERN_TEST(E1000_RDTR
, 0x0000FFFF, 0xFFFFFFFF);
886 REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
887 REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
888 REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
889 REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
890 REG_PATTERN_TEST(E1000_FCRTH
, 0x0000FFF8, 0x0000FFF8);
891 REG_PATTERN_TEST(E1000_FCTTV
, 0x0000FFFF, 0x0000FFFF);
892 REG_PATTERN_TEST(E1000_TIPG
, 0x3FFFFFFF, 0x3FFFFFFF);
893 REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
894 REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
896 REG_SET_AND_CHECK(E1000_RCTL
, 0xFFFFFFFF, 0x00000000);
898 before
= ((adapter
->flags
& FLAG_IS_ICH
) ? 0x06C3B33E : 0x06DFB3FE);
899 REG_SET_AND_CHECK(E1000_RCTL
, before
, 0x003FFFFB);
900 REG_SET_AND_CHECK(E1000_TCTL
, 0xFFFFFFFF, 0x00000000);
902 REG_SET_AND_CHECK(E1000_RCTL
, before
, 0xFFFFFFFF);
903 REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
904 if (!(adapter
->flags
& FLAG_IS_ICH
))
905 REG_PATTERN_TEST(E1000_TXCW
, 0xC000FFFF, 0x0000FFFF);
906 REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
907 REG_PATTERN_TEST(E1000_TIDV
, 0x0000FFFF, 0x0000FFFF);
923 if (mac
->type
>= e1000_pch_lpt
)
924 wlock_mac
= (er32(FWSM
) & E1000_FWSM_WLOCK_MAC_MASK
) >>
925 E1000_FWSM_WLOCK_MAC_SHIFT
;
927 for (i
= 0; i
< mac
->rar_entry_count
; i
++) {
928 if (mac
->type
>= e1000_pch_lpt
) {
929 /* Cannot test write-protected SHRAL[n] registers */
930 if ((wlock_mac
== 1) || (wlock_mac
&& (i
> wlock_mac
)))
933 /* SHRAH[9] different than the others */
939 if (mac
->type
== e1000_pch2lan
) {
940 /* SHRAH[0,1,2] different than previous */
943 /* SHRAH[3] different than SHRAH[0,1,2] */
946 /* RAR[1-6] owned by management engine - skipping */
951 REG_PATTERN_TEST_ARRAY(E1000_RA
, ((i
<< 1) + 1), mask
,
953 /* reset index to actual value */
954 if ((mac
->type
== e1000_pch2lan
) && (i
> 6))
958 for (i
= 0; i
< mac
->mta_reg_count
; i
++)
959 REG_PATTERN_TEST_ARRAY(E1000_MTA
, i
, 0xFFFFFFFF, 0xFFFFFFFF);
966 static int e1000_eeprom_test(struct e1000_adapter
*adapter
, u64
*data
)
973 /* Read and add up the contents of the EEPROM */
974 for (i
= 0; i
< (NVM_CHECKSUM_REG
+ 1); i
++) {
975 if ((e1000_read_nvm(&adapter
->hw
, i
, 1, &temp
)) < 0) {
982 /* If Checksum is not Correct return error else test passed */
983 if ((checksum
!= (u16
)NVM_SUM
) && !(*data
))
989 static irqreturn_t
e1000_test_intr(int __always_unused irq
, void *data
)
991 struct net_device
*netdev
= (struct net_device
*)data
;
992 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
993 struct e1000_hw
*hw
= &adapter
->hw
;
995 adapter
->test_icr
|= er32(ICR
);
1000 static int e1000_intr_test(struct e1000_adapter
*adapter
, u64
*data
)
1002 struct net_device
*netdev
= adapter
->netdev
;
1003 struct e1000_hw
*hw
= &adapter
->hw
;
1006 u32 irq
= adapter
->pdev
->irq
;
1009 int int_mode
= E1000E_INT_MODE_LEGACY
;
1013 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
1014 if (adapter
->int_mode
== E1000E_INT_MODE_MSIX
) {
1015 int_mode
= adapter
->int_mode
;
1016 e1000e_reset_interrupt_capability(adapter
);
1017 adapter
->int_mode
= E1000E_INT_MODE_LEGACY
;
1018 e1000e_set_interrupt_capability(adapter
);
1020 /* Hook up test interrupt handler just for this test */
1021 if (!request_irq(irq
, e1000_test_intr
, IRQF_PROBE_SHARED
, netdev
->name
,
1024 } else if (request_irq(irq
, e1000_test_intr
, IRQF_SHARED
, netdev
->name
,
1030 e_info("testing %s interrupt\n", (shared_int
? "shared" : "unshared"));
1032 /* Disable all the interrupts */
1033 ew32(IMC
, 0xFFFFFFFF);
1035 usleep_range(10000, 20000);
1037 /* Test each interrupt */
1038 for (i
= 0; i
< 10; i
++) {
1039 /* Interrupt to test */
1042 if (adapter
->flags
& FLAG_IS_ICH
) {
1044 case E1000_ICR_RXSEQ
:
1047 if (adapter
->hw
.mac
.type
== e1000_ich8lan
||
1048 adapter
->hw
.mac
.type
== e1000_ich9lan
)
1057 /* Disable the interrupt to be reported in
1058 * the cause register and then force the same
1059 * interrupt and see if one gets posted. If
1060 * an interrupt was posted to the bus, the
1063 adapter
->test_icr
= 0;
1067 usleep_range(10000, 20000);
1069 if (adapter
->test_icr
& mask
) {
1075 /* Enable the interrupt to be reported in
1076 * the cause register and then force the same
1077 * interrupt and see if one gets posted. If
1078 * an interrupt was not posted to the bus, the
1081 adapter
->test_icr
= 0;
1085 usleep_range(10000, 20000);
1087 if (!(adapter
->test_icr
& mask
)) {
1093 /* Disable the other interrupts to be reported in
1094 * the cause register and then force the other
1095 * interrupts and see if any get posted. If
1096 * an interrupt was posted to the bus, the
1099 adapter
->test_icr
= 0;
1100 ew32(IMC
, ~mask
& 0x00007FFF);
1101 ew32(ICS
, ~mask
& 0x00007FFF);
1103 usleep_range(10000, 20000);
1105 if (adapter
->test_icr
) {
1112 /* Disable all the interrupts */
1113 ew32(IMC
, 0xFFFFFFFF);
1115 usleep_range(10000, 20000);
1117 /* Unhook test interrupt handler */
1118 free_irq(irq
, netdev
);
1121 if (int_mode
== E1000E_INT_MODE_MSIX
) {
1122 e1000e_reset_interrupt_capability(adapter
);
1123 adapter
->int_mode
= int_mode
;
1124 e1000e_set_interrupt_capability(adapter
);
1130 static void e1000_free_desc_rings(struct e1000_adapter
*adapter
)
1132 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1133 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1134 struct pci_dev
*pdev
= adapter
->pdev
;
1135 struct e1000_buffer
*buffer_info
;
1138 if (tx_ring
->desc
&& tx_ring
->buffer_info
) {
1139 for (i
= 0; i
< tx_ring
->count
; i
++) {
1140 buffer_info
= &tx_ring
->buffer_info
[i
];
1142 if (buffer_info
->dma
)
1143 dma_unmap_single(&pdev
->dev
,
1145 buffer_info
->length
,
1147 if (buffer_info
->skb
)
1148 dev_kfree_skb(buffer_info
->skb
);
1152 if (rx_ring
->desc
&& rx_ring
->buffer_info
) {
1153 for (i
= 0; i
< rx_ring
->count
; i
++) {
1154 buffer_info
= &rx_ring
->buffer_info
[i
];
1156 if (buffer_info
->dma
)
1157 dma_unmap_single(&pdev
->dev
,
1159 2048, DMA_FROM_DEVICE
);
1160 if (buffer_info
->skb
)
1161 dev_kfree_skb(buffer_info
->skb
);
1165 if (tx_ring
->desc
) {
1166 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
1168 tx_ring
->desc
= NULL
;
1170 if (rx_ring
->desc
) {
1171 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
1173 rx_ring
->desc
= NULL
;
1176 kfree(tx_ring
->buffer_info
);
1177 tx_ring
->buffer_info
= NULL
;
1178 kfree(rx_ring
->buffer_info
);
1179 rx_ring
->buffer_info
= NULL
;
1182 static int e1000_setup_desc_rings(struct e1000_adapter
*adapter
)
1184 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1185 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1186 struct pci_dev
*pdev
= adapter
->pdev
;
1187 struct e1000_hw
*hw
= &adapter
->hw
;
1192 /* Setup Tx descriptor ring and Tx buffers */
1194 if (!tx_ring
->count
)
1195 tx_ring
->count
= E1000_DEFAULT_TXD
;
1197 tx_ring
->buffer_info
= kcalloc(tx_ring
->count
,
1198 sizeof(struct e1000_buffer
), GFP_KERNEL
);
1199 if (!tx_ring
->buffer_info
) {
1204 tx_ring
->size
= tx_ring
->count
* sizeof(struct e1000_tx_desc
);
1205 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1206 tx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, tx_ring
->size
,
1207 &tx_ring
->dma
, GFP_KERNEL
);
1208 if (!tx_ring
->desc
) {
1212 tx_ring
->next_to_use
= 0;
1213 tx_ring
->next_to_clean
= 0;
1215 ew32(TDBAL(0), ((u64
)tx_ring
->dma
& 0x00000000FFFFFFFF));
1216 ew32(TDBAH(0), ((u64
)tx_ring
->dma
>> 32));
1217 ew32(TDLEN(0), tx_ring
->count
* sizeof(struct e1000_tx_desc
));
1220 ew32(TCTL
, E1000_TCTL_PSP
| E1000_TCTL_EN
| E1000_TCTL_MULR
|
1221 E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
|
1222 E1000_COLLISION_DISTANCE
<< E1000_COLD_SHIFT
);
1224 for (i
= 0; i
< tx_ring
->count
; i
++) {
1225 struct e1000_tx_desc
*tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
1226 struct sk_buff
*skb
;
1227 unsigned int skb_size
= 1024;
1229 skb
= alloc_skb(skb_size
, GFP_KERNEL
);
1234 skb_put(skb
, skb_size
);
1235 tx_ring
->buffer_info
[i
].skb
= skb
;
1236 tx_ring
->buffer_info
[i
].length
= skb
->len
;
1237 tx_ring
->buffer_info
[i
].dma
=
1238 dma_map_single(&pdev
->dev
, skb
->data
, skb
->len
,
1240 if (dma_mapping_error(&pdev
->dev
,
1241 tx_ring
->buffer_info
[i
].dma
)) {
1245 tx_desc
->buffer_addr
= cpu_to_le64(tx_ring
->buffer_info
[i
].dma
);
1246 tx_desc
->lower
.data
= cpu_to_le32(skb
->len
);
1247 tx_desc
->lower
.data
|= cpu_to_le32(E1000_TXD_CMD_EOP
|
1248 E1000_TXD_CMD_IFCS
|
1250 tx_desc
->upper
.data
= 0;
1253 /* Setup Rx descriptor ring and Rx buffers */
1255 if (!rx_ring
->count
)
1256 rx_ring
->count
= E1000_DEFAULT_RXD
;
1258 rx_ring
->buffer_info
= kcalloc(rx_ring
->count
,
1259 sizeof(struct e1000_buffer
), GFP_KERNEL
);
1260 if (!rx_ring
->buffer_info
) {
1265 rx_ring
->size
= rx_ring
->count
* sizeof(union e1000_rx_desc_extended
);
1266 rx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, rx_ring
->size
,
1267 &rx_ring
->dma
, GFP_KERNEL
);
1268 if (!rx_ring
->desc
) {
1272 rx_ring
->next_to_use
= 0;
1273 rx_ring
->next_to_clean
= 0;
1276 if (!(adapter
->flags2
& FLAG2_NO_DISABLE_RX
))
1277 ew32(RCTL
, rctl
& ~E1000_RCTL_EN
);
1278 ew32(RDBAL(0), ((u64
)rx_ring
->dma
& 0xFFFFFFFF));
1279 ew32(RDBAH(0), ((u64
)rx_ring
->dma
>> 32));
1280 ew32(RDLEN(0), rx_ring
->size
);
1283 rctl
= E1000_RCTL_EN
| E1000_RCTL_BAM
| E1000_RCTL_SZ_2048
|
1284 E1000_RCTL_UPE
| E1000_RCTL_MPE
| E1000_RCTL_LPE
|
1285 E1000_RCTL_SBP
| E1000_RCTL_SECRC
|
1286 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1287 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1290 for (i
= 0; i
< rx_ring
->count
; i
++) {
1291 union e1000_rx_desc_extended
*rx_desc
;
1292 struct sk_buff
*skb
;
1294 skb
= alloc_skb(2048 + NET_IP_ALIGN
, GFP_KERNEL
);
1299 skb_reserve(skb
, NET_IP_ALIGN
);
1300 rx_ring
->buffer_info
[i
].skb
= skb
;
1301 rx_ring
->buffer_info
[i
].dma
=
1302 dma_map_single(&pdev
->dev
, skb
->data
, 2048,
1304 if (dma_mapping_error(&pdev
->dev
,
1305 rx_ring
->buffer_info
[i
].dma
)) {
1309 rx_desc
= E1000_RX_DESC_EXT(*rx_ring
, i
);
1310 rx_desc
->read
.buffer_addr
=
1311 cpu_to_le64(rx_ring
->buffer_info
[i
].dma
);
1312 memset(skb
->data
, 0x00, skb
->len
);
1318 e1000_free_desc_rings(adapter
);
1322 static void e1000_phy_disable_receiver(struct e1000_adapter
*adapter
)
1324 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1325 e1e_wphy(&adapter
->hw
, 29, 0x001F);
1326 e1e_wphy(&adapter
->hw
, 30, 0x8FFC);
1327 e1e_wphy(&adapter
->hw
, 29, 0x001A);
1328 e1e_wphy(&adapter
->hw
, 30, 0x8FF0);
1331 static int e1000_integrated_phy_loopback(struct e1000_adapter
*adapter
)
1333 struct e1000_hw
*hw
= &adapter
->hw
;
1338 hw
->mac
.autoneg
= 0;
1340 if (hw
->phy
.type
== e1000_phy_ife
) {
1341 /* force 100, set loopback */
1342 e1e_wphy(hw
, MII_BMCR
, 0x6100);
1344 /* Now set up the MAC to the same speed/duplex as the PHY. */
1345 ctrl_reg
= er32(CTRL
);
1346 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1347 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1348 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1349 E1000_CTRL_SPD_100
|/* Force Speed to 100 */
1350 E1000_CTRL_FD
); /* Force Duplex to FULL */
1352 ew32(CTRL
, ctrl_reg
);
1354 usleep_range(500, 1000);
1359 /* Specific PHY configuration for loopback */
1360 switch (hw
->phy
.type
) {
1362 /* Auto-MDI/MDIX Off */
1363 e1e_wphy(hw
, M88E1000_PHY_SPEC_CTRL
, 0x0808);
1364 /* reset to update Auto-MDI/MDIX */
1365 e1e_wphy(hw
, MII_BMCR
, 0x9140);
1367 e1e_wphy(hw
, MII_BMCR
, 0x8140);
1369 case e1000_phy_gg82563
:
1370 e1e_wphy(hw
, GG82563_PHY_KMRN_MODE_CTRL
, 0x1CC);
1373 /* Set Default MAC Interface speed to 1GB */
1374 e1e_rphy(hw
, PHY_REG(2, 21), &phy_reg
);
1377 e1e_wphy(hw
, PHY_REG(2, 21), phy_reg
);
1378 /* Assert SW reset for above settings to take effect */
1379 hw
->phy
.ops
.commit(hw
);
1380 usleep_range(1000, 2000);
1381 /* Force Full Duplex */
1382 e1e_rphy(hw
, PHY_REG(769, 16), &phy_reg
);
1383 e1e_wphy(hw
, PHY_REG(769, 16), phy_reg
| 0x000C);
1384 /* Set Link Up (in force link) */
1385 e1e_rphy(hw
, PHY_REG(776, 16), &phy_reg
);
1386 e1e_wphy(hw
, PHY_REG(776, 16), phy_reg
| 0x0040);
1388 e1e_rphy(hw
, PHY_REG(769, 16), &phy_reg
);
1389 e1e_wphy(hw
, PHY_REG(769, 16), phy_reg
| 0x0040);
1390 /* Set Early Link Enable */
1391 e1e_rphy(hw
, PHY_REG(769, 20), &phy_reg
);
1392 e1e_wphy(hw
, PHY_REG(769, 20), phy_reg
| 0x0400);
1394 case e1000_phy_82577
:
1395 case e1000_phy_82578
:
1396 /* Workaround: K1 must be disabled for stable 1Gbps operation */
1397 ret_val
= hw
->phy
.ops
.acquire(hw
);
1399 e_err("Cannot setup 1Gbps loopback.\n");
1402 e1000_configure_k1_ich8lan(hw
, false);
1403 hw
->phy
.ops
.release(hw
);
1405 case e1000_phy_82579
:
1406 /* Disable PHY energy detect power down */
1407 e1e_rphy(hw
, PHY_REG(0, 21), &phy_reg
);
1408 e1e_wphy(hw
, PHY_REG(0, 21), phy_reg
& ~BIT(3));
1409 /* Disable full chip energy detect */
1410 e1e_rphy(hw
, PHY_REG(776, 18), &phy_reg
);
1411 e1e_wphy(hw
, PHY_REG(776, 18), phy_reg
| 1);
1412 /* Enable loopback on the PHY */
1413 e1e_wphy(hw
, I82577_PHY_LBK_CTRL
, 0x8001);
1419 /* force 1000, set loopback */
1420 e1e_wphy(hw
, MII_BMCR
, 0x4140);
1423 /* Now set up the MAC to the same speed/duplex as the PHY. */
1424 ctrl_reg
= er32(CTRL
);
1425 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1426 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1427 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1428 E1000_CTRL_SPD_1000
|/* Force Speed to 1000 */
1429 E1000_CTRL_FD
); /* Force Duplex to FULL */
1431 if (adapter
->flags
& FLAG_IS_ICH
)
1432 ctrl_reg
|= E1000_CTRL_SLU
; /* Set Link Up */
1434 if (hw
->phy
.media_type
== e1000_media_type_copper
&&
1435 hw
->phy
.type
== e1000_phy_m88
) {
1436 ctrl_reg
|= E1000_CTRL_ILOS
; /* Invert Loss of Signal */
1438 /* Set the ILOS bit on the fiber Nic if half duplex link is
1441 if ((er32(STATUS
) & E1000_STATUS_FD
) == 0)
1442 ctrl_reg
|= (E1000_CTRL_ILOS
| E1000_CTRL_SLU
);
1445 ew32(CTRL
, ctrl_reg
);
1447 /* Disable the receiver on the PHY so when a cable is plugged in, the
1448 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1450 if (hw
->phy
.type
== e1000_phy_m88
)
1451 e1000_phy_disable_receiver(adapter
);
1453 usleep_range(500, 1000);
1458 static int e1000_set_82571_fiber_loopback(struct e1000_adapter
*adapter
)
1460 struct e1000_hw
*hw
= &adapter
->hw
;
1461 u32 ctrl
= er32(CTRL
);
1464 /* special requirements for 82571/82572 fiber adapters */
1466 /* jump through hoops to make sure link is up because serdes
1467 * link is hardwired up
1469 ctrl
|= E1000_CTRL_SLU
;
1472 /* disable autoneg */
1477 link
= (er32(STATUS
) & E1000_STATUS_LU
);
1480 /* set invert loss of signal */
1482 ctrl
|= E1000_CTRL_ILOS
;
1486 /* special write to serdes control register to enable SerDes analog
1489 ew32(SCTL
, E1000_SCTL_ENABLE_SERDES_LOOPBACK
);
1491 usleep_range(10000, 20000);
1496 /* only call this for fiber/serdes connections to es2lan */
1497 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter
*adapter
)
1499 struct e1000_hw
*hw
= &adapter
->hw
;
1500 u32 ctrlext
= er32(CTRL_EXT
);
1501 u32 ctrl
= er32(CTRL
);
1503 /* save CTRL_EXT to restore later, reuse an empty variable (unused
1504 * on mac_type 80003es2lan)
1506 adapter
->tx_fifo_head
= ctrlext
;
1508 /* clear the serdes mode bits, putting the device into mac loopback */
1509 ctrlext
&= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES
;
1510 ew32(CTRL_EXT
, ctrlext
);
1512 /* force speed to 1000/FD, link up */
1513 ctrl
&= ~(E1000_CTRL_SPD_1000
| E1000_CTRL_SPD_100
);
1514 ctrl
|= (E1000_CTRL_SLU
| E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
|
1515 E1000_CTRL_SPD_1000
| E1000_CTRL_FD
);
1518 /* set mac loopback */
1520 ctrl
|= E1000_RCTL_LBM_MAC
;
1523 /* set testing mode parameters (no need to reset later) */
1524 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
1525 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1527 (KMRNCTRLSTA_OPMODE
| KMRNCTRLSTA_OPMODE_1GB_FD_GMII
));
1532 static int e1000_setup_loopback_test(struct e1000_adapter
*adapter
)
1534 struct e1000_hw
*hw
= &adapter
->hw
;
1535 u32 rctl
, fext_nvm11
, tarc0
;
1537 if (hw
->mac
.type
>= e1000_pch_spt
) {
1538 fext_nvm11
= er32(FEXTNVM11
);
1539 fext_nvm11
|= E1000_FEXTNVM11_DISABLE_MULR_FIX
;
1540 ew32(FEXTNVM11
, fext_nvm11
);
1541 tarc0
= er32(TARC(0));
1542 /* clear bits 28 & 29 (control of MULR concurrent requests) */
1543 tarc0
&= 0xcfffffff;
1544 /* set bit 29 (value of MULR requests is now 2) */
1545 tarc0
|= 0x20000000;
1546 ew32(TARC(0), tarc0
);
1548 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1549 hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1550 switch (hw
->mac
.type
) {
1551 case e1000_80003es2lan
:
1552 return e1000_set_es2lan_mac_loopback(adapter
);
1555 return e1000_set_82571_fiber_loopback(adapter
);
1558 rctl
|= E1000_RCTL_LBM_TCVR
;
1562 } else if (hw
->phy
.media_type
== e1000_media_type_copper
) {
1563 return e1000_integrated_phy_loopback(adapter
);
1569 static void e1000_loopback_cleanup(struct e1000_adapter
*adapter
)
1571 struct e1000_hw
*hw
= &adapter
->hw
;
1572 u32 rctl
, fext_nvm11
, tarc0
;
1576 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
1579 switch (hw
->mac
.type
) {
1582 fext_nvm11
= er32(FEXTNVM11
);
1583 fext_nvm11
&= ~E1000_FEXTNVM11_DISABLE_MULR_FIX
;
1584 ew32(FEXTNVM11
, fext_nvm11
);
1585 tarc0
= er32(TARC(0));
1586 /* clear bits 28 & 29 (control of MULR concurrent requests) */
1587 /* set bit 29 (value of MULR requests is now 0) */
1588 tarc0
&= 0xcfffffff;
1589 ew32(TARC(0), tarc0
);
1591 case e1000_80003es2lan
:
1592 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1593 hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1594 /* restore CTRL_EXT, stealing space from tx_fifo_head */
1595 ew32(CTRL_EXT
, adapter
->tx_fifo_head
);
1596 adapter
->tx_fifo_head
= 0;
1601 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1602 hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1603 ew32(SCTL
, E1000_SCTL_DISABLE_SERDES_LOOPBACK
);
1605 usleep_range(10000, 20000);
1610 hw
->mac
.autoneg
= 1;
1611 if (hw
->phy
.type
== e1000_phy_gg82563
)
1612 e1e_wphy(hw
, GG82563_PHY_KMRN_MODE_CTRL
, 0x180);
1613 e1e_rphy(hw
, MII_BMCR
, &phy_reg
);
1614 if (phy_reg
& BMCR_LOOPBACK
) {
1615 phy_reg
&= ~BMCR_LOOPBACK
;
1616 e1e_wphy(hw
, MII_BMCR
, phy_reg
);
1617 if (hw
->phy
.ops
.commit
)
1618 hw
->phy
.ops
.commit(hw
);
1624 static void e1000_create_lbtest_frame(struct sk_buff
*skb
,
1625 unsigned int frame_size
)
1627 memset(skb
->data
, 0xFF, frame_size
);
1629 memset(&skb
->data
[frame_size
/ 2], 0xAA, frame_size
/ 2 - 1);
1630 memset(&skb
->data
[frame_size
/ 2 + 10], 0xBE, 1);
1631 memset(&skb
->data
[frame_size
/ 2 + 12], 0xAF, 1);
1634 static int e1000_check_lbtest_frame(struct sk_buff
*skb
,
1635 unsigned int frame_size
)
1638 if (*(skb
->data
+ 3) == 0xFF)
1639 if ((*(skb
->data
+ frame_size
/ 2 + 10) == 0xBE) &&
1640 (*(skb
->data
+ frame_size
/ 2 + 12) == 0xAF))
1645 static int e1000_run_loopback_test(struct e1000_adapter
*adapter
)
1647 struct e1000_ring
*tx_ring
= &adapter
->test_tx_ring
;
1648 struct e1000_ring
*rx_ring
= &adapter
->test_rx_ring
;
1649 struct pci_dev
*pdev
= adapter
->pdev
;
1650 struct e1000_hw
*hw
= &adapter
->hw
;
1651 struct e1000_buffer
*buffer_info
;
1658 ew32(RDT(0), rx_ring
->count
- 1);
1660 /* Calculate the loop count based on the largest descriptor ring
1661 * The idea is to wrap the largest ring a number of times using 64
1662 * send/receive pairs during each loop
1665 if (rx_ring
->count
<= tx_ring
->count
)
1666 lc
= ((tx_ring
->count
/ 64) * 2) + 1;
1668 lc
= ((rx_ring
->count
/ 64) * 2) + 1;
1672 /* loop count loop */
1673 for (j
= 0; j
<= lc
; j
++) {
1674 /* send the packets */
1675 for (i
= 0; i
< 64; i
++) {
1676 buffer_info
= &tx_ring
->buffer_info
[k
];
1678 e1000_create_lbtest_frame(buffer_info
->skb
, 1024);
1679 dma_sync_single_for_device(&pdev
->dev
,
1681 buffer_info
->length
,
1684 if (k
== tx_ring
->count
)
1690 time
= jiffies
; /* set the start time for the receive */
1692 /* receive the sent packets */
1694 buffer_info
= &rx_ring
->buffer_info
[l
];
1696 dma_sync_single_for_cpu(&pdev
->dev
,
1697 buffer_info
->dma
, 2048,
1700 ret_val
= e1000_check_lbtest_frame(buffer_info
->skb
,
1705 if (l
== rx_ring
->count
)
1707 /* time + 20 msecs (200 msecs on 2.4) is more than
1708 * enough time to complete the receives, if it's
1709 * exceeded, break and error off
1711 } while ((good_cnt
< 64) && !time_after(jiffies
, time
+ 20));
1712 if (good_cnt
!= 64) {
1713 ret_val
= 13; /* ret_val is the same as mis-compare */
1716 if (time_after(jiffies
, time
+ 20)) {
1717 ret_val
= 14; /* error code for time out error */
1724 static int e1000_loopback_test(struct e1000_adapter
*adapter
, u64
*data
)
1726 struct e1000_hw
*hw
= &adapter
->hw
;
1728 /* PHY loopback cannot be performed if SoL/IDER sessions are active */
1729 if (hw
->phy
.ops
.check_reset_block
&&
1730 hw
->phy
.ops
.check_reset_block(hw
)) {
1731 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
1736 *data
= e1000_setup_desc_rings(adapter
);
1740 *data
= e1000_setup_loopback_test(adapter
);
1744 *data
= e1000_run_loopback_test(adapter
);
1745 e1000_loopback_cleanup(adapter
);
1748 e1000_free_desc_rings(adapter
);
1753 static int e1000_link_test(struct e1000_adapter
*adapter
, u64
*data
)
1755 struct e1000_hw
*hw
= &adapter
->hw
;
1758 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1761 hw
->mac
.serdes_has_link
= false;
1763 /* On some blade server designs, link establishment
1764 * could take as long as 2-3 minutes
1767 hw
->mac
.ops
.check_for_link(hw
);
1768 if (hw
->mac
.serdes_has_link
)
1771 } while (i
++ < 3750);
1775 hw
->mac
.ops
.check_for_link(hw
);
1776 if (hw
->mac
.autoneg
)
1777 /* On some Phy/switch combinations, link establishment
1778 * can take a few seconds more than expected.
1780 msleep_interruptible(5000);
1782 if (!(er32(STATUS
) & E1000_STATUS_LU
))
1788 static int e1000e_get_sset_count(struct net_device __always_unused
*netdev
,
1793 return E1000_TEST_LEN
;
1795 return E1000_STATS_LEN
;
1801 static void e1000_diag_test(struct net_device
*netdev
,
1802 struct ethtool_test
*eth_test
, u64
*data
)
1804 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1805 u16 autoneg_advertised
;
1806 u8 forced_speed_duplex
;
1808 bool if_running
= netif_running(netdev
);
1810 pm_runtime_get_sync(netdev
->dev
.parent
);
1812 set_bit(__E1000_TESTING
, &adapter
->state
);
1815 /* Get control of and reset hardware */
1816 if (adapter
->flags
& FLAG_HAS_AMT
)
1817 e1000e_get_hw_control(adapter
);
1819 e1000e_power_up_phy(adapter
);
1821 adapter
->hw
.phy
.autoneg_wait_to_complete
= 1;
1822 e1000e_reset(adapter
);
1823 adapter
->hw
.phy
.autoneg_wait_to_complete
= 0;
1826 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1829 /* save speed, duplex, autoneg settings */
1830 autoneg_advertised
= adapter
->hw
.phy
.autoneg_advertised
;
1831 forced_speed_duplex
= adapter
->hw
.mac
.forced_speed_duplex
;
1832 autoneg
= adapter
->hw
.mac
.autoneg
;
1834 e_info("offline testing starting\n");
1837 /* indicate we're in test mode */
1838 e1000e_close(netdev
);
1840 if (e1000_reg_test(adapter
, &data
[0]))
1841 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1843 e1000e_reset(adapter
);
1844 if (e1000_eeprom_test(adapter
, &data
[1]))
1845 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1847 e1000e_reset(adapter
);
1848 if (e1000_intr_test(adapter
, &data
[2]))
1849 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1851 e1000e_reset(adapter
);
1852 if (e1000_loopback_test(adapter
, &data
[3]))
1853 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1855 /* force this routine to wait until autoneg complete/timeout */
1856 adapter
->hw
.phy
.autoneg_wait_to_complete
= 1;
1857 e1000e_reset(adapter
);
1858 adapter
->hw
.phy
.autoneg_wait_to_complete
= 0;
1860 if (e1000_link_test(adapter
, &data
[4]))
1861 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1863 /* restore speed, duplex, autoneg settings */
1864 adapter
->hw
.phy
.autoneg_advertised
= autoneg_advertised
;
1865 adapter
->hw
.mac
.forced_speed_duplex
= forced_speed_duplex
;
1866 adapter
->hw
.mac
.autoneg
= autoneg
;
1867 e1000e_reset(adapter
);
1869 clear_bit(__E1000_TESTING
, &adapter
->state
);
1871 e1000e_open(netdev
);
1875 e_info("online testing starting\n");
1877 /* register, eeprom, intr and loopback tests not run online */
1883 if (e1000_link_test(adapter
, &data
[4]))
1884 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1886 clear_bit(__E1000_TESTING
, &adapter
->state
);
1890 e1000e_reset(adapter
);
1892 if (adapter
->flags
& FLAG_HAS_AMT
)
1893 e1000e_release_hw_control(adapter
);
1896 msleep_interruptible(4 * 1000);
1898 pm_runtime_put_sync(netdev
->dev
.parent
);
1901 static void e1000_get_wol(struct net_device
*netdev
,
1902 struct ethtool_wolinfo
*wol
)
1904 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1909 if (!(adapter
->flags
& FLAG_HAS_WOL
) ||
1910 !device_can_wakeup(&adapter
->pdev
->dev
))
1913 wol
->supported
= WAKE_UCAST
| WAKE_MCAST
|
1914 WAKE_BCAST
| WAKE_MAGIC
| WAKE_PHY
;
1916 /* apply any specific unsupported masks here */
1917 if (adapter
->flags
& FLAG_NO_WAKE_UCAST
) {
1918 wol
->supported
&= ~WAKE_UCAST
;
1920 if (adapter
->wol
& E1000_WUFC_EX
)
1921 e_err("Interface does not support directed (unicast) frame wake-up packets\n");
1924 if (adapter
->wol
& E1000_WUFC_EX
)
1925 wol
->wolopts
|= WAKE_UCAST
;
1926 if (adapter
->wol
& E1000_WUFC_MC
)
1927 wol
->wolopts
|= WAKE_MCAST
;
1928 if (adapter
->wol
& E1000_WUFC_BC
)
1929 wol
->wolopts
|= WAKE_BCAST
;
1930 if (adapter
->wol
& E1000_WUFC_MAG
)
1931 wol
->wolopts
|= WAKE_MAGIC
;
1932 if (adapter
->wol
& E1000_WUFC_LNKC
)
1933 wol
->wolopts
|= WAKE_PHY
;
1936 static int e1000_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1938 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1940 if (!(adapter
->flags
& FLAG_HAS_WOL
) ||
1941 !device_can_wakeup(&adapter
->pdev
->dev
) ||
1942 (wol
->wolopts
& ~(WAKE_UCAST
| WAKE_MCAST
| WAKE_BCAST
|
1943 WAKE_MAGIC
| WAKE_PHY
)))
1946 /* these settings will always override what we currently have */
1949 if (wol
->wolopts
& WAKE_UCAST
)
1950 adapter
->wol
|= E1000_WUFC_EX
;
1951 if (wol
->wolopts
& WAKE_MCAST
)
1952 adapter
->wol
|= E1000_WUFC_MC
;
1953 if (wol
->wolopts
& WAKE_BCAST
)
1954 adapter
->wol
|= E1000_WUFC_BC
;
1955 if (wol
->wolopts
& WAKE_MAGIC
)
1956 adapter
->wol
|= E1000_WUFC_MAG
;
1957 if (wol
->wolopts
& WAKE_PHY
)
1958 adapter
->wol
|= E1000_WUFC_LNKC
;
1960 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
1965 static int e1000_set_phys_id(struct net_device
*netdev
,
1966 enum ethtool_phys_id_state state
)
1968 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
1969 struct e1000_hw
*hw
= &adapter
->hw
;
1972 case ETHTOOL_ID_ACTIVE
:
1973 pm_runtime_get_sync(netdev
->dev
.parent
);
1975 if (!hw
->mac
.ops
.blink_led
)
1976 return 2; /* cycle on/off twice per second */
1978 hw
->mac
.ops
.blink_led(hw
);
1981 case ETHTOOL_ID_INACTIVE
:
1982 if (hw
->phy
.type
== e1000_phy_ife
)
1983 e1e_wphy(hw
, IFE_PHY_SPECIAL_CONTROL_LED
, 0);
1984 hw
->mac
.ops
.led_off(hw
);
1985 hw
->mac
.ops
.cleanup_led(hw
);
1986 pm_runtime_put_sync(netdev
->dev
.parent
);
1990 hw
->mac
.ops
.led_on(hw
);
1993 case ETHTOOL_ID_OFF
:
1994 hw
->mac
.ops
.led_off(hw
);
2001 static int e1000_get_coalesce(struct net_device
*netdev
,
2002 struct ethtool_coalesce
*ec
)
2004 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2006 if (adapter
->itr_setting
<= 4)
2007 ec
->rx_coalesce_usecs
= adapter
->itr_setting
;
2009 ec
->rx_coalesce_usecs
= 1000000 / adapter
->itr_setting
;
2014 static int e1000_set_coalesce(struct net_device
*netdev
,
2015 struct ethtool_coalesce
*ec
)
2017 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2019 if ((ec
->rx_coalesce_usecs
> E1000_MAX_ITR_USECS
) ||
2020 ((ec
->rx_coalesce_usecs
> 4) &&
2021 (ec
->rx_coalesce_usecs
< E1000_MIN_ITR_USECS
)) ||
2022 (ec
->rx_coalesce_usecs
== 2))
2025 if (ec
->rx_coalesce_usecs
== 4) {
2026 adapter
->itr_setting
= 4;
2027 adapter
->itr
= adapter
->itr_setting
;
2028 } else if (ec
->rx_coalesce_usecs
<= 3) {
2029 adapter
->itr
= 20000;
2030 adapter
->itr_setting
= ec
->rx_coalesce_usecs
;
2032 adapter
->itr
= (1000000 / ec
->rx_coalesce_usecs
);
2033 adapter
->itr_setting
= adapter
->itr
& ~3;
2036 pm_runtime_get_sync(netdev
->dev
.parent
);
2038 if (adapter
->itr_setting
!= 0)
2039 e1000e_write_itr(adapter
, adapter
->itr
);
2041 e1000e_write_itr(adapter
, 0);
2043 pm_runtime_put_sync(netdev
->dev
.parent
);
2048 static int e1000_nway_reset(struct net_device
*netdev
)
2050 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2052 if (!netif_running(netdev
))
2055 if (!adapter
->hw
.mac
.autoneg
)
2058 pm_runtime_get_sync(netdev
->dev
.parent
);
2059 e1000e_reinit_locked(adapter
);
2060 pm_runtime_put_sync(netdev
->dev
.parent
);
2065 static void e1000_get_ethtool_stats(struct net_device
*netdev
,
2066 struct ethtool_stats __always_unused
*stats
,
2069 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2070 struct rtnl_link_stats64 net_stats
;
2074 pm_runtime_get_sync(netdev
->dev
.parent
);
2076 dev_get_stats(netdev
, &net_stats
);
2078 pm_runtime_put_sync(netdev
->dev
.parent
);
2080 for (i
= 0; i
< E1000_GLOBAL_STATS_LEN
; i
++) {
2081 switch (e1000_gstrings_stats
[i
].type
) {
2083 p
= (char *)&net_stats
+
2084 e1000_gstrings_stats
[i
].stat_offset
;
2087 p
= (char *)adapter
+
2088 e1000_gstrings_stats
[i
].stat_offset
;
2095 data
[i
] = (e1000_gstrings_stats
[i
].sizeof_stat
==
2096 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
2100 static void e1000_get_strings(struct net_device __always_unused
*netdev
,
2101 u32 stringset
, u8
*data
)
2106 switch (stringset
) {
2108 memcpy(data
, e1000_gstrings_test
, sizeof(e1000_gstrings_test
));
2111 for (i
= 0; i
< E1000_GLOBAL_STATS_LEN
; i
++) {
2112 memcpy(p
, e1000_gstrings_stats
[i
].stat_string
,
2114 p
+= ETH_GSTRING_LEN
;
2120 static int e1000_get_rxnfc(struct net_device
*netdev
,
2121 struct ethtool_rxnfc
*info
,
2122 u32 __always_unused
*rule_locs
)
2126 switch (info
->cmd
) {
2127 case ETHTOOL_GRXFH
: {
2128 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2129 struct e1000_hw
*hw
= &adapter
->hw
;
2132 pm_runtime_get_sync(netdev
->dev
.parent
);
2134 pm_runtime_put_sync(netdev
->dev
.parent
);
2136 if (!(mrqc
& E1000_MRQC_RSS_FIELD_MASK
))
2139 switch (info
->flow_type
) {
2141 if (mrqc
& E1000_MRQC_RSS_FIELD_IPV4_TCP
)
2142 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
2146 case AH_ESP_V4_FLOW
:
2148 if (mrqc
& E1000_MRQC_RSS_FIELD_IPV4
)
2149 info
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
2152 if (mrqc
& E1000_MRQC_RSS_FIELD_IPV6_TCP
)
2153 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
2157 case AH_ESP_V6_FLOW
:
2159 if (mrqc
& E1000_MRQC_RSS_FIELD_IPV6
)
2160 info
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
2172 static int e1000e_get_eee(struct net_device
*netdev
, struct ethtool_eee
*edata
)
2174 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2175 struct e1000_hw
*hw
= &adapter
->hw
;
2176 u16 cap_addr
, lpa_addr
, pcs_stat_addr
, phy_data
;
2179 if (!(adapter
->flags2
& FLAG2_HAS_EEE
))
2182 switch (hw
->phy
.type
) {
2183 case e1000_phy_82579
:
2184 cap_addr
= I82579_EEE_CAPABILITY
;
2185 lpa_addr
= I82579_EEE_LP_ABILITY
;
2186 pcs_stat_addr
= I82579_EEE_PCS_STATUS
;
2188 case e1000_phy_i217
:
2189 cap_addr
= I217_EEE_CAPABILITY
;
2190 lpa_addr
= I217_EEE_LP_ABILITY
;
2191 pcs_stat_addr
= I217_EEE_PCS_STATUS
;
2197 pm_runtime_get_sync(netdev
->dev
.parent
);
2199 ret_val
= hw
->phy
.ops
.acquire(hw
);
2201 pm_runtime_put_sync(netdev
->dev
.parent
);
2205 /* EEE Capability */
2206 ret_val
= e1000_read_emi_reg_locked(hw
, cap_addr
, &phy_data
);
2209 edata
->supported
= mmd_eee_cap_to_ethtool_sup_t(phy_data
);
2211 /* EEE Advertised */
2212 edata
->advertised
= mmd_eee_adv_to_ethtool_adv_t(adapter
->eee_advert
);
2214 /* EEE Link Partner Advertised */
2215 ret_val
= e1000_read_emi_reg_locked(hw
, lpa_addr
, &phy_data
);
2218 edata
->lp_advertised
= mmd_eee_adv_to_ethtool_adv_t(phy_data
);
2220 /* EEE PCS Status */
2221 ret_val
= e1000_read_emi_reg_locked(hw
, pcs_stat_addr
, &phy_data
);
2224 if (hw
->phy
.type
== e1000_phy_82579
)
2227 /* Result of the EEE auto negotiation - there is no register that
2228 * has the status of the EEE negotiation so do a best-guess based
2229 * on whether Tx or Rx LPI indications have been received.
2231 if (phy_data
& (E1000_EEE_TX_LPI_RCVD
| E1000_EEE_RX_LPI_RCVD
))
2232 edata
->eee_active
= true;
2234 edata
->eee_enabled
= !hw
->dev_spec
.ich8lan
.eee_disable
;
2235 edata
->tx_lpi_enabled
= true;
2236 edata
->tx_lpi_timer
= er32(LPIC
) >> E1000_LPIC_LPIET_SHIFT
;
2239 hw
->phy
.ops
.release(hw
);
2243 pm_runtime_put_sync(netdev
->dev
.parent
);
2248 static int e1000e_set_eee(struct net_device
*netdev
, struct ethtool_eee
*edata
)
2250 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2251 struct e1000_hw
*hw
= &adapter
->hw
;
2252 struct ethtool_eee eee_curr
;
2255 ret_val
= e1000e_get_eee(netdev
, &eee_curr
);
2259 if (eee_curr
.tx_lpi_enabled
!= edata
->tx_lpi_enabled
) {
2260 e_err("Setting EEE tx-lpi is not supported\n");
2264 if (eee_curr
.tx_lpi_timer
!= edata
->tx_lpi_timer
) {
2265 e_err("Setting EEE Tx LPI timer is not supported\n");
2269 if (edata
->advertised
& ~(ADVERTISE_100_FULL
| ADVERTISE_1000_FULL
)) {
2270 e_err("EEE advertisement supports only 100TX and/or 1000T full-duplex\n");
2274 adapter
->eee_advert
= ethtool_adv_to_mmd_eee_adv_t(edata
->advertised
);
2276 hw
->dev_spec
.ich8lan
.eee_disable
= !edata
->eee_enabled
;
2278 pm_runtime_get_sync(netdev
->dev
.parent
);
2280 /* reset the link */
2281 if (netif_running(netdev
))
2282 e1000e_reinit_locked(adapter
);
2284 e1000e_reset(adapter
);
2286 pm_runtime_put_sync(netdev
->dev
.parent
);
2291 static int e1000e_get_ts_info(struct net_device
*netdev
,
2292 struct ethtool_ts_info
*info
)
2294 struct e1000_adapter
*adapter
= netdev_priv(netdev
);
2296 ethtool_op_get_ts_info(netdev
, info
);
2298 if (!(adapter
->flags
& FLAG_HAS_HW_TIMESTAMP
))
2301 info
->so_timestamping
|= (SOF_TIMESTAMPING_TX_HARDWARE
|
2302 SOF_TIMESTAMPING_RX_HARDWARE
|
2303 SOF_TIMESTAMPING_RAW_HARDWARE
);
2305 info
->tx_types
= BIT(HWTSTAMP_TX_OFF
) | BIT(HWTSTAMP_TX_ON
);
2307 info
->rx_filters
= (BIT(HWTSTAMP_FILTER_NONE
) |
2308 BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC
) |
2309 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
) |
2310 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC
) |
2311 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
) |
2312 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC
) |
2313 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ
) |
2314 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT
) |
2315 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC
) |
2316 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ
) |
2317 BIT(HWTSTAMP_FILTER_ALL
));
2319 if (adapter
->ptp_clock
)
2320 info
->phc_index
= ptp_clock_index(adapter
->ptp_clock
);
2325 static const struct ethtool_ops e1000_ethtool_ops
= {
2326 .get_drvinfo
= e1000_get_drvinfo
,
2327 .get_regs_len
= e1000_get_regs_len
,
2328 .get_regs
= e1000_get_regs
,
2329 .get_wol
= e1000_get_wol
,
2330 .set_wol
= e1000_set_wol
,
2331 .get_msglevel
= e1000_get_msglevel
,
2332 .set_msglevel
= e1000_set_msglevel
,
2333 .nway_reset
= e1000_nway_reset
,
2334 .get_link
= ethtool_op_get_link
,
2335 .get_eeprom_len
= e1000_get_eeprom_len
,
2336 .get_eeprom
= e1000_get_eeprom
,
2337 .set_eeprom
= e1000_set_eeprom
,
2338 .get_ringparam
= e1000_get_ringparam
,
2339 .set_ringparam
= e1000_set_ringparam
,
2340 .get_pauseparam
= e1000_get_pauseparam
,
2341 .set_pauseparam
= e1000_set_pauseparam
,
2342 .self_test
= e1000_diag_test
,
2343 .get_strings
= e1000_get_strings
,
2344 .set_phys_id
= e1000_set_phys_id
,
2345 .get_ethtool_stats
= e1000_get_ethtool_stats
,
2346 .get_sset_count
= e1000e_get_sset_count
,
2347 .get_coalesce
= e1000_get_coalesce
,
2348 .set_coalesce
= e1000_set_coalesce
,
2349 .get_rxnfc
= e1000_get_rxnfc
,
2350 .get_ts_info
= e1000e_get_ts_info
,
2351 .get_eee
= e1000e_get_eee
,
2352 .set_eee
= e1000e_set_eee
,
2353 .get_link_ksettings
= e1000_get_link_ksettings
,
2354 .set_link_ksettings
= e1000_set_link_ksettings
,
2357 void e1000e_set_ethtool_ops(struct net_device
*netdev
)
2359 netdev
->ethtool_ops
= &e1000_ethtool_ops
;