1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2013 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 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 /* ethtool support for igb */
30 #include <linux/vmalloc.h>
31 #include <linux/netdevice.h>
32 #include <linux/pci.h>
33 #include <linux/delay.h>
34 #include <linux/interrupt.h>
35 #include <linux/if_ether.h>
36 #include <linux/ethtool.h>
37 #include <linux/sched.h>
38 #include <linux/slab.h>
39 #include <linux/pm_runtime.h>
40 #include <linux/highmem.h>
41 #include <linux/mdio.h>
46 char stat_string
[ETH_GSTRING_LEN
];
51 #define IGB_STAT(_name, _stat) { \
52 .stat_string = _name, \
53 .sizeof_stat = FIELD_SIZEOF(struct igb_adapter, _stat), \
54 .stat_offset = offsetof(struct igb_adapter, _stat) \
56 static const struct igb_stats igb_gstrings_stats
[] = {
57 IGB_STAT("rx_packets", stats
.gprc
),
58 IGB_STAT("tx_packets", stats
.gptc
),
59 IGB_STAT("rx_bytes", stats
.gorc
),
60 IGB_STAT("tx_bytes", stats
.gotc
),
61 IGB_STAT("rx_broadcast", stats
.bprc
),
62 IGB_STAT("tx_broadcast", stats
.bptc
),
63 IGB_STAT("rx_multicast", stats
.mprc
),
64 IGB_STAT("tx_multicast", stats
.mptc
),
65 IGB_STAT("multicast", stats
.mprc
),
66 IGB_STAT("collisions", stats
.colc
),
67 IGB_STAT("rx_crc_errors", stats
.crcerrs
),
68 IGB_STAT("rx_no_buffer_count", stats
.rnbc
),
69 IGB_STAT("rx_missed_errors", stats
.mpc
),
70 IGB_STAT("tx_aborted_errors", stats
.ecol
),
71 IGB_STAT("tx_carrier_errors", stats
.tncrs
),
72 IGB_STAT("tx_window_errors", stats
.latecol
),
73 IGB_STAT("tx_abort_late_coll", stats
.latecol
),
74 IGB_STAT("tx_deferred_ok", stats
.dc
),
75 IGB_STAT("tx_single_coll_ok", stats
.scc
),
76 IGB_STAT("tx_multi_coll_ok", stats
.mcc
),
77 IGB_STAT("tx_timeout_count", tx_timeout_count
),
78 IGB_STAT("rx_long_length_errors", stats
.roc
),
79 IGB_STAT("rx_short_length_errors", stats
.ruc
),
80 IGB_STAT("rx_align_errors", stats
.algnerrc
),
81 IGB_STAT("tx_tcp_seg_good", stats
.tsctc
),
82 IGB_STAT("tx_tcp_seg_failed", stats
.tsctfc
),
83 IGB_STAT("rx_flow_control_xon", stats
.xonrxc
),
84 IGB_STAT("rx_flow_control_xoff", stats
.xoffrxc
),
85 IGB_STAT("tx_flow_control_xon", stats
.xontxc
),
86 IGB_STAT("tx_flow_control_xoff", stats
.xofftxc
),
87 IGB_STAT("rx_long_byte_count", stats
.gorc
),
88 IGB_STAT("tx_dma_out_of_sync", stats
.doosync
),
89 IGB_STAT("tx_smbus", stats
.mgptc
),
90 IGB_STAT("rx_smbus", stats
.mgprc
),
91 IGB_STAT("dropped_smbus", stats
.mgpdc
),
92 IGB_STAT("os2bmc_rx_by_bmc", stats
.o2bgptc
),
93 IGB_STAT("os2bmc_tx_by_bmc", stats
.b2ospc
),
94 IGB_STAT("os2bmc_tx_by_host", stats
.o2bspc
),
95 IGB_STAT("os2bmc_rx_by_host", stats
.b2ogprc
),
96 IGB_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts
),
97 IGB_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared
),
100 #define IGB_NETDEV_STAT(_net_stat) { \
101 .stat_string = __stringify(_net_stat), \
102 .sizeof_stat = FIELD_SIZEOF(struct rtnl_link_stats64, _net_stat), \
103 .stat_offset = offsetof(struct rtnl_link_stats64, _net_stat) \
105 static const struct igb_stats igb_gstrings_net_stats
[] = {
106 IGB_NETDEV_STAT(rx_errors
),
107 IGB_NETDEV_STAT(tx_errors
),
108 IGB_NETDEV_STAT(tx_dropped
),
109 IGB_NETDEV_STAT(rx_length_errors
),
110 IGB_NETDEV_STAT(rx_over_errors
),
111 IGB_NETDEV_STAT(rx_frame_errors
),
112 IGB_NETDEV_STAT(rx_fifo_errors
),
113 IGB_NETDEV_STAT(tx_fifo_errors
),
114 IGB_NETDEV_STAT(tx_heartbeat_errors
)
117 #define IGB_GLOBAL_STATS_LEN \
118 (sizeof(igb_gstrings_stats) / sizeof(struct igb_stats))
119 #define IGB_NETDEV_STATS_LEN \
120 (sizeof(igb_gstrings_net_stats) / sizeof(struct igb_stats))
121 #define IGB_RX_QUEUE_STATS_LEN \
122 (sizeof(struct igb_rx_queue_stats) / sizeof(u64))
124 #define IGB_TX_QUEUE_STATS_LEN 3 /* packets, bytes, restart_queue */
126 #define IGB_QUEUE_STATS_LEN \
127 ((((struct igb_adapter *)netdev_priv(netdev))->num_rx_queues * \
128 IGB_RX_QUEUE_STATS_LEN) + \
129 (((struct igb_adapter *)netdev_priv(netdev))->num_tx_queues * \
130 IGB_TX_QUEUE_STATS_LEN))
131 #define IGB_STATS_LEN \
132 (IGB_GLOBAL_STATS_LEN + IGB_NETDEV_STATS_LEN + IGB_QUEUE_STATS_LEN)
134 static const char igb_gstrings_test
[][ETH_GSTRING_LEN
] = {
135 "Register test (offline)", "Eeprom test (offline)",
136 "Interrupt test (offline)", "Loopback test (offline)",
137 "Link test (on/offline)"
139 #define IGB_TEST_LEN (sizeof(igb_gstrings_test) / ETH_GSTRING_LEN)
141 static int igb_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
143 struct igb_adapter
*adapter
= netdev_priv(netdev
);
144 struct e1000_hw
*hw
= &adapter
->hw
;
145 struct e1000_dev_spec_82575
*dev_spec
= &hw
->dev_spec
._82575
;
146 struct e1000_sfp_flags
*eth_flags
= &dev_spec
->eth_flags
;
149 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
151 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
152 SUPPORTED_10baseT_Full
|
153 SUPPORTED_100baseT_Half
|
154 SUPPORTED_100baseT_Full
|
155 SUPPORTED_1000baseT_Full
|
159 ecmd
->advertising
= ADVERTISED_TP
;
161 if (hw
->mac
.autoneg
== 1) {
162 ecmd
->advertising
|= ADVERTISED_Autoneg
;
163 /* the e1000 autoneg seems to match ethtool nicely */
164 ecmd
->advertising
|= hw
->phy
.autoneg_advertised
;
167 ecmd
->port
= PORT_TP
;
168 ecmd
->phy_address
= hw
->phy
.addr
;
169 ecmd
->transceiver
= XCVR_INTERNAL
;
171 ecmd
->supported
= (SUPPORTED_FIBRE
|
174 ecmd
->advertising
= ADVERTISED_FIBRE
;
175 if (hw
->mac
.type
== e1000_i354
) {
176 ecmd
->supported
|= SUPPORTED_2500baseX_Full
;
177 ecmd
->advertising
|= ADVERTISED_2500baseX_Full
;
179 if ((eth_flags
->e1000_base_lx
) || (eth_flags
->e1000_base_sx
)) {
180 ecmd
->supported
|= SUPPORTED_1000baseT_Full
;
181 ecmd
->advertising
|= ADVERTISED_1000baseT_Full
;
183 if (eth_flags
->e100_base_fx
) {
184 ecmd
->supported
|= SUPPORTED_100baseT_Full
;
185 ecmd
->advertising
|= ADVERTISED_100baseT_Full
;
187 if (hw
->mac
.autoneg
== 1)
188 ecmd
->advertising
|= ADVERTISED_Autoneg
;
190 ecmd
->port
= PORT_FIBRE
;
191 ecmd
->transceiver
= XCVR_EXTERNAL
;
194 if (hw
->mac
.autoneg
!= 1)
195 ecmd
->advertising
&= ~(ADVERTISED_Pause
|
196 ADVERTISED_Asym_Pause
);
198 if (hw
->fc
.requested_mode
== e1000_fc_full
)
199 ecmd
->advertising
|= ADVERTISED_Pause
;
200 else if (hw
->fc
.requested_mode
== e1000_fc_rx_pause
)
201 ecmd
->advertising
|= (ADVERTISED_Pause
|
202 ADVERTISED_Asym_Pause
);
203 else if (hw
->fc
.requested_mode
== e1000_fc_tx_pause
)
204 ecmd
->advertising
|= ADVERTISED_Asym_Pause
;
206 ecmd
->advertising
&= ~(ADVERTISED_Pause
|
207 ADVERTISED_Asym_Pause
);
209 status
= rd32(E1000_STATUS
);
211 if (status
& E1000_STATUS_LU
) {
212 if ((hw
->mac
.type
== e1000_i354
) &&
213 (status
& E1000_STATUS_2P5_SKU
) &&
214 !(status
& E1000_STATUS_2P5_SKU_OVER
))
215 ecmd
->speed
= SPEED_2500
;
216 else if (status
& E1000_STATUS_SPEED_1000
)
217 ecmd
->speed
= SPEED_1000
;
218 else if (status
& E1000_STATUS_SPEED_100
)
219 ecmd
->speed
= SPEED_100
;
221 ecmd
->speed
= SPEED_10
;
222 if ((status
& E1000_STATUS_FD
) ||
223 hw
->phy
.media_type
!= e1000_media_type_copper
)
224 ecmd
->duplex
= DUPLEX_FULL
;
226 ecmd
->duplex
= DUPLEX_HALF
;
232 if ((hw
->phy
.media_type
== e1000_media_type_fiber
) ||
234 ecmd
->autoneg
= AUTONEG_ENABLE
;
236 ecmd
->autoneg
= AUTONEG_DISABLE
;
238 /* MDI-X => 2; MDI =>1; Invalid =>0 */
239 if (hw
->phy
.media_type
== e1000_media_type_copper
)
240 ecmd
->eth_tp_mdix
= hw
->phy
.is_mdix
? ETH_TP_MDI_X
:
243 ecmd
->eth_tp_mdix
= ETH_TP_MDI_INVALID
;
245 if (hw
->phy
.mdix
== AUTO_ALL_MODES
)
246 ecmd
->eth_tp_mdix_ctrl
= ETH_TP_MDI_AUTO
;
248 ecmd
->eth_tp_mdix_ctrl
= hw
->phy
.mdix
;
253 static int igb_set_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
255 struct igb_adapter
*adapter
= netdev_priv(netdev
);
256 struct e1000_hw
*hw
= &adapter
->hw
;
258 /* When SoL/IDER sessions are active, autoneg/speed/duplex
261 if (igb_check_reset_block(hw
)) {
262 dev_err(&adapter
->pdev
->dev
,
263 "Cannot change link characteristics when SoL/IDER is active.\n");
267 /* MDI setting is only allowed when autoneg enabled because
268 * some hardware doesn't allow MDI setting when speed or
271 if (ecmd
->eth_tp_mdix_ctrl
) {
272 if (hw
->phy
.media_type
!= e1000_media_type_copper
)
275 if ((ecmd
->eth_tp_mdix_ctrl
!= ETH_TP_MDI_AUTO
) &&
276 (ecmd
->autoneg
!= AUTONEG_ENABLE
)) {
277 dev_err(&adapter
->pdev
->dev
, "forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
282 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
285 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
287 if (hw
->phy
.media_type
== e1000_media_type_fiber
) {
288 hw
->phy
.autoneg_advertised
= ecmd
->advertising
|
291 switch (adapter
->link_speed
) {
293 hw
->phy
.autoneg_advertised
=
294 ADVERTISED_2500baseX_Full
;
297 hw
->phy
.autoneg_advertised
=
298 ADVERTISED_1000baseT_Full
;
301 hw
->phy
.autoneg_advertised
=
302 ADVERTISED_100baseT_Full
;
308 hw
->phy
.autoneg_advertised
= ecmd
->advertising
|
312 ecmd
->advertising
= hw
->phy
.autoneg_advertised
;
313 if (adapter
->fc_autoneg
)
314 hw
->fc
.requested_mode
= e1000_fc_default
;
316 u32 speed
= ethtool_cmd_speed(ecmd
);
317 /* calling this overrides forced MDI setting */
318 if (igb_set_spd_dplx(adapter
, speed
, ecmd
->duplex
)) {
319 clear_bit(__IGB_RESETTING
, &adapter
->state
);
324 /* MDI-X => 2; MDI => 1; Auto => 3 */
325 if (ecmd
->eth_tp_mdix_ctrl
) {
326 /* fix up the value for auto (3 => 0) as zero is mapped
329 if (ecmd
->eth_tp_mdix_ctrl
== ETH_TP_MDI_AUTO
)
330 hw
->phy
.mdix
= AUTO_ALL_MODES
;
332 hw
->phy
.mdix
= ecmd
->eth_tp_mdix_ctrl
;
336 if (netif_running(adapter
->netdev
)) {
342 clear_bit(__IGB_RESETTING
, &adapter
->state
);
346 static u32
igb_get_link(struct net_device
*netdev
)
348 struct igb_adapter
*adapter
= netdev_priv(netdev
);
349 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
351 /* If the link is not reported up to netdev, interrupts are disabled,
352 * and so the physical link state may have changed since we last
353 * looked. Set get_link_status to make sure that the true link
354 * state is interrogated, rather than pulling a cached and possibly
355 * stale link state from the driver.
357 if (!netif_carrier_ok(netdev
))
358 mac
->get_link_status
= 1;
360 return igb_has_link(adapter
);
363 static void igb_get_pauseparam(struct net_device
*netdev
,
364 struct ethtool_pauseparam
*pause
)
366 struct igb_adapter
*adapter
= netdev_priv(netdev
);
367 struct e1000_hw
*hw
= &adapter
->hw
;
370 (adapter
->fc_autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
);
372 if (hw
->fc
.current_mode
== e1000_fc_rx_pause
)
374 else if (hw
->fc
.current_mode
== e1000_fc_tx_pause
)
376 else if (hw
->fc
.current_mode
== e1000_fc_full
) {
382 static int igb_set_pauseparam(struct net_device
*netdev
,
383 struct ethtool_pauseparam
*pause
)
385 struct igb_adapter
*adapter
= netdev_priv(netdev
);
386 struct e1000_hw
*hw
= &adapter
->hw
;
389 /* 100basefx does not support setting link flow control */
390 if (hw
->dev_spec
._82575
.eth_flags
.e100_base_fx
)
393 adapter
->fc_autoneg
= pause
->autoneg
;
395 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
398 if (adapter
->fc_autoneg
== AUTONEG_ENABLE
) {
399 hw
->fc
.requested_mode
= e1000_fc_default
;
400 if (netif_running(adapter
->netdev
)) {
407 if (pause
->rx_pause
&& pause
->tx_pause
)
408 hw
->fc
.requested_mode
= e1000_fc_full
;
409 else if (pause
->rx_pause
&& !pause
->tx_pause
)
410 hw
->fc
.requested_mode
= e1000_fc_rx_pause
;
411 else if (!pause
->rx_pause
&& pause
->tx_pause
)
412 hw
->fc
.requested_mode
= e1000_fc_tx_pause
;
413 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
414 hw
->fc
.requested_mode
= e1000_fc_none
;
416 hw
->fc
.current_mode
= hw
->fc
.requested_mode
;
418 retval
= ((hw
->phy
.media_type
== e1000_media_type_copper
) ?
419 igb_force_mac_fc(hw
) : igb_setup_link(hw
));
422 clear_bit(__IGB_RESETTING
, &adapter
->state
);
426 static u32
igb_get_msglevel(struct net_device
*netdev
)
428 struct igb_adapter
*adapter
= netdev_priv(netdev
);
429 return adapter
->msg_enable
;
432 static void igb_set_msglevel(struct net_device
*netdev
, u32 data
)
434 struct igb_adapter
*adapter
= netdev_priv(netdev
);
435 adapter
->msg_enable
= data
;
438 static int igb_get_regs_len(struct net_device
*netdev
)
440 #define IGB_REGS_LEN 739
441 return IGB_REGS_LEN
* sizeof(u32
);
444 static void igb_get_regs(struct net_device
*netdev
,
445 struct ethtool_regs
*regs
, void *p
)
447 struct igb_adapter
*adapter
= netdev_priv(netdev
);
448 struct e1000_hw
*hw
= &adapter
->hw
;
452 memset(p
, 0, IGB_REGS_LEN
* sizeof(u32
));
454 regs
->version
= (1 << 24) | (hw
->revision_id
<< 16) | hw
->device_id
;
456 /* General Registers */
457 regs_buff
[0] = rd32(E1000_CTRL
);
458 regs_buff
[1] = rd32(E1000_STATUS
);
459 regs_buff
[2] = rd32(E1000_CTRL_EXT
);
460 regs_buff
[3] = rd32(E1000_MDIC
);
461 regs_buff
[4] = rd32(E1000_SCTL
);
462 regs_buff
[5] = rd32(E1000_CONNSW
);
463 regs_buff
[6] = rd32(E1000_VET
);
464 regs_buff
[7] = rd32(E1000_LEDCTL
);
465 regs_buff
[8] = rd32(E1000_PBA
);
466 regs_buff
[9] = rd32(E1000_PBS
);
467 regs_buff
[10] = rd32(E1000_FRTIMER
);
468 regs_buff
[11] = rd32(E1000_TCPTIMER
);
471 regs_buff
[12] = rd32(E1000_EECD
);
474 /* Reading EICS for EICR because they read the
475 * same but EICS does not clear on read
477 regs_buff
[13] = rd32(E1000_EICS
);
478 regs_buff
[14] = rd32(E1000_EICS
);
479 regs_buff
[15] = rd32(E1000_EIMS
);
480 regs_buff
[16] = rd32(E1000_EIMC
);
481 regs_buff
[17] = rd32(E1000_EIAC
);
482 regs_buff
[18] = rd32(E1000_EIAM
);
483 /* Reading ICS for ICR because they read the
484 * same but ICS does not clear on read
486 regs_buff
[19] = rd32(E1000_ICS
);
487 regs_buff
[20] = rd32(E1000_ICS
);
488 regs_buff
[21] = rd32(E1000_IMS
);
489 regs_buff
[22] = rd32(E1000_IMC
);
490 regs_buff
[23] = rd32(E1000_IAC
);
491 regs_buff
[24] = rd32(E1000_IAM
);
492 regs_buff
[25] = rd32(E1000_IMIRVP
);
495 regs_buff
[26] = rd32(E1000_FCAL
);
496 regs_buff
[27] = rd32(E1000_FCAH
);
497 regs_buff
[28] = rd32(E1000_FCTTV
);
498 regs_buff
[29] = rd32(E1000_FCRTL
);
499 regs_buff
[30] = rd32(E1000_FCRTH
);
500 regs_buff
[31] = rd32(E1000_FCRTV
);
503 regs_buff
[32] = rd32(E1000_RCTL
);
504 regs_buff
[33] = rd32(E1000_RXCSUM
);
505 regs_buff
[34] = rd32(E1000_RLPML
);
506 regs_buff
[35] = rd32(E1000_RFCTL
);
507 regs_buff
[36] = rd32(E1000_MRQC
);
508 regs_buff
[37] = rd32(E1000_VT_CTL
);
511 regs_buff
[38] = rd32(E1000_TCTL
);
512 regs_buff
[39] = rd32(E1000_TCTL_EXT
);
513 regs_buff
[40] = rd32(E1000_TIPG
);
514 regs_buff
[41] = rd32(E1000_DTXCTL
);
517 regs_buff
[42] = rd32(E1000_WUC
);
518 regs_buff
[43] = rd32(E1000_WUFC
);
519 regs_buff
[44] = rd32(E1000_WUS
);
520 regs_buff
[45] = rd32(E1000_IPAV
);
521 regs_buff
[46] = rd32(E1000_WUPL
);
524 regs_buff
[47] = rd32(E1000_PCS_CFG0
);
525 regs_buff
[48] = rd32(E1000_PCS_LCTL
);
526 regs_buff
[49] = rd32(E1000_PCS_LSTAT
);
527 regs_buff
[50] = rd32(E1000_PCS_ANADV
);
528 regs_buff
[51] = rd32(E1000_PCS_LPAB
);
529 regs_buff
[52] = rd32(E1000_PCS_NPTX
);
530 regs_buff
[53] = rd32(E1000_PCS_LPABNP
);
533 regs_buff
[54] = adapter
->stats
.crcerrs
;
534 regs_buff
[55] = adapter
->stats
.algnerrc
;
535 regs_buff
[56] = adapter
->stats
.symerrs
;
536 regs_buff
[57] = adapter
->stats
.rxerrc
;
537 regs_buff
[58] = adapter
->stats
.mpc
;
538 regs_buff
[59] = adapter
->stats
.scc
;
539 regs_buff
[60] = adapter
->stats
.ecol
;
540 regs_buff
[61] = adapter
->stats
.mcc
;
541 regs_buff
[62] = adapter
->stats
.latecol
;
542 regs_buff
[63] = adapter
->stats
.colc
;
543 regs_buff
[64] = adapter
->stats
.dc
;
544 regs_buff
[65] = adapter
->stats
.tncrs
;
545 regs_buff
[66] = adapter
->stats
.sec
;
546 regs_buff
[67] = adapter
->stats
.htdpmc
;
547 regs_buff
[68] = adapter
->stats
.rlec
;
548 regs_buff
[69] = adapter
->stats
.xonrxc
;
549 regs_buff
[70] = adapter
->stats
.xontxc
;
550 regs_buff
[71] = adapter
->stats
.xoffrxc
;
551 regs_buff
[72] = adapter
->stats
.xofftxc
;
552 regs_buff
[73] = adapter
->stats
.fcruc
;
553 regs_buff
[74] = adapter
->stats
.prc64
;
554 regs_buff
[75] = adapter
->stats
.prc127
;
555 regs_buff
[76] = adapter
->stats
.prc255
;
556 regs_buff
[77] = adapter
->stats
.prc511
;
557 regs_buff
[78] = adapter
->stats
.prc1023
;
558 regs_buff
[79] = adapter
->stats
.prc1522
;
559 regs_buff
[80] = adapter
->stats
.gprc
;
560 regs_buff
[81] = adapter
->stats
.bprc
;
561 regs_buff
[82] = adapter
->stats
.mprc
;
562 regs_buff
[83] = adapter
->stats
.gptc
;
563 regs_buff
[84] = adapter
->stats
.gorc
;
564 regs_buff
[86] = adapter
->stats
.gotc
;
565 regs_buff
[88] = adapter
->stats
.rnbc
;
566 regs_buff
[89] = adapter
->stats
.ruc
;
567 regs_buff
[90] = adapter
->stats
.rfc
;
568 regs_buff
[91] = adapter
->stats
.roc
;
569 regs_buff
[92] = adapter
->stats
.rjc
;
570 regs_buff
[93] = adapter
->stats
.mgprc
;
571 regs_buff
[94] = adapter
->stats
.mgpdc
;
572 regs_buff
[95] = adapter
->stats
.mgptc
;
573 regs_buff
[96] = adapter
->stats
.tor
;
574 regs_buff
[98] = adapter
->stats
.tot
;
575 regs_buff
[100] = adapter
->stats
.tpr
;
576 regs_buff
[101] = adapter
->stats
.tpt
;
577 regs_buff
[102] = adapter
->stats
.ptc64
;
578 regs_buff
[103] = adapter
->stats
.ptc127
;
579 regs_buff
[104] = adapter
->stats
.ptc255
;
580 regs_buff
[105] = adapter
->stats
.ptc511
;
581 regs_buff
[106] = adapter
->stats
.ptc1023
;
582 regs_buff
[107] = adapter
->stats
.ptc1522
;
583 regs_buff
[108] = adapter
->stats
.mptc
;
584 regs_buff
[109] = adapter
->stats
.bptc
;
585 regs_buff
[110] = adapter
->stats
.tsctc
;
586 regs_buff
[111] = adapter
->stats
.iac
;
587 regs_buff
[112] = adapter
->stats
.rpthc
;
588 regs_buff
[113] = adapter
->stats
.hgptc
;
589 regs_buff
[114] = adapter
->stats
.hgorc
;
590 regs_buff
[116] = adapter
->stats
.hgotc
;
591 regs_buff
[118] = adapter
->stats
.lenerrs
;
592 regs_buff
[119] = adapter
->stats
.scvpc
;
593 regs_buff
[120] = adapter
->stats
.hrmpc
;
595 for (i
= 0; i
< 4; i
++)
596 regs_buff
[121 + i
] = rd32(E1000_SRRCTL(i
));
597 for (i
= 0; i
< 4; i
++)
598 regs_buff
[125 + i
] = rd32(E1000_PSRTYPE(i
));
599 for (i
= 0; i
< 4; i
++)
600 regs_buff
[129 + i
] = rd32(E1000_RDBAL(i
));
601 for (i
= 0; i
< 4; i
++)
602 regs_buff
[133 + i
] = rd32(E1000_RDBAH(i
));
603 for (i
= 0; i
< 4; i
++)
604 regs_buff
[137 + i
] = rd32(E1000_RDLEN(i
));
605 for (i
= 0; i
< 4; i
++)
606 regs_buff
[141 + i
] = rd32(E1000_RDH(i
));
607 for (i
= 0; i
< 4; i
++)
608 regs_buff
[145 + i
] = rd32(E1000_RDT(i
));
609 for (i
= 0; i
< 4; i
++)
610 regs_buff
[149 + i
] = rd32(E1000_RXDCTL(i
));
612 for (i
= 0; i
< 10; i
++)
613 regs_buff
[153 + i
] = rd32(E1000_EITR(i
));
614 for (i
= 0; i
< 8; i
++)
615 regs_buff
[163 + i
] = rd32(E1000_IMIR(i
));
616 for (i
= 0; i
< 8; i
++)
617 regs_buff
[171 + i
] = rd32(E1000_IMIREXT(i
));
618 for (i
= 0; i
< 16; i
++)
619 regs_buff
[179 + i
] = rd32(E1000_RAL(i
));
620 for (i
= 0; i
< 16; i
++)
621 regs_buff
[195 + i
] = rd32(E1000_RAH(i
));
623 for (i
= 0; i
< 4; i
++)
624 regs_buff
[211 + i
] = rd32(E1000_TDBAL(i
));
625 for (i
= 0; i
< 4; i
++)
626 regs_buff
[215 + i
] = rd32(E1000_TDBAH(i
));
627 for (i
= 0; i
< 4; i
++)
628 regs_buff
[219 + i
] = rd32(E1000_TDLEN(i
));
629 for (i
= 0; i
< 4; i
++)
630 regs_buff
[223 + i
] = rd32(E1000_TDH(i
));
631 for (i
= 0; i
< 4; i
++)
632 regs_buff
[227 + i
] = rd32(E1000_TDT(i
));
633 for (i
= 0; i
< 4; i
++)
634 regs_buff
[231 + i
] = rd32(E1000_TXDCTL(i
));
635 for (i
= 0; i
< 4; i
++)
636 regs_buff
[235 + i
] = rd32(E1000_TDWBAL(i
));
637 for (i
= 0; i
< 4; i
++)
638 regs_buff
[239 + i
] = rd32(E1000_TDWBAH(i
));
639 for (i
= 0; i
< 4; i
++)
640 regs_buff
[243 + i
] = rd32(E1000_DCA_TXCTRL(i
));
642 for (i
= 0; i
< 4; i
++)
643 regs_buff
[247 + i
] = rd32(E1000_IP4AT_REG(i
));
644 for (i
= 0; i
< 4; i
++)
645 regs_buff
[251 + i
] = rd32(E1000_IP6AT_REG(i
));
646 for (i
= 0; i
< 32; i
++)
647 regs_buff
[255 + i
] = rd32(E1000_WUPM_REG(i
));
648 for (i
= 0; i
< 128; i
++)
649 regs_buff
[287 + i
] = rd32(E1000_FFMT_REG(i
));
650 for (i
= 0; i
< 128; i
++)
651 regs_buff
[415 + i
] = rd32(E1000_FFVT_REG(i
));
652 for (i
= 0; i
< 4; i
++)
653 regs_buff
[543 + i
] = rd32(E1000_FFLT_REG(i
));
655 regs_buff
[547] = rd32(E1000_TDFH
);
656 regs_buff
[548] = rd32(E1000_TDFT
);
657 regs_buff
[549] = rd32(E1000_TDFHS
);
658 regs_buff
[550] = rd32(E1000_TDFPC
);
660 if (hw
->mac
.type
> e1000_82580
) {
661 regs_buff
[551] = adapter
->stats
.o2bgptc
;
662 regs_buff
[552] = adapter
->stats
.b2ospc
;
663 regs_buff
[553] = adapter
->stats
.o2bspc
;
664 regs_buff
[554] = adapter
->stats
.b2ogprc
;
667 if (hw
->mac
.type
!= e1000_82576
)
669 for (i
= 0; i
< 12; i
++)
670 regs_buff
[555 + i
] = rd32(E1000_SRRCTL(i
+ 4));
671 for (i
= 0; i
< 4; i
++)
672 regs_buff
[567 + i
] = rd32(E1000_PSRTYPE(i
+ 4));
673 for (i
= 0; i
< 12; i
++)
674 regs_buff
[571 + i
] = rd32(E1000_RDBAL(i
+ 4));
675 for (i
= 0; i
< 12; i
++)
676 regs_buff
[583 + i
] = rd32(E1000_RDBAH(i
+ 4));
677 for (i
= 0; i
< 12; i
++)
678 regs_buff
[595 + i
] = rd32(E1000_RDLEN(i
+ 4));
679 for (i
= 0; i
< 12; i
++)
680 regs_buff
[607 + i
] = rd32(E1000_RDH(i
+ 4));
681 for (i
= 0; i
< 12; i
++)
682 regs_buff
[619 + i
] = rd32(E1000_RDT(i
+ 4));
683 for (i
= 0; i
< 12; i
++)
684 regs_buff
[631 + i
] = rd32(E1000_RXDCTL(i
+ 4));
686 for (i
= 0; i
< 12; i
++)
687 regs_buff
[643 + i
] = rd32(E1000_TDBAL(i
+ 4));
688 for (i
= 0; i
< 12; i
++)
689 regs_buff
[655 + i
] = rd32(E1000_TDBAH(i
+ 4));
690 for (i
= 0; i
< 12; i
++)
691 regs_buff
[667 + i
] = rd32(E1000_TDLEN(i
+ 4));
692 for (i
= 0; i
< 12; i
++)
693 regs_buff
[679 + i
] = rd32(E1000_TDH(i
+ 4));
694 for (i
= 0; i
< 12; i
++)
695 regs_buff
[691 + i
] = rd32(E1000_TDT(i
+ 4));
696 for (i
= 0; i
< 12; i
++)
697 regs_buff
[703 + i
] = rd32(E1000_TXDCTL(i
+ 4));
698 for (i
= 0; i
< 12; i
++)
699 regs_buff
[715 + i
] = rd32(E1000_TDWBAL(i
+ 4));
700 for (i
= 0; i
< 12; i
++)
701 regs_buff
[727 + i
] = rd32(E1000_TDWBAH(i
+ 4));
704 static int igb_get_eeprom_len(struct net_device
*netdev
)
706 struct igb_adapter
*adapter
= netdev_priv(netdev
);
707 return adapter
->hw
.nvm
.word_size
* 2;
710 static int igb_get_eeprom(struct net_device
*netdev
,
711 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
713 struct igb_adapter
*adapter
= netdev_priv(netdev
);
714 struct e1000_hw
*hw
= &adapter
->hw
;
716 int first_word
, last_word
;
720 if (eeprom
->len
== 0)
723 eeprom
->magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
725 first_word
= eeprom
->offset
>> 1;
726 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
728 eeprom_buff
= kmalloc(sizeof(u16
) *
729 (last_word
- first_word
+ 1), GFP_KERNEL
);
733 if (hw
->nvm
.type
== e1000_nvm_eeprom_spi
)
734 ret_val
= hw
->nvm
.ops
.read(hw
, first_word
,
735 last_word
- first_word
+ 1,
738 for (i
= 0; i
< last_word
- first_word
+ 1; i
++) {
739 ret_val
= hw
->nvm
.ops
.read(hw
, first_word
+ i
, 1,
746 /* Device's eeprom is always little-endian, word addressable */
747 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
748 le16_to_cpus(&eeprom_buff
[i
]);
750 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 1),
757 static int igb_set_eeprom(struct net_device
*netdev
,
758 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
760 struct igb_adapter
*adapter
= netdev_priv(netdev
);
761 struct e1000_hw
*hw
= &adapter
->hw
;
764 int max_len
, first_word
, last_word
, ret_val
= 0;
767 if (eeprom
->len
== 0)
770 if (hw
->mac
.type
== e1000_i211
)
773 if (eeprom
->magic
!= (hw
->vendor_id
| (hw
->device_id
<< 16)))
776 max_len
= hw
->nvm
.word_size
* 2;
778 first_word
= eeprom
->offset
>> 1;
779 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
780 eeprom_buff
= kmalloc(max_len
, GFP_KERNEL
);
784 ptr
= (void *)eeprom_buff
;
786 if (eeprom
->offset
& 1) {
787 /* need read/modify/write of first changed EEPROM word
788 * only the second byte of the word is being modified
790 ret_val
= hw
->nvm
.ops
.read(hw
, first_word
, 1,
794 if (((eeprom
->offset
+ eeprom
->len
) & 1) && (ret_val
== 0)) {
795 /* need read/modify/write of last changed EEPROM word
796 * only the first byte of the word is being modified
798 ret_val
= hw
->nvm
.ops
.read(hw
, last_word
, 1,
799 &eeprom_buff
[last_word
- first_word
]);
802 /* Device's eeprom is always little-endian, word addressable */
803 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
804 le16_to_cpus(&eeprom_buff
[i
]);
806 memcpy(ptr
, bytes
, eeprom
->len
);
808 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
809 eeprom_buff
[i
] = cpu_to_le16(eeprom_buff
[i
]);
811 ret_val
= hw
->nvm
.ops
.write(hw
, first_word
,
812 last_word
- first_word
+ 1, eeprom_buff
);
814 /* Update the checksum if nvm write succeeded */
816 hw
->nvm
.ops
.update(hw
);
818 igb_set_fw_version(adapter
);
823 static void igb_get_drvinfo(struct net_device
*netdev
,
824 struct ethtool_drvinfo
*drvinfo
)
826 struct igb_adapter
*adapter
= netdev_priv(netdev
);
828 strlcpy(drvinfo
->driver
, igb_driver_name
, sizeof(drvinfo
->driver
));
829 strlcpy(drvinfo
->version
, igb_driver_version
, sizeof(drvinfo
->version
));
831 /* EEPROM image version # is reported as firmware version # for
834 strlcpy(drvinfo
->fw_version
, adapter
->fw_version
,
835 sizeof(drvinfo
->fw_version
));
836 strlcpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
837 sizeof(drvinfo
->bus_info
));
838 drvinfo
->n_stats
= IGB_STATS_LEN
;
839 drvinfo
->testinfo_len
= IGB_TEST_LEN
;
840 drvinfo
->regdump_len
= igb_get_regs_len(netdev
);
841 drvinfo
->eedump_len
= igb_get_eeprom_len(netdev
);
844 static void igb_get_ringparam(struct net_device
*netdev
,
845 struct ethtool_ringparam
*ring
)
847 struct igb_adapter
*adapter
= netdev_priv(netdev
);
849 ring
->rx_max_pending
= IGB_MAX_RXD
;
850 ring
->tx_max_pending
= IGB_MAX_TXD
;
851 ring
->rx_pending
= adapter
->rx_ring_count
;
852 ring
->tx_pending
= adapter
->tx_ring_count
;
855 static int igb_set_ringparam(struct net_device
*netdev
,
856 struct ethtool_ringparam
*ring
)
858 struct igb_adapter
*adapter
= netdev_priv(netdev
);
859 struct igb_ring
*temp_ring
;
861 u16 new_rx_count
, new_tx_count
;
863 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
866 new_rx_count
= min_t(u32
, ring
->rx_pending
, IGB_MAX_RXD
);
867 new_rx_count
= max_t(u16
, new_rx_count
, IGB_MIN_RXD
);
868 new_rx_count
= ALIGN(new_rx_count
, REQ_RX_DESCRIPTOR_MULTIPLE
);
870 new_tx_count
= min_t(u32
, ring
->tx_pending
, IGB_MAX_TXD
);
871 new_tx_count
= max_t(u16
, new_tx_count
, IGB_MIN_TXD
);
872 new_tx_count
= ALIGN(new_tx_count
, REQ_TX_DESCRIPTOR_MULTIPLE
);
874 if ((new_tx_count
== adapter
->tx_ring_count
) &&
875 (new_rx_count
== adapter
->rx_ring_count
)) {
880 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
883 if (!netif_running(adapter
->netdev
)) {
884 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
885 adapter
->tx_ring
[i
]->count
= new_tx_count
;
886 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
887 adapter
->rx_ring
[i
]->count
= new_rx_count
;
888 adapter
->tx_ring_count
= new_tx_count
;
889 adapter
->rx_ring_count
= new_rx_count
;
893 if (adapter
->num_tx_queues
> adapter
->num_rx_queues
)
894 temp_ring
= vmalloc(adapter
->num_tx_queues
*
895 sizeof(struct igb_ring
));
897 temp_ring
= vmalloc(adapter
->num_rx_queues
*
898 sizeof(struct igb_ring
));
907 /* We can't just free everything and then setup again,
908 * because the ISRs in MSI-X mode get passed pointers
909 * to the Tx and Rx ring structs.
911 if (new_tx_count
!= adapter
->tx_ring_count
) {
912 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
913 memcpy(&temp_ring
[i
], adapter
->tx_ring
[i
],
914 sizeof(struct igb_ring
));
916 temp_ring
[i
].count
= new_tx_count
;
917 err
= igb_setup_tx_resources(&temp_ring
[i
]);
921 igb_free_tx_resources(&temp_ring
[i
]);
927 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
928 igb_free_tx_resources(adapter
->tx_ring
[i
]);
930 memcpy(adapter
->tx_ring
[i
], &temp_ring
[i
],
931 sizeof(struct igb_ring
));
934 adapter
->tx_ring_count
= new_tx_count
;
937 if (new_rx_count
!= adapter
->rx_ring_count
) {
938 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
939 memcpy(&temp_ring
[i
], adapter
->rx_ring
[i
],
940 sizeof(struct igb_ring
));
942 temp_ring
[i
].count
= new_rx_count
;
943 err
= igb_setup_rx_resources(&temp_ring
[i
]);
947 igb_free_rx_resources(&temp_ring
[i
]);
954 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
955 igb_free_rx_resources(adapter
->rx_ring
[i
]);
957 memcpy(adapter
->rx_ring
[i
], &temp_ring
[i
],
958 sizeof(struct igb_ring
));
961 adapter
->rx_ring_count
= new_rx_count
;
967 clear_bit(__IGB_RESETTING
, &adapter
->state
);
971 /* ethtool register test data */
972 struct igb_reg_test
{
981 /* In the hardware, registers are laid out either singly, in arrays
982 * spaced 0x100 bytes apart, or in contiguous tables. We assume
983 * most tests take place on arrays or single registers (handled
984 * as a single-element array) and special-case the tables.
985 * Table tests are always pattern tests.
987 * We also make provision for some required setup steps by specifying
988 * registers to be written without any read-back testing.
991 #define PATTERN_TEST 1
992 #define SET_READ_TEST 2
993 #define WRITE_NO_TEST 3
994 #define TABLE32_TEST 4
995 #define TABLE64_TEST_LO 5
996 #define TABLE64_TEST_HI 6
999 static struct igb_reg_test reg_test_i210
[] = {
1000 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1001 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1002 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1003 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1004 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1005 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
1006 /* RDH is read-only for i210, only test RDT. */
1007 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1008 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
1009 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1010 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
1011 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1012 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1013 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
1014 { E1000_TDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1015 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1016 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0x003FFFFB },
1017 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0xFFFFFFFF },
1018 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1019 { E1000_RA
, 0, 16, TABLE64_TEST_LO
,
1020 0xFFFFFFFF, 0xFFFFFFFF },
1021 { E1000_RA
, 0, 16, TABLE64_TEST_HI
,
1022 0x900FFFFF, 0xFFFFFFFF },
1023 { E1000_MTA
, 0, 128, TABLE32_TEST
,
1024 0xFFFFFFFF, 0xFFFFFFFF },
1029 static struct igb_reg_test reg_test_i350
[] = {
1030 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1031 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1032 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1033 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFF0000, 0xFFFF0000 },
1034 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1035 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1036 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
1037 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1038 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1039 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
1040 /* RDH is read-only for i350, only test RDT. */
1041 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1042 { E1000_RDT(4), 0x40, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1043 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
1044 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1045 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
1046 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1047 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1048 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
1049 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1050 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1051 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
1052 { E1000_TDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1053 { E1000_TDT(4), 0x40, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1054 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1055 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0x003FFFFB },
1056 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0xFFFFFFFF },
1057 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1058 { E1000_RA
, 0, 16, TABLE64_TEST_LO
,
1059 0xFFFFFFFF, 0xFFFFFFFF },
1060 { E1000_RA
, 0, 16, TABLE64_TEST_HI
,
1061 0xC3FFFFFF, 0xFFFFFFFF },
1062 { E1000_RA2
, 0, 16, TABLE64_TEST_LO
,
1063 0xFFFFFFFF, 0xFFFFFFFF },
1064 { E1000_RA2
, 0, 16, TABLE64_TEST_HI
,
1065 0xC3FFFFFF, 0xFFFFFFFF },
1066 { E1000_MTA
, 0, 128, TABLE32_TEST
,
1067 0xFFFFFFFF, 0xFFFFFFFF },
1071 /* 82580 reg test */
1072 static struct igb_reg_test reg_test_82580
[] = {
1073 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1074 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1075 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1076 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1077 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1078 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1079 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
1080 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1081 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1082 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
1083 /* RDH is read-only for 82580, only test RDT. */
1084 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1085 { E1000_RDT(4), 0x40, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1086 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
1087 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1088 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
1089 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1090 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1091 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
1092 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1093 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1094 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
1095 { E1000_TDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1096 { E1000_TDT(4), 0x40, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1097 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1098 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0x003FFFFB },
1099 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0xFFFFFFFF },
1100 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1101 { E1000_RA
, 0, 16, TABLE64_TEST_LO
,
1102 0xFFFFFFFF, 0xFFFFFFFF },
1103 { E1000_RA
, 0, 16, TABLE64_TEST_HI
,
1104 0x83FFFFFF, 0xFFFFFFFF },
1105 { E1000_RA2
, 0, 8, TABLE64_TEST_LO
,
1106 0xFFFFFFFF, 0xFFFFFFFF },
1107 { E1000_RA2
, 0, 8, TABLE64_TEST_HI
,
1108 0x83FFFFFF, 0xFFFFFFFF },
1109 { E1000_MTA
, 0, 128, TABLE32_TEST
,
1110 0xFFFFFFFF, 0xFFFFFFFF },
1114 /* 82576 reg test */
1115 static struct igb_reg_test reg_test_82576
[] = {
1116 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1117 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1118 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1119 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1120 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1121 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1122 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
1123 { E1000_RDBAL(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1124 { E1000_RDBAH(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1125 { E1000_RDLEN(4), 0x40, 12, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
1126 /* Enable all RX queues before testing. */
1127 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, E1000_RXDCTL_QUEUE_ENABLE
},
1128 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST
, 0, E1000_RXDCTL_QUEUE_ENABLE
},
1129 /* RDH is read-only for 82576, only test RDT. */
1130 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1131 { E1000_RDT(4), 0x40, 12, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1132 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, 0 },
1133 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST
, 0, 0 },
1134 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
1135 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1136 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
1137 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1138 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1139 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
1140 { E1000_TDBAL(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1141 { E1000_TDBAH(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1142 { E1000_TDLEN(4), 0x40, 12, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
1143 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1144 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0x003FFFFB },
1145 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0xFFFFFFFF },
1146 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1147 { E1000_RA
, 0, 16, TABLE64_TEST_LO
, 0xFFFFFFFF, 0xFFFFFFFF },
1148 { E1000_RA
, 0, 16, TABLE64_TEST_HI
, 0x83FFFFFF, 0xFFFFFFFF },
1149 { E1000_RA2
, 0, 8, TABLE64_TEST_LO
, 0xFFFFFFFF, 0xFFFFFFFF },
1150 { E1000_RA2
, 0, 8, TABLE64_TEST_HI
, 0x83FFFFFF, 0xFFFFFFFF },
1151 { E1000_MTA
, 0, 128,TABLE32_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1155 /* 82575 register test */
1156 static struct igb_reg_test reg_test_82575
[] = {
1157 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1158 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1159 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1160 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1161 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1162 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1163 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
1164 /* Enable all four RX queues before testing. */
1165 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, E1000_RXDCTL_QUEUE_ENABLE
},
1166 /* RDH is read-only for 82575, only test RDT. */
1167 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1168 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, 0 },
1169 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
1170 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1171 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
1172 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1173 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1174 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
1175 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1176 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB3FE, 0x003FFFFB },
1177 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB3FE, 0xFFFFFFFF },
1178 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1179 { E1000_TXCW
, 0x100, 1, PATTERN_TEST
, 0xC000FFFF, 0x0000FFFF },
1180 { E1000_RA
, 0, 16, TABLE64_TEST_LO
, 0xFFFFFFFF, 0xFFFFFFFF },
1181 { E1000_RA
, 0, 16, TABLE64_TEST_HI
, 0x800FFFFF, 0xFFFFFFFF },
1182 { E1000_MTA
, 0, 128, TABLE32_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1186 static bool reg_pattern_test(struct igb_adapter
*adapter
, u64
*data
,
1187 int reg
, u32 mask
, u32 write
)
1189 struct e1000_hw
*hw
= &adapter
->hw
;
1191 static const u32 _test
[] =
1192 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
1193 for (pat
= 0; pat
< ARRAY_SIZE(_test
); pat
++) {
1194 wr32(reg
, (_test
[pat
] & write
));
1195 val
= rd32(reg
) & mask
;
1196 if (val
!= (_test
[pat
] & write
& mask
)) {
1197 dev_err(&adapter
->pdev
->dev
,
1198 "pattern test reg %04X failed: got 0x%08X expected 0x%08X\n",
1199 reg
, val
, (_test
[pat
] & write
& mask
));
1208 static bool reg_set_and_check(struct igb_adapter
*adapter
, u64
*data
,
1209 int reg
, u32 mask
, u32 write
)
1211 struct e1000_hw
*hw
= &adapter
->hw
;
1213 wr32(reg
, write
& mask
);
1215 if ((write
& mask
) != (val
& mask
)) {
1216 dev_err(&adapter
->pdev
->dev
,
1217 "set/check reg %04X test failed: got 0x%08X expected 0x%08X\n", reg
,
1218 (val
& mask
), (write
& mask
));
1226 #define REG_PATTERN_TEST(reg, mask, write) \
1228 if (reg_pattern_test(adapter, data, reg, mask, write)) \
1232 #define REG_SET_AND_CHECK(reg, mask, write) \
1234 if (reg_set_and_check(adapter, data, reg, mask, write)) \
1238 static int igb_reg_test(struct igb_adapter
*adapter
, u64
*data
)
1240 struct e1000_hw
*hw
= &adapter
->hw
;
1241 struct igb_reg_test
*test
;
1242 u32 value
, before
, after
;
1245 switch (adapter
->hw
.mac
.type
) {
1248 test
= reg_test_i350
;
1249 toggle
= 0x7FEFF3FF;
1253 test
= reg_test_i210
;
1254 toggle
= 0x7FEFF3FF;
1257 test
= reg_test_82580
;
1258 toggle
= 0x7FEFF3FF;
1261 test
= reg_test_82576
;
1262 toggle
= 0x7FFFF3FF;
1265 test
= reg_test_82575
;
1266 toggle
= 0x7FFFF3FF;
1270 /* Because the status register is such a special case,
1271 * we handle it separately from the rest of the register
1272 * tests. Some bits are read-only, some toggle, and some
1273 * are writable on newer MACs.
1275 before
= rd32(E1000_STATUS
);
1276 value
= (rd32(E1000_STATUS
) & toggle
);
1277 wr32(E1000_STATUS
, toggle
);
1278 after
= rd32(E1000_STATUS
) & toggle
;
1279 if (value
!= after
) {
1280 dev_err(&adapter
->pdev
->dev
,
1281 "failed STATUS register test got: 0x%08X expected: 0x%08X\n",
1286 /* restore previous status */
1287 wr32(E1000_STATUS
, before
);
1289 /* Perform the remainder of the register test, looping through
1290 * the test table until we either fail or reach the null entry.
1293 for (i
= 0; i
< test
->array_len
; i
++) {
1294 switch (test
->test_type
) {
1296 REG_PATTERN_TEST(test
->reg
+
1297 (i
* test
->reg_offset
),
1302 REG_SET_AND_CHECK(test
->reg
+
1303 (i
* test
->reg_offset
),
1309 (adapter
->hw
.hw_addr
+ test
->reg
)
1310 + (i
* test
->reg_offset
));
1313 REG_PATTERN_TEST(test
->reg
+ (i
* 4),
1317 case TABLE64_TEST_LO
:
1318 REG_PATTERN_TEST(test
->reg
+ (i
* 8),
1322 case TABLE64_TEST_HI
:
1323 REG_PATTERN_TEST((test
->reg
+ 4) + (i
* 8),
1336 static int igb_eeprom_test(struct igb_adapter
*adapter
, u64
*data
)
1340 /* Validate eeprom on all parts but i211 */
1341 if (adapter
->hw
.mac
.type
!= e1000_i211
) {
1342 if (adapter
->hw
.nvm
.ops
.validate(&adapter
->hw
) < 0)
1349 static irqreturn_t
igb_test_intr(int irq
, void *data
)
1351 struct igb_adapter
*adapter
= (struct igb_adapter
*) data
;
1352 struct e1000_hw
*hw
= &adapter
->hw
;
1354 adapter
->test_icr
|= rd32(E1000_ICR
);
1359 static int igb_intr_test(struct igb_adapter
*adapter
, u64
*data
)
1361 struct e1000_hw
*hw
= &adapter
->hw
;
1362 struct net_device
*netdev
= adapter
->netdev
;
1363 u32 mask
, ics_mask
, i
= 0, shared_int
= true;
1364 u32 irq
= adapter
->pdev
->irq
;
1368 /* Hook up test interrupt handler just for this test */
1369 if (adapter
->msix_entries
) {
1370 if (request_irq(adapter
->msix_entries
[0].vector
,
1371 igb_test_intr
, 0, netdev
->name
, adapter
)) {
1375 } else if (adapter
->flags
& IGB_FLAG_HAS_MSI
) {
1377 if (request_irq(irq
,
1378 igb_test_intr
, 0, netdev
->name
, adapter
)) {
1382 } else if (!request_irq(irq
, igb_test_intr
, IRQF_PROBE_SHARED
,
1383 netdev
->name
, adapter
)) {
1385 } else if (request_irq(irq
, igb_test_intr
, IRQF_SHARED
,
1386 netdev
->name
, adapter
)) {
1390 dev_info(&adapter
->pdev
->dev
, "testing %s interrupt\n",
1391 (shared_int
? "shared" : "unshared"));
1393 /* Disable all the interrupts */
1394 wr32(E1000_IMC
, ~0);
1398 /* Define all writable bits for ICS */
1399 switch (hw
->mac
.type
) {
1401 ics_mask
= 0x37F47EDD;
1404 ics_mask
= 0x77D4FBFD;
1407 ics_mask
= 0x77DCFED5;
1413 ics_mask
= 0x77DCFED5;
1416 ics_mask
= 0x7FFFFFFF;
1420 /* Test each interrupt */
1421 for (; i
< 31; i
++) {
1422 /* Interrupt to test */
1425 if (!(mask
& ics_mask
))
1429 /* Disable the interrupt to be reported in
1430 * the cause register and then force the same
1431 * interrupt and see if one gets posted. If
1432 * an interrupt was posted to the bus, the
1435 adapter
->test_icr
= 0;
1437 /* Flush any pending interrupts */
1438 wr32(E1000_ICR
, ~0);
1440 wr32(E1000_IMC
, mask
);
1441 wr32(E1000_ICS
, mask
);
1445 if (adapter
->test_icr
& mask
) {
1451 /* Enable the interrupt to be reported in
1452 * the cause register and then force the same
1453 * interrupt and see if one gets posted. If
1454 * an interrupt was not posted to the bus, the
1457 adapter
->test_icr
= 0;
1459 /* Flush any pending interrupts */
1460 wr32(E1000_ICR
, ~0);
1462 wr32(E1000_IMS
, mask
);
1463 wr32(E1000_ICS
, mask
);
1467 if (!(adapter
->test_icr
& mask
)) {
1473 /* Disable the other interrupts to be reported in
1474 * the cause register and then force the other
1475 * interrupts and see if any get posted. If
1476 * an interrupt was posted to the bus, the
1479 adapter
->test_icr
= 0;
1481 /* Flush any pending interrupts */
1482 wr32(E1000_ICR
, ~0);
1484 wr32(E1000_IMC
, ~mask
);
1485 wr32(E1000_ICS
, ~mask
);
1489 if (adapter
->test_icr
& mask
) {
1496 /* Disable all the interrupts */
1497 wr32(E1000_IMC
, ~0);
1501 /* Unhook test interrupt handler */
1502 if (adapter
->msix_entries
)
1503 free_irq(adapter
->msix_entries
[0].vector
, adapter
);
1505 free_irq(irq
, adapter
);
1510 static void igb_free_desc_rings(struct igb_adapter
*adapter
)
1512 igb_free_tx_resources(&adapter
->test_tx_ring
);
1513 igb_free_rx_resources(&adapter
->test_rx_ring
);
1516 static int igb_setup_desc_rings(struct igb_adapter
*adapter
)
1518 struct igb_ring
*tx_ring
= &adapter
->test_tx_ring
;
1519 struct igb_ring
*rx_ring
= &adapter
->test_rx_ring
;
1520 struct e1000_hw
*hw
= &adapter
->hw
;
1523 /* Setup Tx descriptor ring and Tx buffers */
1524 tx_ring
->count
= IGB_DEFAULT_TXD
;
1525 tx_ring
->dev
= &adapter
->pdev
->dev
;
1526 tx_ring
->netdev
= adapter
->netdev
;
1527 tx_ring
->reg_idx
= adapter
->vfs_allocated_count
;
1529 if (igb_setup_tx_resources(tx_ring
)) {
1534 igb_setup_tctl(adapter
);
1535 igb_configure_tx_ring(adapter
, tx_ring
);
1537 /* Setup Rx descriptor ring and Rx buffers */
1538 rx_ring
->count
= IGB_DEFAULT_RXD
;
1539 rx_ring
->dev
= &adapter
->pdev
->dev
;
1540 rx_ring
->netdev
= adapter
->netdev
;
1541 rx_ring
->reg_idx
= adapter
->vfs_allocated_count
;
1543 if (igb_setup_rx_resources(rx_ring
)) {
1548 /* set the default queue to queue 0 of PF */
1549 wr32(E1000_MRQC
, adapter
->vfs_allocated_count
<< 3);
1551 /* enable receive ring */
1552 igb_setup_rctl(adapter
);
1553 igb_configure_rx_ring(adapter
, rx_ring
);
1555 igb_alloc_rx_buffers(rx_ring
, igb_desc_unused(rx_ring
));
1560 igb_free_desc_rings(adapter
);
1564 static void igb_phy_disable_receiver(struct igb_adapter
*adapter
)
1566 struct e1000_hw
*hw
= &adapter
->hw
;
1568 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1569 igb_write_phy_reg(hw
, 29, 0x001F);
1570 igb_write_phy_reg(hw
, 30, 0x8FFC);
1571 igb_write_phy_reg(hw
, 29, 0x001A);
1572 igb_write_phy_reg(hw
, 30, 0x8FF0);
1575 static int igb_integrated_phy_loopback(struct igb_adapter
*adapter
)
1577 struct e1000_hw
*hw
= &adapter
->hw
;
1580 hw
->mac
.autoneg
= false;
1582 if (hw
->phy
.type
== e1000_phy_m88
) {
1583 if (hw
->phy
.id
!= I210_I_PHY_ID
) {
1584 /* Auto-MDI/MDIX Off */
1585 igb_write_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, 0x0808);
1586 /* reset to update Auto-MDI/MDIX */
1587 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x9140);
1589 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x8140);
1591 /* force 1000, set loopback */
1592 igb_write_phy_reg(hw
, I347AT4_PAGE_SELECT
, 0);
1593 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x4140);
1597 /* add small delay to avoid loopback test failure */
1600 /* force 1000, set loopback */
1601 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x4140);
1603 /* Now set up the MAC to the same speed/duplex as the PHY. */
1604 ctrl_reg
= rd32(E1000_CTRL
);
1605 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1606 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1607 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1608 E1000_CTRL_SPD_1000
|/* Force Speed to 1000 */
1609 E1000_CTRL_FD
| /* Force Duplex to FULL */
1610 E1000_CTRL_SLU
); /* Set link up enable bit */
1612 if (hw
->phy
.type
== e1000_phy_m88
)
1613 ctrl_reg
|= E1000_CTRL_ILOS
; /* Invert Loss of Signal */
1615 wr32(E1000_CTRL
, ctrl_reg
);
1617 /* Disable the receiver on the PHY so when a cable is plugged in, the
1618 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1620 if (hw
->phy
.type
== e1000_phy_m88
)
1621 igb_phy_disable_receiver(adapter
);
1627 static int igb_set_phy_loopback(struct igb_adapter
*adapter
)
1629 return igb_integrated_phy_loopback(adapter
);
1632 static int igb_setup_loopback_test(struct igb_adapter
*adapter
)
1634 struct e1000_hw
*hw
= &adapter
->hw
;
1637 reg
= rd32(E1000_CTRL_EXT
);
1639 /* use CTRL_EXT to identify link type as SGMII can appear as copper */
1640 if (reg
& E1000_CTRL_EXT_LINK_MODE_MASK
) {
1641 if ((hw
->device_id
== E1000_DEV_ID_DH89XXCC_SGMII
) ||
1642 (hw
->device_id
== E1000_DEV_ID_DH89XXCC_SERDES
) ||
1643 (hw
->device_id
== E1000_DEV_ID_DH89XXCC_BACKPLANE
) ||
1644 (hw
->device_id
== E1000_DEV_ID_DH89XXCC_SFP
)) {
1646 /* Enable DH89xxCC MPHY for near end loopback */
1647 reg
= rd32(E1000_MPHY_ADDR_CTL
);
1648 reg
= (reg
& E1000_MPHY_ADDR_CTL_OFFSET_MASK
) |
1649 E1000_MPHY_PCS_CLK_REG_OFFSET
;
1650 wr32(E1000_MPHY_ADDR_CTL
, reg
);
1652 reg
= rd32(E1000_MPHY_DATA
);
1653 reg
|= E1000_MPHY_PCS_CLK_REG_DIGINELBEN
;
1654 wr32(E1000_MPHY_DATA
, reg
);
1657 reg
= rd32(E1000_RCTL
);
1658 reg
|= E1000_RCTL_LBM_TCVR
;
1659 wr32(E1000_RCTL
, reg
);
1661 wr32(E1000_SCTL
, E1000_ENABLE_SERDES_LOOPBACK
);
1663 reg
= rd32(E1000_CTRL
);
1664 reg
&= ~(E1000_CTRL_RFCE
|
1667 reg
|= E1000_CTRL_SLU
|
1669 wr32(E1000_CTRL
, reg
);
1671 /* Unset switch control to serdes energy detect */
1672 reg
= rd32(E1000_CONNSW
);
1673 reg
&= ~E1000_CONNSW_ENRGSRC
;
1674 wr32(E1000_CONNSW
, reg
);
1676 /* Unset sigdetect for SERDES loopback on
1677 * 82580 and newer devices.
1679 if (hw
->mac
.type
>= e1000_82580
) {
1680 reg
= rd32(E1000_PCS_CFG0
);
1681 reg
|= E1000_PCS_CFG_IGN_SD
;
1682 wr32(E1000_PCS_CFG0
, reg
);
1685 /* Set PCS register for forced speed */
1686 reg
= rd32(E1000_PCS_LCTL
);
1687 reg
&= ~E1000_PCS_LCTL_AN_ENABLE
; /* Disable Autoneg*/
1688 reg
|= E1000_PCS_LCTL_FLV_LINK_UP
| /* Force link up */
1689 E1000_PCS_LCTL_FSV_1000
| /* Force 1000 */
1690 E1000_PCS_LCTL_FDV_FULL
| /* SerDes Full duplex */
1691 E1000_PCS_LCTL_FSD
| /* Force Speed */
1692 E1000_PCS_LCTL_FORCE_LINK
; /* Force Link */
1693 wr32(E1000_PCS_LCTL
, reg
);
1698 return igb_set_phy_loopback(adapter
);
1701 static void igb_loopback_cleanup(struct igb_adapter
*adapter
)
1703 struct e1000_hw
*hw
= &adapter
->hw
;
1707 if ((hw
->device_id
== E1000_DEV_ID_DH89XXCC_SGMII
) ||
1708 (hw
->device_id
== E1000_DEV_ID_DH89XXCC_SERDES
) ||
1709 (hw
->device_id
== E1000_DEV_ID_DH89XXCC_BACKPLANE
) ||
1710 (hw
->device_id
== E1000_DEV_ID_DH89XXCC_SFP
)) {
1713 /* Disable near end loopback on DH89xxCC */
1714 reg
= rd32(E1000_MPHY_ADDR_CTL
);
1715 reg
= (reg
& E1000_MPHY_ADDR_CTL_OFFSET_MASK
) |
1716 E1000_MPHY_PCS_CLK_REG_OFFSET
;
1717 wr32(E1000_MPHY_ADDR_CTL
, reg
);
1719 reg
= rd32(E1000_MPHY_DATA
);
1720 reg
&= ~E1000_MPHY_PCS_CLK_REG_DIGINELBEN
;
1721 wr32(E1000_MPHY_DATA
, reg
);
1724 rctl
= rd32(E1000_RCTL
);
1725 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
1726 wr32(E1000_RCTL
, rctl
);
1728 hw
->mac
.autoneg
= true;
1729 igb_read_phy_reg(hw
, PHY_CONTROL
, &phy_reg
);
1730 if (phy_reg
& MII_CR_LOOPBACK
) {
1731 phy_reg
&= ~MII_CR_LOOPBACK
;
1732 igb_write_phy_reg(hw
, PHY_CONTROL
, phy_reg
);
1733 igb_phy_sw_reset(hw
);
1737 static void igb_create_lbtest_frame(struct sk_buff
*skb
,
1738 unsigned int frame_size
)
1740 memset(skb
->data
, 0xFF, frame_size
);
1742 memset(&skb
->data
[frame_size
], 0xAA, frame_size
- 1);
1743 memset(&skb
->data
[frame_size
+ 10], 0xBE, 1);
1744 memset(&skb
->data
[frame_size
+ 12], 0xAF, 1);
1747 static int igb_check_lbtest_frame(struct igb_rx_buffer
*rx_buffer
,
1748 unsigned int frame_size
)
1750 unsigned char *data
;
1755 data
= kmap(rx_buffer
->page
);
1757 if (data
[3] != 0xFF ||
1758 data
[frame_size
+ 10] != 0xBE ||
1759 data
[frame_size
+ 12] != 0xAF)
1762 kunmap(rx_buffer
->page
);
1767 static int igb_clean_test_rings(struct igb_ring
*rx_ring
,
1768 struct igb_ring
*tx_ring
,
1771 union e1000_adv_rx_desc
*rx_desc
;
1772 struct igb_rx_buffer
*rx_buffer_info
;
1773 struct igb_tx_buffer
*tx_buffer_info
;
1774 u16 rx_ntc
, tx_ntc
, count
= 0;
1776 /* initialize next to clean and descriptor values */
1777 rx_ntc
= rx_ring
->next_to_clean
;
1778 tx_ntc
= tx_ring
->next_to_clean
;
1779 rx_desc
= IGB_RX_DESC(rx_ring
, rx_ntc
);
1781 while (igb_test_staterr(rx_desc
, E1000_RXD_STAT_DD
)) {
1782 /* check Rx buffer */
1783 rx_buffer_info
= &rx_ring
->rx_buffer_info
[rx_ntc
];
1785 /* sync Rx buffer for CPU read */
1786 dma_sync_single_for_cpu(rx_ring
->dev
,
1787 rx_buffer_info
->dma
,
1791 /* verify contents of skb */
1792 if (igb_check_lbtest_frame(rx_buffer_info
, size
))
1795 /* sync Rx buffer for device write */
1796 dma_sync_single_for_device(rx_ring
->dev
,
1797 rx_buffer_info
->dma
,
1801 /* unmap buffer on Tx side */
1802 tx_buffer_info
= &tx_ring
->tx_buffer_info
[tx_ntc
];
1803 igb_unmap_and_free_tx_resource(tx_ring
, tx_buffer_info
);
1805 /* increment Rx/Tx next to clean counters */
1807 if (rx_ntc
== rx_ring
->count
)
1810 if (tx_ntc
== tx_ring
->count
)
1813 /* fetch next descriptor */
1814 rx_desc
= IGB_RX_DESC(rx_ring
, rx_ntc
);
1817 netdev_tx_reset_queue(txring_txq(tx_ring
));
1819 /* re-map buffers to ring, store next to clean values */
1820 igb_alloc_rx_buffers(rx_ring
, count
);
1821 rx_ring
->next_to_clean
= rx_ntc
;
1822 tx_ring
->next_to_clean
= tx_ntc
;
1827 static int igb_run_loopback_test(struct igb_adapter
*adapter
)
1829 struct igb_ring
*tx_ring
= &adapter
->test_tx_ring
;
1830 struct igb_ring
*rx_ring
= &adapter
->test_rx_ring
;
1831 u16 i
, j
, lc
, good_cnt
;
1833 unsigned int size
= IGB_RX_HDR_LEN
;
1834 netdev_tx_t tx_ret_val
;
1835 struct sk_buff
*skb
;
1837 /* allocate test skb */
1838 skb
= alloc_skb(size
, GFP_KERNEL
);
1842 /* place data into test skb */
1843 igb_create_lbtest_frame(skb
, size
);
1846 /* Calculate the loop count based on the largest descriptor ring
1847 * The idea is to wrap the largest ring a number of times using 64
1848 * send/receive pairs during each loop
1851 if (rx_ring
->count
<= tx_ring
->count
)
1852 lc
= ((tx_ring
->count
/ 64) * 2) + 1;
1854 lc
= ((rx_ring
->count
/ 64) * 2) + 1;
1856 for (j
= 0; j
<= lc
; j
++) { /* loop count loop */
1857 /* reset count of good packets */
1860 /* place 64 packets on the transmit queue*/
1861 for (i
= 0; i
< 64; i
++) {
1863 tx_ret_val
= igb_xmit_frame_ring(skb
, tx_ring
);
1864 if (tx_ret_val
== NETDEV_TX_OK
)
1868 if (good_cnt
!= 64) {
1873 /* allow 200 milliseconds for packets to go from Tx to Rx */
1876 good_cnt
= igb_clean_test_rings(rx_ring
, tx_ring
, size
);
1877 if (good_cnt
!= 64) {
1881 } /* end loop count loop */
1883 /* free the original skb */
1889 static int igb_loopback_test(struct igb_adapter
*adapter
, u64
*data
)
1891 /* PHY loopback cannot be performed if SoL/IDER
1892 * sessions are active
1894 if (igb_check_reset_block(&adapter
->hw
)) {
1895 dev_err(&adapter
->pdev
->dev
,
1896 "Cannot do PHY loopback test when SoL/IDER is active.\n");
1901 if (adapter
->hw
.mac
.type
== e1000_i354
) {
1902 dev_info(&adapter
->pdev
->dev
,
1903 "Loopback test not supported on i354.\n");
1907 *data
= igb_setup_desc_rings(adapter
);
1910 *data
= igb_setup_loopback_test(adapter
);
1913 *data
= igb_run_loopback_test(adapter
);
1914 igb_loopback_cleanup(adapter
);
1917 igb_free_desc_rings(adapter
);
1922 static int igb_link_test(struct igb_adapter
*adapter
, u64
*data
)
1924 struct e1000_hw
*hw
= &adapter
->hw
;
1926 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1928 hw
->mac
.serdes_has_link
= false;
1930 /* On some blade server designs, link establishment
1931 * could take as long as 2-3 minutes
1934 hw
->mac
.ops
.check_for_link(&adapter
->hw
);
1935 if (hw
->mac
.serdes_has_link
)
1938 } while (i
++ < 3750);
1942 hw
->mac
.ops
.check_for_link(&adapter
->hw
);
1943 if (hw
->mac
.autoneg
)
1946 if (!(rd32(E1000_STATUS
) & E1000_STATUS_LU
))
1952 static void igb_diag_test(struct net_device
*netdev
,
1953 struct ethtool_test
*eth_test
, u64
*data
)
1955 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1956 u16 autoneg_advertised
;
1957 u8 forced_speed_duplex
, autoneg
;
1958 bool if_running
= netif_running(netdev
);
1960 set_bit(__IGB_TESTING
, &adapter
->state
);
1961 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1964 /* save speed, duplex, autoneg settings */
1965 autoneg_advertised
= adapter
->hw
.phy
.autoneg_advertised
;
1966 forced_speed_duplex
= adapter
->hw
.mac
.forced_speed_duplex
;
1967 autoneg
= adapter
->hw
.mac
.autoneg
;
1969 dev_info(&adapter
->pdev
->dev
, "offline testing starting\n");
1971 /* power up link for link test */
1972 igb_power_up_link(adapter
);
1974 /* Link test performed before hardware reset so autoneg doesn't
1975 * interfere with test result
1977 if (igb_link_test(adapter
, &data
[4]))
1978 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1981 /* indicate we're in test mode */
1986 if (igb_reg_test(adapter
, &data
[0]))
1987 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1990 if (igb_eeprom_test(adapter
, &data
[1]))
1991 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1994 if (igb_intr_test(adapter
, &data
[2]))
1995 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1998 /* power up link for loopback test */
1999 igb_power_up_link(adapter
);
2000 if (igb_loopback_test(adapter
, &data
[3]))
2001 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
2003 /* restore speed, duplex, autoneg settings */
2004 adapter
->hw
.phy
.autoneg_advertised
= autoneg_advertised
;
2005 adapter
->hw
.mac
.forced_speed_duplex
= forced_speed_duplex
;
2006 adapter
->hw
.mac
.autoneg
= autoneg
;
2008 /* force this routine to wait until autoneg complete/timeout */
2009 adapter
->hw
.phy
.autoneg_wait_to_complete
= true;
2011 adapter
->hw
.phy
.autoneg_wait_to_complete
= false;
2013 clear_bit(__IGB_TESTING
, &adapter
->state
);
2017 dev_info(&adapter
->pdev
->dev
, "online testing starting\n");
2019 /* PHY is powered down when interface is down */
2020 if (if_running
&& igb_link_test(adapter
, &data
[4]))
2021 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
2025 /* Online tests aren't run; pass by default */
2031 clear_bit(__IGB_TESTING
, &adapter
->state
);
2033 msleep_interruptible(4 * 1000);
2036 static void igb_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
2038 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2040 wol
->supported
= WAKE_UCAST
| WAKE_MCAST
|
2041 WAKE_BCAST
| WAKE_MAGIC
|
2045 if (!(adapter
->flags
& IGB_FLAG_WOL_SUPPORTED
))
2048 /* apply any specific unsupported masks here */
2049 switch (adapter
->hw
.device_id
) {
2054 if (adapter
->wol
& E1000_WUFC_EX
)
2055 wol
->wolopts
|= WAKE_UCAST
;
2056 if (adapter
->wol
& E1000_WUFC_MC
)
2057 wol
->wolopts
|= WAKE_MCAST
;
2058 if (adapter
->wol
& E1000_WUFC_BC
)
2059 wol
->wolopts
|= WAKE_BCAST
;
2060 if (adapter
->wol
& E1000_WUFC_MAG
)
2061 wol
->wolopts
|= WAKE_MAGIC
;
2062 if (adapter
->wol
& E1000_WUFC_LNKC
)
2063 wol
->wolopts
|= WAKE_PHY
;
2066 static int igb_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
2068 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2070 if (wol
->wolopts
& (WAKE_ARP
| WAKE_MAGICSECURE
))
2073 if (!(adapter
->flags
& IGB_FLAG_WOL_SUPPORTED
))
2074 return wol
->wolopts
? -EOPNOTSUPP
: 0;
2076 /* these settings will always override what we currently have */
2079 if (wol
->wolopts
& WAKE_UCAST
)
2080 adapter
->wol
|= E1000_WUFC_EX
;
2081 if (wol
->wolopts
& WAKE_MCAST
)
2082 adapter
->wol
|= E1000_WUFC_MC
;
2083 if (wol
->wolopts
& WAKE_BCAST
)
2084 adapter
->wol
|= E1000_WUFC_BC
;
2085 if (wol
->wolopts
& WAKE_MAGIC
)
2086 adapter
->wol
|= E1000_WUFC_MAG
;
2087 if (wol
->wolopts
& WAKE_PHY
)
2088 adapter
->wol
|= E1000_WUFC_LNKC
;
2089 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
2094 /* bit defines for adapter->led_status */
2095 #define IGB_LED_ON 0
2097 static int igb_set_phys_id(struct net_device
*netdev
,
2098 enum ethtool_phys_id_state state
)
2100 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2101 struct e1000_hw
*hw
= &adapter
->hw
;
2104 case ETHTOOL_ID_ACTIVE
:
2110 case ETHTOOL_ID_OFF
:
2113 case ETHTOOL_ID_INACTIVE
:
2115 clear_bit(IGB_LED_ON
, &adapter
->led_status
);
2116 igb_cleanup_led(hw
);
2123 static int igb_set_coalesce(struct net_device
*netdev
,
2124 struct ethtool_coalesce
*ec
)
2126 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2129 if ((ec
->rx_coalesce_usecs
> IGB_MAX_ITR_USECS
) ||
2130 ((ec
->rx_coalesce_usecs
> 3) &&
2131 (ec
->rx_coalesce_usecs
< IGB_MIN_ITR_USECS
)) ||
2132 (ec
->rx_coalesce_usecs
== 2))
2135 if ((ec
->tx_coalesce_usecs
> IGB_MAX_ITR_USECS
) ||
2136 ((ec
->tx_coalesce_usecs
> 3) &&
2137 (ec
->tx_coalesce_usecs
< IGB_MIN_ITR_USECS
)) ||
2138 (ec
->tx_coalesce_usecs
== 2))
2141 if ((adapter
->flags
& IGB_FLAG_QUEUE_PAIRS
) && ec
->tx_coalesce_usecs
)
2144 /* If ITR is disabled, disable DMAC */
2145 if (ec
->rx_coalesce_usecs
== 0) {
2146 if (adapter
->flags
& IGB_FLAG_DMAC
)
2147 adapter
->flags
&= ~IGB_FLAG_DMAC
;
2150 /* convert to rate of irq's per second */
2151 if (ec
->rx_coalesce_usecs
&& ec
->rx_coalesce_usecs
<= 3)
2152 adapter
->rx_itr_setting
= ec
->rx_coalesce_usecs
;
2154 adapter
->rx_itr_setting
= ec
->rx_coalesce_usecs
<< 2;
2156 /* convert to rate of irq's per second */
2157 if (adapter
->flags
& IGB_FLAG_QUEUE_PAIRS
)
2158 adapter
->tx_itr_setting
= adapter
->rx_itr_setting
;
2159 else if (ec
->tx_coalesce_usecs
&& ec
->tx_coalesce_usecs
<= 3)
2160 adapter
->tx_itr_setting
= ec
->tx_coalesce_usecs
;
2162 adapter
->tx_itr_setting
= ec
->tx_coalesce_usecs
<< 2;
2164 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
2165 struct igb_q_vector
*q_vector
= adapter
->q_vector
[i
];
2166 q_vector
->tx
.work_limit
= adapter
->tx_work_limit
;
2167 if (q_vector
->rx
.ring
)
2168 q_vector
->itr_val
= adapter
->rx_itr_setting
;
2170 q_vector
->itr_val
= adapter
->tx_itr_setting
;
2171 if (q_vector
->itr_val
&& q_vector
->itr_val
<= 3)
2172 q_vector
->itr_val
= IGB_START_ITR
;
2173 q_vector
->set_itr
= 1;
2179 static int igb_get_coalesce(struct net_device
*netdev
,
2180 struct ethtool_coalesce
*ec
)
2182 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2184 if (adapter
->rx_itr_setting
<= 3)
2185 ec
->rx_coalesce_usecs
= adapter
->rx_itr_setting
;
2187 ec
->rx_coalesce_usecs
= adapter
->rx_itr_setting
>> 2;
2189 if (!(adapter
->flags
& IGB_FLAG_QUEUE_PAIRS
)) {
2190 if (adapter
->tx_itr_setting
<= 3)
2191 ec
->tx_coalesce_usecs
= adapter
->tx_itr_setting
;
2193 ec
->tx_coalesce_usecs
= adapter
->tx_itr_setting
>> 2;
2199 static int igb_nway_reset(struct net_device
*netdev
)
2201 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2202 if (netif_running(netdev
))
2203 igb_reinit_locked(adapter
);
2207 static int igb_get_sset_count(struct net_device
*netdev
, int sset
)
2211 return IGB_STATS_LEN
;
2213 return IGB_TEST_LEN
;
2219 static void igb_get_ethtool_stats(struct net_device
*netdev
,
2220 struct ethtool_stats
*stats
, u64
*data
)
2222 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2223 struct rtnl_link_stats64
*net_stats
= &adapter
->stats64
;
2225 struct igb_ring
*ring
;
2229 spin_lock(&adapter
->stats64_lock
);
2230 igb_update_stats(adapter
, net_stats
);
2232 for (i
= 0; i
< IGB_GLOBAL_STATS_LEN
; i
++) {
2233 p
= (char *)adapter
+ igb_gstrings_stats
[i
].stat_offset
;
2234 data
[i
] = (igb_gstrings_stats
[i
].sizeof_stat
==
2235 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
2237 for (j
= 0; j
< IGB_NETDEV_STATS_LEN
; j
++, i
++) {
2238 p
= (char *)net_stats
+ igb_gstrings_net_stats
[j
].stat_offset
;
2239 data
[i
] = (igb_gstrings_net_stats
[j
].sizeof_stat
==
2240 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
2242 for (j
= 0; j
< adapter
->num_tx_queues
; j
++) {
2245 ring
= adapter
->tx_ring
[j
];
2247 start
= u64_stats_fetch_begin_bh(&ring
->tx_syncp
);
2248 data
[i
] = ring
->tx_stats
.packets
;
2249 data
[i
+1] = ring
->tx_stats
.bytes
;
2250 data
[i
+2] = ring
->tx_stats
.restart_queue
;
2251 } while (u64_stats_fetch_retry_bh(&ring
->tx_syncp
, start
));
2253 start
= u64_stats_fetch_begin_bh(&ring
->tx_syncp2
);
2254 restart2
= ring
->tx_stats
.restart_queue2
;
2255 } while (u64_stats_fetch_retry_bh(&ring
->tx_syncp2
, start
));
2256 data
[i
+2] += restart2
;
2258 i
+= IGB_TX_QUEUE_STATS_LEN
;
2260 for (j
= 0; j
< adapter
->num_rx_queues
; j
++) {
2261 ring
= adapter
->rx_ring
[j
];
2263 start
= u64_stats_fetch_begin_bh(&ring
->rx_syncp
);
2264 data
[i
] = ring
->rx_stats
.packets
;
2265 data
[i
+1] = ring
->rx_stats
.bytes
;
2266 data
[i
+2] = ring
->rx_stats
.drops
;
2267 data
[i
+3] = ring
->rx_stats
.csum_err
;
2268 data
[i
+4] = ring
->rx_stats
.alloc_failed
;
2269 } while (u64_stats_fetch_retry_bh(&ring
->rx_syncp
, start
));
2270 i
+= IGB_RX_QUEUE_STATS_LEN
;
2272 spin_unlock(&adapter
->stats64_lock
);
2275 static void igb_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*data
)
2277 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2281 switch (stringset
) {
2283 memcpy(data
, *igb_gstrings_test
,
2284 IGB_TEST_LEN
*ETH_GSTRING_LEN
);
2287 for (i
= 0; i
< IGB_GLOBAL_STATS_LEN
; i
++) {
2288 memcpy(p
, igb_gstrings_stats
[i
].stat_string
,
2290 p
+= ETH_GSTRING_LEN
;
2292 for (i
= 0; i
< IGB_NETDEV_STATS_LEN
; i
++) {
2293 memcpy(p
, igb_gstrings_net_stats
[i
].stat_string
,
2295 p
+= ETH_GSTRING_LEN
;
2297 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2298 sprintf(p
, "tx_queue_%u_packets", i
);
2299 p
+= ETH_GSTRING_LEN
;
2300 sprintf(p
, "tx_queue_%u_bytes", i
);
2301 p
+= ETH_GSTRING_LEN
;
2302 sprintf(p
, "tx_queue_%u_restart", i
);
2303 p
+= ETH_GSTRING_LEN
;
2305 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2306 sprintf(p
, "rx_queue_%u_packets", i
);
2307 p
+= ETH_GSTRING_LEN
;
2308 sprintf(p
, "rx_queue_%u_bytes", i
);
2309 p
+= ETH_GSTRING_LEN
;
2310 sprintf(p
, "rx_queue_%u_drops", i
);
2311 p
+= ETH_GSTRING_LEN
;
2312 sprintf(p
, "rx_queue_%u_csum_err", i
);
2313 p
+= ETH_GSTRING_LEN
;
2314 sprintf(p
, "rx_queue_%u_alloc_failed", i
);
2315 p
+= ETH_GSTRING_LEN
;
2317 /* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
2322 static int igb_get_ts_info(struct net_device
*dev
,
2323 struct ethtool_ts_info
*info
)
2325 struct igb_adapter
*adapter
= netdev_priv(dev
);
2327 switch (adapter
->hw
.mac
.type
) {
2329 info
->so_timestamping
=
2330 SOF_TIMESTAMPING_TX_SOFTWARE
|
2331 SOF_TIMESTAMPING_RX_SOFTWARE
|
2332 SOF_TIMESTAMPING_SOFTWARE
;
2340 info
->so_timestamping
=
2341 SOF_TIMESTAMPING_TX_SOFTWARE
|
2342 SOF_TIMESTAMPING_RX_SOFTWARE
|
2343 SOF_TIMESTAMPING_SOFTWARE
|
2344 SOF_TIMESTAMPING_TX_HARDWARE
|
2345 SOF_TIMESTAMPING_RX_HARDWARE
|
2346 SOF_TIMESTAMPING_RAW_HARDWARE
;
2348 if (adapter
->ptp_clock
)
2349 info
->phc_index
= ptp_clock_index(adapter
->ptp_clock
);
2351 info
->phc_index
= -1;
2354 (1 << HWTSTAMP_TX_OFF
) |
2355 (1 << HWTSTAMP_TX_ON
);
2357 info
->rx_filters
= 1 << HWTSTAMP_FILTER_NONE
;
2359 /* 82576 does not support timestamping all packets. */
2360 if (adapter
->hw
.mac
.type
>= e1000_82580
)
2361 info
->rx_filters
|= 1 << HWTSTAMP_FILTER_ALL
;
2364 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC
) |
2365 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
) |
2366 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC
) |
2367 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC
) |
2368 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ
) |
2369 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
) |
2370 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT
);
2378 static int igb_get_rss_hash_opts(struct igb_adapter
*adapter
,
2379 struct ethtool_rxnfc
*cmd
)
2383 /* Report default options for RSS on igb */
2384 switch (cmd
->flow_type
) {
2386 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
2388 if (adapter
->flags
& IGB_FLAG_RSS_FIELD_IPV4_UDP
)
2389 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
2391 case AH_ESP_V4_FLOW
:
2395 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
2398 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
2400 if (adapter
->flags
& IGB_FLAG_RSS_FIELD_IPV6_UDP
)
2401 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
2403 case AH_ESP_V6_FLOW
:
2407 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
2416 static int igb_get_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
,
2419 struct igb_adapter
*adapter
= netdev_priv(dev
);
2420 int ret
= -EOPNOTSUPP
;
2423 case ETHTOOL_GRXRINGS
:
2424 cmd
->data
= adapter
->num_rx_queues
;
2428 ret
= igb_get_rss_hash_opts(adapter
, cmd
);
2437 #define UDP_RSS_FLAGS (IGB_FLAG_RSS_FIELD_IPV4_UDP | \
2438 IGB_FLAG_RSS_FIELD_IPV6_UDP)
2439 static int igb_set_rss_hash_opt(struct igb_adapter
*adapter
,
2440 struct ethtool_rxnfc
*nfc
)
2442 u32 flags
= adapter
->flags
;
2444 /* RSS does not support anything other than hashing
2445 * to queues on src and dst IPs and ports
2447 if (nfc
->data
& ~(RXH_IP_SRC
| RXH_IP_DST
|
2448 RXH_L4_B_0_1
| RXH_L4_B_2_3
))
2451 switch (nfc
->flow_type
) {
2454 if (!(nfc
->data
& RXH_IP_SRC
) ||
2455 !(nfc
->data
& RXH_IP_DST
) ||
2456 !(nfc
->data
& RXH_L4_B_0_1
) ||
2457 !(nfc
->data
& RXH_L4_B_2_3
))
2461 if (!(nfc
->data
& RXH_IP_SRC
) ||
2462 !(nfc
->data
& RXH_IP_DST
))
2464 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2466 flags
&= ~IGB_FLAG_RSS_FIELD_IPV4_UDP
;
2468 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2469 flags
|= IGB_FLAG_RSS_FIELD_IPV4_UDP
;
2476 if (!(nfc
->data
& RXH_IP_SRC
) ||
2477 !(nfc
->data
& RXH_IP_DST
))
2479 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2481 flags
&= ~IGB_FLAG_RSS_FIELD_IPV6_UDP
;
2483 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2484 flags
|= IGB_FLAG_RSS_FIELD_IPV6_UDP
;
2490 case AH_ESP_V4_FLOW
:
2494 case AH_ESP_V6_FLOW
:
2498 if (!(nfc
->data
& RXH_IP_SRC
) ||
2499 !(nfc
->data
& RXH_IP_DST
) ||
2500 (nfc
->data
& RXH_L4_B_0_1
) ||
2501 (nfc
->data
& RXH_L4_B_2_3
))
2508 /* if we changed something we need to update flags */
2509 if (flags
!= adapter
->flags
) {
2510 struct e1000_hw
*hw
= &adapter
->hw
;
2511 u32 mrqc
= rd32(E1000_MRQC
);
2513 if ((flags
& UDP_RSS_FLAGS
) &&
2514 !(adapter
->flags
& UDP_RSS_FLAGS
))
2515 dev_err(&adapter
->pdev
->dev
,
2516 "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
2518 adapter
->flags
= flags
;
2520 /* Perform hash on these packet types */
2521 mrqc
|= E1000_MRQC_RSS_FIELD_IPV4
|
2522 E1000_MRQC_RSS_FIELD_IPV4_TCP
|
2523 E1000_MRQC_RSS_FIELD_IPV6
|
2524 E1000_MRQC_RSS_FIELD_IPV6_TCP
;
2526 mrqc
&= ~(E1000_MRQC_RSS_FIELD_IPV4_UDP
|
2527 E1000_MRQC_RSS_FIELD_IPV6_UDP
);
2529 if (flags
& IGB_FLAG_RSS_FIELD_IPV4_UDP
)
2530 mrqc
|= E1000_MRQC_RSS_FIELD_IPV4_UDP
;
2532 if (flags
& IGB_FLAG_RSS_FIELD_IPV6_UDP
)
2533 mrqc
|= E1000_MRQC_RSS_FIELD_IPV6_UDP
;
2535 wr32(E1000_MRQC
, mrqc
);
2541 static int igb_set_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
)
2543 struct igb_adapter
*adapter
= netdev_priv(dev
);
2544 int ret
= -EOPNOTSUPP
;
2548 ret
= igb_set_rss_hash_opt(adapter
, cmd
);
2557 static int igb_get_eee(struct net_device
*netdev
, struct ethtool_eee
*edata
)
2559 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2560 struct e1000_hw
*hw
= &adapter
->hw
;
2561 u32 ipcnfg
, eeer
, ret_val
;
2564 if ((hw
->mac
.type
< e1000_i350
) ||
2565 (hw
->phy
.media_type
!= e1000_media_type_copper
))
2568 edata
->supported
= (SUPPORTED_1000baseT_Full
|
2569 SUPPORTED_100baseT_Full
);
2571 ipcnfg
= rd32(E1000_IPCNFG
);
2572 eeer
= rd32(E1000_EEER
);
2574 /* EEE status on negotiated link */
2575 if (ipcnfg
& E1000_IPCNFG_EEE_1G_AN
)
2576 edata
->advertised
= ADVERTISED_1000baseT_Full
;
2578 if (ipcnfg
& E1000_IPCNFG_EEE_100M_AN
)
2579 edata
->advertised
|= ADVERTISED_100baseT_Full
;
2581 /* EEE Link Partner Advertised */
2582 switch (hw
->mac
.type
) {
2584 ret_val
= igb_read_emi_reg(hw
, E1000_EEE_LP_ADV_ADDR_I350
,
2589 edata
->lp_advertised
= mmd_eee_adv_to_ethtool_adv_t(phy_data
);
2594 ret_val
= igb_read_xmdio_reg(hw
, E1000_EEE_LP_ADV_ADDR_I210
,
2595 E1000_EEE_LP_ADV_DEV_I210
,
2600 edata
->lp_advertised
= mmd_eee_adv_to_ethtool_adv_t(phy_data
);
2607 if (eeer
& E1000_EEER_EEE_NEG
)
2608 edata
->eee_active
= true;
2610 edata
->eee_enabled
= !hw
->dev_spec
._82575
.eee_disable
;
2612 if (eeer
& E1000_EEER_TX_LPI_EN
)
2613 edata
->tx_lpi_enabled
= true;
2615 /* Report correct negotiated EEE status for devices that
2616 * wrongly report EEE at half-duplex
2618 if (adapter
->link_duplex
== HALF_DUPLEX
) {
2619 edata
->eee_enabled
= false;
2620 edata
->eee_active
= false;
2621 edata
->tx_lpi_enabled
= false;
2622 edata
->advertised
&= ~edata
->advertised
;
2628 static int igb_set_eee(struct net_device
*netdev
,
2629 struct ethtool_eee
*edata
)
2631 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2632 struct e1000_hw
*hw
= &adapter
->hw
;
2633 struct ethtool_eee eee_curr
;
2636 if ((hw
->mac
.type
< e1000_i350
) ||
2637 (hw
->phy
.media_type
!= e1000_media_type_copper
))
2640 ret_val
= igb_get_eee(netdev
, &eee_curr
);
2644 if (eee_curr
.eee_enabled
) {
2645 if (eee_curr
.tx_lpi_enabled
!= edata
->tx_lpi_enabled
) {
2646 dev_err(&adapter
->pdev
->dev
,
2647 "Setting EEE tx-lpi is not supported\n");
2651 /* Tx LPI timer is not implemented currently */
2652 if (edata
->tx_lpi_timer
) {
2653 dev_err(&adapter
->pdev
->dev
,
2654 "Setting EEE Tx LPI timer is not supported\n");
2658 if (eee_curr
.advertised
!= edata
->advertised
) {
2659 dev_err(&adapter
->pdev
->dev
,
2660 "Setting EEE Advertisement is not supported\n");
2664 } else if (!edata
->eee_enabled
) {
2665 dev_err(&adapter
->pdev
->dev
,
2666 "Setting EEE options are not supported with EEE disabled\n");
2670 if (hw
->dev_spec
._82575
.eee_disable
!= !edata
->eee_enabled
) {
2671 hw
->dev_spec
._82575
.eee_disable
= !edata
->eee_enabled
;
2672 igb_set_eee_i350(hw
);
2675 if (!netif_running(netdev
))
2682 static int igb_get_module_info(struct net_device
*netdev
,
2683 struct ethtool_modinfo
*modinfo
)
2685 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2686 struct e1000_hw
*hw
= &adapter
->hw
;
2687 u32 status
= E1000_SUCCESS
;
2688 u16 sff8472_rev
, addr_mode
;
2689 bool page_swap
= false;
2691 if ((hw
->phy
.media_type
== e1000_media_type_copper
) ||
2692 (hw
->phy
.media_type
== e1000_media_type_unknown
))
2695 /* Check whether we support SFF-8472 or not */
2696 status
= igb_read_phy_reg_i2c(hw
, IGB_SFF_8472_COMP
, &sff8472_rev
);
2697 if (status
!= E1000_SUCCESS
)
2700 /* addressing mode is not supported */
2701 status
= igb_read_phy_reg_i2c(hw
, IGB_SFF_8472_SWAP
, &addr_mode
);
2702 if (status
!= E1000_SUCCESS
)
2705 /* addressing mode is not supported */
2706 if ((addr_mode
& 0xFF) & IGB_SFF_ADDRESSING_MODE
) {
2707 hw_dbg("Address change required to access page 0xA2, but not supported. Please report the module type to the driver maintainers.\n");
2711 if ((sff8472_rev
& 0xFF) == IGB_SFF_8472_UNSUP
|| page_swap
) {
2712 /* We have an SFP, but it does not support SFF-8472 */
2713 modinfo
->type
= ETH_MODULE_SFF_8079
;
2714 modinfo
->eeprom_len
= ETH_MODULE_SFF_8079_LEN
;
2716 /* We have an SFP which supports a revision of SFF-8472 */
2717 modinfo
->type
= ETH_MODULE_SFF_8472
;
2718 modinfo
->eeprom_len
= ETH_MODULE_SFF_8472_LEN
;
2724 static int igb_get_module_eeprom(struct net_device
*netdev
,
2725 struct ethtool_eeprom
*ee
, u8
*data
)
2727 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2728 struct e1000_hw
*hw
= &adapter
->hw
;
2729 u32 status
= E1000_SUCCESS
;
2731 u16 first_word
, last_word
;
2737 first_word
= ee
->offset
>> 1;
2738 last_word
= (ee
->offset
+ ee
->len
- 1) >> 1;
2740 dataword
= kmalloc(sizeof(u16
) * (last_word
- first_word
+ 1),
2745 /* Read EEPROM block, SFF-8079/SFF-8472, word at a time */
2746 for (i
= 0; i
< last_word
- first_word
+ 1; i
++) {
2747 status
= igb_read_phy_reg_i2c(hw
, first_word
+ i
, &dataword
[i
]);
2748 if (status
!= E1000_SUCCESS
)
2749 /* Error occurred while reading module */
2752 be16_to_cpus(&dataword
[i
]);
2755 memcpy(data
, (u8
*)dataword
+ (ee
->offset
& 1), ee
->len
);
2761 static int igb_ethtool_begin(struct net_device
*netdev
)
2763 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2764 pm_runtime_get_sync(&adapter
->pdev
->dev
);
2768 static void igb_ethtool_complete(struct net_device
*netdev
)
2770 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2771 pm_runtime_put(&adapter
->pdev
->dev
);
2774 static const struct ethtool_ops igb_ethtool_ops
= {
2775 .get_settings
= igb_get_settings
,
2776 .set_settings
= igb_set_settings
,
2777 .get_drvinfo
= igb_get_drvinfo
,
2778 .get_regs_len
= igb_get_regs_len
,
2779 .get_regs
= igb_get_regs
,
2780 .get_wol
= igb_get_wol
,
2781 .set_wol
= igb_set_wol
,
2782 .get_msglevel
= igb_get_msglevel
,
2783 .set_msglevel
= igb_set_msglevel
,
2784 .nway_reset
= igb_nway_reset
,
2785 .get_link
= igb_get_link
,
2786 .get_eeprom_len
= igb_get_eeprom_len
,
2787 .get_eeprom
= igb_get_eeprom
,
2788 .set_eeprom
= igb_set_eeprom
,
2789 .get_ringparam
= igb_get_ringparam
,
2790 .set_ringparam
= igb_set_ringparam
,
2791 .get_pauseparam
= igb_get_pauseparam
,
2792 .set_pauseparam
= igb_set_pauseparam
,
2793 .self_test
= igb_diag_test
,
2794 .get_strings
= igb_get_strings
,
2795 .set_phys_id
= igb_set_phys_id
,
2796 .get_sset_count
= igb_get_sset_count
,
2797 .get_ethtool_stats
= igb_get_ethtool_stats
,
2798 .get_coalesce
= igb_get_coalesce
,
2799 .set_coalesce
= igb_set_coalesce
,
2800 .get_ts_info
= igb_get_ts_info
,
2801 .get_rxnfc
= igb_get_rxnfc
,
2802 .set_rxnfc
= igb_set_rxnfc
,
2803 .get_eee
= igb_get_eee
,
2804 .set_eee
= igb_set_eee
,
2805 .get_module_info
= igb_get_module_info
,
2806 .get_module_eeprom
= igb_get_module_eeprom
,
2807 .begin
= igb_ethtool_begin
,
2808 .complete
= igb_ethtool_complete
,
2811 void igb_set_ethtool_ops(struct net_device
*netdev
)
2813 SET_ETHTOOL_OPS(netdev
, &igb_ethtool_ops
);