blob: 485288303f327e3202f4e7f7934beacb2e4d507a [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
Nick Nunley31455352010-02-17 01:01:21 +0000237static u32 igb_get_link(struct net_device *netdev)
238{
239 struct igb_adapter *adapter = netdev_priv(netdev);
240 struct e1000_mac_info *mac = &adapter->hw.mac;
241
242 /*
243 * If the link is not reported up to netdev, interrupts are disabled,
244 * and so the physical link state may have changed since we last
245 * looked. Set get_link_status to make sure that the true link
246 * state is interrogated, rather than pulling a cached and possibly
247 * stale link state from the driver.
248 */
249 if (!netif_carrier_ok(netdev))
250 mac->get_link_status = 1;
251
252 return igb_has_link(adapter);
253}
254
Auke Kok9d5c8242008-01-24 02:22:38 -0800255static void igb_get_pauseparam(struct net_device *netdev,
256 struct ethtool_pauseparam *pause)
257{
258 struct igb_adapter *adapter = netdev_priv(netdev);
259 struct e1000_hw *hw = &adapter->hw;
260
261 pause->autoneg =
262 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
263
Alexander Duyck0cce1192009-07-23 18:10:24 +0000264 if (hw->fc.current_mode == e1000_fc_rx_pause)
Auke Kok9d5c8242008-01-24 02:22:38 -0800265 pause->rx_pause = 1;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000266 else if (hw->fc.current_mode == e1000_fc_tx_pause)
Auke Kok9d5c8242008-01-24 02:22:38 -0800267 pause->tx_pause = 1;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000268 else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800269 pause->rx_pause = 1;
270 pause->tx_pause = 1;
271 }
272}
273
274static int igb_set_pauseparam(struct net_device *netdev,
275 struct ethtool_pauseparam *pause)
276{
277 struct igb_adapter *adapter = netdev_priv(netdev);
278 struct e1000_hw *hw = &adapter->hw;
279 int retval = 0;
280
281 adapter->fc_autoneg = pause->autoneg;
282
283 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
284 msleep(1);
285
Auke Kok9d5c8242008-01-24 02:22:38 -0800286 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000287 hw->fc.requested_mode = e1000_fc_default;
Auke Kok9d5c8242008-01-24 02:22:38 -0800288 if (netif_running(adapter->netdev)) {
289 igb_down(adapter);
290 igb_up(adapter);
Alexander Duyck317f66b2009-10-27 23:46:20 +0000291 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -0800292 igb_reset(adapter);
Alexander Duyck317f66b2009-10-27 23:46:20 +0000293 }
Alexander Duyck0cce1192009-07-23 18:10:24 +0000294 } else {
295 if (pause->rx_pause && pause->tx_pause)
296 hw->fc.requested_mode = e1000_fc_full;
297 else if (pause->rx_pause && !pause->tx_pause)
298 hw->fc.requested_mode = e1000_fc_rx_pause;
299 else if (!pause->rx_pause && pause->tx_pause)
300 hw->fc.requested_mode = e1000_fc_tx_pause;
301 else if (!pause->rx_pause && !pause->tx_pause)
302 hw->fc.requested_mode = e1000_fc_none;
303
304 hw->fc.current_mode = hw->fc.requested_mode;
305
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000306 retval = ((hw->phy.media_type == e1000_media_type_copper) ?
307 igb_force_mac_fc(hw) : igb_setup_link(hw));
Alexander Duyck0cce1192009-07-23 18:10:24 +0000308 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800309
310 clear_bit(__IGB_RESETTING, &adapter->state);
311 return retval;
312}
313
314static u32 igb_get_rx_csum(struct net_device *netdev)
315{
316 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck85ad76b2009-10-27 15:52:46 +0000317 return !!(adapter->rx_ring[0].flags & IGB_RING_FLAG_RX_CSUM);
Auke Kok9d5c8242008-01-24 02:22:38 -0800318}
319
320static int igb_set_rx_csum(struct net_device *netdev, u32 data)
321{
322 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck85ad76b2009-10-27 15:52:46 +0000323 int i;
Alexander Duyck7beb0142009-05-06 10:25:23 +0000324
Alexander Duyck85ad76b2009-10-27 15:52:46 +0000325 for (i = 0; i < adapter->num_rx_queues; i++) {
326 if (data)
327 adapter->rx_ring[i].flags |= IGB_RING_FLAG_RX_CSUM;
328 else
329 adapter->rx_ring[i].flags &= ~IGB_RING_FLAG_RX_CSUM;
330 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800331
332 return 0;
333}
334
335static u32 igb_get_tx_csum(struct net_device *netdev)
336{
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000337 return (netdev->features & NETIF_F_IP_CSUM) != 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800338}
339
340static int igb_set_tx_csum(struct net_device *netdev, u32 data)
341{
Jesse Brandeburgb9473562009-04-27 22:36:13 +0000342 struct igb_adapter *adapter = netdev_priv(netdev);
343
344 if (data) {
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000345 netdev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
Alexander Duyck317f66b2009-10-27 23:46:20 +0000346 if (adapter->hw.mac.type >= e1000_82576)
Jesse Brandeburgb9473562009-04-27 22:36:13 +0000347 netdev->features |= NETIF_F_SCTP_CSUM;
348 } else {
349 netdev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
350 NETIF_F_SCTP_CSUM);
351 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800352
353 return 0;
354}
355
356static int igb_set_tso(struct net_device *netdev, u32 data)
357{
358 struct igb_adapter *adapter = netdev_priv(netdev);
359
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000360 if (data) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800361 netdev->features |= NETIF_F_TSO;
Auke Kok9d5c8242008-01-24 02:22:38 -0800362 netdev->features |= NETIF_F_TSO6;
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000363 } else {
364 netdev->features &= ~NETIF_F_TSO;
Auke Kok9d5c8242008-01-24 02:22:38 -0800365 netdev->features &= ~NETIF_F_TSO6;
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000366 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800367
368 dev_info(&adapter->pdev->dev, "TSO is %s\n",
369 data ? "Enabled" : "Disabled");
370 return 0;
371}
372
373static u32 igb_get_msglevel(struct net_device *netdev)
374{
375 struct igb_adapter *adapter = netdev_priv(netdev);
376 return adapter->msg_enable;
377}
378
379static void igb_set_msglevel(struct net_device *netdev, u32 data)
380{
381 struct igb_adapter *adapter = netdev_priv(netdev);
382 adapter->msg_enable = data;
383}
384
385static int igb_get_regs_len(struct net_device *netdev)
386{
387#define IGB_REGS_LEN 551
388 return IGB_REGS_LEN * sizeof(u32);
389}
390
391static void igb_get_regs(struct net_device *netdev,
392 struct ethtool_regs *regs, void *p)
393{
394 struct igb_adapter *adapter = netdev_priv(netdev);
395 struct e1000_hw *hw = &adapter->hw;
396 u32 *regs_buff = p;
397 u8 i;
398
399 memset(p, 0, IGB_REGS_LEN * sizeof(u32));
400
401 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
402
403 /* General Registers */
404 regs_buff[0] = rd32(E1000_CTRL);
405 regs_buff[1] = rd32(E1000_STATUS);
406 regs_buff[2] = rd32(E1000_CTRL_EXT);
407 regs_buff[3] = rd32(E1000_MDIC);
408 regs_buff[4] = rd32(E1000_SCTL);
409 regs_buff[5] = rd32(E1000_CONNSW);
410 regs_buff[6] = rd32(E1000_VET);
411 regs_buff[7] = rd32(E1000_LEDCTL);
412 regs_buff[8] = rd32(E1000_PBA);
413 regs_buff[9] = rd32(E1000_PBS);
414 regs_buff[10] = rd32(E1000_FRTIMER);
415 regs_buff[11] = rd32(E1000_TCPTIMER);
416
417 /* NVM Register */
418 regs_buff[12] = rd32(E1000_EECD);
419
420 /* Interrupt */
Alexander Duyckfe59de32008-08-26 04:25:05 -0700421 /* Reading EICS for EICR because they read the
422 * same but EICS does not clear on read */
423 regs_buff[13] = rd32(E1000_EICS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800424 regs_buff[14] = rd32(E1000_EICS);
425 regs_buff[15] = rd32(E1000_EIMS);
426 regs_buff[16] = rd32(E1000_EIMC);
427 regs_buff[17] = rd32(E1000_EIAC);
428 regs_buff[18] = rd32(E1000_EIAM);
Alexander Duyckfe59de32008-08-26 04:25:05 -0700429 /* Reading ICS for ICR because they read the
430 * same but ICS does not clear on read */
431 regs_buff[19] = rd32(E1000_ICS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800432 regs_buff[20] = rd32(E1000_ICS);
433 regs_buff[21] = rd32(E1000_IMS);
434 regs_buff[22] = rd32(E1000_IMC);
435 regs_buff[23] = rd32(E1000_IAC);
436 regs_buff[24] = rd32(E1000_IAM);
437 regs_buff[25] = rd32(E1000_IMIRVP);
438
439 /* Flow Control */
440 regs_buff[26] = rd32(E1000_FCAL);
441 regs_buff[27] = rd32(E1000_FCAH);
442 regs_buff[28] = rd32(E1000_FCTTV);
443 regs_buff[29] = rd32(E1000_FCRTL);
444 regs_buff[30] = rd32(E1000_FCRTH);
445 regs_buff[31] = rd32(E1000_FCRTV);
446
447 /* Receive */
448 regs_buff[32] = rd32(E1000_RCTL);
449 regs_buff[33] = rd32(E1000_RXCSUM);
450 regs_buff[34] = rd32(E1000_RLPML);
451 regs_buff[35] = rd32(E1000_RFCTL);
452 regs_buff[36] = rd32(E1000_MRQC);
Alexander Duycke1739522009-02-19 20:39:44 -0800453 regs_buff[37] = rd32(E1000_VT_CTL);
Auke Kok9d5c8242008-01-24 02:22:38 -0800454
455 /* Transmit */
456 regs_buff[38] = rd32(E1000_TCTL);
457 regs_buff[39] = rd32(E1000_TCTL_EXT);
458 regs_buff[40] = rd32(E1000_TIPG);
459 regs_buff[41] = rd32(E1000_DTXCTL);
460
461 /* Wake Up */
462 regs_buff[42] = rd32(E1000_WUC);
463 regs_buff[43] = rd32(E1000_WUFC);
464 regs_buff[44] = rd32(E1000_WUS);
465 regs_buff[45] = rd32(E1000_IPAV);
466 regs_buff[46] = rd32(E1000_WUPL);
467
468 /* MAC */
469 regs_buff[47] = rd32(E1000_PCS_CFG0);
470 regs_buff[48] = rd32(E1000_PCS_LCTL);
471 regs_buff[49] = rd32(E1000_PCS_LSTAT);
472 regs_buff[50] = rd32(E1000_PCS_ANADV);
473 regs_buff[51] = rd32(E1000_PCS_LPAB);
474 regs_buff[52] = rd32(E1000_PCS_NPTX);
475 regs_buff[53] = rd32(E1000_PCS_LPABNP);
476
477 /* Statistics */
478 regs_buff[54] = adapter->stats.crcerrs;
479 regs_buff[55] = adapter->stats.algnerrc;
480 regs_buff[56] = adapter->stats.symerrs;
481 regs_buff[57] = adapter->stats.rxerrc;
482 regs_buff[58] = adapter->stats.mpc;
483 regs_buff[59] = adapter->stats.scc;
484 regs_buff[60] = adapter->stats.ecol;
485 regs_buff[61] = adapter->stats.mcc;
486 regs_buff[62] = adapter->stats.latecol;
487 regs_buff[63] = adapter->stats.colc;
488 regs_buff[64] = adapter->stats.dc;
489 regs_buff[65] = adapter->stats.tncrs;
490 regs_buff[66] = adapter->stats.sec;
491 regs_buff[67] = adapter->stats.htdpmc;
492 regs_buff[68] = adapter->stats.rlec;
493 regs_buff[69] = adapter->stats.xonrxc;
494 regs_buff[70] = adapter->stats.xontxc;
495 regs_buff[71] = adapter->stats.xoffrxc;
496 regs_buff[72] = adapter->stats.xofftxc;
497 regs_buff[73] = adapter->stats.fcruc;
498 regs_buff[74] = adapter->stats.prc64;
499 regs_buff[75] = adapter->stats.prc127;
500 regs_buff[76] = adapter->stats.prc255;
501 regs_buff[77] = adapter->stats.prc511;
502 regs_buff[78] = adapter->stats.prc1023;
503 regs_buff[79] = adapter->stats.prc1522;
504 regs_buff[80] = adapter->stats.gprc;
505 regs_buff[81] = adapter->stats.bprc;
506 regs_buff[82] = adapter->stats.mprc;
507 regs_buff[83] = adapter->stats.gptc;
508 regs_buff[84] = adapter->stats.gorc;
509 regs_buff[86] = adapter->stats.gotc;
510 regs_buff[88] = adapter->stats.rnbc;
511 regs_buff[89] = adapter->stats.ruc;
512 regs_buff[90] = adapter->stats.rfc;
513 regs_buff[91] = adapter->stats.roc;
514 regs_buff[92] = adapter->stats.rjc;
515 regs_buff[93] = adapter->stats.mgprc;
516 regs_buff[94] = adapter->stats.mgpdc;
517 regs_buff[95] = adapter->stats.mgptc;
518 regs_buff[96] = adapter->stats.tor;
519 regs_buff[98] = adapter->stats.tot;
520 regs_buff[100] = adapter->stats.tpr;
521 regs_buff[101] = adapter->stats.tpt;
522 regs_buff[102] = adapter->stats.ptc64;
523 regs_buff[103] = adapter->stats.ptc127;
524 regs_buff[104] = adapter->stats.ptc255;
525 regs_buff[105] = adapter->stats.ptc511;
526 regs_buff[106] = adapter->stats.ptc1023;
527 regs_buff[107] = adapter->stats.ptc1522;
528 regs_buff[108] = adapter->stats.mptc;
529 regs_buff[109] = adapter->stats.bptc;
530 regs_buff[110] = adapter->stats.tsctc;
531 regs_buff[111] = adapter->stats.iac;
532 regs_buff[112] = adapter->stats.rpthc;
533 regs_buff[113] = adapter->stats.hgptc;
534 regs_buff[114] = adapter->stats.hgorc;
535 regs_buff[116] = adapter->stats.hgotc;
536 regs_buff[118] = adapter->stats.lenerrs;
537 regs_buff[119] = adapter->stats.scvpc;
538 regs_buff[120] = adapter->stats.hrmpc;
539
Auke Kok9d5c8242008-01-24 02:22:38 -0800540 for (i = 0; i < 4; i++)
541 regs_buff[121 + i] = rd32(E1000_SRRCTL(i));
542 for (i = 0; i < 4; i++)
Alexander Duyck83ab50a2009-10-27 15:55:41 +0000543 regs_buff[125 + i] = rd32(E1000_PSRTYPE(i));
Auke Kok9d5c8242008-01-24 02:22:38 -0800544 for (i = 0; i < 4; i++)
545 regs_buff[129 + i] = rd32(E1000_RDBAL(i));
546 for (i = 0; i < 4; i++)
547 regs_buff[133 + i] = rd32(E1000_RDBAH(i));
548 for (i = 0; i < 4; i++)
549 regs_buff[137 + i] = rd32(E1000_RDLEN(i));
550 for (i = 0; i < 4; i++)
551 regs_buff[141 + i] = rd32(E1000_RDH(i));
552 for (i = 0; i < 4; i++)
553 regs_buff[145 + i] = rd32(E1000_RDT(i));
554 for (i = 0; i < 4; i++)
555 regs_buff[149 + i] = rd32(E1000_RXDCTL(i));
556
557 for (i = 0; i < 10; i++)
558 regs_buff[153 + i] = rd32(E1000_EITR(i));
559 for (i = 0; i < 8; i++)
560 regs_buff[163 + i] = rd32(E1000_IMIR(i));
561 for (i = 0; i < 8; i++)
562 regs_buff[171 + i] = rd32(E1000_IMIREXT(i));
563 for (i = 0; i < 16; i++)
564 regs_buff[179 + i] = rd32(E1000_RAL(i));
565 for (i = 0; i < 16; i++)
566 regs_buff[195 + i] = rd32(E1000_RAH(i));
567
568 for (i = 0; i < 4; i++)
569 regs_buff[211 + i] = rd32(E1000_TDBAL(i));
570 for (i = 0; i < 4; i++)
571 regs_buff[215 + i] = rd32(E1000_TDBAH(i));
572 for (i = 0; i < 4; i++)
573 regs_buff[219 + i] = rd32(E1000_TDLEN(i));
574 for (i = 0; i < 4; i++)
575 regs_buff[223 + i] = rd32(E1000_TDH(i));
576 for (i = 0; i < 4; i++)
577 regs_buff[227 + i] = rd32(E1000_TDT(i));
578 for (i = 0; i < 4; i++)
579 regs_buff[231 + i] = rd32(E1000_TXDCTL(i));
580 for (i = 0; i < 4; i++)
581 regs_buff[235 + i] = rd32(E1000_TDWBAL(i));
582 for (i = 0; i < 4; i++)
583 regs_buff[239 + i] = rd32(E1000_TDWBAH(i));
584 for (i = 0; i < 4; i++)
585 regs_buff[243 + i] = rd32(E1000_DCA_TXCTRL(i));
586
587 for (i = 0; i < 4; i++)
588 regs_buff[247 + i] = rd32(E1000_IP4AT_REG(i));
589 for (i = 0; i < 4; i++)
590 regs_buff[251 + i] = rd32(E1000_IP6AT_REG(i));
591 for (i = 0; i < 32; i++)
592 regs_buff[255 + i] = rd32(E1000_WUPM_REG(i));
593 for (i = 0; i < 128; i++)
594 regs_buff[287 + i] = rd32(E1000_FFMT_REG(i));
595 for (i = 0; i < 128; i++)
596 regs_buff[415 + i] = rd32(E1000_FFVT_REG(i));
597 for (i = 0; i < 4; i++)
598 regs_buff[543 + i] = rd32(E1000_FFLT_REG(i));
599
600 regs_buff[547] = rd32(E1000_TDFH);
601 regs_buff[548] = rd32(E1000_TDFT);
602 regs_buff[549] = rd32(E1000_TDFHS);
603 regs_buff[550] = rd32(E1000_TDFPC);
604
605}
606
607static int igb_get_eeprom_len(struct net_device *netdev)
608{
609 struct igb_adapter *adapter = netdev_priv(netdev);
610 return adapter->hw.nvm.word_size * 2;
611}
612
613static int igb_get_eeprom(struct net_device *netdev,
614 struct ethtool_eeprom *eeprom, u8 *bytes)
615{
616 struct igb_adapter *adapter = netdev_priv(netdev);
617 struct e1000_hw *hw = &adapter->hw;
618 u16 *eeprom_buff;
619 int first_word, last_word;
620 int ret_val = 0;
621 u16 i;
622
623 if (eeprom->len == 0)
624 return -EINVAL;
625
626 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
627
628 first_word = eeprom->offset >> 1;
629 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
630
631 eeprom_buff = kmalloc(sizeof(u16) *
632 (last_word - first_word + 1), GFP_KERNEL);
633 if (!eeprom_buff)
634 return -ENOMEM;
635
636 if (hw->nvm.type == e1000_nvm_eeprom_spi)
Alexander Duyck312c75a2009-02-06 23:17:47 +0000637 ret_val = hw->nvm.ops.read(hw, first_word,
Auke Kok9d5c8242008-01-24 02:22:38 -0800638 last_word - first_word + 1,
639 eeprom_buff);
640 else {
641 for (i = 0; i < last_word - first_word + 1; i++) {
Alexander Duyck312c75a2009-02-06 23:17:47 +0000642 ret_val = hw->nvm.ops.read(hw, first_word + i, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800643 &eeprom_buff[i]);
644 if (ret_val)
645 break;
646 }
647 }
648
649 /* Device's eeprom is always little-endian, word addressable */
650 for (i = 0; i < last_word - first_word + 1; i++)
651 le16_to_cpus(&eeprom_buff[i]);
652
653 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
654 eeprom->len);
655 kfree(eeprom_buff);
656
657 return ret_val;
658}
659
660static int igb_set_eeprom(struct net_device *netdev,
661 struct ethtool_eeprom *eeprom, u8 *bytes)
662{
663 struct igb_adapter *adapter = netdev_priv(netdev);
664 struct e1000_hw *hw = &adapter->hw;
665 u16 *eeprom_buff;
666 void *ptr;
667 int max_len, first_word, last_word, ret_val = 0;
668 u16 i;
669
670 if (eeprom->len == 0)
671 return -EOPNOTSUPP;
672
673 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
674 return -EFAULT;
675
676 max_len = hw->nvm.word_size * 2;
677
678 first_word = eeprom->offset >> 1;
679 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
680 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
681 if (!eeprom_buff)
682 return -ENOMEM;
683
684 ptr = (void *)eeprom_buff;
685
686 if (eeprom->offset & 1) {
687 /* need read/modify/write of first changed EEPROM word */
688 /* only the second byte of the word is being modified */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000689 ret_val = hw->nvm.ops.read(hw, first_word, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800690 &eeprom_buff[0]);
691 ptr++;
692 }
693 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
694 /* need read/modify/write of last changed EEPROM word */
695 /* only the first byte of the word is being modified */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000696 ret_val = hw->nvm.ops.read(hw, last_word, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800697 &eeprom_buff[last_word - first_word]);
698 }
699
700 /* Device's eeprom is always little-endian, word addressable */
701 for (i = 0; i < last_word - first_word + 1; i++)
702 le16_to_cpus(&eeprom_buff[i]);
703
704 memcpy(ptr, bytes, eeprom->len);
705
706 for (i = 0; i < last_word - first_word + 1; i++)
707 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
708
Alexander Duyck312c75a2009-02-06 23:17:47 +0000709 ret_val = hw->nvm.ops.write(hw, first_word,
Auke Kok9d5c8242008-01-24 02:22:38 -0800710 last_word - first_word + 1, eeprom_buff);
711
712 /* Update the checksum over the first part of the EEPROM if needed
713 * and flush shadow RAM for 82573 controllers */
714 if ((ret_val == 0) && ((first_word <= NVM_CHECKSUM_REG)))
715 igb_update_nvm_checksum(hw);
716
717 kfree(eeprom_buff);
718 return ret_val;
719}
720
721static void igb_get_drvinfo(struct net_device *netdev,
722 struct ethtool_drvinfo *drvinfo)
723{
724 struct igb_adapter *adapter = netdev_priv(netdev);
725 char firmware_version[32];
726 u16 eeprom_data;
727
728 strncpy(drvinfo->driver, igb_driver_name, 32);
729 strncpy(drvinfo->version, igb_driver_version, 32);
730
731 /* EEPROM image version # is reported as firmware version # for
732 * 82575 controllers */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000733 adapter->hw.nvm.ops.read(&adapter->hw, 5, 1, &eeprom_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800734 sprintf(firmware_version, "%d.%d-%d",
735 (eeprom_data & 0xF000) >> 12,
736 (eeprom_data & 0x0FF0) >> 4,
737 eeprom_data & 0x000F);
738
739 strncpy(drvinfo->fw_version, firmware_version, 32);
740 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
741 drvinfo->n_stats = IGB_STATS_LEN;
742 drvinfo->testinfo_len = IGB_TEST_LEN;
743 drvinfo->regdump_len = igb_get_regs_len(netdev);
744 drvinfo->eedump_len = igb_get_eeprom_len(netdev);
745}
746
747static void igb_get_ringparam(struct net_device *netdev,
748 struct ethtool_ringparam *ring)
749{
750 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -0800751
752 ring->rx_max_pending = IGB_MAX_RXD;
753 ring->tx_max_pending = IGB_MAX_TXD;
754 ring->rx_mini_max_pending = 0;
755 ring->rx_jumbo_max_pending = 0;
Alexander Duyck68fd9912008-11-20 00:48:10 -0800756 ring->rx_pending = adapter->rx_ring_count;
757 ring->tx_pending = adapter->tx_ring_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800758 ring->rx_mini_pending = 0;
759 ring->rx_jumbo_pending = 0;
760}
761
762static int igb_set_ringparam(struct net_device *netdev,
763 struct ethtool_ringparam *ring)
764{
765 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800766 struct igb_ring *temp_ring;
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000767 int i, err = 0;
Alexander Duyck0e154392009-11-12 18:36:41 +0000768 u16 new_rx_count, new_tx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800769
770 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
771 return -EINVAL;
772
Alexander Duyck0e154392009-11-12 18:36:41 +0000773 new_rx_count = min_t(u32, ring->rx_pending, IGB_MAX_RXD);
774 new_rx_count = max_t(u16, new_rx_count, IGB_MIN_RXD);
Auke Kok9d5c8242008-01-24 02:22:38 -0800775 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
776
Alexander Duyck0e154392009-11-12 18:36:41 +0000777 new_tx_count = min_t(u32, ring->tx_pending, IGB_MAX_TXD);
778 new_tx_count = max_t(u16, new_tx_count, IGB_MIN_TXD);
Auke Kok9d5c8242008-01-24 02:22:38 -0800779 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
780
Alexander Duyck68fd9912008-11-20 00:48:10 -0800781 if ((new_tx_count == adapter->tx_ring_count) &&
782 (new_rx_count == adapter->rx_ring_count)) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800783 /* nothing to do */
784 return 0;
785 }
786
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000787 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
788 msleep(1);
789
790 if (!netif_running(adapter->netdev)) {
791 for (i = 0; i < adapter->num_tx_queues; i++)
792 adapter->tx_ring[i].count = new_tx_count;
793 for (i = 0; i < adapter->num_rx_queues; i++)
794 adapter->rx_ring[i].count = new_rx_count;
795 adapter->tx_ring_count = new_tx_count;
796 adapter->rx_ring_count = new_rx_count;
797 goto clear_reset;
798 }
799
Alexander Duyck68fd9912008-11-20 00:48:10 -0800800 if (adapter->num_tx_queues > adapter->num_rx_queues)
801 temp_ring = vmalloc(adapter->num_tx_queues * sizeof(struct igb_ring));
802 else
803 temp_ring = vmalloc(adapter->num_rx_queues * sizeof(struct igb_ring));
Alexander Duyck68fd9912008-11-20 00:48:10 -0800804
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000805 if (!temp_ring) {
806 err = -ENOMEM;
807 goto clear_reset;
808 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800809
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000810 igb_down(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800811
812 /*
813 * We can't just free everything and then setup again,
814 * because the ISRs in MSI-X mode get passed pointers
815 * to the tx and rx ring structs.
816 */
Alexander Duyck68fd9912008-11-20 00:48:10 -0800817 if (new_tx_count != adapter->tx_ring_count) {
818 memcpy(temp_ring, adapter->tx_ring,
819 adapter->num_tx_queues * sizeof(struct igb_ring));
820
Auke Kok9d5c8242008-01-24 02:22:38 -0800821 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800822 temp_ring[i].count = new_tx_count;
Alexander Duyck80785292009-10-27 15:51:47 +0000823 err = igb_setup_tx_resources(&temp_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800824 if (err) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800825 while (i) {
826 i--;
827 igb_free_tx_resources(&temp_ring[i]);
828 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800829 goto err_setup;
830 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800831 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800832
833 for (i = 0; i < adapter->num_tx_queues; i++)
834 igb_free_tx_resources(&adapter->tx_ring[i]);
835
836 memcpy(adapter->tx_ring, temp_ring,
837 adapter->num_tx_queues * sizeof(struct igb_ring));
838
839 adapter->tx_ring_count = new_tx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800840 }
841
842 if (new_rx_count != adapter->rx_ring->count) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800843 memcpy(temp_ring, adapter->rx_ring,
844 adapter->num_rx_queues * sizeof(struct igb_ring));
845
Auke Kok9d5c8242008-01-24 02:22:38 -0800846 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800847 temp_ring[i].count = new_rx_count;
Alexander Duyck80785292009-10-27 15:51:47 +0000848 err = igb_setup_rx_resources(&temp_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800849 if (err) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800850 while (i) {
851 i--;
852 igb_free_rx_resources(&temp_ring[i]);
853 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800854 goto err_setup;
855 }
856
Auke Kok9d5c8242008-01-24 02:22:38 -0800857 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800858
859 for (i = 0; i < adapter->num_rx_queues; i++)
860 igb_free_rx_resources(&adapter->rx_ring[i]);
861
862 memcpy(adapter->rx_ring, temp_ring,
863 adapter->num_rx_queues * sizeof(struct igb_ring));
864
865 adapter->rx_ring_count = new_rx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800866 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800867err_setup:
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000868 igb_up(adapter);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800869 vfree(temp_ring);
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000870clear_reset:
871 clear_bit(__IGB_RESETTING, &adapter->state);
Auke Kok9d5c8242008-01-24 02:22:38 -0800872 return err;
873}
874
875/* ethtool register test data */
876struct igb_reg_test {
877 u16 reg;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700878 u16 reg_offset;
879 u16 array_len;
880 u16 test_type;
Auke Kok9d5c8242008-01-24 02:22:38 -0800881 u32 mask;
882 u32 write;
883};
884
885/* In the hardware, registers are laid out either singly, in arrays
886 * spaced 0x100 bytes apart, or in contiguous tables. We assume
887 * most tests take place on arrays or single registers (handled
888 * as a single-element array) and special-case the tables.
889 * Table tests are always pattern tests.
890 *
891 * We also make provision for some required setup steps by specifying
892 * registers to be written without any read-back testing.
893 */
894
895#define PATTERN_TEST 1
896#define SET_READ_TEST 2
897#define WRITE_NO_TEST 3
898#define TABLE32_TEST 4
899#define TABLE64_TEST_LO 5
900#define TABLE64_TEST_HI 6
901
Alexander Duyck55cac242009-11-19 12:42:21 +0000902/* 82580 reg test */
903static struct igb_reg_test reg_test_82580[] = {
904 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
905 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
906 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
907 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
908 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
909 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
910 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
911 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
912 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
913 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
914 /* RDH is read-only for 82580, only test RDT. */
915 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
916 { E1000_RDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
917 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
918 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
919 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
920 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
921 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
922 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
923 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
924 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
925 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
926 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
927 { E1000_TDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
928 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
929 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
930 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
931 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
932 { E1000_RA, 0, 16, TABLE64_TEST_LO,
933 0xFFFFFFFF, 0xFFFFFFFF },
934 { E1000_RA, 0, 16, TABLE64_TEST_HI,
935 0x83FFFFFF, 0xFFFFFFFF },
936 { E1000_RA2, 0, 8, TABLE64_TEST_LO,
937 0xFFFFFFFF, 0xFFFFFFFF },
938 { E1000_RA2, 0, 8, TABLE64_TEST_HI,
939 0x83FFFFFF, 0xFFFFFFFF },
940 { E1000_MTA, 0, 128, TABLE32_TEST,
941 0xFFFFFFFF, 0xFFFFFFFF },
942 { 0, 0, 0, 0 }
943};
944
Alexander Duyck2d064c02008-07-08 15:10:12 -0700945/* 82576 reg test */
946static struct igb_reg_test reg_test_82576[] = {
947 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
948 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
949 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
950 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
951 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
952 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
953 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +0000954 { E1000_RDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
955 { E1000_RDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
956 { E1000_RDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
957 /* Enable all RX queues before testing. */
958 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE },
959 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE },
Alexander Duyck2d064c02008-07-08 15:10:12 -0700960 /* RDH is read-only for 82576, only test RDT. */
961 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +0000962 { E1000_RDT(4), 0x40, 12, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
Alexander Duyck2d064c02008-07-08 15:10:12 -0700963 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
Alexander Duyck2753f4c2009-02-06 23:18:48 +0000964 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0, 0 },
Alexander Duyck2d064c02008-07-08 15:10:12 -0700965 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
966 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
967 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
968 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
969 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
970 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +0000971 { E1000_TDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
972 { E1000_TDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
973 { E1000_TDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2d064c02008-07-08 15:10:12 -0700974 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
975 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
976 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
977 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
978 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
979 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF },
980 { E1000_RA2, 0, 8, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
981 { E1000_RA2, 0, 8, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF },
982 { E1000_MTA, 0, 128,TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
983 { 0, 0, 0, 0 }
984};
985
986/* 82575 register test */
987static struct igb_reg_test reg_test_82575[] = {
988 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
989 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
990 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
991 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
992 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
993 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
994 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
995 /* Enable all four RX queues before testing. */
996 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE },
Auke Kok9d5c8242008-01-24 02:22:38 -0800997 /* RDH is read-only for 82575, only test RDT. */
Alexander Duyck2d064c02008-07-08 15:10:12 -0700998 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
999 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
1000 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1001 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1002 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1003 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1004 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1005 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1006 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1007 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0x003FFFFB },
1008 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0xFFFFFFFF },
1009 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1010 { E1000_TXCW, 0x100, 1, PATTERN_TEST, 0xC000FFFF, 0x0000FFFF },
1011 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
1012 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x800FFFFF, 0xFFFFFFFF },
1013 { E1000_MTA, 0, 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Auke Kok9d5c8242008-01-24 02:22:38 -08001014 { 0, 0, 0, 0 }
1015};
1016
1017static bool reg_pattern_test(struct igb_adapter *adapter, u64 *data,
1018 int reg, u32 mask, u32 write)
1019{
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001020 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001021 u32 pat, val;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001022 static const u32 _test[] =
Auke Kok9d5c8242008-01-24 02:22:38 -08001023 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
1024 for (pat = 0; pat < ARRAY_SIZE(_test); pat++) {
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001025 wr32(reg, (_test[pat] & write));
1026 val = rd32(reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001027 if (val != (_test[pat] & write & mask)) {
1028 dev_err(&adapter->pdev->dev, "pattern test reg %04X "
1029 "failed: got 0x%08X expected 0x%08X\n",
1030 reg, val, (_test[pat] & write & mask));
1031 *data = reg;
1032 return 1;
1033 }
1034 }
Alexander Duyck317f66b2009-10-27 23:46:20 +00001035
Auke Kok9d5c8242008-01-24 02:22:38 -08001036 return 0;
1037}
1038
1039static bool reg_set_and_check(struct igb_adapter *adapter, u64 *data,
1040 int reg, u32 mask, u32 write)
1041{
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001042 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001043 u32 val;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001044 wr32(reg, write & mask);
1045 val = rd32(reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001046 if ((write & mask) != (val & mask)) {
1047 dev_err(&adapter->pdev->dev, "set/check reg %04X test failed:"
1048 " got 0x%08X expected 0x%08X\n", reg,
1049 (val & mask), (write & mask));
1050 *data = reg;
1051 return 1;
1052 }
Alexander Duyck317f66b2009-10-27 23:46:20 +00001053
Auke Kok9d5c8242008-01-24 02:22:38 -08001054 return 0;
1055}
1056
1057#define REG_PATTERN_TEST(reg, mask, write) \
1058 do { \
1059 if (reg_pattern_test(adapter, data, reg, mask, write)) \
1060 return 1; \
1061 } while (0)
1062
1063#define REG_SET_AND_CHECK(reg, mask, write) \
1064 do { \
1065 if (reg_set_and_check(adapter, data, reg, mask, write)) \
1066 return 1; \
1067 } while (0)
1068
1069static int igb_reg_test(struct igb_adapter *adapter, u64 *data)
1070{
1071 struct e1000_hw *hw = &adapter->hw;
1072 struct igb_reg_test *test;
1073 u32 value, before, after;
1074 u32 i, toggle;
1075
Alexander Duyck2d064c02008-07-08 15:10:12 -07001076 switch (adapter->hw.mac.type) {
Alexander Duyck55cac242009-11-19 12:42:21 +00001077 case e1000_82580:
1078 test = reg_test_82580;
1079 toggle = 0x7FEFF3FF;
1080 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001081 case e1000_82576:
1082 test = reg_test_82576;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001083 toggle = 0x7FFFF3FF;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001084 break;
1085 default:
1086 test = reg_test_82575;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001087 toggle = 0x7FFFF3FF;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001088 break;
1089 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001090
1091 /* Because the status register is such a special case,
1092 * we handle it separately from the rest of the register
1093 * tests. Some bits are read-only, some toggle, and some
1094 * are writable on newer MACs.
1095 */
1096 before = rd32(E1000_STATUS);
1097 value = (rd32(E1000_STATUS) & toggle);
1098 wr32(E1000_STATUS, toggle);
1099 after = rd32(E1000_STATUS) & toggle;
1100 if (value != after) {
1101 dev_err(&adapter->pdev->dev, "failed STATUS register test "
1102 "got: 0x%08X expected: 0x%08X\n", after, value);
1103 *data = 1;
1104 return 1;
1105 }
1106 /* restore previous status */
1107 wr32(E1000_STATUS, before);
1108
1109 /* Perform the remainder of the register test, looping through
1110 * the test table until we either fail or reach the null entry.
1111 */
1112 while (test->reg) {
1113 for (i = 0; i < test->array_len; i++) {
1114 switch (test->test_type) {
1115 case PATTERN_TEST:
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001116 REG_PATTERN_TEST(test->reg +
1117 (i * test->reg_offset),
Auke Kok9d5c8242008-01-24 02:22:38 -08001118 test->mask,
1119 test->write);
1120 break;
1121 case SET_READ_TEST:
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001122 REG_SET_AND_CHECK(test->reg +
1123 (i * test->reg_offset),
Auke Kok9d5c8242008-01-24 02:22:38 -08001124 test->mask,
1125 test->write);
1126 break;
1127 case WRITE_NO_TEST:
1128 writel(test->write,
1129 (adapter->hw.hw_addr + test->reg)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001130 + (i * test->reg_offset));
Auke Kok9d5c8242008-01-24 02:22:38 -08001131 break;
1132 case TABLE32_TEST:
1133 REG_PATTERN_TEST(test->reg + (i * 4),
1134 test->mask,
1135 test->write);
1136 break;
1137 case TABLE64_TEST_LO:
1138 REG_PATTERN_TEST(test->reg + (i * 8),
1139 test->mask,
1140 test->write);
1141 break;
1142 case TABLE64_TEST_HI:
1143 REG_PATTERN_TEST((test->reg + 4) + (i * 8),
1144 test->mask,
1145 test->write);
1146 break;
1147 }
1148 }
1149 test++;
1150 }
1151
1152 *data = 0;
1153 return 0;
1154}
1155
1156static int igb_eeprom_test(struct igb_adapter *adapter, u64 *data)
1157{
1158 u16 temp;
1159 u16 checksum = 0;
1160 u16 i;
1161
1162 *data = 0;
1163 /* Read and add up the contents of the EEPROM */
1164 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
Alexander Duyck317f66b2009-10-27 23:46:20 +00001165 if ((adapter->hw.nvm.ops.read(&adapter->hw, i, 1, &temp)) < 0) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001166 *data = 1;
1167 break;
1168 }
1169 checksum += temp;
1170 }
1171
1172 /* If Checksum is not Correct return error else test passed */
1173 if ((checksum != (u16) NVM_SUM) && !(*data))
1174 *data = 2;
1175
1176 return *data;
1177}
1178
1179static irqreturn_t igb_test_intr(int irq, void *data)
1180{
Alexander Duyck317f66b2009-10-27 23:46:20 +00001181 struct igb_adapter *adapter = (struct igb_adapter *) data;
Auke Kok9d5c8242008-01-24 02:22:38 -08001182 struct e1000_hw *hw = &adapter->hw;
1183
1184 adapter->test_icr |= rd32(E1000_ICR);
1185
1186 return IRQ_HANDLED;
1187}
1188
1189static int igb_intr_test(struct igb_adapter *adapter, u64 *data)
1190{
1191 struct e1000_hw *hw = &adapter->hw;
1192 struct net_device *netdev = adapter->netdev;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001193 u32 mask, ics_mask, i = 0, shared_int = true;
Auke Kok9d5c8242008-01-24 02:22:38 -08001194 u32 irq = adapter->pdev->irq;
1195
1196 *data = 0;
1197
1198 /* Hook up test interrupt handler just for this test */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001199 if (adapter->msix_entries) {
1200 if (request_irq(adapter->msix_entries[0].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001201 igb_test_intr, 0, netdev->name, adapter)) {
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001202 *data = 1;
1203 return -1;
1204 }
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001205 } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001206 shared_int = false;
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001207 if (request_irq(irq,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001208 igb_test_intr, 0, netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001209 *data = 1;
1210 return -1;
1211 }
Joe Perchesa0607fd2009-11-18 23:29:17 -08001212 } else if (!request_irq(irq, igb_test_intr, IRQF_PROBE_SHARED,
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001213 netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001214 shared_int = false;
Joe Perchesa0607fd2009-11-18 23:29:17 -08001215 } else if (request_irq(irq, igb_test_intr, IRQF_SHARED,
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001216 netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001217 *data = 1;
1218 return -1;
1219 }
1220 dev_info(&adapter->pdev->dev, "testing %s interrupt\n",
1221 (shared_int ? "shared" : "unshared"));
Alexander Duyck317f66b2009-10-27 23:46:20 +00001222
Auke Kok9d5c8242008-01-24 02:22:38 -08001223 /* Disable all the interrupts */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001224 wr32(E1000_IMC, ~0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001225 msleep(10);
1226
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001227 /* Define all writable bits for ICS */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001228 switch (hw->mac.type) {
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001229 case e1000_82575:
1230 ics_mask = 0x37F47EDD;
1231 break;
1232 case e1000_82576:
1233 ics_mask = 0x77D4FBFD;
1234 break;
Alexander Duyck55cac242009-11-19 12:42:21 +00001235 case e1000_82580:
1236 ics_mask = 0x77DCFED5;
1237 break;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001238 default:
1239 ics_mask = 0x7FFFFFFF;
1240 break;
1241 }
1242
Auke Kok9d5c8242008-01-24 02:22:38 -08001243 /* Test each interrupt */
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001244 for (; i < 31; i++) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001245 /* Interrupt to test */
1246 mask = 1 << i;
1247
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001248 if (!(mask & ics_mask))
1249 continue;
1250
Auke Kok9d5c8242008-01-24 02:22:38 -08001251 if (!shared_int) {
1252 /* Disable the interrupt to be reported in
1253 * the cause register and then force the same
1254 * interrupt and see if one gets posted. If
1255 * an interrupt was posted to the bus, the
1256 * test failed.
1257 */
1258 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001259
1260 /* Flush any pending interrupts */
1261 wr32(E1000_ICR, ~0);
1262
1263 wr32(E1000_IMC, mask);
1264 wr32(E1000_ICS, mask);
Auke Kok9d5c8242008-01-24 02:22:38 -08001265 msleep(10);
1266
1267 if (adapter->test_icr & mask) {
1268 *data = 3;
1269 break;
1270 }
1271 }
1272
1273 /* Enable the interrupt to be reported in
1274 * the cause register and then force the same
1275 * interrupt and see if one gets posted. If
1276 * an interrupt was not posted to the bus, the
1277 * test failed.
1278 */
1279 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001280
1281 /* Flush any pending interrupts */
1282 wr32(E1000_ICR, ~0);
1283
Auke Kok9d5c8242008-01-24 02:22:38 -08001284 wr32(E1000_IMS, mask);
1285 wr32(E1000_ICS, mask);
1286 msleep(10);
1287
1288 if (!(adapter->test_icr & mask)) {
1289 *data = 4;
1290 break;
1291 }
1292
1293 if (!shared_int) {
1294 /* Disable the other interrupts to be reported in
1295 * the cause register and then force the other
1296 * interrupts and see if any get posted. If
1297 * an interrupt was posted to the bus, the
1298 * test failed.
1299 */
1300 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001301
1302 /* Flush any pending interrupts */
1303 wr32(E1000_ICR, ~0);
1304
1305 wr32(E1000_IMC, ~mask);
1306 wr32(E1000_ICS, ~mask);
Auke Kok9d5c8242008-01-24 02:22:38 -08001307 msleep(10);
1308
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001309 if (adapter->test_icr & mask) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001310 *data = 5;
1311 break;
1312 }
1313 }
1314 }
1315
1316 /* Disable all the interrupts */
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001317 wr32(E1000_IMC, ~0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001318 msleep(10);
1319
1320 /* Unhook test interrupt handler */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001321 if (adapter->msix_entries)
1322 free_irq(adapter->msix_entries[0].vector, adapter);
1323 else
1324 free_irq(irq, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001325
1326 return *data;
1327}
1328
1329static void igb_free_desc_rings(struct igb_adapter *adapter)
1330{
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001331 igb_free_tx_resources(&adapter->test_tx_ring);
1332 igb_free_rx_resources(&adapter->test_rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001333}
1334
1335static int igb_setup_desc_rings(struct igb_adapter *adapter)
1336{
Auke Kok9d5c8242008-01-24 02:22:38 -08001337 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1338 struct igb_ring *rx_ring = &adapter->test_rx_ring;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001339 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckad93d172009-10-27 15:55:02 +00001340 int ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001341
1342 /* Setup Tx descriptor ring and Tx buffers */
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001343 tx_ring->count = IGB_DEFAULT_TXD;
1344 tx_ring->pdev = adapter->pdev;
1345 tx_ring->netdev = adapter->netdev;
1346 tx_ring->reg_idx = adapter->vfs_allocated_count;
Auke Kok9d5c8242008-01-24 02:22:38 -08001347
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001348 if (igb_setup_tx_resources(tx_ring)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001349 ret_val = 1;
1350 goto err_nomem;
1351 }
1352
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001353 igb_setup_tctl(adapter);
1354 igb_configure_tx_ring(adapter, tx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001355
Auke Kok9d5c8242008-01-24 02:22:38 -08001356 /* Setup Rx descriptor ring and Rx buffers */
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001357 rx_ring->count = IGB_DEFAULT_RXD;
1358 rx_ring->pdev = adapter->pdev;
1359 rx_ring->netdev = adapter->netdev;
1360 rx_ring->rx_buffer_len = IGB_RXBUFFER_2048;
1361 rx_ring->reg_idx = adapter->vfs_allocated_count;
Auke Kok9d5c8242008-01-24 02:22:38 -08001362
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001363 if (igb_setup_rx_resources(rx_ring)) {
1364 ret_val = 3;
Auke Kok9d5c8242008-01-24 02:22:38 -08001365 goto err_nomem;
1366 }
1367
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001368 /* set the default queue to queue 0 of PF */
1369 wr32(E1000_MRQC, adapter->vfs_allocated_count << 3);
Auke Kok9d5c8242008-01-24 02:22:38 -08001370
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001371 /* enable receive ring */
1372 igb_setup_rctl(adapter);
1373 igb_configure_rx_ring(adapter, rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001374
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001375 igb_alloc_rx_buffers_adv(rx_ring, igb_desc_unused(rx_ring));
Auke Kok9d5c8242008-01-24 02:22:38 -08001376
1377 return 0;
1378
1379err_nomem:
1380 igb_free_desc_rings(adapter);
1381 return ret_val;
1382}
1383
1384static void igb_phy_disable_receiver(struct igb_adapter *adapter)
1385{
1386 struct e1000_hw *hw = &adapter->hw;
1387
1388 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001389 igb_write_phy_reg(hw, 29, 0x001F);
1390 igb_write_phy_reg(hw, 30, 0x8FFC);
1391 igb_write_phy_reg(hw, 29, 0x001A);
1392 igb_write_phy_reg(hw, 30, 0x8FF0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001393}
1394
1395static int igb_integrated_phy_loopback(struct igb_adapter *adapter)
1396{
1397 struct e1000_hw *hw = &adapter->hw;
1398 u32 ctrl_reg = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001399
1400 hw->mac.autoneg = false;
1401
1402 if (hw->phy.type == e1000_phy_m88) {
1403 /* Auto-MDI/MDIX Off */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001404 igb_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
Auke Kok9d5c8242008-01-24 02:22:38 -08001405 /* reset to update Auto-MDI/MDIX */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001406 igb_write_phy_reg(hw, PHY_CONTROL, 0x9140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001407 /* autoneg off */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001408 igb_write_phy_reg(hw, PHY_CONTROL, 0x8140);
Alexander Duyck55cac242009-11-19 12:42:21 +00001409 } else if (hw->phy.type == e1000_phy_82580) {
1410 /* enable MII loopback */
1411 igb_write_phy_reg(hw, I82580_PHY_LBK_CTRL, 0x8041);
Auke Kok9d5c8242008-01-24 02:22:38 -08001412 }
1413
1414 ctrl_reg = rd32(E1000_CTRL);
1415
1416 /* force 1000, set loopback */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001417 igb_write_phy_reg(hw, PHY_CONTROL, 0x4140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001418
1419 /* Now set up the MAC to the same speed/duplex as the PHY. */
1420 ctrl_reg = rd32(E1000_CTRL);
1421 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1422 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1423 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1424 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
Alexander Duyckcdfa9f62009-03-31 20:38:56 +00001425 E1000_CTRL_FD | /* Force Duplex to FULL */
1426 E1000_CTRL_SLU); /* Set link up enable bit */
Auke Kok9d5c8242008-01-24 02:22:38 -08001427
Alexander Duyckcdfa9f62009-03-31 20:38:56 +00001428 if (hw->phy.type == e1000_phy_m88)
Auke Kok9d5c8242008-01-24 02:22:38 -08001429 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kok9d5c8242008-01-24 02:22:38 -08001430
1431 wr32(E1000_CTRL, ctrl_reg);
1432
1433 /* Disable the receiver on the PHY so when a cable is plugged in, the
1434 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1435 */
1436 if (hw->phy.type == e1000_phy_m88)
1437 igb_phy_disable_receiver(adapter);
1438
1439 udelay(500);
1440
1441 return 0;
1442}
1443
1444static int igb_set_phy_loopback(struct igb_adapter *adapter)
1445{
1446 return igb_integrated_phy_loopback(adapter);
1447}
1448
1449static int igb_setup_loopback_test(struct igb_adapter *adapter)
1450{
1451 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001452 u32 reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001453
Alexander Duyck317f66b2009-10-27 23:46:20 +00001454 reg = rd32(E1000_CTRL_EXT);
1455
1456 /* use CTRL_EXT to identify link type as SGMII can appear as copper */
1457 if (reg & E1000_CTRL_EXT_LINK_MODE_MASK) {
Alexander Duyck2d064c02008-07-08 15:10:12 -07001458 reg = rd32(E1000_RCTL);
1459 reg |= E1000_RCTL_LBM_TCVR;
1460 wr32(E1000_RCTL, reg);
1461
1462 wr32(E1000_SCTL, E1000_ENABLE_SERDES_LOOPBACK);
1463
1464 reg = rd32(E1000_CTRL);
1465 reg &= ~(E1000_CTRL_RFCE |
1466 E1000_CTRL_TFCE |
1467 E1000_CTRL_LRST);
1468 reg |= E1000_CTRL_SLU |
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001469 E1000_CTRL_FD;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001470 wr32(E1000_CTRL, reg);
1471
1472 /* Unset switch control to serdes energy detect */
1473 reg = rd32(E1000_CONNSW);
1474 reg &= ~E1000_CONNSW_ENRGSRC;
1475 wr32(E1000_CONNSW, reg);
1476
1477 /* Set PCS register for forced speed */
1478 reg = rd32(E1000_PCS_LCTL);
1479 reg &= ~E1000_PCS_LCTL_AN_ENABLE; /* Disable Autoneg*/
1480 reg |= E1000_PCS_LCTL_FLV_LINK_UP | /* Force link up */
1481 E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1482 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
1483 E1000_PCS_LCTL_FSD | /* Force Speed */
1484 E1000_PCS_LCTL_FORCE_LINK; /* Force Link */
1485 wr32(E1000_PCS_LCTL, reg);
1486
Auke Kok9d5c8242008-01-24 02:22:38 -08001487 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001488 }
1489
Alexander Duyck317f66b2009-10-27 23:46:20 +00001490 return igb_set_phy_loopback(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001491}
1492
1493static void igb_loopback_cleanup(struct igb_adapter *adapter)
1494{
1495 struct e1000_hw *hw = &adapter->hw;
1496 u32 rctl;
1497 u16 phy_reg;
1498
1499 rctl = rd32(E1000_RCTL);
1500 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1501 wr32(E1000_RCTL, rctl);
1502
1503 hw->mac.autoneg = true;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001504 igb_read_phy_reg(hw, PHY_CONTROL, &phy_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001505 if (phy_reg & MII_CR_LOOPBACK) {
1506 phy_reg &= ~MII_CR_LOOPBACK;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001507 igb_write_phy_reg(hw, PHY_CONTROL, phy_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001508 igb_phy_sw_reset(hw);
1509 }
1510}
1511
1512static void igb_create_lbtest_frame(struct sk_buff *skb,
1513 unsigned int frame_size)
1514{
1515 memset(skb->data, 0xFF, frame_size);
Alexander Duyck317f66b2009-10-27 23:46:20 +00001516 frame_size /= 2;
1517 memset(&skb->data[frame_size], 0xAA, frame_size - 1);
1518 memset(&skb->data[frame_size + 10], 0xBE, 1);
1519 memset(&skb->data[frame_size + 12], 0xAF, 1);
Auke Kok9d5c8242008-01-24 02:22:38 -08001520}
1521
1522static int igb_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1523{
Alexander Duyck317f66b2009-10-27 23:46:20 +00001524 frame_size /= 2;
1525 if (*(skb->data + 3) == 0xFF) {
1526 if ((*(skb->data + frame_size + 10) == 0xBE) &&
1527 (*(skb->data + frame_size + 12) == 0xAF)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001528 return 0;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001529 }
1530 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001531 return 13;
1532}
1533
Alexander Duyckad93d172009-10-27 15:55:02 +00001534static int igb_clean_test_rings(struct igb_ring *rx_ring,
1535 struct igb_ring *tx_ring,
1536 unsigned int size)
1537{
1538 union e1000_adv_rx_desc *rx_desc;
1539 struct igb_buffer *buffer_info;
1540 int rx_ntc, tx_ntc, count = 0;
1541 u32 staterr;
1542
1543 /* initialize next to clean and descriptor values */
1544 rx_ntc = rx_ring->next_to_clean;
1545 tx_ntc = tx_ring->next_to_clean;
1546 rx_desc = E1000_RX_DESC_ADV(*rx_ring, rx_ntc);
1547 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1548
1549 while (staterr & E1000_RXD_STAT_DD) {
1550 /* check rx buffer */
1551 buffer_info = &rx_ring->buffer_info[rx_ntc];
1552
1553 /* unmap rx buffer, will be remapped by alloc_rx_buffers */
1554 pci_unmap_single(rx_ring->pdev,
1555 buffer_info->dma,
1556 rx_ring->rx_buffer_len,
1557 PCI_DMA_FROMDEVICE);
1558 buffer_info->dma = 0;
1559
1560 /* verify contents of skb */
1561 if (!igb_check_lbtest_frame(buffer_info->skb, size))
1562 count++;
1563
1564 /* unmap buffer on tx side */
1565 buffer_info = &tx_ring->buffer_info[tx_ntc];
1566 igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
1567
1568 /* increment rx/tx next to clean counters */
1569 rx_ntc++;
1570 if (rx_ntc == rx_ring->count)
1571 rx_ntc = 0;
1572 tx_ntc++;
1573 if (tx_ntc == tx_ring->count)
1574 tx_ntc = 0;
1575
1576 /* fetch next descriptor */
1577 rx_desc = E1000_RX_DESC_ADV(*rx_ring, rx_ntc);
1578 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1579 }
1580
1581 /* re-map buffers to ring, store next to clean values */
1582 igb_alloc_rx_buffers_adv(rx_ring, count);
1583 rx_ring->next_to_clean = rx_ntc;
1584 tx_ring->next_to_clean = tx_ntc;
1585
1586 return count;
1587}
1588
Auke Kok9d5c8242008-01-24 02:22:38 -08001589static int igb_run_loopback_test(struct igb_adapter *adapter)
1590{
Auke Kok9d5c8242008-01-24 02:22:38 -08001591 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1592 struct igb_ring *rx_ring = &adapter->test_rx_ring;
Alexander Duyckad93d172009-10-27 15:55:02 +00001593 int i, j, lc, good_cnt, ret_val = 0;
1594 unsigned int size = 1024;
1595 netdev_tx_t tx_ret_val;
1596 struct sk_buff *skb;
Auke Kok9d5c8242008-01-24 02:22:38 -08001597
Alexander Duyckad93d172009-10-27 15:55:02 +00001598 /* allocate test skb */
1599 skb = alloc_skb(size, GFP_KERNEL);
1600 if (!skb)
1601 return 11;
1602
1603 /* place data into test skb */
1604 igb_create_lbtest_frame(skb, size);
1605 skb_put(skb, size);
Auke Kok9d5c8242008-01-24 02:22:38 -08001606
Alexander Duyck317f66b2009-10-27 23:46:20 +00001607 /*
1608 * Calculate the loop count based on the largest descriptor ring
Auke Kok9d5c8242008-01-24 02:22:38 -08001609 * The idea is to wrap the largest ring a number of times using 64
1610 * send/receive pairs during each loop
1611 */
1612
1613 if (rx_ring->count <= tx_ring->count)
1614 lc = ((tx_ring->count / 64) * 2) + 1;
1615 else
1616 lc = ((rx_ring->count / 64) * 2) + 1;
1617
Auke Kok9d5c8242008-01-24 02:22:38 -08001618 for (j = 0; j <= lc; j++) { /* loop count loop */
Alexander Duyckad93d172009-10-27 15:55:02 +00001619 /* reset count of good packets */
Auke Kok9d5c8242008-01-24 02:22:38 -08001620 good_cnt = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001621
Alexander Duyckad93d172009-10-27 15:55:02 +00001622 /* place 64 packets on the transmit queue*/
1623 for (i = 0; i < 64; i++) {
1624 skb_get(skb);
1625 tx_ret_val = igb_xmit_frame_ring_adv(skb, tx_ring);
1626 if (tx_ret_val == NETDEV_TX_OK)
Auke Kok9d5c8242008-01-24 02:22:38 -08001627 good_cnt++;
Alexander Duyckad93d172009-10-27 15:55:02 +00001628 }
1629
Auke Kok9d5c8242008-01-24 02:22:38 -08001630 if (good_cnt != 64) {
Alexander Duyckad93d172009-10-27 15:55:02 +00001631 ret_val = 12;
Auke Kok9d5c8242008-01-24 02:22:38 -08001632 break;
1633 }
Alexander Duyckad93d172009-10-27 15:55:02 +00001634
1635 /* allow 200 milliseconds for packets to go from tx to rx */
1636 msleep(200);
1637
1638 good_cnt = igb_clean_test_rings(rx_ring, tx_ring, size);
1639 if (good_cnt != 64) {
1640 ret_val = 13;
Auke Kok9d5c8242008-01-24 02:22:38 -08001641 break;
1642 }
1643 } /* end loop count loop */
Alexander Duyckad93d172009-10-27 15:55:02 +00001644
1645 /* free the original skb */
1646 kfree_skb(skb);
1647
Auke Kok9d5c8242008-01-24 02:22:38 -08001648 return ret_val;
1649}
1650
1651static int igb_loopback_test(struct igb_adapter *adapter, u64 *data)
1652{
1653 /* PHY loopback cannot be performed if SoL/IDER
1654 * sessions are active */
1655 if (igb_check_reset_block(&adapter->hw)) {
1656 dev_err(&adapter->pdev->dev,
1657 "Cannot do PHY loopback test "
1658 "when SoL/IDER is active.\n");
1659 *data = 0;
1660 goto out;
1661 }
1662 *data = igb_setup_desc_rings(adapter);
1663 if (*data)
1664 goto out;
1665 *data = igb_setup_loopback_test(adapter);
1666 if (*data)
1667 goto err_loopback;
1668 *data = igb_run_loopback_test(adapter);
1669 igb_loopback_cleanup(adapter);
1670
1671err_loopback:
1672 igb_free_desc_rings(adapter);
1673out:
1674 return *data;
1675}
1676
1677static int igb_link_test(struct igb_adapter *adapter, u64 *data)
1678{
1679 struct e1000_hw *hw = &adapter->hw;
1680 *data = 0;
1681 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1682 int i = 0;
1683 hw->mac.serdes_has_link = false;
1684
1685 /* On some blade server designs, link establishment
1686 * could take as long as 2-3 minutes */
1687 do {
1688 hw->mac.ops.check_for_link(&adapter->hw);
1689 if (hw->mac.serdes_has_link)
1690 return *data;
1691 msleep(20);
1692 } while (i++ < 3750);
1693
1694 *data = 1;
1695 } else {
1696 hw->mac.ops.check_for_link(&adapter->hw);
1697 if (hw->mac.autoneg)
1698 msleep(4000);
1699
Alexander Duyck317f66b2009-10-27 23:46:20 +00001700 if (!(rd32(E1000_STATUS) & E1000_STATUS_LU))
Auke Kok9d5c8242008-01-24 02:22:38 -08001701 *data = 1;
1702 }
1703 return *data;
1704}
1705
1706static void igb_diag_test(struct net_device *netdev,
1707 struct ethtool_test *eth_test, u64 *data)
1708{
1709 struct igb_adapter *adapter = netdev_priv(netdev);
1710 u16 autoneg_advertised;
1711 u8 forced_speed_duplex, autoneg;
1712 bool if_running = netif_running(netdev);
1713
1714 set_bit(__IGB_TESTING, &adapter->state);
1715 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1716 /* Offline tests */
1717
1718 /* save speed, duplex, autoneg settings */
1719 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1720 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1721 autoneg = adapter->hw.mac.autoneg;
1722
1723 dev_info(&adapter->pdev->dev, "offline testing starting\n");
1724
Nick Nunley88a268c2010-02-17 01:01:59 +00001725 /* power up link for link test */
1726 igb_power_up_link(adapter);
1727
Auke Kok9d5c8242008-01-24 02:22:38 -08001728 /* Link test performed before hardware reset so autoneg doesn't
1729 * interfere with test result */
1730 if (igb_link_test(adapter, &data[4]))
1731 eth_test->flags |= ETH_TEST_FL_FAILED;
1732
1733 if (if_running)
1734 /* indicate we're in test mode */
1735 dev_close(netdev);
1736 else
1737 igb_reset(adapter);
1738
1739 if (igb_reg_test(adapter, &data[0]))
1740 eth_test->flags |= ETH_TEST_FL_FAILED;
1741
1742 igb_reset(adapter);
1743 if (igb_eeprom_test(adapter, &data[1]))
1744 eth_test->flags |= ETH_TEST_FL_FAILED;
1745
1746 igb_reset(adapter);
1747 if (igb_intr_test(adapter, &data[2]))
1748 eth_test->flags |= ETH_TEST_FL_FAILED;
1749
1750 igb_reset(adapter);
Nick Nunley88a268c2010-02-17 01:01:59 +00001751 /* power up link for loopback test */
1752 igb_power_up_link(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001753 if (igb_loopback_test(adapter, &data[3]))
1754 eth_test->flags |= ETH_TEST_FL_FAILED;
1755
1756 /* restore speed, duplex, autoneg settings */
1757 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1758 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1759 adapter->hw.mac.autoneg = autoneg;
1760
1761 /* force this routine to wait until autoneg complete/timeout */
1762 adapter->hw.phy.autoneg_wait_to_complete = true;
1763 igb_reset(adapter);
1764 adapter->hw.phy.autoneg_wait_to_complete = false;
1765
1766 clear_bit(__IGB_TESTING, &adapter->state);
1767 if (if_running)
1768 dev_open(netdev);
1769 } else {
1770 dev_info(&adapter->pdev->dev, "online testing starting\n");
Nick Nunley88a268c2010-02-17 01:01:59 +00001771
1772 /* PHY is powered down when interface is down */
1773 if (!netif_carrier_ok(netdev)) {
1774 data[4] = 0;
1775 } else {
1776 if (igb_link_test(adapter, &data[4]))
1777 eth_test->flags |= ETH_TEST_FL_FAILED;
1778 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001779
1780 /* Online tests aren't run; pass by default */
1781 data[0] = 0;
1782 data[1] = 0;
1783 data[2] = 0;
1784 data[3] = 0;
1785
1786 clear_bit(__IGB_TESTING, &adapter->state);
1787 }
1788 msleep_interruptible(4 * 1000);
1789}
1790
1791static int igb_wol_exclusion(struct igb_adapter *adapter,
1792 struct ethtool_wolinfo *wol)
1793{
1794 struct e1000_hw *hw = &adapter->hw;
1795 int retval = 1; /* fail by default */
1796
1797 switch (hw->device_id) {
1798 case E1000_DEV_ID_82575GB_QUAD_COPPER:
1799 /* WoL not supported */
1800 wol->supported = 0;
1801 break;
1802 case E1000_DEV_ID_82575EB_FIBER_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -07001803 case E1000_DEV_ID_82576_FIBER:
1804 case E1000_DEV_ID_82576_SERDES:
Auke Kok9d5c8242008-01-24 02:22:38 -08001805 /* Wake events not supported on port B */
1806 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1) {
1807 wol->supported = 0;
1808 break;
1809 }
1810 /* return success for non excluded adapter ports */
1811 retval = 0;
1812 break;
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +00001813 case E1000_DEV_ID_82576_QUAD_COPPER:
1814 /* quad port adapters only support WoL on port A */
1815 if (!(adapter->flags & IGB_FLAG_QUAD_PORT_A)) {
1816 wol->supported = 0;
1817 break;
1818 }
1819 /* return success for non excluded adapter ports */
1820 retval = 0;
1821 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08001822 default:
1823 /* dual port cards only support WoL on port A from now on
1824 * unless it was enabled in the eeprom for port B
1825 * so exclude FUNC_1 ports from having WoL enabled */
Alexander Duyck58b8b042009-12-23 13:21:46 +00001826 if ((rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) &&
Auke Kok9d5c8242008-01-24 02:22:38 -08001827 !adapter->eeprom_wol) {
1828 wol->supported = 0;
1829 break;
1830 }
1831
1832 retval = 0;
1833 }
1834
1835 return retval;
1836}
1837
1838static void igb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1839{
1840 struct igb_adapter *adapter = netdev_priv(netdev);
1841
1842 wol->supported = WAKE_UCAST | WAKE_MCAST |
Nick Nunley22939f02010-02-17 01:01:01 +00001843 WAKE_BCAST | WAKE_MAGIC |
1844 WAKE_PHY;
Auke Kok9d5c8242008-01-24 02:22:38 -08001845 wol->wolopts = 0;
1846
1847 /* this function will set ->supported = 0 and return 1 if wol is not
1848 * supported by this hardware */
\"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;
1852
1853 /* apply any specific unsupported masks here */
1854 switch (adapter->hw.device_id) {
1855 default:
1856 break;
1857 }
1858
1859 if (adapter->wol & E1000_WUFC_EX)
1860 wol->wolopts |= WAKE_UCAST;
1861 if (adapter->wol & E1000_WUFC_MC)
1862 wol->wolopts |= WAKE_MCAST;
1863 if (adapter->wol & E1000_WUFC_BC)
1864 wol->wolopts |= WAKE_BCAST;
1865 if (adapter->wol & E1000_WUFC_MAG)
1866 wol->wolopts |= WAKE_MAGIC;
Nick Nunley22939f02010-02-17 01:01:01 +00001867 if (adapter->wol & E1000_WUFC_LNKC)
1868 wol->wolopts |= WAKE_PHY;
Auke Kok9d5c8242008-01-24 02:22:38 -08001869}
1870
1871static int igb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1872{
1873 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001874
Nick Nunley22939f02010-02-17 01:01:01 +00001875 if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE))
Auke Kok9d5c8242008-01-24 02:22:38 -08001876 return -EOPNOTSUPP;
1877
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00001878 if (igb_wol_exclusion(adapter, wol) ||
1879 !device_can_wakeup(&adapter->pdev->dev))
Auke Kok9d5c8242008-01-24 02:22:38 -08001880 return wol->wolopts ? -EOPNOTSUPP : 0;
1881
Auke Kok9d5c8242008-01-24 02:22:38 -08001882 /* these settings will always override what we currently have */
1883 adapter->wol = 0;
1884
1885 if (wol->wolopts & WAKE_UCAST)
1886 adapter->wol |= E1000_WUFC_EX;
1887 if (wol->wolopts & WAKE_MCAST)
1888 adapter->wol |= E1000_WUFC_MC;
1889 if (wol->wolopts & WAKE_BCAST)
1890 adapter->wol |= E1000_WUFC_BC;
1891 if (wol->wolopts & WAKE_MAGIC)
1892 adapter->wol |= E1000_WUFC_MAG;
Nick Nunley22939f02010-02-17 01:01:01 +00001893 if (wol->wolopts & WAKE_PHY)
1894 adapter->wol |= E1000_WUFC_LNKC;
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00001895 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1896
Auke Kok9d5c8242008-01-24 02:22:38 -08001897 return 0;
1898}
1899
Auke Kok9d5c8242008-01-24 02:22:38 -08001900/* bit defines for adapter->led_status */
1901#define IGB_LED_ON 0
1902
1903static int igb_phys_id(struct net_device *netdev, u32 data)
1904{
1905 struct igb_adapter *adapter = netdev_priv(netdev);
1906 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001907 unsigned long timeout;
Auke Kok9d5c8242008-01-24 02:22:38 -08001908
Alexander Duyck317f66b2009-10-27 23:46:20 +00001909 timeout = data * 1000;
1910
1911 /*
1912 * msleep_interruptable only accepts unsigned int so we are limited
1913 * in how long a duration we can wait
1914 */
1915 if (!timeout || timeout > UINT_MAX)
1916 timeout = UINT_MAX;
Auke Kok9d5c8242008-01-24 02:22:38 -08001917
1918 igb_blink_led(hw);
Alexander Duyck317f66b2009-10-27 23:46:20 +00001919 msleep_interruptible(timeout);
Auke Kok9d5c8242008-01-24 02:22:38 -08001920
1921 igb_led_off(hw);
1922 clear_bit(IGB_LED_ON, &adapter->led_status);
1923 igb_cleanup_led(hw);
1924
1925 return 0;
1926}
1927
1928static int igb_set_coalesce(struct net_device *netdev,
1929 struct ethtool_coalesce *ec)
1930{
1931 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07001932 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08001933
1934 if ((ec->rx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
1935 ((ec->rx_coalesce_usecs > 3) &&
1936 (ec->rx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
1937 (ec->rx_coalesce_usecs == 2))
1938 return -EINVAL;
1939
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001940 if ((ec->tx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
1941 ((ec->tx_coalesce_usecs > 3) &&
1942 (ec->tx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
1943 (ec->tx_coalesce_usecs == 2))
1944 return -EINVAL;
1945
1946 if ((adapter->flags & IGB_FLAG_QUEUE_PAIRS) && ec->tx_coalesce_usecs)
1947 return -EINVAL;
1948
Auke Kok9d5c8242008-01-24 02:22:38 -08001949 /* convert to rate of irq's per second */
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001950 if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3)
1951 adapter->rx_itr_setting = ec->rx_coalesce_usecs;
1952 else
1953 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
1954
1955 /* convert to rate of irq's per second */
1956 if (adapter->flags & IGB_FLAG_QUEUE_PAIRS)
1957 adapter->tx_itr_setting = adapter->rx_itr_setting;
1958 else if (ec->tx_coalesce_usecs && ec->tx_coalesce_usecs <= 3)
1959 adapter->tx_itr_setting = ec->tx_coalesce_usecs;
1960 else
1961 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
Auke Kok9d5c8242008-01-24 02:22:38 -08001962
Alexander Duyck047e0032009-10-27 15:49:27 +00001963 for (i = 0; i < adapter->num_q_vectors; i++) {
1964 struct igb_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001965 if (q_vector->rx_ring)
1966 q_vector->itr_val = adapter->rx_itr_setting;
1967 else
1968 q_vector->itr_val = adapter->tx_itr_setting;
1969 if (q_vector->itr_val && q_vector->itr_val <= 3)
1970 q_vector->itr_val = IGB_START_ITR;
Alexander Duyck047e0032009-10-27 15:49:27 +00001971 q_vector->set_itr = 1;
1972 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001973
1974 return 0;
1975}
1976
1977static int igb_get_coalesce(struct net_device *netdev,
1978 struct ethtool_coalesce *ec)
1979{
1980 struct igb_adapter *adapter = netdev_priv(netdev);
1981
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001982 if (adapter->rx_itr_setting <= 3)
1983 ec->rx_coalesce_usecs = adapter->rx_itr_setting;
Auke Kok9d5c8242008-01-24 02:22:38 -08001984 else
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001985 ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
1986
1987 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS)) {
1988 if (adapter->tx_itr_setting <= 3)
1989 ec->tx_coalesce_usecs = adapter->tx_itr_setting;
1990 else
1991 ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
1992 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001993
1994 return 0;
1995}
1996
Auke Kok9d5c8242008-01-24 02:22:38 -08001997static int igb_nway_reset(struct net_device *netdev)
1998{
1999 struct igb_adapter *adapter = netdev_priv(netdev);
2000 if (netif_running(netdev))
2001 igb_reinit_locked(adapter);
2002 return 0;
2003}
2004
2005static int igb_get_sset_count(struct net_device *netdev, int sset)
2006{
2007 switch (sset) {
2008 case ETH_SS_STATS:
2009 return IGB_STATS_LEN;
2010 case ETH_SS_TEST:
2011 return IGB_TEST_LEN;
2012 default:
2013 return -ENOTSUPP;
2014 }
2015}
2016
2017static void igb_get_ethtool_stats(struct net_device *netdev,
2018 struct ethtool_stats *stats, u64 *data)
2019{
2020 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck128e45e2009-11-12 18:37:38 +00002021 struct net_device_stats *net_stats = &netdev->stats;
Auke Kok9d5c8242008-01-24 02:22:38 -08002022 u64 *queue_stat;
Alexander Duyck128e45e2009-11-12 18:37:38 +00002023 int i, j, k;
2024 char *p;
Auke Kok9d5c8242008-01-24 02:22:38 -08002025
2026 igb_update_stats(adapter);
Alexander Duyck317f66b2009-10-27 23:46:20 +00002027
Auke Kok9d5c8242008-01-24 02:22:38 -08002028 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
Alexander Duyck128e45e2009-11-12 18:37:38 +00002029 p = (char *)adapter + igb_gstrings_stats[i].stat_offset;
Auke Kok9d5c8242008-01-24 02:22:38 -08002030 data[i] = (igb_gstrings_stats[i].sizeof_stat ==
2031 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2032 }
Alexander Duyck128e45e2009-11-12 18:37:38 +00002033 for (j = 0; j < IGB_NETDEV_STATS_LEN; j++, i++) {
2034 p = (char *)net_stats + igb_gstrings_net_stats[j].stat_offset;
2035 data[i] = (igb_gstrings_net_stats[j].sizeof_stat ==
2036 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2037 }
Alexander Duycke21ed352008-07-08 15:07:24 -07002038 for (j = 0; j < adapter->num_tx_queues; j++) {
Alexander Duycke21ed352008-07-08 15:07:24 -07002039 queue_stat = (u64 *)&adapter->tx_ring[j].tx_stats;
Alexander Duyck128e45e2009-11-12 18:37:38 +00002040 for (k = 0; k < IGB_TX_QUEUE_STATS_LEN; k++, i++)
2041 data[i] = queue_stat[k];
Alexander Duycke21ed352008-07-08 15:07:24 -07002042 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002043 for (j = 0; j < adapter->num_rx_queues; j++) {
Auke Kok9d5c8242008-01-24 02:22:38 -08002044 queue_stat = (u64 *)&adapter->rx_ring[j].rx_stats;
Alexander Duyck128e45e2009-11-12 18:37:38 +00002045 for (k = 0; k < IGB_RX_QUEUE_STATS_LEN; k++, i++)
2046 data[i] = queue_stat[k];
Auke Kok9d5c8242008-01-24 02:22:38 -08002047 }
2048}
2049
2050static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
2051{
2052 struct igb_adapter *adapter = netdev_priv(netdev);
2053 u8 *p = data;
2054 int i;
2055
2056 switch (stringset) {
2057 case ETH_SS_TEST:
2058 memcpy(data, *igb_gstrings_test,
2059 IGB_TEST_LEN*ETH_GSTRING_LEN);
2060 break;
2061 case ETH_SS_STATS:
2062 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
2063 memcpy(p, igb_gstrings_stats[i].stat_string,
2064 ETH_GSTRING_LEN);
2065 p += ETH_GSTRING_LEN;
2066 }
Alexander Duyck128e45e2009-11-12 18:37:38 +00002067 for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) {
2068 memcpy(p, igb_gstrings_net_stats[i].stat_string,
2069 ETH_GSTRING_LEN);
2070 p += ETH_GSTRING_LEN;
2071 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002072 for (i = 0; i < adapter->num_tx_queues; i++) {
2073 sprintf(p, "tx_queue_%u_packets", i);
2074 p += ETH_GSTRING_LEN;
2075 sprintf(p, "tx_queue_%u_bytes", i);
2076 p += ETH_GSTRING_LEN;
Alexander Duyck04a5fca2009-10-27 15:52:27 +00002077 sprintf(p, "tx_queue_%u_restart", i);
2078 p += ETH_GSTRING_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002079 }
2080 for (i = 0; i < adapter->num_rx_queues; i++) {
2081 sprintf(p, "rx_queue_%u_packets", i);
2082 p += ETH_GSTRING_LEN;
2083 sprintf(p, "rx_queue_%u_bytes", i);
2084 p += ETH_GSTRING_LEN;
Jesper Dangaard Brouer8c0ab702009-05-26 13:50:31 +00002085 sprintf(p, "rx_queue_%u_drops", i);
2086 p += ETH_GSTRING_LEN;
Alexander Duyck04a5fca2009-10-27 15:52:27 +00002087 sprintf(p, "rx_queue_%u_csum_err", i);
2088 p += ETH_GSTRING_LEN;
2089 sprintf(p, "rx_queue_%u_alloc_failed", i);
2090 p += ETH_GSTRING_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002091 }
2092/* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
2093 break;
2094 }
2095}
2096
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07002097static const struct ethtool_ops igb_ethtool_ops = {
Auke Kok9d5c8242008-01-24 02:22:38 -08002098 .get_settings = igb_get_settings,
2099 .set_settings = igb_set_settings,
2100 .get_drvinfo = igb_get_drvinfo,
2101 .get_regs_len = igb_get_regs_len,
2102 .get_regs = igb_get_regs,
2103 .get_wol = igb_get_wol,
2104 .set_wol = igb_set_wol,
2105 .get_msglevel = igb_get_msglevel,
2106 .set_msglevel = igb_set_msglevel,
2107 .nway_reset = igb_nway_reset,
Nick Nunley31455352010-02-17 01:01:21 +00002108 .get_link = igb_get_link,
Auke Kok9d5c8242008-01-24 02:22:38 -08002109 .get_eeprom_len = igb_get_eeprom_len,
2110 .get_eeprom = igb_get_eeprom,
2111 .set_eeprom = igb_set_eeprom,
2112 .get_ringparam = igb_get_ringparam,
2113 .set_ringparam = igb_set_ringparam,
2114 .get_pauseparam = igb_get_pauseparam,
2115 .set_pauseparam = igb_set_pauseparam,
2116 .get_rx_csum = igb_get_rx_csum,
2117 .set_rx_csum = igb_set_rx_csum,
2118 .get_tx_csum = igb_get_tx_csum,
2119 .set_tx_csum = igb_set_tx_csum,
2120 .get_sg = ethtool_op_get_sg,
2121 .set_sg = ethtool_op_set_sg,
2122 .get_tso = ethtool_op_get_tso,
2123 .set_tso = igb_set_tso,
2124 .self_test = igb_diag_test,
2125 .get_strings = igb_get_strings,
2126 .phys_id = igb_phys_id,
2127 .get_sset_count = igb_get_sset_count,
2128 .get_ethtool_stats = igb_get_ethtool_stats,
2129 .get_coalesce = igb_get_coalesce,
2130 .set_coalesce = igb_set_coalesce,
2131};
2132
2133void igb_set_ethtool_ops(struct net_device *netdev)
2134{
2135 SET_ETHTOOL_OPS(netdev, &igb_ethtool_ops);
2136}