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>
41 char stat_string
[ETH_GSTRING_LEN
];
46 #define IGB_STAT(m) FIELD_SIZEOF(struct igb_adapter, m), \
47 offsetof(struct igb_adapter, m)
48 static const struct igb_stats igb_gstrings_stats
[] = {
49 { "rx_packets", IGB_STAT(stats
.gprc
) },
50 { "tx_packets", IGB_STAT(stats
.gptc
) },
51 { "rx_bytes", IGB_STAT(stats
.gorc
) },
52 { "tx_bytes", IGB_STAT(stats
.gotc
) },
53 { "rx_broadcast", IGB_STAT(stats
.bprc
) },
54 { "tx_broadcast", IGB_STAT(stats
.bptc
) },
55 { "rx_multicast", IGB_STAT(stats
.mprc
) },
56 { "tx_multicast", IGB_STAT(stats
.mptc
) },
57 { "rx_errors", IGB_STAT(net_stats
.rx_errors
) },
58 { "tx_errors", IGB_STAT(net_stats
.tx_errors
) },
59 { "tx_dropped", IGB_STAT(net_stats
.tx_dropped
) },
60 { "multicast", IGB_STAT(stats
.mprc
) },
61 { "collisions", IGB_STAT(stats
.colc
) },
62 { "rx_length_errors", IGB_STAT(net_stats
.rx_length_errors
) },
63 { "rx_over_errors", IGB_STAT(net_stats
.rx_over_errors
) },
64 { "rx_crc_errors", IGB_STAT(stats
.crcerrs
) },
65 { "rx_frame_errors", IGB_STAT(net_stats
.rx_frame_errors
) },
66 { "rx_no_buffer_count", IGB_STAT(stats
.rnbc
) },
67 { "rx_queue_drop_packet_count", IGB_STAT(net_stats
.rx_fifo_errors
) },
68 { "rx_missed_errors", IGB_STAT(stats
.mpc
) },
69 { "tx_aborted_errors", IGB_STAT(stats
.ecol
) },
70 { "tx_carrier_errors", IGB_STAT(stats
.tncrs
) },
71 { "tx_fifo_errors", IGB_STAT(net_stats
.tx_fifo_errors
) },
72 { "tx_heartbeat_errors", IGB_STAT(net_stats
.tx_heartbeat_errors
) },
73 { "tx_window_errors", IGB_STAT(stats
.latecol
) },
74 { "tx_abort_late_coll", IGB_STAT(stats
.latecol
) },
75 { "tx_deferred_ok", IGB_STAT(stats
.dc
) },
76 { "tx_single_coll_ok", IGB_STAT(stats
.scc
) },
77 { "tx_multi_coll_ok", IGB_STAT(stats
.mcc
) },
78 { "tx_timeout_count", IGB_STAT(tx_timeout_count
) },
79 { "tx_restart_queue", IGB_STAT(restart_queue
) },
80 { "rx_long_length_errors", IGB_STAT(stats
.roc
) },
81 { "rx_short_length_errors", IGB_STAT(stats
.ruc
) },
82 { "rx_align_errors", IGB_STAT(stats
.algnerrc
) },
83 { "tx_tcp_seg_good", IGB_STAT(stats
.tsctc
) },
84 { "tx_tcp_seg_failed", IGB_STAT(stats
.tsctfc
) },
85 { "rx_flow_control_xon", IGB_STAT(stats
.xonrxc
) },
86 { "rx_flow_control_xoff", IGB_STAT(stats
.xoffrxc
) },
87 { "tx_flow_control_xon", IGB_STAT(stats
.xontxc
) },
88 { "tx_flow_control_xoff", IGB_STAT(stats
.xofftxc
) },
89 { "rx_long_byte_count", IGB_STAT(stats
.gorc
) },
90 { "rx_csum_offload_good", IGB_STAT(hw_csum_good
) },
91 { "rx_csum_offload_errors", IGB_STAT(hw_csum_err
) },
92 { "tx_dma_out_of_sync", IGB_STAT(stats
.doosync
) },
93 { "alloc_rx_buff_failed", IGB_STAT(alloc_rx_buff_failed
) },
94 { "tx_smbus", IGB_STAT(stats
.mgptc
) },
95 { "rx_smbus", IGB_STAT(stats
.mgprc
) },
96 { "dropped_smbus", IGB_STAT(stats
.mgpdc
) },
99 #define IGB_QUEUE_STATS_LEN \
100 (((((struct igb_adapter *)netdev_priv(netdev))->num_rx_queues)* \
101 (sizeof(struct igb_rx_queue_stats) / sizeof(u64))) + \
102 ((((struct igb_adapter *)netdev_priv(netdev))->num_tx_queues) * \
103 (sizeof(struct igb_tx_queue_stats) / sizeof(u64))))
104 #define IGB_GLOBAL_STATS_LEN \
105 sizeof(igb_gstrings_stats) / sizeof(struct igb_stats)
106 #define IGB_STATS_LEN (IGB_GLOBAL_STATS_LEN + IGB_QUEUE_STATS_LEN)
107 static const char igb_gstrings_test
[][ETH_GSTRING_LEN
] = {
108 "Register test (offline)", "Eeprom test (offline)",
109 "Interrupt test (offline)", "Loopback test (offline)",
110 "Link test (on/offline)"
112 #define IGB_TEST_LEN sizeof(igb_gstrings_test) / ETH_GSTRING_LEN
114 static int igb_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
116 struct igb_adapter
*adapter
= netdev_priv(netdev
);
117 struct e1000_hw
*hw
= &adapter
->hw
;
119 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
121 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
122 SUPPORTED_10baseT_Full
|
123 SUPPORTED_100baseT_Half
|
124 SUPPORTED_100baseT_Full
|
125 SUPPORTED_1000baseT_Full
|
128 ecmd
->advertising
= ADVERTISED_TP
;
130 if (hw
->mac
.autoneg
== 1) {
131 ecmd
->advertising
|= ADVERTISED_Autoneg
;
132 /* the e1000 autoneg seems to match ethtool nicely */
133 ecmd
->advertising
|= hw
->phy
.autoneg_advertised
;
136 ecmd
->port
= PORT_TP
;
137 ecmd
->phy_address
= hw
->phy
.addr
;
139 ecmd
->supported
= (SUPPORTED_1000baseT_Full
|
143 ecmd
->advertising
= (ADVERTISED_1000baseT_Full
|
147 ecmd
->port
= PORT_FIBRE
;
150 ecmd
->transceiver
= XCVR_INTERNAL
;
152 if (rd32(E1000_STATUS
) & E1000_STATUS_LU
) {
154 adapter
->hw
.mac
.ops
.get_speed_and_duplex(hw
,
155 &adapter
->link_speed
,
156 &adapter
->link_duplex
);
157 ecmd
->speed
= adapter
->link_speed
;
159 /* unfortunately FULL_DUPLEX != DUPLEX_FULL
160 * and HALF_DUPLEX != DUPLEX_HALF */
162 if (adapter
->link_duplex
== FULL_DUPLEX
)
163 ecmd
->duplex
= DUPLEX_FULL
;
165 ecmd
->duplex
= DUPLEX_HALF
;
171 ecmd
->autoneg
= hw
->mac
.autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
175 static int igb_set_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
177 struct igb_adapter
*adapter
= netdev_priv(netdev
);
178 struct e1000_hw
*hw
= &adapter
->hw
;
180 /* When SoL/IDER sessions are active, autoneg/speed/duplex
181 * cannot be changed */
182 if (igb_check_reset_block(hw
)) {
183 dev_err(&adapter
->pdev
->dev
, "Cannot change link "
184 "characteristics when SoL/IDER is active.\n");
188 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
191 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
193 hw
->phy
.autoneg_advertised
= ecmd
->advertising
|
196 ecmd
->advertising
= hw
->phy
.autoneg_advertised
;
197 if (adapter
->fc_autoneg
)
198 hw
->fc
.requested_mode
= e1000_fc_default
;
200 if (igb_set_spd_dplx(adapter
, ecmd
->speed
+ ecmd
->duplex
)) {
201 clear_bit(__IGB_RESETTING
, &adapter
->state
);
207 if (netif_running(adapter
->netdev
)) {
213 clear_bit(__IGB_RESETTING
, &adapter
->state
);
217 static void igb_get_pauseparam(struct net_device
*netdev
,
218 struct ethtool_pauseparam
*pause
)
220 struct igb_adapter
*adapter
= netdev_priv(netdev
);
221 struct e1000_hw
*hw
= &adapter
->hw
;
224 (adapter
->fc_autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
);
226 if (hw
->fc
.current_mode
== e1000_fc_rx_pause
)
228 else if (hw
->fc
.current_mode
== e1000_fc_tx_pause
)
230 else if (hw
->fc
.current_mode
== e1000_fc_full
) {
236 static int igb_set_pauseparam(struct net_device
*netdev
,
237 struct ethtool_pauseparam
*pause
)
239 struct igb_adapter
*adapter
= netdev_priv(netdev
);
240 struct e1000_hw
*hw
= &adapter
->hw
;
243 adapter
->fc_autoneg
= pause
->autoneg
;
245 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
248 if (adapter
->fc_autoneg
== AUTONEG_ENABLE
) {
249 hw
->fc
.requested_mode
= e1000_fc_default
;
250 if (netif_running(adapter
->netdev
)) {
256 if (pause
->rx_pause
&& pause
->tx_pause
)
257 hw
->fc
.requested_mode
= e1000_fc_full
;
258 else if (pause
->rx_pause
&& !pause
->tx_pause
)
259 hw
->fc
.requested_mode
= e1000_fc_rx_pause
;
260 else if (!pause
->rx_pause
&& pause
->tx_pause
)
261 hw
->fc
.requested_mode
= e1000_fc_tx_pause
;
262 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
263 hw
->fc
.requested_mode
= e1000_fc_none
;
265 hw
->fc
.current_mode
= hw
->fc
.requested_mode
;
267 retval
= ((hw
->phy
.media_type
== e1000_media_type_copper
) ?
268 igb_force_mac_fc(hw
) : igb_setup_link(hw
));
271 clear_bit(__IGB_RESETTING
, &adapter
->state
);
275 static u32
igb_get_rx_csum(struct net_device
*netdev
)
277 struct igb_adapter
*adapter
= netdev_priv(netdev
);
278 return !(adapter
->flags
& IGB_FLAG_RX_CSUM_DISABLED
);
281 static int igb_set_rx_csum(struct net_device
*netdev
, u32 data
)
283 struct igb_adapter
*adapter
= netdev_priv(netdev
);
286 adapter
->flags
&= ~IGB_FLAG_RX_CSUM_DISABLED
;
288 adapter
->flags
|= IGB_FLAG_RX_CSUM_DISABLED
;
293 static u32
igb_get_tx_csum(struct net_device
*netdev
)
295 return (netdev
->features
& NETIF_F_IP_CSUM
) != 0;
298 static int igb_set_tx_csum(struct net_device
*netdev
, u32 data
)
300 struct igb_adapter
*adapter
= netdev_priv(netdev
);
303 netdev
->features
|= (NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
);
304 if (adapter
->hw
.mac
.type
== e1000_82576
)
305 netdev
->features
|= NETIF_F_SCTP_CSUM
;
307 netdev
->features
&= ~(NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
314 static int igb_set_tso(struct net_device
*netdev
, u32 data
)
316 struct igb_adapter
*adapter
= netdev_priv(netdev
);
319 netdev
->features
|= NETIF_F_TSO
;
320 netdev
->features
|= NETIF_F_TSO6
;
322 netdev
->features
&= ~NETIF_F_TSO
;
323 netdev
->features
&= ~NETIF_F_TSO6
;
326 dev_info(&adapter
->pdev
->dev
, "TSO is %s\n",
327 data
? "Enabled" : "Disabled");
331 static u32
igb_get_msglevel(struct net_device
*netdev
)
333 struct igb_adapter
*adapter
= netdev_priv(netdev
);
334 return adapter
->msg_enable
;
337 static void igb_set_msglevel(struct net_device
*netdev
, u32 data
)
339 struct igb_adapter
*adapter
= netdev_priv(netdev
);
340 adapter
->msg_enable
= data
;
343 static int igb_get_regs_len(struct net_device
*netdev
)
345 #define IGB_REGS_LEN 551
346 return IGB_REGS_LEN
* sizeof(u32
);
349 static void igb_get_regs(struct net_device
*netdev
,
350 struct ethtool_regs
*regs
, void *p
)
352 struct igb_adapter
*adapter
= netdev_priv(netdev
);
353 struct e1000_hw
*hw
= &adapter
->hw
;
357 memset(p
, 0, IGB_REGS_LEN
* sizeof(u32
));
359 regs
->version
= (1 << 24) | (hw
->revision_id
<< 16) | hw
->device_id
;
361 /* General Registers */
362 regs_buff
[0] = rd32(E1000_CTRL
);
363 regs_buff
[1] = rd32(E1000_STATUS
);
364 regs_buff
[2] = rd32(E1000_CTRL_EXT
);
365 regs_buff
[3] = rd32(E1000_MDIC
);
366 regs_buff
[4] = rd32(E1000_SCTL
);
367 regs_buff
[5] = rd32(E1000_CONNSW
);
368 regs_buff
[6] = rd32(E1000_VET
);
369 regs_buff
[7] = rd32(E1000_LEDCTL
);
370 regs_buff
[8] = rd32(E1000_PBA
);
371 regs_buff
[9] = rd32(E1000_PBS
);
372 regs_buff
[10] = rd32(E1000_FRTIMER
);
373 regs_buff
[11] = rd32(E1000_TCPTIMER
);
376 regs_buff
[12] = rd32(E1000_EECD
);
379 /* Reading EICS for EICR because they read the
380 * same but EICS does not clear on read */
381 regs_buff
[13] = rd32(E1000_EICS
);
382 regs_buff
[14] = rd32(E1000_EICS
);
383 regs_buff
[15] = rd32(E1000_EIMS
);
384 regs_buff
[16] = rd32(E1000_EIMC
);
385 regs_buff
[17] = rd32(E1000_EIAC
);
386 regs_buff
[18] = rd32(E1000_EIAM
);
387 /* Reading ICS for ICR because they read the
388 * same but ICS does not clear on read */
389 regs_buff
[19] = rd32(E1000_ICS
);
390 regs_buff
[20] = rd32(E1000_ICS
);
391 regs_buff
[21] = rd32(E1000_IMS
);
392 regs_buff
[22] = rd32(E1000_IMC
);
393 regs_buff
[23] = rd32(E1000_IAC
);
394 regs_buff
[24] = rd32(E1000_IAM
);
395 regs_buff
[25] = rd32(E1000_IMIRVP
);
398 regs_buff
[26] = rd32(E1000_FCAL
);
399 regs_buff
[27] = rd32(E1000_FCAH
);
400 regs_buff
[28] = rd32(E1000_FCTTV
);
401 regs_buff
[29] = rd32(E1000_FCRTL
);
402 regs_buff
[30] = rd32(E1000_FCRTH
);
403 regs_buff
[31] = rd32(E1000_FCRTV
);
406 regs_buff
[32] = rd32(E1000_RCTL
);
407 regs_buff
[33] = rd32(E1000_RXCSUM
);
408 regs_buff
[34] = rd32(E1000_RLPML
);
409 regs_buff
[35] = rd32(E1000_RFCTL
);
410 regs_buff
[36] = rd32(E1000_MRQC
);
411 regs_buff
[37] = rd32(E1000_VT_CTL
);
414 regs_buff
[38] = rd32(E1000_TCTL
);
415 regs_buff
[39] = rd32(E1000_TCTL_EXT
);
416 regs_buff
[40] = rd32(E1000_TIPG
);
417 regs_buff
[41] = rd32(E1000_DTXCTL
);
420 regs_buff
[42] = rd32(E1000_WUC
);
421 regs_buff
[43] = rd32(E1000_WUFC
);
422 regs_buff
[44] = rd32(E1000_WUS
);
423 regs_buff
[45] = rd32(E1000_IPAV
);
424 regs_buff
[46] = rd32(E1000_WUPL
);
427 regs_buff
[47] = rd32(E1000_PCS_CFG0
);
428 regs_buff
[48] = rd32(E1000_PCS_LCTL
);
429 regs_buff
[49] = rd32(E1000_PCS_LSTAT
);
430 regs_buff
[50] = rd32(E1000_PCS_ANADV
);
431 regs_buff
[51] = rd32(E1000_PCS_LPAB
);
432 regs_buff
[52] = rd32(E1000_PCS_NPTX
);
433 regs_buff
[53] = rd32(E1000_PCS_LPABNP
);
436 regs_buff
[54] = adapter
->stats
.crcerrs
;
437 regs_buff
[55] = adapter
->stats
.algnerrc
;
438 regs_buff
[56] = adapter
->stats
.symerrs
;
439 regs_buff
[57] = adapter
->stats
.rxerrc
;
440 regs_buff
[58] = adapter
->stats
.mpc
;
441 regs_buff
[59] = adapter
->stats
.scc
;
442 regs_buff
[60] = adapter
->stats
.ecol
;
443 regs_buff
[61] = adapter
->stats
.mcc
;
444 regs_buff
[62] = adapter
->stats
.latecol
;
445 regs_buff
[63] = adapter
->stats
.colc
;
446 regs_buff
[64] = adapter
->stats
.dc
;
447 regs_buff
[65] = adapter
->stats
.tncrs
;
448 regs_buff
[66] = adapter
->stats
.sec
;
449 regs_buff
[67] = adapter
->stats
.htdpmc
;
450 regs_buff
[68] = adapter
->stats
.rlec
;
451 regs_buff
[69] = adapter
->stats
.xonrxc
;
452 regs_buff
[70] = adapter
->stats
.xontxc
;
453 regs_buff
[71] = adapter
->stats
.xoffrxc
;
454 regs_buff
[72] = adapter
->stats
.xofftxc
;
455 regs_buff
[73] = adapter
->stats
.fcruc
;
456 regs_buff
[74] = adapter
->stats
.prc64
;
457 regs_buff
[75] = adapter
->stats
.prc127
;
458 regs_buff
[76] = adapter
->stats
.prc255
;
459 regs_buff
[77] = adapter
->stats
.prc511
;
460 regs_buff
[78] = adapter
->stats
.prc1023
;
461 regs_buff
[79] = adapter
->stats
.prc1522
;
462 regs_buff
[80] = adapter
->stats
.gprc
;
463 regs_buff
[81] = adapter
->stats
.bprc
;
464 regs_buff
[82] = adapter
->stats
.mprc
;
465 regs_buff
[83] = adapter
->stats
.gptc
;
466 regs_buff
[84] = adapter
->stats
.gorc
;
467 regs_buff
[86] = adapter
->stats
.gotc
;
468 regs_buff
[88] = adapter
->stats
.rnbc
;
469 regs_buff
[89] = adapter
->stats
.ruc
;
470 regs_buff
[90] = adapter
->stats
.rfc
;
471 regs_buff
[91] = adapter
->stats
.roc
;
472 regs_buff
[92] = adapter
->stats
.rjc
;
473 regs_buff
[93] = adapter
->stats
.mgprc
;
474 regs_buff
[94] = adapter
->stats
.mgpdc
;
475 regs_buff
[95] = adapter
->stats
.mgptc
;
476 regs_buff
[96] = adapter
->stats
.tor
;
477 regs_buff
[98] = adapter
->stats
.tot
;
478 regs_buff
[100] = adapter
->stats
.tpr
;
479 regs_buff
[101] = adapter
->stats
.tpt
;
480 regs_buff
[102] = adapter
->stats
.ptc64
;
481 regs_buff
[103] = adapter
->stats
.ptc127
;
482 regs_buff
[104] = adapter
->stats
.ptc255
;
483 regs_buff
[105] = adapter
->stats
.ptc511
;
484 regs_buff
[106] = adapter
->stats
.ptc1023
;
485 regs_buff
[107] = adapter
->stats
.ptc1522
;
486 regs_buff
[108] = adapter
->stats
.mptc
;
487 regs_buff
[109] = adapter
->stats
.bptc
;
488 regs_buff
[110] = adapter
->stats
.tsctc
;
489 regs_buff
[111] = adapter
->stats
.iac
;
490 regs_buff
[112] = adapter
->stats
.rpthc
;
491 regs_buff
[113] = adapter
->stats
.hgptc
;
492 regs_buff
[114] = adapter
->stats
.hgorc
;
493 regs_buff
[116] = adapter
->stats
.hgotc
;
494 regs_buff
[118] = adapter
->stats
.lenerrs
;
495 regs_buff
[119] = adapter
->stats
.scvpc
;
496 regs_buff
[120] = adapter
->stats
.hrmpc
;
498 /* These should probably be added to e1000_regs.h instead */
499 #define E1000_PSRTYPE_REG(_i) (0x05480 + ((_i) * 4))
500 #define E1000_IP4AT_REG(_i) (0x05840 + ((_i) * 8))
501 #define E1000_IP6AT_REG(_i) (0x05880 + ((_i) * 4))
502 #define E1000_WUPM_REG(_i) (0x05A00 + ((_i) * 4))
503 #define E1000_FFMT_REG(_i) (0x09000 + ((_i) * 8))
504 #define E1000_FFVT_REG(_i) (0x09800 + ((_i) * 8))
505 #define E1000_FFLT_REG(_i) (0x05F00 + ((_i) * 8))
507 for (i
= 0; i
< 4; i
++)
508 regs_buff
[121 + i
] = rd32(E1000_SRRCTL(i
));
509 for (i
= 0; i
< 4; i
++)
510 regs_buff
[125 + i
] = rd32(E1000_PSRTYPE_REG(i
));
511 for (i
= 0; i
< 4; i
++)
512 regs_buff
[129 + i
] = rd32(E1000_RDBAL(i
));
513 for (i
= 0; i
< 4; i
++)
514 regs_buff
[133 + i
] = rd32(E1000_RDBAH(i
));
515 for (i
= 0; i
< 4; i
++)
516 regs_buff
[137 + i
] = rd32(E1000_RDLEN(i
));
517 for (i
= 0; i
< 4; i
++)
518 regs_buff
[141 + i
] = rd32(E1000_RDH(i
));
519 for (i
= 0; i
< 4; i
++)
520 regs_buff
[145 + i
] = rd32(E1000_RDT(i
));
521 for (i
= 0; i
< 4; i
++)
522 regs_buff
[149 + i
] = rd32(E1000_RXDCTL(i
));
524 for (i
= 0; i
< 10; i
++)
525 regs_buff
[153 + i
] = rd32(E1000_EITR(i
));
526 for (i
= 0; i
< 8; i
++)
527 regs_buff
[163 + i
] = rd32(E1000_IMIR(i
));
528 for (i
= 0; i
< 8; i
++)
529 regs_buff
[171 + i
] = rd32(E1000_IMIREXT(i
));
530 for (i
= 0; i
< 16; i
++)
531 regs_buff
[179 + i
] = rd32(E1000_RAL(i
));
532 for (i
= 0; i
< 16; i
++)
533 regs_buff
[195 + i
] = rd32(E1000_RAH(i
));
535 for (i
= 0; i
< 4; i
++)
536 regs_buff
[211 + i
] = rd32(E1000_TDBAL(i
));
537 for (i
= 0; i
< 4; i
++)
538 regs_buff
[215 + i
] = rd32(E1000_TDBAH(i
));
539 for (i
= 0; i
< 4; i
++)
540 regs_buff
[219 + i
] = rd32(E1000_TDLEN(i
));
541 for (i
= 0; i
< 4; i
++)
542 regs_buff
[223 + i
] = rd32(E1000_TDH(i
));
543 for (i
= 0; i
< 4; i
++)
544 regs_buff
[227 + i
] = rd32(E1000_TDT(i
));
545 for (i
= 0; i
< 4; i
++)
546 regs_buff
[231 + i
] = rd32(E1000_TXDCTL(i
));
547 for (i
= 0; i
< 4; i
++)
548 regs_buff
[235 + i
] = rd32(E1000_TDWBAL(i
));
549 for (i
= 0; i
< 4; i
++)
550 regs_buff
[239 + i
] = rd32(E1000_TDWBAH(i
));
551 for (i
= 0; i
< 4; i
++)
552 regs_buff
[243 + i
] = rd32(E1000_DCA_TXCTRL(i
));
554 for (i
= 0; i
< 4; i
++)
555 regs_buff
[247 + i
] = rd32(E1000_IP4AT_REG(i
));
556 for (i
= 0; i
< 4; i
++)
557 regs_buff
[251 + i
] = rd32(E1000_IP6AT_REG(i
));
558 for (i
= 0; i
< 32; i
++)
559 regs_buff
[255 + i
] = rd32(E1000_WUPM_REG(i
));
560 for (i
= 0; i
< 128; i
++)
561 regs_buff
[287 + i
] = rd32(E1000_FFMT_REG(i
));
562 for (i
= 0; i
< 128; i
++)
563 regs_buff
[415 + i
] = rd32(E1000_FFVT_REG(i
));
564 for (i
= 0; i
< 4; i
++)
565 regs_buff
[543 + i
] = rd32(E1000_FFLT_REG(i
));
567 regs_buff
[547] = rd32(E1000_TDFH
);
568 regs_buff
[548] = rd32(E1000_TDFT
);
569 regs_buff
[549] = rd32(E1000_TDFHS
);
570 regs_buff
[550] = rd32(E1000_TDFPC
);
574 static int igb_get_eeprom_len(struct net_device
*netdev
)
576 struct igb_adapter
*adapter
= netdev_priv(netdev
);
577 return adapter
->hw
.nvm
.word_size
* 2;
580 static int igb_get_eeprom(struct net_device
*netdev
,
581 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
583 struct igb_adapter
*adapter
= netdev_priv(netdev
);
584 struct e1000_hw
*hw
= &adapter
->hw
;
586 int first_word
, last_word
;
590 if (eeprom
->len
== 0)
593 eeprom
->magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
595 first_word
= eeprom
->offset
>> 1;
596 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
598 eeprom_buff
= kmalloc(sizeof(u16
) *
599 (last_word
- first_word
+ 1), GFP_KERNEL
);
603 if (hw
->nvm
.type
== e1000_nvm_eeprom_spi
)
604 ret_val
= hw
->nvm
.ops
.read(hw
, first_word
,
605 last_word
- first_word
+ 1,
608 for (i
= 0; i
< last_word
- first_word
+ 1; i
++) {
609 ret_val
= hw
->nvm
.ops
.read(hw
, first_word
+ i
, 1,
616 /* Device's eeprom is always little-endian, word addressable */
617 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
618 le16_to_cpus(&eeprom_buff
[i
]);
620 memcpy(bytes
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 1),
627 static int igb_set_eeprom(struct net_device
*netdev
,
628 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
630 struct igb_adapter
*adapter
= netdev_priv(netdev
);
631 struct e1000_hw
*hw
= &adapter
->hw
;
634 int max_len
, first_word
, last_word
, ret_val
= 0;
637 if (eeprom
->len
== 0)
640 if (eeprom
->magic
!= (hw
->vendor_id
| (hw
->device_id
<< 16)))
643 max_len
= hw
->nvm
.word_size
* 2;
645 first_word
= eeprom
->offset
>> 1;
646 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
647 eeprom_buff
= kmalloc(max_len
, GFP_KERNEL
);
651 ptr
= (void *)eeprom_buff
;
653 if (eeprom
->offset
& 1) {
654 /* need read/modify/write of first changed EEPROM word */
655 /* only the second byte of the word is being modified */
656 ret_val
= hw
->nvm
.ops
.read(hw
, first_word
, 1,
660 if (((eeprom
->offset
+ eeprom
->len
) & 1) && (ret_val
== 0)) {
661 /* need read/modify/write of last changed EEPROM word */
662 /* only the first byte of the word is being modified */
663 ret_val
= hw
->nvm
.ops
.read(hw
, last_word
, 1,
664 &eeprom_buff
[last_word
- first_word
]);
667 /* Device's eeprom is always little-endian, word addressable */
668 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
669 le16_to_cpus(&eeprom_buff
[i
]);
671 memcpy(ptr
, bytes
, eeprom
->len
);
673 for (i
= 0; i
< last_word
- first_word
+ 1; i
++)
674 eeprom_buff
[i
] = cpu_to_le16(eeprom_buff
[i
]);
676 ret_val
= hw
->nvm
.ops
.write(hw
, first_word
,
677 last_word
- first_word
+ 1, eeprom_buff
);
679 /* Update the checksum over the first part of the EEPROM if needed
680 * and flush shadow RAM for 82573 controllers */
681 if ((ret_val
== 0) && ((first_word
<= NVM_CHECKSUM_REG
)))
682 igb_update_nvm_checksum(hw
);
688 static void igb_get_drvinfo(struct net_device
*netdev
,
689 struct ethtool_drvinfo
*drvinfo
)
691 struct igb_adapter
*adapter
= netdev_priv(netdev
);
692 char firmware_version
[32];
695 strncpy(drvinfo
->driver
, igb_driver_name
, 32);
696 strncpy(drvinfo
->version
, igb_driver_version
, 32);
698 /* EEPROM image version # is reported as firmware version # for
699 * 82575 controllers */
700 adapter
->hw
.nvm
.ops
.read(&adapter
->hw
, 5, 1, &eeprom_data
);
701 sprintf(firmware_version
, "%d.%d-%d",
702 (eeprom_data
& 0xF000) >> 12,
703 (eeprom_data
& 0x0FF0) >> 4,
704 eeprom_data
& 0x000F);
706 strncpy(drvinfo
->fw_version
, firmware_version
, 32);
707 strncpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
), 32);
708 drvinfo
->n_stats
= IGB_STATS_LEN
;
709 drvinfo
->testinfo_len
= IGB_TEST_LEN
;
710 drvinfo
->regdump_len
= igb_get_regs_len(netdev
);
711 drvinfo
->eedump_len
= igb_get_eeprom_len(netdev
);
714 static void igb_get_ringparam(struct net_device
*netdev
,
715 struct ethtool_ringparam
*ring
)
717 struct igb_adapter
*adapter
= netdev_priv(netdev
);
719 ring
->rx_max_pending
= IGB_MAX_RXD
;
720 ring
->tx_max_pending
= IGB_MAX_TXD
;
721 ring
->rx_mini_max_pending
= 0;
722 ring
->rx_jumbo_max_pending
= 0;
723 ring
->rx_pending
= adapter
->rx_ring_count
;
724 ring
->tx_pending
= adapter
->tx_ring_count
;
725 ring
->rx_mini_pending
= 0;
726 ring
->rx_jumbo_pending
= 0;
729 static int igb_set_ringparam(struct net_device
*netdev
,
730 struct ethtool_ringparam
*ring
)
732 struct igb_adapter
*adapter
= netdev_priv(netdev
);
733 struct igb_ring
*temp_ring
;
735 u32 new_rx_count
, new_tx_count
;
737 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
740 new_rx_count
= max(ring
->rx_pending
, (u32
)IGB_MIN_RXD
);
741 new_rx_count
= min(new_rx_count
, (u32
)IGB_MAX_RXD
);
742 new_rx_count
= ALIGN(new_rx_count
, REQ_RX_DESCRIPTOR_MULTIPLE
);
744 new_tx_count
= max(ring
->tx_pending
, (u32
)IGB_MIN_TXD
);
745 new_tx_count
= min(new_tx_count
, (u32
)IGB_MAX_TXD
);
746 new_tx_count
= ALIGN(new_tx_count
, REQ_TX_DESCRIPTOR_MULTIPLE
);
748 if ((new_tx_count
== adapter
->tx_ring_count
) &&
749 (new_rx_count
== adapter
->rx_ring_count
)) {
754 if (adapter
->num_tx_queues
> adapter
->num_rx_queues
)
755 temp_ring
= vmalloc(adapter
->num_tx_queues
* sizeof(struct igb_ring
));
757 temp_ring
= vmalloc(adapter
->num_rx_queues
* sizeof(struct igb_ring
));
761 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
764 if (netif_running(adapter
->netdev
))
768 * We can't just free everything and then setup again,
769 * because the ISRs in MSI-X mode get passed pointers
770 * to the tx and rx ring structs.
772 if (new_tx_count
!= adapter
->tx_ring_count
) {
773 memcpy(temp_ring
, adapter
->tx_ring
,
774 adapter
->num_tx_queues
* sizeof(struct igb_ring
));
776 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
777 temp_ring
[i
].count
= new_tx_count
;
778 err
= igb_setup_tx_resources(adapter
, &temp_ring
[i
]);
782 igb_free_tx_resources(&temp_ring
[i
]);
788 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
789 igb_free_tx_resources(&adapter
->tx_ring
[i
]);
791 memcpy(adapter
->tx_ring
, temp_ring
,
792 adapter
->num_tx_queues
* sizeof(struct igb_ring
));
794 adapter
->tx_ring_count
= new_tx_count
;
797 if (new_rx_count
!= adapter
->rx_ring
->count
) {
798 memcpy(temp_ring
, adapter
->rx_ring
,
799 adapter
->num_rx_queues
* sizeof(struct igb_ring
));
801 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
802 temp_ring
[i
].count
= new_rx_count
;
803 err
= igb_setup_rx_resources(adapter
, &temp_ring
[i
]);
807 igb_free_rx_resources(&temp_ring
[i
]);
814 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
815 igb_free_rx_resources(&adapter
->rx_ring
[i
]);
817 memcpy(adapter
->rx_ring
, temp_ring
,
818 adapter
->num_rx_queues
* sizeof(struct igb_ring
));
820 adapter
->rx_ring_count
= new_rx_count
;
825 if (netif_running(adapter
->netdev
))
828 clear_bit(__IGB_RESETTING
, &adapter
->state
);
833 /* ethtool register test data */
834 struct igb_reg_test
{
843 /* In the hardware, registers are laid out either singly, in arrays
844 * spaced 0x100 bytes apart, or in contiguous tables. We assume
845 * most tests take place on arrays or single registers (handled
846 * as a single-element array) and special-case the tables.
847 * Table tests are always pattern tests.
849 * We also make provision for some required setup steps by specifying
850 * registers to be written without any read-back testing.
853 #define PATTERN_TEST 1
854 #define SET_READ_TEST 2
855 #define WRITE_NO_TEST 3
856 #define TABLE32_TEST 4
857 #define TABLE64_TEST_LO 5
858 #define TABLE64_TEST_HI 6
861 static struct igb_reg_test reg_test_82576
[] = {
862 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
863 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
864 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
865 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
866 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
867 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
868 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
869 { E1000_RDBAL(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
870 { E1000_RDBAH(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
871 { E1000_RDLEN(4), 0x40, 12, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
872 /* Enable all RX queues before testing. */
873 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, E1000_RXDCTL_QUEUE_ENABLE
},
874 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST
, 0, E1000_RXDCTL_QUEUE_ENABLE
},
875 /* RDH is read-only for 82576, only test RDT. */
876 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
877 { E1000_RDT(4), 0x40, 12, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
878 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, 0 },
879 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST
, 0, 0 },
880 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
881 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
882 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
883 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
884 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
885 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
886 { E1000_TDBAL(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
887 { E1000_TDBAH(4), 0x40, 12, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
888 { E1000_TDLEN(4), 0x40, 12, PATTERN_TEST
, 0x000FFFF0, 0x000FFFFF },
889 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
890 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0x003FFFFB },
891 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB0FE, 0xFFFFFFFF },
892 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
893 { E1000_RA
, 0, 16, TABLE64_TEST_LO
, 0xFFFFFFFF, 0xFFFFFFFF },
894 { E1000_RA
, 0, 16, TABLE64_TEST_HI
, 0x83FFFFFF, 0xFFFFFFFF },
895 { E1000_RA2
, 0, 8, TABLE64_TEST_LO
, 0xFFFFFFFF, 0xFFFFFFFF },
896 { E1000_RA2
, 0, 8, TABLE64_TEST_HI
, 0x83FFFFFF, 0xFFFFFFFF },
897 { E1000_MTA
, 0, 128,TABLE32_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
901 /* 82575 register test */
902 static struct igb_reg_test reg_test_82575
[] = {
903 { E1000_FCAL
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
904 { E1000_FCAH
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
905 { E1000_FCT
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0xFFFFFFFF },
906 { E1000_VET
, 0x100, 1, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
907 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
908 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
909 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
910 /* Enable all four RX queues before testing. */
911 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, E1000_RXDCTL_QUEUE_ENABLE
},
912 /* RDH is read-only for 82575, only test RDT. */
913 { E1000_RDT(0), 0x100, 4, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
914 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST
, 0, 0 },
915 { E1000_FCRTH
, 0x100, 1, PATTERN_TEST
, 0x0000FFF0, 0x0000FFF0 },
916 { E1000_FCTTV
, 0x100, 1, PATTERN_TEST
, 0x0000FFFF, 0x0000FFFF },
917 { E1000_TIPG
, 0x100, 1, PATTERN_TEST
, 0x3FFFFFFF, 0x3FFFFFFF },
918 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFF80, 0xFFFFFFFF },
919 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
920 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST
, 0x000FFF80, 0x000FFFFF },
921 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
922 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB3FE, 0x003FFFFB },
923 { E1000_RCTL
, 0x100, 1, SET_READ_TEST
, 0x04CFB3FE, 0xFFFFFFFF },
924 { E1000_TCTL
, 0x100, 1, SET_READ_TEST
, 0xFFFFFFFF, 0x00000000 },
925 { E1000_TXCW
, 0x100, 1, PATTERN_TEST
, 0xC000FFFF, 0x0000FFFF },
926 { E1000_RA
, 0, 16, TABLE64_TEST_LO
, 0xFFFFFFFF, 0xFFFFFFFF },
927 { E1000_RA
, 0, 16, TABLE64_TEST_HI
, 0x800FFFFF, 0xFFFFFFFF },
928 { E1000_MTA
, 0, 128, TABLE32_TEST
, 0xFFFFFFFF, 0xFFFFFFFF },
932 static bool reg_pattern_test(struct igb_adapter
*adapter
, u64
*data
,
933 int reg
, u32 mask
, u32 write
)
935 struct e1000_hw
*hw
= &adapter
->hw
;
938 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
939 for (pat
= 0; pat
< ARRAY_SIZE(_test
); pat
++) {
940 wr32(reg
, (_test
[pat
] & write
));
942 if (val
!= (_test
[pat
] & write
& mask
)) {
943 dev_err(&adapter
->pdev
->dev
, "pattern test reg %04X "
944 "failed: got 0x%08X expected 0x%08X\n",
945 reg
, val
, (_test
[pat
] & write
& mask
));
953 static bool reg_set_and_check(struct igb_adapter
*adapter
, u64
*data
,
954 int reg
, u32 mask
, u32 write
)
956 struct e1000_hw
*hw
= &adapter
->hw
;
958 wr32(reg
, write
& mask
);
960 if ((write
& mask
) != (val
& mask
)) {
961 dev_err(&adapter
->pdev
->dev
, "set/check reg %04X test failed:"
962 " got 0x%08X expected 0x%08X\n", reg
,
963 (val
& mask
), (write
& mask
));
970 #define REG_PATTERN_TEST(reg, mask, write) \
972 if (reg_pattern_test(adapter, data, reg, mask, write)) \
976 #define REG_SET_AND_CHECK(reg, mask, write) \
978 if (reg_set_and_check(adapter, data, reg, mask, write)) \
982 static int igb_reg_test(struct igb_adapter
*adapter
, u64
*data
)
984 struct e1000_hw
*hw
= &adapter
->hw
;
985 struct igb_reg_test
*test
;
986 u32 value
, before
, after
;
991 switch (adapter
->hw
.mac
.type
) {
993 test
= reg_test_82576
;
996 test
= reg_test_82575
;
1000 /* Because the status register is such a special case,
1001 * we handle it separately from the rest of the register
1002 * tests. Some bits are read-only, some toggle, and some
1003 * are writable on newer MACs.
1005 before
= rd32(E1000_STATUS
);
1006 value
= (rd32(E1000_STATUS
) & toggle
);
1007 wr32(E1000_STATUS
, toggle
);
1008 after
= rd32(E1000_STATUS
) & toggle
;
1009 if (value
!= after
) {
1010 dev_err(&adapter
->pdev
->dev
, "failed STATUS register test "
1011 "got: 0x%08X expected: 0x%08X\n", after
, value
);
1015 /* restore previous status */
1016 wr32(E1000_STATUS
, before
);
1018 /* Perform the remainder of the register test, looping through
1019 * the test table until we either fail or reach the null entry.
1022 for (i
= 0; i
< test
->array_len
; i
++) {
1023 switch (test
->test_type
) {
1025 REG_PATTERN_TEST(test
->reg
+
1026 (i
* test
->reg_offset
),
1031 REG_SET_AND_CHECK(test
->reg
+
1032 (i
* test
->reg_offset
),
1038 (adapter
->hw
.hw_addr
+ test
->reg
)
1039 + (i
* test
->reg_offset
));
1042 REG_PATTERN_TEST(test
->reg
+ (i
* 4),
1046 case TABLE64_TEST_LO
:
1047 REG_PATTERN_TEST(test
->reg
+ (i
* 8),
1051 case TABLE64_TEST_HI
:
1052 REG_PATTERN_TEST((test
->reg
+ 4) + (i
* 8),
1065 static int igb_eeprom_test(struct igb_adapter
*adapter
, u64
*data
)
1072 /* Read and add up the contents of the EEPROM */
1073 for (i
= 0; i
< (NVM_CHECKSUM_REG
+ 1); i
++) {
1074 if ((adapter
->hw
.nvm
.ops
.read(&adapter
->hw
, i
, 1, &temp
))
1082 /* If Checksum is not Correct return error else test passed */
1083 if ((checksum
!= (u16
) NVM_SUM
) && !(*data
))
1089 static irqreturn_t
igb_test_intr(int irq
, void *data
)
1091 struct net_device
*netdev
= (struct net_device
*) data
;
1092 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1093 struct e1000_hw
*hw
= &adapter
->hw
;
1095 adapter
->test_icr
|= rd32(E1000_ICR
);
1100 static int igb_intr_test(struct igb_adapter
*adapter
, u64
*data
)
1102 struct e1000_hw
*hw
= &adapter
->hw
;
1103 struct net_device
*netdev
= adapter
->netdev
;
1104 u32 mask
, ics_mask
, i
= 0, shared_int
= true;
1105 u32 irq
= adapter
->pdev
->irq
;
1109 /* Hook up test interrupt handler just for this test */
1110 if (adapter
->msix_entries
)
1111 /* NOTE: we don't test MSI-X interrupts here, yet */
1114 if (adapter
->flags
& IGB_FLAG_HAS_MSI
) {
1116 if (request_irq(irq
, &igb_test_intr
, 0, netdev
->name
, netdev
)) {
1120 } else if (!request_irq(irq
, &igb_test_intr
, IRQF_PROBE_SHARED
,
1121 netdev
->name
, netdev
)) {
1123 } else if (request_irq(irq
, &igb_test_intr
, IRQF_SHARED
,
1124 netdev
->name
, netdev
)) {
1128 dev_info(&adapter
->pdev
->dev
, "testing %s interrupt\n",
1129 (shared_int
? "shared" : "unshared"));
1130 /* Disable all the interrupts */
1131 wr32(E1000_IMC
, 0xFFFFFFFF);
1134 /* Define all writable bits for ICS */
1135 switch(hw
->mac
.type
) {
1137 ics_mask
= 0x37F47EDD;
1140 ics_mask
= 0x77D4FBFD;
1143 ics_mask
= 0x7FFFFFFF;
1147 /* Test each interrupt */
1148 for (; i
< 31; i
++) {
1149 /* Interrupt to test */
1152 if (!(mask
& ics_mask
))
1156 /* Disable the interrupt to be reported in
1157 * the cause register and then force the same
1158 * interrupt and see if one gets posted. If
1159 * an interrupt was posted to the bus, the
1162 adapter
->test_icr
= 0;
1164 /* Flush any pending interrupts */
1165 wr32(E1000_ICR
, ~0);
1167 wr32(E1000_IMC
, mask
);
1168 wr32(E1000_ICS
, mask
);
1171 if (adapter
->test_icr
& mask
) {
1177 /* Enable the interrupt to be reported in
1178 * the cause register and then force the same
1179 * interrupt and see if one gets posted. If
1180 * an interrupt was not posted to the bus, the
1183 adapter
->test_icr
= 0;
1185 /* Flush any pending interrupts */
1186 wr32(E1000_ICR
, ~0);
1188 wr32(E1000_IMS
, mask
);
1189 wr32(E1000_ICS
, mask
);
1192 if (!(adapter
->test_icr
& mask
)) {
1198 /* Disable the other interrupts to be reported in
1199 * the cause register and then force the other
1200 * interrupts and see if any get posted. If
1201 * an interrupt was posted to the bus, the
1204 adapter
->test_icr
= 0;
1206 /* Flush any pending interrupts */
1207 wr32(E1000_ICR
, ~0);
1209 wr32(E1000_IMC
, ~mask
);
1210 wr32(E1000_ICS
, ~mask
);
1213 if (adapter
->test_icr
& mask
) {
1220 /* Disable all the interrupts */
1221 wr32(E1000_IMC
, ~0);
1224 /* Unhook test interrupt handler */
1225 free_irq(irq
, netdev
);
1230 static void igb_free_desc_rings(struct igb_adapter
*adapter
)
1232 struct igb_ring
*tx_ring
= &adapter
->test_tx_ring
;
1233 struct igb_ring
*rx_ring
= &adapter
->test_rx_ring
;
1234 struct pci_dev
*pdev
= adapter
->pdev
;
1237 if (tx_ring
->desc
&& tx_ring
->buffer_info
) {
1238 for (i
= 0; i
< tx_ring
->count
; i
++) {
1239 struct igb_buffer
*buf
= &(tx_ring
->buffer_info
[i
]);
1241 pci_unmap_single(pdev
, buf
->dma
, buf
->length
,
1244 dev_kfree_skb(buf
->skb
);
1248 if (rx_ring
->desc
&& rx_ring
->buffer_info
) {
1249 for (i
= 0; i
< rx_ring
->count
; i
++) {
1250 struct igb_buffer
*buf
= &(rx_ring
->buffer_info
[i
]);
1252 pci_unmap_single(pdev
, buf
->dma
,
1254 PCI_DMA_FROMDEVICE
);
1256 dev_kfree_skb(buf
->skb
);
1260 if (tx_ring
->desc
) {
1261 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
,
1263 tx_ring
->desc
= NULL
;
1265 if (rx_ring
->desc
) {
1266 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
,
1268 rx_ring
->desc
= NULL
;
1271 kfree(tx_ring
->buffer_info
);
1272 tx_ring
->buffer_info
= NULL
;
1273 kfree(rx_ring
->buffer_info
);
1274 rx_ring
->buffer_info
= NULL
;
1279 static int igb_setup_desc_rings(struct igb_adapter
*adapter
)
1281 struct e1000_hw
*hw
= &adapter
->hw
;
1282 struct igb_ring
*tx_ring
= &adapter
->test_tx_ring
;
1283 struct igb_ring
*rx_ring
= &adapter
->test_rx_ring
;
1284 struct pci_dev
*pdev
= adapter
->pdev
;
1285 struct igb_buffer
*buffer_info
;
1289 /* Setup Tx descriptor ring and Tx buffers */
1291 if (!tx_ring
->count
)
1292 tx_ring
->count
= IGB_DEFAULT_TXD
;
1294 tx_ring
->buffer_info
= kcalloc(tx_ring
->count
,
1295 sizeof(struct igb_buffer
),
1297 if (!tx_ring
->buffer_info
) {
1302 tx_ring
->size
= tx_ring
->count
* sizeof(union e1000_adv_tx_desc
);
1303 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1304 tx_ring
->desc
= pci_alloc_consistent(pdev
, tx_ring
->size
,
1306 if (!tx_ring
->desc
) {
1310 tx_ring
->next_to_use
= tx_ring
->next_to_clean
= 0;
1312 wr32(E1000_TDBAL(0),
1313 ((u64
) tx_ring
->dma
& 0x00000000FFFFFFFF));
1314 wr32(E1000_TDBAH(0), ((u64
) tx_ring
->dma
>> 32));
1315 wr32(E1000_TDLEN(0),
1316 tx_ring
->count
* sizeof(union e1000_adv_tx_desc
));
1317 wr32(E1000_TDH(0), 0);
1318 wr32(E1000_TDT(0), 0);
1320 E1000_TCTL_PSP
| E1000_TCTL_EN
|
1321 E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
|
1322 E1000_COLLISION_DISTANCE
<< E1000_COLD_SHIFT
);
1324 for (i
= 0; i
< tx_ring
->count
; i
++) {
1325 union e1000_adv_tx_desc
*tx_desc
;
1326 struct sk_buff
*skb
;
1327 unsigned int size
= 1024;
1329 tx_desc
= E1000_TX_DESC_ADV(*tx_ring
, i
);
1330 skb
= alloc_skb(size
, GFP_KERNEL
);
1336 buffer_info
= &tx_ring
->buffer_info
[i
];
1337 buffer_info
->skb
= skb
;
1338 buffer_info
->length
= skb
->len
;
1339 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
, skb
->len
,
1341 tx_desc
->read
.buffer_addr
= cpu_to_le64(buffer_info
->dma
);
1342 tx_desc
->read
.olinfo_status
= cpu_to_le32(skb
->len
) <<
1343 E1000_ADVTXD_PAYLEN_SHIFT
;
1344 tx_desc
->read
.cmd_type_len
= cpu_to_le32(skb
->len
);
1345 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(E1000_TXD_CMD_EOP
|
1346 E1000_TXD_CMD_IFCS
|
1348 E1000_ADVTXD_DTYP_DATA
|
1349 E1000_ADVTXD_DCMD_DEXT
);
1352 /* Setup Rx descriptor ring and Rx buffers */
1354 if (!rx_ring
->count
)
1355 rx_ring
->count
= IGB_DEFAULT_RXD
;
1357 rx_ring
->buffer_info
= kcalloc(rx_ring
->count
,
1358 sizeof(struct igb_buffer
),
1360 if (!rx_ring
->buffer_info
) {
1365 rx_ring
->size
= rx_ring
->count
* sizeof(union e1000_adv_rx_desc
);
1366 rx_ring
->desc
= pci_alloc_consistent(pdev
, rx_ring
->size
,
1368 if (!rx_ring
->desc
) {
1372 rx_ring
->next_to_use
= rx_ring
->next_to_clean
= 0;
1374 rctl
= rd32(E1000_RCTL
);
1375 wr32(E1000_RCTL
, rctl
& ~E1000_RCTL_EN
);
1376 wr32(E1000_RDBAL(0),
1377 ((u64
) rx_ring
->dma
& 0xFFFFFFFF));
1378 wr32(E1000_RDBAH(0),
1379 ((u64
) rx_ring
->dma
>> 32));
1380 wr32(E1000_RDLEN(0), rx_ring
->size
);
1381 wr32(E1000_RDH(0), 0);
1382 wr32(E1000_RDT(0), 0);
1383 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
1384 rctl
= E1000_RCTL_EN
| E1000_RCTL_BAM
| E1000_RCTL_RDMTS_HALF
|
1385 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1386 wr32(E1000_RCTL
, rctl
);
1387 wr32(E1000_SRRCTL(0), E1000_SRRCTL_DESCTYPE_ADV_ONEBUF
);
1389 for (i
= 0; i
< rx_ring
->count
; i
++) {
1390 union e1000_adv_rx_desc
*rx_desc
;
1391 struct sk_buff
*skb
;
1393 buffer_info
= &rx_ring
->buffer_info
[i
];
1394 rx_desc
= E1000_RX_DESC_ADV(*rx_ring
, i
);
1395 skb
= alloc_skb(IGB_RXBUFFER_2048
+ NET_IP_ALIGN
,
1401 skb_reserve(skb
, NET_IP_ALIGN
);
1402 buffer_info
->skb
= skb
;
1403 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
1405 PCI_DMA_FROMDEVICE
);
1406 rx_desc
->read
.pkt_addr
= cpu_to_le64(buffer_info
->dma
);
1407 memset(skb
->data
, 0x00, skb
->len
);
1413 igb_free_desc_rings(adapter
);
1417 static void igb_phy_disable_receiver(struct igb_adapter
*adapter
)
1419 struct e1000_hw
*hw
= &adapter
->hw
;
1421 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1422 igb_write_phy_reg(hw
, 29, 0x001F);
1423 igb_write_phy_reg(hw
, 30, 0x8FFC);
1424 igb_write_phy_reg(hw
, 29, 0x001A);
1425 igb_write_phy_reg(hw
, 30, 0x8FF0);
1428 static int igb_integrated_phy_loopback(struct igb_adapter
*adapter
)
1430 struct e1000_hw
*hw
= &adapter
->hw
;
1433 hw
->mac
.autoneg
= false;
1435 if (hw
->phy
.type
== e1000_phy_m88
) {
1436 /* Auto-MDI/MDIX Off */
1437 igb_write_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, 0x0808);
1438 /* reset to update Auto-MDI/MDIX */
1439 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x9140);
1441 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x8140);
1444 ctrl_reg
= rd32(E1000_CTRL
);
1446 /* force 1000, set loopback */
1447 igb_write_phy_reg(hw
, PHY_CONTROL
, 0x4140);
1449 /* Now set up the MAC to the same speed/duplex as the PHY. */
1450 ctrl_reg
= rd32(E1000_CTRL
);
1451 ctrl_reg
&= ~E1000_CTRL_SPD_SEL
; /* Clear the speed sel bits */
1452 ctrl_reg
|= (E1000_CTRL_FRCSPD
| /* Set the Force Speed Bit */
1453 E1000_CTRL_FRCDPX
| /* Set the Force Duplex Bit */
1454 E1000_CTRL_SPD_1000
|/* Force Speed to 1000 */
1455 E1000_CTRL_FD
| /* Force Duplex to FULL */
1456 E1000_CTRL_SLU
); /* Set link up enable bit */
1458 if (hw
->phy
.type
== e1000_phy_m88
)
1459 ctrl_reg
|= E1000_CTRL_ILOS
; /* Invert Loss of Signal */
1461 wr32(E1000_CTRL
, ctrl_reg
);
1463 /* Disable the receiver on the PHY so when a cable is plugged in, the
1464 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1466 if (hw
->phy
.type
== e1000_phy_m88
)
1467 igb_phy_disable_receiver(adapter
);
1474 static int igb_set_phy_loopback(struct igb_adapter
*adapter
)
1476 return igb_integrated_phy_loopback(adapter
);
1479 static int igb_setup_loopback_test(struct igb_adapter
*adapter
)
1481 struct e1000_hw
*hw
= &adapter
->hw
;
1484 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1485 reg
= rd32(E1000_RCTL
);
1486 reg
|= E1000_RCTL_LBM_TCVR
;
1487 wr32(E1000_RCTL
, reg
);
1489 wr32(E1000_SCTL
, E1000_ENABLE_SERDES_LOOPBACK
);
1491 reg
= rd32(E1000_CTRL
);
1492 reg
&= ~(E1000_CTRL_RFCE
|
1495 reg
|= E1000_CTRL_SLU
|
1497 wr32(E1000_CTRL
, reg
);
1499 /* Unset switch control to serdes energy detect */
1500 reg
= rd32(E1000_CONNSW
);
1501 reg
&= ~E1000_CONNSW_ENRGSRC
;
1502 wr32(E1000_CONNSW
, reg
);
1504 /* Set PCS register for forced speed */
1505 reg
= rd32(E1000_PCS_LCTL
);
1506 reg
&= ~E1000_PCS_LCTL_AN_ENABLE
; /* Disable Autoneg*/
1507 reg
|= E1000_PCS_LCTL_FLV_LINK_UP
| /* Force link up */
1508 E1000_PCS_LCTL_FSV_1000
| /* Force 1000 */
1509 E1000_PCS_LCTL_FDV_FULL
| /* SerDes Full duplex */
1510 E1000_PCS_LCTL_FSD
| /* Force Speed */
1511 E1000_PCS_LCTL_FORCE_LINK
; /* Force Link */
1512 wr32(E1000_PCS_LCTL
, reg
);
1515 } else if (hw
->phy
.media_type
== e1000_media_type_copper
) {
1516 return igb_set_phy_loopback(adapter
);
1522 static void igb_loopback_cleanup(struct igb_adapter
*adapter
)
1524 struct e1000_hw
*hw
= &adapter
->hw
;
1528 rctl
= rd32(E1000_RCTL
);
1529 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
1530 wr32(E1000_RCTL
, rctl
);
1532 hw
->mac
.autoneg
= true;
1533 igb_read_phy_reg(hw
, PHY_CONTROL
, &phy_reg
);
1534 if (phy_reg
& MII_CR_LOOPBACK
) {
1535 phy_reg
&= ~MII_CR_LOOPBACK
;
1536 igb_write_phy_reg(hw
, PHY_CONTROL
, phy_reg
);
1537 igb_phy_sw_reset(hw
);
1541 static void igb_create_lbtest_frame(struct sk_buff
*skb
,
1542 unsigned int frame_size
)
1544 memset(skb
->data
, 0xFF, frame_size
);
1546 memset(&skb
->data
[frame_size
/ 2], 0xAA, frame_size
/ 2 - 1);
1547 memset(&skb
->data
[frame_size
/ 2 + 10], 0xBE, 1);
1548 memset(&skb
->data
[frame_size
/ 2 + 12], 0xAF, 1);
1551 static int igb_check_lbtest_frame(struct sk_buff
*skb
, unsigned int frame_size
)
1554 if (*(skb
->data
+ 3) == 0xFF)
1555 if ((*(skb
->data
+ frame_size
/ 2 + 10) == 0xBE) &&
1556 (*(skb
->data
+ frame_size
/ 2 + 12) == 0xAF))
1561 static int igb_run_loopback_test(struct igb_adapter
*adapter
)
1563 struct e1000_hw
*hw
= &adapter
->hw
;
1564 struct igb_ring
*tx_ring
= &adapter
->test_tx_ring
;
1565 struct igb_ring
*rx_ring
= &adapter
->test_rx_ring
;
1566 struct pci_dev
*pdev
= adapter
->pdev
;
1567 int i
, j
, k
, l
, lc
, good_cnt
;
1571 wr32(E1000_RDT(0), rx_ring
->count
- 1);
1573 /* Calculate the loop count based on the largest descriptor ring
1574 * The idea is to wrap the largest ring a number of times using 64
1575 * send/receive pairs during each loop
1578 if (rx_ring
->count
<= tx_ring
->count
)
1579 lc
= ((tx_ring
->count
/ 64) * 2) + 1;
1581 lc
= ((rx_ring
->count
/ 64) * 2) + 1;
1584 for (j
= 0; j
<= lc
; j
++) { /* loop count loop */
1585 for (i
= 0; i
< 64; i
++) { /* send the packets */
1586 igb_create_lbtest_frame(tx_ring
->buffer_info
[k
].skb
,
1588 pci_dma_sync_single_for_device(pdev
,
1589 tx_ring
->buffer_info
[k
].dma
,
1590 tx_ring
->buffer_info
[k
].length
,
1593 if (k
== tx_ring
->count
)
1596 wr32(E1000_TDT(0), k
);
1598 time
= jiffies
; /* set the start time for the receive */
1600 do { /* receive the sent packets */
1601 pci_dma_sync_single_for_cpu(pdev
,
1602 rx_ring
->buffer_info
[l
].dma
,
1604 PCI_DMA_FROMDEVICE
);
1606 ret_val
= igb_check_lbtest_frame(
1607 rx_ring
->buffer_info
[l
].skb
, 1024);
1611 if (l
== rx_ring
->count
)
1613 /* time + 20 msecs (200 msecs on 2.4) is more than
1614 * enough time to complete the receives, if it's
1615 * exceeded, break and error off
1617 } while (good_cnt
< 64 && jiffies
< (time
+ 20));
1618 if (good_cnt
!= 64) {
1619 ret_val
= 13; /* ret_val is the same as mis-compare */
1622 if (jiffies
>= (time
+ 20)) {
1623 ret_val
= 14; /* error code for time out error */
1626 } /* end loop count loop */
1630 static int igb_loopback_test(struct igb_adapter
*adapter
, u64
*data
)
1632 /* PHY loopback cannot be performed if SoL/IDER
1633 * sessions are active */
1634 if (igb_check_reset_block(&adapter
->hw
)) {
1635 dev_err(&adapter
->pdev
->dev
,
1636 "Cannot do PHY loopback test "
1637 "when SoL/IDER is active.\n");
1641 *data
= igb_setup_desc_rings(adapter
);
1644 *data
= igb_setup_loopback_test(adapter
);
1647 *data
= igb_run_loopback_test(adapter
);
1648 igb_loopback_cleanup(adapter
);
1651 igb_free_desc_rings(adapter
);
1656 static int igb_link_test(struct igb_adapter
*adapter
, u64
*data
)
1658 struct e1000_hw
*hw
= &adapter
->hw
;
1660 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
) {
1662 hw
->mac
.serdes_has_link
= false;
1664 /* On some blade server designs, link establishment
1665 * could take as long as 2-3 minutes */
1667 hw
->mac
.ops
.check_for_link(&adapter
->hw
);
1668 if (hw
->mac
.serdes_has_link
)
1671 } while (i
++ < 3750);
1675 hw
->mac
.ops
.check_for_link(&adapter
->hw
);
1676 if (hw
->mac
.autoneg
)
1679 if (!(rd32(E1000_STATUS
) &
1686 static void igb_diag_test(struct net_device
*netdev
,
1687 struct ethtool_test
*eth_test
, u64
*data
)
1689 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1690 u16 autoneg_advertised
;
1691 u8 forced_speed_duplex
, autoneg
;
1692 bool if_running
= netif_running(netdev
);
1694 set_bit(__IGB_TESTING
, &adapter
->state
);
1695 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1698 /* save speed, duplex, autoneg settings */
1699 autoneg_advertised
= adapter
->hw
.phy
.autoneg_advertised
;
1700 forced_speed_duplex
= adapter
->hw
.mac
.forced_speed_duplex
;
1701 autoneg
= adapter
->hw
.mac
.autoneg
;
1703 dev_info(&adapter
->pdev
->dev
, "offline testing starting\n");
1705 /* Link test performed before hardware reset so autoneg doesn't
1706 * interfere with test result */
1707 if (igb_link_test(adapter
, &data
[4]))
1708 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1711 /* indicate we're in test mode */
1716 if (igb_reg_test(adapter
, &data
[0]))
1717 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1720 if (igb_eeprom_test(adapter
, &data
[1]))
1721 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1724 if (igb_intr_test(adapter
, &data
[2]))
1725 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1728 if (igb_loopback_test(adapter
, &data
[3]))
1729 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1731 /* restore speed, duplex, autoneg settings */
1732 adapter
->hw
.phy
.autoneg_advertised
= autoneg_advertised
;
1733 adapter
->hw
.mac
.forced_speed_duplex
= forced_speed_duplex
;
1734 adapter
->hw
.mac
.autoneg
= autoneg
;
1736 /* force this routine to wait until autoneg complete/timeout */
1737 adapter
->hw
.phy
.autoneg_wait_to_complete
= true;
1739 adapter
->hw
.phy
.autoneg_wait_to_complete
= false;
1741 clear_bit(__IGB_TESTING
, &adapter
->state
);
1745 dev_info(&adapter
->pdev
->dev
, "online testing starting\n");
1747 if (igb_link_test(adapter
, &data
[4]))
1748 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1750 /* Online tests aren't run; pass by default */
1756 clear_bit(__IGB_TESTING
, &adapter
->state
);
1758 msleep_interruptible(4 * 1000);
1761 static int igb_wol_exclusion(struct igb_adapter
*adapter
,
1762 struct ethtool_wolinfo
*wol
)
1764 struct e1000_hw
*hw
= &adapter
->hw
;
1765 int retval
= 1; /* fail by default */
1767 switch (hw
->device_id
) {
1768 case E1000_DEV_ID_82575GB_QUAD_COPPER
:
1769 /* WoL not supported */
1772 case E1000_DEV_ID_82575EB_FIBER_SERDES
:
1773 case E1000_DEV_ID_82576_FIBER
:
1774 case E1000_DEV_ID_82576_SERDES
:
1775 /* Wake events not supported on port B */
1776 if (rd32(E1000_STATUS
) & E1000_STATUS_FUNC_1
) {
1780 /* return success for non excluded adapter ports */
1783 case E1000_DEV_ID_82576_QUAD_COPPER
:
1784 /* quad port adapters only support WoL on port A */
1785 if (!(adapter
->flags
& IGB_FLAG_QUAD_PORT_A
)) {
1789 /* return success for non excluded adapter ports */
1793 /* dual port cards only support WoL on port A from now on
1794 * unless it was enabled in the eeprom for port B
1795 * so exclude FUNC_1 ports from having WoL enabled */
1796 if (rd32(E1000_STATUS
) & E1000_STATUS_FUNC_1
&&
1797 !adapter
->eeprom_wol
) {
1808 static void igb_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1810 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1812 wol
->supported
= WAKE_UCAST
| WAKE_MCAST
|
1813 WAKE_BCAST
| WAKE_MAGIC
;
1816 /* this function will set ->supported = 0 and return 1 if wol is not
1817 * supported by this hardware */
1818 if (igb_wol_exclusion(adapter
, wol
) ||
1819 !device_can_wakeup(&adapter
->pdev
->dev
))
1822 /* apply any specific unsupported masks here */
1823 switch (adapter
->hw
.device_id
) {
1828 if (adapter
->wol
& E1000_WUFC_EX
)
1829 wol
->wolopts
|= WAKE_UCAST
;
1830 if (adapter
->wol
& E1000_WUFC_MC
)
1831 wol
->wolopts
|= WAKE_MCAST
;
1832 if (adapter
->wol
& E1000_WUFC_BC
)
1833 wol
->wolopts
|= WAKE_BCAST
;
1834 if (adapter
->wol
& E1000_WUFC_MAG
)
1835 wol
->wolopts
|= WAKE_MAGIC
;
1840 static int igb_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1842 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1844 if (wol
->wolopts
& (WAKE_PHY
| WAKE_ARP
| WAKE_MAGICSECURE
))
1847 if (igb_wol_exclusion(adapter
, wol
) ||
1848 !device_can_wakeup(&adapter
->pdev
->dev
))
1849 return wol
->wolopts
? -EOPNOTSUPP
: 0;
1851 /* these settings will always override what we currently have */
1854 if (wol
->wolopts
& WAKE_UCAST
)
1855 adapter
->wol
|= E1000_WUFC_EX
;
1856 if (wol
->wolopts
& WAKE_MCAST
)
1857 adapter
->wol
|= E1000_WUFC_MC
;
1858 if (wol
->wolopts
& WAKE_BCAST
)
1859 adapter
->wol
|= E1000_WUFC_BC
;
1860 if (wol
->wolopts
& WAKE_MAGIC
)
1861 adapter
->wol
|= E1000_WUFC_MAG
;
1863 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
1868 /* bit defines for adapter->led_status */
1869 #define IGB_LED_ON 0
1871 static int igb_phys_id(struct net_device
*netdev
, u32 data
)
1873 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1874 struct e1000_hw
*hw
= &adapter
->hw
;
1876 if (!data
|| data
> (u32
)(MAX_SCHEDULE_TIMEOUT
/ HZ
))
1877 data
= (u32
)(MAX_SCHEDULE_TIMEOUT
/ HZ
);
1880 msleep_interruptible(data
* 1000);
1883 clear_bit(IGB_LED_ON
, &adapter
->led_status
);
1884 igb_cleanup_led(hw
);
1889 static int igb_set_coalesce(struct net_device
*netdev
,
1890 struct ethtool_coalesce
*ec
)
1892 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1893 struct e1000_hw
*hw
= &adapter
->hw
;
1896 if ((ec
->rx_coalesce_usecs
> IGB_MAX_ITR_USECS
) ||
1897 ((ec
->rx_coalesce_usecs
> 3) &&
1898 (ec
->rx_coalesce_usecs
< IGB_MIN_ITR_USECS
)) ||
1899 (ec
->rx_coalesce_usecs
== 2))
1902 /* convert to rate of irq's per second */
1903 if (ec
->rx_coalesce_usecs
&& ec
->rx_coalesce_usecs
<= 3) {
1904 adapter
->itr_setting
= ec
->rx_coalesce_usecs
;
1905 adapter
->itr
= IGB_START_ITR
;
1907 adapter
->itr_setting
= ec
->rx_coalesce_usecs
<< 2;
1908 adapter
->itr
= adapter
->itr_setting
;
1911 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1912 wr32(adapter
->rx_ring
[i
].itr_register
, adapter
->itr
);
1917 static int igb_get_coalesce(struct net_device
*netdev
,
1918 struct ethtool_coalesce
*ec
)
1920 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1922 if (adapter
->itr_setting
<= 3)
1923 ec
->rx_coalesce_usecs
= adapter
->itr_setting
;
1925 ec
->rx_coalesce_usecs
= adapter
->itr_setting
>> 2;
1931 static int igb_nway_reset(struct net_device
*netdev
)
1933 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1934 if (netif_running(netdev
))
1935 igb_reinit_locked(adapter
);
1939 static int igb_get_sset_count(struct net_device
*netdev
, int sset
)
1943 return IGB_STATS_LEN
;
1945 return IGB_TEST_LEN
;
1951 static void igb_get_ethtool_stats(struct net_device
*netdev
,
1952 struct ethtool_stats
*stats
, u64
*data
)
1954 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1956 int stat_count_tx
= sizeof(struct igb_tx_queue_stats
) / sizeof(u64
);
1957 int stat_count_rx
= sizeof(struct igb_rx_queue_stats
) / sizeof(u64
);
1961 igb_update_stats(adapter
);
1962 for (i
= 0; i
< IGB_GLOBAL_STATS_LEN
; i
++) {
1963 char *p
= (char *)adapter
+igb_gstrings_stats
[i
].stat_offset
;
1964 data
[i
] = (igb_gstrings_stats
[i
].sizeof_stat
==
1965 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1967 for (j
= 0; j
< adapter
->num_tx_queues
; j
++) {
1969 queue_stat
= (u64
*)&adapter
->tx_ring
[j
].tx_stats
;
1970 for (k
= 0; k
< stat_count_tx
; k
++)
1971 data
[i
+ k
] = queue_stat
[k
];
1974 for (j
= 0; j
< adapter
->num_rx_queues
; j
++) {
1976 queue_stat
= (u64
*)&adapter
->rx_ring
[j
].rx_stats
;
1977 for (k
= 0; k
< stat_count_rx
; k
++)
1978 data
[i
+ k
] = queue_stat
[k
];
1983 static void igb_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*data
)
1985 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1989 switch (stringset
) {
1991 memcpy(data
, *igb_gstrings_test
,
1992 IGB_TEST_LEN
*ETH_GSTRING_LEN
);
1995 for (i
= 0; i
< IGB_GLOBAL_STATS_LEN
; i
++) {
1996 memcpy(p
, igb_gstrings_stats
[i
].stat_string
,
1998 p
+= ETH_GSTRING_LEN
;
2000 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2001 sprintf(p
, "tx_queue_%u_packets", i
);
2002 p
+= ETH_GSTRING_LEN
;
2003 sprintf(p
, "tx_queue_%u_bytes", i
);
2004 p
+= ETH_GSTRING_LEN
;
2006 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2007 sprintf(p
, "rx_queue_%u_packets", i
);
2008 p
+= ETH_GSTRING_LEN
;
2009 sprintf(p
, "rx_queue_%u_bytes", i
);
2010 p
+= ETH_GSTRING_LEN
;
2011 sprintf(p
, "rx_queue_%u_drops", i
);
2012 p
+= ETH_GSTRING_LEN
;
2014 /* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
2019 static const struct ethtool_ops igb_ethtool_ops
= {
2020 .get_settings
= igb_get_settings
,
2021 .set_settings
= igb_set_settings
,
2022 .get_drvinfo
= igb_get_drvinfo
,
2023 .get_regs_len
= igb_get_regs_len
,
2024 .get_regs
= igb_get_regs
,
2025 .get_wol
= igb_get_wol
,
2026 .set_wol
= igb_set_wol
,
2027 .get_msglevel
= igb_get_msglevel
,
2028 .set_msglevel
= igb_set_msglevel
,
2029 .nway_reset
= igb_nway_reset
,
2030 .get_link
= ethtool_op_get_link
,
2031 .get_eeprom_len
= igb_get_eeprom_len
,
2032 .get_eeprom
= igb_get_eeprom
,
2033 .set_eeprom
= igb_set_eeprom
,
2034 .get_ringparam
= igb_get_ringparam
,
2035 .set_ringparam
= igb_set_ringparam
,
2036 .get_pauseparam
= igb_get_pauseparam
,
2037 .set_pauseparam
= igb_set_pauseparam
,
2038 .get_rx_csum
= igb_get_rx_csum
,
2039 .set_rx_csum
= igb_set_rx_csum
,
2040 .get_tx_csum
= igb_get_tx_csum
,
2041 .set_tx_csum
= igb_set_tx_csum
,
2042 .get_sg
= ethtool_op_get_sg
,
2043 .set_sg
= ethtool_op_set_sg
,
2044 .get_tso
= ethtool_op_get_tso
,
2045 .set_tso
= igb_set_tso
,
2046 .self_test
= igb_diag_test
,
2047 .get_strings
= igb_get_strings
,
2048 .phys_id
= igb_phys_id
,
2049 .get_sset_count
= igb_get_sset_count
,
2050 .get_ethtool_stats
= igb_get_ethtool_stats
,
2051 .get_coalesce
= igb_get_coalesce
,
2052 .set_coalesce
= igb_set_coalesce
,
2055 void igb_set_ethtool_ops(struct net_device
*netdev
)
2057 SET_ETHTOOL_OPS(netdev
, &igb_ethtool_ops
);