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>
7 #include <linux/mdio.h>
12 /* forward declaration */
14 char stat_string[ETH_GSTRING_LEN];
19 #define IGC_STAT(_name, _stat) { \
20 .stat_string = _name, \
21 .sizeof_stat = sizeof_field(struct igc_adapter, _stat), \
22 .stat_offset = offsetof(struct igc_adapter, _stat) \
25 static const struct igc_stats igc_gstrings_stats[] = {
26 IGC_STAT("rx_packets", stats.gprc),
27 IGC_STAT("tx_packets", stats.gptc),
28 IGC_STAT("rx_bytes", stats.gorc),
29 IGC_STAT("tx_bytes", stats.gotc),
30 IGC_STAT("rx_broadcast", stats.bprc),
31 IGC_STAT("tx_broadcast", stats.bptc),
32 IGC_STAT("rx_multicast", stats.mprc),
33 IGC_STAT("tx_multicast", stats.mptc),
34 IGC_STAT("multicast", stats.mprc),
35 IGC_STAT("collisions", stats.colc),
36 IGC_STAT("rx_crc_errors", stats.crcerrs),
37 IGC_STAT("rx_no_buffer_count", stats.rnbc),
38 IGC_STAT("rx_missed_errors", stats.mpc),
39 IGC_STAT("tx_aborted_errors", stats.ecol),
40 IGC_STAT("tx_carrier_errors", stats.tncrs),
41 IGC_STAT("tx_window_errors", stats.latecol),
42 IGC_STAT("tx_abort_late_coll", stats.latecol),
43 IGC_STAT("tx_deferred_ok", stats.dc),
44 IGC_STAT("tx_single_coll_ok", stats.scc),
45 IGC_STAT("tx_multi_coll_ok", stats.mcc),
46 IGC_STAT("tx_timeout_count", tx_timeout_count),
47 IGC_STAT("rx_long_length_errors", stats.roc),
48 IGC_STAT("rx_short_length_errors", stats.ruc),
49 IGC_STAT("rx_align_errors", stats.algnerrc),
50 IGC_STAT("tx_tcp_seg_good", stats.tsctc),
51 IGC_STAT("tx_tcp_seg_failed", stats.tsctfc),
52 IGC_STAT("rx_flow_control_xon", stats.xonrxc),
53 IGC_STAT("rx_flow_control_xoff", stats.xoffrxc),
54 IGC_STAT("tx_flow_control_xon", stats.xontxc),
55 IGC_STAT("tx_flow_control_xoff", stats.xofftxc),
56 IGC_STAT("rx_long_byte_count", stats.gorc),
57 IGC_STAT("tx_dma_out_of_sync", stats.doosync),
58 IGC_STAT("tx_smbus", stats.mgptc),
59 IGC_STAT("rx_smbus", stats.mgprc),
60 IGC_STAT("dropped_smbus", stats.mgpdc),
61 IGC_STAT("os2bmc_rx_by_bmc", stats.o2bgptc),
62 IGC_STAT("os2bmc_tx_by_bmc", stats.b2ospc),
63 IGC_STAT("os2bmc_tx_by_host", stats.o2bspc),
64 IGC_STAT("os2bmc_rx_by_host", stats.b2ogprc),
65 IGC_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
66 IGC_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped),
67 IGC_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
68 IGC_STAT("tx_lpi_counter", stats.tlpic),
69 IGC_STAT("rx_lpi_counter", stats.rlpic),
70 IGC_STAT("qbv_config_change_errors", qbv_config_change_errors),
73 #define IGC_NETDEV_STAT(_net_stat) { \
74 .stat_string = __stringify(_net_stat), \
75 .sizeof_stat = sizeof_field(struct rtnl_link_stats64, _net_stat), \
76 .stat_offset = offsetof(struct rtnl_link_stats64, _net_stat) \
79 static const struct igc_stats igc_gstrings_net_stats[] = {
80 IGC_NETDEV_STAT(rx_errors),
81 IGC_NETDEV_STAT(tx_errors),
82 IGC_NETDEV_STAT(tx_dropped),
83 IGC_NETDEV_STAT(rx_length_errors),
84 IGC_NETDEV_STAT(rx_over_errors),
85 IGC_NETDEV_STAT(rx_frame_errors),
86 IGC_NETDEV_STAT(rx_fifo_errors),
87 IGC_NETDEV_STAT(tx_fifo_errors),
88 IGC_NETDEV_STAT(tx_heartbeat_errors)
91 enum igc_diagnostics_results {
99 static const char igc_gstrings_test[][ETH_GSTRING_LEN] = {
100 [TEST_REG] = "Register test (offline)",
101 [TEST_EEP] = "Eeprom test (offline)",
102 [TEST_IRQ] = "Interrupt test (offline)",
103 [TEST_LOOP] = "Loopback test (offline)",
104 [TEST_LINK] = "Link test (on/offline)"
107 #define IGC_TEST_LEN (sizeof(igc_gstrings_test) / ETH_GSTRING_LEN)
109 #define IGC_GLOBAL_STATS_LEN \
110 (sizeof(igc_gstrings_stats) / sizeof(struct igc_stats))
111 #define IGC_NETDEV_STATS_LEN \
112 (sizeof(igc_gstrings_net_stats) / sizeof(struct igc_stats))
113 #define IGC_RX_QUEUE_STATS_LEN \
114 (sizeof(struct igc_rx_queue_stats) / sizeof(u64))
115 #define IGC_TX_QUEUE_STATS_LEN 3 /* packets, bytes, restart_queue */
116 #define IGC_QUEUE_STATS_LEN \
117 ((((struct igc_adapter *)netdev_priv(netdev))->num_rx_queues * \
118 IGC_RX_QUEUE_STATS_LEN) + \
119 (((struct igc_adapter *)netdev_priv(netdev))->num_tx_queues * \
120 IGC_TX_QUEUE_STATS_LEN))
121 #define IGC_STATS_LEN \
122 (IGC_GLOBAL_STATS_LEN + IGC_NETDEV_STATS_LEN + IGC_QUEUE_STATS_LEN)
124 static const char igc_priv_flags_strings[][ETH_GSTRING_LEN] = {
125 #define IGC_PRIV_FLAGS_LEGACY_RX BIT(0)
129 #define IGC_PRIV_FLAGS_STR_LEN ARRAY_SIZE(igc_priv_flags_strings)
131 static void igc_ethtool_get_drvinfo(struct net_device *netdev,
132 struct ethtool_drvinfo *drvinfo)
134 struct igc_adapter *adapter = netdev_priv(netdev);
135 struct igc_hw *hw = &adapter->hw;
139 strscpy(drvinfo->driver, igc_driver_name, sizeof(drvinfo->driver));
141 /* NVM image version is reported as firmware version for i225 device */
142 hw->nvm.ops.read(hw, IGC_NVM_DEV_STARTER, 1, &nvm_version);
144 /* gPHY firmware version is reported as PHY FW version */
145 gphy_version = igc_read_phy_fw_version(hw);
147 scnprintf(adapter->fw_version,
148 sizeof(adapter->fw_version),
153 strscpy(drvinfo->fw_version, adapter->fw_version,
154 sizeof(drvinfo->fw_version));
156 strscpy(drvinfo->bus_info, pci_name(adapter->pdev),
157 sizeof(drvinfo->bus_info));
159 drvinfo->n_priv_flags = IGC_PRIV_FLAGS_STR_LEN;
162 static int igc_ethtool_get_regs_len(struct net_device *netdev)
164 return IGC_REGS_LEN * sizeof(u32);
167 static void igc_ethtool_get_regs(struct net_device *netdev,
168 struct ethtool_regs *regs, void *p)
170 struct igc_adapter *adapter = netdev_priv(netdev);
171 struct igc_hw *hw = &adapter->hw;
175 memset(p, 0, IGC_REGS_LEN * sizeof(u32));
177 regs->version = (2u << 24) | (hw->revision_id << 16) | hw->device_id;
179 /* General Registers */
180 regs_buff[0] = rd32(IGC_CTRL);
181 regs_buff[1] = rd32(IGC_STATUS);
182 regs_buff[2] = rd32(IGC_CTRL_EXT);
183 regs_buff[3] = rd32(IGC_MDIC);
184 regs_buff[4] = rd32(IGC_CONNSW);
187 regs_buff[5] = rd32(IGC_EECD);
190 /* Reading EICS for EICR because they read the
191 * same but EICS does not clear on read
193 regs_buff[6] = rd32(IGC_EICS);
194 regs_buff[7] = rd32(IGC_EICS);
195 regs_buff[8] = rd32(IGC_EIMS);
196 regs_buff[9] = rd32(IGC_EIMC);
197 regs_buff[10] = rd32(IGC_EIAC);
198 regs_buff[11] = rd32(IGC_EIAM);
199 /* Reading ICS for ICR because they read the
200 * same but ICS does not clear on read
202 regs_buff[12] = rd32(IGC_ICS);
203 regs_buff[13] = rd32(IGC_ICS);
204 regs_buff[14] = rd32(IGC_IMS);
205 regs_buff[15] = rd32(IGC_IMC);
206 regs_buff[16] = rd32(IGC_IAC);
207 regs_buff[17] = rd32(IGC_IAM);
210 regs_buff[18] = rd32(IGC_FCAL);
211 regs_buff[19] = rd32(IGC_FCAH);
212 regs_buff[20] = rd32(IGC_FCTTV);
213 regs_buff[21] = rd32(IGC_FCRTL);
214 regs_buff[22] = rd32(IGC_FCRTH);
215 regs_buff[23] = rd32(IGC_FCRTV);
218 regs_buff[24] = rd32(IGC_RCTL);
219 regs_buff[25] = rd32(IGC_RXCSUM);
220 regs_buff[26] = rd32(IGC_RLPML);
221 regs_buff[27] = rd32(IGC_RFCTL);
224 regs_buff[28] = rd32(IGC_TCTL);
225 regs_buff[29] = rd32(IGC_TIPG);
232 regs_buff[30] = adapter->stats.crcerrs;
233 regs_buff[31] = adapter->stats.algnerrc;
234 regs_buff[32] = adapter->stats.symerrs;
235 regs_buff[33] = adapter->stats.rxerrc;
236 regs_buff[34] = adapter->stats.mpc;
237 regs_buff[35] = adapter->stats.scc;
238 regs_buff[36] = adapter->stats.ecol;
239 regs_buff[37] = adapter->stats.mcc;
240 regs_buff[38] = adapter->stats.latecol;
241 regs_buff[39] = adapter->stats.colc;
242 regs_buff[40] = adapter->stats.dc;
243 regs_buff[41] = adapter->stats.tncrs;
244 regs_buff[42] = adapter->stats.sec;
245 regs_buff[43] = adapter->stats.htdpmc;
246 regs_buff[44] = adapter->stats.rlec;
247 regs_buff[45] = adapter->stats.xonrxc;
248 regs_buff[46] = adapter->stats.xontxc;
249 regs_buff[47] = adapter->stats.xoffrxc;
250 regs_buff[48] = adapter->stats.xofftxc;
251 regs_buff[49] = adapter->stats.fcruc;
252 regs_buff[50] = adapter->stats.prc64;
253 regs_buff[51] = adapter->stats.prc127;
254 regs_buff[52] = adapter->stats.prc255;
255 regs_buff[53] = adapter->stats.prc511;
256 regs_buff[54] = adapter->stats.prc1023;
257 regs_buff[55] = adapter->stats.prc1522;
258 regs_buff[56] = adapter->stats.gprc;
259 regs_buff[57] = adapter->stats.bprc;
260 regs_buff[58] = adapter->stats.mprc;
261 regs_buff[59] = adapter->stats.gptc;
262 regs_buff[60] = adapter->stats.gorc;
263 regs_buff[61] = adapter->stats.gotc;
264 regs_buff[62] = adapter->stats.rnbc;
265 regs_buff[63] = adapter->stats.ruc;
266 regs_buff[64] = adapter->stats.rfc;
267 regs_buff[65] = adapter->stats.roc;
268 regs_buff[66] = adapter->stats.rjc;
269 regs_buff[67] = adapter->stats.mgprc;
270 regs_buff[68] = adapter->stats.mgpdc;
271 regs_buff[69] = adapter->stats.mgptc;
272 regs_buff[70] = adapter->stats.tor;
273 regs_buff[71] = adapter->stats.tot;
274 regs_buff[72] = adapter->stats.tpr;
275 regs_buff[73] = adapter->stats.tpt;
276 regs_buff[74] = adapter->stats.ptc64;
277 regs_buff[75] = adapter->stats.ptc127;
278 regs_buff[76] = adapter->stats.ptc255;
279 regs_buff[77] = adapter->stats.ptc511;
280 regs_buff[78] = adapter->stats.ptc1023;
281 regs_buff[79] = adapter->stats.ptc1522;
282 regs_buff[80] = adapter->stats.mptc;
283 regs_buff[81] = adapter->stats.bptc;
284 regs_buff[82] = adapter->stats.tsctc;
285 regs_buff[83] = adapter->stats.iac;
286 regs_buff[84] = adapter->stats.rpthc;
287 regs_buff[85] = adapter->stats.hgptc;
288 regs_buff[86] = adapter->stats.hgorc;
289 regs_buff[87] = adapter->stats.hgotc;
290 regs_buff[88] = adapter->stats.lenerrs;
291 regs_buff[89] = adapter->stats.scvpc;
292 regs_buff[90] = adapter->stats.hrmpc;
294 for (i = 0; i < 4; i++)
295 regs_buff[91 + i] = rd32(IGC_SRRCTL(i));
296 for (i = 0; i < 4; i++)
297 regs_buff[95 + i] = rd32(IGC_PSRTYPE(i));
298 for (i = 0; i < 4; i++)
299 regs_buff[99 + i] = rd32(IGC_RDBAL(i));
300 for (i = 0; i < 4; i++)
301 regs_buff[103 + i] = rd32(IGC_RDBAH(i));
302 for (i = 0; i < 4; i++)
303 regs_buff[107 + i] = rd32(IGC_RDLEN(i));
304 for (i = 0; i < 4; i++)
305 regs_buff[111 + i] = rd32(IGC_RDH(i));
306 for (i = 0; i < 4; i++)
307 regs_buff[115 + i] = rd32(IGC_RDT(i));
308 for (i = 0; i < 4; i++)
309 regs_buff[119 + i] = rd32(IGC_RXDCTL(i));
311 for (i = 0; i < 10; i++)
312 regs_buff[123 + i] = rd32(IGC_EITR(i));
313 for (i = 0; i < 16; i++)
314 regs_buff[139 + i] = rd32(IGC_RAL(i));
315 for (i = 0; i < 16; i++)
316 regs_buff[145 + i] = rd32(IGC_RAH(i));
318 for (i = 0; i < 4; i++)
319 regs_buff[149 + i] = rd32(IGC_TDBAL(i));
320 for (i = 0; i < 4; i++)
321 regs_buff[152 + i] = rd32(IGC_TDBAH(i));
322 for (i = 0; i < 4; i++)
323 regs_buff[156 + i] = rd32(IGC_TDLEN(i));
324 for (i = 0; i < 4; i++)
325 regs_buff[160 + i] = rd32(IGC_TDH(i));
326 for (i = 0; i < 4; i++)
327 regs_buff[164 + i] = rd32(IGC_TDT(i));
328 for (i = 0; i < 4; i++)
329 regs_buff[168 + i] = rd32(IGC_TXDCTL(i));
331 /* XXX: Due to a bug few lines above, RAL and RAH registers are
332 * overwritten. To preserve the ABI, we write these registers again in
335 for (i = 0; i < 16; i++)
336 regs_buff[172 + i] = rd32(IGC_RAL(i));
337 for (i = 0; i < 16; i++)
338 regs_buff[188 + i] = rd32(IGC_RAH(i));
340 regs_buff[204] = rd32(IGC_VLANPQF);
342 for (i = 0; i < 8; i++)
343 regs_buff[205 + i] = rd32(IGC_ETQF(i));
345 regs_buff[213] = adapter->stats.tlpic;
346 regs_buff[214] = adapter->stats.rlpic;
349 static void igc_ethtool_get_wol(struct net_device *netdev,
350 struct ethtool_wolinfo *wol)
352 struct igc_adapter *adapter = netdev_priv(netdev);
356 if (!(adapter->flags & IGC_FLAG_WOL_SUPPORTED))
359 wol->supported = WAKE_UCAST | WAKE_MCAST |
360 WAKE_BCAST | WAKE_MAGIC |
363 /* apply any specific unsupported masks here */
364 switch (adapter->hw.device_id) {
369 if (adapter->wol & IGC_WUFC_EX)
370 wol->wolopts |= WAKE_UCAST;
371 if (adapter->wol & IGC_WUFC_MC)
372 wol->wolopts |= WAKE_MCAST;
373 if (adapter->wol & IGC_WUFC_BC)
374 wol->wolopts |= WAKE_BCAST;
375 if (adapter->wol & IGC_WUFC_MAG)
376 wol->wolopts |= WAKE_MAGIC;
377 if (adapter->wol & IGC_WUFC_LNKC)
378 wol->wolopts |= WAKE_PHY;
381 static int igc_ethtool_set_wol(struct net_device *netdev,
382 struct ethtool_wolinfo *wol)
384 struct igc_adapter *adapter = netdev_priv(netdev);
386 if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE | WAKE_FILTER))
389 if (!(adapter->flags & IGC_FLAG_WOL_SUPPORTED))
390 return wol->wolopts ? -EOPNOTSUPP : 0;
392 /* these settings will always override what we currently have */
395 if (wol->wolopts & WAKE_UCAST)
396 adapter->wol |= IGC_WUFC_EX;
397 if (wol->wolopts & WAKE_MCAST)
398 adapter->wol |= IGC_WUFC_MC;
399 if (wol->wolopts & WAKE_BCAST)
400 adapter->wol |= IGC_WUFC_BC;
401 if (wol->wolopts & WAKE_MAGIC)
402 adapter->wol |= IGC_WUFC_MAG;
403 if (wol->wolopts & WAKE_PHY)
404 adapter->wol |= IGC_WUFC_LNKC;
405 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
410 static u32 igc_ethtool_get_msglevel(struct net_device *netdev)
412 struct igc_adapter *adapter = netdev_priv(netdev);
414 return adapter->msg_enable;
417 static void igc_ethtool_set_msglevel(struct net_device *netdev, u32 data)
419 struct igc_adapter *adapter = netdev_priv(netdev);
421 adapter->msg_enable = data;
424 static int igc_ethtool_nway_reset(struct net_device *netdev)
426 struct igc_adapter *adapter = netdev_priv(netdev);
428 if (netif_running(netdev))
429 igc_reinit_locked(adapter);
433 static u32 igc_ethtool_get_link(struct net_device *netdev)
435 struct igc_adapter *adapter = netdev_priv(netdev);
436 struct igc_mac_info *mac = &adapter->hw.mac;
438 /* If the link is not reported up to netdev, interrupts are disabled,
439 * and so the physical link state may have changed since we last
440 * looked. Set get_link_status to make sure that the true link
441 * state is interrogated, rather than pulling a cached and possibly
442 * stale link state from the driver.
444 if (!netif_carrier_ok(netdev))
445 mac->get_link_status = 1;
447 return igc_has_link(adapter);
450 static int igc_ethtool_get_eeprom_len(struct net_device *netdev)
452 struct igc_adapter *adapter = netdev_priv(netdev);
454 return adapter->hw.nvm.word_size * 2;
457 static int igc_ethtool_get_eeprom(struct net_device *netdev,
458 struct ethtool_eeprom *eeprom, u8 *bytes)
460 struct igc_adapter *adapter = netdev_priv(netdev);
461 struct igc_hw *hw = &adapter->hw;
462 int first_word, last_word;
467 if (eeprom->len == 0)
470 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
472 first_word = eeprom->offset >> 1;
473 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
475 eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16),
480 if (hw->nvm.type == igc_nvm_eeprom_spi) {
481 ret_val = hw->nvm.ops.read(hw, first_word,
482 last_word - first_word + 1,
485 for (i = 0; i < last_word - first_word + 1; i++) {
486 ret_val = hw->nvm.ops.read(hw, first_word + i, 1,
493 /* Device's eeprom is always little-endian, word addressable */
494 for (i = 0; i < last_word - first_word + 1; i++)
495 le16_to_cpus(&eeprom_buff[i]);
497 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
504 static int igc_ethtool_set_eeprom(struct net_device *netdev,
505 struct ethtool_eeprom *eeprom, u8 *bytes)
507 struct igc_adapter *adapter = netdev_priv(netdev);
508 struct igc_hw *hw = &adapter->hw;
509 int max_len, first_word, last_word, ret_val = 0;
514 if (eeprom->len == 0)
517 if (hw->mac.type >= igc_i225 &&
518 !igc_get_flash_presence_i225(hw)) {
522 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
525 max_len = hw->nvm.word_size * 2;
527 first_word = eeprom->offset >> 1;
528 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
529 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
533 ptr = (void *)eeprom_buff;
535 if (eeprom->offset & 1) {
536 /* need read/modify/write of first changed EEPROM word
537 * only the second byte of the word is being modified
539 ret_val = hw->nvm.ops.read(hw, first_word, 1,
543 if (((eeprom->offset + eeprom->len) & 1) && ret_val == 0) {
544 /* need read/modify/write of last changed EEPROM word
545 * only the first byte of the word is being modified
547 ret_val = hw->nvm.ops.read(hw, last_word, 1,
548 &eeprom_buff[last_word - first_word]);
551 /* Device's eeprom is always little-endian, word addressable */
552 for (i = 0; i < last_word - first_word + 1; i++)
553 le16_to_cpus(&eeprom_buff[i]);
555 memcpy(ptr, bytes, eeprom->len);
557 for (i = 0; i < last_word - first_word + 1; i++)
558 cpu_to_le16s(&eeprom_buff[i]);
560 ret_val = hw->nvm.ops.write(hw, first_word,
561 last_word - first_word + 1, eeprom_buff);
563 /* Update the checksum if nvm write succeeded */
565 hw->nvm.ops.update(hw);
572 igc_ethtool_get_ringparam(struct net_device *netdev,
573 struct ethtool_ringparam *ring,
574 struct kernel_ethtool_ringparam *kernel_ering,
575 struct netlink_ext_ack *extack)
577 struct igc_adapter *adapter = netdev_priv(netdev);
579 ring->rx_max_pending = IGC_MAX_RXD;
580 ring->tx_max_pending = IGC_MAX_TXD;
581 ring->rx_pending = adapter->rx_ring_count;
582 ring->tx_pending = adapter->tx_ring_count;
586 igc_ethtool_set_ringparam(struct net_device *netdev,
587 struct ethtool_ringparam *ring,
588 struct kernel_ethtool_ringparam *kernel_ering,
589 struct netlink_ext_ack *extack)
591 struct igc_adapter *adapter = netdev_priv(netdev);
592 struct igc_ring *temp_ring;
593 u16 new_rx_count, new_tx_count;
596 if (ring->rx_mini_pending || ring->rx_jumbo_pending)
599 new_rx_count = min_t(u32, ring->rx_pending, IGC_MAX_RXD);
600 new_rx_count = max_t(u16, new_rx_count, IGC_MIN_RXD);
601 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
603 new_tx_count = min_t(u32, ring->tx_pending, IGC_MAX_TXD);
604 new_tx_count = max_t(u16, new_tx_count, IGC_MIN_TXD);
605 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
607 if (new_tx_count == adapter->tx_ring_count &&
608 new_rx_count == adapter->rx_ring_count) {
613 while (test_and_set_bit(__IGC_RESETTING, &adapter->state))
614 usleep_range(1000, 2000);
616 if (!netif_running(adapter->netdev)) {
617 for (i = 0; i < adapter->num_tx_queues; i++)
618 adapter->tx_ring[i]->count = new_tx_count;
619 for (i = 0; i < adapter->num_rx_queues; i++)
620 adapter->rx_ring[i]->count = new_rx_count;
621 adapter->tx_ring_count = new_tx_count;
622 adapter->rx_ring_count = new_rx_count;
626 if (adapter->num_tx_queues > adapter->num_rx_queues)
627 temp_ring = vmalloc(array_size(sizeof(struct igc_ring),
628 adapter->num_tx_queues));
630 temp_ring = vmalloc(array_size(sizeof(struct igc_ring),
631 adapter->num_rx_queues));
640 /* We can't just free everything and then setup again,
641 * because the ISRs in MSI-X mode get passed pointers
642 * to the Tx and Rx ring structs.
644 if (new_tx_count != adapter->tx_ring_count) {
645 for (i = 0; i < adapter->num_tx_queues; i++) {
646 memcpy(&temp_ring[i], adapter->tx_ring[i],
647 sizeof(struct igc_ring));
649 temp_ring[i].count = new_tx_count;
650 err = igc_setup_tx_resources(&temp_ring[i]);
654 igc_free_tx_resources(&temp_ring[i]);
660 for (i = 0; i < adapter->num_tx_queues; i++) {
661 igc_free_tx_resources(adapter->tx_ring[i]);
663 memcpy(adapter->tx_ring[i], &temp_ring[i],
664 sizeof(struct igc_ring));
667 adapter->tx_ring_count = new_tx_count;
670 if (new_rx_count != adapter->rx_ring_count) {
671 for (i = 0; i < adapter->num_rx_queues; i++) {
672 memcpy(&temp_ring[i], adapter->rx_ring[i],
673 sizeof(struct igc_ring));
675 temp_ring[i].count = new_rx_count;
676 err = igc_setup_rx_resources(&temp_ring[i]);
680 igc_free_rx_resources(&temp_ring[i]);
686 for (i = 0; i < adapter->num_rx_queues; i++) {
687 igc_free_rx_resources(adapter->rx_ring[i]);
689 memcpy(adapter->rx_ring[i], &temp_ring[i],
690 sizeof(struct igc_ring));
693 adapter->rx_ring_count = new_rx_count;
699 clear_bit(__IGC_RESETTING, &adapter->state);
703 static void igc_ethtool_get_pauseparam(struct net_device *netdev,
704 struct ethtool_pauseparam *pause)
706 struct igc_adapter *adapter = netdev_priv(netdev);
707 struct igc_hw *hw = &adapter->hw;
710 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
712 if (hw->fc.current_mode == igc_fc_rx_pause) {
714 } else if (hw->fc.current_mode == igc_fc_tx_pause) {
716 } else if (hw->fc.current_mode == igc_fc_full) {
722 static int igc_ethtool_set_pauseparam(struct net_device *netdev,
723 struct ethtool_pauseparam *pause)
725 struct igc_adapter *adapter = netdev_priv(netdev);
726 struct igc_hw *hw = &adapter->hw;
729 adapter->fc_autoneg = pause->autoneg;
731 while (test_and_set_bit(__IGC_RESETTING, &adapter->state))
732 usleep_range(1000, 2000);
734 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
735 hw->fc.requested_mode = igc_fc_default;
736 if (netif_running(adapter->netdev)) {
743 if (pause->rx_pause && pause->tx_pause)
744 hw->fc.requested_mode = igc_fc_full;
745 else if (pause->rx_pause && !pause->tx_pause)
746 hw->fc.requested_mode = igc_fc_rx_pause;
747 else if (!pause->rx_pause && pause->tx_pause)
748 hw->fc.requested_mode = igc_fc_tx_pause;
749 else if (!pause->rx_pause && !pause->tx_pause)
750 hw->fc.requested_mode = igc_fc_none;
752 hw->fc.current_mode = hw->fc.requested_mode;
754 retval = ((hw->phy.media_type == igc_media_type_copper) ?
755 igc_force_mac_fc(hw) : igc_setup_link(hw));
758 clear_bit(__IGC_RESETTING, &adapter->state);
762 static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset,
765 struct igc_adapter *adapter = netdev_priv(netdev);
771 memcpy(data, *igc_gstrings_test,
772 IGC_TEST_LEN * ETH_GSTRING_LEN);
775 for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++)
776 ethtool_sprintf(&p, igc_gstrings_stats[i].stat_string);
777 for (i = 0; i < IGC_NETDEV_STATS_LEN; i++)
779 igc_gstrings_net_stats[i].stat_string);
780 for (i = 0; i < adapter->num_tx_queues; i++) {
781 ethtool_sprintf(&p, "tx_queue_%u_packets", i);
782 ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
783 ethtool_sprintf(&p, "tx_queue_%u_restart", i);
785 for (i = 0; i < adapter->num_rx_queues; i++) {
786 ethtool_sprintf(&p, "rx_queue_%u_packets", i);
787 ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
788 ethtool_sprintf(&p, "rx_queue_%u_drops", i);
789 ethtool_sprintf(&p, "rx_queue_%u_csum_err", i);
790 ethtool_sprintf(&p, "rx_queue_%u_alloc_failed", i);
792 /* BUG_ON(p - data != IGC_STATS_LEN * ETH_GSTRING_LEN); */
794 case ETH_SS_PRIV_FLAGS:
795 memcpy(data, igc_priv_flags_strings,
796 IGC_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
801 static int igc_ethtool_get_sset_count(struct net_device *netdev, int sset)
805 return IGC_STATS_LEN;
808 case ETH_SS_PRIV_FLAGS:
809 return IGC_PRIV_FLAGS_STR_LEN;
815 static void igc_ethtool_get_stats(struct net_device *netdev,
816 struct ethtool_stats *stats, u64 *data)
818 struct igc_adapter *adapter = netdev_priv(netdev);
819 struct rtnl_link_stats64 *net_stats = &adapter->stats64;
821 struct igc_ring *ring;
825 spin_lock(&adapter->stats64_lock);
826 igc_update_stats(adapter);
828 for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++) {
829 p = (char *)adapter + igc_gstrings_stats[i].stat_offset;
830 data[i] = (igc_gstrings_stats[i].sizeof_stat ==
831 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
833 for (j = 0; j < IGC_NETDEV_STATS_LEN; j++, i++) {
834 p = (char *)net_stats + igc_gstrings_net_stats[j].stat_offset;
835 data[i] = (igc_gstrings_net_stats[j].sizeof_stat ==
836 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
838 for (j = 0; j < adapter->num_tx_queues; j++) {
841 ring = adapter->tx_ring[j];
843 start = u64_stats_fetch_begin(&ring->tx_syncp);
844 data[i] = ring->tx_stats.packets;
845 data[i + 1] = ring->tx_stats.bytes;
846 data[i + 2] = ring->tx_stats.restart_queue;
847 } while (u64_stats_fetch_retry(&ring->tx_syncp, start));
849 start = u64_stats_fetch_begin(&ring->tx_syncp2);
850 restart2 = ring->tx_stats.restart_queue2;
851 } while (u64_stats_fetch_retry(&ring->tx_syncp2, start));
852 data[i + 2] += restart2;
854 i += IGC_TX_QUEUE_STATS_LEN;
856 for (j = 0; j < adapter->num_rx_queues; j++) {
857 ring = adapter->rx_ring[j];
859 start = u64_stats_fetch_begin(&ring->rx_syncp);
860 data[i] = ring->rx_stats.packets;
861 data[i + 1] = ring->rx_stats.bytes;
862 data[i + 2] = ring->rx_stats.drops;
863 data[i + 3] = ring->rx_stats.csum_err;
864 data[i + 4] = ring->rx_stats.alloc_failed;
865 } while (u64_stats_fetch_retry(&ring->rx_syncp, start));
866 i += IGC_RX_QUEUE_STATS_LEN;
868 spin_unlock(&adapter->stats64_lock);
871 static int igc_ethtool_get_previous_rx_coalesce(struct igc_adapter *adapter)
873 return (adapter->rx_itr_setting <= 3) ?
874 adapter->rx_itr_setting : adapter->rx_itr_setting >> 2;
877 static int igc_ethtool_get_previous_tx_coalesce(struct igc_adapter *adapter)
879 return (adapter->tx_itr_setting <= 3) ?
880 adapter->tx_itr_setting : adapter->tx_itr_setting >> 2;
883 static int igc_ethtool_get_coalesce(struct net_device *netdev,
884 struct ethtool_coalesce *ec,
885 struct kernel_ethtool_coalesce *kernel_coal,
886 struct netlink_ext_ack *extack)
888 struct igc_adapter *adapter = netdev_priv(netdev);
890 ec->rx_coalesce_usecs = igc_ethtool_get_previous_rx_coalesce(adapter);
891 ec->tx_coalesce_usecs = igc_ethtool_get_previous_tx_coalesce(adapter);
896 static int igc_ethtool_set_coalesce(struct net_device *netdev,
897 struct ethtool_coalesce *ec,
898 struct kernel_ethtool_coalesce *kernel_coal,
899 struct netlink_ext_ack *extack)
901 struct igc_adapter *adapter = netdev_priv(netdev);
904 if (ec->rx_coalesce_usecs > IGC_MAX_ITR_USECS ||
905 (ec->rx_coalesce_usecs > 3 &&
906 ec->rx_coalesce_usecs < IGC_MIN_ITR_USECS) ||
907 ec->rx_coalesce_usecs == 2)
910 if (ec->tx_coalesce_usecs > IGC_MAX_ITR_USECS ||
911 (ec->tx_coalesce_usecs > 3 &&
912 ec->tx_coalesce_usecs < IGC_MIN_ITR_USECS) ||
913 ec->tx_coalesce_usecs == 2)
916 if ((adapter->flags & IGC_FLAG_QUEUE_PAIRS) &&
917 ec->tx_coalesce_usecs != igc_ethtool_get_previous_tx_coalesce(adapter)) {
918 NL_SET_ERR_MSG_MOD(extack,
919 "Queue Pair mode enabled, both Rx and Tx coalescing controlled by rx-usecs");
923 /* If ITR is disabled, disable DMAC */
924 if (ec->rx_coalesce_usecs == 0) {
925 if (adapter->flags & IGC_FLAG_DMAC)
926 adapter->flags &= ~IGC_FLAG_DMAC;
929 /* convert to rate of irq's per second */
930 if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3)
931 adapter->rx_itr_setting = ec->rx_coalesce_usecs;
933 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
935 /* convert to rate of irq's per second */
936 if (adapter->flags & IGC_FLAG_QUEUE_PAIRS)
937 adapter->tx_itr_setting = adapter->rx_itr_setting;
938 else if (ec->tx_coalesce_usecs && ec->tx_coalesce_usecs <= 3)
939 adapter->tx_itr_setting = ec->tx_coalesce_usecs;
941 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
943 for (i = 0; i < adapter->num_q_vectors; i++) {
944 struct igc_q_vector *q_vector = adapter->q_vector[i];
946 q_vector->tx.work_limit = adapter->tx_work_limit;
947 if (q_vector->rx.ring)
948 q_vector->itr_val = adapter->rx_itr_setting;
950 q_vector->itr_val = adapter->tx_itr_setting;
951 if (q_vector->itr_val && q_vector->itr_val <= 3)
952 q_vector->itr_val = IGC_START_ITR;
953 q_vector->set_itr = 1;
959 #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
960 static int igc_ethtool_get_nfc_rule(struct igc_adapter *adapter,
961 struct ethtool_rxnfc *cmd)
963 struct ethtool_rx_flow_spec *fsp = &cmd->fs;
964 struct igc_nfc_rule *rule = NULL;
966 cmd->data = IGC_MAX_RXNFC_RULES;
968 mutex_lock(&adapter->nfc_rule_lock);
970 rule = igc_get_nfc_rule(adapter, fsp->location);
974 fsp->flow_type = ETHER_FLOW;
975 fsp->ring_cookie = rule->action;
977 if (rule->filter.match_flags & IGC_FILTER_FLAG_ETHER_TYPE) {
978 fsp->h_u.ether_spec.h_proto = htons(rule->filter.etype);
979 fsp->m_u.ether_spec.h_proto = ETHER_TYPE_FULL_MASK;
982 if (rule->filter.match_flags & IGC_FILTER_FLAG_VLAN_TCI) {
983 fsp->flow_type |= FLOW_EXT;
984 fsp->h_ext.vlan_tci = htons(rule->filter.vlan_tci);
985 fsp->m_ext.vlan_tci = htons(VLAN_PRIO_MASK);
988 if (rule->filter.match_flags & IGC_FILTER_FLAG_DST_MAC_ADDR) {
989 ether_addr_copy(fsp->h_u.ether_spec.h_dest,
990 rule->filter.dst_addr);
991 eth_broadcast_addr(fsp->m_u.ether_spec.h_dest);
994 if (rule->filter.match_flags & IGC_FILTER_FLAG_SRC_MAC_ADDR) {
995 ether_addr_copy(fsp->h_u.ether_spec.h_source,
996 rule->filter.src_addr);
997 eth_broadcast_addr(fsp->m_u.ether_spec.h_source);
1000 if (rule->filter.match_flags & IGC_FILTER_FLAG_USER_DATA) {
1001 fsp->flow_type |= FLOW_EXT;
1002 memcpy(fsp->h_ext.data, rule->filter.user_data, sizeof(fsp->h_ext.data));
1003 memcpy(fsp->m_ext.data, rule->filter.user_mask, sizeof(fsp->m_ext.data));
1006 mutex_unlock(&adapter->nfc_rule_lock);
1010 mutex_unlock(&adapter->nfc_rule_lock);
1014 static int igc_ethtool_get_nfc_rules(struct igc_adapter *adapter,
1015 struct ethtool_rxnfc *cmd,
1018 struct igc_nfc_rule *rule;
1021 cmd->data = IGC_MAX_RXNFC_RULES;
1023 mutex_lock(&adapter->nfc_rule_lock);
1025 list_for_each_entry(rule, &adapter->nfc_rule_list, list) {
1026 if (cnt == cmd->rule_cnt) {
1027 mutex_unlock(&adapter->nfc_rule_lock);
1030 rule_locs[cnt] = rule->location;
1034 mutex_unlock(&adapter->nfc_rule_lock);
1036 cmd->rule_cnt = cnt;
1041 static int igc_ethtool_get_rss_hash_opts(struct igc_adapter *adapter,
1042 struct ethtool_rxnfc *cmd)
1046 /* Report default options for RSS on igc */
1047 switch (cmd->flow_type) {
1049 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1052 if (adapter->flags & IGC_FLAG_RSS_FIELD_IPV4_UDP)
1053 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1056 case AH_ESP_V4_FLOW:
1060 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1063 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1066 if (adapter->flags & IGC_FLAG_RSS_FIELD_IPV6_UDP)
1067 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1070 case AH_ESP_V6_FLOW:
1074 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1083 static int igc_ethtool_get_rxnfc(struct net_device *dev,
1084 struct ethtool_rxnfc *cmd, u32 *rule_locs)
1086 struct igc_adapter *adapter = netdev_priv(dev);
1089 case ETHTOOL_GRXRINGS:
1090 cmd->data = adapter->num_rx_queues;
1092 case ETHTOOL_GRXCLSRLCNT:
1093 cmd->rule_cnt = adapter->nfc_rule_count;
1095 case ETHTOOL_GRXCLSRULE:
1096 return igc_ethtool_get_nfc_rule(adapter, cmd);
1097 case ETHTOOL_GRXCLSRLALL:
1098 return igc_ethtool_get_nfc_rules(adapter, cmd, rule_locs);
1100 return igc_ethtool_get_rss_hash_opts(adapter, cmd);
1106 #define UDP_RSS_FLAGS (IGC_FLAG_RSS_FIELD_IPV4_UDP | \
1107 IGC_FLAG_RSS_FIELD_IPV6_UDP)
1108 static int igc_ethtool_set_rss_hash_opt(struct igc_adapter *adapter,
1109 struct ethtool_rxnfc *nfc)
1111 u32 flags = adapter->flags;
1113 /* RSS does not support anything other than hashing
1114 * to queues on src and dst IPs and ports
1116 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1117 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1120 switch (nfc->flow_type) {
1123 if (!(nfc->data & RXH_IP_SRC) ||
1124 !(nfc->data & RXH_IP_DST) ||
1125 !(nfc->data & RXH_L4_B_0_1) ||
1126 !(nfc->data & RXH_L4_B_2_3))
1130 if (!(nfc->data & RXH_IP_SRC) ||
1131 !(nfc->data & RXH_IP_DST))
1133 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1135 flags &= ~IGC_FLAG_RSS_FIELD_IPV4_UDP;
1137 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1138 flags |= IGC_FLAG_RSS_FIELD_IPV4_UDP;
1145 if (!(nfc->data & RXH_IP_SRC) ||
1146 !(nfc->data & RXH_IP_DST))
1148 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1150 flags &= ~IGC_FLAG_RSS_FIELD_IPV6_UDP;
1152 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1153 flags |= IGC_FLAG_RSS_FIELD_IPV6_UDP;
1159 case AH_ESP_V4_FLOW:
1163 case AH_ESP_V6_FLOW:
1167 if (!(nfc->data & RXH_IP_SRC) ||
1168 !(nfc->data & RXH_IP_DST) ||
1169 (nfc->data & RXH_L4_B_0_1) ||
1170 (nfc->data & RXH_L4_B_2_3))
1177 /* if we changed something we need to update flags */
1178 if (flags != adapter->flags) {
1179 struct igc_hw *hw = &adapter->hw;
1180 u32 mrqc = rd32(IGC_MRQC);
1182 if ((flags & UDP_RSS_FLAGS) &&
1183 !(adapter->flags & UDP_RSS_FLAGS))
1184 netdev_err(adapter->netdev,
1185 "Enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
1187 adapter->flags = flags;
1189 /* Perform hash on these packet types */
1190 mrqc |= IGC_MRQC_RSS_FIELD_IPV4 |
1191 IGC_MRQC_RSS_FIELD_IPV4_TCP |
1192 IGC_MRQC_RSS_FIELD_IPV6 |
1193 IGC_MRQC_RSS_FIELD_IPV6_TCP;
1195 mrqc &= ~(IGC_MRQC_RSS_FIELD_IPV4_UDP |
1196 IGC_MRQC_RSS_FIELD_IPV6_UDP);
1198 if (flags & IGC_FLAG_RSS_FIELD_IPV4_UDP)
1199 mrqc |= IGC_MRQC_RSS_FIELD_IPV4_UDP;
1201 if (flags & IGC_FLAG_RSS_FIELD_IPV6_UDP)
1202 mrqc |= IGC_MRQC_RSS_FIELD_IPV6_UDP;
1204 wr32(IGC_MRQC, mrqc);
1210 static void igc_ethtool_init_nfc_rule(struct igc_nfc_rule *rule,
1211 const struct ethtool_rx_flow_spec *fsp)
1213 INIT_LIST_HEAD(&rule->list);
1215 rule->action = fsp->ring_cookie;
1216 rule->location = fsp->location;
1218 if ((fsp->flow_type & FLOW_EXT) && fsp->m_ext.vlan_tci) {
1219 rule->filter.vlan_tci = ntohs(fsp->h_ext.vlan_tci);
1220 rule->filter.match_flags |= IGC_FILTER_FLAG_VLAN_TCI;
1223 if (fsp->m_u.ether_spec.h_proto == ETHER_TYPE_FULL_MASK) {
1224 rule->filter.etype = ntohs(fsp->h_u.ether_spec.h_proto);
1225 rule->filter.match_flags = IGC_FILTER_FLAG_ETHER_TYPE;
1228 /* Both source and destination address filters only support the full
1231 if (is_broadcast_ether_addr(fsp->m_u.ether_spec.h_source)) {
1232 rule->filter.match_flags |= IGC_FILTER_FLAG_SRC_MAC_ADDR;
1233 ether_addr_copy(rule->filter.src_addr,
1234 fsp->h_u.ether_spec.h_source);
1237 if (is_broadcast_ether_addr(fsp->m_u.ether_spec.h_dest)) {
1238 rule->filter.match_flags |= IGC_FILTER_FLAG_DST_MAC_ADDR;
1239 ether_addr_copy(rule->filter.dst_addr,
1240 fsp->h_u.ether_spec.h_dest);
1243 /* VLAN etype matching */
1244 if ((fsp->flow_type & FLOW_EXT) && fsp->h_ext.vlan_etype) {
1245 rule->filter.vlan_etype = fsp->h_ext.vlan_etype;
1246 rule->filter.match_flags |= IGC_FILTER_FLAG_VLAN_ETYPE;
1249 /* Check for user defined data */
1250 if ((fsp->flow_type & FLOW_EXT) &&
1251 (fsp->h_ext.data[0] || fsp->h_ext.data[1])) {
1252 rule->filter.match_flags |= IGC_FILTER_FLAG_USER_DATA;
1253 memcpy(rule->filter.user_data, fsp->h_ext.data, sizeof(fsp->h_ext.data));
1254 memcpy(rule->filter.user_mask, fsp->m_ext.data, sizeof(fsp->m_ext.data));
1257 /* When multiple filter options or user data or vlan etype is set, use a
1260 if ((rule->filter.match_flags & IGC_FILTER_FLAG_USER_DATA) ||
1261 (rule->filter.match_flags & IGC_FILTER_FLAG_VLAN_ETYPE) ||
1262 (rule->filter.match_flags & (rule->filter.match_flags - 1)))
1269 * igc_ethtool_check_nfc_rule() - Check if NFC rule is valid
1270 * @adapter: Pointer to adapter
1271 * @rule: Rule under evaluation
1273 * The driver doesn't support rules with multiple matches so if more than
1274 * one bit in filter flags is set, @rule is considered invalid.
1276 * Also, if there is already another rule with the same filter in a different
1277 * location, @rule is considered invalid.
1279 * Context: Expects adapter->nfc_rule_lock to be held by caller.
1281 * Return: 0 in case of success, negative errno code otherwise.
1283 static int igc_ethtool_check_nfc_rule(struct igc_adapter *adapter,
1284 struct igc_nfc_rule *rule)
1286 struct net_device *dev = adapter->netdev;
1287 u8 flags = rule->filter.match_flags;
1288 struct igc_nfc_rule *tmp;
1291 netdev_dbg(dev, "Rule with no match\n");
1295 list_for_each_entry(tmp, &adapter->nfc_rule_list, list) {
1296 if (!memcmp(&rule->filter, &tmp->filter,
1297 sizeof(rule->filter)) &&
1298 tmp->location != rule->location) {
1299 netdev_dbg(dev, "Rule already exists\n");
1307 static int igc_ethtool_add_nfc_rule(struct igc_adapter *adapter,
1308 struct ethtool_rxnfc *cmd)
1310 struct net_device *netdev = adapter->netdev;
1311 struct ethtool_rx_flow_spec *fsp =
1312 (struct ethtool_rx_flow_spec *)&cmd->fs;
1313 struct igc_nfc_rule *rule, *old_rule;
1316 if (!(netdev->hw_features & NETIF_F_NTUPLE)) {
1317 netdev_dbg(netdev, "N-tuple filters disabled\n");
1321 if ((fsp->flow_type & ~FLOW_EXT) != ETHER_FLOW) {
1322 netdev_dbg(netdev, "Only ethernet flow type is supported\n");
1326 if (fsp->ring_cookie >= adapter->num_rx_queues) {
1327 netdev_dbg(netdev, "Invalid action\n");
1331 if (fsp->location >= IGC_MAX_RXNFC_RULES) {
1332 netdev_dbg(netdev, "Invalid location\n");
1336 rule = kzalloc(sizeof(*rule), GFP_KERNEL);
1340 igc_ethtool_init_nfc_rule(rule, fsp);
1342 mutex_lock(&adapter->nfc_rule_lock);
1344 err = igc_ethtool_check_nfc_rule(adapter, rule);
1348 old_rule = igc_get_nfc_rule(adapter, fsp->location);
1350 igc_del_nfc_rule(adapter, old_rule);
1352 err = igc_add_nfc_rule(adapter, rule);
1356 mutex_unlock(&adapter->nfc_rule_lock);
1360 mutex_unlock(&adapter->nfc_rule_lock);
1365 static int igc_ethtool_del_nfc_rule(struct igc_adapter *adapter,
1366 struct ethtool_rxnfc *cmd)
1368 struct ethtool_rx_flow_spec *fsp =
1369 (struct ethtool_rx_flow_spec *)&cmd->fs;
1370 struct igc_nfc_rule *rule;
1372 mutex_lock(&adapter->nfc_rule_lock);
1374 rule = igc_get_nfc_rule(adapter, fsp->location);
1376 mutex_unlock(&adapter->nfc_rule_lock);
1380 igc_del_nfc_rule(adapter, rule);
1382 mutex_unlock(&adapter->nfc_rule_lock);
1386 static int igc_ethtool_set_rxnfc(struct net_device *dev,
1387 struct ethtool_rxnfc *cmd)
1389 struct igc_adapter *adapter = netdev_priv(dev);
1393 return igc_ethtool_set_rss_hash_opt(adapter, cmd);
1394 case ETHTOOL_SRXCLSRLINS:
1395 return igc_ethtool_add_nfc_rule(adapter, cmd);
1396 case ETHTOOL_SRXCLSRLDEL:
1397 return igc_ethtool_del_nfc_rule(adapter, cmd);
1403 void igc_write_rss_indir_tbl(struct igc_adapter *adapter)
1405 struct igc_hw *hw = &adapter->hw;
1406 u32 reg = IGC_RETA(0);
1410 while (i < IGC_RETA_SIZE) {
1414 for (j = 3; j >= 0; j--) {
1416 val |= adapter->rss_indir_tbl[i + j];
1419 wr32(reg, val << shift);
1425 static u32 igc_ethtool_get_rxfh_indir_size(struct net_device *netdev)
1427 return IGC_RETA_SIZE;
1430 static int igc_ethtool_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
1433 struct igc_adapter *adapter = netdev_priv(netdev);
1437 *hfunc = ETH_RSS_HASH_TOP;
1440 for (i = 0; i < IGC_RETA_SIZE; i++)
1441 indir[i] = adapter->rss_indir_tbl[i];
1446 static int igc_ethtool_set_rxfh(struct net_device *netdev, const u32 *indir,
1447 const u8 *key, const u8 hfunc)
1449 struct igc_adapter *adapter = netdev_priv(netdev);
1453 /* We do not allow change in unsupported parameters */
1455 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1460 num_queues = adapter->rss_queues;
1462 /* Verify user input. */
1463 for (i = 0; i < IGC_RETA_SIZE; i++)
1464 if (indir[i] >= num_queues)
1467 for (i = 0; i < IGC_RETA_SIZE; i++)
1468 adapter->rss_indir_tbl[i] = indir[i];
1470 igc_write_rss_indir_tbl(adapter);
1475 static void igc_ethtool_get_channels(struct net_device *netdev,
1476 struct ethtool_channels *ch)
1478 struct igc_adapter *adapter = netdev_priv(netdev);
1480 /* Report maximum channels */
1481 ch->max_combined = igc_get_max_rss_queues(adapter);
1483 /* Report info for other vector */
1484 if (adapter->flags & IGC_FLAG_HAS_MSIX) {
1485 ch->max_other = NON_Q_VECTORS;
1486 ch->other_count = NON_Q_VECTORS;
1489 ch->combined_count = adapter->rss_queues;
1492 static int igc_ethtool_set_channels(struct net_device *netdev,
1493 struct ethtool_channels *ch)
1495 struct igc_adapter *adapter = netdev_priv(netdev);
1496 unsigned int count = ch->combined_count;
1497 unsigned int max_combined = 0;
1499 /* Verify they are not requesting separate vectors */
1500 if (!count || ch->rx_count || ch->tx_count)
1503 /* Verify other_count is valid and has not been changed */
1504 if (ch->other_count != NON_Q_VECTORS)
1507 /* Verify the number of channels doesn't exceed hw limits */
1508 max_combined = igc_get_max_rss_queues(adapter);
1509 if (count > max_combined)
1512 if (count != adapter->rss_queues) {
1513 adapter->rss_queues = count;
1514 igc_set_flag_queue_pairs(adapter, max_combined);
1516 /* Hardware has to reinitialize queues and interrupts to
1517 * match the new configuration.
1519 return igc_reinit_queues(adapter);
1525 static int igc_ethtool_get_ts_info(struct net_device *dev,
1526 struct ethtool_ts_info *info)
1528 struct igc_adapter *adapter = netdev_priv(dev);
1530 if (adapter->ptp_clock)
1531 info->phc_index = ptp_clock_index(adapter->ptp_clock);
1533 info->phc_index = -1;
1535 switch (adapter->hw.mac.type) {
1537 info->so_timestamping =
1538 SOF_TIMESTAMPING_TX_SOFTWARE |
1539 SOF_TIMESTAMPING_RX_SOFTWARE |
1540 SOF_TIMESTAMPING_SOFTWARE |
1541 SOF_TIMESTAMPING_TX_HARDWARE |
1542 SOF_TIMESTAMPING_RX_HARDWARE |
1543 SOF_TIMESTAMPING_RAW_HARDWARE;
1546 BIT(HWTSTAMP_TX_OFF) |
1547 BIT(HWTSTAMP_TX_ON);
1549 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE);
1550 info->rx_filters |= BIT(HWTSTAMP_FILTER_ALL);
1558 static u32 igc_ethtool_get_priv_flags(struct net_device *netdev)
1560 struct igc_adapter *adapter = netdev_priv(netdev);
1563 if (adapter->flags & IGC_FLAG_RX_LEGACY)
1564 priv_flags |= IGC_PRIV_FLAGS_LEGACY_RX;
1569 static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags)
1571 struct igc_adapter *adapter = netdev_priv(netdev);
1572 unsigned int flags = adapter->flags;
1574 flags &= ~IGC_FLAG_RX_LEGACY;
1575 if (priv_flags & IGC_PRIV_FLAGS_LEGACY_RX)
1576 flags |= IGC_FLAG_RX_LEGACY;
1578 if (flags != adapter->flags) {
1579 adapter->flags = flags;
1581 /* reset interface to repopulate queues */
1582 if (netif_running(netdev))
1583 igc_reinit_locked(adapter);
1589 static int igc_ethtool_get_eee(struct net_device *netdev,
1590 struct ethtool_eee *edata)
1592 struct igc_adapter *adapter = netdev_priv(netdev);
1593 struct igc_hw *hw = &adapter->hw;
1596 if (hw->dev_spec._base.eee_enable)
1598 mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
1600 *edata = adapter->eee;
1601 edata->supported = SUPPORTED_Autoneg;
1603 eeer = rd32(IGC_EEER);
1605 /* EEE status on negotiated link */
1606 if (eeer & IGC_EEER_EEE_NEG)
1607 edata->eee_active = true;
1609 if (eeer & IGC_EEER_TX_LPI_EN)
1610 edata->tx_lpi_enabled = true;
1612 edata->eee_enabled = hw->dev_spec._base.eee_enable;
1614 edata->advertised = SUPPORTED_Autoneg;
1615 edata->lp_advertised = SUPPORTED_Autoneg;
1617 /* Report correct negotiated EEE status for devices that
1618 * wrongly report EEE at half-duplex
1620 if (adapter->link_duplex == HALF_DUPLEX) {
1621 edata->eee_enabled = false;
1622 edata->eee_active = false;
1623 edata->tx_lpi_enabled = false;
1624 edata->advertised &= ~edata->advertised;
1630 static int igc_ethtool_set_eee(struct net_device *netdev,
1631 struct ethtool_eee *edata)
1633 struct igc_adapter *adapter = netdev_priv(netdev);
1634 struct igc_hw *hw = &adapter->hw;
1635 struct ethtool_eee eee_curr;
1638 memset(&eee_curr, 0, sizeof(struct ethtool_eee));
1640 ret_val = igc_ethtool_get_eee(netdev, &eee_curr);
1643 "Problem setting EEE advertisement options\n");
1647 if (eee_curr.eee_enabled) {
1648 if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
1650 "Setting EEE tx-lpi is not supported\n");
1654 /* Tx LPI timer is not implemented currently */
1655 if (edata->tx_lpi_timer) {
1657 "Setting EEE Tx LPI timer is not supported\n");
1660 } else if (!edata->eee_enabled) {
1662 "Setting EEE options are not supported with EEE disabled\n");
1666 adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
1667 if (hw->dev_spec._base.eee_enable != edata->eee_enabled) {
1668 hw->dev_spec._base.eee_enable = edata->eee_enabled;
1669 adapter->flags |= IGC_FLAG_EEE;
1672 if (netif_running(netdev))
1673 igc_reinit_locked(adapter);
1681 static int igc_ethtool_begin(struct net_device *netdev)
1683 struct igc_adapter *adapter = netdev_priv(netdev);
1685 pm_runtime_get_sync(&adapter->pdev->dev);
1689 static void igc_ethtool_complete(struct net_device *netdev)
1691 struct igc_adapter *adapter = netdev_priv(netdev);
1693 pm_runtime_put(&adapter->pdev->dev);
1696 static int igc_ethtool_get_link_ksettings(struct net_device *netdev,
1697 struct ethtool_link_ksettings *cmd)
1699 struct igc_adapter *adapter = netdev_priv(netdev);
1700 struct igc_hw *hw = &adapter->hw;
1704 ethtool_link_ksettings_zero_link_mode(cmd, supported);
1705 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
1707 /* supported link modes */
1708 ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Half);
1709 ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Full);
1710 ethtool_link_ksettings_add_link_mode(cmd, supported, 100baseT_Half);
1711 ethtool_link_ksettings_add_link_mode(cmd, supported, 100baseT_Full);
1712 ethtool_link_ksettings_add_link_mode(cmd, supported, 1000baseT_Full);
1713 ethtool_link_ksettings_add_link_mode(cmd, supported, 2500baseT_Full);
1716 cmd->base.port = PORT_TP;
1717 cmd->base.phy_address = hw->phy.addr;
1718 ethtool_link_ksettings_add_link_mode(cmd, supported, TP);
1719 ethtool_link_ksettings_add_link_mode(cmd, advertising, TP);
1721 /* advertising link modes */
1722 if (hw->phy.autoneg_advertised & ADVERTISE_10_HALF)
1723 ethtool_link_ksettings_add_link_mode(cmd, advertising, 10baseT_Half);
1724 if (hw->phy.autoneg_advertised & ADVERTISE_10_FULL)
1725 ethtool_link_ksettings_add_link_mode(cmd, advertising, 10baseT_Full);
1726 if (hw->phy.autoneg_advertised & ADVERTISE_100_HALF)
1727 ethtool_link_ksettings_add_link_mode(cmd, advertising, 100baseT_Half);
1728 if (hw->phy.autoneg_advertised & ADVERTISE_100_FULL)
1729 ethtool_link_ksettings_add_link_mode(cmd, advertising, 100baseT_Full);
1730 if (hw->phy.autoneg_advertised & ADVERTISE_1000_FULL)
1731 ethtool_link_ksettings_add_link_mode(cmd, advertising, 1000baseT_Full);
1732 if (hw->phy.autoneg_advertised & ADVERTISE_2500_FULL)
1733 ethtool_link_ksettings_add_link_mode(cmd, advertising, 2500baseT_Full);
1735 /* set autoneg settings */
1736 if (hw->mac.autoneg == 1) {
1737 ethtool_link_ksettings_add_link_mode(cmd, supported, Autoneg);
1738 ethtool_link_ksettings_add_link_mode(cmd, advertising,
1742 /* Set pause flow control settings */
1743 ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
1745 switch (hw->fc.requested_mode) {
1747 ethtool_link_ksettings_add_link_mode(cmd, advertising, Pause);
1749 case igc_fc_rx_pause:
1750 ethtool_link_ksettings_add_link_mode(cmd, advertising, Pause);
1751 ethtool_link_ksettings_add_link_mode(cmd, advertising,
1754 case igc_fc_tx_pause:
1755 ethtool_link_ksettings_add_link_mode(cmd, advertising,
1762 status = pm_runtime_suspended(&adapter->pdev->dev) ?
1763 0 : rd32(IGC_STATUS);
1765 if (status & IGC_STATUS_LU) {
1766 if (status & IGC_STATUS_SPEED_1000) {
1767 /* For I225, STATUS will indicate 1G speed in both
1768 * 1 Gbps and 2.5 Gbps link modes.
1769 * An additional bit is used
1770 * to differentiate between 1 Gbps and 2.5 Gbps.
1772 if (hw->mac.type == igc_i225 &&
1773 (status & IGC_STATUS_SPEED_2500)) {
1778 } else if (status & IGC_STATUS_SPEED_100) {
1783 if ((status & IGC_STATUS_FD) ||
1784 hw->phy.media_type != igc_media_type_copper)
1785 cmd->base.duplex = DUPLEX_FULL;
1787 cmd->base.duplex = DUPLEX_HALF;
1789 speed = SPEED_UNKNOWN;
1790 cmd->base.duplex = DUPLEX_UNKNOWN;
1792 cmd->base.speed = speed;
1793 if (hw->mac.autoneg)
1794 cmd->base.autoneg = AUTONEG_ENABLE;
1796 cmd->base.autoneg = AUTONEG_DISABLE;
1798 /* MDI-X => 2; MDI =>1; Invalid =>0 */
1799 if (hw->phy.media_type == igc_media_type_copper)
1800 cmd->base.eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
1803 cmd->base.eth_tp_mdix = ETH_TP_MDI_INVALID;
1805 if (hw->phy.mdix == AUTO_ALL_MODES)
1806 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
1808 cmd->base.eth_tp_mdix_ctrl = hw->phy.mdix;
1814 igc_ethtool_set_link_ksettings(struct net_device *netdev,
1815 const struct ethtool_link_ksettings *cmd)
1817 struct igc_adapter *adapter = netdev_priv(netdev);
1818 struct net_device *dev = adapter->netdev;
1819 struct igc_hw *hw = &adapter->hw;
1822 /* When adapter in resetting mode, autoneg/speed/duplex
1825 if (igc_check_reset_block(hw)) {
1826 netdev_err(dev, "Cannot change link characteristics when reset is active\n");
1830 /* MDI setting is only allowed when autoneg enabled because
1831 * some hardware doesn't allow MDI setting when speed or
1834 if (cmd->base.eth_tp_mdix_ctrl) {
1835 if (cmd->base.eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO &&
1836 cmd->base.autoneg != AUTONEG_ENABLE) {
1837 netdev_err(dev, "Forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
1842 while (test_and_set_bit(__IGC_RESETTING, &adapter->state))
1843 usleep_range(1000, 2000);
1845 if (ethtool_link_ksettings_test_link_mode(cmd, advertising,
1847 advertised |= ADVERTISE_2500_FULL;
1849 if (ethtool_link_ksettings_test_link_mode(cmd, advertising,
1851 advertised |= ADVERTISE_1000_FULL;
1853 if (ethtool_link_ksettings_test_link_mode(cmd, advertising,
1855 advertised |= ADVERTISE_100_FULL;
1857 if (ethtool_link_ksettings_test_link_mode(cmd, advertising,
1859 advertised |= ADVERTISE_100_HALF;
1861 if (ethtool_link_ksettings_test_link_mode(cmd, advertising,
1863 advertised |= ADVERTISE_10_FULL;
1865 if (ethtool_link_ksettings_test_link_mode(cmd, advertising,
1867 advertised |= ADVERTISE_10_HALF;
1869 if (cmd->base.autoneg == AUTONEG_ENABLE) {
1870 hw->mac.autoneg = 1;
1871 hw->phy.autoneg_advertised = advertised;
1872 if (adapter->fc_autoneg)
1873 hw->fc.requested_mode = igc_fc_default;
1875 netdev_info(dev, "Force mode currently not supported\n");
1878 /* MDI-X => 2; MDI => 1; Auto => 3 */
1879 if (cmd->base.eth_tp_mdix_ctrl) {
1880 /* fix up the value for auto (3 => 0) as zero is mapped
1881 * internally to auto
1883 if (cmd->base.eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
1884 hw->phy.mdix = AUTO_ALL_MODES;
1886 hw->phy.mdix = cmd->base.eth_tp_mdix_ctrl;
1889 /* reset the link */
1890 if (netif_running(adapter->netdev)) {
1897 clear_bit(__IGC_RESETTING, &adapter->state);
1902 static void igc_ethtool_diag_test(struct net_device *netdev,
1903 struct ethtool_test *eth_test, u64 *data)
1905 struct igc_adapter *adapter = netdev_priv(netdev);
1906 bool if_running = netif_running(netdev);
1908 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1909 netdev_info(adapter->netdev, "Offline testing starting");
1910 set_bit(__IGC_TESTING, &adapter->state);
1912 /* Link test performed before hardware reset so autoneg doesn't
1913 * interfere with test result
1915 if (!igc_link_test(adapter, &data[TEST_LINK]))
1916 eth_test->flags |= ETH_TEST_FL_FAILED;
1923 netdev_info(adapter->netdev, "Register testing starting");
1924 if (!igc_reg_test(adapter, &data[TEST_REG]))
1925 eth_test->flags |= ETH_TEST_FL_FAILED;
1929 netdev_info(adapter->netdev, "EEPROM testing starting");
1930 if (!igc_eeprom_test(adapter, &data[TEST_EEP]))
1931 eth_test->flags |= ETH_TEST_FL_FAILED;
1935 /* loopback and interrupt tests
1936 * will be implemented in the future
1938 data[TEST_LOOP] = 0;
1941 clear_bit(__IGC_TESTING, &adapter->state);
1945 netdev_info(adapter->netdev, "Online testing starting");
1947 /* register, eeprom, intr and loopback tests not run online */
1951 data[TEST_LOOP] = 0;
1953 if (!igc_link_test(adapter, &data[TEST_LINK]))
1954 eth_test->flags |= ETH_TEST_FL_FAILED;
1957 msleep_interruptible(4 * 1000);
1960 static const struct ethtool_ops igc_ethtool_ops = {
1961 .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
1962 .get_drvinfo = igc_ethtool_get_drvinfo,
1963 .get_regs_len = igc_ethtool_get_regs_len,
1964 .get_regs = igc_ethtool_get_regs,
1965 .get_wol = igc_ethtool_get_wol,
1966 .set_wol = igc_ethtool_set_wol,
1967 .get_msglevel = igc_ethtool_get_msglevel,
1968 .set_msglevel = igc_ethtool_set_msglevel,
1969 .nway_reset = igc_ethtool_nway_reset,
1970 .get_link = igc_ethtool_get_link,
1971 .get_eeprom_len = igc_ethtool_get_eeprom_len,
1972 .get_eeprom = igc_ethtool_get_eeprom,
1973 .set_eeprom = igc_ethtool_set_eeprom,
1974 .get_ringparam = igc_ethtool_get_ringparam,
1975 .set_ringparam = igc_ethtool_set_ringparam,
1976 .get_pauseparam = igc_ethtool_get_pauseparam,
1977 .set_pauseparam = igc_ethtool_set_pauseparam,
1978 .get_strings = igc_ethtool_get_strings,
1979 .get_sset_count = igc_ethtool_get_sset_count,
1980 .get_ethtool_stats = igc_ethtool_get_stats,
1981 .get_coalesce = igc_ethtool_get_coalesce,
1982 .set_coalesce = igc_ethtool_set_coalesce,
1983 .get_rxnfc = igc_ethtool_get_rxnfc,
1984 .set_rxnfc = igc_ethtool_set_rxnfc,
1985 .get_rxfh_indir_size = igc_ethtool_get_rxfh_indir_size,
1986 .get_rxfh = igc_ethtool_get_rxfh,
1987 .set_rxfh = igc_ethtool_set_rxfh,
1988 .get_ts_info = igc_ethtool_get_ts_info,
1989 .get_channels = igc_ethtool_get_channels,
1990 .set_channels = igc_ethtool_set_channels,
1991 .get_priv_flags = igc_ethtool_get_priv_flags,
1992 .set_priv_flags = igc_ethtool_set_priv_flags,
1993 .get_eee = igc_ethtool_get_eee,
1994 .set_eee = igc_ethtool_set_eee,
1995 .begin = igc_ethtool_begin,
1996 .complete = igc_ethtool_complete,
1997 .get_link_ksettings = igc_ethtool_get_link_ksettings,
1998 .set_link_ksettings = igc_ethtool_set_link_ksettings,
1999 .self_test = igc_ethtool_diag_test,
2002 void igc_ethtool_set_ops(struct net_device *netdev)
2004 netdev->ethtool_ops = &igc_ethtool_ops;