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
),
91 #define IGB_NETDEV_STAT(_net_stat) { \
92 .stat_string = __stringify(_net_stat), \
93 .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \
94 .stat_offset = offsetof(struct net_device_stats, _net_stat) \
96 static const struct igb_stats igb_gstrings_net_stats
[] = {
97 IGB_NETDEV_STAT(rx_errors
),
98 IGB_NETDEV_STAT(tx_errors
),
99 IGB_NETDEV_STAT(tx_dropped
),
100 IGB_NETDEV_STAT(rx_length_errors
),
101 IGB_NETDEV_STAT(rx_over_errors
),
102 IGB_NETDEV_STAT(rx_frame_errors
),
103 IGB_NETDEV_STAT(rx_fifo_errors
),
104 IGB_NETDEV_STAT(tx_fifo_errors
),
105 IGB_NETDEV_STAT(tx_heartbeat_errors
)
108 #define IGB_GLOBAL_STATS_LEN \
109 (sizeof(igb_gstrings_stats) / sizeof(struct igb_stats))
110 #define IGB_NETDEV_STATS_LEN \
111 (sizeof(igb_gstrings_net_stats) / sizeof(struct igb_stats))
112 #define IGB_RX_QUEUE_STATS_LEN \
113 (sizeof(struct igb_rx_queue_stats) / sizeof(u64))
114 #define IGB_TX_QUEUE_STATS_LEN \
115 (sizeof(struct igb_tx_queue_stats) / sizeof(u64))
116 #define IGB_QUEUE_STATS_LEN \
117 ((((struct igb_adapter *)netdev_priv(netdev))->num_rx_queues * \
118 IGB_RX_QUEUE_STATS_LEN) + \
119 (((struct igb_adapter *)netdev_priv(netdev))->num_tx_queues * \
120 IGB_TX_QUEUE_STATS_LEN))
121 #define IGB_STATS_LEN \
122 (IGB_GLOBAL_STATS_LEN + IGB_NETDEV_STATS_LEN + IGB_QUEUE_STATS_LEN)
124 static const char igb_gstrings_test
[][ETH_GSTRING_LEN
] = {
125 "Register test (offline)", "Eeprom test (offline)",
126 "Interrupt test (offline)", "Loopback test (offline)",
127 "Link test (on/offline)"
129 #define IGB_TEST_LEN (sizeof(igb_gstrings_test) / ETH_GSTRING_LEN)
131 static int igb_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
133 struct igb_adapter
*adapter
= netdev_priv(netdev
);
134 struct e1000_hw
*hw
= &adapter
->hw
;
137 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
139 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
140 SUPPORTED_10baseT_Full
|
141 SUPPORTED_100baseT_Half
|
142 SUPPORTED_100baseT_Full
|
143 SUPPORTED_1000baseT_Full
|
146 ecmd
->advertising
= ADVERTISED_TP
;
148 if (hw
->mac
.autoneg
== 1) {
149 ecmd
->advertising
|= ADVERTISED_Autoneg
;
150 /* the e1000 autoneg seems to match ethtool nicely */
151 ecmd
->advertising
|= hw
->phy
.autoneg_advertised
;
154 ecmd
->port
= PORT_TP
;
155 ecmd
->phy_address
= hw
->phy
.addr
;
157 ecmd
->supported
= (SUPPORTED_1000baseT_Full
|
161 ecmd
->advertising
= (ADVERTISED_1000baseT_Full
|
165 ecmd
->port
= PORT_FIBRE
;
168 ecmd
->transceiver
= XCVR_INTERNAL
;
170 status
= rd32(E1000_STATUS
);
172 if (status
& E1000_STATUS_LU
) {
174 if ((status
& E1000_STATUS_SPEED_1000
) ||
175 hw
->phy
.media_type
!= e1000_media_type_copper
)
176 ecmd
->speed
= SPEED_1000
;
177 else if (status
& E1000_STATUS_SPEED_100
)
178 ecmd
->speed
= SPEED_100
;
180 ecmd
->speed
= SPEED_10
;
182 if ((status
& E1000_STATUS_FD
) ||
183 hw
->phy
.media_type
!= e1000_media_type_copper
)
184 ecmd
->duplex
= DUPLEX_FULL
;
186 ecmd
->duplex
= DUPLEX_HALF
;
192 ecmd
->autoneg
= hw
->mac
.autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
196 static int igb_set_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
198 struct igb_adapter
*adapter
= netdev_priv(netdev
);
199 struct e1000_hw
*hw
= &adapter
->hw
;
201 /* When SoL/IDER sessions are active, autoneg/speed/duplex
202 * cannot be changed */
203 if (igb_check_reset_block(hw
)) {
204 dev_err(&adapter
->pdev
->dev
, "Cannot change link "
205 "characteristics when SoL/IDER is active.\n");
209 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
212 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
214 hw
->phy
.autoneg_advertised
= ecmd
->advertising
|
217 ecmd
->advertising
= hw
->phy
.autoneg_advertised
;
218 if (adapter
->fc_autoneg
)
219 hw
->fc
.requested_mode
= e1000_fc_default
;
221 if (igb_set_spd_dplx(adapter
, ecmd
->speed
+ ecmd
->duplex
)) {
222 clear_bit(__IGB_RESETTING
, &adapter
->state
);
228 if (netif_running(adapter
->netdev
)) {
234 clear_bit(__IGB_RESETTING
, &adapter
->state
);
238 static u32
igb_get_link(struct net_device
*netdev
)
240 struct igb_adapter
*adapter
= netdev_priv(netdev
);
241 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
244 * If the link is not reported up to netdev, interrupts are disabled,
245 * and so the physical link state may have changed since we last
246 * looked. Set get_link_status to make sure that the true link
247 * state is interrogated, rather than pulling a cached and possibly
248 * stale link state from the driver.
250 if (!netif_carrier_ok(netdev
))
251 mac
->get_link_status
= 1;
253 return igb_has_link(adapter
);
256 static void igb_get_pauseparam(struct net_device
*netdev
,
257 struct ethtool_pauseparam
*pause
)
259 struct igb_adapter
*adapter
= netdev_priv(netdev
);
260 struct e1000_hw
*hw
= &adapter
->hw
;
263 (adapter
->fc_autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
);
265 if (hw
->fc
.current_mode
== e1000_fc_rx_pause
)
267 else if (hw
->fc
.current_mode
== e1000_fc_tx_pause
)
269 else if (hw
->fc
.current_mode
== e1000_fc_full
) {
275 static int igb_set_pauseparam(struct net_device
*netdev
,
276 struct ethtool_pauseparam
*pause
)
278 struct igb_adapter
*adapter
= netdev_priv(netdev
);
279 struct e1000_hw
*hw
= &adapter
->hw
;
282 adapter
->fc_autoneg
= pause
->autoneg
;
284 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
287 if (adapter
->fc_autoneg
== AUTONEG_ENABLE
) {
288 hw
->fc
.requested_mode
= e1000_fc_default
;
289 if (netif_running(adapter
->netdev
)) {
296 if (pause
->rx_pause
&& pause
->tx_pause
)
297 hw
->fc
.requested_mode
= e1000_fc_full
;
298 else if (pause
->rx_pause
&& !pause
->tx_pause
)
299 hw
->fc
.requested_mode
= e1000_fc_rx_pause
;
300 else if (!pause
->rx_pause
&& pause
->tx_pause
)
301 hw
->fc
.requested_mode
= e1000_fc_tx_pause
;
302 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
303 hw
->fc
.requested_mode
= e1000_fc_none
;
305 hw
->fc
.current_mode
= hw
->fc
.requested_mode
;
307 retval
= ((hw
->phy
.media_type
== e1000_media_type_copper
) ?
308 igb_force_mac_fc(hw
) : igb_setup_link(hw
));
311 clear_bit(__IGB_RESETTING
, &adapter
->state
);
315 static u32
igb_get_rx_csum(struct net_device
*netdev
)
317 struct igb_adapter
*adapter
= netdev_priv(netdev
);
318 return !!(adapter
->rx_ring
[0]->flags
& IGB_RING_FLAG_RX_CSUM
);
321 static int igb_set_rx_csum(struct net_device
*netdev
, u32 data
)
323 struct igb_adapter
*adapter
= netdev_priv(netdev
);
326 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
328 adapter
->rx_ring
[i
]->flags
|= IGB_RING_FLAG_RX_CSUM
;
330 adapter
->rx_ring
[i
]->flags
&= ~IGB_RING_FLAG_RX_CSUM
;
336 static u32
igb_get_tx_csum(struct net_device
*netdev
)
338 return (netdev
->features
& NETIF_F_IP_CSUM
) != 0;
341 static int igb_set_tx_csum(struct net_device
*netdev
, u32 data
)
343 struct igb_adapter
*adapter
= netdev_priv(netdev
);
346 netdev
->features
|= (NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
);
347 if (adapter
->hw
.mac
.type
>= e1000_82576
)
348 netdev
->features
|= NETIF_F_SCTP_CSUM
;
350 netdev
->features
&= ~(NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
357 static int igb_set_tso(struct net_device
*netdev
, u32 data
)
359 struct igb_adapter
*adapter
= netdev_priv(netdev
);
362 netdev
->features
|= NETIF_F_TSO
;
363 netdev
->features
|= NETIF_F_TSO6
;
365 netdev
->features
&= ~NETIF_F_TSO
;
366 netdev
->features
&= ~NETIF_F_TSO6
;
369 dev_info(&adapter
->pdev
->dev
, "TSO is %s\n",
370 data
? "Enabled" : "Disabled");
374 static u32
igb_get_msglevel(struct net_device
*netdev
)
376 struct igb_adapter
*adapter
= netdev_priv(netdev
);
377 return adapter
->msg_enable
;
380 static void igb_set_msglevel(struct net_device
*netdev
, u32 data
)
382 struct igb_adapter
*adapter
= netdev_priv(netdev
);
383 adapter
->msg_enable
= data
;
386 static int igb_get_regs_len(struct net_device
*netdev
)
388 #define IGB_REGS_LEN 551
389 return IGB_REGS_LEN
* sizeof(u32
);
392 static void igb_get_regs(struct net_device
*netdev
,
393 struct ethtool_regs
*regs
, void *p
)
395 struct igb_adapter
*adapter
= netdev_priv(netdev
);
396 struct e1000_hw
*hw
= &adapter
->hw
;
400 memset(p
, 0, IGB_REGS_LEN
* sizeof(u32
));
402 regs
->version
= (1 << 24) | (hw
->revision_id
<< 16) | hw
->device_id
;
404 /* General Registers */
405 regs_buff
[0] = rd32(E1000_CTRL
);
406 regs_buff
[1] = rd32(E1000_STATUS
);
407 regs_buff
[2] = rd32(E1000_CTRL_EXT
);
408 regs_buff
[3] = rd32(E1000_MDIC
);
409 regs_buff
[4] = rd32(E1000_SCTL
);
410 regs_buff
[5] = rd32(E1000_CONNSW
);
411 regs_buff
[6] = rd32(E1000_VET
);
412 regs_buff
[7] = rd32(E1000_LEDCTL
);
413 regs_buff
[8] = rd32(E1000_PBA
);
414 regs_buff
[9] = rd32(E1000_PBS
);
415 regs_buff
[10] = rd32(E1000_FRTIMER
);
416 regs_buff
[11] = rd32(E1000_TCPTIMER
);
419 regs_buff
[12] = rd32(E1000_EECD
);
422 /* Reading EICS for EICR because they read the
423 * same but EICS does not clear on read */
424 regs_buff
[13] = rd32(E1000_EICS
);
425 regs_buff
[14] = rd32(E1000_EICS
);
426 regs_buff
[15] = rd32(E1000_EIMS
);
427 regs_buff
[16] = rd32(E1000_EIMC
);
428 regs_buff
[17] = rd32(E1000_EIAC
);
429 regs_buff
[18] = rd32(E1000_EIAM
);
430 /* Reading ICS for ICR because they read the
431 * same but ICS does not clear on read */
432 regs_buff
[19] = rd32(E1000_ICS
);
433 regs_buff
[20] = rd32(E1000_ICS
);
434 regs_buff
[21] = rd32(E1000_IMS
);
435 regs_buff
[22] = rd32(E1000_IMC
);
436 regs_buff
[23] = rd32(E1000_IAC
);
437 regs_buff
[24] = rd32(E1000_IAM
);
438 regs_buff
[25] = rd32(E1000_IMIRVP
);
441 regs_buff
[26] = rd32(E1000_FCAL
);
442 regs_buff
[27] = rd32(E1000_FCAH
);
443 regs_buff
[28] = rd32(E1000_FCTTV
);
444 regs_buff
[29] = rd32(E1000_FCRTL
);
445 regs_buff
[30] = rd32(E1000_FCRTH
);
446 regs_buff
[31] = rd32(E1000_FCRTV
);
449 regs_buff
[32] = rd32(E1000_RCTL
);
450 regs_buff
[33] = rd32(E1000_RXCSUM
);
451 regs_buff
[34] = rd32(E1000_RLPML
);
452 regs_buff
[35] = rd32(E1000_RFCTL
);
453 regs_buff
[36] = rd32(E1000_MRQC
);
454 regs_buff
[37] = rd32(E1000_VT_CTL
);
457 regs_buff
[38] = rd32(E1000_TCTL
);
458 regs_buff
[39] = rd32(E1000_TCTL_EXT
);
459 regs_buff
[40] = rd32(E1000_TIPG
);
460 regs_buff
[41] = rd32(E1000_DTXCTL
);
463 regs_buff
[42] = rd32(E1000_WUC
);
464 regs_buff
[43] = rd32(E1000_WUFC
);
465 regs_buff
[44] = rd32(E1000_WUS
);
466 regs_buff
[45] = rd32(E1000_IPAV
);
467 regs_buff
[46] = rd32(E1000_WUPL
);
470 regs_buff
[47] = rd32(E1000_PCS_CFG0
);
471 regs_buff
[48] = rd32(E1000_PCS_LCTL
);
472 regs_buff
[49] = rd32(E1000_PCS_LSTAT
);
473 regs_buff
[50] = rd32(E1000_PCS_ANADV
);
474 regs_buff
[51] = rd32(E1000_PCS_LPAB
);
475 regs_buff
[52] = rd32(E1000_PCS_NPTX
);
476 regs_buff
[53] = rd32(E1000_PCS_LPABNP
);
479 regs_buff
[54] = adapter
->stats
.crcerrs
;
480 regs_buff
[55] = adapter
->stats
.algnerrc
;
481 regs_buff
[56] = adapter
->stats
.symerrs
;
482 regs_buff
[57] = adapter
->stats
.rxerrc
;
483 regs_buff
[58] = adapter
->stats
.mpc
;
484 regs_buff
[59] = adapter
->stats
.scc
;
485 regs_buff
[60] = adapter
->stats
.ecol
;
486 regs_buff
[61] = adapter
->stats
.mcc
;
487 regs_buff
[62] = adapter
->stats
.latecol
;
488 regs_buff
[63] = adapter
->stats
.colc
;
489 regs_buff
[64] = adapter
->stats
.dc
;
490 regs_buff
[65] = adapter
->stats
.tncrs
;
491 regs_buff
[66] = adapter
->stats
.sec
;
492 regs_buff
[67] = adapter
->stats
.htdpmc
;
493 regs_buff
[68] = adapter
->stats
.rlec
;
494 regs_buff
[69] = adapter
->stats
.xonrxc
;
495 regs_buff
[70] = adapter
->stats
.xontxc
;
496 regs_buff
[71] = adapter
->stats
.xoffrxc
;
497 regs_buff
[72] = adapter
->stats
.xofftxc
;
498 regs_buff
[73] = adapter
->stats
.fcruc
;
499 regs_buff
[74] = adapter
->stats
.prc64
;
500 regs_buff
[75] = adapter
->stats
.prc127
;
501 regs_buff
[76] = adapter
->stats
.prc255
;
502 regs_buff
[77] = adapter
->stats
.prc511
;
503 regs_buff
[78] = adapter
->stats
.prc1023
;
504 regs_buff
[79] = adapter
->stats
.prc1522
;
505 regs_buff
[80] = adapter
->stats
.gprc
;
506 regs_buff
[81] = adapter
->stats
.bprc
;
507 regs_buff
[82] = adapter
->stats
.mprc
;
508 regs_buff
[83] = adapter
->stats
.gptc
;
509 regs_buff
[84] = adapter
->stats
.gorc
;
510 regs_buff
[86] = adapter
->stats
.gotc
;
511 regs_buff
[88] = adapter
->stats
.rnbc
;
512 regs_buff
[89] = adapter
->stats
.ruc
;
513 regs_buff
[90] = adapter
->stats
.rfc
;
514 regs_buff
[91] = adapter
->stats
.roc
;
515 regs_buff
[92] = adapter
->stats
.rjc
;
516 regs_buff
[93] = adapter
->stats
.mgprc
;
517 regs_buff
[94] = adapter
->stats
.mgpdc
;
518 regs_buff
[95] = adapter
->stats
.mgptc
;
519 regs_buff
[96] = adapter
->stats
.tor
;
520 regs_buff
[98] = adapter
->stats
.tot
;
521 regs_buff
[100] = adapter
->stats
.tpr
;
522 regs_buff
[101] = adapter
->stats
.tpt
;
523 regs_buff
[102] = adapter
->stats
.ptc64
;
524 regs_buff
[103] = adapter
->stats
.ptc127
;
525 regs_buff
[104] = adapter
->stats
.ptc255
;
526 regs_buff
[105] = adapter
->stats
.ptc511
;
527 regs_buff
[106] = adapter
->stats
.ptc1023
;
528 regs_buff
[107] = adapter
->stats
.ptc1522
;
529 regs_buff
[108] = adapter
->stats
.mptc
;
530 regs_buff
[109] = adapter
->stats
.bptc
;
531 regs_buff
[110] = adapter
->stats
.tsctc
;
532 regs_buff
[111] = adapter
->stats
.iac
;
533 regs_buff
[112] = adapter
->stats
.rpthc
;
534 regs_buff
[113] = adapter
->stats
.hgptc
;
535 regs_buff
[114] = adapter
->stats
.hgorc
;
536 regs_buff
[116] = adapter
->stats
.hgotc
;
537 regs_buff
[118] = adapter
->stats
.lenerrs
;
538 regs_buff
[119] = adapter
->stats
.scvpc
;
539 regs_buff
[120] = adapter
->stats
.hrmpc
;
541 for (i
= 0; i
< 4; i
++)
542 regs_buff
[121 + i
] = rd32(E1000_SRRCTL(i
));
543 for (i
= 0; i
< 4; i
++)
544 regs_buff
[125 + i
] = rd32(E1000_PSRTYPE(i
));
545 for (i
= 0; i
< 4; i
++)
546 regs_buff
[129 + i
] = rd32(E1000_RDBAL(i
));
547 for (i
= 0; i
< 4; i
++)
548 regs_buff
[133 + i
] = rd32(E1000_RDBAH(i
));
549 for (i
= 0; i
< 4; i
++)
550 regs_buff
[137 + i
] = rd32(E1000_RDLEN(i
));
551 for (i
= 0; i
< 4; i
++)
552 regs_buff
[141 + i
] = rd32(E1000_RDH(i
));
553 for (i
= 0; i
< 4; i
++)
554 regs_buff
[145 + i
] = rd32(E1000_RDT(i
));
555 for (i
= 0; i
< 4; i
++)
556 regs_buff
[149 + i
] = rd32(E1000_RXDCTL(i
));
558 for (i
= 0; i
< 10; i
++)
559 regs_buff
[153 + i
] = rd32(E1000_EITR(i
));
560 for (i
= 0; i
< 8; i
++)
561 regs_buff
[163 + i
] = rd32(E1000_IMIR(i
));
562 for (i
= 0; i
< 8; i
++)
563 regs_buff
[171 + i
] = rd32(E1000_IMIREXT(i
));
564 for (i
= 0; i
< 16; i
++)
565 regs_buff
[179 + i
] = rd32(E1000_RAL(i
));
566 for (i
= 0; i
< 16; i
++)
567 regs_buff
[195 + i
] = rd32(E1000_RAH(i
));
569 for (i
= 0; i
< 4; i
++)
570 regs_buff
[211 + i
] = rd32(E1000_TDBAL(i
));
571 for (i
= 0; i
< 4; i
++)
572 regs_buff
[215 + i
] = rd32(E1000_TDBAH(i
));
573 for (i
= 0; i
< 4; i
++)
574 regs_buff
[219 + i
] = rd32(E1000_TDLEN(i
));
575 for (i
= 0; i
< 4; i
++)
576 regs_buff
[223 + i
] = rd32(E1000_TDH(i
));
577 for (i
= 0; i
< 4; i
++)
578 regs_buff
[227 + i
] = rd32(E1000_TDT(i
));
579 for (i
= 0; i
< 4; i
++)
580 regs_buff
[231 + i
] = rd32(E1000_TXDCTL(i
));
581 for (i
= 0; i
< 4; i
++)
582 regs_buff
[235 + i
] = rd32(E1000_TDWBAL(i
));
583 for (i
= 0; i
< 4; i
++)
584 regs_buff
[239 + i
] = rd32(E1000_TDWBAH(i
));
585 for (i
= 0; i
< 4; i
++)
586 regs_buff
[243 + i
] = rd32(E1000_DCA_TXCTRL(i
));
588 for (i
= 0; i
< 4; i
++)
589 regs_buff
[247 + i
] = rd32(E1000_IP4AT_REG(i
));
590 for (i
= 0; i
< 4; i
++)
591 regs_buff
[251 + i
] = rd32(E1000_IP6AT_REG(i
));
592 for (i
= 0; i
< 32; i
++)
593 regs_buff
[255 + i
] = rd32(E1000_WUPM_REG(i
));
594 for (i
= 0; i
< 128; i
++)
595 regs_buff
[287 + i
] = rd32(E1000_FFMT_REG(i
));
596 for (i
= 0; i
< 128; i
++)
597 regs_buff
[415 + i
] = rd32(E1000_FFVT_REG(i
));
598 for (i
= 0; i
< 4; i
++)
599 regs_buff
[543 + i
] = rd32(E1000_FFLT_REG(i
));
601 regs_buff
[547] = rd32(E1000_TDFH
);
602 regs_buff
[548] = rd32(E1000_TDFT
);
603 regs_buff
[549] = rd32(E1000_TDFHS
);
604 regs_buff
[550] = rd32(E1000_TDFPC
);
608 static int igb_get_eeprom_len(struct net_device
*netdev
)
610 struct igb_adapter
*adapter
= netdev_priv(netdev
);
611 return adapter
->hw
.nvm
.word_size
* 2;
614 static int igb_get_eeprom(struct net_device
*netdev
,
615 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
617 struct igb_adapter
*adapter
= netdev_priv(netdev
);
618 struct e1000_hw
*hw
= &adapter
->hw
;
620 int first_word
, last_word
;
624 if (eeprom
->len
== 0)
627 eeprom
->magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
629 first_word
= eeprom
->offset
>> 1;
630 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
632 eeprom_buff
= kmalloc(sizeof(u16
) *
633 (last_word
- first_word
+ 1), GFP_KERNEL
);
637 if (hw
->nvm
.type
== e1000_nvm_eeprom_spi
)
638 ret_val
= hw
->nvm
.ops
.read(hw
, first_word
,
639 last_word
- first_word
+ 1,
642 for (i
= 0; i
< last_word
- first_word
+ 1; i
++) {
643 ret_val
= hw
->nvm
.ops
.read(hw
, first_word
+ i
, 1,
650 /* Device's eeprom is always little-endian, word addressable */
651 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
652 le16_to_cpus(&eeprom_buff
[i
]);
654 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 1),
661 static int igb_set_eeprom(struct net_device
*netdev
,
662 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
664 struct igb_adapter
*adapter
= netdev_priv(netdev
);
665 struct e1000_hw
*hw
= &adapter
->hw
;
668 int max_len
, first_word
, last_word
, ret_val
= 0;
671 if (eeprom
->len
== 0)
674 if (eeprom
->magic
!= (hw
->vendor_id
| (hw
->device_id
<< 16)))
677 max_len
= hw
->nvm
.word_size
* 2;
679 first_word
= eeprom
->offset
>> 1;
680 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
681 eeprom_buff
= kmalloc(max_len
, GFP_KERNEL
);
685 ptr
= (void *)eeprom_buff
;
687 if (eeprom
->offset
& 1) {
688 /* need read/modify/write of first changed EEPROM word */
689 /* only the second byte of the word is being modified */
690 ret_val
= hw
->nvm
.ops
.read(hw
, first_word
, 1,
694 if (((eeprom
->offset
+ eeprom
->len
) & 1) && (ret_val
== 0)) {
695 /* need read/modify/write of last changed EEPROM word */
696 /* only the first byte of the word is being modified */
697 ret_val
= hw
->nvm
.ops
.read(hw
, last_word
, 1,
698 &eeprom_buff
[last_word
- first_word
]);
701 /* Device's eeprom is always little-endian, word addressable */
702 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
703 le16_to_cpus(&eeprom_buff
[i
]);
705 memcpy(ptr
, bytes
, eeprom
->len
);
707 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
708 eeprom_buff
[i
] = cpu_to_le16(eeprom_buff
[i
]);
710 ret_val
= hw
->nvm
.ops
.write(hw
, first_word
,
711 last_word
- first_word
+ 1, eeprom_buff
);
713 /* Update the checksum over the first part of the EEPROM if needed
714 * and flush shadow RAM for 82573 controllers */
715 if ((ret_val
== 0) && ((first_word
<= NVM_CHECKSUM_REG
)))
716 igb_update_nvm_checksum(hw
);
722 static void igb_get_drvinfo(struct net_device
*netdev
,
723 struct ethtool_drvinfo
*drvinfo
)
725 struct igb_adapter
*adapter
= netdev_priv(netdev
);
726 char firmware_version
[32];
729 strncpy(drvinfo
->driver
, igb_driver_name
, 32);
730 strncpy(drvinfo
->version
, igb_driver_version
, 32);
732 /* EEPROM image version # is reported as firmware version # for
733 * 82575 controllers */
734 adapter
->hw
.nvm
.ops
.read(&adapter
->hw
, 5, 1, &eeprom_data
);
735 sprintf(firmware_version
, "%d.%d-%d",
736 (eeprom_data
& 0xF000) >> 12,
737 (eeprom_data
& 0x0FF0) >> 4,
738 eeprom_data
& 0x000F);
740 strncpy(drvinfo
->fw_version
, firmware_version
, 32);
741 strncpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
), 32);
742 drvinfo
->n_stats
= IGB_STATS_LEN
;
743 drvinfo
->testinfo_len
= IGB_TEST_LEN
;
744 drvinfo
->regdump_len
= igb_get_regs_len(netdev
);
745 drvinfo
->eedump_len
= igb_get_eeprom_len(netdev
);
748 static void igb_get_ringparam(struct net_device
*netdev
,
749 struct ethtool_ringparam
*ring
)
751 struct igb_adapter
*adapter
= netdev_priv(netdev
);
753 ring
->rx_max_pending
= IGB_MAX_RXD
;
754 ring
->tx_max_pending
= IGB_MAX_TXD
;
755 ring
->rx_mini_max_pending
= 0;
756 ring
->rx_jumbo_max_pending
= 0;
757 ring
->rx_pending
= adapter
->rx_ring_count
;
758 ring
->tx_pending
= adapter
->tx_ring_count
;
759 ring
->rx_mini_pending
= 0;
760 ring
->rx_jumbo_pending
= 0;
763 static int igb_set_ringparam(struct net_device
*netdev
,
764 struct ethtool_ringparam
*ring
)
766 struct igb_adapter
*adapter
= netdev_priv(netdev
);
767 struct igb_ring
*temp_ring
;
769 u16 new_rx_count
, new_tx_count
;
771 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
774 new_rx_count
= min_t(u32
, ring
->rx_pending
, IGB_MAX_RXD
);
775 new_rx_count
= max_t(u16
, new_rx_count
, IGB_MIN_RXD
);
776 new_rx_count
= ALIGN(new_rx_count
, REQ_RX_DESCRIPTOR_MULTIPLE
);
778 new_tx_count
= min_t(u32
, ring
->tx_pending
, IGB_MAX_TXD
);
779 new_tx_count
= max_t(u16
, new_tx_count
, IGB_MIN_TXD
);
780 new_tx_count
= ALIGN(new_tx_count
, REQ_TX_DESCRIPTOR_MULTIPLE
);
782 if ((new_tx_count
== adapter
->tx_ring_count
) &&
783 (new_rx_count
== adapter
->rx_ring_count
)) {
788 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
791 if (!netif_running(adapter
->netdev
)) {
792 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
793 adapter
->tx_ring
[i
]->count
= new_tx_count
;
794 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
795 adapter
->rx_ring
[i
]->count
= new_rx_count
;
796 adapter
->tx_ring_count
= new_tx_count
;
797 adapter
->rx_ring_count
= new_rx_count
;
801 if (adapter
->num_tx_queues
> adapter
->num_rx_queues
)
802 temp_ring
= vmalloc(adapter
->num_tx_queues
* sizeof(struct igb_ring
));
804 temp_ring
= vmalloc(adapter
->num_rx_queues
* sizeof(struct igb_ring
));
814 * We can't just free everything and then setup again,
815 * because the ISRs in MSI-X mode get passed pointers
816 * to the tx and rx ring structs.
818 if (new_tx_count
!= adapter
->tx_ring_count
) {
819 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
820 memcpy(&temp_ring
[i
], adapter
->tx_ring
[i
],
821 sizeof(struct igb_ring
));
823 temp_ring
[i
].count
= new_tx_count
;
824 err
= igb_setup_tx_resources(&temp_ring
[i
]);
828 igb_free_tx_resources(&temp_ring
[i
]);
834 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
835 igb_free_tx_resources(adapter
->tx_ring
[i
]);
837 memcpy(adapter
->tx_ring
[i
], &temp_ring
[i
],
838 sizeof(struct igb_ring
));
841 adapter
->tx_ring_count
= new_tx_count
;
844 if (new_rx_count
!= adapter
->rx_ring_count
) {
845 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
846 memcpy(&temp_ring
[i
], adapter
->rx_ring
[i
],
847 sizeof(struct igb_ring
));
849 temp_ring
[i
].count
= new_rx_count
;
850 err
= igb_setup_rx_resources(&temp_ring
[i
]);
854 igb_free_rx_resources(&temp_ring
[i
]);
861 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
862 igb_free_rx_resources(adapter
->rx_ring
[i
]);
864 memcpy(adapter
->rx_ring
[i
], &temp_ring
[i
],
865 sizeof(struct igb_ring
));
868 adapter
->rx_ring_count
= new_rx_count
;
874 clear_bit(__IGB_RESETTING
, &adapter
->state
);
878 /* ethtool register test data */
879 struct igb_reg_test
{
888 /* In the hardware, registers are laid out either singly, in arrays
889 * spaced 0x100 bytes apart, or in contiguous tables. We assume
890 * most tests take place on arrays or single registers (handled
891 * as a single-element array) and special-case the tables.
892 * Table tests are always pattern tests.
894 * We also make provision for some required setup steps by specifying
895 * registers to be written without any read-back testing.
898 #define PATTERN_TEST 1
899 #define SET_READ_TEST 2
900 #define WRITE_NO_TEST 3
901 #define TABLE32_TEST 4
902 #define TABLE64_TEST_LO 5
903 #define TABLE64_TEST_HI 6
906 static struct igb_reg_test reg_test_82580
[] = {
907 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
908 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
909 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
910 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
911 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
912 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
913 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
914 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
915 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
916 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
917 /* RDH is read-only for 82580, only test RDT. */
918 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
919 { E1000_RDT(4), 0x40, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
920 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
921 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
922 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
923 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
924 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
925 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
926 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
927 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
928 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
929 { E1000_TDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
930 { E1000_TDT(4), 0x40, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
931 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
932 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0x003FFFFB },
933 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0xFFFFFFFF },
934 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
935 { E1000_RA
, 0, 16, TABLE64_TEST_LO
,
936 0xFFFFFFFF, 0xFFFFFFFF },
937 { E1000_RA
, 0, 16, TABLE64_TEST_HI
,
938 0x83FFFFFF, 0xFFFFFFFF },
939 { E1000_RA2
, 0, 8, TABLE64_TEST_LO
,
940 0xFFFFFFFF, 0xFFFFFFFF },
941 { E1000_RA2
, 0, 8, TABLE64_TEST_HI
,
942 0x83FFFFFF, 0xFFFFFFFF },
943 { E1000_MTA
, 0, 128, TABLE32_TEST
,
944 0xFFFFFFFF, 0xFFFFFFFF },
949 static struct igb_reg_test reg_test_82576
[] = {
950 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
951 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
952 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
953 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
954 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
955 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
956 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
957 { E1000_RDBAL(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
958 { E1000_RDBAH(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
959 { E1000_RDLEN(4), 0x40, 12, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
960 /* Enable all RX queues before testing. */
961 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, E1000_RXDCTL_QUEUE_ENABLE
},
962 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST
, 0, E1000_RXDCTL_QUEUE_ENABLE
},
963 /* RDH is read-only for 82576, only test RDT. */
964 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
965 { E1000_RDT(4), 0x40, 12, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
966 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, 0 },
967 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST
, 0, 0 },
968 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
969 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
970 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
971 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
972 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
973 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
974 { E1000_TDBAL(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
975 { E1000_TDBAH(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
976 { E1000_TDLEN(4), 0x40, 12, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
977 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
978 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0x003FFFFB },
979 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0xFFFFFFFF },
980 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
981 { E1000_RA
, 0, 16, TABLE64_TEST_LO
, 0xFFFFFFFF, 0xFFFFFFFF },
982 { E1000_RA
, 0, 16, TABLE64_TEST_HI
, 0x83FFFFFF, 0xFFFFFFFF },
983 { E1000_RA2
, 0, 8, TABLE64_TEST_LO
, 0xFFFFFFFF, 0xFFFFFFFF },
984 { E1000_RA2
, 0, 8, TABLE64_TEST_HI
, 0x83FFFFFF, 0xFFFFFFFF },
985 { E1000_MTA
, 0, 128,TABLE32_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
989 /* 82575 register test */
990 static struct igb_reg_test reg_test_82575
[] = {
991 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
992 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
993 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
994 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
995 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
996 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
997 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
998 /* Enable all four RX queues before testing. */
999 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, E1000_RXDCTL_QUEUE_ENABLE
},
1000 /* RDH is read-only for 82575, only test RDT. */
1001 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1002 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, 0 },
1003 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
1004 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
1005 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
1006 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
1007 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1008 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
1009 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1010 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB3FE, 0x003FFFFB },
1011 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB3FE, 0xFFFFFFFF },
1012 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
1013 { E1000_TXCW
, 0x100, 1, PATTERN_TEST
, 0xC000FFFF, 0x0000FFFF },
1014 { E1000_RA
, 0, 16, TABLE64_TEST_LO
, 0xFFFFFFFF, 0xFFFFFFFF },
1015 { E1000_RA
, 0, 16, TABLE64_TEST_HI
, 0x800FFFFF, 0xFFFFFFFF },
1016 { E1000_MTA
, 0, 128, TABLE32_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
1020 static bool reg_pattern_test(struct igb_adapter
*adapter
, u64
*data
,
1021 int reg
, u32 mask
, u32 write
)
1023 struct e1000_hw
*hw
= &adapter
->hw
;
1025 static const u32 _test
[] =
1026 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
1027 for (pat
= 0; pat
< ARRAY_SIZE(_test
); pat
++) {
1028 wr32(reg
, (_test
[pat
] & write
));
1030 if (val
!= (_test
[pat
] & write
& mask
)) {
1031 dev_err(&adapter
->pdev
->dev
, "pattern test reg %04X "
1032 "failed: got 0x%08X expected 0x%08X\n",
1033 reg
, val
, (_test
[pat
] & write
& mask
));
1042 static bool reg_set_and_check(struct igb_adapter
*adapter
, u64
*data
,
1043 int reg
, u32 mask
, u32 write
)
1045 struct e1000_hw
*hw
= &adapter
->hw
;
1047 wr32(reg
, write
& mask
);
1049 if ((write
& mask
) != (val
& mask
)) {
1050 dev_err(&adapter
->pdev
->dev
, "set/check reg %04X test failed:"
1051 " got 0x%08X expected 0x%08X\n", reg
,
1052 (val
& mask
), (write
& mask
));
1060 #define REG_PATTERN_TEST(reg, mask, write) \
1062 if (reg_pattern_test(adapter, data, reg, mask, write)) \
1066 #define REG_SET_AND_CHECK(reg, mask, write) \
1068 if (reg_set_and_check(adapter, data, reg, mask, write)) \
1072 static int igb_reg_test(struct igb_adapter
*adapter
, u64
*data
)
1074 struct e1000_hw
*hw
= &adapter
->hw
;
1075 struct igb_reg_test
*test
;
1076 u32 value
, before
, after
;
1079 switch (adapter
->hw
.mac
.type
) {
1081 test
= reg_test_82580
;
1082 toggle
= 0x7FEFF3FF;
1085 test
= reg_test_82576
;
1086 toggle
= 0x7FFFF3FF;
1089 test
= reg_test_82575
;
1090 toggle
= 0x7FFFF3FF;
1094 /* Because the status register is such a special case,
1095 * we handle it separately from the rest of the register
1096 * tests. Some bits are read-only, some toggle, and some
1097 * are writable on newer MACs.
1099 before
= rd32(E1000_STATUS
);
1100 value
= (rd32(E1000_STATUS
) & toggle
);
1101 wr32(E1000_STATUS
, toggle
);
1102 after
= rd32(E1000_STATUS
) & toggle
;
1103 if (value
!= after
) {
1104 dev_err(&adapter
->pdev
->dev
, "failed STATUS register test "
1105 "got: 0x%08X expected: 0x%08X\n", after
, value
);
1109 /* restore previous status */
1110 wr32(E1000_STATUS
, before
);
1112 /* Perform the remainder of the register test, looping through
1113 * the test table until we either fail or reach the null entry.
1116 for (i
= 0; i
< test
->array_len
; i
++) {
1117 switch (test
->test_type
) {
1119 REG_PATTERN_TEST(test
->reg
+
1120 (i
* test
->reg_offset
),
1125 REG_SET_AND_CHECK(test
->reg
+
1126 (i
* test
->reg_offset
),
1132 (adapter
->hw
.hw_addr
+ test
->reg
)
1133 + (i
* test
->reg_offset
));
1136 REG_PATTERN_TEST(test
->reg
+ (i
* 4),
1140 case TABLE64_TEST_LO
:
1141 REG_PATTERN_TEST(test
->reg
+ (i
* 8),
1145 case TABLE64_TEST_HI
:
1146 REG_PATTERN_TEST((test
->reg
+ 4) + (i
* 8),
1159 static int igb_eeprom_test(struct igb_adapter
*adapter
, u64
*data
)
1166 /* Read and add up the contents of the EEPROM */
1167 for (i
= 0; i
< (NVM_CHECKSUM_REG
+ 1); i
++) {
1168 if ((adapter
->hw
.nvm
.ops
.read(&adapter
->hw
, i
, 1, &temp
)) < 0) {
1175 /* If Checksum is not Correct return error else test passed */
1176 if ((checksum
!= (u16
) NVM_SUM
) && !(*data
))
1182 static irqreturn_t
igb_test_intr(int irq
, void *data
)
1184 struct igb_adapter
*adapter
= (struct igb_adapter
*) data
;
1185 struct e1000_hw
*hw
= &adapter
->hw
;
1187 adapter
->test_icr
|= rd32(E1000_ICR
);
1192 static int igb_intr_test(struct igb_adapter
*adapter
, u64
*data
)
1194 struct e1000_hw
*hw
= &adapter
->hw
;
1195 struct net_device
*netdev
= adapter
->netdev
;
1196 u32 mask
, ics_mask
, i
= 0, shared_int
= true;
1197 u32 irq
= adapter
->pdev
->irq
;
1201 /* Hook up test interrupt handler just for this test */
1202 if (adapter
->msix_entries
) {
1203 if (request_irq(adapter
->msix_entries
[0].vector
,
1204 igb_test_intr
, 0, netdev
->name
, adapter
)) {
1208 } else if (adapter
->flags
& IGB_FLAG_HAS_MSI
) {
1210 if (request_irq(irq
,
1211 igb_test_intr
, 0, netdev
->name
, adapter
)) {
1215 } else if (!request_irq(irq
, igb_test_intr
, IRQF_PROBE_SHARED
,
1216 netdev
->name
, adapter
)) {
1218 } else if (request_irq(irq
, igb_test_intr
, IRQF_SHARED
,
1219 netdev
->name
, adapter
)) {
1223 dev_info(&adapter
->pdev
->dev
, "testing %s interrupt\n",
1224 (shared_int
? "shared" : "unshared"));
1226 /* Disable all the interrupts */
1227 wr32(E1000_IMC
, ~0);
1230 /* Define all writable bits for ICS */
1231 switch (hw
->mac
.type
) {
1233 ics_mask
= 0x37F47EDD;
1236 ics_mask
= 0x77D4FBFD;
1239 ics_mask
= 0x77DCFED5;
1242 ics_mask
= 0x7FFFFFFF;
1246 /* Test each interrupt */
1247 for (; i
< 31; i
++) {
1248 /* Interrupt to test */
1251 if (!(mask
& ics_mask
))
1255 /* Disable the interrupt to be reported in
1256 * the cause register and then force the same
1257 * interrupt and see if one gets posted. If
1258 * an interrupt was posted to the bus, the
1261 adapter
->test_icr
= 0;
1263 /* Flush any pending interrupts */
1264 wr32(E1000_ICR
, ~0);
1266 wr32(E1000_IMC
, mask
);
1267 wr32(E1000_ICS
, mask
);
1270 if (adapter
->test_icr
& mask
) {
1276 /* Enable the interrupt to be reported in
1277 * the cause register and then force the same
1278 * interrupt and see if one gets posted. If
1279 * an interrupt was not posted to the bus, the
1282 adapter
->test_icr
= 0;
1284 /* Flush any pending interrupts */
1285 wr32(E1000_ICR
, ~0);
1287 wr32(E1000_IMS
, mask
);
1288 wr32(E1000_ICS
, mask
);
1291 if (!(adapter
->test_icr
& mask
)) {
1297 /* Disable the other interrupts to be reported in
1298 * the cause register and then force the other
1299 * interrupts and see if any get posted. If
1300 * an interrupt was posted to the bus, the
1303 adapter
->test_icr
= 0;
1305 /* Flush any pending interrupts */
1306 wr32(E1000_ICR
, ~0);
1308 wr32(E1000_IMC
, ~mask
);
1309 wr32(E1000_ICS
, ~mask
);
1312 if (adapter
->test_icr
& mask
) {
1319 /* Disable all the interrupts */
1320 wr32(E1000_IMC
, ~0);
1323 /* Unhook test interrupt handler */
1324 if (adapter
->msix_entries
)
1325 free_irq(adapter
->msix_entries
[0].vector
, adapter
);
1327 free_irq(irq
, adapter
);
1332 static void igb_free_desc_rings(struct igb_adapter
*adapter
)
1334 igb_free_tx_resources(&adapter
->test_tx_ring
);
1335 igb_free_rx_resources(&adapter
->test_rx_ring
);
1338 static int igb_setup_desc_rings(struct igb_adapter
*adapter
)
1340 struct igb_ring
*tx_ring
= &adapter
->test_tx_ring
;
1341 struct igb_ring
*rx_ring
= &adapter
->test_rx_ring
;
1342 struct e1000_hw
*hw
= &adapter
->hw
;
1345 /* Setup Tx descriptor ring and Tx buffers */
1346 tx_ring
->count
= IGB_DEFAULT_TXD
;
1347 tx_ring
->pdev
= adapter
->pdev
;
1348 tx_ring
->netdev
= adapter
->netdev
;
1349 tx_ring
->reg_idx
= adapter
->vfs_allocated_count
;
1351 if (igb_setup_tx_resources(tx_ring
)) {
1356 igb_setup_tctl(adapter
);
1357 igb_configure_tx_ring(adapter
, tx_ring
);
1359 /* Setup Rx descriptor ring and Rx buffers */
1360 rx_ring
->count
= IGB_DEFAULT_RXD
;
1361 rx_ring
->pdev
= adapter
->pdev
;
1362 rx_ring
->netdev
= adapter
->netdev
;
1363 rx_ring
->rx_buffer_len
= IGB_RXBUFFER_2048
;
1364 rx_ring
->reg_idx
= adapter
->vfs_allocated_count
;
1366 if (igb_setup_rx_resources(rx_ring
)) {
1371 /* set the default queue to queue 0 of PF */
1372 wr32(E1000_MRQC
, adapter
->vfs_allocated_count
<< 3);
1374 /* enable receive ring */
1375 igb_setup_rctl(adapter
);
1376 igb_configure_rx_ring(adapter
, rx_ring
);
1378 igb_alloc_rx_buffers_adv(rx_ring
, igb_desc_unused(rx_ring
));
1383 igb_free_desc_rings(adapter
);
1387 static void igb_phy_disable_receiver(struct igb_adapter
*adapter
)
1389 struct e1000_hw
*hw
= &adapter
->hw
;
1391 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1392 igb_write_phy_reg(hw
, 29, 0x001F);
1393 igb_write_phy_reg(hw
, 30, 0x8FFC);
1394 igb_write_phy_reg(hw
, 29, 0x001A);
1395 igb_write_phy_reg(hw
, 30, 0x8FF0);
1398 static int igb_integrated_phy_loopback(struct igb_adapter
*adapter
)
1400 struct e1000_hw
*hw
= &adapter
->hw
;
1403 hw
->mac
.autoneg
= false;
1405 if (hw
->phy
.type
== e1000_phy_m88
) {
1406 /* Auto-MDI/MDIX Off */
1407 igb_write_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, 0x0808);
1408 /* reset to update Auto-MDI/MDIX */
1409 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x9140);
1411 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x8140);
1412 } else if (hw
->phy
.type
== e1000_phy_82580
) {
1413 /* enable MII loopback */
1414 igb_write_phy_reg(hw
, I82580_PHY_LBK_CTRL
, 0x8041);
1417 ctrl_reg
= rd32(E1000_CTRL
);
1419 /* force 1000, set loopback */
1420 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x4140);
1422 /* Now set up the MAC to the same speed/duplex as the PHY. */
1423 ctrl_reg
= rd32(E1000_CTRL
);
1424 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1425 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1426 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1427 E1000_CTRL_SPD_1000
|/* Force Speed to 1000 */
1428 E1000_CTRL_FD
| /* Force Duplex to FULL */
1429 E1000_CTRL_SLU
); /* Set link up enable bit */
1431 if (hw
->phy
.type
== e1000_phy_m88
)
1432 ctrl_reg
|= E1000_CTRL_ILOS
; /* Invert Loss of Signal */
1434 wr32(E1000_CTRL
, ctrl_reg
);
1436 /* Disable the receiver on the PHY so when a cable is plugged in, the
1437 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1439 if (hw
->phy
.type
== e1000_phy_m88
)
1440 igb_phy_disable_receiver(adapter
);
1447 static int igb_set_phy_loopback(struct igb_adapter
*adapter
)
1449 return igb_integrated_phy_loopback(adapter
);
1452 static int igb_setup_loopback_test(struct igb_adapter
*adapter
)
1454 struct e1000_hw
*hw
= &adapter
->hw
;
1457 reg
= rd32(E1000_CTRL_EXT
);
1459 /* use CTRL_EXT to identify link type as SGMII can appear as copper */
1460 if (reg
& E1000_CTRL_EXT_LINK_MODE_MASK
) {
1461 reg
= rd32(E1000_RCTL
);
1462 reg
|= E1000_RCTL_LBM_TCVR
;
1463 wr32(E1000_RCTL
, reg
);
1465 wr32(E1000_SCTL
, E1000_ENABLE_SERDES_LOOPBACK
);
1467 reg
= rd32(E1000_CTRL
);
1468 reg
&= ~(E1000_CTRL_RFCE
|
1471 reg
|= E1000_CTRL_SLU
|
1473 wr32(E1000_CTRL
, reg
);
1475 /* Unset switch control to serdes energy detect */
1476 reg
= rd32(E1000_CONNSW
);
1477 reg
&= ~E1000_CONNSW_ENRGSRC
;
1478 wr32(E1000_CONNSW
, reg
);
1480 /* Set PCS register for forced speed */
1481 reg
= rd32(E1000_PCS_LCTL
);
1482 reg
&= ~E1000_PCS_LCTL_AN_ENABLE
; /* Disable Autoneg*/
1483 reg
|= E1000_PCS_LCTL_FLV_LINK_UP
| /* Force link up */
1484 E1000_PCS_LCTL_FSV_1000
| /* Force 1000 */
1485 E1000_PCS_LCTL_FDV_FULL
| /* SerDes Full duplex */
1486 E1000_PCS_LCTL_FSD
| /* Force Speed */
1487 E1000_PCS_LCTL_FORCE_LINK
; /* Force Link */
1488 wr32(E1000_PCS_LCTL
, reg
);
1493 return igb_set_phy_loopback(adapter
);
1496 static void igb_loopback_cleanup(struct igb_adapter
*adapter
)
1498 struct e1000_hw
*hw
= &adapter
->hw
;
1502 rctl
= rd32(E1000_RCTL
);
1503 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
1504 wr32(E1000_RCTL
, rctl
);
1506 hw
->mac
.autoneg
= true;
1507 igb_read_phy_reg(hw
, PHY_CONTROL
, &phy_reg
);
1508 if (phy_reg
& MII_CR_LOOPBACK
) {
1509 phy_reg
&= ~MII_CR_LOOPBACK
;
1510 igb_write_phy_reg(hw
, PHY_CONTROL
, phy_reg
);
1511 igb_phy_sw_reset(hw
);
1515 static void igb_create_lbtest_frame(struct sk_buff
*skb
,
1516 unsigned int frame_size
)
1518 memset(skb
->data
, 0xFF, frame_size
);
1520 memset(&skb
->data
[frame_size
], 0xAA, frame_size
- 1);
1521 memset(&skb
->data
[frame_size
+ 10], 0xBE, 1);
1522 memset(&skb
->data
[frame_size
+ 12], 0xAF, 1);
1525 static int igb_check_lbtest_frame(struct sk_buff
*skb
, unsigned int frame_size
)
1528 if (*(skb
->data
+ 3) == 0xFF) {
1529 if ((*(skb
->data
+ frame_size
+ 10) == 0xBE) &&
1530 (*(skb
->data
+ frame_size
+ 12) == 0xAF)) {
1537 static int igb_clean_test_rings(struct igb_ring
*rx_ring
,
1538 struct igb_ring
*tx_ring
,
1541 union e1000_adv_rx_desc
*rx_desc
;
1542 struct igb_buffer
*buffer_info
;
1543 int rx_ntc
, tx_ntc
, count
= 0;
1546 /* initialize next to clean and descriptor values */
1547 rx_ntc
= rx_ring
->next_to_clean
;
1548 tx_ntc
= tx_ring
->next_to_clean
;
1549 rx_desc
= E1000_RX_DESC_ADV(*rx_ring
, rx_ntc
);
1550 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1552 while (staterr
& E1000_RXD_STAT_DD
) {
1553 /* check rx buffer */
1554 buffer_info
= &rx_ring
->buffer_info
[rx_ntc
];
1556 /* unmap rx buffer, will be remapped by alloc_rx_buffers */
1557 pci_unmap_single(rx_ring
->pdev
,
1559 rx_ring
->rx_buffer_len
,
1560 PCI_DMA_FROMDEVICE
);
1561 buffer_info
->dma
= 0;
1563 /* verify contents of skb */
1564 if (!igb_check_lbtest_frame(buffer_info
->skb
, size
))
1567 /* unmap buffer on tx side */
1568 buffer_info
= &tx_ring
->buffer_info
[tx_ntc
];
1569 igb_unmap_and_free_tx_resource(tx_ring
, buffer_info
);
1571 /* increment rx/tx next to clean counters */
1573 if (rx_ntc
== rx_ring
->count
)
1576 if (tx_ntc
== tx_ring
->count
)
1579 /* fetch next descriptor */
1580 rx_desc
= E1000_RX_DESC_ADV(*rx_ring
, rx_ntc
);
1581 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1584 /* re-map buffers to ring, store next to clean values */
1585 igb_alloc_rx_buffers_adv(rx_ring
, count
);
1586 rx_ring
->next_to_clean
= rx_ntc
;
1587 tx_ring
->next_to_clean
= tx_ntc
;
1592 static int igb_run_loopback_test(struct igb_adapter
*adapter
)
1594 struct igb_ring
*tx_ring
= &adapter
->test_tx_ring
;
1595 struct igb_ring
*rx_ring
= &adapter
->test_rx_ring
;
1596 int i
, j
, lc
, good_cnt
, ret_val
= 0;
1597 unsigned int size
= 1024;
1598 netdev_tx_t tx_ret_val
;
1599 struct sk_buff
*skb
;
1601 /* allocate test skb */
1602 skb
= alloc_skb(size
, GFP_KERNEL
);
1606 /* place data into test skb */
1607 igb_create_lbtest_frame(skb
, size
);
1611 * Calculate the loop count based on the largest descriptor ring
1612 * The idea is to wrap the largest ring a number of times using 64
1613 * send/receive pairs during each loop
1616 if (rx_ring
->count
<= tx_ring
->count
)
1617 lc
= ((tx_ring
->count
/ 64) * 2) + 1;
1619 lc
= ((rx_ring
->count
/ 64) * 2) + 1;
1621 for (j
= 0; j
<= lc
; j
++) { /* loop count loop */
1622 /* reset count of good packets */
1625 /* place 64 packets on the transmit queue*/
1626 for (i
= 0; i
< 64; i
++) {
1628 tx_ret_val
= igb_xmit_frame_ring_adv(skb
, tx_ring
);
1629 if (tx_ret_val
== NETDEV_TX_OK
)
1633 if (good_cnt
!= 64) {
1638 /* allow 200 milliseconds for packets to go from tx to rx */
1641 good_cnt
= igb_clean_test_rings(rx_ring
, tx_ring
, size
);
1642 if (good_cnt
!= 64) {
1646 } /* end loop count loop */
1648 /* free the original skb */
1654 static int igb_loopback_test(struct igb_adapter
*adapter
, u64
*data
)
1656 /* PHY loopback cannot be performed if SoL/IDER
1657 * sessions are active */
1658 if (igb_check_reset_block(&adapter
->hw
)) {
1659 dev_err(&adapter
->pdev
->dev
,
1660 "Cannot do PHY loopback test "
1661 "when SoL/IDER is active.\n");
1665 *data
= igb_setup_desc_rings(adapter
);
1668 *data
= igb_setup_loopback_test(adapter
);
1671 *data
= igb_run_loopback_test(adapter
);
1672 igb_loopback_cleanup(adapter
);
1675 igb_free_desc_rings(adapter
);
1680 static int igb_link_test(struct igb_adapter
*adapter
, u64
*data
)
1682 struct e1000_hw
*hw
= &adapter
->hw
;
1684 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1686 hw
->mac
.serdes_has_link
= false;
1688 /* On some blade server designs, link establishment
1689 * could take as long as 2-3 minutes */
1691 hw
->mac
.ops
.check_for_link(&adapter
->hw
);
1692 if (hw
->mac
.serdes_has_link
)
1695 } while (i
++ < 3750);
1699 hw
->mac
.ops
.check_for_link(&adapter
->hw
);
1700 if (hw
->mac
.autoneg
)
1703 if (!(rd32(E1000_STATUS
) & E1000_STATUS_LU
))
1709 static void igb_diag_test(struct net_device
*netdev
,
1710 struct ethtool_test
*eth_test
, u64
*data
)
1712 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1713 u16 autoneg_advertised
;
1714 u8 forced_speed_duplex
, autoneg
;
1715 bool if_running
= netif_running(netdev
);
1717 set_bit(__IGB_TESTING
, &adapter
->state
);
1718 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1721 /* save speed, duplex, autoneg settings */
1722 autoneg_advertised
= adapter
->hw
.phy
.autoneg_advertised
;
1723 forced_speed_duplex
= adapter
->hw
.mac
.forced_speed_duplex
;
1724 autoneg
= adapter
->hw
.mac
.autoneg
;
1726 dev_info(&adapter
->pdev
->dev
, "offline testing starting\n");
1728 /* power up link for link test */
1729 igb_power_up_link(adapter
);
1731 /* Link test performed before hardware reset so autoneg doesn't
1732 * interfere with test result */
1733 if (igb_link_test(adapter
, &data
[4]))
1734 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1737 /* indicate we're in test mode */
1742 if (igb_reg_test(adapter
, &data
[0]))
1743 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1746 if (igb_eeprom_test(adapter
, &data
[1]))
1747 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1750 if (igb_intr_test(adapter
, &data
[2]))
1751 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1754 /* power up link for loopback test */
1755 igb_power_up_link(adapter
);
1756 if (igb_loopback_test(adapter
, &data
[3]))
1757 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1759 /* restore speed, duplex, autoneg settings */
1760 adapter
->hw
.phy
.autoneg_advertised
= autoneg_advertised
;
1761 adapter
->hw
.mac
.forced_speed_duplex
= forced_speed_duplex
;
1762 adapter
->hw
.mac
.autoneg
= autoneg
;
1764 /* force this routine to wait until autoneg complete/timeout */
1765 adapter
->hw
.phy
.autoneg_wait_to_complete
= true;
1767 adapter
->hw
.phy
.autoneg_wait_to_complete
= false;
1769 clear_bit(__IGB_TESTING
, &adapter
->state
);
1773 dev_info(&adapter
->pdev
->dev
, "online testing starting\n");
1775 /* PHY is powered down when interface is down */
1776 if (!netif_carrier_ok(netdev
)) {
1779 if (igb_link_test(adapter
, &data
[4]))
1780 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1783 /* Online tests aren't run; pass by default */
1789 clear_bit(__IGB_TESTING
, &adapter
->state
);
1791 msleep_interruptible(4 * 1000);
1794 static int igb_wol_exclusion(struct igb_adapter
*adapter
,
1795 struct ethtool_wolinfo
*wol
)
1797 struct e1000_hw
*hw
= &adapter
->hw
;
1798 int retval
= 1; /* fail by default */
1800 switch (hw
->device_id
) {
1801 case E1000_DEV_ID_82575GB_QUAD_COPPER
:
1802 /* WoL not supported */
1805 case E1000_DEV_ID_82575EB_FIBER_SERDES
:
1806 case E1000_DEV_ID_82576_FIBER
:
1807 case E1000_DEV_ID_82576_SERDES
:
1808 /* Wake events not supported on port B */
1809 if (rd32(E1000_STATUS
) & E1000_STATUS_FUNC_1
) {
1813 /* return success for non excluded adapter ports */
1816 case E1000_DEV_ID_82576_QUAD_COPPER
:
1817 case E1000_DEV_ID_82576_QUAD_COPPER_ET2
:
1818 /* quad port adapters only support WoL on port A */
1819 if (!(adapter
->flags
& IGB_FLAG_QUAD_PORT_A
)) {
1823 /* return success for non excluded adapter ports */
1827 /* dual port cards only support WoL on port A from now on
1828 * unless it was enabled in the eeprom for port B
1829 * so exclude FUNC_1 ports from having WoL enabled */
1830 if ((rd32(E1000_STATUS
) & E1000_STATUS_FUNC_MASK
) &&
1831 !adapter
->eeprom_wol
) {
1842 static void igb_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1844 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1846 wol
->supported
= WAKE_UCAST
| WAKE_MCAST
|
1847 WAKE_BCAST
| WAKE_MAGIC
|
1851 /* this function will set ->supported = 0 and return 1 if wol is not
1852 * supported by this hardware */
1853 if (igb_wol_exclusion(adapter
, wol
) ||
1854 !device_can_wakeup(&adapter
->pdev
->dev
))
1857 /* apply any specific unsupported masks here */
1858 switch (adapter
->hw
.device_id
) {
1863 if (adapter
->wol
& E1000_WUFC_EX
)
1864 wol
->wolopts
|= WAKE_UCAST
;
1865 if (adapter
->wol
& E1000_WUFC_MC
)
1866 wol
->wolopts
|= WAKE_MCAST
;
1867 if (adapter
->wol
& E1000_WUFC_BC
)
1868 wol
->wolopts
|= WAKE_BCAST
;
1869 if (adapter
->wol
& E1000_WUFC_MAG
)
1870 wol
->wolopts
|= WAKE_MAGIC
;
1871 if (adapter
->wol
& E1000_WUFC_LNKC
)
1872 wol
->wolopts
|= WAKE_PHY
;
1875 static int igb_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1877 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1879 if (wol
->wolopts
& (WAKE_ARP
| WAKE_MAGICSECURE
))
1882 if (igb_wol_exclusion(adapter
, wol
) ||
1883 !device_can_wakeup(&adapter
->pdev
->dev
))
1884 return wol
->wolopts
? -EOPNOTSUPP
: 0;
1886 /* these settings will always override what we currently have */
1889 if (wol
->wolopts
& WAKE_UCAST
)
1890 adapter
->wol
|= E1000_WUFC_EX
;
1891 if (wol
->wolopts
& WAKE_MCAST
)
1892 adapter
->wol
|= E1000_WUFC_MC
;
1893 if (wol
->wolopts
& WAKE_BCAST
)
1894 adapter
->wol
|= E1000_WUFC_BC
;
1895 if (wol
->wolopts
& WAKE_MAGIC
)
1896 adapter
->wol
|= E1000_WUFC_MAG
;
1897 if (wol
->wolopts
& WAKE_PHY
)
1898 adapter
->wol
|= E1000_WUFC_LNKC
;
1899 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
1904 /* bit defines for adapter->led_status */
1905 #define IGB_LED_ON 0
1907 static int igb_phys_id(struct net_device
*netdev
, u32 data
)
1909 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1910 struct e1000_hw
*hw
= &adapter
->hw
;
1911 unsigned long timeout
;
1913 timeout
= data
* 1000;
1916 * msleep_interruptable only accepts unsigned int so we are limited
1917 * in how long a duration we can wait
1919 if (!timeout
|| timeout
> UINT_MAX
)
1923 msleep_interruptible(timeout
);
1926 clear_bit(IGB_LED_ON
, &adapter
->led_status
);
1927 igb_cleanup_led(hw
);
1932 static int igb_set_coalesce(struct net_device
*netdev
,
1933 struct ethtool_coalesce
*ec
)
1935 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1938 if ((ec
->rx_coalesce_usecs
> IGB_MAX_ITR_USECS
) ||
1939 ((ec
->rx_coalesce_usecs
> 3) &&
1940 (ec
->rx_coalesce_usecs
< IGB_MIN_ITR_USECS
)) ||
1941 (ec
->rx_coalesce_usecs
== 2))
1944 if ((ec
->tx_coalesce_usecs
> IGB_MAX_ITR_USECS
) ||
1945 ((ec
->tx_coalesce_usecs
> 3) &&
1946 (ec
->tx_coalesce_usecs
< IGB_MIN_ITR_USECS
)) ||
1947 (ec
->tx_coalesce_usecs
== 2))
1950 if ((adapter
->flags
& IGB_FLAG_QUEUE_PAIRS
) && ec
->tx_coalesce_usecs
)
1953 /* convert to rate of irq's per second */
1954 if (ec
->rx_coalesce_usecs
&& ec
->rx_coalesce_usecs
<= 3)
1955 adapter
->rx_itr_setting
= ec
->rx_coalesce_usecs
;
1957 adapter
->rx_itr_setting
= ec
->rx_coalesce_usecs
<< 2;
1959 /* convert to rate of irq's per second */
1960 if (adapter
->flags
& IGB_FLAG_QUEUE_PAIRS
)
1961 adapter
->tx_itr_setting
= adapter
->rx_itr_setting
;
1962 else if (ec
->tx_coalesce_usecs
&& ec
->tx_coalesce_usecs
<= 3)
1963 adapter
->tx_itr_setting
= ec
->tx_coalesce_usecs
;
1965 adapter
->tx_itr_setting
= ec
->tx_coalesce_usecs
<< 2;
1967 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
1968 struct igb_q_vector
*q_vector
= adapter
->q_vector
[i
];
1969 if (q_vector
->rx_ring
)
1970 q_vector
->itr_val
= adapter
->rx_itr_setting
;
1972 q_vector
->itr_val
= adapter
->tx_itr_setting
;
1973 if (q_vector
->itr_val
&& q_vector
->itr_val
<= 3)
1974 q_vector
->itr_val
= IGB_START_ITR
;
1975 q_vector
->set_itr
= 1;
1981 static int igb_get_coalesce(struct net_device
*netdev
,
1982 struct ethtool_coalesce
*ec
)
1984 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1986 if (adapter
->rx_itr_setting
<= 3)
1987 ec
->rx_coalesce_usecs
= adapter
->rx_itr_setting
;
1989 ec
->rx_coalesce_usecs
= adapter
->rx_itr_setting
>> 2;
1991 if (!(adapter
->flags
& IGB_FLAG_QUEUE_PAIRS
)) {
1992 if (adapter
->tx_itr_setting
<= 3)
1993 ec
->tx_coalesce_usecs
= adapter
->tx_itr_setting
;
1995 ec
->tx_coalesce_usecs
= adapter
->tx_itr_setting
>> 2;
2001 static int igb_nway_reset(struct net_device
*netdev
)
2003 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2004 if (netif_running(netdev
))
2005 igb_reinit_locked(adapter
);
2009 static int igb_get_sset_count(struct net_device
*netdev
, int sset
)
2013 return IGB_STATS_LEN
;
2015 return IGB_TEST_LEN
;
2021 static void igb_get_ethtool_stats(struct net_device
*netdev
,
2022 struct ethtool_stats
*stats
, u64
*data
)
2024 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2025 struct net_device_stats
*net_stats
= &netdev
->stats
;
2030 igb_update_stats(adapter
);
2032 for (i
= 0; i
< IGB_GLOBAL_STATS_LEN
; i
++) {
2033 p
= (char *)adapter
+ igb_gstrings_stats
[i
].stat_offset
;
2034 data
[i
] = (igb_gstrings_stats
[i
].sizeof_stat
==
2035 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
2037 for (j
= 0; j
< IGB_NETDEV_STATS_LEN
; j
++, i
++) {
2038 p
= (char *)net_stats
+ igb_gstrings_net_stats
[j
].stat_offset
;
2039 data
[i
] = (igb_gstrings_net_stats
[j
].sizeof_stat
==
2040 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
2042 for (j
= 0; j
< adapter
->num_tx_queues
; j
++) {
2043 queue_stat
= (u64
*)&adapter
->tx_ring
[j
]->tx_stats
;
2044 for (k
= 0; k
< IGB_TX_QUEUE_STATS_LEN
; k
++, i
++)
2045 data
[i
] = queue_stat
[k
];
2047 for (j
= 0; j
< adapter
->num_rx_queues
; j
++) {
2048 queue_stat
= (u64
*)&adapter
->rx_ring
[j
]->rx_stats
;
2049 for (k
= 0; k
< IGB_RX_QUEUE_STATS_LEN
; k
++, i
++)
2050 data
[i
] = queue_stat
[k
];
2054 static void igb_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*data
)
2056 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2060 switch (stringset
) {
2062 memcpy(data
, *igb_gstrings_test
,
2063 IGB_TEST_LEN
*ETH_GSTRING_LEN
);
2066 for (i
= 0; i
< IGB_GLOBAL_STATS_LEN
; i
++) {
2067 memcpy(p
, igb_gstrings_stats
[i
].stat_string
,
2069 p
+= ETH_GSTRING_LEN
;
2071 for (i
= 0; i
< IGB_NETDEV_STATS_LEN
; i
++) {
2072 memcpy(p
, igb_gstrings_net_stats
[i
].stat_string
,
2074 p
+= ETH_GSTRING_LEN
;
2076 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2077 sprintf(p
, "tx_queue_%u_packets", i
);
2078 p
+= ETH_GSTRING_LEN
;
2079 sprintf(p
, "tx_queue_%u_bytes", i
);
2080 p
+= ETH_GSTRING_LEN
;
2081 sprintf(p
, "tx_queue_%u_restart", i
);
2082 p
+= ETH_GSTRING_LEN
;
2084 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2085 sprintf(p
, "rx_queue_%u_packets", i
);
2086 p
+= ETH_GSTRING_LEN
;
2087 sprintf(p
, "rx_queue_%u_bytes", i
);
2088 p
+= ETH_GSTRING_LEN
;
2089 sprintf(p
, "rx_queue_%u_drops", i
);
2090 p
+= ETH_GSTRING_LEN
;
2091 sprintf(p
, "rx_queue_%u_csum_err", i
);
2092 p
+= ETH_GSTRING_LEN
;
2093 sprintf(p
, "rx_queue_%u_alloc_failed", i
);
2094 p
+= ETH_GSTRING_LEN
;
2096 /* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
2101 static const struct ethtool_ops igb_ethtool_ops
= {
2102 .get_settings
= igb_get_settings
,
2103 .set_settings
= igb_set_settings
,
2104 .get_drvinfo
= igb_get_drvinfo
,
2105 .get_regs_len
= igb_get_regs_len
,
2106 .get_regs
= igb_get_regs
,
2107 .get_wol
= igb_get_wol
,
2108 .set_wol
= igb_set_wol
,
2109 .get_msglevel
= igb_get_msglevel
,
2110 .set_msglevel
= igb_set_msglevel
,
2111 .nway_reset
= igb_nway_reset
,
2112 .get_link
= igb_get_link
,
2113 .get_eeprom_len
= igb_get_eeprom_len
,
2114 .get_eeprom
= igb_get_eeprom
,
2115 .set_eeprom
= igb_set_eeprom
,
2116 .get_ringparam
= igb_get_ringparam
,
2117 .set_ringparam
= igb_set_ringparam
,
2118 .get_pauseparam
= igb_get_pauseparam
,
2119 .set_pauseparam
= igb_set_pauseparam
,
2120 .get_rx_csum
= igb_get_rx_csum
,
2121 .set_rx_csum
= igb_set_rx_csum
,
2122 .get_tx_csum
= igb_get_tx_csum
,
2123 .set_tx_csum
= igb_set_tx_csum
,
2124 .get_sg
= ethtool_op_get_sg
,
2125 .set_sg
= ethtool_op_set_sg
,
2126 .get_tso
= ethtool_op_get_tso
,
2127 .set_tso
= igb_set_tso
,
2128 .self_test
= igb_diag_test
,
2129 .get_strings
= igb_get_strings
,
2130 .phys_id
= igb_phys_id
,
2131 .get_sset_count
= igb_get_sset_count
,
2132 .get_ethtool_stats
= igb_get_ethtool_stats
,
2133 .get_coalesce
= igb_get_coalesce
,
2134 .set_coalesce
= igb_set_coalesce
,
2137 void igb_set_ethtool_ops(struct net_device
*netdev
)
2139 SET_ETHTOOL_OPS(netdev
, &igb_ethtool_ops
);