1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
4 /* ethtool support for iavf */
7 #include <linux/uaccess.h>
9 /* ethtool statistics helpers */
12 * struct iavf_stats - definition for an ethtool statistic
13 * @stat_string: statistic name to display in ethtool -S output
14 * @sizeof_stat: the sizeof() the stat, must be no greater than sizeof(u64)
15 * @stat_offset: offsetof() the stat from a base pointer
17 * This structure defines a statistic to be added to the ethtool stats buffer.
18 * It defines a statistic as offset from a common base pointer. Stats should
19 * be defined in constant arrays using the IAVF_STAT macro, with every element
20 * of the array using the same _type for calculating the sizeof_stat and
23 * The @sizeof_stat is expected to be sizeof(u8), sizeof(u16), sizeof(u32) or
24 * sizeof(u64). Other sizes are not expected and will produce a WARN_ONCE from
25 * the iavf_add_ethtool_stat() helper function.
27 * The @stat_string is interpreted as a format string, allowing formatted
28 * values to be inserted while looping over multiple structures for a given
29 * statistics array. Thus, every statistic string in an array should have the
30 * same type and number of format specifiers, to be formatted by variadic
31 * arguments to the iavf_add_stat_string() helper function.
34 char stat_string[ETH_GSTRING_LEN];
39 /* Helper macro to define an iavf_stat structure with proper size and type.
40 * Use this when defining constant statistics arrays. Note that @_type expects
41 * only a type name and is used multiple times.
43 #define IAVF_STAT(_type, _name, _stat) { \
44 .stat_string = _name, \
45 .sizeof_stat = sizeof_field(_type, _stat), \
46 .stat_offset = offsetof(_type, _stat) \
49 /* Helper macro for defining some statistics related to queues */
50 #define IAVF_QUEUE_STAT(_name, _stat) \
51 IAVF_STAT(struct iavf_ring, _name, _stat)
53 /* Stats associated with a Tx or Rx ring */
54 static const struct iavf_stats iavf_gstrings_queue_stats[] = {
55 IAVF_QUEUE_STAT("%s-%u.packets", stats.packets),
56 IAVF_QUEUE_STAT("%s-%u.bytes", stats.bytes),
60 * iavf_add_one_ethtool_stat - copy the stat into the supplied buffer
61 * @data: location to store the stat value
62 * @pointer: basis for where to copy from
63 * @stat: the stat definition
65 * Copies the stat data defined by the pointer and stat structure pair into
66 * the memory supplied as data. Used to implement iavf_add_ethtool_stats and
67 * iavf_add_queue_stats. If the pointer is null, data will be zero'd.
70 iavf_add_one_ethtool_stat(u64 *data, void *pointer,
71 const struct iavf_stats *stat)
76 /* ensure that the ethtool data buffer is zero'd for any stats
77 * which don't have a valid pointer.
83 p = (char *)pointer + stat->stat_offset;
84 switch (stat->sizeof_stat) {
98 WARN_ONCE(1, "unexpected stat size for %s",
105 * __iavf_add_ethtool_stats - copy stats into the ethtool supplied buffer
106 * @data: ethtool stats buffer
107 * @pointer: location to copy stats from
108 * @stats: array of stats to copy
109 * @size: the size of the stats definition
111 * Copy the stats defined by the stats array using the pointer as a base into
112 * the data buffer supplied by ethtool. Updates the data pointer to point to
113 * the next empty location for successive calls to __iavf_add_ethtool_stats.
114 * If pointer is null, set the data values to zero and update the pointer to
118 __iavf_add_ethtool_stats(u64 **data, void *pointer,
119 const struct iavf_stats stats[],
120 const unsigned int size)
124 for (i = 0; i < size; i++)
125 iavf_add_one_ethtool_stat((*data)++, pointer, &stats[i]);
129 * iavf_add_ethtool_stats - copy stats into ethtool supplied buffer
130 * @data: ethtool stats buffer
131 * @pointer: location where stats are stored
132 * @stats: static const array of stat definitions
134 * Macro to ease the use of __iavf_add_ethtool_stats by taking a static
135 * constant stats array and passing the ARRAY_SIZE(). This avoids typos by
136 * ensuring that we pass the size associated with the given stats array.
138 * The parameter @stats is evaluated twice, so parameters with side effects
141 #define iavf_add_ethtool_stats(data, pointer, stats) \
142 __iavf_add_ethtool_stats(data, pointer, stats, ARRAY_SIZE(stats))
145 * iavf_add_queue_stats - copy queue statistics into supplied buffer
146 * @data: ethtool stats buffer
147 * @ring: the ring to copy
149 * Queue statistics must be copied while protected by
150 * u64_stats_fetch_begin_irq, so we can't directly use iavf_add_ethtool_stats.
151 * Assumes that queue stats are defined in iavf_gstrings_queue_stats. If the
152 * ring pointer is null, zero out the queue stat values and update the data
153 * pointer. Otherwise safely copy the stats from the ring into the supplied
154 * buffer and update the data pointer when finished.
156 * This function expects to be called while under rcu_read_lock().
159 iavf_add_queue_stats(u64 **data, struct iavf_ring *ring)
161 const unsigned int size = ARRAY_SIZE(iavf_gstrings_queue_stats);
162 const struct iavf_stats *stats = iavf_gstrings_queue_stats;
166 /* To avoid invalid statistics values, ensure that we keep retrying
167 * the copy until we get a consistent value according to
168 * u64_stats_fetch_retry_irq. But first, make sure our ring is
169 * non-null before attempting to access its syncp.
172 start = !ring ? 0 : u64_stats_fetch_begin_irq(&ring->syncp);
173 for (i = 0; i < size; i++)
174 iavf_add_one_ethtool_stat(&(*data)[i], ring, &stats[i]);
175 } while (ring && u64_stats_fetch_retry_irq(&ring->syncp, start));
177 /* Once we successfully copy the stats in, update the data pointer */
182 * __iavf_add_stat_strings - copy stat strings into ethtool buffer
183 * @p: ethtool supplied buffer
184 * @stats: stat definitions array
185 * @size: size of the stats array
187 * Format and copy the strings described by stats into the buffer pointed at
190 static void __iavf_add_stat_strings(u8 **p, const struct iavf_stats stats[],
191 const unsigned int size, ...)
195 for (i = 0; i < size; i++) {
198 va_start(args, size);
199 vsnprintf(*p, ETH_GSTRING_LEN, stats[i].stat_string, args);
200 *p += ETH_GSTRING_LEN;
206 * iavf_add_stat_strings - copy stat strings into ethtool buffer
207 * @p: ethtool supplied buffer
208 * @stats: stat definitions array
210 * Format and copy the strings described by the const static stats value into
211 * the buffer pointed at by p.
213 * The parameter @stats is evaluated twice, so parameters with side effects
214 * should be avoided. Additionally, stats must be an array such that
215 * ARRAY_SIZE can be called on it.
217 #define iavf_add_stat_strings(p, stats, ...) \
218 __iavf_add_stat_strings(p, stats, ARRAY_SIZE(stats), ## __VA_ARGS__)
220 #define VF_STAT(_name, _stat) \
221 IAVF_STAT(struct iavf_adapter, _name, _stat)
223 static const struct iavf_stats iavf_gstrings_stats[] = {
224 VF_STAT("rx_bytes", current_stats.rx_bytes),
225 VF_STAT("rx_unicast", current_stats.rx_unicast),
226 VF_STAT("rx_multicast", current_stats.rx_multicast),
227 VF_STAT("rx_broadcast", current_stats.rx_broadcast),
228 VF_STAT("rx_discards", current_stats.rx_discards),
229 VF_STAT("rx_unknown_protocol", current_stats.rx_unknown_protocol),
230 VF_STAT("tx_bytes", current_stats.tx_bytes),
231 VF_STAT("tx_unicast", current_stats.tx_unicast),
232 VF_STAT("tx_multicast", current_stats.tx_multicast),
233 VF_STAT("tx_broadcast", current_stats.tx_broadcast),
234 VF_STAT("tx_discards", current_stats.tx_discards),
235 VF_STAT("tx_errors", current_stats.tx_errors),
238 #define IAVF_STATS_LEN ARRAY_SIZE(iavf_gstrings_stats)
240 #define IAVF_QUEUE_STATS_LEN ARRAY_SIZE(iavf_gstrings_queue_stats)
242 /* For now we have one and only one private flag and it is only defined
243 * when we have support for the SKIP_CPU_SYNC DMA attribute. Instead
244 * of leaving all this code sitting around empty we will strip it unless
245 * our one private flag is actually available.
247 struct iavf_priv_flags {
248 char flag_string[ETH_GSTRING_LEN];
253 #define IAVF_PRIV_FLAG(_name, _flag, _read_only) { \
254 .flag_string = _name, \
256 .read_only = _read_only, \
259 static const struct iavf_priv_flags iavf_gstrings_priv_flags[] = {
260 IAVF_PRIV_FLAG("legacy-rx", IAVF_FLAG_LEGACY_RX, 0),
263 #define IAVF_PRIV_FLAGS_STR_LEN ARRAY_SIZE(iavf_gstrings_priv_flags)
266 * iavf_get_link_ksettings - Get Link Speed and Duplex settings
267 * @netdev: network interface device structure
268 * @cmd: ethtool command
270 * Reports speed/duplex settings. Because this is a VF, we don't know what
271 * kind of link we really have, so we fake it.
273 static int iavf_get_link_ksettings(struct net_device *netdev,
274 struct ethtool_link_ksettings *cmd)
276 struct iavf_adapter *adapter = netdev_priv(netdev);
278 ethtool_link_ksettings_zero_link_mode(cmd, supported);
279 cmd->base.autoneg = AUTONEG_DISABLE;
280 cmd->base.port = PORT_NONE;
281 cmd->base.duplex = DUPLEX_FULL;
283 if (ADV_LINK_SUPPORT(adapter)) {
284 if (adapter->link_speed_mbps &&
285 adapter->link_speed_mbps < U32_MAX)
286 cmd->base.speed = adapter->link_speed_mbps;
288 cmd->base.speed = SPEED_UNKNOWN;
293 switch (adapter->link_speed) {
294 case VIRTCHNL_LINK_SPEED_40GB:
295 cmd->base.speed = SPEED_40000;
297 case VIRTCHNL_LINK_SPEED_25GB:
298 cmd->base.speed = SPEED_25000;
300 case VIRTCHNL_LINK_SPEED_20GB:
301 cmd->base.speed = SPEED_20000;
303 case VIRTCHNL_LINK_SPEED_10GB:
304 cmd->base.speed = SPEED_10000;
306 case VIRTCHNL_LINK_SPEED_5GB:
307 cmd->base.speed = SPEED_5000;
309 case VIRTCHNL_LINK_SPEED_2_5GB:
310 cmd->base.speed = SPEED_2500;
312 case VIRTCHNL_LINK_SPEED_1GB:
313 cmd->base.speed = SPEED_1000;
315 case VIRTCHNL_LINK_SPEED_100MB:
316 cmd->base.speed = SPEED_100;
326 * iavf_get_sset_count - Get length of string set
327 * @netdev: network interface device structure
328 * @sset: id of string set
330 * Reports size of various string tables.
332 static int iavf_get_sset_count(struct net_device *netdev, int sset)
334 if (sset == ETH_SS_STATS)
335 return IAVF_STATS_LEN +
336 (IAVF_QUEUE_STATS_LEN * 2 * IAVF_MAX_REQ_QUEUES);
337 else if (sset == ETH_SS_PRIV_FLAGS)
338 return IAVF_PRIV_FLAGS_STR_LEN;
344 * iavf_get_ethtool_stats - report device statistics
345 * @netdev: network interface device structure
346 * @stats: ethtool statistics structure
347 * @data: pointer to data buffer
349 * All statistics are added to the data buffer as an array of u64.
351 static void iavf_get_ethtool_stats(struct net_device *netdev,
352 struct ethtool_stats *stats, u64 *data)
354 struct iavf_adapter *adapter = netdev_priv(netdev);
357 iavf_add_ethtool_stats(&data, adapter, iavf_gstrings_stats);
360 for (i = 0; i < IAVF_MAX_REQ_QUEUES; i++) {
361 struct iavf_ring *ring;
363 /* Avoid accessing un-allocated queues */
364 ring = (i < adapter->num_active_queues ?
365 &adapter->tx_rings[i] : NULL);
366 iavf_add_queue_stats(&data, ring);
368 /* Avoid accessing un-allocated queues */
369 ring = (i < adapter->num_active_queues ?
370 &adapter->rx_rings[i] : NULL);
371 iavf_add_queue_stats(&data, ring);
377 * iavf_get_priv_flag_strings - Get private flag strings
378 * @netdev: network interface device structure
379 * @data: buffer for string data
381 * Builds the private flags string table
383 static void iavf_get_priv_flag_strings(struct net_device *netdev, u8 *data)
387 for (i = 0; i < IAVF_PRIV_FLAGS_STR_LEN; i++) {
388 snprintf(data, ETH_GSTRING_LEN, "%s",
389 iavf_gstrings_priv_flags[i].flag_string);
390 data += ETH_GSTRING_LEN;
395 * iavf_get_stat_strings - Get stat strings
396 * @netdev: network interface device structure
397 * @data: buffer for string data
399 * Builds the statistics string table
401 static void iavf_get_stat_strings(struct net_device *netdev, u8 *data)
405 iavf_add_stat_strings(&data, iavf_gstrings_stats);
407 /* Queues are always allocated in pairs, so we just use num_tx_queues
408 * for both Tx and Rx queues.
410 for (i = 0; i < netdev->num_tx_queues; i++) {
411 iavf_add_stat_strings(&data, iavf_gstrings_queue_stats,
413 iavf_add_stat_strings(&data, iavf_gstrings_queue_stats,
419 * iavf_get_strings - Get string set
420 * @netdev: network interface device structure
421 * @sset: id of string set
422 * @data: buffer for string data
424 * Builds string tables for various string sets
426 static void iavf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
430 iavf_get_stat_strings(netdev, data);
432 case ETH_SS_PRIV_FLAGS:
433 iavf_get_priv_flag_strings(netdev, data);
441 * iavf_get_priv_flags - report device private flags
442 * @netdev: network interface device structure
444 * The get string set count and the string set should be matched for each
445 * flag returned. Add new strings for each flag to the iavf_gstrings_priv_flags
448 * Returns a u32 bitmap of flags.
450 static u32 iavf_get_priv_flags(struct net_device *netdev)
452 struct iavf_adapter *adapter = netdev_priv(netdev);
453 u32 i, ret_flags = 0;
455 for (i = 0; i < IAVF_PRIV_FLAGS_STR_LEN; i++) {
456 const struct iavf_priv_flags *priv_flags;
458 priv_flags = &iavf_gstrings_priv_flags[i];
460 if (priv_flags->flag & adapter->flags)
468 * iavf_set_priv_flags - set private flags
469 * @netdev: network interface device structure
470 * @flags: bit flags to be set
472 static int iavf_set_priv_flags(struct net_device *netdev, u32 flags)
474 struct iavf_adapter *adapter = netdev_priv(netdev);
475 u32 orig_flags, new_flags, changed_flags;
478 orig_flags = READ_ONCE(adapter->flags);
479 new_flags = orig_flags;
481 for (i = 0; i < IAVF_PRIV_FLAGS_STR_LEN; i++) {
482 const struct iavf_priv_flags *priv_flags;
484 priv_flags = &iavf_gstrings_priv_flags[i];
487 new_flags |= priv_flags->flag;
489 new_flags &= ~(priv_flags->flag);
491 if (priv_flags->read_only &&
492 ((orig_flags ^ new_flags) & ~BIT(i)))
496 /* Before we finalize any flag changes, any checks which we need to
497 * perform to determine if the new flags will be supported should go
501 /* Compare and exchange the new flags into place. If we failed, that
502 * is if cmpxchg returns anything but the old value, this means
503 * something else must have modified the flags variable since we
504 * copied it. We'll just punt with an error and log something in the
507 if (cmpxchg(&adapter->flags, orig_flags, new_flags) != orig_flags) {
508 dev_warn(&adapter->pdev->dev,
509 "Unable to update adapter->flags as it was modified by another thread...\n");
513 changed_flags = orig_flags ^ new_flags;
515 /* Process any additional changes needed as a result of flag changes.
516 * The changed_flags value reflects the list of bits that were changed
520 /* issue a reset to force legacy-rx change to take effect */
521 if (changed_flags & IAVF_FLAG_LEGACY_RX) {
522 if (netif_running(netdev)) {
523 adapter->flags |= IAVF_FLAG_RESET_NEEDED;
524 queue_work(iavf_wq, &adapter->reset_task);
532 * iavf_get_msglevel - Get debug message level
533 * @netdev: network interface device structure
535 * Returns current debug message level.
537 static u32 iavf_get_msglevel(struct net_device *netdev)
539 struct iavf_adapter *adapter = netdev_priv(netdev);
541 return adapter->msg_enable;
545 * iavf_set_msglevel - Set debug message level
546 * @netdev: network interface device structure
547 * @data: message level
549 * Set current debug message level. Higher values cause the driver to
552 static void iavf_set_msglevel(struct net_device *netdev, u32 data)
554 struct iavf_adapter *adapter = netdev_priv(netdev);
556 if (IAVF_DEBUG_USER & data)
557 adapter->hw.debug_mask = data;
558 adapter->msg_enable = data;
562 * iavf_get_drvinfo - Get driver info
563 * @netdev: network interface device structure
564 * @drvinfo: ethool driver info structure
566 * Returns information about the driver and device for display to the user.
568 static void iavf_get_drvinfo(struct net_device *netdev,
569 struct ethtool_drvinfo *drvinfo)
571 struct iavf_adapter *adapter = netdev_priv(netdev);
573 strlcpy(drvinfo->driver, iavf_driver_name, 32);
574 strlcpy(drvinfo->version, iavf_driver_version, 32);
575 strlcpy(drvinfo->fw_version, "N/A", 4);
576 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
577 drvinfo->n_priv_flags = IAVF_PRIV_FLAGS_STR_LEN;
581 * iavf_get_ringparam - Get ring parameters
582 * @netdev: network interface device structure
583 * @ring: ethtool ringparam structure
585 * Returns current ring parameters. TX and RX rings are reported separately,
586 * but the number of rings is not reported.
588 static void iavf_get_ringparam(struct net_device *netdev,
589 struct ethtool_ringparam *ring)
591 struct iavf_adapter *adapter = netdev_priv(netdev);
593 ring->rx_max_pending = IAVF_MAX_RXD;
594 ring->tx_max_pending = IAVF_MAX_TXD;
595 ring->rx_pending = adapter->rx_desc_count;
596 ring->tx_pending = adapter->tx_desc_count;
600 * iavf_set_ringparam - Set ring parameters
601 * @netdev: network interface device structure
602 * @ring: ethtool ringparam structure
604 * Sets ring parameters. TX and RX rings are controlled separately, but the
605 * number of rings is not specified, so all rings get the same settings.
607 static int iavf_set_ringparam(struct net_device *netdev,
608 struct ethtool_ringparam *ring)
610 struct iavf_adapter *adapter = netdev_priv(netdev);
611 u32 new_rx_count, new_tx_count;
613 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
616 new_tx_count = clamp_t(u32, ring->tx_pending,
619 new_tx_count = ALIGN(new_tx_count, IAVF_REQ_DESCRIPTOR_MULTIPLE);
621 new_rx_count = clamp_t(u32, ring->rx_pending,
624 new_rx_count = ALIGN(new_rx_count, IAVF_REQ_DESCRIPTOR_MULTIPLE);
626 /* if nothing to do return success */
627 if ((new_tx_count == adapter->tx_desc_count) &&
628 (new_rx_count == adapter->rx_desc_count))
631 adapter->tx_desc_count = new_tx_count;
632 adapter->rx_desc_count = new_rx_count;
634 if (netif_running(netdev)) {
635 adapter->flags |= IAVF_FLAG_RESET_NEEDED;
636 queue_work(iavf_wq, &adapter->reset_task);
643 * __iavf_get_coalesce - get per-queue coalesce settings
644 * @netdev: the netdev to check
645 * @ec: ethtool coalesce data structure
646 * @queue: which queue to pick
648 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
649 * are per queue. If queue is <0 then we default to queue 0 as the
650 * representative value.
652 static int __iavf_get_coalesce(struct net_device *netdev,
653 struct ethtool_coalesce *ec, int queue)
655 struct iavf_adapter *adapter = netdev_priv(netdev);
656 struct iavf_vsi *vsi = &adapter->vsi;
657 struct iavf_ring *rx_ring, *tx_ring;
659 ec->tx_max_coalesced_frames = vsi->work_limit;
660 ec->rx_max_coalesced_frames = vsi->work_limit;
662 /* Rx and Tx usecs per queue value. If user doesn't specify the
663 * queue, return queue 0's value to represent.
667 else if (queue >= adapter->num_active_queues)
670 rx_ring = &adapter->rx_rings[queue];
671 tx_ring = &adapter->tx_rings[queue];
673 if (ITR_IS_DYNAMIC(rx_ring->itr_setting))
674 ec->use_adaptive_rx_coalesce = 1;
676 if (ITR_IS_DYNAMIC(tx_ring->itr_setting))
677 ec->use_adaptive_tx_coalesce = 1;
679 ec->rx_coalesce_usecs = rx_ring->itr_setting & ~IAVF_ITR_DYNAMIC;
680 ec->tx_coalesce_usecs = tx_ring->itr_setting & ~IAVF_ITR_DYNAMIC;
686 * iavf_get_coalesce - Get interrupt coalescing settings
687 * @netdev: network interface device structure
688 * @ec: ethtool coalesce structure
690 * Returns current coalescing settings. This is referred to elsewhere in the
691 * driver as Interrupt Throttle Rate, as this is how the hardware describes
692 * this functionality. Note that if per-queue settings have been modified this
693 * only represents the settings of queue 0.
695 static int iavf_get_coalesce(struct net_device *netdev,
696 struct ethtool_coalesce *ec)
698 return __iavf_get_coalesce(netdev, ec, -1);
702 * iavf_get_per_queue_coalesce - get coalesce values for specific queue
703 * @netdev: netdev to read
704 * @ec: coalesce settings from ethtool
705 * @queue: the queue to read
707 * Read specific queue's coalesce settings.
709 static int iavf_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
710 struct ethtool_coalesce *ec)
712 return __iavf_get_coalesce(netdev, ec, queue);
716 * iavf_set_itr_per_queue - set ITR values for specific queue
717 * @adapter: the VF adapter struct to set values for
718 * @ec: coalesce settings from ethtool
719 * @queue: the queue to modify
721 * Change the ITR settings for a specific queue.
723 static void iavf_set_itr_per_queue(struct iavf_adapter *adapter,
724 struct ethtool_coalesce *ec, int queue)
726 struct iavf_ring *rx_ring = &adapter->rx_rings[queue];
727 struct iavf_ring *tx_ring = &adapter->tx_rings[queue];
728 struct iavf_q_vector *q_vector;
730 rx_ring->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs);
731 tx_ring->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs);
733 rx_ring->itr_setting |= IAVF_ITR_DYNAMIC;
734 if (!ec->use_adaptive_rx_coalesce)
735 rx_ring->itr_setting ^= IAVF_ITR_DYNAMIC;
737 tx_ring->itr_setting |= IAVF_ITR_DYNAMIC;
738 if (!ec->use_adaptive_tx_coalesce)
739 tx_ring->itr_setting ^= IAVF_ITR_DYNAMIC;
741 q_vector = rx_ring->q_vector;
742 q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting);
744 q_vector = tx_ring->q_vector;
745 q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting);
747 /* The interrupt handler itself will take care of programming
748 * the Tx and Rx ITR values based on the values we have entered
749 * into the q_vector, no need to write the values now.
754 * __iavf_set_coalesce - set coalesce settings for particular queue
755 * @netdev: the netdev to change
756 * @ec: ethtool coalesce settings
757 * @queue: the queue to change
759 * Sets the coalesce settings for a particular queue.
761 static int __iavf_set_coalesce(struct net_device *netdev,
762 struct ethtool_coalesce *ec, int queue)
764 struct iavf_adapter *adapter = netdev_priv(netdev);
765 struct iavf_vsi *vsi = &adapter->vsi;
768 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
769 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
771 if (ec->rx_coalesce_usecs == 0) {
772 if (ec->use_adaptive_rx_coalesce)
773 netif_info(adapter, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
774 } else if ((ec->rx_coalesce_usecs < IAVF_MIN_ITR) ||
775 (ec->rx_coalesce_usecs > IAVF_MAX_ITR)) {
776 netif_info(adapter, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
778 } else if (ec->tx_coalesce_usecs == 0) {
779 if (ec->use_adaptive_tx_coalesce)
780 netif_info(adapter, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
781 } else if ((ec->tx_coalesce_usecs < IAVF_MIN_ITR) ||
782 (ec->tx_coalesce_usecs > IAVF_MAX_ITR)) {
783 netif_info(adapter, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
787 /* Rx and Tx usecs has per queue value. If user doesn't specify the
788 * queue, apply to all queues.
791 for (i = 0; i < adapter->num_active_queues; i++)
792 iavf_set_itr_per_queue(adapter, ec, i);
793 } else if (queue < adapter->num_active_queues) {
794 iavf_set_itr_per_queue(adapter, ec, queue);
796 netif_info(adapter, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
797 adapter->num_active_queues - 1);
805 * iavf_set_coalesce - Set interrupt coalescing settings
806 * @netdev: network interface device structure
807 * @ec: ethtool coalesce structure
809 * Change current coalescing settings for every queue.
811 static int iavf_set_coalesce(struct net_device *netdev,
812 struct ethtool_coalesce *ec)
814 return __iavf_set_coalesce(netdev, ec, -1);
818 * iavf_set_per_queue_coalesce - set specific queue's coalesce settings
819 * @netdev: the netdev to change
820 * @ec: ethtool's coalesce settings
821 * @queue: the queue to modify
823 * Modifies a specific queue's coalesce settings.
825 static int iavf_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
826 struct ethtool_coalesce *ec)
828 return __iavf_set_coalesce(netdev, ec, queue);
832 * iavf_get_rxnfc - command to get RX flow classification rules
833 * @netdev: network interface device structure
834 * @cmd: ethtool rxnfc command
835 * @rule_locs: pointer to store rule locations
837 * Returns Success if the command is supported.
839 static int iavf_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
842 struct iavf_adapter *adapter = netdev_priv(netdev);
843 int ret = -EOPNOTSUPP;
846 case ETHTOOL_GRXRINGS:
847 cmd->data = adapter->num_active_queues;
852 "RSS hash info is not available to vf, use pf.\n");
861 * iavf_get_channels: get the number of channels supported by the device
862 * @netdev: network interface device structure
863 * @ch: channel information structure
865 * For the purposes of our device, we only use combined channels, i.e. a tx/rx
866 * queue pair. Report one extra channel to match our "other" MSI-X vector.
868 static void iavf_get_channels(struct net_device *netdev,
869 struct ethtool_channels *ch)
871 struct iavf_adapter *adapter = netdev_priv(netdev);
873 /* Report maximum channels */
874 ch->max_combined = adapter->vsi_res->num_queue_pairs;
876 ch->max_other = NONQ_VECS;
877 ch->other_count = NONQ_VECS;
879 ch->combined_count = adapter->num_active_queues;
883 * iavf_set_channels: set the new channel count
884 * @netdev: network interface device structure
885 * @ch: channel information structure
887 * Negotiate a new number of channels with the PF then do a reset. During
888 * reset we'll realloc queues and fix the RSS table. Returns 0 on success,
889 * negative on failure.
891 static int iavf_set_channels(struct net_device *netdev,
892 struct ethtool_channels *ch)
894 struct iavf_adapter *adapter = netdev_priv(netdev);
895 u32 num_req = ch->combined_count;
897 if ((adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ) &&
899 dev_info(&adapter->pdev->dev, "Cannot set channels since ADq is enabled.\n");
903 /* All of these should have already been checked by ethtool before this
904 * even gets to us, but just to be sure.
906 if (num_req > adapter->vsi_res->num_queue_pairs)
909 if (num_req == adapter->num_active_queues)
912 if (ch->rx_count || ch->tx_count || ch->other_count != NONQ_VECS)
915 adapter->num_req_queues = num_req;
916 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
917 iavf_schedule_reset(adapter);
922 * iavf_get_rxfh_key_size - get the RSS hash key size
923 * @netdev: network interface device structure
925 * Returns the table size.
927 static u32 iavf_get_rxfh_key_size(struct net_device *netdev)
929 struct iavf_adapter *adapter = netdev_priv(netdev);
931 return adapter->rss_key_size;
935 * iavf_get_rxfh_indir_size - get the rx flow hash indirection table size
936 * @netdev: network interface device structure
938 * Returns the table size.
940 static u32 iavf_get_rxfh_indir_size(struct net_device *netdev)
942 struct iavf_adapter *adapter = netdev_priv(netdev);
944 return adapter->rss_lut_size;
948 * iavf_get_rxfh - get the rx flow hash indirection table
949 * @netdev: network interface device structure
950 * @indir: indirection table
952 * @hfunc: hash function in use
954 * Reads the indirection table directly from the hardware. Always returns 0.
956 static int iavf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
959 struct iavf_adapter *adapter = netdev_priv(netdev);
963 *hfunc = ETH_RSS_HASH_TOP;
967 memcpy(key, adapter->rss_key, adapter->rss_key_size);
969 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
970 for (i = 0; i < adapter->rss_lut_size; i++)
971 indir[i] = (u32)adapter->rss_lut[i];
977 * iavf_set_rxfh - set the rx flow hash indirection table
978 * @netdev: network interface device structure
979 * @indir: indirection table
981 * @hfunc: hash function to use
983 * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
984 * returns 0 after programming the table.
986 static int iavf_set_rxfh(struct net_device *netdev, const u32 *indir,
987 const u8 *key, const u8 hfunc)
989 struct iavf_adapter *adapter = netdev_priv(netdev);
992 /* We do not allow change in unsupported parameters */
994 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1000 memcpy(adapter->rss_key, key, adapter->rss_key_size);
1002 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
1003 for (i = 0; i < adapter->rss_lut_size; i++)
1004 adapter->rss_lut[i] = (u8)(indir[i]);
1006 return iavf_config_rss(adapter);
1009 static const struct ethtool_ops iavf_ethtool_ops = {
1010 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
1011 ETHTOOL_COALESCE_MAX_FRAMES |
1012 ETHTOOL_COALESCE_MAX_FRAMES_IRQ |
1013 ETHTOOL_COALESCE_USE_ADAPTIVE,
1014 .get_drvinfo = iavf_get_drvinfo,
1015 .get_link = ethtool_op_get_link,
1016 .get_ringparam = iavf_get_ringparam,
1017 .set_ringparam = iavf_set_ringparam,
1018 .get_strings = iavf_get_strings,
1019 .get_ethtool_stats = iavf_get_ethtool_stats,
1020 .get_sset_count = iavf_get_sset_count,
1021 .get_priv_flags = iavf_get_priv_flags,
1022 .set_priv_flags = iavf_set_priv_flags,
1023 .get_msglevel = iavf_get_msglevel,
1024 .set_msglevel = iavf_set_msglevel,
1025 .get_coalesce = iavf_get_coalesce,
1026 .set_coalesce = iavf_set_coalesce,
1027 .get_per_queue_coalesce = iavf_get_per_queue_coalesce,
1028 .set_per_queue_coalesce = iavf_set_per_queue_coalesce,
1029 .get_rxnfc = iavf_get_rxnfc,
1030 .get_rxfh_indir_size = iavf_get_rxfh_indir_size,
1031 .get_rxfh = iavf_get_rxfh,
1032 .set_rxfh = iavf_set_rxfh,
1033 .get_channels = iavf_get_channels,
1034 .set_channels = iavf_set_channels,
1035 .get_rxfh_key_size = iavf_get_rxfh_key_size,
1036 .get_link_ksettings = iavf_get_link_ksettings,
1040 * iavf_set_ethtool_ops - Initialize ethtool ops struct
1041 * @netdev: network interface device structure
1043 * Sets ethtool ops struct in our netdev so that ethtool can call
1046 void iavf_set_ethtool_ops(struct net_device *netdev)
1048 netdev->ethtool_ops = &iavf_ethtool_ops;