blob: d7bdc6c16d0ea0a3efd410826f5f41334d38392b [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007 Intel Corporation.
5
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>
37
38#include "igb.h"
39
40struct igb_stats {
41 char stat_string[ETH_GSTRING_LEN];
42 int sizeof_stat;
43 int stat_offset;
44};
45
Julia Lawall030ed682008-02-11 09:25:40 -080046#define IGB_STAT(m) FIELD_SIZEOF(struct igb_adapter, m), \
Auke Kok9d5c8242008-01-24 02:22:38 -080047 offsetof(struct igb_adapter, m)
48static const struct igb_stats igb_gstrings_stats[] = {
49 { "rx_packets", IGB_STAT(stats.gprc) },
50 { "tx_packets", IGB_STAT(stats.gptc) },
51 { "rx_bytes", IGB_STAT(stats.gorc) },
52 { "tx_bytes", IGB_STAT(stats.gotc) },
53 { "rx_broadcast", IGB_STAT(stats.bprc) },
54 { "tx_broadcast", IGB_STAT(stats.bptc) },
55 { "rx_multicast", IGB_STAT(stats.mprc) },
56 { "tx_multicast", IGB_STAT(stats.mptc) },
57 { "rx_errors", IGB_STAT(net_stats.rx_errors) },
58 { "tx_errors", IGB_STAT(net_stats.tx_errors) },
59 { "tx_dropped", IGB_STAT(net_stats.tx_dropped) },
60 { "multicast", IGB_STAT(stats.mprc) },
61 { "collisions", IGB_STAT(stats.colc) },
62 { "rx_length_errors", IGB_STAT(net_stats.rx_length_errors) },
63 { "rx_over_errors", IGB_STAT(net_stats.rx_over_errors) },
64 { "rx_crc_errors", IGB_STAT(stats.crcerrs) },
65 { "rx_frame_errors", IGB_STAT(net_stats.rx_frame_errors) },
66 { "rx_no_buffer_count", IGB_STAT(stats.rnbc) },
67 { "rx_missed_errors", IGB_STAT(stats.mpc) },
68 { "tx_aborted_errors", IGB_STAT(stats.ecol) },
69 { "tx_carrier_errors", IGB_STAT(stats.tncrs) },
70 { "tx_fifo_errors", IGB_STAT(net_stats.tx_fifo_errors) },
71 { "tx_heartbeat_errors", IGB_STAT(net_stats.tx_heartbeat_errors) },
72 { "tx_window_errors", IGB_STAT(stats.latecol) },
73 { "tx_abort_late_coll", IGB_STAT(stats.latecol) },
74 { "tx_deferred_ok", IGB_STAT(stats.dc) },
75 { "tx_single_coll_ok", IGB_STAT(stats.scc) },
76 { "tx_multi_coll_ok", IGB_STAT(stats.mcc) },
77 { "tx_timeout_count", IGB_STAT(tx_timeout_count) },
78 { "tx_restart_queue", IGB_STAT(restart_queue) },
79 { "rx_long_length_errors", IGB_STAT(stats.roc) },
80 { "rx_short_length_errors", IGB_STAT(stats.ruc) },
81 { "rx_align_errors", IGB_STAT(stats.algnerrc) },
82 { "tx_tcp_seg_good", IGB_STAT(stats.tsctc) },
83 { "tx_tcp_seg_failed", IGB_STAT(stats.tsctfc) },
84 { "rx_flow_control_xon", IGB_STAT(stats.xonrxc) },
85 { "rx_flow_control_xoff", IGB_STAT(stats.xoffrxc) },
86 { "tx_flow_control_xon", IGB_STAT(stats.xontxc) },
87 { "tx_flow_control_xoff", IGB_STAT(stats.xofftxc) },
88 { "rx_long_byte_count", IGB_STAT(stats.gorc) },
89 { "rx_csum_offload_good", IGB_STAT(hw_csum_good) },
90 { "rx_csum_offload_errors", IGB_STAT(hw_csum_err) },
Auke Kok9d5c8242008-01-24 02:22:38 -080091 { "alloc_rx_buff_failed", IGB_STAT(alloc_rx_buff_failed) },
92 { "tx_smbus", IGB_STAT(stats.mgptc) },
93 { "rx_smbus", IGB_STAT(stats.mgprc) },
94 { "dropped_smbus", IGB_STAT(stats.mgpdc) },
95};
96
97#define IGB_QUEUE_STATS_LEN \
Wang Chen4cf16532008-11-12 23:38:14 -080098 ((((struct igb_adapter *)netdev_priv(netdev))->num_rx_queues + \
99 ((struct igb_adapter *)netdev_priv(netdev))->num_tx_queues) * \
Auke Kok9d5c8242008-01-24 02:22:38 -0800100 (sizeof(struct igb_queue_stats) / sizeof(u64)))
101#define IGB_GLOBAL_STATS_LEN \
102 sizeof(igb_gstrings_stats) / sizeof(struct igb_stats)
103#define IGB_STATS_LEN (IGB_GLOBAL_STATS_LEN + IGB_QUEUE_STATS_LEN)
104static const char igb_gstrings_test[][ETH_GSTRING_LEN] = {
105 "Register test (offline)", "Eeprom test (offline)",
106 "Interrupt test (offline)", "Loopback test (offline)",
107 "Link test (on/offline)"
108};
109#define IGB_TEST_LEN sizeof(igb_gstrings_test) / ETH_GSTRING_LEN
110
111static int igb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
112{
113 struct igb_adapter *adapter = netdev_priv(netdev);
114 struct e1000_hw *hw = &adapter->hw;
115
116 if (hw->phy.media_type == e1000_media_type_copper) {
117
118 ecmd->supported = (SUPPORTED_10baseT_Half |
119 SUPPORTED_10baseT_Full |
120 SUPPORTED_100baseT_Half |
121 SUPPORTED_100baseT_Full |
122 SUPPORTED_1000baseT_Full|
123 SUPPORTED_Autoneg |
124 SUPPORTED_TP);
125 ecmd->advertising = ADVERTISED_TP;
126
127 if (hw->mac.autoneg == 1) {
128 ecmd->advertising |= ADVERTISED_Autoneg;
129 /* the e1000 autoneg seems to match ethtool nicely */
130 ecmd->advertising |= hw->phy.autoneg_advertised;
131 }
132
133 ecmd->port = PORT_TP;
134 ecmd->phy_address = hw->phy.addr;
135 } else {
136 ecmd->supported = (SUPPORTED_1000baseT_Full |
137 SUPPORTED_FIBRE |
138 SUPPORTED_Autoneg);
139
140 ecmd->advertising = (ADVERTISED_1000baseT_Full |
141 ADVERTISED_FIBRE |
142 ADVERTISED_Autoneg);
143
144 ecmd->port = PORT_FIBRE;
145 }
146
147 ecmd->transceiver = XCVR_INTERNAL;
148
149 if (rd32(E1000_STATUS) & E1000_STATUS_LU) {
150
151 adapter->hw.mac.ops.get_speed_and_duplex(hw,
152 &adapter->link_speed,
153 &adapter->link_duplex);
154 ecmd->speed = adapter->link_speed;
155
156 /* unfortunately FULL_DUPLEX != DUPLEX_FULL
157 * and HALF_DUPLEX != DUPLEX_HALF */
158
159 if (adapter->link_duplex == FULL_DUPLEX)
160 ecmd->duplex = DUPLEX_FULL;
161 else
162 ecmd->duplex = DUPLEX_HALF;
163 } else {
164 ecmd->speed = -1;
165 ecmd->duplex = -1;
166 }
167
168 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
169 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
170 return 0;
171}
172
173static int igb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
174{
175 struct igb_adapter *adapter = netdev_priv(netdev);
176 struct e1000_hw *hw = &adapter->hw;
177
178 /* When SoL/IDER sessions are active, autoneg/speed/duplex
179 * cannot be changed */
180 if (igb_check_reset_block(hw)) {
181 dev_err(&adapter->pdev->dev, "Cannot change link "
182 "characteristics when SoL/IDER is active.\n");
183 return -EINVAL;
184 }
185
186 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
187 msleep(1);
188
189 if (ecmd->autoneg == AUTONEG_ENABLE) {
190 hw->mac.autoneg = 1;
191 if (hw->phy.media_type == e1000_media_type_fiber)
192 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
193 ADVERTISED_FIBRE |
194 ADVERTISED_Autoneg;
195 else
196 hw->phy.autoneg_advertised = ecmd->advertising |
197 ADVERTISED_TP |
198 ADVERTISED_Autoneg;
199 ecmd->advertising = hw->phy.autoneg_advertised;
200 } else
201 if (igb_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
202 clear_bit(__IGB_RESETTING, &adapter->state);
203 return -EINVAL;
204 }
205
206 /* reset the link */
207
208 if (netif_running(adapter->netdev)) {
209 igb_down(adapter);
210 igb_up(adapter);
211 } else
212 igb_reset(adapter);
213
214 clear_bit(__IGB_RESETTING, &adapter->state);
215 return 0;
216}
217
218static void igb_get_pauseparam(struct net_device *netdev,
219 struct ethtool_pauseparam *pause)
220{
221 struct igb_adapter *adapter = netdev_priv(netdev);
222 struct e1000_hw *hw = &adapter->hw;
223
224 pause->autoneg =
225 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
226
227 if (hw->fc.type == e1000_fc_rx_pause)
228 pause->rx_pause = 1;
229 else if (hw->fc.type == e1000_fc_tx_pause)
230 pause->tx_pause = 1;
231 else if (hw->fc.type == e1000_fc_full) {
232 pause->rx_pause = 1;
233 pause->tx_pause = 1;
234 }
235}
236
237static int igb_set_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 int retval = 0;
243
244 adapter->fc_autoneg = pause->autoneg;
245
246 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
247 msleep(1);
248
249 if (pause->rx_pause && pause->tx_pause)
250 hw->fc.type = e1000_fc_full;
251 else if (pause->rx_pause && !pause->tx_pause)
252 hw->fc.type = e1000_fc_rx_pause;
253 else if (!pause->rx_pause && pause->tx_pause)
254 hw->fc.type = e1000_fc_tx_pause;
255 else if (!pause->rx_pause && !pause->tx_pause)
256 hw->fc.type = e1000_fc_none;
257
258 hw->fc.original_type = hw->fc.type;
259
260 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
261 if (netif_running(adapter->netdev)) {
262 igb_down(adapter);
263 igb_up(adapter);
264 } else
265 igb_reset(adapter);
266 } else
267 retval = ((hw->phy.media_type == e1000_media_type_fiber) ?
268 igb_setup_link(hw) : igb_force_mac_fc(hw));
269
270 clear_bit(__IGB_RESETTING, &adapter->state);
271 return retval;
272}
273
274static u32 igb_get_rx_csum(struct net_device *netdev)
275{
276 struct igb_adapter *adapter = netdev_priv(netdev);
277 return adapter->rx_csum;
278}
279
280static int igb_set_rx_csum(struct net_device *netdev, u32 data)
281{
282 struct igb_adapter *adapter = netdev_priv(netdev);
283 adapter->rx_csum = data;
284
285 return 0;
286}
287
288static u32 igb_get_tx_csum(struct net_device *netdev)
289{
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000290 return (netdev->features & NETIF_F_IP_CSUM) != 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800291}
292
293static int igb_set_tx_csum(struct net_device *netdev, u32 data)
294{
295 if (data)
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000296 netdev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
Auke Kok9d5c8242008-01-24 02:22:38 -0800297 else
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000298 netdev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
Auke Kok9d5c8242008-01-24 02:22:38 -0800299
300 return 0;
301}
302
303static int igb_set_tso(struct net_device *netdev, u32 data)
304{
305 struct igb_adapter *adapter = netdev_priv(netdev);
306
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000307 if (data) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800308 netdev->features |= NETIF_F_TSO;
Auke Kok9d5c8242008-01-24 02:22:38 -0800309 netdev->features |= NETIF_F_TSO6;
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000310 } else {
311 netdev->features &= ~NETIF_F_TSO;
Auke Kok9d5c8242008-01-24 02:22:38 -0800312 netdev->features &= ~NETIF_F_TSO6;
Alexander Duyck7d8eb292009-02-06 23:18:27 +0000313 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800314
315 dev_info(&adapter->pdev->dev, "TSO is %s\n",
316 data ? "Enabled" : "Disabled");
317 return 0;
318}
319
320static u32 igb_get_msglevel(struct net_device *netdev)
321{
322 struct igb_adapter *adapter = netdev_priv(netdev);
323 return adapter->msg_enable;
324}
325
326static void igb_set_msglevel(struct net_device *netdev, u32 data)
327{
328 struct igb_adapter *adapter = netdev_priv(netdev);
329 adapter->msg_enable = data;
330}
331
332static int igb_get_regs_len(struct net_device *netdev)
333{
334#define IGB_REGS_LEN 551
335 return IGB_REGS_LEN * sizeof(u32);
336}
337
338static void igb_get_regs(struct net_device *netdev,
339 struct ethtool_regs *regs, void *p)
340{
341 struct igb_adapter *adapter = netdev_priv(netdev);
342 struct e1000_hw *hw = &adapter->hw;
343 u32 *regs_buff = p;
344 u8 i;
345
346 memset(p, 0, IGB_REGS_LEN * sizeof(u32));
347
348 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
349
350 /* General Registers */
351 regs_buff[0] = rd32(E1000_CTRL);
352 regs_buff[1] = rd32(E1000_STATUS);
353 regs_buff[2] = rd32(E1000_CTRL_EXT);
354 regs_buff[3] = rd32(E1000_MDIC);
355 regs_buff[4] = rd32(E1000_SCTL);
356 regs_buff[5] = rd32(E1000_CONNSW);
357 regs_buff[6] = rd32(E1000_VET);
358 regs_buff[7] = rd32(E1000_LEDCTL);
359 regs_buff[8] = rd32(E1000_PBA);
360 regs_buff[9] = rd32(E1000_PBS);
361 regs_buff[10] = rd32(E1000_FRTIMER);
362 regs_buff[11] = rd32(E1000_TCPTIMER);
363
364 /* NVM Register */
365 regs_buff[12] = rd32(E1000_EECD);
366
367 /* Interrupt */
Alexander Duyckfe59de32008-08-26 04:25:05 -0700368 /* Reading EICS for EICR because they read the
369 * same but EICS does not clear on read */
370 regs_buff[13] = rd32(E1000_EICS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800371 regs_buff[14] = rd32(E1000_EICS);
372 regs_buff[15] = rd32(E1000_EIMS);
373 regs_buff[16] = rd32(E1000_EIMC);
374 regs_buff[17] = rd32(E1000_EIAC);
375 regs_buff[18] = rd32(E1000_EIAM);
Alexander Duyckfe59de32008-08-26 04:25:05 -0700376 /* Reading ICS for ICR because they read the
377 * same but ICS does not clear on read */
378 regs_buff[19] = rd32(E1000_ICS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800379 regs_buff[20] = rd32(E1000_ICS);
380 regs_buff[21] = rd32(E1000_IMS);
381 regs_buff[22] = rd32(E1000_IMC);
382 regs_buff[23] = rd32(E1000_IAC);
383 regs_buff[24] = rd32(E1000_IAM);
384 regs_buff[25] = rd32(E1000_IMIRVP);
385
386 /* Flow Control */
387 regs_buff[26] = rd32(E1000_FCAL);
388 regs_buff[27] = rd32(E1000_FCAH);
389 regs_buff[28] = rd32(E1000_FCTTV);
390 regs_buff[29] = rd32(E1000_FCRTL);
391 regs_buff[30] = rd32(E1000_FCRTH);
392 regs_buff[31] = rd32(E1000_FCRTV);
393
394 /* Receive */
395 regs_buff[32] = rd32(E1000_RCTL);
396 regs_buff[33] = rd32(E1000_RXCSUM);
397 regs_buff[34] = rd32(E1000_RLPML);
398 regs_buff[35] = rd32(E1000_RFCTL);
399 regs_buff[36] = rd32(E1000_MRQC);
400 regs_buff[37] = rd32(E1000_VMD_CTL);
401
402 /* Transmit */
403 regs_buff[38] = rd32(E1000_TCTL);
404 regs_buff[39] = rd32(E1000_TCTL_EXT);
405 regs_buff[40] = rd32(E1000_TIPG);
406 regs_buff[41] = rd32(E1000_DTXCTL);
407
408 /* Wake Up */
409 regs_buff[42] = rd32(E1000_WUC);
410 regs_buff[43] = rd32(E1000_WUFC);
411 regs_buff[44] = rd32(E1000_WUS);
412 regs_buff[45] = rd32(E1000_IPAV);
413 regs_buff[46] = rd32(E1000_WUPL);
414
415 /* MAC */
416 regs_buff[47] = rd32(E1000_PCS_CFG0);
417 regs_buff[48] = rd32(E1000_PCS_LCTL);
418 regs_buff[49] = rd32(E1000_PCS_LSTAT);
419 regs_buff[50] = rd32(E1000_PCS_ANADV);
420 regs_buff[51] = rd32(E1000_PCS_LPAB);
421 regs_buff[52] = rd32(E1000_PCS_NPTX);
422 regs_buff[53] = rd32(E1000_PCS_LPABNP);
423
424 /* Statistics */
425 regs_buff[54] = adapter->stats.crcerrs;
426 regs_buff[55] = adapter->stats.algnerrc;
427 regs_buff[56] = adapter->stats.symerrs;
428 regs_buff[57] = adapter->stats.rxerrc;
429 regs_buff[58] = adapter->stats.mpc;
430 regs_buff[59] = adapter->stats.scc;
431 regs_buff[60] = adapter->stats.ecol;
432 regs_buff[61] = adapter->stats.mcc;
433 regs_buff[62] = adapter->stats.latecol;
434 regs_buff[63] = adapter->stats.colc;
435 regs_buff[64] = adapter->stats.dc;
436 regs_buff[65] = adapter->stats.tncrs;
437 regs_buff[66] = adapter->stats.sec;
438 regs_buff[67] = adapter->stats.htdpmc;
439 regs_buff[68] = adapter->stats.rlec;
440 regs_buff[69] = adapter->stats.xonrxc;
441 regs_buff[70] = adapter->stats.xontxc;
442 regs_buff[71] = adapter->stats.xoffrxc;
443 regs_buff[72] = adapter->stats.xofftxc;
444 regs_buff[73] = adapter->stats.fcruc;
445 regs_buff[74] = adapter->stats.prc64;
446 regs_buff[75] = adapter->stats.prc127;
447 regs_buff[76] = adapter->stats.prc255;
448 regs_buff[77] = adapter->stats.prc511;
449 regs_buff[78] = adapter->stats.prc1023;
450 regs_buff[79] = adapter->stats.prc1522;
451 regs_buff[80] = adapter->stats.gprc;
452 regs_buff[81] = adapter->stats.bprc;
453 regs_buff[82] = adapter->stats.mprc;
454 regs_buff[83] = adapter->stats.gptc;
455 regs_buff[84] = adapter->stats.gorc;
456 regs_buff[86] = adapter->stats.gotc;
457 regs_buff[88] = adapter->stats.rnbc;
458 regs_buff[89] = adapter->stats.ruc;
459 regs_buff[90] = adapter->stats.rfc;
460 regs_buff[91] = adapter->stats.roc;
461 regs_buff[92] = adapter->stats.rjc;
462 regs_buff[93] = adapter->stats.mgprc;
463 regs_buff[94] = adapter->stats.mgpdc;
464 regs_buff[95] = adapter->stats.mgptc;
465 regs_buff[96] = adapter->stats.tor;
466 regs_buff[98] = adapter->stats.tot;
467 regs_buff[100] = adapter->stats.tpr;
468 regs_buff[101] = adapter->stats.tpt;
469 regs_buff[102] = adapter->stats.ptc64;
470 regs_buff[103] = adapter->stats.ptc127;
471 regs_buff[104] = adapter->stats.ptc255;
472 regs_buff[105] = adapter->stats.ptc511;
473 regs_buff[106] = adapter->stats.ptc1023;
474 regs_buff[107] = adapter->stats.ptc1522;
475 regs_buff[108] = adapter->stats.mptc;
476 regs_buff[109] = adapter->stats.bptc;
477 regs_buff[110] = adapter->stats.tsctc;
478 regs_buff[111] = adapter->stats.iac;
479 regs_buff[112] = adapter->stats.rpthc;
480 regs_buff[113] = adapter->stats.hgptc;
481 regs_buff[114] = adapter->stats.hgorc;
482 regs_buff[116] = adapter->stats.hgotc;
483 regs_buff[118] = adapter->stats.lenerrs;
484 regs_buff[119] = adapter->stats.scvpc;
485 regs_buff[120] = adapter->stats.hrmpc;
486
487 /* These should probably be added to e1000_regs.h instead */
488 #define E1000_PSRTYPE_REG(_i) (0x05480 + ((_i) * 4))
Auke Kok9d5c8242008-01-24 02:22:38 -0800489 #define E1000_IP4AT_REG(_i) (0x05840 + ((_i) * 8))
490 #define E1000_IP6AT_REG(_i) (0x05880 + ((_i) * 4))
491 #define E1000_WUPM_REG(_i) (0x05A00 + ((_i) * 4))
492 #define E1000_FFMT_REG(_i) (0x09000 + ((_i) * 8))
493 #define E1000_FFVT_REG(_i) (0x09800 + ((_i) * 8))
494 #define E1000_FFLT_REG(_i) (0x05F00 + ((_i) * 8))
495
496 for (i = 0; i < 4; i++)
497 regs_buff[121 + i] = rd32(E1000_SRRCTL(i));
498 for (i = 0; i < 4; i++)
499 regs_buff[125 + i] = rd32(E1000_PSRTYPE_REG(i));
500 for (i = 0; i < 4; i++)
501 regs_buff[129 + i] = rd32(E1000_RDBAL(i));
502 for (i = 0; i < 4; i++)
503 regs_buff[133 + i] = rd32(E1000_RDBAH(i));
504 for (i = 0; i < 4; i++)
505 regs_buff[137 + i] = rd32(E1000_RDLEN(i));
506 for (i = 0; i < 4; i++)
507 regs_buff[141 + i] = rd32(E1000_RDH(i));
508 for (i = 0; i < 4; i++)
509 regs_buff[145 + i] = rd32(E1000_RDT(i));
510 for (i = 0; i < 4; i++)
511 regs_buff[149 + i] = rd32(E1000_RXDCTL(i));
512
513 for (i = 0; i < 10; i++)
514 regs_buff[153 + i] = rd32(E1000_EITR(i));
515 for (i = 0; i < 8; i++)
516 regs_buff[163 + i] = rd32(E1000_IMIR(i));
517 for (i = 0; i < 8; i++)
518 regs_buff[171 + i] = rd32(E1000_IMIREXT(i));
519 for (i = 0; i < 16; i++)
520 regs_buff[179 + i] = rd32(E1000_RAL(i));
521 for (i = 0; i < 16; i++)
522 regs_buff[195 + i] = rd32(E1000_RAH(i));
523
524 for (i = 0; i < 4; i++)
525 regs_buff[211 + i] = rd32(E1000_TDBAL(i));
526 for (i = 0; i < 4; i++)
527 regs_buff[215 + i] = rd32(E1000_TDBAH(i));
528 for (i = 0; i < 4; i++)
529 regs_buff[219 + i] = rd32(E1000_TDLEN(i));
530 for (i = 0; i < 4; i++)
531 regs_buff[223 + i] = rd32(E1000_TDH(i));
532 for (i = 0; i < 4; i++)
533 regs_buff[227 + i] = rd32(E1000_TDT(i));
534 for (i = 0; i < 4; i++)
535 regs_buff[231 + i] = rd32(E1000_TXDCTL(i));
536 for (i = 0; i < 4; i++)
537 regs_buff[235 + i] = rd32(E1000_TDWBAL(i));
538 for (i = 0; i < 4; i++)
539 regs_buff[239 + i] = rd32(E1000_TDWBAH(i));
540 for (i = 0; i < 4; i++)
541 regs_buff[243 + i] = rd32(E1000_DCA_TXCTRL(i));
542
543 for (i = 0; i < 4; i++)
544 regs_buff[247 + i] = rd32(E1000_IP4AT_REG(i));
545 for (i = 0; i < 4; i++)
546 regs_buff[251 + i] = rd32(E1000_IP6AT_REG(i));
547 for (i = 0; i < 32; i++)
548 regs_buff[255 + i] = rd32(E1000_WUPM_REG(i));
549 for (i = 0; i < 128; i++)
550 regs_buff[287 + i] = rd32(E1000_FFMT_REG(i));
551 for (i = 0; i < 128; i++)
552 regs_buff[415 + i] = rd32(E1000_FFVT_REG(i));
553 for (i = 0; i < 4; i++)
554 regs_buff[543 + i] = rd32(E1000_FFLT_REG(i));
555
556 regs_buff[547] = rd32(E1000_TDFH);
557 regs_buff[548] = rd32(E1000_TDFT);
558 regs_buff[549] = rd32(E1000_TDFHS);
559 regs_buff[550] = rd32(E1000_TDFPC);
560
561}
562
563static int igb_get_eeprom_len(struct net_device *netdev)
564{
565 struct igb_adapter *adapter = netdev_priv(netdev);
566 return adapter->hw.nvm.word_size * 2;
567}
568
569static int igb_get_eeprom(struct net_device *netdev,
570 struct ethtool_eeprom *eeprom, u8 *bytes)
571{
572 struct igb_adapter *adapter = netdev_priv(netdev);
573 struct e1000_hw *hw = &adapter->hw;
574 u16 *eeprom_buff;
575 int first_word, last_word;
576 int ret_val = 0;
577 u16 i;
578
579 if (eeprom->len == 0)
580 return -EINVAL;
581
582 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
583
584 first_word = eeprom->offset >> 1;
585 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
586
587 eeprom_buff = kmalloc(sizeof(u16) *
588 (last_word - first_word + 1), GFP_KERNEL);
589 if (!eeprom_buff)
590 return -ENOMEM;
591
592 if (hw->nvm.type == e1000_nvm_eeprom_spi)
Alexander Duyck312c75a2009-02-06 23:17:47 +0000593 ret_val = hw->nvm.ops.read(hw, first_word,
Auke Kok9d5c8242008-01-24 02:22:38 -0800594 last_word - first_word + 1,
595 eeprom_buff);
596 else {
597 for (i = 0; i < last_word - first_word + 1; i++) {
Alexander Duyck312c75a2009-02-06 23:17:47 +0000598 ret_val = hw->nvm.ops.read(hw, first_word + i, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800599 &eeprom_buff[i]);
600 if (ret_val)
601 break;
602 }
603 }
604
605 /* Device's eeprom is always little-endian, word addressable */
606 for (i = 0; i < last_word - first_word + 1; i++)
607 le16_to_cpus(&eeprom_buff[i]);
608
609 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
610 eeprom->len);
611 kfree(eeprom_buff);
612
613 return ret_val;
614}
615
616static int igb_set_eeprom(struct net_device *netdev,
617 struct ethtool_eeprom *eeprom, u8 *bytes)
618{
619 struct igb_adapter *adapter = netdev_priv(netdev);
620 struct e1000_hw *hw = &adapter->hw;
621 u16 *eeprom_buff;
622 void *ptr;
623 int max_len, first_word, last_word, ret_val = 0;
624 u16 i;
625
626 if (eeprom->len == 0)
627 return -EOPNOTSUPP;
628
629 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
630 return -EFAULT;
631
632 max_len = hw->nvm.word_size * 2;
633
634 first_word = eeprom->offset >> 1;
635 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
636 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
637 if (!eeprom_buff)
638 return -ENOMEM;
639
640 ptr = (void *)eeprom_buff;
641
642 if (eeprom->offset & 1) {
643 /* need read/modify/write of first changed EEPROM word */
644 /* only the second byte of the word is being modified */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000645 ret_val = hw->nvm.ops.read(hw, first_word, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800646 &eeprom_buff[0]);
647 ptr++;
648 }
649 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
650 /* need read/modify/write of last changed EEPROM word */
651 /* only the first byte of the word is being modified */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000652 ret_val = hw->nvm.ops.read(hw, last_word, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800653 &eeprom_buff[last_word - first_word]);
654 }
655
656 /* Device's eeprom is always little-endian, word addressable */
657 for (i = 0; i < last_word - first_word + 1; i++)
658 le16_to_cpus(&eeprom_buff[i]);
659
660 memcpy(ptr, bytes, eeprom->len);
661
662 for (i = 0; i < last_word - first_word + 1; i++)
663 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
664
Alexander Duyck312c75a2009-02-06 23:17:47 +0000665 ret_val = hw->nvm.ops.write(hw, first_word,
Auke Kok9d5c8242008-01-24 02:22:38 -0800666 last_word - first_word + 1, eeprom_buff);
667
668 /* Update the checksum over the first part of the EEPROM if needed
669 * and flush shadow RAM for 82573 controllers */
670 if ((ret_val == 0) && ((first_word <= NVM_CHECKSUM_REG)))
671 igb_update_nvm_checksum(hw);
672
673 kfree(eeprom_buff);
674 return ret_val;
675}
676
677static void igb_get_drvinfo(struct net_device *netdev,
678 struct ethtool_drvinfo *drvinfo)
679{
680 struct igb_adapter *adapter = netdev_priv(netdev);
681 char firmware_version[32];
682 u16 eeprom_data;
683
684 strncpy(drvinfo->driver, igb_driver_name, 32);
685 strncpy(drvinfo->version, igb_driver_version, 32);
686
687 /* EEPROM image version # is reported as firmware version # for
688 * 82575 controllers */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000689 adapter->hw.nvm.ops.read(&adapter->hw, 5, 1, &eeprom_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800690 sprintf(firmware_version, "%d.%d-%d",
691 (eeprom_data & 0xF000) >> 12,
692 (eeprom_data & 0x0FF0) >> 4,
693 eeprom_data & 0x000F);
694
695 strncpy(drvinfo->fw_version, firmware_version, 32);
696 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
697 drvinfo->n_stats = IGB_STATS_LEN;
698 drvinfo->testinfo_len = IGB_TEST_LEN;
699 drvinfo->regdump_len = igb_get_regs_len(netdev);
700 drvinfo->eedump_len = igb_get_eeprom_len(netdev);
701}
702
703static void igb_get_ringparam(struct net_device *netdev,
704 struct ethtool_ringparam *ring)
705{
706 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -0800707
708 ring->rx_max_pending = IGB_MAX_RXD;
709 ring->tx_max_pending = IGB_MAX_TXD;
710 ring->rx_mini_max_pending = 0;
711 ring->rx_jumbo_max_pending = 0;
Alexander Duyck68fd9912008-11-20 00:48:10 -0800712 ring->rx_pending = adapter->rx_ring_count;
713 ring->tx_pending = adapter->tx_ring_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800714 ring->rx_mini_pending = 0;
715 ring->rx_jumbo_pending = 0;
716}
717
718static int igb_set_ringparam(struct net_device *netdev,
719 struct ethtool_ringparam *ring)
720{
721 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800722 struct igb_ring *temp_ring;
Auke Kok9d5c8242008-01-24 02:22:38 -0800723 int i, err;
Alexander Duyck68fd9912008-11-20 00:48:10 -0800724 u32 new_rx_count, new_tx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800725
726 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
727 return -EINVAL;
728
729 new_rx_count = max(ring->rx_pending, (u32)IGB_MIN_RXD);
730 new_rx_count = min(new_rx_count, (u32)IGB_MAX_RXD);
731 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
732
733 new_tx_count = max(ring->tx_pending, (u32)IGB_MIN_TXD);
734 new_tx_count = min(new_tx_count, (u32)IGB_MAX_TXD);
735 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
736
Alexander Duyck68fd9912008-11-20 00:48:10 -0800737 if ((new_tx_count == adapter->tx_ring_count) &&
738 (new_rx_count == adapter->rx_ring_count)) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800739 /* nothing to do */
740 return 0;
741 }
742
Alexander Duyck68fd9912008-11-20 00:48:10 -0800743 if (adapter->num_tx_queues > adapter->num_rx_queues)
744 temp_ring = vmalloc(adapter->num_tx_queues * sizeof(struct igb_ring));
745 else
746 temp_ring = vmalloc(adapter->num_rx_queues * sizeof(struct igb_ring));
747 if (!temp_ring)
748 return -ENOMEM;
749
Auke Kok9d5c8242008-01-24 02:22:38 -0800750 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
751 msleep(1);
752
753 if (netif_running(adapter->netdev))
754 igb_down(adapter);
755
756 /*
757 * We can't just free everything and then setup again,
758 * because the ISRs in MSI-X mode get passed pointers
759 * to the tx and rx ring structs.
760 */
Alexander Duyck68fd9912008-11-20 00:48:10 -0800761 if (new_tx_count != adapter->tx_ring_count) {
762 memcpy(temp_ring, adapter->tx_ring,
763 adapter->num_tx_queues * sizeof(struct igb_ring));
764
Auke Kok9d5c8242008-01-24 02:22:38 -0800765 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800766 temp_ring[i].count = new_tx_count;
767 err = igb_setup_tx_resources(adapter, &temp_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800768 if (err) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800769 while (i) {
770 i--;
771 igb_free_tx_resources(&temp_ring[i]);
772 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800773 goto err_setup;
774 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800775 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800776
777 for (i = 0; i < adapter->num_tx_queues; i++)
778 igb_free_tx_resources(&adapter->tx_ring[i]);
779
780 memcpy(adapter->tx_ring, temp_ring,
781 adapter->num_tx_queues * sizeof(struct igb_ring));
782
783 adapter->tx_ring_count = new_tx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800784 }
785
786 if (new_rx_count != adapter->rx_ring->count) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800787 memcpy(temp_ring, adapter->rx_ring,
788 adapter->num_rx_queues * sizeof(struct igb_ring));
789
Auke Kok9d5c8242008-01-24 02:22:38 -0800790 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800791 temp_ring[i].count = new_rx_count;
792 err = igb_setup_rx_resources(adapter, &temp_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800793 if (err) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800794 while (i) {
795 i--;
796 igb_free_rx_resources(&temp_ring[i]);
797 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800798 goto err_setup;
799 }
800
Auke Kok9d5c8242008-01-24 02:22:38 -0800801 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800802
803 for (i = 0; i < adapter->num_rx_queues; i++)
804 igb_free_rx_resources(&adapter->rx_ring[i]);
805
806 memcpy(adapter->rx_ring, temp_ring,
807 adapter->num_rx_queues * sizeof(struct igb_ring));
808
809 adapter->rx_ring_count = new_rx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800810 }
811
812 err = 0;
813err_setup:
814 if (netif_running(adapter->netdev))
815 igb_up(adapter);
816
817 clear_bit(__IGB_RESETTING, &adapter->state);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800818 vfree(temp_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -0800819 return err;
820}
821
822/* ethtool register test data */
823struct igb_reg_test {
824 u16 reg;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700825 u16 reg_offset;
826 u16 array_len;
827 u16 test_type;
Auke Kok9d5c8242008-01-24 02:22:38 -0800828 u32 mask;
829 u32 write;
830};
831
832/* In the hardware, registers are laid out either singly, in arrays
833 * spaced 0x100 bytes apart, or in contiguous tables. We assume
834 * most tests take place on arrays or single registers (handled
835 * as a single-element array) and special-case the tables.
836 * Table tests are always pattern tests.
837 *
838 * We also make provision for some required setup steps by specifying
839 * registers to be written without any read-back testing.
840 */
841
842#define PATTERN_TEST 1
843#define SET_READ_TEST 2
844#define WRITE_NO_TEST 3
845#define TABLE32_TEST 4
846#define TABLE64_TEST_LO 5
847#define TABLE64_TEST_HI 6
848
Alexander Duyck2d064c02008-07-08 15:10:12 -0700849/* 82576 reg test */
850static struct igb_reg_test reg_test_82576[] = {
851 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
852 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
853 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
854 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
855 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
856 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
857 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
858 { E1000_RDBAL(4), 0x40, 8, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
859 { E1000_RDBAH(4), 0x40, 8, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
860 { E1000_RDLEN(4), 0x40, 8, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Auke Kok9d5c8242008-01-24 02:22:38 -0800861 /* Enable all four RX queues before testing. */
Alexander Duyck2d064c02008-07-08 15:10:12 -0700862 { E1000_RXDCTL(0), 0x100, 1, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE },
863 /* RDH is read-only for 82576, only test RDT. */
864 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
865 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
866 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
867 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
868 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
869 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
870 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
871 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
872 { E1000_TDBAL(4), 0x40, 8, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
873 { E1000_TDBAH(4), 0x40, 8, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
874 { E1000_TDLEN(4), 0x40, 8, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
875 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
876 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
877 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
878 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
879 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
880 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF },
881 { E1000_RA2, 0, 8, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
882 { E1000_RA2, 0, 8, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF },
883 { E1000_MTA, 0, 128,TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
884 { 0, 0, 0, 0 }
885};
886
887/* 82575 register test */
888static struct igb_reg_test reg_test_82575[] = {
889 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
890 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
891 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
892 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
893 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
894 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
895 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
896 /* Enable all four RX queues before testing. */
897 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE },
Auke Kok9d5c8242008-01-24 02:22:38 -0800898 /* RDH is read-only for 82575, only test RDT. */
Alexander Duyck2d064c02008-07-08 15:10:12 -0700899 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
900 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
901 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
902 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
903 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
904 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
905 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
906 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
907 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
908 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0x003FFFFB },
909 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0xFFFFFFFF },
910 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
911 { E1000_TXCW, 0x100, 1, PATTERN_TEST, 0xC000FFFF, 0x0000FFFF },
912 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
913 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x800FFFFF, 0xFFFFFFFF },
914 { E1000_MTA, 0, 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Auke Kok9d5c8242008-01-24 02:22:38 -0800915 { 0, 0, 0, 0 }
916};
917
918static bool reg_pattern_test(struct igb_adapter *adapter, u64 *data,
919 int reg, u32 mask, u32 write)
920{
921 u32 pat, val;
922 u32 _test[] =
923 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
924 for (pat = 0; pat < ARRAY_SIZE(_test); pat++) {
925 writel((_test[pat] & write), (adapter->hw.hw_addr + reg));
926 val = readl(adapter->hw.hw_addr + reg);
927 if (val != (_test[pat] & write & mask)) {
928 dev_err(&adapter->pdev->dev, "pattern test reg %04X "
929 "failed: got 0x%08X expected 0x%08X\n",
930 reg, val, (_test[pat] & write & mask));
931 *data = reg;
932 return 1;
933 }
934 }
935 return 0;
936}
937
938static bool reg_set_and_check(struct igb_adapter *adapter, u64 *data,
939 int reg, u32 mask, u32 write)
940{
941 u32 val;
942 writel((write & mask), (adapter->hw.hw_addr + reg));
943 val = readl(adapter->hw.hw_addr + reg);
944 if ((write & mask) != (val & mask)) {
945 dev_err(&adapter->pdev->dev, "set/check reg %04X test failed:"
946 " got 0x%08X expected 0x%08X\n", reg,
947 (val & mask), (write & mask));
948 *data = reg;
949 return 1;
950 }
951 return 0;
952}
953
954#define REG_PATTERN_TEST(reg, mask, write) \
955 do { \
956 if (reg_pattern_test(adapter, data, reg, mask, write)) \
957 return 1; \
958 } while (0)
959
960#define REG_SET_AND_CHECK(reg, mask, write) \
961 do { \
962 if (reg_set_and_check(adapter, data, reg, mask, write)) \
963 return 1; \
964 } while (0)
965
966static int igb_reg_test(struct igb_adapter *adapter, u64 *data)
967{
968 struct e1000_hw *hw = &adapter->hw;
969 struct igb_reg_test *test;
970 u32 value, before, after;
971 u32 i, toggle;
972
973 toggle = 0x7FFFF3FF;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700974
975 switch (adapter->hw.mac.type) {
976 case e1000_82576:
977 test = reg_test_82576;
978 break;
979 default:
980 test = reg_test_82575;
981 break;
982 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800983
984 /* Because the status register is such a special case,
985 * we handle it separately from the rest of the register
986 * tests. Some bits are read-only, some toggle, and some
987 * are writable on newer MACs.
988 */
989 before = rd32(E1000_STATUS);
990 value = (rd32(E1000_STATUS) & toggle);
991 wr32(E1000_STATUS, toggle);
992 after = rd32(E1000_STATUS) & toggle;
993 if (value != after) {
994 dev_err(&adapter->pdev->dev, "failed STATUS register test "
995 "got: 0x%08X expected: 0x%08X\n", after, value);
996 *data = 1;
997 return 1;
998 }
999 /* restore previous status */
1000 wr32(E1000_STATUS, before);
1001
1002 /* Perform the remainder of the register test, looping through
1003 * the test table until we either fail or reach the null entry.
1004 */
1005 while (test->reg) {
1006 for (i = 0; i < test->array_len; i++) {
1007 switch (test->test_type) {
1008 case PATTERN_TEST:
Alexander Duyck2d064c02008-07-08 15:10:12 -07001009 REG_PATTERN_TEST(test->reg + (i * test->reg_offset),
Auke Kok9d5c8242008-01-24 02:22:38 -08001010 test->mask,
1011 test->write);
1012 break;
1013 case SET_READ_TEST:
Alexander Duyck2d064c02008-07-08 15:10:12 -07001014 REG_SET_AND_CHECK(test->reg + (i * test->reg_offset),
Auke Kok9d5c8242008-01-24 02:22:38 -08001015 test->mask,
1016 test->write);
1017 break;
1018 case WRITE_NO_TEST:
1019 writel(test->write,
1020 (adapter->hw.hw_addr + test->reg)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001021 + (i * test->reg_offset));
Auke Kok9d5c8242008-01-24 02:22:38 -08001022 break;
1023 case TABLE32_TEST:
1024 REG_PATTERN_TEST(test->reg + (i * 4),
1025 test->mask,
1026 test->write);
1027 break;
1028 case TABLE64_TEST_LO:
1029 REG_PATTERN_TEST(test->reg + (i * 8),
1030 test->mask,
1031 test->write);
1032 break;
1033 case TABLE64_TEST_HI:
1034 REG_PATTERN_TEST((test->reg + 4) + (i * 8),
1035 test->mask,
1036 test->write);
1037 break;
1038 }
1039 }
1040 test++;
1041 }
1042
1043 *data = 0;
1044 return 0;
1045}
1046
1047static int igb_eeprom_test(struct igb_adapter *adapter, u64 *data)
1048{
1049 u16 temp;
1050 u16 checksum = 0;
1051 u16 i;
1052
1053 *data = 0;
1054 /* Read and add up the contents of the EEPROM */
1055 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
Alexander Duyck312c75a2009-02-06 23:17:47 +00001056 if ((adapter->hw.nvm.ops.read(&adapter->hw, i, 1, &temp))
Auke Kok9d5c8242008-01-24 02:22:38 -08001057 < 0) {
1058 *data = 1;
1059 break;
1060 }
1061 checksum += temp;
1062 }
1063
1064 /* If Checksum is not Correct return error else test passed */
1065 if ((checksum != (u16) NVM_SUM) && !(*data))
1066 *data = 2;
1067
1068 return *data;
1069}
1070
1071static irqreturn_t igb_test_intr(int irq, void *data)
1072{
1073 struct net_device *netdev = (struct net_device *) data;
1074 struct igb_adapter *adapter = netdev_priv(netdev);
1075 struct e1000_hw *hw = &adapter->hw;
1076
1077 adapter->test_icr |= rd32(E1000_ICR);
1078
1079 return IRQ_HANDLED;
1080}
1081
1082static int igb_intr_test(struct igb_adapter *adapter, u64 *data)
1083{
1084 struct e1000_hw *hw = &adapter->hw;
1085 struct net_device *netdev = adapter->netdev;
1086 u32 mask, i = 0, shared_int = true;
1087 u32 irq = adapter->pdev->irq;
1088
1089 *data = 0;
1090
1091 /* Hook up test interrupt handler just for this test */
1092 if (adapter->msix_entries) {
1093 /* NOTE: we don't test MSI-X interrupts here, yet */
1094 return 0;
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001095 } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001096 shared_int = false;
1097 if (request_irq(irq, &igb_test_intr, 0, netdev->name, netdev)) {
1098 *data = 1;
1099 return -1;
1100 }
1101 } else if (!request_irq(irq, &igb_test_intr, IRQF_PROBE_SHARED,
1102 netdev->name, netdev)) {
1103 shared_int = false;
1104 } else if (request_irq(irq, &igb_test_intr, IRQF_SHARED,
1105 netdev->name, netdev)) {
1106 *data = 1;
1107 return -1;
1108 }
1109 dev_info(&adapter->pdev->dev, "testing %s interrupt\n",
1110 (shared_int ? "shared" : "unshared"));
1111
1112 /* Disable all the interrupts */
1113 wr32(E1000_IMC, 0xFFFFFFFF);
1114 msleep(10);
1115
1116 /* Test each interrupt */
1117 for (; i < 10; i++) {
1118 /* Interrupt to test */
1119 mask = 1 << i;
1120
1121 if (!shared_int) {
1122 /* Disable the interrupt to be reported in
1123 * the cause register and then force the same
1124 * interrupt and see if one gets posted. If
1125 * an interrupt was posted to the bus, the
1126 * test failed.
1127 */
1128 adapter->test_icr = 0;
1129 wr32(E1000_IMC, ~mask & 0x00007FFF);
1130 wr32(E1000_ICS, ~mask & 0x00007FFF);
1131 msleep(10);
1132
1133 if (adapter->test_icr & mask) {
1134 *data = 3;
1135 break;
1136 }
1137 }
1138
1139 /* Enable the interrupt to be reported in
1140 * the cause register and then force the same
1141 * interrupt and see if one gets posted. If
1142 * an interrupt was not posted to the bus, the
1143 * test failed.
1144 */
1145 adapter->test_icr = 0;
1146 wr32(E1000_IMS, mask);
1147 wr32(E1000_ICS, mask);
1148 msleep(10);
1149
1150 if (!(adapter->test_icr & mask)) {
1151 *data = 4;
1152 break;
1153 }
1154
1155 if (!shared_int) {
1156 /* Disable the other interrupts to be reported in
1157 * the cause register and then force the other
1158 * interrupts and see if any get posted. If
1159 * an interrupt was posted to the bus, the
1160 * test failed.
1161 */
1162 adapter->test_icr = 0;
1163 wr32(E1000_IMC, ~mask & 0x00007FFF);
1164 wr32(E1000_ICS, ~mask & 0x00007FFF);
1165 msleep(10);
1166
1167 if (adapter->test_icr) {
1168 *data = 5;
1169 break;
1170 }
1171 }
1172 }
1173
1174 /* Disable all the interrupts */
1175 wr32(E1000_IMC, 0xFFFFFFFF);
1176 msleep(10);
1177
1178 /* Unhook test interrupt handler */
1179 free_irq(irq, netdev);
1180
1181 return *data;
1182}
1183
1184static void igb_free_desc_rings(struct igb_adapter *adapter)
1185{
1186 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1187 struct igb_ring *rx_ring = &adapter->test_rx_ring;
1188 struct pci_dev *pdev = adapter->pdev;
1189 int i;
1190
1191 if (tx_ring->desc && tx_ring->buffer_info) {
1192 for (i = 0; i < tx_ring->count; i++) {
1193 struct igb_buffer *buf = &(tx_ring->buffer_info[i]);
1194 if (buf->dma)
1195 pci_unmap_single(pdev, buf->dma, buf->length,
1196 PCI_DMA_TODEVICE);
1197 if (buf->skb)
1198 dev_kfree_skb(buf->skb);
1199 }
1200 }
1201
1202 if (rx_ring->desc && rx_ring->buffer_info) {
1203 for (i = 0; i < rx_ring->count; i++) {
1204 struct igb_buffer *buf = &(rx_ring->buffer_info[i]);
1205 if (buf->dma)
1206 pci_unmap_single(pdev, buf->dma,
1207 IGB_RXBUFFER_2048,
1208 PCI_DMA_FROMDEVICE);
1209 if (buf->skb)
1210 dev_kfree_skb(buf->skb);
1211 }
1212 }
1213
1214 if (tx_ring->desc) {
1215 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc,
1216 tx_ring->dma);
1217 tx_ring->desc = NULL;
1218 }
1219 if (rx_ring->desc) {
1220 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc,
1221 rx_ring->dma);
1222 rx_ring->desc = NULL;
1223 }
1224
1225 kfree(tx_ring->buffer_info);
1226 tx_ring->buffer_info = NULL;
1227 kfree(rx_ring->buffer_info);
1228 rx_ring->buffer_info = NULL;
1229
1230 return;
1231}
1232
1233static int igb_setup_desc_rings(struct igb_adapter *adapter)
1234{
1235 struct e1000_hw *hw = &adapter->hw;
1236 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1237 struct igb_ring *rx_ring = &adapter->test_rx_ring;
1238 struct pci_dev *pdev = adapter->pdev;
1239 u32 rctl;
1240 int i, ret_val;
1241
1242 /* Setup Tx descriptor ring and Tx buffers */
1243
1244 if (!tx_ring->count)
1245 tx_ring->count = IGB_DEFAULT_TXD;
1246
1247 tx_ring->buffer_info = kcalloc(tx_ring->count,
1248 sizeof(struct igb_buffer),
1249 GFP_KERNEL);
1250 if (!tx_ring->buffer_info) {
1251 ret_val = 1;
1252 goto err_nomem;
1253 }
1254
1255 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1256 tx_ring->size = ALIGN(tx_ring->size, 4096);
1257 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
1258 &tx_ring->dma);
1259 if (!tx_ring->desc) {
1260 ret_val = 2;
1261 goto err_nomem;
1262 }
1263 tx_ring->next_to_use = tx_ring->next_to_clean = 0;
1264
1265 wr32(E1000_TDBAL(0),
1266 ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
1267 wr32(E1000_TDBAH(0), ((u64) tx_ring->dma >> 32));
1268 wr32(E1000_TDLEN(0),
1269 tx_ring->count * sizeof(struct e1000_tx_desc));
1270 wr32(E1000_TDH(0), 0);
1271 wr32(E1000_TDT(0), 0);
1272 wr32(E1000_TCTL,
1273 E1000_TCTL_PSP | E1000_TCTL_EN |
1274 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1275 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1276
1277 for (i = 0; i < tx_ring->count; i++) {
1278 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1279 struct sk_buff *skb;
1280 unsigned int size = 1024;
1281
1282 skb = alloc_skb(size, GFP_KERNEL);
1283 if (!skb) {
1284 ret_val = 3;
1285 goto err_nomem;
1286 }
1287 skb_put(skb, size);
1288 tx_ring->buffer_info[i].skb = skb;
1289 tx_ring->buffer_info[i].length = skb->len;
1290 tx_ring->buffer_info[i].dma =
1291 pci_map_single(pdev, skb->data, skb->len,
1292 PCI_DMA_TODEVICE);
1293 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
1294 tx_desc->lower.data = cpu_to_le32(skb->len);
1295 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1296 E1000_TXD_CMD_IFCS |
1297 E1000_TXD_CMD_RS);
1298 tx_desc->upper.data = 0;
1299 }
1300
1301 /* Setup Rx descriptor ring and Rx buffers */
1302
1303 if (!rx_ring->count)
1304 rx_ring->count = IGB_DEFAULT_RXD;
1305
1306 rx_ring->buffer_info = kcalloc(rx_ring->count,
1307 sizeof(struct igb_buffer),
1308 GFP_KERNEL);
1309 if (!rx_ring->buffer_info) {
1310 ret_val = 4;
1311 goto err_nomem;
1312 }
1313
1314 rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
1315 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size,
1316 &rx_ring->dma);
1317 if (!rx_ring->desc) {
1318 ret_val = 5;
1319 goto err_nomem;
1320 }
1321 rx_ring->next_to_use = rx_ring->next_to_clean = 0;
1322
1323 rctl = rd32(E1000_RCTL);
1324 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
1325 wr32(E1000_RDBAL(0),
1326 ((u64) rx_ring->dma & 0xFFFFFFFF));
1327 wr32(E1000_RDBAH(0),
1328 ((u64) rx_ring->dma >> 32));
1329 wr32(E1000_RDLEN(0), rx_ring->size);
1330 wr32(E1000_RDH(0), 0);
1331 wr32(E1000_RDT(0), 0);
Alexander Duyck69d728b2008-11-25 01:04:03 -08001332 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001333 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Alexander Duyck69d728b2008-11-25 01:04:03 -08001334 E1000_RCTL_RDMTS_HALF |
Auke Kok9d5c8242008-01-24 02:22:38 -08001335 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1336 wr32(E1000_RCTL, rctl);
1337 wr32(E1000_SRRCTL(0), 0);
1338
1339 for (i = 0; i < rx_ring->count; i++) {
1340 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
1341 struct sk_buff *skb;
1342
1343 skb = alloc_skb(IGB_RXBUFFER_2048 + NET_IP_ALIGN,
1344 GFP_KERNEL);
1345 if (!skb) {
1346 ret_val = 6;
1347 goto err_nomem;
1348 }
1349 skb_reserve(skb, NET_IP_ALIGN);
1350 rx_ring->buffer_info[i].skb = skb;
1351 rx_ring->buffer_info[i].dma =
1352 pci_map_single(pdev, skb->data, IGB_RXBUFFER_2048,
1353 PCI_DMA_FROMDEVICE);
1354 rx_desc->buffer_addr = cpu_to_le64(rx_ring->buffer_info[i].dma);
1355 memset(skb->data, 0x00, skb->len);
1356 }
1357
1358 return 0;
1359
1360err_nomem:
1361 igb_free_desc_rings(adapter);
1362 return ret_val;
1363}
1364
1365static void igb_phy_disable_receiver(struct igb_adapter *adapter)
1366{
1367 struct e1000_hw *hw = &adapter->hw;
1368
1369 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001370 igb_write_phy_reg(hw, 29, 0x001F);
1371 igb_write_phy_reg(hw, 30, 0x8FFC);
1372 igb_write_phy_reg(hw, 29, 0x001A);
1373 igb_write_phy_reg(hw, 30, 0x8FF0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001374}
1375
1376static int igb_integrated_phy_loopback(struct igb_adapter *adapter)
1377{
1378 struct e1000_hw *hw = &adapter->hw;
1379 u32 ctrl_reg = 0;
1380 u32 stat_reg = 0;
1381
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);
Auke Kok9d5c8242008-01-24 02:22:38 -08001391 }
1392
1393 ctrl_reg = rd32(E1000_CTRL);
1394
1395 /* force 1000, set loopback */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001396 igb_write_phy_reg(hw, PHY_CONTROL, 0x4140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001397
1398 /* Now set up the MAC to the same speed/duplex as the PHY. */
1399 ctrl_reg = rd32(E1000_CTRL);
1400 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1401 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1402 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1403 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1404 E1000_CTRL_FD); /* Force Duplex to FULL */
1405
1406 if (hw->phy.media_type == e1000_media_type_copper &&
1407 hw->phy.type == e1000_phy_m88)
1408 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1409 else {
1410 /* Set the ILOS bit on the fiber Nic if half duplex link is
1411 * detected. */
1412 stat_reg = rd32(E1000_STATUS);
1413 if ((stat_reg & E1000_STATUS_FD) == 0)
1414 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1415 }
1416
1417 wr32(E1000_CTRL, ctrl_reg);
1418
1419 /* Disable the receiver on the PHY so when a cable is plugged in, the
1420 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1421 */
1422 if (hw->phy.type == e1000_phy_m88)
1423 igb_phy_disable_receiver(adapter);
1424
1425 udelay(500);
1426
1427 return 0;
1428}
1429
1430static int igb_set_phy_loopback(struct igb_adapter *adapter)
1431{
1432 return igb_integrated_phy_loopback(adapter);
1433}
1434
1435static int igb_setup_loopback_test(struct igb_adapter *adapter)
1436{
1437 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001438 u32 reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001439
1440 if (hw->phy.media_type == e1000_media_type_fiber ||
1441 hw->phy.media_type == e1000_media_type_internal_serdes) {
Alexander Duyck2d064c02008-07-08 15:10:12 -07001442 reg = rd32(E1000_RCTL);
1443 reg |= E1000_RCTL_LBM_TCVR;
1444 wr32(E1000_RCTL, reg);
1445
1446 wr32(E1000_SCTL, E1000_ENABLE_SERDES_LOOPBACK);
1447
1448 reg = rd32(E1000_CTRL);
1449 reg &= ~(E1000_CTRL_RFCE |
1450 E1000_CTRL_TFCE |
1451 E1000_CTRL_LRST);
1452 reg |= E1000_CTRL_SLU |
1453 E1000_CTRL_FD;
1454 wr32(E1000_CTRL, reg);
1455
1456 /* Unset switch control to serdes energy detect */
1457 reg = rd32(E1000_CONNSW);
1458 reg &= ~E1000_CONNSW_ENRGSRC;
1459 wr32(E1000_CONNSW, reg);
1460
1461 /* Set PCS register for forced speed */
1462 reg = rd32(E1000_PCS_LCTL);
1463 reg &= ~E1000_PCS_LCTL_AN_ENABLE; /* Disable Autoneg*/
1464 reg |= E1000_PCS_LCTL_FLV_LINK_UP | /* Force link up */
1465 E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1466 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
1467 E1000_PCS_LCTL_FSD | /* Force Speed */
1468 E1000_PCS_LCTL_FORCE_LINK; /* Force Link */
1469 wr32(E1000_PCS_LCTL, reg);
1470
Auke Kok9d5c8242008-01-24 02:22:38 -08001471 return 0;
1472 } else if (hw->phy.media_type == e1000_media_type_copper) {
1473 return igb_set_phy_loopback(adapter);
1474 }
1475
1476 return 7;
1477}
1478
1479static void igb_loopback_cleanup(struct igb_adapter *adapter)
1480{
1481 struct e1000_hw *hw = &adapter->hw;
1482 u32 rctl;
1483 u16 phy_reg;
1484
1485 rctl = rd32(E1000_RCTL);
1486 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1487 wr32(E1000_RCTL, rctl);
1488
1489 hw->mac.autoneg = true;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001490 igb_read_phy_reg(hw, PHY_CONTROL, &phy_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001491 if (phy_reg & MII_CR_LOOPBACK) {
1492 phy_reg &= ~MII_CR_LOOPBACK;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001493 igb_write_phy_reg(hw, PHY_CONTROL, phy_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001494 igb_phy_sw_reset(hw);
1495 }
1496}
1497
1498static void igb_create_lbtest_frame(struct sk_buff *skb,
1499 unsigned int frame_size)
1500{
1501 memset(skb->data, 0xFF, frame_size);
1502 frame_size &= ~1;
1503 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1504 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1505 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1506}
1507
1508static int igb_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1509{
1510 frame_size &= ~1;
1511 if (*(skb->data + 3) == 0xFF)
1512 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1513 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1514 return 0;
1515 return 13;
1516}
1517
1518static int igb_run_loopback_test(struct igb_adapter *adapter)
1519{
1520 struct e1000_hw *hw = &adapter->hw;
1521 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1522 struct igb_ring *rx_ring = &adapter->test_rx_ring;
1523 struct pci_dev *pdev = adapter->pdev;
1524 int i, j, k, l, lc, good_cnt;
1525 int ret_val = 0;
1526 unsigned long time;
1527
1528 wr32(E1000_RDT(0), rx_ring->count - 1);
1529
1530 /* Calculate the loop count based on the largest descriptor ring
1531 * The idea is to wrap the largest ring a number of times using 64
1532 * send/receive pairs during each loop
1533 */
1534
1535 if (rx_ring->count <= tx_ring->count)
1536 lc = ((tx_ring->count / 64) * 2) + 1;
1537 else
1538 lc = ((rx_ring->count / 64) * 2) + 1;
1539
1540 k = l = 0;
1541 for (j = 0; j <= lc; j++) { /* loop count loop */
1542 for (i = 0; i < 64; i++) { /* send the packets */
1543 igb_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1544 1024);
1545 pci_dma_sync_single_for_device(pdev,
1546 tx_ring->buffer_info[k].dma,
1547 tx_ring->buffer_info[k].length,
1548 PCI_DMA_TODEVICE);
1549 k++;
1550 if (k == tx_ring->count)
1551 k = 0;
1552 }
1553 wr32(E1000_TDT(0), k);
1554 msleep(200);
1555 time = jiffies; /* set the start time for the receive */
1556 good_cnt = 0;
1557 do { /* receive the sent packets */
1558 pci_dma_sync_single_for_cpu(pdev,
1559 rx_ring->buffer_info[l].dma,
1560 IGB_RXBUFFER_2048,
1561 PCI_DMA_FROMDEVICE);
1562
1563 ret_val = igb_check_lbtest_frame(
1564 rx_ring->buffer_info[l].skb, 1024);
1565 if (!ret_val)
1566 good_cnt++;
1567 l++;
1568 if (l == rx_ring->count)
1569 l = 0;
1570 /* time + 20 msecs (200 msecs on 2.4) is more than
1571 * enough time to complete the receives, if it's
1572 * exceeded, break and error off
1573 */
1574 } while (good_cnt < 64 && jiffies < (time + 20));
1575 if (good_cnt != 64) {
1576 ret_val = 13; /* ret_val is the same as mis-compare */
1577 break;
1578 }
1579 if (jiffies >= (time + 20)) {
1580 ret_val = 14; /* error code for time out error */
1581 break;
1582 }
1583 } /* end loop count loop */
1584 return ret_val;
1585}
1586
1587static int igb_loopback_test(struct igb_adapter *adapter, u64 *data)
1588{
1589 /* PHY loopback cannot be performed if SoL/IDER
1590 * sessions are active */
1591 if (igb_check_reset_block(&adapter->hw)) {
1592 dev_err(&adapter->pdev->dev,
1593 "Cannot do PHY loopback test "
1594 "when SoL/IDER is active.\n");
1595 *data = 0;
1596 goto out;
1597 }
1598 *data = igb_setup_desc_rings(adapter);
1599 if (*data)
1600 goto out;
1601 *data = igb_setup_loopback_test(adapter);
1602 if (*data)
1603 goto err_loopback;
1604 *data = igb_run_loopback_test(adapter);
1605 igb_loopback_cleanup(adapter);
1606
1607err_loopback:
1608 igb_free_desc_rings(adapter);
1609out:
1610 return *data;
1611}
1612
1613static int igb_link_test(struct igb_adapter *adapter, u64 *data)
1614{
1615 struct e1000_hw *hw = &adapter->hw;
1616 *data = 0;
1617 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1618 int i = 0;
1619 hw->mac.serdes_has_link = false;
1620
1621 /* On some blade server designs, link establishment
1622 * could take as long as 2-3 minutes */
1623 do {
1624 hw->mac.ops.check_for_link(&adapter->hw);
1625 if (hw->mac.serdes_has_link)
1626 return *data;
1627 msleep(20);
1628 } while (i++ < 3750);
1629
1630 *data = 1;
1631 } else {
1632 hw->mac.ops.check_for_link(&adapter->hw);
1633 if (hw->mac.autoneg)
1634 msleep(4000);
1635
1636 if (!(rd32(E1000_STATUS) &
1637 E1000_STATUS_LU))
1638 *data = 1;
1639 }
1640 return *data;
1641}
1642
1643static void igb_diag_test(struct net_device *netdev,
1644 struct ethtool_test *eth_test, u64 *data)
1645{
1646 struct igb_adapter *adapter = netdev_priv(netdev);
1647 u16 autoneg_advertised;
1648 u8 forced_speed_duplex, autoneg;
1649 bool if_running = netif_running(netdev);
1650
1651 set_bit(__IGB_TESTING, &adapter->state);
1652 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1653 /* Offline tests */
1654
1655 /* save speed, duplex, autoneg settings */
1656 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1657 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1658 autoneg = adapter->hw.mac.autoneg;
1659
1660 dev_info(&adapter->pdev->dev, "offline testing starting\n");
1661
1662 /* Link test performed before hardware reset so autoneg doesn't
1663 * interfere with test result */
1664 if (igb_link_test(adapter, &data[4]))
1665 eth_test->flags |= ETH_TEST_FL_FAILED;
1666
1667 if (if_running)
1668 /* indicate we're in test mode */
1669 dev_close(netdev);
1670 else
1671 igb_reset(adapter);
1672
1673 if (igb_reg_test(adapter, &data[0]))
1674 eth_test->flags |= ETH_TEST_FL_FAILED;
1675
1676 igb_reset(adapter);
1677 if (igb_eeprom_test(adapter, &data[1]))
1678 eth_test->flags |= ETH_TEST_FL_FAILED;
1679
1680 igb_reset(adapter);
1681 if (igb_intr_test(adapter, &data[2]))
1682 eth_test->flags |= ETH_TEST_FL_FAILED;
1683
1684 igb_reset(adapter);
1685 if (igb_loopback_test(adapter, &data[3]))
1686 eth_test->flags |= ETH_TEST_FL_FAILED;
1687
1688 /* restore speed, duplex, autoneg settings */
1689 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1690 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1691 adapter->hw.mac.autoneg = autoneg;
1692
1693 /* force this routine to wait until autoneg complete/timeout */
1694 adapter->hw.phy.autoneg_wait_to_complete = true;
1695 igb_reset(adapter);
1696 adapter->hw.phy.autoneg_wait_to_complete = false;
1697
1698 clear_bit(__IGB_TESTING, &adapter->state);
1699 if (if_running)
1700 dev_open(netdev);
1701 } else {
1702 dev_info(&adapter->pdev->dev, "online testing starting\n");
1703 /* Online tests */
1704 if (igb_link_test(adapter, &data[4]))
1705 eth_test->flags |= ETH_TEST_FL_FAILED;
1706
1707 /* Online tests aren't run; pass by default */
1708 data[0] = 0;
1709 data[1] = 0;
1710 data[2] = 0;
1711 data[3] = 0;
1712
1713 clear_bit(__IGB_TESTING, &adapter->state);
1714 }
1715 msleep_interruptible(4 * 1000);
1716}
1717
1718static int igb_wol_exclusion(struct igb_adapter *adapter,
1719 struct ethtool_wolinfo *wol)
1720{
1721 struct e1000_hw *hw = &adapter->hw;
1722 int retval = 1; /* fail by default */
1723
1724 switch (hw->device_id) {
1725 case E1000_DEV_ID_82575GB_QUAD_COPPER:
1726 /* WoL not supported */
1727 wol->supported = 0;
1728 break;
1729 case E1000_DEV_ID_82575EB_FIBER_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -07001730 case E1000_DEV_ID_82576_FIBER:
1731 case E1000_DEV_ID_82576_SERDES:
Auke Kok9d5c8242008-01-24 02:22:38 -08001732 /* Wake events not supported on port B */
1733 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1) {
1734 wol->supported = 0;
1735 break;
1736 }
1737 /* return success for non excluded adapter ports */
1738 retval = 0;
1739 break;
1740 default:
1741 /* dual port cards only support WoL on port A from now on
1742 * unless it was enabled in the eeprom for port B
1743 * so exclude FUNC_1 ports from having WoL enabled */
1744 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1 &&
1745 !adapter->eeprom_wol) {
1746 wol->supported = 0;
1747 break;
1748 }
1749
1750 retval = 0;
1751 }
1752
1753 return retval;
1754}
1755
1756static void igb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1757{
1758 struct igb_adapter *adapter = netdev_priv(netdev);
1759
1760 wol->supported = WAKE_UCAST | WAKE_MCAST |
1761 WAKE_BCAST | WAKE_MAGIC;
1762 wol->wolopts = 0;
1763
1764 /* this function will set ->supported = 0 and return 1 if wol is not
1765 * supported by this hardware */
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00001766 if (igb_wol_exclusion(adapter, wol) ||
1767 !device_can_wakeup(&adapter->pdev->dev))
Auke Kok9d5c8242008-01-24 02:22:38 -08001768 return;
1769
1770 /* apply any specific unsupported masks here */
1771 switch (adapter->hw.device_id) {
1772 default:
1773 break;
1774 }
1775
1776 if (adapter->wol & E1000_WUFC_EX)
1777 wol->wolopts |= WAKE_UCAST;
1778 if (adapter->wol & E1000_WUFC_MC)
1779 wol->wolopts |= WAKE_MCAST;
1780 if (adapter->wol & E1000_WUFC_BC)
1781 wol->wolopts |= WAKE_BCAST;
1782 if (adapter->wol & E1000_WUFC_MAG)
1783 wol->wolopts |= WAKE_MAGIC;
1784
1785 return;
1786}
1787
1788static int igb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1789{
1790 struct igb_adapter *adapter = netdev_priv(netdev);
1791 struct e1000_hw *hw = &adapter->hw;
1792
1793 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1794 return -EOPNOTSUPP;
1795
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00001796 if (igb_wol_exclusion(adapter, wol) ||
1797 !device_can_wakeup(&adapter->pdev->dev))
Auke Kok9d5c8242008-01-24 02:22:38 -08001798 return wol->wolopts ? -EOPNOTSUPP : 0;
1799
1800 switch (hw->device_id) {
1801 default:
1802 break;
1803 }
1804
1805 /* these settings will always override what we currently have */
1806 adapter->wol = 0;
1807
1808 if (wol->wolopts & WAKE_UCAST)
1809 adapter->wol |= E1000_WUFC_EX;
1810 if (wol->wolopts & WAKE_MCAST)
1811 adapter->wol |= E1000_WUFC_MC;
1812 if (wol->wolopts & WAKE_BCAST)
1813 adapter->wol |= E1000_WUFC_BC;
1814 if (wol->wolopts & WAKE_MAGIC)
1815 adapter->wol |= E1000_WUFC_MAG;
1816
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00001817 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1818
Auke Kok9d5c8242008-01-24 02:22:38 -08001819 return 0;
1820}
1821
1822/* toggle LED 4 times per second = 2 "blinks" per second */
1823#define IGB_ID_INTERVAL (HZ/4)
1824
1825/* bit defines for adapter->led_status */
1826#define IGB_LED_ON 0
1827
1828static int igb_phys_id(struct net_device *netdev, u32 data)
1829{
1830 struct igb_adapter *adapter = netdev_priv(netdev);
1831 struct e1000_hw *hw = &adapter->hw;
1832
1833 if (!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ))
1834 data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ);
1835
1836 igb_blink_led(hw);
1837 msleep_interruptible(data * 1000);
1838
1839 igb_led_off(hw);
1840 clear_bit(IGB_LED_ON, &adapter->led_status);
1841 igb_cleanup_led(hw);
1842
1843 return 0;
1844}
1845
1846static int igb_set_coalesce(struct net_device *netdev,
1847 struct ethtool_coalesce *ec)
1848{
1849 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07001850 struct e1000_hw *hw = &adapter->hw;
1851 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08001852
1853 if ((ec->rx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
1854 ((ec->rx_coalesce_usecs > 3) &&
1855 (ec->rx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
1856 (ec->rx_coalesce_usecs == 2))
1857 return -EINVAL;
1858
1859 /* convert to rate of irq's per second */
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07001860 if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001861 adapter->itr_setting = ec->rx_coalesce_usecs;
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07001862 adapter->itr = IGB_START_ITR;
1863 } else {
1864 adapter->itr_setting = ec->rx_coalesce_usecs << 2;
1865 adapter->itr = adapter->itr_setting;
1866 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001867
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07001868 for (i = 0; i < adapter->num_rx_queues; i++)
1869 wr32(adapter->rx_ring[i].itr_register, adapter->itr);
Auke Kok9d5c8242008-01-24 02:22:38 -08001870
1871 return 0;
1872}
1873
1874static int igb_get_coalesce(struct net_device *netdev,
1875 struct ethtool_coalesce *ec)
1876{
1877 struct igb_adapter *adapter = netdev_priv(netdev);
1878
1879 if (adapter->itr_setting <= 3)
1880 ec->rx_coalesce_usecs = adapter->itr_setting;
1881 else
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07001882 ec->rx_coalesce_usecs = adapter->itr_setting >> 2;
Auke Kok9d5c8242008-01-24 02:22:38 -08001883
1884 return 0;
1885}
1886
1887
1888static int igb_nway_reset(struct net_device *netdev)
1889{
1890 struct igb_adapter *adapter = netdev_priv(netdev);
1891 if (netif_running(netdev))
1892 igb_reinit_locked(adapter);
1893 return 0;
1894}
1895
1896static int igb_get_sset_count(struct net_device *netdev, int sset)
1897{
1898 switch (sset) {
1899 case ETH_SS_STATS:
1900 return IGB_STATS_LEN;
1901 case ETH_SS_TEST:
1902 return IGB_TEST_LEN;
1903 default:
1904 return -ENOTSUPP;
1905 }
1906}
1907
1908static void igb_get_ethtool_stats(struct net_device *netdev,
1909 struct ethtool_stats *stats, u64 *data)
1910{
1911 struct igb_adapter *adapter = netdev_priv(netdev);
1912 u64 *queue_stat;
1913 int stat_count = sizeof(struct igb_queue_stats) / sizeof(u64);
1914 int j;
1915 int i;
1916
1917 igb_update_stats(adapter);
1918 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
1919 char *p = (char *)adapter+igb_gstrings_stats[i].stat_offset;
1920 data[i] = (igb_gstrings_stats[i].sizeof_stat ==
1921 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1922 }
Alexander Duycke21ed352008-07-08 15:07:24 -07001923 for (j = 0; j < adapter->num_tx_queues; j++) {
1924 int k;
1925 queue_stat = (u64 *)&adapter->tx_ring[j].tx_stats;
1926 for (k = 0; k < stat_count; k++)
1927 data[i + k] = queue_stat[k];
1928 i += k;
1929 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001930 for (j = 0; j < adapter->num_rx_queues; j++) {
1931 int k;
1932 queue_stat = (u64 *)&adapter->rx_ring[j].rx_stats;
1933 for (k = 0; k < stat_count; k++)
1934 data[i + k] = queue_stat[k];
1935 i += k;
1936 }
1937}
1938
1939static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
1940{
1941 struct igb_adapter *adapter = netdev_priv(netdev);
1942 u8 *p = data;
1943 int i;
1944
1945 switch (stringset) {
1946 case ETH_SS_TEST:
1947 memcpy(data, *igb_gstrings_test,
1948 IGB_TEST_LEN*ETH_GSTRING_LEN);
1949 break;
1950 case ETH_SS_STATS:
1951 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
1952 memcpy(p, igb_gstrings_stats[i].stat_string,
1953 ETH_GSTRING_LEN);
1954 p += ETH_GSTRING_LEN;
1955 }
1956 for (i = 0; i < adapter->num_tx_queues; i++) {
1957 sprintf(p, "tx_queue_%u_packets", i);
1958 p += ETH_GSTRING_LEN;
1959 sprintf(p, "tx_queue_%u_bytes", i);
1960 p += ETH_GSTRING_LEN;
1961 }
1962 for (i = 0; i < adapter->num_rx_queues; i++) {
1963 sprintf(p, "rx_queue_%u_packets", i);
1964 p += ETH_GSTRING_LEN;
1965 sprintf(p, "rx_queue_%u_bytes", i);
1966 p += ETH_GSTRING_LEN;
1967 }
1968/* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
1969 break;
1970 }
1971}
1972
1973static struct ethtool_ops igb_ethtool_ops = {
1974 .get_settings = igb_get_settings,
1975 .set_settings = igb_set_settings,
1976 .get_drvinfo = igb_get_drvinfo,
1977 .get_regs_len = igb_get_regs_len,
1978 .get_regs = igb_get_regs,
1979 .get_wol = igb_get_wol,
1980 .set_wol = igb_set_wol,
1981 .get_msglevel = igb_get_msglevel,
1982 .set_msglevel = igb_set_msglevel,
1983 .nway_reset = igb_nway_reset,
1984 .get_link = ethtool_op_get_link,
1985 .get_eeprom_len = igb_get_eeprom_len,
1986 .get_eeprom = igb_get_eeprom,
1987 .set_eeprom = igb_set_eeprom,
1988 .get_ringparam = igb_get_ringparam,
1989 .set_ringparam = igb_set_ringparam,
1990 .get_pauseparam = igb_get_pauseparam,
1991 .set_pauseparam = igb_set_pauseparam,
1992 .get_rx_csum = igb_get_rx_csum,
1993 .set_rx_csum = igb_set_rx_csum,
1994 .get_tx_csum = igb_get_tx_csum,
1995 .set_tx_csum = igb_set_tx_csum,
1996 .get_sg = ethtool_op_get_sg,
1997 .set_sg = ethtool_op_set_sg,
1998 .get_tso = ethtool_op_get_tso,
1999 .set_tso = igb_set_tso,
2000 .self_test = igb_diag_test,
2001 .get_strings = igb_get_strings,
2002 .phys_id = igb_phys_id,
2003 .get_sset_count = igb_get_sset_count,
2004 .get_ethtool_stats = igb_get_ethtool_stats,
2005 .get_coalesce = igb_get_coalesce,
2006 .set_coalesce = igb_set_coalesce,
2007};
2008
2009void igb_set_ethtool_ops(struct net_device *netdev)
2010{
2011 SET_ETHTOOL_OPS(netdev, &igb_ethtool_ops);
2012}