1 /*******************************************************************************
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 /* ethtool support for ixgbevf */
30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include <linux/types.h>
33 #include <linux/module.h>
34 #include <linux/slab.h>
35 #include <linux/pci.h>
36 #include <linux/netdevice.h>
37 #include <linux/ethtool.h>
38 #include <linux/vmalloc.h>
39 #include <linux/if_vlan.h>
40 #include <linux/uaccess.h>
44 #define IXGBE_ALL_RAR_ENTRIES 16
47 char stat_string[ETH_GSTRING_LEN];
52 int saved_reset_offset;
56 #define IXGBEVF_STAT(m, b, r) { \
57 .sizeof_stat = FIELD_SIZEOF(struct ixgbevf_adapter, m), \
58 .stat_offset = offsetof(struct ixgbevf_adapter, m), \
59 .base_stat_offset = offsetof(struct ixgbevf_adapter, b), \
60 .saved_reset_offset = offsetof(struct ixgbevf_adapter, r) \
63 #define IXGBEVF_ZSTAT(m) { \
64 .sizeof_stat = FIELD_SIZEOF(struct ixgbevf_adapter, m), \
65 .stat_offset = offsetof(struct ixgbevf_adapter, m), \
66 .base_stat_offset = -1, \
67 .saved_reset_offset = -1 \
70 static const struct ixgbe_stats ixgbe_gstrings_stats[] = {
71 {"rx_packets", IXGBEVF_STAT(stats.vfgprc, stats.base_vfgprc,
72 stats.saved_reset_vfgprc)},
73 {"tx_packets", IXGBEVF_STAT(stats.vfgptc, stats.base_vfgptc,
74 stats.saved_reset_vfgptc)},
75 {"rx_bytes", IXGBEVF_STAT(stats.vfgorc, stats.base_vfgorc,
76 stats.saved_reset_vfgorc)},
77 {"tx_bytes", IXGBEVF_STAT(stats.vfgotc, stats.base_vfgotc,
78 stats.saved_reset_vfgotc)},
79 {"tx_busy", IXGBEVF_ZSTAT(tx_busy)},
80 {"multicast", IXGBEVF_STAT(stats.vfmprc, stats.base_vfmprc,
81 stats.saved_reset_vfmprc)},
82 {"rx_csum_offload_good", IXGBEVF_ZSTAT(hw_csum_rx_good)},
83 {"rx_csum_offload_errors", IXGBEVF_ZSTAT(hw_csum_rx_error)},
84 {"tx_csum_offload_ctxt", IXGBEVF_ZSTAT(hw_csum_tx_good)},
85 #ifdef BP_EXTENDED_STATS
86 {"rx_bp_poll_yield", IXGBEVF_ZSTAT(bp_rx_yields)},
87 {"rx_bp_cleaned", IXGBEVF_ZSTAT(bp_rx_cleaned)},
88 {"rx_bp_misses", IXGBEVF_ZSTAT(bp_rx_missed)},
89 {"tx_bp_napi_yield", IXGBEVF_ZSTAT(bp_tx_yields)},
90 {"tx_bp_cleaned", IXGBEVF_ZSTAT(bp_tx_cleaned)},
91 {"tx_bp_misses", IXGBEVF_ZSTAT(bp_tx_missed)},
95 #define IXGBE_QUEUE_STATS_LEN 0
96 #define IXGBE_GLOBAL_STATS_LEN ARRAY_SIZE(ixgbe_gstrings_stats)
98 #define IXGBEVF_STATS_LEN (IXGBE_GLOBAL_STATS_LEN + IXGBE_QUEUE_STATS_LEN)
99 static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = {
100 "Register test (offline)",
101 "Link test (on/offline)"
103 #define IXGBE_TEST_LEN (sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN)
105 static int ixgbevf_get_settings(struct net_device *netdev,
106 struct ethtool_cmd *ecmd)
108 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
109 struct ixgbe_hw *hw = &adapter->hw;
113 ecmd->supported = SUPPORTED_10000baseT_Full;
114 ecmd->autoneg = AUTONEG_DISABLE;
115 ecmd->transceiver = XCVR_DUMMY1;
118 hw->mac.get_link_status = 1;
119 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
122 __u32 speed = SPEED_10000;
123 switch (link_speed) {
124 case IXGBE_LINK_SPEED_10GB_FULL:
127 case IXGBE_LINK_SPEED_1GB_FULL:
130 case IXGBE_LINK_SPEED_100_FULL:
135 ethtool_cmd_speed_set(ecmd, speed);
136 ecmd->duplex = DUPLEX_FULL;
138 ethtool_cmd_speed_set(ecmd, -1);
145 static u32 ixgbevf_get_msglevel(struct net_device *netdev)
147 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
148 return adapter->msg_enable;
151 static void ixgbevf_set_msglevel(struct net_device *netdev, u32 data)
153 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
154 adapter->msg_enable = data;
157 #define IXGBE_GET_STAT(_A_, _R_) (_A_->stats._R_)
159 static int ixgbevf_get_regs_len(struct net_device *netdev)
161 #define IXGBE_REGS_LEN 45
162 return IXGBE_REGS_LEN * sizeof(u32);
165 static void ixgbevf_get_regs(struct net_device *netdev,
166 struct ethtool_regs *regs,
169 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
170 struct ixgbe_hw *hw = &adapter->hw;
172 u32 regs_len = ixgbevf_get_regs_len(netdev);
175 memset(p, 0, regs_len);
177 regs->version = (1 << 24) | hw->revision_id << 16 | hw->device_id;
179 /* General Registers */
180 regs_buff[0] = IXGBE_READ_REG(hw, IXGBE_VFCTRL);
181 regs_buff[1] = IXGBE_READ_REG(hw, IXGBE_VFSTATUS);
182 regs_buff[2] = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
183 regs_buff[3] = IXGBE_READ_REG(hw, IXGBE_VFRXMEMWRAP);
184 regs_buff[4] = IXGBE_READ_REG(hw, IXGBE_VFFRTIMER);
187 /* don't read EICR because it can clear interrupt causes, instead
188 * read EICS which is a shadow but doesn't clear EICR */
189 regs_buff[5] = IXGBE_READ_REG(hw, IXGBE_VTEICS);
190 regs_buff[6] = IXGBE_READ_REG(hw, IXGBE_VTEICS);
191 regs_buff[7] = IXGBE_READ_REG(hw, IXGBE_VTEIMS);
192 regs_buff[8] = IXGBE_READ_REG(hw, IXGBE_VTEIMC);
193 regs_buff[9] = IXGBE_READ_REG(hw, IXGBE_VTEIAC);
194 regs_buff[10] = IXGBE_READ_REG(hw, IXGBE_VTEIAM);
195 regs_buff[11] = IXGBE_READ_REG(hw, IXGBE_VTEITR(0));
196 regs_buff[12] = IXGBE_READ_REG(hw, IXGBE_VTIVAR(0));
197 regs_buff[13] = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
200 for (i = 0; i < 2; i++)
201 regs_buff[14 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDBAL(i));
202 for (i = 0; i < 2; i++)
203 regs_buff[16 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDBAH(i));
204 for (i = 0; i < 2; i++)
205 regs_buff[18 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDLEN(i));
206 for (i = 0; i < 2; i++)
207 regs_buff[20 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDH(i));
208 for (i = 0; i < 2; i++)
209 regs_buff[22 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDT(i));
210 for (i = 0; i < 2; i++)
211 regs_buff[24 + i] = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
212 for (i = 0; i < 2; i++)
213 regs_buff[26 + i] = IXGBE_READ_REG(hw, IXGBE_VFSRRCTL(i));
216 regs_buff[28] = IXGBE_READ_REG(hw, IXGBE_VFPSRTYPE);
219 for (i = 0; i < 2; i++)
220 regs_buff[29 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDBAL(i));
221 for (i = 0; i < 2; i++)
222 regs_buff[31 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDBAH(i));
223 for (i = 0; i < 2; i++)
224 regs_buff[33 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDLEN(i));
225 for (i = 0; i < 2; i++)
226 regs_buff[35 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDH(i));
227 for (i = 0; i < 2; i++)
228 regs_buff[37 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDT(i));
229 for (i = 0; i < 2; i++)
230 regs_buff[39 + i] = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
231 for (i = 0; i < 2; i++)
232 regs_buff[41 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDWBAL(i));
233 for (i = 0; i < 2; i++)
234 regs_buff[43 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDWBAH(i));
237 static void ixgbevf_get_drvinfo(struct net_device *netdev,
238 struct ethtool_drvinfo *drvinfo)
240 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
242 strlcpy(drvinfo->driver, ixgbevf_driver_name, sizeof(drvinfo->driver));
243 strlcpy(drvinfo->version, ixgbevf_driver_version,
244 sizeof(drvinfo->version));
245 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
246 sizeof(drvinfo->bus_info));
249 static void ixgbevf_get_ringparam(struct net_device *netdev,
250 struct ethtool_ringparam *ring)
252 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
254 ring->rx_max_pending = IXGBEVF_MAX_RXD;
255 ring->tx_max_pending = IXGBEVF_MAX_TXD;
256 ring->rx_pending = adapter->rx_ring_count;
257 ring->tx_pending = adapter->tx_ring_count;
260 static int ixgbevf_set_ringparam(struct net_device *netdev,
261 struct ethtool_ringparam *ring)
263 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
264 struct ixgbevf_ring *tx_ring = NULL, *rx_ring = NULL;
265 u32 new_rx_count, new_tx_count;
268 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
271 new_tx_count = max_t(u32, ring->tx_pending, IXGBEVF_MIN_TXD);
272 new_tx_count = min_t(u32, new_tx_count, IXGBEVF_MAX_TXD);
273 new_tx_count = ALIGN(new_tx_count, IXGBE_REQ_TX_DESCRIPTOR_MULTIPLE);
275 new_rx_count = max_t(u32, ring->rx_pending, IXGBEVF_MIN_RXD);
276 new_rx_count = min_t(u32, new_rx_count, IXGBEVF_MAX_RXD);
277 new_rx_count = ALIGN(new_rx_count, IXGBE_REQ_RX_DESCRIPTOR_MULTIPLE);
279 /* if nothing to do return success */
280 if ((new_tx_count == adapter->tx_ring_count) &&
281 (new_rx_count == adapter->rx_ring_count))
284 while (test_and_set_bit(__IXGBEVF_RESETTING, &adapter->state))
285 usleep_range(1000, 2000);
287 if (!netif_running(adapter->netdev)) {
288 for (i = 0; i < adapter->num_tx_queues; i++)
289 adapter->tx_ring[i]->count = new_tx_count;
290 for (i = 0; i < adapter->num_rx_queues; i++)
291 adapter->rx_ring[i]->count = new_rx_count;
292 adapter->tx_ring_count = new_tx_count;
293 adapter->rx_ring_count = new_rx_count;
297 if (new_tx_count != adapter->tx_ring_count) {
298 tx_ring = vmalloc(adapter->num_tx_queues * sizeof(*tx_ring));
304 for (i = 0; i < adapter->num_tx_queues; i++) {
305 /* clone ring and setup updated count */
306 tx_ring[i] = *adapter->tx_ring[i];
307 tx_ring[i].count = new_tx_count;
308 err = ixgbevf_setup_tx_resources(adapter, &tx_ring[i]);
313 ixgbevf_free_tx_resources(adapter, &tx_ring[i]);
323 if (new_rx_count != adapter->rx_ring_count) {
324 rx_ring = vmalloc(adapter->num_rx_queues * sizeof(*rx_ring));
330 for (i = 0; i < adapter->num_rx_queues; i++) {
331 /* clone ring and setup updated count */
332 rx_ring[i] = *adapter->rx_ring[i];
333 rx_ring[i].count = new_rx_count;
334 err = ixgbevf_setup_rx_resources(adapter, &rx_ring[i]);
339 ixgbevf_free_rx_resources(adapter, &rx_ring[i]);
349 /* bring interface down to prepare for update */
350 ixgbevf_down(adapter);
354 for (i = 0; i < adapter->num_tx_queues; i++) {
355 ixgbevf_free_tx_resources(adapter, adapter->tx_ring[i]);
356 *adapter->tx_ring[i] = tx_ring[i];
358 adapter->tx_ring_count = new_tx_count;
366 for (i = 0; i < adapter->num_rx_queues; i++) {
367 ixgbevf_free_rx_resources(adapter, adapter->rx_ring[i]);
368 *adapter->rx_ring[i] = rx_ring[i];
370 adapter->rx_ring_count = new_rx_count;
376 /* restore interface using new values */
380 /* free Tx resources if Rx error is encountered */
382 for (i = 0; i < adapter->num_tx_queues; i++)
383 ixgbevf_free_tx_resources(adapter, &tx_ring[i]);
387 clear_bit(__IXGBEVF_RESETTING, &adapter->state);
391 static int ixgbevf_get_sset_count(struct net_device *dev, int stringset)
395 return IXGBE_TEST_LEN;
397 return IXGBE_GLOBAL_STATS_LEN;
403 static void ixgbevf_get_ethtool_stats(struct net_device *netdev,
404 struct ethtool_stats *stats, u64 *data)
406 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
407 char *base = (char *) adapter;
409 #ifdef BP_EXTENDED_STATS
410 u64 rx_yields = 0, rx_cleaned = 0, rx_missed = 0,
411 tx_yields = 0, tx_cleaned = 0, tx_missed = 0;
413 for (i = 0; i < adapter->num_rx_queues; i++) {
414 rx_yields += adapter->rx_ring[i]->bp_yields;
415 rx_cleaned += adapter->rx_ring[i]->bp_cleaned;
416 rx_yields += adapter->rx_ring[i]->bp_yields;
419 for (i = 0; i < adapter->num_tx_queues; i++) {
420 tx_yields += adapter->tx_ring[i]->bp_yields;
421 tx_cleaned += adapter->tx_ring[i]->bp_cleaned;
422 tx_yields += adapter->tx_ring[i]->bp_yields;
425 adapter->bp_rx_yields = rx_yields;
426 adapter->bp_rx_cleaned = rx_cleaned;
427 adapter->bp_rx_missed = rx_missed;
429 adapter->bp_tx_yields = tx_yields;
430 adapter->bp_tx_cleaned = tx_cleaned;
431 adapter->bp_tx_missed = tx_missed;
434 ixgbevf_update_stats(adapter);
435 for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) {
436 char *p = base + ixgbe_gstrings_stats[i].stat_offset;
437 char *b = base + ixgbe_gstrings_stats[i].base_stat_offset;
438 char *r = base + ixgbe_gstrings_stats[i].saved_reset_offset;
440 if (ixgbe_gstrings_stats[i].sizeof_stat == sizeof(u64)) {
441 if (ixgbe_gstrings_stats[i].base_stat_offset >= 0)
442 data[i] = *(u64 *)p - *(u64 *)b + *(u64 *)r;
446 if (ixgbe_gstrings_stats[i].base_stat_offset >= 0)
447 data[i] = *(u32 *)p - *(u32 *)b + *(u32 *)r;
454 static void ixgbevf_get_strings(struct net_device *netdev, u32 stringset,
457 char *p = (char *)data;
462 memcpy(data, *ixgbe_gstrings_test,
463 IXGBE_TEST_LEN * ETH_GSTRING_LEN);
466 for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) {
467 memcpy(p, ixgbe_gstrings_stats[i].stat_string,
469 p += ETH_GSTRING_LEN;
475 static int ixgbevf_link_test(struct ixgbevf_adapter *adapter, u64 *data)
477 struct ixgbe_hw *hw = &adapter->hw;
482 hw->mac.ops.check_link(hw, &link_speed, &link_up, true);
489 /* ethtool register test data */
490 struct ixgbevf_reg_test {
498 /* In the hardware, registers are laid out either singly, in arrays
499 * spaced 0x40 bytes apart, or in contiguous tables. We assume
500 * most tests take place on arrays or single registers (handled
501 * as a single-element array) and special-case the tables.
502 * Table tests are always pattern tests.
504 * We also make provision for some required setup steps by specifying
505 * registers to be written without any read-back testing.
508 #define PATTERN_TEST 1
509 #define SET_READ_TEST 2
510 #define WRITE_NO_TEST 3
511 #define TABLE32_TEST 4
512 #define TABLE64_TEST_LO 5
513 #define TABLE64_TEST_HI 6
515 /* default VF register test */
516 static const struct ixgbevf_reg_test reg_test_vf[] = {
517 { IXGBE_VFRDBAL(0), 2, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFF80 },
518 { IXGBE_VFRDBAH(0), 2, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
519 { IXGBE_VFRDLEN(0), 2, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
520 { IXGBE_VFRXDCTL(0), 2, WRITE_NO_TEST, 0, IXGBE_RXDCTL_ENABLE },
521 { IXGBE_VFRDT(0), 2, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
522 { IXGBE_VFRXDCTL(0), 2, WRITE_NO_TEST, 0, 0 },
523 { IXGBE_VFTDBAL(0), 2, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
524 { IXGBE_VFTDBAH(0), 2, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
525 { IXGBE_VFTDLEN(0), 2, PATTERN_TEST, 0x000FFF80, 0x000FFF80 },
529 static const u32 register_test_patterns[] = {
530 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
533 #define REG_PATTERN_TEST(R, M, W) \
535 u32 pat, val, before; \
536 for (pat = 0; pat < ARRAY_SIZE(register_test_patterns); pat++) { \
537 before = readl(adapter->hw.hw_addr + R); \
538 writel((register_test_patterns[pat] & W), \
539 (adapter->hw.hw_addr + R)); \
540 val = readl(adapter->hw.hw_addr + R); \
541 if (val != (register_test_patterns[pat] & W & M)) { \
542 hw_dbg(&adapter->hw, \
543 "pattern test reg %04X failed: got " \
544 "0x%08X expected 0x%08X\n", \
545 R, val, (register_test_patterns[pat] & W & M)); \
547 writel(before, adapter->hw.hw_addr + R); \
550 writel(before, adapter->hw.hw_addr + R); \
554 #define REG_SET_AND_CHECK(R, M, W) \
557 before = readl(adapter->hw.hw_addr + R); \
558 writel((W & M), (adapter->hw.hw_addr + R)); \
559 val = readl(adapter->hw.hw_addr + R); \
560 if ((W & M) != (val & M)) { \
561 pr_err("set/check reg %04X test failed: got 0x%08X expected " \
562 "0x%08X\n", R, (val & M), (W & M)); \
564 writel(before, (adapter->hw.hw_addr + R)); \
567 writel(before, (adapter->hw.hw_addr + R)); \
570 static int ixgbevf_reg_test(struct ixgbevf_adapter *adapter, u64 *data)
572 const struct ixgbevf_reg_test *test;
578 * Perform the register test, looping through the test table
579 * until we either fail or reach the null entry.
582 for (i = 0; i < test->array_len; i++) {
583 switch (test->test_type) {
585 REG_PATTERN_TEST(test->reg + (i * 0x40),
590 REG_SET_AND_CHECK(test->reg + (i * 0x40),
596 (adapter->hw.hw_addr + test->reg)
600 REG_PATTERN_TEST(test->reg + (i * 4),
604 case TABLE64_TEST_LO:
605 REG_PATTERN_TEST(test->reg + (i * 8),
609 case TABLE64_TEST_HI:
610 REG_PATTERN_TEST((test->reg + 4) + (i * 8),
623 static void ixgbevf_diag_test(struct net_device *netdev,
624 struct ethtool_test *eth_test, u64 *data)
626 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
627 bool if_running = netif_running(netdev);
629 set_bit(__IXGBEVF_TESTING, &adapter->state);
630 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
633 hw_dbg(&adapter->hw, "offline testing starting\n");
635 /* Link test performed before hardware reset so autoneg doesn't
636 * interfere with test result */
637 if (ixgbevf_link_test(adapter, &data[1]))
638 eth_test->flags |= ETH_TEST_FL_FAILED;
641 /* indicate we're in test mode */
644 ixgbevf_reset(adapter);
646 hw_dbg(&adapter->hw, "register testing starting\n");
647 if (ixgbevf_reg_test(adapter, &data[0]))
648 eth_test->flags |= ETH_TEST_FL_FAILED;
650 ixgbevf_reset(adapter);
652 clear_bit(__IXGBEVF_TESTING, &adapter->state);
656 hw_dbg(&adapter->hw, "online testing starting\n");
658 if (ixgbevf_link_test(adapter, &data[1]))
659 eth_test->flags |= ETH_TEST_FL_FAILED;
661 /* Online tests aren't run; pass by default */
664 clear_bit(__IXGBEVF_TESTING, &adapter->state);
666 msleep_interruptible(4 * 1000);
669 static int ixgbevf_nway_reset(struct net_device *netdev)
671 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
673 if (netif_running(netdev))
674 ixgbevf_reinit_locked(adapter);
679 static int ixgbevf_get_coalesce(struct net_device *netdev,
680 struct ethtool_coalesce *ec)
682 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
684 /* only valid if in constant ITR mode */
685 if (adapter->rx_itr_setting <= 1)
686 ec->rx_coalesce_usecs = adapter->rx_itr_setting;
688 ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
690 /* if in mixed tx/rx queues per vector mode, report only rx settings */
691 if (adapter->q_vector[0]->tx.count && adapter->q_vector[0]->rx.count)
694 /* only valid if in constant ITR mode */
695 if (adapter->tx_itr_setting <= 1)
696 ec->tx_coalesce_usecs = adapter->tx_itr_setting;
698 ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
703 static int ixgbevf_set_coalesce(struct net_device *netdev,
704 struct ethtool_coalesce *ec)
706 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
707 struct ixgbevf_q_vector *q_vector;
709 u16 tx_itr_param, rx_itr_param;
711 /* don't accept tx specific changes if we've got mixed RxTx vectors */
712 if (adapter->q_vector[0]->tx.count && adapter->q_vector[0]->rx.count
713 && ec->tx_coalesce_usecs)
717 if ((ec->rx_coalesce_usecs > (IXGBE_MAX_EITR >> 2)) ||
718 (ec->tx_coalesce_usecs > (IXGBE_MAX_EITR >> 2)))
721 if (ec->rx_coalesce_usecs > 1)
722 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
724 adapter->rx_itr_setting = ec->rx_coalesce_usecs;
726 if (adapter->rx_itr_setting == 1)
727 rx_itr_param = IXGBE_20K_ITR;
729 rx_itr_param = adapter->rx_itr_setting;
732 if (ec->tx_coalesce_usecs > 1)
733 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
735 adapter->tx_itr_setting = ec->tx_coalesce_usecs;
737 if (adapter->tx_itr_setting == 1)
738 tx_itr_param = IXGBE_10K_ITR;
740 tx_itr_param = adapter->tx_itr_setting;
742 num_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
744 for (i = 0; i < num_vectors; i++) {
745 q_vector = adapter->q_vector[i];
746 if (q_vector->tx.count && !q_vector->rx.count)
748 q_vector->itr = tx_itr_param;
750 /* rx only or mixed */
751 q_vector->itr = rx_itr_param;
752 ixgbevf_write_eitr(q_vector);
758 static const struct ethtool_ops ixgbevf_ethtool_ops = {
759 .get_settings = ixgbevf_get_settings,
760 .get_drvinfo = ixgbevf_get_drvinfo,
761 .get_regs_len = ixgbevf_get_regs_len,
762 .get_regs = ixgbevf_get_regs,
763 .nway_reset = ixgbevf_nway_reset,
764 .get_link = ethtool_op_get_link,
765 .get_ringparam = ixgbevf_get_ringparam,
766 .set_ringparam = ixgbevf_set_ringparam,
767 .get_msglevel = ixgbevf_get_msglevel,
768 .set_msglevel = ixgbevf_set_msglevel,
769 .self_test = ixgbevf_diag_test,
770 .get_sset_count = ixgbevf_get_sset_count,
771 .get_strings = ixgbevf_get_strings,
772 .get_ethtool_stats = ixgbevf_get_ethtool_stats,
773 .get_coalesce = ixgbevf_get_coalesce,
774 .set_coalesce = ixgbevf_set_coalesce,
777 void ixgbevf_set_ethtool_ops(struct net_device *netdev)
779 SET_ETHTOOL_OPS(netdev, &ixgbevf_ethtool_ops);