1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2009 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>
43 char stat_string
[ETH_GSTRING_LEN
];
48 #define IGB_STAT(_name, _stat) { \
49 .stat_string = _name, \
50 .sizeof_stat = FIELD_SIZEOF(struct igb_adapter, _stat), \
51 .stat_offset = offsetof(struct igb_adapter, _stat) \
53 static const struct igb_stats igb_gstrings_stats
[] = {
54 IGB_STAT("rx_packets", stats
.gprc
),
55 IGB_STAT("tx_packets", stats
.gptc
),
56 IGB_STAT("rx_bytes", stats
.gorc
),
57 IGB_STAT("tx_bytes", stats
.gotc
),
58 IGB_STAT("rx_broadcast", stats
.bprc
),
59 IGB_STAT("tx_broadcast", stats
.bptc
),
60 IGB_STAT("rx_multicast", stats
.mprc
),
61 IGB_STAT("tx_multicast", stats
.mptc
),
62 IGB_STAT("multicast", stats
.mprc
),
63 IGB_STAT("collisions", stats
.colc
),
64 IGB_STAT("rx_crc_errors", stats
.crcerrs
),
65 IGB_STAT("rx_no_buffer_count", stats
.rnbc
),
66 IGB_STAT("rx_missed_errors", stats
.mpc
),
67 IGB_STAT("tx_aborted_errors", stats
.ecol
),
68 IGB_STAT("tx_carrier_errors", stats
.tncrs
),
69 IGB_STAT("tx_window_errors", stats
.latecol
),
70 IGB_STAT("tx_abort_late_coll", stats
.latecol
),
71 IGB_STAT("tx_deferred_ok", stats
.dc
),
72 IGB_STAT("tx_single_coll_ok", stats
.scc
),
73 IGB_STAT("tx_multi_coll_ok", stats
.mcc
),
74 IGB_STAT("tx_timeout_count", tx_timeout_count
),
75 IGB_STAT("rx_long_length_errors", stats
.roc
),
76 IGB_STAT("rx_short_length_errors", stats
.ruc
),
77 IGB_STAT("rx_align_errors", stats
.algnerrc
),
78 IGB_STAT("tx_tcp_seg_good", stats
.tsctc
),
79 IGB_STAT("tx_tcp_seg_failed", stats
.tsctfc
),
80 IGB_STAT("rx_flow_control_xon", stats
.xonrxc
),
81 IGB_STAT("rx_flow_control_xoff", stats
.xoffrxc
),
82 IGB_STAT("tx_flow_control_xon", stats
.xontxc
),
83 IGB_STAT("tx_flow_control_xoff", stats
.xofftxc
),
84 IGB_STAT("rx_long_byte_count", stats
.gorc
),
85 IGB_STAT("tx_dma_out_of_sync", stats
.doosync
),
86 IGB_STAT("tx_smbus", stats
.mgptc
),
87 IGB_STAT("rx_smbus", stats
.mgprc
),
88 IGB_STAT("dropped_smbus", stats
.mgpdc
),
89 IGB_STAT("os2bmc_rx_by_bmc", stats
.o2bgptc
),
90 IGB_STAT("os2bmc_tx_by_bmc", stats
.b2ospc
),
91 IGB_STAT("os2bmc_tx_by_host", stats
.o2bspc
),
92 IGB_STAT("os2bmc_rx_by_host", stats
.b2ogprc
),
95 #define IGB_NETDEV_STAT(_net_stat) { \
96 .stat_string = __stringify(_net_stat), \
97 .sizeof_stat = FIELD_SIZEOF(struct rtnl_link_stats64, _net_stat), \
98 .stat_offset = offsetof(struct rtnl_link_stats64, _net_stat) \
100 static const struct igb_stats igb_gstrings_net_stats
[] = {
101 IGB_NETDEV_STAT(rx_errors
),
102 IGB_NETDEV_STAT(tx_errors
),
103 IGB_NETDEV_STAT(tx_dropped
),
104 IGB_NETDEV_STAT(rx_length_errors
),
105 IGB_NETDEV_STAT(rx_over_errors
),
106 IGB_NETDEV_STAT(rx_frame_errors
),
107 IGB_NETDEV_STAT(rx_fifo_errors
),
108 IGB_NETDEV_STAT(tx_fifo_errors
),
109 IGB_NETDEV_STAT(tx_heartbeat_errors
)
112 #define IGB_GLOBAL_STATS_LEN \
113 (sizeof(igb_gstrings_stats) / sizeof(struct igb_stats))
114 #define IGB_NETDEV_STATS_LEN \
115 (sizeof(igb_gstrings_net_stats) / sizeof(struct igb_stats))
116 #define IGB_RX_QUEUE_STATS_LEN \
117 (sizeof(struct igb_rx_queue_stats) / sizeof(u64))
119 #define IGB_TX_QUEUE_STATS_LEN 3 /* packets, bytes, restart_queue */
121 #define IGB_QUEUE_STATS_LEN \
122 ((((struct igb_adapter *)netdev_priv(netdev))->num_rx_queues * \
123 IGB_RX_QUEUE_STATS_LEN) + \
124 (((struct igb_adapter *)netdev_priv(netdev))->num_tx_queues * \
125 IGB_TX_QUEUE_STATS_LEN))
126 #define IGB_STATS_LEN \
127 (IGB_GLOBAL_STATS_LEN + IGB_NETDEV_STATS_LEN + IGB_QUEUE_STATS_LEN)
129 static const char igb_gstrings_test
[][ETH_GSTRING_LEN
] = {
130 "Register test (offline)", "Eeprom test (offline)",
131 "Interrupt test (offline)", "Loopback test (offline)",
132 "Link test (on/offline)"
134 #define IGB_TEST_LEN (sizeof(igb_gstrings_test) / ETH_GSTRING_LEN)
136 static int igb_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
138 struct igb_adapter
*adapter
= netdev_priv(netdev
);
139 struct e1000_hw
*hw
= &adapter
->hw
;
142 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
144 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
145 SUPPORTED_10baseT_Full
|
146 SUPPORTED_100baseT_Half
|
147 SUPPORTED_100baseT_Full
|
148 SUPPORTED_1000baseT_Full
|
151 ecmd
->advertising
= ADVERTISED_TP
;
153 if (hw
->mac
.autoneg
== 1) {
154 ecmd
->advertising
|= ADVERTISED_Autoneg
;
155 /* the e1000 autoneg seems to match ethtool nicely */
156 ecmd
->advertising
|= hw
->phy
.autoneg_advertised
;
159 ecmd
->port
= PORT_TP
;
160 ecmd
->phy_address
= hw
->phy
.addr
;
162 ecmd
->supported
= (SUPPORTED_1000baseT_Full
|
166 ecmd
->advertising
= (ADVERTISED_1000baseT_Full
|
170 ecmd
->port
= PORT_FIBRE
;
173 ecmd
->transceiver
= XCVR_INTERNAL
;
175 status
= rd32(E1000_STATUS
);
177 if (status
& E1000_STATUS_LU
) {
179 if ((status
& E1000_STATUS_SPEED_1000
) ||
180 hw
->phy
.media_type
!= e1000_media_type_copper
)
181 ethtool_cmd_speed_set(ecmd
, SPEED_1000
);
182 else if (status
& E1000_STATUS_SPEED_100
)
183 ethtool_cmd_speed_set(ecmd
, SPEED_100
);
185 ethtool_cmd_speed_set(ecmd
, SPEED_10
);
187 if ((status
& E1000_STATUS_FD
) ||
188 hw
->phy
.media_type
!= e1000_media_type_copper
)
189 ecmd
->duplex
= DUPLEX_FULL
;
191 ecmd
->duplex
= DUPLEX_HALF
;
193 ethtool_cmd_speed_set(ecmd
, -1);
197 ecmd
->autoneg
= hw
->mac
.autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
201 static int igb_set_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
203 struct igb_adapter
*adapter
= netdev_priv(netdev
);
204 struct e1000_hw
*hw
= &adapter
->hw
;
206 /* When SoL/IDER sessions are active, autoneg/speed/duplex
207 * cannot be changed */
208 if (igb_check_reset_block(hw
)) {
209 dev_err(&adapter
->pdev
->dev
, "Cannot change link "
210 "characteristics when SoL/IDER is active.\n");
214 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
217 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
219 hw
->phy
.autoneg_advertised
= ecmd
->advertising
|
222 ecmd
->advertising
= hw
->phy
.autoneg_advertised
;
223 if (adapter
->fc_autoneg
)
224 hw
->fc
.requested_mode
= e1000_fc_default
;
226 u32 speed
= ethtool_cmd_speed(ecmd
);
227 if (igb_set_spd_dplx(adapter
, speed
, ecmd
->duplex
)) {
228 clear_bit(__IGB_RESETTING
, &adapter
->state
);
234 if (netif_running(adapter
->netdev
)) {
240 clear_bit(__IGB_RESETTING
, &adapter
->state
);
244 static u32
igb_get_link(struct net_device
*netdev
)
246 struct igb_adapter
*adapter
= netdev_priv(netdev
);
247 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
250 * If the link is not reported up to netdev, interrupts are disabled,
251 * and so the physical link state may have changed since we last
252 * looked. Set get_link_status to make sure that the true link
253 * state is interrogated, rather than pulling a cached and possibly
254 * stale link state from the driver.
256 if (!netif_carrier_ok(netdev
))
257 mac
->get_link_status
= 1;
259 return igb_has_link(adapter
);
262 static void igb_get_pauseparam(struct net_device
*netdev
,
263 struct ethtool_pauseparam
*pause
)
265 struct igb_adapter
*adapter
= netdev_priv(netdev
);
266 struct e1000_hw
*hw
= &adapter
->hw
;
269 (adapter
->fc_autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
);
271 if (hw
->fc
.current_mode
== e1000_fc_rx_pause
)
273 else if (hw
->fc
.current_mode
== e1000_fc_tx_pause
)
275 else if (hw
->fc
.current_mode
== e1000_fc_full
) {
281 static int igb_set_pauseparam(struct net_device
*netdev
,
282 struct ethtool_pauseparam
*pause
)
284 struct igb_adapter
*adapter
= netdev_priv(netdev
);
285 struct e1000_hw
*hw
= &adapter
->hw
;
288 adapter
->fc_autoneg
= pause
->autoneg
;
290 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
293 if (adapter
->fc_autoneg
== AUTONEG_ENABLE
) {
294 hw
->fc
.requested_mode
= e1000_fc_default
;
295 if (netif_running(adapter
->netdev
)) {
302 if (pause
->rx_pause
&& pause
->tx_pause
)
303 hw
->fc
.requested_mode
= e1000_fc_full
;
304 else if (pause
->rx_pause
&& !pause
->tx_pause
)
305 hw
->fc
.requested_mode
= e1000_fc_rx_pause
;
306 else if (!pause
->rx_pause
&& pause
->tx_pause
)
307 hw
->fc
.requested_mode
= e1000_fc_tx_pause
;
308 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
309 hw
->fc
.requested_mode
= e1000_fc_none
;
311 hw
->fc
.current_mode
= hw
->fc
.requested_mode
;
313 retval
= ((hw
->phy
.media_type
== e1000_media_type_copper
) ?
314 igb_force_mac_fc(hw
) : igb_setup_link(hw
));
317 clear_bit(__IGB_RESETTING
, &adapter
->state
);
321 static u32
igb_get_rx_csum(struct net_device
*netdev
)
323 struct igb_adapter
*adapter
= netdev_priv(netdev
);
324 return !!(adapter
->rx_ring
[0]->flags
& IGB_RING_FLAG_RX_CSUM
);
327 static int igb_set_rx_csum(struct net_device
*netdev
, u32 data
)
329 struct igb_adapter
*adapter
= netdev_priv(netdev
);
332 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
334 adapter
->rx_ring
[i
]->flags
|= IGB_RING_FLAG_RX_CSUM
;
336 adapter
->rx_ring
[i
]->flags
&= ~IGB_RING_FLAG_RX_CSUM
;
342 static u32
igb_get_tx_csum(struct net_device
*netdev
)
344 return (netdev
->features
& NETIF_F_IP_CSUM
) != 0;
347 static int igb_set_tx_csum(struct net_device
*netdev
, u32 data
)
349 struct igb_adapter
*adapter
= netdev_priv(netdev
);
352 netdev
->features
|= (NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
);
353 if (adapter
->hw
.mac
.type
>= e1000_82576
)
354 netdev
->features
|= NETIF_F_SCTP_CSUM
;
356 netdev
->features
&= ~(NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
363 static int igb_set_tso(struct net_device
*netdev
, u32 data
)
365 struct igb_adapter
*adapter
= netdev_priv(netdev
);
368 netdev
->features
|= NETIF_F_TSO
;
369 netdev
->features
|= NETIF_F_TSO6
;
371 netdev
->features
&= ~NETIF_F_TSO
;
372 netdev
->features
&= ~NETIF_F_TSO6
;
375 dev_info(&adapter
->pdev
->dev
, "TSO is %s\n",
376 data
? "Enabled" : "Disabled");
380 static u32
igb_get_msglevel(struct net_device
*netdev
)
382 struct igb_adapter
*adapter
= netdev_priv(netdev
);
383 return adapter
->msg_enable
;
386 static void igb_set_msglevel(struct net_device
*netdev
, u32 data
)
388 struct igb_adapter
*adapter
= netdev_priv(netdev
);
389 adapter
->msg_enable
= data
;
392 static int igb_get_regs_len(struct net_device
*netdev
)
394 #define IGB_REGS_LEN 551
395 return IGB_REGS_LEN
* sizeof(u32
);
398 static void igb_get_regs(struct net_device
*netdev
,
399 struct ethtool_regs
*regs
, void *p
)
401 struct igb_adapter
*adapter
= netdev_priv(netdev
);
402 struct e1000_hw
*hw
= &adapter
->hw
;
406 memset(p
, 0, IGB_REGS_LEN
* sizeof(u32
));
408 regs
->version
= (1 << 24) | (hw
->revision_id
<< 16) | hw
->device_id
;
410 /* General Registers */
411 regs_buff
[0] = rd32(E1000_CTRL
);
412 regs_buff
[1] = rd32(E1000_STATUS
);
413 regs_buff
[2] = rd32(E1000_CTRL_EXT
);
414 regs_buff
[3] = rd32(E1000_MDIC
);
415 regs_buff
[4] = rd32(E1000_SCTL
);
416 regs_buff
[5] = rd32(E1000_CONNSW
);
417 regs_buff
[6] = rd32(E1000_VET
);
418 regs_buff
[7] = rd32(E1000_LEDCTL
);
419 regs_buff
[8] = rd32(E1000_PBA
);
420 regs_buff
[9] = rd32(E1000_PBS
);
421 regs_buff
[10] = rd32(E1000_FRTIMER
);
422 regs_buff
[11] = rd32(E1000_TCPTIMER
);
425 regs_buff
[12] = rd32(E1000_EECD
);
428 /* Reading EICS for EICR because they read the
429 * same but EICS does not clear on read */
430 regs_buff
[13] = rd32(E1000_EICS
);
431 regs_buff
[14] = rd32(E1000_EICS
);
432 regs_buff
[15] = rd32(E1000_EIMS
);
433 regs_buff
[16] = rd32(E1000_EIMC
);
434 regs_buff
[17] = rd32(E1000_EIAC
);
435 regs_buff
[18] = rd32(E1000_EIAM
);
436 /* Reading ICS for ICR because they read the
437 * same but ICS does not clear on read */
438 regs_buff
[19] = rd32(E1000_ICS
);
439 regs_buff
[20] = rd32(E1000_ICS
);
440 regs_buff
[21] = rd32(E1000_IMS
);
441 regs_buff
[22] = rd32(E1000_IMC
);
442 regs_buff
[23] = rd32(E1000_IAC
);
443 regs_buff
[24] = rd32(E1000_IAM
);
444 regs_buff
[25] = rd32(E1000_IMIRVP
);
447 regs_buff
[26] = rd32(E1000_FCAL
);
448 regs_buff
[27] = rd32(E1000_FCAH
);
449 regs_buff
[28] = rd32(E1000_FCTTV
);
450 regs_buff
[29] = rd32(E1000_FCRTL
);
451 regs_buff
[30] = rd32(E1000_FCRTH
);
452 regs_buff
[31] = rd32(E1000_FCRTV
);
455 regs_buff
[32] = rd32(E1000_RCTL
);
456 regs_buff
[33] = rd32(E1000_RXCSUM
);
457 regs_buff
[34] = rd32(E1000_RLPML
);
458 regs_buff
[35] = rd32(E1000_RFCTL
);
459 regs_buff
[36] = rd32(E1000_MRQC
);
460 regs_buff
[37] = rd32(E1000_VT_CTL
);
463 regs_buff
[38] = rd32(E1000_TCTL
);
464 regs_buff
[39] = rd32(E1000_TCTL_EXT
);
465 regs_buff
[40] = rd32(E1000_TIPG
);
466 regs_buff
[41] = rd32(E1000_DTXCTL
);
469 regs_buff
[42] = rd32(E1000_WUC
);
470 regs_buff
[43] = rd32(E1000_WUFC
);
471 regs_buff
[44] = rd32(E1000_WUS
);
472 regs_buff
[45] = rd32(E1000_IPAV
);
473 regs_buff
[46] = rd32(E1000_WUPL
);
476 regs_buff
[47] = rd32(E1000_PCS_CFG0
);
477 regs_buff
[48] = rd32(E1000_PCS_LCTL
);
478 regs_buff
[49] = rd32(E1000_PCS_LSTAT
);
479 regs_buff
[50] = rd32(E1000_PCS_ANADV
);
480 regs_buff
[51] = rd32(E1000_PCS_LPAB
);
481 regs_buff
[52] = rd32(E1000_PCS_NPTX
);
482 regs_buff
[53] = rd32(E1000_PCS_LPABNP
);
485 regs_buff
[54] = adapter
->stats
.crcerrs
;
486 regs_buff
[55] = adapter
->stats
.algnerrc
;
487 regs_buff
[56] = adapter
->stats
.symerrs
;
488 regs_buff
[57] = adapter
->stats
.rxerrc
;
489 regs_buff
[58] = adapter
->stats
.mpc
;
490 regs_buff
[59] = adapter
->stats
.scc
;
491 regs_buff
[60] = adapter
->stats
.ecol
;
492 regs_buff
[61] = adapter
->stats
.mcc
;
493 regs_buff
[62] = adapter
->stats
.latecol
;
494 regs_buff
[63] = adapter
->stats
.colc
;
495 regs_buff
[64] = adapter
->stats
.dc
;
496 regs_buff
[65] = adapter
->stats
.tncrs
;
497 regs_buff
[66] = adapter
->stats
.sec
;
498 regs_buff
[67] = adapter
->stats
.htdpmc
;
499 regs_buff
[68] = adapter
->stats
.rlec
;
500 regs_buff
[69] = adapter
->stats
.xonrxc
;
501 regs_buff
[70] = adapter
->stats
.xontxc
;
502 regs_buff
[71] = adapter
->stats
.xoffrxc
;
503 regs_buff
[72] = adapter
->stats
.xofftxc
;
504 regs_buff
[73] = adapter
->stats
.fcruc
;
505 regs_buff
[74] = adapter
->stats
.prc64
;
506 regs_buff
[75] = adapter
->stats
.prc127
;
507 regs_buff
[76] = adapter
->stats
.prc255
;
508 regs_buff
[77] = adapter
->stats
.prc511
;
509 regs_buff
[78] = adapter
->stats
.prc1023
;
510 regs_buff
[79] = adapter
->stats
.prc1522
;
511 regs_buff
[80] = adapter
->stats
.gprc
;
512 regs_buff
[81] = adapter
->stats
.bprc
;
513 regs_buff
[82] = adapter
->stats
.mprc
;
514 regs_buff
[83] = adapter
->stats
.gptc
;
515 regs_buff
[84] = adapter
->stats
.gorc
;
516 regs_buff
[86] = adapter
->stats
.gotc
;
517 regs_buff
[88] = adapter
->stats
.rnbc
;
518 regs_buff
[89] = adapter
->stats
.ruc
;
519 regs_buff
[90] = adapter
->stats
.rfc
;
520 regs_buff
[91] = adapter
->stats
.roc
;
521 regs_buff
[92] = adapter
->stats
.rjc
;
522 regs_buff
[93] = adapter
->stats
.mgprc
;
523 regs_buff
[94] = adapter
->stats
.mgpdc
;
524 regs_buff
[95] = adapter
->stats
.mgptc
;
525 regs_buff
[96] = adapter
->stats
.tor
;
526 regs_buff
[98] = adapter
->stats
.tot
;
527 regs_buff
[100] = adapter
->stats
.tpr
;
528 regs_buff
[101] = adapter
->stats
.tpt
;
529 regs_buff
[102] = adapter
->stats
.ptc64
;
530 regs_buff
[103] = adapter
->stats
.ptc127
;
531 regs_buff
[104] = adapter
->stats
.ptc255
;
532 regs_buff
[105] = adapter
->stats
.ptc511
;
533 regs_buff
[106] = adapter
->stats
.ptc1023
;
534 regs_buff
[107] = adapter
->stats
.ptc1522
;
535 regs_buff
[108] = adapter
->stats
.mptc
;
536 regs_buff
[109] = adapter
->stats
.bptc
;
537 regs_buff
[110] = adapter
->stats
.tsctc
;
538 regs_buff
[111] = adapter
->stats
.iac
;
539 regs_buff
[112] = adapter
->stats
.rpthc
;
540 regs_buff
[113] = adapter
->stats
.hgptc
;
541 regs_buff
[114] = adapter
->stats
.hgorc
;
542 regs_buff
[116] = adapter
->stats
.hgotc
;
543 regs_buff
[118] = adapter
->stats
.lenerrs
;
544 regs_buff
[119] = adapter
->stats
.scvpc
;
545 regs_buff
[120] = adapter
->stats
.hrmpc
;
547 for (i
= 0; i
< 4; i
++)
548 regs_buff
[121 + i
] = rd32(E1000_SRRCTL(i
));
549 for (i
= 0; i
< 4; i
++)
550 regs_buff
[125 + i
] = rd32(E1000_PSRTYPE(i
));
551 for (i
= 0; i
< 4; i
++)
552 regs_buff
[129 + i
] = rd32(E1000_RDBAL(i
));
553 for (i
= 0; i
< 4; i
++)
554 regs_buff
[133 + i
] = rd32(E1000_RDBAH(i
));
555 for (i
= 0; i
< 4; i
++)
556 regs_buff
[137 + i
] = rd32(E1000_RDLEN(i
));
557 for (i
= 0; i
< 4; i
++)
558 regs_buff
[141 + i
] = rd32(E1000_RDH(i
));
559 for (i
= 0; i
< 4; i
++)
560 regs_buff
[145 + i
] = rd32(E1000_RDT(i
));
561 for (i
= 0; i
< 4; i
++)
562 regs_buff
[149 + i
] = rd32(E1000_RXDCTL(i
));
564 for (i
= 0; i
< 10; i
++)
565 regs_buff
[153 + i
] = rd32(E1000_EITR(i
));
566 for (i
= 0; i
< 8; i
++)
567 regs_buff
[163 + i
] = rd32(E1000_IMIR(i
));
568 for (i
= 0; i
< 8; i
++)
569 regs_buff
[171 + i
] = rd32(E1000_IMIREXT(i
));
570 for (i
= 0; i
< 16; i
++)
571 regs_buff
[179 + i
] = rd32(E1000_RAL(i
));
572 for (i
= 0; i
< 16; i
++)
573 regs_buff
[195 + i
] = rd32(E1000_RAH(i
));
575 for (i
= 0; i
< 4; i
++)
576 regs_buff
[211 + i
] = rd32(E1000_TDBAL(i
));
577 for (i
= 0; i
< 4; i
++)
578 regs_buff
[215 + i
] = rd32(E1000_TDBAH(i
));
579 for (i
= 0; i
< 4; i
++)
580 regs_buff
[219 + i
] = rd32(E1000_TDLEN(i
));
581 for (i
= 0; i
< 4; i
++)
582 regs_buff
[223 + i
] = rd32(E1000_TDH(i
));
583 for (i
= 0; i
< 4; i
++)
584 regs_buff
[227 + i
] = rd32(E1000_TDT(i
));
585 for (i
= 0; i
< 4; i
++)
586 regs_buff
[231 + i
] = rd32(E1000_TXDCTL(i
));
587 for (i
= 0; i
< 4; i
++)
588 regs_buff
[235 + i
] = rd32(E1000_TDWBAL(i
));
589 for (i
= 0; i
< 4; i
++)
590 regs_buff
[239 + i
] = rd32(E1000_TDWBAH(i
));
591 for (i
= 0; i
< 4; i
++)
592 regs_buff
[243 + i
] = rd32(E1000_DCA_TXCTRL(i
));
594 for (i
= 0; i
< 4; i
++)
595 regs_buff
[247 + i
] = rd32(E1000_IP4AT_REG(i
));
596 for (i
= 0; i
< 4; i
++)
597 regs_buff
[251 + i
] = rd32(E1000_IP6AT_REG(i
));
598 for (i
= 0; i
< 32; i
++)
599 regs_buff
[255 + i
] = rd32(E1000_WUPM_REG(i
));
600 for (i
= 0; i
< 128; i
++)
601 regs_buff
[287 + i
] = rd32(E1000_FFMT_REG(i
));
602 for (i
= 0; i
< 128; i
++)
603 regs_buff
[415 + i
] = rd32(E1000_FFVT_REG(i
));
604 for (i
= 0; i
< 4; i
++)
605 regs_buff
[543 + i
] = rd32(E1000_FFLT_REG(i
));
607 regs_buff
[547] = rd32(E1000_TDFH
);
608 regs_buff
[548] = rd32(E1000_TDFT
);
609 regs_buff
[549] = rd32(E1000_TDFHS
);
610 regs_buff
[550] = rd32(E1000_TDFPC
);
611 regs_buff
[551] = adapter
->stats
.o2bgptc
;
612 regs_buff
[552] = adapter
->stats
.b2ospc
;
613 regs_buff
[553] = adapter
->stats
.o2bspc
;
614 regs_buff
[554] = adapter
->stats
.b2ogprc
;
617 static int igb_get_eeprom_len(struct net_device
*netdev
)
619 struct igb_adapter
*adapter
= netdev_priv(netdev
);
620 return adapter
->hw
.nvm
.word_size
* 2;
623 static int igb_get_eeprom(struct net_device
*netdev
,
624 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
626 struct igb_adapter
*adapter
= netdev_priv(netdev
);
627 struct e1000_hw
*hw
= &adapter
->hw
;
629 int first_word
, last_word
;
633 if (eeprom
->len
== 0)
636 eeprom
->magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
638 first_word
= eeprom
->offset
>> 1;
639 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
641 eeprom_buff
= kmalloc(sizeof(u16
) *
642 (last_word
- first_word
+ 1), GFP_KERNEL
);
646 if (hw
->nvm
.type
== e1000_nvm_eeprom_spi
)
647 ret_val
= hw
->nvm
.ops
.read(hw
, first_word
,
648 last_word
- first_word
+ 1,
651 for (i
= 0; i
< last_word
- first_word
+ 1; i
++) {
652 ret_val
= hw
->nvm
.ops
.read(hw
, first_word
+ i
, 1,
659 /* Device's eeprom is always little-endian, word addressable */
660 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
661 le16_to_cpus(&eeprom_buff
[i
]);
663 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 1),
670 static int igb_set_eeprom(struct net_device
*netdev
,
671 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
673 struct igb_adapter
*adapter
= netdev_priv(netdev
);
674 struct e1000_hw
*hw
= &adapter
->hw
;
677 int max_len
, first_word
, last_word
, ret_val
= 0;
680 if (eeprom
->len
== 0)
683 if (eeprom
->magic
!= (hw
->vendor_id
| (hw
->device_id
<< 16)))
686 max_len
= hw
->nvm
.word_size
* 2;
688 first_word
= eeprom
->offset
>> 1;
689 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
690 eeprom_buff
= kmalloc(max_len
, GFP_KERNEL
);
694 ptr
= (void *)eeprom_buff
;
696 if (eeprom
->offset
& 1) {
697 /* need read/modify/write of first changed EEPROM word */
698 /* only the second byte of the word is being modified */
699 ret_val
= hw
->nvm
.ops
.read(hw
, first_word
, 1,
703 if (((eeprom
->offset
+ eeprom
->len
) & 1) && (ret_val
== 0)) {
704 /* need read/modify/write of last changed EEPROM word */
705 /* only the first byte of the word is being modified */
706 ret_val
= hw
->nvm
.ops
.read(hw
, last_word
, 1,
707 &eeprom_buff
[last_word
- first_word
]);
710 /* Device's eeprom is always little-endian, word addressable */
711 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
712 le16_to_cpus(&eeprom_buff
[i
]);
714 memcpy(ptr
, bytes
, eeprom
->len
);
716 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
717 eeprom_buff
[i
] = cpu_to_le16(eeprom_buff
[i
]);
719 ret_val
= hw
->nvm
.ops
.write(hw
, first_word
,
720 last_word
- first_word
+ 1, eeprom_buff
);
722 /* Update the checksum over the first part of the EEPROM if needed
723 * and flush shadow RAM for 82573 controllers */
724 if ((ret_val
== 0) && ((first_word
<= NVM_CHECKSUM_REG
)))
725 hw
->nvm
.ops
.update(hw
);
731 static void igb_get_drvinfo(struct net_device
*netdev
,
732 struct ethtool_drvinfo
*drvinfo
)
734 struct igb_adapter
*adapter
= netdev_priv(netdev
);
735 char firmware_version
[32];
738 strncpy(drvinfo
->driver
, igb_driver_name
, sizeof(drvinfo
->driver
) - 1);
739 strncpy(drvinfo
->version
, igb_driver_version
,
740 sizeof(drvinfo
->version
) - 1);
742 /* EEPROM image version # is reported as firmware version # for
743 * 82575 controllers */
744 adapter
->hw
.nvm
.ops
.read(&adapter
->hw
, 5, 1, &eeprom_data
);
745 sprintf(firmware_version
, "%d.%d-%d",
746 (eeprom_data
& 0xF000) >> 12,
747 (eeprom_data
& 0x0FF0) >> 4,
748 eeprom_data
& 0x000F);
750 strncpy(drvinfo
->fw_version
, firmware_version
,
751 sizeof(drvinfo
->fw_version
) - 1);
752 strncpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
753 sizeof(drvinfo
->bus_info
) - 1);
754 drvinfo
->n_stats
= IGB_STATS_LEN
;
755 drvinfo
->testinfo_len
= IGB_TEST_LEN
;
756 drvinfo
->regdump_len
= igb_get_regs_len(netdev
);
757 drvinfo
->eedump_len
= igb_get_eeprom_len(netdev
);
760 static void igb_get_ringparam(struct net_device
*netdev
,
761 struct ethtool_ringparam
*ring
)
763 struct igb_adapter
*adapter
= netdev_priv(netdev
);
765 ring
->rx_max_pending
= IGB_MAX_RXD
;
766 ring
->tx_max_pending
= IGB_MAX_TXD
;
767 ring
->rx_mini_max_pending
= 0;
768 ring
->rx_jumbo_max_pending
= 0;
769 ring
->rx_pending
= adapter
->rx_ring_count
;
770 ring
->tx_pending
= adapter
->tx_ring_count
;
771 ring
->rx_mini_pending
= 0;
772 ring
->rx_jumbo_pending
= 0;
775 static int igb_set_ringparam(struct net_device
*netdev
,
776 struct ethtool_ringparam
*ring
)
778 struct igb_adapter
*adapter
= netdev_priv(netdev
);
779 struct igb_ring
*temp_ring
;
781 u16 new_rx_count
, new_tx_count
;
783 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
786 new_rx_count
= min_t(u32
, ring
->rx_pending
, IGB_MAX_RXD
);
787 new_rx_count
= max_t(u16
, new_rx_count
, IGB_MIN_RXD
);
788 new_rx_count
= ALIGN(new_rx_count
, REQ_RX_DESCRIPTOR_MULTIPLE
);
790 new_tx_count
= min_t(u32
, ring
->tx_pending
, IGB_MAX_TXD
);
791 new_tx_count
= max_t(u16
, new_tx_count
, IGB_MIN_TXD
);
792 new_tx_count
= ALIGN(new_tx_count
, REQ_TX_DESCRIPTOR_MULTIPLE
);
794 if ((new_tx_count
== adapter
->tx_ring_count
) &&
795 (new_rx_count
== adapter
->rx_ring_count
)) {
800 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
803 if (!netif_running(adapter
->netdev
)) {
804 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
805 adapter
->tx_ring
[i
]->count
= new_tx_count
;
806 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
807 adapter
->rx_ring
[i
]->count
= new_rx_count
;
808 adapter
->tx_ring_count
= new_tx_count
;
809 adapter
->rx_ring_count
= new_rx_count
;
813 if (adapter
->num_tx_queues
> adapter
->num_rx_queues
)
814 temp_ring
= vmalloc(adapter
->num_tx_queues
* sizeof(struct igb_ring
));
816 temp_ring
= vmalloc(adapter
->num_rx_queues
* sizeof(struct igb_ring
));
826 * We can't just free everything and then setup again,
827 * because the ISRs in MSI-X mode get passed pointers
828 * to the tx and rx ring structs.
830 if (new_tx_count
!= adapter
->tx_ring_count
) {
831 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
832 memcpy(&temp_ring
[i
], adapter
->tx_ring
[i
],
833 sizeof(struct igb_ring
));
835 temp_ring
[i
].count
= new_tx_count
;
836 err
= igb_setup_tx_resources(&temp_ring
[i
]);
840 igb_free_tx_resources(&temp_ring
[i
]);
846 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
847 igb_free_tx_resources(adapter
->tx_ring
[i
]);
849 memcpy(adapter
->tx_ring
[i
], &temp_ring
[i
],
850 sizeof(struct igb_ring
));
853 adapter
->tx_ring_count
= new_tx_count
;
856 if (new_rx_count
!= adapter
->rx_ring_count
) {
857 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
858 memcpy(&temp_ring
[i
], adapter
->rx_ring
[i
],
859 sizeof(struct igb_ring
));
861 temp_ring
[i
].count
= new_rx_count
;
862 err
= igb_setup_rx_resources(&temp_ring
[i
]);
866 igb_free_rx_resources(&temp_ring
[i
]);
873 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
874 igb_free_rx_resources(adapter
->rx_ring
[i
]);
876 memcpy(adapter
->rx_ring
[i
], &temp_ring
[i
],
877 sizeof(struct igb_ring
));
880 adapter
->rx_ring_count
= new_rx_count
;
886 clear_bit(__IGB_RESETTING
, &adapter
->state
);
890 /* ethtool register test data */
891 struct igb_reg_test
{
900 /* In the hardware, registers are laid out either singly, in arrays
901 * spaced 0x100 bytes apart, or in contiguous tables. We assume
902 * most tests take place on arrays or single registers (handled
903 * as a single-element array) and special-case the tables.
904 * Table tests are always pattern tests.
906 * We also make provision for some required setup steps by specifying
907 * registers to be written without any read-back testing.
910 #define PATTERN_TEST 1
911 #define SET_READ_TEST 2
912 #define WRITE_NO_TEST 3
913 #define TABLE32_TEST 4
914 #define TABLE64_TEST_LO 5
915 #define TABLE64_TEST_HI 6
918 static struct igb_reg_test reg_test_i350
[] = {
919 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
920 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
921 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
922 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFF0000, 0xFFFF0000 },
923 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
924 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
925 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
926 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
927 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
928 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
929 /* RDH is read-only for i350, only test RDT. */
930 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
931 { E1000_RDT(4), 0x40, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
932 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
933 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
934 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
935 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
936 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
937 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
938 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
939 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
940 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
941 { E1000_TDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
942 { E1000_TDT(4), 0x40, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
943 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
944 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0x003FFFFB },
945 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0xFFFFFFFF },
946 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
947 { E1000_RA
, 0, 16, TABLE64_TEST_LO
,
948 0xFFFFFFFF, 0xFFFFFFFF },
949 { E1000_RA
, 0, 16, TABLE64_TEST_HI
,
950 0xC3FFFFFF, 0xFFFFFFFF },
951 { E1000_RA2
, 0, 16, TABLE64_TEST_LO
,
952 0xFFFFFFFF, 0xFFFFFFFF },
953 { E1000_RA2
, 0, 16, TABLE64_TEST_HI
,
954 0xC3FFFFFF, 0xFFFFFFFF },
955 { E1000_MTA
, 0, 128, TABLE32_TEST
,
956 0xFFFFFFFF, 0xFFFFFFFF },
961 static struct igb_reg_test reg_test_82580
[] = {
962 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
963 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
964 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
965 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
966 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
967 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
968 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
969 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
970 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
971 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
972 /* RDH is read-only for 82580, only test RDT. */
973 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
974 { E1000_RDT(4), 0x40, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
975 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
976 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
977 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
978 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
979 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
980 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
981 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
982 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
983 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
984 { E1000_TDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
985 { E1000_TDT(4), 0x40, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
986 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
987 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0x003FFFFB },
988 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0xFFFFFFFF },
989 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
990 { E1000_RA
, 0, 16, TABLE64_TEST_LO
,
991 0xFFFFFFFF, 0xFFFFFFFF },
992 { E1000_RA
, 0, 16, TABLE64_TEST_HI
,
993 0x83FFFFFF, 0xFFFFFFFF },
994 { E1000_RA2
, 0, 8, TABLE64_TEST_LO
,
995 0xFFFFFFFF, 0xFFFFFFFF },
996 { E1000_RA2
, 0, 8, TABLE64_TEST_HI
,
997 0x83FFFFFF, 0xFFFFFFFF },
998 { E1000_MTA
, 0, 128, TABLE32_TEST
,
999 0xFFFFFFFF, 0xFFFFFFFF },
1003 /* 82576 reg test */
1004 static struct igb_reg_test reg_test_82576
[] = {
1005 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1006 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1007 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1008 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1009 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1010 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1011 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
1012 { E1000_RDBAL(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1013 { E1000_RDBAH(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1014 { E1000_RDLEN(4), 0x40, 12, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
1015 /* Enable all RX queues before testing. */
1016 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, E1000_RXDCTL_QUEUE_ENABLE
},
1017 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST
, 0, E1000_RXDCTL_QUEUE_ENABLE
},
1018 /* RDH is read-only for 82576, only test RDT. */
1019 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1020 { E1000_RDT(4), 0x40, 12, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1021 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, 0 },
1022 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST
, 0, 0 },
1023 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
1024 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1025 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
1026 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1027 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1028 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
1029 { E1000_TDBAL(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1030 { E1000_TDBAH(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1031 { E1000_TDLEN(4), 0x40, 12, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
1032 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1033 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0x003FFFFB },
1034 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0xFFFFFFFF },
1035 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1036 { E1000_RA
, 0, 16, TABLE64_TEST_LO
, 0xFFFFFFFF, 0xFFFFFFFF },
1037 { E1000_RA
, 0, 16, TABLE64_TEST_HI
, 0x83FFFFFF, 0xFFFFFFFF },
1038 { E1000_RA2
, 0, 8, TABLE64_TEST_LO
, 0xFFFFFFFF, 0xFFFFFFFF },
1039 { E1000_RA2
, 0, 8, TABLE64_TEST_HI
, 0x83FFFFFF, 0xFFFFFFFF },
1040 { E1000_MTA
, 0, 128,TABLE32_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1044 /* 82575 register test */
1045 static struct igb_reg_test reg_test_82575
[] = {
1046 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1047 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1048 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
1049 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1050 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1051 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1052 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
1053 /* Enable all four RX queues before testing. */
1054 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, E1000_RXDCTL_QUEUE_ENABLE
},
1055 /* RDH is read-only for 82575, only test RDT. */
1056 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1057 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, 0 },
1058 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
1059 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1060 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
1061 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1062 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1063 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
1064 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1065 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB3FE, 0x003FFFFB },
1066 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB3FE, 0xFFFFFFFF },
1067 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1068 { E1000_TXCW
, 0x100, 1, PATTERN_TEST
, 0xC000FFFF, 0x0000FFFF },
1069 { E1000_RA
, 0, 16, TABLE64_TEST_LO
, 0xFFFFFFFF, 0xFFFFFFFF },
1070 { E1000_RA
, 0, 16, TABLE64_TEST_HI
, 0x800FFFFF, 0xFFFFFFFF },
1071 { E1000_MTA
, 0, 128, TABLE32_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1075 static bool reg_pattern_test(struct igb_adapter
*adapter
, u64
*data
,
1076 int reg
, u32 mask
, u32 write
)
1078 struct e1000_hw
*hw
= &adapter
->hw
;
1080 static const u32 _test
[] =
1081 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
1082 for (pat
= 0; pat
< ARRAY_SIZE(_test
); pat
++) {
1083 wr32(reg
, (_test
[pat
] & write
));
1084 val
= rd32(reg
) & mask
;
1085 if (val
!= (_test
[pat
] & write
& mask
)) {
1086 dev_err(&adapter
->pdev
->dev
, "pattern test reg %04X "
1087 "failed: got 0x%08X expected 0x%08X\n",
1088 reg
, val
, (_test
[pat
] & write
& mask
));
1097 static bool reg_set_and_check(struct igb_adapter
*adapter
, u64
*data
,
1098 int reg
, u32 mask
, u32 write
)
1100 struct e1000_hw
*hw
= &adapter
->hw
;
1102 wr32(reg
, write
& mask
);
1104 if ((write
& mask
) != (val
& mask
)) {
1105 dev_err(&adapter
->pdev
->dev
, "set/check reg %04X test failed:"
1106 " got 0x%08X expected 0x%08X\n", reg
,
1107 (val
& mask
), (write
& mask
));
1115 #define REG_PATTERN_TEST(reg, mask, write) \
1117 if (reg_pattern_test(adapter, data, reg, mask, write)) \
1121 #define REG_SET_AND_CHECK(reg, mask, write) \
1123 if (reg_set_and_check(adapter, data, reg, mask, write)) \
1127 static int igb_reg_test(struct igb_adapter
*adapter
, u64
*data
)
1129 struct e1000_hw
*hw
= &adapter
->hw
;
1130 struct igb_reg_test
*test
;
1131 u32 value
, before
, after
;
1134 switch (adapter
->hw
.mac
.type
) {
1136 test
= reg_test_i350
;
1137 toggle
= 0x7FEFF3FF;
1140 test
= reg_test_82580
;
1141 toggle
= 0x7FEFF3FF;
1144 test
= reg_test_82576
;
1145 toggle
= 0x7FFFF3FF;
1148 test
= reg_test_82575
;
1149 toggle
= 0x7FFFF3FF;
1153 /* Because the status register is such a special case,
1154 * we handle it separately from the rest of the register
1155 * tests. Some bits are read-only, some toggle, and some
1156 * are writable on newer MACs.
1158 before
= rd32(E1000_STATUS
);
1159 value
= (rd32(E1000_STATUS
) & toggle
);
1160 wr32(E1000_STATUS
, toggle
);
1161 after
= rd32(E1000_STATUS
) & toggle
;
1162 if (value
!= after
) {
1163 dev_err(&adapter
->pdev
->dev
, "failed STATUS register test "
1164 "got: 0x%08X expected: 0x%08X\n", after
, value
);
1168 /* restore previous status */
1169 wr32(E1000_STATUS
, before
);
1171 /* Perform the remainder of the register test, looping through
1172 * the test table until we either fail or reach the null entry.
1175 for (i
= 0; i
< test
->array_len
; i
++) {
1176 switch (test
->test_type
) {
1178 REG_PATTERN_TEST(test
->reg
+
1179 (i
* test
->reg_offset
),
1184 REG_SET_AND_CHECK(test
->reg
+
1185 (i
* test
->reg_offset
),
1191 (adapter
->hw
.hw_addr
+ test
->reg
)
1192 + (i
* test
->reg_offset
));
1195 REG_PATTERN_TEST(test
->reg
+ (i
* 4),
1199 case TABLE64_TEST_LO
:
1200 REG_PATTERN_TEST(test
->reg
+ (i
* 8),
1204 case TABLE64_TEST_HI
:
1205 REG_PATTERN_TEST((test
->reg
+ 4) + (i
* 8),
1218 static int igb_eeprom_test(struct igb_adapter
*adapter
, u64
*data
)
1225 /* Read and add up the contents of the EEPROM */
1226 for (i
= 0; i
< (NVM_CHECKSUM_REG
+ 1); i
++) {
1227 if ((adapter
->hw
.nvm
.ops
.read(&adapter
->hw
, i
, 1, &temp
)) < 0) {
1234 /* If Checksum is not Correct return error else test passed */
1235 if ((checksum
!= (u16
) NVM_SUM
) && !(*data
))
1241 static irqreturn_t
igb_test_intr(int irq
, void *data
)
1243 struct igb_adapter
*adapter
= (struct igb_adapter
*) data
;
1244 struct e1000_hw
*hw
= &adapter
->hw
;
1246 adapter
->test_icr
|= rd32(E1000_ICR
);
1251 static int igb_intr_test(struct igb_adapter
*adapter
, u64
*data
)
1253 struct e1000_hw
*hw
= &adapter
->hw
;
1254 struct net_device
*netdev
= adapter
->netdev
;
1255 u32 mask
, ics_mask
, i
= 0, shared_int
= true;
1256 u32 irq
= adapter
->pdev
->irq
;
1260 /* Hook up test interrupt handler just for this test */
1261 if (adapter
->msix_entries
) {
1262 if (request_irq(adapter
->msix_entries
[0].vector
,
1263 igb_test_intr
, 0, netdev
->name
, adapter
)) {
1267 } else if (adapter
->flags
& IGB_FLAG_HAS_MSI
) {
1269 if (request_irq(irq
,
1270 igb_test_intr
, 0, netdev
->name
, adapter
)) {
1274 } else if (!request_irq(irq
, igb_test_intr
, IRQF_PROBE_SHARED
,
1275 netdev
->name
, adapter
)) {
1277 } else if (request_irq(irq
, igb_test_intr
, IRQF_SHARED
,
1278 netdev
->name
, adapter
)) {
1282 dev_info(&adapter
->pdev
->dev
, "testing %s interrupt\n",
1283 (shared_int
? "shared" : "unshared"));
1285 /* Disable all the interrupts */
1286 wr32(E1000_IMC
, ~0);
1289 /* Define all writable bits for ICS */
1290 switch (hw
->mac
.type
) {
1292 ics_mask
= 0x37F47EDD;
1295 ics_mask
= 0x77D4FBFD;
1298 ics_mask
= 0x77DCFED5;
1301 ics_mask
= 0x77DCFED5;
1304 ics_mask
= 0x7FFFFFFF;
1308 /* Test each interrupt */
1309 for (; i
< 31; i
++) {
1310 /* Interrupt to test */
1313 if (!(mask
& ics_mask
))
1317 /* Disable the interrupt to be reported in
1318 * the cause register and then force the same
1319 * interrupt and see if one gets posted. If
1320 * an interrupt was posted to the bus, the
1323 adapter
->test_icr
= 0;
1325 /* Flush any pending interrupts */
1326 wr32(E1000_ICR
, ~0);
1328 wr32(E1000_IMC
, mask
);
1329 wr32(E1000_ICS
, mask
);
1332 if (adapter
->test_icr
& mask
) {
1338 /* Enable the interrupt to be reported in
1339 * the cause register and then force the same
1340 * interrupt and see if one gets posted. If
1341 * an interrupt was not posted to the bus, the
1344 adapter
->test_icr
= 0;
1346 /* Flush any pending interrupts */
1347 wr32(E1000_ICR
, ~0);
1349 wr32(E1000_IMS
, mask
);
1350 wr32(E1000_ICS
, mask
);
1353 if (!(adapter
->test_icr
& mask
)) {
1359 /* Disable the other interrupts to be reported in
1360 * the cause register and then force the other
1361 * interrupts and see if any get posted. If
1362 * an interrupt was posted to the bus, the
1365 adapter
->test_icr
= 0;
1367 /* Flush any pending interrupts */
1368 wr32(E1000_ICR
, ~0);
1370 wr32(E1000_IMC
, ~mask
);
1371 wr32(E1000_ICS
, ~mask
);
1374 if (adapter
->test_icr
& mask
) {
1381 /* Disable all the interrupts */
1382 wr32(E1000_IMC
, ~0);
1385 /* Unhook test interrupt handler */
1386 if (adapter
->msix_entries
)
1387 free_irq(adapter
->msix_entries
[0].vector
, adapter
);
1389 free_irq(irq
, adapter
);
1394 static void igb_free_desc_rings(struct igb_adapter
*adapter
)
1396 igb_free_tx_resources(&adapter
->test_tx_ring
);
1397 igb_free_rx_resources(&adapter
->test_rx_ring
);
1400 static int igb_setup_desc_rings(struct igb_adapter
*adapter
)
1402 struct igb_ring
*tx_ring
= &adapter
->test_tx_ring
;
1403 struct igb_ring
*rx_ring
= &adapter
->test_rx_ring
;
1404 struct e1000_hw
*hw
= &adapter
->hw
;
1407 /* Setup Tx descriptor ring and Tx buffers */
1408 tx_ring
->count
= IGB_DEFAULT_TXD
;
1409 tx_ring
->dev
= &adapter
->pdev
->dev
;
1410 tx_ring
->netdev
= adapter
->netdev
;
1411 tx_ring
->reg_idx
= adapter
->vfs_allocated_count
;
1413 if (igb_setup_tx_resources(tx_ring
)) {
1418 igb_setup_tctl(adapter
);
1419 igb_configure_tx_ring(adapter
, tx_ring
);
1421 /* Setup Rx descriptor ring and Rx buffers */
1422 rx_ring
->count
= IGB_DEFAULT_RXD
;
1423 rx_ring
->dev
= &adapter
->pdev
->dev
;
1424 rx_ring
->netdev
= adapter
->netdev
;
1425 rx_ring
->rx_buffer_len
= IGB_RXBUFFER_2048
;
1426 rx_ring
->reg_idx
= adapter
->vfs_allocated_count
;
1428 if (igb_setup_rx_resources(rx_ring
)) {
1433 /* set the default queue to queue 0 of PF */
1434 wr32(E1000_MRQC
, adapter
->vfs_allocated_count
<< 3);
1436 /* enable receive ring */
1437 igb_setup_rctl(adapter
);
1438 igb_configure_rx_ring(adapter
, rx_ring
);
1440 igb_alloc_rx_buffers_adv(rx_ring
, igb_desc_unused(rx_ring
));
1445 igb_free_desc_rings(adapter
);
1449 static void igb_phy_disable_receiver(struct igb_adapter
*adapter
)
1451 struct e1000_hw
*hw
= &adapter
->hw
;
1453 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1454 igb_write_phy_reg(hw
, 29, 0x001F);
1455 igb_write_phy_reg(hw
, 30, 0x8FFC);
1456 igb_write_phy_reg(hw
, 29, 0x001A);
1457 igb_write_phy_reg(hw
, 30, 0x8FF0);
1460 static int igb_integrated_phy_loopback(struct igb_adapter
*adapter
)
1462 struct e1000_hw
*hw
= &adapter
->hw
;
1465 hw
->mac
.autoneg
= false;
1467 if (hw
->phy
.type
== e1000_phy_m88
) {
1468 /* Auto-MDI/MDIX Off */
1469 igb_write_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, 0x0808);
1470 /* reset to update Auto-MDI/MDIX */
1471 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x9140);
1473 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x8140);
1474 } else if (hw
->phy
.type
== e1000_phy_82580
) {
1475 /* enable MII loopback */
1476 igb_write_phy_reg(hw
, I82580_PHY_LBK_CTRL
, 0x8041);
1479 ctrl_reg
= rd32(E1000_CTRL
);
1481 /* force 1000, set loopback */
1482 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x4140);
1484 /* Now set up the MAC to the same speed/duplex as the PHY. */
1485 ctrl_reg
= rd32(E1000_CTRL
);
1486 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1487 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1488 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1489 E1000_CTRL_SPD_1000
|/* Force Speed to 1000 */
1490 E1000_CTRL_FD
| /* Force Duplex to FULL */
1491 E1000_CTRL_SLU
); /* Set link up enable bit */
1493 if (hw
->phy
.type
== e1000_phy_m88
)
1494 ctrl_reg
|= E1000_CTRL_ILOS
; /* Invert Loss of Signal */
1496 wr32(E1000_CTRL
, ctrl_reg
);
1498 /* Disable the receiver on the PHY so when a cable is plugged in, the
1499 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1501 if (hw
->phy
.type
== e1000_phy_m88
)
1502 igb_phy_disable_receiver(adapter
);
1509 static int igb_set_phy_loopback(struct igb_adapter
*adapter
)
1511 return igb_integrated_phy_loopback(adapter
);
1514 static int igb_setup_loopback_test(struct igb_adapter
*adapter
)
1516 struct e1000_hw
*hw
= &adapter
->hw
;
1519 reg
= rd32(E1000_CTRL_EXT
);
1521 /* use CTRL_EXT to identify link type as SGMII can appear as copper */
1522 if (reg
& E1000_CTRL_EXT_LINK_MODE_MASK
) {
1523 reg
= rd32(E1000_RCTL
);
1524 reg
|= E1000_RCTL_LBM_TCVR
;
1525 wr32(E1000_RCTL
, reg
);
1527 wr32(E1000_SCTL
, E1000_ENABLE_SERDES_LOOPBACK
);
1529 reg
= rd32(E1000_CTRL
);
1530 reg
&= ~(E1000_CTRL_RFCE
|
1533 reg
|= E1000_CTRL_SLU
|
1535 wr32(E1000_CTRL
, reg
);
1537 /* Unset switch control to serdes energy detect */
1538 reg
= rd32(E1000_CONNSW
);
1539 reg
&= ~E1000_CONNSW_ENRGSRC
;
1540 wr32(E1000_CONNSW
, reg
);
1542 /* Set PCS register for forced speed */
1543 reg
= rd32(E1000_PCS_LCTL
);
1544 reg
&= ~E1000_PCS_LCTL_AN_ENABLE
; /* Disable Autoneg*/
1545 reg
|= E1000_PCS_LCTL_FLV_LINK_UP
| /* Force link up */
1546 E1000_PCS_LCTL_FSV_1000
| /* Force 1000 */
1547 E1000_PCS_LCTL_FDV_FULL
| /* SerDes Full duplex */
1548 E1000_PCS_LCTL_FSD
| /* Force Speed */
1549 E1000_PCS_LCTL_FORCE_LINK
; /* Force Link */
1550 wr32(E1000_PCS_LCTL
, reg
);
1555 return igb_set_phy_loopback(adapter
);
1558 static void igb_loopback_cleanup(struct igb_adapter
*adapter
)
1560 struct e1000_hw
*hw
= &adapter
->hw
;
1564 rctl
= rd32(E1000_RCTL
);
1565 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
1566 wr32(E1000_RCTL
, rctl
);
1568 hw
->mac
.autoneg
= true;
1569 igb_read_phy_reg(hw
, PHY_CONTROL
, &phy_reg
);
1570 if (phy_reg
& MII_CR_LOOPBACK
) {
1571 phy_reg
&= ~MII_CR_LOOPBACK
;
1572 igb_write_phy_reg(hw
, PHY_CONTROL
, phy_reg
);
1573 igb_phy_sw_reset(hw
);
1577 static void igb_create_lbtest_frame(struct sk_buff
*skb
,
1578 unsigned int frame_size
)
1580 memset(skb
->data
, 0xFF, frame_size
);
1582 memset(&skb
->data
[frame_size
], 0xAA, frame_size
- 1);
1583 memset(&skb
->data
[frame_size
+ 10], 0xBE, 1);
1584 memset(&skb
->data
[frame_size
+ 12], 0xAF, 1);
1587 static int igb_check_lbtest_frame(struct sk_buff
*skb
, unsigned int frame_size
)
1590 if (*(skb
->data
+ 3) == 0xFF) {
1591 if ((*(skb
->data
+ frame_size
+ 10) == 0xBE) &&
1592 (*(skb
->data
+ frame_size
+ 12) == 0xAF)) {
1599 static int igb_clean_test_rings(struct igb_ring
*rx_ring
,
1600 struct igb_ring
*tx_ring
,
1603 union e1000_adv_rx_desc
*rx_desc
;
1604 struct igb_buffer
*buffer_info
;
1605 int rx_ntc
, tx_ntc
, count
= 0;
1608 /* initialize next to clean and descriptor values */
1609 rx_ntc
= rx_ring
->next_to_clean
;
1610 tx_ntc
= tx_ring
->next_to_clean
;
1611 rx_desc
= E1000_RX_DESC_ADV(*rx_ring
, rx_ntc
);
1612 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1614 while (staterr
& E1000_RXD_STAT_DD
) {
1615 /* check rx buffer */
1616 buffer_info
= &rx_ring
->buffer_info
[rx_ntc
];
1618 /* unmap rx buffer, will be remapped by alloc_rx_buffers */
1619 dma_unmap_single(rx_ring
->dev
,
1621 rx_ring
->rx_buffer_len
,
1623 buffer_info
->dma
= 0;
1625 /* verify contents of skb */
1626 if (!igb_check_lbtest_frame(buffer_info
->skb
, size
))
1629 /* unmap buffer on tx side */
1630 buffer_info
= &tx_ring
->buffer_info
[tx_ntc
];
1631 igb_unmap_and_free_tx_resource(tx_ring
, buffer_info
);
1633 /* increment rx/tx next to clean counters */
1635 if (rx_ntc
== rx_ring
->count
)
1638 if (tx_ntc
== tx_ring
->count
)
1641 /* fetch next descriptor */
1642 rx_desc
= E1000_RX_DESC_ADV(*rx_ring
, rx_ntc
);
1643 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1646 /* re-map buffers to ring, store next to clean values */
1647 igb_alloc_rx_buffers_adv(rx_ring
, count
);
1648 rx_ring
->next_to_clean
= rx_ntc
;
1649 tx_ring
->next_to_clean
= tx_ntc
;
1654 static int igb_run_loopback_test(struct igb_adapter
*adapter
)
1656 struct igb_ring
*tx_ring
= &adapter
->test_tx_ring
;
1657 struct igb_ring
*rx_ring
= &adapter
->test_rx_ring
;
1658 int i
, j
, lc
, good_cnt
, ret_val
= 0;
1659 unsigned int size
= 1024;
1660 netdev_tx_t tx_ret_val
;
1661 struct sk_buff
*skb
;
1663 /* allocate test skb */
1664 skb
= alloc_skb(size
, GFP_KERNEL
);
1668 /* place data into test skb */
1669 igb_create_lbtest_frame(skb
, size
);
1673 * Calculate the loop count based on the largest descriptor ring
1674 * The idea is to wrap the largest ring a number of times using 64
1675 * send/receive pairs during each loop
1678 if (rx_ring
->count
<= tx_ring
->count
)
1679 lc
= ((tx_ring
->count
/ 64) * 2) + 1;
1681 lc
= ((rx_ring
->count
/ 64) * 2) + 1;
1683 for (j
= 0; j
<= lc
; j
++) { /* loop count loop */
1684 /* reset count of good packets */
1687 /* place 64 packets on the transmit queue*/
1688 for (i
= 0; i
< 64; i
++) {
1690 tx_ret_val
= igb_xmit_frame_ring_adv(skb
, tx_ring
);
1691 if (tx_ret_val
== NETDEV_TX_OK
)
1695 if (good_cnt
!= 64) {
1700 /* allow 200 milliseconds for packets to go from tx to rx */
1703 good_cnt
= igb_clean_test_rings(rx_ring
, tx_ring
, size
);
1704 if (good_cnt
!= 64) {
1708 } /* end loop count loop */
1710 /* free the original skb */
1716 static int igb_loopback_test(struct igb_adapter
*adapter
, u64
*data
)
1718 /* PHY loopback cannot be performed if SoL/IDER
1719 * sessions are active */
1720 if (igb_check_reset_block(&adapter
->hw
)) {
1721 dev_err(&adapter
->pdev
->dev
,
1722 "Cannot do PHY loopback test "
1723 "when SoL/IDER is active.\n");
1727 *data
= igb_setup_desc_rings(adapter
);
1730 *data
= igb_setup_loopback_test(adapter
);
1733 *data
= igb_run_loopback_test(adapter
);
1734 igb_loopback_cleanup(adapter
);
1737 igb_free_desc_rings(adapter
);
1742 static int igb_link_test(struct igb_adapter
*adapter
, u64
*data
)
1744 struct e1000_hw
*hw
= &adapter
->hw
;
1746 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1748 hw
->mac
.serdes_has_link
= false;
1750 /* On some blade server designs, link establishment
1751 * could take as long as 2-3 minutes */
1753 hw
->mac
.ops
.check_for_link(&adapter
->hw
);
1754 if (hw
->mac
.serdes_has_link
)
1757 } while (i
++ < 3750);
1761 hw
->mac
.ops
.check_for_link(&adapter
->hw
);
1762 if (hw
->mac
.autoneg
)
1765 if (!(rd32(E1000_STATUS
) & E1000_STATUS_LU
))
1771 static void igb_diag_test(struct net_device
*netdev
,
1772 struct ethtool_test
*eth_test
, u64
*data
)
1774 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1775 u16 autoneg_advertised
;
1776 u8 forced_speed_duplex
, autoneg
;
1777 bool if_running
= netif_running(netdev
);
1779 set_bit(__IGB_TESTING
, &adapter
->state
);
1780 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1783 /* save speed, duplex, autoneg settings */
1784 autoneg_advertised
= adapter
->hw
.phy
.autoneg_advertised
;
1785 forced_speed_duplex
= adapter
->hw
.mac
.forced_speed_duplex
;
1786 autoneg
= adapter
->hw
.mac
.autoneg
;
1788 dev_info(&adapter
->pdev
->dev
, "offline testing starting\n");
1790 /* power up link for link test */
1791 igb_power_up_link(adapter
);
1793 /* Link test performed before hardware reset so autoneg doesn't
1794 * interfere with test result */
1795 if (igb_link_test(adapter
, &data
[4]))
1796 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1799 /* indicate we're in test mode */
1804 if (igb_reg_test(adapter
, &data
[0]))
1805 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1808 if (igb_eeprom_test(adapter
, &data
[1]))
1809 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1812 if (igb_intr_test(adapter
, &data
[2]))
1813 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1816 /* power up link for loopback test */
1817 igb_power_up_link(adapter
);
1818 if (igb_loopback_test(adapter
, &data
[3]))
1819 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1821 /* restore speed, duplex, autoneg settings */
1822 adapter
->hw
.phy
.autoneg_advertised
= autoneg_advertised
;
1823 adapter
->hw
.mac
.forced_speed_duplex
= forced_speed_duplex
;
1824 adapter
->hw
.mac
.autoneg
= autoneg
;
1826 /* force this routine to wait until autoneg complete/timeout */
1827 adapter
->hw
.phy
.autoneg_wait_to_complete
= true;
1829 adapter
->hw
.phy
.autoneg_wait_to_complete
= false;
1831 clear_bit(__IGB_TESTING
, &adapter
->state
);
1835 dev_info(&adapter
->pdev
->dev
, "online testing starting\n");
1837 /* PHY is powered down when interface is down */
1838 if (if_running
&& igb_link_test(adapter
, &data
[4]))
1839 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1843 /* Online tests aren't run; pass by default */
1849 clear_bit(__IGB_TESTING
, &adapter
->state
);
1851 msleep_interruptible(4 * 1000);
1854 static int igb_wol_exclusion(struct igb_adapter
*adapter
,
1855 struct ethtool_wolinfo
*wol
)
1857 struct e1000_hw
*hw
= &adapter
->hw
;
1858 int retval
= 1; /* fail by default */
1860 switch (hw
->device_id
) {
1861 case E1000_DEV_ID_82575GB_QUAD_COPPER
:
1862 /* WoL not supported */
1865 case E1000_DEV_ID_82575EB_FIBER_SERDES
:
1866 case E1000_DEV_ID_82576_FIBER
:
1867 case E1000_DEV_ID_82576_SERDES
:
1868 /* Wake events not supported on port B */
1869 if (rd32(E1000_STATUS
) & E1000_STATUS_FUNC_1
) {
1873 /* return success for non excluded adapter ports */
1876 case E1000_DEV_ID_82576_QUAD_COPPER
:
1877 case E1000_DEV_ID_82576_QUAD_COPPER_ET2
:
1878 /* quad port adapters only support WoL on port A */
1879 if (!(adapter
->flags
& IGB_FLAG_QUAD_PORT_A
)) {
1883 /* return success for non excluded adapter ports */
1887 /* dual port cards only support WoL on port A from now on
1888 * unless it was enabled in the eeprom for port B
1889 * so exclude FUNC_1 ports from having WoL enabled */
1890 if ((rd32(E1000_STATUS
) & E1000_STATUS_FUNC_MASK
) &&
1891 !adapter
->eeprom_wol
) {
1902 static void igb_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1904 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1906 wol
->supported
= WAKE_UCAST
| WAKE_MCAST
|
1907 WAKE_BCAST
| WAKE_MAGIC
|
1911 /* this function will set ->supported = 0 and return 1 if wol is not
1912 * supported by this hardware */
1913 if (igb_wol_exclusion(adapter
, wol
) ||
1914 !device_can_wakeup(&adapter
->pdev
->dev
))
1917 /* apply any specific unsupported masks here */
1918 switch (adapter
->hw
.device_id
) {
1923 if (adapter
->wol
& E1000_WUFC_EX
)
1924 wol
->wolopts
|= WAKE_UCAST
;
1925 if (adapter
->wol
& E1000_WUFC_MC
)
1926 wol
->wolopts
|= WAKE_MCAST
;
1927 if (adapter
->wol
& E1000_WUFC_BC
)
1928 wol
->wolopts
|= WAKE_BCAST
;
1929 if (adapter
->wol
& E1000_WUFC_MAG
)
1930 wol
->wolopts
|= WAKE_MAGIC
;
1931 if (adapter
->wol
& E1000_WUFC_LNKC
)
1932 wol
->wolopts
|= WAKE_PHY
;
1935 static int igb_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1937 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1939 if (wol
->wolopts
& (WAKE_ARP
| WAKE_MAGICSECURE
))
1942 if (igb_wol_exclusion(adapter
, wol
) ||
1943 !device_can_wakeup(&adapter
->pdev
->dev
))
1944 return wol
->wolopts
? -EOPNOTSUPP
: 0;
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
;
1959 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
1964 /* bit defines for adapter->led_status */
1965 #define IGB_LED_ON 0
1967 static int igb_set_phys_id(struct net_device
*netdev
,
1968 enum ethtool_phys_id_state state
)
1970 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1971 struct e1000_hw
*hw
= &adapter
->hw
;
1974 case ETHTOOL_ID_ACTIVE
:
1980 case ETHTOOL_ID_OFF
:
1983 case ETHTOOL_ID_INACTIVE
:
1985 clear_bit(IGB_LED_ON
, &adapter
->led_status
);
1986 igb_cleanup_led(hw
);
1993 static int igb_set_coalesce(struct net_device
*netdev
,
1994 struct ethtool_coalesce
*ec
)
1996 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1999 if ((ec
->rx_coalesce_usecs
> IGB_MAX_ITR_USECS
) ||
2000 ((ec
->rx_coalesce_usecs
> 3) &&
2001 (ec
->rx_coalesce_usecs
< IGB_MIN_ITR_USECS
)) ||
2002 (ec
->rx_coalesce_usecs
== 2))
2005 if ((ec
->tx_coalesce_usecs
> IGB_MAX_ITR_USECS
) ||
2006 ((ec
->tx_coalesce_usecs
> 3) &&
2007 (ec
->tx_coalesce_usecs
< IGB_MIN_ITR_USECS
)) ||
2008 (ec
->tx_coalesce_usecs
== 2))
2011 if ((adapter
->flags
& IGB_FLAG_QUEUE_PAIRS
) && ec
->tx_coalesce_usecs
)
2014 /* If ITR is disabled, disable DMAC */
2015 if (ec
->rx_coalesce_usecs
== 0) {
2016 if (adapter
->flags
& IGB_FLAG_DMAC
)
2017 adapter
->flags
&= ~IGB_FLAG_DMAC
;
2020 /* convert to rate of irq's per second */
2021 if (ec
->rx_coalesce_usecs
&& ec
->rx_coalesce_usecs
<= 3)
2022 adapter
->rx_itr_setting
= ec
->rx_coalesce_usecs
;
2024 adapter
->rx_itr_setting
= ec
->rx_coalesce_usecs
<< 2;
2026 /* convert to rate of irq's per second */
2027 if (adapter
->flags
& IGB_FLAG_QUEUE_PAIRS
)
2028 adapter
->tx_itr_setting
= adapter
->rx_itr_setting
;
2029 else if (ec
->tx_coalesce_usecs
&& ec
->tx_coalesce_usecs
<= 3)
2030 adapter
->tx_itr_setting
= ec
->tx_coalesce_usecs
;
2032 adapter
->tx_itr_setting
= ec
->tx_coalesce_usecs
<< 2;
2034 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
2035 struct igb_q_vector
*q_vector
= adapter
->q_vector
[i
];
2036 if (q_vector
->rx_ring
)
2037 q_vector
->itr_val
= adapter
->rx_itr_setting
;
2039 q_vector
->itr_val
= adapter
->tx_itr_setting
;
2040 if (q_vector
->itr_val
&& q_vector
->itr_val
<= 3)
2041 q_vector
->itr_val
= IGB_START_ITR
;
2042 q_vector
->set_itr
= 1;
2048 static int igb_get_coalesce(struct net_device
*netdev
,
2049 struct ethtool_coalesce
*ec
)
2051 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2053 if (adapter
->rx_itr_setting
<= 3)
2054 ec
->rx_coalesce_usecs
= adapter
->rx_itr_setting
;
2056 ec
->rx_coalesce_usecs
= adapter
->rx_itr_setting
>> 2;
2058 if (!(adapter
->flags
& IGB_FLAG_QUEUE_PAIRS
)) {
2059 if (adapter
->tx_itr_setting
<= 3)
2060 ec
->tx_coalesce_usecs
= adapter
->tx_itr_setting
;
2062 ec
->tx_coalesce_usecs
= adapter
->tx_itr_setting
>> 2;
2068 static int igb_nway_reset(struct net_device
*netdev
)
2070 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2071 if (netif_running(netdev
))
2072 igb_reinit_locked(adapter
);
2076 static int igb_get_sset_count(struct net_device
*netdev
, int sset
)
2080 return IGB_STATS_LEN
;
2082 return IGB_TEST_LEN
;
2088 static void igb_get_ethtool_stats(struct net_device
*netdev
,
2089 struct ethtool_stats
*stats
, u64
*data
)
2091 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2092 struct rtnl_link_stats64
*net_stats
= &adapter
->stats64
;
2094 struct igb_ring
*ring
;
2098 spin_lock(&adapter
->stats64_lock
);
2099 igb_update_stats(adapter
, net_stats
);
2101 for (i
= 0; i
< IGB_GLOBAL_STATS_LEN
; i
++) {
2102 p
= (char *)adapter
+ igb_gstrings_stats
[i
].stat_offset
;
2103 data
[i
] = (igb_gstrings_stats
[i
].sizeof_stat
==
2104 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
2106 for (j
= 0; j
< IGB_NETDEV_STATS_LEN
; j
++, i
++) {
2107 p
= (char *)net_stats
+ igb_gstrings_net_stats
[j
].stat_offset
;
2108 data
[i
] = (igb_gstrings_net_stats
[j
].sizeof_stat
==
2109 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
2111 for (j
= 0; j
< adapter
->num_tx_queues
; j
++) {
2114 ring
= adapter
->tx_ring
[j
];
2116 start
= u64_stats_fetch_begin_bh(&ring
->tx_syncp
);
2117 data
[i
] = ring
->tx_stats
.packets
;
2118 data
[i
+1] = ring
->tx_stats
.bytes
;
2119 data
[i
+2] = ring
->tx_stats
.restart_queue
;
2120 } while (u64_stats_fetch_retry_bh(&ring
->tx_syncp
, start
));
2122 start
= u64_stats_fetch_begin_bh(&ring
->tx_syncp2
);
2123 restart2
= ring
->tx_stats
.restart_queue2
;
2124 } while (u64_stats_fetch_retry_bh(&ring
->tx_syncp2
, start
));
2125 data
[i
+2] += restart2
;
2127 i
+= IGB_TX_QUEUE_STATS_LEN
;
2129 for (j
= 0; j
< adapter
->num_rx_queues
; j
++) {
2130 ring
= adapter
->rx_ring
[j
];
2132 start
= u64_stats_fetch_begin_bh(&ring
->rx_syncp
);
2133 data
[i
] = ring
->rx_stats
.packets
;
2134 data
[i
+1] = ring
->rx_stats
.bytes
;
2135 data
[i
+2] = ring
->rx_stats
.drops
;
2136 data
[i
+3] = ring
->rx_stats
.csum_err
;
2137 data
[i
+4] = ring
->rx_stats
.alloc_failed
;
2138 } while (u64_stats_fetch_retry_bh(&ring
->rx_syncp
, start
));
2139 i
+= IGB_RX_QUEUE_STATS_LEN
;
2141 spin_unlock(&adapter
->stats64_lock
);
2144 static void igb_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*data
)
2146 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2150 switch (stringset
) {
2152 memcpy(data
, *igb_gstrings_test
,
2153 IGB_TEST_LEN
*ETH_GSTRING_LEN
);
2156 for (i
= 0; i
< IGB_GLOBAL_STATS_LEN
; i
++) {
2157 memcpy(p
, igb_gstrings_stats
[i
].stat_string
,
2159 p
+= ETH_GSTRING_LEN
;
2161 for (i
= 0; i
< IGB_NETDEV_STATS_LEN
; i
++) {
2162 memcpy(p
, igb_gstrings_net_stats
[i
].stat_string
,
2164 p
+= ETH_GSTRING_LEN
;
2166 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2167 sprintf(p
, "tx_queue_%u_packets", i
);
2168 p
+= ETH_GSTRING_LEN
;
2169 sprintf(p
, "tx_queue_%u_bytes", i
);
2170 p
+= ETH_GSTRING_LEN
;
2171 sprintf(p
, "tx_queue_%u_restart", i
);
2172 p
+= ETH_GSTRING_LEN
;
2174 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2175 sprintf(p
, "rx_queue_%u_packets", i
);
2176 p
+= ETH_GSTRING_LEN
;
2177 sprintf(p
, "rx_queue_%u_bytes", i
);
2178 p
+= ETH_GSTRING_LEN
;
2179 sprintf(p
, "rx_queue_%u_drops", i
);
2180 p
+= ETH_GSTRING_LEN
;
2181 sprintf(p
, "rx_queue_%u_csum_err", i
);
2182 p
+= ETH_GSTRING_LEN
;
2183 sprintf(p
, "rx_queue_%u_alloc_failed", i
);
2184 p
+= ETH_GSTRING_LEN
;
2186 /* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
2191 static const struct ethtool_ops igb_ethtool_ops
= {
2192 .get_settings
= igb_get_settings
,
2193 .set_settings
= igb_set_settings
,
2194 .get_drvinfo
= igb_get_drvinfo
,
2195 .get_regs_len
= igb_get_regs_len
,
2196 .get_regs
= igb_get_regs
,
2197 .get_wol
= igb_get_wol
,
2198 .set_wol
= igb_set_wol
,
2199 .get_msglevel
= igb_get_msglevel
,
2200 .set_msglevel
= igb_set_msglevel
,
2201 .nway_reset
= igb_nway_reset
,
2202 .get_link
= igb_get_link
,
2203 .get_eeprom_len
= igb_get_eeprom_len
,
2204 .get_eeprom
= igb_get_eeprom
,
2205 .set_eeprom
= igb_set_eeprom
,
2206 .get_ringparam
= igb_get_ringparam
,
2207 .set_ringparam
= igb_set_ringparam
,
2208 .get_pauseparam
= igb_get_pauseparam
,
2209 .set_pauseparam
= igb_set_pauseparam
,
2210 .get_rx_csum
= igb_get_rx_csum
,
2211 .set_rx_csum
= igb_set_rx_csum
,
2212 .get_tx_csum
= igb_get_tx_csum
,
2213 .set_tx_csum
= igb_set_tx_csum
,
2214 .get_sg
= ethtool_op_get_sg
,
2215 .set_sg
= ethtool_op_set_sg
,
2216 .get_tso
= ethtool_op_get_tso
,
2217 .set_tso
= igb_set_tso
,
2218 .self_test
= igb_diag_test
,
2219 .get_strings
= igb_get_strings
,
2220 .set_phys_id
= igb_set_phys_id
,
2221 .get_sset_count
= igb_get_sset_count
,
2222 .get_ethtool_stats
= igb_get_ethtool_stats
,
2223 .get_coalesce
= igb_get_coalesce
,
2224 .set_coalesce
= igb_set_coalesce
,
2227 void igb_set_ethtool_ops(struct net_device
*netdev
)
2229 SET_ETHTOOL_OPS(netdev
, &igb_ethtool_ops
);