blob: ac9d5272650dbee362ded07308ea8cac651bab32 [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Alexander Duyck86d5d382009-02-06 23:23:12 +00004 Copyright(c) 2007-2009 Intel Corporation.
Auke Kok9d5c8242008-01-24 02:22:38 -08005
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.
9
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
13 more details.
14
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.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28/* ethtool support for igb */
29
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>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040037#include <linux/sched.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080038
39#include "igb.h"
40
41struct igb_stats {
42 char stat_string[ETH_GSTRING_LEN];
43 int sizeof_stat;
44 int stat_offset;
45};
46
Alexander Duyck128e45e2009-11-12 18:37:38 +000047#define IGB_STAT(_name, _stat) { \
48 .stat_string = _name, \
49 .sizeof_stat = FIELD_SIZEOF(struct igb_adapter, _stat), \
50 .stat_offset = offsetof(struct igb_adapter, _stat) \
51}
Auke Kok9d5c8242008-01-24 02:22:38 -080052static const struct igb_stats igb_gstrings_stats[] = {
Alexander Duyck128e45e2009-11-12 18:37:38 +000053 IGB_STAT("rx_packets", stats.gprc),
54 IGB_STAT("tx_packets", stats.gptc),
55 IGB_STAT("rx_bytes", stats.gorc),
56 IGB_STAT("tx_bytes", stats.gotc),
57 IGB_STAT("rx_broadcast", stats.bprc),
58 IGB_STAT("tx_broadcast", stats.bptc),
59 IGB_STAT("rx_multicast", stats.mprc),
60 IGB_STAT("tx_multicast", stats.mptc),
61 IGB_STAT("multicast", stats.mprc),
62 IGB_STAT("collisions", stats.colc),
63 IGB_STAT("rx_crc_errors", stats.crcerrs),
64 IGB_STAT("rx_no_buffer_count", stats.rnbc),
65 IGB_STAT("rx_missed_errors", stats.mpc),
66 IGB_STAT("tx_aborted_errors", stats.ecol),
67 IGB_STAT("tx_carrier_errors", stats.tncrs),
68 IGB_STAT("tx_window_errors", stats.latecol),
69 IGB_STAT("tx_abort_late_coll", stats.latecol),
70 IGB_STAT("tx_deferred_ok", stats.dc),
71 IGB_STAT("tx_single_coll_ok", stats.scc),
72 IGB_STAT("tx_multi_coll_ok", stats.mcc),
73 IGB_STAT("tx_timeout_count", tx_timeout_count),
74 IGB_STAT("rx_long_length_errors", stats.roc),
75 IGB_STAT("rx_short_length_errors", stats.ruc),
76 IGB_STAT("rx_align_errors", stats.algnerrc),
77 IGB_STAT("tx_tcp_seg_good", stats.tsctc),
78 IGB_STAT("tx_tcp_seg_failed", stats.tsctfc),
79 IGB_STAT("rx_flow_control_xon", stats.xonrxc),
80 IGB_STAT("rx_flow_control_xoff", stats.xoffrxc),
81 IGB_STAT("tx_flow_control_xon", stats.xontxc),
82 IGB_STAT("tx_flow_control_xoff", stats.xofftxc),
83 IGB_STAT("rx_long_byte_count", stats.gorc),
84 IGB_STAT("tx_dma_out_of_sync", stats.doosync),
85 IGB_STAT("tx_smbus", stats.mgptc),
86 IGB_STAT("rx_smbus", stats.mgprc),
87 IGB_STAT("dropped_smbus", stats.mgpdc),
Auke Kok9d5c8242008-01-24 02:22:38 -080088};
89
Alexander Duyck128e45e2009-11-12 18:37:38 +000090#define IGB_NETDEV_STAT(_net_stat) { \
91 .stat_string = __stringify(_net_stat), \
92 .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \
93 .stat_offset = offsetof(struct net_device_stats, _net_stat) \
94}
95static const struct igb_stats igb_gstrings_net_stats[] = {
96 IGB_NETDEV_STAT(rx_errors),
97 IGB_NETDEV_STAT(tx_errors),
98 IGB_NETDEV_STAT(tx_dropped),
99 IGB_NETDEV_STAT(rx_length_errors),
100 IGB_NETDEV_STAT(rx_over_errors),
101 IGB_NETDEV_STAT(rx_frame_errors),
102 IGB_NETDEV_STAT(rx_fifo_errors),
103 IGB_NETDEV_STAT(tx_fifo_errors),
104 IGB_NETDEV_STAT(tx_heartbeat_errors)
105};
106
Auke Kok9d5c8242008-01-24 02:22:38 -0800107#define IGB_GLOBAL_STATS_LEN \
Alexander Duyck317f66b2009-10-27 23:46:20 +0000108 (sizeof(igb_gstrings_stats) / sizeof(struct igb_stats))
Alexander Duyck128e45e2009-11-12 18:37:38 +0000109#define IGB_NETDEV_STATS_LEN \
110 (sizeof(igb_gstrings_net_stats) / sizeof(struct igb_stats))
111#define IGB_RX_QUEUE_STATS_LEN \
112 (sizeof(struct igb_rx_queue_stats) / sizeof(u64))
113#define IGB_TX_QUEUE_STATS_LEN \
114 (sizeof(struct igb_tx_queue_stats) / sizeof(u64))
115#define IGB_QUEUE_STATS_LEN \
116 ((((struct igb_adapter *)netdev_priv(netdev))->num_rx_queues * \
117 IGB_RX_QUEUE_STATS_LEN) + \
118 (((struct igb_adapter *)netdev_priv(netdev))->num_tx_queues * \
119 IGB_TX_QUEUE_STATS_LEN))
120#define IGB_STATS_LEN \
121 (IGB_GLOBAL_STATS_LEN + IGB_NETDEV_STATS_LEN + IGB_QUEUE_STATS_LEN)
122
Auke Kok9d5c8242008-01-24 02:22:38 -0800123static const char igb_gstrings_test[][ETH_GSTRING_LEN] = {
124 "Register test (offline)", "Eeprom test (offline)",
125 "Interrupt test (offline)", "Loopback test (offline)",
126 "Link test (on/offline)"
127};
Alexander Duyck317f66b2009-10-27 23:46:20 +0000128#define IGB_TEST_LEN (sizeof(igb_gstrings_test) / ETH_GSTRING_LEN)
Auke Kok9d5c8242008-01-24 02:22:38 -0800129
130static int igb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
131{
132 struct igb_adapter *adapter = netdev_priv(netdev);
133 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck317f66b2009-10-27 23:46:20 +0000134 u32 status;
Auke Kok9d5c8242008-01-24 02:22:38 -0800135
136 if (hw->phy.media_type == e1000_media_type_copper) {
137
138 ecmd->supported = (SUPPORTED_10baseT_Half |
139 SUPPORTED_10baseT_Full |
140 SUPPORTED_100baseT_Half |
141 SUPPORTED_100baseT_Full |
142 SUPPORTED_1000baseT_Full|
143 SUPPORTED_Autoneg |
144 SUPPORTED_TP);
145 ecmd->advertising = ADVERTISED_TP;
146
147 if (hw->mac.autoneg == 1) {
148 ecmd->advertising |= ADVERTISED_Autoneg;
149 /* the e1000 autoneg seems to match ethtool nicely */
150 ecmd->advertising |= hw->phy.autoneg_advertised;
151 }
152
153 ecmd->port = PORT_TP;
154 ecmd->phy_address = hw->phy.addr;
155 } else {
156 ecmd->supported = (SUPPORTED_1000baseT_Full |
157 SUPPORTED_FIBRE |
158 SUPPORTED_Autoneg);
159
160 ecmd->advertising = (ADVERTISED_1000baseT_Full |
161 ADVERTISED_FIBRE |
162 ADVERTISED_Autoneg);
163
164 ecmd->port = PORT_FIBRE;
165 }
166
167 ecmd->transceiver = XCVR_INTERNAL;
168
Alexander Duyck317f66b2009-10-27 23:46:20 +0000169 status = rd32(E1000_STATUS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800170
Alexander Duyck317f66b2009-10-27 23:46:20 +0000171 if (status & E1000_STATUS_LU) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800172
Alexander Duyck317f66b2009-10-27 23:46:20 +0000173 if ((status & E1000_STATUS_SPEED_1000) ||
174 hw->phy.media_type != e1000_media_type_copper)
175 ecmd->speed = SPEED_1000;
176 else if (status & E1000_STATUS_SPEED_100)
177 ecmd->speed = SPEED_100;
178 else
179 ecmd->speed = SPEED_10;
Auke Kok9d5c8242008-01-24 02:22:38 -0800180
Alexander Duyck317f66b2009-10-27 23:46:20 +0000181 if ((status & E1000_STATUS_FD) ||
182 hw->phy.media_type != e1000_media_type_copper)
Auke Kok9d5c8242008-01-24 02:22:38 -0800183 ecmd->duplex = DUPLEX_FULL;
184 else
185 ecmd->duplex = DUPLEX_HALF;
186 } else {
187 ecmd->speed = -1;
188 ecmd->duplex = -1;
189 }
190
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000191 ecmd->autoneg = hw->mac.autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Auke Kok9d5c8242008-01-24 02:22:38 -0800192 return 0;
193}
194
195static int igb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
196{
197 struct igb_adapter *adapter = netdev_priv(netdev);
198 struct e1000_hw *hw = &adapter->hw;
199
200 /* When SoL/IDER sessions are active, autoneg/speed/duplex
201 * cannot be changed */
202 if (igb_check_reset_block(hw)) {
203 dev_err(&adapter->pdev->dev, "Cannot change link "
204 "characteristics when SoL/IDER is active.\n");
205 return -EINVAL;
206 }
207
208 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
209 msleep(1);
210
211 if (ecmd->autoneg == AUTONEG_ENABLE) {
212 hw->mac.autoneg = 1;
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000213 hw->phy.autoneg_advertised = ecmd->advertising |
214 ADVERTISED_TP |
215 ADVERTISED_Autoneg;
Auke Kok9d5c8242008-01-24 02:22:38 -0800216 ecmd->advertising = hw->phy.autoneg_advertised;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000217 if (adapter->fc_autoneg)
218 hw->fc.requested_mode = e1000_fc_default;
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000219 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -0800220 if (igb_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
221 clear_bit(__IGB_RESETTING, &adapter->state);
222 return -EINVAL;
223 }
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000224 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800225
226 /* reset the link */
Auke Kok9d5c8242008-01-24 02:22:38 -0800227 if (netif_running(adapter->netdev)) {
228 igb_down(adapter);
229 igb_up(adapter);
230 } else
231 igb_reset(adapter);
232
233 clear_bit(__IGB_RESETTING, &adapter->state);
234 return 0;
235}
236
237static void igb_get_pauseparam(struct net_device *netdev,
238 struct ethtool_pauseparam *pause)
239{
240 struct igb_adapter *adapter = netdev_priv(netdev);
241 struct e1000_hw *hw = &adapter->hw;
242
243 pause->autoneg =
244 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
245
Alexander Duyck0cce1192009-07-23 18:10:24 +0000246 if (hw->fc.current_mode == e1000_fc_rx_pause)
Auke Kok9d5c8242008-01-24 02:22:38 -0800247 pause->rx_pause = 1;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000248 else if (hw->fc.current_mode == e1000_fc_tx_pause)
Auke Kok9d5c8242008-01-24 02:22:38 -0800249 pause->tx_pause = 1;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000250 else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800251 pause->rx_pause = 1;
252 pause->tx_pause = 1;
253 }
254}
255
256static int igb_set_pauseparam(struct net_device *netdev,
257 struct ethtool_pauseparam *pause)
258{
259 struct igb_adapter *adapter = netdev_priv(netdev);
260 struct e1000_hw *hw = &adapter->hw;
261 int retval = 0;
262
263 adapter->fc_autoneg = pause->autoneg;
264
265 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
266 msleep(1);
267
Auke Kok9d5c8242008-01-24 02:22:38 -0800268 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000269 hw->fc.requested_mode = e1000_fc_default;
Auke Kok9d5c8242008-01-24 02:22:38 -0800270 if (netif_running(adapter->netdev)) {
271 igb_down(adapter);
272 igb_up(adapter);
Alexander Duyck317f66b2009-10-27 23:46:20 +0000273 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -0800274 igb_reset(adapter);
Alexander Duyck317f66b2009-10-27 23:46:20 +0000275 }
Alexander Duyck0cce1192009-07-23 18:10:24 +0000276 } else {
277 if (pause->rx_pause && pause->tx_pause)
278 hw->fc.requested_mode = e1000_fc_full;
279 else if (pause->rx_pause && !pause->tx_pause)
280 hw->fc.requested_mode = e1000_fc_rx_pause;
281 else if (!pause->rx_pause && pause->tx_pause)
282 hw->fc.requested_mode = e1000_fc_tx_pause;
283 else if (!pause->rx_pause && !pause->tx_pause)
284 hw->fc.requested_mode = e1000_fc_none;
285
286 hw->fc.current_mode = hw->fc.requested_mode;
287
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000288 retval = ((hw->phy.media_type == e1000_media_type_copper) ?
289 igb_force_mac_fc(hw) : igb_setup_link(hw));
Alexander Duyck0cce1192009-07-23 18:10:24 +0000290 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800291
292 clear_bit(__IGB_RESETTING, &adapter->state);
293 return retval;
294}
295
296static u32 igb_get_rx_csum(struct net_device *netdev)
297{
298 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck85ad76b2009-10-27 15:52:46 +0000299 return !!(adapter->rx_ring[0].flags & IGB_RING_FLAG_RX_CSUM);
Auke Kok9d5c8242008-01-24 02:22:38 -0800300}
301
302static int igb_set_rx_csum(struct net_device *netdev, u32 data)
303{
304 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck85ad76b2009-10-27 15:52:46 +0000305 int i;
Alexander Duyck7beb0142009-05-06 10:25:23 +0000306
Alexander Duyck85ad76b2009-10-27 15:52:46 +0000307 for (i = 0; i < adapter->num_rx_queues; i++) {
308 if (data)
309 adapter->rx_ring[i].flags |= IGB_RING_FLAG_RX_CSUM;
310 else
311 adapter->rx_ring[i].flags &= ~IGB_RING_FLAG_RX_CSUM;
312 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800313
314 return 0;
315}
316
317static u32 igb_get_tx_csum(struct net_device *netdev)
318{
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000319 return (netdev->features & NETIF_F_IP_CSUM) != 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800320}
321
322static int igb_set_tx_csum(struct net_device *netdev, u32 data)
323{
Jesse Brandeburgb9473562009-04-27 22:36:13 +0000324 struct igb_adapter *adapter = netdev_priv(netdev);
325
326 if (data) {
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000327 netdev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
Alexander Duyck317f66b2009-10-27 23:46:20 +0000328 if (adapter->hw.mac.type >= e1000_82576)
Jesse Brandeburgb9473562009-04-27 22:36:13 +0000329 netdev->features |= NETIF_F_SCTP_CSUM;
330 } else {
331 netdev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
332 NETIF_F_SCTP_CSUM);
333 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800334
335 return 0;
336}
337
338static int igb_set_tso(struct net_device *netdev, u32 data)
339{
340 struct igb_adapter *adapter = netdev_priv(netdev);
341
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000342 if (data) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800343 netdev->features |= NETIF_F_TSO;
Auke Kok9d5c8242008-01-24 02:22:38 -0800344 netdev->features |= NETIF_F_TSO6;
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000345 } else {
346 netdev->features &= ~NETIF_F_TSO;
Auke Kok9d5c8242008-01-24 02:22:38 -0800347 netdev->features &= ~NETIF_F_TSO6;
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000348 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800349
350 dev_info(&adapter->pdev->dev, "TSO is %s\n",
351 data ? "Enabled" : "Disabled");
352 return 0;
353}
354
355static u32 igb_get_msglevel(struct net_device *netdev)
356{
357 struct igb_adapter *adapter = netdev_priv(netdev);
358 return adapter->msg_enable;
359}
360
361static void igb_set_msglevel(struct net_device *netdev, u32 data)
362{
363 struct igb_adapter *adapter = netdev_priv(netdev);
364 adapter->msg_enable = data;
365}
366
367static int igb_get_regs_len(struct net_device *netdev)
368{
369#define IGB_REGS_LEN 551
370 return IGB_REGS_LEN * sizeof(u32);
371}
372
373static void igb_get_regs(struct net_device *netdev,
374 struct ethtool_regs *regs, void *p)
375{
376 struct igb_adapter *adapter = netdev_priv(netdev);
377 struct e1000_hw *hw = &adapter->hw;
378 u32 *regs_buff = p;
379 u8 i;
380
381 memset(p, 0, IGB_REGS_LEN * sizeof(u32));
382
383 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
384
385 /* General Registers */
386 regs_buff[0] = rd32(E1000_CTRL);
387 regs_buff[1] = rd32(E1000_STATUS);
388 regs_buff[2] = rd32(E1000_CTRL_EXT);
389 regs_buff[3] = rd32(E1000_MDIC);
390 regs_buff[4] = rd32(E1000_SCTL);
391 regs_buff[5] = rd32(E1000_CONNSW);
392 regs_buff[6] = rd32(E1000_VET);
393 regs_buff[7] = rd32(E1000_LEDCTL);
394 regs_buff[8] = rd32(E1000_PBA);
395 regs_buff[9] = rd32(E1000_PBS);
396 regs_buff[10] = rd32(E1000_FRTIMER);
397 regs_buff[11] = rd32(E1000_TCPTIMER);
398
399 /* NVM Register */
400 regs_buff[12] = rd32(E1000_EECD);
401
402 /* Interrupt */
Alexander Duyckfe59de32008-08-26 04:25:05 -0700403 /* Reading EICS for EICR because they read the
404 * same but EICS does not clear on read */
405 regs_buff[13] = rd32(E1000_EICS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800406 regs_buff[14] = rd32(E1000_EICS);
407 regs_buff[15] = rd32(E1000_EIMS);
408 regs_buff[16] = rd32(E1000_EIMC);
409 regs_buff[17] = rd32(E1000_EIAC);
410 regs_buff[18] = rd32(E1000_EIAM);
Alexander Duyckfe59de32008-08-26 04:25:05 -0700411 /* Reading ICS for ICR because they read the
412 * same but ICS does not clear on read */
413 regs_buff[19] = rd32(E1000_ICS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800414 regs_buff[20] = rd32(E1000_ICS);
415 regs_buff[21] = rd32(E1000_IMS);
416 regs_buff[22] = rd32(E1000_IMC);
417 regs_buff[23] = rd32(E1000_IAC);
418 regs_buff[24] = rd32(E1000_IAM);
419 regs_buff[25] = rd32(E1000_IMIRVP);
420
421 /* Flow Control */
422 regs_buff[26] = rd32(E1000_FCAL);
423 regs_buff[27] = rd32(E1000_FCAH);
424 regs_buff[28] = rd32(E1000_FCTTV);
425 regs_buff[29] = rd32(E1000_FCRTL);
426 regs_buff[30] = rd32(E1000_FCRTH);
427 regs_buff[31] = rd32(E1000_FCRTV);
428
429 /* Receive */
430 regs_buff[32] = rd32(E1000_RCTL);
431 regs_buff[33] = rd32(E1000_RXCSUM);
432 regs_buff[34] = rd32(E1000_RLPML);
433 regs_buff[35] = rd32(E1000_RFCTL);
434 regs_buff[36] = rd32(E1000_MRQC);
Alexander Duycke1739522009-02-19 20:39:44 -0800435 regs_buff[37] = rd32(E1000_VT_CTL);
Auke Kok9d5c8242008-01-24 02:22:38 -0800436
437 /* Transmit */
438 regs_buff[38] = rd32(E1000_TCTL);
439 regs_buff[39] = rd32(E1000_TCTL_EXT);
440 regs_buff[40] = rd32(E1000_TIPG);
441 regs_buff[41] = rd32(E1000_DTXCTL);
442
443 /* Wake Up */
444 regs_buff[42] = rd32(E1000_WUC);
445 regs_buff[43] = rd32(E1000_WUFC);
446 regs_buff[44] = rd32(E1000_WUS);
447 regs_buff[45] = rd32(E1000_IPAV);
448 regs_buff[46] = rd32(E1000_WUPL);
449
450 /* MAC */
451 regs_buff[47] = rd32(E1000_PCS_CFG0);
452 regs_buff[48] = rd32(E1000_PCS_LCTL);
453 regs_buff[49] = rd32(E1000_PCS_LSTAT);
454 regs_buff[50] = rd32(E1000_PCS_ANADV);
455 regs_buff[51] = rd32(E1000_PCS_LPAB);
456 regs_buff[52] = rd32(E1000_PCS_NPTX);
457 regs_buff[53] = rd32(E1000_PCS_LPABNP);
458
459 /* Statistics */
460 regs_buff[54] = adapter->stats.crcerrs;
461 regs_buff[55] = adapter->stats.algnerrc;
462 regs_buff[56] = adapter->stats.symerrs;
463 regs_buff[57] = adapter->stats.rxerrc;
464 regs_buff[58] = adapter->stats.mpc;
465 regs_buff[59] = adapter->stats.scc;
466 regs_buff[60] = adapter->stats.ecol;
467 regs_buff[61] = adapter->stats.mcc;
468 regs_buff[62] = adapter->stats.latecol;
469 regs_buff[63] = adapter->stats.colc;
470 regs_buff[64] = adapter->stats.dc;
471 regs_buff[65] = adapter->stats.tncrs;
472 regs_buff[66] = adapter->stats.sec;
473 regs_buff[67] = adapter->stats.htdpmc;
474 regs_buff[68] = adapter->stats.rlec;
475 regs_buff[69] = adapter->stats.xonrxc;
476 regs_buff[70] = adapter->stats.xontxc;
477 regs_buff[71] = adapter->stats.xoffrxc;
478 regs_buff[72] = adapter->stats.xofftxc;
479 regs_buff[73] = adapter->stats.fcruc;
480 regs_buff[74] = adapter->stats.prc64;
481 regs_buff[75] = adapter->stats.prc127;
482 regs_buff[76] = adapter->stats.prc255;
483 regs_buff[77] = adapter->stats.prc511;
484 regs_buff[78] = adapter->stats.prc1023;
485 regs_buff[79] = adapter->stats.prc1522;
486 regs_buff[80] = adapter->stats.gprc;
487 regs_buff[81] = adapter->stats.bprc;
488 regs_buff[82] = adapter->stats.mprc;
489 regs_buff[83] = adapter->stats.gptc;
490 regs_buff[84] = adapter->stats.gorc;
491 regs_buff[86] = adapter->stats.gotc;
492 regs_buff[88] = adapter->stats.rnbc;
493 regs_buff[89] = adapter->stats.ruc;
494 regs_buff[90] = adapter->stats.rfc;
495 regs_buff[91] = adapter->stats.roc;
496 regs_buff[92] = adapter->stats.rjc;
497 regs_buff[93] = adapter->stats.mgprc;
498 regs_buff[94] = adapter->stats.mgpdc;
499 regs_buff[95] = adapter->stats.mgptc;
500 regs_buff[96] = adapter->stats.tor;
501 regs_buff[98] = adapter->stats.tot;
502 regs_buff[100] = adapter->stats.tpr;
503 regs_buff[101] = adapter->stats.tpt;
504 regs_buff[102] = adapter->stats.ptc64;
505 regs_buff[103] = adapter->stats.ptc127;
506 regs_buff[104] = adapter->stats.ptc255;
507 regs_buff[105] = adapter->stats.ptc511;
508 regs_buff[106] = adapter->stats.ptc1023;
509 regs_buff[107] = adapter->stats.ptc1522;
510 regs_buff[108] = adapter->stats.mptc;
511 regs_buff[109] = adapter->stats.bptc;
512 regs_buff[110] = adapter->stats.tsctc;
513 regs_buff[111] = adapter->stats.iac;
514 regs_buff[112] = adapter->stats.rpthc;
515 regs_buff[113] = adapter->stats.hgptc;
516 regs_buff[114] = adapter->stats.hgorc;
517 regs_buff[116] = adapter->stats.hgotc;
518 regs_buff[118] = adapter->stats.lenerrs;
519 regs_buff[119] = adapter->stats.scvpc;
520 regs_buff[120] = adapter->stats.hrmpc;
521
Auke Kok9d5c8242008-01-24 02:22:38 -0800522 for (i = 0; i < 4; i++)
523 regs_buff[121 + i] = rd32(E1000_SRRCTL(i));
524 for (i = 0; i < 4; i++)
Alexander Duyck83ab50a2009-10-27 15:55:41 +0000525 regs_buff[125 + i] = rd32(E1000_PSRTYPE(i));
Auke Kok9d5c8242008-01-24 02:22:38 -0800526 for (i = 0; i < 4; i++)
527 regs_buff[129 + i] = rd32(E1000_RDBAL(i));
528 for (i = 0; i < 4; i++)
529 regs_buff[133 + i] = rd32(E1000_RDBAH(i));
530 for (i = 0; i < 4; i++)
531 regs_buff[137 + i] = rd32(E1000_RDLEN(i));
532 for (i = 0; i < 4; i++)
533 regs_buff[141 + i] = rd32(E1000_RDH(i));
534 for (i = 0; i < 4; i++)
535 regs_buff[145 + i] = rd32(E1000_RDT(i));
536 for (i = 0; i < 4; i++)
537 regs_buff[149 + i] = rd32(E1000_RXDCTL(i));
538
539 for (i = 0; i < 10; i++)
540 regs_buff[153 + i] = rd32(E1000_EITR(i));
541 for (i = 0; i < 8; i++)
542 regs_buff[163 + i] = rd32(E1000_IMIR(i));
543 for (i = 0; i < 8; i++)
544 regs_buff[171 + i] = rd32(E1000_IMIREXT(i));
545 for (i = 0; i < 16; i++)
546 regs_buff[179 + i] = rd32(E1000_RAL(i));
547 for (i = 0; i < 16; i++)
548 regs_buff[195 + i] = rd32(E1000_RAH(i));
549
550 for (i = 0; i < 4; i++)
551 regs_buff[211 + i] = rd32(E1000_TDBAL(i));
552 for (i = 0; i < 4; i++)
553 regs_buff[215 + i] = rd32(E1000_TDBAH(i));
554 for (i = 0; i < 4; i++)
555 regs_buff[219 + i] = rd32(E1000_TDLEN(i));
556 for (i = 0; i < 4; i++)
557 regs_buff[223 + i] = rd32(E1000_TDH(i));
558 for (i = 0; i < 4; i++)
559 regs_buff[227 + i] = rd32(E1000_TDT(i));
560 for (i = 0; i < 4; i++)
561 regs_buff[231 + i] = rd32(E1000_TXDCTL(i));
562 for (i = 0; i < 4; i++)
563 regs_buff[235 + i] = rd32(E1000_TDWBAL(i));
564 for (i = 0; i < 4; i++)
565 regs_buff[239 + i] = rd32(E1000_TDWBAH(i));
566 for (i = 0; i < 4; i++)
567 regs_buff[243 + i] = rd32(E1000_DCA_TXCTRL(i));
568
569 for (i = 0; i < 4; i++)
570 regs_buff[247 + i] = rd32(E1000_IP4AT_REG(i));
571 for (i = 0; i < 4; i++)
572 regs_buff[251 + i] = rd32(E1000_IP6AT_REG(i));
573 for (i = 0; i < 32; i++)
574 regs_buff[255 + i] = rd32(E1000_WUPM_REG(i));
575 for (i = 0; i < 128; i++)
576 regs_buff[287 + i] = rd32(E1000_FFMT_REG(i));
577 for (i = 0; i < 128; i++)
578 regs_buff[415 + i] = rd32(E1000_FFVT_REG(i));
579 for (i = 0; i < 4; i++)
580 regs_buff[543 + i] = rd32(E1000_FFLT_REG(i));
581
582 regs_buff[547] = rd32(E1000_TDFH);
583 regs_buff[548] = rd32(E1000_TDFT);
584 regs_buff[549] = rd32(E1000_TDFHS);
585 regs_buff[550] = rd32(E1000_TDFPC);
586
587}
588
589static int igb_get_eeprom_len(struct net_device *netdev)
590{
591 struct igb_adapter *adapter = netdev_priv(netdev);
592 return adapter->hw.nvm.word_size * 2;
593}
594
595static int igb_get_eeprom(struct net_device *netdev,
596 struct ethtool_eeprom *eeprom, u8 *bytes)
597{
598 struct igb_adapter *adapter = netdev_priv(netdev);
599 struct e1000_hw *hw = &adapter->hw;
600 u16 *eeprom_buff;
601 int first_word, last_word;
602 int ret_val = 0;
603 u16 i;
604
605 if (eeprom->len == 0)
606 return -EINVAL;
607
608 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
609
610 first_word = eeprom->offset >> 1;
611 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
612
613 eeprom_buff = kmalloc(sizeof(u16) *
614 (last_word - first_word + 1), GFP_KERNEL);
615 if (!eeprom_buff)
616 return -ENOMEM;
617
618 if (hw->nvm.type == e1000_nvm_eeprom_spi)
Alexander Duyck312c75a2009-02-06 23:17:47 +0000619 ret_val = hw->nvm.ops.read(hw, first_word,
Auke Kok9d5c8242008-01-24 02:22:38 -0800620 last_word - first_word + 1,
621 eeprom_buff);
622 else {
623 for (i = 0; i < last_word - first_word + 1; i++) {
Alexander Duyck312c75a2009-02-06 23:17:47 +0000624 ret_val = hw->nvm.ops.read(hw, first_word + i, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800625 &eeprom_buff[i]);
626 if (ret_val)
627 break;
628 }
629 }
630
631 /* Device's eeprom is always little-endian, word addressable */
632 for (i = 0; i < last_word - first_word + 1; i++)
633 le16_to_cpus(&eeprom_buff[i]);
634
635 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
636 eeprom->len);
637 kfree(eeprom_buff);
638
639 return ret_val;
640}
641
642static int igb_set_eeprom(struct net_device *netdev,
643 struct ethtool_eeprom *eeprom, u8 *bytes)
644{
645 struct igb_adapter *adapter = netdev_priv(netdev);
646 struct e1000_hw *hw = &adapter->hw;
647 u16 *eeprom_buff;
648 void *ptr;
649 int max_len, first_word, last_word, ret_val = 0;
650 u16 i;
651
652 if (eeprom->len == 0)
653 return -EOPNOTSUPP;
654
655 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
656 return -EFAULT;
657
658 max_len = hw->nvm.word_size * 2;
659
660 first_word = eeprom->offset >> 1;
661 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
662 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
663 if (!eeprom_buff)
664 return -ENOMEM;
665
666 ptr = (void *)eeprom_buff;
667
668 if (eeprom->offset & 1) {
669 /* need read/modify/write of first changed EEPROM word */
670 /* only the second byte of the word is being modified */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000671 ret_val = hw->nvm.ops.read(hw, first_word, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800672 &eeprom_buff[0]);
673 ptr++;
674 }
675 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
676 /* need read/modify/write of last changed EEPROM word */
677 /* only the first byte of the word is being modified */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000678 ret_val = hw->nvm.ops.read(hw, last_word, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800679 &eeprom_buff[last_word - first_word]);
680 }
681
682 /* Device's eeprom is always little-endian, word addressable */
683 for (i = 0; i < last_word - first_word + 1; i++)
684 le16_to_cpus(&eeprom_buff[i]);
685
686 memcpy(ptr, bytes, eeprom->len);
687
688 for (i = 0; i < last_word - first_word + 1; i++)
689 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
690
Alexander Duyck312c75a2009-02-06 23:17:47 +0000691 ret_val = hw->nvm.ops.write(hw, first_word,
Auke Kok9d5c8242008-01-24 02:22:38 -0800692 last_word - first_word + 1, eeprom_buff);
693
694 /* Update the checksum over the first part of the EEPROM if needed
695 * and flush shadow RAM for 82573 controllers */
696 if ((ret_val == 0) && ((first_word <= NVM_CHECKSUM_REG)))
697 igb_update_nvm_checksum(hw);
698
699 kfree(eeprom_buff);
700 return ret_val;
701}
702
703static void igb_get_drvinfo(struct net_device *netdev,
704 struct ethtool_drvinfo *drvinfo)
705{
706 struct igb_adapter *adapter = netdev_priv(netdev);
707 char firmware_version[32];
708 u16 eeprom_data;
709
710 strncpy(drvinfo->driver, igb_driver_name, 32);
711 strncpy(drvinfo->version, igb_driver_version, 32);
712
713 /* EEPROM image version # is reported as firmware version # for
714 * 82575 controllers */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000715 adapter->hw.nvm.ops.read(&adapter->hw, 5, 1, &eeprom_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800716 sprintf(firmware_version, "%d.%d-%d",
717 (eeprom_data & 0xF000) >> 12,
718 (eeprom_data & 0x0FF0) >> 4,
719 eeprom_data & 0x000F);
720
721 strncpy(drvinfo->fw_version, firmware_version, 32);
722 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
723 drvinfo->n_stats = IGB_STATS_LEN;
724 drvinfo->testinfo_len = IGB_TEST_LEN;
725 drvinfo->regdump_len = igb_get_regs_len(netdev);
726 drvinfo->eedump_len = igb_get_eeprom_len(netdev);
727}
728
729static void igb_get_ringparam(struct net_device *netdev,
730 struct ethtool_ringparam *ring)
731{
732 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -0800733
734 ring->rx_max_pending = IGB_MAX_RXD;
735 ring->tx_max_pending = IGB_MAX_TXD;
736 ring->rx_mini_max_pending = 0;
737 ring->rx_jumbo_max_pending = 0;
Alexander Duyck68fd9912008-11-20 00:48:10 -0800738 ring->rx_pending = adapter->rx_ring_count;
739 ring->tx_pending = adapter->tx_ring_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800740 ring->rx_mini_pending = 0;
741 ring->rx_jumbo_pending = 0;
742}
743
744static int igb_set_ringparam(struct net_device *netdev,
745 struct ethtool_ringparam *ring)
746{
747 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800748 struct igb_ring *temp_ring;
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000749 int i, err = 0;
Alexander Duyck0e154392009-11-12 18:36:41 +0000750 u16 new_rx_count, new_tx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800751
752 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
753 return -EINVAL;
754
Alexander Duyck0e154392009-11-12 18:36:41 +0000755 new_rx_count = min_t(u32, ring->rx_pending, IGB_MAX_RXD);
756 new_rx_count = max_t(u16, new_rx_count, IGB_MIN_RXD);
Auke Kok9d5c8242008-01-24 02:22:38 -0800757 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
758
Alexander Duyck0e154392009-11-12 18:36:41 +0000759 new_tx_count = min_t(u32, ring->tx_pending, IGB_MAX_TXD);
760 new_tx_count = max_t(u16, new_tx_count, IGB_MIN_TXD);
Auke Kok9d5c8242008-01-24 02:22:38 -0800761 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
762
Alexander Duyck68fd9912008-11-20 00:48:10 -0800763 if ((new_tx_count == adapter->tx_ring_count) &&
764 (new_rx_count == adapter->rx_ring_count)) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800765 /* nothing to do */
766 return 0;
767 }
768
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000769 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
770 msleep(1);
771
772 if (!netif_running(adapter->netdev)) {
773 for (i = 0; i < adapter->num_tx_queues; i++)
774 adapter->tx_ring[i].count = new_tx_count;
775 for (i = 0; i < adapter->num_rx_queues; i++)
776 adapter->rx_ring[i].count = new_rx_count;
777 adapter->tx_ring_count = new_tx_count;
778 adapter->rx_ring_count = new_rx_count;
779 goto clear_reset;
780 }
781
Alexander Duyck68fd9912008-11-20 00:48:10 -0800782 if (adapter->num_tx_queues > adapter->num_rx_queues)
783 temp_ring = vmalloc(adapter->num_tx_queues * sizeof(struct igb_ring));
784 else
785 temp_ring = vmalloc(adapter->num_rx_queues * sizeof(struct igb_ring));
Alexander Duyck68fd9912008-11-20 00:48:10 -0800786
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000787 if (!temp_ring) {
788 err = -ENOMEM;
789 goto clear_reset;
790 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800791
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000792 igb_down(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800793
794 /*
795 * We can't just free everything and then setup again,
796 * because the ISRs in MSI-X mode get passed pointers
797 * to the tx and rx ring structs.
798 */
Alexander Duyck68fd9912008-11-20 00:48:10 -0800799 if (new_tx_count != adapter->tx_ring_count) {
800 memcpy(temp_ring, adapter->tx_ring,
801 adapter->num_tx_queues * sizeof(struct igb_ring));
802
Auke Kok9d5c8242008-01-24 02:22:38 -0800803 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800804 temp_ring[i].count = new_tx_count;
Alexander Duyck80785292009-10-27 15:51:47 +0000805 err = igb_setup_tx_resources(&temp_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800806 if (err) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800807 while (i) {
808 i--;
809 igb_free_tx_resources(&temp_ring[i]);
810 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800811 goto err_setup;
812 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800813 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800814
815 for (i = 0; i < adapter->num_tx_queues; i++)
816 igb_free_tx_resources(&adapter->tx_ring[i]);
817
818 memcpy(adapter->tx_ring, temp_ring,
819 adapter->num_tx_queues * sizeof(struct igb_ring));
820
821 adapter->tx_ring_count = new_tx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800822 }
823
824 if (new_rx_count != adapter->rx_ring->count) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800825 memcpy(temp_ring, adapter->rx_ring,
826 adapter->num_rx_queues * sizeof(struct igb_ring));
827
Auke Kok9d5c8242008-01-24 02:22:38 -0800828 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800829 temp_ring[i].count = new_rx_count;
Alexander Duyck80785292009-10-27 15:51:47 +0000830 err = igb_setup_rx_resources(&temp_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800831 if (err) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800832 while (i) {
833 i--;
834 igb_free_rx_resources(&temp_ring[i]);
835 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800836 goto err_setup;
837 }
838
Auke Kok9d5c8242008-01-24 02:22:38 -0800839 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800840
841 for (i = 0; i < adapter->num_rx_queues; i++)
842 igb_free_rx_resources(&adapter->rx_ring[i]);
843
844 memcpy(adapter->rx_ring, temp_ring,
845 adapter->num_rx_queues * sizeof(struct igb_ring));
846
847 adapter->rx_ring_count = new_rx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800848 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800849err_setup:
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000850 igb_up(adapter);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800851 vfree(temp_ring);
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000852clear_reset:
853 clear_bit(__IGB_RESETTING, &adapter->state);
Auke Kok9d5c8242008-01-24 02:22:38 -0800854 return err;
855}
856
857/* ethtool register test data */
858struct igb_reg_test {
859 u16 reg;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700860 u16 reg_offset;
861 u16 array_len;
862 u16 test_type;
Auke Kok9d5c8242008-01-24 02:22:38 -0800863 u32 mask;
864 u32 write;
865};
866
867/* In the hardware, registers are laid out either singly, in arrays
868 * spaced 0x100 bytes apart, or in contiguous tables. We assume
869 * most tests take place on arrays or single registers (handled
870 * as a single-element array) and special-case the tables.
871 * Table tests are always pattern tests.
872 *
873 * We also make provision for some required setup steps by specifying
874 * registers to be written without any read-back testing.
875 */
876
877#define PATTERN_TEST 1
878#define SET_READ_TEST 2
879#define WRITE_NO_TEST 3
880#define TABLE32_TEST 4
881#define TABLE64_TEST_LO 5
882#define TABLE64_TEST_HI 6
883
Alexander Duyck55cac242009-11-19 12:42:21 +0000884/* 82580 reg test */
885static struct igb_reg_test reg_test_82580[] = {
886 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
887 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
888 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
889 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
890 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
891 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
892 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
893 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
894 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
895 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
896 /* RDH is read-only for 82580, only test RDT. */
897 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
898 { E1000_RDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
899 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
900 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
901 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
902 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
903 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
904 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
905 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
906 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
907 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
908 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
909 { E1000_TDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
910 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
911 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
912 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
913 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
914 { E1000_RA, 0, 16, TABLE64_TEST_LO,
915 0xFFFFFFFF, 0xFFFFFFFF },
916 { E1000_RA, 0, 16, TABLE64_TEST_HI,
917 0x83FFFFFF, 0xFFFFFFFF },
918 { E1000_RA2, 0, 8, TABLE64_TEST_LO,
919 0xFFFFFFFF, 0xFFFFFFFF },
920 { E1000_RA2, 0, 8, TABLE64_TEST_HI,
921 0x83FFFFFF, 0xFFFFFFFF },
922 { E1000_MTA, 0, 128, TABLE32_TEST,
923 0xFFFFFFFF, 0xFFFFFFFF },
924 { 0, 0, 0, 0 }
925};
926
Alexander Duyck2d064c02008-07-08 15:10:12 -0700927/* 82576 reg test */
928static struct igb_reg_test reg_test_82576[] = {
929 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
930 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
931 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
932 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
933 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
934 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
935 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +0000936 { E1000_RDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
937 { E1000_RDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
938 { E1000_RDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
939 /* Enable all RX queues before testing. */
940 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE },
941 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE },
Alexander Duyck2d064c02008-07-08 15:10:12 -0700942 /* RDH is read-only for 82576, only test RDT. */
943 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +0000944 { E1000_RDT(4), 0x40, 12, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
Alexander Duyck2d064c02008-07-08 15:10:12 -0700945 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
Alexander Duyck2753f4c2009-02-06 23:18:48 +0000946 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0, 0 },
Alexander Duyck2d064c02008-07-08 15:10:12 -0700947 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
948 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
949 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
950 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
951 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
952 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +0000953 { E1000_TDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
954 { E1000_TDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
955 { E1000_TDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2d064c02008-07-08 15:10:12 -0700956 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
957 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
958 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
959 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
960 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
961 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF },
962 { E1000_RA2, 0, 8, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
963 { E1000_RA2, 0, 8, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF },
964 { E1000_MTA, 0, 128,TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
965 { 0, 0, 0, 0 }
966};
967
968/* 82575 register test */
969static struct igb_reg_test reg_test_82575[] = {
970 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
971 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
972 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
973 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
974 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
975 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
976 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
977 /* Enable all four RX queues before testing. */
978 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE },
Auke Kok9d5c8242008-01-24 02:22:38 -0800979 /* RDH is read-only for 82575, only test RDT. */
Alexander Duyck2d064c02008-07-08 15:10:12 -0700980 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
981 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
982 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
983 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
984 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
985 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
986 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
987 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
988 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
989 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0x003FFFFB },
990 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0xFFFFFFFF },
991 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
992 { E1000_TXCW, 0x100, 1, PATTERN_TEST, 0xC000FFFF, 0x0000FFFF },
993 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
994 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x800FFFFF, 0xFFFFFFFF },
995 { E1000_MTA, 0, 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Auke Kok9d5c8242008-01-24 02:22:38 -0800996 { 0, 0, 0, 0 }
997};
998
999static bool reg_pattern_test(struct igb_adapter *adapter, u64 *data,
1000 int reg, u32 mask, u32 write)
1001{
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001002 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001003 u32 pat, val;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001004 static const u32 _test[] =
Auke Kok9d5c8242008-01-24 02:22:38 -08001005 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
1006 for (pat = 0; pat < ARRAY_SIZE(_test); pat++) {
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001007 wr32(reg, (_test[pat] & write));
1008 val = rd32(reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001009 if (val != (_test[pat] & write & mask)) {
1010 dev_err(&adapter->pdev->dev, "pattern test reg %04X "
1011 "failed: got 0x%08X expected 0x%08X\n",
1012 reg, val, (_test[pat] & write & mask));
1013 *data = reg;
1014 return 1;
1015 }
1016 }
Alexander Duyck317f66b2009-10-27 23:46:20 +00001017
Auke Kok9d5c8242008-01-24 02:22:38 -08001018 return 0;
1019}
1020
1021static bool reg_set_and_check(struct igb_adapter *adapter, u64 *data,
1022 int reg, u32 mask, u32 write)
1023{
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001024 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001025 u32 val;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001026 wr32(reg, write & mask);
1027 val = rd32(reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001028 if ((write & mask) != (val & mask)) {
1029 dev_err(&adapter->pdev->dev, "set/check reg %04X test failed:"
1030 " got 0x%08X expected 0x%08X\n", reg,
1031 (val & mask), (write & mask));
1032 *data = reg;
1033 return 1;
1034 }
Alexander Duyck317f66b2009-10-27 23:46:20 +00001035
Auke Kok9d5c8242008-01-24 02:22:38 -08001036 return 0;
1037}
1038
1039#define REG_PATTERN_TEST(reg, mask, write) \
1040 do { \
1041 if (reg_pattern_test(adapter, data, reg, mask, write)) \
1042 return 1; \
1043 } while (0)
1044
1045#define REG_SET_AND_CHECK(reg, mask, write) \
1046 do { \
1047 if (reg_set_and_check(adapter, data, reg, mask, write)) \
1048 return 1; \
1049 } while (0)
1050
1051static int igb_reg_test(struct igb_adapter *adapter, u64 *data)
1052{
1053 struct e1000_hw *hw = &adapter->hw;
1054 struct igb_reg_test *test;
1055 u32 value, before, after;
1056 u32 i, toggle;
1057
Alexander Duyck2d064c02008-07-08 15:10:12 -07001058 switch (adapter->hw.mac.type) {
Alexander Duyck55cac242009-11-19 12:42:21 +00001059 case e1000_82580:
1060 test = reg_test_82580;
1061 toggle = 0x7FEFF3FF;
1062 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001063 case e1000_82576:
1064 test = reg_test_82576;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001065 toggle = 0x7FFFF3FF;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001066 break;
1067 default:
1068 test = reg_test_82575;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001069 toggle = 0x7FFFF3FF;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001070 break;
1071 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001072
1073 /* Because the status register is such a special case,
1074 * we handle it separately from the rest of the register
1075 * tests. Some bits are read-only, some toggle, and some
1076 * are writable on newer MACs.
1077 */
1078 before = rd32(E1000_STATUS);
1079 value = (rd32(E1000_STATUS) & toggle);
1080 wr32(E1000_STATUS, toggle);
1081 after = rd32(E1000_STATUS) & toggle;
1082 if (value != after) {
1083 dev_err(&adapter->pdev->dev, "failed STATUS register test "
1084 "got: 0x%08X expected: 0x%08X\n", after, value);
1085 *data = 1;
1086 return 1;
1087 }
1088 /* restore previous status */
1089 wr32(E1000_STATUS, before);
1090
1091 /* Perform the remainder of the register test, looping through
1092 * the test table until we either fail or reach the null entry.
1093 */
1094 while (test->reg) {
1095 for (i = 0; i < test->array_len; i++) {
1096 switch (test->test_type) {
1097 case PATTERN_TEST:
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001098 REG_PATTERN_TEST(test->reg +
1099 (i * test->reg_offset),
Auke Kok9d5c8242008-01-24 02:22:38 -08001100 test->mask,
1101 test->write);
1102 break;
1103 case SET_READ_TEST:
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001104 REG_SET_AND_CHECK(test->reg +
1105 (i * test->reg_offset),
Auke Kok9d5c8242008-01-24 02:22:38 -08001106 test->mask,
1107 test->write);
1108 break;
1109 case WRITE_NO_TEST:
1110 writel(test->write,
1111 (adapter->hw.hw_addr + test->reg)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001112 + (i * test->reg_offset));
Auke Kok9d5c8242008-01-24 02:22:38 -08001113 break;
1114 case TABLE32_TEST:
1115 REG_PATTERN_TEST(test->reg + (i * 4),
1116 test->mask,
1117 test->write);
1118 break;
1119 case TABLE64_TEST_LO:
1120 REG_PATTERN_TEST(test->reg + (i * 8),
1121 test->mask,
1122 test->write);
1123 break;
1124 case TABLE64_TEST_HI:
1125 REG_PATTERN_TEST((test->reg + 4) + (i * 8),
1126 test->mask,
1127 test->write);
1128 break;
1129 }
1130 }
1131 test++;
1132 }
1133
1134 *data = 0;
1135 return 0;
1136}
1137
1138static int igb_eeprom_test(struct igb_adapter *adapter, u64 *data)
1139{
1140 u16 temp;
1141 u16 checksum = 0;
1142 u16 i;
1143
1144 *data = 0;
1145 /* Read and add up the contents of the EEPROM */
1146 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
Alexander Duyck317f66b2009-10-27 23:46:20 +00001147 if ((adapter->hw.nvm.ops.read(&adapter->hw, i, 1, &temp)) < 0) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001148 *data = 1;
1149 break;
1150 }
1151 checksum += temp;
1152 }
1153
1154 /* If Checksum is not Correct return error else test passed */
1155 if ((checksum != (u16) NVM_SUM) && !(*data))
1156 *data = 2;
1157
1158 return *data;
1159}
1160
1161static irqreturn_t igb_test_intr(int irq, void *data)
1162{
Alexander Duyck317f66b2009-10-27 23:46:20 +00001163 struct igb_adapter *adapter = (struct igb_adapter *) data;
Auke Kok9d5c8242008-01-24 02:22:38 -08001164 struct e1000_hw *hw = &adapter->hw;
1165
1166 adapter->test_icr |= rd32(E1000_ICR);
1167
1168 return IRQ_HANDLED;
1169}
1170
1171static int igb_intr_test(struct igb_adapter *adapter, u64 *data)
1172{
1173 struct e1000_hw *hw = &adapter->hw;
1174 struct net_device *netdev = adapter->netdev;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001175 u32 mask, ics_mask, i = 0, shared_int = true;
Auke Kok9d5c8242008-01-24 02:22:38 -08001176 u32 irq = adapter->pdev->irq;
1177
1178 *data = 0;
1179
1180 /* Hook up test interrupt handler just for this test */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001181 if (adapter->msix_entries) {
1182 if (request_irq(adapter->msix_entries[0].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001183 igb_test_intr, 0, netdev->name, adapter)) {
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001184 *data = 1;
1185 return -1;
1186 }
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001187 } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001188 shared_int = false;
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001189 if (request_irq(irq,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001190 igb_test_intr, 0, netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001191 *data = 1;
1192 return -1;
1193 }
Joe Perchesa0607fd2009-11-18 23:29:17 -08001194 } else if (!request_irq(irq, igb_test_intr, IRQF_PROBE_SHARED,
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001195 netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001196 shared_int = false;
Joe Perchesa0607fd2009-11-18 23:29:17 -08001197 } else if (request_irq(irq, igb_test_intr, IRQF_SHARED,
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001198 netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001199 *data = 1;
1200 return -1;
1201 }
1202 dev_info(&adapter->pdev->dev, "testing %s interrupt\n",
1203 (shared_int ? "shared" : "unshared"));
Alexander Duyck317f66b2009-10-27 23:46:20 +00001204
Auke Kok9d5c8242008-01-24 02:22:38 -08001205 /* Disable all the interrupts */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001206 wr32(E1000_IMC, ~0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001207 msleep(10);
1208
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001209 /* Define all writable bits for ICS */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001210 switch (hw->mac.type) {
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001211 case e1000_82575:
1212 ics_mask = 0x37F47EDD;
1213 break;
1214 case e1000_82576:
1215 ics_mask = 0x77D4FBFD;
1216 break;
Alexander Duyck55cac242009-11-19 12:42:21 +00001217 case e1000_82580:
1218 ics_mask = 0x77DCFED5;
1219 break;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001220 default:
1221 ics_mask = 0x7FFFFFFF;
1222 break;
1223 }
1224
Auke Kok9d5c8242008-01-24 02:22:38 -08001225 /* Test each interrupt */
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001226 for (; i < 31; i++) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001227 /* Interrupt to test */
1228 mask = 1 << i;
1229
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001230 if (!(mask & ics_mask))
1231 continue;
1232
Auke Kok9d5c8242008-01-24 02:22:38 -08001233 if (!shared_int) {
1234 /* Disable the interrupt to be reported in
1235 * the cause register and then force the same
1236 * interrupt and see if one gets posted. If
1237 * an interrupt was posted to the bus, the
1238 * test failed.
1239 */
1240 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001241
1242 /* Flush any pending interrupts */
1243 wr32(E1000_ICR, ~0);
1244
1245 wr32(E1000_IMC, mask);
1246 wr32(E1000_ICS, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -08001247 msleep(10);
1248
1249 if (adapter->test_icr & mask) {
1250 *data = 3;
1251 break;
1252 }
1253 }
1254
1255 /* Enable 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 not posted to the bus, the
1259 * test failed.
1260 */
1261 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001262
1263 /* Flush any pending interrupts */
1264 wr32(E1000_ICR, ~0);
1265
Auke Kok9d5c8242008-01-24 02:22:38 -08001266 wr32(E1000_IMS, mask);
1267 wr32(E1000_ICS, mask);
1268 msleep(10);
1269
1270 if (!(adapter->test_icr & mask)) {
1271 *data = 4;
1272 break;
1273 }
1274
1275 if (!shared_int) {
1276 /* Disable the other interrupts to be reported in
1277 * the cause register and then force the other
1278 * interrupts and see if any get posted. If
1279 * an interrupt was posted to the bus, the
1280 * test failed.
1281 */
1282 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001283
1284 /* Flush any pending interrupts */
1285 wr32(E1000_ICR, ~0);
1286
1287 wr32(E1000_IMC, ~mask);
1288 wr32(E1000_ICS, ~mask);
Auke Kok9d5c8242008-01-24 02:22:38 -08001289 msleep(10);
1290
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001291 if (adapter->test_icr & mask) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001292 *data = 5;
1293 break;
1294 }
1295 }
1296 }
1297
1298 /* Disable all the interrupts */
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001299 wr32(E1000_IMC, ~0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001300 msleep(10);
1301
1302 /* Unhook test interrupt handler */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001303 if (adapter->msix_entries)
1304 free_irq(adapter->msix_entries[0].vector, adapter);
1305 else
1306 free_irq(irq, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001307
1308 return *data;
1309}
1310
1311static void igb_free_desc_rings(struct igb_adapter *adapter)
1312{
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001313 igb_free_tx_resources(&adapter->test_tx_ring);
1314 igb_free_rx_resources(&adapter->test_rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001315}
1316
1317static int igb_setup_desc_rings(struct igb_adapter *adapter)
1318{
Auke Kok9d5c8242008-01-24 02:22:38 -08001319 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1320 struct igb_ring *rx_ring = &adapter->test_rx_ring;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001321 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckad93d172009-10-27 15:55:02 +00001322 int ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001323
1324 /* Setup Tx descriptor ring and Tx buffers */
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001325 tx_ring->count = IGB_DEFAULT_TXD;
1326 tx_ring->pdev = adapter->pdev;
1327 tx_ring->netdev = adapter->netdev;
1328 tx_ring->reg_idx = adapter->vfs_allocated_count;
Auke Kok9d5c8242008-01-24 02:22:38 -08001329
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001330 if (igb_setup_tx_resources(tx_ring)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001331 ret_val = 1;
1332 goto err_nomem;
1333 }
1334
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001335 igb_setup_tctl(adapter);
1336 igb_configure_tx_ring(adapter, tx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001337
Auke Kok9d5c8242008-01-24 02:22:38 -08001338 /* Setup Rx descriptor ring and Rx buffers */
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001339 rx_ring->count = IGB_DEFAULT_RXD;
1340 rx_ring->pdev = adapter->pdev;
1341 rx_ring->netdev = adapter->netdev;
1342 rx_ring->rx_buffer_len = IGB_RXBUFFER_2048;
1343 rx_ring->reg_idx = adapter->vfs_allocated_count;
Auke Kok9d5c8242008-01-24 02:22:38 -08001344
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001345 if (igb_setup_rx_resources(rx_ring)) {
1346 ret_val = 3;
Auke Kok9d5c8242008-01-24 02:22:38 -08001347 goto err_nomem;
1348 }
1349
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001350 /* set the default queue to queue 0 of PF */
1351 wr32(E1000_MRQC, adapter->vfs_allocated_count << 3);
Auke Kok9d5c8242008-01-24 02:22:38 -08001352
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001353 /* enable receive ring */
1354 igb_setup_rctl(adapter);
1355 igb_configure_rx_ring(adapter, rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001356
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001357 igb_alloc_rx_buffers_adv(rx_ring, igb_desc_unused(rx_ring));
Auke Kok9d5c8242008-01-24 02:22:38 -08001358
1359 return 0;
1360
1361err_nomem:
1362 igb_free_desc_rings(adapter);
1363 return ret_val;
1364}
1365
1366static void igb_phy_disable_receiver(struct igb_adapter *adapter)
1367{
1368 struct e1000_hw *hw = &adapter->hw;
1369
1370 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001371 igb_write_phy_reg(hw, 29, 0x001F);
1372 igb_write_phy_reg(hw, 30, 0x8FFC);
1373 igb_write_phy_reg(hw, 29, 0x001A);
1374 igb_write_phy_reg(hw, 30, 0x8FF0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001375}
1376
1377static int igb_integrated_phy_loopback(struct igb_adapter *adapter)
1378{
1379 struct e1000_hw *hw = &adapter->hw;
1380 u32 ctrl_reg = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001381
1382 hw->mac.autoneg = false;
1383
1384 if (hw->phy.type == e1000_phy_m88) {
1385 /* Auto-MDI/MDIX Off */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001386 igb_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
Auke Kok9d5c8242008-01-24 02:22:38 -08001387 /* reset to update Auto-MDI/MDIX */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001388 igb_write_phy_reg(hw, PHY_CONTROL, 0x9140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001389 /* autoneg off */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001390 igb_write_phy_reg(hw, PHY_CONTROL, 0x8140);
Alexander Duyck55cac242009-11-19 12:42:21 +00001391 } else if (hw->phy.type == e1000_phy_82580) {
1392 /* enable MII loopback */
1393 igb_write_phy_reg(hw, I82580_PHY_LBK_CTRL, 0x8041);
Auke Kok9d5c8242008-01-24 02:22:38 -08001394 }
1395
1396 ctrl_reg = rd32(E1000_CTRL);
1397
1398 /* force 1000, set loopback */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001399 igb_write_phy_reg(hw, PHY_CONTROL, 0x4140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001400
1401 /* Now set up the MAC to the same speed/duplex as the PHY. */
1402 ctrl_reg = rd32(E1000_CTRL);
1403 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1404 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1405 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1406 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
Alexander Duyckcdfa9f62009-03-31 20:38:56 +00001407 E1000_CTRL_FD | /* Force Duplex to FULL */
1408 E1000_CTRL_SLU); /* Set link up enable bit */
Auke Kok9d5c8242008-01-24 02:22:38 -08001409
Alexander Duyckcdfa9f62009-03-31 20:38:56 +00001410 if (hw->phy.type == e1000_phy_m88)
Auke Kok9d5c8242008-01-24 02:22:38 -08001411 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kok9d5c8242008-01-24 02:22:38 -08001412
1413 wr32(E1000_CTRL, ctrl_reg);
1414
1415 /* Disable the receiver on the PHY so when a cable is plugged in, the
1416 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1417 */
1418 if (hw->phy.type == e1000_phy_m88)
1419 igb_phy_disable_receiver(adapter);
1420
1421 udelay(500);
1422
1423 return 0;
1424}
1425
1426static int igb_set_phy_loopback(struct igb_adapter *adapter)
1427{
1428 return igb_integrated_phy_loopback(adapter);
1429}
1430
1431static int igb_setup_loopback_test(struct igb_adapter *adapter)
1432{
1433 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001434 u32 reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001435
Alexander Duyck317f66b2009-10-27 23:46:20 +00001436 reg = rd32(E1000_CTRL_EXT);
1437
1438 /* use CTRL_EXT to identify link type as SGMII can appear as copper */
1439 if (reg & E1000_CTRL_EXT_LINK_MODE_MASK) {
Alexander Duyck2d064c02008-07-08 15:10:12 -07001440 reg = rd32(E1000_RCTL);
1441 reg |= E1000_RCTL_LBM_TCVR;
1442 wr32(E1000_RCTL, reg);
1443
1444 wr32(E1000_SCTL, E1000_ENABLE_SERDES_LOOPBACK);
1445
1446 reg = rd32(E1000_CTRL);
1447 reg &= ~(E1000_CTRL_RFCE |
1448 E1000_CTRL_TFCE |
1449 E1000_CTRL_LRST);
1450 reg |= E1000_CTRL_SLU |
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001451 E1000_CTRL_FD;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001452 wr32(E1000_CTRL, reg);
1453
1454 /* Unset switch control to serdes energy detect */
1455 reg = rd32(E1000_CONNSW);
1456 reg &= ~E1000_CONNSW_ENRGSRC;
1457 wr32(E1000_CONNSW, reg);
1458
1459 /* Set PCS register for forced speed */
1460 reg = rd32(E1000_PCS_LCTL);
1461 reg &= ~E1000_PCS_LCTL_AN_ENABLE; /* Disable Autoneg*/
1462 reg |= E1000_PCS_LCTL_FLV_LINK_UP | /* Force link up */
1463 E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1464 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
1465 E1000_PCS_LCTL_FSD | /* Force Speed */
1466 E1000_PCS_LCTL_FORCE_LINK; /* Force Link */
1467 wr32(E1000_PCS_LCTL, reg);
1468
Auke Kok9d5c8242008-01-24 02:22:38 -08001469 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001470 }
1471
Alexander Duyck317f66b2009-10-27 23:46:20 +00001472 return igb_set_phy_loopback(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001473}
1474
1475static void igb_loopback_cleanup(struct igb_adapter *adapter)
1476{
1477 struct e1000_hw *hw = &adapter->hw;
1478 u32 rctl;
1479 u16 phy_reg;
1480
1481 rctl = rd32(E1000_RCTL);
1482 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1483 wr32(E1000_RCTL, rctl);
1484
1485 hw->mac.autoneg = true;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001486 igb_read_phy_reg(hw, PHY_CONTROL, &phy_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001487 if (phy_reg & MII_CR_LOOPBACK) {
1488 phy_reg &= ~MII_CR_LOOPBACK;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001489 igb_write_phy_reg(hw, PHY_CONTROL, phy_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001490 igb_phy_sw_reset(hw);
1491 }
1492}
1493
1494static void igb_create_lbtest_frame(struct sk_buff *skb,
1495 unsigned int frame_size)
1496{
1497 memset(skb->data, 0xFF, frame_size);
Alexander Duyck317f66b2009-10-27 23:46:20 +00001498 frame_size /= 2;
1499 memset(&skb->data[frame_size], 0xAA, frame_size - 1);
1500 memset(&skb->data[frame_size + 10], 0xBE, 1);
1501 memset(&skb->data[frame_size + 12], 0xAF, 1);
Auke Kok9d5c8242008-01-24 02:22:38 -08001502}
1503
1504static int igb_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1505{
Alexander Duyck317f66b2009-10-27 23:46:20 +00001506 frame_size /= 2;
1507 if (*(skb->data + 3) == 0xFF) {
1508 if ((*(skb->data + frame_size + 10) == 0xBE) &&
1509 (*(skb->data + frame_size + 12) == 0xAF)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001510 return 0;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001511 }
1512 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001513 return 13;
1514}
1515
Alexander Duyckad93d172009-10-27 15:55:02 +00001516static int igb_clean_test_rings(struct igb_ring *rx_ring,
1517 struct igb_ring *tx_ring,
1518 unsigned int size)
1519{
1520 union e1000_adv_rx_desc *rx_desc;
1521 struct igb_buffer *buffer_info;
1522 int rx_ntc, tx_ntc, count = 0;
1523 u32 staterr;
1524
1525 /* initialize next to clean and descriptor values */
1526 rx_ntc = rx_ring->next_to_clean;
1527 tx_ntc = tx_ring->next_to_clean;
1528 rx_desc = E1000_RX_DESC_ADV(*rx_ring, rx_ntc);
1529 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1530
1531 while (staterr & E1000_RXD_STAT_DD) {
1532 /* check rx buffer */
1533 buffer_info = &rx_ring->buffer_info[rx_ntc];
1534
1535 /* unmap rx buffer, will be remapped by alloc_rx_buffers */
1536 pci_unmap_single(rx_ring->pdev,
1537 buffer_info->dma,
1538 rx_ring->rx_buffer_len,
1539 PCI_DMA_FROMDEVICE);
1540 buffer_info->dma = 0;
1541
1542 /* verify contents of skb */
1543 if (!igb_check_lbtest_frame(buffer_info->skb, size))
1544 count++;
1545
1546 /* unmap buffer on tx side */
1547 buffer_info = &tx_ring->buffer_info[tx_ntc];
1548 igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
1549
1550 /* increment rx/tx next to clean counters */
1551 rx_ntc++;
1552 if (rx_ntc == rx_ring->count)
1553 rx_ntc = 0;
1554 tx_ntc++;
1555 if (tx_ntc == tx_ring->count)
1556 tx_ntc = 0;
1557
1558 /* fetch next descriptor */
1559 rx_desc = E1000_RX_DESC_ADV(*rx_ring, rx_ntc);
1560 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1561 }
1562
1563 /* re-map buffers to ring, store next to clean values */
1564 igb_alloc_rx_buffers_adv(rx_ring, count);
1565 rx_ring->next_to_clean = rx_ntc;
1566 tx_ring->next_to_clean = tx_ntc;
1567
1568 return count;
1569}
1570
Auke Kok9d5c8242008-01-24 02:22:38 -08001571static int igb_run_loopback_test(struct igb_adapter *adapter)
1572{
Auke Kok9d5c8242008-01-24 02:22:38 -08001573 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1574 struct igb_ring *rx_ring = &adapter->test_rx_ring;
Alexander Duyckad93d172009-10-27 15:55:02 +00001575 int i, j, lc, good_cnt, ret_val = 0;
1576 unsigned int size = 1024;
1577 netdev_tx_t tx_ret_val;
1578 struct sk_buff *skb;
Auke Kok9d5c8242008-01-24 02:22:38 -08001579
Alexander Duyckad93d172009-10-27 15:55:02 +00001580 /* allocate test skb */
1581 skb = alloc_skb(size, GFP_KERNEL);
1582 if (!skb)
1583 return 11;
1584
1585 /* place data into test skb */
1586 igb_create_lbtest_frame(skb, size);
1587 skb_put(skb, size);
Auke Kok9d5c8242008-01-24 02:22:38 -08001588
Alexander Duyck317f66b2009-10-27 23:46:20 +00001589 /*
1590 * Calculate the loop count based on the largest descriptor ring
Auke Kok9d5c8242008-01-24 02:22:38 -08001591 * The idea is to wrap the largest ring a number of times using 64
1592 * send/receive pairs during each loop
1593 */
1594
1595 if (rx_ring->count <= tx_ring->count)
1596 lc = ((tx_ring->count / 64) * 2) + 1;
1597 else
1598 lc = ((rx_ring->count / 64) * 2) + 1;
1599
Auke Kok9d5c8242008-01-24 02:22:38 -08001600 for (j = 0; j <= lc; j++) { /* loop count loop */
Alexander Duyckad93d172009-10-27 15:55:02 +00001601 /* reset count of good packets */
Auke Kok9d5c8242008-01-24 02:22:38 -08001602 good_cnt = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001603
Alexander Duyckad93d172009-10-27 15:55:02 +00001604 /* place 64 packets on the transmit queue*/
1605 for (i = 0; i < 64; i++) {
1606 skb_get(skb);
1607 tx_ret_val = igb_xmit_frame_ring_adv(skb, tx_ring);
1608 if (tx_ret_val == NETDEV_TX_OK)
Auke Kok9d5c8242008-01-24 02:22:38 -08001609 good_cnt++;
Alexander Duyckad93d172009-10-27 15:55:02 +00001610 }
1611
Auke Kok9d5c8242008-01-24 02:22:38 -08001612 if (good_cnt != 64) {
Alexander Duyckad93d172009-10-27 15:55:02 +00001613 ret_val = 12;
Auke Kok9d5c8242008-01-24 02:22:38 -08001614 break;
1615 }
Alexander Duyckad93d172009-10-27 15:55:02 +00001616
1617 /* allow 200 milliseconds for packets to go from tx to rx */
1618 msleep(200);
1619
1620 good_cnt = igb_clean_test_rings(rx_ring, tx_ring, size);
1621 if (good_cnt != 64) {
1622 ret_val = 13;
Auke Kok9d5c8242008-01-24 02:22:38 -08001623 break;
1624 }
1625 } /* end loop count loop */
Alexander Duyckad93d172009-10-27 15:55:02 +00001626
1627 /* free the original skb */
1628 kfree_skb(skb);
1629
Auke Kok9d5c8242008-01-24 02:22:38 -08001630 return ret_val;
1631}
1632
1633static int igb_loopback_test(struct igb_adapter *adapter, u64 *data)
1634{
1635 /* PHY loopback cannot be performed if SoL/IDER
1636 * sessions are active */
1637 if (igb_check_reset_block(&adapter->hw)) {
1638 dev_err(&adapter->pdev->dev,
1639 "Cannot do PHY loopback test "
1640 "when SoL/IDER is active.\n");
1641 *data = 0;
1642 goto out;
1643 }
1644 *data = igb_setup_desc_rings(adapter);
1645 if (*data)
1646 goto out;
1647 *data = igb_setup_loopback_test(adapter);
1648 if (*data)
1649 goto err_loopback;
1650 *data = igb_run_loopback_test(adapter);
1651 igb_loopback_cleanup(adapter);
1652
1653err_loopback:
1654 igb_free_desc_rings(adapter);
1655out:
1656 return *data;
1657}
1658
1659static int igb_link_test(struct igb_adapter *adapter, u64 *data)
1660{
1661 struct e1000_hw *hw = &adapter->hw;
1662 *data = 0;
1663 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1664 int i = 0;
1665 hw->mac.serdes_has_link = false;
1666
1667 /* On some blade server designs, link establishment
1668 * could take as long as 2-3 minutes */
1669 do {
1670 hw->mac.ops.check_for_link(&adapter->hw);
1671 if (hw->mac.serdes_has_link)
1672 return *data;
1673 msleep(20);
1674 } while (i++ < 3750);
1675
1676 *data = 1;
1677 } else {
1678 hw->mac.ops.check_for_link(&adapter->hw);
1679 if (hw->mac.autoneg)
1680 msleep(4000);
1681
Alexander Duyck317f66b2009-10-27 23:46:20 +00001682 if (!(rd32(E1000_STATUS) & E1000_STATUS_LU))
Auke Kok9d5c8242008-01-24 02:22:38 -08001683 *data = 1;
1684 }
1685 return *data;
1686}
1687
1688static void igb_diag_test(struct net_device *netdev,
1689 struct ethtool_test *eth_test, u64 *data)
1690{
1691 struct igb_adapter *adapter = netdev_priv(netdev);
1692 u16 autoneg_advertised;
1693 u8 forced_speed_duplex, autoneg;
1694 bool if_running = netif_running(netdev);
1695
1696 set_bit(__IGB_TESTING, &adapter->state);
1697 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1698 /* Offline tests */
1699
1700 /* save speed, duplex, autoneg settings */
1701 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1702 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1703 autoneg = adapter->hw.mac.autoneg;
1704
1705 dev_info(&adapter->pdev->dev, "offline testing starting\n");
1706
1707 /* Link test performed before hardware reset so autoneg doesn't
1708 * interfere with test result */
1709 if (igb_link_test(adapter, &data[4]))
1710 eth_test->flags |= ETH_TEST_FL_FAILED;
1711
1712 if (if_running)
1713 /* indicate we're in test mode */
1714 dev_close(netdev);
1715 else
1716 igb_reset(adapter);
1717
1718 if (igb_reg_test(adapter, &data[0]))
1719 eth_test->flags |= ETH_TEST_FL_FAILED;
1720
1721 igb_reset(adapter);
1722 if (igb_eeprom_test(adapter, &data[1]))
1723 eth_test->flags |= ETH_TEST_FL_FAILED;
1724
1725 igb_reset(adapter);
1726 if (igb_intr_test(adapter, &data[2]))
1727 eth_test->flags |= ETH_TEST_FL_FAILED;
1728
1729 igb_reset(adapter);
1730 if (igb_loopback_test(adapter, &data[3]))
1731 eth_test->flags |= ETH_TEST_FL_FAILED;
1732
1733 /* restore speed, duplex, autoneg settings */
1734 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1735 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1736 adapter->hw.mac.autoneg = autoneg;
1737
1738 /* force this routine to wait until autoneg complete/timeout */
1739 adapter->hw.phy.autoneg_wait_to_complete = true;
1740 igb_reset(adapter);
1741 adapter->hw.phy.autoneg_wait_to_complete = false;
1742
1743 clear_bit(__IGB_TESTING, &adapter->state);
1744 if (if_running)
1745 dev_open(netdev);
1746 } else {
1747 dev_info(&adapter->pdev->dev, "online testing starting\n");
1748 /* Online tests */
1749 if (igb_link_test(adapter, &data[4]))
1750 eth_test->flags |= ETH_TEST_FL_FAILED;
1751
1752 /* Online tests aren't run; pass by default */
1753 data[0] = 0;
1754 data[1] = 0;
1755 data[2] = 0;
1756 data[3] = 0;
1757
1758 clear_bit(__IGB_TESTING, &adapter->state);
1759 }
1760 msleep_interruptible(4 * 1000);
1761}
1762
1763static int igb_wol_exclusion(struct igb_adapter *adapter,
1764 struct ethtool_wolinfo *wol)
1765{
1766 struct e1000_hw *hw = &adapter->hw;
1767 int retval = 1; /* fail by default */
1768
1769 switch (hw->device_id) {
1770 case E1000_DEV_ID_82575GB_QUAD_COPPER:
1771 /* WoL not supported */
1772 wol->supported = 0;
1773 break;
1774 case E1000_DEV_ID_82575EB_FIBER_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -07001775 case E1000_DEV_ID_82576_FIBER:
1776 case E1000_DEV_ID_82576_SERDES:
Auke Kok9d5c8242008-01-24 02:22:38 -08001777 /* Wake events not supported on port B */
1778 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1) {
1779 wol->supported = 0;
1780 break;
1781 }
1782 /* return success for non excluded adapter ports */
1783 retval = 0;
1784 break;
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +00001785 case E1000_DEV_ID_82576_QUAD_COPPER:
1786 /* quad port adapters only support WoL on port A */
1787 if (!(adapter->flags & IGB_FLAG_QUAD_PORT_A)) {
1788 wol->supported = 0;
1789 break;
1790 }
1791 /* return success for non excluded adapter ports */
1792 retval = 0;
1793 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08001794 default:
1795 /* dual port cards only support WoL on port A from now on
1796 * unless it was enabled in the eeprom for port B
1797 * so exclude FUNC_1 ports from having WoL enabled */
1798 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1 &&
1799 !adapter->eeprom_wol) {
1800 wol->supported = 0;
1801 break;
1802 }
1803
1804 retval = 0;
1805 }
1806
1807 return retval;
1808}
1809
1810static void igb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1811{
1812 struct igb_adapter *adapter = netdev_priv(netdev);
1813
1814 wol->supported = WAKE_UCAST | WAKE_MCAST |
1815 WAKE_BCAST | WAKE_MAGIC;
1816 wol->wolopts = 0;
1817
1818 /* this function will set ->supported = 0 and return 1 if wol is not
1819 * supported by this hardware */
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00001820 if (igb_wol_exclusion(adapter, wol) ||
1821 !device_can_wakeup(&adapter->pdev->dev))
Auke Kok9d5c8242008-01-24 02:22:38 -08001822 return;
1823
1824 /* apply any specific unsupported masks here */
1825 switch (adapter->hw.device_id) {
1826 default:
1827 break;
1828 }
1829
1830 if (adapter->wol & E1000_WUFC_EX)
1831 wol->wolopts |= WAKE_UCAST;
1832 if (adapter->wol & E1000_WUFC_MC)
1833 wol->wolopts |= WAKE_MCAST;
1834 if (adapter->wol & E1000_WUFC_BC)
1835 wol->wolopts |= WAKE_BCAST;
1836 if (adapter->wol & E1000_WUFC_MAG)
1837 wol->wolopts |= WAKE_MAGIC;
1838
1839 return;
1840}
1841
1842static int igb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1843{
1844 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001845
1846 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1847 return -EOPNOTSUPP;
1848
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00001849 if (igb_wol_exclusion(adapter, wol) ||
1850 !device_can_wakeup(&adapter->pdev->dev))
Auke Kok9d5c8242008-01-24 02:22:38 -08001851 return wol->wolopts ? -EOPNOTSUPP : 0;
1852
Auke Kok9d5c8242008-01-24 02:22:38 -08001853 /* these settings will always override what we currently have */
1854 adapter->wol = 0;
1855
1856 if (wol->wolopts & WAKE_UCAST)
1857 adapter->wol |= E1000_WUFC_EX;
1858 if (wol->wolopts & WAKE_MCAST)
1859 adapter->wol |= E1000_WUFC_MC;
1860 if (wol->wolopts & WAKE_BCAST)
1861 adapter->wol |= E1000_WUFC_BC;
1862 if (wol->wolopts & WAKE_MAGIC)
1863 adapter->wol |= E1000_WUFC_MAG;
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00001864 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1865
Auke Kok9d5c8242008-01-24 02:22:38 -08001866 return 0;
1867}
1868
Auke Kok9d5c8242008-01-24 02:22:38 -08001869/* bit defines for adapter->led_status */
1870#define IGB_LED_ON 0
1871
1872static int igb_phys_id(struct net_device *netdev, u32 data)
1873{
1874 struct igb_adapter *adapter = netdev_priv(netdev);
1875 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001876 unsigned long timeout;
Auke Kok9d5c8242008-01-24 02:22:38 -08001877
Alexander Duyck317f66b2009-10-27 23:46:20 +00001878 timeout = data * 1000;
1879
1880 /*
1881 * msleep_interruptable only accepts unsigned int so we are limited
1882 * in how long a duration we can wait
1883 */
1884 if (!timeout || timeout > UINT_MAX)
1885 timeout = UINT_MAX;
Auke Kok9d5c8242008-01-24 02:22:38 -08001886
1887 igb_blink_led(hw);
Alexander Duyck317f66b2009-10-27 23:46:20 +00001888 msleep_interruptible(timeout);
Auke Kok9d5c8242008-01-24 02:22:38 -08001889
1890 igb_led_off(hw);
1891 clear_bit(IGB_LED_ON, &adapter->led_status);
1892 igb_cleanup_led(hw);
1893
1894 return 0;
1895}
1896
1897static int igb_set_coalesce(struct net_device *netdev,
1898 struct ethtool_coalesce *ec)
1899{
1900 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07001901 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08001902
1903 if ((ec->rx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
1904 ((ec->rx_coalesce_usecs > 3) &&
1905 (ec->rx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
1906 (ec->rx_coalesce_usecs == 2))
1907 return -EINVAL;
1908
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001909 if ((ec->tx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
1910 ((ec->tx_coalesce_usecs > 3) &&
1911 (ec->tx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
1912 (ec->tx_coalesce_usecs == 2))
1913 return -EINVAL;
1914
1915 if ((adapter->flags & IGB_FLAG_QUEUE_PAIRS) && ec->tx_coalesce_usecs)
1916 return -EINVAL;
1917
Auke Kok9d5c8242008-01-24 02:22:38 -08001918 /* convert to rate of irq's per second */
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001919 if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3)
1920 adapter->rx_itr_setting = ec->rx_coalesce_usecs;
1921 else
1922 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
1923
1924 /* convert to rate of irq's per second */
1925 if (adapter->flags & IGB_FLAG_QUEUE_PAIRS)
1926 adapter->tx_itr_setting = adapter->rx_itr_setting;
1927 else if (ec->tx_coalesce_usecs && ec->tx_coalesce_usecs <= 3)
1928 adapter->tx_itr_setting = ec->tx_coalesce_usecs;
1929 else
1930 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
Auke Kok9d5c8242008-01-24 02:22:38 -08001931
Alexander Duyck047e0032009-10-27 15:49:27 +00001932 for (i = 0; i < adapter->num_q_vectors; i++) {
1933 struct igb_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001934 if (q_vector->rx_ring)
1935 q_vector->itr_val = adapter->rx_itr_setting;
1936 else
1937 q_vector->itr_val = adapter->tx_itr_setting;
1938 if (q_vector->itr_val && q_vector->itr_val <= 3)
1939 q_vector->itr_val = IGB_START_ITR;
Alexander Duyck047e0032009-10-27 15:49:27 +00001940 q_vector->set_itr = 1;
1941 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001942
1943 return 0;
1944}
1945
1946static int igb_get_coalesce(struct net_device *netdev,
1947 struct ethtool_coalesce *ec)
1948{
1949 struct igb_adapter *adapter = netdev_priv(netdev);
1950
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001951 if (adapter->rx_itr_setting <= 3)
1952 ec->rx_coalesce_usecs = adapter->rx_itr_setting;
Auke Kok9d5c8242008-01-24 02:22:38 -08001953 else
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001954 ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
1955
1956 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS)) {
1957 if (adapter->tx_itr_setting <= 3)
1958 ec->tx_coalesce_usecs = adapter->tx_itr_setting;
1959 else
1960 ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
1961 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001962
1963 return 0;
1964}
1965
Auke Kok9d5c8242008-01-24 02:22:38 -08001966static int igb_nway_reset(struct net_device *netdev)
1967{
1968 struct igb_adapter *adapter = netdev_priv(netdev);
1969 if (netif_running(netdev))
1970 igb_reinit_locked(adapter);
1971 return 0;
1972}
1973
1974static int igb_get_sset_count(struct net_device *netdev, int sset)
1975{
1976 switch (sset) {
1977 case ETH_SS_STATS:
1978 return IGB_STATS_LEN;
1979 case ETH_SS_TEST:
1980 return IGB_TEST_LEN;
1981 default:
1982 return -ENOTSUPP;
1983 }
1984}
1985
1986static void igb_get_ethtool_stats(struct net_device *netdev,
1987 struct ethtool_stats *stats, u64 *data)
1988{
1989 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck128e45e2009-11-12 18:37:38 +00001990 struct net_device_stats *net_stats = &netdev->stats;
Auke Kok9d5c8242008-01-24 02:22:38 -08001991 u64 *queue_stat;
Alexander Duyck128e45e2009-11-12 18:37:38 +00001992 int i, j, k;
1993 char *p;
Auke Kok9d5c8242008-01-24 02:22:38 -08001994
1995 igb_update_stats(adapter);
Alexander Duyck317f66b2009-10-27 23:46:20 +00001996
Auke Kok9d5c8242008-01-24 02:22:38 -08001997 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
Alexander Duyck128e45e2009-11-12 18:37:38 +00001998 p = (char *)adapter + igb_gstrings_stats[i].stat_offset;
Auke Kok9d5c8242008-01-24 02:22:38 -08001999 data[i] = (igb_gstrings_stats[i].sizeof_stat ==
2000 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2001 }
Alexander Duyck128e45e2009-11-12 18:37:38 +00002002 for (j = 0; j < IGB_NETDEV_STATS_LEN; j++, i++) {
2003 p = (char *)net_stats + igb_gstrings_net_stats[j].stat_offset;
2004 data[i] = (igb_gstrings_net_stats[j].sizeof_stat ==
2005 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2006 }
Alexander Duycke21ed352008-07-08 15:07:24 -07002007 for (j = 0; j < adapter->num_tx_queues; j++) {
Alexander Duycke21ed352008-07-08 15:07:24 -07002008 queue_stat = (u64 *)&adapter->tx_ring[j].tx_stats;
Alexander Duyck128e45e2009-11-12 18:37:38 +00002009 for (k = 0; k < IGB_TX_QUEUE_STATS_LEN; k++, i++)
2010 data[i] = queue_stat[k];
Alexander Duycke21ed352008-07-08 15:07:24 -07002011 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002012 for (j = 0; j < adapter->num_rx_queues; j++) {
Auke Kok9d5c8242008-01-24 02:22:38 -08002013 queue_stat = (u64 *)&adapter->rx_ring[j].rx_stats;
Alexander Duyck128e45e2009-11-12 18:37:38 +00002014 for (k = 0; k < IGB_RX_QUEUE_STATS_LEN; k++, i++)
2015 data[i] = queue_stat[k];
Auke Kok9d5c8242008-01-24 02:22:38 -08002016 }
2017}
2018
2019static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
2020{
2021 struct igb_adapter *adapter = netdev_priv(netdev);
2022 u8 *p = data;
2023 int i;
2024
2025 switch (stringset) {
2026 case ETH_SS_TEST:
2027 memcpy(data, *igb_gstrings_test,
2028 IGB_TEST_LEN*ETH_GSTRING_LEN);
2029 break;
2030 case ETH_SS_STATS:
2031 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
2032 memcpy(p, igb_gstrings_stats[i].stat_string,
2033 ETH_GSTRING_LEN);
2034 p += ETH_GSTRING_LEN;
2035 }
Alexander Duyck128e45e2009-11-12 18:37:38 +00002036 for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) {
2037 memcpy(p, igb_gstrings_net_stats[i].stat_string,
2038 ETH_GSTRING_LEN);
2039 p += ETH_GSTRING_LEN;
2040 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002041 for (i = 0; i < adapter->num_tx_queues; i++) {
2042 sprintf(p, "tx_queue_%u_packets", i);
2043 p += ETH_GSTRING_LEN;
2044 sprintf(p, "tx_queue_%u_bytes", i);
2045 p += ETH_GSTRING_LEN;
Alexander Duyck04a5fca2009-10-27 15:52:27 +00002046 sprintf(p, "tx_queue_%u_restart", i);
2047 p += ETH_GSTRING_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002048 }
2049 for (i = 0; i < adapter->num_rx_queues; i++) {
2050 sprintf(p, "rx_queue_%u_packets", i);
2051 p += ETH_GSTRING_LEN;
2052 sprintf(p, "rx_queue_%u_bytes", i);
2053 p += ETH_GSTRING_LEN;
Jesper Dangaard Brouer8c0ab702009-05-26 13:50:31 +00002054 sprintf(p, "rx_queue_%u_drops", i);
2055 p += ETH_GSTRING_LEN;
Alexander Duyck04a5fca2009-10-27 15:52:27 +00002056 sprintf(p, "rx_queue_%u_csum_err", i);
2057 p += ETH_GSTRING_LEN;
2058 sprintf(p, "rx_queue_%u_alloc_failed", i);
2059 p += ETH_GSTRING_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002060 }
2061/* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
2062 break;
2063 }
2064}
2065
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07002066static const struct ethtool_ops igb_ethtool_ops = {
Auke Kok9d5c8242008-01-24 02:22:38 -08002067 .get_settings = igb_get_settings,
2068 .set_settings = igb_set_settings,
2069 .get_drvinfo = igb_get_drvinfo,
2070 .get_regs_len = igb_get_regs_len,
2071 .get_regs = igb_get_regs,
2072 .get_wol = igb_get_wol,
2073 .set_wol = igb_set_wol,
2074 .get_msglevel = igb_get_msglevel,
2075 .set_msglevel = igb_set_msglevel,
2076 .nway_reset = igb_nway_reset,
2077 .get_link = ethtool_op_get_link,
2078 .get_eeprom_len = igb_get_eeprom_len,
2079 .get_eeprom = igb_get_eeprom,
2080 .set_eeprom = igb_set_eeprom,
2081 .get_ringparam = igb_get_ringparam,
2082 .set_ringparam = igb_set_ringparam,
2083 .get_pauseparam = igb_get_pauseparam,
2084 .set_pauseparam = igb_set_pauseparam,
2085 .get_rx_csum = igb_get_rx_csum,
2086 .set_rx_csum = igb_set_rx_csum,
2087 .get_tx_csum = igb_get_tx_csum,
2088 .set_tx_csum = igb_set_tx_csum,
2089 .get_sg = ethtool_op_get_sg,
2090 .set_sg = ethtool_op_set_sg,
2091 .get_tso = ethtool_op_get_tso,
2092 .set_tso = igb_set_tso,
2093 .self_test = igb_diag_test,
2094 .get_strings = igb_get_strings,
2095 .phys_id = igb_phys_id,
2096 .get_sset_count = igb_get_sset_count,
2097 .get_ethtool_stats = igb_get_ethtool_stats,
2098 .get_coalesce = igb_get_coalesce,
2099 .set_coalesce = igb_set_coalesce,
2100};
2101
2102void igb_set_ethtool_ops(struct net_device *netdev)
2103{
2104 SET_ETHTOOL_OPS(netdev, &igb_ethtool_ops);
2105}