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->fw_version, "N/A", 4);
575 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
576 drvinfo->n_priv_flags = IAVF_PRIV_FLAGS_STR_LEN;
580 * iavf_get_ringparam - Get ring parameters
581 * @netdev: network interface device structure
582 * @ring: ethtool ringparam structure
584 * Returns current ring parameters. TX and RX rings are reported separately,
585 * but the number of rings is not reported.
587 static void iavf_get_ringparam(struct net_device *netdev,
588 struct ethtool_ringparam *ring)
590 struct iavf_adapter *adapter = netdev_priv(netdev);
592 ring->rx_max_pending = IAVF_MAX_RXD;
593 ring->tx_max_pending = IAVF_MAX_TXD;
594 ring->rx_pending = adapter->rx_desc_count;
595 ring->tx_pending = adapter->tx_desc_count;
599 * iavf_set_ringparam - Set ring parameters
600 * @netdev: network interface device structure
601 * @ring: ethtool ringparam structure
603 * Sets ring parameters. TX and RX rings are controlled separately, but the
604 * number of rings is not specified, so all rings get the same settings.
606 static int iavf_set_ringparam(struct net_device *netdev,
607 struct ethtool_ringparam *ring)
609 struct iavf_adapter *adapter = netdev_priv(netdev);
610 u32 new_rx_count, new_tx_count;
612 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
615 new_tx_count = clamp_t(u32, ring->tx_pending,
618 new_tx_count = ALIGN(new_tx_count, IAVF_REQ_DESCRIPTOR_MULTIPLE);
620 new_rx_count = clamp_t(u32, ring->rx_pending,
623 new_rx_count = ALIGN(new_rx_count, IAVF_REQ_DESCRIPTOR_MULTIPLE);
625 /* if nothing to do return success */
626 if ((new_tx_count == adapter->tx_desc_count) &&
627 (new_rx_count == adapter->rx_desc_count))
630 adapter->tx_desc_count = new_tx_count;
631 adapter->rx_desc_count = new_rx_count;
633 if (netif_running(netdev)) {
634 adapter->flags |= IAVF_FLAG_RESET_NEEDED;
635 queue_work(iavf_wq, &adapter->reset_task);
642 * __iavf_get_coalesce - get per-queue coalesce settings
643 * @netdev: the netdev to check
644 * @ec: ethtool coalesce data structure
645 * @queue: which queue to pick
647 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
648 * are per queue. If queue is <0 then we default to queue 0 as the
649 * representative value.
651 static int __iavf_get_coalesce(struct net_device *netdev,
652 struct ethtool_coalesce *ec, int queue)
654 struct iavf_adapter *adapter = netdev_priv(netdev);
655 struct iavf_vsi *vsi = &adapter->vsi;
656 struct iavf_ring *rx_ring, *tx_ring;
658 ec->tx_max_coalesced_frames = vsi->work_limit;
659 ec->rx_max_coalesced_frames = vsi->work_limit;
661 /* Rx and Tx usecs per queue value. If user doesn't specify the
662 * queue, return queue 0's value to represent.
666 else if (queue >= adapter->num_active_queues)
669 rx_ring = &adapter->rx_rings[queue];
670 tx_ring = &adapter->tx_rings[queue];
672 if (ITR_IS_DYNAMIC(rx_ring->itr_setting))
673 ec->use_adaptive_rx_coalesce = 1;
675 if (ITR_IS_DYNAMIC(tx_ring->itr_setting))
676 ec->use_adaptive_tx_coalesce = 1;
678 ec->rx_coalesce_usecs = rx_ring->itr_setting & ~IAVF_ITR_DYNAMIC;
679 ec->tx_coalesce_usecs = tx_ring->itr_setting & ~IAVF_ITR_DYNAMIC;
685 * iavf_get_coalesce - Get interrupt coalescing settings
686 * @netdev: network interface device structure
687 * @ec: ethtool coalesce structure
689 * Returns current coalescing settings. This is referred to elsewhere in the
690 * driver as Interrupt Throttle Rate, as this is how the hardware describes
691 * this functionality. Note that if per-queue settings have been modified this
692 * only represents the settings of queue 0.
694 static int iavf_get_coalesce(struct net_device *netdev,
695 struct ethtool_coalesce *ec)
697 return __iavf_get_coalesce(netdev, ec, -1);
701 * iavf_get_per_queue_coalesce - get coalesce values for specific queue
702 * @netdev: netdev to read
703 * @ec: coalesce settings from ethtool
704 * @queue: the queue to read
706 * Read specific queue's coalesce settings.
708 static int iavf_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
709 struct ethtool_coalesce *ec)
711 return __iavf_get_coalesce(netdev, ec, queue);
715 * iavf_set_itr_per_queue - set ITR values for specific queue
716 * @adapter: the VF adapter struct to set values for
717 * @ec: coalesce settings from ethtool
718 * @queue: the queue to modify
720 * Change the ITR settings for a specific queue.
722 static void iavf_set_itr_per_queue(struct iavf_adapter *adapter,
723 struct ethtool_coalesce *ec, int queue)
725 struct iavf_ring *rx_ring = &adapter->rx_rings[queue];
726 struct iavf_ring *tx_ring = &adapter->tx_rings[queue];
727 struct iavf_q_vector *q_vector;
729 rx_ring->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs);
730 tx_ring->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs);
732 rx_ring->itr_setting |= IAVF_ITR_DYNAMIC;
733 if (!ec->use_adaptive_rx_coalesce)
734 rx_ring->itr_setting ^= IAVF_ITR_DYNAMIC;
736 tx_ring->itr_setting |= IAVF_ITR_DYNAMIC;
737 if (!ec->use_adaptive_tx_coalesce)
738 tx_ring->itr_setting ^= IAVF_ITR_DYNAMIC;
740 q_vector = rx_ring->q_vector;
741 q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting);
743 q_vector = tx_ring->q_vector;
744 q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting);
746 /* The interrupt handler itself will take care of programming
747 * the Tx and Rx ITR values based on the values we have entered
748 * into the q_vector, no need to write the values now.
753 * __iavf_set_coalesce - set coalesce settings for particular queue
754 * @netdev: the netdev to change
755 * @ec: ethtool coalesce settings
756 * @queue: the queue to change
758 * Sets the coalesce settings for a particular queue.
760 static int __iavf_set_coalesce(struct net_device *netdev,
761 struct ethtool_coalesce *ec, int queue)
763 struct iavf_adapter *adapter = netdev_priv(netdev);
764 struct iavf_vsi *vsi = &adapter->vsi;
767 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
768 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
770 if (ec->rx_coalesce_usecs == 0) {
771 if (ec->use_adaptive_rx_coalesce)
772 netif_info(adapter, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
773 } else if ((ec->rx_coalesce_usecs < IAVF_MIN_ITR) ||
774 (ec->rx_coalesce_usecs > IAVF_MAX_ITR)) {
775 netif_info(adapter, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
777 } else if (ec->tx_coalesce_usecs == 0) {
778 if (ec->use_adaptive_tx_coalesce)
779 netif_info(adapter, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
780 } else if ((ec->tx_coalesce_usecs < IAVF_MIN_ITR) ||
781 (ec->tx_coalesce_usecs > IAVF_MAX_ITR)) {
782 netif_info(adapter, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
786 /* Rx and Tx usecs has per queue value. If user doesn't specify the
787 * queue, apply to all queues.
790 for (i = 0; i < adapter->num_active_queues; i++)
791 iavf_set_itr_per_queue(adapter, ec, i);
792 } else if (queue < adapter->num_active_queues) {
793 iavf_set_itr_per_queue(adapter, ec, queue);
795 netif_info(adapter, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
796 adapter->num_active_queues - 1);
804 * iavf_set_coalesce - Set interrupt coalescing settings
805 * @netdev: network interface device structure
806 * @ec: ethtool coalesce structure
808 * Change current coalescing settings for every queue.
810 static int iavf_set_coalesce(struct net_device *netdev,
811 struct ethtool_coalesce *ec)
813 return __iavf_set_coalesce(netdev, ec, -1);
817 * iavf_set_per_queue_coalesce - set specific queue's coalesce settings
818 * @netdev: the netdev to change
819 * @ec: ethtool's coalesce settings
820 * @queue: the queue to modify
822 * Modifies a specific queue's coalesce settings.
824 static int iavf_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
825 struct ethtool_coalesce *ec)
827 return __iavf_set_coalesce(netdev, ec, queue);
831 * iavf_fltr_to_ethtool_flow - convert filter type values to ethtool
833 * @flow: filter type to be converted
835 * Returns the corresponding ethtool flow type.
837 static int iavf_fltr_to_ethtool_flow(enum iavf_fdir_flow_type flow)
840 case IAVF_FDIR_FLOW_IPV4_TCP:
842 case IAVF_FDIR_FLOW_IPV4_UDP:
844 case IAVF_FDIR_FLOW_IPV4_SCTP:
846 case IAVF_FDIR_FLOW_IPV4_AH:
848 case IAVF_FDIR_FLOW_IPV4_ESP:
850 case IAVF_FDIR_FLOW_IPV4_OTHER:
851 return IPV4_USER_FLOW;
852 case IAVF_FDIR_FLOW_IPV6_TCP:
854 case IAVF_FDIR_FLOW_IPV6_UDP:
856 case IAVF_FDIR_FLOW_IPV6_SCTP:
858 case IAVF_FDIR_FLOW_IPV6_AH:
860 case IAVF_FDIR_FLOW_IPV6_ESP:
862 case IAVF_FDIR_FLOW_IPV6_OTHER:
863 return IPV6_USER_FLOW;
864 case IAVF_FDIR_FLOW_NON_IP_L2:
867 /* 0 is undefined ethtool flow */
873 * iavf_ethtool_flow_to_fltr - convert ethtool flow type to filter enum
874 * @eth: Ethtool flow type to be converted
878 static enum iavf_fdir_flow_type iavf_ethtool_flow_to_fltr(int eth)
882 return IAVF_FDIR_FLOW_IPV4_TCP;
884 return IAVF_FDIR_FLOW_IPV4_UDP;
886 return IAVF_FDIR_FLOW_IPV4_SCTP;
888 return IAVF_FDIR_FLOW_IPV4_AH;
890 return IAVF_FDIR_FLOW_IPV4_ESP;
892 return IAVF_FDIR_FLOW_IPV4_OTHER;
894 return IAVF_FDIR_FLOW_IPV6_TCP;
896 return IAVF_FDIR_FLOW_IPV6_UDP;
898 return IAVF_FDIR_FLOW_IPV6_SCTP;
900 return IAVF_FDIR_FLOW_IPV6_AH;
902 return IAVF_FDIR_FLOW_IPV6_ESP;
904 return IAVF_FDIR_FLOW_IPV6_OTHER;
906 return IAVF_FDIR_FLOW_NON_IP_L2;
908 return IAVF_FDIR_FLOW_NONE;
913 * iavf_is_mask_valid - check mask field set
914 * @mask: full mask to check
915 * @field: field for which mask should be valid
917 * If the mask is fully set return true. If it is not valid for field return
920 static bool iavf_is_mask_valid(u64 mask, u64 field)
922 return (mask & field) == field;
926 * iavf_parse_rx_flow_user_data - deconstruct user-defined data
927 * @fsp: pointer to ethtool Rx flow specification
928 * @fltr: pointer to Flow Director filter for userdef data storage
930 * Returns 0 on success, negative error value on failure
933 iavf_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
934 struct iavf_fdir_fltr *fltr)
936 struct iavf_flex_word *flex;
939 if (!(fsp->flow_type & FLOW_EXT))
942 for (i = 0; i < IAVF_FLEX_WORD_NUM; i++) {
943 #define IAVF_USERDEF_FLEX_WORD_M GENMASK(15, 0)
944 #define IAVF_USERDEF_FLEX_OFFS_S 16
945 #define IAVF_USERDEF_FLEX_OFFS_M GENMASK(31, IAVF_USERDEF_FLEX_OFFS_S)
946 #define IAVF_USERDEF_FLEX_FLTR_M GENMASK(31, 0)
947 u32 value = be32_to_cpu(fsp->h_ext.data[i]);
948 u32 mask = be32_to_cpu(fsp->m_ext.data[i]);
953 if (!iavf_is_mask_valid(mask, IAVF_USERDEF_FLEX_FLTR_M))
956 /* 504 is the maximum value for offsets, and offset is measured
957 * from the start of the MAC address.
959 #define IAVF_USERDEF_FLEX_MAX_OFFS_VAL 504
960 flex = &fltr->flex_words[cnt++];
961 flex->word = value & IAVF_USERDEF_FLEX_WORD_M;
962 flex->offset = (value & IAVF_USERDEF_FLEX_OFFS_M) >>
963 IAVF_USERDEF_FLEX_OFFS_S;
964 if (flex->offset > IAVF_USERDEF_FLEX_MAX_OFFS_VAL)
968 fltr->flex_cnt = cnt;
974 * iavf_fill_rx_flow_ext_data - fill the additional data
975 * @fsp: pointer to ethtool Rx flow specification
976 * @fltr: pointer to Flow Director filter to get additional data
979 iavf_fill_rx_flow_ext_data(struct ethtool_rx_flow_spec *fsp,
980 struct iavf_fdir_fltr *fltr)
982 if (!fltr->ext_mask.usr_def[0] && !fltr->ext_mask.usr_def[1])
985 fsp->flow_type |= FLOW_EXT;
987 memcpy(fsp->h_ext.data, fltr->ext_data.usr_def, sizeof(fsp->h_ext.data));
988 memcpy(fsp->m_ext.data, fltr->ext_mask.usr_def, sizeof(fsp->m_ext.data));
992 * iavf_get_ethtool_fdir_entry - fill ethtool structure with Flow Director filter data
993 * @adapter: the VF adapter structure that contains filter list
994 * @cmd: ethtool command data structure to receive the filter data
996 * Returns 0 as expected for success by ethtool
999 iavf_get_ethtool_fdir_entry(struct iavf_adapter *adapter,
1000 struct ethtool_rxnfc *cmd)
1002 struct ethtool_rx_flow_spec *fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
1003 struct iavf_fdir_fltr *rule = NULL;
1006 if (!FDIR_FLTR_SUPPORT(adapter))
1009 spin_lock_bh(&adapter->fdir_fltr_lock);
1011 rule = iavf_find_fdir_fltr_by_loc(adapter, fsp->location);
1017 fsp->flow_type = iavf_fltr_to_ethtool_flow(rule->flow_type);
1019 memset(&fsp->m_u, 0, sizeof(fsp->m_u));
1020 memset(&fsp->m_ext, 0, sizeof(fsp->m_ext));
1022 switch (fsp->flow_type) {
1026 fsp->h_u.tcp_ip4_spec.ip4src = rule->ip_data.v4_addrs.src_ip;
1027 fsp->h_u.tcp_ip4_spec.ip4dst = rule->ip_data.v4_addrs.dst_ip;
1028 fsp->h_u.tcp_ip4_spec.psrc = rule->ip_data.src_port;
1029 fsp->h_u.tcp_ip4_spec.pdst = rule->ip_data.dst_port;
1030 fsp->h_u.tcp_ip4_spec.tos = rule->ip_data.tos;
1031 fsp->m_u.tcp_ip4_spec.ip4src = rule->ip_mask.v4_addrs.src_ip;
1032 fsp->m_u.tcp_ip4_spec.ip4dst = rule->ip_mask.v4_addrs.dst_ip;
1033 fsp->m_u.tcp_ip4_spec.psrc = rule->ip_mask.src_port;
1034 fsp->m_u.tcp_ip4_spec.pdst = rule->ip_mask.dst_port;
1035 fsp->m_u.tcp_ip4_spec.tos = rule->ip_mask.tos;
1039 fsp->h_u.ah_ip4_spec.ip4src = rule->ip_data.v4_addrs.src_ip;
1040 fsp->h_u.ah_ip4_spec.ip4dst = rule->ip_data.v4_addrs.dst_ip;
1041 fsp->h_u.ah_ip4_spec.spi = rule->ip_data.spi;
1042 fsp->h_u.ah_ip4_spec.tos = rule->ip_data.tos;
1043 fsp->m_u.ah_ip4_spec.ip4src = rule->ip_mask.v4_addrs.src_ip;
1044 fsp->m_u.ah_ip4_spec.ip4dst = rule->ip_mask.v4_addrs.dst_ip;
1045 fsp->m_u.ah_ip4_spec.spi = rule->ip_mask.spi;
1046 fsp->m_u.ah_ip4_spec.tos = rule->ip_mask.tos;
1048 case IPV4_USER_FLOW:
1049 fsp->h_u.usr_ip4_spec.ip4src = rule->ip_data.v4_addrs.src_ip;
1050 fsp->h_u.usr_ip4_spec.ip4dst = rule->ip_data.v4_addrs.dst_ip;
1051 fsp->h_u.usr_ip4_spec.l4_4_bytes = rule->ip_data.l4_header;
1052 fsp->h_u.usr_ip4_spec.tos = rule->ip_data.tos;
1053 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1054 fsp->h_u.usr_ip4_spec.proto = rule->ip_data.proto;
1055 fsp->m_u.usr_ip4_spec.ip4src = rule->ip_mask.v4_addrs.src_ip;
1056 fsp->m_u.usr_ip4_spec.ip4dst = rule->ip_mask.v4_addrs.dst_ip;
1057 fsp->m_u.usr_ip4_spec.l4_4_bytes = rule->ip_mask.l4_header;
1058 fsp->m_u.usr_ip4_spec.tos = rule->ip_mask.tos;
1059 fsp->m_u.usr_ip4_spec.ip_ver = 0xFF;
1060 fsp->m_u.usr_ip4_spec.proto = rule->ip_mask.proto;
1065 memcpy(fsp->h_u.usr_ip6_spec.ip6src, &rule->ip_data.v6_addrs.src_ip,
1066 sizeof(struct in6_addr));
1067 memcpy(fsp->h_u.usr_ip6_spec.ip6dst, &rule->ip_data.v6_addrs.dst_ip,
1068 sizeof(struct in6_addr));
1069 fsp->h_u.tcp_ip6_spec.psrc = rule->ip_data.src_port;
1070 fsp->h_u.tcp_ip6_spec.pdst = rule->ip_data.dst_port;
1071 fsp->h_u.tcp_ip6_spec.tclass = rule->ip_data.tclass;
1072 memcpy(fsp->m_u.usr_ip6_spec.ip6src, &rule->ip_mask.v6_addrs.src_ip,
1073 sizeof(struct in6_addr));
1074 memcpy(fsp->m_u.usr_ip6_spec.ip6dst, &rule->ip_mask.v6_addrs.dst_ip,
1075 sizeof(struct in6_addr));
1076 fsp->m_u.tcp_ip6_spec.psrc = rule->ip_mask.src_port;
1077 fsp->m_u.tcp_ip6_spec.pdst = rule->ip_mask.dst_port;
1078 fsp->m_u.tcp_ip6_spec.tclass = rule->ip_mask.tclass;
1082 memcpy(fsp->h_u.ah_ip6_spec.ip6src, &rule->ip_data.v6_addrs.src_ip,
1083 sizeof(struct in6_addr));
1084 memcpy(fsp->h_u.ah_ip6_spec.ip6dst, &rule->ip_data.v6_addrs.dst_ip,
1085 sizeof(struct in6_addr));
1086 fsp->h_u.ah_ip6_spec.spi = rule->ip_data.spi;
1087 fsp->h_u.ah_ip6_spec.tclass = rule->ip_data.tclass;
1088 memcpy(fsp->m_u.ah_ip6_spec.ip6src, &rule->ip_mask.v6_addrs.src_ip,
1089 sizeof(struct in6_addr));
1090 memcpy(fsp->m_u.ah_ip6_spec.ip6dst, &rule->ip_mask.v6_addrs.dst_ip,
1091 sizeof(struct in6_addr));
1092 fsp->m_u.ah_ip6_spec.spi = rule->ip_mask.spi;
1093 fsp->m_u.ah_ip6_spec.tclass = rule->ip_mask.tclass;
1095 case IPV6_USER_FLOW:
1096 memcpy(fsp->h_u.usr_ip6_spec.ip6src, &rule->ip_data.v6_addrs.src_ip,
1097 sizeof(struct in6_addr));
1098 memcpy(fsp->h_u.usr_ip6_spec.ip6dst, &rule->ip_data.v6_addrs.dst_ip,
1099 sizeof(struct in6_addr));
1100 fsp->h_u.usr_ip6_spec.l4_4_bytes = rule->ip_data.l4_header;
1101 fsp->h_u.usr_ip6_spec.tclass = rule->ip_data.tclass;
1102 fsp->h_u.usr_ip6_spec.l4_proto = rule->ip_data.proto;
1103 memcpy(fsp->m_u.usr_ip6_spec.ip6src, &rule->ip_mask.v6_addrs.src_ip,
1104 sizeof(struct in6_addr));
1105 memcpy(fsp->m_u.usr_ip6_spec.ip6dst, &rule->ip_mask.v6_addrs.dst_ip,
1106 sizeof(struct in6_addr));
1107 fsp->m_u.usr_ip6_spec.l4_4_bytes = rule->ip_mask.l4_header;
1108 fsp->m_u.usr_ip6_spec.tclass = rule->ip_mask.tclass;
1109 fsp->m_u.usr_ip6_spec.l4_proto = rule->ip_mask.proto;
1112 fsp->h_u.ether_spec.h_proto = rule->eth_data.etype;
1113 fsp->m_u.ether_spec.h_proto = rule->eth_mask.etype;
1120 iavf_fill_rx_flow_ext_data(fsp, rule);
1122 if (rule->action == VIRTCHNL_ACTION_DROP)
1123 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1125 fsp->ring_cookie = rule->q_index;
1128 spin_unlock_bh(&adapter->fdir_fltr_lock);
1133 * iavf_get_fdir_fltr_ids - fill buffer with filter IDs of active filters
1134 * @adapter: the VF adapter structure containing the filter list
1135 * @cmd: ethtool command data structure
1136 * @rule_locs: ethtool array passed in from OS to receive filter IDs
1138 * Returns 0 as expected for success by ethtool
1141 iavf_get_fdir_fltr_ids(struct iavf_adapter *adapter, struct ethtool_rxnfc *cmd,
1144 struct iavf_fdir_fltr *fltr;
1145 unsigned int cnt = 0;
1148 if (!FDIR_FLTR_SUPPORT(adapter))
1151 cmd->data = IAVF_MAX_FDIR_FILTERS;
1153 spin_lock_bh(&adapter->fdir_fltr_lock);
1155 list_for_each_entry(fltr, &adapter->fdir_list_head, list) {
1156 if (cnt == cmd->rule_cnt) {
1160 rule_locs[cnt] = fltr->loc;
1165 spin_unlock_bh(&adapter->fdir_fltr_lock);
1167 cmd->rule_cnt = cnt;
1173 * iavf_add_fdir_fltr_info - Set the input set for Flow Director filter
1174 * @adapter: pointer to the VF adapter structure
1175 * @fsp: pointer to ethtool Rx flow specification
1176 * @fltr: filter structure
1179 iavf_add_fdir_fltr_info(struct iavf_adapter *adapter, struct ethtool_rx_flow_spec *fsp,
1180 struct iavf_fdir_fltr *fltr)
1182 u32 flow_type, q_index = 0;
1183 enum virtchnl_action act;
1186 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
1187 act = VIRTCHNL_ACTION_DROP;
1189 q_index = fsp->ring_cookie;
1190 if (q_index >= adapter->num_active_queues)
1193 act = VIRTCHNL_ACTION_QUEUE;
1197 fltr->loc = fsp->location;
1198 fltr->q_index = q_index;
1200 if (fsp->flow_type & FLOW_EXT) {
1201 memcpy(fltr->ext_data.usr_def, fsp->h_ext.data,
1202 sizeof(fltr->ext_data.usr_def));
1203 memcpy(fltr->ext_mask.usr_def, fsp->m_ext.data,
1204 sizeof(fltr->ext_mask.usr_def));
1207 flow_type = fsp->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS);
1208 fltr->flow_type = iavf_ethtool_flow_to_fltr(flow_type);
1210 switch (flow_type) {
1214 fltr->ip_data.v4_addrs.src_ip = fsp->h_u.tcp_ip4_spec.ip4src;
1215 fltr->ip_data.v4_addrs.dst_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
1216 fltr->ip_data.src_port = fsp->h_u.tcp_ip4_spec.psrc;
1217 fltr->ip_data.dst_port = fsp->h_u.tcp_ip4_spec.pdst;
1218 fltr->ip_data.tos = fsp->h_u.tcp_ip4_spec.tos;
1219 fltr->ip_mask.v4_addrs.src_ip = fsp->m_u.tcp_ip4_spec.ip4src;
1220 fltr->ip_mask.v4_addrs.dst_ip = fsp->m_u.tcp_ip4_spec.ip4dst;
1221 fltr->ip_mask.src_port = fsp->m_u.tcp_ip4_spec.psrc;
1222 fltr->ip_mask.dst_port = fsp->m_u.tcp_ip4_spec.pdst;
1223 fltr->ip_mask.tos = fsp->m_u.tcp_ip4_spec.tos;
1227 fltr->ip_data.v4_addrs.src_ip = fsp->h_u.ah_ip4_spec.ip4src;
1228 fltr->ip_data.v4_addrs.dst_ip = fsp->h_u.ah_ip4_spec.ip4dst;
1229 fltr->ip_data.spi = fsp->h_u.ah_ip4_spec.spi;
1230 fltr->ip_data.tos = fsp->h_u.ah_ip4_spec.tos;
1231 fltr->ip_mask.v4_addrs.src_ip = fsp->m_u.ah_ip4_spec.ip4src;
1232 fltr->ip_mask.v4_addrs.dst_ip = fsp->m_u.ah_ip4_spec.ip4dst;
1233 fltr->ip_mask.spi = fsp->m_u.ah_ip4_spec.spi;
1234 fltr->ip_mask.tos = fsp->m_u.ah_ip4_spec.tos;
1236 case IPV4_USER_FLOW:
1237 fltr->ip_data.v4_addrs.src_ip = fsp->h_u.usr_ip4_spec.ip4src;
1238 fltr->ip_data.v4_addrs.dst_ip = fsp->h_u.usr_ip4_spec.ip4dst;
1239 fltr->ip_data.l4_header = fsp->h_u.usr_ip4_spec.l4_4_bytes;
1240 fltr->ip_data.tos = fsp->h_u.usr_ip4_spec.tos;
1241 fltr->ip_data.proto = fsp->h_u.usr_ip4_spec.proto;
1242 fltr->ip_mask.v4_addrs.src_ip = fsp->m_u.usr_ip4_spec.ip4src;
1243 fltr->ip_mask.v4_addrs.dst_ip = fsp->m_u.usr_ip4_spec.ip4dst;
1244 fltr->ip_mask.l4_header = fsp->m_u.usr_ip4_spec.l4_4_bytes;
1245 fltr->ip_mask.tos = fsp->m_u.usr_ip4_spec.tos;
1246 fltr->ip_mask.proto = fsp->m_u.usr_ip4_spec.proto;
1251 memcpy(&fltr->ip_data.v6_addrs.src_ip, fsp->h_u.usr_ip6_spec.ip6src,
1252 sizeof(struct in6_addr));
1253 memcpy(&fltr->ip_data.v6_addrs.dst_ip, fsp->h_u.usr_ip6_spec.ip6dst,
1254 sizeof(struct in6_addr));
1255 fltr->ip_data.src_port = fsp->h_u.tcp_ip6_spec.psrc;
1256 fltr->ip_data.dst_port = fsp->h_u.tcp_ip6_spec.pdst;
1257 fltr->ip_data.tclass = fsp->h_u.tcp_ip6_spec.tclass;
1258 memcpy(&fltr->ip_mask.v6_addrs.src_ip, fsp->m_u.usr_ip6_spec.ip6src,
1259 sizeof(struct in6_addr));
1260 memcpy(&fltr->ip_mask.v6_addrs.dst_ip, fsp->m_u.usr_ip6_spec.ip6dst,
1261 sizeof(struct in6_addr));
1262 fltr->ip_mask.src_port = fsp->m_u.tcp_ip6_spec.psrc;
1263 fltr->ip_mask.dst_port = fsp->m_u.tcp_ip6_spec.pdst;
1264 fltr->ip_mask.tclass = fsp->m_u.tcp_ip6_spec.tclass;
1268 memcpy(&fltr->ip_data.v6_addrs.src_ip, fsp->h_u.ah_ip6_spec.ip6src,
1269 sizeof(struct in6_addr));
1270 memcpy(&fltr->ip_data.v6_addrs.dst_ip, fsp->h_u.ah_ip6_spec.ip6dst,
1271 sizeof(struct in6_addr));
1272 fltr->ip_data.spi = fsp->h_u.ah_ip6_spec.spi;
1273 fltr->ip_data.tclass = fsp->h_u.ah_ip6_spec.tclass;
1274 memcpy(&fltr->ip_mask.v6_addrs.src_ip, fsp->m_u.ah_ip6_spec.ip6src,
1275 sizeof(struct in6_addr));
1276 memcpy(&fltr->ip_mask.v6_addrs.dst_ip, fsp->m_u.ah_ip6_spec.ip6dst,
1277 sizeof(struct in6_addr));
1278 fltr->ip_mask.spi = fsp->m_u.ah_ip6_spec.spi;
1279 fltr->ip_mask.tclass = fsp->m_u.ah_ip6_spec.tclass;
1281 case IPV6_USER_FLOW:
1282 memcpy(&fltr->ip_data.v6_addrs.src_ip, fsp->h_u.usr_ip6_spec.ip6src,
1283 sizeof(struct in6_addr));
1284 memcpy(&fltr->ip_data.v6_addrs.dst_ip, fsp->h_u.usr_ip6_spec.ip6dst,
1285 sizeof(struct in6_addr));
1286 fltr->ip_data.l4_header = fsp->h_u.usr_ip6_spec.l4_4_bytes;
1287 fltr->ip_data.tclass = fsp->h_u.usr_ip6_spec.tclass;
1288 fltr->ip_data.proto = fsp->h_u.usr_ip6_spec.l4_proto;
1289 memcpy(&fltr->ip_mask.v6_addrs.src_ip, fsp->m_u.usr_ip6_spec.ip6src,
1290 sizeof(struct in6_addr));
1291 memcpy(&fltr->ip_mask.v6_addrs.dst_ip, fsp->m_u.usr_ip6_spec.ip6dst,
1292 sizeof(struct in6_addr));
1293 fltr->ip_mask.l4_header = fsp->m_u.usr_ip6_spec.l4_4_bytes;
1294 fltr->ip_mask.tclass = fsp->m_u.usr_ip6_spec.tclass;
1295 fltr->ip_mask.proto = fsp->m_u.usr_ip6_spec.l4_proto;
1298 fltr->eth_data.etype = fsp->h_u.ether_spec.h_proto;
1299 fltr->eth_mask.etype = fsp->m_u.ether_spec.h_proto;
1302 /* not doing un-parsed flow types */
1306 if (iavf_fdir_is_dup_fltr(adapter, fltr))
1309 err = iavf_parse_rx_flow_user_data(fsp, fltr);
1313 return iavf_fill_fdir_add_msg(adapter, fltr);
1317 * iavf_add_fdir_ethtool - add Flow Director filter
1318 * @adapter: pointer to the VF adapter structure
1319 * @cmd: command to add Flow Director filter
1321 * Returns 0 on success and negative values for failure
1323 static int iavf_add_fdir_ethtool(struct iavf_adapter *adapter, struct ethtool_rxnfc *cmd)
1325 struct ethtool_rx_flow_spec *fsp = &cmd->fs;
1326 struct iavf_fdir_fltr *fltr;
1330 if (!FDIR_FLTR_SUPPORT(adapter))
1333 if (fsp->flow_type & FLOW_MAC_EXT)
1336 if (adapter->fdir_active_fltr >= IAVF_MAX_FDIR_FILTERS) {
1337 dev_err(&adapter->pdev->dev,
1338 "Unable to add Flow Director filter because VF reached the limit of max allowed filters (%u)\n",
1339 IAVF_MAX_FDIR_FILTERS);
1343 spin_lock_bh(&adapter->fdir_fltr_lock);
1344 if (iavf_find_fdir_fltr_by_loc(adapter, fsp->location)) {
1345 dev_err(&adapter->pdev->dev, "Failed to add Flow Director filter, it already exists\n");
1346 spin_unlock_bh(&adapter->fdir_fltr_lock);
1349 spin_unlock_bh(&adapter->fdir_fltr_lock);
1351 fltr = kzalloc(sizeof(*fltr), GFP_KERNEL);
1355 while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK,
1356 &adapter->crit_section)) {
1364 err = iavf_add_fdir_fltr_info(adapter, fsp, fltr);
1368 spin_lock_bh(&adapter->fdir_fltr_lock);
1369 iavf_fdir_list_add_fltr(adapter, fltr);
1370 adapter->fdir_active_fltr++;
1371 fltr->state = IAVF_FDIR_FLTR_ADD_REQUEST;
1372 adapter->aq_required |= IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1373 spin_unlock_bh(&adapter->fdir_fltr_lock);
1375 mod_delayed_work(iavf_wq, &adapter->watchdog_task, 0);
1381 clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section);
1386 * iavf_del_fdir_ethtool - delete Flow Director filter
1387 * @adapter: pointer to the VF adapter structure
1388 * @cmd: command to delete Flow Director filter
1390 * Returns 0 on success and negative values for failure
1392 static int iavf_del_fdir_ethtool(struct iavf_adapter *adapter, struct ethtool_rxnfc *cmd)
1394 struct ethtool_rx_flow_spec *fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
1395 struct iavf_fdir_fltr *fltr = NULL;
1398 if (!FDIR_FLTR_SUPPORT(adapter))
1401 spin_lock_bh(&adapter->fdir_fltr_lock);
1402 fltr = iavf_find_fdir_fltr_by_loc(adapter, fsp->location);
1404 if (fltr->state == IAVF_FDIR_FLTR_ACTIVE) {
1405 fltr->state = IAVF_FDIR_FLTR_DEL_REQUEST;
1406 adapter->aq_required |= IAVF_FLAG_AQ_DEL_FDIR_FILTER;
1410 } else if (adapter->fdir_active_fltr) {
1413 spin_unlock_bh(&adapter->fdir_fltr_lock);
1415 if (fltr && fltr->state == IAVF_FDIR_FLTR_DEL_REQUEST)
1416 mod_delayed_work(iavf_wq, &adapter->watchdog_task, 0);
1422 * iavf_adv_rss_parse_hdrs - parses headers from RSS hash input
1423 * @cmd: ethtool rxnfc command
1425 * This function parses the rxnfc command and returns intended
1426 * header types for RSS configuration
1428 static u32 iavf_adv_rss_parse_hdrs(struct ethtool_rxnfc *cmd)
1430 u32 hdrs = IAVF_ADV_RSS_FLOW_SEG_HDR_NONE;
1432 switch (cmd->flow_type) {
1434 hdrs |= IAVF_ADV_RSS_FLOW_SEG_HDR_TCP |
1435 IAVF_ADV_RSS_FLOW_SEG_HDR_IPV4;
1438 hdrs |= IAVF_ADV_RSS_FLOW_SEG_HDR_UDP |
1439 IAVF_ADV_RSS_FLOW_SEG_HDR_IPV4;
1442 hdrs |= IAVF_ADV_RSS_FLOW_SEG_HDR_SCTP |
1443 IAVF_ADV_RSS_FLOW_SEG_HDR_IPV4;
1446 hdrs |= IAVF_ADV_RSS_FLOW_SEG_HDR_TCP |
1447 IAVF_ADV_RSS_FLOW_SEG_HDR_IPV6;
1450 hdrs |= IAVF_ADV_RSS_FLOW_SEG_HDR_UDP |
1451 IAVF_ADV_RSS_FLOW_SEG_HDR_IPV6;
1454 hdrs |= IAVF_ADV_RSS_FLOW_SEG_HDR_SCTP |
1455 IAVF_ADV_RSS_FLOW_SEG_HDR_IPV6;
1465 * iavf_adv_rss_parse_hash_flds - parses hash fields from RSS hash input
1466 * @cmd: ethtool rxnfc command
1468 * This function parses the rxnfc command and returns intended hash fields for
1471 static u64 iavf_adv_rss_parse_hash_flds(struct ethtool_rxnfc *cmd)
1473 u64 hfld = IAVF_ADV_RSS_HASH_INVALID;
1475 if (cmd->data & RXH_IP_SRC || cmd->data & RXH_IP_DST) {
1476 switch (cmd->flow_type) {
1480 if (cmd->data & RXH_IP_SRC)
1481 hfld |= IAVF_ADV_RSS_HASH_FLD_IPV4_SA;
1482 if (cmd->data & RXH_IP_DST)
1483 hfld |= IAVF_ADV_RSS_HASH_FLD_IPV4_DA;
1488 if (cmd->data & RXH_IP_SRC)
1489 hfld |= IAVF_ADV_RSS_HASH_FLD_IPV6_SA;
1490 if (cmd->data & RXH_IP_DST)
1491 hfld |= IAVF_ADV_RSS_HASH_FLD_IPV6_DA;
1498 if (cmd->data & RXH_L4_B_0_1 || cmd->data & RXH_L4_B_2_3) {
1499 switch (cmd->flow_type) {
1502 if (cmd->data & RXH_L4_B_0_1)
1503 hfld |= IAVF_ADV_RSS_HASH_FLD_TCP_SRC_PORT;
1504 if (cmd->data & RXH_L4_B_2_3)
1505 hfld |= IAVF_ADV_RSS_HASH_FLD_TCP_DST_PORT;
1509 if (cmd->data & RXH_L4_B_0_1)
1510 hfld |= IAVF_ADV_RSS_HASH_FLD_UDP_SRC_PORT;
1511 if (cmd->data & RXH_L4_B_2_3)
1512 hfld |= IAVF_ADV_RSS_HASH_FLD_UDP_DST_PORT;
1516 if (cmd->data & RXH_L4_B_0_1)
1517 hfld |= IAVF_ADV_RSS_HASH_FLD_SCTP_SRC_PORT;
1518 if (cmd->data & RXH_L4_B_2_3)
1519 hfld |= IAVF_ADV_RSS_HASH_FLD_SCTP_DST_PORT;
1530 * iavf_set_adv_rss_hash_opt - Enable/Disable flow types for RSS hash
1531 * @adapter: pointer to the VF adapter structure
1532 * @cmd: ethtool rxnfc command
1534 * Returns Success if the flow input set is supported.
1537 iavf_set_adv_rss_hash_opt(struct iavf_adapter *adapter,
1538 struct ethtool_rxnfc *cmd)
1540 struct iavf_adv_rss *rss_old, *rss_new;
1541 bool rss_new_add = false;
1542 int count = 50, err = 0;
1546 if (!ADV_RSS_SUPPORT(adapter))
1549 hdrs = iavf_adv_rss_parse_hdrs(cmd);
1550 if (hdrs == IAVF_ADV_RSS_FLOW_SEG_HDR_NONE)
1553 hash_flds = iavf_adv_rss_parse_hash_flds(cmd);
1554 if (hash_flds == IAVF_ADV_RSS_HASH_INVALID)
1557 rss_new = kzalloc(sizeof(*rss_new), GFP_KERNEL);
1561 if (iavf_fill_adv_rss_cfg_msg(&rss_new->cfg_msg, hdrs, hash_flds)) {
1566 while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK,
1567 &adapter->crit_section)) {
1576 spin_lock_bh(&adapter->adv_rss_lock);
1577 rss_old = iavf_find_adv_rss_cfg_by_hdrs(adapter, hdrs);
1579 if (rss_old->state != IAVF_ADV_RSS_ACTIVE) {
1581 } else if (rss_old->hash_flds != hash_flds) {
1582 rss_old->state = IAVF_ADV_RSS_ADD_REQUEST;
1583 rss_old->hash_flds = hash_flds;
1584 memcpy(&rss_old->cfg_msg, &rss_new->cfg_msg,
1585 sizeof(rss_new->cfg_msg));
1586 adapter->aq_required |= IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1592 rss_new->state = IAVF_ADV_RSS_ADD_REQUEST;
1593 rss_new->packet_hdrs = hdrs;
1594 rss_new->hash_flds = hash_flds;
1595 list_add_tail(&rss_new->list, &adapter->adv_rss_list_head);
1596 adapter->aq_required |= IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1598 spin_unlock_bh(&adapter->adv_rss_lock);
1601 mod_delayed_work(iavf_wq, &adapter->watchdog_task, 0);
1603 clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section);
1612 * iavf_get_adv_rss_hash_opt - Retrieve hash fields for a given flow-type
1613 * @adapter: pointer to the VF adapter structure
1614 * @cmd: ethtool rxnfc command
1616 * Returns Success if the flow input set is supported.
1619 iavf_get_adv_rss_hash_opt(struct iavf_adapter *adapter,
1620 struct ethtool_rxnfc *cmd)
1622 struct iavf_adv_rss *rss;
1626 if (!ADV_RSS_SUPPORT(adapter))
1631 hdrs = iavf_adv_rss_parse_hdrs(cmd);
1632 if (hdrs == IAVF_ADV_RSS_FLOW_SEG_HDR_NONE)
1635 spin_lock_bh(&adapter->adv_rss_lock);
1636 rss = iavf_find_adv_rss_cfg_by_hdrs(adapter, hdrs);
1638 hash_flds = rss->hash_flds;
1640 hash_flds = IAVF_ADV_RSS_HASH_INVALID;
1641 spin_unlock_bh(&adapter->adv_rss_lock);
1643 if (hash_flds == IAVF_ADV_RSS_HASH_INVALID)
1646 if (hash_flds & (IAVF_ADV_RSS_HASH_FLD_IPV4_SA |
1647 IAVF_ADV_RSS_HASH_FLD_IPV6_SA))
1648 cmd->data |= (u64)RXH_IP_SRC;
1650 if (hash_flds & (IAVF_ADV_RSS_HASH_FLD_IPV4_DA |
1651 IAVF_ADV_RSS_HASH_FLD_IPV6_DA))
1652 cmd->data |= (u64)RXH_IP_DST;
1654 if (hash_flds & (IAVF_ADV_RSS_HASH_FLD_TCP_SRC_PORT |
1655 IAVF_ADV_RSS_HASH_FLD_UDP_SRC_PORT |
1656 IAVF_ADV_RSS_HASH_FLD_SCTP_SRC_PORT))
1657 cmd->data |= (u64)RXH_L4_B_0_1;
1659 if (hash_flds & (IAVF_ADV_RSS_HASH_FLD_TCP_DST_PORT |
1660 IAVF_ADV_RSS_HASH_FLD_UDP_DST_PORT |
1661 IAVF_ADV_RSS_HASH_FLD_SCTP_DST_PORT))
1662 cmd->data |= (u64)RXH_L4_B_2_3;
1668 * iavf_set_rxnfc - command to set Rx flow rules.
1669 * @netdev: network interface device structure
1670 * @cmd: ethtool rxnfc command
1672 * Returns 0 for success and negative values for errors
1674 static int iavf_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1676 struct iavf_adapter *adapter = netdev_priv(netdev);
1677 int ret = -EOPNOTSUPP;
1680 case ETHTOOL_SRXCLSRLINS:
1681 ret = iavf_add_fdir_ethtool(adapter, cmd);
1683 case ETHTOOL_SRXCLSRLDEL:
1684 ret = iavf_del_fdir_ethtool(adapter, cmd);
1687 ret = iavf_set_adv_rss_hash_opt(adapter, cmd);
1697 * iavf_get_rxnfc - command to get RX flow classification rules
1698 * @netdev: network interface device structure
1699 * @cmd: ethtool rxnfc command
1700 * @rule_locs: pointer to store rule locations
1702 * Returns Success if the command is supported.
1704 static int iavf_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1707 struct iavf_adapter *adapter = netdev_priv(netdev);
1708 int ret = -EOPNOTSUPP;
1711 case ETHTOOL_GRXRINGS:
1712 cmd->data = adapter->num_active_queues;
1715 case ETHTOOL_GRXCLSRLCNT:
1716 if (!FDIR_FLTR_SUPPORT(adapter))
1718 cmd->rule_cnt = adapter->fdir_active_fltr;
1719 cmd->data = IAVF_MAX_FDIR_FILTERS;
1722 case ETHTOOL_GRXCLSRULE:
1723 ret = iavf_get_ethtool_fdir_entry(adapter, cmd);
1725 case ETHTOOL_GRXCLSRLALL:
1726 ret = iavf_get_fdir_fltr_ids(adapter, cmd, (u32 *)rule_locs);
1729 ret = iavf_get_adv_rss_hash_opt(adapter, cmd);
1738 * iavf_get_channels: get the number of channels supported by the device
1739 * @netdev: network interface device structure
1740 * @ch: channel information structure
1742 * For the purposes of our device, we only use combined channels, i.e. a tx/rx
1743 * queue pair. Report one extra channel to match our "other" MSI-X vector.
1745 static void iavf_get_channels(struct net_device *netdev,
1746 struct ethtool_channels *ch)
1748 struct iavf_adapter *adapter = netdev_priv(netdev);
1750 /* Report maximum channels */
1751 ch->max_combined = adapter->vsi_res->num_queue_pairs;
1753 ch->max_other = NONQ_VECS;
1754 ch->other_count = NONQ_VECS;
1756 ch->combined_count = adapter->num_active_queues;
1760 * iavf_set_channels: set the new channel count
1761 * @netdev: network interface device structure
1762 * @ch: channel information structure
1764 * Negotiate a new number of channels with the PF then do a reset. During
1765 * reset we'll realloc queues and fix the RSS table. Returns 0 on success,
1766 * negative on failure.
1768 static int iavf_set_channels(struct net_device *netdev,
1769 struct ethtool_channels *ch)
1771 struct iavf_adapter *adapter = netdev_priv(netdev);
1772 u32 num_req = ch->combined_count;
1774 if ((adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ) &&
1776 dev_info(&adapter->pdev->dev, "Cannot set channels since ADq is enabled.\n");
1780 /* All of these should have already been checked by ethtool before this
1781 * even gets to us, but just to be sure.
1783 if (num_req > adapter->vsi_res->num_queue_pairs)
1786 if (num_req == adapter->num_active_queues)
1789 if (ch->rx_count || ch->tx_count || ch->other_count != NONQ_VECS)
1792 adapter->num_req_queues = num_req;
1793 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1794 iavf_schedule_reset(adapter);
1799 * iavf_get_rxfh_key_size - get the RSS hash key size
1800 * @netdev: network interface device structure
1802 * Returns the table size.
1804 static u32 iavf_get_rxfh_key_size(struct net_device *netdev)
1806 struct iavf_adapter *adapter = netdev_priv(netdev);
1808 return adapter->rss_key_size;
1812 * iavf_get_rxfh_indir_size - get the rx flow hash indirection table size
1813 * @netdev: network interface device structure
1815 * Returns the table size.
1817 static u32 iavf_get_rxfh_indir_size(struct net_device *netdev)
1819 struct iavf_adapter *adapter = netdev_priv(netdev);
1821 return adapter->rss_lut_size;
1825 * iavf_get_rxfh - get the rx flow hash indirection table
1826 * @netdev: network interface device structure
1827 * @indir: indirection table
1829 * @hfunc: hash function in use
1831 * Reads the indirection table directly from the hardware. Always returns 0.
1833 static int iavf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
1836 struct iavf_adapter *adapter = netdev_priv(netdev);
1840 *hfunc = ETH_RSS_HASH_TOP;
1844 memcpy(key, adapter->rss_key, adapter->rss_key_size);
1846 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
1847 for (i = 0; i < adapter->rss_lut_size; i++)
1848 indir[i] = (u32)adapter->rss_lut[i];
1854 * iavf_set_rxfh - set the rx flow hash indirection table
1855 * @netdev: network interface device structure
1856 * @indir: indirection table
1858 * @hfunc: hash function to use
1860 * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
1861 * returns 0 after programming the table.
1863 static int iavf_set_rxfh(struct net_device *netdev, const u32 *indir,
1864 const u8 *key, const u8 hfunc)
1866 struct iavf_adapter *adapter = netdev_priv(netdev);
1869 /* We do not allow change in unsupported parameters */
1871 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1877 memcpy(adapter->rss_key, key, adapter->rss_key_size);
1879 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
1880 for (i = 0; i < adapter->rss_lut_size; i++)
1881 adapter->rss_lut[i] = (u8)(indir[i]);
1883 return iavf_config_rss(adapter);
1886 static const struct ethtool_ops iavf_ethtool_ops = {
1887 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
1888 ETHTOOL_COALESCE_MAX_FRAMES |
1889 ETHTOOL_COALESCE_MAX_FRAMES_IRQ |
1890 ETHTOOL_COALESCE_USE_ADAPTIVE,
1891 .get_drvinfo = iavf_get_drvinfo,
1892 .get_link = ethtool_op_get_link,
1893 .get_ringparam = iavf_get_ringparam,
1894 .set_ringparam = iavf_set_ringparam,
1895 .get_strings = iavf_get_strings,
1896 .get_ethtool_stats = iavf_get_ethtool_stats,
1897 .get_sset_count = iavf_get_sset_count,
1898 .get_priv_flags = iavf_get_priv_flags,
1899 .set_priv_flags = iavf_set_priv_flags,
1900 .get_msglevel = iavf_get_msglevel,
1901 .set_msglevel = iavf_set_msglevel,
1902 .get_coalesce = iavf_get_coalesce,
1903 .set_coalesce = iavf_set_coalesce,
1904 .get_per_queue_coalesce = iavf_get_per_queue_coalesce,
1905 .set_per_queue_coalesce = iavf_set_per_queue_coalesce,
1906 .set_rxnfc = iavf_set_rxnfc,
1907 .get_rxnfc = iavf_get_rxnfc,
1908 .get_rxfh_indir_size = iavf_get_rxfh_indir_size,
1909 .get_rxfh = iavf_get_rxfh,
1910 .set_rxfh = iavf_set_rxfh,
1911 .get_channels = iavf_get_channels,
1912 .set_channels = iavf_set_channels,
1913 .get_rxfh_key_size = iavf_get_rxfh_key_size,
1914 .get_link_ksettings = iavf_get_link_ksettings,
1918 * iavf_set_ethtool_ops - Initialize ethtool ops struct
1919 * @netdev: network interface device structure
1921 * Sets ethtool ops struct in our netdev so that ethtool can call
1924 void iavf_set_ethtool_ops(struct net_device *netdev)
1926 netdev->ethtool_ops = &iavf_ethtool_ops;