blob: 2529bc625de4532e78407500d4c43ba92714f06a [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;
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200144 u32 speed;
Auke Kok9d5c8242008-01-24 02:22:38 -0800145
Carolyn Wyborny01237132013-11-09 04:52:14 -0800146 status = rd32(E1000_STATUS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800147 if (hw->phy.media_type == e1000_media_type_copper) {
148
149 ecmd->supported = (SUPPORTED_10baseT_Half |
150 SUPPORTED_10baseT_Full |
151 SUPPORTED_100baseT_Half |
152 SUPPORTED_100baseT_Full |
153 SUPPORTED_1000baseT_Full|
154 SUPPORTED_Autoneg |
Akeem G. Abodunrin42f3c432012-08-17 03:35:07 +0000155 SUPPORTED_TP |
156 SUPPORTED_Pause);
157 ecmd->advertising = ADVERTISED_TP;
Auke Kok9d5c8242008-01-24 02:22:38 -0800158
159 if (hw->mac.autoneg == 1) {
160 ecmd->advertising |= ADVERTISED_Autoneg;
161 /* the e1000 autoneg seems to match ethtool nicely */
162 ecmd->advertising |= hw->phy.autoneg_advertised;
163 }
164
165 ecmd->port = PORT_TP;
166 ecmd->phy_address = hw->phy.addr;
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000167 ecmd->transceiver = XCVR_INTERNAL;
Auke Kok9d5c8242008-01-24 02:22:38 -0800168 } else {
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000169 ecmd->supported = (SUPPORTED_FIBRE |
Carolyn Wyborny01237132013-11-09 04:52:14 -0800170 SUPPORTED_1000baseKX_Full |
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000171 SUPPORTED_Autoneg |
172 SUPPORTED_Pause);
Carolyn Wyborny01237132013-11-09 04:52:14 -0800173 ecmd->advertising = (ADVERTISED_FIBRE |
174 ADVERTISED_1000baseKX_Full);
175 if (hw->mac.type == e1000_i354) {
176 if ((hw->device_id ==
177 E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) &&
178 !(status & E1000_STATUS_2P5_SKU_OVER)) {
179 ecmd->supported |= SUPPORTED_2500baseX_Full;
180 ecmd->supported &=
181 ~SUPPORTED_1000baseKX_Full;
182 ecmd->advertising |= ADVERTISED_2500baseX_Full;
183 ecmd->advertising &=
184 ~ADVERTISED_1000baseKX_Full;
185 }
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000186 }
187 if (eth_flags->e100_base_fx) {
188 ecmd->supported |= SUPPORTED_100baseT_Full;
189 ecmd->advertising |= ADVERTISED_100baseT_Full;
190 }
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000191 if (hw->mac.autoneg == 1)
192 ecmd->advertising |= ADVERTISED_Autoneg;
Auke Kok9d5c8242008-01-24 02:22:38 -0800193
194 ecmd->port = PORT_FIBRE;
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000195 ecmd->transceiver = XCVR_EXTERNAL;
Auke Kok9d5c8242008-01-24 02:22:38 -0800196 }
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000197 if (hw->mac.autoneg != 1)
198 ecmd->advertising &= ~(ADVERTISED_Pause |
199 ADVERTISED_Asym_Pause);
200
Carolyn Wyborny01237132013-11-09 04:52:14 -0800201 switch (hw->fc.requested_mode) {
202 case e1000_fc_full:
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000203 ecmd->advertising |= ADVERTISED_Pause;
Carolyn Wyborny01237132013-11-09 04:52:14 -0800204 break;
205 case e1000_fc_rx_pause:
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000206 ecmd->advertising |= (ADVERTISED_Pause |
207 ADVERTISED_Asym_Pause);
Carolyn Wyborny01237132013-11-09 04:52:14 -0800208 break;
209 case e1000_fc_tx_pause:
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000210 ecmd->advertising |= ADVERTISED_Asym_Pause;
Carolyn Wyborny01237132013-11-09 04:52:14 -0800211 break;
212 default:
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000213 ecmd->advertising &= ~(ADVERTISED_Pause |
214 ADVERTISED_Asym_Pause);
Carolyn Wyborny01237132013-11-09 04:52:14 -0800215 }
Alexander Duyck317f66b2009-10-27 23:46:20 +0000216 if (status & E1000_STATUS_LU) {
Carolyn Wyborny01237132013-11-09 04:52:14 -0800217 if ((status & E1000_STATUS_2P5_SKU) &&
218 !(status & E1000_STATUS_2P5_SKU_OVER)) {
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200219 speed = SPEED_2500;
Akeem G Abodunrin41fcfbe2013-08-30 23:49:36 +0000220 } else if (status & E1000_STATUS_SPEED_1000) {
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200221 speed = SPEED_1000;
Akeem G Abodunrin41fcfbe2013-08-30 23:49:36 +0000222 } else if (status & E1000_STATUS_SPEED_100) {
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200223 speed = SPEED_100;
Akeem G Abodunrin41fcfbe2013-08-30 23:49:36 +0000224 } else {
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200225 speed = SPEED_10;
Akeem G Abodunrin41fcfbe2013-08-30 23:49:36 +0000226 }
Alexander Duyck317f66b2009-10-27 23:46:20 +0000227 if ((status & E1000_STATUS_FD) ||
228 hw->phy.media_type != e1000_media_type_copper)
Auke Kok9d5c8242008-01-24 02:22:38 -0800229 ecmd->duplex = DUPLEX_FULL;
230 else
231 ecmd->duplex = DUPLEX_HALF;
232 } else {
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200233 speed = SPEED_UNKNOWN;
Jiri Pirko537fae02014-06-06 14:17:00 +0200234 ecmd->duplex = DUPLEX_UNKNOWN;
Auke Kok9d5c8242008-01-24 02:22:38 -0800235 }
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200236 ethtool_cmd_speed_set(ecmd, speed);
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000237 if ((hw->phy.media_type == e1000_media_type_fiber) ||
238 hw->mac.autoneg)
239 ecmd->autoneg = AUTONEG_ENABLE;
240 else
241 ecmd->autoneg = AUTONEG_DISABLE;
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000242
243 /* MDI-X => 2; MDI =>1; Invalid =>0 */
244 if (hw->phy.media_type == e1000_media_type_copper)
245 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
246 ETH_TP_MDI;
247 else
248 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
249
250 if (hw->phy.mdix == AUTO_ALL_MODES)
251 ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
252 else
253 ecmd->eth_tp_mdix_ctrl = hw->phy.mdix;
254
Auke Kok9d5c8242008-01-24 02:22:38 -0800255 return 0;
256}
257
258static int igb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
259{
260 struct igb_adapter *adapter = netdev_priv(netdev);
261 struct e1000_hw *hw = &adapter->hw;
262
263 /* When SoL/IDER sessions are active, autoneg/speed/duplex
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000264 * cannot be changed
265 */
Auke Kok9d5c8242008-01-24 02:22:38 -0800266 if (igb_check_reset_block(hw)) {
Jesper Juhld836200a2012-08-01 05:41:30 +0000267 dev_err(&adapter->pdev->dev,
268 "Cannot change link characteristics when SoL/IDER is active.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800269 return -EINVAL;
270 }
271
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000272 /* MDI setting is only allowed when autoneg enabled because
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000273 * some hardware doesn't allow MDI setting when speed or
274 * duplex is forced.
275 */
276 if (ecmd->eth_tp_mdix_ctrl) {
277 if (hw->phy.media_type != e1000_media_type_copper)
278 return -EOPNOTSUPP;
279
280 if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
281 (ecmd->autoneg != AUTONEG_ENABLE)) {
282 dev_err(&adapter->pdev->dev, "forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
283 return -EINVAL;
284 }
285 }
286
Auke Kok9d5c8242008-01-24 02:22:38 -0800287 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
Carolyn Wyborny0d451e72014-04-11 01:46:40 +0000288 usleep_range(1000, 2000);
Auke Kok9d5c8242008-01-24 02:22:38 -0800289
290 if (ecmd->autoneg == AUTONEG_ENABLE) {
291 hw->mac.autoneg = 1;
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000292 if (hw->phy.media_type == e1000_media_type_fiber) {
293 hw->phy.autoneg_advertised = ecmd->advertising |
294 ADVERTISED_FIBRE |
295 ADVERTISED_Autoneg;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000296 switch (adapter->link_speed) {
297 case SPEED_2500:
298 hw->phy.autoneg_advertised =
299 ADVERTISED_2500baseX_Full;
300 break;
301 case SPEED_1000:
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000302 hw->phy.autoneg_advertised =
303 ADVERTISED_1000baseT_Full;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000304 break;
305 case SPEED_100:
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000306 hw->phy.autoneg_advertised =
307 ADVERTISED_100baseT_Full;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000308 break;
309 default:
310 break;
311 }
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000312 } else {
313 hw->phy.autoneg_advertised = ecmd->advertising |
314 ADVERTISED_TP |
315 ADVERTISED_Autoneg;
316 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800317 ecmd->advertising = hw->phy.autoneg_advertised;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000318 if (adapter->fc_autoneg)
319 hw->fc.requested_mode = e1000_fc_default;
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000320 } else {
David Decotigny25db0332011-04-27 18:32:39 +0000321 u32 speed = ethtool_cmd_speed(ecmd);
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000322 /* calling this overrides forced MDI setting */
David Decotigny14ad2512011-04-27 18:32:43 +0000323 if (igb_set_spd_dplx(adapter, speed, ecmd->duplex)) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800324 clear_bit(__IGB_RESETTING, &adapter->state);
325 return -EINVAL;
326 }
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000327 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800328
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000329 /* MDI-X => 2; MDI => 1; Auto => 3 */
330 if (ecmd->eth_tp_mdix_ctrl) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000331 /* fix up the value for auto (3 => 0) as zero is mapped
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000332 * internally to auto
333 */
334 if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
335 hw->phy.mdix = AUTO_ALL_MODES;
336 else
337 hw->phy.mdix = ecmd->eth_tp_mdix_ctrl;
338 }
339
Auke Kok9d5c8242008-01-24 02:22:38 -0800340 /* reset the link */
Auke Kok9d5c8242008-01-24 02:22:38 -0800341 if (netif_running(adapter->netdev)) {
342 igb_down(adapter);
343 igb_up(adapter);
344 } else
345 igb_reset(adapter);
346
347 clear_bit(__IGB_RESETTING, &adapter->state);
348 return 0;
349}
350
Nick Nunley31455352010-02-17 01:01:21 +0000351static u32 igb_get_link(struct net_device *netdev)
352{
353 struct igb_adapter *adapter = netdev_priv(netdev);
354 struct e1000_mac_info *mac = &adapter->hw.mac;
355
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000356 /* If the link is not reported up to netdev, interrupts are disabled,
Nick Nunley31455352010-02-17 01:01:21 +0000357 * and so the physical link state may have changed since we last
358 * looked. Set get_link_status to make sure that the true link
359 * state is interrogated, rather than pulling a cached and possibly
360 * stale link state from the driver.
361 */
362 if (!netif_carrier_ok(netdev))
363 mac->get_link_status = 1;
364
365 return igb_has_link(adapter);
366}
367
Auke Kok9d5c8242008-01-24 02:22:38 -0800368static void igb_get_pauseparam(struct net_device *netdev,
369 struct ethtool_pauseparam *pause)
370{
371 struct igb_adapter *adapter = netdev_priv(netdev);
372 struct e1000_hw *hw = &adapter->hw;
373
374 pause->autoneg =
375 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
376
Alexander Duyck0cce1192009-07-23 18:10:24 +0000377 if (hw->fc.current_mode == e1000_fc_rx_pause)
Auke Kok9d5c8242008-01-24 02:22:38 -0800378 pause->rx_pause = 1;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000379 else if (hw->fc.current_mode == e1000_fc_tx_pause)
Auke Kok9d5c8242008-01-24 02:22:38 -0800380 pause->tx_pause = 1;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000381 else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800382 pause->rx_pause = 1;
383 pause->tx_pause = 1;
384 }
385}
386
387static int igb_set_pauseparam(struct net_device *netdev,
388 struct ethtool_pauseparam *pause)
389{
390 struct igb_adapter *adapter = netdev_priv(netdev);
391 struct e1000_hw *hw = &adapter->hw;
392 int retval = 0;
393
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000394 /* 100basefx does not support setting link flow control */
395 if (hw->dev_spec._82575.eth_flags.e100_base_fx)
396 return -EINVAL;
397
Auke Kok9d5c8242008-01-24 02:22:38 -0800398 adapter->fc_autoneg = pause->autoneg;
399
400 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
Carolyn Wyborny0d451e72014-04-11 01:46:40 +0000401 usleep_range(1000, 2000);
Auke Kok9d5c8242008-01-24 02:22:38 -0800402
Auke Kok9d5c8242008-01-24 02:22:38 -0800403 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000404 hw->fc.requested_mode = e1000_fc_default;
Auke Kok9d5c8242008-01-24 02:22:38 -0800405 if (netif_running(adapter->netdev)) {
406 igb_down(adapter);
407 igb_up(adapter);
Alexander Duyck317f66b2009-10-27 23:46:20 +0000408 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -0800409 igb_reset(adapter);
Alexander Duyck317f66b2009-10-27 23:46:20 +0000410 }
Alexander Duyck0cce1192009-07-23 18:10:24 +0000411 } else {
412 if (pause->rx_pause && pause->tx_pause)
413 hw->fc.requested_mode = e1000_fc_full;
414 else if (pause->rx_pause && !pause->tx_pause)
415 hw->fc.requested_mode = e1000_fc_rx_pause;
416 else if (!pause->rx_pause && pause->tx_pause)
417 hw->fc.requested_mode = e1000_fc_tx_pause;
418 else if (!pause->rx_pause && !pause->tx_pause)
419 hw->fc.requested_mode = e1000_fc_none;
420
421 hw->fc.current_mode = hw->fc.requested_mode;
422
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000423 retval = ((hw->phy.media_type == e1000_media_type_copper) ?
424 igb_force_mac_fc(hw) : igb_setup_link(hw));
Alexander Duyck0cce1192009-07-23 18:10:24 +0000425 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800426
427 clear_bit(__IGB_RESETTING, &adapter->state);
428 return retval;
429}
430
Auke Kok9d5c8242008-01-24 02:22:38 -0800431static u32 igb_get_msglevel(struct net_device *netdev)
432{
433 struct igb_adapter *adapter = netdev_priv(netdev);
434 return adapter->msg_enable;
435}
436
437static void igb_set_msglevel(struct net_device *netdev, u32 data)
438{
439 struct igb_adapter *adapter = netdev_priv(netdev);
440 adapter->msg_enable = data;
441}
442
443static int igb_get_regs_len(struct net_device *netdev)
444{
Koki Sanagi7e3b4ff2012-02-15 14:45:39 +0000445#define IGB_REGS_LEN 739
Auke Kok9d5c8242008-01-24 02:22:38 -0800446 return IGB_REGS_LEN * sizeof(u32);
447}
448
449static void igb_get_regs(struct net_device *netdev,
450 struct ethtool_regs *regs, void *p)
451{
452 struct igb_adapter *adapter = netdev_priv(netdev);
453 struct e1000_hw *hw = &adapter->hw;
454 u32 *regs_buff = p;
455 u8 i;
456
457 memset(p, 0, IGB_REGS_LEN * sizeof(u32));
458
459 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
460
461 /* General Registers */
462 regs_buff[0] = rd32(E1000_CTRL);
463 regs_buff[1] = rd32(E1000_STATUS);
464 regs_buff[2] = rd32(E1000_CTRL_EXT);
465 regs_buff[3] = rd32(E1000_MDIC);
466 regs_buff[4] = rd32(E1000_SCTL);
467 regs_buff[5] = rd32(E1000_CONNSW);
468 regs_buff[6] = rd32(E1000_VET);
469 regs_buff[7] = rd32(E1000_LEDCTL);
470 regs_buff[8] = rd32(E1000_PBA);
471 regs_buff[9] = rd32(E1000_PBS);
472 regs_buff[10] = rd32(E1000_FRTIMER);
473 regs_buff[11] = rd32(E1000_TCPTIMER);
474
475 /* NVM Register */
476 regs_buff[12] = rd32(E1000_EECD);
477
478 /* Interrupt */
Alexander Duyckfe59de32008-08-26 04:25:05 -0700479 /* Reading EICS for EICR because they read the
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000480 * same but EICS does not clear on read
481 */
Alexander Duyckfe59de32008-08-26 04:25:05 -0700482 regs_buff[13] = rd32(E1000_EICS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800483 regs_buff[14] = rd32(E1000_EICS);
484 regs_buff[15] = rd32(E1000_EIMS);
485 regs_buff[16] = rd32(E1000_EIMC);
486 regs_buff[17] = rd32(E1000_EIAC);
487 regs_buff[18] = rd32(E1000_EIAM);
Alexander Duyckfe59de32008-08-26 04:25:05 -0700488 /* Reading ICS for ICR because they read the
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000489 * same but ICS does not clear on read
490 */
Alexander Duyckfe59de32008-08-26 04:25:05 -0700491 regs_buff[19] = rd32(E1000_ICS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800492 regs_buff[20] = rd32(E1000_ICS);
493 regs_buff[21] = rd32(E1000_IMS);
494 regs_buff[22] = rd32(E1000_IMC);
495 regs_buff[23] = rd32(E1000_IAC);
496 regs_buff[24] = rd32(E1000_IAM);
497 regs_buff[25] = rd32(E1000_IMIRVP);
498
499 /* Flow Control */
500 regs_buff[26] = rd32(E1000_FCAL);
501 regs_buff[27] = rd32(E1000_FCAH);
502 regs_buff[28] = rd32(E1000_FCTTV);
503 regs_buff[29] = rd32(E1000_FCRTL);
504 regs_buff[30] = rd32(E1000_FCRTH);
505 regs_buff[31] = rd32(E1000_FCRTV);
506
507 /* Receive */
508 regs_buff[32] = rd32(E1000_RCTL);
509 regs_buff[33] = rd32(E1000_RXCSUM);
510 regs_buff[34] = rd32(E1000_RLPML);
511 regs_buff[35] = rd32(E1000_RFCTL);
512 regs_buff[36] = rd32(E1000_MRQC);
Alexander Duycke1739522009-02-19 20:39:44 -0800513 regs_buff[37] = rd32(E1000_VT_CTL);
Auke Kok9d5c8242008-01-24 02:22:38 -0800514
515 /* Transmit */
516 regs_buff[38] = rd32(E1000_TCTL);
517 regs_buff[39] = rd32(E1000_TCTL_EXT);
518 regs_buff[40] = rd32(E1000_TIPG);
519 regs_buff[41] = rd32(E1000_DTXCTL);
520
521 /* Wake Up */
522 regs_buff[42] = rd32(E1000_WUC);
523 regs_buff[43] = rd32(E1000_WUFC);
524 regs_buff[44] = rd32(E1000_WUS);
525 regs_buff[45] = rd32(E1000_IPAV);
526 regs_buff[46] = rd32(E1000_WUPL);
527
528 /* MAC */
529 regs_buff[47] = rd32(E1000_PCS_CFG0);
530 regs_buff[48] = rd32(E1000_PCS_LCTL);
531 regs_buff[49] = rd32(E1000_PCS_LSTAT);
532 regs_buff[50] = rd32(E1000_PCS_ANADV);
533 regs_buff[51] = rd32(E1000_PCS_LPAB);
534 regs_buff[52] = rd32(E1000_PCS_NPTX);
535 regs_buff[53] = rd32(E1000_PCS_LPABNP);
536
537 /* Statistics */
538 regs_buff[54] = adapter->stats.crcerrs;
539 regs_buff[55] = adapter->stats.algnerrc;
540 regs_buff[56] = adapter->stats.symerrs;
541 regs_buff[57] = adapter->stats.rxerrc;
542 regs_buff[58] = adapter->stats.mpc;
543 regs_buff[59] = adapter->stats.scc;
544 regs_buff[60] = adapter->stats.ecol;
545 regs_buff[61] = adapter->stats.mcc;
546 regs_buff[62] = adapter->stats.latecol;
547 regs_buff[63] = adapter->stats.colc;
548 regs_buff[64] = adapter->stats.dc;
549 regs_buff[65] = adapter->stats.tncrs;
550 regs_buff[66] = adapter->stats.sec;
551 regs_buff[67] = adapter->stats.htdpmc;
552 regs_buff[68] = adapter->stats.rlec;
553 regs_buff[69] = adapter->stats.xonrxc;
554 regs_buff[70] = adapter->stats.xontxc;
555 regs_buff[71] = adapter->stats.xoffrxc;
556 regs_buff[72] = adapter->stats.xofftxc;
557 regs_buff[73] = adapter->stats.fcruc;
558 regs_buff[74] = adapter->stats.prc64;
559 regs_buff[75] = adapter->stats.prc127;
560 regs_buff[76] = adapter->stats.prc255;
561 regs_buff[77] = adapter->stats.prc511;
562 regs_buff[78] = adapter->stats.prc1023;
563 regs_buff[79] = adapter->stats.prc1522;
564 regs_buff[80] = adapter->stats.gprc;
565 regs_buff[81] = adapter->stats.bprc;
566 regs_buff[82] = adapter->stats.mprc;
567 regs_buff[83] = adapter->stats.gptc;
568 regs_buff[84] = adapter->stats.gorc;
569 regs_buff[86] = adapter->stats.gotc;
570 regs_buff[88] = adapter->stats.rnbc;
571 regs_buff[89] = adapter->stats.ruc;
572 regs_buff[90] = adapter->stats.rfc;
573 regs_buff[91] = adapter->stats.roc;
574 regs_buff[92] = adapter->stats.rjc;
575 regs_buff[93] = adapter->stats.mgprc;
576 regs_buff[94] = adapter->stats.mgpdc;
577 regs_buff[95] = adapter->stats.mgptc;
578 regs_buff[96] = adapter->stats.tor;
579 regs_buff[98] = adapter->stats.tot;
580 regs_buff[100] = adapter->stats.tpr;
581 regs_buff[101] = adapter->stats.tpt;
582 regs_buff[102] = adapter->stats.ptc64;
583 regs_buff[103] = adapter->stats.ptc127;
584 regs_buff[104] = adapter->stats.ptc255;
585 regs_buff[105] = adapter->stats.ptc511;
586 regs_buff[106] = adapter->stats.ptc1023;
587 regs_buff[107] = adapter->stats.ptc1522;
588 regs_buff[108] = adapter->stats.mptc;
589 regs_buff[109] = adapter->stats.bptc;
590 regs_buff[110] = adapter->stats.tsctc;
591 regs_buff[111] = adapter->stats.iac;
592 regs_buff[112] = adapter->stats.rpthc;
593 regs_buff[113] = adapter->stats.hgptc;
594 regs_buff[114] = adapter->stats.hgorc;
595 regs_buff[116] = adapter->stats.hgotc;
596 regs_buff[118] = adapter->stats.lenerrs;
597 regs_buff[119] = adapter->stats.scvpc;
598 regs_buff[120] = adapter->stats.hrmpc;
599
Auke Kok9d5c8242008-01-24 02:22:38 -0800600 for (i = 0; i < 4; i++)
601 regs_buff[121 + i] = rd32(E1000_SRRCTL(i));
602 for (i = 0; i < 4; i++)
Alexander Duyck83ab50a2009-10-27 15:55:41 +0000603 regs_buff[125 + i] = rd32(E1000_PSRTYPE(i));
Auke Kok9d5c8242008-01-24 02:22:38 -0800604 for (i = 0; i < 4; i++)
605 regs_buff[129 + i] = rd32(E1000_RDBAL(i));
606 for (i = 0; i < 4; i++)
607 regs_buff[133 + i] = rd32(E1000_RDBAH(i));
608 for (i = 0; i < 4; i++)
609 regs_buff[137 + i] = rd32(E1000_RDLEN(i));
610 for (i = 0; i < 4; i++)
611 regs_buff[141 + i] = rd32(E1000_RDH(i));
612 for (i = 0; i < 4; i++)
613 regs_buff[145 + i] = rd32(E1000_RDT(i));
614 for (i = 0; i < 4; i++)
615 regs_buff[149 + i] = rd32(E1000_RXDCTL(i));
616
617 for (i = 0; i < 10; i++)
618 regs_buff[153 + i] = rd32(E1000_EITR(i));
619 for (i = 0; i < 8; i++)
620 regs_buff[163 + i] = rd32(E1000_IMIR(i));
621 for (i = 0; i < 8; i++)
622 regs_buff[171 + i] = rd32(E1000_IMIREXT(i));
623 for (i = 0; i < 16; i++)
624 regs_buff[179 + i] = rd32(E1000_RAL(i));
625 for (i = 0; i < 16; i++)
626 regs_buff[195 + i] = rd32(E1000_RAH(i));
627
628 for (i = 0; i < 4; i++)
629 regs_buff[211 + i] = rd32(E1000_TDBAL(i));
630 for (i = 0; i < 4; i++)
631 regs_buff[215 + i] = rd32(E1000_TDBAH(i));
632 for (i = 0; i < 4; i++)
633 regs_buff[219 + i] = rd32(E1000_TDLEN(i));
634 for (i = 0; i < 4; i++)
635 regs_buff[223 + i] = rd32(E1000_TDH(i));
636 for (i = 0; i < 4; i++)
637 regs_buff[227 + i] = rd32(E1000_TDT(i));
638 for (i = 0; i < 4; i++)
639 regs_buff[231 + i] = rd32(E1000_TXDCTL(i));
640 for (i = 0; i < 4; i++)
641 regs_buff[235 + i] = rd32(E1000_TDWBAL(i));
642 for (i = 0; i < 4; i++)
643 regs_buff[239 + i] = rd32(E1000_TDWBAH(i));
644 for (i = 0; i < 4; i++)
645 regs_buff[243 + i] = rd32(E1000_DCA_TXCTRL(i));
646
647 for (i = 0; i < 4; i++)
648 regs_buff[247 + i] = rd32(E1000_IP4AT_REG(i));
649 for (i = 0; i < 4; i++)
650 regs_buff[251 + i] = rd32(E1000_IP6AT_REG(i));
651 for (i = 0; i < 32; i++)
652 regs_buff[255 + i] = rd32(E1000_WUPM_REG(i));
653 for (i = 0; i < 128; i++)
654 regs_buff[287 + i] = rd32(E1000_FFMT_REG(i));
655 for (i = 0; i < 128; i++)
656 regs_buff[415 + i] = rd32(E1000_FFVT_REG(i));
657 for (i = 0; i < 4; i++)
658 regs_buff[543 + i] = rd32(E1000_FFLT_REG(i));
659
660 regs_buff[547] = rd32(E1000_TDFH);
661 regs_buff[548] = rd32(E1000_TDFT);
662 regs_buff[549] = rd32(E1000_TDFHS);
663 regs_buff[550] = rd32(E1000_TDFPC);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000664
665 if (hw->mac.type > e1000_82580) {
666 regs_buff[551] = adapter->stats.o2bgptc;
667 regs_buff[552] = adapter->stats.b2ospc;
668 regs_buff[553] = adapter->stats.o2bspc;
669 regs_buff[554] = adapter->stats.b2ogprc;
670 }
Koki Sanagi7e3b4ff2012-02-15 14:45:39 +0000671
672 if (hw->mac.type != e1000_82576)
673 return;
674 for (i = 0; i < 12; i++)
675 regs_buff[555 + i] = rd32(E1000_SRRCTL(i + 4));
676 for (i = 0; i < 4; i++)
677 regs_buff[567 + i] = rd32(E1000_PSRTYPE(i + 4));
678 for (i = 0; i < 12; i++)
679 regs_buff[571 + i] = rd32(E1000_RDBAL(i + 4));
680 for (i = 0; i < 12; i++)
681 regs_buff[583 + i] = rd32(E1000_RDBAH(i + 4));
682 for (i = 0; i < 12; i++)
683 regs_buff[595 + i] = rd32(E1000_RDLEN(i + 4));
684 for (i = 0; i < 12; i++)
685 regs_buff[607 + i] = rd32(E1000_RDH(i + 4));
686 for (i = 0; i < 12; i++)
687 regs_buff[619 + i] = rd32(E1000_RDT(i + 4));
688 for (i = 0; i < 12; i++)
689 regs_buff[631 + i] = rd32(E1000_RXDCTL(i + 4));
690
691 for (i = 0; i < 12; i++)
692 regs_buff[643 + i] = rd32(E1000_TDBAL(i + 4));
693 for (i = 0; i < 12; i++)
694 regs_buff[655 + i] = rd32(E1000_TDBAH(i + 4));
695 for (i = 0; i < 12; i++)
696 regs_buff[667 + i] = rd32(E1000_TDLEN(i + 4));
697 for (i = 0; i < 12; i++)
698 regs_buff[679 + i] = rd32(E1000_TDH(i + 4));
699 for (i = 0; i < 12; i++)
700 regs_buff[691 + i] = rd32(E1000_TDT(i + 4));
701 for (i = 0; i < 12; i++)
702 regs_buff[703 + i] = rd32(E1000_TXDCTL(i + 4));
703 for (i = 0; i < 12; i++)
704 regs_buff[715 + i] = rd32(E1000_TDWBAL(i + 4));
705 for (i = 0; i < 12; i++)
706 regs_buff[727 + i] = rd32(E1000_TDWBAH(i + 4));
Auke Kok9d5c8242008-01-24 02:22:38 -0800707}
708
709static int igb_get_eeprom_len(struct net_device *netdev)
710{
711 struct igb_adapter *adapter = netdev_priv(netdev);
712 return adapter->hw.nvm.word_size * 2;
713}
714
715static int igb_get_eeprom(struct net_device *netdev,
716 struct ethtool_eeprom *eeprom, u8 *bytes)
717{
718 struct igb_adapter *adapter = netdev_priv(netdev);
719 struct e1000_hw *hw = &adapter->hw;
720 u16 *eeprom_buff;
721 int first_word, last_word;
722 int ret_val = 0;
723 u16 i;
724
725 if (eeprom->len == 0)
726 return -EINVAL;
727
728 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
729
730 first_word = eeprom->offset >> 1;
731 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
732
733 eeprom_buff = kmalloc(sizeof(u16) *
734 (last_word - first_word + 1), GFP_KERNEL);
735 if (!eeprom_buff)
736 return -ENOMEM;
737
738 if (hw->nvm.type == e1000_nvm_eeprom_spi)
Alexander Duyck312c75a2009-02-06 23:17:47 +0000739 ret_val = hw->nvm.ops.read(hw, first_word,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000740 last_word - first_word + 1,
741 eeprom_buff);
Auke Kok9d5c8242008-01-24 02:22:38 -0800742 else {
743 for (i = 0; i < last_word - first_word + 1; i++) {
Alexander Duyck312c75a2009-02-06 23:17:47 +0000744 ret_val = hw->nvm.ops.read(hw, first_word + i, 1,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000745 &eeprom_buff[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800746 if (ret_val)
747 break;
748 }
749 }
750
751 /* Device's eeprom is always little-endian, word addressable */
752 for (i = 0; i < last_word - first_word + 1; i++)
753 le16_to_cpus(&eeprom_buff[i]);
754
755 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
756 eeprom->len);
757 kfree(eeprom_buff);
758
759 return ret_val;
760}
761
762static int igb_set_eeprom(struct net_device *netdev,
763 struct ethtool_eeprom *eeprom, u8 *bytes)
764{
765 struct igb_adapter *adapter = netdev_priv(netdev);
766 struct e1000_hw *hw = &adapter->hw;
767 u16 *eeprom_buff;
768 void *ptr;
769 int max_len, first_word, last_word, ret_val = 0;
770 u16 i;
771
772 if (eeprom->len == 0)
773 return -EOPNOTSUPP;
774
Fujinaka, Todda71fc312013-10-23 05:52:11 +0000775 if ((hw->mac.type >= e1000_i210) &&
776 !igb_get_flash_presence_i210(hw)) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000777 return -EOPNOTSUPP;
Fujinaka, Todda71fc312013-10-23 05:52:11 +0000778 }
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000779
Auke Kok9d5c8242008-01-24 02:22:38 -0800780 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
781 return -EFAULT;
782
783 max_len = hw->nvm.word_size * 2;
784
785 first_word = eeprom->offset >> 1;
786 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
787 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
788 if (!eeprom_buff)
789 return -ENOMEM;
790
791 ptr = (void *)eeprom_buff;
792
793 if (eeprom->offset & 1) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000794 /* need read/modify/write of first changed EEPROM word
795 * only the second byte of the word is being modified
796 */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000797 ret_val = hw->nvm.ops.read(hw, first_word, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800798 &eeprom_buff[0]);
799 ptr++;
800 }
801 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000802 /* need read/modify/write of last changed EEPROM word
803 * only the first byte of the word is being modified
804 */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000805 ret_val = hw->nvm.ops.read(hw, last_word, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800806 &eeprom_buff[last_word - first_word]);
807 }
808
809 /* Device's eeprom is always little-endian, word addressable */
810 for (i = 0; i < last_word - first_word + 1; i++)
811 le16_to_cpus(&eeprom_buff[i]);
812
813 memcpy(ptr, bytes, eeprom->len);
814
815 for (i = 0; i < last_word - first_word + 1; i++)
816 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
817
Alexander Duyck312c75a2009-02-06 23:17:47 +0000818 ret_val = hw->nvm.ops.write(hw, first_word,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000819 last_word - first_word + 1, eeprom_buff);
Auke Kok9d5c8242008-01-24 02:22:38 -0800820
Carolyn Wyborny2a0a0f12013-04-25 17:22:34 +0000821 /* Update the checksum if nvm write succeeded */
822 if (ret_val == 0)
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800823 hw->nvm.ops.update(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800824
Carolyn Wybornyd67974f2012-06-14 16:04:19 +0000825 igb_set_fw_version(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800826 kfree(eeprom_buff);
827 return ret_val;
828}
829
830static void igb_get_drvinfo(struct net_device *netdev,
831 struct ethtool_drvinfo *drvinfo)
832{
833 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -0800834
Rick Jones612a94d2011-11-14 08:13:25 +0000835 strlcpy(drvinfo->driver, igb_driver_name, sizeof(drvinfo->driver));
836 strlcpy(drvinfo->version, igb_driver_version, sizeof(drvinfo->version));
Auke Kok9d5c8242008-01-24 02:22:38 -0800837
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000838 /* EEPROM image version # is reported as firmware version # for
Carolyn Wybornyd67974f2012-06-14 16:04:19 +0000839 * 82575 controllers
840 */
841 strlcpy(drvinfo->fw_version, adapter->fw_version,
842 sizeof(drvinfo->fw_version));
Rick Jones612a94d2011-11-14 08:13:25 +0000843 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
844 sizeof(drvinfo->bus_info));
Auke Kok9d5c8242008-01-24 02:22:38 -0800845}
846
847static void igb_get_ringparam(struct net_device *netdev,
848 struct ethtool_ringparam *ring)
849{
850 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -0800851
852 ring->rx_max_pending = IGB_MAX_RXD;
853 ring->tx_max_pending = IGB_MAX_TXD;
Alexander Duyck68fd9912008-11-20 00:48:10 -0800854 ring->rx_pending = adapter->rx_ring_count;
855 ring->tx_pending = adapter->tx_ring_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800856}
857
858static int igb_set_ringparam(struct net_device *netdev,
859 struct ethtool_ringparam *ring)
860{
861 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800862 struct igb_ring *temp_ring;
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000863 int i, err = 0;
Alexander Duyck0e15439a2009-11-12 18:36:41 +0000864 u16 new_rx_count, new_tx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800865
866 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
867 return -EINVAL;
868
Alexander Duyck0e15439a2009-11-12 18:36:41 +0000869 new_rx_count = min_t(u32, ring->rx_pending, IGB_MAX_RXD);
870 new_rx_count = max_t(u16, new_rx_count, IGB_MIN_RXD);
Auke Kok9d5c8242008-01-24 02:22:38 -0800871 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
872
Alexander Duyck0e15439a2009-11-12 18:36:41 +0000873 new_tx_count = min_t(u32, ring->tx_pending, IGB_MAX_TXD);
874 new_tx_count = max_t(u16, new_tx_count, IGB_MIN_TXD);
Auke Kok9d5c8242008-01-24 02:22:38 -0800875 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
876
Alexander Duyck68fd9912008-11-20 00:48:10 -0800877 if ((new_tx_count == adapter->tx_ring_count) &&
878 (new_rx_count == adapter->rx_ring_count)) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800879 /* nothing to do */
880 return 0;
881 }
882
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000883 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
Carolyn Wyborny0d451e72014-04-11 01:46:40 +0000884 usleep_range(1000, 2000);
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000885
886 if (!netif_running(adapter->netdev)) {
887 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +0000888 adapter->tx_ring[i]->count = new_tx_count;
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000889 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +0000890 adapter->rx_ring[i]->count = new_rx_count;
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000891 adapter->tx_ring_count = new_tx_count;
892 adapter->rx_ring_count = new_rx_count;
893 goto clear_reset;
894 }
895
Alexander Duyck68fd9912008-11-20 00:48:10 -0800896 if (adapter->num_tx_queues > adapter->num_rx_queues)
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000897 temp_ring = vmalloc(adapter->num_tx_queues *
898 sizeof(struct igb_ring));
Alexander Duyck68fd9912008-11-20 00:48:10 -0800899 else
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000900 temp_ring = vmalloc(adapter->num_rx_queues *
901 sizeof(struct igb_ring));
Alexander Duyck68fd9912008-11-20 00:48:10 -0800902
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000903 if (!temp_ring) {
904 err = -ENOMEM;
905 goto clear_reset;
906 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800907
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000908 igb_down(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800909
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000910 /* We can't just free everything and then setup again,
Auke Kok9d5c8242008-01-24 02:22:38 -0800911 * because the ISRs in MSI-X mode get passed pointers
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000912 * to the Tx and Rx ring structs.
Auke Kok9d5c8242008-01-24 02:22:38 -0800913 */
Alexander Duyck68fd9912008-11-20 00:48:10 -0800914 if (new_tx_count != adapter->tx_ring_count) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800915 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +0000916 memcpy(&temp_ring[i], adapter->tx_ring[i],
917 sizeof(struct igb_ring));
918
Alexander Duyck68fd9912008-11-20 00:48:10 -0800919 temp_ring[i].count = new_tx_count;
Alexander Duyck80785292009-10-27 15:51:47 +0000920 err = igb_setup_tx_resources(&temp_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800921 if (err) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800922 while (i) {
923 i--;
924 igb_free_tx_resources(&temp_ring[i]);
925 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800926 goto err_setup;
927 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800928 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800929
Alexander Duyck3025a442010-02-17 01:02:39 +0000930 for (i = 0; i < adapter->num_tx_queues; i++) {
931 igb_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800932
Alexander Duyck3025a442010-02-17 01:02:39 +0000933 memcpy(adapter->tx_ring[i], &temp_ring[i],
934 sizeof(struct igb_ring));
935 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800936
937 adapter->tx_ring_count = new_tx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800938 }
939
Alexander Duyck3025a442010-02-17 01:02:39 +0000940 if (new_rx_count != adapter->rx_ring_count) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800941 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +0000942 memcpy(&temp_ring[i], adapter->rx_ring[i],
943 sizeof(struct igb_ring));
944
Alexander Duyck68fd9912008-11-20 00:48:10 -0800945 temp_ring[i].count = new_rx_count;
Alexander Duyck80785292009-10-27 15:51:47 +0000946 err = igb_setup_rx_resources(&temp_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800947 if (err) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800948 while (i) {
949 i--;
950 igb_free_rx_resources(&temp_ring[i]);
951 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800952 goto err_setup;
953 }
954
Auke Kok9d5c8242008-01-24 02:22:38 -0800955 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800956
Alexander Duyck3025a442010-02-17 01:02:39 +0000957 for (i = 0; i < adapter->num_rx_queues; i++) {
958 igb_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800959
Alexander Duyck3025a442010-02-17 01:02:39 +0000960 memcpy(adapter->rx_ring[i], &temp_ring[i],
961 sizeof(struct igb_ring));
962 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800963
964 adapter->rx_ring_count = new_rx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800965 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800966err_setup:
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000967 igb_up(adapter);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800968 vfree(temp_ring);
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000969clear_reset:
970 clear_bit(__IGB_RESETTING, &adapter->state);
Auke Kok9d5c8242008-01-24 02:22:38 -0800971 return err;
972}
973
974/* ethtool register test data */
975struct igb_reg_test {
976 u16 reg;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700977 u16 reg_offset;
978 u16 array_len;
979 u16 test_type;
Auke Kok9d5c8242008-01-24 02:22:38 -0800980 u32 mask;
981 u32 write;
982};
983
984/* In the hardware, registers are laid out either singly, in arrays
985 * spaced 0x100 bytes apart, or in contiguous tables. We assume
986 * most tests take place on arrays or single registers (handled
987 * as a single-element array) and special-case the tables.
988 * Table tests are always pattern tests.
989 *
990 * We also make provision for some required setup steps by specifying
991 * registers to be written without any read-back testing.
992 */
993
994#define PATTERN_TEST 1
995#define SET_READ_TEST 2
996#define WRITE_NO_TEST 3
997#define TABLE32_TEST 4
998#define TABLE64_TEST_LO 5
999#define TABLE64_TEST_HI 6
1000
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001001/* i210 reg test */
1002static struct igb_reg_test reg_test_i210[] = {
1003 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1004 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1005 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1006 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1007 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1008 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1009 /* RDH is read-only for i210, only test RDT. */
1010 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1011 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1012 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1013 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1014 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1015 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1016 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1017 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1018 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1019 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
1020 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
1021 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1022 { E1000_RA, 0, 16, TABLE64_TEST_LO,
1023 0xFFFFFFFF, 0xFFFFFFFF },
1024 { E1000_RA, 0, 16, TABLE64_TEST_HI,
1025 0x900FFFFF, 0xFFFFFFFF },
1026 { E1000_MTA, 0, 128, TABLE32_TEST,
1027 0xFFFFFFFF, 0xFFFFFFFF },
1028 { 0, 0, 0, 0, 0 }
1029};
1030
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001031/* i350 reg test */
1032static struct igb_reg_test reg_test_i350[] = {
1033 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1034 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1035 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1036 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFF0000, 0xFFFF0000 },
1037 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1038 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck1b6e6612010-04-09 09:53:08 +00001039 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001040 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1041 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck1b6e6612010-04-09 09:53:08 +00001042 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001043 /* RDH is read-only for i350, only test RDT. */
1044 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1045 { E1000_RDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1046 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1047 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1048 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1049 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1050 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck1b6e6612010-04-09 09:53:08 +00001051 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001052 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1053 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck1b6e6612010-04-09 09:53:08 +00001054 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001055 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1056 { E1000_TDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1057 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001058 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
1059 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001060 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1061 { E1000_RA, 0, 16, TABLE64_TEST_LO,
1062 0xFFFFFFFF, 0xFFFFFFFF },
1063 { E1000_RA, 0, 16, TABLE64_TEST_HI,
1064 0xC3FFFFFF, 0xFFFFFFFF },
1065 { E1000_RA2, 0, 16, TABLE64_TEST_LO,
1066 0xFFFFFFFF, 0xFFFFFFFF },
1067 { E1000_RA2, 0, 16, TABLE64_TEST_HI,
1068 0xC3FFFFFF, 0xFFFFFFFF },
1069 { E1000_MTA, 0, 128, TABLE32_TEST,
1070 0xFFFFFFFF, 0xFFFFFFFF },
1071 { 0, 0, 0, 0 }
1072};
1073
Alexander Duyck55cac242009-11-19 12:42:21 +00001074/* 82580 reg test */
1075static struct igb_reg_test reg_test_82580[] = {
1076 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1077 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1078 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1079 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1080 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1081 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1082 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1083 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1084 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1085 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1086 /* RDH is read-only for 82580, only test RDT. */
1087 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1088 { E1000_RDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1089 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1090 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1091 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1092 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1093 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1094 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1095 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1096 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1097 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1098 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1099 { E1000_TDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1100 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001101 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
1102 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
Alexander Duyck55cac242009-11-19 12:42:21 +00001103 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1104 { E1000_RA, 0, 16, TABLE64_TEST_LO,
1105 0xFFFFFFFF, 0xFFFFFFFF },
1106 { E1000_RA, 0, 16, TABLE64_TEST_HI,
1107 0x83FFFFFF, 0xFFFFFFFF },
1108 { E1000_RA2, 0, 8, TABLE64_TEST_LO,
1109 0xFFFFFFFF, 0xFFFFFFFF },
1110 { E1000_RA2, 0, 8, TABLE64_TEST_HI,
1111 0x83FFFFFF, 0xFFFFFFFF },
1112 { E1000_MTA, 0, 128, TABLE32_TEST,
1113 0xFFFFFFFF, 0xFFFFFFFF },
1114 { 0, 0, 0, 0 }
1115};
1116
Alexander Duyck2d064c02008-07-08 15:10:12 -07001117/* 82576 reg test */
1118static struct igb_reg_test reg_test_82576[] = {
1119 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1120 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1121 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1122 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1123 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1124 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1125 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001126 { E1000_RDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1127 { E1000_RDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1128 { E1000_RDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1129 /* Enable all RX queues before testing. */
Carolyn Wybornyc502ea22014-04-11 01:46:33 +00001130 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0,
1131 E1000_RXDCTL_QUEUE_ENABLE },
1132 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0,
1133 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. */
Carolyn Wybornyc502ea22014-04-11 01:46:33 +00001170 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0,
1171 E1000_RXDCTL_QUEUE_ENABLE },
Auke Kok9d5c8242008-01-24 02:22:38 -08001172 /* RDH is read-only for 82575, only test RDT. */
Alexander Duyck2d064c02008-07-08 15:10:12 -07001173 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1174 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
1175 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1176 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1177 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1178 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1179 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1180 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1181 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1182 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0x003FFFFB },
1183 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0xFFFFFFFF },
1184 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1185 { E1000_TXCW, 0x100, 1, PATTERN_TEST, 0xC000FFFF, 0x0000FFFF },
1186 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
1187 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x800FFFFF, 0xFFFFFFFF },
1188 { E1000_MTA, 0, 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Auke Kok9d5c8242008-01-24 02:22:38 -08001189 { 0, 0, 0, 0 }
1190};
1191
1192static bool reg_pattern_test(struct igb_adapter *adapter, u64 *data,
1193 int reg, u32 mask, u32 write)
1194{
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001195 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001196 u32 pat, val;
Carolyn Wybornyd34a15a2014-04-11 01:45:23 +00001197 static const u32 _test[] = {
1198 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Auke Kok9d5c8242008-01-24 02:22:38 -08001199 for (pat = 0; pat < ARRAY_SIZE(_test); pat++) {
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001200 wr32(reg, (_test[pat] & write));
Carolyn Wyborny93ed8352011-02-24 03:12:15 +00001201 val = rd32(reg) & mask;
Auke Kok9d5c8242008-01-24 02:22:38 -08001202 if (val != (_test[pat] & write & mask)) {
Jesper Juhld836200a2012-08-01 05:41:30 +00001203 dev_err(&adapter->pdev->dev,
1204 "pattern test reg %04X failed: got 0x%08X expected 0x%08X\n",
Auke Kok9d5c8242008-01-24 02:22:38 -08001205 reg, val, (_test[pat] & write & mask));
1206 *data = reg;
Carolyn Wybornyf6f38e22014-04-11 02:20:14 +00001207 return true;
Auke Kok9d5c8242008-01-24 02:22:38 -08001208 }
1209 }
Alexander Duyck317f66b2009-10-27 23:46:20 +00001210
Carolyn Wybornyf6f38e22014-04-11 02:20:14 +00001211 return false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001212}
1213
1214static bool reg_set_and_check(struct igb_adapter *adapter, u64 *data,
1215 int reg, u32 mask, u32 write)
1216{
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001217 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001218 u32 val;
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001219
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001220 wr32(reg, write & mask);
1221 val = rd32(reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001222 if ((write & mask) != (val & mask)) {
Jesper Juhld836200a2012-08-01 05:41:30 +00001223 dev_err(&adapter->pdev->dev,
Carolyn Wybornyc502ea22014-04-11 01:46:33 +00001224 "set/check reg %04X test failed: got 0x%08X expected 0x%08X\n",
1225 reg, (val & mask), (write & mask));
Auke Kok9d5c8242008-01-24 02:22:38 -08001226 *data = reg;
Carolyn Wybornyf6f38e22014-04-11 02:20:14 +00001227 return true;
Auke Kok9d5c8242008-01-24 02:22:38 -08001228 }
Alexander Duyck317f66b2009-10-27 23:46:20 +00001229
Carolyn Wybornyf6f38e22014-04-11 02:20:14 +00001230 return false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001231}
1232
1233#define REG_PATTERN_TEST(reg, mask, write) \
1234 do { \
1235 if (reg_pattern_test(adapter, data, reg, mask, write)) \
1236 return 1; \
1237 } while (0)
1238
1239#define REG_SET_AND_CHECK(reg, mask, write) \
1240 do { \
1241 if (reg_set_and_check(adapter, data, reg, mask, write)) \
1242 return 1; \
1243 } while (0)
1244
1245static int igb_reg_test(struct igb_adapter *adapter, u64 *data)
1246{
1247 struct e1000_hw *hw = &adapter->hw;
1248 struct igb_reg_test *test;
1249 u32 value, before, after;
1250 u32 i, toggle;
1251
Alexander Duyck2d064c02008-07-08 15:10:12 -07001252 switch (adapter->hw.mac.type) {
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001253 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001254 case e1000_i354:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001255 test = reg_test_i350;
1256 toggle = 0x7FEFF3FF;
1257 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001258 case e1000_i210:
1259 case e1000_i211:
1260 test = reg_test_i210;
1261 toggle = 0x7FEFF3FF;
1262 break;
Alexander Duyck55cac242009-11-19 12:42:21 +00001263 case e1000_82580:
1264 test = reg_test_82580;
1265 toggle = 0x7FEFF3FF;
1266 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001267 case e1000_82576:
1268 test = reg_test_82576;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001269 toggle = 0x7FFFF3FF;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001270 break;
1271 default:
1272 test = reg_test_82575;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001273 toggle = 0x7FFFF3FF;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001274 break;
1275 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001276
1277 /* Because the status register is such a special case,
1278 * we handle it separately from the rest of the register
1279 * tests. Some bits are read-only, some toggle, and some
1280 * are writable on newer MACs.
1281 */
1282 before = rd32(E1000_STATUS);
1283 value = (rd32(E1000_STATUS) & toggle);
1284 wr32(E1000_STATUS, toggle);
1285 after = rd32(E1000_STATUS) & toggle;
1286 if (value != after) {
Jesper Juhld836200a2012-08-01 05:41:30 +00001287 dev_err(&adapter->pdev->dev,
1288 "failed STATUS register test got: 0x%08X expected: 0x%08X\n",
1289 after, value);
Auke Kok9d5c8242008-01-24 02:22:38 -08001290 *data = 1;
1291 return 1;
1292 }
1293 /* restore previous status */
1294 wr32(E1000_STATUS, before);
1295
1296 /* Perform the remainder of the register test, looping through
1297 * the test table until we either fail or reach the null entry.
1298 */
1299 while (test->reg) {
1300 for (i = 0; i < test->array_len; i++) {
1301 switch (test->test_type) {
1302 case PATTERN_TEST:
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001303 REG_PATTERN_TEST(test->reg +
1304 (i * test->reg_offset),
Auke Kok9d5c8242008-01-24 02:22:38 -08001305 test->mask,
1306 test->write);
1307 break;
1308 case SET_READ_TEST:
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001309 REG_SET_AND_CHECK(test->reg +
1310 (i * test->reg_offset),
Auke Kok9d5c8242008-01-24 02:22:38 -08001311 test->mask,
1312 test->write);
1313 break;
1314 case WRITE_NO_TEST:
1315 writel(test->write,
1316 (adapter->hw.hw_addr + test->reg)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001317 + (i * test->reg_offset));
Auke Kok9d5c8242008-01-24 02:22:38 -08001318 break;
1319 case TABLE32_TEST:
1320 REG_PATTERN_TEST(test->reg + (i * 4),
1321 test->mask,
1322 test->write);
1323 break;
1324 case TABLE64_TEST_LO:
1325 REG_PATTERN_TEST(test->reg + (i * 8),
1326 test->mask,
1327 test->write);
1328 break;
1329 case TABLE64_TEST_HI:
1330 REG_PATTERN_TEST((test->reg + 4) + (i * 8),
1331 test->mask,
1332 test->write);
1333 break;
1334 }
1335 }
1336 test++;
1337 }
1338
1339 *data = 0;
1340 return 0;
1341}
1342
1343static int igb_eeprom_test(struct igb_adapter *adapter, u64 *data)
1344{
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +00001345 struct e1000_hw *hw = &adapter->hw;
1346
Auke Kok9d5c8242008-01-24 02:22:38 -08001347 *data = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001348
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +00001349 /* Validate eeprom on all parts but flashless */
1350 switch (hw->mac.type) {
1351 case e1000_i210:
1352 case e1000_i211:
1353 if (igb_get_flash_presence_i210(hw)) {
1354 if (adapter->hw.nvm.ops.validate(&adapter->hw) < 0)
1355 *data = 2;
1356 }
1357 break;
1358 default:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001359 if (adapter->hw.nvm.ops.validate(&adapter->hw) < 0)
1360 *data = 2;
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +00001361 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001362 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001363
1364 return *data;
1365}
1366
1367static irqreturn_t igb_test_intr(int irq, void *data)
1368{
Alexander Duyck317f66b2009-10-27 23:46:20 +00001369 struct igb_adapter *adapter = (struct igb_adapter *) data;
Auke Kok9d5c8242008-01-24 02:22:38 -08001370 struct e1000_hw *hw = &adapter->hw;
1371
1372 adapter->test_icr |= rd32(E1000_ICR);
1373
1374 return IRQ_HANDLED;
1375}
1376
1377static int igb_intr_test(struct igb_adapter *adapter, u64 *data)
1378{
1379 struct e1000_hw *hw = &adapter->hw;
1380 struct net_device *netdev = adapter->netdev;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001381 u32 mask, ics_mask, i = 0, shared_int = true;
Auke Kok9d5c8242008-01-24 02:22:38 -08001382 u32 irq = adapter->pdev->irq;
1383
1384 *data = 0;
1385
1386 /* Hook up test interrupt handler just for this test */
Carolyn Wybornycd14ef52013-12-10 07:58:34 +00001387 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001388 if (request_irq(adapter->msix_entries[0].vector,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001389 igb_test_intr, 0, netdev->name, adapter)) {
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001390 *data = 1;
1391 return -1;
1392 }
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001393 } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001394 shared_int = false;
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001395 if (request_irq(irq,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001396 igb_test_intr, 0, netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001397 *data = 1;
1398 return -1;
1399 }
Joe Perchesa0607fd2009-11-18 23:29:17 -08001400 } else if (!request_irq(irq, igb_test_intr, IRQF_PROBE_SHARED,
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001401 netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001402 shared_int = false;
Joe Perchesa0607fd2009-11-18 23:29:17 -08001403 } else if (request_irq(irq, igb_test_intr, IRQF_SHARED,
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001404 netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001405 *data = 1;
1406 return -1;
1407 }
1408 dev_info(&adapter->pdev->dev, "testing %s interrupt\n",
1409 (shared_int ? "shared" : "unshared"));
Alexander Duyck317f66b2009-10-27 23:46:20 +00001410
Auke Kok9d5c8242008-01-24 02:22:38 -08001411 /* Disable all the interrupts */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001412 wr32(E1000_IMC, ~0);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001413 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001414 usleep_range(10000, 11000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001415
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001416 /* Define all writable bits for ICS */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001417 switch (hw->mac.type) {
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001418 case e1000_82575:
1419 ics_mask = 0x37F47EDD;
1420 break;
1421 case e1000_82576:
1422 ics_mask = 0x77D4FBFD;
1423 break;
Alexander Duyck55cac242009-11-19 12:42:21 +00001424 case e1000_82580:
1425 ics_mask = 0x77DCFED5;
1426 break;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001427 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001428 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001429 case e1000_i210:
1430 case e1000_i211:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001431 ics_mask = 0x77DCFED5;
1432 break;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001433 default:
1434 ics_mask = 0x7FFFFFFF;
1435 break;
1436 }
1437
Auke Kok9d5c8242008-01-24 02:22:38 -08001438 /* Test each interrupt */
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001439 for (; i < 31; i++) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001440 /* Interrupt to test */
1441 mask = 1 << i;
1442
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001443 if (!(mask & ics_mask))
1444 continue;
1445
Auke Kok9d5c8242008-01-24 02:22:38 -08001446 if (!shared_int) {
1447 /* Disable the interrupt to be reported in
1448 * the cause register and then force the same
1449 * interrupt and see if one gets posted. If
1450 * an interrupt was posted to the bus, the
1451 * test failed.
1452 */
1453 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001454
1455 /* Flush any pending interrupts */
1456 wr32(E1000_ICR, ~0);
1457
1458 wr32(E1000_IMC, mask);
1459 wr32(E1000_ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001460 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001461 usleep_range(10000, 11000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001462
1463 if (adapter->test_icr & mask) {
1464 *data = 3;
1465 break;
1466 }
1467 }
1468
1469 /* Enable the interrupt to be reported in
1470 * the cause register and then force the same
1471 * interrupt and see if one gets posted. If
1472 * an interrupt was not posted to the bus, the
1473 * test failed.
1474 */
1475 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001476
1477 /* Flush any pending interrupts */
1478 wr32(E1000_ICR, ~0);
1479
Auke Kok9d5c8242008-01-24 02:22:38 -08001480 wr32(E1000_IMS, mask);
1481 wr32(E1000_ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001482 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001483 usleep_range(10000, 11000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001484
1485 if (!(adapter->test_icr & mask)) {
1486 *data = 4;
1487 break;
1488 }
1489
1490 if (!shared_int) {
1491 /* Disable the other interrupts to be reported in
1492 * the cause register and then force the other
1493 * interrupts and see if any get posted. If
1494 * an interrupt was posted to the bus, the
1495 * test failed.
1496 */
1497 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001498
1499 /* Flush any pending interrupts */
1500 wr32(E1000_ICR, ~0);
1501
1502 wr32(E1000_IMC, ~mask);
1503 wr32(E1000_ICS, ~mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001504 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001505 usleep_range(10000, 11000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001506
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001507 if (adapter->test_icr & mask) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001508 *data = 5;
1509 break;
1510 }
1511 }
1512 }
1513
1514 /* Disable all the interrupts */
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001515 wr32(E1000_IMC, ~0);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001516 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001517 usleep_range(10000, 11000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001518
1519 /* Unhook test interrupt handler */
Carolyn Wybornycd14ef52013-12-10 07:58:34 +00001520 if (adapter->flags & IGB_FLAG_HAS_MSIX)
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001521 free_irq(adapter->msix_entries[0].vector, adapter);
1522 else
1523 free_irq(irq, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001524
1525 return *data;
1526}
1527
1528static void igb_free_desc_rings(struct igb_adapter *adapter)
1529{
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001530 igb_free_tx_resources(&adapter->test_tx_ring);
1531 igb_free_rx_resources(&adapter->test_rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001532}
1533
1534static int igb_setup_desc_rings(struct igb_adapter *adapter)
1535{
Auke Kok9d5c8242008-01-24 02:22:38 -08001536 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1537 struct igb_ring *rx_ring = &adapter->test_rx_ring;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001538 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckad93d172009-10-27 15:55:02 +00001539 int ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001540
1541 /* Setup Tx descriptor ring and Tx buffers */
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001542 tx_ring->count = IGB_DEFAULT_TXD;
Alexander Duyck59d71982010-04-27 13:09:25 +00001543 tx_ring->dev = &adapter->pdev->dev;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001544 tx_ring->netdev = adapter->netdev;
1545 tx_ring->reg_idx = adapter->vfs_allocated_count;
Auke Kok9d5c8242008-01-24 02:22:38 -08001546
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001547 if (igb_setup_tx_resources(tx_ring)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001548 ret_val = 1;
1549 goto err_nomem;
1550 }
1551
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001552 igb_setup_tctl(adapter);
1553 igb_configure_tx_ring(adapter, tx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001554
Auke Kok9d5c8242008-01-24 02:22:38 -08001555 /* Setup Rx descriptor ring and Rx buffers */
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001556 rx_ring->count = IGB_DEFAULT_RXD;
Alexander Duyck59d71982010-04-27 13:09:25 +00001557 rx_ring->dev = &adapter->pdev->dev;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001558 rx_ring->netdev = adapter->netdev;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001559 rx_ring->reg_idx = adapter->vfs_allocated_count;
Auke Kok9d5c8242008-01-24 02:22:38 -08001560
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001561 if (igb_setup_rx_resources(rx_ring)) {
1562 ret_val = 3;
Auke Kok9d5c8242008-01-24 02:22:38 -08001563 goto err_nomem;
1564 }
1565
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001566 /* set the default queue to queue 0 of PF */
1567 wr32(E1000_MRQC, adapter->vfs_allocated_count << 3);
Auke Kok9d5c8242008-01-24 02:22:38 -08001568
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001569 /* enable receive ring */
1570 igb_setup_rctl(adapter);
1571 igb_configure_rx_ring(adapter, rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001572
Alexander Duyckcd392f52011-08-26 07:43:59 +00001573 igb_alloc_rx_buffers(rx_ring, igb_desc_unused(rx_ring));
Auke Kok9d5c8242008-01-24 02:22:38 -08001574
1575 return 0;
1576
1577err_nomem:
1578 igb_free_desc_rings(adapter);
1579 return ret_val;
1580}
1581
1582static void igb_phy_disable_receiver(struct igb_adapter *adapter)
1583{
1584 struct e1000_hw *hw = &adapter->hw;
1585
1586 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001587 igb_write_phy_reg(hw, 29, 0x001F);
1588 igb_write_phy_reg(hw, 30, 0x8FFC);
1589 igb_write_phy_reg(hw, 29, 0x001A);
1590 igb_write_phy_reg(hw, 30, 0x8FF0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001591}
1592
1593static int igb_integrated_phy_loopback(struct igb_adapter *adapter)
1594{
1595 struct e1000_hw *hw = &adapter->hw;
1596 u32 ctrl_reg = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001597
1598 hw->mac.autoneg = false;
1599
Carolyn Wyborny8aa23f02012-06-08 05:01:39 +00001600 if (hw->phy.type == e1000_phy_m88) {
1601 if (hw->phy.id != I210_I_PHY_ID) {
1602 /* Auto-MDI/MDIX Off */
1603 igb_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1604 /* reset to update Auto-MDI/MDIX */
1605 igb_write_phy_reg(hw, PHY_CONTROL, 0x9140);
1606 /* autoneg off */
1607 igb_write_phy_reg(hw, PHY_CONTROL, 0x8140);
1608 } else {
1609 /* force 1000, set loopback */
1610 igb_write_phy_reg(hw, I347AT4_PAGE_SELECT, 0);
1611 igb_write_phy_reg(hw, PHY_CONTROL, 0x4140);
1612 }
Todd Fujinaka5aa3a442013-09-17 05:08:48 +00001613 } else if (hw->phy.type == e1000_phy_82580) {
1614 /* enable MII loopback */
1615 igb_write_phy_reg(hw, I82580_PHY_LBK_CTRL, 0x8041);
Auke Kok9d5c8242008-01-24 02:22:38 -08001616 }
1617
Stefan Assmann119b0e02012-08-07 00:45:57 -07001618 /* add small delay to avoid loopback test failure */
1619 msleep(50);
1620
Auke Kok9d5c8242008-01-24 02:22:38 -08001621 /* force 1000, set loopback */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001622 igb_write_phy_reg(hw, PHY_CONTROL, 0x4140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001623
1624 /* Now set up the MAC to the same speed/duplex as the PHY. */
1625 ctrl_reg = rd32(E1000_CTRL);
1626 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1627 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1628 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1629 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
Alexander Duyckcdfa9f62009-03-31 20:38:56 +00001630 E1000_CTRL_FD | /* Force Duplex to FULL */
1631 E1000_CTRL_SLU); /* Set link up enable bit */
Auke Kok9d5c8242008-01-24 02:22:38 -08001632
Carolyn Wyborny8aa23f02012-06-08 05:01:39 +00001633 if (hw->phy.type == e1000_phy_m88)
Auke Kok9d5c8242008-01-24 02:22:38 -08001634 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kok9d5c8242008-01-24 02:22:38 -08001635
1636 wr32(E1000_CTRL, ctrl_reg);
1637
1638 /* Disable the receiver on the PHY so when a cable is plugged in, the
1639 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1640 */
Carolyn Wyborny8aa23f02012-06-08 05:01:39 +00001641 if (hw->phy.type == e1000_phy_m88)
Auke Kok9d5c8242008-01-24 02:22:38 -08001642 igb_phy_disable_receiver(adapter);
1643
Carolyn Wyborny8aa23f02012-06-08 05:01:39 +00001644 mdelay(500);
Auke Kok9d5c8242008-01-24 02:22:38 -08001645 return 0;
1646}
1647
1648static int igb_set_phy_loopback(struct igb_adapter *adapter)
1649{
1650 return igb_integrated_phy_loopback(adapter);
1651}
1652
1653static int igb_setup_loopback_test(struct igb_adapter *adapter)
1654{
1655 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001656 u32 reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001657
Alexander Duyck317f66b2009-10-27 23:46:20 +00001658 reg = rd32(E1000_CTRL_EXT);
1659
1660 /* use CTRL_EXT to identify link type as SGMII can appear as copper */
1661 if (reg & E1000_CTRL_EXT_LINK_MODE_MASK) {
Robert Healya14bc2b2011-07-12 08:46:20 +00001662 if ((hw->device_id == E1000_DEV_ID_DH89XXCC_SGMII) ||
1663 (hw->device_id == E1000_DEV_ID_DH89XXCC_SERDES) ||
1664 (hw->device_id == E1000_DEV_ID_DH89XXCC_BACKPLANE) ||
Fujinaka, Todda4e979a2013-10-01 04:33:55 -07001665 (hw->device_id == E1000_DEV_ID_DH89XXCC_SFP) ||
Todd Fujinaka3cfcf032014-05-29 05:45:15 +00001666 (hw->device_id == E1000_DEV_ID_I354_SGMII) ||
1667 (hw->device_id == E1000_DEV_ID_I354_BACKPLANE_2_5GBPS)) {
Robert Healya14bc2b2011-07-12 08:46:20 +00001668 /* Enable DH89xxCC MPHY for near end loopback */
1669 reg = rd32(E1000_MPHY_ADDR_CTL);
1670 reg = (reg & E1000_MPHY_ADDR_CTL_OFFSET_MASK) |
1671 E1000_MPHY_PCS_CLK_REG_OFFSET;
1672 wr32(E1000_MPHY_ADDR_CTL, reg);
1673
1674 reg = rd32(E1000_MPHY_DATA);
1675 reg |= E1000_MPHY_PCS_CLK_REG_DIGINELBEN;
1676 wr32(E1000_MPHY_DATA, reg);
1677 }
1678
Alexander Duyck2d064c02008-07-08 15:10:12 -07001679 reg = rd32(E1000_RCTL);
1680 reg |= E1000_RCTL_LBM_TCVR;
1681 wr32(E1000_RCTL, reg);
1682
1683 wr32(E1000_SCTL, E1000_ENABLE_SERDES_LOOPBACK);
1684
1685 reg = rd32(E1000_CTRL);
1686 reg &= ~(E1000_CTRL_RFCE |
1687 E1000_CTRL_TFCE |
1688 E1000_CTRL_LRST);
1689 reg |= E1000_CTRL_SLU |
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001690 E1000_CTRL_FD;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001691 wr32(E1000_CTRL, reg);
1692
1693 /* Unset switch control to serdes energy detect */
1694 reg = rd32(E1000_CONNSW);
1695 reg &= ~E1000_CONNSW_ENRGSRC;
1696 wr32(E1000_CONNSW, reg);
1697
Carolyn Wyborny3860a0b2012-11-22 02:49:22 +00001698 /* Unset sigdetect for SERDES loopback on
Akeem G. Abodunrin0ba96d32013-03-20 08:01:40 +00001699 * 82580 and newer devices.
Carolyn Wyborny3860a0b2012-11-22 02:49:22 +00001700 */
Akeem G. Abodunrin0ba96d32013-03-20 08:01:40 +00001701 if (hw->mac.type >= e1000_82580) {
Carolyn Wyborny3860a0b2012-11-22 02:49:22 +00001702 reg = rd32(E1000_PCS_CFG0);
1703 reg |= E1000_PCS_CFG_IGN_SD;
1704 wr32(E1000_PCS_CFG0, reg);
Carolyn Wyborny3860a0b2012-11-22 02:49:22 +00001705 }
1706
Alexander Duyck2d064c02008-07-08 15:10:12 -07001707 /* Set PCS register for forced speed */
1708 reg = rd32(E1000_PCS_LCTL);
1709 reg &= ~E1000_PCS_LCTL_AN_ENABLE; /* Disable Autoneg*/
1710 reg |= E1000_PCS_LCTL_FLV_LINK_UP | /* Force link up */
1711 E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1712 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
1713 E1000_PCS_LCTL_FSD | /* Force Speed */
1714 E1000_PCS_LCTL_FORCE_LINK; /* Force Link */
1715 wr32(E1000_PCS_LCTL, reg);
1716
Auke Kok9d5c8242008-01-24 02:22:38 -08001717 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001718 }
1719
Alexander Duyck317f66b2009-10-27 23:46:20 +00001720 return igb_set_phy_loopback(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001721}
1722
1723static void igb_loopback_cleanup(struct igb_adapter *adapter)
1724{
1725 struct e1000_hw *hw = &adapter->hw;
1726 u32 rctl;
1727 u16 phy_reg;
1728
Robert Healya14bc2b2011-07-12 08:46:20 +00001729 if ((hw->device_id == E1000_DEV_ID_DH89XXCC_SGMII) ||
1730 (hw->device_id == E1000_DEV_ID_DH89XXCC_SERDES) ||
1731 (hw->device_id == E1000_DEV_ID_DH89XXCC_BACKPLANE) ||
Fujinaka, Todda4e979a2013-10-01 04:33:55 -07001732 (hw->device_id == E1000_DEV_ID_DH89XXCC_SFP) ||
1733 (hw->device_id == E1000_DEV_ID_I354_SGMII)) {
Robert Healya14bc2b2011-07-12 08:46:20 +00001734 u32 reg;
1735
1736 /* Disable near end loopback on DH89xxCC */
1737 reg = rd32(E1000_MPHY_ADDR_CTL);
1738 reg = (reg & E1000_MPHY_ADDR_CTL_OFFSET_MASK) |
1739 E1000_MPHY_PCS_CLK_REG_OFFSET;
1740 wr32(E1000_MPHY_ADDR_CTL, reg);
1741
1742 reg = rd32(E1000_MPHY_DATA);
1743 reg &= ~E1000_MPHY_PCS_CLK_REG_DIGINELBEN;
1744 wr32(E1000_MPHY_DATA, reg);
1745 }
1746
Auke Kok9d5c8242008-01-24 02:22:38 -08001747 rctl = rd32(E1000_RCTL);
1748 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1749 wr32(E1000_RCTL, rctl);
1750
1751 hw->mac.autoneg = true;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001752 igb_read_phy_reg(hw, PHY_CONTROL, &phy_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001753 if (phy_reg & MII_CR_LOOPBACK) {
1754 phy_reg &= ~MII_CR_LOOPBACK;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001755 igb_write_phy_reg(hw, PHY_CONTROL, phy_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001756 igb_phy_sw_reset(hw);
1757 }
1758}
1759
1760static void igb_create_lbtest_frame(struct sk_buff *skb,
1761 unsigned int frame_size)
1762{
1763 memset(skb->data, 0xFF, frame_size);
Alexander Duyck317f66b2009-10-27 23:46:20 +00001764 frame_size /= 2;
1765 memset(&skb->data[frame_size], 0xAA, frame_size - 1);
1766 memset(&skb->data[frame_size + 10], 0xBE, 1);
1767 memset(&skb->data[frame_size + 12], 0xAF, 1);
Auke Kok9d5c8242008-01-24 02:22:38 -08001768}
1769
Alexander Duyck1a1c2252012-09-25 00:30:52 +00001770static int igb_check_lbtest_frame(struct igb_rx_buffer *rx_buffer,
1771 unsigned int frame_size)
Auke Kok9d5c8242008-01-24 02:22:38 -08001772{
Alexander Duyck1a1c2252012-09-25 00:30:52 +00001773 unsigned char *data;
1774 bool match = true;
1775
1776 frame_size >>= 1;
1777
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001778 data = kmap(rx_buffer->page);
Alexander Duyck1a1c2252012-09-25 00:30:52 +00001779
1780 if (data[3] != 0xFF ||
1781 data[frame_size + 10] != 0xBE ||
1782 data[frame_size + 12] != 0xAF)
1783 match = false;
1784
1785 kunmap(rx_buffer->page);
1786
1787 return match;
Auke Kok9d5c8242008-01-24 02:22:38 -08001788}
1789
Alexander Duyckad93d172009-10-27 15:55:02 +00001790static int igb_clean_test_rings(struct igb_ring *rx_ring,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001791 struct igb_ring *tx_ring,
1792 unsigned int size)
Alexander Duyckad93d172009-10-27 15:55:02 +00001793{
1794 union e1000_adv_rx_desc *rx_desc;
Alexander Duyck06034642011-08-26 07:44:22 +00001795 struct igb_rx_buffer *rx_buffer_info;
1796 struct igb_tx_buffer *tx_buffer_info;
Alexander Duyck6ad4edf2011-08-26 07:45:26 +00001797 u16 rx_ntc, tx_ntc, count = 0;
Alexander Duyckad93d172009-10-27 15:55:02 +00001798
1799 /* initialize next to clean and descriptor values */
1800 rx_ntc = rx_ring->next_to_clean;
1801 tx_ntc = tx_ring->next_to_clean;
Alexander Duyck601369062011-08-26 07:44:05 +00001802 rx_desc = IGB_RX_DESC(rx_ring, rx_ntc);
Alexander Duyckad93d172009-10-27 15:55:02 +00001803
Alexander Duyck3ceb90f2011-08-26 07:46:03 +00001804 while (igb_test_staterr(rx_desc, E1000_RXD_STAT_DD)) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001805 /* check Rx buffer */
Alexander Duyck06034642011-08-26 07:44:22 +00001806 rx_buffer_info = &rx_ring->rx_buffer_info[rx_ntc];
Alexander Duyckad93d172009-10-27 15:55:02 +00001807
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001808 /* sync Rx buffer for CPU read */
1809 dma_sync_single_for_cpu(rx_ring->dev,
1810 rx_buffer_info->dma,
Alexander Duyckde78d1f2012-09-25 00:31:12 +00001811 IGB_RX_BUFSZ,
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001812 DMA_FROM_DEVICE);
Alexander Duyckad93d172009-10-27 15:55:02 +00001813
1814 /* verify contents of skb */
Alexander Duyck1a1c2252012-09-25 00:30:52 +00001815 if (igb_check_lbtest_frame(rx_buffer_info, size))
Alexander Duyckad93d172009-10-27 15:55:02 +00001816 count++;
1817
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001818 /* sync Rx buffer for device write */
1819 dma_sync_single_for_device(rx_ring->dev,
1820 rx_buffer_info->dma,
Alexander Duyckde78d1f2012-09-25 00:31:12 +00001821 IGB_RX_BUFSZ,
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001822 DMA_FROM_DEVICE);
1823
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001824 /* unmap buffer on Tx side */
Alexander Duyck06034642011-08-26 07:44:22 +00001825 tx_buffer_info = &tx_ring->tx_buffer_info[tx_ntc];
1826 igb_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duyckad93d172009-10-27 15:55:02 +00001827
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001828 /* increment Rx/Tx next to clean counters */
Alexander Duyckad93d172009-10-27 15:55:02 +00001829 rx_ntc++;
1830 if (rx_ntc == rx_ring->count)
1831 rx_ntc = 0;
1832 tx_ntc++;
1833 if (tx_ntc == tx_ring->count)
1834 tx_ntc = 0;
1835
1836 /* fetch next descriptor */
Alexander Duyck601369062011-08-26 07:44:05 +00001837 rx_desc = IGB_RX_DESC(rx_ring, rx_ntc);
Alexander Duyckad93d172009-10-27 15:55:02 +00001838 }
1839
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001840 netdev_tx_reset_queue(txring_txq(tx_ring));
Jeff Kirsher51a76c32012-01-19 18:31:34 +00001841
Alexander Duyckad93d172009-10-27 15:55:02 +00001842 /* re-map buffers to ring, store next to clean values */
Alexander Duyckcd392f52011-08-26 07:43:59 +00001843 igb_alloc_rx_buffers(rx_ring, count);
Alexander Duyckad93d172009-10-27 15:55:02 +00001844 rx_ring->next_to_clean = rx_ntc;
1845 tx_ring->next_to_clean = tx_ntc;
1846
1847 return count;
1848}
1849
Auke Kok9d5c8242008-01-24 02:22:38 -08001850static int igb_run_loopback_test(struct igb_adapter *adapter)
1851{
Auke Kok9d5c8242008-01-24 02:22:38 -08001852 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1853 struct igb_ring *rx_ring = &adapter->test_rx_ring;
Alexander Duyck6ad4edf2011-08-26 07:45:26 +00001854 u16 i, j, lc, good_cnt;
1855 int ret_val = 0;
Alexander Duyck44390ca2011-08-26 07:43:38 +00001856 unsigned int size = IGB_RX_HDR_LEN;
Alexander Duyckad93d172009-10-27 15:55:02 +00001857 netdev_tx_t tx_ret_val;
1858 struct sk_buff *skb;
Auke Kok9d5c8242008-01-24 02:22:38 -08001859
Alexander Duyckad93d172009-10-27 15:55:02 +00001860 /* allocate test skb */
1861 skb = alloc_skb(size, GFP_KERNEL);
1862 if (!skb)
1863 return 11;
1864
1865 /* place data into test skb */
1866 igb_create_lbtest_frame(skb, size);
1867 skb_put(skb, size);
Auke Kok9d5c8242008-01-24 02:22:38 -08001868
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001869 /* Calculate the loop count based on the largest descriptor ring
Auke Kok9d5c8242008-01-24 02:22:38 -08001870 * The idea is to wrap the largest ring a number of times using 64
1871 * send/receive pairs during each loop
1872 */
1873
1874 if (rx_ring->count <= tx_ring->count)
1875 lc = ((tx_ring->count / 64) * 2) + 1;
1876 else
1877 lc = ((rx_ring->count / 64) * 2) + 1;
1878
Auke Kok9d5c8242008-01-24 02:22:38 -08001879 for (j = 0; j <= lc; j++) { /* loop count loop */
Alexander Duyckad93d172009-10-27 15:55:02 +00001880 /* reset count of good packets */
Auke Kok9d5c8242008-01-24 02:22:38 -08001881 good_cnt = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001882
Alexander Duyckad93d172009-10-27 15:55:02 +00001883 /* place 64 packets on the transmit queue*/
1884 for (i = 0; i < 64; i++) {
1885 skb_get(skb);
Alexander Duyckcd392f52011-08-26 07:43:59 +00001886 tx_ret_val = igb_xmit_frame_ring(skb, tx_ring);
Alexander Duyckad93d172009-10-27 15:55:02 +00001887 if (tx_ret_val == NETDEV_TX_OK)
Auke Kok9d5c8242008-01-24 02:22:38 -08001888 good_cnt++;
Alexander Duyckad93d172009-10-27 15:55:02 +00001889 }
1890
Auke Kok9d5c8242008-01-24 02:22:38 -08001891 if (good_cnt != 64) {
Alexander Duyckad93d172009-10-27 15:55:02 +00001892 ret_val = 12;
Auke Kok9d5c8242008-01-24 02:22:38 -08001893 break;
1894 }
Alexander Duyckad93d172009-10-27 15:55:02 +00001895
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001896 /* allow 200 milliseconds for packets to go from Tx to Rx */
Alexander Duyckad93d172009-10-27 15:55:02 +00001897 msleep(200);
1898
1899 good_cnt = igb_clean_test_rings(rx_ring, tx_ring, size);
1900 if (good_cnt != 64) {
1901 ret_val = 13;
Auke Kok9d5c8242008-01-24 02:22:38 -08001902 break;
1903 }
1904 } /* end loop count loop */
Alexander Duyckad93d172009-10-27 15:55:02 +00001905
1906 /* free the original skb */
1907 kfree_skb(skb);
1908
Auke Kok9d5c8242008-01-24 02:22:38 -08001909 return ret_val;
1910}
1911
1912static int igb_loopback_test(struct igb_adapter *adapter, u64 *data)
1913{
1914 /* PHY loopback cannot be performed if SoL/IDER
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001915 * sessions are active
1916 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001917 if (igb_check_reset_block(&adapter->hw)) {
1918 dev_err(&adapter->pdev->dev,
Jesper Juhld836200a2012-08-01 05:41:30 +00001919 "Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001920 *data = 0;
1921 goto out;
1922 }
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001923
1924 if (adapter->hw.mac.type == e1000_i354) {
1925 dev_info(&adapter->pdev->dev,
1926 "Loopback test not supported on i354.\n");
1927 *data = 0;
1928 goto out;
1929 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001930 *data = igb_setup_desc_rings(adapter);
1931 if (*data)
1932 goto out;
1933 *data = igb_setup_loopback_test(adapter);
1934 if (*data)
1935 goto err_loopback;
1936 *data = igb_run_loopback_test(adapter);
1937 igb_loopback_cleanup(adapter);
1938
1939err_loopback:
1940 igb_free_desc_rings(adapter);
1941out:
1942 return *data;
1943}
1944
1945static int igb_link_test(struct igb_adapter *adapter, u64 *data)
1946{
1947 struct e1000_hw *hw = &adapter->hw;
1948 *data = 0;
1949 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1950 int i = 0;
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001951
Auke Kok9d5c8242008-01-24 02:22:38 -08001952 hw->mac.serdes_has_link = false;
1953
1954 /* On some blade server designs, link establishment
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001955 * could take as long as 2-3 minutes
1956 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001957 do {
1958 hw->mac.ops.check_for_link(&adapter->hw);
1959 if (hw->mac.serdes_has_link)
1960 return *data;
1961 msleep(20);
1962 } while (i++ < 3750);
1963
1964 *data = 1;
1965 } else {
1966 hw->mac.ops.check_for_link(&adapter->hw);
1967 if (hw->mac.autoneg)
Stefan Assmann4507dc92013-02-02 08:31:50 +00001968 msleep(5000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001969
Alexander Duyck317f66b2009-10-27 23:46:20 +00001970 if (!(rd32(E1000_STATUS) & E1000_STATUS_LU))
Auke Kok9d5c8242008-01-24 02:22:38 -08001971 *data = 1;
1972 }
1973 return *data;
1974}
1975
1976static void igb_diag_test(struct net_device *netdev,
1977 struct ethtool_test *eth_test, u64 *data)
1978{
1979 struct igb_adapter *adapter = netdev_priv(netdev);
1980 u16 autoneg_advertised;
1981 u8 forced_speed_duplex, autoneg;
1982 bool if_running = netif_running(netdev);
1983
1984 set_bit(__IGB_TESTING, &adapter->state);
Carolyn Wyborny56cec242013-10-17 05:36:26 +00001985
1986 /* can't do offline tests on media switching devices */
1987 if (adapter->hw.dev_spec._82575.mas_capable)
1988 eth_test->flags &= ~ETH_TEST_FL_OFFLINE;
Auke Kok9d5c8242008-01-24 02:22:38 -08001989 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1990 /* Offline tests */
1991
1992 /* save speed, duplex, autoneg settings */
1993 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1994 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1995 autoneg = adapter->hw.mac.autoneg;
1996
1997 dev_info(&adapter->pdev->dev, "offline testing starting\n");
1998
Nick Nunley88a268c2010-02-17 01:01:59 +00001999 /* power up link for link test */
2000 igb_power_up_link(adapter);
2001
Auke Kok9d5c8242008-01-24 02:22:38 -08002002 /* Link test performed before hardware reset so autoneg doesn't
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002003 * interfere with test result
2004 */
Auke Kok9d5c8242008-01-24 02:22:38 -08002005 if (igb_link_test(adapter, &data[4]))
2006 eth_test->flags |= ETH_TEST_FL_FAILED;
2007
2008 if (if_running)
2009 /* indicate we're in test mode */
2010 dev_close(netdev);
2011 else
2012 igb_reset(adapter);
2013
2014 if (igb_reg_test(adapter, &data[0]))
2015 eth_test->flags |= ETH_TEST_FL_FAILED;
2016
2017 igb_reset(adapter);
2018 if (igb_eeprom_test(adapter, &data[1]))
2019 eth_test->flags |= ETH_TEST_FL_FAILED;
2020
2021 igb_reset(adapter);
2022 if (igb_intr_test(adapter, &data[2]))
2023 eth_test->flags |= ETH_TEST_FL_FAILED;
2024
2025 igb_reset(adapter);
Nick Nunley88a268c2010-02-17 01:01:59 +00002026 /* power up link for loopback test */
2027 igb_power_up_link(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002028 if (igb_loopback_test(adapter, &data[3]))
2029 eth_test->flags |= ETH_TEST_FL_FAILED;
2030
2031 /* restore speed, duplex, autoneg settings */
2032 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
2033 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
2034 adapter->hw.mac.autoneg = autoneg;
2035
2036 /* force this routine to wait until autoneg complete/timeout */
2037 adapter->hw.phy.autoneg_wait_to_complete = true;
2038 igb_reset(adapter);
2039 adapter->hw.phy.autoneg_wait_to_complete = false;
2040
2041 clear_bit(__IGB_TESTING, &adapter->state);
2042 if (if_running)
2043 dev_open(netdev);
2044 } else {
2045 dev_info(&adapter->pdev->dev, "online testing starting\n");
Nick Nunley88a268c2010-02-17 01:01:59 +00002046
2047 /* PHY is powered down when interface is down */
Alexander Duyck8d420a12010-07-01 13:39:01 +00002048 if (if_running && igb_link_test(adapter, &data[4]))
2049 eth_test->flags |= ETH_TEST_FL_FAILED;
2050 else
Nick Nunley88a268c2010-02-17 01:01:59 +00002051 data[4] = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002052
2053 /* Online tests aren't run; pass by default */
2054 data[0] = 0;
2055 data[1] = 0;
2056 data[2] = 0;
2057 data[3] = 0;
2058
2059 clear_bit(__IGB_TESTING, &adapter->state);
2060 }
2061 msleep_interruptible(4 * 1000);
2062}
2063
Auke Kok9d5c8242008-01-24 02:22:38 -08002064static void igb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2065{
2066 struct igb_adapter *adapter = netdev_priv(netdev);
2067
Auke Kok9d5c8242008-01-24 02:22:38 -08002068 wol->wolopts = 0;
2069
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002070 if (!(adapter->flags & IGB_FLAG_WOL_SUPPORTED))
Auke Kok9d5c8242008-01-24 02:22:38 -08002071 return;
2072
Akeem G Abodunrin42ce4122013-11-08 01:54:07 +00002073 wol->supported = WAKE_UCAST | WAKE_MCAST |
2074 WAKE_BCAST | WAKE_MAGIC |
2075 WAKE_PHY;
2076
Auke Kok9d5c8242008-01-24 02:22:38 -08002077 /* apply any specific unsupported masks here */
2078 switch (adapter->hw.device_id) {
2079 default:
2080 break;
2081 }
2082
2083 if (adapter->wol & E1000_WUFC_EX)
2084 wol->wolopts |= WAKE_UCAST;
2085 if (adapter->wol & E1000_WUFC_MC)
2086 wol->wolopts |= WAKE_MCAST;
2087 if (adapter->wol & E1000_WUFC_BC)
2088 wol->wolopts |= WAKE_BCAST;
2089 if (adapter->wol & E1000_WUFC_MAG)
2090 wol->wolopts |= WAKE_MAGIC;
Nick Nunley22939f02010-02-17 01:01:01 +00002091 if (adapter->wol & E1000_WUFC_LNKC)
2092 wol->wolopts |= WAKE_PHY;
Auke Kok9d5c8242008-01-24 02:22:38 -08002093}
2094
2095static int igb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2096{
2097 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08002098
Nick Nunley22939f02010-02-17 01:01:01 +00002099 if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE))
Auke Kok9d5c8242008-01-24 02:22:38 -08002100 return -EOPNOTSUPP;
2101
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002102 if (!(adapter->flags & IGB_FLAG_WOL_SUPPORTED))
Auke Kok9d5c8242008-01-24 02:22:38 -08002103 return wol->wolopts ? -EOPNOTSUPP : 0;
2104
Auke Kok9d5c8242008-01-24 02:22:38 -08002105 /* these settings will always override what we currently have */
2106 adapter->wol = 0;
2107
2108 if (wol->wolopts & WAKE_UCAST)
2109 adapter->wol |= E1000_WUFC_EX;
2110 if (wol->wolopts & WAKE_MCAST)
2111 adapter->wol |= E1000_WUFC_MC;
2112 if (wol->wolopts & WAKE_BCAST)
2113 adapter->wol |= E1000_WUFC_BC;
2114 if (wol->wolopts & WAKE_MAGIC)
2115 adapter->wol |= E1000_WUFC_MAG;
Nick Nunley22939f02010-02-17 01:01:01 +00002116 if (wol->wolopts & WAKE_PHY)
2117 adapter->wol |= E1000_WUFC_LNKC;
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00002118 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
2119
Auke Kok9d5c8242008-01-24 02:22:38 -08002120 return 0;
2121}
2122
Auke Kok9d5c8242008-01-24 02:22:38 -08002123/* bit defines for adapter->led_status */
2124#define IGB_LED_ON 0
2125
Jeff Kirsher936db352011-05-07 06:37:14 +00002126static int igb_set_phys_id(struct net_device *netdev,
2127 enum ethtool_phys_id_state state)
Auke Kok9d5c8242008-01-24 02:22:38 -08002128{
2129 struct igb_adapter *adapter = netdev_priv(netdev);
2130 struct e1000_hw *hw = &adapter->hw;
2131
Jeff Kirsher936db352011-05-07 06:37:14 +00002132 switch (state) {
2133 case ETHTOOL_ID_ACTIVE:
2134 igb_blink_led(hw);
2135 return 2;
2136 case ETHTOOL_ID_ON:
2137 igb_blink_led(hw);
2138 break;
2139 case ETHTOOL_ID_OFF:
2140 igb_led_off(hw);
2141 break;
2142 case ETHTOOL_ID_INACTIVE:
2143 igb_led_off(hw);
2144 clear_bit(IGB_LED_ON, &adapter->led_status);
2145 igb_cleanup_led(hw);
2146 break;
2147 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002148
2149 return 0;
2150}
2151
2152static int igb_set_coalesce(struct net_device *netdev,
2153 struct ethtool_coalesce *ec)
2154{
2155 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002156 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08002157
Todd Fujinaka0c5bbeb2015-06-04 14:26:56 -07002158 if (ec->rx_max_coalesced_frames ||
2159 ec->rx_coalesce_usecs_irq ||
2160 ec->rx_max_coalesced_frames_irq ||
2161 ec->tx_max_coalesced_frames ||
2162 ec->tx_coalesce_usecs_irq ||
2163 ec->stats_block_coalesce_usecs ||
2164 ec->use_adaptive_rx_coalesce ||
2165 ec->use_adaptive_tx_coalesce ||
2166 ec->pkt_rate_low ||
2167 ec->rx_coalesce_usecs_low ||
2168 ec->rx_max_coalesced_frames_low ||
2169 ec->tx_coalesce_usecs_low ||
2170 ec->tx_max_coalesced_frames_low ||
2171 ec->pkt_rate_high ||
2172 ec->rx_coalesce_usecs_high ||
2173 ec->rx_max_coalesced_frames_high ||
2174 ec->tx_coalesce_usecs_high ||
2175 ec->tx_max_coalesced_frames_high ||
2176 ec->rate_sample_interval)
2177 return -ENOTSUPP;
2178
Auke Kok9d5c8242008-01-24 02:22:38 -08002179 if ((ec->rx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
2180 ((ec->rx_coalesce_usecs > 3) &&
2181 (ec->rx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
2182 (ec->rx_coalesce_usecs == 2))
2183 return -EINVAL;
2184
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002185 if ((ec->tx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
2186 ((ec->tx_coalesce_usecs > 3) &&
2187 (ec->tx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
2188 (ec->tx_coalesce_usecs == 2))
2189 return -EINVAL;
2190
2191 if ((adapter->flags & IGB_FLAG_QUEUE_PAIRS) && ec->tx_coalesce_usecs)
2192 return -EINVAL;
2193
Carolyn Wyborny831ec0b2011-03-11 20:43:54 -08002194 /* If ITR is disabled, disable DMAC */
2195 if (ec->rx_coalesce_usecs == 0) {
2196 if (adapter->flags & IGB_FLAG_DMAC)
2197 adapter->flags &= ~IGB_FLAG_DMAC;
2198 }
2199
Auke Kok9d5c8242008-01-24 02:22:38 -08002200 /* convert to rate of irq's per second */
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002201 if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3)
2202 adapter->rx_itr_setting = ec->rx_coalesce_usecs;
2203 else
2204 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
2205
2206 /* convert to rate of irq's per second */
2207 if (adapter->flags & IGB_FLAG_QUEUE_PAIRS)
2208 adapter->tx_itr_setting = adapter->rx_itr_setting;
2209 else if (ec->tx_coalesce_usecs && ec->tx_coalesce_usecs <= 3)
2210 adapter->tx_itr_setting = ec->tx_coalesce_usecs;
2211 else
2212 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
Auke Kok9d5c8242008-01-24 02:22:38 -08002213
Alexander Duyck047e0032009-10-27 15:49:27 +00002214 for (i = 0; i < adapter->num_q_vectors; i++) {
2215 struct igb_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck0ba82992011-08-26 07:45:47 +00002216 q_vector->tx.work_limit = adapter->tx_work_limit;
2217 if (q_vector->rx.ring)
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002218 q_vector->itr_val = adapter->rx_itr_setting;
2219 else
2220 q_vector->itr_val = adapter->tx_itr_setting;
2221 if (q_vector->itr_val && q_vector->itr_val <= 3)
2222 q_vector->itr_val = IGB_START_ITR;
Alexander Duyck047e0032009-10-27 15:49:27 +00002223 q_vector->set_itr = 1;
2224 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002225
2226 return 0;
2227}
2228
2229static int igb_get_coalesce(struct net_device *netdev,
2230 struct ethtool_coalesce *ec)
2231{
2232 struct igb_adapter *adapter = netdev_priv(netdev);
2233
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002234 if (adapter->rx_itr_setting <= 3)
2235 ec->rx_coalesce_usecs = adapter->rx_itr_setting;
Auke Kok9d5c8242008-01-24 02:22:38 -08002236 else
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002237 ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
2238
2239 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS)) {
2240 if (adapter->tx_itr_setting <= 3)
2241 ec->tx_coalesce_usecs = adapter->tx_itr_setting;
2242 else
2243 ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
2244 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002245
2246 return 0;
2247}
2248
Auke Kok9d5c8242008-01-24 02:22:38 -08002249static int igb_nway_reset(struct net_device *netdev)
2250{
2251 struct igb_adapter *adapter = netdev_priv(netdev);
2252 if (netif_running(netdev))
2253 igb_reinit_locked(adapter);
2254 return 0;
2255}
2256
2257static int igb_get_sset_count(struct net_device *netdev, int sset)
2258{
2259 switch (sset) {
2260 case ETH_SS_STATS:
2261 return IGB_STATS_LEN;
2262 case ETH_SS_TEST:
2263 return IGB_TEST_LEN;
2264 default:
2265 return -ENOTSUPP;
2266 }
2267}
2268
2269static void igb_get_ethtool_stats(struct net_device *netdev,
2270 struct ethtool_stats *stats, u64 *data)
2271{
2272 struct igb_adapter *adapter = netdev_priv(netdev);
Eric Dumazet12dcd862010-10-15 17:27:10 +00002273 struct rtnl_link_stats64 *net_stats = &adapter->stats64;
2274 unsigned int start;
2275 struct igb_ring *ring;
2276 int i, j;
Alexander Duyck128e45e2009-11-12 18:37:38 +00002277 char *p;
Auke Kok9d5c8242008-01-24 02:22:38 -08002278
Eric Dumazet12dcd862010-10-15 17:27:10 +00002279 spin_lock(&adapter->stats64_lock);
2280 igb_update_stats(adapter, net_stats);
Alexander Duyck317f66b2009-10-27 23:46:20 +00002281
Auke Kok9d5c8242008-01-24 02:22:38 -08002282 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
Alexander Duyck128e45e2009-11-12 18:37:38 +00002283 p = (char *)adapter + igb_gstrings_stats[i].stat_offset;
Auke Kok9d5c8242008-01-24 02:22:38 -08002284 data[i] = (igb_gstrings_stats[i].sizeof_stat ==
2285 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2286 }
Alexander Duyck128e45e2009-11-12 18:37:38 +00002287 for (j = 0; j < IGB_NETDEV_STATS_LEN; j++, i++) {
2288 p = (char *)net_stats + igb_gstrings_net_stats[j].stat_offset;
2289 data[i] = (igb_gstrings_net_stats[j].sizeof_stat ==
2290 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2291 }
Alexander Duycke21ed352008-07-08 15:07:24 -07002292 for (j = 0; j < adapter->num_tx_queues; j++) {
Eric Dumazet12dcd862010-10-15 17:27:10 +00002293 u64 restart2;
2294
2295 ring = adapter->tx_ring[j];
2296 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07002297 start = u64_stats_fetch_begin_irq(&ring->tx_syncp);
Eric Dumazet12dcd862010-10-15 17:27:10 +00002298 data[i] = ring->tx_stats.packets;
2299 data[i+1] = ring->tx_stats.bytes;
2300 data[i+2] = ring->tx_stats.restart_queue;
Eric W. Biederman57a77442014-03-13 21:26:42 -07002301 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp, start));
Eric Dumazet12dcd862010-10-15 17:27:10 +00002302 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07002303 start = u64_stats_fetch_begin_irq(&ring->tx_syncp2);
Eric Dumazet12dcd862010-10-15 17:27:10 +00002304 restart2 = ring->tx_stats.restart_queue2;
Eric W. Biederman57a77442014-03-13 21:26:42 -07002305 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp2, start));
Eric Dumazet12dcd862010-10-15 17:27:10 +00002306 data[i+2] += restart2;
2307
2308 i += IGB_TX_QUEUE_STATS_LEN;
Alexander Duycke21ed352008-07-08 15:07:24 -07002309 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002310 for (j = 0; j < adapter->num_rx_queues; j++) {
Eric Dumazet12dcd862010-10-15 17:27:10 +00002311 ring = adapter->rx_ring[j];
2312 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07002313 start = u64_stats_fetch_begin_irq(&ring->rx_syncp);
Eric Dumazet12dcd862010-10-15 17:27:10 +00002314 data[i] = ring->rx_stats.packets;
2315 data[i+1] = ring->rx_stats.bytes;
2316 data[i+2] = ring->rx_stats.drops;
2317 data[i+3] = ring->rx_stats.csum_err;
2318 data[i+4] = ring->rx_stats.alloc_failed;
Eric W. Biederman57a77442014-03-13 21:26:42 -07002319 } while (u64_stats_fetch_retry_irq(&ring->rx_syncp, start));
Eric Dumazet12dcd862010-10-15 17:27:10 +00002320 i += IGB_RX_QUEUE_STATS_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002321 }
Eric Dumazet12dcd862010-10-15 17:27:10 +00002322 spin_unlock(&adapter->stats64_lock);
Auke Kok9d5c8242008-01-24 02:22:38 -08002323}
2324
2325static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
2326{
2327 struct igb_adapter *adapter = netdev_priv(netdev);
2328 u8 *p = data;
2329 int i;
2330
2331 switch (stringset) {
2332 case ETH_SS_TEST:
2333 memcpy(data, *igb_gstrings_test,
2334 IGB_TEST_LEN*ETH_GSTRING_LEN);
2335 break;
2336 case ETH_SS_STATS:
2337 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
2338 memcpy(p, igb_gstrings_stats[i].stat_string,
2339 ETH_GSTRING_LEN);
2340 p += ETH_GSTRING_LEN;
2341 }
Alexander Duyck128e45e2009-11-12 18:37:38 +00002342 for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) {
2343 memcpy(p, igb_gstrings_net_stats[i].stat_string,
2344 ETH_GSTRING_LEN);
2345 p += ETH_GSTRING_LEN;
2346 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002347 for (i = 0; i < adapter->num_tx_queues; i++) {
2348 sprintf(p, "tx_queue_%u_packets", i);
2349 p += ETH_GSTRING_LEN;
2350 sprintf(p, "tx_queue_%u_bytes", i);
2351 p += ETH_GSTRING_LEN;
Alexander Duyck04a5fcaa2009-10-27 15:52:27 +00002352 sprintf(p, "tx_queue_%u_restart", i);
2353 p += ETH_GSTRING_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002354 }
2355 for (i = 0; i < adapter->num_rx_queues; i++) {
2356 sprintf(p, "rx_queue_%u_packets", i);
2357 p += ETH_GSTRING_LEN;
2358 sprintf(p, "rx_queue_%u_bytes", i);
2359 p += ETH_GSTRING_LEN;
Jesper Dangaard Brouer8c0ab702009-05-26 13:50:31 +00002360 sprintf(p, "rx_queue_%u_drops", i);
2361 p += ETH_GSTRING_LEN;
Alexander Duyck04a5fcaa2009-10-27 15:52:27 +00002362 sprintf(p, "rx_queue_%u_csum_err", i);
2363 p += ETH_GSTRING_LEN;
2364 sprintf(p, "rx_queue_%u_alloc_failed", i);
2365 p += ETH_GSTRING_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002366 }
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002367 /* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
Auke Kok9d5c8242008-01-24 02:22:38 -08002368 break;
2369 }
2370}
2371
Matthew Vicka79f4f82012-08-10 05:40:44 +00002372static int igb_get_ts_info(struct net_device *dev,
Matthew Vicka9188022012-08-28 06:33:05 +00002373 struct ethtool_ts_info *info)
Carolyn Wybornycb411452012-04-04 17:43:59 +00002374{
2375 struct igb_adapter *adapter = netdev_priv(dev);
2376
Ken ICHIKAWA0f49da02014-03-21 03:37:24 -07002377 if (adapter->ptp_clock)
2378 info->phc_index = ptp_clock_index(adapter->ptp_clock);
2379 else
2380 info->phc_index = -1;
2381
Matthew Vicka9188022012-08-28 06:33:05 +00002382 switch (adapter->hw.mac.type) {
Matthew Vickb66e2392012-12-13 07:20:33 +00002383 case e1000_82575:
2384 info->so_timestamping =
2385 SOF_TIMESTAMPING_TX_SOFTWARE |
2386 SOF_TIMESTAMPING_RX_SOFTWARE |
2387 SOF_TIMESTAMPING_SOFTWARE;
2388 return 0;
Matthew Vicka9188022012-08-28 06:33:05 +00002389 case e1000_82576:
2390 case e1000_82580:
2391 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002392 case e1000_i354:
Matthew Vicka9188022012-08-28 06:33:05 +00002393 case e1000_i210:
2394 case e1000_i211:
2395 info->so_timestamping =
Matthew Vickb66e2392012-12-13 07:20:33 +00002396 SOF_TIMESTAMPING_TX_SOFTWARE |
2397 SOF_TIMESTAMPING_RX_SOFTWARE |
2398 SOF_TIMESTAMPING_SOFTWARE |
Matthew Vicka9188022012-08-28 06:33:05 +00002399 SOF_TIMESTAMPING_TX_HARDWARE |
2400 SOF_TIMESTAMPING_RX_HARDWARE |
2401 SOF_TIMESTAMPING_RAW_HARDWARE;
Carolyn Wybornycb411452012-04-04 17:43:59 +00002402
Matthew Vicka9188022012-08-28 06:33:05 +00002403 info->tx_types =
2404 (1 << HWTSTAMP_TX_OFF) |
2405 (1 << HWTSTAMP_TX_ON);
Carolyn Wybornycb411452012-04-04 17:43:59 +00002406
Matthew Vicka9188022012-08-28 06:33:05 +00002407 info->rx_filters = 1 << HWTSTAMP_FILTER_NONE;
Carolyn Wybornycb411452012-04-04 17:43:59 +00002408
Matthew Vicka9188022012-08-28 06:33:05 +00002409 /* 82576 does not support timestamping all packets. */
2410 if (adapter->hw.mac.type >= e1000_82580)
2411 info->rx_filters |= 1 << HWTSTAMP_FILTER_ALL;
2412 else
2413 info->rx_filters |=
2414 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
2415 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
Matthew Vicka9188022012-08-28 06:33:05 +00002416 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
2417
2418 return 0;
Matthew Vicka9188022012-08-28 06:33:05 +00002419 default:
2420 return -EOPNOTSUPP;
2421 }
2422}
Carolyn Wybornycb411452012-04-04 17:43:59 +00002423
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002424static int igb_get_rss_hash_opts(struct igb_adapter *adapter,
2425 struct ethtool_rxnfc *cmd)
2426{
2427 cmd->data = 0;
2428
2429 /* Report default options for RSS on igb */
2430 switch (cmd->flow_type) {
2431 case TCP_V4_FLOW:
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 UDP_V4_FLOW:
2435 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
2436 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
Carolyn Wybornyb26141d2014-04-17 04:10:13 +00002437 /* Fall through */
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002438 case SCTP_V4_FLOW:
2439 case AH_ESP_V4_FLOW:
2440 case AH_V4_FLOW:
2441 case ESP_V4_FLOW:
2442 case IPV4_FLOW:
2443 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2444 break;
2445 case TCP_V6_FLOW:
2446 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
Carolyn Wybornyb26141d2014-04-17 04:10:13 +00002447 /* Fall through */
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002448 case UDP_V6_FLOW:
2449 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
2450 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
Carolyn Wybornyb26141d2014-04-17 04:10:13 +00002451 /* Fall through */
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002452 case SCTP_V6_FLOW:
2453 case AH_ESP_V6_FLOW:
2454 case AH_V6_FLOW:
2455 case ESP_V6_FLOW:
2456 case IPV6_FLOW:
2457 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2458 break;
2459 default:
2460 return -EINVAL;
2461 }
2462
2463 return 0;
2464}
2465
2466static int igb_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002467 u32 *rule_locs)
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002468{
2469 struct igb_adapter *adapter = netdev_priv(dev);
2470 int ret = -EOPNOTSUPP;
2471
2472 switch (cmd->cmd) {
2473 case ETHTOOL_GRXRINGS:
2474 cmd->data = adapter->num_rx_queues;
2475 ret = 0;
2476 break;
2477 case ETHTOOL_GRXFH:
2478 ret = igb_get_rss_hash_opts(adapter, cmd);
2479 break;
2480 default:
2481 break;
2482 }
2483
2484 return ret;
2485}
2486
2487#define UDP_RSS_FLAGS (IGB_FLAG_RSS_FIELD_IPV4_UDP | \
2488 IGB_FLAG_RSS_FIELD_IPV6_UDP)
2489static int igb_set_rss_hash_opt(struct igb_adapter *adapter,
2490 struct ethtool_rxnfc *nfc)
2491{
2492 u32 flags = adapter->flags;
2493
2494 /* RSS does not support anything other than hashing
2495 * to queues on src and dst IPs and ports
2496 */
2497 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2498 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2499 return -EINVAL;
2500
2501 switch (nfc->flow_type) {
2502 case TCP_V4_FLOW:
2503 case TCP_V6_FLOW:
2504 if (!(nfc->data & RXH_IP_SRC) ||
2505 !(nfc->data & RXH_IP_DST) ||
2506 !(nfc->data & RXH_L4_B_0_1) ||
2507 !(nfc->data & RXH_L4_B_2_3))
2508 return -EINVAL;
2509 break;
2510 case UDP_V4_FLOW:
2511 if (!(nfc->data & RXH_IP_SRC) ||
2512 !(nfc->data & RXH_IP_DST))
2513 return -EINVAL;
2514 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2515 case 0:
2516 flags &= ~IGB_FLAG_RSS_FIELD_IPV4_UDP;
2517 break;
2518 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2519 flags |= IGB_FLAG_RSS_FIELD_IPV4_UDP;
2520 break;
2521 default:
2522 return -EINVAL;
2523 }
2524 break;
2525 case UDP_V6_FLOW:
2526 if (!(nfc->data & RXH_IP_SRC) ||
2527 !(nfc->data & RXH_IP_DST))
2528 return -EINVAL;
2529 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2530 case 0:
2531 flags &= ~IGB_FLAG_RSS_FIELD_IPV6_UDP;
2532 break;
2533 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2534 flags |= IGB_FLAG_RSS_FIELD_IPV6_UDP;
2535 break;
2536 default:
2537 return -EINVAL;
2538 }
2539 break;
2540 case AH_ESP_V4_FLOW:
2541 case AH_V4_FLOW:
2542 case ESP_V4_FLOW:
2543 case SCTP_V4_FLOW:
2544 case AH_ESP_V6_FLOW:
2545 case AH_V6_FLOW:
2546 case ESP_V6_FLOW:
2547 case SCTP_V6_FLOW:
2548 if (!(nfc->data & RXH_IP_SRC) ||
2549 !(nfc->data & RXH_IP_DST) ||
2550 (nfc->data & RXH_L4_B_0_1) ||
2551 (nfc->data & RXH_L4_B_2_3))
2552 return -EINVAL;
2553 break;
2554 default:
2555 return -EINVAL;
2556 }
2557
2558 /* if we changed something we need to update flags */
2559 if (flags != adapter->flags) {
2560 struct e1000_hw *hw = &adapter->hw;
2561 u32 mrqc = rd32(E1000_MRQC);
2562
2563 if ((flags & UDP_RSS_FLAGS) &&
2564 !(adapter->flags & UDP_RSS_FLAGS))
2565 dev_err(&adapter->pdev->dev,
2566 "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
2567
2568 adapter->flags = flags;
2569
2570 /* Perform hash on these packet types */
2571 mrqc |= E1000_MRQC_RSS_FIELD_IPV4 |
2572 E1000_MRQC_RSS_FIELD_IPV4_TCP |
2573 E1000_MRQC_RSS_FIELD_IPV6 |
2574 E1000_MRQC_RSS_FIELD_IPV6_TCP;
2575
2576 mrqc &= ~(E1000_MRQC_RSS_FIELD_IPV4_UDP |
2577 E1000_MRQC_RSS_FIELD_IPV6_UDP);
2578
2579 if (flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
2580 mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
2581
2582 if (flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
2583 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
2584
2585 wr32(E1000_MRQC, mrqc);
2586 }
2587
2588 return 0;
2589}
2590
2591static int igb_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
2592{
2593 struct igb_adapter *adapter = netdev_priv(dev);
2594 int ret = -EOPNOTSUPP;
2595
2596 switch (cmd->cmd) {
2597 case ETHTOOL_SRXFH:
2598 ret = igb_set_rss_hash_opt(adapter, cmd);
2599 break;
2600 default:
2601 break;
2602 }
2603
2604 return ret;
2605}
2606
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002607static int igb_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
2608{
2609 struct igb_adapter *adapter = netdev_priv(netdev);
2610 struct e1000_hw *hw = &adapter->hw;
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002611 u32 ret_val;
Matthew Vick87371b92013-02-21 03:32:52 +00002612 u16 phy_data;
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002613
2614 if ((hw->mac.type < e1000_i350) ||
2615 (hw->phy.media_type != e1000_media_type_copper))
2616 return -EOPNOTSUPP;
2617
2618 edata->supported = (SUPPORTED_1000baseT_Full |
2619 SUPPORTED_100baseT_Full);
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002620 if (!hw->dev_spec._82575.eee_disable)
2621 edata->advertised =
2622 mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002623
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002624 /* The IPCNFG and EEER registers are not supported on I354. */
2625 if (hw->mac.type == e1000_i354) {
2626 igb_get_eee_status_i354(hw, (bool *)&edata->eee_active);
2627 } else {
2628 u32 eeer;
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002629
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002630 eeer = rd32(E1000_EEER);
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002631
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002632 /* EEE status on negotiated link */
2633 if (eeer & E1000_EEER_EEE_NEG)
2634 edata->eee_active = true;
2635
2636 if (eeer & E1000_EEER_TX_LPI_EN)
2637 edata->tx_lpi_enabled = true;
2638 }
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002639
Matthew Vick87371b92013-02-21 03:32:52 +00002640 /* EEE Link Partner Advertised */
2641 switch (hw->mac.type) {
2642 case e1000_i350:
2643 ret_val = igb_read_emi_reg(hw, E1000_EEE_LP_ADV_ADDR_I350,
2644 &phy_data);
2645 if (ret_val)
2646 return -ENODATA;
2647
2648 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
Matthew Vick87371b92013-02-21 03:32:52 +00002649 break;
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002650 case e1000_i354:
Matthew Vick87371b92013-02-21 03:32:52 +00002651 case e1000_i210:
2652 case e1000_i211:
2653 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_LP_ADV_ADDR_I210,
2654 E1000_EEE_LP_ADV_DEV_I210,
2655 &phy_data);
2656 if (ret_val)
2657 return -ENODATA;
2658
2659 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
2660
2661 break;
2662 default:
2663 break;
2664 }
2665
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002666 edata->eee_enabled = !hw->dev_spec._82575.eee_disable;
2667
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002668 if ((hw->mac.type == e1000_i354) &&
2669 (edata->eee_enabled))
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002670 edata->tx_lpi_enabled = true;
2671
2672 /* Report correct negotiated EEE status for devices that
2673 * wrongly report EEE at half-duplex
2674 */
2675 if (adapter->link_duplex == HALF_DUPLEX) {
2676 edata->eee_enabled = false;
2677 edata->eee_active = false;
2678 edata->tx_lpi_enabled = false;
2679 edata->advertised &= ~edata->advertised;
2680 }
2681
2682 return 0;
2683}
2684
2685static int igb_set_eee(struct net_device *netdev,
2686 struct ethtool_eee *edata)
2687{
2688 struct igb_adapter *adapter = netdev_priv(netdev);
2689 struct e1000_hw *hw = &adapter->hw;
2690 struct ethtool_eee eee_curr;
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002691 bool adv1g_eee = true, adv100m_eee = true;
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002692 s32 ret_val;
2693
2694 if ((hw->mac.type < e1000_i350) ||
2695 (hw->phy.media_type != e1000_media_type_copper))
2696 return -EOPNOTSUPP;
2697
Andi Kleen58e4e1f2013-09-30 13:29:08 -07002698 memset(&eee_curr, 0, sizeof(struct ethtool_eee));
2699
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002700 ret_val = igb_get_eee(netdev, &eee_curr);
2701 if (ret_val)
2702 return ret_val;
2703
2704 if (eee_curr.eee_enabled) {
2705 if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
2706 dev_err(&adapter->pdev->dev,
2707 "Setting EEE tx-lpi is not supported\n");
2708 return -EINVAL;
2709 }
2710
2711 /* Tx LPI timer is not implemented currently */
2712 if (edata->tx_lpi_timer) {
2713 dev_err(&adapter->pdev->dev,
2714 "Setting EEE Tx LPI timer is not supported\n");
2715 return -EINVAL;
2716 }
2717
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002718 if (!edata->advertised || (edata->advertised &
2719 ~(ADVERTISE_100_FULL | ADVERTISE_1000_FULL))) {
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002720 dev_err(&adapter->pdev->dev,
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002721 "EEE Advertisement supports only 100Tx and/or 100T full duplex\n");
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002722 return -EINVAL;
2723 }
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002724 adv100m_eee = !!(edata->advertised & ADVERTISE_100_FULL);
2725 adv1g_eee = !!(edata->advertised & ADVERTISE_1000_FULL);
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002726
2727 } else if (!edata->eee_enabled) {
2728 dev_err(&adapter->pdev->dev,
2729 "Setting EEE options are not supported with EEE disabled\n");
2730 return -EINVAL;
2731 }
2732
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002733 adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002734 if (hw->dev_spec._82575.eee_disable != !edata->eee_enabled) {
2735 hw->dev_spec._82575.eee_disable = !edata->eee_enabled;
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002736 adapter->flags |= IGB_FLAG_EEE;
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002737
2738 /* reset link */
Akeem G Abodunrin8a650aa2013-05-24 07:20:57 +00002739 if (netif_running(netdev))
2740 igb_reinit_locked(adapter);
2741 else
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002742 igb_reset(adapter);
2743 }
2744
Todd Fujinakac4c112f2014-08-29 06:43:13 +00002745 if (hw->mac.type == e1000_i354)
2746 ret_val = igb_set_eee_i354(hw, adv1g_eee, adv100m_eee);
2747 else
2748 ret_val = igb_set_eee_i350(hw, adv1g_eee, adv100m_eee);
2749
2750 if (ret_val) {
2751 dev_err(&adapter->pdev->dev,
2752 "Problem setting EEE advertisement options\n");
2753 return -EINVAL;
2754 }
2755
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002756 return 0;
2757}
2758
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00002759static int igb_get_module_info(struct net_device *netdev,
2760 struct ethtool_modinfo *modinfo)
2761{
2762 struct igb_adapter *adapter = netdev_priv(netdev);
2763 struct e1000_hw *hw = &adapter->hw;
Todd Fujinaka23d87822014-06-04 07:12:15 +00002764 u32 status = 0;
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00002765 u16 sff8472_rev, addr_mode;
2766 bool page_swap = false;
2767
2768 if ((hw->phy.media_type == e1000_media_type_copper) ||
2769 (hw->phy.media_type == e1000_media_type_unknown))
2770 return -EOPNOTSUPP;
2771
2772 /* Check whether we support SFF-8472 or not */
2773 status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_COMP, &sff8472_rev);
Todd Fujinaka23d87822014-06-04 07:12:15 +00002774 if (status)
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00002775 return -EIO;
2776
2777 /* addressing mode is not supported */
2778 status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_SWAP, &addr_mode);
Todd Fujinaka23d87822014-06-04 07:12:15 +00002779 if (status)
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00002780 return -EIO;
2781
2782 /* addressing mode is not supported */
2783 if ((addr_mode & 0xFF) & IGB_SFF_ADDRESSING_MODE) {
2784 hw_dbg("Address change required to access page 0xA2, but not supported. Please report the module type to the driver maintainers.\n");
2785 page_swap = true;
2786 }
2787
2788 if ((sff8472_rev & 0xFF) == IGB_SFF_8472_UNSUP || page_swap) {
2789 /* We have an SFP, but it does not support SFF-8472 */
2790 modinfo->type = ETH_MODULE_SFF_8079;
2791 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
2792 } else {
2793 /* We have an SFP which supports a revision of SFF-8472 */
2794 modinfo->type = ETH_MODULE_SFF_8472;
2795 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
2796 }
2797
2798 return 0;
2799}
2800
2801static int igb_get_module_eeprom(struct net_device *netdev,
2802 struct ethtool_eeprom *ee, u8 *data)
2803{
2804 struct igb_adapter *adapter = netdev_priv(netdev);
2805 struct e1000_hw *hw = &adapter->hw;
Todd Fujinaka23d87822014-06-04 07:12:15 +00002806 u32 status = 0;
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00002807 u16 *dataword;
2808 u16 first_word, last_word;
2809 int i = 0;
2810
2811 if (ee->len == 0)
2812 return -EINVAL;
2813
2814 first_word = ee->offset >> 1;
2815 last_word = (ee->offset + ee->len - 1) >> 1;
2816
2817 dataword = kmalloc(sizeof(u16) * (last_word - first_word + 1),
2818 GFP_KERNEL);
2819 if (!dataword)
2820 return -ENOMEM;
2821
2822 /* Read EEPROM block, SFF-8079/SFF-8472, word at a time */
2823 for (i = 0; i < last_word - first_word + 1; i++) {
2824 status = igb_read_phy_reg_i2c(hw, first_word + i, &dataword[i]);
Todd Fujinaka23d87822014-06-04 07:12:15 +00002825 if (status) {
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00002826 /* Error occurred while reading module */
Christian Engelmayerdb41b872014-03-21 03:25:30 -07002827 kfree(dataword);
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00002828 return -EIO;
Christian Engelmayerdb41b872014-03-21 03:25:30 -07002829 }
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00002830
2831 be16_to_cpus(&dataword[i]);
2832 }
2833
2834 memcpy(data, (u8 *)dataword + (ee->offset & 1), ee->len);
2835 kfree(dataword);
2836
2837 return 0;
2838}
2839
Matthew Vicka79f4f82012-08-10 05:40:44 +00002840static int igb_ethtool_begin(struct net_device *netdev)
2841{
2842 struct igb_adapter *adapter = netdev_priv(netdev);
2843 pm_runtime_get_sync(&adapter->pdev->dev);
2844 return 0;
2845}
2846
2847static void igb_ethtool_complete(struct net_device *netdev)
2848{
2849 struct igb_adapter *adapter = netdev_priv(netdev);
2850 pm_runtime_put(&adapter->pdev->dev);
2851}
2852
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00002853static u32 igb_get_rxfh_indir_size(struct net_device *netdev)
2854{
2855 return IGB_RETA_SIZE;
2856}
2857
Eyal Perry892311f2014-12-02 18:12:10 +02002858static int igb_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2859 u8 *hfunc)
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00002860{
2861 struct igb_adapter *adapter = netdev_priv(netdev);
2862 int i;
2863
Eyal Perry892311f2014-12-02 18:12:10 +02002864 if (hfunc)
2865 *hfunc = ETH_RSS_HASH_TOP;
2866 if (!indir)
2867 return 0;
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00002868 for (i = 0; i < IGB_RETA_SIZE; i++)
2869 indir[i] = adapter->rss_indir_tbl[i];
2870
2871 return 0;
2872}
2873
2874void igb_write_rss_indir_tbl(struct igb_adapter *adapter)
2875{
2876 struct e1000_hw *hw = &adapter->hw;
2877 u32 reg = E1000_RETA(0);
2878 u32 shift = 0;
2879 int i = 0;
2880
2881 switch (hw->mac.type) {
2882 case e1000_82575:
2883 shift = 6;
2884 break;
2885 case e1000_82576:
2886 /* 82576 supports 2 RSS queues for SR-IOV */
2887 if (adapter->vfs_allocated_count)
2888 shift = 3;
2889 break;
2890 default:
2891 break;
2892 }
2893
2894 while (i < IGB_RETA_SIZE) {
2895 u32 val = 0;
2896 int j;
2897
2898 for (j = 3; j >= 0; j--) {
2899 val <<= 8;
2900 val |= adapter->rss_indir_tbl[i + j];
2901 }
2902
2903 wr32(reg, val << shift);
2904 reg += 4;
2905 i += 4;
2906 }
2907}
2908
Ben Hutchingsfe62d002014-05-15 01:25:27 +01002909static int igb_set_rxfh(struct net_device *netdev, const u32 *indir,
Eyal Perry892311f2014-12-02 18:12:10 +02002910 const u8 *key, const u8 hfunc)
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00002911{
2912 struct igb_adapter *adapter = netdev_priv(netdev);
2913 struct e1000_hw *hw = &adapter->hw;
2914 int i;
2915 u32 num_queues;
2916
Eyal Perry892311f2014-12-02 18:12:10 +02002917 /* We do not allow change in unsupported parameters */
2918 if (key ||
2919 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
2920 return -EOPNOTSUPP;
2921 if (!indir)
2922 return 0;
2923
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00002924 num_queues = adapter->rss_queues;
2925
2926 switch (hw->mac.type) {
2927 case e1000_82576:
2928 /* 82576 supports 2 RSS queues for SR-IOV */
2929 if (adapter->vfs_allocated_count)
2930 num_queues = 2;
2931 break;
2932 default:
2933 break;
2934 }
2935
2936 /* Verify user input. */
2937 for (i = 0; i < IGB_RETA_SIZE; i++)
2938 if (indir[i] >= num_queues)
2939 return -EINVAL;
2940
2941
2942 for (i = 0; i < IGB_RETA_SIZE; i++)
2943 adapter->rss_indir_tbl[i] = indir[i];
2944
2945 igb_write_rss_indir_tbl(adapter);
2946
2947 return 0;
2948}
2949
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07002950static unsigned int igb_max_channels(struct igb_adapter *adapter)
2951{
2952 struct e1000_hw *hw = &adapter->hw;
2953 unsigned int max_combined = 0;
2954
2955 switch (hw->mac.type) {
2956 case e1000_i211:
2957 max_combined = IGB_MAX_RX_QUEUES_I211;
2958 break;
2959 case e1000_82575:
2960 case e1000_i210:
2961 max_combined = IGB_MAX_RX_QUEUES_82575;
2962 break;
2963 case e1000_i350:
2964 if (!!adapter->vfs_allocated_count) {
2965 max_combined = 1;
2966 break;
2967 }
2968 /* fall through */
2969 case e1000_82576:
2970 if (!!adapter->vfs_allocated_count) {
2971 max_combined = 2;
2972 break;
2973 }
2974 /* fall through */
2975 case e1000_82580:
2976 case e1000_i354:
2977 default:
2978 max_combined = IGB_MAX_RX_QUEUES;
2979 break;
2980 }
2981
2982 return max_combined;
2983}
2984
2985static void igb_get_channels(struct net_device *netdev,
2986 struct ethtool_channels *ch)
2987{
2988 struct igb_adapter *adapter = netdev_priv(netdev);
2989
2990 /* Report maximum channels */
2991 ch->max_combined = igb_max_channels(adapter);
2992
2993 /* Report info for other vector */
Carolyn Wybornycd14ef52013-12-10 07:58:34 +00002994 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07002995 ch->max_other = NON_Q_VECTORS;
2996 ch->other_count = NON_Q_VECTORS;
2997 }
2998
2999 ch->combined_count = adapter->rss_queues;
3000}
3001
3002static int igb_set_channels(struct net_device *netdev,
3003 struct ethtool_channels *ch)
3004{
3005 struct igb_adapter *adapter = netdev_priv(netdev);
3006 unsigned int count = ch->combined_count;
Shota Suzuki72ddef02015-07-01 09:25:52 +09003007 unsigned int max_combined = 0;
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07003008
3009 /* Verify they are not requesting separate vectors */
3010 if (!count || ch->rx_count || ch->tx_count)
3011 return -EINVAL;
3012
3013 /* Verify other_count is valid and has not been changed */
3014 if (ch->other_count != NON_Q_VECTORS)
3015 return -EINVAL;
3016
3017 /* Verify the number of channels doesn't exceed hw limits */
Shota Suzuki72ddef02015-07-01 09:25:52 +09003018 max_combined = igb_max_channels(adapter);
3019 if (count > max_combined)
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07003020 return -EINVAL;
3021
3022 if (count != adapter->rss_queues) {
3023 adapter->rss_queues = count;
Shota Suzuki72ddef02015-07-01 09:25:52 +09003024 igb_set_flag_queue_pairs(adapter, max_combined);
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07003025
3026 /* Hardware has to reinitialize queues and interrupts to
3027 * match the new configuration.
3028 */
3029 return igb_reinit_queues(adapter);
3030 }
3031
3032 return 0;
3033}
3034
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003035static const struct ethtool_ops igb_ethtool_ops = {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00003036 .get_settings = igb_get_settings,
3037 .set_settings = igb_set_settings,
3038 .get_drvinfo = igb_get_drvinfo,
3039 .get_regs_len = igb_get_regs_len,
3040 .get_regs = igb_get_regs,
3041 .get_wol = igb_get_wol,
3042 .set_wol = igb_set_wol,
3043 .get_msglevel = igb_get_msglevel,
3044 .set_msglevel = igb_set_msglevel,
3045 .nway_reset = igb_nway_reset,
3046 .get_link = igb_get_link,
3047 .get_eeprom_len = igb_get_eeprom_len,
3048 .get_eeprom = igb_get_eeprom,
3049 .set_eeprom = igb_set_eeprom,
3050 .get_ringparam = igb_get_ringparam,
3051 .set_ringparam = igb_set_ringparam,
3052 .get_pauseparam = igb_get_pauseparam,
3053 .set_pauseparam = igb_set_pauseparam,
3054 .self_test = igb_diag_test,
3055 .get_strings = igb_get_strings,
3056 .set_phys_id = igb_set_phys_id,
3057 .get_sset_count = igb_get_sset_count,
3058 .get_ethtool_stats = igb_get_ethtool_stats,
3059 .get_coalesce = igb_get_coalesce,
3060 .set_coalesce = igb_set_coalesce,
3061 .get_ts_info = igb_get_ts_info,
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00003062 .get_rxnfc = igb_get_rxnfc,
3063 .set_rxnfc = igb_set_rxnfc,
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003064 .get_eee = igb_get_eee,
3065 .set_eee = igb_set_eee,
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00003066 .get_module_info = igb_get_module_info,
3067 .get_module_eeprom = igb_get_module_eeprom,
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00003068 .get_rxfh_indir_size = igb_get_rxfh_indir_size,
Ben Hutchingsfe62d002014-05-15 01:25:27 +01003069 .get_rxfh = igb_get_rxfh,
3070 .set_rxfh = igb_set_rxfh,
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07003071 .get_channels = igb_get_channels,
3072 .set_channels = igb_set_channels,
Yan, Zheng749ab2c2012-01-04 20:23:37 +00003073 .begin = igb_ethtool_begin,
3074 .complete = igb_ethtool_complete,
Auke Kok9d5c8242008-01-24 02:22:38 -08003075};
3076
3077void igb_set_ethtool_ops(struct net_device *netdev)
3078{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003079 netdev->ethtool_ops = &igb_ethtool_ops;
Auke Kok9d5c8242008-01-24 02:22:38 -08003080}