blob: 561df67ae595dd4161b82974d3b84e31cb59f2f3 [file] [log] [blame]
Carolyn Wybornye52c0f92014-04-11 01:46:06 +00001/* Intel(R) Gigabit Ethernet Linux driver
2 * Copyright(c) 2007-2014 Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, see <http://www.gnu.org/licenses/>.
15 *
16 * The full GNU General Public License is included in this distribution in
17 * the file called "COPYING".
18 *
19 * Contact Information:
20 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
21 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
22 */
Auke Kok9d5c8242008-01-24 02:22:38 -080023
24/* ethtool support for igb */
25
26#include <linux/vmalloc.h>
27#include <linux/netdevice.h>
28#include <linux/pci.h>
29#include <linux/delay.h>
30#include <linux/interrupt.h>
31#include <linux/if_ether.h>
32#include <linux/ethtool.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040033#include <linux/sched.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Yan, Zheng749ab2c2012-01-04 20:23:37 +000035#include <linux/pm_runtime.h>
Alexander Duyck1a1c2252012-09-25 00:30:52 +000036#include <linux/highmem.h>
Matthew Vick87371b92013-02-21 03:32:52 +000037#include <linux/mdio.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080038
39#include "igb.h"
40
41struct igb_stats {
42 char stat_string[ETH_GSTRING_LEN];
43 int sizeof_stat;
44 int stat_offset;
45};
46
Alexander Duyck128e45e2009-11-12 18:37:38 +000047#define IGB_STAT(_name, _stat) { \
48 .stat_string = _name, \
49 .sizeof_stat = FIELD_SIZEOF(struct igb_adapter, _stat), \
50 .stat_offset = offsetof(struct igb_adapter, _stat) \
51}
Auke Kok9d5c8242008-01-24 02:22:38 -080052static const struct igb_stats igb_gstrings_stats[] = {
Alexander Duyck128e45e2009-11-12 18:37:38 +000053 IGB_STAT("rx_packets", stats.gprc),
54 IGB_STAT("tx_packets", stats.gptc),
55 IGB_STAT("rx_bytes", stats.gorc),
56 IGB_STAT("tx_bytes", stats.gotc),
57 IGB_STAT("rx_broadcast", stats.bprc),
58 IGB_STAT("tx_broadcast", stats.bptc),
59 IGB_STAT("rx_multicast", stats.mprc),
60 IGB_STAT("tx_multicast", stats.mptc),
61 IGB_STAT("multicast", stats.mprc),
62 IGB_STAT("collisions", stats.colc),
63 IGB_STAT("rx_crc_errors", stats.crcerrs),
64 IGB_STAT("rx_no_buffer_count", stats.rnbc),
65 IGB_STAT("rx_missed_errors", stats.mpc),
66 IGB_STAT("tx_aborted_errors", stats.ecol),
67 IGB_STAT("tx_carrier_errors", stats.tncrs),
68 IGB_STAT("tx_window_errors", stats.latecol),
69 IGB_STAT("tx_abort_late_coll", stats.latecol),
70 IGB_STAT("tx_deferred_ok", stats.dc),
71 IGB_STAT("tx_single_coll_ok", stats.scc),
72 IGB_STAT("tx_multi_coll_ok", stats.mcc),
73 IGB_STAT("tx_timeout_count", tx_timeout_count),
74 IGB_STAT("rx_long_length_errors", stats.roc),
75 IGB_STAT("rx_short_length_errors", stats.ruc),
76 IGB_STAT("rx_align_errors", stats.algnerrc),
77 IGB_STAT("tx_tcp_seg_good", stats.tsctc),
78 IGB_STAT("tx_tcp_seg_failed", stats.tsctfc),
79 IGB_STAT("rx_flow_control_xon", stats.xonrxc),
80 IGB_STAT("rx_flow_control_xoff", stats.xoffrxc),
81 IGB_STAT("tx_flow_control_xon", stats.xontxc),
82 IGB_STAT("tx_flow_control_xoff", stats.xofftxc),
83 IGB_STAT("rx_long_byte_count", stats.gorc),
84 IGB_STAT("tx_dma_out_of_sync", stats.doosync),
85 IGB_STAT("tx_smbus", stats.mgptc),
86 IGB_STAT("rx_smbus", stats.mgprc),
87 IGB_STAT("dropped_smbus", stats.mgpdc),
Carolyn Wyborny0a915b92011-02-26 07:42:37 +000088 IGB_STAT("os2bmc_rx_by_bmc", stats.o2bgptc),
89 IGB_STAT("os2bmc_tx_by_bmc", stats.b2ospc),
90 IGB_STAT("os2bmc_tx_by_host", stats.o2bspc),
91 IGB_STAT("os2bmc_rx_by_host", stats.b2ogprc),
Matthew Vick428f1f72012-12-13 07:20:34 +000092 IGB_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
Matthew Vickfc580752012-12-13 07:20:35 +000093 IGB_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Auke Kok9d5c8242008-01-24 02:22:38 -080094};
95
Alexander Duyck128e45e2009-11-12 18:37:38 +000096#define IGB_NETDEV_STAT(_net_stat) { \
97 .stat_string = __stringify(_net_stat), \
Eric Dumazet12dcd862010-10-15 17:27:10 +000098 .sizeof_stat = FIELD_SIZEOF(struct rtnl_link_stats64, _net_stat), \
99 .stat_offset = offsetof(struct rtnl_link_stats64, _net_stat) \
Alexander Duyck128e45e2009-11-12 18:37:38 +0000100}
101static const struct igb_stats igb_gstrings_net_stats[] = {
102 IGB_NETDEV_STAT(rx_errors),
103 IGB_NETDEV_STAT(tx_errors),
104 IGB_NETDEV_STAT(tx_dropped),
105 IGB_NETDEV_STAT(rx_length_errors),
106 IGB_NETDEV_STAT(rx_over_errors),
107 IGB_NETDEV_STAT(rx_frame_errors),
108 IGB_NETDEV_STAT(rx_fifo_errors),
109 IGB_NETDEV_STAT(tx_fifo_errors),
110 IGB_NETDEV_STAT(tx_heartbeat_errors)
111};
112
Auke Kok9d5c8242008-01-24 02:22:38 -0800113#define IGB_GLOBAL_STATS_LEN \
Alexander Duyck317f66b2009-10-27 23:46:20 +0000114 (sizeof(igb_gstrings_stats) / sizeof(struct igb_stats))
Alexander Duyck128e45e2009-11-12 18:37:38 +0000115#define IGB_NETDEV_STATS_LEN \
116 (sizeof(igb_gstrings_net_stats) / sizeof(struct igb_stats))
117#define IGB_RX_QUEUE_STATS_LEN \
118 (sizeof(struct igb_rx_queue_stats) / sizeof(u64))
Eric Dumazet12dcd862010-10-15 17:27:10 +0000119
120#define IGB_TX_QUEUE_STATS_LEN 3 /* packets, bytes, restart_queue */
121
Alexander Duyck128e45e2009-11-12 18:37:38 +0000122#define IGB_QUEUE_STATS_LEN \
123 ((((struct igb_adapter *)netdev_priv(netdev))->num_rx_queues * \
124 IGB_RX_QUEUE_STATS_LEN) + \
125 (((struct igb_adapter *)netdev_priv(netdev))->num_tx_queues * \
126 IGB_TX_QUEUE_STATS_LEN))
127#define IGB_STATS_LEN \
128 (IGB_GLOBAL_STATS_LEN + IGB_NETDEV_STATS_LEN + IGB_QUEUE_STATS_LEN)
129
Auke Kok9d5c8242008-01-24 02:22:38 -0800130static const char igb_gstrings_test[][ETH_GSTRING_LEN] = {
131 "Register test (offline)", "Eeprom test (offline)",
132 "Interrupt test (offline)", "Loopback test (offline)",
133 "Link test (on/offline)"
134};
Alexander Duyck317f66b2009-10-27 23:46:20 +0000135#define IGB_TEST_LEN (sizeof(igb_gstrings_test) / ETH_GSTRING_LEN)
Auke Kok9d5c8242008-01-24 02:22:38 -0800136
137static int igb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
138{
139 struct igb_adapter *adapter = netdev_priv(netdev);
140 struct e1000_hw *hw = &adapter->hw;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000141 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
142 struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags;
Alexander Duyck317f66b2009-10-27 23:46:20 +0000143 u32 status;
Auke Kok9d5c8242008-01-24 02:22:38 -0800144
Carolyn Wyborny01237132013-11-09 04:52:14 -0800145 status = rd32(E1000_STATUS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800146 if (hw->phy.media_type == e1000_media_type_copper) {
147
148 ecmd->supported = (SUPPORTED_10baseT_Half |
149 SUPPORTED_10baseT_Full |
150 SUPPORTED_100baseT_Half |
151 SUPPORTED_100baseT_Full |
152 SUPPORTED_1000baseT_Full|
153 SUPPORTED_Autoneg |
Akeem G. Abodunrin42f3c432012-08-17 03:35:07 +0000154 SUPPORTED_TP |
155 SUPPORTED_Pause);
156 ecmd->advertising = ADVERTISED_TP;
Auke Kok9d5c8242008-01-24 02:22:38 -0800157
158 if (hw->mac.autoneg == 1) {
159 ecmd->advertising |= ADVERTISED_Autoneg;
160 /* the e1000 autoneg seems to match ethtool nicely */
161 ecmd->advertising |= hw->phy.autoneg_advertised;
162 }
163
164 ecmd->port = PORT_TP;
165 ecmd->phy_address = hw->phy.addr;
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000166 ecmd->transceiver = XCVR_INTERNAL;
Auke Kok9d5c8242008-01-24 02:22:38 -0800167 } else {
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000168 ecmd->supported = (SUPPORTED_FIBRE |
Carolyn Wyborny01237132013-11-09 04:52:14 -0800169 SUPPORTED_1000baseKX_Full |
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000170 SUPPORTED_Autoneg |
171 SUPPORTED_Pause);
Carolyn Wyborny01237132013-11-09 04:52:14 -0800172 ecmd->advertising = (ADVERTISED_FIBRE |
173 ADVERTISED_1000baseKX_Full);
174 if (hw->mac.type == e1000_i354) {
175 if ((hw->device_id ==
176 E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) &&
177 !(status & E1000_STATUS_2P5_SKU_OVER)) {
178 ecmd->supported |= SUPPORTED_2500baseX_Full;
179 ecmd->supported &=
180 ~SUPPORTED_1000baseKX_Full;
181 ecmd->advertising |= ADVERTISED_2500baseX_Full;
182 ecmd->advertising &=
183 ~ADVERTISED_1000baseKX_Full;
184 }
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000185 }
186 if (eth_flags->e100_base_fx) {
187 ecmd->supported |= SUPPORTED_100baseT_Full;
188 ecmd->advertising |= ADVERTISED_100baseT_Full;
189 }
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000190 if (hw->mac.autoneg == 1)
191 ecmd->advertising |= ADVERTISED_Autoneg;
Auke Kok9d5c8242008-01-24 02:22:38 -0800192
193 ecmd->port = PORT_FIBRE;
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000194 ecmd->transceiver = XCVR_EXTERNAL;
Auke Kok9d5c8242008-01-24 02:22:38 -0800195 }
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000196 if (hw->mac.autoneg != 1)
197 ecmd->advertising &= ~(ADVERTISED_Pause |
198 ADVERTISED_Asym_Pause);
199
Carolyn Wyborny01237132013-11-09 04:52:14 -0800200 switch (hw->fc.requested_mode) {
201 case e1000_fc_full:
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000202 ecmd->advertising |= ADVERTISED_Pause;
Carolyn Wyborny01237132013-11-09 04:52:14 -0800203 break;
204 case e1000_fc_rx_pause:
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000205 ecmd->advertising |= (ADVERTISED_Pause |
206 ADVERTISED_Asym_Pause);
Carolyn Wyborny01237132013-11-09 04:52:14 -0800207 break;
208 case e1000_fc_tx_pause:
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000209 ecmd->advertising |= ADVERTISED_Asym_Pause;
Carolyn Wyborny01237132013-11-09 04:52:14 -0800210 break;
211 default:
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000212 ecmd->advertising &= ~(ADVERTISED_Pause |
213 ADVERTISED_Asym_Pause);
Carolyn Wyborny01237132013-11-09 04:52:14 -0800214 }
Alexander Duyck317f66b2009-10-27 23:46:20 +0000215 if (status & E1000_STATUS_LU) {
Carolyn Wyborny01237132013-11-09 04:52:14 -0800216 if ((status & E1000_STATUS_2P5_SKU) &&
217 !(status & E1000_STATUS_2P5_SKU_OVER)) {
218 ecmd->speed = SPEED_2500;
Akeem G Abodunrin41fcfbe2013-08-30 23:49:36 +0000219 } else if (status & E1000_STATUS_SPEED_1000) {
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000220 ecmd->speed = SPEED_1000;
Akeem G Abodunrin41fcfbe2013-08-30 23:49:36 +0000221 } else if (status & E1000_STATUS_SPEED_100) {
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000222 ecmd->speed = SPEED_100;
Akeem G Abodunrin41fcfbe2013-08-30 23:49:36 +0000223 } else {
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000224 ecmd->speed = SPEED_10;
Akeem G Abodunrin41fcfbe2013-08-30 23:49:36 +0000225 }
Alexander Duyck317f66b2009-10-27 23:46:20 +0000226 if ((status & E1000_STATUS_FD) ||
227 hw->phy.media_type != e1000_media_type_copper)
Auke Kok9d5c8242008-01-24 02:22:38 -0800228 ecmd->duplex = DUPLEX_FULL;
229 else
230 ecmd->duplex = DUPLEX_HALF;
231 } else {
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000232 ecmd->speed = -1;
Auke Kok9d5c8242008-01-24 02:22:38 -0800233 ecmd->duplex = -1;
234 }
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000235 if ((hw->phy.media_type == e1000_media_type_fiber) ||
236 hw->mac.autoneg)
237 ecmd->autoneg = AUTONEG_ENABLE;
238 else
239 ecmd->autoneg = AUTONEG_DISABLE;
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000240
241 /* MDI-X => 2; MDI =>1; Invalid =>0 */
242 if (hw->phy.media_type == e1000_media_type_copper)
243 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
244 ETH_TP_MDI;
245 else
246 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
247
248 if (hw->phy.mdix == AUTO_ALL_MODES)
249 ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
250 else
251 ecmd->eth_tp_mdix_ctrl = hw->phy.mdix;
252
Auke Kok9d5c8242008-01-24 02:22:38 -0800253 return 0;
254}
255
256static int igb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
257{
258 struct igb_adapter *adapter = netdev_priv(netdev);
259 struct e1000_hw *hw = &adapter->hw;
260
261 /* When SoL/IDER sessions are active, autoneg/speed/duplex
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000262 * cannot be changed
263 */
Auke Kok9d5c8242008-01-24 02:22:38 -0800264 if (igb_check_reset_block(hw)) {
Jesper Juhld836200a2012-08-01 05:41:30 +0000265 dev_err(&adapter->pdev->dev,
266 "Cannot change link characteristics when SoL/IDER is active.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800267 return -EINVAL;
268 }
269
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000270 /* MDI setting is only allowed when autoneg enabled because
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000271 * some hardware doesn't allow MDI setting when speed or
272 * duplex is forced.
273 */
274 if (ecmd->eth_tp_mdix_ctrl) {
275 if (hw->phy.media_type != e1000_media_type_copper)
276 return -EOPNOTSUPP;
277
278 if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
279 (ecmd->autoneg != AUTONEG_ENABLE)) {
280 dev_err(&adapter->pdev->dev, "forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
281 return -EINVAL;
282 }
283 }
284
Auke Kok9d5c8242008-01-24 02:22:38 -0800285 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
286 msleep(1);
287
288 if (ecmd->autoneg == AUTONEG_ENABLE) {
289 hw->mac.autoneg = 1;
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000290 if (hw->phy.media_type == e1000_media_type_fiber) {
291 hw->phy.autoneg_advertised = ecmd->advertising |
292 ADVERTISED_FIBRE |
293 ADVERTISED_Autoneg;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000294 switch (adapter->link_speed) {
295 case SPEED_2500:
296 hw->phy.autoneg_advertised =
297 ADVERTISED_2500baseX_Full;
298 break;
299 case SPEED_1000:
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000300 hw->phy.autoneg_advertised =
301 ADVERTISED_1000baseT_Full;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000302 break;
303 case SPEED_100:
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000304 hw->phy.autoneg_advertised =
305 ADVERTISED_100baseT_Full;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000306 break;
307 default:
308 break;
309 }
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000310 } else {
311 hw->phy.autoneg_advertised = ecmd->advertising |
312 ADVERTISED_TP |
313 ADVERTISED_Autoneg;
314 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800315 ecmd->advertising = hw->phy.autoneg_advertised;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000316 if (adapter->fc_autoneg)
317 hw->fc.requested_mode = e1000_fc_default;
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000318 } else {
David Decotigny25db0332011-04-27 18:32:39 +0000319 u32 speed = ethtool_cmd_speed(ecmd);
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000320 /* calling this overrides forced MDI setting */
David Decotigny14ad2512011-04-27 18:32:43 +0000321 if (igb_set_spd_dplx(adapter, speed, ecmd->duplex)) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800322 clear_bit(__IGB_RESETTING, &adapter->state);
323 return -EINVAL;
324 }
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000325 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800326
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000327 /* MDI-X => 2; MDI => 1; Auto => 3 */
328 if (ecmd->eth_tp_mdix_ctrl) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000329 /* fix up the value for auto (3 => 0) as zero is mapped
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000330 * internally to auto
331 */
332 if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
333 hw->phy.mdix = AUTO_ALL_MODES;
334 else
335 hw->phy.mdix = ecmd->eth_tp_mdix_ctrl;
336 }
337
Auke Kok9d5c8242008-01-24 02:22:38 -0800338 /* reset the link */
Auke Kok9d5c8242008-01-24 02:22:38 -0800339 if (netif_running(adapter->netdev)) {
340 igb_down(adapter);
341 igb_up(adapter);
342 } else
343 igb_reset(adapter);
344
345 clear_bit(__IGB_RESETTING, &adapter->state);
346 return 0;
347}
348
Nick Nunley31455352010-02-17 01:01:21 +0000349static u32 igb_get_link(struct net_device *netdev)
350{
351 struct igb_adapter *adapter = netdev_priv(netdev);
352 struct e1000_mac_info *mac = &adapter->hw.mac;
353
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000354 /* If the link is not reported up to netdev, interrupts are disabled,
Nick Nunley31455352010-02-17 01:01:21 +0000355 * and so the physical link state may have changed since we last
356 * looked. Set get_link_status to make sure that the true link
357 * state is interrogated, rather than pulling a cached and possibly
358 * stale link state from the driver.
359 */
360 if (!netif_carrier_ok(netdev))
361 mac->get_link_status = 1;
362
363 return igb_has_link(adapter);
364}
365
Auke Kok9d5c8242008-01-24 02:22:38 -0800366static void igb_get_pauseparam(struct net_device *netdev,
367 struct ethtool_pauseparam *pause)
368{
369 struct igb_adapter *adapter = netdev_priv(netdev);
370 struct e1000_hw *hw = &adapter->hw;
371
372 pause->autoneg =
373 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
374
Alexander Duyck0cce1192009-07-23 18:10:24 +0000375 if (hw->fc.current_mode == e1000_fc_rx_pause)
Auke Kok9d5c8242008-01-24 02:22:38 -0800376 pause->rx_pause = 1;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000377 else if (hw->fc.current_mode == e1000_fc_tx_pause)
Auke Kok9d5c8242008-01-24 02:22:38 -0800378 pause->tx_pause = 1;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000379 else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800380 pause->rx_pause = 1;
381 pause->tx_pause = 1;
382 }
383}
384
385static int igb_set_pauseparam(struct net_device *netdev,
386 struct ethtool_pauseparam *pause)
387{
388 struct igb_adapter *adapter = netdev_priv(netdev);
389 struct e1000_hw *hw = &adapter->hw;
390 int retval = 0;
391
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000392 /* 100basefx does not support setting link flow control */
393 if (hw->dev_spec._82575.eth_flags.e100_base_fx)
394 return -EINVAL;
395
Auke Kok9d5c8242008-01-24 02:22:38 -0800396 adapter->fc_autoneg = pause->autoneg;
397
398 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
399 msleep(1);
400
Auke Kok9d5c8242008-01-24 02:22:38 -0800401 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000402 hw->fc.requested_mode = e1000_fc_default;
Auke Kok9d5c8242008-01-24 02:22:38 -0800403 if (netif_running(adapter->netdev)) {
404 igb_down(adapter);
405 igb_up(adapter);
Alexander Duyck317f66b2009-10-27 23:46:20 +0000406 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -0800407 igb_reset(adapter);
Alexander Duyck317f66b2009-10-27 23:46:20 +0000408 }
Alexander Duyck0cce1192009-07-23 18:10:24 +0000409 } else {
410 if (pause->rx_pause && pause->tx_pause)
411 hw->fc.requested_mode = e1000_fc_full;
412 else if (pause->rx_pause && !pause->tx_pause)
413 hw->fc.requested_mode = e1000_fc_rx_pause;
414 else if (!pause->rx_pause && pause->tx_pause)
415 hw->fc.requested_mode = e1000_fc_tx_pause;
416 else if (!pause->rx_pause && !pause->tx_pause)
417 hw->fc.requested_mode = e1000_fc_none;
418
419 hw->fc.current_mode = hw->fc.requested_mode;
420
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000421 retval = ((hw->phy.media_type == e1000_media_type_copper) ?
422 igb_force_mac_fc(hw) : igb_setup_link(hw));
Alexander Duyck0cce1192009-07-23 18:10:24 +0000423 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800424
425 clear_bit(__IGB_RESETTING, &adapter->state);
426 return retval;
427}
428
Auke Kok9d5c8242008-01-24 02:22:38 -0800429static u32 igb_get_msglevel(struct net_device *netdev)
430{
431 struct igb_adapter *adapter = netdev_priv(netdev);
432 return adapter->msg_enable;
433}
434
435static void igb_set_msglevel(struct net_device *netdev, u32 data)
436{
437 struct igb_adapter *adapter = netdev_priv(netdev);
438 adapter->msg_enable = data;
439}
440
441static int igb_get_regs_len(struct net_device *netdev)
442{
Koki Sanagi7e3b4ff2012-02-15 14:45:39 +0000443#define IGB_REGS_LEN 739
Auke Kok9d5c8242008-01-24 02:22:38 -0800444 return IGB_REGS_LEN * sizeof(u32);
445}
446
447static void igb_get_regs(struct net_device *netdev,
448 struct ethtool_regs *regs, void *p)
449{
450 struct igb_adapter *adapter = netdev_priv(netdev);
451 struct e1000_hw *hw = &adapter->hw;
452 u32 *regs_buff = p;
453 u8 i;
454
455 memset(p, 0, IGB_REGS_LEN * sizeof(u32));
456
457 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
458
459 /* General Registers */
460 regs_buff[0] = rd32(E1000_CTRL);
461 regs_buff[1] = rd32(E1000_STATUS);
462 regs_buff[2] = rd32(E1000_CTRL_EXT);
463 regs_buff[3] = rd32(E1000_MDIC);
464 regs_buff[4] = rd32(E1000_SCTL);
465 regs_buff[5] = rd32(E1000_CONNSW);
466 regs_buff[6] = rd32(E1000_VET);
467 regs_buff[7] = rd32(E1000_LEDCTL);
468 regs_buff[8] = rd32(E1000_PBA);
469 regs_buff[9] = rd32(E1000_PBS);
470 regs_buff[10] = rd32(E1000_FRTIMER);
471 regs_buff[11] = rd32(E1000_TCPTIMER);
472
473 /* NVM Register */
474 regs_buff[12] = rd32(E1000_EECD);
475
476 /* Interrupt */
Alexander Duyckfe59de32008-08-26 04:25:05 -0700477 /* Reading EICS for EICR because they read the
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000478 * same but EICS does not clear on read
479 */
Alexander Duyckfe59de32008-08-26 04:25:05 -0700480 regs_buff[13] = rd32(E1000_EICS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800481 regs_buff[14] = rd32(E1000_EICS);
482 regs_buff[15] = rd32(E1000_EIMS);
483 regs_buff[16] = rd32(E1000_EIMC);
484 regs_buff[17] = rd32(E1000_EIAC);
485 regs_buff[18] = rd32(E1000_EIAM);
Alexander Duyckfe59de32008-08-26 04:25:05 -0700486 /* Reading ICS for ICR because they read the
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000487 * same but ICS does not clear on read
488 */
Alexander Duyckfe59de32008-08-26 04:25:05 -0700489 regs_buff[19] = rd32(E1000_ICS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800490 regs_buff[20] = rd32(E1000_ICS);
491 regs_buff[21] = rd32(E1000_IMS);
492 regs_buff[22] = rd32(E1000_IMC);
493 regs_buff[23] = rd32(E1000_IAC);
494 regs_buff[24] = rd32(E1000_IAM);
495 regs_buff[25] = rd32(E1000_IMIRVP);
496
497 /* Flow Control */
498 regs_buff[26] = rd32(E1000_FCAL);
499 regs_buff[27] = rd32(E1000_FCAH);
500 regs_buff[28] = rd32(E1000_FCTTV);
501 regs_buff[29] = rd32(E1000_FCRTL);
502 regs_buff[30] = rd32(E1000_FCRTH);
503 regs_buff[31] = rd32(E1000_FCRTV);
504
505 /* Receive */
506 regs_buff[32] = rd32(E1000_RCTL);
507 regs_buff[33] = rd32(E1000_RXCSUM);
508 regs_buff[34] = rd32(E1000_RLPML);
509 regs_buff[35] = rd32(E1000_RFCTL);
510 regs_buff[36] = rd32(E1000_MRQC);
Alexander Duycke1739522009-02-19 20:39:44 -0800511 regs_buff[37] = rd32(E1000_VT_CTL);
Auke Kok9d5c8242008-01-24 02:22:38 -0800512
513 /* Transmit */
514 regs_buff[38] = rd32(E1000_TCTL);
515 regs_buff[39] = rd32(E1000_TCTL_EXT);
516 regs_buff[40] = rd32(E1000_TIPG);
517 regs_buff[41] = rd32(E1000_DTXCTL);
518
519 /* Wake Up */
520 regs_buff[42] = rd32(E1000_WUC);
521 regs_buff[43] = rd32(E1000_WUFC);
522 regs_buff[44] = rd32(E1000_WUS);
523 regs_buff[45] = rd32(E1000_IPAV);
524 regs_buff[46] = rd32(E1000_WUPL);
525
526 /* MAC */
527 regs_buff[47] = rd32(E1000_PCS_CFG0);
528 regs_buff[48] = rd32(E1000_PCS_LCTL);
529 regs_buff[49] = rd32(E1000_PCS_LSTAT);
530 regs_buff[50] = rd32(E1000_PCS_ANADV);
531 regs_buff[51] = rd32(E1000_PCS_LPAB);
532 regs_buff[52] = rd32(E1000_PCS_NPTX);
533 regs_buff[53] = rd32(E1000_PCS_LPABNP);
534
535 /* Statistics */
536 regs_buff[54] = adapter->stats.crcerrs;
537 regs_buff[55] = adapter->stats.algnerrc;
538 regs_buff[56] = adapter->stats.symerrs;
539 regs_buff[57] = adapter->stats.rxerrc;
540 regs_buff[58] = adapter->stats.mpc;
541 regs_buff[59] = adapter->stats.scc;
542 regs_buff[60] = adapter->stats.ecol;
543 regs_buff[61] = adapter->stats.mcc;
544 regs_buff[62] = adapter->stats.latecol;
545 regs_buff[63] = adapter->stats.colc;
546 regs_buff[64] = adapter->stats.dc;
547 regs_buff[65] = adapter->stats.tncrs;
548 regs_buff[66] = adapter->stats.sec;
549 regs_buff[67] = adapter->stats.htdpmc;
550 regs_buff[68] = adapter->stats.rlec;
551 regs_buff[69] = adapter->stats.xonrxc;
552 regs_buff[70] = adapter->stats.xontxc;
553 regs_buff[71] = adapter->stats.xoffrxc;
554 regs_buff[72] = adapter->stats.xofftxc;
555 regs_buff[73] = adapter->stats.fcruc;
556 regs_buff[74] = adapter->stats.prc64;
557 regs_buff[75] = adapter->stats.prc127;
558 regs_buff[76] = adapter->stats.prc255;
559 regs_buff[77] = adapter->stats.prc511;
560 regs_buff[78] = adapter->stats.prc1023;
561 regs_buff[79] = adapter->stats.prc1522;
562 regs_buff[80] = adapter->stats.gprc;
563 regs_buff[81] = adapter->stats.bprc;
564 regs_buff[82] = adapter->stats.mprc;
565 regs_buff[83] = adapter->stats.gptc;
566 regs_buff[84] = adapter->stats.gorc;
567 regs_buff[86] = adapter->stats.gotc;
568 regs_buff[88] = adapter->stats.rnbc;
569 regs_buff[89] = adapter->stats.ruc;
570 regs_buff[90] = adapter->stats.rfc;
571 regs_buff[91] = adapter->stats.roc;
572 regs_buff[92] = adapter->stats.rjc;
573 regs_buff[93] = adapter->stats.mgprc;
574 regs_buff[94] = adapter->stats.mgpdc;
575 regs_buff[95] = adapter->stats.mgptc;
576 regs_buff[96] = adapter->stats.tor;
577 regs_buff[98] = adapter->stats.tot;
578 regs_buff[100] = adapter->stats.tpr;
579 regs_buff[101] = adapter->stats.tpt;
580 regs_buff[102] = adapter->stats.ptc64;
581 regs_buff[103] = adapter->stats.ptc127;
582 regs_buff[104] = adapter->stats.ptc255;
583 regs_buff[105] = adapter->stats.ptc511;
584 regs_buff[106] = adapter->stats.ptc1023;
585 regs_buff[107] = adapter->stats.ptc1522;
586 regs_buff[108] = adapter->stats.mptc;
587 regs_buff[109] = adapter->stats.bptc;
588 regs_buff[110] = adapter->stats.tsctc;
589 regs_buff[111] = adapter->stats.iac;
590 regs_buff[112] = adapter->stats.rpthc;
591 regs_buff[113] = adapter->stats.hgptc;
592 regs_buff[114] = adapter->stats.hgorc;
593 regs_buff[116] = adapter->stats.hgotc;
594 regs_buff[118] = adapter->stats.lenerrs;
595 regs_buff[119] = adapter->stats.scvpc;
596 regs_buff[120] = adapter->stats.hrmpc;
597
Auke Kok9d5c8242008-01-24 02:22:38 -0800598 for (i = 0; i < 4; i++)
599 regs_buff[121 + i] = rd32(E1000_SRRCTL(i));
600 for (i = 0; i < 4; i++)
Alexander Duyck83ab50a2009-10-27 15:55:41 +0000601 regs_buff[125 + i] = rd32(E1000_PSRTYPE(i));
Auke Kok9d5c8242008-01-24 02:22:38 -0800602 for (i = 0; i < 4; i++)
603 regs_buff[129 + i] = rd32(E1000_RDBAL(i));
604 for (i = 0; i < 4; i++)
605 regs_buff[133 + i] = rd32(E1000_RDBAH(i));
606 for (i = 0; i < 4; i++)
607 regs_buff[137 + i] = rd32(E1000_RDLEN(i));
608 for (i = 0; i < 4; i++)
609 regs_buff[141 + i] = rd32(E1000_RDH(i));
610 for (i = 0; i < 4; i++)
611 regs_buff[145 + i] = rd32(E1000_RDT(i));
612 for (i = 0; i < 4; i++)
613 regs_buff[149 + i] = rd32(E1000_RXDCTL(i));
614
615 for (i = 0; i < 10; i++)
616 regs_buff[153 + i] = rd32(E1000_EITR(i));
617 for (i = 0; i < 8; i++)
618 regs_buff[163 + i] = rd32(E1000_IMIR(i));
619 for (i = 0; i < 8; i++)
620 regs_buff[171 + i] = rd32(E1000_IMIREXT(i));
621 for (i = 0; i < 16; i++)
622 regs_buff[179 + i] = rd32(E1000_RAL(i));
623 for (i = 0; i < 16; i++)
624 regs_buff[195 + i] = rd32(E1000_RAH(i));
625
626 for (i = 0; i < 4; i++)
627 regs_buff[211 + i] = rd32(E1000_TDBAL(i));
628 for (i = 0; i < 4; i++)
629 regs_buff[215 + i] = rd32(E1000_TDBAH(i));
630 for (i = 0; i < 4; i++)
631 regs_buff[219 + i] = rd32(E1000_TDLEN(i));
632 for (i = 0; i < 4; i++)
633 regs_buff[223 + i] = rd32(E1000_TDH(i));
634 for (i = 0; i < 4; i++)
635 regs_buff[227 + i] = rd32(E1000_TDT(i));
636 for (i = 0; i < 4; i++)
637 regs_buff[231 + i] = rd32(E1000_TXDCTL(i));
638 for (i = 0; i < 4; i++)
639 regs_buff[235 + i] = rd32(E1000_TDWBAL(i));
640 for (i = 0; i < 4; i++)
641 regs_buff[239 + i] = rd32(E1000_TDWBAH(i));
642 for (i = 0; i < 4; i++)
643 regs_buff[243 + i] = rd32(E1000_DCA_TXCTRL(i));
644
645 for (i = 0; i < 4; i++)
646 regs_buff[247 + i] = rd32(E1000_IP4AT_REG(i));
647 for (i = 0; i < 4; i++)
648 regs_buff[251 + i] = rd32(E1000_IP6AT_REG(i));
649 for (i = 0; i < 32; i++)
650 regs_buff[255 + i] = rd32(E1000_WUPM_REG(i));
651 for (i = 0; i < 128; i++)
652 regs_buff[287 + i] = rd32(E1000_FFMT_REG(i));
653 for (i = 0; i < 128; i++)
654 regs_buff[415 + i] = rd32(E1000_FFVT_REG(i));
655 for (i = 0; i < 4; i++)
656 regs_buff[543 + i] = rd32(E1000_FFLT_REG(i));
657
658 regs_buff[547] = rd32(E1000_TDFH);
659 regs_buff[548] = rd32(E1000_TDFT);
660 regs_buff[549] = rd32(E1000_TDFHS);
661 regs_buff[550] = rd32(E1000_TDFPC);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000662
663 if (hw->mac.type > e1000_82580) {
664 regs_buff[551] = adapter->stats.o2bgptc;
665 regs_buff[552] = adapter->stats.b2ospc;
666 regs_buff[553] = adapter->stats.o2bspc;
667 regs_buff[554] = adapter->stats.b2ogprc;
668 }
Koki Sanagi7e3b4ff2012-02-15 14:45:39 +0000669
670 if (hw->mac.type != e1000_82576)
671 return;
672 for (i = 0; i < 12; i++)
673 regs_buff[555 + i] = rd32(E1000_SRRCTL(i + 4));
674 for (i = 0; i < 4; i++)
675 regs_buff[567 + i] = rd32(E1000_PSRTYPE(i + 4));
676 for (i = 0; i < 12; i++)
677 regs_buff[571 + i] = rd32(E1000_RDBAL(i + 4));
678 for (i = 0; i < 12; i++)
679 regs_buff[583 + i] = rd32(E1000_RDBAH(i + 4));
680 for (i = 0; i < 12; i++)
681 regs_buff[595 + i] = rd32(E1000_RDLEN(i + 4));
682 for (i = 0; i < 12; i++)
683 regs_buff[607 + i] = rd32(E1000_RDH(i + 4));
684 for (i = 0; i < 12; i++)
685 regs_buff[619 + i] = rd32(E1000_RDT(i + 4));
686 for (i = 0; i < 12; i++)
687 regs_buff[631 + i] = rd32(E1000_RXDCTL(i + 4));
688
689 for (i = 0; i < 12; i++)
690 regs_buff[643 + i] = rd32(E1000_TDBAL(i + 4));
691 for (i = 0; i < 12; i++)
692 regs_buff[655 + i] = rd32(E1000_TDBAH(i + 4));
693 for (i = 0; i < 12; i++)
694 regs_buff[667 + i] = rd32(E1000_TDLEN(i + 4));
695 for (i = 0; i < 12; i++)
696 regs_buff[679 + i] = rd32(E1000_TDH(i + 4));
697 for (i = 0; i < 12; i++)
698 regs_buff[691 + i] = rd32(E1000_TDT(i + 4));
699 for (i = 0; i < 12; i++)
700 regs_buff[703 + i] = rd32(E1000_TXDCTL(i + 4));
701 for (i = 0; i < 12; i++)
702 regs_buff[715 + i] = rd32(E1000_TDWBAL(i + 4));
703 for (i = 0; i < 12; i++)
704 regs_buff[727 + i] = rd32(E1000_TDWBAH(i + 4));
Auke Kok9d5c8242008-01-24 02:22:38 -0800705}
706
707static int igb_get_eeprom_len(struct net_device *netdev)
708{
709 struct igb_adapter *adapter = netdev_priv(netdev);
710 return adapter->hw.nvm.word_size * 2;
711}
712
713static int igb_get_eeprom(struct net_device *netdev,
714 struct ethtool_eeprom *eeprom, u8 *bytes)
715{
716 struct igb_adapter *adapter = netdev_priv(netdev);
717 struct e1000_hw *hw = &adapter->hw;
718 u16 *eeprom_buff;
719 int first_word, last_word;
720 int ret_val = 0;
721 u16 i;
722
723 if (eeprom->len == 0)
724 return -EINVAL;
725
726 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
727
728 first_word = eeprom->offset >> 1;
729 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
730
731 eeprom_buff = kmalloc(sizeof(u16) *
732 (last_word - first_word + 1), GFP_KERNEL);
733 if (!eeprom_buff)
734 return -ENOMEM;
735
736 if (hw->nvm.type == e1000_nvm_eeprom_spi)
Alexander Duyck312c75a2009-02-06 23:17:47 +0000737 ret_val = hw->nvm.ops.read(hw, first_word,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000738 last_word - first_word + 1,
739 eeprom_buff);
Auke Kok9d5c8242008-01-24 02:22:38 -0800740 else {
741 for (i = 0; i < last_word - first_word + 1; i++) {
Alexander Duyck312c75a2009-02-06 23:17:47 +0000742 ret_val = hw->nvm.ops.read(hw, first_word + i, 1,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000743 &eeprom_buff[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800744 if (ret_val)
745 break;
746 }
747 }
748
749 /* Device's eeprom is always little-endian, word addressable */
750 for (i = 0; i < last_word - first_word + 1; i++)
751 le16_to_cpus(&eeprom_buff[i]);
752
753 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
754 eeprom->len);
755 kfree(eeprom_buff);
756
757 return ret_val;
758}
759
760static int igb_set_eeprom(struct net_device *netdev,
761 struct ethtool_eeprom *eeprom, u8 *bytes)
762{
763 struct igb_adapter *adapter = netdev_priv(netdev);
764 struct e1000_hw *hw = &adapter->hw;
765 u16 *eeprom_buff;
766 void *ptr;
767 int max_len, first_word, last_word, ret_val = 0;
768 u16 i;
769
770 if (eeprom->len == 0)
771 return -EOPNOTSUPP;
772
Fujinaka, Todda71fc312013-10-23 05:52:11 +0000773 if ((hw->mac.type >= e1000_i210) &&
774 !igb_get_flash_presence_i210(hw)) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000775 return -EOPNOTSUPP;
Fujinaka, Todda71fc312013-10-23 05:52:11 +0000776 }
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000777
Auke Kok9d5c8242008-01-24 02:22:38 -0800778 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
779 return -EFAULT;
780
781 max_len = hw->nvm.word_size * 2;
782
783 first_word = eeprom->offset >> 1;
784 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
785 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
786 if (!eeprom_buff)
787 return -ENOMEM;
788
789 ptr = (void *)eeprom_buff;
790
791 if (eeprom->offset & 1) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000792 /* need read/modify/write of first changed EEPROM word
793 * only the second byte of the word is being modified
794 */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000795 ret_val = hw->nvm.ops.read(hw, first_word, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800796 &eeprom_buff[0]);
797 ptr++;
798 }
799 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000800 /* need read/modify/write of last changed EEPROM word
801 * only the first byte of the word is being modified
802 */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000803 ret_val = hw->nvm.ops.read(hw, last_word, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800804 &eeprom_buff[last_word - first_word]);
805 }
806
807 /* Device's eeprom is always little-endian, word addressable */
808 for (i = 0; i < last_word - first_word + 1; i++)
809 le16_to_cpus(&eeprom_buff[i]);
810
811 memcpy(ptr, bytes, eeprom->len);
812
813 for (i = 0; i < last_word - first_word + 1; i++)
814 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
815
Alexander Duyck312c75a2009-02-06 23:17:47 +0000816 ret_val = hw->nvm.ops.write(hw, first_word,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000817 last_word - first_word + 1, eeprom_buff);
Auke Kok9d5c8242008-01-24 02:22:38 -0800818
Carolyn Wyborny2a0a0f12013-04-25 17:22:34 +0000819 /* Update the checksum if nvm write succeeded */
820 if (ret_val == 0)
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800821 hw->nvm.ops.update(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800822
Carolyn Wybornyd67974f2012-06-14 16:04:19 +0000823 igb_set_fw_version(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800824 kfree(eeprom_buff);
825 return ret_val;
826}
827
828static void igb_get_drvinfo(struct net_device *netdev,
829 struct ethtool_drvinfo *drvinfo)
830{
831 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -0800832
Rick Jones612a94d2011-11-14 08:13:25 +0000833 strlcpy(drvinfo->driver, igb_driver_name, sizeof(drvinfo->driver));
834 strlcpy(drvinfo->version, igb_driver_version, sizeof(drvinfo->version));
Auke Kok9d5c8242008-01-24 02:22:38 -0800835
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000836 /* EEPROM image version # is reported as firmware version # for
Carolyn Wybornyd67974f2012-06-14 16:04:19 +0000837 * 82575 controllers
838 */
839 strlcpy(drvinfo->fw_version, adapter->fw_version,
840 sizeof(drvinfo->fw_version));
Rick Jones612a94d2011-11-14 08:13:25 +0000841 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
842 sizeof(drvinfo->bus_info));
Auke Kok9d5c8242008-01-24 02:22:38 -0800843 drvinfo->n_stats = IGB_STATS_LEN;
844 drvinfo->testinfo_len = IGB_TEST_LEN;
845 drvinfo->regdump_len = igb_get_regs_len(netdev);
846 drvinfo->eedump_len = igb_get_eeprom_len(netdev);
847}
848
849static void igb_get_ringparam(struct net_device *netdev,
850 struct ethtool_ringparam *ring)
851{
852 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -0800853
854 ring->rx_max_pending = IGB_MAX_RXD;
855 ring->tx_max_pending = IGB_MAX_TXD;
Alexander Duyck68fd9912008-11-20 00:48:10 -0800856 ring->rx_pending = adapter->rx_ring_count;
857 ring->tx_pending = adapter->tx_ring_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800858}
859
860static int igb_set_ringparam(struct net_device *netdev,
861 struct ethtool_ringparam *ring)
862{
863 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800864 struct igb_ring *temp_ring;
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000865 int i, err = 0;
Alexander Duyck0e15439a2009-11-12 18:36:41 +0000866 u16 new_rx_count, new_tx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800867
868 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
869 return -EINVAL;
870
Alexander Duyck0e15439a2009-11-12 18:36:41 +0000871 new_rx_count = min_t(u32, ring->rx_pending, IGB_MAX_RXD);
872 new_rx_count = max_t(u16, new_rx_count, IGB_MIN_RXD);
Auke Kok9d5c8242008-01-24 02:22:38 -0800873 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
874
Alexander Duyck0e15439a2009-11-12 18:36:41 +0000875 new_tx_count = min_t(u32, ring->tx_pending, IGB_MAX_TXD);
876 new_tx_count = max_t(u16, new_tx_count, IGB_MIN_TXD);
Auke Kok9d5c8242008-01-24 02:22:38 -0800877 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
878
Alexander Duyck68fd9912008-11-20 00:48:10 -0800879 if ((new_tx_count == adapter->tx_ring_count) &&
880 (new_rx_count == adapter->rx_ring_count)) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800881 /* nothing to do */
882 return 0;
883 }
884
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000885 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
886 msleep(1);
887
888 if (!netif_running(adapter->netdev)) {
889 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +0000890 adapter->tx_ring[i]->count = new_tx_count;
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000891 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +0000892 adapter->rx_ring[i]->count = new_rx_count;
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000893 adapter->tx_ring_count = new_tx_count;
894 adapter->rx_ring_count = new_rx_count;
895 goto clear_reset;
896 }
897
Alexander Duyck68fd9912008-11-20 00:48:10 -0800898 if (adapter->num_tx_queues > adapter->num_rx_queues)
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000899 temp_ring = vmalloc(adapter->num_tx_queues *
900 sizeof(struct igb_ring));
Alexander Duyck68fd9912008-11-20 00:48:10 -0800901 else
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000902 temp_ring = vmalloc(adapter->num_rx_queues *
903 sizeof(struct igb_ring));
Alexander Duyck68fd9912008-11-20 00:48:10 -0800904
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000905 if (!temp_ring) {
906 err = -ENOMEM;
907 goto clear_reset;
908 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800909
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000910 igb_down(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800911
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000912 /* We can't just free everything and then setup again,
Auke Kok9d5c8242008-01-24 02:22:38 -0800913 * because the ISRs in MSI-X mode get passed pointers
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000914 * to the Tx and Rx ring structs.
Auke Kok9d5c8242008-01-24 02:22:38 -0800915 */
Alexander Duyck68fd9912008-11-20 00:48:10 -0800916 if (new_tx_count != adapter->tx_ring_count) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800917 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +0000918 memcpy(&temp_ring[i], adapter->tx_ring[i],
919 sizeof(struct igb_ring));
920
Alexander Duyck68fd9912008-11-20 00:48:10 -0800921 temp_ring[i].count = new_tx_count;
Alexander Duyck80785292009-10-27 15:51:47 +0000922 err = igb_setup_tx_resources(&temp_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800923 if (err) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800924 while (i) {
925 i--;
926 igb_free_tx_resources(&temp_ring[i]);
927 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800928 goto err_setup;
929 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800930 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800931
Alexander Duyck3025a442010-02-17 01:02:39 +0000932 for (i = 0; i < adapter->num_tx_queues; i++) {
933 igb_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800934
Alexander Duyck3025a442010-02-17 01:02:39 +0000935 memcpy(adapter->tx_ring[i], &temp_ring[i],
936 sizeof(struct igb_ring));
937 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800938
939 adapter->tx_ring_count = new_tx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800940 }
941
Alexander Duyck3025a442010-02-17 01:02:39 +0000942 if (new_rx_count != adapter->rx_ring_count) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800943 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +0000944 memcpy(&temp_ring[i], adapter->rx_ring[i],
945 sizeof(struct igb_ring));
946
Alexander Duyck68fd9912008-11-20 00:48:10 -0800947 temp_ring[i].count = new_rx_count;
Alexander Duyck80785292009-10-27 15:51:47 +0000948 err = igb_setup_rx_resources(&temp_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800949 if (err) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800950 while (i) {
951 i--;
952 igb_free_rx_resources(&temp_ring[i]);
953 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800954 goto err_setup;
955 }
956
Auke Kok9d5c8242008-01-24 02:22:38 -0800957 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800958
Alexander Duyck3025a442010-02-17 01:02:39 +0000959 for (i = 0; i < adapter->num_rx_queues; i++) {
960 igb_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800961
Alexander Duyck3025a442010-02-17 01:02:39 +0000962 memcpy(adapter->rx_ring[i], &temp_ring[i],
963 sizeof(struct igb_ring));
964 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800965
966 adapter->rx_ring_count = new_rx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800967 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800968err_setup:
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000969 igb_up(adapter);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800970 vfree(temp_ring);
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000971clear_reset:
972 clear_bit(__IGB_RESETTING, &adapter->state);
Auke Kok9d5c8242008-01-24 02:22:38 -0800973 return err;
974}
975
976/* ethtool register test data */
977struct igb_reg_test {
978 u16 reg;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700979 u16 reg_offset;
980 u16 array_len;
981 u16 test_type;
Auke Kok9d5c8242008-01-24 02:22:38 -0800982 u32 mask;
983 u32 write;
984};
985
986/* In the hardware, registers are laid out either singly, in arrays
987 * spaced 0x100 bytes apart, or in contiguous tables. We assume
988 * most tests take place on arrays or single registers (handled
989 * as a single-element array) and special-case the tables.
990 * Table tests are always pattern tests.
991 *
992 * We also make provision for some required setup steps by specifying
993 * registers to be written without any read-back testing.
994 */
995
996#define PATTERN_TEST 1
997#define SET_READ_TEST 2
998#define WRITE_NO_TEST 3
999#define TABLE32_TEST 4
1000#define TABLE64_TEST_LO 5
1001#define TABLE64_TEST_HI 6
1002
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001003/* i210 reg test */
1004static struct igb_reg_test reg_test_i210[] = {
1005 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1006 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1007 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1008 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1009 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1010 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1011 /* RDH is read-only for i210, only test RDT. */
1012 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1013 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1014 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1015 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1016 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1017 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1018 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1019 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1020 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1021 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
1022 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
1023 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1024 { E1000_RA, 0, 16, TABLE64_TEST_LO,
1025 0xFFFFFFFF, 0xFFFFFFFF },
1026 { E1000_RA, 0, 16, TABLE64_TEST_HI,
1027 0x900FFFFF, 0xFFFFFFFF },
1028 { E1000_MTA, 0, 128, TABLE32_TEST,
1029 0xFFFFFFFF, 0xFFFFFFFF },
1030 { 0, 0, 0, 0, 0 }
1031};
1032
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001033/* i350 reg test */
1034static struct igb_reg_test reg_test_i350[] = {
1035 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1036 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1037 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1038 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFF0000, 0xFFFF0000 },
1039 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1040 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck1b6e6612010-04-09 09:53:08 +00001041 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001042 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1043 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck1b6e6612010-04-09 09:53:08 +00001044 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001045 /* RDH is read-only for i350, only test RDT. */
1046 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1047 { E1000_RDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1048 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1049 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1050 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1051 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1052 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck1b6e6612010-04-09 09:53:08 +00001053 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001054 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1055 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck1b6e6612010-04-09 09:53:08 +00001056 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001057 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1058 { E1000_TDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1059 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001060 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
1061 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001062 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1063 { E1000_RA, 0, 16, TABLE64_TEST_LO,
1064 0xFFFFFFFF, 0xFFFFFFFF },
1065 { E1000_RA, 0, 16, TABLE64_TEST_HI,
1066 0xC3FFFFFF, 0xFFFFFFFF },
1067 { E1000_RA2, 0, 16, TABLE64_TEST_LO,
1068 0xFFFFFFFF, 0xFFFFFFFF },
1069 { E1000_RA2, 0, 16, TABLE64_TEST_HI,
1070 0xC3FFFFFF, 0xFFFFFFFF },
1071 { E1000_MTA, 0, 128, TABLE32_TEST,
1072 0xFFFFFFFF, 0xFFFFFFFF },
1073 { 0, 0, 0, 0 }
1074};
1075
Alexander Duyck55cac242009-11-19 12:42:21 +00001076/* 82580 reg test */
1077static struct igb_reg_test reg_test_82580[] = {
1078 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1079 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1080 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1081 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1082 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1083 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1084 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1085 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1086 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1087 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1088 /* RDH is read-only for 82580, only test RDT. */
1089 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1090 { E1000_RDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1091 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1092 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1093 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1094 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1095 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1096 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1097 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1098 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1099 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1100 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1101 { E1000_TDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1102 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001103 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
1104 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
Alexander Duyck55cac242009-11-19 12:42:21 +00001105 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1106 { E1000_RA, 0, 16, TABLE64_TEST_LO,
1107 0xFFFFFFFF, 0xFFFFFFFF },
1108 { E1000_RA, 0, 16, TABLE64_TEST_HI,
1109 0x83FFFFFF, 0xFFFFFFFF },
1110 { E1000_RA2, 0, 8, TABLE64_TEST_LO,
1111 0xFFFFFFFF, 0xFFFFFFFF },
1112 { E1000_RA2, 0, 8, TABLE64_TEST_HI,
1113 0x83FFFFFF, 0xFFFFFFFF },
1114 { E1000_MTA, 0, 128, TABLE32_TEST,
1115 0xFFFFFFFF, 0xFFFFFFFF },
1116 { 0, 0, 0, 0 }
1117};
1118
Alexander Duyck2d064c02008-07-08 15:10:12 -07001119/* 82576 reg test */
1120static struct igb_reg_test reg_test_82576[] = {
1121 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1122 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1123 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1124 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1125 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1126 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1127 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001128 { E1000_RDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1129 { E1000_RDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1130 { E1000_RDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1131 /* Enable all RX queues before testing. */
1132 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE },
1133 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE },
Alexander Duyck2d064c02008-07-08 15:10:12 -07001134 /* RDH is read-only for 82576, only test RDT. */
1135 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001136 { E1000_RDT(4), 0x40, 12, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
Alexander Duyck2d064c02008-07-08 15:10:12 -07001137 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001138 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0, 0 },
Alexander Duyck2d064c02008-07-08 15:10:12 -07001139 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1140 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1141 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1142 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1143 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1144 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001145 { E1000_TDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1146 { E1000_TDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1147 { E1000_TDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2d064c02008-07-08 15:10:12 -07001148 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001149 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
1150 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
Alexander Duyck2d064c02008-07-08 15:10:12 -07001151 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1152 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
1153 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF },
1154 { E1000_RA2, 0, 8, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
1155 { E1000_RA2, 0, 8, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF },
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001156 { E1000_MTA, 0, 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck2d064c02008-07-08 15:10:12 -07001157 { 0, 0, 0, 0 }
1158};
1159
1160/* 82575 register test */
1161static struct igb_reg_test reg_test_82575[] = {
1162 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1163 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1164 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1165 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1166 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1167 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1168 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1169 /* Enable all four RX queues before testing. */
1170 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE },
Auke Kok9d5c8242008-01-24 02:22:38 -08001171 /* RDH is read-only for 82575, only test RDT. */
Alexander Duyck2d064c02008-07-08 15:10:12 -07001172 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1173 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
1174 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1175 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1176 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1177 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1178 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1179 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1180 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1181 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0x003FFFFB },
1182 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0xFFFFFFFF },
1183 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1184 { E1000_TXCW, 0x100, 1, PATTERN_TEST, 0xC000FFFF, 0x0000FFFF },
1185 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
1186 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x800FFFFF, 0xFFFFFFFF },
1187 { E1000_MTA, 0, 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Auke Kok9d5c8242008-01-24 02:22:38 -08001188 { 0, 0, 0, 0 }
1189};
1190
1191static bool reg_pattern_test(struct igb_adapter *adapter, u64 *data,
1192 int reg, u32 mask, u32 write)
1193{
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001194 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001195 u32 pat, val;
Carolyn Wybornyd34a15a2014-04-11 01:45:23 +00001196 static const u32 _test[] = {
1197 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Auke Kok9d5c8242008-01-24 02:22:38 -08001198 for (pat = 0; pat < ARRAY_SIZE(_test); pat++) {
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001199 wr32(reg, (_test[pat] & write));
Carolyn Wyborny93ed8352011-02-24 03:12:15 +00001200 val = rd32(reg) & mask;
Auke Kok9d5c8242008-01-24 02:22:38 -08001201 if (val != (_test[pat] & write & mask)) {
Jesper Juhld836200a2012-08-01 05:41:30 +00001202 dev_err(&adapter->pdev->dev,
1203 "pattern test reg %04X failed: got 0x%08X expected 0x%08X\n",
Auke Kok9d5c8242008-01-24 02:22:38 -08001204 reg, val, (_test[pat] & write & mask));
1205 *data = reg;
1206 return 1;
1207 }
1208 }
Alexander Duyck317f66b2009-10-27 23:46:20 +00001209
Auke Kok9d5c8242008-01-24 02:22:38 -08001210 return 0;
1211}
1212
1213static bool reg_set_and_check(struct igb_adapter *adapter, u64 *data,
1214 int reg, u32 mask, u32 write)
1215{
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001216 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001217 u32 val;
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001218
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001219 wr32(reg, write & mask);
1220 val = rd32(reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001221 if ((write & mask) != (val & mask)) {
Jesper Juhld836200a2012-08-01 05:41:30 +00001222 dev_err(&adapter->pdev->dev,
1223 "set/check reg %04X test failed: got 0x%08X expected 0x%08X\n", reg,
Auke Kok9d5c8242008-01-24 02:22:38 -08001224 (val & mask), (write & mask));
1225 *data = reg;
1226 return 1;
1227 }
Alexander Duyck317f66b2009-10-27 23:46:20 +00001228
Auke Kok9d5c8242008-01-24 02:22:38 -08001229 return 0;
1230}
1231
1232#define REG_PATTERN_TEST(reg, mask, write) \
1233 do { \
1234 if (reg_pattern_test(adapter, data, reg, mask, write)) \
1235 return 1; \
1236 } while (0)
1237
1238#define REG_SET_AND_CHECK(reg, mask, write) \
1239 do { \
1240 if (reg_set_and_check(adapter, data, reg, mask, write)) \
1241 return 1; \
1242 } while (0)
1243
1244static int igb_reg_test(struct igb_adapter *adapter, u64 *data)
1245{
1246 struct e1000_hw *hw = &adapter->hw;
1247 struct igb_reg_test *test;
1248 u32 value, before, after;
1249 u32 i, toggle;
1250
Alexander Duyck2d064c02008-07-08 15:10:12 -07001251 switch (adapter->hw.mac.type) {
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001252 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001253 case e1000_i354:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001254 test = reg_test_i350;
1255 toggle = 0x7FEFF3FF;
1256 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001257 case e1000_i210:
1258 case e1000_i211:
1259 test = reg_test_i210;
1260 toggle = 0x7FEFF3FF;
1261 break;
Alexander Duyck55cac242009-11-19 12:42:21 +00001262 case e1000_82580:
1263 test = reg_test_82580;
1264 toggle = 0x7FEFF3FF;
1265 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001266 case e1000_82576:
1267 test = reg_test_82576;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001268 toggle = 0x7FFFF3FF;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001269 break;
1270 default:
1271 test = reg_test_82575;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001272 toggle = 0x7FFFF3FF;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001273 break;
1274 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001275
1276 /* Because the status register is such a special case,
1277 * we handle it separately from the rest of the register
1278 * tests. Some bits are read-only, some toggle, and some
1279 * are writable on newer MACs.
1280 */
1281 before = rd32(E1000_STATUS);
1282 value = (rd32(E1000_STATUS) & toggle);
1283 wr32(E1000_STATUS, toggle);
1284 after = rd32(E1000_STATUS) & toggle;
1285 if (value != after) {
Jesper Juhld836200a2012-08-01 05:41:30 +00001286 dev_err(&adapter->pdev->dev,
1287 "failed STATUS register test got: 0x%08X expected: 0x%08X\n",
1288 after, value);
Auke Kok9d5c8242008-01-24 02:22:38 -08001289 *data = 1;
1290 return 1;
1291 }
1292 /* restore previous status */
1293 wr32(E1000_STATUS, before);
1294
1295 /* Perform the remainder of the register test, looping through
1296 * the test table until we either fail or reach the null entry.
1297 */
1298 while (test->reg) {
1299 for (i = 0; i < test->array_len; i++) {
1300 switch (test->test_type) {
1301 case PATTERN_TEST:
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001302 REG_PATTERN_TEST(test->reg +
1303 (i * test->reg_offset),
Auke Kok9d5c8242008-01-24 02:22:38 -08001304 test->mask,
1305 test->write);
1306 break;
1307 case SET_READ_TEST:
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001308 REG_SET_AND_CHECK(test->reg +
1309 (i * test->reg_offset),
Auke Kok9d5c8242008-01-24 02:22:38 -08001310 test->mask,
1311 test->write);
1312 break;
1313 case WRITE_NO_TEST:
1314 writel(test->write,
1315 (adapter->hw.hw_addr + test->reg)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001316 + (i * test->reg_offset));
Auke Kok9d5c8242008-01-24 02:22:38 -08001317 break;
1318 case TABLE32_TEST:
1319 REG_PATTERN_TEST(test->reg + (i * 4),
1320 test->mask,
1321 test->write);
1322 break;
1323 case TABLE64_TEST_LO:
1324 REG_PATTERN_TEST(test->reg + (i * 8),
1325 test->mask,
1326 test->write);
1327 break;
1328 case TABLE64_TEST_HI:
1329 REG_PATTERN_TEST((test->reg + 4) + (i * 8),
1330 test->mask,
1331 test->write);
1332 break;
1333 }
1334 }
1335 test++;
1336 }
1337
1338 *data = 0;
1339 return 0;
1340}
1341
1342static int igb_eeprom_test(struct igb_adapter *adapter, u64 *data)
1343{
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +00001344 struct e1000_hw *hw = &adapter->hw;
1345
Auke Kok9d5c8242008-01-24 02:22:38 -08001346 *data = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001347
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +00001348 /* Validate eeprom on all parts but flashless */
1349 switch (hw->mac.type) {
1350 case e1000_i210:
1351 case e1000_i211:
1352 if (igb_get_flash_presence_i210(hw)) {
1353 if (adapter->hw.nvm.ops.validate(&adapter->hw) < 0)
1354 *data = 2;
1355 }
1356 break;
1357 default:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001358 if (adapter->hw.nvm.ops.validate(&adapter->hw) < 0)
1359 *data = 2;
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +00001360 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001361 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001362
1363 return *data;
1364}
1365
1366static irqreturn_t igb_test_intr(int irq, void *data)
1367{
Alexander Duyck317f66b2009-10-27 23:46:20 +00001368 struct igb_adapter *adapter = (struct igb_adapter *) data;
Auke Kok9d5c8242008-01-24 02:22:38 -08001369 struct e1000_hw *hw = &adapter->hw;
1370
1371 adapter->test_icr |= rd32(E1000_ICR);
1372
1373 return IRQ_HANDLED;
1374}
1375
1376static int igb_intr_test(struct igb_adapter *adapter, u64 *data)
1377{
1378 struct e1000_hw *hw = &adapter->hw;
1379 struct net_device *netdev = adapter->netdev;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001380 u32 mask, ics_mask, i = 0, shared_int = true;
Auke Kok9d5c8242008-01-24 02:22:38 -08001381 u32 irq = adapter->pdev->irq;
1382
1383 *data = 0;
1384
1385 /* Hook up test interrupt handler just for this test */
Carolyn Wybornycd14ef52013-12-10 07:58:34 +00001386 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001387 if (request_irq(adapter->msix_entries[0].vector,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001388 igb_test_intr, 0, netdev->name, adapter)) {
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001389 *data = 1;
1390 return -1;
1391 }
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001392 } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001393 shared_int = false;
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001394 if (request_irq(irq,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001395 igb_test_intr, 0, netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001396 *data = 1;
1397 return -1;
1398 }
Joe Perchesa0607fd2009-11-18 23:29:17 -08001399 } else if (!request_irq(irq, igb_test_intr, IRQF_PROBE_SHARED,
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001400 netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001401 shared_int = false;
Joe Perchesa0607fd2009-11-18 23:29:17 -08001402 } else if (request_irq(irq, igb_test_intr, IRQF_SHARED,
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001403 netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001404 *data = 1;
1405 return -1;
1406 }
1407 dev_info(&adapter->pdev->dev, "testing %s interrupt\n",
1408 (shared_int ? "shared" : "unshared"));
Alexander Duyck317f66b2009-10-27 23:46:20 +00001409
Auke Kok9d5c8242008-01-24 02:22:38 -08001410 /* Disable all the interrupts */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001411 wr32(E1000_IMC, ~0);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001412 wrfl();
Auke Kok9d5c8242008-01-24 02:22:38 -08001413 msleep(10);
1414
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001415 /* Define all writable bits for ICS */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001416 switch (hw->mac.type) {
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001417 case e1000_82575:
1418 ics_mask = 0x37F47EDD;
1419 break;
1420 case e1000_82576:
1421 ics_mask = 0x77D4FBFD;
1422 break;
Alexander Duyck55cac242009-11-19 12:42:21 +00001423 case e1000_82580:
1424 ics_mask = 0x77DCFED5;
1425 break;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001426 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001427 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001428 case e1000_i210:
1429 case e1000_i211:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001430 ics_mask = 0x77DCFED5;
1431 break;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001432 default:
1433 ics_mask = 0x7FFFFFFF;
1434 break;
1435 }
1436
Auke Kok9d5c8242008-01-24 02:22:38 -08001437 /* Test each interrupt */
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001438 for (; i < 31; i++) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001439 /* Interrupt to test */
1440 mask = 1 << i;
1441
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001442 if (!(mask & ics_mask))
1443 continue;
1444
Auke Kok9d5c8242008-01-24 02:22:38 -08001445 if (!shared_int) {
1446 /* Disable the interrupt to be reported in
1447 * the cause register and then force the same
1448 * interrupt and see if one gets posted. If
1449 * an interrupt was posted to the bus, the
1450 * test failed.
1451 */
1452 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001453
1454 /* Flush any pending interrupts */
1455 wr32(E1000_ICR, ~0);
1456
1457 wr32(E1000_IMC, mask);
1458 wr32(E1000_ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001459 wrfl();
Auke Kok9d5c8242008-01-24 02:22:38 -08001460 msleep(10);
1461
1462 if (adapter->test_icr & mask) {
1463 *data = 3;
1464 break;
1465 }
1466 }
1467
1468 /* Enable the interrupt to be reported in
1469 * the cause register and then force the same
1470 * interrupt and see if one gets posted. If
1471 * an interrupt was not posted to the bus, the
1472 * test failed.
1473 */
1474 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001475
1476 /* Flush any pending interrupts */
1477 wr32(E1000_ICR, ~0);
1478
Auke Kok9d5c8242008-01-24 02:22:38 -08001479 wr32(E1000_IMS, mask);
1480 wr32(E1000_ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001481 wrfl();
Auke Kok9d5c8242008-01-24 02:22:38 -08001482 msleep(10);
1483
1484 if (!(adapter->test_icr & mask)) {
1485 *data = 4;
1486 break;
1487 }
1488
1489 if (!shared_int) {
1490 /* Disable the other interrupts to be reported in
1491 * the cause register and then force the other
1492 * interrupts and see if any get posted. If
1493 * an interrupt was posted to the bus, the
1494 * test failed.
1495 */
1496 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001497
1498 /* Flush any pending interrupts */
1499 wr32(E1000_ICR, ~0);
1500
1501 wr32(E1000_IMC, ~mask);
1502 wr32(E1000_ICS, ~mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001503 wrfl();
Auke Kok9d5c8242008-01-24 02:22:38 -08001504 msleep(10);
1505
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001506 if (adapter->test_icr & mask) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001507 *data = 5;
1508 break;
1509 }
1510 }
1511 }
1512
1513 /* Disable all the interrupts */
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001514 wr32(E1000_IMC, ~0);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001515 wrfl();
Auke Kok9d5c8242008-01-24 02:22:38 -08001516 msleep(10);
1517
1518 /* Unhook test interrupt handler */
Carolyn Wybornycd14ef52013-12-10 07:58:34 +00001519 if (adapter->flags & IGB_FLAG_HAS_MSIX)
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001520 free_irq(adapter->msix_entries[0].vector, adapter);
1521 else
1522 free_irq(irq, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001523
1524 return *data;
1525}
1526
1527static void igb_free_desc_rings(struct igb_adapter *adapter)
1528{
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001529 igb_free_tx_resources(&adapter->test_tx_ring);
1530 igb_free_rx_resources(&adapter->test_rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001531}
1532
1533static int igb_setup_desc_rings(struct igb_adapter *adapter)
1534{
Auke Kok9d5c8242008-01-24 02:22:38 -08001535 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1536 struct igb_ring *rx_ring = &adapter->test_rx_ring;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001537 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckad93d172009-10-27 15:55:02 +00001538 int ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001539
1540 /* Setup Tx descriptor ring and Tx buffers */
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001541 tx_ring->count = IGB_DEFAULT_TXD;
Alexander Duyck59d71982010-04-27 13:09:25 +00001542 tx_ring->dev = &adapter->pdev->dev;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001543 tx_ring->netdev = adapter->netdev;
1544 tx_ring->reg_idx = adapter->vfs_allocated_count;
Auke Kok9d5c8242008-01-24 02:22:38 -08001545
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001546 if (igb_setup_tx_resources(tx_ring)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001547 ret_val = 1;
1548 goto err_nomem;
1549 }
1550
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001551 igb_setup_tctl(adapter);
1552 igb_configure_tx_ring(adapter, tx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001553
Auke Kok9d5c8242008-01-24 02:22:38 -08001554 /* Setup Rx descriptor ring and Rx buffers */
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001555 rx_ring->count = IGB_DEFAULT_RXD;
Alexander Duyck59d71982010-04-27 13:09:25 +00001556 rx_ring->dev = &adapter->pdev->dev;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001557 rx_ring->netdev = adapter->netdev;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001558 rx_ring->reg_idx = adapter->vfs_allocated_count;
Auke Kok9d5c8242008-01-24 02:22:38 -08001559
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001560 if (igb_setup_rx_resources(rx_ring)) {
1561 ret_val = 3;
Auke Kok9d5c8242008-01-24 02:22:38 -08001562 goto err_nomem;
1563 }
1564
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001565 /* set the default queue to queue 0 of PF */
1566 wr32(E1000_MRQC, adapter->vfs_allocated_count << 3);
Auke Kok9d5c8242008-01-24 02:22:38 -08001567
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001568 /* enable receive ring */
1569 igb_setup_rctl(adapter);
1570 igb_configure_rx_ring(adapter, rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001571
Alexander Duyckcd392f52011-08-26 07:43:59 +00001572 igb_alloc_rx_buffers(rx_ring, igb_desc_unused(rx_ring));
Auke Kok9d5c8242008-01-24 02:22:38 -08001573
1574 return 0;
1575
1576err_nomem:
1577 igb_free_desc_rings(adapter);
1578 return ret_val;
1579}
1580
1581static void igb_phy_disable_receiver(struct igb_adapter *adapter)
1582{
1583 struct e1000_hw *hw = &adapter->hw;
1584
1585 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001586 igb_write_phy_reg(hw, 29, 0x001F);
1587 igb_write_phy_reg(hw, 30, 0x8FFC);
1588 igb_write_phy_reg(hw, 29, 0x001A);
1589 igb_write_phy_reg(hw, 30, 0x8FF0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001590}
1591
1592static int igb_integrated_phy_loopback(struct igb_adapter *adapter)
1593{
1594 struct e1000_hw *hw = &adapter->hw;
1595 u32 ctrl_reg = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001596
1597 hw->mac.autoneg = false;
1598
Carolyn Wyborny8aa23f02012-06-08 05:01:39 +00001599 if (hw->phy.type == e1000_phy_m88) {
1600 if (hw->phy.id != I210_I_PHY_ID) {
1601 /* Auto-MDI/MDIX Off */
1602 igb_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1603 /* reset to update Auto-MDI/MDIX */
1604 igb_write_phy_reg(hw, PHY_CONTROL, 0x9140);
1605 /* autoneg off */
1606 igb_write_phy_reg(hw, PHY_CONTROL, 0x8140);
1607 } else {
1608 /* force 1000, set loopback */
1609 igb_write_phy_reg(hw, I347AT4_PAGE_SELECT, 0);
1610 igb_write_phy_reg(hw, PHY_CONTROL, 0x4140);
1611 }
Todd Fujinaka5aa3a442013-09-17 05:08:48 +00001612 } else if (hw->phy.type == e1000_phy_82580) {
1613 /* enable MII loopback */
1614 igb_write_phy_reg(hw, I82580_PHY_LBK_CTRL, 0x8041);
Auke Kok9d5c8242008-01-24 02:22:38 -08001615 }
1616
Stefan Assmann119b0e02012-08-07 00:45:57 -07001617 /* add small delay to avoid loopback test failure */
1618 msleep(50);
1619
Auke Kok9d5c8242008-01-24 02:22:38 -08001620 /* force 1000, set loopback */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001621 igb_write_phy_reg(hw, PHY_CONTROL, 0x4140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001622
1623 /* Now set up the MAC to the same speed/duplex as the PHY. */
1624 ctrl_reg = rd32(E1000_CTRL);
1625 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1626 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1627 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1628 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
Alexander Duyckcdfa9f62009-03-31 20:38:56 +00001629 E1000_CTRL_FD | /* Force Duplex to FULL */
1630 E1000_CTRL_SLU); /* Set link up enable bit */
Auke Kok9d5c8242008-01-24 02:22:38 -08001631
Carolyn Wyborny8aa23f02012-06-08 05:01:39 +00001632 if (hw->phy.type == e1000_phy_m88)
Auke Kok9d5c8242008-01-24 02:22:38 -08001633 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kok9d5c8242008-01-24 02:22:38 -08001634
1635 wr32(E1000_CTRL, ctrl_reg);
1636
1637 /* Disable the receiver on the PHY so when a cable is plugged in, the
1638 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1639 */
Carolyn Wyborny8aa23f02012-06-08 05:01:39 +00001640 if (hw->phy.type == e1000_phy_m88)
Auke Kok9d5c8242008-01-24 02:22:38 -08001641 igb_phy_disable_receiver(adapter);
1642
Carolyn Wyborny8aa23f02012-06-08 05:01:39 +00001643 mdelay(500);
Auke Kok9d5c8242008-01-24 02:22:38 -08001644 return 0;
1645}
1646
1647static int igb_set_phy_loopback(struct igb_adapter *adapter)
1648{
1649 return igb_integrated_phy_loopback(adapter);
1650}
1651
1652static int igb_setup_loopback_test(struct igb_adapter *adapter)
1653{
1654 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001655 u32 reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001656
Alexander Duyck317f66b2009-10-27 23:46:20 +00001657 reg = rd32(E1000_CTRL_EXT);
1658
1659 /* use CTRL_EXT to identify link type as SGMII can appear as copper */
1660 if (reg & E1000_CTRL_EXT_LINK_MODE_MASK) {
Robert Healya14bc2b2011-07-12 08:46:20 +00001661 if ((hw->device_id == E1000_DEV_ID_DH89XXCC_SGMII) ||
1662 (hw->device_id == E1000_DEV_ID_DH89XXCC_SERDES) ||
1663 (hw->device_id == E1000_DEV_ID_DH89XXCC_BACKPLANE) ||
Fujinaka, Todda4e979a2013-10-01 04:33:55 -07001664 (hw->device_id == E1000_DEV_ID_DH89XXCC_SFP) ||
1665 (hw->device_id == E1000_DEV_ID_I354_SGMII)) {
Robert Healya14bc2b2011-07-12 08:46:20 +00001666
1667 /* Enable DH89xxCC MPHY for near end loopback */
1668 reg = rd32(E1000_MPHY_ADDR_CTL);
1669 reg = (reg & E1000_MPHY_ADDR_CTL_OFFSET_MASK) |
1670 E1000_MPHY_PCS_CLK_REG_OFFSET;
1671 wr32(E1000_MPHY_ADDR_CTL, reg);
1672
1673 reg = rd32(E1000_MPHY_DATA);
1674 reg |= E1000_MPHY_PCS_CLK_REG_DIGINELBEN;
1675 wr32(E1000_MPHY_DATA, reg);
1676 }
1677
Alexander Duyck2d064c02008-07-08 15:10:12 -07001678 reg = rd32(E1000_RCTL);
1679 reg |= E1000_RCTL_LBM_TCVR;
1680 wr32(E1000_RCTL, reg);
1681
1682 wr32(E1000_SCTL, E1000_ENABLE_SERDES_LOOPBACK);
1683
1684 reg = rd32(E1000_CTRL);
1685 reg &= ~(E1000_CTRL_RFCE |
1686 E1000_CTRL_TFCE |
1687 E1000_CTRL_LRST);
1688 reg |= E1000_CTRL_SLU |
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001689 E1000_CTRL_FD;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001690 wr32(E1000_CTRL, reg);
1691
1692 /* Unset switch control to serdes energy detect */
1693 reg = rd32(E1000_CONNSW);
1694 reg &= ~E1000_CONNSW_ENRGSRC;
1695 wr32(E1000_CONNSW, reg);
1696
Carolyn Wyborny3860a0b2012-11-22 02:49:22 +00001697 /* Unset sigdetect for SERDES loopback on
Akeem G. Abodunrin0ba96d32013-03-20 08:01:40 +00001698 * 82580 and newer devices.
Carolyn Wyborny3860a0b2012-11-22 02:49:22 +00001699 */
Akeem G. Abodunrin0ba96d32013-03-20 08:01:40 +00001700 if (hw->mac.type >= e1000_82580) {
Carolyn Wyborny3860a0b2012-11-22 02:49:22 +00001701 reg = rd32(E1000_PCS_CFG0);
1702 reg |= E1000_PCS_CFG_IGN_SD;
1703 wr32(E1000_PCS_CFG0, reg);
Carolyn Wyborny3860a0b2012-11-22 02:49:22 +00001704 }
1705
Alexander Duyck2d064c02008-07-08 15:10:12 -07001706 /* Set PCS register for forced speed */
1707 reg = rd32(E1000_PCS_LCTL);
1708 reg &= ~E1000_PCS_LCTL_AN_ENABLE; /* Disable Autoneg*/
1709 reg |= E1000_PCS_LCTL_FLV_LINK_UP | /* Force link up */
1710 E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1711 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
1712 E1000_PCS_LCTL_FSD | /* Force Speed */
1713 E1000_PCS_LCTL_FORCE_LINK; /* Force Link */
1714 wr32(E1000_PCS_LCTL, reg);
1715
Auke Kok9d5c8242008-01-24 02:22:38 -08001716 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001717 }
1718
Alexander Duyck317f66b2009-10-27 23:46:20 +00001719 return igb_set_phy_loopback(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001720}
1721
1722static void igb_loopback_cleanup(struct igb_adapter *adapter)
1723{
1724 struct e1000_hw *hw = &adapter->hw;
1725 u32 rctl;
1726 u16 phy_reg;
1727
Robert Healya14bc2b2011-07-12 08:46:20 +00001728 if ((hw->device_id == E1000_DEV_ID_DH89XXCC_SGMII) ||
1729 (hw->device_id == E1000_DEV_ID_DH89XXCC_SERDES) ||
1730 (hw->device_id == E1000_DEV_ID_DH89XXCC_BACKPLANE) ||
Fujinaka, Todda4e979a2013-10-01 04:33:55 -07001731 (hw->device_id == E1000_DEV_ID_DH89XXCC_SFP) ||
1732 (hw->device_id == E1000_DEV_ID_I354_SGMII)) {
Robert Healya14bc2b2011-07-12 08:46:20 +00001733 u32 reg;
1734
1735 /* Disable near end loopback on DH89xxCC */
1736 reg = rd32(E1000_MPHY_ADDR_CTL);
1737 reg = (reg & E1000_MPHY_ADDR_CTL_OFFSET_MASK) |
1738 E1000_MPHY_PCS_CLK_REG_OFFSET;
1739 wr32(E1000_MPHY_ADDR_CTL, reg);
1740
1741 reg = rd32(E1000_MPHY_DATA);
1742 reg &= ~E1000_MPHY_PCS_CLK_REG_DIGINELBEN;
1743 wr32(E1000_MPHY_DATA, reg);
1744 }
1745
Auke Kok9d5c8242008-01-24 02:22:38 -08001746 rctl = rd32(E1000_RCTL);
1747 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1748 wr32(E1000_RCTL, rctl);
1749
1750 hw->mac.autoneg = true;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001751 igb_read_phy_reg(hw, PHY_CONTROL, &phy_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001752 if (phy_reg & MII_CR_LOOPBACK) {
1753 phy_reg &= ~MII_CR_LOOPBACK;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001754 igb_write_phy_reg(hw, PHY_CONTROL, phy_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001755 igb_phy_sw_reset(hw);
1756 }
1757}
1758
1759static void igb_create_lbtest_frame(struct sk_buff *skb,
1760 unsigned int frame_size)
1761{
1762 memset(skb->data, 0xFF, frame_size);
Alexander Duyck317f66b2009-10-27 23:46:20 +00001763 frame_size /= 2;
1764 memset(&skb->data[frame_size], 0xAA, frame_size - 1);
1765 memset(&skb->data[frame_size + 10], 0xBE, 1);
1766 memset(&skb->data[frame_size + 12], 0xAF, 1);
Auke Kok9d5c8242008-01-24 02:22:38 -08001767}
1768
Alexander Duyck1a1c2252012-09-25 00:30:52 +00001769static int igb_check_lbtest_frame(struct igb_rx_buffer *rx_buffer,
1770 unsigned int frame_size)
Auke Kok9d5c8242008-01-24 02:22:38 -08001771{
Alexander Duyck1a1c2252012-09-25 00:30:52 +00001772 unsigned char *data;
1773 bool match = true;
1774
1775 frame_size >>= 1;
1776
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001777 data = kmap(rx_buffer->page);
Alexander Duyck1a1c2252012-09-25 00:30:52 +00001778
1779 if (data[3] != 0xFF ||
1780 data[frame_size + 10] != 0xBE ||
1781 data[frame_size + 12] != 0xAF)
1782 match = false;
1783
1784 kunmap(rx_buffer->page);
1785
1786 return match;
Auke Kok9d5c8242008-01-24 02:22:38 -08001787}
1788
Alexander Duyckad93d172009-10-27 15:55:02 +00001789static int igb_clean_test_rings(struct igb_ring *rx_ring,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001790 struct igb_ring *tx_ring,
1791 unsigned int size)
Alexander Duyckad93d172009-10-27 15:55:02 +00001792{
1793 union e1000_adv_rx_desc *rx_desc;
Alexander Duyck06034642011-08-26 07:44:22 +00001794 struct igb_rx_buffer *rx_buffer_info;
1795 struct igb_tx_buffer *tx_buffer_info;
Alexander Duyck6ad4edf2011-08-26 07:45:26 +00001796 u16 rx_ntc, tx_ntc, count = 0;
Alexander Duyckad93d172009-10-27 15:55:02 +00001797
1798 /* initialize next to clean and descriptor values */
1799 rx_ntc = rx_ring->next_to_clean;
1800 tx_ntc = tx_ring->next_to_clean;
Alexander Duyck601369062011-08-26 07:44:05 +00001801 rx_desc = IGB_RX_DESC(rx_ring, rx_ntc);
Alexander Duyckad93d172009-10-27 15:55:02 +00001802
Alexander Duyck3ceb90f2011-08-26 07:46:03 +00001803 while (igb_test_staterr(rx_desc, E1000_RXD_STAT_DD)) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001804 /* check Rx buffer */
Alexander Duyck06034642011-08-26 07:44:22 +00001805 rx_buffer_info = &rx_ring->rx_buffer_info[rx_ntc];
Alexander Duyckad93d172009-10-27 15:55:02 +00001806
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001807 /* sync Rx buffer for CPU read */
1808 dma_sync_single_for_cpu(rx_ring->dev,
1809 rx_buffer_info->dma,
Alexander Duyckde78d1f2012-09-25 00:31:12 +00001810 IGB_RX_BUFSZ,
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001811 DMA_FROM_DEVICE);
Alexander Duyckad93d172009-10-27 15:55:02 +00001812
1813 /* verify contents of skb */
Alexander Duyck1a1c2252012-09-25 00:30:52 +00001814 if (igb_check_lbtest_frame(rx_buffer_info, size))
Alexander Duyckad93d172009-10-27 15:55:02 +00001815 count++;
1816
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001817 /* sync Rx buffer for device write */
1818 dma_sync_single_for_device(rx_ring->dev,
1819 rx_buffer_info->dma,
Alexander Duyckde78d1f2012-09-25 00:31:12 +00001820 IGB_RX_BUFSZ,
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001821 DMA_FROM_DEVICE);
1822
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001823 /* unmap buffer on Tx side */
Alexander Duyck06034642011-08-26 07:44:22 +00001824 tx_buffer_info = &tx_ring->tx_buffer_info[tx_ntc];
1825 igb_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duyckad93d172009-10-27 15:55:02 +00001826
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001827 /* increment Rx/Tx next to clean counters */
Alexander Duyckad93d172009-10-27 15:55:02 +00001828 rx_ntc++;
1829 if (rx_ntc == rx_ring->count)
1830 rx_ntc = 0;
1831 tx_ntc++;
1832 if (tx_ntc == tx_ring->count)
1833 tx_ntc = 0;
1834
1835 /* fetch next descriptor */
Alexander Duyck601369062011-08-26 07:44:05 +00001836 rx_desc = IGB_RX_DESC(rx_ring, rx_ntc);
Alexander Duyckad93d172009-10-27 15:55:02 +00001837 }
1838
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001839 netdev_tx_reset_queue(txring_txq(tx_ring));
Jeff Kirsher51a76c32012-01-19 18:31:34 +00001840
Alexander Duyckad93d172009-10-27 15:55:02 +00001841 /* re-map buffers to ring, store next to clean values */
Alexander Duyckcd392f52011-08-26 07:43:59 +00001842 igb_alloc_rx_buffers(rx_ring, count);
Alexander Duyckad93d172009-10-27 15:55:02 +00001843 rx_ring->next_to_clean = rx_ntc;
1844 tx_ring->next_to_clean = tx_ntc;
1845
1846 return count;
1847}
1848
Auke Kok9d5c8242008-01-24 02:22:38 -08001849static int igb_run_loopback_test(struct igb_adapter *adapter)
1850{
Auke Kok9d5c8242008-01-24 02:22:38 -08001851 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1852 struct igb_ring *rx_ring = &adapter->test_rx_ring;
Alexander Duyck6ad4edf2011-08-26 07:45:26 +00001853 u16 i, j, lc, good_cnt;
1854 int ret_val = 0;
Alexander Duyck44390ca2011-08-26 07:43:38 +00001855 unsigned int size = IGB_RX_HDR_LEN;
Alexander Duyckad93d172009-10-27 15:55:02 +00001856 netdev_tx_t tx_ret_val;
1857 struct sk_buff *skb;
Auke Kok9d5c8242008-01-24 02:22:38 -08001858
Alexander Duyckad93d172009-10-27 15:55:02 +00001859 /* allocate test skb */
1860 skb = alloc_skb(size, GFP_KERNEL);
1861 if (!skb)
1862 return 11;
1863
1864 /* place data into test skb */
1865 igb_create_lbtest_frame(skb, size);
1866 skb_put(skb, size);
Auke Kok9d5c8242008-01-24 02:22:38 -08001867
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001868 /* Calculate the loop count based on the largest descriptor ring
Auke Kok9d5c8242008-01-24 02:22:38 -08001869 * The idea is to wrap the largest ring a number of times using 64
1870 * send/receive pairs during each loop
1871 */
1872
1873 if (rx_ring->count <= tx_ring->count)
1874 lc = ((tx_ring->count / 64) * 2) + 1;
1875 else
1876 lc = ((rx_ring->count / 64) * 2) + 1;
1877
Auke Kok9d5c8242008-01-24 02:22:38 -08001878 for (j = 0; j <= lc; j++) { /* loop count loop */
Alexander Duyckad93d172009-10-27 15:55:02 +00001879 /* reset count of good packets */
Auke Kok9d5c8242008-01-24 02:22:38 -08001880 good_cnt = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001881
Alexander Duyckad93d172009-10-27 15:55:02 +00001882 /* place 64 packets on the transmit queue*/
1883 for (i = 0; i < 64; i++) {
1884 skb_get(skb);
Alexander Duyckcd392f52011-08-26 07:43:59 +00001885 tx_ret_val = igb_xmit_frame_ring(skb, tx_ring);
Alexander Duyckad93d172009-10-27 15:55:02 +00001886 if (tx_ret_val == NETDEV_TX_OK)
Auke Kok9d5c8242008-01-24 02:22:38 -08001887 good_cnt++;
Alexander Duyckad93d172009-10-27 15:55:02 +00001888 }
1889
Auke Kok9d5c8242008-01-24 02:22:38 -08001890 if (good_cnt != 64) {
Alexander Duyckad93d172009-10-27 15:55:02 +00001891 ret_val = 12;
Auke Kok9d5c8242008-01-24 02:22:38 -08001892 break;
1893 }
Alexander Duyckad93d172009-10-27 15:55:02 +00001894
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001895 /* allow 200 milliseconds for packets to go from Tx to Rx */
Alexander Duyckad93d172009-10-27 15:55:02 +00001896 msleep(200);
1897
1898 good_cnt = igb_clean_test_rings(rx_ring, tx_ring, size);
1899 if (good_cnt != 64) {
1900 ret_val = 13;
Auke Kok9d5c8242008-01-24 02:22:38 -08001901 break;
1902 }
1903 } /* end loop count loop */
Alexander Duyckad93d172009-10-27 15:55:02 +00001904
1905 /* free the original skb */
1906 kfree_skb(skb);
1907
Auke Kok9d5c8242008-01-24 02:22:38 -08001908 return ret_val;
1909}
1910
1911static int igb_loopback_test(struct igb_adapter *adapter, u64 *data)
1912{
1913 /* PHY loopback cannot be performed if SoL/IDER
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001914 * sessions are active
1915 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001916 if (igb_check_reset_block(&adapter->hw)) {
1917 dev_err(&adapter->pdev->dev,
Jesper Juhld836200a2012-08-01 05:41:30 +00001918 "Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001919 *data = 0;
1920 goto out;
1921 }
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001922
1923 if (adapter->hw.mac.type == e1000_i354) {
1924 dev_info(&adapter->pdev->dev,
1925 "Loopback test not supported on i354.\n");
1926 *data = 0;
1927 goto out;
1928 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001929 *data = igb_setup_desc_rings(adapter);
1930 if (*data)
1931 goto out;
1932 *data = igb_setup_loopback_test(adapter);
1933 if (*data)
1934 goto err_loopback;
1935 *data = igb_run_loopback_test(adapter);
1936 igb_loopback_cleanup(adapter);
1937
1938err_loopback:
1939 igb_free_desc_rings(adapter);
1940out:
1941 return *data;
1942}
1943
1944static int igb_link_test(struct igb_adapter *adapter, u64 *data)
1945{
1946 struct e1000_hw *hw = &adapter->hw;
1947 *data = 0;
1948 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1949 int i = 0;
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001950
Auke Kok9d5c8242008-01-24 02:22:38 -08001951 hw->mac.serdes_has_link = false;
1952
1953 /* On some blade server designs, link establishment
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001954 * could take as long as 2-3 minutes
1955 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001956 do {
1957 hw->mac.ops.check_for_link(&adapter->hw);
1958 if (hw->mac.serdes_has_link)
1959 return *data;
1960 msleep(20);
1961 } while (i++ < 3750);
1962
1963 *data = 1;
1964 } else {
1965 hw->mac.ops.check_for_link(&adapter->hw);
1966 if (hw->mac.autoneg)
Stefan Assmann4507dc92013-02-02 08:31:50 +00001967 msleep(5000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001968
Alexander Duyck317f66b2009-10-27 23:46:20 +00001969 if (!(rd32(E1000_STATUS) & E1000_STATUS_LU))
Auke Kok9d5c8242008-01-24 02:22:38 -08001970 *data = 1;
1971 }
1972 return *data;
1973}
1974
1975static void igb_diag_test(struct net_device *netdev,
1976 struct ethtool_test *eth_test, u64 *data)
1977{
1978 struct igb_adapter *adapter = netdev_priv(netdev);
1979 u16 autoneg_advertised;
1980 u8 forced_speed_duplex, autoneg;
1981 bool if_running = netif_running(netdev);
1982
1983 set_bit(__IGB_TESTING, &adapter->state);
Carolyn Wyborny56cec242013-10-17 05:36:26 +00001984
1985 /* can't do offline tests on media switching devices */
1986 if (adapter->hw.dev_spec._82575.mas_capable)
1987 eth_test->flags &= ~ETH_TEST_FL_OFFLINE;
Auke Kok9d5c8242008-01-24 02:22:38 -08001988 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1989 /* Offline tests */
1990
1991 /* save speed, duplex, autoneg settings */
1992 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1993 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1994 autoneg = adapter->hw.mac.autoneg;
1995
1996 dev_info(&adapter->pdev->dev, "offline testing starting\n");
1997
Nick Nunley88a268c2010-02-17 01:01:59 +00001998 /* power up link for link test */
1999 igb_power_up_link(adapter);
2000
Auke Kok9d5c8242008-01-24 02:22:38 -08002001 /* Link test performed before hardware reset so autoneg doesn't
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002002 * interfere with test result
2003 */
Auke Kok9d5c8242008-01-24 02:22:38 -08002004 if (igb_link_test(adapter, &data[4]))
2005 eth_test->flags |= ETH_TEST_FL_FAILED;
2006
2007 if (if_running)
2008 /* indicate we're in test mode */
2009 dev_close(netdev);
2010 else
2011 igb_reset(adapter);
2012
2013 if (igb_reg_test(adapter, &data[0]))
2014 eth_test->flags |= ETH_TEST_FL_FAILED;
2015
2016 igb_reset(adapter);
2017 if (igb_eeprom_test(adapter, &data[1]))
2018 eth_test->flags |= ETH_TEST_FL_FAILED;
2019
2020 igb_reset(adapter);
2021 if (igb_intr_test(adapter, &data[2]))
2022 eth_test->flags |= ETH_TEST_FL_FAILED;
2023
2024 igb_reset(adapter);
Nick Nunley88a268c2010-02-17 01:01:59 +00002025 /* power up link for loopback test */
2026 igb_power_up_link(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002027 if (igb_loopback_test(adapter, &data[3]))
2028 eth_test->flags |= ETH_TEST_FL_FAILED;
2029
2030 /* restore speed, duplex, autoneg settings */
2031 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
2032 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
2033 adapter->hw.mac.autoneg = autoneg;
2034
2035 /* force this routine to wait until autoneg complete/timeout */
2036 adapter->hw.phy.autoneg_wait_to_complete = true;
2037 igb_reset(adapter);
2038 adapter->hw.phy.autoneg_wait_to_complete = false;
2039
2040 clear_bit(__IGB_TESTING, &adapter->state);
2041 if (if_running)
2042 dev_open(netdev);
2043 } else {
2044 dev_info(&adapter->pdev->dev, "online testing starting\n");
Nick Nunley88a268c2010-02-17 01:01:59 +00002045
2046 /* PHY is powered down when interface is down */
Alexander Duyck8d420a12010-07-01 13:39:01 +00002047 if (if_running && igb_link_test(adapter, &data[4]))
2048 eth_test->flags |= ETH_TEST_FL_FAILED;
2049 else
Nick Nunley88a268c2010-02-17 01:01:59 +00002050 data[4] = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002051
2052 /* Online tests aren't run; pass by default */
2053 data[0] = 0;
2054 data[1] = 0;
2055 data[2] = 0;
2056 data[3] = 0;
2057
2058 clear_bit(__IGB_TESTING, &adapter->state);
2059 }
2060 msleep_interruptible(4 * 1000);
2061}
2062
Auke Kok9d5c8242008-01-24 02:22:38 -08002063static void igb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2064{
2065 struct igb_adapter *adapter = netdev_priv(netdev);
2066
Auke Kok9d5c8242008-01-24 02:22:38 -08002067 wol->wolopts = 0;
2068
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002069 if (!(adapter->flags & IGB_FLAG_WOL_SUPPORTED))
Auke Kok9d5c8242008-01-24 02:22:38 -08002070 return;
2071
Akeem G Abodunrin42ce4122013-11-08 01:54:07 +00002072 wol->supported = WAKE_UCAST | WAKE_MCAST |
2073 WAKE_BCAST | WAKE_MAGIC |
2074 WAKE_PHY;
2075
Auke Kok9d5c8242008-01-24 02:22:38 -08002076 /* apply any specific unsupported masks here */
2077 switch (adapter->hw.device_id) {
2078 default:
2079 break;
2080 }
2081
2082 if (adapter->wol & E1000_WUFC_EX)
2083 wol->wolopts |= WAKE_UCAST;
2084 if (adapter->wol & E1000_WUFC_MC)
2085 wol->wolopts |= WAKE_MCAST;
2086 if (adapter->wol & E1000_WUFC_BC)
2087 wol->wolopts |= WAKE_BCAST;
2088 if (adapter->wol & E1000_WUFC_MAG)
2089 wol->wolopts |= WAKE_MAGIC;
Nick Nunley22939f02010-02-17 01:01:01 +00002090 if (adapter->wol & E1000_WUFC_LNKC)
2091 wol->wolopts |= WAKE_PHY;
Auke Kok9d5c8242008-01-24 02:22:38 -08002092}
2093
2094static int igb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2095{
2096 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08002097
Nick Nunley22939f02010-02-17 01:01:01 +00002098 if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE))
Auke Kok9d5c8242008-01-24 02:22:38 -08002099 return -EOPNOTSUPP;
2100
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002101 if (!(adapter->flags & IGB_FLAG_WOL_SUPPORTED))
Auke Kok9d5c8242008-01-24 02:22:38 -08002102 return wol->wolopts ? -EOPNOTSUPP : 0;
2103
Auke Kok9d5c8242008-01-24 02:22:38 -08002104 /* these settings will always override what we currently have */
2105 adapter->wol = 0;
2106
2107 if (wol->wolopts & WAKE_UCAST)
2108 adapter->wol |= E1000_WUFC_EX;
2109 if (wol->wolopts & WAKE_MCAST)
2110 adapter->wol |= E1000_WUFC_MC;
2111 if (wol->wolopts & WAKE_BCAST)
2112 adapter->wol |= E1000_WUFC_BC;
2113 if (wol->wolopts & WAKE_MAGIC)
2114 adapter->wol |= E1000_WUFC_MAG;
Nick Nunley22939f02010-02-17 01:01:01 +00002115 if (wol->wolopts & WAKE_PHY)
2116 adapter->wol |= E1000_WUFC_LNKC;
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00002117 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
2118
Auke Kok9d5c8242008-01-24 02:22:38 -08002119 return 0;
2120}
2121
Auke Kok9d5c8242008-01-24 02:22:38 -08002122/* bit defines for adapter->led_status */
2123#define IGB_LED_ON 0
2124
Jeff Kirsher936db352011-05-07 06:37:14 +00002125static int igb_set_phys_id(struct net_device *netdev,
2126 enum ethtool_phys_id_state state)
Auke Kok9d5c8242008-01-24 02:22:38 -08002127{
2128 struct igb_adapter *adapter = netdev_priv(netdev);
2129 struct e1000_hw *hw = &adapter->hw;
2130
Jeff Kirsher936db352011-05-07 06:37:14 +00002131 switch (state) {
2132 case ETHTOOL_ID_ACTIVE:
2133 igb_blink_led(hw);
2134 return 2;
2135 case ETHTOOL_ID_ON:
2136 igb_blink_led(hw);
2137 break;
2138 case ETHTOOL_ID_OFF:
2139 igb_led_off(hw);
2140 break;
2141 case ETHTOOL_ID_INACTIVE:
2142 igb_led_off(hw);
2143 clear_bit(IGB_LED_ON, &adapter->led_status);
2144 igb_cleanup_led(hw);
2145 break;
2146 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002147
2148 return 0;
2149}
2150
2151static int igb_set_coalesce(struct net_device *netdev,
2152 struct ethtool_coalesce *ec)
2153{
2154 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002155 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08002156
2157 if ((ec->rx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
2158 ((ec->rx_coalesce_usecs > 3) &&
2159 (ec->rx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
2160 (ec->rx_coalesce_usecs == 2))
2161 return -EINVAL;
2162
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002163 if ((ec->tx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
2164 ((ec->tx_coalesce_usecs > 3) &&
2165 (ec->tx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
2166 (ec->tx_coalesce_usecs == 2))
2167 return -EINVAL;
2168
2169 if ((adapter->flags & IGB_FLAG_QUEUE_PAIRS) && ec->tx_coalesce_usecs)
2170 return -EINVAL;
2171
Carolyn Wyborny831ec0b2011-03-11 20:43:54 -08002172 /* If ITR is disabled, disable DMAC */
2173 if (ec->rx_coalesce_usecs == 0) {
2174 if (adapter->flags & IGB_FLAG_DMAC)
2175 adapter->flags &= ~IGB_FLAG_DMAC;
2176 }
2177
Auke Kok9d5c8242008-01-24 02:22:38 -08002178 /* convert to rate of irq's per second */
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002179 if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3)
2180 adapter->rx_itr_setting = ec->rx_coalesce_usecs;
2181 else
2182 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
2183
2184 /* convert to rate of irq's per second */
2185 if (adapter->flags & IGB_FLAG_QUEUE_PAIRS)
2186 adapter->tx_itr_setting = adapter->rx_itr_setting;
2187 else if (ec->tx_coalesce_usecs && ec->tx_coalesce_usecs <= 3)
2188 adapter->tx_itr_setting = ec->tx_coalesce_usecs;
2189 else
2190 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
Auke Kok9d5c8242008-01-24 02:22:38 -08002191
Alexander Duyck047e0032009-10-27 15:49:27 +00002192 for (i = 0; i < adapter->num_q_vectors; i++) {
2193 struct igb_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck0ba82992011-08-26 07:45:47 +00002194 q_vector->tx.work_limit = adapter->tx_work_limit;
2195 if (q_vector->rx.ring)
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002196 q_vector->itr_val = adapter->rx_itr_setting;
2197 else
2198 q_vector->itr_val = adapter->tx_itr_setting;
2199 if (q_vector->itr_val && q_vector->itr_val <= 3)
2200 q_vector->itr_val = IGB_START_ITR;
Alexander Duyck047e0032009-10-27 15:49:27 +00002201 q_vector->set_itr = 1;
2202 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002203
2204 return 0;
2205}
2206
2207static int igb_get_coalesce(struct net_device *netdev,
2208 struct ethtool_coalesce *ec)
2209{
2210 struct igb_adapter *adapter = netdev_priv(netdev);
2211
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002212 if (adapter->rx_itr_setting <= 3)
2213 ec->rx_coalesce_usecs = adapter->rx_itr_setting;
Auke Kok9d5c8242008-01-24 02:22:38 -08002214 else
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002215 ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
2216
2217 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS)) {
2218 if (adapter->tx_itr_setting <= 3)
2219 ec->tx_coalesce_usecs = adapter->tx_itr_setting;
2220 else
2221 ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
2222 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002223
2224 return 0;
2225}
2226
Auke Kok9d5c8242008-01-24 02:22:38 -08002227static int igb_nway_reset(struct net_device *netdev)
2228{
2229 struct igb_adapter *adapter = netdev_priv(netdev);
2230 if (netif_running(netdev))
2231 igb_reinit_locked(adapter);
2232 return 0;
2233}
2234
2235static int igb_get_sset_count(struct net_device *netdev, int sset)
2236{
2237 switch (sset) {
2238 case ETH_SS_STATS:
2239 return IGB_STATS_LEN;
2240 case ETH_SS_TEST:
2241 return IGB_TEST_LEN;
2242 default:
2243 return -ENOTSUPP;
2244 }
2245}
2246
2247static void igb_get_ethtool_stats(struct net_device *netdev,
2248 struct ethtool_stats *stats, u64 *data)
2249{
2250 struct igb_adapter *adapter = netdev_priv(netdev);
Eric Dumazet12dcd862010-10-15 17:27:10 +00002251 struct rtnl_link_stats64 *net_stats = &adapter->stats64;
2252 unsigned int start;
2253 struct igb_ring *ring;
2254 int i, j;
Alexander Duyck128e45e2009-11-12 18:37:38 +00002255 char *p;
Auke Kok9d5c8242008-01-24 02:22:38 -08002256
Eric Dumazet12dcd862010-10-15 17:27:10 +00002257 spin_lock(&adapter->stats64_lock);
2258 igb_update_stats(adapter, net_stats);
Alexander Duyck317f66b2009-10-27 23:46:20 +00002259
Auke Kok9d5c8242008-01-24 02:22:38 -08002260 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
Alexander Duyck128e45e2009-11-12 18:37:38 +00002261 p = (char *)adapter + igb_gstrings_stats[i].stat_offset;
Auke Kok9d5c8242008-01-24 02:22:38 -08002262 data[i] = (igb_gstrings_stats[i].sizeof_stat ==
2263 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2264 }
Alexander Duyck128e45e2009-11-12 18:37:38 +00002265 for (j = 0; j < IGB_NETDEV_STATS_LEN; j++, i++) {
2266 p = (char *)net_stats + igb_gstrings_net_stats[j].stat_offset;
2267 data[i] = (igb_gstrings_net_stats[j].sizeof_stat ==
2268 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2269 }
Alexander Duycke21ed352008-07-08 15:07:24 -07002270 for (j = 0; j < adapter->num_tx_queues; j++) {
Eric Dumazet12dcd862010-10-15 17:27:10 +00002271 u64 restart2;
2272
2273 ring = adapter->tx_ring[j];
2274 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07002275 start = u64_stats_fetch_begin_irq(&ring->tx_syncp);
Eric Dumazet12dcd862010-10-15 17:27:10 +00002276 data[i] = ring->tx_stats.packets;
2277 data[i+1] = ring->tx_stats.bytes;
2278 data[i+2] = ring->tx_stats.restart_queue;
Eric W. Biederman57a77442014-03-13 21:26:42 -07002279 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp, start));
Eric Dumazet12dcd862010-10-15 17:27:10 +00002280 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07002281 start = u64_stats_fetch_begin_irq(&ring->tx_syncp2);
Eric Dumazet12dcd862010-10-15 17:27:10 +00002282 restart2 = ring->tx_stats.restart_queue2;
Eric W. Biederman57a77442014-03-13 21:26:42 -07002283 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp2, start));
Eric Dumazet12dcd862010-10-15 17:27:10 +00002284 data[i+2] += restart2;
2285
2286 i += IGB_TX_QUEUE_STATS_LEN;
Alexander Duycke21ed352008-07-08 15:07:24 -07002287 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002288 for (j = 0; j < adapter->num_rx_queues; j++) {
Eric Dumazet12dcd862010-10-15 17:27:10 +00002289 ring = adapter->rx_ring[j];
2290 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07002291 start = u64_stats_fetch_begin_irq(&ring->rx_syncp);
Eric Dumazet12dcd862010-10-15 17:27:10 +00002292 data[i] = ring->rx_stats.packets;
2293 data[i+1] = ring->rx_stats.bytes;
2294 data[i+2] = ring->rx_stats.drops;
2295 data[i+3] = ring->rx_stats.csum_err;
2296 data[i+4] = ring->rx_stats.alloc_failed;
Eric W. Biederman57a77442014-03-13 21:26:42 -07002297 } while (u64_stats_fetch_retry_irq(&ring->rx_syncp, start));
Eric Dumazet12dcd862010-10-15 17:27:10 +00002298 i += IGB_RX_QUEUE_STATS_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002299 }
Eric Dumazet12dcd862010-10-15 17:27:10 +00002300 spin_unlock(&adapter->stats64_lock);
Auke Kok9d5c8242008-01-24 02:22:38 -08002301}
2302
2303static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
2304{
2305 struct igb_adapter *adapter = netdev_priv(netdev);
2306 u8 *p = data;
2307 int i;
2308
2309 switch (stringset) {
2310 case ETH_SS_TEST:
2311 memcpy(data, *igb_gstrings_test,
2312 IGB_TEST_LEN*ETH_GSTRING_LEN);
2313 break;
2314 case ETH_SS_STATS:
2315 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
2316 memcpy(p, igb_gstrings_stats[i].stat_string,
2317 ETH_GSTRING_LEN);
2318 p += ETH_GSTRING_LEN;
2319 }
Alexander Duyck128e45e2009-11-12 18:37:38 +00002320 for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) {
2321 memcpy(p, igb_gstrings_net_stats[i].stat_string,
2322 ETH_GSTRING_LEN);
2323 p += ETH_GSTRING_LEN;
2324 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002325 for (i = 0; i < adapter->num_tx_queues; i++) {
2326 sprintf(p, "tx_queue_%u_packets", i);
2327 p += ETH_GSTRING_LEN;
2328 sprintf(p, "tx_queue_%u_bytes", i);
2329 p += ETH_GSTRING_LEN;
Alexander Duyck04a5fcaa2009-10-27 15:52:27 +00002330 sprintf(p, "tx_queue_%u_restart", i);
2331 p += ETH_GSTRING_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002332 }
2333 for (i = 0; i < adapter->num_rx_queues; i++) {
2334 sprintf(p, "rx_queue_%u_packets", i);
2335 p += ETH_GSTRING_LEN;
2336 sprintf(p, "rx_queue_%u_bytes", i);
2337 p += ETH_GSTRING_LEN;
Jesper Dangaard Brouer8c0ab702009-05-26 13:50:31 +00002338 sprintf(p, "rx_queue_%u_drops", i);
2339 p += ETH_GSTRING_LEN;
Alexander Duyck04a5fcaa2009-10-27 15:52:27 +00002340 sprintf(p, "rx_queue_%u_csum_err", i);
2341 p += ETH_GSTRING_LEN;
2342 sprintf(p, "rx_queue_%u_alloc_failed", i);
2343 p += ETH_GSTRING_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002344 }
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002345 /* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
Auke Kok9d5c8242008-01-24 02:22:38 -08002346 break;
2347 }
2348}
2349
Matthew Vicka79f4f82012-08-10 05:40:44 +00002350static int igb_get_ts_info(struct net_device *dev,
Matthew Vicka9188022012-08-28 06:33:05 +00002351 struct ethtool_ts_info *info)
Carolyn Wybornycb411452012-04-04 17:43:59 +00002352{
2353 struct igb_adapter *adapter = netdev_priv(dev);
2354
Ken ICHIKAWA0f49da02014-03-21 03:37:24 -07002355 if (adapter->ptp_clock)
2356 info->phc_index = ptp_clock_index(adapter->ptp_clock);
2357 else
2358 info->phc_index = -1;
2359
Matthew Vicka9188022012-08-28 06:33:05 +00002360 switch (adapter->hw.mac.type) {
Matthew Vickb66e2392012-12-13 07:20:33 +00002361 case e1000_82575:
2362 info->so_timestamping =
2363 SOF_TIMESTAMPING_TX_SOFTWARE |
2364 SOF_TIMESTAMPING_RX_SOFTWARE |
2365 SOF_TIMESTAMPING_SOFTWARE;
2366 return 0;
Matthew Vicka9188022012-08-28 06:33:05 +00002367 case e1000_82576:
2368 case e1000_82580:
2369 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002370 case e1000_i354:
Matthew Vicka9188022012-08-28 06:33:05 +00002371 case e1000_i210:
2372 case e1000_i211:
2373 info->so_timestamping =
Matthew Vickb66e2392012-12-13 07:20:33 +00002374 SOF_TIMESTAMPING_TX_SOFTWARE |
2375 SOF_TIMESTAMPING_RX_SOFTWARE |
2376 SOF_TIMESTAMPING_SOFTWARE |
Matthew Vicka9188022012-08-28 06:33:05 +00002377 SOF_TIMESTAMPING_TX_HARDWARE |
2378 SOF_TIMESTAMPING_RX_HARDWARE |
2379 SOF_TIMESTAMPING_RAW_HARDWARE;
Carolyn Wybornycb411452012-04-04 17:43:59 +00002380
Matthew Vicka9188022012-08-28 06:33:05 +00002381 info->tx_types =
2382 (1 << HWTSTAMP_TX_OFF) |
2383 (1 << HWTSTAMP_TX_ON);
Carolyn Wybornycb411452012-04-04 17:43:59 +00002384
Matthew Vicka9188022012-08-28 06:33:05 +00002385 info->rx_filters = 1 << HWTSTAMP_FILTER_NONE;
Carolyn Wybornycb411452012-04-04 17:43:59 +00002386
Matthew Vicka9188022012-08-28 06:33:05 +00002387 /* 82576 does not support timestamping all packets. */
2388 if (adapter->hw.mac.type >= e1000_82580)
2389 info->rx_filters |= 1 << HWTSTAMP_FILTER_ALL;
2390 else
2391 info->rx_filters |=
2392 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
2393 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
2394 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
2395 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
2396 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
2397 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
2398 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
2399
2400 return 0;
Matthew Vicka9188022012-08-28 06:33:05 +00002401 default:
2402 return -EOPNOTSUPP;
2403 }
2404}
Carolyn Wybornycb411452012-04-04 17:43:59 +00002405
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002406static int igb_get_rss_hash_opts(struct igb_adapter *adapter,
2407 struct ethtool_rxnfc *cmd)
2408{
2409 cmd->data = 0;
2410
2411 /* Report default options for RSS on igb */
2412 switch (cmd->flow_type) {
2413 case TCP_V4_FLOW:
2414 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
Carolyn Wybornyb26141d2014-04-17 04:10:13 +00002415 /* Fall through */
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002416 case UDP_V4_FLOW:
2417 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
2418 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
Carolyn Wybornyb26141d2014-04-17 04:10:13 +00002419 /* Fall through */
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002420 case SCTP_V4_FLOW:
2421 case AH_ESP_V4_FLOW:
2422 case AH_V4_FLOW:
2423 case ESP_V4_FLOW:
2424 case IPV4_FLOW:
2425 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2426 break;
2427 case TCP_V6_FLOW:
2428 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
Carolyn Wybornyb26141d2014-04-17 04:10:13 +00002429 /* Fall through */
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002430 case UDP_V6_FLOW:
2431 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
2432 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
Carolyn Wybornyb26141d2014-04-17 04:10:13 +00002433 /* Fall through */
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002434 case SCTP_V6_FLOW:
2435 case AH_ESP_V6_FLOW:
2436 case AH_V6_FLOW:
2437 case ESP_V6_FLOW:
2438 case IPV6_FLOW:
2439 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2440 break;
2441 default:
2442 return -EINVAL;
2443 }
2444
2445 return 0;
2446}
2447
2448static int igb_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002449 u32 *rule_locs)
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002450{
2451 struct igb_adapter *adapter = netdev_priv(dev);
2452 int ret = -EOPNOTSUPP;
2453
2454 switch (cmd->cmd) {
2455 case ETHTOOL_GRXRINGS:
2456 cmd->data = adapter->num_rx_queues;
2457 ret = 0;
2458 break;
2459 case ETHTOOL_GRXFH:
2460 ret = igb_get_rss_hash_opts(adapter, cmd);
2461 break;
2462 default:
2463 break;
2464 }
2465
2466 return ret;
2467}
2468
2469#define UDP_RSS_FLAGS (IGB_FLAG_RSS_FIELD_IPV4_UDP | \
2470 IGB_FLAG_RSS_FIELD_IPV6_UDP)
2471static int igb_set_rss_hash_opt(struct igb_adapter *adapter,
2472 struct ethtool_rxnfc *nfc)
2473{
2474 u32 flags = adapter->flags;
2475
2476 /* RSS does not support anything other than hashing
2477 * to queues on src and dst IPs and ports
2478 */
2479 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2480 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2481 return -EINVAL;
2482
2483 switch (nfc->flow_type) {
2484 case TCP_V4_FLOW:
2485 case TCP_V6_FLOW:
2486 if (!(nfc->data & RXH_IP_SRC) ||
2487 !(nfc->data & RXH_IP_DST) ||
2488 !(nfc->data & RXH_L4_B_0_1) ||
2489 !(nfc->data & RXH_L4_B_2_3))
2490 return -EINVAL;
2491 break;
2492 case UDP_V4_FLOW:
2493 if (!(nfc->data & RXH_IP_SRC) ||
2494 !(nfc->data & RXH_IP_DST))
2495 return -EINVAL;
2496 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2497 case 0:
2498 flags &= ~IGB_FLAG_RSS_FIELD_IPV4_UDP;
2499 break;
2500 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2501 flags |= IGB_FLAG_RSS_FIELD_IPV4_UDP;
2502 break;
2503 default:
2504 return -EINVAL;
2505 }
2506 break;
2507 case UDP_V6_FLOW:
2508 if (!(nfc->data & RXH_IP_SRC) ||
2509 !(nfc->data & RXH_IP_DST))
2510 return -EINVAL;
2511 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2512 case 0:
2513 flags &= ~IGB_FLAG_RSS_FIELD_IPV6_UDP;
2514 break;
2515 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2516 flags |= IGB_FLAG_RSS_FIELD_IPV6_UDP;
2517 break;
2518 default:
2519 return -EINVAL;
2520 }
2521 break;
2522 case AH_ESP_V4_FLOW:
2523 case AH_V4_FLOW:
2524 case ESP_V4_FLOW:
2525 case SCTP_V4_FLOW:
2526 case AH_ESP_V6_FLOW:
2527 case AH_V6_FLOW:
2528 case ESP_V6_FLOW:
2529 case SCTP_V6_FLOW:
2530 if (!(nfc->data & RXH_IP_SRC) ||
2531 !(nfc->data & RXH_IP_DST) ||
2532 (nfc->data & RXH_L4_B_0_1) ||
2533 (nfc->data & RXH_L4_B_2_3))
2534 return -EINVAL;
2535 break;
2536 default:
2537 return -EINVAL;
2538 }
2539
2540 /* if we changed something we need to update flags */
2541 if (flags != adapter->flags) {
2542 struct e1000_hw *hw = &adapter->hw;
2543 u32 mrqc = rd32(E1000_MRQC);
2544
2545 if ((flags & UDP_RSS_FLAGS) &&
2546 !(adapter->flags & UDP_RSS_FLAGS))
2547 dev_err(&adapter->pdev->dev,
2548 "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
2549
2550 adapter->flags = flags;
2551
2552 /* Perform hash on these packet types */
2553 mrqc |= E1000_MRQC_RSS_FIELD_IPV4 |
2554 E1000_MRQC_RSS_FIELD_IPV4_TCP |
2555 E1000_MRQC_RSS_FIELD_IPV6 |
2556 E1000_MRQC_RSS_FIELD_IPV6_TCP;
2557
2558 mrqc &= ~(E1000_MRQC_RSS_FIELD_IPV4_UDP |
2559 E1000_MRQC_RSS_FIELD_IPV6_UDP);
2560
2561 if (flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
2562 mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
2563
2564 if (flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
2565 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
2566
2567 wr32(E1000_MRQC, mrqc);
2568 }
2569
2570 return 0;
2571}
2572
2573static int igb_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
2574{
2575 struct igb_adapter *adapter = netdev_priv(dev);
2576 int ret = -EOPNOTSUPP;
2577
2578 switch (cmd->cmd) {
2579 case ETHTOOL_SRXFH:
2580 ret = igb_set_rss_hash_opt(adapter, cmd);
2581 break;
2582 default:
2583 break;
2584 }
2585
2586 return ret;
2587}
2588
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002589static int igb_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
2590{
2591 struct igb_adapter *adapter = netdev_priv(netdev);
2592 struct e1000_hw *hw = &adapter->hw;
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002593 u32 ret_val;
Matthew Vick87371b92013-02-21 03:32:52 +00002594 u16 phy_data;
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002595
2596 if ((hw->mac.type < e1000_i350) ||
2597 (hw->phy.media_type != e1000_media_type_copper))
2598 return -EOPNOTSUPP;
2599
2600 edata->supported = (SUPPORTED_1000baseT_Full |
2601 SUPPORTED_100baseT_Full);
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002602 if (!hw->dev_spec._82575.eee_disable)
2603 edata->advertised =
2604 mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002605
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002606 /* The IPCNFG and EEER registers are not supported on I354. */
2607 if (hw->mac.type == e1000_i354) {
2608 igb_get_eee_status_i354(hw, (bool *)&edata->eee_active);
2609 } else {
2610 u32 eeer;
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002611
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002612 eeer = rd32(E1000_EEER);
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002613
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002614 /* EEE status on negotiated link */
2615 if (eeer & E1000_EEER_EEE_NEG)
2616 edata->eee_active = true;
2617
2618 if (eeer & E1000_EEER_TX_LPI_EN)
2619 edata->tx_lpi_enabled = true;
2620 }
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002621
Matthew Vick87371b92013-02-21 03:32:52 +00002622 /* EEE Link Partner Advertised */
2623 switch (hw->mac.type) {
2624 case e1000_i350:
2625 ret_val = igb_read_emi_reg(hw, E1000_EEE_LP_ADV_ADDR_I350,
2626 &phy_data);
2627 if (ret_val)
2628 return -ENODATA;
2629
2630 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
Matthew Vick87371b92013-02-21 03:32:52 +00002631 break;
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002632 case e1000_i354:
Matthew Vick87371b92013-02-21 03:32:52 +00002633 case e1000_i210:
2634 case e1000_i211:
2635 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_LP_ADV_ADDR_I210,
2636 E1000_EEE_LP_ADV_DEV_I210,
2637 &phy_data);
2638 if (ret_val)
2639 return -ENODATA;
2640
2641 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
2642
2643 break;
2644 default:
2645 break;
2646 }
2647
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002648 edata->eee_enabled = !hw->dev_spec._82575.eee_disable;
2649
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002650 if ((hw->mac.type == e1000_i354) &&
2651 (edata->eee_enabled))
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002652 edata->tx_lpi_enabled = true;
2653
2654 /* Report correct negotiated EEE status for devices that
2655 * wrongly report EEE at half-duplex
2656 */
2657 if (adapter->link_duplex == HALF_DUPLEX) {
2658 edata->eee_enabled = false;
2659 edata->eee_active = false;
2660 edata->tx_lpi_enabled = false;
2661 edata->advertised &= ~edata->advertised;
2662 }
2663
2664 return 0;
2665}
2666
2667static int igb_set_eee(struct net_device *netdev,
2668 struct ethtool_eee *edata)
2669{
2670 struct igb_adapter *adapter = netdev_priv(netdev);
2671 struct e1000_hw *hw = &adapter->hw;
2672 struct ethtool_eee eee_curr;
2673 s32 ret_val;
2674
2675 if ((hw->mac.type < e1000_i350) ||
2676 (hw->phy.media_type != e1000_media_type_copper))
2677 return -EOPNOTSUPP;
2678
Andi Kleen58e4e1f2013-09-30 13:29:08 -07002679 memset(&eee_curr, 0, sizeof(struct ethtool_eee));
2680
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002681 ret_val = igb_get_eee(netdev, &eee_curr);
2682 if (ret_val)
2683 return ret_val;
2684
2685 if (eee_curr.eee_enabled) {
2686 if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
2687 dev_err(&adapter->pdev->dev,
2688 "Setting EEE tx-lpi is not supported\n");
2689 return -EINVAL;
2690 }
2691
2692 /* Tx LPI timer is not implemented currently */
2693 if (edata->tx_lpi_timer) {
2694 dev_err(&adapter->pdev->dev,
2695 "Setting EEE Tx LPI timer is not supported\n");
2696 return -EINVAL;
2697 }
2698
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002699 if (edata->advertised &
2700 ~(ADVERTISE_100_FULL | ADVERTISE_1000_FULL)) {
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002701 dev_err(&adapter->pdev->dev,
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002702 "EEE Advertisement supports only 100Tx and or 100T full duplex\n");
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002703 return -EINVAL;
2704 }
2705
2706 } else if (!edata->eee_enabled) {
2707 dev_err(&adapter->pdev->dev,
2708 "Setting EEE options are not supported with EEE disabled\n");
2709 return -EINVAL;
2710 }
2711
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002712 adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002713 if (hw->dev_spec._82575.eee_disable != !edata->eee_enabled) {
2714 hw->dev_spec._82575.eee_disable = !edata->eee_enabled;
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002715 adapter->flags |= IGB_FLAG_EEE;
2716 if (hw->mac.type == e1000_i350)
2717 igb_set_eee_i350(hw);
2718 else
2719 igb_set_eee_i354(hw);
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002720
2721 /* reset link */
Akeem G Abodunrin8a650aa2013-05-24 07:20:57 +00002722 if (netif_running(netdev))
2723 igb_reinit_locked(adapter);
2724 else
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002725 igb_reset(adapter);
2726 }
2727
2728 return 0;
2729}
2730
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00002731static int igb_get_module_info(struct net_device *netdev,
2732 struct ethtool_modinfo *modinfo)
2733{
2734 struct igb_adapter *adapter = netdev_priv(netdev);
2735 struct e1000_hw *hw = &adapter->hw;
2736 u32 status = E1000_SUCCESS;
2737 u16 sff8472_rev, addr_mode;
2738 bool page_swap = false;
2739
2740 if ((hw->phy.media_type == e1000_media_type_copper) ||
2741 (hw->phy.media_type == e1000_media_type_unknown))
2742 return -EOPNOTSUPP;
2743
2744 /* Check whether we support SFF-8472 or not */
2745 status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_COMP, &sff8472_rev);
2746 if (status != E1000_SUCCESS)
2747 return -EIO;
2748
2749 /* addressing mode is not supported */
2750 status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_SWAP, &addr_mode);
2751 if (status != E1000_SUCCESS)
2752 return -EIO;
2753
2754 /* addressing mode is not supported */
2755 if ((addr_mode & 0xFF) & IGB_SFF_ADDRESSING_MODE) {
2756 hw_dbg("Address change required to access page 0xA2, but not supported. Please report the module type to the driver maintainers.\n");
2757 page_swap = true;
2758 }
2759
2760 if ((sff8472_rev & 0xFF) == IGB_SFF_8472_UNSUP || page_swap) {
2761 /* We have an SFP, but it does not support SFF-8472 */
2762 modinfo->type = ETH_MODULE_SFF_8079;
2763 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
2764 } else {
2765 /* We have an SFP which supports a revision of SFF-8472 */
2766 modinfo->type = ETH_MODULE_SFF_8472;
2767 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
2768 }
2769
2770 return 0;
2771}
2772
2773static int igb_get_module_eeprom(struct net_device *netdev,
2774 struct ethtool_eeprom *ee, u8 *data)
2775{
2776 struct igb_adapter *adapter = netdev_priv(netdev);
2777 struct e1000_hw *hw = &adapter->hw;
2778 u32 status = E1000_SUCCESS;
2779 u16 *dataword;
2780 u16 first_word, last_word;
2781 int i = 0;
2782
2783 if (ee->len == 0)
2784 return -EINVAL;
2785
2786 first_word = ee->offset >> 1;
2787 last_word = (ee->offset + ee->len - 1) >> 1;
2788
2789 dataword = kmalloc(sizeof(u16) * (last_word - first_word + 1),
2790 GFP_KERNEL);
2791 if (!dataword)
2792 return -ENOMEM;
2793
2794 /* Read EEPROM block, SFF-8079/SFF-8472, word at a time */
2795 for (i = 0; i < last_word - first_word + 1; i++) {
2796 status = igb_read_phy_reg_i2c(hw, first_word + i, &dataword[i]);
Christian Engelmayerdb41b872014-03-21 03:25:30 -07002797 if (status != E1000_SUCCESS) {
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00002798 /* Error occurred while reading module */
Christian Engelmayerdb41b872014-03-21 03:25:30 -07002799 kfree(dataword);
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00002800 return -EIO;
Christian Engelmayerdb41b872014-03-21 03:25:30 -07002801 }
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00002802
2803 be16_to_cpus(&dataword[i]);
2804 }
2805
2806 memcpy(data, (u8 *)dataword + (ee->offset & 1), ee->len);
2807 kfree(dataword);
2808
2809 return 0;
2810}
2811
Matthew Vicka79f4f82012-08-10 05:40:44 +00002812static int igb_ethtool_begin(struct net_device *netdev)
2813{
2814 struct igb_adapter *adapter = netdev_priv(netdev);
2815 pm_runtime_get_sync(&adapter->pdev->dev);
2816 return 0;
2817}
2818
2819static void igb_ethtool_complete(struct net_device *netdev)
2820{
2821 struct igb_adapter *adapter = netdev_priv(netdev);
2822 pm_runtime_put(&adapter->pdev->dev);
2823}
2824
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00002825static u32 igb_get_rxfh_indir_size(struct net_device *netdev)
2826{
2827 return IGB_RETA_SIZE;
2828}
2829
2830static int igb_get_rxfh_indir(struct net_device *netdev, u32 *indir)
2831{
2832 struct igb_adapter *adapter = netdev_priv(netdev);
2833 int i;
2834
2835 for (i = 0; i < IGB_RETA_SIZE; i++)
2836 indir[i] = adapter->rss_indir_tbl[i];
2837
2838 return 0;
2839}
2840
2841void igb_write_rss_indir_tbl(struct igb_adapter *adapter)
2842{
2843 struct e1000_hw *hw = &adapter->hw;
2844 u32 reg = E1000_RETA(0);
2845 u32 shift = 0;
2846 int i = 0;
2847
2848 switch (hw->mac.type) {
2849 case e1000_82575:
2850 shift = 6;
2851 break;
2852 case e1000_82576:
2853 /* 82576 supports 2 RSS queues for SR-IOV */
2854 if (adapter->vfs_allocated_count)
2855 shift = 3;
2856 break;
2857 default:
2858 break;
2859 }
2860
2861 while (i < IGB_RETA_SIZE) {
2862 u32 val = 0;
2863 int j;
2864
2865 for (j = 3; j >= 0; j--) {
2866 val <<= 8;
2867 val |= adapter->rss_indir_tbl[i + j];
2868 }
2869
2870 wr32(reg, val << shift);
2871 reg += 4;
2872 i += 4;
2873 }
2874}
2875
2876static int igb_set_rxfh_indir(struct net_device *netdev, const u32 *indir)
2877{
2878 struct igb_adapter *adapter = netdev_priv(netdev);
2879 struct e1000_hw *hw = &adapter->hw;
2880 int i;
2881 u32 num_queues;
2882
2883 num_queues = adapter->rss_queues;
2884
2885 switch (hw->mac.type) {
2886 case e1000_82576:
2887 /* 82576 supports 2 RSS queues for SR-IOV */
2888 if (adapter->vfs_allocated_count)
2889 num_queues = 2;
2890 break;
2891 default:
2892 break;
2893 }
2894
2895 /* Verify user input. */
2896 for (i = 0; i < IGB_RETA_SIZE; i++)
2897 if (indir[i] >= num_queues)
2898 return -EINVAL;
2899
2900
2901 for (i = 0; i < IGB_RETA_SIZE; i++)
2902 adapter->rss_indir_tbl[i] = indir[i];
2903
2904 igb_write_rss_indir_tbl(adapter);
2905
2906 return 0;
2907}
2908
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07002909static unsigned int igb_max_channels(struct igb_adapter *adapter)
2910{
2911 struct e1000_hw *hw = &adapter->hw;
2912 unsigned int max_combined = 0;
2913
2914 switch (hw->mac.type) {
2915 case e1000_i211:
2916 max_combined = IGB_MAX_RX_QUEUES_I211;
2917 break;
2918 case e1000_82575:
2919 case e1000_i210:
2920 max_combined = IGB_MAX_RX_QUEUES_82575;
2921 break;
2922 case e1000_i350:
2923 if (!!adapter->vfs_allocated_count) {
2924 max_combined = 1;
2925 break;
2926 }
2927 /* fall through */
2928 case e1000_82576:
2929 if (!!adapter->vfs_allocated_count) {
2930 max_combined = 2;
2931 break;
2932 }
2933 /* fall through */
2934 case e1000_82580:
2935 case e1000_i354:
2936 default:
2937 max_combined = IGB_MAX_RX_QUEUES;
2938 break;
2939 }
2940
2941 return max_combined;
2942}
2943
2944static void igb_get_channels(struct net_device *netdev,
2945 struct ethtool_channels *ch)
2946{
2947 struct igb_adapter *adapter = netdev_priv(netdev);
2948
2949 /* Report maximum channels */
2950 ch->max_combined = igb_max_channels(adapter);
2951
2952 /* Report info for other vector */
Carolyn Wybornycd14ef52013-12-10 07:58:34 +00002953 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07002954 ch->max_other = NON_Q_VECTORS;
2955 ch->other_count = NON_Q_VECTORS;
2956 }
2957
2958 ch->combined_count = adapter->rss_queues;
2959}
2960
2961static int igb_set_channels(struct net_device *netdev,
2962 struct ethtool_channels *ch)
2963{
2964 struct igb_adapter *adapter = netdev_priv(netdev);
2965 unsigned int count = ch->combined_count;
2966
2967 /* Verify they are not requesting separate vectors */
2968 if (!count || ch->rx_count || ch->tx_count)
2969 return -EINVAL;
2970
2971 /* Verify other_count is valid and has not been changed */
2972 if (ch->other_count != NON_Q_VECTORS)
2973 return -EINVAL;
2974
2975 /* Verify the number of channels doesn't exceed hw limits */
2976 if (count > igb_max_channels(adapter))
2977 return -EINVAL;
2978
2979 if (count != adapter->rss_queues) {
2980 adapter->rss_queues = count;
2981
2982 /* Hardware has to reinitialize queues and interrupts to
2983 * match the new configuration.
2984 */
2985 return igb_reinit_queues(adapter);
2986 }
2987
2988 return 0;
2989}
2990
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07002991static const struct ethtool_ops igb_ethtool_ops = {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002992 .get_settings = igb_get_settings,
2993 .set_settings = igb_set_settings,
2994 .get_drvinfo = igb_get_drvinfo,
2995 .get_regs_len = igb_get_regs_len,
2996 .get_regs = igb_get_regs,
2997 .get_wol = igb_get_wol,
2998 .set_wol = igb_set_wol,
2999 .get_msglevel = igb_get_msglevel,
3000 .set_msglevel = igb_set_msglevel,
3001 .nway_reset = igb_nway_reset,
3002 .get_link = igb_get_link,
3003 .get_eeprom_len = igb_get_eeprom_len,
3004 .get_eeprom = igb_get_eeprom,
3005 .set_eeprom = igb_set_eeprom,
3006 .get_ringparam = igb_get_ringparam,
3007 .set_ringparam = igb_set_ringparam,
3008 .get_pauseparam = igb_get_pauseparam,
3009 .set_pauseparam = igb_set_pauseparam,
3010 .self_test = igb_diag_test,
3011 .get_strings = igb_get_strings,
3012 .set_phys_id = igb_set_phys_id,
3013 .get_sset_count = igb_get_sset_count,
3014 .get_ethtool_stats = igb_get_ethtool_stats,
3015 .get_coalesce = igb_get_coalesce,
3016 .set_coalesce = igb_set_coalesce,
3017 .get_ts_info = igb_get_ts_info,
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00003018 .get_rxnfc = igb_get_rxnfc,
3019 .set_rxnfc = igb_set_rxnfc,
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003020 .get_eee = igb_get_eee,
3021 .set_eee = igb_set_eee,
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00003022 .get_module_info = igb_get_module_info,
3023 .get_module_eeprom = igb_get_module_eeprom,
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00003024 .get_rxfh_indir_size = igb_get_rxfh_indir_size,
3025 .get_rxfh_indir = igb_get_rxfh_indir,
3026 .set_rxfh_indir = igb_set_rxfh_indir,
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07003027 .get_channels = igb_get_channels,
3028 .set_channels = igb_set_channels,
Yan, Zheng749ab2c2012-01-04 20:23:37 +00003029 .begin = igb_ethtool_begin,
3030 .complete = igb_ethtool_complete,
Auke Kok9d5c8242008-01-24 02:22:38 -08003031};
3032
3033void igb_set_ethtool_ops(struct net_device *netdev)
3034{
3035 SET_ETHTOOL_OPS(netdev, &igb_ethtool_ops);
3036}