1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2018 Intel Corporation. */
4 /* ethtool support for ixgbevf */
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <linux/types.h>
9 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/pci.h>
12 #include <linux/netdevice.h>
13 #include <linux/ethtool.h>
14 #include <linux/vmalloc.h>
15 #include <linux/if_vlan.h>
16 #include <linux/uaccess.h>
20 #define IXGBE_ALL_RAR_ENTRIES 16
22 enum {NETDEV_STATS, IXGBEVF_STATS};
25 char stat_string[ETH_GSTRING_LEN];
31 #define IXGBEVF_STAT(_name, _stat) { \
32 .stat_string = _name, \
33 .type = IXGBEVF_STATS, \
34 .sizeof_stat = FIELD_SIZEOF(struct ixgbevf_adapter, _stat), \
35 .stat_offset = offsetof(struct ixgbevf_adapter, _stat) \
38 #define IXGBEVF_NETDEV_STAT(_net_stat) { \
39 .stat_string = #_net_stat, \
40 .type = NETDEV_STATS, \
41 .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \
42 .stat_offset = offsetof(struct net_device_stats, _net_stat) \
45 static struct ixgbe_stats ixgbevf_gstrings_stats[] = {
46 IXGBEVF_NETDEV_STAT(rx_packets),
47 IXGBEVF_NETDEV_STAT(tx_packets),
48 IXGBEVF_NETDEV_STAT(rx_bytes),
49 IXGBEVF_NETDEV_STAT(tx_bytes),
50 IXGBEVF_STAT("tx_busy", tx_busy),
51 IXGBEVF_STAT("tx_restart_queue", restart_queue),
52 IXGBEVF_STAT("tx_timeout_count", tx_timeout_count),
53 IXGBEVF_NETDEV_STAT(multicast),
54 IXGBEVF_STAT("rx_csum_offload_errors", hw_csum_rx_error),
55 IXGBEVF_STAT("alloc_rx_page", alloc_rx_page),
56 IXGBEVF_STAT("alloc_rx_page_failed", alloc_rx_page_failed),
57 IXGBEVF_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
58 IXGBEVF_STAT("tx_ipsec", tx_ipsec),
59 IXGBEVF_STAT("rx_ipsec", rx_ipsec),
62 #define IXGBEVF_QUEUE_STATS_LEN ( \
63 (((struct ixgbevf_adapter *)netdev_priv(netdev))->num_tx_queues + \
64 ((struct ixgbevf_adapter *)netdev_priv(netdev))->num_xdp_queues + \
65 ((struct ixgbevf_adapter *)netdev_priv(netdev))->num_rx_queues) * \
66 (sizeof(struct ixgbevf_stats) / sizeof(u64)))
67 #define IXGBEVF_GLOBAL_STATS_LEN ARRAY_SIZE(ixgbevf_gstrings_stats)
69 #define IXGBEVF_STATS_LEN (IXGBEVF_GLOBAL_STATS_LEN + IXGBEVF_QUEUE_STATS_LEN)
70 static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = {
71 "Register test (offline)",
72 "Link test (on/offline)"
75 #define IXGBEVF_TEST_LEN (sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN)
77 static const char ixgbevf_priv_flags_strings[][ETH_GSTRING_LEN] = {
78 #define IXGBEVF_PRIV_FLAGS_LEGACY_RX BIT(0)
82 #define IXGBEVF_PRIV_FLAGS_STR_LEN ARRAY_SIZE(ixgbevf_priv_flags_strings)
84 static int ixgbevf_get_link_ksettings(struct net_device *netdev,
85 struct ethtool_link_ksettings *cmd)
87 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
88 struct ixgbe_hw *hw = &adapter->hw;
92 ethtool_link_ksettings_zero_link_mode(cmd, supported);
93 ethtool_link_ksettings_add_link_mode(cmd, supported, 10000baseT_Full);
94 cmd->base.autoneg = AUTONEG_DISABLE;
97 hw->mac.get_link_status = 1;
98 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
101 __u32 speed = SPEED_10000;
103 switch (link_speed) {
104 case IXGBE_LINK_SPEED_10GB_FULL:
107 case IXGBE_LINK_SPEED_1GB_FULL:
110 case IXGBE_LINK_SPEED_100_FULL:
115 cmd->base.speed = speed;
116 cmd->base.duplex = DUPLEX_FULL;
118 cmd->base.speed = SPEED_UNKNOWN;
119 cmd->base.duplex = DUPLEX_UNKNOWN;
125 static u32 ixgbevf_get_msglevel(struct net_device *netdev)
127 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
129 return adapter->msg_enable;
132 static void ixgbevf_set_msglevel(struct net_device *netdev, u32 data)
134 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
136 adapter->msg_enable = data;
139 #define IXGBE_GET_STAT(_A_, _R_) (_A_->stats._R_)
141 static int ixgbevf_get_regs_len(struct net_device *netdev)
143 #define IXGBE_REGS_LEN 45
144 return IXGBE_REGS_LEN * sizeof(u32);
147 static void ixgbevf_get_regs(struct net_device *netdev,
148 struct ethtool_regs *regs,
151 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
152 struct ixgbe_hw *hw = &adapter->hw;
154 u32 regs_len = ixgbevf_get_regs_len(netdev);
157 memset(p, 0, regs_len);
159 /* generate a number suitable for ethtool's register version */
160 regs->version = (1u << 24) | (hw->revision_id << 16) | hw->device_id;
162 /* General Registers */
163 regs_buff[0] = IXGBE_READ_REG(hw, IXGBE_VFCTRL);
164 regs_buff[1] = IXGBE_READ_REG(hw, IXGBE_VFSTATUS);
165 regs_buff[2] = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
166 regs_buff[3] = IXGBE_READ_REG(hw, IXGBE_VFRXMEMWRAP);
167 regs_buff[4] = IXGBE_READ_REG(hw, IXGBE_VFFRTIMER);
170 /* don't read EICR because it can clear interrupt causes, instead
171 * read EICS which is a shadow but doesn't clear EICR
173 regs_buff[5] = IXGBE_READ_REG(hw, IXGBE_VTEICS);
174 regs_buff[6] = IXGBE_READ_REG(hw, IXGBE_VTEICS);
175 regs_buff[7] = IXGBE_READ_REG(hw, IXGBE_VTEIMS);
176 regs_buff[8] = IXGBE_READ_REG(hw, IXGBE_VTEIMC);
177 regs_buff[9] = IXGBE_READ_REG(hw, IXGBE_VTEIAC);
178 regs_buff[10] = IXGBE_READ_REG(hw, IXGBE_VTEIAM);
179 regs_buff[11] = IXGBE_READ_REG(hw, IXGBE_VTEITR(0));
180 regs_buff[12] = IXGBE_READ_REG(hw, IXGBE_VTIVAR(0));
181 regs_buff[13] = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
184 for (i = 0; i < 2; i++)
185 regs_buff[14 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDBAL(i));
186 for (i = 0; i < 2; i++)
187 regs_buff[16 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDBAH(i));
188 for (i = 0; i < 2; i++)
189 regs_buff[18 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDLEN(i));
190 for (i = 0; i < 2; i++)
191 regs_buff[20 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDH(i));
192 for (i = 0; i < 2; i++)
193 regs_buff[22 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDT(i));
194 for (i = 0; i < 2; i++)
195 regs_buff[24 + i] = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
196 for (i = 0; i < 2; i++)
197 regs_buff[26 + i] = IXGBE_READ_REG(hw, IXGBE_VFSRRCTL(i));
200 regs_buff[28] = IXGBE_READ_REG(hw, IXGBE_VFPSRTYPE);
203 for (i = 0; i < 2; i++)
204 regs_buff[29 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDBAL(i));
205 for (i = 0; i < 2; i++)
206 regs_buff[31 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDBAH(i));
207 for (i = 0; i < 2; i++)
208 regs_buff[33 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDLEN(i));
209 for (i = 0; i < 2; i++)
210 regs_buff[35 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDH(i));
211 for (i = 0; i < 2; i++)
212 regs_buff[37 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDT(i));
213 for (i = 0; i < 2; i++)
214 regs_buff[39 + i] = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
215 for (i = 0; i < 2; i++)
216 regs_buff[41 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDWBAL(i));
217 for (i = 0; i < 2; i++)
218 regs_buff[43 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDWBAH(i));
221 static void ixgbevf_get_drvinfo(struct net_device *netdev,
222 struct ethtool_drvinfo *drvinfo)
224 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
226 strlcpy(drvinfo->driver, ixgbevf_driver_name, sizeof(drvinfo->driver));
227 strlcpy(drvinfo->version, ixgbevf_driver_version,
228 sizeof(drvinfo->version));
229 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
230 sizeof(drvinfo->bus_info));
232 drvinfo->n_priv_flags = IXGBEVF_PRIV_FLAGS_STR_LEN;
235 static void ixgbevf_get_ringparam(struct net_device *netdev,
236 struct ethtool_ringparam *ring)
238 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
240 ring->rx_max_pending = IXGBEVF_MAX_RXD;
241 ring->tx_max_pending = IXGBEVF_MAX_TXD;
242 ring->rx_pending = adapter->rx_ring_count;
243 ring->tx_pending = adapter->tx_ring_count;
246 static int ixgbevf_set_ringparam(struct net_device *netdev,
247 struct ethtool_ringparam *ring)
249 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
250 struct ixgbevf_ring *tx_ring = NULL, *rx_ring = NULL;
251 u32 new_rx_count, new_tx_count;
254 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
257 new_tx_count = max_t(u32, ring->tx_pending, IXGBEVF_MIN_TXD);
258 new_tx_count = min_t(u32, new_tx_count, IXGBEVF_MAX_TXD);
259 new_tx_count = ALIGN(new_tx_count, IXGBE_REQ_TX_DESCRIPTOR_MULTIPLE);
261 new_rx_count = max_t(u32, ring->rx_pending, IXGBEVF_MIN_RXD);
262 new_rx_count = min_t(u32, new_rx_count, IXGBEVF_MAX_RXD);
263 new_rx_count = ALIGN(new_rx_count, IXGBE_REQ_RX_DESCRIPTOR_MULTIPLE);
265 /* if nothing to do return success */
266 if ((new_tx_count == adapter->tx_ring_count) &&
267 (new_rx_count == adapter->rx_ring_count))
270 while (test_and_set_bit(__IXGBEVF_RESETTING, &adapter->state))
271 usleep_range(1000, 2000);
273 if (!netif_running(adapter->netdev)) {
274 for (i = 0; i < adapter->num_tx_queues; i++)
275 adapter->tx_ring[i]->count = new_tx_count;
276 for (i = 0; i < adapter->num_xdp_queues; i++)
277 adapter->xdp_ring[i]->count = new_tx_count;
278 for (i = 0; i < adapter->num_rx_queues; i++)
279 adapter->rx_ring[i]->count = new_rx_count;
280 adapter->tx_ring_count = new_tx_count;
281 adapter->xdp_ring_count = new_tx_count;
282 adapter->rx_ring_count = new_rx_count;
286 if (new_tx_count != adapter->tx_ring_count) {
287 tx_ring = vmalloc(array_size(sizeof(*tx_ring),
288 adapter->num_tx_queues +
289 adapter->num_xdp_queues));
295 for (i = 0; i < adapter->num_tx_queues; i++) {
296 /* clone ring and setup updated count */
297 tx_ring[i] = *adapter->tx_ring[i];
298 tx_ring[i].count = new_tx_count;
299 err = ixgbevf_setup_tx_resources(&tx_ring[i]);
303 ixgbevf_free_tx_resources(&tx_ring[i]);
313 for (j = 0; j < adapter->num_xdp_queues; i++, j++) {
314 /* clone ring and setup updated count */
315 tx_ring[i] = *adapter->xdp_ring[j];
316 tx_ring[i].count = new_tx_count;
317 err = ixgbevf_setup_tx_resources(&tx_ring[i]);
321 ixgbevf_free_tx_resources(&tx_ring[i]);
332 if (new_rx_count != adapter->rx_ring_count) {
333 rx_ring = vmalloc(array_size(sizeof(*rx_ring),
334 adapter->num_rx_queues));
340 for (i = 0; i < adapter->num_rx_queues; i++) {
341 /* clone ring and setup updated count */
342 rx_ring[i] = *adapter->rx_ring[i];
344 /* Clear copied XDP RX-queue info */
345 memset(&rx_ring[i].xdp_rxq, 0,
346 sizeof(rx_ring[i].xdp_rxq));
348 rx_ring[i].count = new_rx_count;
349 err = ixgbevf_setup_rx_resources(adapter, &rx_ring[i]);
353 ixgbevf_free_rx_resources(&rx_ring[i]);
364 /* bring interface down to prepare for update */
365 ixgbevf_down(adapter);
369 for (i = 0; i < adapter->num_tx_queues; i++) {
370 ixgbevf_free_tx_resources(adapter->tx_ring[i]);
371 *adapter->tx_ring[i] = tx_ring[i];
373 adapter->tx_ring_count = new_tx_count;
375 for (j = 0; j < adapter->num_xdp_queues; i++, j++) {
376 ixgbevf_free_tx_resources(adapter->xdp_ring[j]);
377 *adapter->xdp_ring[j] = tx_ring[i];
379 adapter->xdp_ring_count = new_tx_count;
387 for (i = 0; i < adapter->num_rx_queues; i++) {
388 ixgbevf_free_rx_resources(adapter->rx_ring[i]);
389 *adapter->rx_ring[i] = rx_ring[i];
391 adapter->rx_ring_count = new_rx_count;
397 /* restore interface using new values */
401 /* free Tx resources if Rx error is encountered */
404 i < adapter->num_tx_queues + adapter->num_xdp_queues; i++)
405 ixgbevf_free_tx_resources(&tx_ring[i]);
409 clear_bit(__IXGBEVF_RESETTING, &adapter->state);
413 static int ixgbevf_get_sset_count(struct net_device *netdev, int stringset)
417 return IXGBEVF_TEST_LEN;
419 return IXGBEVF_STATS_LEN;
420 case ETH_SS_PRIV_FLAGS:
421 return IXGBEVF_PRIV_FLAGS_STR_LEN;
427 static void ixgbevf_get_ethtool_stats(struct net_device *netdev,
428 struct ethtool_stats *stats, u64 *data)
430 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
431 struct rtnl_link_stats64 temp;
432 const struct rtnl_link_stats64 *net_stats;
434 struct ixgbevf_ring *ring;
438 ixgbevf_update_stats(adapter);
439 net_stats = dev_get_stats(netdev, &temp);
440 for (i = 0; i < IXGBEVF_GLOBAL_STATS_LEN; i++) {
441 switch (ixgbevf_gstrings_stats[i].type) {
443 p = (char *)net_stats +
444 ixgbevf_gstrings_stats[i].stat_offset;
447 p = (char *)adapter +
448 ixgbevf_gstrings_stats[i].stat_offset;
455 data[i] = (ixgbevf_gstrings_stats[i].sizeof_stat ==
456 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
459 /* populate Tx queue data */
460 for (j = 0; j < adapter->num_tx_queues; j++) {
461 ring = adapter->tx_ring[j];
469 start = u64_stats_fetch_begin_irq(&ring->syncp);
470 data[i] = ring->stats.packets;
471 data[i + 1] = ring->stats.bytes;
472 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
476 /* populate XDP queue data */
477 for (j = 0; j < adapter->num_xdp_queues; j++) {
478 ring = adapter->xdp_ring[j];
486 start = u64_stats_fetch_begin_irq(&ring->syncp);
487 data[i] = ring->stats.packets;
488 data[i + 1] = ring->stats.bytes;
489 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
493 /* populate Rx queue data */
494 for (j = 0; j < adapter->num_rx_queues; j++) {
495 ring = adapter->rx_ring[j];
503 start = u64_stats_fetch_begin_irq(&ring->syncp);
504 data[i] = ring->stats.packets;
505 data[i + 1] = ring->stats.bytes;
506 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
511 static void ixgbevf_get_strings(struct net_device *netdev, u32 stringset,
514 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
515 char *p = (char *)data;
520 memcpy(data, *ixgbe_gstrings_test,
521 IXGBEVF_TEST_LEN * ETH_GSTRING_LEN);
524 for (i = 0; i < IXGBEVF_GLOBAL_STATS_LEN; i++) {
525 memcpy(p, ixgbevf_gstrings_stats[i].stat_string,
527 p += ETH_GSTRING_LEN;
530 for (i = 0; i < adapter->num_tx_queues; i++) {
531 sprintf(p, "tx_queue_%u_packets", i);
532 p += ETH_GSTRING_LEN;
533 sprintf(p, "tx_queue_%u_bytes", i);
534 p += ETH_GSTRING_LEN;
536 for (i = 0; i < adapter->num_xdp_queues; i++) {
537 sprintf(p, "xdp_queue_%u_packets", i);
538 p += ETH_GSTRING_LEN;
539 sprintf(p, "xdp_queue_%u_bytes", i);
540 p += ETH_GSTRING_LEN;
542 for (i = 0; i < adapter->num_rx_queues; i++) {
543 sprintf(p, "rx_queue_%u_packets", i);
544 p += ETH_GSTRING_LEN;
545 sprintf(p, "rx_queue_%u_bytes", i);
546 p += ETH_GSTRING_LEN;
549 case ETH_SS_PRIV_FLAGS:
550 memcpy(data, ixgbevf_priv_flags_strings,
551 IXGBEVF_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
556 static int ixgbevf_link_test(struct ixgbevf_adapter *adapter, u64 *data)
558 struct ixgbe_hw *hw = &adapter->hw;
563 hw->mac.ops.check_link(hw, &link_speed, &link_up, true);
570 /* ethtool register test data */
571 struct ixgbevf_reg_test {
579 /* In the hardware, registers are laid out either singly, in arrays
580 * spaced 0x40 bytes apart, or in contiguous tables. We assume
581 * most tests take place on arrays or single registers (handled
582 * as a single-element array) and special-case the tables.
583 * Table tests are always pattern tests.
585 * We also make provision for some required setup steps by specifying
586 * registers to be written without any read-back testing.
589 #define PATTERN_TEST 1
590 #define SET_READ_TEST 2
591 #define WRITE_NO_TEST 3
592 #define TABLE32_TEST 4
593 #define TABLE64_TEST_LO 5
594 #define TABLE64_TEST_HI 6
596 /* default VF register test */
597 static const struct ixgbevf_reg_test reg_test_vf[] = {
598 { IXGBE_VFRDBAL(0), 2, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFF80 },
599 { IXGBE_VFRDBAH(0), 2, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
600 { IXGBE_VFRDLEN(0), 2, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
601 { IXGBE_VFRXDCTL(0), 2, WRITE_NO_TEST, 0, IXGBE_RXDCTL_ENABLE },
602 { IXGBE_VFRDT(0), 2, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
603 { IXGBE_VFRXDCTL(0), 2, WRITE_NO_TEST, 0, 0 },
604 { IXGBE_VFTDBAL(0), 2, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
605 { IXGBE_VFTDBAH(0), 2, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
606 { IXGBE_VFTDLEN(0), 2, PATTERN_TEST, 0x000FFF80, 0x000FFF80 },
610 static const u32 register_test_patterns[] = {
611 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
614 static bool reg_pattern_test(struct ixgbevf_adapter *adapter, u64 *data,
615 int reg, u32 mask, u32 write)
617 u32 pat, val, before;
619 if (IXGBE_REMOVED(adapter->hw.hw_addr)) {
623 for (pat = 0; pat < ARRAY_SIZE(register_test_patterns); pat++) {
624 before = ixgbevf_read_reg(&adapter->hw, reg);
625 ixgbe_write_reg(&adapter->hw, reg,
626 register_test_patterns[pat] & write);
627 val = ixgbevf_read_reg(&adapter->hw, reg);
628 if (val != (register_test_patterns[pat] & write & mask)) {
630 "pattern test reg %04X failed: got 0x%08X expected 0x%08X\n",
632 register_test_patterns[pat] & write & mask);
634 ixgbe_write_reg(&adapter->hw, reg, before);
637 ixgbe_write_reg(&adapter->hw, reg, before);
642 static bool reg_set_and_check(struct ixgbevf_adapter *adapter, u64 *data,
643 int reg, u32 mask, u32 write)
647 if (IXGBE_REMOVED(adapter->hw.hw_addr)) {
651 before = ixgbevf_read_reg(&adapter->hw, reg);
652 ixgbe_write_reg(&adapter->hw, reg, write & mask);
653 val = ixgbevf_read_reg(&adapter->hw, reg);
654 if ((write & mask) != (val & mask)) {
655 pr_err("set/check reg %04X test failed: got 0x%08X expected 0x%08X\n",
656 reg, (val & mask), write & mask);
658 ixgbe_write_reg(&adapter->hw, reg, before);
661 ixgbe_write_reg(&adapter->hw, reg, before);
665 static int ixgbevf_reg_test(struct ixgbevf_adapter *adapter, u64 *data)
667 const struct ixgbevf_reg_test *test;
670 if (IXGBE_REMOVED(adapter->hw.hw_addr)) {
671 dev_err(&adapter->pdev->dev,
672 "Adapter removed - register test blocked\n");
678 /* Perform the register test, looping through the test table
679 * until we either fail or reach the null entry.
682 for (i = 0; i < test->array_len; i++) {
685 switch (test->test_type) {
687 b = reg_pattern_test(adapter, data,
688 test->reg + (i * 0x40),
693 b = reg_set_and_check(adapter, data,
694 test->reg + (i * 0x40),
699 ixgbe_write_reg(&adapter->hw,
700 test->reg + (i * 0x40),
704 b = reg_pattern_test(adapter, data,
709 case TABLE64_TEST_LO:
710 b = reg_pattern_test(adapter, data,
715 case TABLE64_TEST_HI:
716 b = reg_pattern_test(adapter, data,
717 test->reg + 4 + (i * 8),
732 static void ixgbevf_diag_test(struct net_device *netdev,
733 struct ethtool_test *eth_test, u64 *data)
735 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
736 bool if_running = netif_running(netdev);
738 if (IXGBE_REMOVED(adapter->hw.hw_addr)) {
739 dev_err(&adapter->pdev->dev,
740 "Adapter removed - test blocked\n");
743 eth_test->flags |= ETH_TEST_FL_FAILED;
746 set_bit(__IXGBEVF_TESTING, &adapter->state);
747 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
750 hw_dbg(&adapter->hw, "offline testing starting\n");
752 /* Link test performed before hardware reset so autoneg doesn't
753 * interfere with test result
755 if (ixgbevf_link_test(adapter, &data[1]))
756 eth_test->flags |= ETH_TEST_FL_FAILED;
759 /* indicate we're in test mode */
760 ixgbevf_close(netdev);
762 ixgbevf_reset(adapter);
764 hw_dbg(&adapter->hw, "register testing starting\n");
765 if (ixgbevf_reg_test(adapter, &data[0]))
766 eth_test->flags |= ETH_TEST_FL_FAILED;
768 ixgbevf_reset(adapter);
770 clear_bit(__IXGBEVF_TESTING, &adapter->state);
772 ixgbevf_open(netdev);
774 hw_dbg(&adapter->hw, "online testing starting\n");
776 if (ixgbevf_link_test(adapter, &data[1]))
777 eth_test->flags |= ETH_TEST_FL_FAILED;
779 /* Online tests aren't run; pass by default */
782 clear_bit(__IXGBEVF_TESTING, &adapter->state);
784 msleep_interruptible(4 * 1000);
787 static int ixgbevf_nway_reset(struct net_device *netdev)
789 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
791 if (netif_running(netdev))
792 ixgbevf_reinit_locked(adapter);
797 static int ixgbevf_get_coalesce(struct net_device *netdev,
798 struct ethtool_coalesce *ec)
800 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
802 /* only valid if in constant ITR mode */
803 if (adapter->rx_itr_setting <= 1)
804 ec->rx_coalesce_usecs = adapter->rx_itr_setting;
806 ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
808 /* if in mixed Tx/Rx queues per vector mode, report only Rx settings */
809 if (adapter->q_vector[0]->tx.count && adapter->q_vector[0]->rx.count)
812 /* only valid if in constant ITR mode */
813 if (adapter->tx_itr_setting <= 1)
814 ec->tx_coalesce_usecs = adapter->tx_itr_setting;
816 ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
821 static int ixgbevf_set_coalesce(struct net_device *netdev,
822 struct ethtool_coalesce *ec)
824 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
825 struct ixgbevf_q_vector *q_vector;
827 u16 tx_itr_param, rx_itr_param;
829 /* don't accept Tx specific changes if we've got mixed RxTx vectors */
830 if (adapter->q_vector[0]->tx.count &&
831 adapter->q_vector[0]->rx.count && ec->tx_coalesce_usecs)
834 if ((ec->rx_coalesce_usecs > (IXGBE_MAX_EITR >> 2)) ||
835 (ec->tx_coalesce_usecs > (IXGBE_MAX_EITR >> 2)))
838 if (ec->rx_coalesce_usecs > 1)
839 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
841 adapter->rx_itr_setting = ec->rx_coalesce_usecs;
843 if (adapter->rx_itr_setting == 1)
844 rx_itr_param = IXGBE_20K_ITR;
846 rx_itr_param = adapter->rx_itr_setting;
848 if (ec->tx_coalesce_usecs > 1)
849 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
851 adapter->tx_itr_setting = ec->tx_coalesce_usecs;
853 if (adapter->tx_itr_setting == 1)
854 tx_itr_param = IXGBE_12K_ITR;
856 tx_itr_param = adapter->tx_itr_setting;
858 num_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
860 for (i = 0; i < num_vectors; i++) {
861 q_vector = adapter->q_vector[i];
862 if (q_vector->tx.count && !q_vector->rx.count)
864 q_vector->itr = tx_itr_param;
866 /* Rx only or mixed */
867 q_vector->itr = rx_itr_param;
868 ixgbevf_write_eitr(q_vector);
874 static int ixgbevf_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
875 u32 *rules __always_unused)
877 struct ixgbevf_adapter *adapter = netdev_priv(dev);
880 case ETHTOOL_GRXRINGS:
881 info->data = adapter->num_rx_queues;
884 hw_dbg(&adapter->hw, "Command parameters not supported\n");
889 static u32 ixgbevf_get_rxfh_indir_size(struct net_device *netdev)
891 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
893 if (adapter->hw.mac.type >= ixgbe_mac_X550_vf)
894 return IXGBEVF_X550_VFRETA_SIZE;
896 return IXGBEVF_82599_RETA_SIZE;
899 static u32 ixgbevf_get_rxfh_key_size(struct net_device *netdev)
901 return IXGBEVF_RSS_HASH_KEY_SIZE;
904 static int ixgbevf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
907 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
911 *hfunc = ETH_RSS_HASH_TOP;
913 if (adapter->hw.mac.type >= ixgbe_mac_X550_vf) {
915 memcpy(key, adapter->rss_key,
916 ixgbevf_get_rxfh_key_size(netdev));
921 for (i = 0; i < IXGBEVF_X550_VFRETA_SIZE; i++)
922 indir[i] = adapter->rss_indir_tbl[i];
925 /* If neither indirection table nor hash key was requested
926 * - just return a success avoiding taking any locks.
931 spin_lock_bh(&adapter->mbx_lock);
933 err = ixgbevf_get_reta_locked(&adapter->hw, indir,
934 adapter->num_rx_queues);
937 err = ixgbevf_get_rss_key_locked(&adapter->hw, key);
939 spin_unlock_bh(&adapter->mbx_lock);
945 static u32 ixgbevf_get_priv_flags(struct net_device *netdev)
947 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
950 if (adapter->flags & IXGBEVF_FLAGS_LEGACY_RX)
951 priv_flags |= IXGBEVF_PRIV_FLAGS_LEGACY_RX;
956 static int ixgbevf_set_priv_flags(struct net_device *netdev, u32 priv_flags)
958 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
959 unsigned int flags = adapter->flags;
961 flags &= ~IXGBEVF_FLAGS_LEGACY_RX;
962 if (priv_flags & IXGBEVF_PRIV_FLAGS_LEGACY_RX)
963 flags |= IXGBEVF_FLAGS_LEGACY_RX;
965 if (flags != adapter->flags) {
966 adapter->flags = flags;
968 /* reset interface to repopulate queues */
969 if (netif_running(netdev))
970 ixgbevf_reinit_locked(adapter);
976 static const struct ethtool_ops ixgbevf_ethtool_ops = {
977 .get_drvinfo = ixgbevf_get_drvinfo,
978 .get_regs_len = ixgbevf_get_regs_len,
979 .get_regs = ixgbevf_get_regs,
980 .nway_reset = ixgbevf_nway_reset,
981 .get_link = ethtool_op_get_link,
982 .get_ringparam = ixgbevf_get_ringparam,
983 .set_ringparam = ixgbevf_set_ringparam,
984 .get_msglevel = ixgbevf_get_msglevel,
985 .set_msglevel = ixgbevf_set_msglevel,
986 .self_test = ixgbevf_diag_test,
987 .get_sset_count = ixgbevf_get_sset_count,
988 .get_strings = ixgbevf_get_strings,
989 .get_ethtool_stats = ixgbevf_get_ethtool_stats,
990 .get_coalesce = ixgbevf_get_coalesce,
991 .set_coalesce = ixgbevf_set_coalesce,
992 .get_rxnfc = ixgbevf_get_rxnfc,
993 .get_rxfh_indir_size = ixgbevf_get_rxfh_indir_size,
994 .get_rxfh_key_size = ixgbevf_get_rxfh_key_size,
995 .get_rxfh = ixgbevf_get_rxfh,
996 .get_link_ksettings = ixgbevf_get_link_ksettings,
997 .get_priv_flags = ixgbevf_get_priv_flags,
998 .set_priv_flags = ixgbevf_set_priv_flags,
1001 void ixgbevf_set_ethtool_ops(struct net_device *netdev)
1003 netdev->ethtool_ops = &ixgbevf_ethtool_ops;