// SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2013 - 2018 Intel Corporation. */ #include <linux/bitfield.h> #include <linux/uaccess.h> /* ethtool support for iavf */ #include "iavf.h" /* ethtool statistics helpers */ /** * struct iavf_stats - definition for an ethtool statistic * @stat_string: statistic name to display in ethtool -S output * @sizeof_stat: the sizeof() the stat, must be no greater than sizeof(u64) * @stat_offset: offsetof() the stat from a base pointer * * This structure defines a statistic to be added to the ethtool stats buffer. * It defines a statistic as offset from a common base pointer. Stats should * be defined in constant arrays using the IAVF_STAT macro, with every element * of the array using the same _type for calculating the sizeof_stat and * stat_offset. * * The @sizeof_stat is expected to be sizeof(u8), sizeof(u16), sizeof(u32) or * sizeof(u64). Other sizes are not expected and will produce a WARN_ONCE from * the iavf_add_ethtool_stat() helper function. * * The @stat_string is interpreted as a format string, allowing formatted * values to be inserted while looping over multiple structures for a given * statistics array. Thus, every statistic string in an array should have the * same type and number of format specifiers, to be formatted by variadic * arguments to the iavf_add_stat_string() helper function. **/ struct iavf_stats { … }; /* Helper macro to define an iavf_stat structure with proper size and type. * Use this when defining constant statistics arrays. Note that @_type expects * only a type name and is used multiple times. */ #define IAVF_STAT(_type, _name, _stat) … /* Helper macro for defining some statistics related to queues */ #define IAVF_QUEUE_STAT(_name, _stat) … /* Stats associated with a Tx or Rx ring */ static const struct iavf_stats iavf_gstrings_queue_stats[] = …; /** * iavf_add_one_ethtool_stat - copy the stat into the supplied buffer * @data: location to store the stat value * @pointer: basis for where to copy from * @stat: the stat definition * * Copies the stat data defined by the pointer and stat structure pair into * the memory supplied as data. Used to implement iavf_add_ethtool_stats and * iavf_add_queue_stats. If the pointer is null, data will be zero'd. */ static void iavf_add_one_ethtool_stat(u64 *data, void *pointer, const struct iavf_stats *stat) { … } /** * __iavf_add_ethtool_stats - copy stats into the ethtool supplied buffer * @data: ethtool stats buffer * @pointer: location to copy stats from * @stats: array of stats to copy * @size: the size of the stats definition * * Copy the stats defined by the stats array using the pointer as a base into * the data buffer supplied by ethtool. Updates the data pointer to point to * the next empty location for successive calls to __iavf_add_ethtool_stats. * If pointer is null, set the data values to zero and update the pointer to * skip these stats. **/ static void __iavf_add_ethtool_stats(u64 **data, void *pointer, const struct iavf_stats stats[], const unsigned int size) { … } /** * iavf_add_ethtool_stats - copy stats into ethtool supplied buffer * @data: ethtool stats buffer * @pointer: location where stats are stored * @stats: static const array of stat definitions * * Macro to ease the use of __iavf_add_ethtool_stats by taking a static * constant stats array and passing the ARRAY_SIZE(). This avoids typos by * ensuring that we pass the size associated with the given stats array. * * The parameter @stats is evaluated twice, so parameters with side effects * should be avoided. **/ #define iavf_add_ethtool_stats(data, pointer, stats) … /** * iavf_add_queue_stats - copy queue statistics into supplied buffer * @data: ethtool stats buffer * @ring: the ring to copy * * Queue statistics must be copied while protected by * u64_stats_fetch_begin, so we can't directly use iavf_add_ethtool_stats. * Assumes that queue stats are defined in iavf_gstrings_queue_stats. If the * ring pointer is null, zero out the queue stat values and update the data * pointer. Otherwise safely copy the stats from the ring into the supplied * buffer and update the data pointer when finished. * * This function expects to be called while under rcu_read_lock(). **/ static void iavf_add_queue_stats(u64 **data, struct iavf_ring *ring) { … } /** * __iavf_add_stat_strings - copy stat strings into ethtool buffer * @p: ethtool supplied buffer * @stats: stat definitions array * @size: size of the stats array * * Format and copy the strings described by stats into the buffer pointed at * by p. **/ static void __iavf_add_stat_strings(u8 **p, const struct iavf_stats stats[], const unsigned int size, ...) { … } /** * iavf_add_stat_strings - copy stat strings into ethtool buffer * @p: ethtool supplied buffer * @stats: stat definitions array * * Format and copy the strings described by the const static stats value into * the buffer pointed at by p. * * The parameter @stats is evaluated twice, so parameters with side effects * should be avoided. Additionally, stats must be an array such that * ARRAY_SIZE can be called on it. **/ #define iavf_add_stat_strings(p, stats, ...) … #define VF_STAT(_name, _stat) … static const struct iavf_stats iavf_gstrings_stats[] = …; #define IAVF_STATS_LEN … #define IAVF_QUEUE_STATS_LEN … /** * iavf_get_link_ksettings - Get Link Speed and Duplex settings * @netdev: network interface device structure * @cmd: ethtool command * * Reports speed/duplex settings. Because this is a VF, we don't know what * kind of link we really have, so we fake it. **/ static int iavf_get_link_ksettings(struct net_device *netdev, struct ethtool_link_ksettings *cmd) { … } /** * iavf_get_sset_count - Get length of string set * @netdev: network interface device structure * @sset: id of string set * * Reports size of various string tables. **/ static int iavf_get_sset_count(struct net_device *netdev, int sset) { … } /** * iavf_get_ethtool_stats - report device statistics * @netdev: network interface device structure * @stats: ethtool statistics structure * @data: pointer to data buffer * * All statistics are added to the data buffer as an array of u64. **/ static void iavf_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats, u64 *data) { … } /** * iavf_get_stat_strings - Get stat strings * @netdev: network interface device structure * @data: buffer for string data * * Builds the statistics string table **/ static void iavf_get_stat_strings(struct net_device *netdev, u8 *data) { … } /** * iavf_get_strings - Get string set * @netdev: network interface device structure * @sset: id of string set * @data: buffer for string data * * Builds string tables for various string sets **/ static void iavf_get_strings(struct net_device *netdev, u32 sset, u8 *data) { … } /** * iavf_get_msglevel - Get debug message level * @netdev: network interface device structure * * Returns current debug message level. **/ static u32 iavf_get_msglevel(struct net_device *netdev) { … } /** * iavf_set_msglevel - Set debug message level * @netdev: network interface device structure * @data: message level * * Set current debug message level. Higher values cause the driver to * be noisier. **/ static void iavf_set_msglevel(struct net_device *netdev, u32 data) { … } /** * iavf_get_drvinfo - Get driver info * @netdev: network interface device structure * @drvinfo: ethool driver info structure * * Returns information about the driver and device for display to the user. **/ static void iavf_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) { … } /** * iavf_get_ringparam - Get ring parameters * @netdev: network interface device structure * @ring: ethtool ringparam structure * @kernel_ring: ethtool extenal ringparam structure * @extack: netlink extended ACK report struct * * Returns current ring parameters. TX and RX rings are reported separately, * but the number of rings is not reported. **/ static void iavf_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, struct kernel_ethtool_ringparam *kernel_ring, struct netlink_ext_ack *extack) { … } /** * iavf_set_ringparam - Set ring parameters * @netdev: network interface device structure * @ring: ethtool ringparam structure * @kernel_ring: ethtool external ringparam structure * @extack: netlink extended ACK report struct * * Sets ring parameters. TX and RX rings are controlled separately, but the * number of rings is not specified, so all rings get the same settings. **/ static int iavf_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, struct kernel_ethtool_ringparam *kernel_ring, struct netlink_ext_ack *extack) { … } /** * __iavf_get_coalesce - get per-queue coalesce settings * @netdev: the netdev to check * @ec: ethtool coalesce data structure * @queue: which queue to pick * * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs * are per queue. If queue is <0 then we default to queue 0 as the * representative value. **/ static int __iavf_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec, int queue) { … } /** * iavf_get_coalesce - Get interrupt coalescing settings * @netdev: network interface device structure * @ec: ethtool coalesce structure * @kernel_coal: ethtool CQE mode setting structure * @extack: extack for reporting error messages * * Returns current coalescing settings. This is referred to elsewhere in the * driver as Interrupt Throttle Rate, as this is how the hardware describes * this functionality. Note that if per-queue settings have been modified this * only represents the settings of queue 0. **/ static int iavf_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec, struct kernel_ethtool_coalesce *kernel_coal, struct netlink_ext_ack *extack) { … } /** * iavf_get_per_queue_coalesce - get coalesce values for specific queue * @netdev: netdev to read * @ec: coalesce settings from ethtool * @queue: the queue to read * * Read specific queue's coalesce settings. **/ static int iavf_get_per_queue_coalesce(struct net_device *netdev, u32 queue, struct ethtool_coalesce *ec) { … } /** * iavf_set_itr_per_queue - set ITR values for specific queue * @adapter: the VF adapter struct to set values for * @ec: coalesce settings from ethtool * @queue: the queue to modify * * Change the ITR settings for a specific queue. **/ static int iavf_set_itr_per_queue(struct iavf_adapter *adapter, struct ethtool_coalesce *ec, int queue) { … } /** * __iavf_set_coalesce - set coalesce settings for particular queue * @netdev: the netdev to change * @ec: ethtool coalesce settings * @queue: the queue to change * * Sets the coalesce settings for a particular queue. **/ static int __iavf_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec, int queue) { … } /** * iavf_set_coalesce - Set interrupt coalescing settings * @netdev: network interface device structure * @ec: ethtool coalesce structure * @kernel_coal: ethtool CQE mode setting structure * @extack: extack for reporting error messages * * Change current coalescing settings for every queue. **/ static int iavf_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec, struct kernel_ethtool_coalesce *kernel_coal, struct netlink_ext_ack *extack) { … } /** * iavf_set_per_queue_coalesce - set specific queue's coalesce settings * @netdev: the netdev to change * @ec: ethtool's coalesce settings * @queue: the queue to modify * * Modifies a specific queue's coalesce settings. */ static int iavf_set_per_queue_coalesce(struct net_device *netdev, u32 queue, struct ethtool_coalesce *ec) { … } /** * iavf_fltr_to_ethtool_flow - convert filter type values to ethtool * flow type values * @flow: filter type to be converted * * Returns the corresponding ethtool flow type. */ static int iavf_fltr_to_ethtool_flow(enum iavf_fdir_flow_type flow) { … } /** * iavf_ethtool_flow_to_fltr - convert ethtool flow type to filter enum * @eth: Ethtool flow type to be converted * * Returns flow enum */ static enum iavf_fdir_flow_type iavf_ethtool_flow_to_fltr(int eth) { … } /** * iavf_is_mask_valid - check mask field set * @mask: full mask to check * @field: field for which mask should be valid * * If the mask is fully set return true. If it is not valid for field return * false. */ static bool iavf_is_mask_valid(u64 mask, u64 field) { … } /** * iavf_parse_rx_flow_user_data - deconstruct user-defined data * @fsp: pointer to ethtool Rx flow specification * @fltr: pointer to Flow Director filter for userdef data storage * * Returns 0 on success, negative error value on failure */ static int iavf_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp, struct iavf_fdir_fltr *fltr) { … } /** * iavf_fill_rx_flow_ext_data - fill the additional data * @fsp: pointer to ethtool Rx flow specification * @fltr: pointer to Flow Director filter to get additional data */ static void iavf_fill_rx_flow_ext_data(struct ethtool_rx_flow_spec *fsp, struct iavf_fdir_fltr *fltr) { … } /** * iavf_get_ethtool_fdir_entry - fill ethtool structure with Flow Director filter data * @adapter: the VF adapter structure that contains filter list * @cmd: ethtool command data structure to receive the filter data * * Returns 0 as expected for success by ethtool */ static int iavf_get_ethtool_fdir_entry(struct iavf_adapter *adapter, struct ethtool_rxnfc *cmd) { … } /** * iavf_get_fdir_fltr_ids - fill buffer with filter IDs of active filters * @adapter: the VF adapter structure containing the filter list * @cmd: ethtool command data structure * @rule_locs: ethtool array passed in from OS to receive filter IDs * * Returns 0 as expected for success by ethtool */ static int iavf_get_fdir_fltr_ids(struct iavf_adapter *adapter, struct ethtool_rxnfc *cmd, u32 *rule_locs) { … } /** * iavf_add_fdir_fltr_info - Set the input set for Flow Director filter * @adapter: pointer to the VF adapter structure * @fsp: pointer to ethtool Rx flow specification * @fltr: filter structure */ static int iavf_add_fdir_fltr_info(struct iavf_adapter *adapter, struct ethtool_rx_flow_spec *fsp, struct iavf_fdir_fltr *fltr) { … } /** * iavf_add_fdir_ethtool - add Flow Director filter * @adapter: pointer to the VF adapter structure * @cmd: command to add Flow Director filter * * Returns 0 on success and negative values for failure */ static int iavf_add_fdir_ethtool(struct iavf_adapter *adapter, struct ethtool_rxnfc *cmd) { … } /** * iavf_del_fdir_ethtool - delete Flow Director filter * @adapter: pointer to the VF adapter structure * @cmd: command to delete Flow Director filter * * Returns 0 on success and negative values for failure */ static int iavf_del_fdir_ethtool(struct iavf_adapter *adapter, struct ethtool_rxnfc *cmd) { … } /** * iavf_adv_rss_parse_hdrs - parses headers from RSS hash input * @cmd: ethtool rxnfc command * * This function parses the rxnfc command and returns intended * header types for RSS configuration */ static u32 iavf_adv_rss_parse_hdrs(struct ethtool_rxnfc *cmd) { … } /** * iavf_adv_rss_parse_hash_flds - parses hash fields from RSS hash input * @cmd: ethtool rxnfc command * @symm: true if Symmetric Topelitz is set * * This function parses the rxnfc command and returns intended hash fields for * RSS configuration */ static u64 iavf_adv_rss_parse_hash_flds(struct ethtool_rxnfc *cmd, bool symm) { … } /** * iavf_set_adv_rss_hash_opt - Enable/Disable flow types for RSS hash * @adapter: pointer to the VF adapter structure * @cmd: ethtool rxnfc command * * Returns Success if the flow input set is supported. */ static int iavf_set_adv_rss_hash_opt(struct iavf_adapter *adapter, struct ethtool_rxnfc *cmd) { … } /** * iavf_get_adv_rss_hash_opt - Retrieve hash fields for a given flow-type * @adapter: pointer to the VF adapter structure * @cmd: ethtool rxnfc command * * Returns Success if the flow input set is supported. */ static int iavf_get_adv_rss_hash_opt(struct iavf_adapter *adapter, struct ethtool_rxnfc *cmd) { … } /** * iavf_set_rxnfc - command to set Rx flow rules. * @netdev: network interface device structure * @cmd: ethtool rxnfc command * * Returns 0 for success and negative values for errors */ static int iavf_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) { … } /** * iavf_get_rxnfc - command to get RX flow classification rules * @netdev: network interface device structure * @cmd: ethtool rxnfc command * @rule_locs: pointer to store rule locations * * Returns Success if the command is supported. **/ static int iavf_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, u32 *rule_locs) { … } /** * iavf_get_channels: get the number of channels supported by the device * @netdev: network interface device structure * @ch: channel information structure * * For the purposes of our device, we only use combined channels, i.e. a tx/rx * queue pair. Report one extra channel to match our "other" MSI-X vector. **/ static void iavf_get_channels(struct net_device *netdev, struct ethtool_channels *ch) { … } /** * iavf_set_channels: set the new channel count * @netdev: network interface device structure * @ch: channel information structure * * Negotiate a new number of channels with the PF then do a reset. During * reset we'll realloc queues and fix the RSS table. Returns 0 on success, * negative on failure. **/ static int iavf_set_channels(struct net_device *netdev, struct ethtool_channels *ch) { … } /** * iavf_get_rxfh_key_size - get the RSS hash key size * @netdev: network interface device structure * * Returns the table size. **/ static u32 iavf_get_rxfh_key_size(struct net_device *netdev) { … } /** * iavf_get_rxfh_indir_size - get the rx flow hash indirection table size * @netdev: network interface device structure * * Returns the table size. **/ static u32 iavf_get_rxfh_indir_size(struct net_device *netdev) { … } /** * iavf_get_rxfh - get the rx flow hash indirection table * @netdev: network interface device structure * @rxfh: pointer to param struct (indir, key, hfunc) * * Reads the indirection table directly from the hardware. Always returns 0. **/ static int iavf_get_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh) { … } /** * iavf_set_rxfh - set the rx flow hash indirection table * @netdev: network interface device structure * @rxfh: pointer to param struct (indir, key, hfunc) * @extack: extended ACK from the Netlink message * * Returns -EINVAL if the table specifies an invalid queue id, otherwise * returns 0 after programming the table. **/ static int iavf_set_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh, struct netlink_ext_ack *extack) { … } static const struct ethtool_ops iavf_ethtool_ops = …; /** * iavf_set_ethtool_ops - Initialize ethtool ops struct * @netdev: network interface device structure * * Sets ethtool ops struct in our netdev so that ethtool can call * our functions. **/ void iavf_set_ethtool_ops(struct net_device *netdev) { … }