1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2009 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 /* ethtool support for igb */
30 #include <linux/vmalloc.h>
31 #include <linux/netdevice.h>
32 #include <linux/pci.h>
33 #include <linux/delay.h>
34 #include <linux/interrupt.h>
35 #include <linux/if_ether.h>
36 #include <linux/ethtool.h>
37 #include <linux/sched.h>
42 char stat_string[ETH_GSTRING_LEN];
47 #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) \
52 static const struct igb_stats igb_gstrings_stats[] = {
53 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),
90 #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) \
95 static 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)
107 #define IGB_GLOBAL_STATS_LEN \
108 (sizeof(igb_gstrings_stats) / sizeof(struct igb_stats))
109 #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)
123 static 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)"
128 #define IGB_TEST_LEN (sizeof(igb_gstrings_test) / ETH_GSTRING_LEN)
130 static int igb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
132 struct igb_adapter *adapter = netdev_priv(netdev);
133 struct e1000_hw *hw = &adapter->hw;
136 if (hw->phy.media_type == e1000_media_type_copper) {
138 ecmd->supported = (SUPPORTED_10baseT_Half |
139 SUPPORTED_10baseT_Full |
140 SUPPORTED_100baseT_Half |
141 SUPPORTED_100baseT_Full |
142 SUPPORTED_1000baseT_Full|
145 ecmd->advertising = ADVERTISED_TP;
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;
153 ecmd->port = PORT_TP;
154 ecmd->phy_address = hw->phy.addr;
156 ecmd->supported = (SUPPORTED_1000baseT_Full |
160 ecmd->advertising = (ADVERTISED_1000baseT_Full |
164 ecmd->port = PORT_FIBRE;
167 ecmd->transceiver = XCVR_INTERNAL;
169 status = rd32(E1000_STATUS);
171 if (status & E1000_STATUS_LU) {
173 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;
179 ecmd->speed = SPEED_10;
181 if ((status & E1000_STATUS_FD) ||
182 hw->phy.media_type != e1000_media_type_copper)
183 ecmd->duplex = DUPLEX_FULL;
185 ecmd->duplex = DUPLEX_HALF;
191 ecmd->autoneg = hw->mac.autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE;
195 static int igb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
197 struct igb_adapter *adapter = netdev_priv(netdev);
198 struct e1000_hw *hw = &adapter->hw;
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");
208 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
211 if (ecmd->autoneg == AUTONEG_ENABLE) {
213 hw->phy.autoneg_advertised = ecmd->advertising |
216 ecmd->advertising = hw->phy.autoneg_advertised;
217 if (adapter->fc_autoneg)
218 hw->fc.requested_mode = e1000_fc_default;
220 if (igb_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
221 clear_bit(__IGB_RESETTING, &adapter->state);
227 if (netif_running(adapter->netdev)) {
233 clear_bit(__IGB_RESETTING, &adapter->state);
237 static u32 igb_get_link(struct net_device *netdev)
239 struct igb_adapter *adapter = netdev_priv(netdev);
240 struct e1000_mac_info *mac = &adapter->hw.mac;
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.
249 if (!netif_carrier_ok(netdev))
250 mac->get_link_status = 1;
252 return igb_has_link(adapter);
255 static void igb_get_pauseparam(struct net_device *netdev,
256 struct ethtool_pauseparam *pause)
258 struct igb_adapter *adapter = netdev_priv(netdev);
259 struct e1000_hw *hw = &adapter->hw;
262 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
264 if (hw->fc.current_mode == e1000_fc_rx_pause)
266 else if (hw->fc.current_mode == e1000_fc_tx_pause)
268 else if (hw->fc.current_mode == e1000_fc_full) {
274 static int igb_set_pauseparam(struct net_device *netdev,
275 struct ethtool_pauseparam *pause)
277 struct igb_adapter *adapter = netdev_priv(netdev);
278 struct e1000_hw *hw = &adapter->hw;
281 adapter->fc_autoneg = pause->autoneg;
283 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
286 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
287 hw->fc.requested_mode = e1000_fc_default;
288 if (netif_running(adapter->netdev)) {
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;
304 hw->fc.current_mode = hw->fc.requested_mode;
306 retval = ((hw->phy.media_type == e1000_media_type_copper) ?
307 igb_force_mac_fc(hw) : igb_setup_link(hw));
310 clear_bit(__IGB_RESETTING, &adapter->state);
314 static u32 igb_get_rx_csum(struct net_device *netdev)
316 struct igb_adapter *adapter = netdev_priv(netdev);
317 return !!(adapter->rx_ring[0].flags & IGB_RING_FLAG_RX_CSUM);
320 static int igb_set_rx_csum(struct net_device *netdev, u32 data)
322 struct igb_adapter *adapter = netdev_priv(netdev);
325 for (i = 0; i < adapter->num_rx_queues; i++) {
327 adapter->rx_ring[i].flags |= IGB_RING_FLAG_RX_CSUM;
329 adapter->rx_ring[i].flags &= ~IGB_RING_FLAG_RX_CSUM;
335 static u32 igb_get_tx_csum(struct net_device *netdev)
337 return (netdev->features & NETIF_F_IP_CSUM) != 0;
340 static int igb_set_tx_csum(struct net_device *netdev, u32 data)
342 struct igb_adapter *adapter = netdev_priv(netdev);
345 netdev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
346 if (adapter->hw.mac.type >= e1000_82576)
347 netdev->features |= NETIF_F_SCTP_CSUM;
349 netdev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
356 static int igb_set_tso(struct net_device *netdev, u32 data)
358 struct igb_adapter *adapter = netdev_priv(netdev);
361 netdev->features |= NETIF_F_TSO;
362 netdev->features |= NETIF_F_TSO6;
364 netdev->features &= ~NETIF_F_TSO;
365 netdev->features &= ~NETIF_F_TSO6;
368 dev_info(&adapter->pdev->dev, "TSO is %s\n",
369 data ? "Enabled" : "Disabled");
373 static u32 igb_get_msglevel(struct net_device *netdev)
375 struct igb_adapter *adapter = netdev_priv(netdev);
376 return adapter->msg_enable;
379 static void igb_set_msglevel(struct net_device *netdev, u32 data)
381 struct igb_adapter *adapter = netdev_priv(netdev);
382 adapter->msg_enable = data;
385 static int igb_get_regs_len(struct net_device *netdev)
387 #define IGB_REGS_LEN 551
388 return IGB_REGS_LEN * sizeof(u32);
391 static void igb_get_regs(struct net_device *netdev,
392 struct ethtool_regs *regs, void *p)
394 struct igb_adapter *adapter = netdev_priv(netdev);
395 struct e1000_hw *hw = &adapter->hw;
399 memset(p, 0, IGB_REGS_LEN * sizeof(u32));
401 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
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);
418 regs_buff[12] = rd32(E1000_EECD);
421 /* Reading EICS for EICR because they read the
422 * same but EICS does not clear on read */
423 regs_buff[13] = rd32(E1000_EICS);
424 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);
429 /* Reading ICS for ICR because they read the
430 * same but ICS does not clear on read */
431 regs_buff[19] = rd32(E1000_ICS);
432 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);
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);
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);
453 regs_buff[37] = rd32(E1000_VT_CTL);
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);
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);
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);
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;
540 for (i = 0; i < 4; i++)
541 regs_buff[121 + i] = rd32(E1000_SRRCTL(i));
542 for (i = 0; i < 4; i++)
543 regs_buff[125 + i] = rd32(E1000_PSRTYPE(i));
544 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));
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));
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));
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));
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);
607 static int igb_get_eeprom_len(struct net_device *netdev)
609 struct igb_adapter *adapter = netdev_priv(netdev);
610 return adapter->hw.nvm.word_size * 2;
613 static int igb_get_eeprom(struct net_device *netdev,
614 struct ethtool_eeprom *eeprom, u8 *bytes)
616 struct igb_adapter *adapter = netdev_priv(netdev);
617 struct e1000_hw *hw = &adapter->hw;
619 int first_word, last_word;
623 if (eeprom->len == 0)
626 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
628 first_word = eeprom->offset >> 1;
629 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
631 eeprom_buff = kmalloc(sizeof(u16) *
632 (last_word - first_word + 1), GFP_KERNEL);
636 if (hw->nvm.type == e1000_nvm_eeprom_spi)
637 ret_val = hw->nvm.ops.read(hw, first_word,
638 last_word - first_word + 1,
641 for (i = 0; i < last_word - first_word + 1; i++) {
642 ret_val = hw->nvm.ops.read(hw, first_word + i, 1,
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]);
653 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
660 static int igb_set_eeprom(struct net_device *netdev,
661 struct ethtool_eeprom *eeprom, u8 *bytes)
663 struct igb_adapter *adapter = netdev_priv(netdev);
664 struct e1000_hw *hw = &adapter->hw;
667 int max_len, first_word, last_word, ret_val = 0;
670 if (eeprom->len == 0)
673 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
676 max_len = hw->nvm.word_size * 2;
678 first_word = eeprom->offset >> 1;
679 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
680 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
684 ptr = (void *)eeprom_buff;
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 */
689 ret_val = hw->nvm.ops.read(hw, first_word, 1,
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 */
696 ret_val = hw->nvm.ops.read(hw, last_word, 1,
697 &eeprom_buff[last_word - first_word]);
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]);
704 memcpy(ptr, bytes, eeprom->len);
706 for (i = 0; i < last_word - first_word + 1; i++)
707 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
709 ret_val = hw->nvm.ops.write(hw, first_word,
710 last_word - first_word + 1, eeprom_buff);
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);
721 static void igb_get_drvinfo(struct net_device *netdev,
722 struct ethtool_drvinfo *drvinfo)
724 struct igb_adapter *adapter = netdev_priv(netdev);
725 char firmware_version[32];
728 strncpy(drvinfo->driver, igb_driver_name, 32);
729 strncpy(drvinfo->version, igb_driver_version, 32);
731 /* EEPROM image version # is reported as firmware version # for
732 * 82575 controllers */
733 adapter->hw.nvm.ops.read(&adapter->hw, 5, 1, &eeprom_data);
734 sprintf(firmware_version, "%d.%d-%d",
735 (eeprom_data & 0xF000) >> 12,
736 (eeprom_data & 0x0FF0) >> 4,
737 eeprom_data & 0x000F);
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);
747 static void igb_get_ringparam(struct net_device *netdev,
748 struct ethtool_ringparam *ring)
750 struct igb_adapter *adapter = netdev_priv(netdev);
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;
756 ring->rx_pending = adapter->rx_ring_count;
757 ring->tx_pending = adapter->tx_ring_count;
758 ring->rx_mini_pending = 0;
759 ring->rx_jumbo_pending = 0;
762 static int igb_set_ringparam(struct net_device *netdev,
763 struct ethtool_ringparam *ring)
765 struct igb_adapter *adapter = netdev_priv(netdev);
766 struct igb_ring *temp_ring;
768 u16 new_rx_count, new_tx_count;
770 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
773 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);
775 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
777 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);
779 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
781 if ((new_tx_count == adapter->tx_ring_count) &&
782 (new_rx_count == adapter->rx_ring_count)) {
787 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
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;
800 if (adapter->num_tx_queues > adapter->num_rx_queues)
801 temp_ring = vmalloc(adapter->num_tx_queues * sizeof(struct igb_ring));
803 temp_ring = vmalloc(adapter->num_rx_queues * sizeof(struct igb_ring));
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.
817 if (new_tx_count != adapter->tx_ring_count) {
818 memcpy(temp_ring, adapter->tx_ring,
819 adapter->num_tx_queues * sizeof(struct igb_ring));
821 for (i = 0; i < adapter->num_tx_queues; i++) {
822 temp_ring[i].count = new_tx_count;
823 err = igb_setup_tx_resources(&temp_ring[i]);
827 igb_free_tx_resources(&temp_ring[i]);
833 for (i = 0; i < adapter->num_tx_queues; i++)
834 igb_free_tx_resources(&adapter->tx_ring[i]);
836 memcpy(adapter->tx_ring, temp_ring,
837 adapter->num_tx_queues * sizeof(struct igb_ring));
839 adapter->tx_ring_count = new_tx_count;
842 if (new_rx_count != adapter->rx_ring->count) {
843 memcpy(temp_ring, adapter->rx_ring,
844 adapter->num_rx_queues * sizeof(struct igb_ring));
846 for (i = 0; i < adapter->num_rx_queues; i++) {
847 temp_ring[i].count = new_rx_count;
848 err = igb_setup_rx_resources(&temp_ring[i]);
852 igb_free_rx_resources(&temp_ring[i]);
859 for (i = 0; i < adapter->num_rx_queues; i++)
860 igb_free_rx_resources(&adapter->rx_ring[i]);
862 memcpy(adapter->rx_ring, temp_ring,
863 adapter->num_rx_queues * sizeof(struct igb_ring));
865 adapter->rx_ring_count = new_rx_count;
871 clear_bit(__IGB_RESETTING, &adapter->state);
875 /* ethtool register test data */
876 struct igb_reg_test {
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.
891 * We also make provision for some required setup steps by specifying
892 * registers to be written without any read-back testing.
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
903 static 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 },
946 static 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 },
954 { 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 },
960 /* RDH is read-only for 82576, only test RDT. */
961 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
962 { E1000_RDT(4), 0x40, 12, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
963 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
964 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0, 0 },
965 { 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 },
971 { 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 },
974 { 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 },
986 /* 82575 register test */
987 static 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 },
997 /* RDH is read-only for 82575, only test RDT. */
998 { 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 },
1017 static bool reg_pattern_test(struct igb_adapter *adapter, u64 *data,
1018 int reg, u32 mask, u32 write)
1020 struct e1000_hw *hw = &adapter->hw;
1022 static const u32 _test[] =
1023 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
1024 for (pat = 0; pat < ARRAY_SIZE(_test); pat++) {
1025 wr32(reg, (_test[pat] & write));
1027 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));
1039 static bool reg_set_and_check(struct igb_adapter *adapter, u64 *data,
1040 int reg, u32 mask, u32 write)
1042 struct e1000_hw *hw = &adapter->hw;
1044 wr32(reg, write & mask);
1046 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));
1057 #define REG_PATTERN_TEST(reg, mask, write) \
1059 if (reg_pattern_test(adapter, data, reg, mask, write)) \
1063 #define REG_SET_AND_CHECK(reg, mask, write) \
1065 if (reg_set_and_check(adapter, data, reg, mask, write)) \
1069 static int igb_reg_test(struct igb_adapter *adapter, u64 *data)
1071 struct e1000_hw *hw = &adapter->hw;
1072 struct igb_reg_test *test;
1073 u32 value, before, after;
1076 switch (adapter->hw.mac.type) {
1078 test = reg_test_82580;
1079 toggle = 0x7FEFF3FF;
1082 test = reg_test_82576;
1083 toggle = 0x7FFFF3FF;
1086 test = reg_test_82575;
1087 toggle = 0x7FFFF3FF;
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.
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);
1106 /* restore previous status */
1107 wr32(E1000_STATUS, before);
1109 /* Perform the remainder of the register test, looping through
1110 * the test table until we either fail or reach the null entry.
1113 for (i = 0; i < test->array_len; i++) {
1114 switch (test->test_type) {
1116 REG_PATTERN_TEST(test->reg +
1117 (i * test->reg_offset),
1122 REG_SET_AND_CHECK(test->reg +
1123 (i * test->reg_offset),
1129 (adapter->hw.hw_addr + test->reg)
1130 + (i * test->reg_offset));
1133 REG_PATTERN_TEST(test->reg + (i * 4),
1137 case TABLE64_TEST_LO:
1138 REG_PATTERN_TEST(test->reg + (i * 8),
1142 case TABLE64_TEST_HI:
1143 REG_PATTERN_TEST((test->reg + 4) + (i * 8),
1156 static int igb_eeprom_test(struct igb_adapter *adapter, u64 *data)
1163 /* Read and add up the contents of the EEPROM */
1164 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
1165 if ((adapter->hw.nvm.ops.read(&adapter->hw, i, 1, &temp)) < 0) {
1172 /* If Checksum is not Correct return error else test passed */
1173 if ((checksum != (u16) NVM_SUM) && !(*data))
1179 static irqreturn_t igb_test_intr(int irq, void *data)
1181 struct igb_adapter *adapter = (struct igb_adapter *) data;
1182 struct e1000_hw *hw = &adapter->hw;
1184 adapter->test_icr |= rd32(E1000_ICR);
1189 static int igb_intr_test(struct igb_adapter *adapter, u64 *data)
1191 struct e1000_hw *hw = &adapter->hw;
1192 struct net_device *netdev = adapter->netdev;
1193 u32 mask, ics_mask, i = 0, shared_int = true;
1194 u32 irq = adapter->pdev->irq;
1198 /* Hook up test interrupt handler just for this test */
1199 if (adapter->msix_entries) {
1200 if (request_irq(adapter->msix_entries[0].vector,
1201 igb_test_intr, 0, netdev->name, adapter)) {
1205 } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
1207 if (request_irq(irq,
1208 igb_test_intr, 0, netdev->name, adapter)) {
1212 } else if (!request_irq(irq, igb_test_intr, IRQF_PROBE_SHARED,
1213 netdev->name, adapter)) {
1215 } else if (request_irq(irq, igb_test_intr, IRQF_SHARED,
1216 netdev->name, adapter)) {
1220 dev_info(&adapter->pdev->dev, "testing %s interrupt\n",
1221 (shared_int ? "shared" : "unshared"));
1223 /* Disable all the interrupts */
1224 wr32(E1000_IMC, ~0);
1227 /* Define all writable bits for ICS */
1228 switch (hw->mac.type) {
1230 ics_mask = 0x37F47EDD;
1233 ics_mask = 0x77D4FBFD;
1236 ics_mask = 0x77DCFED5;
1239 ics_mask = 0x7FFFFFFF;
1243 /* Test each interrupt */
1244 for (; i < 31; i++) {
1245 /* Interrupt to test */
1248 if (!(mask & ics_mask))
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
1258 adapter->test_icr = 0;
1260 /* Flush any pending interrupts */
1261 wr32(E1000_ICR, ~0);
1263 wr32(E1000_IMC, mask);
1264 wr32(E1000_ICS, mask);
1267 if (adapter->test_icr & mask) {
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
1279 adapter->test_icr = 0;
1281 /* Flush any pending interrupts */
1282 wr32(E1000_ICR, ~0);
1284 wr32(E1000_IMS, mask);
1285 wr32(E1000_ICS, mask);
1288 if (!(adapter->test_icr & mask)) {
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
1300 adapter->test_icr = 0;
1302 /* Flush any pending interrupts */
1303 wr32(E1000_ICR, ~0);
1305 wr32(E1000_IMC, ~mask);
1306 wr32(E1000_ICS, ~mask);
1309 if (adapter->test_icr & mask) {
1316 /* Disable all the interrupts */
1317 wr32(E1000_IMC, ~0);
1320 /* Unhook test interrupt handler */
1321 if (adapter->msix_entries)
1322 free_irq(adapter->msix_entries[0].vector, adapter);
1324 free_irq(irq, adapter);
1329 static void igb_free_desc_rings(struct igb_adapter *adapter)
1331 igb_free_tx_resources(&adapter->test_tx_ring);
1332 igb_free_rx_resources(&adapter->test_rx_ring);
1335 static int igb_setup_desc_rings(struct igb_adapter *adapter)
1337 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1338 struct igb_ring *rx_ring = &adapter->test_rx_ring;
1339 struct e1000_hw *hw = &adapter->hw;
1342 /* Setup Tx descriptor ring and Tx buffers */
1343 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;
1348 if (igb_setup_tx_resources(tx_ring)) {
1353 igb_setup_tctl(adapter);
1354 igb_configure_tx_ring(adapter, tx_ring);
1356 /* Setup Rx descriptor ring and Rx buffers */
1357 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;
1363 if (igb_setup_rx_resources(rx_ring)) {
1368 /* set the default queue to queue 0 of PF */
1369 wr32(E1000_MRQC, adapter->vfs_allocated_count << 3);
1371 /* enable receive ring */
1372 igb_setup_rctl(adapter);
1373 igb_configure_rx_ring(adapter, rx_ring);
1375 igb_alloc_rx_buffers_adv(rx_ring, igb_desc_unused(rx_ring));
1380 igb_free_desc_rings(adapter);
1384 static void igb_phy_disable_receiver(struct igb_adapter *adapter)
1386 struct e1000_hw *hw = &adapter->hw;
1388 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1389 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);
1395 static int igb_integrated_phy_loopback(struct igb_adapter *adapter)
1397 struct e1000_hw *hw = &adapter->hw;
1400 hw->mac.autoneg = false;
1402 if (hw->phy.type == e1000_phy_m88) {
1403 /* Auto-MDI/MDIX Off */
1404 igb_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1405 /* reset to update Auto-MDI/MDIX */
1406 igb_write_phy_reg(hw, PHY_CONTROL, 0x9140);
1408 igb_write_phy_reg(hw, PHY_CONTROL, 0x8140);
1409 } else if (hw->phy.type == e1000_phy_82580) {
1410 /* enable MII loopback */
1411 igb_write_phy_reg(hw, I82580_PHY_LBK_CTRL, 0x8041);
1414 ctrl_reg = rd32(E1000_CTRL);
1416 /* force 1000, set loopback */
1417 igb_write_phy_reg(hw, PHY_CONTROL, 0x4140);
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 */
1425 E1000_CTRL_FD | /* Force Duplex to FULL */
1426 E1000_CTRL_SLU); /* Set link up enable bit */
1428 if (hw->phy.type == e1000_phy_m88)
1429 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1431 wr32(E1000_CTRL, ctrl_reg);
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.
1436 if (hw->phy.type == e1000_phy_m88)
1437 igb_phy_disable_receiver(adapter);
1444 static int igb_set_phy_loopback(struct igb_adapter *adapter)
1446 return igb_integrated_phy_loopback(adapter);
1449 static int igb_setup_loopback_test(struct igb_adapter *adapter)
1451 struct e1000_hw *hw = &adapter->hw;
1454 reg = rd32(E1000_CTRL_EXT);
1456 /* use CTRL_EXT to identify link type as SGMII can appear as copper */
1457 if (reg & E1000_CTRL_EXT_LINK_MODE_MASK) {
1458 reg = rd32(E1000_RCTL);
1459 reg |= E1000_RCTL_LBM_TCVR;
1460 wr32(E1000_RCTL, reg);
1462 wr32(E1000_SCTL, E1000_ENABLE_SERDES_LOOPBACK);
1464 reg = rd32(E1000_CTRL);
1465 reg &= ~(E1000_CTRL_RFCE |
1468 reg |= E1000_CTRL_SLU |
1470 wr32(E1000_CTRL, reg);
1472 /* Unset switch control to serdes energy detect */
1473 reg = rd32(E1000_CONNSW);
1474 reg &= ~E1000_CONNSW_ENRGSRC;
1475 wr32(E1000_CONNSW, reg);
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);
1490 return igb_set_phy_loopback(adapter);
1493 static void igb_loopback_cleanup(struct igb_adapter *adapter)
1495 struct e1000_hw *hw = &adapter->hw;
1499 rctl = rd32(E1000_RCTL);
1500 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1501 wr32(E1000_RCTL, rctl);
1503 hw->mac.autoneg = true;
1504 igb_read_phy_reg(hw, PHY_CONTROL, &phy_reg);
1505 if (phy_reg & MII_CR_LOOPBACK) {
1506 phy_reg &= ~MII_CR_LOOPBACK;
1507 igb_write_phy_reg(hw, PHY_CONTROL, phy_reg);
1508 igb_phy_sw_reset(hw);
1512 static void igb_create_lbtest_frame(struct sk_buff *skb,
1513 unsigned int frame_size)
1515 memset(skb->data, 0xFF, frame_size);
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);
1522 static int igb_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1525 if (*(skb->data + 3) == 0xFF) {
1526 if ((*(skb->data + frame_size + 10) == 0xBE) &&
1527 (*(skb->data + frame_size + 12) == 0xAF)) {
1534 static int igb_clean_test_rings(struct igb_ring *rx_ring,
1535 struct igb_ring *tx_ring,
1538 union e1000_adv_rx_desc *rx_desc;
1539 struct igb_buffer *buffer_info;
1540 int rx_ntc, tx_ntc, count = 0;
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);
1549 while (staterr & E1000_RXD_STAT_DD) {
1550 /* check rx buffer */
1551 buffer_info = &rx_ring->buffer_info[rx_ntc];
1553 /* unmap rx buffer, will be remapped by alloc_rx_buffers */
1554 pci_unmap_single(rx_ring->pdev,
1556 rx_ring->rx_buffer_len,
1557 PCI_DMA_FROMDEVICE);
1558 buffer_info->dma = 0;
1560 /* verify contents of skb */
1561 if (!igb_check_lbtest_frame(buffer_info->skb, size))
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);
1568 /* increment rx/tx next to clean counters */
1570 if (rx_ntc == rx_ring->count)
1573 if (tx_ntc == tx_ring->count)
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);
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;
1589 static int igb_run_loopback_test(struct igb_adapter *adapter)
1591 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1592 struct igb_ring *rx_ring = &adapter->test_rx_ring;
1593 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;
1598 /* allocate test skb */
1599 skb = alloc_skb(size, GFP_KERNEL);
1603 /* place data into test skb */
1604 igb_create_lbtest_frame(skb, size);
1608 * Calculate the loop count based on the largest descriptor ring
1609 * The idea is to wrap the largest ring a number of times using 64
1610 * send/receive pairs during each loop
1613 if (rx_ring->count <= tx_ring->count)
1614 lc = ((tx_ring->count / 64) * 2) + 1;
1616 lc = ((rx_ring->count / 64) * 2) + 1;
1618 for (j = 0; j <= lc; j++) { /* loop count loop */
1619 /* reset count of good packets */
1622 /* place 64 packets on the transmit queue*/
1623 for (i = 0; i < 64; i++) {
1625 tx_ret_val = igb_xmit_frame_ring_adv(skb, tx_ring);
1626 if (tx_ret_val == NETDEV_TX_OK)
1630 if (good_cnt != 64) {
1635 /* allow 200 milliseconds for packets to go from tx to rx */
1638 good_cnt = igb_clean_test_rings(rx_ring, tx_ring, size);
1639 if (good_cnt != 64) {
1643 } /* end loop count loop */
1645 /* free the original skb */
1651 static int igb_loopback_test(struct igb_adapter *adapter, u64 *data)
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");
1662 *data = igb_setup_desc_rings(adapter);
1665 *data = igb_setup_loopback_test(adapter);
1668 *data = igb_run_loopback_test(adapter);
1669 igb_loopback_cleanup(adapter);
1672 igb_free_desc_rings(adapter);
1677 static int igb_link_test(struct igb_adapter *adapter, u64 *data)
1679 struct e1000_hw *hw = &adapter->hw;
1681 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1683 hw->mac.serdes_has_link = false;
1685 /* On some blade server designs, link establishment
1686 * could take as long as 2-3 minutes */
1688 hw->mac.ops.check_for_link(&adapter->hw);
1689 if (hw->mac.serdes_has_link)
1692 } while (i++ < 3750);
1696 hw->mac.ops.check_for_link(&adapter->hw);
1697 if (hw->mac.autoneg)
1700 if (!(rd32(E1000_STATUS) & E1000_STATUS_LU))
1706 static void igb_diag_test(struct net_device *netdev,
1707 struct ethtool_test *eth_test, u64 *data)
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);
1714 set_bit(__IGB_TESTING, &adapter->state);
1715 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
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;
1723 dev_info(&adapter->pdev->dev, "offline testing starting\n");
1725 /* Link test performed before hardware reset so autoneg doesn't
1726 * interfere with test result */
1727 if (igb_link_test(adapter, &data[4]))
1728 eth_test->flags |= ETH_TEST_FL_FAILED;
1731 /* indicate we're in test mode */
1736 if (igb_reg_test(adapter, &data[0]))
1737 eth_test->flags |= ETH_TEST_FL_FAILED;
1740 if (igb_eeprom_test(adapter, &data[1]))
1741 eth_test->flags |= ETH_TEST_FL_FAILED;
1744 if (igb_intr_test(adapter, &data[2]))
1745 eth_test->flags |= ETH_TEST_FL_FAILED;
1748 if (igb_loopback_test(adapter, &data[3]))
1749 eth_test->flags |= ETH_TEST_FL_FAILED;
1751 /* restore speed, duplex, autoneg settings */
1752 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1753 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1754 adapter->hw.mac.autoneg = autoneg;
1756 /* force this routine to wait until autoneg complete/timeout */
1757 adapter->hw.phy.autoneg_wait_to_complete = true;
1759 adapter->hw.phy.autoneg_wait_to_complete = false;
1761 clear_bit(__IGB_TESTING, &adapter->state);
1765 dev_info(&adapter->pdev->dev, "online testing starting\n");
1767 if (igb_link_test(adapter, &data[4]))
1768 eth_test->flags |= ETH_TEST_FL_FAILED;
1770 /* Online tests aren't run; pass by default */
1776 clear_bit(__IGB_TESTING, &adapter->state);
1778 msleep_interruptible(4 * 1000);
1781 static int igb_wol_exclusion(struct igb_adapter *adapter,
1782 struct ethtool_wolinfo *wol)
1784 struct e1000_hw *hw = &adapter->hw;
1785 int retval = 1; /* fail by default */
1787 switch (hw->device_id) {
1788 case E1000_DEV_ID_82575GB_QUAD_COPPER:
1789 /* WoL not supported */
1792 case E1000_DEV_ID_82575EB_FIBER_SERDES:
1793 case E1000_DEV_ID_82576_FIBER:
1794 case E1000_DEV_ID_82576_SERDES:
1795 /* Wake events not supported on port B */
1796 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1) {
1800 /* return success for non excluded adapter ports */
1803 case E1000_DEV_ID_82576_QUAD_COPPER:
1804 /* quad port adapters only support WoL on port A */
1805 if (!(adapter->flags & IGB_FLAG_QUAD_PORT_A)) {
1809 /* return success for non excluded adapter ports */
1813 /* dual port cards only support WoL on port A from now on
1814 * unless it was enabled in the eeprom for port B
1815 * so exclude FUNC_1 ports from having WoL enabled */
1816 if ((rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) &&
1817 !adapter->eeprom_wol) {
1828 static void igb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1830 struct igb_adapter *adapter = netdev_priv(netdev);
1832 wol->supported = WAKE_UCAST | WAKE_MCAST |
1833 WAKE_BCAST | WAKE_MAGIC |
1837 /* this function will set ->supported = 0 and return 1 if wol is not
1838 * supported by this hardware */
1839 if (igb_wol_exclusion(adapter, wol) ||
1840 !device_can_wakeup(&adapter->pdev->dev))
1843 /* apply any specific unsupported masks here */
1844 switch (adapter->hw.device_id) {
1849 if (adapter->wol & E1000_WUFC_EX)
1850 wol->wolopts |= WAKE_UCAST;
1851 if (adapter->wol & E1000_WUFC_MC)
1852 wol->wolopts |= WAKE_MCAST;
1853 if (adapter->wol & E1000_WUFC_BC)
1854 wol->wolopts |= WAKE_BCAST;
1855 if (adapter->wol & E1000_WUFC_MAG)
1856 wol->wolopts |= WAKE_MAGIC;
1857 if (adapter->wol & E1000_WUFC_LNKC)
1858 wol->wolopts |= WAKE_PHY;
1861 static int igb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1863 struct igb_adapter *adapter = netdev_priv(netdev);
1865 if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE))
1868 if (igb_wol_exclusion(adapter, wol) ||
1869 !device_can_wakeup(&adapter->pdev->dev))
1870 return wol->wolopts ? -EOPNOTSUPP : 0;
1872 /* these settings will always override what we currently have */
1875 if (wol->wolopts & WAKE_UCAST)
1876 adapter->wol |= E1000_WUFC_EX;
1877 if (wol->wolopts & WAKE_MCAST)
1878 adapter->wol |= E1000_WUFC_MC;
1879 if (wol->wolopts & WAKE_BCAST)
1880 adapter->wol |= E1000_WUFC_BC;
1881 if (wol->wolopts & WAKE_MAGIC)
1882 adapter->wol |= E1000_WUFC_MAG;
1883 if (wol->wolopts & WAKE_PHY)
1884 adapter->wol |= E1000_WUFC_LNKC;
1885 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1890 /* bit defines for adapter->led_status */
1891 #define IGB_LED_ON 0
1893 static int igb_phys_id(struct net_device *netdev, u32 data)
1895 struct igb_adapter *adapter = netdev_priv(netdev);
1896 struct e1000_hw *hw = &adapter->hw;
1897 unsigned long timeout;
1899 timeout = data * 1000;
1902 * msleep_interruptable only accepts unsigned int so we are limited
1903 * in how long a duration we can wait
1905 if (!timeout || timeout > UINT_MAX)
1909 msleep_interruptible(timeout);
1912 clear_bit(IGB_LED_ON, &adapter->led_status);
1913 igb_cleanup_led(hw);
1918 static int igb_set_coalesce(struct net_device *netdev,
1919 struct ethtool_coalesce *ec)
1921 struct igb_adapter *adapter = netdev_priv(netdev);
1924 if ((ec->rx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
1925 ((ec->rx_coalesce_usecs > 3) &&
1926 (ec->rx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
1927 (ec->rx_coalesce_usecs == 2))
1930 if ((ec->tx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
1931 ((ec->tx_coalesce_usecs > 3) &&
1932 (ec->tx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
1933 (ec->tx_coalesce_usecs == 2))
1936 if ((adapter->flags & IGB_FLAG_QUEUE_PAIRS) && ec->tx_coalesce_usecs)
1939 /* convert to rate of irq's per second */
1940 if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3)
1941 adapter->rx_itr_setting = ec->rx_coalesce_usecs;
1943 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
1945 /* convert to rate of irq's per second */
1946 if (adapter->flags & IGB_FLAG_QUEUE_PAIRS)
1947 adapter->tx_itr_setting = adapter->rx_itr_setting;
1948 else if (ec->tx_coalesce_usecs && ec->tx_coalesce_usecs <= 3)
1949 adapter->tx_itr_setting = ec->tx_coalesce_usecs;
1951 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
1953 for (i = 0; i < adapter->num_q_vectors; i++) {
1954 struct igb_q_vector *q_vector = adapter->q_vector[i];
1955 if (q_vector->rx_ring)
1956 q_vector->itr_val = adapter->rx_itr_setting;
1958 q_vector->itr_val = adapter->tx_itr_setting;
1959 if (q_vector->itr_val && q_vector->itr_val <= 3)
1960 q_vector->itr_val = IGB_START_ITR;
1961 q_vector->set_itr = 1;
1967 static int igb_get_coalesce(struct net_device *netdev,
1968 struct ethtool_coalesce *ec)
1970 struct igb_adapter *adapter = netdev_priv(netdev);
1972 if (adapter->rx_itr_setting <= 3)
1973 ec->rx_coalesce_usecs = adapter->rx_itr_setting;
1975 ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
1977 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS)) {
1978 if (adapter->tx_itr_setting <= 3)
1979 ec->tx_coalesce_usecs = adapter->tx_itr_setting;
1981 ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
1987 static int igb_nway_reset(struct net_device *netdev)
1989 struct igb_adapter *adapter = netdev_priv(netdev);
1990 if (netif_running(netdev))
1991 igb_reinit_locked(adapter);
1995 static int igb_get_sset_count(struct net_device *netdev, int sset)
1999 return IGB_STATS_LEN;
2001 return IGB_TEST_LEN;
2007 static void igb_get_ethtool_stats(struct net_device *netdev,
2008 struct ethtool_stats *stats, u64 *data)
2010 struct igb_adapter *adapter = netdev_priv(netdev);
2011 struct net_device_stats *net_stats = &netdev->stats;
2016 igb_update_stats(adapter);
2018 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
2019 p = (char *)adapter + igb_gstrings_stats[i].stat_offset;
2020 data[i] = (igb_gstrings_stats[i].sizeof_stat ==
2021 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2023 for (j = 0; j < IGB_NETDEV_STATS_LEN; j++, i++) {
2024 p = (char *)net_stats + igb_gstrings_net_stats[j].stat_offset;
2025 data[i] = (igb_gstrings_net_stats[j].sizeof_stat ==
2026 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2028 for (j = 0; j < adapter->num_tx_queues; j++) {
2029 queue_stat = (u64 *)&adapter->tx_ring[j].tx_stats;
2030 for (k = 0; k < IGB_TX_QUEUE_STATS_LEN; k++, i++)
2031 data[i] = queue_stat[k];
2033 for (j = 0; j < adapter->num_rx_queues; j++) {
2034 queue_stat = (u64 *)&adapter->rx_ring[j].rx_stats;
2035 for (k = 0; k < IGB_RX_QUEUE_STATS_LEN; k++, i++)
2036 data[i] = queue_stat[k];
2040 static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
2042 struct igb_adapter *adapter = netdev_priv(netdev);
2046 switch (stringset) {
2048 memcpy(data, *igb_gstrings_test,
2049 IGB_TEST_LEN*ETH_GSTRING_LEN);
2052 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
2053 memcpy(p, igb_gstrings_stats[i].stat_string,
2055 p += ETH_GSTRING_LEN;
2057 for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) {
2058 memcpy(p, igb_gstrings_net_stats[i].stat_string,
2060 p += ETH_GSTRING_LEN;
2062 for (i = 0; i < adapter->num_tx_queues; i++) {
2063 sprintf(p, "tx_queue_%u_packets", i);
2064 p += ETH_GSTRING_LEN;
2065 sprintf(p, "tx_queue_%u_bytes", i);
2066 p += ETH_GSTRING_LEN;
2067 sprintf(p, "tx_queue_%u_restart", i);
2068 p += ETH_GSTRING_LEN;
2070 for (i = 0; i < adapter->num_rx_queues; i++) {
2071 sprintf(p, "rx_queue_%u_packets", i);
2072 p += ETH_GSTRING_LEN;
2073 sprintf(p, "rx_queue_%u_bytes", i);
2074 p += ETH_GSTRING_LEN;
2075 sprintf(p, "rx_queue_%u_drops", i);
2076 p += ETH_GSTRING_LEN;
2077 sprintf(p, "rx_queue_%u_csum_err", i);
2078 p += ETH_GSTRING_LEN;
2079 sprintf(p, "rx_queue_%u_alloc_failed", i);
2080 p += ETH_GSTRING_LEN;
2082 /* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
2087 static const struct ethtool_ops igb_ethtool_ops = {
2088 .get_settings = igb_get_settings,
2089 .set_settings = igb_set_settings,
2090 .get_drvinfo = igb_get_drvinfo,
2091 .get_regs_len = igb_get_regs_len,
2092 .get_regs = igb_get_regs,
2093 .get_wol = igb_get_wol,
2094 .set_wol = igb_set_wol,
2095 .get_msglevel = igb_get_msglevel,
2096 .set_msglevel = igb_set_msglevel,
2097 .nway_reset = igb_nway_reset,
2098 .get_link = igb_get_link,
2099 .get_eeprom_len = igb_get_eeprom_len,
2100 .get_eeprom = igb_get_eeprom,
2101 .set_eeprom = igb_set_eeprom,
2102 .get_ringparam = igb_get_ringparam,
2103 .set_ringparam = igb_set_ringparam,
2104 .get_pauseparam = igb_get_pauseparam,
2105 .set_pauseparam = igb_set_pauseparam,
2106 .get_rx_csum = igb_get_rx_csum,
2107 .set_rx_csum = igb_set_rx_csum,
2108 .get_tx_csum = igb_get_tx_csum,
2109 .set_tx_csum = igb_set_tx_csum,
2110 .get_sg = ethtool_op_get_sg,
2111 .set_sg = ethtool_op_set_sg,
2112 .get_tso = ethtool_op_get_tso,
2113 .set_tso = igb_set_tso,
2114 .self_test = igb_diag_test,
2115 .get_strings = igb_get_strings,
2116 .phys_id = igb_phys_id,
2117 .get_sset_count = igb_get_sset_count,
2118 .get_ethtool_stats = igb_get_ethtool_stats,
2119 .get_coalesce = igb_get_coalesce,
2120 .set_coalesce = igb_set_coalesce,
2123 void igb_set_ethtool_ops(struct net_device *netdev)
2125 SET_ETHTOOL_OPS(netdev, &igb_ethtool_ops);