blob: 797b9daba224aa95e68816a677409e31a4d1a349 [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
Joe Schultzd602de02015-11-03 12:37:29 -0600130enum igb_diagnostics_results {
131 TEST_REG = 0,
132 TEST_EEP,
133 TEST_IRQ,
134 TEST_LOOP,
135 TEST_LINK
136};
137
Auke Kok9d5c8242008-01-24 02:22:38 -0800138static const char igb_gstrings_test[][ETH_GSTRING_LEN] = {
Joe Schultzd602de02015-11-03 12:37:29 -0600139 [TEST_REG] = "Register test (offline)",
140 [TEST_EEP] = "Eeprom test (offline)",
141 [TEST_IRQ] = "Interrupt test (offline)",
142 [TEST_LOOP] = "Loopback test (offline)",
143 [TEST_LINK] = "Link test (on/offline)"
Auke Kok9d5c8242008-01-24 02:22:38 -0800144};
Alexander Duyck317f66b2009-10-27 23:46:20 +0000145#define IGB_TEST_LEN (sizeof(igb_gstrings_test) / ETH_GSTRING_LEN)
Auke Kok9d5c8242008-01-24 02:22:38 -0800146
Alexander Duycke0891292017-02-06 18:26:52 -0800147static const char igb_priv_flags_strings[][ETH_GSTRING_LEN] = {
148#define IGB_PRIV_FLAGS_LEGACY_RX BIT(0)
149 "legacy-rx",
150};
151
152#define IGB_PRIV_FLAGS_STR_LEN ARRAY_SIZE(igb_priv_flags_strings)
153
Auke Kok9d5c8242008-01-24 02:22:38 -0800154static int igb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
155{
156 struct igb_adapter *adapter = netdev_priv(netdev);
157 struct e1000_hw *hw = &adapter->hw;
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000158 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
159 struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags;
Alexander Duyck317f66b2009-10-27 23:46:20 +0000160 u32 status;
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200161 u32 speed;
Auke Kok9d5c8242008-01-24 02:22:38 -0800162
Carolyn Wyborny01237132013-11-09 04:52:14 -0800163 status = rd32(E1000_STATUS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800164 if (hw->phy.media_type == e1000_media_type_copper) {
165
166 ecmd->supported = (SUPPORTED_10baseT_Half |
167 SUPPORTED_10baseT_Full |
168 SUPPORTED_100baseT_Half |
169 SUPPORTED_100baseT_Full |
170 SUPPORTED_1000baseT_Full|
171 SUPPORTED_Autoneg |
Akeem G. Abodunrin42f3c432012-08-17 03:35:07 +0000172 SUPPORTED_TP |
173 SUPPORTED_Pause);
174 ecmd->advertising = ADVERTISED_TP;
Auke Kok9d5c8242008-01-24 02:22:38 -0800175
176 if (hw->mac.autoneg == 1) {
177 ecmd->advertising |= ADVERTISED_Autoneg;
178 /* the e1000 autoneg seems to match ethtool nicely */
179 ecmd->advertising |= hw->phy.autoneg_advertised;
180 }
181
182 ecmd->port = PORT_TP;
183 ecmd->phy_address = hw->phy.addr;
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000184 ecmd->transceiver = XCVR_INTERNAL;
Auke Kok9d5c8242008-01-24 02:22:38 -0800185 } else {
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000186 ecmd->supported = (SUPPORTED_FIBRE |
Carolyn Wyborny01237132013-11-09 04:52:14 -0800187 SUPPORTED_1000baseKX_Full |
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000188 SUPPORTED_Autoneg |
189 SUPPORTED_Pause);
Carolyn Wyborny01237132013-11-09 04:52:14 -0800190 ecmd->advertising = (ADVERTISED_FIBRE |
191 ADVERTISED_1000baseKX_Full);
192 if (hw->mac.type == e1000_i354) {
193 if ((hw->device_id ==
194 E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) &&
195 !(status & E1000_STATUS_2P5_SKU_OVER)) {
196 ecmd->supported |= SUPPORTED_2500baseX_Full;
197 ecmd->supported &=
198 ~SUPPORTED_1000baseKX_Full;
199 ecmd->advertising |= ADVERTISED_2500baseX_Full;
200 ecmd->advertising &=
201 ~ADVERTISED_1000baseKX_Full;
202 }
Akeem G. Abodunrin641ac5c2013-04-24 16:54:50 +0000203 }
204 if (eth_flags->e100_base_fx) {
205 ecmd->supported |= SUPPORTED_100baseT_Full;
206 ecmd->advertising |= ADVERTISED_100baseT_Full;
207 }
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000208 if (hw->mac.autoneg == 1)
209 ecmd->advertising |= ADVERTISED_Autoneg;
Auke Kok9d5c8242008-01-24 02:22:38 -0800210
211 ecmd->port = PORT_FIBRE;
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000212 ecmd->transceiver = XCVR_EXTERNAL;
Auke Kok9d5c8242008-01-24 02:22:38 -0800213 }
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000214 if (hw->mac.autoneg != 1)
215 ecmd->advertising &= ~(ADVERTISED_Pause |
216 ADVERTISED_Asym_Pause);
217
Carolyn Wyborny01237132013-11-09 04:52:14 -0800218 switch (hw->fc.requested_mode) {
219 case e1000_fc_full:
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000220 ecmd->advertising |= ADVERTISED_Pause;
Carolyn Wyborny01237132013-11-09 04:52:14 -0800221 break;
222 case e1000_fc_rx_pause:
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000223 ecmd->advertising |= (ADVERTISED_Pause |
224 ADVERTISED_Asym_Pause);
Carolyn Wyborny01237132013-11-09 04:52:14 -0800225 break;
226 case e1000_fc_tx_pause:
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000227 ecmd->advertising |= ADVERTISED_Asym_Pause;
Carolyn Wyborny01237132013-11-09 04:52:14 -0800228 break;
229 default:
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000230 ecmd->advertising &= ~(ADVERTISED_Pause |
231 ADVERTISED_Asym_Pause);
Carolyn Wyborny01237132013-11-09 04:52:14 -0800232 }
Alexander Duyck317f66b2009-10-27 23:46:20 +0000233 if (status & E1000_STATUS_LU) {
Carolyn Wyborny01237132013-11-09 04:52:14 -0800234 if ((status & E1000_STATUS_2P5_SKU) &&
235 !(status & E1000_STATUS_2P5_SKU_OVER)) {
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200236 speed = SPEED_2500;
Akeem G Abodunrin41fcfbe2013-08-30 23:49:36 +0000237 } else if (status & E1000_STATUS_SPEED_1000) {
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200238 speed = SPEED_1000;
Akeem G Abodunrin41fcfbe2013-08-30 23:49:36 +0000239 } else if (status & E1000_STATUS_SPEED_100) {
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200240 speed = SPEED_100;
Akeem G Abodunrin41fcfbe2013-08-30 23:49:36 +0000241 } else {
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200242 speed = SPEED_10;
Akeem G Abodunrin41fcfbe2013-08-30 23:49:36 +0000243 }
Alexander Duyck317f66b2009-10-27 23:46:20 +0000244 if ((status & E1000_STATUS_FD) ||
245 hw->phy.media_type != e1000_media_type_copper)
Auke Kok9d5c8242008-01-24 02:22:38 -0800246 ecmd->duplex = DUPLEX_FULL;
247 else
248 ecmd->duplex = DUPLEX_HALF;
249 } else {
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200250 speed = SPEED_UNKNOWN;
Jiri Pirko537fae02014-06-06 14:17:00 +0200251 ecmd->duplex = DUPLEX_UNKNOWN;
Auke Kok9d5c8242008-01-24 02:22:38 -0800252 }
Jiri Pirkod4f3cd42014-06-06 14:17:01 +0200253 ethtool_cmd_speed_set(ecmd, speed);
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000254 if ((hw->phy.media_type == e1000_media_type_fiber) ||
255 hw->mac.autoneg)
256 ecmd->autoneg = AUTONEG_ENABLE;
257 else
258 ecmd->autoneg = AUTONEG_DISABLE;
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000259
260 /* MDI-X => 2; MDI =>1; Invalid =>0 */
261 if (hw->phy.media_type == e1000_media_type_copper)
262 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
263 ETH_TP_MDI;
264 else
265 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
266
267 if (hw->phy.mdix == AUTO_ALL_MODES)
268 ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
269 else
270 ecmd->eth_tp_mdix_ctrl = hw->phy.mdix;
271
Auke Kok9d5c8242008-01-24 02:22:38 -0800272 return 0;
273}
274
275static int igb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
276{
277 struct igb_adapter *adapter = netdev_priv(netdev);
278 struct e1000_hw *hw = &adapter->hw;
279
280 /* When SoL/IDER sessions are active, autoneg/speed/duplex
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000281 * cannot be changed
282 */
Auke Kok9d5c8242008-01-24 02:22:38 -0800283 if (igb_check_reset_block(hw)) {
Jesper Juhld836200a2012-08-01 05:41:30 +0000284 dev_err(&adapter->pdev->dev,
285 "Cannot change link characteristics when SoL/IDER is active.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800286 return -EINVAL;
287 }
288
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000289 /* MDI setting is only allowed when autoneg enabled because
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000290 * some hardware doesn't allow MDI setting when speed or
291 * duplex is forced.
292 */
293 if (ecmd->eth_tp_mdix_ctrl) {
294 if (hw->phy.media_type != e1000_media_type_copper)
295 return -EOPNOTSUPP;
296
297 if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
298 (ecmd->autoneg != AUTONEG_ENABLE)) {
299 dev_err(&adapter->pdev->dev, "forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
300 return -EINVAL;
301 }
302 }
303
Auke Kok9d5c8242008-01-24 02:22:38 -0800304 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
Carolyn Wyborny0d451e72014-04-11 01:46:40 +0000305 usleep_range(1000, 2000);
Auke Kok9d5c8242008-01-24 02:22:38 -0800306
307 if (ecmd->autoneg == AUTONEG_ENABLE) {
308 hw->mac.autoneg = 1;
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000309 if (hw->phy.media_type == e1000_media_type_fiber) {
310 hw->phy.autoneg_advertised = ecmd->advertising |
311 ADVERTISED_FIBRE |
312 ADVERTISED_Autoneg;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000313 switch (adapter->link_speed) {
314 case SPEED_2500:
315 hw->phy.autoneg_advertised =
316 ADVERTISED_2500baseX_Full;
317 break;
318 case SPEED_1000:
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000319 hw->phy.autoneg_advertised =
320 ADVERTISED_1000baseT_Full;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000321 break;
322 case SPEED_100:
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000323 hw->phy.autoneg_advertised =
324 ADVERTISED_100baseT_Full;
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000325 break;
326 default:
327 break;
328 }
Akeem G. Abodunrinf502ef72013-04-05 16:49:06 +0000329 } else {
330 hw->phy.autoneg_advertised = ecmd->advertising |
331 ADVERTISED_TP |
332 ADVERTISED_Autoneg;
333 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800334 ecmd->advertising = hw->phy.autoneg_advertised;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000335 if (adapter->fc_autoneg)
336 hw->fc.requested_mode = e1000_fc_default;
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000337 } else {
David Decotigny25db0332011-04-27 18:32:39 +0000338 u32 speed = ethtool_cmd_speed(ecmd);
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000339 /* calling this overrides forced MDI setting */
David Decotigny14ad2512011-04-27 18:32:43 +0000340 if (igb_set_spd_dplx(adapter, speed, ecmd->duplex)) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800341 clear_bit(__IGB_RESETTING, &adapter->state);
342 return -EINVAL;
343 }
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000344 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800345
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000346 /* MDI-X => 2; MDI => 1; Auto => 3 */
347 if (ecmd->eth_tp_mdix_ctrl) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000348 /* fix up the value for auto (3 => 0) as zero is mapped
Jesse Brandeburg8376dad2012-07-26 02:31:19 +0000349 * internally to auto
350 */
351 if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
352 hw->phy.mdix = AUTO_ALL_MODES;
353 else
354 hw->phy.mdix = ecmd->eth_tp_mdix_ctrl;
355 }
356
Auke Kok9d5c8242008-01-24 02:22:38 -0800357 /* reset the link */
Auke Kok9d5c8242008-01-24 02:22:38 -0800358 if (netif_running(adapter->netdev)) {
359 igb_down(adapter);
360 igb_up(adapter);
361 } else
362 igb_reset(adapter);
363
364 clear_bit(__IGB_RESETTING, &adapter->state);
365 return 0;
366}
367
Nick Nunley31455352010-02-17 01:01:21 +0000368static u32 igb_get_link(struct net_device *netdev)
369{
370 struct igb_adapter *adapter = netdev_priv(netdev);
371 struct e1000_mac_info *mac = &adapter->hw.mac;
372
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000373 /* If the link is not reported up to netdev, interrupts are disabled,
Nick Nunley31455352010-02-17 01:01:21 +0000374 * and so the physical link state may have changed since we last
375 * looked. Set get_link_status to make sure that the true link
376 * state is interrogated, rather than pulling a cached and possibly
377 * stale link state from the driver.
378 */
379 if (!netif_carrier_ok(netdev))
380 mac->get_link_status = 1;
381
382 return igb_has_link(adapter);
383}
384
Auke Kok9d5c8242008-01-24 02:22:38 -0800385static void igb_get_pauseparam(struct net_device *netdev,
386 struct ethtool_pauseparam *pause)
387{
388 struct igb_adapter *adapter = netdev_priv(netdev);
389 struct e1000_hw *hw = &adapter->hw;
390
391 pause->autoneg =
392 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
393
Alexander Duyck0cce1192009-07-23 18:10:24 +0000394 if (hw->fc.current_mode == e1000_fc_rx_pause)
Auke Kok9d5c8242008-01-24 02:22:38 -0800395 pause->rx_pause = 1;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000396 else if (hw->fc.current_mode == e1000_fc_tx_pause)
Auke Kok9d5c8242008-01-24 02:22:38 -0800397 pause->tx_pause = 1;
Alexander Duyck0cce1192009-07-23 18:10:24 +0000398 else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800399 pause->rx_pause = 1;
400 pause->tx_pause = 1;
401 }
402}
403
404static int igb_set_pauseparam(struct net_device *netdev,
405 struct ethtool_pauseparam *pause)
406{
407 struct igb_adapter *adapter = netdev_priv(netdev);
408 struct e1000_hw *hw = &adapter->hw;
409 int retval = 0;
410
Akeem G. Abodunrin373e6972013-03-29 15:22:17 +0000411 /* 100basefx does not support setting link flow control */
412 if (hw->dev_spec._82575.eth_flags.e100_base_fx)
413 return -EINVAL;
414
Auke Kok9d5c8242008-01-24 02:22:38 -0800415 adapter->fc_autoneg = pause->autoneg;
416
417 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
Carolyn Wyborny0d451e72014-04-11 01:46:40 +0000418 usleep_range(1000, 2000);
Auke Kok9d5c8242008-01-24 02:22:38 -0800419
Auke Kok9d5c8242008-01-24 02:22:38 -0800420 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000421 hw->fc.requested_mode = e1000_fc_default;
Auke Kok9d5c8242008-01-24 02:22:38 -0800422 if (netif_running(adapter->netdev)) {
423 igb_down(adapter);
424 igb_up(adapter);
Alexander Duyck317f66b2009-10-27 23:46:20 +0000425 } else {
Auke Kok9d5c8242008-01-24 02:22:38 -0800426 igb_reset(adapter);
Alexander Duyck317f66b2009-10-27 23:46:20 +0000427 }
Alexander Duyck0cce1192009-07-23 18:10:24 +0000428 } else {
429 if (pause->rx_pause && pause->tx_pause)
430 hw->fc.requested_mode = e1000_fc_full;
431 else if (pause->rx_pause && !pause->tx_pause)
432 hw->fc.requested_mode = e1000_fc_rx_pause;
433 else if (!pause->rx_pause && pause->tx_pause)
434 hw->fc.requested_mode = e1000_fc_tx_pause;
435 else if (!pause->rx_pause && !pause->tx_pause)
436 hw->fc.requested_mode = e1000_fc_none;
437
438 hw->fc.current_mode = hw->fc.requested_mode;
439
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000440 retval = ((hw->phy.media_type == e1000_media_type_copper) ?
441 igb_force_mac_fc(hw) : igb_setup_link(hw));
Alexander Duyck0cce1192009-07-23 18:10:24 +0000442 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800443
444 clear_bit(__IGB_RESETTING, &adapter->state);
445 return retval;
446}
447
Auke Kok9d5c8242008-01-24 02:22:38 -0800448static u32 igb_get_msglevel(struct net_device *netdev)
449{
450 struct igb_adapter *adapter = netdev_priv(netdev);
451 return adapter->msg_enable;
452}
453
454static void igb_set_msglevel(struct net_device *netdev, u32 data)
455{
456 struct igb_adapter *adapter = netdev_priv(netdev);
457 adapter->msg_enable = data;
458}
459
460static int igb_get_regs_len(struct net_device *netdev)
461{
Koki Sanagi7e3b4ff2012-02-15 14:45:39 +0000462#define IGB_REGS_LEN 739
Auke Kok9d5c8242008-01-24 02:22:38 -0800463 return IGB_REGS_LEN * sizeof(u32);
464}
465
466static void igb_get_regs(struct net_device *netdev,
467 struct ethtool_regs *regs, void *p)
468{
469 struct igb_adapter *adapter = netdev_priv(netdev);
470 struct e1000_hw *hw = &adapter->hw;
471 u32 *regs_buff = p;
472 u8 i;
473
474 memset(p, 0, IGB_REGS_LEN * sizeof(u32));
475
Jacob Kellera51d8c22016-04-13 16:08:28 -0700476 regs->version = (1u << 24) | (hw->revision_id << 16) | hw->device_id;
Auke Kok9d5c8242008-01-24 02:22:38 -0800477
478 /* General Registers */
479 regs_buff[0] = rd32(E1000_CTRL);
480 regs_buff[1] = rd32(E1000_STATUS);
481 regs_buff[2] = rd32(E1000_CTRL_EXT);
482 regs_buff[3] = rd32(E1000_MDIC);
483 regs_buff[4] = rd32(E1000_SCTL);
484 regs_buff[5] = rd32(E1000_CONNSW);
485 regs_buff[6] = rd32(E1000_VET);
486 regs_buff[7] = rd32(E1000_LEDCTL);
487 regs_buff[8] = rd32(E1000_PBA);
488 regs_buff[9] = rd32(E1000_PBS);
489 regs_buff[10] = rd32(E1000_FRTIMER);
490 regs_buff[11] = rd32(E1000_TCPTIMER);
491
492 /* NVM Register */
493 regs_buff[12] = rd32(E1000_EECD);
494
495 /* Interrupt */
Alexander Duyckfe59de32008-08-26 04:25:05 -0700496 /* Reading EICS for EICR because they read the
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000497 * same but EICS does not clear on read
498 */
Alexander Duyckfe59de32008-08-26 04:25:05 -0700499 regs_buff[13] = rd32(E1000_EICS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800500 regs_buff[14] = rd32(E1000_EICS);
501 regs_buff[15] = rd32(E1000_EIMS);
502 regs_buff[16] = rd32(E1000_EIMC);
503 regs_buff[17] = rd32(E1000_EIAC);
504 regs_buff[18] = rd32(E1000_EIAM);
Alexander Duyckfe59de32008-08-26 04:25:05 -0700505 /* Reading ICS for ICR because they read the
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000506 * same but ICS does not clear on read
507 */
Alexander Duyckfe59de32008-08-26 04:25:05 -0700508 regs_buff[19] = rd32(E1000_ICS);
Auke Kok9d5c8242008-01-24 02:22:38 -0800509 regs_buff[20] = rd32(E1000_ICS);
510 regs_buff[21] = rd32(E1000_IMS);
511 regs_buff[22] = rd32(E1000_IMC);
512 regs_buff[23] = rd32(E1000_IAC);
513 regs_buff[24] = rd32(E1000_IAM);
514 regs_buff[25] = rd32(E1000_IMIRVP);
515
516 /* Flow Control */
517 regs_buff[26] = rd32(E1000_FCAL);
518 regs_buff[27] = rd32(E1000_FCAH);
519 regs_buff[28] = rd32(E1000_FCTTV);
520 regs_buff[29] = rd32(E1000_FCRTL);
521 regs_buff[30] = rd32(E1000_FCRTH);
522 regs_buff[31] = rd32(E1000_FCRTV);
523
524 /* Receive */
525 regs_buff[32] = rd32(E1000_RCTL);
526 regs_buff[33] = rd32(E1000_RXCSUM);
527 regs_buff[34] = rd32(E1000_RLPML);
528 regs_buff[35] = rd32(E1000_RFCTL);
529 regs_buff[36] = rd32(E1000_MRQC);
Alexander Duycke1739522009-02-19 20:39:44 -0800530 regs_buff[37] = rd32(E1000_VT_CTL);
Auke Kok9d5c8242008-01-24 02:22:38 -0800531
532 /* Transmit */
533 regs_buff[38] = rd32(E1000_TCTL);
534 regs_buff[39] = rd32(E1000_TCTL_EXT);
535 regs_buff[40] = rd32(E1000_TIPG);
536 regs_buff[41] = rd32(E1000_DTXCTL);
537
538 /* Wake Up */
539 regs_buff[42] = rd32(E1000_WUC);
540 regs_buff[43] = rd32(E1000_WUFC);
541 regs_buff[44] = rd32(E1000_WUS);
542 regs_buff[45] = rd32(E1000_IPAV);
543 regs_buff[46] = rd32(E1000_WUPL);
544
545 /* MAC */
546 regs_buff[47] = rd32(E1000_PCS_CFG0);
547 regs_buff[48] = rd32(E1000_PCS_LCTL);
548 regs_buff[49] = rd32(E1000_PCS_LSTAT);
549 regs_buff[50] = rd32(E1000_PCS_ANADV);
550 regs_buff[51] = rd32(E1000_PCS_LPAB);
551 regs_buff[52] = rd32(E1000_PCS_NPTX);
552 regs_buff[53] = rd32(E1000_PCS_LPABNP);
553
554 /* Statistics */
555 regs_buff[54] = adapter->stats.crcerrs;
556 regs_buff[55] = adapter->stats.algnerrc;
557 regs_buff[56] = adapter->stats.symerrs;
558 regs_buff[57] = adapter->stats.rxerrc;
559 regs_buff[58] = adapter->stats.mpc;
560 regs_buff[59] = adapter->stats.scc;
561 regs_buff[60] = adapter->stats.ecol;
562 regs_buff[61] = adapter->stats.mcc;
563 regs_buff[62] = adapter->stats.latecol;
564 regs_buff[63] = adapter->stats.colc;
565 regs_buff[64] = adapter->stats.dc;
566 regs_buff[65] = adapter->stats.tncrs;
567 regs_buff[66] = adapter->stats.sec;
568 regs_buff[67] = adapter->stats.htdpmc;
569 regs_buff[68] = adapter->stats.rlec;
570 regs_buff[69] = adapter->stats.xonrxc;
571 regs_buff[70] = adapter->stats.xontxc;
572 regs_buff[71] = adapter->stats.xoffrxc;
573 regs_buff[72] = adapter->stats.xofftxc;
574 regs_buff[73] = adapter->stats.fcruc;
575 regs_buff[74] = adapter->stats.prc64;
576 regs_buff[75] = adapter->stats.prc127;
577 regs_buff[76] = adapter->stats.prc255;
578 regs_buff[77] = adapter->stats.prc511;
579 regs_buff[78] = adapter->stats.prc1023;
580 regs_buff[79] = adapter->stats.prc1522;
581 regs_buff[80] = adapter->stats.gprc;
582 regs_buff[81] = adapter->stats.bprc;
583 regs_buff[82] = adapter->stats.mprc;
584 regs_buff[83] = adapter->stats.gptc;
585 regs_buff[84] = adapter->stats.gorc;
586 regs_buff[86] = adapter->stats.gotc;
587 regs_buff[88] = adapter->stats.rnbc;
588 regs_buff[89] = adapter->stats.ruc;
589 regs_buff[90] = adapter->stats.rfc;
590 regs_buff[91] = adapter->stats.roc;
591 regs_buff[92] = adapter->stats.rjc;
592 regs_buff[93] = adapter->stats.mgprc;
593 regs_buff[94] = adapter->stats.mgpdc;
594 regs_buff[95] = adapter->stats.mgptc;
595 regs_buff[96] = adapter->stats.tor;
596 regs_buff[98] = adapter->stats.tot;
597 regs_buff[100] = adapter->stats.tpr;
598 regs_buff[101] = adapter->stats.tpt;
599 regs_buff[102] = adapter->stats.ptc64;
600 regs_buff[103] = adapter->stats.ptc127;
601 regs_buff[104] = adapter->stats.ptc255;
602 regs_buff[105] = adapter->stats.ptc511;
603 regs_buff[106] = adapter->stats.ptc1023;
604 regs_buff[107] = adapter->stats.ptc1522;
605 regs_buff[108] = adapter->stats.mptc;
606 regs_buff[109] = adapter->stats.bptc;
607 regs_buff[110] = adapter->stats.tsctc;
608 regs_buff[111] = adapter->stats.iac;
609 regs_buff[112] = adapter->stats.rpthc;
610 regs_buff[113] = adapter->stats.hgptc;
611 regs_buff[114] = adapter->stats.hgorc;
612 regs_buff[116] = adapter->stats.hgotc;
613 regs_buff[118] = adapter->stats.lenerrs;
614 regs_buff[119] = adapter->stats.scvpc;
615 regs_buff[120] = adapter->stats.hrmpc;
616
Auke Kok9d5c8242008-01-24 02:22:38 -0800617 for (i = 0; i < 4; i++)
618 regs_buff[121 + i] = rd32(E1000_SRRCTL(i));
619 for (i = 0; i < 4; i++)
Alexander Duyck83ab50a2009-10-27 15:55:41 +0000620 regs_buff[125 + i] = rd32(E1000_PSRTYPE(i));
Auke Kok9d5c8242008-01-24 02:22:38 -0800621 for (i = 0; i < 4; i++)
622 regs_buff[129 + i] = rd32(E1000_RDBAL(i));
623 for (i = 0; i < 4; i++)
624 regs_buff[133 + i] = rd32(E1000_RDBAH(i));
625 for (i = 0; i < 4; i++)
626 regs_buff[137 + i] = rd32(E1000_RDLEN(i));
627 for (i = 0; i < 4; i++)
628 regs_buff[141 + i] = rd32(E1000_RDH(i));
629 for (i = 0; i < 4; i++)
630 regs_buff[145 + i] = rd32(E1000_RDT(i));
631 for (i = 0; i < 4; i++)
632 regs_buff[149 + i] = rd32(E1000_RXDCTL(i));
633
634 for (i = 0; i < 10; i++)
635 regs_buff[153 + i] = rd32(E1000_EITR(i));
636 for (i = 0; i < 8; i++)
637 regs_buff[163 + i] = rd32(E1000_IMIR(i));
638 for (i = 0; i < 8; i++)
639 regs_buff[171 + i] = rd32(E1000_IMIREXT(i));
640 for (i = 0; i < 16; i++)
641 regs_buff[179 + i] = rd32(E1000_RAL(i));
642 for (i = 0; i < 16; i++)
643 regs_buff[195 + i] = rd32(E1000_RAH(i));
644
645 for (i = 0; i < 4; i++)
646 regs_buff[211 + i] = rd32(E1000_TDBAL(i));
647 for (i = 0; i < 4; i++)
648 regs_buff[215 + i] = rd32(E1000_TDBAH(i));
649 for (i = 0; i < 4; i++)
650 regs_buff[219 + i] = rd32(E1000_TDLEN(i));
651 for (i = 0; i < 4; i++)
652 regs_buff[223 + i] = rd32(E1000_TDH(i));
653 for (i = 0; i < 4; i++)
654 regs_buff[227 + i] = rd32(E1000_TDT(i));
655 for (i = 0; i < 4; i++)
656 regs_buff[231 + i] = rd32(E1000_TXDCTL(i));
657 for (i = 0; i < 4; i++)
658 regs_buff[235 + i] = rd32(E1000_TDWBAL(i));
659 for (i = 0; i < 4; i++)
660 regs_buff[239 + i] = rd32(E1000_TDWBAH(i));
661 for (i = 0; i < 4; i++)
662 regs_buff[243 + i] = rd32(E1000_DCA_TXCTRL(i));
663
664 for (i = 0; i < 4; i++)
665 regs_buff[247 + i] = rd32(E1000_IP4AT_REG(i));
666 for (i = 0; i < 4; i++)
667 regs_buff[251 + i] = rd32(E1000_IP6AT_REG(i));
668 for (i = 0; i < 32; i++)
669 regs_buff[255 + i] = rd32(E1000_WUPM_REG(i));
670 for (i = 0; i < 128; i++)
671 regs_buff[287 + i] = rd32(E1000_FFMT_REG(i));
672 for (i = 0; i < 128; i++)
673 regs_buff[415 + i] = rd32(E1000_FFVT_REG(i));
674 for (i = 0; i < 4; i++)
675 regs_buff[543 + i] = rd32(E1000_FFLT_REG(i));
676
677 regs_buff[547] = rd32(E1000_TDFH);
678 regs_buff[548] = rd32(E1000_TDFT);
679 regs_buff[549] = rd32(E1000_TDFHS);
680 regs_buff[550] = rd32(E1000_TDFPC);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000681
682 if (hw->mac.type > e1000_82580) {
683 regs_buff[551] = adapter->stats.o2bgptc;
684 regs_buff[552] = adapter->stats.b2ospc;
685 regs_buff[553] = adapter->stats.o2bspc;
686 regs_buff[554] = adapter->stats.b2ogprc;
687 }
Koki Sanagi7e3b4ff2012-02-15 14:45:39 +0000688
689 if (hw->mac.type != e1000_82576)
690 return;
691 for (i = 0; i < 12; i++)
692 regs_buff[555 + i] = rd32(E1000_SRRCTL(i + 4));
693 for (i = 0; i < 4; i++)
694 regs_buff[567 + i] = rd32(E1000_PSRTYPE(i + 4));
695 for (i = 0; i < 12; i++)
696 regs_buff[571 + i] = rd32(E1000_RDBAL(i + 4));
697 for (i = 0; i < 12; i++)
698 regs_buff[583 + i] = rd32(E1000_RDBAH(i + 4));
699 for (i = 0; i < 12; i++)
700 regs_buff[595 + i] = rd32(E1000_RDLEN(i + 4));
701 for (i = 0; i < 12; i++)
702 regs_buff[607 + i] = rd32(E1000_RDH(i + 4));
703 for (i = 0; i < 12; i++)
704 regs_buff[619 + i] = rd32(E1000_RDT(i + 4));
705 for (i = 0; i < 12; i++)
706 regs_buff[631 + i] = rd32(E1000_RXDCTL(i + 4));
707
708 for (i = 0; i < 12; i++)
709 regs_buff[643 + i] = rd32(E1000_TDBAL(i + 4));
710 for (i = 0; i < 12; i++)
711 regs_buff[655 + i] = rd32(E1000_TDBAH(i + 4));
712 for (i = 0; i < 12; i++)
713 regs_buff[667 + i] = rd32(E1000_TDLEN(i + 4));
714 for (i = 0; i < 12; i++)
715 regs_buff[679 + i] = rd32(E1000_TDH(i + 4));
716 for (i = 0; i < 12; i++)
717 regs_buff[691 + i] = rd32(E1000_TDT(i + 4));
718 for (i = 0; i < 12; i++)
719 regs_buff[703 + i] = rd32(E1000_TXDCTL(i + 4));
720 for (i = 0; i < 12; i++)
721 regs_buff[715 + i] = rd32(E1000_TDWBAL(i + 4));
722 for (i = 0; i < 12; i++)
723 regs_buff[727 + i] = rd32(E1000_TDWBAH(i + 4));
Auke Kok9d5c8242008-01-24 02:22:38 -0800724}
725
726static int igb_get_eeprom_len(struct net_device *netdev)
727{
728 struct igb_adapter *adapter = netdev_priv(netdev);
729 return adapter->hw.nvm.word_size * 2;
730}
731
732static int igb_get_eeprom(struct net_device *netdev,
733 struct ethtool_eeprom *eeprom, u8 *bytes)
734{
735 struct igb_adapter *adapter = netdev_priv(netdev);
736 struct e1000_hw *hw = &adapter->hw;
737 u16 *eeprom_buff;
738 int first_word, last_word;
739 int ret_val = 0;
740 u16 i;
741
742 if (eeprom->len == 0)
743 return -EINVAL;
744
745 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
746
747 first_word = eeprom->offset >> 1;
748 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
749
750 eeprom_buff = kmalloc(sizeof(u16) *
751 (last_word - first_word + 1), GFP_KERNEL);
752 if (!eeprom_buff)
753 return -ENOMEM;
754
755 if (hw->nvm.type == e1000_nvm_eeprom_spi)
Alexander Duyck312c75a2009-02-06 23:17:47 +0000756 ret_val = hw->nvm.ops.read(hw, first_word,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000757 last_word - first_word + 1,
758 eeprom_buff);
Auke Kok9d5c8242008-01-24 02:22:38 -0800759 else {
760 for (i = 0; i < last_word - first_word + 1; i++) {
Alexander Duyck312c75a2009-02-06 23:17:47 +0000761 ret_val = hw->nvm.ops.read(hw, first_word + i, 1,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000762 &eeprom_buff[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800763 if (ret_val)
764 break;
765 }
766 }
767
768 /* Device's eeprom is always little-endian, word addressable */
769 for (i = 0; i < last_word - first_word + 1; i++)
770 le16_to_cpus(&eeprom_buff[i]);
771
772 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
773 eeprom->len);
774 kfree(eeprom_buff);
775
776 return ret_val;
777}
778
779static int igb_set_eeprom(struct net_device *netdev,
780 struct ethtool_eeprom *eeprom, u8 *bytes)
781{
782 struct igb_adapter *adapter = netdev_priv(netdev);
783 struct e1000_hw *hw = &adapter->hw;
784 u16 *eeprom_buff;
785 void *ptr;
786 int max_len, first_word, last_word, ret_val = 0;
787 u16 i;
788
789 if (eeprom->len == 0)
790 return -EOPNOTSUPP;
791
Fujinaka, Todda71fc312013-10-23 05:52:11 +0000792 if ((hw->mac.type >= e1000_i210) &&
793 !igb_get_flash_presence_i210(hw)) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000794 return -EOPNOTSUPP;
Fujinaka, Todda71fc312013-10-23 05:52:11 +0000795 }
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000796
Auke Kok9d5c8242008-01-24 02:22:38 -0800797 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
798 return -EFAULT;
799
800 max_len = hw->nvm.word_size * 2;
801
802 first_word = eeprom->offset >> 1;
803 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
804 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
805 if (!eeprom_buff)
806 return -ENOMEM;
807
808 ptr = (void *)eeprom_buff;
809
810 if (eeprom->offset & 1) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000811 /* need read/modify/write of first changed EEPROM word
812 * only the second byte of the word is being modified
813 */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000814 ret_val = hw->nvm.ops.read(hw, first_word, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800815 &eeprom_buff[0]);
816 ptr++;
817 }
818 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000819 /* need read/modify/write of last changed EEPROM word
820 * only the first byte of the word is being modified
821 */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000822 ret_val = hw->nvm.ops.read(hw, last_word, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800823 &eeprom_buff[last_word - first_word]);
824 }
825
826 /* Device's eeprom is always little-endian, word addressable */
827 for (i = 0; i < last_word - first_word + 1; i++)
828 le16_to_cpus(&eeprom_buff[i]);
829
830 memcpy(ptr, bytes, eeprom->len);
831
832 for (i = 0; i < last_word - first_word + 1; i++)
833 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
834
Alexander Duyck312c75a2009-02-06 23:17:47 +0000835 ret_val = hw->nvm.ops.write(hw, first_word,
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000836 last_word - first_word + 1, eeprom_buff);
Auke Kok9d5c8242008-01-24 02:22:38 -0800837
Carolyn Wyborny2a0a0f12013-04-25 17:22:34 +0000838 /* Update the checksum if nvm write succeeded */
839 if (ret_val == 0)
Carolyn Wyborny4322e562011-03-11 20:43:18 -0800840 hw->nvm.ops.update(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800841
Carolyn Wybornyd67974f2012-06-14 16:04:19 +0000842 igb_set_fw_version(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800843 kfree(eeprom_buff);
844 return ret_val;
845}
846
847static void igb_get_drvinfo(struct net_device *netdev,
848 struct ethtool_drvinfo *drvinfo)
849{
850 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -0800851
Rick Jones612a94d2011-11-14 08:13:25 +0000852 strlcpy(drvinfo->driver, igb_driver_name, sizeof(drvinfo->driver));
853 strlcpy(drvinfo->version, igb_driver_version, sizeof(drvinfo->version));
Auke Kok9d5c8242008-01-24 02:22:38 -0800854
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000855 /* EEPROM image version # is reported as firmware version # for
Carolyn Wybornyd67974f2012-06-14 16:04:19 +0000856 * 82575 controllers
857 */
858 strlcpy(drvinfo->fw_version, adapter->fw_version,
859 sizeof(drvinfo->fw_version));
Rick Jones612a94d2011-11-14 08:13:25 +0000860 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
861 sizeof(drvinfo->bus_info));
Alexander Duycke0891292017-02-06 18:26:52 -0800862
863 drvinfo->n_priv_flags = IGB_PRIV_FLAGS_STR_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -0800864}
865
866static void igb_get_ringparam(struct net_device *netdev,
867 struct ethtool_ringparam *ring)
868{
869 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -0800870
871 ring->rx_max_pending = IGB_MAX_RXD;
872 ring->tx_max_pending = IGB_MAX_TXD;
Alexander Duyck68fd9912008-11-20 00:48:10 -0800873 ring->rx_pending = adapter->rx_ring_count;
874 ring->tx_pending = adapter->tx_ring_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800875}
876
877static int igb_set_ringparam(struct net_device *netdev,
878 struct ethtool_ringparam *ring)
879{
880 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800881 struct igb_ring *temp_ring;
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000882 int i, err = 0;
Alexander Duyck0e15439a2009-11-12 18:36:41 +0000883 u16 new_rx_count, new_tx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800884
885 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
886 return -EINVAL;
887
Alexander Duyck0e15439a2009-11-12 18:36:41 +0000888 new_rx_count = min_t(u32, ring->rx_pending, IGB_MAX_RXD);
889 new_rx_count = max_t(u16, new_rx_count, IGB_MIN_RXD);
Auke Kok9d5c8242008-01-24 02:22:38 -0800890 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
891
Alexander Duyck0e15439a2009-11-12 18:36:41 +0000892 new_tx_count = min_t(u32, ring->tx_pending, IGB_MAX_TXD);
893 new_tx_count = max_t(u16, new_tx_count, IGB_MIN_TXD);
Auke Kok9d5c8242008-01-24 02:22:38 -0800894 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
895
Alexander Duyck68fd9912008-11-20 00:48:10 -0800896 if ((new_tx_count == adapter->tx_ring_count) &&
897 (new_rx_count == adapter->rx_ring_count)) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800898 /* nothing to do */
899 return 0;
900 }
901
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000902 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
Carolyn Wyborny0d451e72014-04-11 01:46:40 +0000903 usleep_range(1000, 2000);
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000904
905 if (!netif_running(adapter->netdev)) {
906 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +0000907 adapter->tx_ring[i]->count = new_tx_count;
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000908 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +0000909 adapter->rx_ring[i]->count = new_rx_count;
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000910 adapter->tx_ring_count = new_tx_count;
911 adapter->rx_ring_count = new_rx_count;
912 goto clear_reset;
913 }
914
Alexander Duyck68fd9912008-11-20 00:48:10 -0800915 if (adapter->num_tx_queues > adapter->num_rx_queues)
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000916 temp_ring = vmalloc(adapter->num_tx_queues *
917 sizeof(struct igb_ring));
Alexander Duyck68fd9912008-11-20 00:48:10 -0800918 else
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000919 temp_ring = vmalloc(adapter->num_rx_queues *
920 sizeof(struct igb_ring));
Alexander Duyck68fd9912008-11-20 00:48:10 -0800921
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000922 if (!temp_ring) {
923 err = -ENOMEM;
924 goto clear_reset;
925 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800926
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000927 igb_down(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800928
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000929 /* We can't just free everything and then setup again,
Auke Kok9d5c8242008-01-24 02:22:38 -0800930 * because the ISRs in MSI-X mode get passed pointers
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000931 * to the Tx and Rx ring structs.
Auke Kok9d5c8242008-01-24 02:22:38 -0800932 */
Alexander Duyck68fd9912008-11-20 00:48:10 -0800933 if (new_tx_count != adapter->tx_ring_count) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800934 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +0000935 memcpy(&temp_ring[i], adapter->tx_ring[i],
936 sizeof(struct igb_ring));
937
Alexander Duyck68fd9912008-11-20 00:48:10 -0800938 temp_ring[i].count = new_tx_count;
Alexander Duyck80785292009-10-27 15:51:47 +0000939 err = igb_setup_tx_resources(&temp_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800940 if (err) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800941 while (i) {
942 i--;
943 igb_free_tx_resources(&temp_ring[i]);
944 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800945 goto err_setup;
946 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800947 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800948
Alexander Duyck3025a442010-02-17 01:02:39 +0000949 for (i = 0; i < adapter->num_tx_queues; i++) {
950 igb_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800951
Alexander Duyck3025a442010-02-17 01:02:39 +0000952 memcpy(adapter->tx_ring[i], &temp_ring[i],
953 sizeof(struct igb_ring));
954 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800955
956 adapter->tx_ring_count = new_tx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800957 }
958
Alexander Duyck3025a442010-02-17 01:02:39 +0000959 if (new_rx_count != adapter->rx_ring_count) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800960 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +0000961 memcpy(&temp_ring[i], adapter->rx_ring[i],
962 sizeof(struct igb_ring));
963
Alexander Duyck68fd9912008-11-20 00:48:10 -0800964 temp_ring[i].count = new_rx_count;
Alexander Duyck80785292009-10-27 15:51:47 +0000965 err = igb_setup_rx_resources(&temp_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -0800966 if (err) {
Alexander Duyck68fd9912008-11-20 00:48:10 -0800967 while (i) {
968 i--;
969 igb_free_rx_resources(&temp_ring[i]);
970 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800971 goto err_setup;
972 }
973
Auke Kok9d5c8242008-01-24 02:22:38 -0800974 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800975
Alexander Duyck3025a442010-02-17 01:02:39 +0000976 for (i = 0; i < adapter->num_rx_queues; i++) {
977 igb_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800978
Alexander Duyck3025a442010-02-17 01:02:39 +0000979 memcpy(adapter->rx_ring[i], &temp_ring[i],
980 sizeof(struct igb_ring));
981 }
Alexander Duyck68fd9912008-11-20 00:48:10 -0800982
983 adapter->rx_ring_count = new_rx_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800984 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800985err_setup:
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000986 igb_up(adapter);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800987 vfree(temp_ring);
Alexander Duyck6d9f4fc2009-10-26 11:31:47 +0000988clear_reset:
989 clear_bit(__IGB_RESETTING, &adapter->state);
Auke Kok9d5c8242008-01-24 02:22:38 -0800990 return err;
991}
992
993/* ethtool register test data */
994struct igb_reg_test {
995 u16 reg;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700996 u16 reg_offset;
997 u16 array_len;
998 u16 test_type;
Auke Kok9d5c8242008-01-24 02:22:38 -0800999 u32 mask;
1000 u32 write;
1001};
1002
1003/* In the hardware, registers are laid out either singly, in arrays
1004 * spaced 0x100 bytes apart, or in contiguous tables. We assume
1005 * most tests take place on arrays or single registers (handled
1006 * as a single-element array) and special-case the tables.
1007 * Table tests are always pattern tests.
1008 *
1009 * We also make provision for some required setup steps by specifying
1010 * registers to be written without any read-back testing.
1011 */
1012
1013#define PATTERN_TEST 1
1014#define SET_READ_TEST 2
1015#define WRITE_NO_TEST 3
1016#define TABLE32_TEST 4
1017#define TABLE64_TEST_LO 5
1018#define TABLE64_TEST_HI 6
1019
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001020/* i210 reg test */
1021static struct igb_reg_test reg_test_i210[] = {
1022 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1023 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1024 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1025 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1026 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1027 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1028 /* RDH is read-only for i210, only test RDT. */
1029 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1030 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1031 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1032 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1033 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1034 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1035 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1036 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1037 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1038 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
1039 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
1040 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1041 { E1000_RA, 0, 16, TABLE64_TEST_LO,
1042 0xFFFFFFFF, 0xFFFFFFFF },
1043 { E1000_RA, 0, 16, TABLE64_TEST_HI,
1044 0x900FFFFF, 0xFFFFFFFF },
1045 { E1000_MTA, 0, 128, TABLE32_TEST,
1046 0xFFFFFFFF, 0xFFFFFFFF },
1047 { 0, 0, 0, 0, 0 }
1048};
1049
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001050/* i350 reg test */
1051static struct igb_reg_test reg_test_i350[] = {
1052 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1053 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1054 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1055 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFF0000, 0xFFFF0000 },
1056 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1057 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck1b6e6612010-04-09 09:53:08 +00001058 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001059 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1060 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck1b6e6612010-04-09 09:53:08 +00001061 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001062 /* RDH is read-only for i350, only test RDT. */
1063 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1064 { E1000_RDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1065 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1066 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1067 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1068 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1069 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck1b6e6612010-04-09 09:53:08 +00001070 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001071 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1072 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck1b6e6612010-04-09 09:53:08 +00001073 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001074 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1075 { E1000_TDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1076 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001077 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
1078 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001079 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1080 { E1000_RA, 0, 16, TABLE64_TEST_LO,
1081 0xFFFFFFFF, 0xFFFFFFFF },
1082 { E1000_RA, 0, 16, TABLE64_TEST_HI,
1083 0xC3FFFFFF, 0xFFFFFFFF },
1084 { E1000_RA2, 0, 16, TABLE64_TEST_LO,
1085 0xFFFFFFFF, 0xFFFFFFFF },
1086 { E1000_RA2, 0, 16, TABLE64_TEST_HI,
1087 0xC3FFFFFF, 0xFFFFFFFF },
1088 { E1000_MTA, 0, 128, TABLE32_TEST,
1089 0xFFFFFFFF, 0xFFFFFFFF },
1090 { 0, 0, 0, 0 }
1091};
1092
Alexander Duyck55cac242009-11-19 12:42:21 +00001093/* 82580 reg test */
1094static struct igb_reg_test reg_test_82580[] = {
1095 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1096 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1097 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1098 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1099 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1100 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1101 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1102 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1103 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1104 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1105 /* RDH is read-only for 82580, only test RDT. */
1106 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1107 { E1000_RDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1108 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1109 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1110 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1111 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1112 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1113 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1114 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1115 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1116 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1117 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1118 { E1000_TDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1119 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001120 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
1121 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
Alexander Duyck55cac242009-11-19 12:42:21 +00001122 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1123 { E1000_RA, 0, 16, TABLE64_TEST_LO,
1124 0xFFFFFFFF, 0xFFFFFFFF },
1125 { E1000_RA, 0, 16, TABLE64_TEST_HI,
1126 0x83FFFFFF, 0xFFFFFFFF },
1127 { E1000_RA2, 0, 8, TABLE64_TEST_LO,
1128 0xFFFFFFFF, 0xFFFFFFFF },
1129 { E1000_RA2, 0, 8, TABLE64_TEST_HI,
1130 0x83FFFFFF, 0xFFFFFFFF },
1131 { E1000_MTA, 0, 128, TABLE32_TEST,
1132 0xFFFFFFFF, 0xFFFFFFFF },
1133 { 0, 0, 0, 0 }
1134};
1135
Alexander Duyck2d064c02008-07-08 15:10:12 -07001136/* 82576 reg test */
1137static struct igb_reg_test reg_test_82576[] = {
1138 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1139 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1140 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1141 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1142 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1143 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1144 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001145 { E1000_RDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1146 { E1000_RDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1147 { E1000_RDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
1148 /* Enable all RX queues before testing. */
Carolyn Wybornyc502ea22014-04-11 01:46:33 +00001149 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0,
1150 E1000_RXDCTL_QUEUE_ENABLE },
1151 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0,
1152 E1000_RXDCTL_QUEUE_ENABLE },
Alexander Duyck2d064c02008-07-08 15:10:12 -07001153 /* RDH is read-only for 82576, only test RDT. */
1154 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001155 { E1000_RDT(4), 0x40, 12, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
Alexander Duyck2d064c02008-07-08 15:10:12 -07001156 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001157 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0, 0 },
Alexander Duyck2d064c02008-07-08 15:10:12 -07001158 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1159 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1160 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1161 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1162 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1163 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001164 { E1000_TDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1165 { E1000_TDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1166 { E1000_TDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
Alexander Duyck2d064c02008-07-08 15:10:12 -07001167 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001168 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
1169 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
Alexander Duyck2d064c02008-07-08 15:10:12 -07001170 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1171 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
1172 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF },
1173 { E1000_RA2, 0, 8, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
1174 { E1000_RA2, 0, 8, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF },
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001175 { E1000_MTA, 0, 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Alexander Duyck2d064c02008-07-08 15:10:12 -07001176 { 0, 0, 0, 0 }
1177};
1178
1179/* 82575 register test */
1180static struct igb_reg_test reg_test_82575[] = {
1181 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1182 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1183 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
1184 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1185 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1186 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1187 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1188 /* Enable all four RX queues before testing. */
Carolyn Wybornyc502ea22014-04-11 01:46:33 +00001189 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0,
1190 E1000_RXDCTL_QUEUE_ENABLE },
Auke Kok9d5c8242008-01-24 02:22:38 -08001191 /* RDH is read-only for 82575, only test RDT. */
Alexander Duyck2d064c02008-07-08 15:10:12 -07001192 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1193 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
1194 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
1195 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1196 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
1197 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1198 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1199 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1200 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1201 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0x003FFFFB },
1202 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0xFFFFFFFF },
1203 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
1204 { E1000_TXCW, 0x100, 1, PATTERN_TEST, 0xC000FFFF, 0x0000FFFF },
1205 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
1206 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x800FFFFF, 0xFFFFFFFF },
1207 { E1000_MTA, 0, 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
Auke Kok9d5c8242008-01-24 02:22:38 -08001208 { 0, 0, 0, 0 }
1209};
1210
1211static bool reg_pattern_test(struct igb_adapter *adapter, u64 *data,
1212 int reg, u32 mask, u32 write)
1213{
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001214 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001215 u32 pat, val;
Carolyn Wybornyd34a15a2014-04-11 01:45:23 +00001216 static const u32 _test[] = {
1217 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Auke Kok9d5c8242008-01-24 02:22:38 -08001218 for (pat = 0; pat < ARRAY_SIZE(_test); pat++) {
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001219 wr32(reg, (_test[pat] & write));
Carolyn Wyborny93ed8352011-02-24 03:12:15 +00001220 val = rd32(reg) & mask;
Auke Kok9d5c8242008-01-24 02:22:38 -08001221 if (val != (_test[pat] & write & mask)) {
Jesper Juhld836200a2012-08-01 05:41:30 +00001222 dev_err(&adapter->pdev->dev,
1223 "pattern test reg %04X failed: got 0x%08X expected 0x%08X\n",
Auke Kok9d5c8242008-01-24 02:22:38 -08001224 reg, val, (_test[pat] & write & mask));
1225 *data = reg;
Carolyn Wybornyf6f38e22014-04-11 02:20:14 +00001226 return true;
Auke Kok9d5c8242008-01-24 02:22:38 -08001227 }
1228 }
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
1233static bool reg_set_and_check(struct igb_adapter *adapter, u64 *data,
1234 int reg, u32 mask, u32 write)
1235{
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001236 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001237 u32 val;
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001238
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001239 wr32(reg, write & mask);
1240 val = rd32(reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001241 if ((write & mask) != (val & mask)) {
Jesper Juhld836200a2012-08-01 05:41:30 +00001242 dev_err(&adapter->pdev->dev,
Carolyn Wybornyc502ea22014-04-11 01:46:33 +00001243 "set/check reg %04X test failed: got 0x%08X expected 0x%08X\n",
1244 reg, (val & mask), (write & mask));
Auke Kok9d5c8242008-01-24 02:22:38 -08001245 *data = reg;
Carolyn Wybornyf6f38e22014-04-11 02:20:14 +00001246 return true;
Auke Kok9d5c8242008-01-24 02:22:38 -08001247 }
Alexander Duyck317f66b2009-10-27 23:46:20 +00001248
Carolyn Wybornyf6f38e22014-04-11 02:20:14 +00001249 return false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001250}
1251
1252#define REG_PATTERN_TEST(reg, mask, write) \
1253 do { \
1254 if (reg_pattern_test(adapter, data, reg, mask, write)) \
1255 return 1; \
1256 } while (0)
1257
1258#define REG_SET_AND_CHECK(reg, mask, write) \
1259 do { \
1260 if (reg_set_and_check(adapter, data, reg, mask, write)) \
1261 return 1; \
1262 } while (0)
1263
1264static int igb_reg_test(struct igb_adapter *adapter, u64 *data)
1265{
1266 struct e1000_hw *hw = &adapter->hw;
1267 struct igb_reg_test *test;
1268 u32 value, before, after;
1269 u32 i, toggle;
1270
Alexander Duyck2d064c02008-07-08 15:10:12 -07001271 switch (adapter->hw.mac.type) {
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001272 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001273 case e1000_i354:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001274 test = reg_test_i350;
1275 toggle = 0x7FEFF3FF;
1276 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001277 case e1000_i210:
1278 case e1000_i211:
1279 test = reg_test_i210;
1280 toggle = 0x7FEFF3FF;
1281 break;
Alexander Duyck55cac242009-11-19 12:42:21 +00001282 case e1000_82580:
1283 test = reg_test_82580;
1284 toggle = 0x7FEFF3FF;
1285 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001286 case e1000_82576:
1287 test = reg_test_82576;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001288 toggle = 0x7FFFF3FF;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001289 break;
1290 default:
1291 test = reg_test_82575;
Alexander Duyck317f66b2009-10-27 23:46:20 +00001292 toggle = 0x7FFFF3FF;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001293 break;
1294 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001295
1296 /* Because the status register is such a special case,
1297 * we handle it separately from the rest of the register
1298 * tests. Some bits are read-only, some toggle, and some
1299 * are writable on newer MACs.
1300 */
1301 before = rd32(E1000_STATUS);
1302 value = (rd32(E1000_STATUS) & toggle);
1303 wr32(E1000_STATUS, toggle);
1304 after = rd32(E1000_STATUS) & toggle;
1305 if (value != after) {
Jesper Juhld836200a2012-08-01 05:41:30 +00001306 dev_err(&adapter->pdev->dev,
1307 "failed STATUS register test got: 0x%08X expected: 0x%08X\n",
1308 after, value);
Auke Kok9d5c8242008-01-24 02:22:38 -08001309 *data = 1;
1310 return 1;
1311 }
1312 /* restore previous status */
1313 wr32(E1000_STATUS, before);
1314
1315 /* Perform the remainder of the register test, looping through
1316 * the test table until we either fail or reach the null entry.
1317 */
1318 while (test->reg) {
1319 for (i = 0; i < test->array_len; i++) {
1320 switch (test->test_type) {
1321 case PATTERN_TEST:
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001322 REG_PATTERN_TEST(test->reg +
1323 (i * test->reg_offset),
Auke Kok9d5c8242008-01-24 02:22:38 -08001324 test->mask,
1325 test->write);
1326 break;
1327 case SET_READ_TEST:
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001328 REG_SET_AND_CHECK(test->reg +
1329 (i * test->reg_offset),
Auke Kok9d5c8242008-01-24 02:22:38 -08001330 test->mask,
1331 test->write);
1332 break;
1333 case WRITE_NO_TEST:
1334 writel(test->write,
1335 (adapter->hw.hw_addr + test->reg)
Alexander Duyck2d064c02008-07-08 15:10:12 -07001336 + (i * test->reg_offset));
Auke Kok9d5c8242008-01-24 02:22:38 -08001337 break;
1338 case TABLE32_TEST:
1339 REG_PATTERN_TEST(test->reg + (i * 4),
1340 test->mask,
1341 test->write);
1342 break;
1343 case TABLE64_TEST_LO:
1344 REG_PATTERN_TEST(test->reg + (i * 8),
1345 test->mask,
1346 test->write);
1347 break;
1348 case TABLE64_TEST_HI:
1349 REG_PATTERN_TEST((test->reg + 4) + (i * 8),
1350 test->mask,
1351 test->write);
1352 break;
1353 }
1354 }
1355 test++;
1356 }
1357
1358 *data = 0;
1359 return 0;
1360}
1361
1362static int igb_eeprom_test(struct igb_adapter *adapter, u64 *data)
1363{
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +00001364 struct e1000_hw *hw = &adapter->hw;
1365
Auke Kok9d5c8242008-01-24 02:22:38 -08001366 *data = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001367
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +00001368 /* Validate eeprom on all parts but flashless */
1369 switch (hw->mac.type) {
1370 case e1000_i210:
1371 case e1000_i211:
1372 if (igb_get_flash_presence_i210(hw)) {
1373 if (adapter->hw.nvm.ops.validate(&adapter->hw) < 0)
1374 *data = 2;
1375 }
1376 break;
1377 default:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001378 if (adapter->hw.nvm.ops.validate(&adapter->hw) < 0)
1379 *data = 2;
Carolyn Wyborny53b87ce2013-07-16 19:18:36 +00001380 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001381 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001382
1383 return *data;
1384}
1385
1386static irqreturn_t igb_test_intr(int irq, void *data)
1387{
Alexander Duyck317f66b2009-10-27 23:46:20 +00001388 struct igb_adapter *adapter = (struct igb_adapter *) data;
Auke Kok9d5c8242008-01-24 02:22:38 -08001389 struct e1000_hw *hw = &adapter->hw;
1390
1391 adapter->test_icr |= rd32(E1000_ICR);
1392
1393 return IRQ_HANDLED;
1394}
1395
1396static int igb_intr_test(struct igb_adapter *adapter, u64 *data)
1397{
1398 struct e1000_hw *hw = &adapter->hw;
1399 struct net_device *netdev = adapter->netdev;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001400 u32 mask, ics_mask, i = 0, shared_int = true;
Auke Kok9d5c8242008-01-24 02:22:38 -08001401 u32 irq = adapter->pdev->irq;
1402
1403 *data = 0;
1404
1405 /* Hook up test interrupt handler just for this test */
Carolyn Wybornycd14ef52013-12-10 07:58:34 +00001406 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001407 if (request_irq(adapter->msix_entries[0].vector,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001408 igb_test_intr, 0, netdev->name, adapter)) {
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001409 *data = 1;
1410 return -1;
1411 }
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001412 } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001413 shared_int = false;
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001414 if (request_irq(irq,
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001415 igb_test_intr, 0, netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001416 *data = 1;
1417 return -1;
1418 }
Joe Perchesa0607fd2009-11-18 23:29:17 -08001419 } else if (!request_irq(irq, igb_test_intr, IRQF_PROBE_SHARED,
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001420 netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001421 shared_int = false;
Joe Perchesa0607fd2009-11-18 23:29:17 -08001422 } else if (request_irq(irq, igb_test_intr, IRQF_SHARED,
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001423 netdev->name, adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001424 *data = 1;
1425 return -1;
1426 }
1427 dev_info(&adapter->pdev->dev, "testing %s interrupt\n",
1428 (shared_int ? "shared" : "unshared"));
Alexander Duyck317f66b2009-10-27 23:46:20 +00001429
Auke Kok9d5c8242008-01-24 02:22:38 -08001430 /* Disable all the interrupts */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001431 wr32(E1000_IMC, ~0);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001432 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001433 usleep_range(10000, 11000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001434
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001435 /* Define all writable bits for ICS */
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001436 switch (hw->mac.type) {
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001437 case e1000_82575:
1438 ics_mask = 0x37F47EDD;
1439 break;
1440 case e1000_82576:
1441 ics_mask = 0x77D4FBFD;
1442 break;
Alexander Duyck55cac242009-11-19 12:42:21 +00001443 case e1000_82580:
1444 ics_mask = 0x77DCFED5;
1445 break;
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001446 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001447 case e1000_i354:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001448 case e1000_i210:
1449 case e1000_i211:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001450 ics_mask = 0x77DCFED5;
1451 break;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001452 default:
1453 ics_mask = 0x7FFFFFFF;
1454 break;
1455 }
1456
Auke Kok9d5c8242008-01-24 02:22:38 -08001457 /* Test each interrupt */
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001458 for (; i < 31; i++) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001459 /* Interrupt to test */
Jacob Kellera51d8c22016-04-13 16:08:28 -07001460 mask = BIT(i);
Auke Kok9d5c8242008-01-24 02:22:38 -08001461
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001462 if (!(mask & ics_mask))
1463 continue;
1464
Auke Kok9d5c8242008-01-24 02:22:38 -08001465 if (!shared_int) {
1466 /* Disable the interrupt to be reported in
1467 * the cause register and then force the same
1468 * interrupt and see if one gets posted. If
1469 * an interrupt was posted to the bus, the
1470 * test failed.
1471 */
1472 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001473
1474 /* Flush any pending interrupts */
1475 wr32(E1000_ICR, ~0);
1476
1477 wr32(E1000_IMC, mask);
1478 wr32(E1000_ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001479 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001480 usleep_range(10000, 11000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001481
1482 if (adapter->test_icr & mask) {
1483 *data = 3;
1484 break;
1485 }
1486 }
1487
1488 /* Enable the interrupt to be reported in
1489 * the cause register and then force the same
1490 * interrupt and see if one gets posted. If
1491 * an interrupt was not posted to the bus, the
1492 * test failed.
1493 */
1494 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001495
1496 /* Flush any pending interrupts */
1497 wr32(E1000_ICR, ~0);
1498
Auke Kok9d5c8242008-01-24 02:22:38 -08001499 wr32(E1000_IMS, mask);
1500 wr32(E1000_ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001501 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001502 usleep_range(10000, 11000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001503
1504 if (!(adapter->test_icr & mask)) {
1505 *data = 4;
1506 break;
1507 }
1508
1509 if (!shared_int) {
1510 /* Disable the other interrupts to be reported in
1511 * the cause register and then force the other
1512 * interrupts and see if any get posted. If
1513 * an interrupt was posted to the bus, the
1514 * test failed.
1515 */
1516 adapter->test_icr = 0;
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001517
1518 /* Flush any pending interrupts */
1519 wr32(E1000_ICR, ~0);
1520
1521 wr32(E1000_IMC, ~mask);
1522 wr32(E1000_ICS, ~mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001523 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001524 usleep_range(10000, 11000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001525
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001526 if (adapter->test_icr & mask) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001527 *data = 5;
1528 break;
1529 }
1530 }
1531 }
1532
1533 /* Disable all the interrupts */
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001534 wr32(E1000_IMC, ~0);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001535 wrfl();
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001536 usleep_range(10000, 11000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001537
1538 /* Unhook test interrupt handler */
Carolyn Wybornycd14ef52013-12-10 07:58:34 +00001539 if (adapter->flags & IGB_FLAG_HAS_MSIX)
Alexander Duyck4eefa8f2009-10-27 15:55:22 +00001540 free_irq(adapter->msix_entries[0].vector, adapter);
1541 else
1542 free_irq(irq, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001543
1544 return *data;
1545}
1546
1547static void igb_free_desc_rings(struct igb_adapter *adapter)
1548{
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001549 igb_free_tx_resources(&adapter->test_tx_ring);
1550 igb_free_rx_resources(&adapter->test_rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001551}
1552
1553static int igb_setup_desc_rings(struct igb_adapter *adapter)
1554{
Auke Kok9d5c8242008-01-24 02:22:38 -08001555 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1556 struct igb_ring *rx_ring = &adapter->test_rx_ring;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001557 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckad93d172009-10-27 15:55:02 +00001558 int ret_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08001559
1560 /* Setup Tx descriptor ring and Tx buffers */
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001561 tx_ring->count = IGB_DEFAULT_TXD;
Alexander Duyck59d71982010-04-27 13:09:25 +00001562 tx_ring->dev = &adapter->pdev->dev;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001563 tx_ring->netdev = adapter->netdev;
1564 tx_ring->reg_idx = adapter->vfs_allocated_count;
Auke Kok9d5c8242008-01-24 02:22:38 -08001565
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001566 if (igb_setup_tx_resources(tx_ring)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001567 ret_val = 1;
1568 goto err_nomem;
1569 }
1570
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001571 igb_setup_tctl(adapter);
1572 igb_configure_tx_ring(adapter, tx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001573
Auke Kok9d5c8242008-01-24 02:22:38 -08001574 /* Setup Rx descriptor ring and Rx buffers */
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001575 rx_ring->count = IGB_DEFAULT_RXD;
Alexander Duyck59d71982010-04-27 13:09:25 +00001576 rx_ring->dev = &adapter->pdev->dev;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001577 rx_ring->netdev = adapter->netdev;
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001578 rx_ring->reg_idx = adapter->vfs_allocated_count;
Auke Kok9d5c8242008-01-24 02:22:38 -08001579
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001580 if (igb_setup_rx_resources(rx_ring)) {
1581 ret_val = 3;
Auke Kok9d5c8242008-01-24 02:22:38 -08001582 goto err_nomem;
1583 }
1584
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001585 /* set the default queue to queue 0 of PF */
1586 wr32(E1000_MRQC, adapter->vfs_allocated_count << 3);
Auke Kok9d5c8242008-01-24 02:22:38 -08001587
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00001588 /* enable receive ring */
1589 igb_setup_rctl(adapter);
1590 igb_configure_rx_ring(adapter, rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08001591
Alexander Duyckcd392f52011-08-26 07:43:59 +00001592 igb_alloc_rx_buffers(rx_ring, igb_desc_unused(rx_ring));
Auke Kok9d5c8242008-01-24 02:22:38 -08001593
1594 return 0;
1595
1596err_nomem:
1597 igb_free_desc_rings(adapter);
1598 return ret_val;
1599}
1600
1601static void igb_phy_disable_receiver(struct igb_adapter *adapter)
1602{
1603 struct e1000_hw *hw = &adapter->hw;
1604
1605 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001606 igb_write_phy_reg(hw, 29, 0x001F);
1607 igb_write_phy_reg(hw, 30, 0x8FFC);
1608 igb_write_phy_reg(hw, 29, 0x001A);
1609 igb_write_phy_reg(hw, 30, 0x8FF0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001610}
1611
1612static int igb_integrated_phy_loopback(struct igb_adapter *adapter)
1613{
1614 struct e1000_hw *hw = &adapter->hw;
1615 u32 ctrl_reg = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001616
1617 hw->mac.autoneg = false;
1618
Carolyn Wyborny8aa23f02012-06-08 05:01:39 +00001619 if (hw->phy.type == e1000_phy_m88) {
1620 if (hw->phy.id != I210_I_PHY_ID) {
1621 /* Auto-MDI/MDIX Off */
1622 igb_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1623 /* reset to update Auto-MDI/MDIX */
1624 igb_write_phy_reg(hw, PHY_CONTROL, 0x9140);
1625 /* autoneg off */
1626 igb_write_phy_reg(hw, PHY_CONTROL, 0x8140);
1627 } else {
1628 /* force 1000, set loopback */
1629 igb_write_phy_reg(hw, I347AT4_PAGE_SELECT, 0);
1630 igb_write_phy_reg(hw, PHY_CONTROL, 0x4140);
1631 }
Todd Fujinaka5aa3a442013-09-17 05:08:48 +00001632 } else if (hw->phy.type == e1000_phy_82580) {
1633 /* enable MII loopback */
1634 igb_write_phy_reg(hw, I82580_PHY_LBK_CTRL, 0x8041);
Auke Kok9d5c8242008-01-24 02:22:38 -08001635 }
1636
Stefan Assmann119b0e02012-08-07 00:45:57 -07001637 /* add small delay to avoid loopback test failure */
1638 msleep(50);
1639
Auke Kok9d5c8242008-01-24 02:22:38 -08001640 /* force 1000, set loopback */
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001641 igb_write_phy_reg(hw, PHY_CONTROL, 0x4140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001642
1643 /* Now set up the MAC to the same speed/duplex as the PHY. */
1644 ctrl_reg = rd32(E1000_CTRL);
1645 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1646 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1647 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1648 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
Alexander Duyckcdfa9f62009-03-31 20:38:56 +00001649 E1000_CTRL_FD | /* Force Duplex to FULL */
1650 E1000_CTRL_SLU); /* Set link up enable bit */
Auke Kok9d5c8242008-01-24 02:22:38 -08001651
Carolyn Wyborny8aa23f02012-06-08 05:01:39 +00001652 if (hw->phy.type == e1000_phy_m88)
Auke Kok9d5c8242008-01-24 02:22:38 -08001653 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kok9d5c8242008-01-24 02:22:38 -08001654
1655 wr32(E1000_CTRL, ctrl_reg);
1656
1657 /* Disable the receiver on the PHY so when a cable is plugged in, the
1658 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1659 */
Carolyn Wyborny8aa23f02012-06-08 05:01:39 +00001660 if (hw->phy.type == e1000_phy_m88)
Auke Kok9d5c8242008-01-24 02:22:38 -08001661 igb_phy_disable_receiver(adapter);
1662
Carolyn Wyborny8aa23f02012-06-08 05:01:39 +00001663 mdelay(500);
Auke Kok9d5c8242008-01-24 02:22:38 -08001664 return 0;
1665}
1666
1667static int igb_set_phy_loopback(struct igb_adapter *adapter)
1668{
1669 return igb_integrated_phy_loopback(adapter);
1670}
1671
1672static int igb_setup_loopback_test(struct igb_adapter *adapter)
1673{
1674 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001675 u32 reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001676
Alexander Duyck317f66b2009-10-27 23:46:20 +00001677 reg = rd32(E1000_CTRL_EXT);
1678
1679 /* use CTRL_EXT to identify link type as SGMII can appear as copper */
1680 if (reg & E1000_CTRL_EXT_LINK_MODE_MASK) {
Robert Healya14bc2b2011-07-12 08:46:20 +00001681 if ((hw->device_id == E1000_DEV_ID_DH89XXCC_SGMII) ||
1682 (hw->device_id == E1000_DEV_ID_DH89XXCC_SERDES) ||
1683 (hw->device_id == E1000_DEV_ID_DH89XXCC_BACKPLANE) ||
Fujinaka, Todda4e979a2013-10-01 04:33:55 -07001684 (hw->device_id == E1000_DEV_ID_DH89XXCC_SFP) ||
Todd Fujinaka3cfcf032014-05-29 05:45:15 +00001685 (hw->device_id == E1000_DEV_ID_I354_SGMII) ||
1686 (hw->device_id == E1000_DEV_ID_I354_BACKPLANE_2_5GBPS)) {
Robert Healya14bc2b2011-07-12 08:46:20 +00001687 /* Enable DH89xxCC MPHY for near end loopback */
1688 reg = rd32(E1000_MPHY_ADDR_CTL);
1689 reg = (reg & E1000_MPHY_ADDR_CTL_OFFSET_MASK) |
1690 E1000_MPHY_PCS_CLK_REG_OFFSET;
1691 wr32(E1000_MPHY_ADDR_CTL, reg);
1692
1693 reg = rd32(E1000_MPHY_DATA);
1694 reg |= E1000_MPHY_PCS_CLK_REG_DIGINELBEN;
1695 wr32(E1000_MPHY_DATA, reg);
1696 }
1697
Alexander Duyck2d064c02008-07-08 15:10:12 -07001698 reg = rd32(E1000_RCTL);
1699 reg |= E1000_RCTL_LBM_TCVR;
1700 wr32(E1000_RCTL, reg);
1701
1702 wr32(E1000_SCTL, E1000_ENABLE_SERDES_LOOPBACK);
1703
1704 reg = rd32(E1000_CTRL);
1705 reg &= ~(E1000_CTRL_RFCE |
1706 E1000_CTRL_TFCE |
1707 E1000_CTRL_LRST);
1708 reg |= E1000_CTRL_SLU |
Alexander Duyck2753f4c2009-02-06 23:18:48 +00001709 E1000_CTRL_FD;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001710 wr32(E1000_CTRL, reg);
1711
1712 /* Unset switch control to serdes energy detect */
1713 reg = rd32(E1000_CONNSW);
1714 reg &= ~E1000_CONNSW_ENRGSRC;
1715 wr32(E1000_CONNSW, reg);
1716
Carolyn Wyborny3860a0b2012-11-22 02:49:22 +00001717 /* Unset sigdetect for SERDES loopback on
Akeem G. Abodunrin0ba96d32013-03-20 08:01:40 +00001718 * 82580 and newer devices.
Carolyn Wyborny3860a0b2012-11-22 02:49:22 +00001719 */
Akeem G. Abodunrin0ba96d32013-03-20 08:01:40 +00001720 if (hw->mac.type >= e1000_82580) {
Carolyn Wyborny3860a0b2012-11-22 02:49:22 +00001721 reg = rd32(E1000_PCS_CFG0);
1722 reg |= E1000_PCS_CFG_IGN_SD;
1723 wr32(E1000_PCS_CFG0, reg);
Carolyn Wyborny3860a0b2012-11-22 02:49:22 +00001724 }
1725
Alexander Duyck2d064c02008-07-08 15:10:12 -07001726 /* Set PCS register for forced speed */
1727 reg = rd32(E1000_PCS_LCTL);
1728 reg &= ~E1000_PCS_LCTL_AN_ENABLE; /* Disable Autoneg*/
1729 reg |= E1000_PCS_LCTL_FLV_LINK_UP | /* Force link up */
1730 E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
1731 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
1732 E1000_PCS_LCTL_FSD | /* Force Speed */
1733 E1000_PCS_LCTL_FORCE_LINK; /* Force Link */
1734 wr32(E1000_PCS_LCTL, reg);
1735
Auke Kok9d5c8242008-01-24 02:22:38 -08001736 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001737 }
1738
Alexander Duyck317f66b2009-10-27 23:46:20 +00001739 return igb_set_phy_loopback(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001740}
1741
1742static void igb_loopback_cleanup(struct igb_adapter *adapter)
1743{
1744 struct e1000_hw *hw = &adapter->hw;
1745 u32 rctl;
1746 u16 phy_reg;
1747
Robert Healya14bc2b2011-07-12 08:46:20 +00001748 if ((hw->device_id == E1000_DEV_ID_DH89XXCC_SGMII) ||
1749 (hw->device_id == E1000_DEV_ID_DH89XXCC_SERDES) ||
1750 (hw->device_id == E1000_DEV_ID_DH89XXCC_BACKPLANE) ||
Fujinaka, Todda4e979a2013-10-01 04:33:55 -07001751 (hw->device_id == E1000_DEV_ID_DH89XXCC_SFP) ||
1752 (hw->device_id == E1000_DEV_ID_I354_SGMII)) {
Robert Healya14bc2b2011-07-12 08:46:20 +00001753 u32 reg;
1754
1755 /* Disable near end loopback on DH89xxCC */
1756 reg = rd32(E1000_MPHY_ADDR_CTL);
1757 reg = (reg & E1000_MPHY_ADDR_CTL_OFFSET_MASK) |
1758 E1000_MPHY_PCS_CLK_REG_OFFSET;
1759 wr32(E1000_MPHY_ADDR_CTL, reg);
1760
1761 reg = rd32(E1000_MPHY_DATA);
1762 reg &= ~E1000_MPHY_PCS_CLK_REG_DIGINELBEN;
1763 wr32(E1000_MPHY_DATA, reg);
1764 }
1765
Auke Kok9d5c8242008-01-24 02:22:38 -08001766 rctl = rd32(E1000_RCTL);
1767 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1768 wr32(E1000_RCTL, rctl);
1769
1770 hw->mac.autoneg = true;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001771 igb_read_phy_reg(hw, PHY_CONTROL, &phy_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001772 if (phy_reg & MII_CR_LOOPBACK) {
1773 phy_reg &= ~MII_CR_LOOPBACK;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001774 igb_write_phy_reg(hw, PHY_CONTROL, phy_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001775 igb_phy_sw_reset(hw);
1776 }
1777}
1778
1779static void igb_create_lbtest_frame(struct sk_buff *skb,
1780 unsigned int frame_size)
1781{
1782 memset(skb->data, 0xFF, frame_size);
Alexander Duyck317f66b2009-10-27 23:46:20 +00001783 frame_size /= 2;
1784 memset(&skb->data[frame_size], 0xAA, frame_size - 1);
1785 memset(&skb->data[frame_size + 10], 0xBE, 1);
1786 memset(&skb->data[frame_size + 12], 0xAF, 1);
Auke Kok9d5c8242008-01-24 02:22:38 -08001787}
1788
Alexander Duyck1a1c2252012-09-25 00:30:52 +00001789static int igb_check_lbtest_frame(struct igb_rx_buffer *rx_buffer,
1790 unsigned int frame_size)
Auke Kok9d5c8242008-01-24 02:22:38 -08001791{
Alexander Duyck1a1c2252012-09-25 00:30:52 +00001792 unsigned char *data;
1793 bool match = true;
1794
1795 frame_size >>= 1;
1796
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001797 data = kmap(rx_buffer->page);
Alexander Duyck1a1c2252012-09-25 00:30:52 +00001798
1799 if (data[3] != 0xFF ||
1800 data[frame_size + 10] != 0xBE ||
1801 data[frame_size + 12] != 0xAF)
1802 match = false;
1803
1804 kunmap(rx_buffer->page);
1805
1806 return match;
Auke Kok9d5c8242008-01-24 02:22:38 -08001807}
1808
Alexander Duyckad93d172009-10-27 15:55:02 +00001809static int igb_clean_test_rings(struct igb_ring *rx_ring,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001810 struct igb_ring *tx_ring,
1811 unsigned int size)
Alexander Duyckad93d172009-10-27 15:55:02 +00001812{
1813 union e1000_adv_rx_desc *rx_desc;
Alexander Duyck06034642011-08-26 07:44:22 +00001814 struct igb_rx_buffer *rx_buffer_info;
1815 struct igb_tx_buffer *tx_buffer_info;
Alexander Duyck6ad4edf2011-08-26 07:45:26 +00001816 u16 rx_ntc, tx_ntc, count = 0;
Alexander Duyckad93d172009-10-27 15:55:02 +00001817
1818 /* initialize next to clean and descriptor values */
1819 rx_ntc = rx_ring->next_to_clean;
1820 tx_ntc = tx_ring->next_to_clean;
Alexander Duyck601369062011-08-26 07:44:05 +00001821 rx_desc = IGB_RX_DESC(rx_ring, rx_ntc);
Alexander Duyckad93d172009-10-27 15:55:02 +00001822
Alexander Duyck7ec01162017-02-06 18:25:41 -08001823 while (rx_desc->wb.upper.length) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001824 /* check Rx buffer */
Alexander Duyck06034642011-08-26 07:44:22 +00001825 rx_buffer_info = &rx_ring->rx_buffer_info[rx_ntc];
Alexander Duyckad93d172009-10-27 15:55:02 +00001826
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001827 /* sync Rx buffer for CPU read */
1828 dma_sync_single_for_cpu(rx_ring->dev,
1829 rx_buffer_info->dma,
Alexander Duyckcb0ef1d2017-02-06 18:26:26 -08001830 size,
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001831 DMA_FROM_DEVICE);
Alexander Duyckad93d172009-10-27 15:55:02 +00001832
1833 /* verify contents of skb */
Alexander Duyck1a1c2252012-09-25 00:30:52 +00001834 if (igb_check_lbtest_frame(rx_buffer_info, size))
Alexander Duyckad93d172009-10-27 15:55:02 +00001835 count++;
1836
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001837 /* sync Rx buffer for device write */
1838 dma_sync_single_for_device(rx_ring->dev,
1839 rx_buffer_info->dma,
Alexander Duyckcb0ef1d2017-02-06 18:26:26 -08001840 size,
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001841 DMA_FROM_DEVICE);
1842
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001843 /* unmap buffer on Tx side */
Alexander Duyck06034642011-08-26 07:44:22 +00001844 tx_buffer_info = &tx_ring->tx_buffer_info[tx_ntc];
Alexander Duyck7cc6fd42017-02-06 18:26:02 -08001845
1846 /* Free all the Tx ring sk_buffs */
1847 dev_kfree_skb_any(tx_buffer_info->skb);
1848
1849 /* unmap skb header data */
1850 dma_unmap_single(tx_ring->dev,
1851 dma_unmap_addr(tx_buffer_info, dma),
1852 dma_unmap_len(tx_buffer_info, len),
1853 DMA_TO_DEVICE);
1854 dma_unmap_len_set(tx_buffer_info, len, 0);
Alexander Duyckad93d172009-10-27 15:55:02 +00001855
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001856 /* increment Rx/Tx next to clean counters */
Alexander Duyckad93d172009-10-27 15:55:02 +00001857 rx_ntc++;
1858 if (rx_ntc == rx_ring->count)
1859 rx_ntc = 0;
1860 tx_ntc++;
1861 if (tx_ntc == tx_ring->count)
1862 tx_ntc = 0;
1863
1864 /* fetch next descriptor */
Alexander Duyck601369062011-08-26 07:44:05 +00001865 rx_desc = IGB_RX_DESC(rx_ring, rx_ntc);
Alexander Duyckad93d172009-10-27 15:55:02 +00001866 }
1867
Alexander Duyckcbc8e552012-09-25 00:31:02 +00001868 netdev_tx_reset_queue(txring_txq(tx_ring));
Jeff Kirsher51a76c32012-01-19 18:31:34 +00001869
Alexander Duyckad93d172009-10-27 15:55:02 +00001870 /* re-map buffers to ring, store next to clean values */
Alexander Duyckcd392f52011-08-26 07:43:59 +00001871 igb_alloc_rx_buffers(rx_ring, count);
Alexander Duyckad93d172009-10-27 15:55:02 +00001872 rx_ring->next_to_clean = rx_ntc;
1873 tx_ring->next_to_clean = tx_ntc;
1874
1875 return count;
1876}
1877
Auke Kok9d5c8242008-01-24 02:22:38 -08001878static int igb_run_loopback_test(struct igb_adapter *adapter)
1879{
Auke Kok9d5c8242008-01-24 02:22:38 -08001880 struct igb_ring *tx_ring = &adapter->test_tx_ring;
1881 struct igb_ring *rx_ring = &adapter->test_rx_ring;
Alexander Duyck6ad4edf2011-08-26 07:45:26 +00001882 u16 i, j, lc, good_cnt;
1883 int ret_val = 0;
Alexander Duyck44390ca2011-08-26 07:43:38 +00001884 unsigned int size = IGB_RX_HDR_LEN;
Alexander Duyckad93d172009-10-27 15:55:02 +00001885 netdev_tx_t tx_ret_val;
1886 struct sk_buff *skb;
Auke Kok9d5c8242008-01-24 02:22:38 -08001887
Alexander Duyckad93d172009-10-27 15:55:02 +00001888 /* allocate test skb */
1889 skb = alloc_skb(size, GFP_KERNEL);
1890 if (!skb)
1891 return 11;
1892
1893 /* place data into test skb */
1894 igb_create_lbtest_frame(skb, size);
1895 skb_put(skb, size);
Auke Kok9d5c8242008-01-24 02:22:38 -08001896
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001897 /* Calculate the loop count based on the largest descriptor ring
Auke Kok9d5c8242008-01-24 02:22:38 -08001898 * The idea is to wrap the largest ring a number of times using 64
1899 * send/receive pairs during each loop
1900 */
1901
1902 if (rx_ring->count <= tx_ring->count)
1903 lc = ((tx_ring->count / 64) * 2) + 1;
1904 else
1905 lc = ((rx_ring->count / 64) * 2) + 1;
1906
Auke Kok9d5c8242008-01-24 02:22:38 -08001907 for (j = 0; j <= lc; j++) { /* loop count loop */
Alexander Duyckad93d172009-10-27 15:55:02 +00001908 /* reset count of good packets */
Auke Kok9d5c8242008-01-24 02:22:38 -08001909 good_cnt = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001910
Alexander Duyckad93d172009-10-27 15:55:02 +00001911 /* place 64 packets on the transmit queue*/
1912 for (i = 0; i < 64; i++) {
1913 skb_get(skb);
Alexander Duyckcd392f52011-08-26 07:43:59 +00001914 tx_ret_val = igb_xmit_frame_ring(skb, tx_ring);
Alexander Duyckad93d172009-10-27 15:55:02 +00001915 if (tx_ret_val == NETDEV_TX_OK)
Auke Kok9d5c8242008-01-24 02:22:38 -08001916 good_cnt++;
Alexander Duyckad93d172009-10-27 15:55:02 +00001917 }
1918
Auke Kok9d5c8242008-01-24 02:22:38 -08001919 if (good_cnt != 64) {
Alexander Duyckad93d172009-10-27 15:55:02 +00001920 ret_val = 12;
Auke Kok9d5c8242008-01-24 02:22:38 -08001921 break;
1922 }
Alexander Duyckad93d172009-10-27 15:55:02 +00001923
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001924 /* allow 200 milliseconds for packets to go from Tx to Rx */
Alexander Duyckad93d172009-10-27 15:55:02 +00001925 msleep(200);
1926
1927 good_cnt = igb_clean_test_rings(rx_ring, tx_ring, size);
1928 if (good_cnt != 64) {
1929 ret_val = 13;
Auke Kok9d5c8242008-01-24 02:22:38 -08001930 break;
1931 }
1932 } /* end loop count loop */
Alexander Duyckad93d172009-10-27 15:55:02 +00001933
1934 /* free the original skb */
1935 kfree_skb(skb);
1936
Auke Kok9d5c8242008-01-24 02:22:38 -08001937 return ret_val;
1938}
1939
1940static int igb_loopback_test(struct igb_adapter *adapter, u64 *data)
1941{
1942 /* PHY loopback cannot be performed if SoL/IDER
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001943 * sessions are active
1944 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001945 if (igb_check_reset_block(&adapter->hw)) {
1946 dev_err(&adapter->pdev->dev,
Jesper Juhld836200a2012-08-01 05:41:30 +00001947 "Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001948 *data = 0;
1949 goto out;
1950 }
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00001951
1952 if (adapter->hw.mac.type == e1000_i354) {
1953 dev_info(&adapter->pdev->dev,
1954 "Loopback test not supported on i354.\n");
1955 *data = 0;
1956 goto out;
1957 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001958 *data = igb_setup_desc_rings(adapter);
1959 if (*data)
1960 goto out;
1961 *data = igb_setup_loopback_test(adapter);
1962 if (*data)
1963 goto err_loopback;
1964 *data = igb_run_loopback_test(adapter);
1965 igb_loopback_cleanup(adapter);
1966
1967err_loopback:
1968 igb_free_desc_rings(adapter);
1969out:
1970 return *data;
1971}
1972
1973static int igb_link_test(struct igb_adapter *adapter, u64 *data)
1974{
1975 struct e1000_hw *hw = &adapter->hw;
1976 *data = 0;
1977 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1978 int i = 0;
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001979
Auke Kok9d5c8242008-01-24 02:22:38 -08001980 hw->mac.serdes_has_link = false;
1981
1982 /* On some blade server designs, link establishment
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001983 * could take as long as 2-3 minutes
1984 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001985 do {
1986 hw->mac.ops.check_for_link(&adapter->hw);
1987 if (hw->mac.serdes_has_link)
1988 return *data;
1989 msleep(20);
1990 } while (i++ < 3750);
1991
1992 *data = 1;
1993 } else {
1994 hw->mac.ops.check_for_link(&adapter->hw);
1995 if (hw->mac.autoneg)
Stefan Assmann4507dc92013-02-02 08:31:50 +00001996 msleep(5000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001997
Alexander Duyck317f66b2009-10-27 23:46:20 +00001998 if (!(rd32(E1000_STATUS) & E1000_STATUS_LU))
Auke Kok9d5c8242008-01-24 02:22:38 -08001999 *data = 1;
2000 }
2001 return *data;
2002}
2003
2004static void igb_diag_test(struct net_device *netdev,
2005 struct ethtool_test *eth_test, u64 *data)
2006{
2007 struct igb_adapter *adapter = netdev_priv(netdev);
2008 u16 autoneg_advertised;
2009 u8 forced_speed_duplex, autoneg;
2010 bool if_running = netif_running(netdev);
2011
2012 set_bit(__IGB_TESTING, &adapter->state);
Carolyn Wyborny56cec242013-10-17 05:36:26 +00002013
2014 /* can't do offline tests on media switching devices */
2015 if (adapter->hw.dev_spec._82575.mas_capable)
2016 eth_test->flags &= ~ETH_TEST_FL_OFFLINE;
Auke Kok9d5c8242008-01-24 02:22:38 -08002017 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
2018 /* Offline tests */
2019
2020 /* save speed, duplex, autoneg settings */
2021 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
2022 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
2023 autoneg = adapter->hw.mac.autoneg;
2024
2025 dev_info(&adapter->pdev->dev, "offline testing starting\n");
2026
Nick Nunley88a268c2010-02-17 01:01:59 +00002027 /* power up link for link test */
2028 igb_power_up_link(adapter);
2029
Auke Kok9d5c8242008-01-24 02:22:38 -08002030 /* Link test performed before hardware reset so autoneg doesn't
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002031 * interfere with test result
2032 */
Joe Schultzd602de02015-11-03 12:37:29 -06002033 if (igb_link_test(adapter, &data[TEST_LINK]))
Auke Kok9d5c8242008-01-24 02:22:38 -08002034 eth_test->flags |= ETH_TEST_FL_FAILED;
2035
2036 if (if_running)
2037 /* indicate we're in test mode */
Stefan Assmann46eafa52016-02-03 09:20:50 +01002038 igb_close(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08002039 else
2040 igb_reset(adapter);
2041
Joe Schultzd602de02015-11-03 12:37:29 -06002042 if (igb_reg_test(adapter, &data[TEST_REG]))
Auke Kok9d5c8242008-01-24 02:22:38 -08002043 eth_test->flags |= ETH_TEST_FL_FAILED;
2044
2045 igb_reset(adapter);
Joe Schultzd602de02015-11-03 12:37:29 -06002046 if (igb_eeprom_test(adapter, &data[TEST_EEP]))
Auke Kok9d5c8242008-01-24 02:22:38 -08002047 eth_test->flags |= ETH_TEST_FL_FAILED;
2048
2049 igb_reset(adapter);
Joe Schultzd602de02015-11-03 12:37:29 -06002050 if (igb_intr_test(adapter, &data[TEST_IRQ]))
Auke Kok9d5c8242008-01-24 02:22:38 -08002051 eth_test->flags |= ETH_TEST_FL_FAILED;
2052
2053 igb_reset(adapter);
Nick Nunley88a268c2010-02-17 01:01:59 +00002054 /* power up link for loopback test */
2055 igb_power_up_link(adapter);
Joe Schultzd602de02015-11-03 12:37:29 -06002056 if (igb_loopback_test(adapter, &data[TEST_LOOP]))
Auke Kok9d5c8242008-01-24 02:22:38 -08002057 eth_test->flags |= ETH_TEST_FL_FAILED;
2058
2059 /* restore speed, duplex, autoneg settings */
2060 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
2061 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
2062 adapter->hw.mac.autoneg = autoneg;
2063
2064 /* force this routine to wait until autoneg complete/timeout */
2065 adapter->hw.phy.autoneg_wait_to_complete = true;
2066 igb_reset(adapter);
2067 adapter->hw.phy.autoneg_wait_to_complete = false;
2068
2069 clear_bit(__IGB_TESTING, &adapter->state);
2070 if (if_running)
Stefan Assmann46eafa52016-02-03 09:20:50 +01002071 igb_open(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08002072 } else {
2073 dev_info(&adapter->pdev->dev, "online testing starting\n");
Nick Nunley88a268c2010-02-17 01:01:59 +00002074
2075 /* PHY is powered down when interface is down */
Joe Schultzd602de02015-11-03 12:37:29 -06002076 if (if_running && igb_link_test(adapter, &data[TEST_LINK]))
Alexander Duyck8d420a12010-07-01 13:39:01 +00002077 eth_test->flags |= ETH_TEST_FL_FAILED;
2078 else
Joe Schultzd602de02015-11-03 12:37:29 -06002079 data[TEST_LINK] = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002080
2081 /* Online tests aren't run; pass by default */
Joe Schultzd602de02015-11-03 12:37:29 -06002082 data[TEST_REG] = 0;
2083 data[TEST_EEP] = 0;
2084 data[TEST_IRQ] = 0;
2085 data[TEST_LOOP] = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002086
2087 clear_bit(__IGB_TESTING, &adapter->state);
2088 }
2089 msleep_interruptible(4 * 1000);
2090}
2091
Auke Kok9d5c8242008-01-24 02:22:38 -08002092static void igb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2093{
2094 struct igb_adapter *adapter = netdev_priv(netdev);
2095
Auke Kok9d5c8242008-01-24 02:22:38 -08002096 wol->wolopts = 0;
2097
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002098 if (!(adapter->flags & IGB_FLAG_WOL_SUPPORTED))
Auke Kok9d5c8242008-01-24 02:22:38 -08002099 return;
2100
Akeem G Abodunrin42ce4122013-11-08 01:54:07 +00002101 wol->supported = WAKE_UCAST | WAKE_MCAST |
2102 WAKE_BCAST | WAKE_MAGIC |
2103 WAKE_PHY;
2104
Auke Kok9d5c8242008-01-24 02:22:38 -08002105 /* apply any specific unsupported masks here */
2106 switch (adapter->hw.device_id) {
2107 default:
2108 break;
2109 }
2110
2111 if (adapter->wol & E1000_WUFC_EX)
2112 wol->wolopts |= WAKE_UCAST;
2113 if (adapter->wol & E1000_WUFC_MC)
2114 wol->wolopts |= WAKE_MCAST;
2115 if (adapter->wol & E1000_WUFC_BC)
2116 wol->wolopts |= WAKE_BCAST;
2117 if (adapter->wol & E1000_WUFC_MAG)
2118 wol->wolopts |= WAKE_MAGIC;
Nick Nunley22939f02010-02-17 01:01:01 +00002119 if (adapter->wol & E1000_WUFC_LNKC)
2120 wol->wolopts |= WAKE_PHY;
Auke Kok9d5c8242008-01-24 02:22:38 -08002121}
2122
2123static int igb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2124{
2125 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08002126
Nick Nunley22939f02010-02-17 01:01:01 +00002127 if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE))
Auke Kok9d5c8242008-01-24 02:22:38 -08002128 return -EOPNOTSUPP;
2129
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002130 if (!(adapter->flags & IGB_FLAG_WOL_SUPPORTED))
Auke Kok9d5c8242008-01-24 02:22:38 -08002131 return wol->wolopts ? -EOPNOTSUPP : 0;
2132
Auke Kok9d5c8242008-01-24 02:22:38 -08002133 /* these settings will always override what we currently have */
2134 adapter->wol = 0;
2135
2136 if (wol->wolopts & WAKE_UCAST)
2137 adapter->wol |= E1000_WUFC_EX;
2138 if (wol->wolopts & WAKE_MCAST)
2139 adapter->wol |= E1000_WUFC_MC;
2140 if (wol->wolopts & WAKE_BCAST)
2141 adapter->wol |= E1000_WUFC_BC;
2142 if (wol->wolopts & WAKE_MAGIC)
2143 adapter->wol |= E1000_WUFC_MAG;
Nick Nunley22939f02010-02-17 01:01:01 +00002144 if (wol->wolopts & WAKE_PHY)
2145 adapter->wol |= E1000_WUFC_LNKC;
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00002146 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
2147
Auke Kok9d5c8242008-01-24 02:22:38 -08002148 return 0;
2149}
2150
Auke Kok9d5c8242008-01-24 02:22:38 -08002151/* bit defines for adapter->led_status */
2152#define IGB_LED_ON 0
2153
Jeff Kirsher936db352011-05-07 06:37:14 +00002154static int igb_set_phys_id(struct net_device *netdev,
2155 enum ethtool_phys_id_state state)
Auke Kok9d5c8242008-01-24 02:22:38 -08002156{
2157 struct igb_adapter *adapter = netdev_priv(netdev);
2158 struct e1000_hw *hw = &adapter->hw;
2159
Jeff Kirsher936db352011-05-07 06:37:14 +00002160 switch (state) {
2161 case ETHTOOL_ID_ACTIVE:
2162 igb_blink_led(hw);
2163 return 2;
2164 case ETHTOOL_ID_ON:
2165 igb_blink_led(hw);
2166 break;
2167 case ETHTOOL_ID_OFF:
2168 igb_led_off(hw);
2169 break;
2170 case ETHTOOL_ID_INACTIVE:
2171 igb_led_off(hw);
2172 clear_bit(IGB_LED_ON, &adapter->led_status);
2173 igb_cleanup_led(hw);
2174 break;
2175 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002176
2177 return 0;
2178}
2179
2180static int igb_set_coalesce(struct net_device *netdev,
2181 struct ethtool_coalesce *ec)
2182{
2183 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002184 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08002185
Todd Fujinaka0c5bbeb2015-06-04 14:26:56 -07002186 if (ec->rx_max_coalesced_frames ||
2187 ec->rx_coalesce_usecs_irq ||
2188 ec->rx_max_coalesced_frames_irq ||
2189 ec->tx_max_coalesced_frames ||
2190 ec->tx_coalesce_usecs_irq ||
2191 ec->stats_block_coalesce_usecs ||
2192 ec->use_adaptive_rx_coalesce ||
2193 ec->use_adaptive_tx_coalesce ||
2194 ec->pkt_rate_low ||
2195 ec->rx_coalesce_usecs_low ||
2196 ec->rx_max_coalesced_frames_low ||
2197 ec->tx_coalesce_usecs_low ||
2198 ec->tx_max_coalesced_frames_low ||
2199 ec->pkt_rate_high ||
2200 ec->rx_coalesce_usecs_high ||
2201 ec->rx_max_coalesced_frames_high ||
2202 ec->tx_coalesce_usecs_high ||
2203 ec->tx_max_coalesced_frames_high ||
2204 ec->rate_sample_interval)
2205 return -ENOTSUPP;
2206
Auke Kok9d5c8242008-01-24 02:22:38 -08002207 if ((ec->rx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
2208 ((ec->rx_coalesce_usecs > 3) &&
2209 (ec->rx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
2210 (ec->rx_coalesce_usecs == 2))
2211 return -EINVAL;
2212
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002213 if ((ec->tx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
2214 ((ec->tx_coalesce_usecs > 3) &&
2215 (ec->tx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
2216 (ec->tx_coalesce_usecs == 2))
2217 return -EINVAL;
2218
2219 if ((adapter->flags & IGB_FLAG_QUEUE_PAIRS) && ec->tx_coalesce_usecs)
2220 return -EINVAL;
2221
Carolyn Wyborny831ec0b2011-03-11 20:43:54 -08002222 /* If ITR is disabled, disable DMAC */
2223 if (ec->rx_coalesce_usecs == 0) {
2224 if (adapter->flags & IGB_FLAG_DMAC)
2225 adapter->flags &= ~IGB_FLAG_DMAC;
2226 }
2227
Auke Kok9d5c8242008-01-24 02:22:38 -08002228 /* convert to rate of irq's per second */
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002229 if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3)
2230 adapter->rx_itr_setting = ec->rx_coalesce_usecs;
2231 else
2232 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
2233
2234 /* convert to rate of irq's per second */
2235 if (adapter->flags & IGB_FLAG_QUEUE_PAIRS)
2236 adapter->tx_itr_setting = adapter->rx_itr_setting;
2237 else if (ec->tx_coalesce_usecs && ec->tx_coalesce_usecs <= 3)
2238 adapter->tx_itr_setting = ec->tx_coalesce_usecs;
2239 else
2240 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
Auke Kok9d5c8242008-01-24 02:22:38 -08002241
Alexander Duyck047e0032009-10-27 15:49:27 +00002242 for (i = 0; i < adapter->num_q_vectors; i++) {
2243 struct igb_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck0ba82992011-08-26 07:45:47 +00002244 q_vector->tx.work_limit = adapter->tx_work_limit;
2245 if (q_vector->rx.ring)
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002246 q_vector->itr_val = adapter->rx_itr_setting;
2247 else
2248 q_vector->itr_val = adapter->tx_itr_setting;
2249 if (q_vector->itr_val && q_vector->itr_val <= 3)
2250 q_vector->itr_val = IGB_START_ITR;
Alexander Duyck047e0032009-10-27 15:49:27 +00002251 q_vector->set_itr = 1;
2252 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002253
2254 return 0;
2255}
2256
2257static int igb_get_coalesce(struct net_device *netdev,
2258 struct ethtool_coalesce *ec)
2259{
2260 struct igb_adapter *adapter = netdev_priv(netdev);
2261
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002262 if (adapter->rx_itr_setting <= 3)
2263 ec->rx_coalesce_usecs = adapter->rx_itr_setting;
Auke Kok9d5c8242008-01-24 02:22:38 -08002264 else
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002265 ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
2266
2267 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS)) {
2268 if (adapter->tx_itr_setting <= 3)
2269 ec->tx_coalesce_usecs = adapter->tx_itr_setting;
2270 else
2271 ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
2272 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002273
2274 return 0;
2275}
2276
Auke Kok9d5c8242008-01-24 02:22:38 -08002277static int igb_nway_reset(struct net_device *netdev)
2278{
2279 struct igb_adapter *adapter = netdev_priv(netdev);
2280 if (netif_running(netdev))
2281 igb_reinit_locked(adapter);
2282 return 0;
2283}
2284
2285static int igb_get_sset_count(struct net_device *netdev, int sset)
2286{
2287 switch (sset) {
2288 case ETH_SS_STATS:
2289 return IGB_STATS_LEN;
2290 case ETH_SS_TEST:
2291 return IGB_TEST_LEN;
Alexander Duycke0891292017-02-06 18:26:52 -08002292 case ETH_SS_PRIV_FLAGS:
2293 return IGB_PRIV_FLAGS_STR_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002294 default:
2295 return -ENOTSUPP;
2296 }
2297}
2298
2299static void igb_get_ethtool_stats(struct net_device *netdev,
2300 struct ethtool_stats *stats, u64 *data)
2301{
2302 struct igb_adapter *adapter = netdev_priv(netdev);
Eric Dumazet12dcd862010-10-15 17:27:10 +00002303 struct rtnl_link_stats64 *net_stats = &adapter->stats64;
2304 unsigned int start;
2305 struct igb_ring *ring;
2306 int i, j;
Alexander Duyck128e45e2009-11-12 18:37:38 +00002307 char *p;
Auke Kok9d5c8242008-01-24 02:22:38 -08002308
Eric Dumazet12dcd862010-10-15 17:27:10 +00002309 spin_lock(&adapter->stats64_lock);
2310 igb_update_stats(adapter, net_stats);
Alexander Duyck317f66b2009-10-27 23:46:20 +00002311
Auke Kok9d5c8242008-01-24 02:22:38 -08002312 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
Alexander Duyck128e45e2009-11-12 18:37:38 +00002313 p = (char *)adapter + igb_gstrings_stats[i].stat_offset;
Auke Kok9d5c8242008-01-24 02:22:38 -08002314 data[i] = (igb_gstrings_stats[i].sizeof_stat ==
2315 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2316 }
Alexander Duyck128e45e2009-11-12 18:37:38 +00002317 for (j = 0; j < IGB_NETDEV_STATS_LEN; j++, i++) {
2318 p = (char *)net_stats + igb_gstrings_net_stats[j].stat_offset;
2319 data[i] = (igb_gstrings_net_stats[j].sizeof_stat ==
2320 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2321 }
Alexander Duycke21ed352008-07-08 15:07:24 -07002322 for (j = 0; j < adapter->num_tx_queues; j++) {
Eric Dumazet12dcd862010-10-15 17:27:10 +00002323 u64 restart2;
2324
2325 ring = adapter->tx_ring[j];
2326 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07002327 start = u64_stats_fetch_begin_irq(&ring->tx_syncp);
Eric Dumazet12dcd862010-10-15 17:27:10 +00002328 data[i] = ring->tx_stats.packets;
2329 data[i+1] = ring->tx_stats.bytes;
2330 data[i+2] = ring->tx_stats.restart_queue;
Eric W. Biederman57a77442014-03-13 21:26:42 -07002331 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp, start));
Eric Dumazet12dcd862010-10-15 17:27:10 +00002332 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07002333 start = u64_stats_fetch_begin_irq(&ring->tx_syncp2);
Eric Dumazet12dcd862010-10-15 17:27:10 +00002334 restart2 = ring->tx_stats.restart_queue2;
Eric W. Biederman57a77442014-03-13 21:26:42 -07002335 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp2, start));
Eric Dumazet12dcd862010-10-15 17:27:10 +00002336 data[i+2] += restart2;
2337
2338 i += IGB_TX_QUEUE_STATS_LEN;
Alexander Duycke21ed352008-07-08 15:07:24 -07002339 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002340 for (j = 0; j < adapter->num_rx_queues; j++) {
Eric Dumazet12dcd862010-10-15 17:27:10 +00002341 ring = adapter->rx_ring[j];
2342 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07002343 start = u64_stats_fetch_begin_irq(&ring->rx_syncp);
Eric Dumazet12dcd862010-10-15 17:27:10 +00002344 data[i] = ring->rx_stats.packets;
2345 data[i+1] = ring->rx_stats.bytes;
2346 data[i+2] = ring->rx_stats.drops;
2347 data[i+3] = ring->rx_stats.csum_err;
2348 data[i+4] = ring->rx_stats.alloc_failed;
Eric W. Biederman57a77442014-03-13 21:26:42 -07002349 } while (u64_stats_fetch_retry_irq(&ring->rx_syncp, start));
Eric Dumazet12dcd862010-10-15 17:27:10 +00002350 i += IGB_RX_QUEUE_STATS_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002351 }
Eric Dumazet12dcd862010-10-15 17:27:10 +00002352 spin_unlock(&adapter->stats64_lock);
Auke Kok9d5c8242008-01-24 02:22:38 -08002353}
2354
2355static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
2356{
2357 struct igb_adapter *adapter = netdev_priv(netdev);
2358 u8 *p = data;
2359 int i;
2360
2361 switch (stringset) {
2362 case ETH_SS_TEST:
2363 memcpy(data, *igb_gstrings_test,
2364 IGB_TEST_LEN*ETH_GSTRING_LEN);
2365 break;
2366 case ETH_SS_STATS:
2367 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
2368 memcpy(p, igb_gstrings_stats[i].stat_string,
2369 ETH_GSTRING_LEN);
2370 p += ETH_GSTRING_LEN;
2371 }
Alexander Duyck128e45e2009-11-12 18:37:38 +00002372 for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) {
2373 memcpy(p, igb_gstrings_net_stats[i].stat_string,
2374 ETH_GSTRING_LEN);
2375 p += ETH_GSTRING_LEN;
2376 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002377 for (i = 0; i < adapter->num_tx_queues; i++) {
2378 sprintf(p, "tx_queue_%u_packets", i);
2379 p += ETH_GSTRING_LEN;
2380 sprintf(p, "tx_queue_%u_bytes", i);
2381 p += ETH_GSTRING_LEN;
Alexander Duyck04a5fcaa2009-10-27 15:52:27 +00002382 sprintf(p, "tx_queue_%u_restart", i);
2383 p += ETH_GSTRING_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002384 }
2385 for (i = 0; i < adapter->num_rx_queues; i++) {
2386 sprintf(p, "rx_queue_%u_packets", i);
2387 p += ETH_GSTRING_LEN;
2388 sprintf(p, "rx_queue_%u_bytes", i);
2389 p += ETH_GSTRING_LEN;
Jesper Dangaard Brouer8c0ab702009-05-26 13:50:31 +00002390 sprintf(p, "rx_queue_%u_drops", i);
2391 p += ETH_GSTRING_LEN;
Alexander Duyck04a5fcaa2009-10-27 15:52:27 +00002392 sprintf(p, "rx_queue_%u_csum_err", i);
2393 p += ETH_GSTRING_LEN;
2394 sprintf(p, "rx_queue_%u_alloc_failed", i);
2395 p += ETH_GSTRING_LEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002396 }
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002397 /* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
Auke Kok9d5c8242008-01-24 02:22:38 -08002398 break;
Alexander Duycke0891292017-02-06 18:26:52 -08002399 case ETH_SS_PRIV_FLAGS:
2400 memcpy(data, igb_priv_flags_strings,
2401 IGB_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
2402 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08002403 }
2404}
2405
Matthew Vicka79f4f82012-08-10 05:40:44 +00002406static int igb_get_ts_info(struct net_device *dev,
Matthew Vicka9188022012-08-28 06:33:05 +00002407 struct ethtool_ts_info *info)
Carolyn Wybornycb411452012-04-04 17:43:59 +00002408{
2409 struct igb_adapter *adapter = netdev_priv(dev);
2410
Ken ICHIKAWA0f49da02014-03-21 03:37:24 -07002411 if (adapter->ptp_clock)
2412 info->phc_index = ptp_clock_index(adapter->ptp_clock);
2413 else
2414 info->phc_index = -1;
2415
Matthew Vicka9188022012-08-28 06:33:05 +00002416 switch (adapter->hw.mac.type) {
Matthew Vickb66e2392012-12-13 07:20:33 +00002417 case e1000_82575:
2418 info->so_timestamping =
2419 SOF_TIMESTAMPING_TX_SOFTWARE |
2420 SOF_TIMESTAMPING_RX_SOFTWARE |
2421 SOF_TIMESTAMPING_SOFTWARE;
2422 return 0;
Matthew Vicka9188022012-08-28 06:33:05 +00002423 case e1000_82576:
2424 case e1000_82580:
2425 case e1000_i350:
Carolyn Wybornyceb5f132013-04-18 22:21:30 +00002426 case e1000_i354:
Matthew Vicka9188022012-08-28 06:33:05 +00002427 case e1000_i210:
2428 case e1000_i211:
2429 info->so_timestamping =
Matthew Vickb66e2392012-12-13 07:20:33 +00002430 SOF_TIMESTAMPING_TX_SOFTWARE |
2431 SOF_TIMESTAMPING_RX_SOFTWARE |
2432 SOF_TIMESTAMPING_SOFTWARE |
Matthew Vicka9188022012-08-28 06:33:05 +00002433 SOF_TIMESTAMPING_TX_HARDWARE |
2434 SOF_TIMESTAMPING_RX_HARDWARE |
2435 SOF_TIMESTAMPING_RAW_HARDWARE;
Carolyn Wybornycb411452012-04-04 17:43:59 +00002436
Matthew Vicka9188022012-08-28 06:33:05 +00002437 info->tx_types =
Jacob Kellera51d8c22016-04-13 16:08:28 -07002438 BIT(HWTSTAMP_TX_OFF) |
2439 BIT(HWTSTAMP_TX_ON);
Carolyn Wybornycb411452012-04-04 17:43:59 +00002440
Jacob Kellera51d8c22016-04-13 16:08:28 -07002441 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE);
Carolyn Wybornycb411452012-04-04 17:43:59 +00002442
Matthew Vicka9188022012-08-28 06:33:05 +00002443 /* 82576 does not support timestamping all packets. */
2444 if (adapter->hw.mac.type >= e1000_82580)
Jacob Kellera51d8c22016-04-13 16:08:28 -07002445 info->rx_filters |= BIT(HWTSTAMP_FILTER_ALL);
Matthew Vicka9188022012-08-28 06:33:05 +00002446 else
2447 info->rx_filters |=
Jacob Kellera51d8c22016-04-13 16:08:28 -07002448 BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
2449 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
2450 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Matthew Vicka9188022012-08-28 06:33:05 +00002451
2452 return 0;
Matthew Vicka9188022012-08-28 06:33:05 +00002453 default:
2454 return -EOPNOTSUPP;
2455 }
2456}
Carolyn Wybornycb411452012-04-04 17:43:59 +00002457
Gangfeng Huang64c75d42016-07-06 13:22:55 +08002458#define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
Gangfeng Huang0e71def2016-07-06 13:22:54 +08002459static int igb_get_ethtool_nfc_entry(struct igb_adapter *adapter,
2460 struct ethtool_rxnfc *cmd)
2461{
2462 struct ethtool_rx_flow_spec *fsp = &cmd->fs;
2463 struct igb_nfc_filter *rule = NULL;
2464
2465 /* report total rule count */
2466 cmd->data = IGB_MAX_RXNFC_FILTERS;
2467
2468 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node) {
2469 if (fsp->location <= rule->sw_idx)
2470 break;
2471 }
2472
2473 if (!rule || fsp->location != rule->sw_idx)
2474 return -EINVAL;
2475
Gangfeng Huang7a277a92016-07-06 13:22:56 +08002476 if (rule->filter.match_flags) {
Gangfeng Huang64c75d42016-07-06 13:22:55 +08002477 fsp->flow_type = ETHER_FLOW;
2478 fsp->ring_cookie = rule->action;
Gangfeng Huang7a277a92016-07-06 13:22:56 +08002479 if (rule->filter.match_flags & IGB_FILTER_FLAG_ETHER_TYPE) {
2480 fsp->h_u.ether_spec.h_proto = rule->filter.etype;
2481 fsp->m_u.ether_spec.h_proto = ETHER_TYPE_FULL_MASK;
2482 }
2483 if (rule->filter.match_flags & IGB_FILTER_FLAG_VLAN_TCI) {
2484 fsp->flow_type |= FLOW_EXT;
2485 fsp->h_ext.vlan_tci = rule->filter.vlan_tci;
2486 fsp->m_ext.vlan_tci = htons(VLAN_PRIO_MASK);
2487 }
Gangfeng Huang64c75d42016-07-06 13:22:55 +08002488 return 0;
2489 }
Gangfeng Huang0e71def2016-07-06 13:22:54 +08002490 return -EINVAL;
2491}
2492
2493static int igb_get_ethtool_nfc_all(struct igb_adapter *adapter,
2494 struct ethtool_rxnfc *cmd,
2495 u32 *rule_locs)
2496{
2497 struct igb_nfc_filter *rule;
2498 int cnt = 0;
2499
2500 /* report total rule count */
2501 cmd->data = IGB_MAX_RXNFC_FILTERS;
2502
2503 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node) {
2504 if (cnt == cmd->rule_cnt)
2505 return -EMSGSIZE;
2506 rule_locs[cnt] = rule->sw_idx;
2507 cnt++;
2508 }
2509
2510 cmd->rule_cnt = cnt;
2511
2512 return 0;
2513}
2514
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002515static int igb_get_rss_hash_opts(struct igb_adapter *adapter,
2516 struct ethtool_rxnfc *cmd)
2517{
2518 cmd->data = 0;
2519
2520 /* Report default options for RSS on igb */
2521 switch (cmd->flow_type) {
2522 case TCP_V4_FLOW:
2523 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
Carolyn Wybornyb26141d2014-04-17 04:10:13 +00002524 /* Fall through */
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002525 case UDP_V4_FLOW:
2526 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
2527 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
Carolyn Wybornyb26141d2014-04-17 04:10:13 +00002528 /* Fall through */
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002529 case SCTP_V4_FLOW:
2530 case AH_ESP_V4_FLOW:
2531 case AH_V4_FLOW:
2532 case ESP_V4_FLOW:
2533 case IPV4_FLOW:
2534 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2535 break;
2536 case TCP_V6_FLOW:
2537 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
Carolyn Wybornyb26141d2014-04-17 04:10:13 +00002538 /* Fall through */
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002539 case UDP_V6_FLOW:
2540 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
2541 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
Carolyn Wybornyb26141d2014-04-17 04:10:13 +00002542 /* Fall through */
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002543 case SCTP_V6_FLOW:
2544 case AH_ESP_V6_FLOW:
2545 case AH_V6_FLOW:
2546 case ESP_V6_FLOW:
2547 case IPV6_FLOW:
2548 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2549 break;
2550 default:
2551 return -EINVAL;
2552 }
2553
2554 return 0;
2555}
2556
2557static int igb_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
Jeff Kirsherb980ac12013-02-23 07:29:56 +00002558 u32 *rule_locs)
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002559{
2560 struct igb_adapter *adapter = netdev_priv(dev);
2561 int ret = -EOPNOTSUPP;
2562
2563 switch (cmd->cmd) {
2564 case ETHTOOL_GRXRINGS:
2565 cmd->data = adapter->num_rx_queues;
2566 ret = 0;
2567 break;
Gangfeng Huang0e71def2016-07-06 13:22:54 +08002568 case ETHTOOL_GRXCLSRLCNT:
2569 cmd->rule_cnt = adapter->nfc_filter_count;
2570 ret = 0;
2571 break;
2572 case ETHTOOL_GRXCLSRULE:
2573 ret = igb_get_ethtool_nfc_entry(adapter, cmd);
2574 break;
2575 case ETHTOOL_GRXCLSRLALL:
2576 ret = igb_get_ethtool_nfc_all(adapter, cmd, rule_locs);
2577 break;
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002578 case ETHTOOL_GRXFH:
2579 ret = igb_get_rss_hash_opts(adapter, cmd);
2580 break;
2581 default:
2582 break;
2583 }
2584
2585 return ret;
2586}
2587
2588#define UDP_RSS_FLAGS (IGB_FLAG_RSS_FIELD_IPV4_UDP | \
2589 IGB_FLAG_RSS_FIELD_IPV6_UDP)
2590static int igb_set_rss_hash_opt(struct igb_adapter *adapter,
2591 struct ethtool_rxnfc *nfc)
2592{
2593 u32 flags = adapter->flags;
2594
2595 /* RSS does not support anything other than hashing
2596 * to queues on src and dst IPs and ports
2597 */
2598 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2599 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2600 return -EINVAL;
2601
2602 switch (nfc->flow_type) {
2603 case TCP_V4_FLOW:
2604 case TCP_V6_FLOW:
2605 if (!(nfc->data & RXH_IP_SRC) ||
2606 !(nfc->data & RXH_IP_DST) ||
2607 !(nfc->data & RXH_L4_B_0_1) ||
2608 !(nfc->data & RXH_L4_B_2_3))
2609 return -EINVAL;
2610 break;
2611 case UDP_V4_FLOW:
2612 if (!(nfc->data & RXH_IP_SRC) ||
2613 !(nfc->data & RXH_IP_DST))
2614 return -EINVAL;
2615 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2616 case 0:
2617 flags &= ~IGB_FLAG_RSS_FIELD_IPV4_UDP;
2618 break;
2619 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2620 flags |= IGB_FLAG_RSS_FIELD_IPV4_UDP;
2621 break;
2622 default:
2623 return -EINVAL;
2624 }
2625 break;
2626 case UDP_V6_FLOW:
2627 if (!(nfc->data & RXH_IP_SRC) ||
2628 !(nfc->data & RXH_IP_DST))
2629 return -EINVAL;
2630 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2631 case 0:
2632 flags &= ~IGB_FLAG_RSS_FIELD_IPV6_UDP;
2633 break;
2634 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2635 flags |= IGB_FLAG_RSS_FIELD_IPV6_UDP;
2636 break;
2637 default:
2638 return -EINVAL;
2639 }
2640 break;
2641 case AH_ESP_V4_FLOW:
2642 case AH_V4_FLOW:
2643 case ESP_V4_FLOW:
2644 case SCTP_V4_FLOW:
2645 case AH_ESP_V6_FLOW:
2646 case AH_V6_FLOW:
2647 case ESP_V6_FLOW:
2648 case SCTP_V6_FLOW:
2649 if (!(nfc->data & RXH_IP_SRC) ||
2650 !(nfc->data & RXH_IP_DST) ||
2651 (nfc->data & RXH_L4_B_0_1) ||
2652 (nfc->data & RXH_L4_B_2_3))
2653 return -EINVAL;
2654 break;
2655 default:
2656 return -EINVAL;
2657 }
2658
2659 /* if we changed something we need to update flags */
2660 if (flags != adapter->flags) {
2661 struct e1000_hw *hw = &adapter->hw;
2662 u32 mrqc = rd32(E1000_MRQC);
2663
2664 if ((flags & UDP_RSS_FLAGS) &&
2665 !(adapter->flags & UDP_RSS_FLAGS))
2666 dev_err(&adapter->pdev->dev,
2667 "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
2668
2669 adapter->flags = flags;
2670
2671 /* Perform hash on these packet types */
2672 mrqc |= E1000_MRQC_RSS_FIELD_IPV4 |
2673 E1000_MRQC_RSS_FIELD_IPV4_TCP |
2674 E1000_MRQC_RSS_FIELD_IPV6 |
2675 E1000_MRQC_RSS_FIELD_IPV6_TCP;
2676
2677 mrqc &= ~(E1000_MRQC_RSS_FIELD_IPV4_UDP |
2678 E1000_MRQC_RSS_FIELD_IPV6_UDP);
2679
2680 if (flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
2681 mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
2682
2683 if (flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
2684 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
2685
2686 wr32(E1000_MRQC, mrqc);
2687 }
2688
2689 return 0;
2690}
2691
Gangfeng Huang64c75d42016-07-06 13:22:55 +08002692static int igb_rxnfc_write_etype_filter(struct igb_adapter *adapter,
2693 struct igb_nfc_filter *input)
2694{
2695 struct e1000_hw *hw = &adapter->hw;
2696 u8 i;
2697 u32 etqf;
2698 u16 etype;
2699
2700 /* find an empty etype filter register */
2701 for (i = 0; i < MAX_ETYPE_FILTER; ++i) {
2702 if (!adapter->etype_bitmap[i])
2703 break;
2704 }
2705 if (i == MAX_ETYPE_FILTER) {
2706 dev_err(&adapter->pdev->dev, "ethtool -N: etype filters are all used.\n");
2707 return -EINVAL;
2708 }
2709
2710 adapter->etype_bitmap[i] = true;
2711
2712 etqf = rd32(E1000_ETQF(i));
2713 etype = ntohs(input->filter.etype & ETHER_TYPE_FULL_MASK);
2714
2715 etqf |= E1000_ETQF_FILTER_ENABLE;
2716 etqf &= ~E1000_ETQF_ETYPE_MASK;
2717 etqf |= (etype & E1000_ETQF_ETYPE_MASK);
2718
2719 etqf &= ~E1000_ETQF_QUEUE_MASK;
2720 etqf |= ((input->action << E1000_ETQF_QUEUE_SHIFT)
2721 & E1000_ETQF_QUEUE_MASK);
2722 etqf |= E1000_ETQF_QUEUE_ENABLE;
2723
2724 wr32(E1000_ETQF(i), etqf);
2725
2726 input->etype_reg_index = i;
2727
2728 return 0;
2729}
2730
Wei Yongjun7a823472016-08-23 15:08:09 +00002731static int igb_rxnfc_write_vlan_prio_filter(struct igb_adapter *adapter,
2732 struct igb_nfc_filter *input)
Gangfeng Huang7a277a92016-07-06 13:22:56 +08002733{
2734 struct e1000_hw *hw = &adapter->hw;
2735 u8 vlan_priority;
2736 u16 queue_index;
2737 u32 vlapqf;
2738
2739 vlapqf = rd32(E1000_VLAPQF);
2740 vlan_priority = (ntohs(input->filter.vlan_tci) & VLAN_PRIO_MASK)
2741 >> VLAN_PRIO_SHIFT;
2742 queue_index = (vlapqf >> (vlan_priority * 4)) & E1000_VLAPQF_QUEUE_MASK;
2743
2744 /* check whether this vlan prio is already set */
2745 if ((vlapqf & E1000_VLAPQF_P_VALID(vlan_priority)) &&
2746 (queue_index != input->action)) {
2747 dev_err(&adapter->pdev->dev, "ethtool rxnfc set vlan prio filter failed.\n");
2748 return -EEXIST;
2749 }
2750
2751 vlapqf |= E1000_VLAPQF_P_VALID(vlan_priority);
2752 vlapqf |= E1000_VLAPQF_QUEUE_SEL(vlan_priority, input->action);
2753
2754 wr32(E1000_VLAPQF, vlapqf);
2755
2756 return 0;
2757}
2758
Gangfeng Huang0e71def2016-07-06 13:22:54 +08002759int igb_add_filter(struct igb_adapter *adapter, struct igb_nfc_filter *input)
2760{
Gangfeng Huang64c75d42016-07-06 13:22:55 +08002761 int err = -EINVAL;
2762
Gangfeng Huang7a277a92016-07-06 13:22:56 +08002763 if (input->filter.match_flags & IGB_FILTER_FLAG_ETHER_TYPE) {
Gangfeng Huang64c75d42016-07-06 13:22:55 +08002764 err = igb_rxnfc_write_etype_filter(adapter, input);
Gangfeng Huang7a277a92016-07-06 13:22:56 +08002765 if (err)
2766 return err;
2767 }
2768
2769 if (input->filter.match_flags & IGB_FILTER_FLAG_VLAN_TCI)
2770 err = igb_rxnfc_write_vlan_prio_filter(adapter, input);
Gangfeng Huang64c75d42016-07-06 13:22:55 +08002771
2772 return err;
2773}
2774
2775static void igb_clear_etype_filter_regs(struct igb_adapter *adapter,
2776 u16 reg_index)
2777{
2778 struct e1000_hw *hw = &adapter->hw;
2779 u32 etqf = rd32(E1000_ETQF(reg_index));
2780
2781 etqf &= ~E1000_ETQF_QUEUE_ENABLE;
2782 etqf &= ~E1000_ETQF_QUEUE_MASK;
2783 etqf &= ~E1000_ETQF_FILTER_ENABLE;
2784
2785 wr32(E1000_ETQF(reg_index), etqf);
2786
2787 adapter->etype_bitmap[reg_index] = false;
Gangfeng Huang0e71def2016-07-06 13:22:54 +08002788}
2789
Gangfeng Huang7a277a92016-07-06 13:22:56 +08002790static void igb_clear_vlan_prio_filter(struct igb_adapter *adapter,
2791 u16 vlan_tci)
2792{
2793 struct e1000_hw *hw = &adapter->hw;
2794 u8 vlan_priority;
2795 u32 vlapqf;
2796
2797 vlan_priority = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
2798
2799 vlapqf = rd32(E1000_VLAPQF);
2800 vlapqf &= ~E1000_VLAPQF_P_VALID(vlan_priority);
2801 vlapqf &= ~E1000_VLAPQF_QUEUE_SEL(vlan_priority,
2802 E1000_VLAPQF_QUEUE_MASK);
2803
2804 wr32(E1000_VLAPQF, vlapqf);
2805}
2806
Gangfeng Huang0e71def2016-07-06 13:22:54 +08002807int igb_erase_filter(struct igb_adapter *adapter, struct igb_nfc_filter *input)
2808{
Gangfeng Huang64c75d42016-07-06 13:22:55 +08002809 if (input->filter.match_flags & IGB_FILTER_FLAG_ETHER_TYPE)
2810 igb_clear_etype_filter_regs(adapter,
2811 input->etype_reg_index);
Gangfeng Huang7a277a92016-07-06 13:22:56 +08002812
2813 if (input->filter.match_flags & IGB_FILTER_FLAG_VLAN_TCI)
2814 igb_clear_vlan_prio_filter(adapter,
2815 ntohs(input->filter.vlan_tci));
2816
Gangfeng Huang0e71def2016-07-06 13:22:54 +08002817 return 0;
2818}
2819
2820static int igb_update_ethtool_nfc_entry(struct igb_adapter *adapter,
2821 struct igb_nfc_filter *input,
2822 u16 sw_idx)
2823{
2824 struct igb_nfc_filter *rule, *parent;
2825 int err = -EINVAL;
2826
2827 parent = NULL;
2828 rule = NULL;
2829
2830 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node) {
2831 /* hash found, or no matching entry */
2832 if (rule->sw_idx >= sw_idx)
2833 break;
2834 parent = rule;
2835 }
2836
2837 /* if there is an old rule occupying our place remove it */
2838 if (rule && (rule->sw_idx == sw_idx)) {
2839 if (!input)
2840 err = igb_erase_filter(adapter, rule);
2841
2842 hlist_del(&rule->nfc_node);
2843 kfree(rule);
2844 adapter->nfc_filter_count--;
2845 }
2846
2847 /* If no input this was a delete, err should be 0 if a rule was
2848 * successfully found and removed from the list else -EINVAL
2849 */
2850 if (!input)
2851 return err;
2852
2853 /* initialize node */
2854 INIT_HLIST_NODE(&input->nfc_node);
2855
2856 /* add filter to the list */
2857 if (parent)
2858 hlist_add_behind(&parent->nfc_node, &input->nfc_node);
2859 else
2860 hlist_add_head(&input->nfc_node, &adapter->nfc_filter_list);
2861
2862 /* update counts */
2863 adapter->nfc_filter_count++;
2864
2865 return 0;
2866}
2867
2868static int igb_add_ethtool_nfc_entry(struct igb_adapter *adapter,
2869 struct ethtool_rxnfc *cmd)
2870{
2871 struct net_device *netdev = adapter->netdev;
2872 struct ethtool_rx_flow_spec *fsp =
2873 (struct ethtool_rx_flow_spec *)&cmd->fs;
2874 struct igb_nfc_filter *input, *rule;
2875 int err = 0;
2876
2877 if (!(netdev->hw_features & NETIF_F_NTUPLE))
Gangfeng Huang54be8132016-07-06 13:22:57 +08002878 return -EOPNOTSUPP;
Gangfeng Huang0e71def2016-07-06 13:22:54 +08002879
2880 /* Don't allow programming if the action is a queue greater than
2881 * the number of online Rx queues.
2882 */
2883 if ((fsp->ring_cookie == RX_CLS_FLOW_DISC) ||
2884 (fsp->ring_cookie >= adapter->num_rx_queues)) {
2885 dev_err(&adapter->pdev->dev, "ethtool -N: The specified action is invalid\n");
2886 return -EINVAL;
2887 }
2888
2889 /* Don't allow indexes to exist outside of available space */
2890 if (fsp->location >= IGB_MAX_RXNFC_FILTERS) {
2891 dev_err(&adapter->pdev->dev, "Location out of range\n");
2892 return -EINVAL;
2893 }
2894
2895 if ((fsp->flow_type & ~FLOW_EXT) != ETHER_FLOW)
2896 return -EINVAL;
2897
Gangfeng Huang7a277a92016-07-06 13:22:56 +08002898 if (fsp->m_u.ether_spec.h_proto != ETHER_TYPE_FULL_MASK &&
2899 fsp->m_ext.vlan_tci != htons(VLAN_PRIO_MASK))
Gangfeng Huang64c75d42016-07-06 13:22:55 +08002900 return -EINVAL;
2901
Gangfeng Huang0e71def2016-07-06 13:22:54 +08002902 input = kzalloc(sizeof(*input), GFP_KERNEL);
2903 if (!input)
2904 return -ENOMEM;
2905
Gangfeng Huang7a277a92016-07-06 13:22:56 +08002906 if (fsp->m_u.ether_spec.h_proto == ETHER_TYPE_FULL_MASK) {
2907 input->filter.etype = fsp->h_u.ether_spec.h_proto;
2908 input->filter.match_flags = IGB_FILTER_FLAG_ETHER_TYPE;
2909 }
2910
2911 if ((fsp->flow_type & FLOW_EXT) && fsp->m_ext.vlan_tci) {
2912 if (fsp->m_ext.vlan_tci != htons(VLAN_PRIO_MASK)) {
2913 err = -EINVAL;
2914 goto err_out;
2915 }
2916 input->filter.vlan_tci = fsp->h_ext.vlan_tci;
2917 input->filter.match_flags |= IGB_FILTER_FLAG_VLAN_TCI;
2918 }
2919
Gangfeng Huang0e71def2016-07-06 13:22:54 +08002920 input->action = fsp->ring_cookie;
2921 input->sw_idx = fsp->location;
2922
2923 spin_lock(&adapter->nfc_lock);
2924
2925 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node) {
2926 if (!memcmp(&input->filter, &rule->filter,
2927 sizeof(input->filter))) {
2928 err = -EEXIST;
2929 dev_err(&adapter->pdev->dev,
2930 "ethtool: this filter is already set\n");
2931 goto err_out_w_lock;
2932 }
2933 }
2934
2935 err = igb_add_filter(adapter, input);
2936 if (err)
2937 goto err_out_w_lock;
2938
2939 igb_update_ethtool_nfc_entry(adapter, input, input->sw_idx);
2940
2941 spin_unlock(&adapter->nfc_lock);
2942 return 0;
2943
2944err_out_w_lock:
2945 spin_unlock(&adapter->nfc_lock);
Gangfeng Huang7a277a92016-07-06 13:22:56 +08002946err_out:
Gangfeng Huang0e71def2016-07-06 13:22:54 +08002947 kfree(input);
2948 return err;
2949}
2950
2951static int igb_del_ethtool_nfc_entry(struct igb_adapter *adapter,
2952 struct ethtool_rxnfc *cmd)
2953{
2954 struct ethtool_rx_flow_spec *fsp =
2955 (struct ethtool_rx_flow_spec *)&cmd->fs;
2956 int err;
2957
2958 spin_lock(&adapter->nfc_lock);
2959 err = igb_update_ethtool_nfc_entry(adapter, NULL, fsp->location);
2960 spin_unlock(&adapter->nfc_lock);
2961
2962 return err;
2963}
2964
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002965static int igb_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
2966{
2967 struct igb_adapter *adapter = netdev_priv(dev);
2968 int ret = -EOPNOTSUPP;
2969
2970 switch (cmd->cmd) {
2971 case ETHTOOL_SRXFH:
2972 ret = igb_set_rss_hash_opt(adapter, cmd);
2973 break;
Gangfeng Huang0e71def2016-07-06 13:22:54 +08002974 case ETHTOOL_SRXCLSRLINS:
2975 ret = igb_add_ethtool_nfc_entry(adapter, cmd);
2976 break;
2977 case ETHTOOL_SRXCLSRLDEL:
2978 ret = igb_del_ethtool_nfc_entry(adapter, cmd);
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002979 default:
2980 break;
2981 }
2982
2983 return ret;
2984}
2985
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002986static int igb_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
2987{
2988 struct igb_adapter *adapter = netdev_priv(netdev);
2989 struct e1000_hw *hw = &adapter->hw;
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002990 u32 ret_val;
Matthew Vick87371b92013-02-21 03:32:52 +00002991 u16 phy_data;
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00002992
2993 if ((hw->mac.type < e1000_i350) ||
2994 (hw->phy.media_type != e1000_media_type_copper))
2995 return -EOPNOTSUPP;
2996
2997 edata->supported = (SUPPORTED_1000baseT_Full |
2998 SUPPORTED_100baseT_Full);
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00002999 if (!hw->dev_spec._82575.eee_disable)
3000 edata->advertised =
3001 mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003002
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00003003 /* The IPCNFG and EEER registers are not supported on I354. */
3004 if (hw->mac.type == e1000_i354) {
3005 igb_get_eee_status_i354(hw, (bool *)&edata->eee_active);
3006 } else {
3007 u32 eeer;
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003008
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00003009 eeer = rd32(E1000_EEER);
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003010
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00003011 /* EEE status on negotiated link */
3012 if (eeer & E1000_EEER_EEE_NEG)
3013 edata->eee_active = true;
3014
3015 if (eeer & E1000_EEER_TX_LPI_EN)
3016 edata->tx_lpi_enabled = true;
3017 }
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003018
Matthew Vick87371b92013-02-21 03:32:52 +00003019 /* EEE Link Partner Advertised */
3020 switch (hw->mac.type) {
3021 case e1000_i350:
3022 ret_val = igb_read_emi_reg(hw, E1000_EEE_LP_ADV_ADDR_I350,
3023 &phy_data);
3024 if (ret_val)
3025 return -ENODATA;
3026
3027 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
Matthew Vick87371b92013-02-21 03:32:52 +00003028 break;
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00003029 case e1000_i354:
Matthew Vick87371b92013-02-21 03:32:52 +00003030 case e1000_i210:
3031 case e1000_i211:
3032 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_LP_ADV_ADDR_I210,
3033 E1000_EEE_LP_ADV_DEV_I210,
3034 &phy_data);
3035 if (ret_val)
3036 return -ENODATA;
3037
3038 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
3039
3040 break;
3041 default:
3042 break;
3043 }
3044
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003045 edata->eee_enabled = !hw->dev_spec._82575.eee_disable;
3046
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00003047 if ((hw->mac.type == e1000_i354) &&
3048 (edata->eee_enabled))
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003049 edata->tx_lpi_enabled = true;
3050
3051 /* Report correct negotiated EEE status for devices that
3052 * wrongly report EEE at half-duplex
3053 */
3054 if (adapter->link_duplex == HALF_DUPLEX) {
3055 edata->eee_enabled = false;
3056 edata->eee_active = false;
3057 edata->tx_lpi_enabled = false;
3058 edata->advertised &= ~edata->advertised;
3059 }
3060
3061 return 0;
3062}
3063
3064static int igb_set_eee(struct net_device *netdev,
3065 struct ethtool_eee *edata)
3066{
3067 struct igb_adapter *adapter = netdev_priv(netdev);
3068 struct e1000_hw *hw = &adapter->hw;
3069 struct ethtool_eee eee_curr;
Todd Fujinakac4c112f2014-08-29 06:43:13 +00003070 bool adv1g_eee = true, adv100m_eee = true;
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003071 s32 ret_val;
3072
3073 if ((hw->mac.type < e1000_i350) ||
3074 (hw->phy.media_type != e1000_media_type_copper))
3075 return -EOPNOTSUPP;
3076
Andi Kleen58e4e1f2013-09-30 13:29:08 -07003077 memset(&eee_curr, 0, sizeof(struct ethtool_eee));
3078
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003079 ret_val = igb_get_eee(netdev, &eee_curr);
3080 if (ret_val)
3081 return ret_val;
3082
3083 if (eee_curr.eee_enabled) {
3084 if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
3085 dev_err(&adapter->pdev->dev,
3086 "Setting EEE tx-lpi is not supported\n");
3087 return -EINVAL;
3088 }
3089
3090 /* Tx LPI timer is not implemented currently */
3091 if (edata->tx_lpi_timer) {
3092 dev_err(&adapter->pdev->dev,
3093 "Setting EEE Tx LPI timer is not supported\n");
3094 return -EINVAL;
3095 }
3096
Todd Fujinakac4c112f2014-08-29 06:43:13 +00003097 if (!edata->advertised || (edata->advertised &
3098 ~(ADVERTISE_100_FULL | ADVERTISE_1000_FULL))) {
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003099 dev_err(&adapter->pdev->dev,
Todd Fujinakac4c112f2014-08-29 06:43:13 +00003100 "EEE Advertisement supports only 100Tx and/or 100T full duplex\n");
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003101 return -EINVAL;
3102 }
Todd Fujinakac4c112f2014-08-29 06:43:13 +00003103 adv100m_eee = !!(edata->advertised & ADVERTISE_100_FULL);
3104 adv1g_eee = !!(edata->advertised & ADVERTISE_1000_FULL);
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003105
3106 } else if (!edata->eee_enabled) {
3107 dev_err(&adapter->pdev->dev,
3108 "Setting EEE options are not supported with EEE disabled\n");
3109 return -EINVAL;
3110 }
3111
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00003112 adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003113 if (hw->dev_spec._82575.eee_disable != !edata->eee_enabled) {
3114 hw->dev_spec._82575.eee_disable = !edata->eee_enabled;
Carolyn Wybornyf4c01e92014-03-12 03:58:22 +00003115 adapter->flags |= IGB_FLAG_EEE;
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003116
3117 /* reset link */
Akeem G Abodunrin8a650aa2013-05-24 07:20:57 +00003118 if (netif_running(netdev))
3119 igb_reinit_locked(adapter);
3120 else
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003121 igb_reset(adapter);
3122 }
3123
Todd Fujinakac4c112f2014-08-29 06:43:13 +00003124 if (hw->mac.type == e1000_i354)
3125 ret_val = igb_set_eee_i354(hw, adv1g_eee, adv100m_eee);
3126 else
3127 ret_val = igb_set_eee_i350(hw, adv1g_eee, adv100m_eee);
3128
3129 if (ret_val) {
3130 dev_err(&adapter->pdev->dev,
3131 "Problem setting EEE advertisement options\n");
3132 return -EINVAL;
3133 }
3134
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003135 return 0;
3136}
3137
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00003138static int igb_get_module_info(struct net_device *netdev,
3139 struct ethtool_modinfo *modinfo)
3140{
3141 struct igb_adapter *adapter = netdev_priv(netdev);
3142 struct e1000_hw *hw = &adapter->hw;
Todd Fujinaka23d87822014-06-04 07:12:15 +00003143 u32 status = 0;
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00003144 u16 sff8472_rev, addr_mode;
3145 bool page_swap = false;
3146
3147 if ((hw->phy.media_type == e1000_media_type_copper) ||
3148 (hw->phy.media_type == e1000_media_type_unknown))
3149 return -EOPNOTSUPP;
3150
3151 /* Check whether we support SFF-8472 or not */
3152 status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_COMP, &sff8472_rev);
Todd Fujinaka23d87822014-06-04 07:12:15 +00003153 if (status)
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00003154 return -EIO;
3155
3156 /* addressing mode is not supported */
3157 status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_SWAP, &addr_mode);
Todd Fujinaka23d87822014-06-04 07:12:15 +00003158 if (status)
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00003159 return -EIO;
3160
3161 /* addressing mode is not supported */
3162 if ((addr_mode & 0xFF) & IGB_SFF_ADDRESSING_MODE) {
3163 hw_dbg("Address change required to access page 0xA2, but not supported. Please report the module type to the driver maintainers.\n");
3164 page_swap = true;
3165 }
3166
3167 if ((sff8472_rev & 0xFF) == IGB_SFF_8472_UNSUP || page_swap) {
3168 /* We have an SFP, but it does not support SFF-8472 */
3169 modinfo->type = ETH_MODULE_SFF_8079;
3170 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
3171 } else {
3172 /* We have an SFP which supports a revision of SFF-8472 */
3173 modinfo->type = ETH_MODULE_SFF_8472;
3174 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
3175 }
3176
3177 return 0;
3178}
3179
3180static int igb_get_module_eeprom(struct net_device *netdev,
3181 struct ethtool_eeprom *ee, u8 *data)
3182{
3183 struct igb_adapter *adapter = netdev_priv(netdev);
3184 struct e1000_hw *hw = &adapter->hw;
Todd Fujinaka23d87822014-06-04 07:12:15 +00003185 u32 status = 0;
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00003186 u16 *dataword;
3187 u16 first_word, last_word;
3188 int i = 0;
3189
3190 if (ee->len == 0)
3191 return -EINVAL;
3192
3193 first_word = ee->offset >> 1;
3194 last_word = (ee->offset + ee->len - 1) >> 1;
3195
3196 dataword = kmalloc(sizeof(u16) * (last_word - first_word + 1),
3197 GFP_KERNEL);
3198 if (!dataword)
3199 return -ENOMEM;
3200
3201 /* Read EEPROM block, SFF-8079/SFF-8472, word at a time */
3202 for (i = 0; i < last_word - first_word + 1; i++) {
Doron Shikmoniefea95d2016-02-17 09:34:25 +02003203 status = igb_read_phy_reg_i2c(hw, (first_word + i) * 2,
3204 &dataword[i]);
Todd Fujinaka23d87822014-06-04 07:12:15 +00003205 if (status) {
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00003206 /* Error occurred while reading module */
Christian Engelmayerdb41b872014-03-21 03:25:30 -07003207 kfree(dataword);
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00003208 return -EIO;
Christian Engelmayerdb41b872014-03-21 03:25:30 -07003209 }
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00003210
3211 be16_to_cpus(&dataword[i]);
3212 }
3213
3214 memcpy(data, (u8 *)dataword + (ee->offset & 1), ee->len);
3215 kfree(dataword);
3216
3217 return 0;
3218}
3219
Matthew Vicka79f4f82012-08-10 05:40:44 +00003220static int igb_ethtool_begin(struct net_device *netdev)
3221{
3222 struct igb_adapter *adapter = netdev_priv(netdev);
3223 pm_runtime_get_sync(&adapter->pdev->dev);
3224 return 0;
3225}
3226
3227static void igb_ethtool_complete(struct net_device *netdev)
3228{
3229 struct igb_adapter *adapter = netdev_priv(netdev);
3230 pm_runtime_put(&adapter->pdev->dev);
3231}
3232
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00003233static u32 igb_get_rxfh_indir_size(struct net_device *netdev)
3234{
3235 return IGB_RETA_SIZE;
3236}
3237
Eyal Perry892311f2014-12-02 18:12:10 +02003238static int igb_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
3239 u8 *hfunc)
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00003240{
3241 struct igb_adapter *adapter = netdev_priv(netdev);
3242 int i;
3243
Eyal Perry892311f2014-12-02 18:12:10 +02003244 if (hfunc)
3245 *hfunc = ETH_RSS_HASH_TOP;
3246 if (!indir)
3247 return 0;
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00003248 for (i = 0; i < IGB_RETA_SIZE; i++)
3249 indir[i] = adapter->rss_indir_tbl[i];
3250
3251 return 0;
3252}
3253
3254void igb_write_rss_indir_tbl(struct igb_adapter *adapter)
3255{
3256 struct e1000_hw *hw = &adapter->hw;
3257 u32 reg = E1000_RETA(0);
3258 u32 shift = 0;
3259 int i = 0;
3260
3261 switch (hw->mac.type) {
3262 case e1000_82575:
3263 shift = 6;
3264 break;
3265 case e1000_82576:
3266 /* 82576 supports 2 RSS queues for SR-IOV */
3267 if (adapter->vfs_allocated_count)
3268 shift = 3;
3269 break;
3270 default:
3271 break;
3272 }
3273
3274 while (i < IGB_RETA_SIZE) {
3275 u32 val = 0;
3276 int j;
3277
3278 for (j = 3; j >= 0; j--) {
3279 val <<= 8;
3280 val |= adapter->rss_indir_tbl[i + j];
3281 }
3282
3283 wr32(reg, val << shift);
3284 reg += 4;
3285 i += 4;
3286 }
3287}
3288
Ben Hutchingsfe62d002014-05-15 01:25:27 +01003289static int igb_set_rxfh(struct net_device *netdev, const u32 *indir,
Eyal Perry892311f2014-12-02 18:12:10 +02003290 const u8 *key, const u8 hfunc)
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00003291{
3292 struct igb_adapter *adapter = netdev_priv(netdev);
3293 struct e1000_hw *hw = &adapter->hw;
3294 int i;
3295 u32 num_queues;
3296
Eyal Perry892311f2014-12-02 18:12:10 +02003297 /* We do not allow change in unsupported parameters */
3298 if (key ||
3299 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
3300 return -EOPNOTSUPP;
3301 if (!indir)
3302 return 0;
3303
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00003304 num_queues = adapter->rss_queues;
3305
3306 switch (hw->mac.type) {
3307 case e1000_82576:
3308 /* 82576 supports 2 RSS queues for SR-IOV */
3309 if (adapter->vfs_allocated_count)
3310 num_queues = 2;
3311 break;
3312 default:
3313 break;
3314 }
3315
3316 /* Verify user input. */
3317 for (i = 0; i < IGB_RETA_SIZE; i++)
3318 if (indir[i] >= num_queues)
3319 return -EINVAL;
3320
3321
3322 for (i = 0; i < IGB_RETA_SIZE; i++)
3323 adapter->rss_indir_tbl[i] = indir[i];
3324
3325 igb_write_rss_indir_tbl(adapter);
3326
3327 return 0;
3328}
3329
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07003330static unsigned int igb_max_channels(struct igb_adapter *adapter)
3331{
3332 struct e1000_hw *hw = &adapter->hw;
3333 unsigned int max_combined = 0;
3334
3335 switch (hw->mac.type) {
3336 case e1000_i211:
3337 max_combined = IGB_MAX_RX_QUEUES_I211;
3338 break;
3339 case e1000_82575:
3340 case e1000_i210:
3341 max_combined = IGB_MAX_RX_QUEUES_82575;
3342 break;
3343 case e1000_i350:
3344 if (!!adapter->vfs_allocated_count) {
3345 max_combined = 1;
3346 break;
3347 }
3348 /* fall through */
3349 case e1000_82576:
3350 if (!!adapter->vfs_allocated_count) {
3351 max_combined = 2;
3352 break;
3353 }
3354 /* fall through */
3355 case e1000_82580:
3356 case e1000_i354:
3357 default:
3358 max_combined = IGB_MAX_RX_QUEUES;
3359 break;
3360 }
3361
3362 return max_combined;
3363}
3364
3365static void igb_get_channels(struct net_device *netdev,
3366 struct ethtool_channels *ch)
3367{
3368 struct igb_adapter *adapter = netdev_priv(netdev);
3369
3370 /* Report maximum channels */
3371 ch->max_combined = igb_max_channels(adapter);
3372
3373 /* Report info for other vector */
Carolyn Wybornycd14ef52013-12-10 07:58:34 +00003374 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07003375 ch->max_other = NON_Q_VECTORS;
3376 ch->other_count = NON_Q_VECTORS;
3377 }
3378
3379 ch->combined_count = adapter->rss_queues;
3380}
3381
3382static int igb_set_channels(struct net_device *netdev,
3383 struct ethtool_channels *ch)
3384{
3385 struct igb_adapter *adapter = netdev_priv(netdev);
3386 unsigned int count = ch->combined_count;
Shota Suzuki72ddef02015-07-01 09:25:52 +09003387 unsigned int max_combined = 0;
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07003388
3389 /* Verify they are not requesting separate vectors */
3390 if (!count || ch->rx_count || ch->tx_count)
3391 return -EINVAL;
3392
3393 /* Verify other_count is valid and has not been changed */
3394 if (ch->other_count != NON_Q_VECTORS)
3395 return -EINVAL;
3396
3397 /* Verify the number of channels doesn't exceed hw limits */
Shota Suzuki72ddef02015-07-01 09:25:52 +09003398 max_combined = igb_max_channels(adapter);
3399 if (count > max_combined)
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07003400 return -EINVAL;
3401
3402 if (count != adapter->rss_queues) {
3403 adapter->rss_queues = count;
Shota Suzuki72ddef02015-07-01 09:25:52 +09003404 igb_set_flag_queue_pairs(adapter, max_combined);
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07003405
3406 /* Hardware has to reinitialize queues and interrupts to
3407 * match the new configuration.
3408 */
3409 return igb_reinit_queues(adapter);
3410 }
3411
3412 return 0;
3413}
3414
Alexander Duycke0891292017-02-06 18:26:52 -08003415static u32 igb_get_priv_flags(struct net_device *netdev)
3416{
3417 struct igb_adapter *adapter = netdev_priv(netdev);
3418 u32 priv_flags = 0;
3419
3420 if (adapter->flags & IGB_FLAG_RX_LEGACY)
3421 priv_flags |= IGB_PRIV_FLAGS_LEGACY_RX;
3422
3423 return priv_flags;
3424}
3425
3426static int igb_set_priv_flags(struct net_device *netdev, u32 priv_flags)
3427{
3428 struct igb_adapter *adapter = netdev_priv(netdev);
3429 unsigned int flags = adapter->flags;
3430
3431 flags &= ~IGB_FLAG_RX_LEGACY;
3432 if (priv_flags & IGB_PRIV_FLAGS_LEGACY_RX)
3433 flags |= IGB_FLAG_RX_LEGACY;
3434
3435 if (flags != adapter->flags) {
3436 adapter->flags = flags;
3437
3438 /* reset interface to repopulate queues */
3439 if (netif_running(netdev))
3440 igb_reinit_locked(adapter);
3441 }
3442
3443 return 0;
3444}
3445
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07003446static const struct ethtool_ops igb_ethtool_ops = {
Jeff Kirsherb980ac12013-02-23 07:29:56 +00003447 .get_settings = igb_get_settings,
3448 .set_settings = igb_set_settings,
3449 .get_drvinfo = igb_get_drvinfo,
3450 .get_regs_len = igb_get_regs_len,
3451 .get_regs = igb_get_regs,
3452 .get_wol = igb_get_wol,
3453 .set_wol = igb_set_wol,
3454 .get_msglevel = igb_get_msglevel,
3455 .set_msglevel = igb_set_msglevel,
3456 .nway_reset = igb_nway_reset,
3457 .get_link = igb_get_link,
3458 .get_eeprom_len = igb_get_eeprom_len,
3459 .get_eeprom = igb_get_eeprom,
3460 .set_eeprom = igb_set_eeprom,
3461 .get_ringparam = igb_get_ringparam,
3462 .set_ringparam = igb_set_ringparam,
3463 .get_pauseparam = igb_get_pauseparam,
3464 .set_pauseparam = igb_set_pauseparam,
3465 .self_test = igb_diag_test,
3466 .get_strings = igb_get_strings,
3467 .set_phys_id = igb_set_phys_id,
3468 .get_sset_count = igb_get_sset_count,
3469 .get_ethtool_stats = igb_get_ethtool_stats,
3470 .get_coalesce = igb_get_coalesce,
3471 .set_coalesce = igb_set_coalesce,
3472 .get_ts_info = igb_get_ts_info,
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00003473 .get_rxnfc = igb_get_rxnfc,
3474 .set_rxnfc = igb_set_rxnfc,
Akeem G. Abodunrin24a372c2012-11-13 04:03:25 +00003475 .get_eee = igb_get_eee,
3476 .set_eee = igb_set_eee,
Akeem G. Abodunrinf69aa392013-04-11 06:36:35 +00003477 .get_module_info = igb_get_module_info,
3478 .get_module_eeprom = igb_get_module_eeprom,
Laura Mihaela Vasilescued12cc92013-07-31 20:19:54 +00003479 .get_rxfh_indir_size = igb_get_rxfh_indir_size,
Ben Hutchingsfe62d002014-05-15 01:25:27 +01003480 .get_rxfh = igb_get_rxfh,
3481 .set_rxfh = igb_set_rxfh,
Laura Mihaela Vasilescu907b7832013-10-01 04:33:56 -07003482 .get_channels = igb_get_channels,
3483 .set_channels = igb_set_channels,
Alexander Duycke0891292017-02-06 18:26:52 -08003484 .get_priv_flags = igb_get_priv_flags,
3485 .set_priv_flags = igb_set_priv_flags,
Yan, Zheng749ab2c2012-01-04 20:23:37 +00003486 .begin = igb_ethtool_begin,
3487 .complete = igb_ethtool_complete,
Auke Kok9d5c8242008-01-24 02:22:38 -08003488};
3489
3490void igb_set_ethtool_ops(struct net_device *netdev)
3491{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003492 netdev->ethtool_ops = &igb_ethtool_ops;
Auke Kok9d5c8242008-01-24 02:22:38 -08003493}