gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / net / ethernet / intel / igc / igc_ethtool.c
blobf530fc29b074a189fd3e3cf35173ad593594aed1
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018 Intel Corporation */
4 /* ethtool support for igc */
5 #include <linux/if_vlan.h>
6 #include <linux/pm_runtime.h>
8 #include "igc.h"
10 /* forward declaration */
11 struct igc_stats {
12 char stat_string[ETH_GSTRING_LEN];
13 int sizeof_stat;
14 int stat_offset;
17 #define IGC_STAT(_name, _stat) { \
18 .stat_string = _name, \
19 .sizeof_stat = sizeof_field(struct igc_adapter, _stat), \
20 .stat_offset = offsetof(struct igc_adapter, _stat) \
23 static const struct igc_stats igc_gstrings_stats[] = {
24 IGC_STAT("rx_packets", stats.gprc),
25 IGC_STAT("tx_packets", stats.gptc),
26 IGC_STAT("rx_bytes", stats.gorc),
27 IGC_STAT("tx_bytes", stats.gotc),
28 IGC_STAT("rx_broadcast", stats.bprc),
29 IGC_STAT("tx_broadcast", stats.bptc),
30 IGC_STAT("rx_multicast", stats.mprc),
31 IGC_STAT("tx_multicast", stats.mptc),
32 IGC_STAT("multicast", stats.mprc),
33 IGC_STAT("collisions", stats.colc),
34 IGC_STAT("rx_crc_errors", stats.crcerrs),
35 IGC_STAT("rx_no_buffer_count", stats.rnbc),
36 IGC_STAT("rx_missed_errors", stats.mpc),
37 IGC_STAT("tx_aborted_errors", stats.ecol),
38 IGC_STAT("tx_carrier_errors", stats.tncrs),
39 IGC_STAT("tx_window_errors", stats.latecol),
40 IGC_STAT("tx_abort_late_coll", stats.latecol),
41 IGC_STAT("tx_deferred_ok", stats.dc),
42 IGC_STAT("tx_single_coll_ok", stats.scc),
43 IGC_STAT("tx_multi_coll_ok", stats.mcc),
44 IGC_STAT("tx_timeout_count", tx_timeout_count),
45 IGC_STAT("rx_long_length_errors", stats.roc),
46 IGC_STAT("rx_short_length_errors", stats.ruc),
47 IGC_STAT("rx_align_errors", stats.algnerrc),
48 IGC_STAT("tx_tcp_seg_good", stats.tsctc),
49 IGC_STAT("tx_tcp_seg_failed", stats.tsctfc),
50 IGC_STAT("rx_flow_control_xon", stats.xonrxc),
51 IGC_STAT("rx_flow_control_xoff", stats.xoffrxc),
52 IGC_STAT("tx_flow_control_xon", stats.xontxc),
53 IGC_STAT("tx_flow_control_xoff", stats.xofftxc),
54 IGC_STAT("rx_long_byte_count", stats.gorc),
55 IGC_STAT("tx_dma_out_of_sync", stats.doosync),
56 IGC_STAT("tx_smbus", stats.mgptc),
57 IGC_STAT("rx_smbus", stats.mgprc),
58 IGC_STAT("dropped_smbus", stats.mgpdc),
59 IGC_STAT("os2bmc_rx_by_bmc", stats.o2bgptc),
60 IGC_STAT("os2bmc_tx_by_bmc", stats.b2ospc),
61 IGC_STAT("os2bmc_tx_by_host", stats.o2bspc),
62 IGC_STAT("os2bmc_rx_by_host", stats.b2ogprc),
63 IGC_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
64 IGC_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped),
65 IGC_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
68 #define IGC_NETDEV_STAT(_net_stat) { \
69 .stat_string = __stringify(_net_stat), \
70 .sizeof_stat = sizeof_field(struct rtnl_link_stats64, _net_stat), \
71 .stat_offset = offsetof(struct rtnl_link_stats64, _net_stat) \
74 static const struct igc_stats igc_gstrings_net_stats[] = {
75 IGC_NETDEV_STAT(rx_errors),
76 IGC_NETDEV_STAT(tx_errors),
77 IGC_NETDEV_STAT(tx_dropped),
78 IGC_NETDEV_STAT(rx_length_errors),
79 IGC_NETDEV_STAT(rx_over_errors),
80 IGC_NETDEV_STAT(rx_frame_errors),
81 IGC_NETDEV_STAT(rx_fifo_errors),
82 IGC_NETDEV_STAT(tx_fifo_errors),
83 IGC_NETDEV_STAT(tx_heartbeat_errors)
86 enum igc_diagnostics_results {
87 TEST_REG = 0,
88 TEST_EEP,
89 TEST_IRQ,
90 TEST_LOOP,
91 TEST_LINK
94 static const char igc_gstrings_test[][ETH_GSTRING_LEN] = {
95 [TEST_REG] = "Register test (offline)",
96 [TEST_EEP] = "Eeprom test (offline)",
97 [TEST_IRQ] = "Interrupt test (offline)",
98 [TEST_LOOP] = "Loopback test (offline)",
99 [TEST_LINK] = "Link test (on/offline)"
102 #define IGC_TEST_LEN (sizeof(igc_gstrings_test) / ETH_GSTRING_LEN)
104 #define IGC_GLOBAL_STATS_LEN \
105 (sizeof(igc_gstrings_stats) / sizeof(struct igc_stats))
106 #define IGC_NETDEV_STATS_LEN \
107 (sizeof(igc_gstrings_net_stats) / sizeof(struct igc_stats))
108 #define IGC_RX_QUEUE_STATS_LEN \
109 (sizeof(struct igc_rx_queue_stats) / sizeof(u64))
110 #define IGC_TX_QUEUE_STATS_LEN 3 /* packets, bytes, restart_queue */
111 #define IGC_QUEUE_STATS_LEN \
112 ((((struct igc_adapter *)netdev_priv(netdev))->num_rx_queues * \
113 IGC_RX_QUEUE_STATS_LEN) + \
114 (((struct igc_adapter *)netdev_priv(netdev))->num_tx_queues * \
115 IGC_TX_QUEUE_STATS_LEN))
116 #define IGC_STATS_LEN \
117 (IGC_GLOBAL_STATS_LEN + IGC_NETDEV_STATS_LEN + IGC_QUEUE_STATS_LEN)
119 static const char igc_priv_flags_strings[][ETH_GSTRING_LEN] = {
120 #define IGC_PRIV_FLAGS_LEGACY_RX BIT(0)
121 "legacy-rx",
124 #define IGC_PRIV_FLAGS_STR_LEN ARRAY_SIZE(igc_priv_flags_strings)
126 static void igc_get_drvinfo(struct net_device *netdev,
127 struct ethtool_drvinfo *drvinfo)
129 struct igc_adapter *adapter = netdev_priv(netdev);
131 strlcpy(drvinfo->driver, igc_driver_name, sizeof(drvinfo->driver));
132 strlcpy(drvinfo->version, igc_driver_version, sizeof(drvinfo->version));
134 /* add fw_version here */
135 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
136 sizeof(drvinfo->bus_info));
138 drvinfo->n_priv_flags = IGC_PRIV_FLAGS_STR_LEN;
141 static int igc_get_regs_len(struct net_device *netdev)
143 return IGC_REGS_LEN * sizeof(u32);
146 static void igc_get_regs(struct net_device *netdev,
147 struct ethtool_regs *regs, void *p)
149 struct igc_adapter *adapter = netdev_priv(netdev);
150 struct igc_hw *hw = &adapter->hw;
151 u32 *regs_buff = p;
152 u8 i;
154 memset(p, 0, IGC_REGS_LEN * sizeof(u32));
156 regs->version = (1u << 24) | (hw->revision_id << 16) | hw->device_id;
158 /* General Registers */
159 regs_buff[0] = rd32(IGC_CTRL);
160 regs_buff[1] = rd32(IGC_STATUS);
161 regs_buff[2] = rd32(IGC_CTRL_EXT);
162 regs_buff[3] = rd32(IGC_MDIC);
163 regs_buff[4] = rd32(IGC_CONNSW);
165 /* NVM Register */
166 regs_buff[5] = rd32(IGC_EECD);
168 /* Interrupt */
169 /* Reading EICS for EICR because they read the
170 * same but EICS does not clear on read
172 regs_buff[6] = rd32(IGC_EICS);
173 regs_buff[7] = rd32(IGC_EICS);
174 regs_buff[8] = rd32(IGC_EIMS);
175 regs_buff[9] = rd32(IGC_EIMC);
176 regs_buff[10] = rd32(IGC_EIAC);
177 regs_buff[11] = rd32(IGC_EIAM);
178 /* Reading ICS for ICR because they read the
179 * same but ICS does not clear on read
181 regs_buff[12] = rd32(IGC_ICS);
182 regs_buff[13] = rd32(IGC_ICS);
183 regs_buff[14] = rd32(IGC_IMS);
184 regs_buff[15] = rd32(IGC_IMC);
185 regs_buff[16] = rd32(IGC_IAC);
186 regs_buff[17] = rd32(IGC_IAM);
188 /* Flow Control */
189 regs_buff[18] = rd32(IGC_FCAL);
190 regs_buff[19] = rd32(IGC_FCAH);
191 regs_buff[20] = rd32(IGC_FCTTV);
192 regs_buff[21] = rd32(IGC_FCRTL);
193 regs_buff[22] = rd32(IGC_FCRTH);
194 regs_buff[23] = rd32(IGC_FCRTV);
196 /* Receive */
197 regs_buff[24] = rd32(IGC_RCTL);
198 regs_buff[25] = rd32(IGC_RXCSUM);
199 regs_buff[26] = rd32(IGC_RLPML);
200 regs_buff[27] = rd32(IGC_RFCTL);
202 /* Transmit */
203 regs_buff[28] = rd32(IGC_TCTL);
204 regs_buff[29] = rd32(IGC_TIPG);
206 /* Wake Up */
208 /* MAC */
210 /* Statistics */
211 regs_buff[30] = adapter->stats.crcerrs;
212 regs_buff[31] = adapter->stats.algnerrc;
213 regs_buff[32] = adapter->stats.symerrs;
214 regs_buff[33] = adapter->stats.rxerrc;
215 regs_buff[34] = adapter->stats.mpc;
216 regs_buff[35] = adapter->stats.scc;
217 regs_buff[36] = adapter->stats.ecol;
218 regs_buff[37] = adapter->stats.mcc;
219 regs_buff[38] = adapter->stats.latecol;
220 regs_buff[39] = adapter->stats.colc;
221 regs_buff[40] = adapter->stats.dc;
222 regs_buff[41] = adapter->stats.tncrs;
223 regs_buff[42] = adapter->stats.sec;
224 regs_buff[43] = adapter->stats.htdpmc;
225 regs_buff[44] = adapter->stats.rlec;
226 regs_buff[45] = adapter->stats.xonrxc;
227 regs_buff[46] = adapter->stats.xontxc;
228 regs_buff[47] = adapter->stats.xoffrxc;
229 regs_buff[48] = adapter->stats.xofftxc;
230 regs_buff[49] = adapter->stats.fcruc;
231 regs_buff[50] = adapter->stats.prc64;
232 regs_buff[51] = adapter->stats.prc127;
233 regs_buff[52] = adapter->stats.prc255;
234 regs_buff[53] = adapter->stats.prc511;
235 regs_buff[54] = adapter->stats.prc1023;
236 regs_buff[55] = adapter->stats.prc1522;
237 regs_buff[56] = adapter->stats.gprc;
238 regs_buff[57] = adapter->stats.bprc;
239 regs_buff[58] = adapter->stats.mprc;
240 regs_buff[59] = adapter->stats.gptc;
241 regs_buff[60] = adapter->stats.gorc;
242 regs_buff[61] = adapter->stats.gotc;
243 regs_buff[62] = adapter->stats.rnbc;
244 regs_buff[63] = adapter->stats.ruc;
245 regs_buff[64] = adapter->stats.rfc;
246 regs_buff[65] = adapter->stats.roc;
247 regs_buff[66] = adapter->stats.rjc;
248 regs_buff[67] = adapter->stats.mgprc;
249 regs_buff[68] = adapter->stats.mgpdc;
250 regs_buff[69] = adapter->stats.mgptc;
251 regs_buff[70] = adapter->stats.tor;
252 regs_buff[71] = adapter->stats.tot;
253 regs_buff[72] = adapter->stats.tpr;
254 regs_buff[73] = adapter->stats.tpt;
255 regs_buff[74] = adapter->stats.ptc64;
256 regs_buff[75] = adapter->stats.ptc127;
257 regs_buff[76] = adapter->stats.ptc255;
258 regs_buff[77] = adapter->stats.ptc511;
259 regs_buff[78] = adapter->stats.ptc1023;
260 regs_buff[79] = adapter->stats.ptc1522;
261 regs_buff[80] = adapter->stats.mptc;
262 regs_buff[81] = adapter->stats.bptc;
263 regs_buff[82] = adapter->stats.tsctc;
264 regs_buff[83] = adapter->stats.iac;
265 regs_buff[84] = adapter->stats.rpthc;
266 regs_buff[85] = adapter->stats.hgptc;
267 regs_buff[86] = adapter->stats.hgorc;
268 regs_buff[87] = adapter->stats.hgotc;
269 regs_buff[88] = adapter->stats.lenerrs;
270 regs_buff[89] = adapter->stats.scvpc;
271 regs_buff[90] = adapter->stats.hrmpc;
273 for (i = 0; i < 4; i++)
274 regs_buff[91 + i] = rd32(IGC_SRRCTL(i));
275 for (i = 0; i < 4; i++)
276 regs_buff[95 + i] = rd32(IGC_PSRTYPE(i));
277 for (i = 0; i < 4; i++)
278 regs_buff[99 + i] = rd32(IGC_RDBAL(i));
279 for (i = 0; i < 4; i++)
280 regs_buff[103 + i] = rd32(IGC_RDBAH(i));
281 for (i = 0; i < 4; i++)
282 regs_buff[107 + i] = rd32(IGC_RDLEN(i));
283 for (i = 0; i < 4; i++)
284 regs_buff[111 + i] = rd32(IGC_RDH(i));
285 for (i = 0; i < 4; i++)
286 regs_buff[115 + i] = rd32(IGC_RDT(i));
287 for (i = 0; i < 4; i++)
288 regs_buff[119 + i] = rd32(IGC_RXDCTL(i));
290 for (i = 0; i < 10; i++)
291 regs_buff[123 + i] = rd32(IGC_EITR(i));
292 for (i = 0; i < 16; i++)
293 regs_buff[139 + i] = rd32(IGC_RAL(i));
294 for (i = 0; i < 16; i++)
295 regs_buff[145 + i] = rd32(IGC_RAH(i));
297 for (i = 0; i < 4; i++)
298 regs_buff[149 + i] = rd32(IGC_TDBAL(i));
299 for (i = 0; i < 4; i++)
300 regs_buff[152 + i] = rd32(IGC_TDBAH(i));
301 for (i = 0; i < 4; i++)
302 regs_buff[156 + i] = rd32(IGC_TDLEN(i));
303 for (i = 0; i < 4; i++)
304 regs_buff[160 + i] = rd32(IGC_TDH(i));
305 for (i = 0; i < 4; i++)
306 regs_buff[164 + i] = rd32(IGC_TDT(i));
307 for (i = 0; i < 4; i++)
308 regs_buff[168 + i] = rd32(IGC_TXDCTL(i));
311 static void igc_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
313 struct igc_adapter *adapter = netdev_priv(netdev);
315 wol->wolopts = 0;
317 if (!(adapter->flags & IGC_FLAG_WOL_SUPPORTED))
318 return;
320 wol->supported = WAKE_UCAST | WAKE_MCAST |
321 WAKE_BCAST | WAKE_MAGIC |
322 WAKE_PHY;
324 /* apply any specific unsupported masks here */
325 switch (adapter->hw.device_id) {
326 default:
327 break;
330 if (adapter->wol & IGC_WUFC_EX)
331 wol->wolopts |= WAKE_UCAST;
332 if (adapter->wol & IGC_WUFC_MC)
333 wol->wolopts |= WAKE_MCAST;
334 if (adapter->wol & IGC_WUFC_BC)
335 wol->wolopts |= WAKE_BCAST;
336 if (adapter->wol & IGC_WUFC_MAG)
337 wol->wolopts |= WAKE_MAGIC;
338 if (adapter->wol & IGC_WUFC_LNKC)
339 wol->wolopts |= WAKE_PHY;
342 static int igc_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
344 struct igc_adapter *adapter = netdev_priv(netdev);
346 if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE | WAKE_FILTER))
347 return -EOPNOTSUPP;
349 if (!(adapter->flags & IGC_FLAG_WOL_SUPPORTED))
350 return wol->wolopts ? -EOPNOTSUPP : 0;
352 /* these settings will always override what we currently have */
353 adapter->wol = 0;
355 if (wol->wolopts & WAKE_UCAST)
356 adapter->wol |= IGC_WUFC_EX;
357 if (wol->wolopts & WAKE_MCAST)
358 adapter->wol |= IGC_WUFC_MC;
359 if (wol->wolopts & WAKE_BCAST)
360 adapter->wol |= IGC_WUFC_BC;
361 if (wol->wolopts & WAKE_MAGIC)
362 adapter->wol |= IGC_WUFC_MAG;
363 if (wol->wolopts & WAKE_PHY)
364 adapter->wol |= IGC_WUFC_LNKC;
365 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
367 return 0;
370 static u32 igc_get_msglevel(struct net_device *netdev)
372 struct igc_adapter *adapter = netdev_priv(netdev);
374 return adapter->msg_enable;
377 static void igc_set_msglevel(struct net_device *netdev, u32 data)
379 struct igc_adapter *adapter = netdev_priv(netdev);
381 adapter->msg_enable = data;
384 static int igc_nway_reset(struct net_device *netdev)
386 struct igc_adapter *adapter = netdev_priv(netdev);
388 if (netif_running(netdev))
389 igc_reinit_locked(adapter);
390 return 0;
393 static u32 igc_get_link(struct net_device *netdev)
395 struct igc_adapter *adapter = netdev_priv(netdev);
396 struct igc_mac_info *mac = &adapter->hw.mac;
398 /* If the link is not reported up to netdev, interrupts are disabled,
399 * and so the physical link state may have changed since we last
400 * looked. Set get_link_status to make sure that the true link
401 * state is interrogated, rather than pulling a cached and possibly
402 * stale link state from the driver.
404 if (!netif_carrier_ok(netdev))
405 mac->get_link_status = 1;
407 return igc_has_link(adapter);
410 static int igc_get_eeprom_len(struct net_device *netdev)
412 struct igc_adapter *adapter = netdev_priv(netdev);
414 return adapter->hw.nvm.word_size * 2;
417 static int igc_get_eeprom(struct net_device *netdev,
418 struct ethtool_eeprom *eeprom, u8 *bytes)
420 struct igc_adapter *adapter = netdev_priv(netdev);
421 struct igc_hw *hw = &adapter->hw;
422 int first_word, last_word;
423 u16 *eeprom_buff;
424 int ret_val = 0;
425 u16 i;
427 if (eeprom->len == 0)
428 return -EINVAL;
430 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
432 first_word = eeprom->offset >> 1;
433 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
435 eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16),
436 GFP_KERNEL);
437 if (!eeprom_buff)
438 return -ENOMEM;
440 if (hw->nvm.type == igc_nvm_eeprom_spi) {
441 ret_val = hw->nvm.ops.read(hw, first_word,
442 last_word - first_word + 1,
443 eeprom_buff);
444 } else {
445 for (i = 0; i < last_word - first_word + 1; i++) {
446 ret_val = hw->nvm.ops.read(hw, first_word + i, 1,
447 &eeprom_buff[i]);
448 if (ret_val)
449 break;
453 /* Device's eeprom is always little-endian, word addressable */
454 for (i = 0; i < last_word - first_word + 1; i++)
455 le16_to_cpus(&eeprom_buff[i]);
457 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
458 eeprom->len);
459 kfree(eeprom_buff);
461 return ret_val;
464 static int igc_set_eeprom(struct net_device *netdev,
465 struct ethtool_eeprom *eeprom, u8 *bytes)
467 struct igc_adapter *adapter = netdev_priv(netdev);
468 struct igc_hw *hw = &adapter->hw;
469 int max_len, first_word, last_word, ret_val = 0;
470 u16 *eeprom_buff;
471 void *ptr;
472 u16 i;
474 if (eeprom->len == 0)
475 return -EOPNOTSUPP;
477 if (hw->mac.type >= igc_i225 &&
478 !igc_get_flash_presence_i225(hw)) {
479 return -EOPNOTSUPP;
482 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
483 return -EFAULT;
485 max_len = hw->nvm.word_size * 2;
487 first_word = eeprom->offset >> 1;
488 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
489 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
490 if (!eeprom_buff)
491 return -ENOMEM;
493 ptr = (void *)eeprom_buff;
495 if (eeprom->offset & 1) {
496 /* need read/modify/write of first changed EEPROM word
497 * only the second byte of the word is being modified
499 ret_val = hw->nvm.ops.read(hw, first_word, 1,
500 &eeprom_buff[0]);
501 ptr++;
503 if (((eeprom->offset + eeprom->len) & 1) && ret_val == 0) {
504 /* need read/modify/write of last changed EEPROM word
505 * only the first byte of the word is being modified
507 ret_val = hw->nvm.ops.read(hw, last_word, 1,
508 &eeprom_buff[last_word - first_word]);
511 /* Device's eeprom is always little-endian, word addressable */
512 for (i = 0; i < last_word - first_word + 1; i++)
513 le16_to_cpus(&eeprom_buff[i]);
515 memcpy(ptr, bytes, eeprom->len);
517 for (i = 0; i < last_word - first_word + 1; i++)
518 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
520 ret_val = hw->nvm.ops.write(hw, first_word,
521 last_word - first_word + 1, eeprom_buff);
523 /* Update the checksum if nvm write succeeded */
524 if (ret_val == 0)
525 hw->nvm.ops.update(hw);
527 /* check if need: igc_set_fw_version(adapter); */
528 kfree(eeprom_buff);
529 return ret_val;
532 static void igc_get_ringparam(struct net_device *netdev,
533 struct ethtool_ringparam *ring)
535 struct igc_adapter *adapter = netdev_priv(netdev);
537 ring->rx_max_pending = IGC_MAX_RXD;
538 ring->tx_max_pending = IGC_MAX_TXD;
539 ring->rx_pending = adapter->rx_ring_count;
540 ring->tx_pending = adapter->tx_ring_count;
543 static int igc_set_ringparam(struct net_device *netdev,
544 struct ethtool_ringparam *ring)
546 struct igc_adapter *adapter = netdev_priv(netdev);
547 struct igc_ring *temp_ring;
548 u16 new_rx_count, new_tx_count;
549 int i, err = 0;
551 if (ring->rx_mini_pending || ring->rx_jumbo_pending)
552 return -EINVAL;
554 new_rx_count = min_t(u32, ring->rx_pending, IGC_MAX_RXD);
555 new_rx_count = max_t(u16, new_rx_count, IGC_MIN_RXD);
556 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
558 new_tx_count = min_t(u32, ring->tx_pending, IGC_MAX_TXD);
559 new_tx_count = max_t(u16, new_tx_count, IGC_MIN_TXD);
560 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
562 if (new_tx_count == adapter->tx_ring_count &&
563 new_rx_count == adapter->rx_ring_count) {
564 /* nothing to do */
565 return 0;
568 while (test_and_set_bit(__IGC_RESETTING, &adapter->state))
569 usleep_range(1000, 2000);
571 if (!netif_running(adapter->netdev)) {
572 for (i = 0; i < adapter->num_tx_queues; i++)
573 adapter->tx_ring[i]->count = new_tx_count;
574 for (i = 0; i < adapter->num_rx_queues; i++)
575 adapter->rx_ring[i]->count = new_rx_count;
576 adapter->tx_ring_count = new_tx_count;
577 adapter->rx_ring_count = new_rx_count;
578 goto clear_reset;
581 if (adapter->num_tx_queues > adapter->num_rx_queues)
582 temp_ring = vmalloc(array_size(sizeof(struct igc_ring),
583 adapter->num_tx_queues));
584 else
585 temp_ring = vmalloc(array_size(sizeof(struct igc_ring),
586 adapter->num_rx_queues));
588 if (!temp_ring) {
589 err = -ENOMEM;
590 goto clear_reset;
593 igc_down(adapter);
595 /* We can't just free everything and then setup again,
596 * because the ISRs in MSI-X mode get passed pointers
597 * to the Tx and Rx ring structs.
599 if (new_tx_count != adapter->tx_ring_count) {
600 for (i = 0; i < adapter->num_tx_queues; i++) {
601 memcpy(&temp_ring[i], adapter->tx_ring[i],
602 sizeof(struct igc_ring));
604 temp_ring[i].count = new_tx_count;
605 err = igc_setup_tx_resources(&temp_ring[i]);
606 if (err) {
607 while (i) {
608 i--;
609 igc_free_tx_resources(&temp_ring[i]);
611 goto err_setup;
615 for (i = 0; i < adapter->num_tx_queues; i++) {
616 igc_free_tx_resources(adapter->tx_ring[i]);
618 memcpy(adapter->tx_ring[i], &temp_ring[i],
619 sizeof(struct igc_ring));
622 adapter->tx_ring_count = new_tx_count;
625 if (new_rx_count != adapter->rx_ring_count) {
626 for (i = 0; i < adapter->num_rx_queues; i++) {
627 memcpy(&temp_ring[i], adapter->rx_ring[i],
628 sizeof(struct igc_ring));
630 temp_ring[i].count = new_rx_count;
631 err = igc_setup_rx_resources(&temp_ring[i]);
632 if (err) {
633 while (i) {
634 i--;
635 igc_free_rx_resources(&temp_ring[i]);
637 goto err_setup;
641 for (i = 0; i < adapter->num_rx_queues; i++) {
642 igc_free_rx_resources(adapter->rx_ring[i]);
644 memcpy(adapter->rx_ring[i], &temp_ring[i],
645 sizeof(struct igc_ring));
648 adapter->rx_ring_count = new_rx_count;
650 err_setup:
651 igc_up(adapter);
652 vfree(temp_ring);
653 clear_reset:
654 clear_bit(__IGC_RESETTING, &adapter->state);
655 return err;
658 static void igc_get_pauseparam(struct net_device *netdev,
659 struct ethtool_pauseparam *pause)
661 struct igc_adapter *adapter = netdev_priv(netdev);
662 struct igc_hw *hw = &adapter->hw;
664 pause->autoneg =
665 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
667 if (hw->fc.current_mode == igc_fc_rx_pause) {
668 pause->rx_pause = 1;
669 } else if (hw->fc.current_mode == igc_fc_tx_pause) {
670 pause->tx_pause = 1;
671 } else if (hw->fc.current_mode == igc_fc_full) {
672 pause->rx_pause = 1;
673 pause->tx_pause = 1;
677 static int igc_set_pauseparam(struct net_device *netdev,
678 struct ethtool_pauseparam *pause)
680 struct igc_adapter *adapter = netdev_priv(netdev);
681 struct igc_hw *hw = &adapter->hw;
682 int retval = 0;
684 adapter->fc_autoneg = pause->autoneg;
686 while (test_and_set_bit(__IGC_RESETTING, &adapter->state))
687 usleep_range(1000, 2000);
689 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
690 hw->fc.requested_mode = igc_fc_default;
691 if (netif_running(adapter->netdev)) {
692 igc_down(adapter);
693 igc_up(adapter);
694 } else {
695 igc_reset(adapter);
697 } else {
698 if (pause->rx_pause && pause->tx_pause)
699 hw->fc.requested_mode = igc_fc_full;
700 else if (pause->rx_pause && !pause->tx_pause)
701 hw->fc.requested_mode = igc_fc_rx_pause;
702 else if (!pause->rx_pause && pause->tx_pause)
703 hw->fc.requested_mode = igc_fc_tx_pause;
704 else if (!pause->rx_pause && !pause->tx_pause)
705 hw->fc.requested_mode = igc_fc_none;
707 hw->fc.current_mode = hw->fc.requested_mode;
709 retval = ((hw->phy.media_type == igc_media_type_copper) ?
710 igc_force_mac_fc(hw) : igc_setup_link(hw));
713 clear_bit(__IGC_RESETTING, &adapter->state);
714 return retval;
717 static void igc_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
719 struct igc_adapter *adapter = netdev_priv(netdev);
720 u8 *p = data;
721 int i;
723 switch (stringset) {
724 case ETH_SS_TEST:
725 memcpy(data, *igc_gstrings_test,
726 IGC_TEST_LEN * ETH_GSTRING_LEN);
727 break;
728 case ETH_SS_STATS:
729 for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++) {
730 memcpy(p, igc_gstrings_stats[i].stat_string,
731 ETH_GSTRING_LEN);
732 p += ETH_GSTRING_LEN;
734 for (i = 0; i < IGC_NETDEV_STATS_LEN; i++) {
735 memcpy(p, igc_gstrings_net_stats[i].stat_string,
736 ETH_GSTRING_LEN);
737 p += ETH_GSTRING_LEN;
739 for (i = 0; i < adapter->num_tx_queues; i++) {
740 sprintf(p, "tx_queue_%u_packets", i);
741 p += ETH_GSTRING_LEN;
742 sprintf(p, "tx_queue_%u_bytes", i);
743 p += ETH_GSTRING_LEN;
744 sprintf(p, "tx_queue_%u_restart", i);
745 p += ETH_GSTRING_LEN;
747 for (i = 0; i < adapter->num_rx_queues; i++) {
748 sprintf(p, "rx_queue_%u_packets", i);
749 p += ETH_GSTRING_LEN;
750 sprintf(p, "rx_queue_%u_bytes", i);
751 p += ETH_GSTRING_LEN;
752 sprintf(p, "rx_queue_%u_drops", i);
753 p += ETH_GSTRING_LEN;
754 sprintf(p, "rx_queue_%u_csum_err", i);
755 p += ETH_GSTRING_LEN;
756 sprintf(p, "rx_queue_%u_alloc_failed", i);
757 p += ETH_GSTRING_LEN;
759 /* BUG_ON(p - data != IGC_STATS_LEN * ETH_GSTRING_LEN); */
760 break;
761 case ETH_SS_PRIV_FLAGS:
762 memcpy(data, igc_priv_flags_strings,
763 IGC_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
764 break;
768 static int igc_get_sset_count(struct net_device *netdev, int sset)
770 switch (sset) {
771 case ETH_SS_STATS:
772 return IGC_STATS_LEN;
773 case ETH_SS_TEST:
774 return IGC_TEST_LEN;
775 case ETH_SS_PRIV_FLAGS:
776 return IGC_PRIV_FLAGS_STR_LEN;
777 default:
778 return -ENOTSUPP;
782 static void igc_get_ethtool_stats(struct net_device *netdev,
783 struct ethtool_stats *stats, u64 *data)
785 struct igc_adapter *adapter = netdev_priv(netdev);
786 struct rtnl_link_stats64 *net_stats = &adapter->stats64;
787 unsigned int start;
788 struct igc_ring *ring;
789 int i, j;
790 char *p;
792 spin_lock(&adapter->stats64_lock);
793 igc_update_stats(adapter);
795 for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++) {
796 p = (char *)adapter + igc_gstrings_stats[i].stat_offset;
797 data[i] = (igc_gstrings_stats[i].sizeof_stat ==
798 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
800 for (j = 0; j < IGC_NETDEV_STATS_LEN; j++, i++) {
801 p = (char *)net_stats + igc_gstrings_net_stats[j].stat_offset;
802 data[i] = (igc_gstrings_net_stats[j].sizeof_stat ==
803 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
805 for (j = 0; j < adapter->num_tx_queues; j++) {
806 u64 restart2;
808 ring = adapter->tx_ring[j];
809 do {
810 start = u64_stats_fetch_begin_irq(&ring->tx_syncp);
811 data[i] = ring->tx_stats.packets;
812 data[i + 1] = ring->tx_stats.bytes;
813 data[i + 2] = ring->tx_stats.restart_queue;
814 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp, start));
815 do {
816 start = u64_stats_fetch_begin_irq(&ring->tx_syncp2);
817 restart2 = ring->tx_stats.restart_queue2;
818 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp2, start));
819 data[i + 2] += restart2;
821 i += IGC_TX_QUEUE_STATS_LEN;
823 for (j = 0; j < adapter->num_rx_queues; j++) {
824 ring = adapter->rx_ring[j];
825 do {
826 start = u64_stats_fetch_begin_irq(&ring->rx_syncp);
827 data[i] = ring->rx_stats.packets;
828 data[i + 1] = ring->rx_stats.bytes;
829 data[i + 2] = ring->rx_stats.drops;
830 data[i + 3] = ring->rx_stats.csum_err;
831 data[i + 4] = ring->rx_stats.alloc_failed;
832 } while (u64_stats_fetch_retry_irq(&ring->rx_syncp, start));
833 i += IGC_RX_QUEUE_STATS_LEN;
835 spin_unlock(&adapter->stats64_lock);
838 static int igc_get_coalesce(struct net_device *netdev,
839 struct ethtool_coalesce *ec)
841 struct igc_adapter *adapter = netdev_priv(netdev);
843 if (adapter->rx_itr_setting <= 3)
844 ec->rx_coalesce_usecs = adapter->rx_itr_setting;
845 else
846 ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
848 if (!(adapter->flags & IGC_FLAG_QUEUE_PAIRS)) {
849 if (adapter->tx_itr_setting <= 3)
850 ec->tx_coalesce_usecs = adapter->tx_itr_setting;
851 else
852 ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
855 return 0;
858 static int igc_set_coalesce(struct net_device *netdev,
859 struct ethtool_coalesce *ec)
861 struct igc_adapter *adapter = netdev_priv(netdev);
862 int i;
864 if (ec->rx_coalesce_usecs > IGC_MAX_ITR_USECS ||
865 (ec->rx_coalesce_usecs > 3 &&
866 ec->rx_coalesce_usecs < IGC_MIN_ITR_USECS) ||
867 ec->rx_coalesce_usecs == 2)
868 return -EINVAL;
870 if (ec->tx_coalesce_usecs > IGC_MAX_ITR_USECS ||
871 (ec->tx_coalesce_usecs > 3 &&
872 ec->tx_coalesce_usecs < IGC_MIN_ITR_USECS) ||
873 ec->tx_coalesce_usecs == 2)
874 return -EINVAL;
876 if ((adapter->flags & IGC_FLAG_QUEUE_PAIRS) && ec->tx_coalesce_usecs)
877 return -EINVAL;
879 /* If ITR is disabled, disable DMAC */
880 if (ec->rx_coalesce_usecs == 0) {
881 if (adapter->flags & IGC_FLAG_DMAC)
882 adapter->flags &= ~IGC_FLAG_DMAC;
885 /* convert to rate of irq's per second */
886 if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3)
887 adapter->rx_itr_setting = ec->rx_coalesce_usecs;
888 else
889 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
891 /* convert to rate of irq's per second */
892 if (adapter->flags & IGC_FLAG_QUEUE_PAIRS)
893 adapter->tx_itr_setting = adapter->rx_itr_setting;
894 else if (ec->tx_coalesce_usecs && ec->tx_coalesce_usecs <= 3)
895 adapter->tx_itr_setting = ec->tx_coalesce_usecs;
896 else
897 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
899 for (i = 0; i < adapter->num_q_vectors; i++) {
900 struct igc_q_vector *q_vector = adapter->q_vector[i];
902 q_vector->tx.work_limit = adapter->tx_work_limit;
903 if (q_vector->rx.ring)
904 q_vector->itr_val = adapter->rx_itr_setting;
905 else
906 q_vector->itr_val = adapter->tx_itr_setting;
907 if (q_vector->itr_val && q_vector->itr_val <= 3)
908 q_vector->itr_val = IGC_START_ITR;
909 q_vector->set_itr = 1;
912 return 0;
915 #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
916 static int igc_get_ethtool_nfc_entry(struct igc_adapter *adapter,
917 struct ethtool_rxnfc *cmd)
919 struct ethtool_rx_flow_spec *fsp = &cmd->fs;
920 struct igc_nfc_filter *rule = NULL;
922 /* report total rule count */
923 cmd->data = IGC_MAX_RXNFC_FILTERS;
925 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node) {
926 if (fsp->location <= rule->sw_idx)
927 break;
930 if (!rule || fsp->location != rule->sw_idx)
931 return -EINVAL;
933 if (rule->filter.match_flags) {
934 fsp->flow_type = ETHER_FLOW;
935 fsp->ring_cookie = rule->action;
936 if (rule->filter.match_flags & IGC_FILTER_FLAG_ETHER_TYPE) {
937 fsp->h_u.ether_spec.h_proto = rule->filter.etype;
938 fsp->m_u.ether_spec.h_proto = ETHER_TYPE_FULL_MASK;
940 if (rule->filter.match_flags & IGC_FILTER_FLAG_VLAN_TCI) {
941 fsp->flow_type |= FLOW_EXT;
942 fsp->h_ext.vlan_tci = rule->filter.vlan_tci;
943 fsp->m_ext.vlan_tci = htons(VLAN_PRIO_MASK);
945 if (rule->filter.match_flags & IGC_FILTER_FLAG_DST_MAC_ADDR) {
946 ether_addr_copy(fsp->h_u.ether_spec.h_dest,
947 rule->filter.dst_addr);
948 /* As we only support matching by the full
949 * mask, return the mask to userspace
951 eth_broadcast_addr(fsp->m_u.ether_spec.h_dest);
953 if (rule->filter.match_flags & IGC_FILTER_FLAG_SRC_MAC_ADDR) {
954 ether_addr_copy(fsp->h_u.ether_spec.h_source,
955 rule->filter.src_addr);
956 /* As we only support matching by the full
957 * mask, return the mask to userspace
959 eth_broadcast_addr(fsp->m_u.ether_spec.h_source);
962 return 0;
964 return -EINVAL;
967 static int igc_get_ethtool_nfc_all(struct igc_adapter *adapter,
968 struct ethtool_rxnfc *cmd,
969 u32 *rule_locs)
971 struct igc_nfc_filter *rule;
972 int cnt = 0;
974 /* report total rule count */
975 cmd->data = IGC_MAX_RXNFC_FILTERS;
977 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node) {
978 if (cnt == cmd->rule_cnt)
979 return -EMSGSIZE;
980 rule_locs[cnt] = rule->sw_idx;
981 cnt++;
984 cmd->rule_cnt = cnt;
986 return 0;
989 static int igc_get_rss_hash_opts(struct igc_adapter *adapter,
990 struct ethtool_rxnfc *cmd)
992 cmd->data = 0;
994 /* Report default options for RSS on igc */
995 switch (cmd->flow_type) {
996 case TCP_V4_FLOW:
997 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
998 /* Fall through */
999 case UDP_V4_FLOW:
1000 if (adapter->flags & IGC_FLAG_RSS_FIELD_IPV4_UDP)
1001 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1002 /* Fall through */
1003 case SCTP_V4_FLOW:
1004 /* Fall through */
1005 case AH_ESP_V4_FLOW:
1006 /* Fall through */
1007 case AH_V4_FLOW:
1008 /* Fall through */
1009 case ESP_V4_FLOW:
1010 /* Fall through */
1011 case IPV4_FLOW:
1012 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1013 break;
1014 case TCP_V6_FLOW:
1015 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1016 /* Fall through */
1017 case UDP_V6_FLOW:
1018 if (adapter->flags & IGC_FLAG_RSS_FIELD_IPV6_UDP)
1019 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1020 /* Fall through */
1021 case SCTP_V6_FLOW:
1022 /* Fall through */
1023 case AH_ESP_V6_FLOW:
1024 /* Fall through */
1025 case AH_V6_FLOW:
1026 /* Fall through */
1027 case ESP_V6_FLOW:
1028 /* Fall through */
1029 case IPV6_FLOW:
1030 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1031 break;
1032 default:
1033 return -EINVAL;
1036 return 0;
1039 static int igc_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
1040 u32 *rule_locs)
1042 struct igc_adapter *adapter = netdev_priv(dev);
1043 int ret = -EOPNOTSUPP;
1045 switch (cmd->cmd) {
1046 case ETHTOOL_GRXRINGS:
1047 cmd->data = adapter->num_rx_queues;
1048 ret = 0;
1049 break;
1050 case ETHTOOL_GRXCLSRLCNT:
1051 cmd->rule_cnt = adapter->nfc_filter_count;
1052 ret = 0;
1053 break;
1054 case ETHTOOL_GRXCLSRULE:
1055 ret = igc_get_ethtool_nfc_entry(adapter, cmd);
1056 break;
1057 case ETHTOOL_GRXCLSRLALL:
1058 ret = igc_get_ethtool_nfc_all(adapter, cmd, rule_locs);
1059 break;
1060 case ETHTOOL_GRXFH:
1061 ret = igc_get_rss_hash_opts(adapter, cmd);
1062 break;
1063 default:
1064 break;
1067 return ret;
1070 #define UDP_RSS_FLAGS (IGC_FLAG_RSS_FIELD_IPV4_UDP | \
1071 IGC_FLAG_RSS_FIELD_IPV6_UDP)
1072 static int igc_set_rss_hash_opt(struct igc_adapter *adapter,
1073 struct ethtool_rxnfc *nfc)
1075 u32 flags = adapter->flags;
1077 /* RSS does not support anything other than hashing
1078 * to queues on src and dst IPs and ports
1080 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1081 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1082 return -EINVAL;
1084 switch (nfc->flow_type) {
1085 case TCP_V4_FLOW:
1086 case TCP_V6_FLOW:
1087 if (!(nfc->data & RXH_IP_SRC) ||
1088 !(nfc->data & RXH_IP_DST) ||
1089 !(nfc->data & RXH_L4_B_0_1) ||
1090 !(nfc->data & RXH_L4_B_2_3))
1091 return -EINVAL;
1092 break;
1093 case UDP_V4_FLOW:
1094 if (!(nfc->data & RXH_IP_SRC) ||
1095 !(nfc->data & RXH_IP_DST))
1096 return -EINVAL;
1097 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1098 case 0:
1099 flags &= ~IGC_FLAG_RSS_FIELD_IPV4_UDP;
1100 break;
1101 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1102 flags |= IGC_FLAG_RSS_FIELD_IPV4_UDP;
1103 break;
1104 default:
1105 return -EINVAL;
1107 break;
1108 case UDP_V6_FLOW:
1109 if (!(nfc->data & RXH_IP_SRC) ||
1110 !(nfc->data & RXH_IP_DST))
1111 return -EINVAL;
1112 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1113 case 0:
1114 flags &= ~IGC_FLAG_RSS_FIELD_IPV6_UDP;
1115 break;
1116 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1117 flags |= IGC_FLAG_RSS_FIELD_IPV6_UDP;
1118 break;
1119 default:
1120 return -EINVAL;
1122 break;
1123 case AH_ESP_V4_FLOW:
1124 case AH_V4_FLOW:
1125 case ESP_V4_FLOW:
1126 case SCTP_V4_FLOW:
1127 case AH_ESP_V6_FLOW:
1128 case AH_V6_FLOW:
1129 case ESP_V6_FLOW:
1130 case SCTP_V6_FLOW:
1131 if (!(nfc->data & RXH_IP_SRC) ||
1132 !(nfc->data & RXH_IP_DST) ||
1133 (nfc->data & RXH_L4_B_0_1) ||
1134 (nfc->data & RXH_L4_B_2_3))
1135 return -EINVAL;
1136 break;
1137 default:
1138 return -EINVAL;
1141 /* if we changed something we need to update flags */
1142 if (flags != adapter->flags) {
1143 struct igc_hw *hw = &adapter->hw;
1144 u32 mrqc = rd32(IGC_MRQC);
1146 if ((flags & UDP_RSS_FLAGS) &&
1147 !(adapter->flags & UDP_RSS_FLAGS))
1148 dev_err(&adapter->pdev->dev,
1149 "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
1151 adapter->flags = flags;
1153 /* Perform hash on these packet types */
1154 mrqc |= IGC_MRQC_RSS_FIELD_IPV4 |
1155 IGC_MRQC_RSS_FIELD_IPV4_TCP |
1156 IGC_MRQC_RSS_FIELD_IPV6 |
1157 IGC_MRQC_RSS_FIELD_IPV6_TCP;
1159 mrqc &= ~(IGC_MRQC_RSS_FIELD_IPV4_UDP |
1160 IGC_MRQC_RSS_FIELD_IPV6_UDP);
1162 if (flags & IGC_FLAG_RSS_FIELD_IPV4_UDP)
1163 mrqc |= IGC_MRQC_RSS_FIELD_IPV4_UDP;
1165 if (flags & IGC_FLAG_RSS_FIELD_IPV6_UDP)
1166 mrqc |= IGC_MRQC_RSS_FIELD_IPV6_UDP;
1168 wr32(IGC_MRQC, mrqc);
1171 return 0;
1174 static int igc_rxnfc_write_etype_filter(struct igc_adapter *adapter,
1175 struct igc_nfc_filter *input)
1177 struct igc_hw *hw = &adapter->hw;
1178 u8 i;
1179 u32 etqf;
1180 u16 etype;
1182 /* find an empty etype filter register */
1183 for (i = 0; i < MAX_ETYPE_FILTER; ++i) {
1184 if (!adapter->etype_bitmap[i])
1185 break;
1187 if (i == MAX_ETYPE_FILTER) {
1188 dev_err(&adapter->pdev->dev, "ethtool -N: etype filters are all used.\n");
1189 return -EINVAL;
1192 adapter->etype_bitmap[i] = true;
1194 etqf = rd32(IGC_ETQF(i));
1195 etype = ntohs(input->filter.etype & ETHER_TYPE_FULL_MASK);
1197 etqf |= IGC_ETQF_FILTER_ENABLE;
1198 etqf &= ~IGC_ETQF_ETYPE_MASK;
1199 etqf |= (etype & IGC_ETQF_ETYPE_MASK);
1201 etqf &= ~IGC_ETQF_QUEUE_MASK;
1202 etqf |= ((input->action << IGC_ETQF_QUEUE_SHIFT)
1203 & IGC_ETQF_QUEUE_MASK);
1204 etqf |= IGC_ETQF_QUEUE_ENABLE;
1206 wr32(IGC_ETQF(i), etqf);
1208 input->etype_reg_index = i;
1210 return 0;
1213 static int igc_rxnfc_write_vlan_prio_filter(struct igc_adapter *adapter,
1214 struct igc_nfc_filter *input)
1216 struct igc_hw *hw = &adapter->hw;
1217 u8 vlan_priority;
1218 u16 queue_index;
1219 u32 vlapqf;
1221 vlapqf = rd32(IGC_VLAPQF);
1222 vlan_priority = (ntohs(input->filter.vlan_tci) & VLAN_PRIO_MASK)
1223 >> VLAN_PRIO_SHIFT;
1224 queue_index = (vlapqf >> (vlan_priority * 4)) & IGC_VLAPQF_QUEUE_MASK;
1226 /* check whether this vlan prio is already set */
1227 if (vlapqf & IGC_VLAPQF_P_VALID(vlan_priority) &&
1228 queue_index != input->action) {
1229 dev_err(&adapter->pdev->dev, "ethtool rxnfc set vlan prio filter failed.\n");
1230 return -EEXIST;
1233 vlapqf |= IGC_VLAPQF_P_VALID(vlan_priority);
1234 vlapqf |= IGC_VLAPQF_QUEUE_SEL(vlan_priority, input->action);
1236 wr32(IGC_VLAPQF, vlapqf);
1238 return 0;
1241 int igc_add_filter(struct igc_adapter *adapter, struct igc_nfc_filter *input)
1243 struct igc_hw *hw = &adapter->hw;
1244 int err = -EINVAL;
1246 if (hw->mac.type == igc_i225 &&
1247 !(input->filter.match_flags & ~IGC_FILTER_FLAG_SRC_MAC_ADDR)) {
1248 dev_err(&adapter->pdev->dev,
1249 "i225 doesn't support flow classification rules specifying only source addresses.\n");
1250 return -EOPNOTSUPP;
1253 if (input->filter.match_flags & IGC_FILTER_FLAG_ETHER_TYPE) {
1254 err = igc_rxnfc_write_etype_filter(adapter, input);
1255 if (err)
1256 return err;
1259 if (input->filter.match_flags & IGC_FILTER_FLAG_DST_MAC_ADDR) {
1260 err = igc_add_mac_steering_filter(adapter,
1261 input->filter.dst_addr,
1262 input->action, 0);
1263 err = min_t(int, err, 0);
1264 if (err)
1265 return err;
1268 if (input->filter.match_flags & IGC_FILTER_FLAG_SRC_MAC_ADDR) {
1269 err = igc_add_mac_steering_filter(adapter,
1270 input->filter.src_addr,
1271 input->action,
1272 IGC_MAC_STATE_SRC_ADDR);
1273 err = min_t(int, err, 0);
1274 if (err)
1275 return err;
1278 if (input->filter.match_flags & IGC_FILTER_FLAG_VLAN_TCI)
1279 err = igc_rxnfc_write_vlan_prio_filter(adapter, input);
1281 return err;
1284 static void igc_clear_etype_filter_regs(struct igc_adapter *adapter,
1285 u16 reg_index)
1287 struct igc_hw *hw = &adapter->hw;
1288 u32 etqf = rd32(IGC_ETQF(reg_index));
1290 etqf &= ~IGC_ETQF_QUEUE_ENABLE;
1291 etqf &= ~IGC_ETQF_QUEUE_MASK;
1292 etqf &= ~IGC_ETQF_FILTER_ENABLE;
1294 wr32(IGC_ETQF(reg_index), etqf);
1296 adapter->etype_bitmap[reg_index] = false;
1299 static void igc_clear_vlan_prio_filter(struct igc_adapter *adapter,
1300 u16 vlan_tci)
1302 struct igc_hw *hw = &adapter->hw;
1303 u8 vlan_priority;
1304 u32 vlapqf;
1306 vlan_priority = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
1308 vlapqf = rd32(IGC_VLAPQF);
1309 vlapqf &= ~IGC_VLAPQF_P_VALID(vlan_priority);
1310 vlapqf &= ~IGC_VLAPQF_QUEUE_SEL(vlan_priority,
1311 IGC_VLAPQF_QUEUE_MASK);
1313 wr32(IGC_VLAPQF, vlapqf);
1316 int igc_erase_filter(struct igc_adapter *adapter, struct igc_nfc_filter *input)
1318 if (input->filter.match_flags & IGC_FILTER_FLAG_ETHER_TYPE)
1319 igc_clear_etype_filter_regs(adapter,
1320 input->etype_reg_index);
1322 if (input->filter.match_flags & IGC_FILTER_FLAG_VLAN_TCI)
1323 igc_clear_vlan_prio_filter(adapter,
1324 ntohs(input->filter.vlan_tci));
1326 if (input->filter.match_flags & IGC_FILTER_FLAG_SRC_MAC_ADDR)
1327 igc_del_mac_steering_filter(adapter, input->filter.src_addr,
1328 input->action,
1329 IGC_MAC_STATE_SRC_ADDR);
1331 if (input->filter.match_flags & IGC_FILTER_FLAG_DST_MAC_ADDR)
1332 igc_del_mac_steering_filter(adapter, input->filter.dst_addr,
1333 input->action, 0);
1335 return 0;
1338 static int igc_update_ethtool_nfc_entry(struct igc_adapter *adapter,
1339 struct igc_nfc_filter *input,
1340 u16 sw_idx)
1342 struct igc_nfc_filter *rule, *parent;
1343 int err = -EINVAL;
1345 parent = NULL;
1346 rule = NULL;
1348 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node) {
1349 /* hash found, or no matching entry */
1350 if (rule->sw_idx >= sw_idx)
1351 break;
1352 parent = rule;
1355 /* if there is an old rule occupying our place remove it */
1356 if (rule && rule->sw_idx == sw_idx) {
1357 if (!input)
1358 err = igc_erase_filter(adapter, rule);
1360 hlist_del(&rule->nfc_node);
1361 kfree(rule);
1362 adapter->nfc_filter_count--;
1365 /* If no input this was a delete, err should be 0 if a rule was
1366 * successfully found and removed from the list else -EINVAL
1368 if (!input)
1369 return err;
1371 /* initialize node */
1372 INIT_HLIST_NODE(&input->nfc_node);
1374 /* add filter to the list */
1375 if (parent)
1376 hlist_add_behind(&input->nfc_node, &parent->nfc_node);
1377 else
1378 hlist_add_head(&input->nfc_node, &adapter->nfc_filter_list);
1380 /* update counts */
1381 adapter->nfc_filter_count++;
1383 return 0;
1386 static int igc_add_ethtool_nfc_entry(struct igc_adapter *adapter,
1387 struct ethtool_rxnfc *cmd)
1389 struct net_device *netdev = adapter->netdev;
1390 struct ethtool_rx_flow_spec *fsp =
1391 (struct ethtool_rx_flow_spec *)&cmd->fs;
1392 struct igc_nfc_filter *input, *rule;
1393 int err = 0;
1395 if (!(netdev->hw_features & NETIF_F_NTUPLE))
1396 return -EOPNOTSUPP;
1398 /* Don't allow programming if the action is a queue greater than
1399 * the number of online Rx queues.
1401 if (fsp->ring_cookie == RX_CLS_FLOW_DISC ||
1402 fsp->ring_cookie >= adapter->num_rx_queues) {
1403 dev_err(&adapter->pdev->dev, "ethtool -N: The specified action is invalid\n");
1404 return -EINVAL;
1407 /* Don't allow indexes to exist outside of available space */
1408 if (fsp->location >= IGC_MAX_RXNFC_FILTERS) {
1409 dev_err(&adapter->pdev->dev, "Location out of range\n");
1410 return -EINVAL;
1413 if ((fsp->flow_type & ~FLOW_EXT) != ETHER_FLOW)
1414 return -EINVAL;
1416 input = kzalloc(sizeof(*input), GFP_KERNEL);
1417 if (!input)
1418 return -ENOMEM;
1420 if (fsp->m_u.ether_spec.h_proto == ETHER_TYPE_FULL_MASK) {
1421 input->filter.etype = fsp->h_u.ether_spec.h_proto;
1422 input->filter.match_flags = IGC_FILTER_FLAG_ETHER_TYPE;
1425 /* Only support matching addresses by the full mask */
1426 if (is_broadcast_ether_addr(fsp->m_u.ether_spec.h_source)) {
1427 input->filter.match_flags |= IGC_FILTER_FLAG_SRC_MAC_ADDR;
1428 ether_addr_copy(input->filter.src_addr,
1429 fsp->h_u.ether_spec.h_source);
1432 /* Only support matching addresses by the full mask */
1433 if (is_broadcast_ether_addr(fsp->m_u.ether_spec.h_dest)) {
1434 input->filter.match_flags |= IGC_FILTER_FLAG_DST_MAC_ADDR;
1435 ether_addr_copy(input->filter.dst_addr,
1436 fsp->h_u.ether_spec.h_dest);
1439 if ((fsp->flow_type & FLOW_EXT) && fsp->m_ext.vlan_tci) {
1440 if (fsp->m_ext.vlan_tci != htons(VLAN_PRIO_MASK)) {
1441 err = -EINVAL;
1442 goto err_out;
1444 input->filter.vlan_tci = fsp->h_ext.vlan_tci;
1445 input->filter.match_flags |= IGC_FILTER_FLAG_VLAN_TCI;
1448 input->action = fsp->ring_cookie;
1449 input->sw_idx = fsp->location;
1451 spin_lock(&adapter->nfc_lock);
1453 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node) {
1454 if (!memcmp(&input->filter, &rule->filter,
1455 sizeof(input->filter))) {
1456 err = -EEXIST;
1457 dev_err(&adapter->pdev->dev,
1458 "ethtool: this filter is already set\n");
1459 goto err_out_w_lock;
1463 err = igc_add_filter(adapter, input);
1464 if (err)
1465 goto err_out_w_lock;
1467 igc_update_ethtool_nfc_entry(adapter, input, input->sw_idx);
1469 spin_unlock(&adapter->nfc_lock);
1470 return 0;
1472 err_out_w_lock:
1473 spin_unlock(&adapter->nfc_lock);
1474 err_out:
1475 kfree(input);
1476 return err;
1479 static int igc_del_ethtool_nfc_entry(struct igc_adapter *adapter,
1480 struct ethtool_rxnfc *cmd)
1482 struct ethtool_rx_flow_spec *fsp =
1483 (struct ethtool_rx_flow_spec *)&cmd->fs;
1484 int err;
1486 spin_lock(&adapter->nfc_lock);
1487 err = igc_update_ethtool_nfc_entry(adapter, NULL, fsp->location);
1488 spin_unlock(&adapter->nfc_lock);
1490 return err;
1493 static int igc_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
1495 struct igc_adapter *adapter = netdev_priv(dev);
1496 int ret = -EOPNOTSUPP;
1498 switch (cmd->cmd) {
1499 case ETHTOOL_SRXFH:
1500 ret = igc_set_rss_hash_opt(adapter, cmd);
1501 break;
1502 case ETHTOOL_SRXCLSRLINS:
1503 ret = igc_add_ethtool_nfc_entry(adapter, cmd);
1504 break;
1505 case ETHTOOL_SRXCLSRLDEL:
1506 ret = igc_del_ethtool_nfc_entry(adapter, cmd);
1507 default:
1508 break;
1511 return ret;
1514 void igc_write_rss_indir_tbl(struct igc_adapter *adapter)
1516 struct igc_hw *hw = &adapter->hw;
1517 u32 reg = IGC_RETA(0);
1518 u32 shift = 0;
1519 int i = 0;
1521 while (i < IGC_RETA_SIZE) {
1522 u32 val = 0;
1523 int j;
1525 for (j = 3; j >= 0; j--) {
1526 val <<= 8;
1527 val |= adapter->rss_indir_tbl[i + j];
1530 wr32(reg, val << shift);
1531 reg += 4;
1532 i += 4;
1536 static u32 igc_get_rxfh_indir_size(struct net_device *netdev)
1538 return IGC_RETA_SIZE;
1541 static int igc_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
1542 u8 *hfunc)
1544 struct igc_adapter *adapter = netdev_priv(netdev);
1545 int i;
1547 if (hfunc)
1548 *hfunc = ETH_RSS_HASH_TOP;
1549 if (!indir)
1550 return 0;
1551 for (i = 0; i < IGC_RETA_SIZE; i++)
1552 indir[i] = adapter->rss_indir_tbl[i];
1554 return 0;
1557 static int igc_set_rxfh(struct net_device *netdev, const u32 *indir,
1558 const u8 *key, const u8 hfunc)
1560 struct igc_adapter *adapter = netdev_priv(netdev);
1561 u32 num_queues;
1562 int i;
1564 /* We do not allow change in unsupported parameters */
1565 if (key ||
1566 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1567 return -EOPNOTSUPP;
1568 if (!indir)
1569 return 0;
1571 num_queues = adapter->rss_queues;
1573 /* Verify user input. */
1574 for (i = 0; i < IGC_RETA_SIZE; i++)
1575 if (indir[i] >= num_queues)
1576 return -EINVAL;
1578 for (i = 0; i < IGC_RETA_SIZE; i++)
1579 adapter->rss_indir_tbl[i] = indir[i];
1581 igc_write_rss_indir_tbl(adapter);
1583 return 0;
1586 static unsigned int igc_max_channels(struct igc_adapter *adapter)
1588 return igc_get_max_rss_queues(adapter);
1591 static void igc_get_channels(struct net_device *netdev,
1592 struct ethtool_channels *ch)
1594 struct igc_adapter *adapter = netdev_priv(netdev);
1596 /* Report maximum channels */
1597 ch->max_combined = igc_max_channels(adapter);
1599 /* Report info for other vector */
1600 if (adapter->flags & IGC_FLAG_HAS_MSIX) {
1601 ch->max_other = NON_Q_VECTORS;
1602 ch->other_count = NON_Q_VECTORS;
1605 ch->combined_count = adapter->rss_queues;
1608 static int igc_set_channels(struct net_device *netdev,
1609 struct ethtool_channels *ch)
1611 struct igc_adapter *adapter = netdev_priv(netdev);
1612 unsigned int count = ch->combined_count;
1613 unsigned int max_combined = 0;
1615 /* Verify they are not requesting separate vectors */
1616 if (!count || ch->rx_count || ch->tx_count)
1617 return -EINVAL;
1619 /* Verify other_count is valid and has not been changed */
1620 if (ch->other_count != NON_Q_VECTORS)
1621 return -EINVAL;
1623 /* Verify the number of channels doesn't exceed hw limits */
1624 max_combined = igc_max_channels(adapter);
1625 if (count > max_combined)
1626 return -EINVAL;
1628 if (count != adapter->rss_queues) {
1629 adapter->rss_queues = count;
1630 igc_set_flag_queue_pairs(adapter, max_combined);
1632 /* Hardware has to reinitialize queues and interrupts to
1633 * match the new configuration.
1635 return igc_reinit_queues(adapter);
1638 return 0;
1641 static int igc_get_ts_info(struct net_device *dev,
1642 struct ethtool_ts_info *info)
1644 struct igc_adapter *adapter = netdev_priv(dev);
1646 if (adapter->ptp_clock)
1647 info->phc_index = ptp_clock_index(adapter->ptp_clock);
1648 else
1649 info->phc_index = -1;
1651 switch (adapter->hw.mac.type) {
1652 case igc_i225:
1653 info->so_timestamping =
1654 SOF_TIMESTAMPING_TX_SOFTWARE |
1655 SOF_TIMESTAMPING_RX_SOFTWARE |
1656 SOF_TIMESTAMPING_SOFTWARE |
1657 SOF_TIMESTAMPING_TX_HARDWARE |
1658 SOF_TIMESTAMPING_RX_HARDWARE |
1659 SOF_TIMESTAMPING_RAW_HARDWARE;
1661 info->tx_types =
1662 BIT(HWTSTAMP_TX_OFF) |
1663 BIT(HWTSTAMP_TX_ON);
1665 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE);
1666 info->rx_filters |= BIT(HWTSTAMP_FILTER_ALL);
1668 return 0;
1669 default:
1670 return -EOPNOTSUPP;
1674 static u32 igc_get_priv_flags(struct net_device *netdev)
1676 struct igc_adapter *adapter = netdev_priv(netdev);
1677 u32 priv_flags = 0;
1679 if (adapter->flags & IGC_FLAG_RX_LEGACY)
1680 priv_flags |= IGC_PRIV_FLAGS_LEGACY_RX;
1682 return priv_flags;
1685 static int igc_set_priv_flags(struct net_device *netdev, u32 priv_flags)
1687 struct igc_adapter *adapter = netdev_priv(netdev);
1688 unsigned int flags = adapter->flags;
1690 flags &= ~IGC_FLAG_RX_LEGACY;
1691 if (priv_flags & IGC_PRIV_FLAGS_LEGACY_RX)
1692 flags |= IGC_FLAG_RX_LEGACY;
1694 if (flags != adapter->flags) {
1695 adapter->flags = flags;
1697 /* reset interface to repopulate queues */
1698 if (netif_running(netdev))
1699 igc_reinit_locked(adapter);
1702 return 0;
1705 static int igc_ethtool_begin(struct net_device *netdev)
1707 struct igc_adapter *adapter = netdev_priv(netdev);
1709 pm_runtime_get_sync(&adapter->pdev->dev);
1710 return 0;
1713 static void igc_ethtool_complete(struct net_device *netdev)
1715 struct igc_adapter *adapter = netdev_priv(netdev);
1717 pm_runtime_put(&adapter->pdev->dev);
1720 static int igc_get_link_ksettings(struct net_device *netdev,
1721 struct ethtool_link_ksettings *cmd)
1723 struct igc_adapter *adapter = netdev_priv(netdev);
1724 struct igc_hw *hw = &adapter->hw;
1725 u32 status;
1726 u32 speed;
1728 ethtool_link_ksettings_zero_link_mode(cmd, supported);
1729 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
1731 /* supported link modes */
1732 ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Half);
1733 ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Full);
1734 ethtool_link_ksettings_add_link_mode(cmd, supported, 100baseT_Half);
1735 ethtool_link_ksettings_add_link_mode(cmd, supported, 100baseT_Full);
1736 ethtool_link_ksettings_add_link_mode(cmd, supported, 1000baseT_Full);
1737 ethtool_link_ksettings_add_link_mode(cmd, supported, 2500baseT_Full);
1739 /* twisted pair */
1740 cmd->base.port = PORT_TP;
1741 cmd->base.phy_address = hw->phy.addr;
1743 /* advertising link modes */
1744 ethtool_link_ksettings_add_link_mode(cmd, advertising, 10baseT_Half);
1745 ethtool_link_ksettings_add_link_mode(cmd, advertising, 10baseT_Full);
1746 ethtool_link_ksettings_add_link_mode(cmd, advertising, 100baseT_Half);
1747 ethtool_link_ksettings_add_link_mode(cmd, advertising, 100baseT_Full);
1748 ethtool_link_ksettings_add_link_mode(cmd, advertising, 1000baseT_Full);
1749 ethtool_link_ksettings_add_link_mode(cmd, advertising, 2500baseT_Full);
1751 /* set autoneg settings */
1752 if (hw->mac.autoneg == 1) {
1753 ethtool_link_ksettings_add_link_mode(cmd, supported, Autoneg);
1754 ethtool_link_ksettings_add_link_mode(cmd, advertising,
1755 Autoneg);
1758 switch (hw->fc.requested_mode) {
1759 case igc_fc_full:
1760 ethtool_link_ksettings_add_link_mode(cmd, advertising, Pause);
1761 break;
1762 case igc_fc_rx_pause:
1763 ethtool_link_ksettings_add_link_mode(cmd, advertising, Pause);
1764 ethtool_link_ksettings_add_link_mode(cmd, advertising,
1765 Asym_Pause);
1766 break;
1767 case igc_fc_tx_pause:
1768 ethtool_link_ksettings_add_link_mode(cmd, advertising,
1769 Asym_Pause);
1770 break;
1771 default:
1772 ethtool_link_ksettings_add_link_mode(cmd, advertising, Pause);
1773 ethtool_link_ksettings_add_link_mode(cmd, advertising,
1774 Asym_Pause);
1777 status = rd32(IGC_STATUS);
1779 if (status & IGC_STATUS_LU) {
1780 if (status & IGC_STATUS_SPEED_1000) {
1781 /* For I225, STATUS will indicate 1G speed in both
1782 * 1 Gbps and 2.5 Gbps link modes.
1783 * An additional bit is used
1784 * to differentiate between 1 Gbps and 2.5 Gbps.
1786 if (hw->mac.type == igc_i225 &&
1787 (status & IGC_STATUS_SPEED_2500)) {
1788 speed = SPEED_2500;
1789 } else {
1790 speed = SPEED_1000;
1792 } else if (status & IGC_STATUS_SPEED_100) {
1793 speed = SPEED_100;
1794 } else {
1795 speed = SPEED_10;
1797 if ((status & IGC_STATUS_FD) ||
1798 hw->phy.media_type != igc_media_type_copper)
1799 cmd->base.duplex = DUPLEX_FULL;
1800 else
1801 cmd->base.duplex = DUPLEX_HALF;
1802 } else {
1803 speed = SPEED_UNKNOWN;
1804 cmd->base.duplex = DUPLEX_UNKNOWN;
1806 cmd->base.speed = speed;
1807 if (hw->mac.autoneg)
1808 cmd->base.autoneg = AUTONEG_ENABLE;
1809 else
1810 cmd->base.autoneg = AUTONEG_DISABLE;
1812 /* MDI-X => 2; MDI =>1; Invalid =>0 */
1813 if (hw->phy.media_type == igc_media_type_copper)
1814 cmd->base.eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
1815 ETH_TP_MDI;
1816 else
1817 cmd->base.eth_tp_mdix = ETH_TP_MDI_INVALID;
1819 if (hw->phy.mdix == AUTO_ALL_MODES)
1820 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
1821 else
1822 cmd->base.eth_tp_mdix_ctrl = hw->phy.mdix;
1824 return 0;
1827 static int igc_set_link_ksettings(struct net_device *netdev,
1828 const struct ethtool_link_ksettings *cmd)
1830 struct igc_adapter *adapter = netdev_priv(netdev);
1831 struct igc_hw *hw = &adapter->hw;
1832 u32 advertising;
1834 /* When adapter in resetting mode, autoneg/speed/duplex
1835 * cannot be changed
1837 if (igc_check_reset_block(hw)) {
1838 dev_err(&adapter->pdev->dev,
1839 "Cannot change link characteristics when reset is active.\n");
1840 return -EINVAL;
1843 /* MDI setting is only allowed when autoneg enabled because
1844 * some hardware doesn't allow MDI setting when speed or
1845 * duplex is forced.
1847 if (cmd->base.eth_tp_mdix_ctrl) {
1848 if (cmd->base.eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO &&
1849 cmd->base.autoneg != AUTONEG_ENABLE) {
1850 dev_err(&adapter->pdev->dev, "forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
1851 return -EINVAL;
1855 while (test_and_set_bit(__IGC_RESETTING, &adapter->state))
1856 usleep_range(1000, 2000);
1858 ethtool_convert_link_mode_to_legacy_u32(&advertising,
1859 cmd->link_modes.advertising);
1861 if (cmd->base.autoneg == AUTONEG_ENABLE) {
1862 hw->mac.autoneg = 1;
1863 hw->phy.autoneg_advertised = advertising;
1864 if (adapter->fc_autoneg)
1865 hw->fc.requested_mode = igc_fc_default;
1866 } else {
1867 /* calling this overrides forced MDI setting */
1868 dev_info(&adapter->pdev->dev,
1869 "Force mode currently not supported\n");
1872 /* MDI-X => 2; MDI => 1; Auto => 3 */
1873 if (cmd->base.eth_tp_mdix_ctrl) {
1874 /* fix up the value for auto (3 => 0) as zero is mapped
1875 * internally to auto
1877 if (cmd->base.eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
1878 hw->phy.mdix = AUTO_ALL_MODES;
1879 else
1880 hw->phy.mdix = cmd->base.eth_tp_mdix_ctrl;
1883 /* reset the link */
1884 if (netif_running(adapter->netdev)) {
1885 igc_down(adapter);
1886 igc_up(adapter);
1887 } else {
1888 igc_reset(adapter);
1891 clear_bit(__IGC_RESETTING, &adapter->state);
1893 return 0;
1896 static const struct ethtool_ops igc_ethtool_ops = {
1897 .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
1898 .get_drvinfo = igc_get_drvinfo,
1899 .get_regs_len = igc_get_regs_len,
1900 .get_regs = igc_get_regs,
1901 .get_wol = igc_get_wol,
1902 .set_wol = igc_set_wol,
1903 .get_msglevel = igc_get_msglevel,
1904 .set_msglevel = igc_set_msglevel,
1905 .nway_reset = igc_nway_reset,
1906 .get_link = igc_get_link,
1907 .get_eeprom_len = igc_get_eeprom_len,
1908 .get_eeprom = igc_get_eeprom,
1909 .set_eeprom = igc_set_eeprom,
1910 .get_ringparam = igc_get_ringparam,
1911 .set_ringparam = igc_set_ringparam,
1912 .get_pauseparam = igc_get_pauseparam,
1913 .set_pauseparam = igc_set_pauseparam,
1914 .get_strings = igc_get_strings,
1915 .get_sset_count = igc_get_sset_count,
1916 .get_ethtool_stats = igc_get_ethtool_stats,
1917 .get_coalesce = igc_get_coalesce,
1918 .set_coalesce = igc_set_coalesce,
1919 .get_rxnfc = igc_get_rxnfc,
1920 .set_rxnfc = igc_set_rxnfc,
1921 .get_rxfh_indir_size = igc_get_rxfh_indir_size,
1922 .get_rxfh = igc_get_rxfh,
1923 .set_rxfh = igc_set_rxfh,
1924 .get_ts_info = igc_get_ts_info,
1925 .get_channels = igc_get_channels,
1926 .set_channels = igc_set_channels,
1927 .get_priv_flags = igc_get_priv_flags,
1928 .set_priv_flags = igc_set_priv_flags,
1929 .begin = igc_ethtool_begin,
1930 .complete = igc_ethtool_complete,
1931 .get_link_ksettings = igc_get_link_ksettings,
1932 .set_link_ksettings = igc_set_link_ksettings,
1935 void igc_set_ethtool_ops(struct net_device *netdev)
1937 netdev->ethtool_ops = &igc_ethtool_ops;