162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* Copyright(c) 2013 - 2018 Intel Corporation. */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci/* ethtool support for i40e */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#include "i40e.h" 762306a36Sopenharmony_ci#include "i40e_diag.h" 862306a36Sopenharmony_ci#include "i40e_txrx_common.h" 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci/* ethtool statistics helpers */ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci/** 1362306a36Sopenharmony_ci * struct i40e_stats - definition for an ethtool statistic 1462306a36Sopenharmony_ci * @stat_string: statistic name to display in ethtool -S output 1562306a36Sopenharmony_ci * @sizeof_stat: the sizeof() the stat, must be no greater than sizeof(u64) 1662306a36Sopenharmony_ci * @stat_offset: offsetof() the stat from a base pointer 1762306a36Sopenharmony_ci * 1862306a36Sopenharmony_ci * This structure defines a statistic to be added to the ethtool stats buffer. 1962306a36Sopenharmony_ci * It defines a statistic as offset from a common base pointer. Stats should 2062306a36Sopenharmony_ci * be defined in constant arrays using the I40E_STAT macro, with every element 2162306a36Sopenharmony_ci * of the array using the same _type for calculating the sizeof_stat and 2262306a36Sopenharmony_ci * stat_offset. 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * The @sizeof_stat is expected to be sizeof(u8), sizeof(u16), sizeof(u32) or 2562306a36Sopenharmony_ci * sizeof(u64). Other sizes are not expected and will produce a WARN_ONCE from 2662306a36Sopenharmony_ci * the i40e_add_ethtool_stat() helper function. 2762306a36Sopenharmony_ci * 2862306a36Sopenharmony_ci * The @stat_string is interpreted as a format string, allowing formatted 2962306a36Sopenharmony_ci * values to be inserted while looping over multiple structures for a given 3062306a36Sopenharmony_ci * statistics array. Thus, every statistic string in an array should have the 3162306a36Sopenharmony_ci * same type and number of format specifiers, to be formatted by variadic 3262306a36Sopenharmony_ci * arguments to the i40e_add_stat_string() helper function. 3362306a36Sopenharmony_ci **/ 3462306a36Sopenharmony_cistruct i40e_stats { 3562306a36Sopenharmony_ci char stat_string[ETH_GSTRING_LEN]; 3662306a36Sopenharmony_ci int sizeof_stat; 3762306a36Sopenharmony_ci int stat_offset; 3862306a36Sopenharmony_ci}; 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci/* Helper macro to define an i40e_stat structure with proper size and type. 4162306a36Sopenharmony_ci * Use this when defining constant statistics arrays. Note that @_type expects 4262306a36Sopenharmony_ci * only a type name and is used multiple times. 4362306a36Sopenharmony_ci */ 4462306a36Sopenharmony_ci#define I40E_STAT(_type, _name, _stat) { \ 4562306a36Sopenharmony_ci .stat_string = _name, \ 4662306a36Sopenharmony_ci .sizeof_stat = sizeof_field(_type, _stat), \ 4762306a36Sopenharmony_ci .stat_offset = offsetof(_type, _stat) \ 4862306a36Sopenharmony_ci} 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci/* Helper macro for defining some statistics directly copied from the netdev 5162306a36Sopenharmony_ci * stats structure. 5262306a36Sopenharmony_ci */ 5362306a36Sopenharmony_ci#define I40E_NETDEV_STAT(_net_stat) \ 5462306a36Sopenharmony_ci I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat) 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci/* Helper macro for defining some statistics related to queues */ 5762306a36Sopenharmony_ci#define I40E_QUEUE_STAT(_name, _stat) \ 5862306a36Sopenharmony_ci I40E_STAT(struct i40e_ring, _name, _stat) 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci/* Stats associated with a Tx or Rx ring */ 6162306a36Sopenharmony_cistatic const struct i40e_stats i40e_gstrings_queue_stats[] = { 6262306a36Sopenharmony_ci I40E_QUEUE_STAT("%s-%u.packets", stats.packets), 6362306a36Sopenharmony_ci I40E_QUEUE_STAT("%s-%u.bytes", stats.bytes), 6462306a36Sopenharmony_ci}; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/** 6762306a36Sopenharmony_ci * i40e_add_one_ethtool_stat - copy the stat into the supplied buffer 6862306a36Sopenharmony_ci * @data: location to store the stat value 6962306a36Sopenharmony_ci * @pointer: basis for where to copy from 7062306a36Sopenharmony_ci * @stat: the stat definition 7162306a36Sopenharmony_ci * 7262306a36Sopenharmony_ci * Copies the stat data defined by the pointer and stat structure pair into 7362306a36Sopenharmony_ci * the memory supplied as data. Used to implement i40e_add_ethtool_stats and 7462306a36Sopenharmony_ci * i40e_add_queue_stats. If the pointer is null, data will be zero'd. 7562306a36Sopenharmony_ci */ 7662306a36Sopenharmony_cistatic void 7762306a36Sopenharmony_cii40e_add_one_ethtool_stat(u64 *data, void *pointer, 7862306a36Sopenharmony_ci const struct i40e_stats *stat) 7962306a36Sopenharmony_ci{ 8062306a36Sopenharmony_ci char *p; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci if (!pointer) { 8362306a36Sopenharmony_ci /* ensure that the ethtool data buffer is zero'd for any stats 8462306a36Sopenharmony_ci * which don't have a valid pointer. 8562306a36Sopenharmony_ci */ 8662306a36Sopenharmony_ci *data = 0; 8762306a36Sopenharmony_ci return; 8862306a36Sopenharmony_ci } 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci p = (char *)pointer + stat->stat_offset; 9162306a36Sopenharmony_ci switch (stat->sizeof_stat) { 9262306a36Sopenharmony_ci case sizeof(u64): 9362306a36Sopenharmony_ci *data = *((u64 *)p); 9462306a36Sopenharmony_ci break; 9562306a36Sopenharmony_ci case sizeof(u32): 9662306a36Sopenharmony_ci *data = *((u32 *)p); 9762306a36Sopenharmony_ci break; 9862306a36Sopenharmony_ci case sizeof(u16): 9962306a36Sopenharmony_ci *data = *((u16 *)p); 10062306a36Sopenharmony_ci break; 10162306a36Sopenharmony_ci case sizeof(u8): 10262306a36Sopenharmony_ci *data = *((u8 *)p); 10362306a36Sopenharmony_ci break; 10462306a36Sopenharmony_ci default: 10562306a36Sopenharmony_ci WARN_ONCE(1, "unexpected stat size for %s", 10662306a36Sopenharmony_ci stat->stat_string); 10762306a36Sopenharmony_ci *data = 0; 10862306a36Sopenharmony_ci } 10962306a36Sopenharmony_ci} 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci/** 11262306a36Sopenharmony_ci * __i40e_add_ethtool_stats - copy stats into the ethtool supplied buffer 11362306a36Sopenharmony_ci * @data: ethtool stats buffer 11462306a36Sopenharmony_ci * @pointer: location to copy stats from 11562306a36Sopenharmony_ci * @stats: array of stats to copy 11662306a36Sopenharmony_ci * @size: the size of the stats definition 11762306a36Sopenharmony_ci * 11862306a36Sopenharmony_ci * Copy the stats defined by the stats array using the pointer as a base into 11962306a36Sopenharmony_ci * the data buffer supplied by ethtool. Updates the data pointer to point to 12062306a36Sopenharmony_ci * the next empty location for successive calls to __i40e_add_ethtool_stats. 12162306a36Sopenharmony_ci * If pointer is null, set the data values to zero and update the pointer to 12262306a36Sopenharmony_ci * skip these stats. 12362306a36Sopenharmony_ci **/ 12462306a36Sopenharmony_cistatic void 12562306a36Sopenharmony_ci__i40e_add_ethtool_stats(u64 **data, void *pointer, 12662306a36Sopenharmony_ci const struct i40e_stats stats[], 12762306a36Sopenharmony_ci const unsigned int size) 12862306a36Sopenharmony_ci{ 12962306a36Sopenharmony_ci unsigned int i; 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci for (i = 0; i < size; i++) 13262306a36Sopenharmony_ci i40e_add_one_ethtool_stat((*data)++, pointer, &stats[i]); 13362306a36Sopenharmony_ci} 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci/** 13662306a36Sopenharmony_ci * i40e_add_ethtool_stats - copy stats into ethtool supplied buffer 13762306a36Sopenharmony_ci * @data: ethtool stats buffer 13862306a36Sopenharmony_ci * @pointer: location where stats are stored 13962306a36Sopenharmony_ci * @stats: static const array of stat definitions 14062306a36Sopenharmony_ci * 14162306a36Sopenharmony_ci * Macro to ease the use of __i40e_add_ethtool_stats by taking a static 14262306a36Sopenharmony_ci * constant stats array and passing the ARRAY_SIZE(). This avoids typos by 14362306a36Sopenharmony_ci * ensuring that we pass the size associated with the given stats array. 14462306a36Sopenharmony_ci * 14562306a36Sopenharmony_ci * The parameter @stats is evaluated twice, so parameters with side effects 14662306a36Sopenharmony_ci * should be avoided. 14762306a36Sopenharmony_ci **/ 14862306a36Sopenharmony_ci#define i40e_add_ethtool_stats(data, pointer, stats) \ 14962306a36Sopenharmony_ci __i40e_add_ethtool_stats(data, pointer, stats, ARRAY_SIZE(stats)) 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci/** 15262306a36Sopenharmony_ci * i40e_add_queue_stats - copy queue statistics into supplied buffer 15362306a36Sopenharmony_ci * @data: ethtool stats buffer 15462306a36Sopenharmony_ci * @ring: the ring to copy 15562306a36Sopenharmony_ci * 15662306a36Sopenharmony_ci * Queue statistics must be copied while protected by 15762306a36Sopenharmony_ci * u64_stats_fetch_begin, so we can't directly use i40e_add_ethtool_stats. 15862306a36Sopenharmony_ci * Assumes that queue stats are defined in i40e_gstrings_queue_stats. If the 15962306a36Sopenharmony_ci * ring pointer is null, zero out the queue stat values and update the data 16062306a36Sopenharmony_ci * pointer. Otherwise safely copy the stats from the ring into the supplied 16162306a36Sopenharmony_ci * buffer and update the data pointer when finished. 16262306a36Sopenharmony_ci * 16362306a36Sopenharmony_ci * This function expects to be called while under rcu_read_lock(). 16462306a36Sopenharmony_ci **/ 16562306a36Sopenharmony_cistatic void 16662306a36Sopenharmony_cii40e_add_queue_stats(u64 **data, struct i40e_ring *ring) 16762306a36Sopenharmony_ci{ 16862306a36Sopenharmony_ci const unsigned int size = ARRAY_SIZE(i40e_gstrings_queue_stats); 16962306a36Sopenharmony_ci const struct i40e_stats *stats = i40e_gstrings_queue_stats; 17062306a36Sopenharmony_ci unsigned int start; 17162306a36Sopenharmony_ci unsigned int i; 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci /* To avoid invalid statistics values, ensure that we keep retrying 17462306a36Sopenharmony_ci * the copy until we get a consistent value according to 17562306a36Sopenharmony_ci * u64_stats_fetch_retry. But first, make sure our ring is 17662306a36Sopenharmony_ci * non-null before attempting to access its syncp. 17762306a36Sopenharmony_ci */ 17862306a36Sopenharmony_ci do { 17962306a36Sopenharmony_ci start = !ring ? 0 : u64_stats_fetch_begin(&ring->syncp); 18062306a36Sopenharmony_ci for (i = 0; i < size; i++) { 18162306a36Sopenharmony_ci i40e_add_one_ethtool_stat(&(*data)[i], ring, 18262306a36Sopenharmony_ci &stats[i]); 18362306a36Sopenharmony_ci } 18462306a36Sopenharmony_ci } while (ring && u64_stats_fetch_retry(&ring->syncp, start)); 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ci /* Once we successfully copy the stats in, update the data pointer */ 18762306a36Sopenharmony_ci *data += size; 18862306a36Sopenharmony_ci} 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci/** 19162306a36Sopenharmony_ci * __i40e_add_stat_strings - copy stat strings into ethtool buffer 19262306a36Sopenharmony_ci * @p: ethtool supplied buffer 19362306a36Sopenharmony_ci * @stats: stat definitions array 19462306a36Sopenharmony_ci * @size: size of the stats array 19562306a36Sopenharmony_ci * 19662306a36Sopenharmony_ci * Format and copy the strings described by stats into the buffer pointed at 19762306a36Sopenharmony_ci * by p. 19862306a36Sopenharmony_ci **/ 19962306a36Sopenharmony_cistatic void __i40e_add_stat_strings(u8 **p, const struct i40e_stats stats[], 20062306a36Sopenharmony_ci const unsigned int size, ...) 20162306a36Sopenharmony_ci{ 20262306a36Sopenharmony_ci unsigned int i; 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ci for (i = 0; i < size; i++) { 20562306a36Sopenharmony_ci va_list args; 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ci va_start(args, size); 20862306a36Sopenharmony_ci vsnprintf(*p, ETH_GSTRING_LEN, stats[i].stat_string, args); 20962306a36Sopenharmony_ci *p += ETH_GSTRING_LEN; 21062306a36Sopenharmony_ci va_end(args); 21162306a36Sopenharmony_ci } 21262306a36Sopenharmony_ci} 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci/** 21562306a36Sopenharmony_ci * i40e_add_stat_strings - copy stat strings into ethtool buffer 21662306a36Sopenharmony_ci * @p: ethtool supplied buffer 21762306a36Sopenharmony_ci * @stats: stat definitions array 21862306a36Sopenharmony_ci * 21962306a36Sopenharmony_ci * Format and copy the strings described by the const static stats value into 22062306a36Sopenharmony_ci * the buffer pointed at by p. 22162306a36Sopenharmony_ci * 22262306a36Sopenharmony_ci * The parameter @stats is evaluated twice, so parameters with side effects 22362306a36Sopenharmony_ci * should be avoided. Additionally, stats must be an array such that 22462306a36Sopenharmony_ci * ARRAY_SIZE can be called on it. 22562306a36Sopenharmony_ci **/ 22662306a36Sopenharmony_ci#define i40e_add_stat_strings(p, stats, ...) \ 22762306a36Sopenharmony_ci __i40e_add_stat_strings(p, stats, ARRAY_SIZE(stats), ## __VA_ARGS__) 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci#define I40E_PF_STAT(_name, _stat) \ 23062306a36Sopenharmony_ci I40E_STAT(struct i40e_pf, _name, _stat) 23162306a36Sopenharmony_ci#define I40E_VSI_STAT(_name, _stat) \ 23262306a36Sopenharmony_ci I40E_STAT(struct i40e_vsi, _name, _stat) 23362306a36Sopenharmony_ci#define I40E_VEB_STAT(_name, _stat) \ 23462306a36Sopenharmony_ci I40E_STAT(struct i40e_veb, _name, _stat) 23562306a36Sopenharmony_ci#define I40E_VEB_TC_STAT(_name, _stat) \ 23662306a36Sopenharmony_ci I40E_STAT(struct i40e_cp_veb_tc_stats, _name, _stat) 23762306a36Sopenharmony_ci#define I40E_PFC_STAT(_name, _stat) \ 23862306a36Sopenharmony_ci I40E_STAT(struct i40e_pfc_stats, _name, _stat) 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_cistatic const struct i40e_stats i40e_gstrings_net_stats[] = { 24162306a36Sopenharmony_ci I40E_NETDEV_STAT(rx_packets), 24262306a36Sopenharmony_ci I40E_NETDEV_STAT(tx_packets), 24362306a36Sopenharmony_ci I40E_NETDEV_STAT(rx_bytes), 24462306a36Sopenharmony_ci I40E_NETDEV_STAT(tx_bytes), 24562306a36Sopenharmony_ci I40E_NETDEV_STAT(rx_errors), 24662306a36Sopenharmony_ci I40E_NETDEV_STAT(tx_errors), 24762306a36Sopenharmony_ci I40E_NETDEV_STAT(rx_dropped), 24862306a36Sopenharmony_ci I40E_NETDEV_STAT(tx_dropped), 24962306a36Sopenharmony_ci I40E_NETDEV_STAT(collisions), 25062306a36Sopenharmony_ci I40E_NETDEV_STAT(rx_length_errors), 25162306a36Sopenharmony_ci I40E_NETDEV_STAT(rx_crc_errors), 25262306a36Sopenharmony_ci}; 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_cistatic const struct i40e_stats i40e_gstrings_veb_stats[] = { 25562306a36Sopenharmony_ci I40E_VEB_STAT("veb.rx_bytes", stats.rx_bytes), 25662306a36Sopenharmony_ci I40E_VEB_STAT("veb.tx_bytes", stats.tx_bytes), 25762306a36Sopenharmony_ci I40E_VEB_STAT("veb.rx_unicast", stats.rx_unicast), 25862306a36Sopenharmony_ci I40E_VEB_STAT("veb.tx_unicast", stats.tx_unicast), 25962306a36Sopenharmony_ci I40E_VEB_STAT("veb.rx_multicast", stats.rx_multicast), 26062306a36Sopenharmony_ci I40E_VEB_STAT("veb.tx_multicast", stats.tx_multicast), 26162306a36Sopenharmony_ci I40E_VEB_STAT("veb.rx_broadcast", stats.rx_broadcast), 26262306a36Sopenharmony_ci I40E_VEB_STAT("veb.tx_broadcast", stats.tx_broadcast), 26362306a36Sopenharmony_ci I40E_VEB_STAT("veb.rx_discards", stats.rx_discards), 26462306a36Sopenharmony_ci I40E_VEB_STAT("veb.tx_discards", stats.tx_discards), 26562306a36Sopenharmony_ci I40E_VEB_STAT("veb.tx_errors", stats.tx_errors), 26662306a36Sopenharmony_ci I40E_VEB_STAT("veb.rx_unknown_protocol", stats.rx_unknown_protocol), 26762306a36Sopenharmony_ci}; 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_cistruct i40e_cp_veb_tc_stats { 27062306a36Sopenharmony_ci u64 tc_rx_packets; 27162306a36Sopenharmony_ci u64 tc_rx_bytes; 27262306a36Sopenharmony_ci u64 tc_tx_packets; 27362306a36Sopenharmony_ci u64 tc_tx_bytes; 27462306a36Sopenharmony_ci}; 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_cistatic const struct i40e_stats i40e_gstrings_veb_tc_stats[] = { 27762306a36Sopenharmony_ci I40E_VEB_TC_STAT("veb.tc_%u_tx_packets", tc_tx_packets), 27862306a36Sopenharmony_ci I40E_VEB_TC_STAT("veb.tc_%u_tx_bytes", tc_tx_bytes), 27962306a36Sopenharmony_ci I40E_VEB_TC_STAT("veb.tc_%u_rx_packets", tc_rx_packets), 28062306a36Sopenharmony_ci I40E_VEB_TC_STAT("veb.tc_%u_rx_bytes", tc_rx_bytes), 28162306a36Sopenharmony_ci}; 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_cistatic const struct i40e_stats i40e_gstrings_misc_stats[] = { 28462306a36Sopenharmony_ci I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast), 28562306a36Sopenharmony_ci I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast), 28662306a36Sopenharmony_ci I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast), 28762306a36Sopenharmony_ci I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast), 28862306a36Sopenharmony_ci I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast), 28962306a36Sopenharmony_ci I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast), 29062306a36Sopenharmony_ci I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol), 29162306a36Sopenharmony_ci I40E_VSI_STAT("tx_linearize", tx_linearize), 29262306a36Sopenharmony_ci I40E_VSI_STAT("tx_force_wb", tx_force_wb), 29362306a36Sopenharmony_ci I40E_VSI_STAT("tx_busy", tx_busy), 29462306a36Sopenharmony_ci I40E_VSI_STAT("tx_stopped", tx_stopped), 29562306a36Sopenharmony_ci I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed), 29662306a36Sopenharmony_ci I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed), 29762306a36Sopenharmony_ci I40E_VSI_STAT("rx_cache_reuse", rx_page_reuse), 29862306a36Sopenharmony_ci I40E_VSI_STAT("rx_cache_alloc", rx_page_alloc), 29962306a36Sopenharmony_ci I40E_VSI_STAT("rx_cache_waive", rx_page_waive), 30062306a36Sopenharmony_ci I40E_VSI_STAT("rx_cache_busy", rx_page_busy), 30162306a36Sopenharmony_ci I40E_VSI_STAT("tx_restart", tx_restart), 30262306a36Sopenharmony_ci}; 30362306a36Sopenharmony_ci 30462306a36Sopenharmony_ci/* These PF_STATs might look like duplicates of some NETDEV_STATs, 30562306a36Sopenharmony_ci * but they are separate. This device supports Virtualization, and 30662306a36Sopenharmony_ci * as such might have several netdevs supporting VMDq and FCoE going 30762306a36Sopenharmony_ci * through a single port. The NETDEV_STATs are for individual netdevs 30862306a36Sopenharmony_ci * seen at the top of the stack, and the PF_STATs are for the physical 30962306a36Sopenharmony_ci * function at the bottom of the stack hosting those netdevs. 31062306a36Sopenharmony_ci * 31162306a36Sopenharmony_ci * The PF_STATs are appended to the netdev stats only when ethtool -S 31262306a36Sopenharmony_ci * is queried on the base PF netdev, not on the VMDq or FCoE netdev. 31362306a36Sopenharmony_ci */ 31462306a36Sopenharmony_cistatic const struct i40e_stats i40e_gstrings_stats[] = { 31562306a36Sopenharmony_ci I40E_PF_STAT("port.rx_bytes", stats.eth.rx_bytes), 31662306a36Sopenharmony_ci I40E_PF_STAT("port.tx_bytes", stats.eth.tx_bytes), 31762306a36Sopenharmony_ci I40E_PF_STAT("port.rx_unicast", stats.eth.rx_unicast), 31862306a36Sopenharmony_ci I40E_PF_STAT("port.tx_unicast", stats.eth.tx_unicast), 31962306a36Sopenharmony_ci I40E_PF_STAT("port.rx_multicast", stats.eth.rx_multicast), 32062306a36Sopenharmony_ci I40E_PF_STAT("port.tx_multicast", stats.eth.tx_multicast), 32162306a36Sopenharmony_ci I40E_PF_STAT("port.rx_broadcast", stats.eth.rx_broadcast), 32262306a36Sopenharmony_ci I40E_PF_STAT("port.tx_broadcast", stats.eth.tx_broadcast), 32362306a36Sopenharmony_ci I40E_PF_STAT("port.tx_errors", stats.eth.tx_errors), 32462306a36Sopenharmony_ci I40E_PF_STAT("port.rx_dropped", stats.eth.rx_discards), 32562306a36Sopenharmony_ci I40E_PF_STAT("port.tx_dropped_link_down", stats.tx_dropped_link_down), 32662306a36Sopenharmony_ci I40E_PF_STAT("port.rx_crc_errors", stats.crc_errors), 32762306a36Sopenharmony_ci I40E_PF_STAT("port.illegal_bytes", stats.illegal_bytes), 32862306a36Sopenharmony_ci I40E_PF_STAT("port.mac_local_faults", stats.mac_local_faults), 32962306a36Sopenharmony_ci I40E_PF_STAT("port.mac_remote_faults", stats.mac_remote_faults), 33062306a36Sopenharmony_ci I40E_PF_STAT("port.tx_timeout", tx_timeout_count), 33162306a36Sopenharmony_ci I40E_PF_STAT("port.rx_csum_bad", hw_csum_rx_error), 33262306a36Sopenharmony_ci I40E_PF_STAT("port.rx_length_errors", stats.rx_length_errors), 33362306a36Sopenharmony_ci I40E_PF_STAT("port.link_xon_rx", stats.link_xon_rx), 33462306a36Sopenharmony_ci I40E_PF_STAT("port.link_xoff_rx", stats.link_xoff_rx), 33562306a36Sopenharmony_ci I40E_PF_STAT("port.link_xon_tx", stats.link_xon_tx), 33662306a36Sopenharmony_ci I40E_PF_STAT("port.link_xoff_tx", stats.link_xoff_tx), 33762306a36Sopenharmony_ci I40E_PF_STAT("port.rx_size_64", stats.rx_size_64), 33862306a36Sopenharmony_ci I40E_PF_STAT("port.rx_size_127", stats.rx_size_127), 33962306a36Sopenharmony_ci I40E_PF_STAT("port.rx_size_255", stats.rx_size_255), 34062306a36Sopenharmony_ci I40E_PF_STAT("port.rx_size_511", stats.rx_size_511), 34162306a36Sopenharmony_ci I40E_PF_STAT("port.rx_size_1023", stats.rx_size_1023), 34262306a36Sopenharmony_ci I40E_PF_STAT("port.rx_size_1522", stats.rx_size_1522), 34362306a36Sopenharmony_ci I40E_PF_STAT("port.rx_size_big", stats.rx_size_big), 34462306a36Sopenharmony_ci I40E_PF_STAT("port.tx_size_64", stats.tx_size_64), 34562306a36Sopenharmony_ci I40E_PF_STAT("port.tx_size_127", stats.tx_size_127), 34662306a36Sopenharmony_ci I40E_PF_STAT("port.tx_size_255", stats.tx_size_255), 34762306a36Sopenharmony_ci I40E_PF_STAT("port.tx_size_511", stats.tx_size_511), 34862306a36Sopenharmony_ci I40E_PF_STAT("port.tx_size_1023", stats.tx_size_1023), 34962306a36Sopenharmony_ci I40E_PF_STAT("port.tx_size_1522", stats.tx_size_1522), 35062306a36Sopenharmony_ci I40E_PF_STAT("port.tx_size_big", stats.tx_size_big), 35162306a36Sopenharmony_ci I40E_PF_STAT("port.rx_undersize", stats.rx_undersize), 35262306a36Sopenharmony_ci I40E_PF_STAT("port.rx_fragments", stats.rx_fragments), 35362306a36Sopenharmony_ci I40E_PF_STAT("port.rx_oversize", stats.rx_oversize), 35462306a36Sopenharmony_ci I40E_PF_STAT("port.rx_jabber", stats.rx_jabber), 35562306a36Sopenharmony_ci I40E_PF_STAT("port.VF_admin_queue_requests", vf_aq_requests), 35662306a36Sopenharmony_ci I40E_PF_STAT("port.arq_overflows", arq_overflows), 35762306a36Sopenharmony_ci I40E_PF_STAT("port.tx_hwtstamp_timeouts", tx_hwtstamp_timeouts), 35862306a36Sopenharmony_ci I40E_PF_STAT("port.rx_hwtstamp_cleared", rx_hwtstamp_cleared), 35962306a36Sopenharmony_ci I40E_PF_STAT("port.tx_hwtstamp_skipped", tx_hwtstamp_skipped), 36062306a36Sopenharmony_ci I40E_PF_STAT("port.fdir_flush_cnt", fd_flush_cnt), 36162306a36Sopenharmony_ci I40E_PF_STAT("port.fdir_atr_match", stats.fd_atr_match), 36262306a36Sopenharmony_ci I40E_PF_STAT("port.fdir_atr_tunnel_match", stats.fd_atr_tunnel_match), 36362306a36Sopenharmony_ci I40E_PF_STAT("port.fdir_atr_status", stats.fd_atr_status), 36462306a36Sopenharmony_ci I40E_PF_STAT("port.fdir_sb_match", stats.fd_sb_match), 36562306a36Sopenharmony_ci I40E_PF_STAT("port.fdir_sb_status", stats.fd_sb_status), 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ci /* LPI stats */ 36862306a36Sopenharmony_ci I40E_PF_STAT("port.tx_lpi_status", stats.tx_lpi_status), 36962306a36Sopenharmony_ci I40E_PF_STAT("port.rx_lpi_status", stats.rx_lpi_status), 37062306a36Sopenharmony_ci I40E_PF_STAT("port.tx_lpi_count", stats.tx_lpi_count), 37162306a36Sopenharmony_ci I40E_PF_STAT("port.rx_lpi_count", stats.rx_lpi_count), 37262306a36Sopenharmony_ci}; 37362306a36Sopenharmony_ci 37462306a36Sopenharmony_cistruct i40e_pfc_stats { 37562306a36Sopenharmony_ci u64 priority_xon_rx; 37662306a36Sopenharmony_ci u64 priority_xoff_rx; 37762306a36Sopenharmony_ci u64 priority_xon_tx; 37862306a36Sopenharmony_ci u64 priority_xoff_tx; 37962306a36Sopenharmony_ci u64 priority_xon_2_xoff; 38062306a36Sopenharmony_ci}; 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_cistatic const struct i40e_stats i40e_gstrings_pfc_stats[] = { 38362306a36Sopenharmony_ci I40E_PFC_STAT("port.tx_priority_%u_xon_tx", priority_xon_tx), 38462306a36Sopenharmony_ci I40E_PFC_STAT("port.tx_priority_%u_xoff_tx", priority_xoff_tx), 38562306a36Sopenharmony_ci I40E_PFC_STAT("port.rx_priority_%u_xon_rx", priority_xon_rx), 38662306a36Sopenharmony_ci I40E_PFC_STAT("port.rx_priority_%u_xoff_rx", priority_xoff_rx), 38762306a36Sopenharmony_ci I40E_PFC_STAT("port.rx_priority_%u_xon_2_xoff", priority_xon_2_xoff), 38862306a36Sopenharmony_ci}; 38962306a36Sopenharmony_ci 39062306a36Sopenharmony_ci#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats) 39162306a36Sopenharmony_ci 39262306a36Sopenharmony_ci#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats) 39362306a36Sopenharmony_ci 39462306a36Sopenharmony_ci#define I40E_VSI_STATS_LEN (I40E_NETDEV_STATS_LEN + I40E_MISC_STATS_LEN) 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_ci#define I40E_PFC_STATS_LEN (ARRAY_SIZE(i40e_gstrings_pfc_stats) * \ 39762306a36Sopenharmony_ci I40E_MAX_USER_PRIORITY) 39862306a36Sopenharmony_ci 39962306a36Sopenharmony_ci#define I40E_VEB_STATS_LEN (ARRAY_SIZE(i40e_gstrings_veb_stats) + \ 40062306a36Sopenharmony_ci (ARRAY_SIZE(i40e_gstrings_veb_tc_stats) * \ 40162306a36Sopenharmony_ci I40E_MAX_TRAFFIC_CLASS)) 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ci#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats) 40462306a36Sopenharmony_ci 40562306a36Sopenharmony_ci#define I40E_PF_STATS_LEN (I40E_GLOBAL_STATS_LEN + \ 40662306a36Sopenharmony_ci I40E_PFC_STATS_LEN + \ 40762306a36Sopenharmony_ci I40E_VEB_STATS_LEN + \ 40862306a36Sopenharmony_ci I40E_VSI_STATS_LEN) 40962306a36Sopenharmony_ci 41062306a36Sopenharmony_ci/* Length of stats for a single queue */ 41162306a36Sopenharmony_ci#define I40E_QUEUE_STATS_LEN ARRAY_SIZE(i40e_gstrings_queue_stats) 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_cienum i40e_ethtool_test_id { 41462306a36Sopenharmony_ci I40E_ETH_TEST_REG = 0, 41562306a36Sopenharmony_ci I40E_ETH_TEST_EEPROM, 41662306a36Sopenharmony_ci I40E_ETH_TEST_INTR, 41762306a36Sopenharmony_ci I40E_ETH_TEST_LINK, 41862306a36Sopenharmony_ci}; 41962306a36Sopenharmony_ci 42062306a36Sopenharmony_cistatic const char i40e_gstrings_test[][ETH_GSTRING_LEN] = { 42162306a36Sopenharmony_ci "Register test (offline)", 42262306a36Sopenharmony_ci "Eeprom test (offline)", 42362306a36Sopenharmony_ci "Interrupt test (offline)", 42462306a36Sopenharmony_ci "Link test (on/offline)" 42562306a36Sopenharmony_ci}; 42662306a36Sopenharmony_ci 42762306a36Sopenharmony_ci#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN) 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_cistruct i40e_priv_flags { 43062306a36Sopenharmony_ci char flag_string[ETH_GSTRING_LEN]; 43162306a36Sopenharmony_ci u64 flag; 43262306a36Sopenharmony_ci bool read_only; 43362306a36Sopenharmony_ci}; 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci#define I40E_PRIV_FLAG(_name, _flag, _read_only) { \ 43662306a36Sopenharmony_ci .flag_string = _name, \ 43762306a36Sopenharmony_ci .flag = _flag, \ 43862306a36Sopenharmony_ci .read_only = _read_only, \ 43962306a36Sopenharmony_ci} 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_cistatic const struct i40e_priv_flags i40e_gstrings_priv_flags[] = { 44262306a36Sopenharmony_ci /* NOTE: MFP setting cannot be changed */ 44362306a36Sopenharmony_ci I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1), 44462306a36Sopenharmony_ci I40E_PRIV_FLAG("total-port-shutdown", 44562306a36Sopenharmony_ci I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED, 1), 44662306a36Sopenharmony_ci I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0), 44762306a36Sopenharmony_ci I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0), 44862306a36Sopenharmony_ci I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0), 44962306a36Sopenharmony_ci I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0), 45062306a36Sopenharmony_ci I40E_PRIV_FLAG("link-down-on-close", 45162306a36Sopenharmony_ci I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED, 0), 45262306a36Sopenharmony_ci I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0), 45362306a36Sopenharmony_ci I40E_PRIV_FLAG("disable-source-pruning", 45462306a36Sopenharmony_ci I40E_FLAG_SOURCE_PRUNING_DISABLED, 0), 45562306a36Sopenharmony_ci I40E_PRIV_FLAG("disable-fw-lldp", I40E_FLAG_DISABLE_FW_LLDP, 0), 45662306a36Sopenharmony_ci I40E_PRIV_FLAG("rs-fec", I40E_FLAG_RS_FEC, 0), 45762306a36Sopenharmony_ci I40E_PRIV_FLAG("base-r-fec", I40E_FLAG_BASE_R_FEC, 0), 45862306a36Sopenharmony_ci I40E_PRIV_FLAG("vf-vlan-pruning", 45962306a36Sopenharmony_ci I40E_FLAG_VF_VLAN_PRUNING, 0), 46062306a36Sopenharmony_ci}; 46162306a36Sopenharmony_ci 46262306a36Sopenharmony_ci#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags) 46362306a36Sopenharmony_ci 46462306a36Sopenharmony_ci/* Private flags with a global effect, restricted to PF 0 */ 46562306a36Sopenharmony_cistatic const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = { 46662306a36Sopenharmony_ci I40E_PRIV_FLAG("vf-true-promisc-support", 46762306a36Sopenharmony_ci I40E_FLAG_TRUE_PROMISC_SUPPORT, 0), 46862306a36Sopenharmony_ci}; 46962306a36Sopenharmony_ci 47062306a36Sopenharmony_ci#define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags) 47162306a36Sopenharmony_ci 47262306a36Sopenharmony_ci/** 47362306a36Sopenharmony_ci * i40e_partition_setting_complaint - generic complaint for MFP restriction 47462306a36Sopenharmony_ci * @pf: the PF struct 47562306a36Sopenharmony_ci **/ 47662306a36Sopenharmony_cistatic void i40e_partition_setting_complaint(struct i40e_pf *pf) 47762306a36Sopenharmony_ci{ 47862306a36Sopenharmony_ci dev_info(&pf->pdev->dev, 47962306a36Sopenharmony_ci "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n"); 48062306a36Sopenharmony_ci} 48162306a36Sopenharmony_ci 48262306a36Sopenharmony_ci/** 48362306a36Sopenharmony_ci * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes 48462306a36Sopenharmony_ci * @pf: PF struct with phy_types 48562306a36Sopenharmony_ci * @ks: ethtool link ksettings struct to fill out 48662306a36Sopenharmony_ci * 48762306a36Sopenharmony_ci **/ 48862306a36Sopenharmony_cistatic void i40e_phy_type_to_ethtool(struct i40e_pf *pf, 48962306a36Sopenharmony_ci struct ethtool_link_ksettings *ks) 49062306a36Sopenharmony_ci{ 49162306a36Sopenharmony_ci struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info; 49262306a36Sopenharmony_ci u64 phy_types = pf->hw.phy.phy_types; 49362306a36Sopenharmony_ci 49462306a36Sopenharmony_ci ethtool_link_ksettings_zero_link_mode(ks, supported); 49562306a36Sopenharmony_ci ethtool_link_ksettings_zero_link_mode(ks, advertising); 49662306a36Sopenharmony_ci 49762306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_SGMII) { 49862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 49962306a36Sopenharmony_ci 1000baseT_Full); 50062306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) 50162306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 50262306a36Sopenharmony_ci 1000baseT_Full); 50362306a36Sopenharmony_ci if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) { 50462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 50562306a36Sopenharmony_ci 100baseT_Full); 50662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 50762306a36Sopenharmony_ci 100baseT_Full); 50862306a36Sopenharmony_ci } 50962306a36Sopenharmony_ci } 51062306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_XAUI || 51162306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_XFI || 51262306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_SFI || 51362306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU || 51462306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC) { 51562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 51662306a36Sopenharmony_ci 10000baseT_Full); 51762306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) 51862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 51962306a36Sopenharmony_ci 10000baseT_Full); 52062306a36Sopenharmony_ci } 52162306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_T) { 52262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 52362306a36Sopenharmony_ci 10000baseT_Full); 52462306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) 52562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 52662306a36Sopenharmony_ci 10000baseT_Full); 52762306a36Sopenharmony_ci } 52862306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_2_5GBASE_T) { 52962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 53062306a36Sopenharmony_ci 2500baseT_Full); 53162306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_2_5GB) 53262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 53362306a36Sopenharmony_ci 2500baseT_Full); 53462306a36Sopenharmony_ci } 53562306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_5GBASE_T) { 53662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 53762306a36Sopenharmony_ci 5000baseT_Full); 53862306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_5GB) 53962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 54062306a36Sopenharmony_ci 5000baseT_Full); 54162306a36Sopenharmony_ci } 54262306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_XLAUI || 54362306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_XLPPI || 54462306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC) 54562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 54662306a36Sopenharmony_ci 40000baseCR4_Full); 54762306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU || 54862306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) { 54962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 55062306a36Sopenharmony_ci 40000baseCR4_Full); 55162306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB) 55262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 55362306a36Sopenharmony_ci 40000baseCR4_Full); 55462306a36Sopenharmony_ci } 55562306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) { 55662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 55762306a36Sopenharmony_ci 100baseT_Full); 55862306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB) 55962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 56062306a36Sopenharmony_ci 100baseT_Full); 56162306a36Sopenharmony_ci } 56262306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T) { 56362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 56462306a36Sopenharmony_ci 1000baseT_Full); 56562306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) 56662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 56762306a36Sopenharmony_ci 1000baseT_Full); 56862306a36Sopenharmony_ci } 56962306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4) { 57062306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 57162306a36Sopenharmony_ci 40000baseSR4_Full); 57262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 57362306a36Sopenharmony_ci 40000baseSR4_Full); 57462306a36Sopenharmony_ci } 57562306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4) { 57662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 57762306a36Sopenharmony_ci 40000baseLR4_Full); 57862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 57962306a36Sopenharmony_ci 40000baseLR4_Full); 58062306a36Sopenharmony_ci } 58162306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) { 58262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 58362306a36Sopenharmony_ci 40000baseKR4_Full); 58462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 58562306a36Sopenharmony_ci 40000baseKR4_Full); 58662306a36Sopenharmony_ci } 58762306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) { 58862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 58962306a36Sopenharmony_ci 20000baseKR2_Full); 59062306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB) 59162306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 59262306a36Sopenharmony_ci 20000baseKR2_Full); 59362306a36Sopenharmony_ci } 59462306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) { 59562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 59662306a36Sopenharmony_ci 10000baseKX4_Full); 59762306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) 59862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 59962306a36Sopenharmony_ci 10000baseKX4_Full); 60062306a36Sopenharmony_ci } 60162306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR && 60262306a36Sopenharmony_ci !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) { 60362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 60462306a36Sopenharmony_ci 10000baseKR_Full); 60562306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) 60662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 60762306a36Sopenharmony_ci 10000baseKR_Full); 60862306a36Sopenharmony_ci } 60962306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX && 61062306a36Sopenharmony_ci !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) { 61162306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 61262306a36Sopenharmony_ci 1000baseKX_Full); 61362306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) 61462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 61562306a36Sopenharmony_ci 1000baseKX_Full); 61662306a36Sopenharmony_ci } 61762306a36Sopenharmony_ci /* need to add 25G PHY types */ 61862306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR) { 61962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 62062306a36Sopenharmony_ci 25000baseKR_Full); 62162306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB) 62262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 62362306a36Sopenharmony_ci 25000baseKR_Full); 62462306a36Sopenharmony_ci } 62562306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR) { 62662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 62762306a36Sopenharmony_ci 25000baseCR_Full); 62862306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB) 62962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 63062306a36Sopenharmony_ci 25000baseCR_Full); 63162306a36Sopenharmony_ci } 63262306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR || 63362306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) { 63462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 63562306a36Sopenharmony_ci 25000baseSR_Full); 63662306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB) 63762306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 63862306a36Sopenharmony_ci 25000baseSR_Full); 63962306a36Sopenharmony_ci } 64062306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_AOC || 64162306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_25GBASE_ACC) { 64262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 64362306a36Sopenharmony_ci 25000baseCR_Full); 64462306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB) 64562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 64662306a36Sopenharmony_ci 25000baseCR_Full); 64762306a36Sopenharmony_ci } 64862306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR || 64962306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR || 65062306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR || 65162306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR || 65262306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_25GBASE_AOC || 65362306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_25GBASE_ACC) { 65462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE); 65562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS); 65662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER); 65762306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB) { 65862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 65962306a36Sopenharmony_ci FEC_NONE); 66062306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 66162306a36Sopenharmony_ci FEC_RS); 66262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 66362306a36Sopenharmony_ci FEC_BASER); 66462306a36Sopenharmony_ci } 66562306a36Sopenharmony_ci } 66662306a36Sopenharmony_ci /* need to add new 10G PHY types */ 66762306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 || 66862306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU) { 66962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 67062306a36Sopenharmony_ci 10000baseCR_Full); 67162306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) 67262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 67362306a36Sopenharmony_ci 10000baseCR_Full); 67462306a36Sopenharmony_ci } 67562306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR) { 67662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 67762306a36Sopenharmony_ci 10000baseSR_Full); 67862306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) 67962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 68062306a36Sopenharmony_ci 10000baseSR_Full); 68162306a36Sopenharmony_ci } 68262306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) { 68362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 68462306a36Sopenharmony_ci 10000baseLR_Full); 68562306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) 68662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 68762306a36Sopenharmony_ci 10000baseLR_Full); 68862306a36Sopenharmony_ci } 68962306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX || 69062306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX || 69162306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) { 69262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 69362306a36Sopenharmony_ci 1000baseX_Full); 69462306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) 69562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 69662306a36Sopenharmony_ci 1000baseX_Full); 69762306a36Sopenharmony_ci } 69862306a36Sopenharmony_ci /* Autoneg PHY types */ 69962306a36Sopenharmony_ci if (phy_types & I40E_CAP_PHY_TYPE_SGMII || 70062306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4 || 70162306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU || 70262306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4 || 70362306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR || 70462306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR || 70562306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR || 70662306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR || 70762306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2 || 70862306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR || 70962306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR || 71062306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4 || 71162306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR || 71262306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU || 71362306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 || 71462306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_10GBASE_T || 71562306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_5GBASE_T || 71662306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_2_5GBASE_T || 71762306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL || 71862306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_1000BASE_T || 71962306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX || 72062306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX || 72162306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX || 72262306a36Sopenharmony_ci phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) { 72362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 72462306a36Sopenharmony_ci Autoneg); 72562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 72662306a36Sopenharmony_ci Autoneg); 72762306a36Sopenharmony_ci } 72862306a36Sopenharmony_ci} 72962306a36Sopenharmony_ci 73062306a36Sopenharmony_ci/** 73162306a36Sopenharmony_ci * i40e_get_settings_link_up_fec - Get the FEC mode encoding from mask 73262306a36Sopenharmony_ci * @req_fec_info: mask request FEC info 73362306a36Sopenharmony_ci * @ks: ethtool ksettings to fill in 73462306a36Sopenharmony_ci **/ 73562306a36Sopenharmony_cistatic void i40e_get_settings_link_up_fec(u8 req_fec_info, 73662306a36Sopenharmony_ci struct ethtool_link_ksettings *ks) 73762306a36Sopenharmony_ci{ 73862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE); 73962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS); 74062306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER); 74162306a36Sopenharmony_ci 74262306a36Sopenharmony_ci if ((I40E_AQ_SET_FEC_REQUEST_RS & req_fec_info) && 74362306a36Sopenharmony_ci (I40E_AQ_SET_FEC_REQUEST_KR & req_fec_info)) { 74462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 74562306a36Sopenharmony_ci FEC_NONE); 74662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 74762306a36Sopenharmony_ci FEC_BASER); 74862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS); 74962306a36Sopenharmony_ci } else if (I40E_AQ_SET_FEC_REQUEST_RS & req_fec_info) { 75062306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS); 75162306a36Sopenharmony_ci } else if (I40E_AQ_SET_FEC_REQUEST_KR & req_fec_info) { 75262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 75362306a36Sopenharmony_ci FEC_BASER); 75462306a36Sopenharmony_ci } else { 75562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 75662306a36Sopenharmony_ci FEC_NONE); 75762306a36Sopenharmony_ci } 75862306a36Sopenharmony_ci} 75962306a36Sopenharmony_ci 76062306a36Sopenharmony_ci/** 76162306a36Sopenharmony_ci * i40e_get_settings_link_up - Get the Link settings for when link is up 76262306a36Sopenharmony_ci * @hw: hw structure 76362306a36Sopenharmony_ci * @ks: ethtool ksettings to fill in 76462306a36Sopenharmony_ci * @netdev: network interface device structure 76562306a36Sopenharmony_ci * @pf: pointer to physical function struct 76662306a36Sopenharmony_ci **/ 76762306a36Sopenharmony_cistatic void i40e_get_settings_link_up(struct i40e_hw *hw, 76862306a36Sopenharmony_ci struct ethtool_link_ksettings *ks, 76962306a36Sopenharmony_ci struct net_device *netdev, 77062306a36Sopenharmony_ci struct i40e_pf *pf) 77162306a36Sopenharmony_ci{ 77262306a36Sopenharmony_ci struct i40e_link_status *hw_link_info = &hw->phy.link_info; 77362306a36Sopenharmony_ci struct ethtool_link_ksettings cap_ksettings; 77462306a36Sopenharmony_ci u32 link_speed = hw_link_info->link_speed; 77562306a36Sopenharmony_ci 77662306a36Sopenharmony_ci /* Initialize supported and advertised settings based on phy settings */ 77762306a36Sopenharmony_ci switch (hw_link_info->phy_type) { 77862306a36Sopenharmony_ci case I40E_PHY_TYPE_40GBASE_CR4: 77962306a36Sopenharmony_ci case I40E_PHY_TYPE_40GBASE_CR4_CU: 78062306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 78162306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 78262306a36Sopenharmony_ci 40000baseCR4_Full); 78362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 78462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 78562306a36Sopenharmony_ci 40000baseCR4_Full); 78662306a36Sopenharmony_ci break; 78762306a36Sopenharmony_ci case I40E_PHY_TYPE_XLAUI: 78862306a36Sopenharmony_ci case I40E_PHY_TYPE_XLPPI: 78962306a36Sopenharmony_ci case I40E_PHY_TYPE_40GBASE_AOC: 79062306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 79162306a36Sopenharmony_ci 40000baseCR4_Full); 79262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 79362306a36Sopenharmony_ci 40000baseCR4_Full); 79462306a36Sopenharmony_ci break; 79562306a36Sopenharmony_ci case I40E_PHY_TYPE_40GBASE_SR4: 79662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 79762306a36Sopenharmony_ci 40000baseSR4_Full); 79862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 79962306a36Sopenharmony_ci 40000baseSR4_Full); 80062306a36Sopenharmony_ci break; 80162306a36Sopenharmony_ci case I40E_PHY_TYPE_40GBASE_LR4: 80262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 80362306a36Sopenharmony_ci 40000baseLR4_Full); 80462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 80562306a36Sopenharmony_ci 40000baseLR4_Full); 80662306a36Sopenharmony_ci break; 80762306a36Sopenharmony_ci case I40E_PHY_TYPE_25GBASE_SR: 80862306a36Sopenharmony_ci case I40E_PHY_TYPE_25GBASE_LR: 80962306a36Sopenharmony_ci case I40E_PHY_TYPE_10GBASE_SR: 81062306a36Sopenharmony_ci case I40E_PHY_TYPE_10GBASE_LR: 81162306a36Sopenharmony_ci case I40E_PHY_TYPE_1000BASE_SX: 81262306a36Sopenharmony_ci case I40E_PHY_TYPE_1000BASE_LX: 81362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 81462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 81562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 81662306a36Sopenharmony_ci 25000baseSR_Full); 81762306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 81862306a36Sopenharmony_ci 25000baseSR_Full); 81962306a36Sopenharmony_ci i40e_get_settings_link_up_fec(hw_link_info->req_fec_info, ks); 82062306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 82162306a36Sopenharmony_ci 10000baseSR_Full); 82262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 82362306a36Sopenharmony_ci 10000baseSR_Full); 82462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 82562306a36Sopenharmony_ci 10000baseLR_Full); 82662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 82762306a36Sopenharmony_ci 10000baseLR_Full); 82862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 82962306a36Sopenharmony_ci 1000baseX_Full); 83062306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 83162306a36Sopenharmony_ci 1000baseX_Full); 83262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 83362306a36Sopenharmony_ci 10000baseT_Full); 83462306a36Sopenharmony_ci if (hw_link_info->module_type[2] & 83562306a36Sopenharmony_ci I40E_MODULE_TYPE_1000BASE_SX || 83662306a36Sopenharmony_ci hw_link_info->module_type[2] & 83762306a36Sopenharmony_ci I40E_MODULE_TYPE_1000BASE_LX) { 83862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 83962306a36Sopenharmony_ci 1000baseT_Full); 84062306a36Sopenharmony_ci if (hw_link_info->requested_speeds & 84162306a36Sopenharmony_ci I40E_LINK_SPEED_1GB) 84262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode( 84362306a36Sopenharmony_ci ks, advertising, 1000baseT_Full); 84462306a36Sopenharmony_ci } 84562306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) 84662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 84762306a36Sopenharmony_ci 10000baseT_Full); 84862306a36Sopenharmony_ci break; 84962306a36Sopenharmony_ci case I40E_PHY_TYPE_10GBASE_T: 85062306a36Sopenharmony_ci case I40E_PHY_TYPE_5GBASE_T_LINK_STATUS: 85162306a36Sopenharmony_ci case I40E_PHY_TYPE_2_5GBASE_T_LINK_STATUS: 85262306a36Sopenharmony_ci case I40E_PHY_TYPE_1000BASE_T: 85362306a36Sopenharmony_ci case I40E_PHY_TYPE_100BASE_TX: 85462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 85562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 85662306a36Sopenharmony_ci 10000baseT_Full); 85762306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 85862306a36Sopenharmony_ci 5000baseT_Full); 85962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 86062306a36Sopenharmony_ci 2500baseT_Full); 86162306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 86262306a36Sopenharmony_ci 1000baseT_Full); 86362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 86462306a36Sopenharmony_ci 100baseT_Full); 86562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 86662306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) 86762306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 86862306a36Sopenharmony_ci 10000baseT_Full); 86962306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_5GB) 87062306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 87162306a36Sopenharmony_ci 5000baseT_Full); 87262306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_2_5GB) 87362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 87462306a36Sopenharmony_ci 2500baseT_Full); 87562306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) 87662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 87762306a36Sopenharmony_ci 1000baseT_Full); 87862306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB) 87962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 88062306a36Sopenharmony_ci 100baseT_Full); 88162306a36Sopenharmony_ci break; 88262306a36Sopenharmony_ci case I40E_PHY_TYPE_1000BASE_T_OPTICAL: 88362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 88462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 88562306a36Sopenharmony_ci 1000baseT_Full); 88662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 88762306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 88862306a36Sopenharmony_ci 1000baseT_Full); 88962306a36Sopenharmony_ci break; 89062306a36Sopenharmony_ci case I40E_PHY_TYPE_10GBASE_CR1_CU: 89162306a36Sopenharmony_ci case I40E_PHY_TYPE_10GBASE_CR1: 89262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 89362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 89462306a36Sopenharmony_ci 10000baseT_Full); 89562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 89662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 89762306a36Sopenharmony_ci 10000baseT_Full); 89862306a36Sopenharmony_ci break; 89962306a36Sopenharmony_ci case I40E_PHY_TYPE_XAUI: 90062306a36Sopenharmony_ci case I40E_PHY_TYPE_XFI: 90162306a36Sopenharmony_ci case I40E_PHY_TYPE_SFI: 90262306a36Sopenharmony_ci case I40E_PHY_TYPE_10GBASE_SFPP_CU: 90362306a36Sopenharmony_ci case I40E_PHY_TYPE_10GBASE_AOC: 90462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 90562306a36Sopenharmony_ci 10000baseT_Full); 90662306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) 90762306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 90862306a36Sopenharmony_ci 10000baseT_Full); 90962306a36Sopenharmony_ci i40e_get_settings_link_up_fec(hw_link_info->req_fec_info, ks); 91062306a36Sopenharmony_ci break; 91162306a36Sopenharmony_ci case I40E_PHY_TYPE_SGMII: 91262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 91362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 91462306a36Sopenharmony_ci 1000baseT_Full); 91562306a36Sopenharmony_ci if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) 91662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 91762306a36Sopenharmony_ci 1000baseT_Full); 91862306a36Sopenharmony_ci if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) { 91962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 92062306a36Sopenharmony_ci 100baseT_Full); 92162306a36Sopenharmony_ci if (hw_link_info->requested_speeds & 92262306a36Sopenharmony_ci I40E_LINK_SPEED_100MB) 92362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode( 92462306a36Sopenharmony_ci ks, advertising, 100baseT_Full); 92562306a36Sopenharmony_ci } 92662306a36Sopenharmony_ci break; 92762306a36Sopenharmony_ci case I40E_PHY_TYPE_40GBASE_KR4: 92862306a36Sopenharmony_ci case I40E_PHY_TYPE_25GBASE_KR: 92962306a36Sopenharmony_ci case I40E_PHY_TYPE_20GBASE_KR2: 93062306a36Sopenharmony_ci case I40E_PHY_TYPE_10GBASE_KR: 93162306a36Sopenharmony_ci case I40E_PHY_TYPE_10GBASE_KX4: 93262306a36Sopenharmony_ci case I40E_PHY_TYPE_1000BASE_KX: 93362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 93462306a36Sopenharmony_ci 40000baseKR4_Full); 93562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 93662306a36Sopenharmony_ci 25000baseKR_Full); 93762306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 93862306a36Sopenharmony_ci 20000baseKR2_Full); 93962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 94062306a36Sopenharmony_ci 10000baseKR_Full); 94162306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 94262306a36Sopenharmony_ci 10000baseKX4_Full); 94362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 94462306a36Sopenharmony_ci 1000baseKX_Full); 94562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 94662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 94762306a36Sopenharmony_ci 40000baseKR4_Full); 94862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 94962306a36Sopenharmony_ci 25000baseKR_Full); 95062306a36Sopenharmony_ci i40e_get_settings_link_up_fec(hw_link_info->req_fec_info, ks); 95162306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 95262306a36Sopenharmony_ci 20000baseKR2_Full); 95362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 95462306a36Sopenharmony_ci 10000baseKR_Full); 95562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 95662306a36Sopenharmony_ci 10000baseKX4_Full); 95762306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 95862306a36Sopenharmony_ci 1000baseKX_Full); 95962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 96062306a36Sopenharmony_ci break; 96162306a36Sopenharmony_ci case I40E_PHY_TYPE_25GBASE_CR: 96262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 96362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 96462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 96562306a36Sopenharmony_ci 25000baseCR_Full); 96662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 96762306a36Sopenharmony_ci 25000baseCR_Full); 96862306a36Sopenharmony_ci i40e_get_settings_link_up_fec(hw_link_info->req_fec_info, ks); 96962306a36Sopenharmony_ci 97062306a36Sopenharmony_ci break; 97162306a36Sopenharmony_ci case I40E_PHY_TYPE_25GBASE_AOC: 97262306a36Sopenharmony_ci case I40E_PHY_TYPE_25GBASE_ACC: 97362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 97462306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 97562306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 97662306a36Sopenharmony_ci 25000baseCR_Full); 97762306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 97862306a36Sopenharmony_ci 25000baseCR_Full); 97962306a36Sopenharmony_ci i40e_get_settings_link_up_fec(hw_link_info->req_fec_info, ks); 98062306a36Sopenharmony_ci 98162306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, 98262306a36Sopenharmony_ci 10000baseCR_Full); 98362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 98462306a36Sopenharmony_ci 10000baseCR_Full); 98562306a36Sopenharmony_ci break; 98662306a36Sopenharmony_ci default: 98762306a36Sopenharmony_ci /* if we got here and link is up something bad is afoot */ 98862306a36Sopenharmony_ci netdev_info(netdev, 98962306a36Sopenharmony_ci "WARNING: Link is up but PHY type 0x%x is not recognized, or incorrect cable is in use\n", 99062306a36Sopenharmony_ci hw_link_info->phy_type); 99162306a36Sopenharmony_ci } 99262306a36Sopenharmony_ci 99362306a36Sopenharmony_ci /* Now that we've worked out everything that could be supported by the 99462306a36Sopenharmony_ci * current PHY type, get what is supported by the NVM and intersect 99562306a36Sopenharmony_ci * them to get what is truly supported 99662306a36Sopenharmony_ci */ 99762306a36Sopenharmony_ci memset(&cap_ksettings, 0, sizeof(struct ethtool_link_ksettings)); 99862306a36Sopenharmony_ci i40e_phy_type_to_ethtool(pf, &cap_ksettings); 99962306a36Sopenharmony_ci ethtool_intersect_link_masks(ks, &cap_ksettings); 100062306a36Sopenharmony_ci 100162306a36Sopenharmony_ci /* Set speed and duplex */ 100262306a36Sopenharmony_ci switch (link_speed) { 100362306a36Sopenharmony_ci case I40E_LINK_SPEED_40GB: 100462306a36Sopenharmony_ci ks->base.speed = SPEED_40000; 100562306a36Sopenharmony_ci break; 100662306a36Sopenharmony_ci case I40E_LINK_SPEED_25GB: 100762306a36Sopenharmony_ci ks->base.speed = SPEED_25000; 100862306a36Sopenharmony_ci break; 100962306a36Sopenharmony_ci case I40E_LINK_SPEED_20GB: 101062306a36Sopenharmony_ci ks->base.speed = SPEED_20000; 101162306a36Sopenharmony_ci break; 101262306a36Sopenharmony_ci case I40E_LINK_SPEED_10GB: 101362306a36Sopenharmony_ci ks->base.speed = SPEED_10000; 101462306a36Sopenharmony_ci break; 101562306a36Sopenharmony_ci case I40E_LINK_SPEED_5GB: 101662306a36Sopenharmony_ci ks->base.speed = SPEED_5000; 101762306a36Sopenharmony_ci break; 101862306a36Sopenharmony_ci case I40E_LINK_SPEED_2_5GB: 101962306a36Sopenharmony_ci ks->base.speed = SPEED_2500; 102062306a36Sopenharmony_ci break; 102162306a36Sopenharmony_ci case I40E_LINK_SPEED_1GB: 102262306a36Sopenharmony_ci ks->base.speed = SPEED_1000; 102362306a36Sopenharmony_ci break; 102462306a36Sopenharmony_ci case I40E_LINK_SPEED_100MB: 102562306a36Sopenharmony_ci ks->base.speed = SPEED_100; 102662306a36Sopenharmony_ci break; 102762306a36Sopenharmony_ci default: 102862306a36Sopenharmony_ci ks->base.speed = SPEED_UNKNOWN; 102962306a36Sopenharmony_ci break; 103062306a36Sopenharmony_ci } 103162306a36Sopenharmony_ci ks->base.duplex = DUPLEX_FULL; 103262306a36Sopenharmony_ci} 103362306a36Sopenharmony_ci 103462306a36Sopenharmony_ci/** 103562306a36Sopenharmony_ci * i40e_get_settings_link_down - Get the Link settings for when link is down 103662306a36Sopenharmony_ci * @hw: hw structure 103762306a36Sopenharmony_ci * @ks: ethtool ksettings to fill in 103862306a36Sopenharmony_ci * @pf: pointer to physical function struct 103962306a36Sopenharmony_ci * 104062306a36Sopenharmony_ci * Reports link settings that can be determined when link is down 104162306a36Sopenharmony_ci **/ 104262306a36Sopenharmony_cistatic void i40e_get_settings_link_down(struct i40e_hw *hw, 104362306a36Sopenharmony_ci struct ethtool_link_ksettings *ks, 104462306a36Sopenharmony_ci struct i40e_pf *pf) 104562306a36Sopenharmony_ci{ 104662306a36Sopenharmony_ci /* link is down and the driver needs to fall back on 104762306a36Sopenharmony_ci * supported phy types to figure out what info to display 104862306a36Sopenharmony_ci */ 104962306a36Sopenharmony_ci i40e_phy_type_to_ethtool(pf, ks); 105062306a36Sopenharmony_ci 105162306a36Sopenharmony_ci /* With no link speed and duplex are unknown */ 105262306a36Sopenharmony_ci ks->base.speed = SPEED_UNKNOWN; 105362306a36Sopenharmony_ci ks->base.duplex = DUPLEX_UNKNOWN; 105462306a36Sopenharmony_ci} 105562306a36Sopenharmony_ci 105662306a36Sopenharmony_ci/** 105762306a36Sopenharmony_ci * i40e_get_link_ksettings - Get Link Speed and Duplex settings 105862306a36Sopenharmony_ci * @netdev: network interface device structure 105962306a36Sopenharmony_ci * @ks: ethtool ksettings 106062306a36Sopenharmony_ci * 106162306a36Sopenharmony_ci * Reports speed/duplex settings based on media_type 106262306a36Sopenharmony_ci **/ 106362306a36Sopenharmony_cistatic int i40e_get_link_ksettings(struct net_device *netdev, 106462306a36Sopenharmony_ci struct ethtool_link_ksettings *ks) 106562306a36Sopenharmony_ci{ 106662306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 106762306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 106862306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 106962306a36Sopenharmony_ci struct i40e_link_status *hw_link_info = &hw->phy.link_info; 107062306a36Sopenharmony_ci bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP; 107162306a36Sopenharmony_ci 107262306a36Sopenharmony_ci ethtool_link_ksettings_zero_link_mode(ks, supported); 107362306a36Sopenharmony_ci ethtool_link_ksettings_zero_link_mode(ks, advertising); 107462306a36Sopenharmony_ci 107562306a36Sopenharmony_ci if (link_up) 107662306a36Sopenharmony_ci i40e_get_settings_link_up(hw, ks, netdev, pf); 107762306a36Sopenharmony_ci else 107862306a36Sopenharmony_ci i40e_get_settings_link_down(hw, ks, pf); 107962306a36Sopenharmony_ci 108062306a36Sopenharmony_ci /* Now set the settings that don't rely on link being up/down */ 108162306a36Sopenharmony_ci /* Set autoneg settings */ 108262306a36Sopenharmony_ci ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? 108362306a36Sopenharmony_ci AUTONEG_ENABLE : AUTONEG_DISABLE); 108462306a36Sopenharmony_ci 108562306a36Sopenharmony_ci /* Set media type settings */ 108662306a36Sopenharmony_ci switch (hw->phy.media_type) { 108762306a36Sopenharmony_ci case I40E_MEDIA_TYPE_BACKPLANE: 108862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 108962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Backplane); 109062306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 109162306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 109262306a36Sopenharmony_ci Backplane); 109362306a36Sopenharmony_ci ks->base.port = PORT_NONE; 109462306a36Sopenharmony_ci break; 109562306a36Sopenharmony_ci case I40E_MEDIA_TYPE_BASET: 109662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, TP); 109762306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, TP); 109862306a36Sopenharmony_ci ks->base.port = PORT_TP; 109962306a36Sopenharmony_ci break; 110062306a36Sopenharmony_ci case I40E_MEDIA_TYPE_DA: 110162306a36Sopenharmony_ci case I40E_MEDIA_TYPE_CX4: 110262306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE); 110362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE); 110462306a36Sopenharmony_ci ks->base.port = PORT_DA; 110562306a36Sopenharmony_ci break; 110662306a36Sopenharmony_ci case I40E_MEDIA_TYPE_FIBER: 110762306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE); 110862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE); 110962306a36Sopenharmony_ci ks->base.port = PORT_FIBRE; 111062306a36Sopenharmony_ci break; 111162306a36Sopenharmony_ci case I40E_MEDIA_TYPE_UNKNOWN: 111262306a36Sopenharmony_ci default: 111362306a36Sopenharmony_ci ks->base.port = PORT_OTHER; 111462306a36Sopenharmony_ci break; 111562306a36Sopenharmony_ci } 111662306a36Sopenharmony_ci 111762306a36Sopenharmony_ci /* Set flow control settings */ 111862306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Pause); 111962306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, supported, Asym_Pause); 112062306a36Sopenharmony_ci 112162306a36Sopenharmony_ci switch (hw->fc.requested_mode) { 112262306a36Sopenharmony_ci case I40E_FC_FULL: 112362306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, Pause); 112462306a36Sopenharmony_ci break; 112562306a36Sopenharmony_ci case I40E_FC_TX_PAUSE: 112662306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 112762306a36Sopenharmony_ci Asym_Pause); 112862306a36Sopenharmony_ci break; 112962306a36Sopenharmony_ci case I40E_FC_RX_PAUSE: 113062306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, Pause); 113162306a36Sopenharmony_ci ethtool_link_ksettings_add_link_mode(ks, advertising, 113262306a36Sopenharmony_ci Asym_Pause); 113362306a36Sopenharmony_ci break; 113462306a36Sopenharmony_ci default: 113562306a36Sopenharmony_ci ethtool_link_ksettings_del_link_mode(ks, advertising, Pause); 113662306a36Sopenharmony_ci ethtool_link_ksettings_del_link_mode(ks, advertising, 113762306a36Sopenharmony_ci Asym_Pause); 113862306a36Sopenharmony_ci break; 113962306a36Sopenharmony_ci } 114062306a36Sopenharmony_ci 114162306a36Sopenharmony_ci return 0; 114262306a36Sopenharmony_ci} 114362306a36Sopenharmony_ci 114462306a36Sopenharmony_ci#define I40E_LBIT_SIZE 8 114562306a36Sopenharmony_ci/** 114662306a36Sopenharmony_ci * i40e_speed_to_link_speed - Translate decimal speed to i40e_aq_link_speed 114762306a36Sopenharmony_ci * @speed: speed in decimal 114862306a36Sopenharmony_ci * @ks: ethtool ksettings 114962306a36Sopenharmony_ci * 115062306a36Sopenharmony_ci * Return i40e_aq_link_speed based on speed 115162306a36Sopenharmony_ci **/ 115262306a36Sopenharmony_cistatic enum i40e_aq_link_speed 115362306a36Sopenharmony_cii40e_speed_to_link_speed(__u32 speed, const struct ethtool_link_ksettings *ks) 115462306a36Sopenharmony_ci{ 115562306a36Sopenharmony_ci enum i40e_aq_link_speed link_speed = I40E_LINK_SPEED_UNKNOWN; 115662306a36Sopenharmony_ci bool speed_changed = false; 115762306a36Sopenharmony_ci int i, j; 115862306a36Sopenharmony_ci 115962306a36Sopenharmony_ci static const struct { 116062306a36Sopenharmony_ci __u32 speed; 116162306a36Sopenharmony_ci enum i40e_aq_link_speed link_speed; 116262306a36Sopenharmony_ci __u8 bit[I40E_LBIT_SIZE]; 116362306a36Sopenharmony_ci } i40e_speed_lut[] = { 116462306a36Sopenharmony_ci#define I40E_LBIT(mode) ETHTOOL_LINK_MODE_ ## mode ##_Full_BIT 116562306a36Sopenharmony_ci {SPEED_100, I40E_LINK_SPEED_100MB, {I40E_LBIT(100baseT)} }, 116662306a36Sopenharmony_ci {SPEED_1000, I40E_LINK_SPEED_1GB, 116762306a36Sopenharmony_ci {I40E_LBIT(1000baseT), I40E_LBIT(1000baseX), 116862306a36Sopenharmony_ci I40E_LBIT(1000baseKX)} }, 116962306a36Sopenharmony_ci {SPEED_10000, I40E_LINK_SPEED_10GB, 117062306a36Sopenharmony_ci {I40E_LBIT(10000baseT), I40E_LBIT(10000baseKR), 117162306a36Sopenharmony_ci I40E_LBIT(10000baseLR), I40E_LBIT(10000baseCR), 117262306a36Sopenharmony_ci I40E_LBIT(10000baseSR), I40E_LBIT(10000baseKX4)} }, 117362306a36Sopenharmony_ci 117462306a36Sopenharmony_ci {SPEED_25000, I40E_LINK_SPEED_25GB, 117562306a36Sopenharmony_ci {I40E_LBIT(25000baseCR), I40E_LBIT(25000baseKR), 117662306a36Sopenharmony_ci I40E_LBIT(25000baseSR)} }, 117762306a36Sopenharmony_ci {SPEED_40000, I40E_LINK_SPEED_40GB, 117862306a36Sopenharmony_ci {I40E_LBIT(40000baseKR4), I40E_LBIT(40000baseCR4), 117962306a36Sopenharmony_ci I40E_LBIT(40000baseSR4), I40E_LBIT(40000baseLR4)} }, 118062306a36Sopenharmony_ci {SPEED_20000, I40E_LINK_SPEED_20GB, 118162306a36Sopenharmony_ci {I40E_LBIT(20000baseKR2)} }, 118262306a36Sopenharmony_ci {SPEED_2500, I40E_LINK_SPEED_2_5GB, {I40E_LBIT(2500baseT)} }, 118362306a36Sopenharmony_ci {SPEED_5000, I40E_LINK_SPEED_5GB, {I40E_LBIT(2500baseT)} } 118462306a36Sopenharmony_ci#undef I40E_LBIT 118562306a36Sopenharmony_ci}; 118662306a36Sopenharmony_ci 118762306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(i40e_speed_lut); i++) { 118862306a36Sopenharmony_ci if (i40e_speed_lut[i].speed == speed) { 118962306a36Sopenharmony_ci for (j = 0; j < I40E_LBIT_SIZE; j++) { 119062306a36Sopenharmony_ci if (test_bit(i40e_speed_lut[i].bit[j], 119162306a36Sopenharmony_ci ks->link_modes.supported)) { 119262306a36Sopenharmony_ci speed_changed = true; 119362306a36Sopenharmony_ci break; 119462306a36Sopenharmony_ci } 119562306a36Sopenharmony_ci if (!i40e_speed_lut[i].bit[j]) 119662306a36Sopenharmony_ci break; 119762306a36Sopenharmony_ci } 119862306a36Sopenharmony_ci if (speed_changed) { 119962306a36Sopenharmony_ci link_speed = i40e_speed_lut[i].link_speed; 120062306a36Sopenharmony_ci break; 120162306a36Sopenharmony_ci } 120262306a36Sopenharmony_ci } 120362306a36Sopenharmony_ci } 120462306a36Sopenharmony_ci return link_speed; 120562306a36Sopenharmony_ci} 120662306a36Sopenharmony_ci 120762306a36Sopenharmony_ci#undef I40E_LBIT_SIZE 120862306a36Sopenharmony_ci 120962306a36Sopenharmony_ci/** 121062306a36Sopenharmony_ci * i40e_set_link_ksettings - Set Speed and Duplex 121162306a36Sopenharmony_ci * @netdev: network interface device structure 121262306a36Sopenharmony_ci * @ks: ethtool ksettings 121362306a36Sopenharmony_ci * 121462306a36Sopenharmony_ci * Set speed/duplex per media_types advertised/forced 121562306a36Sopenharmony_ci **/ 121662306a36Sopenharmony_cistatic int i40e_set_link_ksettings(struct net_device *netdev, 121762306a36Sopenharmony_ci const struct ethtool_link_ksettings *ks) 121862306a36Sopenharmony_ci{ 121962306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 122062306a36Sopenharmony_ci struct i40e_aq_get_phy_abilities_resp abilities; 122162306a36Sopenharmony_ci struct ethtool_link_ksettings safe_ks; 122262306a36Sopenharmony_ci struct ethtool_link_ksettings copy_ks; 122362306a36Sopenharmony_ci struct i40e_aq_set_phy_config config; 122462306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 122562306a36Sopenharmony_ci enum i40e_aq_link_speed link_speed; 122662306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 122762306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 122862306a36Sopenharmony_ci bool autoneg_changed = false; 122962306a36Sopenharmony_ci int timeout = 50; 123062306a36Sopenharmony_ci int status = 0; 123162306a36Sopenharmony_ci int err = 0; 123262306a36Sopenharmony_ci __u32 speed; 123362306a36Sopenharmony_ci u8 autoneg; 123462306a36Sopenharmony_ci 123562306a36Sopenharmony_ci /* Changing port settings is not supported if this isn't the 123662306a36Sopenharmony_ci * port's controlling PF 123762306a36Sopenharmony_ci */ 123862306a36Sopenharmony_ci if (hw->partition_id != 1) { 123962306a36Sopenharmony_ci i40e_partition_setting_complaint(pf); 124062306a36Sopenharmony_ci return -EOPNOTSUPP; 124162306a36Sopenharmony_ci } 124262306a36Sopenharmony_ci if (vsi != pf->vsi[pf->lan_vsi]) 124362306a36Sopenharmony_ci return -EOPNOTSUPP; 124462306a36Sopenharmony_ci if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET && 124562306a36Sopenharmony_ci hw->phy.media_type != I40E_MEDIA_TYPE_FIBER && 124662306a36Sopenharmony_ci hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE && 124762306a36Sopenharmony_ci hw->phy.media_type != I40E_MEDIA_TYPE_DA && 124862306a36Sopenharmony_ci hw->phy.link_info.link_info & I40E_AQ_LINK_UP) 124962306a36Sopenharmony_ci return -EOPNOTSUPP; 125062306a36Sopenharmony_ci if (hw->device_id == I40E_DEV_ID_KX_B || 125162306a36Sopenharmony_ci hw->device_id == I40E_DEV_ID_KX_C || 125262306a36Sopenharmony_ci hw->device_id == I40E_DEV_ID_20G_KR2 || 125362306a36Sopenharmony_ci hw->device_id == I40E_DEV_ID_20G_KR2_A || 125462306a36Sopenharmony_ci hw->device_id == I40E_DEV_ID_25G_B || 125562306a36Sopenharmony_ci hw->device_id == I40E_DEV_ID_KX_X722) { 125662306a36Sopenharmony_ci netdev_info(netdev, "Changing settings is not supported on backplane.\n"); 125762306a36Sopenharmony_ci return -EOPNOTSUPP; 125862306a36Sopenharmony_ci } 125962306a36Sopenharmony_ci 126062306a36Sopenharmony_ci /* copy the ksettings to copy_ks to avoid modifying the origin */ 126162306a36Sopenharmony_ci memcpy(©_ks, ks, sizeof(struct ethtool_link_ksettings)); 126262306a36Sopenharmony_ci 126362306a36Sopenharmony_ci /* save autoneg out of ksettings */ 126462306a36Sopenharmony_ci autoneg = copy_ks.base.autoneg; 126562306a36Sopenharmony_ci speed = copy_ks.base.speed; 126662306a36Sopenharmony_ci 126762306a36Sopenharmony_ci /* get our own copy of the bits to check against */ 126862306a36Sopenharmony_ci memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings)); 126962306a36Sopenharmony_ci safe_ks.base.cmd = copy_ks.base.cmd; 127062306a36Sopenharmony_ci safe_ks.base.link_mode_masks_nwords = 127162306a36Sopenharmony_ci copy_ks.base.link_mode_masks_nwords; 127262306a36Sopenharmony_ci i40e_get_link_ksettings(netdev, &safe_ks); 127362306a36Sopenharmony_ci 127462306a36Sopenharmony_ci /* Get link modes supported by hardware and check against modes 127562306a36Sopenharmony_ci * requested by the user. Return an error if unsupported mode was set. 127662306a36Sopenharmony_ci */ 127762306a36Sopenharmony_ci if (!bitmap_subset(copy_ks.link_modes.advertising, 127862306a36Sopenharmony_ci safe_ks.link_modes.supported, 127962306a36Sopenharmony_ci __ETHTOOL_LINK_MODE_MASK_NBITS)) 128062306a36Sopenharmony_ci return -EINVAL; 128162306a36Sopenharmony_ci 128262306a36Sopenharmony_ci /* set autoneg back to what it currently is */ 128362306a36Sopenharmony_ci copy_ks.base.autoneg = safe_ks.base.autoneg; 128462306a36Sopenharmony_ci copy_ks.base.speed = safe_ks.base.speed; 128562306a36Sopenharmony_ci 128662306a36Sopenharmony_ci /* If copy_ks.base and safe_ks.base are not the same now, then they are 128762306a36Sopenharmony_ci * trying to set something that we do not support. 128862306a36Sopenharmony_ci */ 128962306a36Sopenharmony_ci if (memcmp(©_ks.base, &safe_ks.base, 129062306a36Sopenharmony_ci sizeof(struct ethtool_link_settings))) { 129162306a36Sopenharmony_ci netdev_err(netdev, "Only speed and autoneg are supported.\n"); 129262306a36Sopenharmony_ci return -EOPNOTSUPP; 129362306a36Sopenharmony_ci } 129462306a36Sopenharmony_ci 129562306a36Sopenharmony_ci while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) { 129662306a36Sopenharmony_ci timeout--; 129762306a36Sopenharmony_ci if (!timeout) 129862306a36Sopenharmony_ci return -EBUSY; 129962306a36Sopenharmony_ci usleep_range(1000, 2000); 130062306a36Sopenharmony_ci } 130162306a36Sopenharmony_ci 130262306a36Sopenharmony_ci /* Get the current phy config */ 130362306a36Sopenharmony_ci status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, 130462306a36Sopenharmony_ci NULL); 130562306a36Sopenharmony_ci if (status) { 130662306a36Sopenharmony_ci err = -EAGAIN; 130762306a36Sopenharmony_ci goto done; 130862306a36Sopenharmony_ci } 130962306a36Sopenharmony_ci 131062306a36Sopenharmony_ci /* Copy abilities to config in case autoneg is not 131162306a36Sopenharmony_ci * set below 131262306a36Sopenharmony_ci */ 131362306a36Sopenharmony_ci memset(&config, 0, sizeof(struct i40e_aq_set_phy_config)); 131462306a36Sopenharmony_ci config.abilities = abilities.abilities; 131562306a36Sopenharmony_ci 131662306a36Sopenharmony_ci /* Check autoneg */ 131762306a36Sopenharmony_ci if (autoneg == AUTONEG_ENABLE) { 131862306a36Sopenharmony_ci /* If autoneg was not already enabled */ 131962306a36Sopenharmony_ci if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) { 132062306a36Sopenharmony_ci /* If autoneg is not supported, return error */ 132162306a36Sopenharmony_ci if (!ethtool_link_ksettings_test_link_mode(&safe_ks, 132262306a36Sopenharmony_ci supported, 132362306a36Sopenharmony_ci Autoneg)) { 132462306a36Sopenharmony_ci netdev_info(netdev, "Autoneg not supported on this phy\n"); 132562306a36Sopenharmony_ci err = -EINVAL; 132662306a36Sopenharmony_ci goto done; 132762306a36Sopenharmony_ci } 132862306a36Sopenharmony_ci /* Autoneg is allowed to change */ 132962306a36Sopenharmony_ci config.abilities = abilities.abilities | 133062306a36Sopenharmony_ci I40E_AQ_PHY_ENABLE_AN; 133162306a36Sopenharmony_ci autoneg_changed = true; 133262306a36Sopenharmony_ci } 133362306a36Sopenharmony_ci } else { 133462306a36Sopenharmony_ci /* If autoneg is currently enabled */ 133562306a36Sopenharmony_ci if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) { 133662306a36Sopenharmony_ci /* If autoneg is supported 10GBASE_T is the only PHY 133762306a36Sopenharmony_ci * that can disable it, so otherwise return error 133862306a36Sopenharmony_ci */ 133962306a36Sopenharmony_ci if (ethtool_link_ksettings_test_link_mode(&safe_ks, 134062306a36Sopenharmony_ci supported, 134162306a36Sopenharmony_ci Autoneg) && 134262306a36Sopenharmony_ci hw->phy.media_type != I40E_MEDIA_TYPE_BASET) { 134362306a36Sopenharmony_ci netdev_info(netdev, "Autoneg cannot be disabled on this phy\n"); 134462306a36Sopenharmony_ci err = -EINVAL; 134562306a36Sopenharmony_ci goto done; 134662306a36Sopenharmony_ci } 134762306a36Sopenharmony_ci /* Autoneg is allowed to change */ 134862306a36Sopenharmony_ci config.abilities = abilities.abilities & 134962306a36Sopenharmony_ci ~I40E_AQ_PHY_ENABLE_AN; 135062306a36Sopenharmony_ci autoneg_changed = true; 135162306a36Sopenharmony_ci } 135262306a36Sopenharmony_ci } 135362306a36Sopenharmony_ci 135462306a36Sopenharmony_ci if (ethtool_link_ksettings_test_link_mode(ks, advertising, 135562306a36Sopenharmony_ci 100baseT_Full)) 135662306a36Sopenharmony_ci config.link_speed |= I40E_LINK_SPEED_100MB; 135762306a36Sopenharmony_ci if (ethtool_link_ksettings_test_link_mode(ks, advertising, 135862306a36Sopenharmony_ci 1000baseT_Full) || 135962306a36Sopenharmony_ci ethtool_link_ksettings_test_link_mode(ks, advertising, 136062306a36Sopenharmony_ci 1000baseX_Full) || 136162306a36Sopenharmony_ci ethtool_link_ksettings_test_link_mode(ks, advertising, 136262306a36Sopenharmony_ci 1000baseKX_Full)) 136362306a36Sopenharmony_ci config.link_speed |= I40E_LINK_SPEED_1GB; 136462306a36Sopenharmony_ci if (ethtool_link_ksettings_test_link_mode(ks, advertising, 136562306a36Sopenharmony_ci 10000baseT_Full) || 136662306a36Sopenharmony_ci ethtool_link_ksettings_test_link_mode(ks, advertising, 136762306a36Sopenharmony_ci 10000baseKX4_Full) || 136862306a36Sopenharmony_ci ethtool_link_ksettings_test_link_mode(ks, advertising, 136962306a36Sopenharmony_ci 10000baseKR_Full) || 137062306a36Sopenharmony_ci ethtool_link_ksettings_test_link_mode(ks, advertising, 137162306a36Sopenharmony_ci 10000baseCR_Full) || 137262306a36Sopenharmony_ci ethtool_link_ksettings_test_link_mode(ks, advertising, 137362306a36Sopenharmony_ci 10000baseSR_Full) || 137462306a36Sopenharmony_ci ethtool_link_ksettings_test_link_mode(ks, advertising, 137562306a36Sopenharmony_ci 10000baseLR_Full)) 137662306a36Sopenharmony_ci config.link_speed |= I40E_LINK_SPEED_10GB; 137762306a36Sopenharmony_ci if (ethtool_link_ksettings_test_link_mode(ks, advertising, 137862306a36Sopenharmony_ci 2500baseT_Full)) 137962306a36Sopenharmony_ci config.link_speed |= I40E_LINK_SPEED_2_5GB; 138062306a36Sopenharmony_ci if (ethtool_link_ksettings_test_link_mode(ks, advertising, 138162306a36Sopenharmony_ci 5000baseT_Full)) 138262306a36Sopenharmony_ci config.link_speed |= I40E_LINK_SPEED_5GB; 138362306a36Sopenharmony_ci if (ethtool_link_ksettings_test_link_mode(ks, advertising, 138462306a36Sopenharmony_ci 20000baseKR2_Full)) 138562306a36Sopenharmony_ci config.link_speed |= I40E_LINK_SPEED_20GB; 138662306a36Sopenharmony_ci if (ethtool_link_ksettings_test_link_mode(ks, advertising, 138762306a36Sopenharmony_ci 25000baseCR_Full) || 138862306a36Sopenharmony_ci ethtool_link_ksettings_test_link_mode(ks, advertising, 138962306a36Sopenharmony_ci 25000baseKR_Full) || 139062306a36Sopenharmony_ci ethtool_link_ksettings_test_link_mode(ks, advertising, 139162306a36Sopenharmony_ci 25000baseSR_Full)) 139262306a36Sopenharmony_ci config.link_speed |= I40E_LINK_SPEED_25GB; 139362306a36Sopenharmony_ci if (ethtool_link_ksettings_test_link_mode(ks, advertising, 139462306a36Sopenharmony_ci 40000baseKR4_Full) || 139562306a36Sopenharmony_ci ethtool_link_ksettings_test_link_mode(ks, advertising, 139662306a36Sopenharmony_ci 40000baseCR4_Full) || 139762306a36Sopenharmony_ci ethtool_link_ksettings_test_link_mode(ks, advertising, 139862306a36Sopenharmony_ci 40000baseSR4_Full) || 139962306a36Sopenharmony_ci ethtool_link_ksettings_test_link_mode(ks, advertising, 140062306a36Sopenharmony_ci 40000baseLR4_Full)) 140162306a36Sopenharmony_ci config.link_speed |= I40E_LINK_SPEED_40GB; 140262306a36Sopenharmony_ci 140362306a36Sopenharmony_ci /* Autonegotiation must be disabled to change speed */ 140462306a36Sopenharmony_ci if ((speed != SPEED_UNKNOWN && safe_ks.base.speed != speed) && 140562306a36Sopenharmony_ci (autoneg == AUTONEG_DISABLE || 140662306a36Sopenharmony_ci (safe_ks.base.autoneg == AUTONEG_DISABLE && !autoneg_changed))) { 140762306a36Sopenharmony_ci link_speed = i40e_speed_to_link_speed(speed, ks); 140862306a36Sopenharmony_ci if (link_speed == I40E_LINK_SPEED_UNKNOWN) { 140962306a36Sopenharmony_ci netdev_info(netdev, "Given speed is not supported\n"); 141062306a36Sopenharmony_ci err = -EOPNOTSUPP; 141162306a36Sopenharmony_ci goto done; 141262306a36Sopenharmony_ci } else { 141362306a36Sopenharmony_ci config.link_speed = link_speed; 141462306a36Sopenharmony_ci } 141562306a36Sopenharmony_ci } else { 141662306a36Sopenharmony_ci if (safe_ks.base.speed != speed) { 141762306a36Sopenharmony_ci netdev_info(netdev, 141862306a36Sopenharmony_ci "Unable to set speed, disable autoneg\n"); 141962306a36Sopenharmony_ci err = -EOPNOTSUPP; 142062306a36Sopenharmony_ci goto done; 142162306a36Sopenharmony_ci } 142262306a36Sopenharmony_ci } 142362306a36Sopenharmony_ci 142462306a36Sopenharmony_ci /* If speed didn't get set, set it to what it currently is. 142562306a36Sopenharmony_ci * This is needed because if advertise is 0 (as it is when autoneg 142662306a36Sopenharmony_ci * is disabled) then speed won't get set. 142762306a36Sopenharmony_ci */ 142862306a36Sopenharmony_ci if (!config.link_speed) 142962306a36Sopenharmony_ci config.link_speed = abilities.link_speed; 143062306a36Sopenharmony_ci if (autoneg_changed || abilities.link_speed != config.link_speed) { 143162306a36Sopenharmony_ci /* copy over the rest of the abilities */ 143262306a36Sopenharmony_ci config.phy_type = abilities.phy_type; 143362306a36Sopenharmony_ci config.phy_type_ext = abilities.phy_type_ext; 143462306a36Sopenharmony_ci config.eee_capability = abilities.eee_capability; 143562306a36Sopenharmony_ci config.eeer = abilities.eeer_val; 143662306a36Sopenharmony_ci config.low_power_ctrl = abilities.d3_lpan; 143762306a36Sopenharmony_ci config.fec_config = abilities.fec_cfg_curr_mod_ext_info & 143862306a36Sopenharmony_ci I40E_AQ_PHY_FEC_CONFIG_MASK; 143962306a36Sopenharmony_ci 144062306a36Sopenharmony_ci /* save the requested speeds */ 144162306a36Sopenharmony_ci hw->phy.link_info.requested_speeds = config.link_speed; 144262306a36Sopenharmony_ci /* set link and auto negotiation so changes take effect */ 144362306a36Sopenharmony_ci config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK; 144462306a36Sopenharmony_ci /* If link is up put link down */ 144562306a36Sopenharmony_ci if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) { 144662306a36Sopenharmony_ci /* Tell the OS link is going down, the link will go 144762306a36Sopenharmony_ci * back up when fw says it is ready asynchronously 144862306a36Sopenharmony_ci */ 144962306a36Sopenharmony_ci i40e_print_link_message(vsi, false); 145062306a36Sopenharmony_ci netif_carrier_off(netdev); 145162306a36Sopenharmony_ci netif_tx_stop_all_queues(netdev); 145262306a36Sopenharmony_ci } 145362306a36Sopenharmony_ci 145462306a36Sopenharmony_ci /* make the aq call */ 145562306a36Sopenharmony_ci status = i40e_aq_set_phy_config(hw, &config, NULL); 145662306a36Sopenharmony_ci if (status) { 145762306a36Sopenharmony_ci netdev_info(netdev, 145862306a36Sopenharmony_ci "Set phy config failed, err %pe aq_err %s\n", 145962306a36Sopenharmony_ci ERR_PTR(status), 146062306a36Sopenharmony_ci i40e_aq_str(hw, hw->aq.asq_last_status)); 146162306a36Sopenharmony_ci err = -EAGAIN; 146262306a36Sopenharmony_ci goto done; 146362306a36Sopenharmony_ci } 146462306a36Sopenharmony_ci 146562306a36Sopenharmony_ci status = i40e_update_link_info(hw); 146662306a36Sopenharmony_ci if (status) 146762306a36Sopenharmony_ci netdev_dbg(netdev, 146862306a36Sopenharmony_ci "Updating link info failed with err %pe aq_err %s\n", 146962306a36Sopenharmony_ci ERR_PTR(status), 147062306a36Sopenharmony_ci i40e_aq_str(hw, hw->aq.asq_last_status)); 147162306a36Sopenharmony_ci 147262306a36Sopenharmony_ci } else { 147362306a36Sopenharmony_ci netdev_info(netdev, "Nothing changed, exiting without setting anything.\n"); 147462306a36Sopenharmony_ci } 147562306a36Sopenharmony_ci 147662306a36Sopenharmony_cidone: 147762306a36Sopenharmony_ci clear_bit(__I40E_CONFIG_BUSY, pf->state); 147862306a36Sopenharmony_ci 147962306a36Sopenharmony_ci return err; 148062306a36Sopenharmony_ci} 148162306a36Sopenharmony_ci 148262306a36Sopenharmony_cistatic int i40e_set_fec_cfg(struct net_device *netdev, u8 fec_cfg) 148362306a36Sopenharmony_ci{ 148462306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 148562306a36Sopenharmony_ci struct i40e_aq_get_phy_abilities_resp abilities; 148662306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 148762306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 148862306a36Sopenharmony_ci int status = 0; 148962306a36Sopenharmony_ci u32 flags = 0; 149062306a36Sopenharmony_ci int err = 0; 149162306a36Sopenharmony_ci 149262306a36Sopenharmony_ci flags = READ_ONCE(pf->flags); 149362306a36Sopenharmony_ci i40e_set_fec_in_flags(fec_cfg, &flags); 149462306a36Sopenharmony_ci 149562306a36Sopenharmony_ci /* Get the current phy config */ 149662306a36Sopenharmony_ci memset(&abilities, 0, sizeof(abilities)); 149762306a36Sopenharmony_ci status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, 149862306a36Sopenharmony_ci NULL); 149962306a36Sopenharmony_ci if (status) { 150062306a36Sopenharmony_ci err = -EAGAIN; 150162306a36Sopenharmony_ci goto done; 150262306a36Sopenharmony_ci } 150362306a36Sopenharmony_ci 150462306a36Sopenharmony_ci if (abilities.fec_cfg_curr_mod_ext_info != fec_cfg) { 150562306a36Sopenharmony_ci struct i40e_aq_set_phy_config config; 150662306a36Sopenharmony_ci 150762306a36Sopenharmony_ci memset(&config, 0, sizeof(config)); 150862306a36Sopenharmony_ci config.phy_type = abilities.phy_type; 150962306a36Sopenharmony_ci config.abilities = abilities.abilities | 151062306a36Sopenharmony_ci I40E_AQ_PHY_ENABLE_ATOMIC_LINK; 151162306a36Sopenharmony_ci config.phy_type_ext = abilities.phy_type_ext; 151262306a36Sopenharmony_ci config.link_speed = abilities.link_speed; 151362306a36Sopenharmony_ci config.eee_capability = abilities.eee_capability; 151462306a36Sopenharmony_ci config.eeer = abilities.eeer_val; 151562306a36Sopenharmony_ci config.low_power_ctrl = abilities.d3_lpan; 151662306a36Sopenharmony_ci config.fec_config = fec_cfg & I40E_AQ_PHY_FEC_CONFIG_MASK; 151762306a36Sopenharmony_ci status = i40e_aq_set_phy_config(hw, &config, NULL); 151862306a36Sopenharmony_ci if (status) { 151962306a36Sopenharmony_ci netdev_info(netdev, 152062306a36Sopenharmony_ci "Set phy config failed, err %pe aq_err %s\n", 152162306a36Sopenharmony_ci ERR_PTR(status), 152262306a36Sopenharmony_ci i40e_aq_str(hw, hw->aq.asq_last_status)); 152362306a36Sopenharmony_ci err = -EAGAIN; 152462306a36Sopenharmony_ci goto done; 152562306a36Sopenharmony_ci } 152662306a36Sopenharmony_ci pf->flags = flags; 152762306a36Sopenharmony_ci status = i40e_update_link_info(hw); 152862306a36Sopenharmony_ci if (status) 152962306a36Sopenharmony_ci /* debug level message only due to relation to the link 153062306a36Sopenharmony_ci * itself rather than to the FEC settings 153162306a36Sopenharmony_ci * (e.g. no physical connection etc.) 153262306a36Sopenharmony_ci */ 153362306a36Sopenharmony_ci netdev_dbg(netdev, 153462306a36Sopenharmony_ci "Updating link info failed with err %pe aq_err %s\n", 153562306a36Sopenharmony_ci ERR_PTR(status), 153662306a36Sopenharmony_ci i40e_aq_str(hw, hw->aq.asq_last_status)); 153762306a36Sopenharmony_ci } 153862306a36Sopenharmony_ci 153962306a36Sopenharmony_cidone: 154062306a36Sopenharmony_ci return err; 154162306a36Sopenharmony_ci} 154262306a36Sopenharmony_ci 154362306a36Sopenharmony_cistatic int i40e_get_fec_param(struct net_device *netdev, 154462306a36Sopenharmony_ci struct ethtool_fecparam *fecparam) 154562306a36Sopenharmony_ci{ 154662306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 154762306a36Sopenharmony_ci struct i40e_aq_get_phy_abilities_resp abilities; 154862306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 154962306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 155062306a36Sopenharmony_ci int status = 0; 155162306a36Sopenharmony_ci int err = 0; 155262306a36Sopenharmony_ci u8 fec_cfg; 155362306a36Sopenharmony_ci 155462306a36Sopenharmony_ci /* Get the current phy config */ 155562306a36Sopenharmony_ci memset(&abilities, 0, sizeof(abilities)); 155662306a36Sopenharmony_ci status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, 155762306a36Sopenharmony_ci NULL); 155862306a36Sopenharmony_ci if (status) { 155962306a36Sopenharmony_ci err = -EAGAIN; 156062306a36Sopenharmony_ci goto done; 156162306a36Sopenharmony_ci } 156262306a36Sopenharmony_ci 156362306a36Sopenharmony_ci fecparam->fec = 0; 156462306a36Sopenharmony_ci fec_cfg = abilities.fec_cfg_curr_mod_ext_info; 156562306a36Sopenharmony_ci if (fec_cfg & I40E_AQ_SET_FEC_AUTO) 156662306a36Sopenharmony_ci fecparam->fec |= ETHTOOL_FEC_AUTO; 156762306a36Sopenharmony_ci else if (fec_cfg & (I40E_AQ_SET_FEC_REQUEST_RS | 156862306a36Sopenharmony_ci I40E_AQ_SET_FEC_ABILITY_RS)) 156962306a36Sopenharmony_ci fecparam->fec |= ETHTOOL_FEC_RS; 157062306a36Sopenharmony_ci else if (fec_cfg & (I40E_AQ_SET_FEC_REQUEST_KR | 157162306a36Sopenharmony_ci I40E_AQ_SET_FEC_ABILITY_KR)) 157262306a36Sopenharmony_ci fecparam->fec |= ETHTOOL_FEC_BASER; 157362306a36Sopenharmony_ci if (fec_cfg == 0) 157462306a36Sopenharmony_ci fecparam->fec |= ETHTOOL_FEC_OFF; 157562306a36Sopenharmony_ci 157662306a36Sopenharmony_ci if (hw->phy.link_info.fec_info & I40E_AQ_CONFIG_FEC_KR_ENA) 157762306a36Sopenharmony_ci fecparam->active_fec = ETHTOOL_FEC_BASER; 157862306a36Sopenharmony_ci else if (hw->phy.link_info.fec_info & I40E_AQ_CONFIG_FEC_RS_ENA) 157962306a36Sopenharmony_ci fecparam->active_fec = ETHTOOL_FEC_RS; 158062306a36Sopenharmony_ci else 158162306a36Sopenharmony_ci fecparam->active_fec = ETHTOOL_FEC_OFF; 158262306a36Sopenharmony_cidone: 158362306a36Sopenharmony_ci return err; 158462306a36Sopenharmony_ci} 158562306a36Sopenharmony_ci 158662306a36Sopenharmony_cistatic int i40e_set_fec_param(struct net_device *netdev, 158762306a36Sopenharmony_ci struct ethtool_fecparam *fecparam) 158862306a36Sopenharmony_ci{ 158962306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 159062306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 159162306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 159262306a36Sopenharmony_ci u8 fec_cfg = 0; 159362306a36Sopenharmony_ci 159462306a36Sopenharmony_ci if (hw->device_id != I40E_DEV_ID_25G_SFP28 && 159562306a36Sopenharmony_ci hw->device_id != I40E_DEV_ID_25G_B && 159662306a36Sopenharmony_ci hw->device_id != I40E_DEV_ID_KX_X722) 159762306a36Sopenharmony_ci return -EPERM; 159862306a36Sopenharmony_ci 159962306a36Sopenharmony_ci if (hw->mac.type == I40E_MAC_X722 && 160062306a36Sopenharmony_ci !(hw->flags & I40E_HW_FLAG_X722_FEC_REQUEST_CAPABLE)) { 160162306a36Sopenharmony_ci netdev_err(netdev, "Setting FEC encoding not supported by firmware. Please update the NVM image.\n"); 160262306a36Sopenharmony_ci return -EOPNOTSUPP; 160362306a36Sopenharmony_ci } 160462306a36Sopenharmony_ci 160562306a36Sopenharmony_ci switch (fecparam->fec) { 160662306a36Sopenharmony_ci case ETHTOOL_FEC_AUTO: 160762306a36Sopenharmony_ci fec_cfg = I40E_AQ_SET_FEC_AUTO; 160862306a36Sopenharmony_ci break; 160962306a36Sopenharmony_ci case ETHTOOL_FEC_RS: 161062306a36Sopenharmony_ci fec_cfg = (I40E_AQ_SET_FEC_REQUEST_RS | 161162306a36Sopenharmony_ci I40E_AQ_SET_FEC_ABILITY_RS); 161262306a36Sopenharmony_ci break; 161362306a36Sopenharmony_ci case ETHTOOL_FEC_BASER: 161462306a36Sopenharmony_ci fec_cfg = (I40E_AQ_SET_FEC_REQUEST_KR | 161562306a36Sopenharmony_ci I40E_AQ_SET_FEC_ABILITY_KR); 161662306a36Sopenharmony_ci break; 161762306a36Sopenharmony_ci case ETHTOOL_FEC_OFF: 161862306a36Sopenharmony_ci case ETHTOOL_FEC_NONE: 161962306a36Sopenharmony_ci fec_cfg = 0; 162062306a36Sopenharmony_ci break; 162162306a36Sopenharmony_ci default: 162262306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, "Unsupported FEC mode: %d", 162362306a36Sopenharmony_ci fecparam->fec); 162462306a36Sopenharmony_ci return -EINVAL; 162562306a36Sopenharmony_ci } 162662306a36Sopenharmony_ci 162762306a36Sopenharmony_ci return i40e_set_fec_cfg(netdev, fec_cfg); 162862306a36Sopenharmony_ci} 162962306a36Sopenharmony_ci 163062306a36Sopenharmony_cistatic int i40e_nway_reset(struct net_device *netdev) 163162306a36Sopenharmony_ci{ 163262306a36Sopenharmony_ci /* restart autonegotiation */ 163362306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 163462306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 163562306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 163662306a36Sopenharmony_ci bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP; 163762306a36Sopenharmony_ci int ret = 0; 163862306a36Sopenharmony_ci 163962306a36Sopenharmony_ci ret = i40e_aq_set_link_restart_an(hw, link_up, NULL); 164062306a36Sopenharmony_ci if (ret) { 164162306a36Sopenharmony_ci netdev_info(netdev, "link restart failed, err %pe aq_err %s\n", 164262306a36Sopenharmony_ci ERR_PTR(ret), 164362306a36Sopenharmony_ci i40e_aq_str(hw, hw->aq.asq_last_status)); 164462306a36Sopenharmony_ci return -EIO; 164562306a36Sopenharmony_ci } 164662306a36Sopenharmony_ci 164762306a36Sopenharmony_ci return 0; 164862306a36Sopenharmony_ci} 164962306a36Sopenharmony_ci 165062306a36Sopenharmony_ci/** 165162306a36Sopenharmony_ci * i40e_get_pauseparam - Get Flow Control status 165262306a36Sopenharmony_ci * @netdev: netdevice structure 165362306a36Sopenharmony_ci * @pause: buffer to return pause parameters 165462306a36Sopenharmony_ci * 165562306a36Sopenharmony_ci * Return tx/rx-pause status 165662306a36Sopenharmony_ci **/ 165762306a36Sopenharmony_cistatic void i40e_get_pauseparam(struct net_device *netdev, 165862306a36Sopenharmony_ci struct ethtool_pauseparam *pause) 165962306a36Sopenharmony_ci{ 166062306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 166162306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 166262306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 166362306a36Sopenharmony_ci struct i40e_link_status *hw_link_info = &hw->phy.link_info; 166462306a36Sopenharmony_ci struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config; 166562306a36Sopenharmony_ci 166662306a36Sopenharmony_ci pause->autoneg = 166762306a36Sopenharmony_ci ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? 166862306a36Sopenharmony_ci AUTONEG_ENABLE : AUTONEG_DISABLE); 166962306a36Sopenharmony_ci 167062306a36Sopenharmony_ci /* PFC enabled so report LFC as off */ 167162306a36Sopenharmony_ci if (dcbx_cfg->pfc.pfcenable) { 167262306a36Sopenharmony_ci pause->rx_pause = 0; 167362306a36Sopenharmony_ci pause->tx_pause = 0; 167462306a36Sopenharmony_ci return; 167562306a36Sopenharmony_ci } 167662306a36Sopenharmony_ci 167762306a36Sopenharmony_ci if (hw->fc.current_mode == I40E_FC_RX_PAUSE) { 167862306a36Sopenharmony_ci pause->rx_pause = 1; 167962306a36Sopenharmony_ci } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) { 168062306a36Sopenharmony_ci pause->tx_pause = 1; 168162306a36Sopenharmony_ci } else if (hw->fc.current_mode == I40E_FC_FULL) { 168262306a36Sopenharmony_ci pause->rx_pause = 1; 168362306a36Sopenharmony_ci pause->tx_pause = 1; 168462306a36Sopenharmony_ci } 168562306a36Sopenharmony_ci} 168662306a36Sopenharmony_ci 168762306a36Sopenharmony_ci/** 168862306a36Sopenharmony_ci * i40e_set_pauseparam - Set Flow Control parameter 168962306a36Sopenharmony_ci * @netdev: network interface device structure 169062306a36Sopenharmony_ci * @pause: return tx/rx flow control status 169162306a36Sopenharmony_ci **/ 169262306a36Sopenharmony_cistatic int i40e_set_pauseparam(struct net_device *netdev, 169362306a36Sopenharmony_ci struct ethtool_pauseparam *pause) 169462306a36Sopenharmony_ci{ 169562306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 169662306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 169762306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 169862306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 169962306a36Sopenharmony_ci struct i40e_link_status *hw_link_info = &hw->phy.link_info; 170062306a36Sopenharmony_ci struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config; 170162306a36Sopenharmony_ci bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP; 170262306a36Sopenharmony_ci u8 aq_failures; 170362306a36Sopenharmony_ci int err = 0; 170462306a36Sopenharmony_ci int status; 170562306a36Sopenharmony_ci u32 is_an; 170662306a36Sopenharmony_ci 170762306a36Sopenharmony_ci /* Changing the port's flow control is not supported if this isn't the 170862306a36Sopenharmony_ci * port's controlling PF 170962306a36Sopenharmony_ci */ 171062306a36Sopenharmony_ci if (hw->partition_id != 1) { 171162306a36Sopenharmony_ci i40e_partition_setting_complaint(pf); 171262306a36Sopenharmony_ci return -EOPNOTSUPP; 171362306a36Sopenharmony_ci } 171462306a36Sopenharmony_ci 171562306a36Sopenharmony_ci if (vsi != pf->vsi[pf->lan_vsi]) 171662306a36Sopenharmony_ci return -EOPNOTSUPP; 171762306a36Sopenharmony_ci 171862306a36Sopenharmony_ci is_an = hw_link_info->an_info & I40E_AQ_AN_COMPLETED; 171962306a36Sopenharmony_ci if (pause->autoneg != is_an) { 172062306a36Sopenharmony_ci netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n"); 172162306a36Sopenharmony_ci return -EOPNOTSUPP; 172262306a36Sopenharmony_ci } 172362306a36Sopenharmony_ci 172462306a36Sopenharmony_ci /* If we have link and don't have autoneg */ 172562306a36Sopenharmony_ci if (!test_bit(__I40E_DOWN, pf->state) && !is_an) { 172662306a36Sopenharmony_ci /* Send message that it might not necessarily work*/ 172762306a36Sopenharmony_ci netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n"); 172862306a36Sopenharmony_ci } 172962306a36Sopenharmony_ci 173062306a36Sopenharmony_ci if (dcbx_cfg->pfc.pfcenable) { 173162306a36Sopenharmony_ci netdev_info(netdev, 173262306a36Sopenharmony_ci "Priority flow control enabled. Cannot set link flow control.\n"); 173362306a36Sopenharmony_ci return -EOPNOTSUPP; 173462306a36Sopenharmony_ci } 173562306a36Sopenharmony_ci 173662306a36Sopenharmony_ci if (pause->rx_pause && pause->tx_pause) 173762306a36Sopenharmony_ci hw->fc.requested_mode = I40E_FC_FULL; 173862306a36Sopenharmony_ci else if (pause->rx_pause && !pause->tx_pause) 173962306a36Sopenharmony_ci hw->fc.requested_mode = I40E_FC_RX_PAUSE; 174062306a36Sopenharmony_ci else if (!pause->rx_pause && pause->tx_pause) 174162306a36Sopenharmony_ci hw->fc.requested_mode = I40E_FC_TX_PAUSE; 174262306a36Sopenharmony_ci else if (!pause->rx_pause && !pause->tx_pause) 174362306a36Sopenharmony_ci hw->fc.requested_mode = I40E_FC_NONE; 174462306a36Sopenharmony_ci else 174562306a36Sopenharmony_ci return -EINVAL; 174662306a36Sopenharmony_ci 174762306a36Sopenharmony_ci /* Tell the OS link is going down, the link will go back up when fw 174862306a36Sopenharmony_ci * says it is ready asynchronously 174962306a36Sopenharmony_ci */ 175062306a36Sopenharmony_ci i40e_print_link_message(vsi, false); 175162306a36Sopenharmony_ci netif_carrier_off(netdev); 175262306a36Sopenharmony_ci netif_tx_stop_all_queues(netdev); 175362306a36Sopenharmony_ci 175462306a36Sopenharmony_ci /* Set the fc mode and only restart an if link is up*/ 175562306a36Sopenharmony_ci status = i40e_set_fc(hw, &aq_failures, link_up); 175662306a36Sopenharmony_ci 175762306a36Sopenharmony_ci if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) { 175862306a36Sopenharmony_ci netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %pe aq_err %s\n", 175962306a36Sopenharmony_ci ERR_PTR(status), 176062306a36Sopenharmony_ci i40e_aq_str(hw, hw->aq.asq_last_status)); 176162306a36Sopenharmony_ci err = -EAGAIN; 176262306a36Sopenharmony_ci } 176362306a36Sopenharmony_ci if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) { 176462306a36Sopenharmony_ci netdev_info(netdev, "Set fc failed on the set_phy_config call with err %pe aq_err %s\n", 176562306a36Sopenharmony_ci ERR_PTR(status), 176662306a36Sopenharmony_ci i40e_aq_str(hw, hw->aq.asq_last_status)); 176762306a36Sopenharmony_ci err = -EAGAIN; 176862306a36Sopenharmony_ci } 176962306a36Sopenharmony_ci if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) { 177062306a36Sopenharmony_ci netdev_info(netdev, "Set fc failed on the get_link_info call with err %pe aq_err %s\n", 177162306a36Sopenharmony_ci ERR_PTR(status), 177262306a36Sopenharmony_ci i40e_aq_str(hw, hw->aq.asq_last_status)); 177362306a36Sopenharmony_ci err = -EAGAIN; 177462306a36Sopenharmony_ci } 177562306a36Sopenharmony_ci 177662306a36Sopenharmony_ci if (!test_bit(__I40E_DOWN, pf->state) && is_an) { 177762306a36Sopenharmony_ci /* Give it a little more time to try to come back */ 177862306a36Sopenharmony_ci msleep(75); 177962306a36Sopenharmony_ci if (!test_bit(__I40E_DOWN, pf->state)) 178062306a36Sopenharmony_ci return i40e_nway_reset(netdev); 178162306a36Sopenharmony_ci } 178262306a36Sopenharmony_ci 178362306a36Sopenharmony_ci return err; 178462306a36Sopenharmony_ci} 178562306a36Sopenharmony_ci 178662306a36Sopenharmony_cistatic u32 i40e_get_msglevel(struct net_device *netdev) 178762306a36Sopenharmony_ci{ 178862306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 178962306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 179062306a36Sopenharmony_ci u32 debug_mask = pf->hw.debug_mask; 179162306a36Sopenharmony_ci 179262306a36Sopenharmony_ci if (debug_mask) 179362306a36Sopenharmony_ci netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask); 179462306a36Sopenharmony_ci 179562306a36Sopenharmony_ci return pf->msg_enable; 179662306a36Sopenharmony_ci} 179762306a36Sopenharmony_ci 179862306a36Sopenharmony_cistatic void i40e_set_msglevel(struct net_device *netdev, u32 data) 179962306a36Sopenharmony_ci{ 180062306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 180162306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 180262306a36Sopenharmony_ci 180362306a36Sopenharmony_ci if (I40E_DEBUG_USER & data) 180462306a36Sopenharmony_ci pf->hw.debug_mask = data; 180562306a36Sopenharmony_ci else 180662306a36Sopenharmony_ci pf->msg_enable = data; 180762306a36Sopenharmony_ci} 180862306a36Sopenharmony_ci 180962306a36Sopenharmony_cistatic int i40e_get_regs_len(struct net_device *netdev) 181062306a36Sopenharmony_ci{ 181162306a36Sopenharmony_ci int reg_count = 0; 181262306a36Sopenharmony_ci int i; 181362306a36Sopenharmony_ci 181462306a36Sopenharmony_ci for (i = 0; i40e_reg_list[i].offset != 0; i++) 181562306a36Sopenharmony_ci reg_count += i40e_reg_list[i].elements; 181662306a36Sopenharmony_ci 181762306a36Sopenharmony_ci return reg_count * sizeof(u32); 181862306a36Sopenharmony_ci} 181962306a36Sopenharmony_ci 182062306a36Sopenharmony_cistatic void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs, 182162306a36Sopenharmony_ci void *p) 182262306a36Sopenharmony_ci{ 182362306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 182462306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 182562306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 182662306a36Sopenharmony_ci u32 *reg_buf = p; 182762306a36Sopenharmony_ci unsigned int i, j, ri; 182862306a36Sopenharmony_ci u32 reg; 182962306a36Sopenharmony_ci 183062306a36Sopenharmony_ci /* Tell ethtool which driver-version-specific regs output we have. 183162306a36Sopenharmony_ci * 183262306a36Sopenharmony_ci * At some point, if we have ethtool doing special formatting of 183362306a36Sopenharmony_ci * this data, it will rely on this version number to know how to 183462306a36Sopenharmony_ci * interpret things. Hence, this needs to be updated if/when the 183562306a36Sopenharmony_ci * diags register table is changed. 183662306a36Sopenharmony_ci */ 183762306a36Sopenharmony_ci regs->version = 1; 183862306a36Sopenharmony_ci 183962306a36Sopenharmony_ci /* loop through the diags reg table for what to print */ 184062306a36Sopenharmony_ci ri = 0; 184162306a36Sopenharmony_ci for (i = 0; i40e_reg_list[i].offset != 0; i++) { 184262306a36Sopenharmony_ci for (j = 0; j < i40e_reg_list[i].elements; j++) { 184362306a36Sopenharmony_ci reg = i40e_reg_list[i].offset 184462306a36Sopenharmony_ci + (j * i40e_reg_list[i].stride); 184562306a36Sopenharmony_ci reg_buf[ri++] = rd32(hw, reg); 184662306a36Sopenharmony_ci } 184762306a36Sopenharmony_ci } 184862306a36Sopenharmony_ci 184962306a36Sopenharmony_ci} 185062306a36Sopenharmony_ci 185162306a36Sopenharmony_cistatic int i40e_get_eeprom(struct net_device *netdev, 185262306a36Sopenharmony_ci struct ethtool_eeprom *eeprom, u8 *bytes) 185362306a36Sopenharmony_ci{ 185462306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 185562306a36Sopenharmony_ci struct i40e_hw *hw = &np->vsi->back->hw; 185662306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 185762306a36Sopenharmony_ci int ret_val = 0, len, offset; 185862306a36Sopenharmony_ci u8 *eeprom_buff; 185962306a36Sopenharmony_ci u16 i, sectors; 186062306a36Sopenharmony_ci bool last; 186162306a36Sopenharmony_ci u32 magic; 186262306a36Sopenharmony_ci 186362306a36Sopenharmony_ci#define I40E_NVM_SECTOR_SIZE 4096 186462306a36Sopenharmony_ci if (eeprom->len == 0) 186562306a36Sopenharmony_ci return -EINVAL; 186662306a36Sopenharmony_ci 186762306a36Sopenharmony_ci /* check for NVMUpdate access method */ 186862306a36Sopenharmony_ci magic = hw->vendor_id | (hw->device_id << 16); 186962306a36Sopenharmony_ci if (eeprom->magic && eeprom->magic != magic) { 187062306a36Sopenharmony_ci struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom; 187162306a36Sopenharmony_ci int errno = 0; 187262306a36Sopenharmony_ci 187362306a36Sopenharmony_ci /* make sure it is the right magic for NVMUpdate */ 187462306a36Sopenharmony_ci if ((eeprom->magic >> 16) != hw->device_id) 187562306a36Sopenharmony_ci errno = -EINVAL; 187662306a36Sopenharmony_ci else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) || 187762306a36Sopenharmony_ci test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) 187862306a36Sopenharmony_ci errno = -EBUSY; 187962306a36Sopenharmony_ci else 188062306a36Sopenharmony_ci ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno); 188162306a36Sopenharmony_ci 188262306a36Sopenharmony_ci if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM)) 188362306a36Sopenharmony_ci dev_info(&pf->pdev->dev, 188462306a36Sopenharmony_ci "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n", 188562306a36Sopenharmony_ci ret_val, hw->aq.asq_last_status, errno, 188662306a36Sopenharmony_ci (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK), 188762306a36Sopenharmony_ci cmd->offset, cmd->data_size); 188862306a36Sopenharmony_ci 188962306a36Sopenharmony_ci return errno; 189062306a36Sopenharmony_ci } 189162306a36Sopenharmony_ci 189262306a36Sopenharmony_ci /* normal ethtool get_eeprom support */ 189362306a36Sopenharmony_ci eeprom->magic = hw->vendor_id | (hw->device_id << 16); 189462306a36Sopenharmony_ci 189562306a36Sopenharmony_ci eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL); 189662306a36Sopenharmony_ci if (!eeprom_buff) 189762306a36Sopenharmony_ci return -ENOMEM; 189862306a36Sopenharmony_ci 189962306a36Sopenharmony_ci ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ); 190062306a36Sopenharmony_ci if (ret_val) { 190162306a36Sopenharmony_ci dev_info(&pf->pdev->dev, 190262306a36Sopenharmony_ci "Failed Acquiring NVM resource for read err=%d status=0x%x\n", 190362306a36Sopenharmony_ci ret_val, hw->aq.asq_last_status); 190462306a36Sopenharmony_ci goto free_buff; 190562306a36Sopenharmony_ci } 190662306a36Sopenharmony_ci 190762306a36Sopenharmony_ci sectors = eeprom->len / I40E_NVM_SECTOR_SIZE; 190862306a36Sopenharmony_ci sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0; 190962306a36Sopenharmony_ci len = I40E_NVM_SECTOR_SIZE; 191062306a36Sopenharmony_ci last = false; 191162306a36Sopenharmony_ci for (i = 0; i < sectors; i++) { 191262306a36Sopenharmony_ci if (i == (sectors - 1)) { 191362306a36Sopenharmony_ci len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i); 191462306a36Sopenharmony_ci last = true; 191562306a36Sopenharmony_ci } 191662306a36Sopenharmony_ci offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i), 191762306a36Sopenharmony_ci ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len, 191862306a36Sopenharmony_ci (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i), 191962306a36Sopenharmony_ci last, NULL); 192062306a36Sopenharmony_ci if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) { 192162306a36Sopenharmony_ci dev_info(&pf->pdev->dev, 192262306a36Sopenharmony_ci "read NVM failed, invalid offset 0x%x\n", 192362306a36Sopenharmony_ci offset); 192462306a36Sopenharmony_ci break; 192562306a36Sopenharmony_ci } else if (ret_val && 192662306a36Sopenharmony_ci hw->aq.asq_last_status == I40E_AQ_RC_EACCES) { 192762306a36Sopenharmony_ci dev_info(&pf->pdev->dev, 192862306a36Sopenharmony_ci "read NVM failed, access, offset 0x%x\n", 192962306a36Sopenharmony_ci offset); 193062306a36Sopenharmony_ci break; 193162306a36Sopenharmony_ci } else if (ret_val) { 193262306a36Sopenharmony_ci dev_info(&pf->pdev->dev, 193362306a36Sopenharmony_ci "read NVM failed offset %d err=%d status=0x%x\n", 193462306a36Sopenharmony_ci offset, ret_val, hw->aq.asq_last_status); 193562306a36Sopenharmony_ci break; 193662306a36Sopenharmony_ci } 193762306a36Sopenharmony_ci } 193862306a36Sopenharmony_ci 193962306a36Sopenharmony_ci i40e_release_nvm(hw); 194062306a36Sopenharmony_ci memcpy(bytes, (u8 *)eeprom_buff, eeprom->len); 194162306a36Sopenharmony_cifree_buff: 194262306a36Sopenharmony_ci kfree(eeprom_buff); 194362306a36Sopenharmony_ci return ret_val; 194462306a36Sopenharmony_ci} 194562306a36Sopenharmony_ci 194662306a36Sopenharmony_cistatic int i40e_get_eeprom_len(struct net_device *netdev) 194762306a36Sopenharmony_ci{ 194862306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 194962306a36Sopenharmony_ci struct i40e_hw *hw = &np->vsi->back->hw; 195062306a36Sopenharmony_ci u32 val; 195162306a36Sopenharmony_ci 195262306a36Sopenharmony_ci#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF 195362306a36Sopenharmony_ci if (hw->mac.type == I40E_MAC_X722) { 195462306a36Sopenharmony_ci val = X722_EEPROM_SCOPE_LIMIT + 1; 195562306a36Sopenharmony_ci return val; 195662306a36Sopenharmony_ci } 195762306a36Sopenharmony_ci val = (rd32(hw, I40E_GLPCI_LBARCTRL) 195862306a36Sopenharmony_ci & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK) 195962306a36Sopenharmony_ci >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT; 196062306a36Sopenharmony_ci /* register returns value in power of 2, 64Kbyte chunks. */ 196162306a36Sopenharmony_ci val = (64 * 1024) * BIT(val); 196262306a36Sopenharmony_ci return val; 196362306a36Sopenharmony_ci} 196462306a36Sopenharmony_ci 196562306a36Sopenharmony_cistatic int i40e_set_eeprom(struct net_device *netdev, 196662306a36Sopenharmony_ci struct ethtool_eeprom *eeprom, u8 *bytes) 196762306a36Sopenharmony_ci{ 196862306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 196962306a36Sopenharmony_ci struct i40e_hw *hw = &np->vsi->back->hw; 197062306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 197162306a36Sopenharmony_ci struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom; 197262306a36Sopenharmony_ci int ret_val = 0; 197362306a36Sopenharmony_ci int errno = 0; 197462306a36Sopenharmony_ci u32 magic; 197562306a36Sopenharmony_ci 197662306a36Sopenharmony_ci /* normal ethtool set_eeprom is not supported */ 197762306a36Sopenharmony_ci magic = hw->vendor_id | (hw->device_id << 16); 197862306a36Sopenharmony_ci if (eeprom->magic == magic) 197962306a36Sopenharmony_ci errno = -EOPNOTSUPP; 198062306a36Sopenharmony_ci /* check for NVMUpdate access method */ 198162306a36Sopenharmony_ci else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id) 198262306a36Sopenharmony_ci errno = -EINVAL; 198362306a36Sopenharmony_ci else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) || 198462306a36Sopenharmony_ci test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) 198562306a36Sopenharmony_ci errno = -EBUSY; 198662306a36Sopenharmony_ci else 198762306a36Sopenharmony_ci ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno); 198862306a36Sopenharmony_ci 198962306a36Sopenharmony_ci if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM)) 199062306a36Sopenharmony_ci dev_info(&pf->pdev->dev, 199162306a36Sopenharmony_ci "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n", 199262306a36Sopenharmony_ci ret_val, hw->aq.asq_last_status, errno, 199362306a36Sopenharmony_ci (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK), 199462306a36Sopenharmony_ci cmd->offset, cmd->data_size); 199562306a36Sopenharmony_ci 199662306a36Sopenharmony_ci return errno; 199762306a36Sopenharmony_ci} 199862306a36Sopenharmony_ci 199962306a36Sopenharmony_cistatic void i40e_get_drvinfo(struct net_device *netdev, 200062306a36Sopenharmony_ci struct ethtool_drvinfo *drvinfo) 200162306a36Sopenharmony_ci{ 200262306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 200362306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 200462306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 200562306a36Sopenharmony_ci 200662306a36Sopenharmony_ci strscpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver)); 200762306a36Sopenharmony_ci strscpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw), 200862306a36Sopenharmony_ci sizeof(drvinfo->fw_version)); 200962306a36Sopenharmony_ci strscpy(drvinfo->bus_info, pci_name(pf->pdev), 201062306a36Sopenharmony_ci sizeof(drvinfo->bus_info)); 201162306a36Sopenharmony_ci drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN; 201262306a36Sopenharmony_ci if (pf->hw.pf_id == 0) 201362306a36Sopenharmony_ci drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN; 201462306a36Sopenharmony_ci} 201562306a36Sopenharmony_ci 201662306a36Sopenharmony_cistatic void i40e_get_ringparam(struct net_device *netdev, 201762306a36Sopenharmony_ci struct ethtool_ringparam *ring, 201862306a36Sopenharmony_ci struct kernel_ethtool_ringparam *kernel_ring, 201962306a36Sopenharmony_ci struct netlink_ext_ack *extack) 202062306a36Sopenharmony_ci{ 202162306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 202262306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 202362306a36Sopenharmony_ci struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; 202462306a36Sopenharmony_ci 202562306a36Sopenharmony_ci ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS; 202662306a36Sopenharmony_ci ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS; 202762306a36Sopenharmony_ci ring->rx_mini_max_pending = 0; 202862306a36Sopenharmony_ci ring->rx_jumbo_max_pending = 0; 202962306a36Sopenharmony_ci ring->rx_pending = vsi->rx_rings[0]->count; 203062306a36Sopenharmony_ci ring->tx_pending = vsi->tx_rings[0]->count; 203162306a36Sopenharmony_ci ring->rx_mini_pending = 0; 203262306a36Sopenharmony_ci ring->rx_jumbo_pending = 0; 203362306a36Sopenharmony_ci} 203462306a36Sopenharmony_ci 203562306a36Sopenharmony_cistatic bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index) 203662306a36Sopenharmony_ci{ 203762306a36Sopenharmony_ci if (i40e_enabled_xdp_vsi(vsi)) { 203862306a36Sopenharmony_ci return index < vsi->num_queue_pairs || 203962306a36Sopenharmony_ci (index >= vsi->alloc_queue_pairs && 204062306a36Sopenharmony_ci index < vsi->alloc_queue_pairs + vsi->num_queue_pairs); 204162306a36Sopenharmony_ci } 204262306a36Sopenharmony_ci 204362306a36Sopenharmony_ci return index < vsi->num_queue_pairs; 204462306a36Sopenharmony_ci} 204562306a36Sopenharmony_ci 204662306a36Sopenharmony_cistatic int i40e_set_ringparam(struct net_device *netdev, 204762306a36Sopenharmony_ci struct ethtool_ringparam *ring, 204862306a36Sopenharmony_ci struct kernel_ethtool_ringparam *kernel_ring, 204962306a36Sopenharmony_ci struct netlink_ext_ack *extack) 205062306a36Sopenharmony_ci{ 205162306a36Sopenharmony_ci struct i40e_ring *tx_rings = NULL, *rx_rings = NULL; 205262306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 205362306a36Sopenharmony_ci struct i40e_hw *hw = &np->vsi->back->hw; 205462306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 205562306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 205662306a36Sopenharmony_ci u32 new_rx_count, new_tx_count; 205762306a36Sopenharmony_ci u16 tx_alloc_queue_pairs; 205862306a36Sopenharmony_ci int timeout = 50; 205962306a36Sopenharmony_ci int i, err = 0; 206062306a36Sopenharmony_ci 206162306a36Sopenharmony_ci if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) 206262306a36Sopenharmony_ci return -EINVAL; 206362306a36Sopenharmony_ci 206462306a36Sopenharmony_ci if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS || 206562306a36Sopenharmony_ci ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS || 206662306a36Sopenharmony_ci ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS || 206762306a36Sopenharmony_ci ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) { 206862306a36Sopenharmony_ci netdev_info(netdev, 206962306a36Sopenharmony_ci "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n", 207062306a36Sopenharmony_ci ring->tx_pending, ring->rx_pending, 207162306a36Sopenharmony_ci I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS); 207262306a36Sopenharmony_ci return -EINVAL; 207362306a36Sopenharmony_ci } 207462306a36Sopenharmony_ci 207562306a36Sopenharmony_ci new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); 207662306a36Sopenharmony_ci new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); 207762306a36Sopenharmony_ci 207862306a36Sopenharmony_ci /* if nothing to do return success */ 207962306a36Sopenharmony_ci if ((new_tx_count == vsi->tx_rings[0]->count) && 208062306a36Sopenharmony_ci (new_rx_count == vsi->rx_rings[0]->count)) 208162306a36Sopenharmony_ci return 0; 208262306a36Sopenharmony_ci 208362306a36Sopenharmony_ci /* If there is a AF_XDP page pool attached to any of Rx rings, 208462306a36Sopenharmony_ci * disallow changing the number of descriptors -- regardless 208562306a36Sopenharmony_ci * if the netdev is running or not. 208662306a36Sopenharmony_ci */ 208762306a36Sopenharmony_ci if (i40e_xsk_any_rx_ring_enabled(vsi)) 208862306a36Sopenharmony_ci return -EBUSY; 208962306a36Sopenharmony_ci 209062306a36Sopenharmony_ci while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) { 209162306a36Sopenharmony_ci timeout--; 209262306a36Sopenharmony_ci if (!timeout) 209362306a36Sopenharmony_ci return -EBUSY; 209462306a36Sopenharmony_ci usleep_range(1000, 2000); 209562306a36Sopenharmony_ci } 209662306a36Sopenharmony_ci 209762306a36Sopenharmony_ci if (!netif_running(vsi->netdev)) { 209862306a36Sopenharmony_ci /* simple case - set for the next time the netdev is started */ 209962306a36Sopenharmony_ci for (i = 0; i < vsi->num_queue_pairs; i++) { 210062306a36Sopenharmony_ci vsi->tx_rings[i]->count = new_tx_count; 210162306a36Sopenharmony_ci vsi->rx_rings[i]->count = new_rx_count; 210262306a36Sopenharmony_ci if (i40e_enabled_xdp_vsi(vsi)) 210362306a36Sopenharmony_ci vsi->xdp_rings[i]->count = new_tx_count; 210462306a36Sopenharmony_ci } 210562306a36Sopenharmony_ci vsi->num_tx_desc = new_tx_count; 210662306a36Sopenharmony_ci vsi->num_rx_desc = new_rx_count; 210762306a36Sopenharmony_ci goto done; 210862306a36Sopenharmony_ci } 210962306a36Sopenharmony_ci 211062306a36Sopenharmony_ci /* We can't just free everything and then setup again, 211162306a36Sopenharmony_ci * because the ISRs in MSI-X mode get passed pointers 211262306a36Sopenharmony_ci * to the Tx and Rx ring structs. 211362306a36Sopenharmony_ci */ 211462306a36Sopenharmony_ci 211562306a36Sopenharmony_ci /* alloc updated Tx and XDP Tx resources */ 211662306a36Sopenharmony_ci tx_alloc_queue_pairs = vsi->alloc_queue_pairs * 211762306a36Sopenharmony_ci (i40e_enabled_xdp_vsi(vsi) ? 2 : 1); 211862306a36Sopenharmony_ci if (new_tx_count != vsi->tx_rings[0]->count) { 211962306a36Sopenharmony_ci netdev_info(netdev, 212062306a36Sopenharmony_ci "Changing Tx descriptor count from %d to %d.\n", 212162306a36Sopenharmony_ci vsi->tx_rings[0]->count, new_tx_count); 212262306a36Sopenharmony_ci tx_rings = kcalloc(tx_alloc_queue_pairs, 212362306a36Sopenharmony_ci sizeof(struct i40e_ring), GFP_KERNEL); 212462306a36Sopenharmony_ci if (!tx_rings) { 212562306a36Sopenharmony_ci err = -ENOMEM; 212662306a36Sopenharmony_ci goto done; 212762306a36Sopenharmony_ci } 212862306a36Sopenharmony_ci 212962306a36Sopenharmony_ci for (i = 0; i < tx_alloc_queue_pairs; i++) { 213062306a36Sopenharmony_ci if (!i40e_active_tx_ring_index(vsi, i)) 213162306a36Sopenharmony_ci continue; 213262306a36Sopenharmony_ci 213362306a36Sopenharmony_ci tx_rings[i] = *vsi->tx_rings[i]; 213462306a36Sopenharmony_ci tx_rings[i].count = new_tx_count; 213562306a36Sopenharmony_ci /* the desc and bi pointers will be reallocated in the 213662306a36Sopenharmony_ci * setup call 213762306a36Sopenharmony_ci */ 213862306a36Sopenharmony_ci tx_rings[i].desc = NULL; 213962306a36Sopenharmony_ci tx_rings[i].rx_bi = NULL; 214062306a36Sopenharmony_ci err = i40e_setup_tx_descriptors(&tx_rings[i]); 214162306a36Sopenharmony_ci if (err) { 214262306a36Sopenharmony_ci while (i) { 214362306a36Sopenharmony_ci i--; 214462306a36Sopenharmony_ci if (!i40e_active_tx_ring_index(vsi, i)) 214562306a36Sopenharmony_ci continue; 214662306a36Sopenharmony_ci i40e_free_tx_resources(&tx_rings[i]); 214762306a36Sopenharmony_ci } 214862306a36Sopenharmony_ci kfree(tx_rings); 214962306a36Sopenharmony_ci tx_rings = NULL; 215062306a36Sopenharmony_ci 215162306a36Sopenharmony_ci goto done; 215262306a36Sopenharmony_ci } 215362306a36Sopenharmony_ci } 215462306a36Sopenharmony_ci } 215562306a36Sopenharmony_ci 215662306a36Sopenharmony_ci /* alloc updated Rx resources */ 215762306a36Sopenharmony_ci if (new_rx_count != vsi->rx_rings[0]->count) { 215862306a36Sopenharmony_ci netdev_info(netdev, 215962306a36Sopenharmony_ci "Changing Rx descriptor count from %d to %d\n", 216062306a36Sopenharmony_ci vsi->rx_rings[0]->count, new_rx_count); 216162306a36Sopenharmony_ci rx_rings = kcalloc(vsi->alloc_queue_pairs, 216262306a36Sopenharmony_ci sizeof(struct i40e_ring), GFP_KERNEL); 216362306a36Sopenharmony_ci if (!rx_rings) { 216462306a36Sopenharmony_ci err = -ENOMEM; 216562306a36Sopenharmony_ci goto free_tx; 216662306a36Sopenharmony_ci } 216762306a36Sopenharmony_ci 216862306a36Sopenharmony_ci for (i = 0; i < vsi->num_queue_pairs; i++) { 216962306a36Sopenharmony_ci u16 unused; 217062306a36Sopenharmony_ci 217162306a36Sopenharmony_ci /* clone ring and setup updated count */ 217262306a36Sopenharmony_ci rx_rings[i] = *vsi->rx_rings[i]; 217362306a36Sopenharmony_ci rx_rings[i].count = new_rx_count; 217462306a36Sopenharmony_ci /* the desc and bi pointers will be reallocated in the 217562306a36Sopenharmony_ci * setup call 217662306a36Sopenharmony_ci */ 217762306a36Sopenharmony_ci rx_rings[i].desc = NULL; 217862306a36Sopenharmony_ci rx_rings[i].rx_bi = NULL; 217962306a36Sopenharmony_ci /* Clear cloned XDP RX-queue info before setup call */ 218062306a36Sopenharmony_ci memset(&rx_rings[i].xdp_rxq, 0, sizeof(rx_rings[i].xdp_rxq)); 218162306a36Sopenharmony_ci /* this is to allow wr32 to have something to write to 218262306a36Sopenharmony_ci * during early allocation of Rx buffers 218362306a36Sopenharmony_ci */ 218462306a36Sopenharmony_ci rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS; 218562306a36Sopenharmony_ci err = i40e_setup_rx_descriptors(&rx_rings[i]); 218662306a36Sopenharmony_ci if (err) 218762306a36Sopenharmony_ci goto rx_unwind; 218862306a36Sopenharmony_ci 218962306a36Sopenharmony_ci /* now allocate the Rx buffers to make sure the OS 219062306a36Sopenharmony_ci * has enough memory, any failure here means abort 219162306a36Sopenharmony_ci */ 219262306a36Sopenharmony_ci unused = I40E_DESC_UNUSED(&rx_rings[i]); 219362306a36Sopenharmony_ci err = i40e_alloc_rx_buffers(&rx_rings[i], unused); 219462306a36Sopenharmony_cirx_unwind: 219562306a36Sopenharmony_ci if (err) { 219662306a36Sopenharmony_ci do { 219762306a36Sopenharmony_ci i40e_free_rx_resources(&rx_rings[i]); 219862306a36Sopenharmony_ci } while (i--); 219962306a36Sopenharmony_ci kfree(rx_rings); 220062306a36Sopenharmony_ci rx_rings = NULL; 220162306a36Sopenharmony_ci 220262306a36Sopenharmony_ci goto free_tx; 220362306a36Sopenharmony_ci } 220462306a36Sopenharmony_ci } 220562306a36Sopenharmony_ci } 220662306a36Sopenharmony_ci 220762306a36Sopenharmony_ci /* Bring interface down, copy in the new ring info, 220862306a36Sopenharmony_ci * then restore the interface 220962306a36Sopenharmony_ci */ 221062306a36Sopenharmony_ci i40e_down(vsi); 221162306a36Sopenharmony_ci 221262306a36Sopenharmony_ci if (tx_rings) { 221362306a36Sopenharmony_ci for (i = 0; i < tx_alloc_queue_pairs; i++) { 221462306a36Sopenharmony_ci if (i40e_active_tx_ring_index(vsi, i)) { 221562306a36Sopenharmony_ci i40e_free_tx_resources(vsi->tx_rings[i]); 221662306a36Sopenharmony_ci *vsi->tx_rings[i] = tx_rings[i]; 221762306a36Sopenharmony_ci } 221862306a36Sopenharmony_ci } 221962306a36Sopenharmony_ci kfree(tx_rings); 222062306a36Sopenharmony_ci tx_rings = NULL; 222162306a36Sopenharmony_ci } 222262306a36Sopenharmony_ci 222362306a36Sopenharmony_ci if (rx_rings) { 222462306a36Sopenharmony_ci for (i = 0; i < vsi->num_queue_pairs; i++) { 222562306a36Sopenharmony_ci i40e_free_rx_resources(vsi->rx_rings[i]); 222662306a36Sopenharmony_ci /* get the real tail offset */ 222762306a36Sopenharmony_ci rx_rings[i].tail = vsi->rx_rings[i]->tail; 222862306a36Sopenharmony_ci /* this is to fake out the allocation routine 222962306a36Sopenharmony_ci * into thinking it has to realloc everything 223062306a36Sopenharmony_ci * but the recycling logic will let us re-use 223162306a36Sopenharmony_ci * the buffers allocated above 223262306a36Sopenharmony_ci */ 223362306a36Sopenharmony_ci rx_rings[i].next_to_use = 0; 223462306a36Sopenharmony_ci rx_rings[i].next_to_clean = 0; 223562306a36Sopenharmony_ci rx_rings[i].next_to_alloc = 0; 223662306a36Sopenharmony_ci /* do a struct copy */ 223762306a36Sopenharmony_ci *vsi->rx_rings[i] = rx_rings[i]; 223862306a36Sopenharmony_ci } 223962306a36Sopenharmony_ci kfree(rx_rings); 224062306a36Sopenharmony_ci rx_rings = NULL; 224162306a36Sopenharmony_ci } 224262306a36Sopenharmony_ci 224362306a36Sopenharmony_ci vsi->num_tx_desc = new_tx_count; 224462306a36Sopenharmony_ci vsi->num_rx_desc = new_rx_count; 224562306a36Sopenharmony_ci i40e_up(vsi); 224662306a36Sopenharmony_ci 224762306a36Sopenharmony_cifree_tx: 224862306a36Sopenharmony_ci /* error cleanup if the Rx allocations failed after getting Tx */ 224962306a36Sopenharmony_ci if (tx_rings) { 225062306a36Sopenharmony_ci for (i = 0; i < tx_alloc_queue_pairs; i++) { 225162306a36Sopenharmony_ci if (i40e_active_tx_ring_index(vsi, i)) 225262306a36Sopenharmony_ci i40e_free_tx_resources(vsi->tx_rings[i]); 225362306a36Sopenharmony_ci } 225462306a36Sopenharmony_ci kfree(tx_rings); 225562306a36Sopenharmony_ci tx_rings = NULL; 225662306a36Sopenharmony_ci } 225762306a36Sopenharmony_ci 225862306a36Sopenharmony_cidone: 225962306a36Sopenharmony_ci clear_bit(__I40E_CONFIG_BUSY, pf->state); 226062306a36Sopenharmony_ci 226162306a36Sopenharmony_ci return err; 226262306a36Sopenharmony_ci} 226362306a36Sopenharmony_ci 226462306a36Sopenharmony_ci/** 226562306a36Sopenharmony_ci * i40e_get_stats_count - return the stats count for a device 226662306a36Sopenharmony_ci * @netdev: the netdev to return the count for 226762306a36Sopenharmony_ci * 226862306a36Sopenharmony_ci * Returns the total number of statistics for this netdev. Note that even 226962306a36Sopenharmony_ci * though this is a function, it is required that the count for a specific 227062306a36Sopenharmony_ci * netdev must never change. Basing the count on static values such as the 227162306a36Sopenharmony_ci * maximum number of queues or the device type is ok. However, the API for 227262306a36Sopenharmony_ci * obtaining stats is *not* safe against changes based on non-static 227362306a36Sopenharmony_ci * values such as the *current* number of queues, or runtime flags. 227462306a36Sopenharmony_ci * 227562306a36Sopenharmony_ci * If a statistic is not always enabled, return it as part of the count 227662306a36Sopenharmony_ci * anyways, always return its string, and report its value as zero. 227762306a36Sopenharmony_ci **/ 227862306a36Sopenharmony_cistatic int i40e_get_stats_count(struct net_device *netdev) 227962306a36Sopenharmony_ci{ 228062306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 228162306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 228262306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 228362306a36Sopenharmony_ci int stats_len; 228462306a36Sopenharmony_ci 228562306a36Sopenharmony_ci if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) 228662306a36Sopenharmony_ci stats_len = I40E_PF_STATS_LEN; 228762306a36Sopenharmony_ci else 228862306a36Sopenharmony_ci stats_len = I40E_VSI_STATS_LEN; 228962306a36Sopenharmony_ci 229062306a36Sopenharmony_ci /* The number of stats reported for a given net_device must remain 229162306a36Sopenharmony_ci * constant throughout the life of that device. 229262306a36Sopenharmony_ci * 229362306a36Sopenharmony_ci * This is because the API for obtaining the size, strings, and stats 229462306a36Sopenharmony_ci * is spread out over three separate ethtool ioctls. There is no safe 229562306a36Sopenharmony_ci * way to lock the number of stats across these calls, so we must 229662306a36Sopenharmony_ci * assume that they will never change. 229762306a36Sopenharmony_ci * 229862306a36Sopenharmony_ci * Due to this, we report the maximum number of queues, even if not 229962306a36Sopenharmony_ci * every queue is currently configured. Since we always allocate 230062306a36Sopenharmony_ci * queues in pairs, we'll just use netdev->num_tx_queues * 2. This 230162306a36Sopenharmony_ci * works because the num_tx_queues is set at device creation and never 230262306a36Sopenharmony_ci * changes. 230362306a36Sopenharmony_ci */ 230462306a36Sopenharmony_ci stats_len += I40E_QUEUE_STATS_LEN * 2 * netdev->num_tx_queues; 230562306a36Sopenharmony_ci 230662306a36Sopenharmony_ci return stats_len; 230762306a36Sopenharmony_ci} 230862306a36Sopenharmony_ci 230962306a36Sopenharmony_cistatic int i40e_get_sset_count(struct net_device *netdev, int sset) 231062306a36Sopenharmony_ci{ 231162306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 231262306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 231362306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 231462306a36Sopenharmony_ci 231562306a36Sopenharmony_ci switch (sset) { 231662306a36Sopenharmony_ci case ETH_SS_TEST: 231762306a36Sopenharmony_ci return I40E_TEST_LEN; 231862306a36Sopenharmony_ci case ETH_SS_STATS: 231962306a36Sopenharmony_ci return i40e_get_stats_count(netdev); 232062306a36Sopenharmony_ci case ETH_SS_PRIV_FLAGS: 232162306a36Sopenharmony_ci return I40E_PRIV_FLAGS_STR_LEN + 232262306a36Sopenharmony_ci (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0); 232362306a36Sopenharmony_ci default: 232462306a36Sopenharmony_ci return -EOPNOTSUPP; 232562306a36Sopenharmony_ci } 232662306a36Sopenharmony_ci} 232762306a36Sopenharmony_ci 232862306a36Sopenharmony_ci/** 232962306a36Sopenharmony_ci * i40e_get_veb_tc_stats - copy VEB TC statistics to formatted structure 233062306a36Sopenharmony_ci * @tc: the TC statistics in VEB structure (veb->tc_stats) 233162306a36Sopenharmony_ci * @i: the index of traffic class in (veb->tc_stats) structure to copy 233262306a36Sopenharmony_ci * 233362306a36Sopenharmony_ci * Copy VEB TC statistics from structure of arrays (veb->tc_stats) to 233462306a36Sopenharmony_ci * one dimensional structure i40e_cp_veb_tc_stats. 233562306a36Sopenharmony_ci * Produce formatted i40e_cp_veb_tc_stats structure of the VEB TC 233662306a36Sopenharmony_ci * statistics for the given TC. 233762306a36Sopenharmony_ci **/ 233862306a36Sopenharmony_cistatic struct i40e_cp_veb_tc_stats 233962306a36Sopenharmony_cii40e_get_veb_tc_stats(struct i40e_veb_tc_stats *tc, unsigned int i) 234062306a36Sopenharmony_ci{ 234162306a36Sopenharmony_ci struct i40e_cp_veb_tc_stats veb_tc = { 234262306a36Sopenharmony_ci .tc_rx_packets = tc->tc_rx_packets[i], 234362306a36Sopenharmony_ci .tc_rx_bytes = tc->tc_rx_bytes[i], 234462306a36Sopenharmony_ci .tc_tx_packets = tc->tc_tx_packets[i], 234562306a36Sopenharmony_ci .tc_tx_bytes = tc->tc_tx_bytes[i], 234662306a36Sopenharmony_ci }; 234762306a36Sopenharmony_ci 234862306a36Sopenharmony_ci return veb_tc; 234962306a36Sopenharmony_ci} 235062306a36Sopenharmony_ci 235162306a36Sopenharmony_ci/** 235262306a36Sopenharmony_ci * i40e_get_pfc_stats - copy HW PFC statistics to formatted structure 235362306a36Sopenharmony_ci * @pf: the PF device structure 235462306a36Sopenharmony_ci * @i: the priority value to copy 235562306a36Sopenharmony_ci * 235662306a36Sopenharmony_ci * The PFC stats are found as arrays in pf->stats, which is not easy to pass 235762306a36Sopenharmony_ci * into i40e_add_ethtool_stats. Produce a formatted i40e_pfc_stats structure 235862306a36Sopenharmony_ci * of the PFC stats for the given priority. 235962306a36Sopenharmony_ci **/ 236062306a36Sopenharmony_cistatic inline struct i40e_pfc_stats 236162306a36Sopenharmony_cii40e_get_pfc_stats(struct i40e_pf *pf, unsigned int i) 236262306a36Sopenharmony_ci{ 236362306a36Sopenharmony_ci#define I40E_GET_PFC_STAT(stat, priority) \ 236462306a36Sopenharmony_ci .stat = pf->stats.stat[priority] 236562306a36Sopenharmony_ci 236662306a36Sopenharmony_ci struct i40e_pfc_stats pfc = { 236762306a36Sopenharmony_ci I40E_GET_PFC_STAT(priority_xon_rx, i), 236862306a36Sopenharmony_ci I40E_GET_PFC_STAT(priority_xoff_rx, i), 236962306a36Sopenharmony_ci I40E_GET_PFC_STAT(priority_xon_tx, i), 237062306a36Sopenharmony_ci I40E_GET_PFC_STAT(priority_xoff_tx, i), 237162306a36Sopenharmony_ci I40E_GET_PFC_STAT(priority_xon_2_xoff, i), 237262306a36Sopenharmony_ci }; 237362306a36Sopenharmony_ci return pfc; 237462306a36Sopenharmony_ci} 237562306a36Sopenharmony_ci 237662306a36Sopenharmony_ci/** 237762306a36Sopenharmony_ci * i40e_get_ethtool_stats - copy stat values into supplied buffer 237862306a36Sopenharmony_ci * @netdev: the netdev to collect stats for 237962306a36Sopenharmony_ci * @stats: ethtool stats command structure 238062306a36Sopenharmony_ci * @data: ethtool supplied buffer 238162306a36Sopenharmony_ci * 238262306a36Sopenharmony_ci * Copy the stats values for this netdev into the buffer. Expects data to be 238362306a36Sopenharmony_ci * pre-allocated to the size returned by i40e_get_stats_count.. Note that all 238462306a36Sopenharmony_ci * statistics must be copied in a static order, and the count must not change 238562306a36Sopenharmony_ci * for a given netdev. See i40e_get_stats_count for more details. 238662306a36Sopenharmony_ci * 238762306a36Sopenharmony_ci * If a statistic is not currently valid (such as a disabled queue), this 238862306a36Sopenharmony_ci * function reports its value as zero. 238962306a36Sopenharmony_ci **/ 239062306a36Sopenharmony_cistatic void i40e_get_ethtool_stats(struct net_device *netdev, 239162306a36Sopenharmony_ci struct ethtool_stats *stats, u64 *data) 239262306a36Sopenharmony_ci{ 239362306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 239462306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 239562306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 239662306a36Sopenharmony_ci struct i40e_veb *veb = NULL; 239762306a36Sopenharmony_ci unsigned int i; 239862306a36Sopenharmony_ci bool veb_stats; 239962306a36Sopenharmony_ci u64 *p = data; 240062306a36Sopenharmony_ci 240162306a36Sopenharmony_ci i40e_update_stats(vsi); 240262306a36Sopenharmony_ci 240362306a36Sopenharmony_ci i40e_add_ethtool_stats(&data, i40e_get_vsi_stats_struct(vsi), 240462306a36Sopenharmony_ci i40e_gstrings_net_stats); 240562306a36Sopenharmony_ci 240662306a36Sopenharmony_ci i40e_add_ethtool_stats(&data, vsi, i40e_gstrings_misc_stats); 240762306a36Sopenharmony_ci 240862306a36Sopenharmony_ci rcu_read_lock(); 240962306a36Sopenharmony_ci for (i = 0; i < netdev->num_tx_queues; i++) { 241062306a36Sopenharmony_ci i40e_add_queue_stats(&data, READ_ONCE(vsi->tx_rings[i])); 241162306a36Sopenharmony_ci i40e_add_queue_stats(&data, READ_ONCE(vsi->rx_rings[i])); 241262306a36Sopenharmony_ci } 241362306a36Sopenharmony_ci rcu_read_unlock(); 241462306a36Sopenharmony_ci 241562306a36Sopenharmony_ci if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1) 241662306a36Sopenharmony_ci goto check_data_pointer; 241762306a36Sopenharmony_ci 241862306a36Sopenharmony_ci veb_stats = ((pf->lan_veb != I40E_NO_VEB) && 241962306a36Sopenharmony_ci (pf->lan_veb < I40E_MAX_VEB) && 242062306a36Sopenharmony_ci (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)); 242162306a36Sopenharmony_ci 242262306a36Sopenharmony_ci if (veb_stats) { 242362306a36Sopenharmony_ci veb = pf->veb[pf->lan_veb]; 242462306a36Sopenharmony_ci i40e_update_veb_stats(veb); 242562306a36Sopenharmony_ci } 242662306a36Sopenharmony_ci 242762306a36Sopenharmony_ci /* If veb stats aren't enabled, pass NULL instead of the veb so that 242862306a36Sopenharmony_ci * we initialize stats to zero and update the data pointer 242962306a36Sopenharmony_ci * intelligently 243062306a36Sopenharmony_ci */ 243162306a36Sopenharmony_ci i40e_add_ethtool_stats(&data, veb_stats ? veb : NULL, 243262306a36Sopenharmony_ci i40e_gstrings_veb_stats); 243362306a36Sopenharmony_ci 243462306a36Sopenharmony_ci for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) 243562306a36Sopenharmony_ci if (veb_stats) { 243662306a36Sopenharmony_ci struct i40e_cp_veb_tc_stats veb_tc = 243762306a36Sopenharmony_ci i40e_get_veb_tc_stats(&veb->tc_stats, i); 243862306a36Sopenharmony_ci 243962306a36Sopenharmony_ci i40e_add_ethtool_stats(&data, &veb_tc, 244062306a36Sopenharmony_ci i40e_gstrings_veb_tc_stats); 244162306a36Sopenharmony_ci } else { 244262306a36Sopenharmony_ci i40e_add_ethtool_stats(&data, NULL, 244362306a36Sopenharmony_ci i40e_gstrings_veb_tc_stats); 244462306a36Sopenharmony_ci } 244562306a36Sopenharmony_ci 244662306a36Sopenharmony_ci i40e_add_ethtool_stats(&data, pf, i40e_gstrings_stats); 244762306a36Sopenharmony_ci 244862306a36Sopenharmony_ci for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { 244962306a36Sopenharmony_ci struct i40e_pfc_stats pfc = i40e_get_pfc_stats(pf, i); 245062306a36Sopenharmony_ci 245162306a36Sopenharmony_ci i40e_add_ethtool_stats(&data, &pfc, i40e_gstrings_pfc_stats); 245262306a36Sopenharmony_ci } 245362306a36Sopenharmony_ci 245462306a36Sopenharmony_cicheck_data_pointer: 245562306a36Sopenharmony_ci WARN_ONCE(data - p != i40e_get_stats_count(netdev), 245662306a36Sopenharmony_ci "ethtool stats count mismatch!"); 245762306a36Sopenharmony_ci} 245862306a36Sopenharmony_ci 245962306a36Sopenharmony_ci/** 246062306a36Sopenharmony_ci * i40e_get_stat_strings - copy stat strings into supplied buffer 246162306a36Sopenharmony_ci * @netdev: the netdev to collect strings for 246262306a36Sopenharmony_ci * @data: supplied buffer to copy strings into 246362306a36Sopenharmony_ci * 246462306a36Sopenharmony_ci * Copy the strings related to stats for this netdev. Expects data to be 246562306a36Sopenharmony_ci * pre-allocated with the size reported by i40e_get_stats_count. Note that the 246662306a36Sopenharmony_ci * strings must be copied in a static order and the total count must not 246762306a36Sopenharmony_ci * change for a given netdev. See i40e_get_stats_count for more details. 246862306a36Sopenharmony_ci **/ 246962306a36Sopenharmony_cistatic void i40e_get_stat_strings(struct net_device *netdev, u8 *data) 247062306a36Sopenharmony_ci{ 247162306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 247262306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 247362306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 247462306a36Sopenharmony_ci unsigned int i; 247562306a36Sopenharmony_ci u8 *p = data; 247662306a36Sopenharmony_ci 247762306a36Sopenharmony_ci i40e_add_stat_strings(&data, i40e_gstrings_net_stats); 247862306a36Sopenharmony_ci 247962306a36Sopenharmony_ci i40e_add_stat_strings(&data, i40e_gstrings_misc_stats); 248062306a36Sopenharmony_ci 248162306a36Sopenharmony_ci for (i = 0; i < netdev->num_tx_queues; i++) { 248262306a36Sopenharmony_ci i40e_add_stat_strings(&data, i40e_gstrings_queue_stats, 248362306a36Sopenharmony_ci "tx", i); 248462306a36Sopenharmony_ci i40e_add_stat_strings(&data, i40e_gstrings_queue_stats, 248562306a36Sopenharmony_ci "rx", i); 248662306a36Sopenharmony_ci } 248762306a36Sopenharmony_ci 248862306a36Sopenharmony_ci if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1) 248962306a36Sopenharmony_ci goto check_data_pointer; 249062306a36Sopenharmony_ci 249162306a36Sopenharmony_ci i40e_add_stat_strings(&data, i40e_gstrings_veb_stats); 249262306a36Sopenharmony_ci 249362306a36Sopenharmony_ci for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) 249462306a36Sopenharmony_ci i40e_add_stat_strings(&data, i40e_gstrings_veb_tc_stats, i); 249562306a36Sopenharmony_ci 249662306a36Sopenharmony_ci i40e_add_stat_strings(&data, i40e_gstrings_stats); 249762306a36Sopenharmony_ci 249862306a36Sopenharmony_ci for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) 249962306a36Sopenharmony_ci i40e_add_stat_strings(&data, i40e_gstrings_pfc_stats, i); 250062306a36Sopenharmony_ci 250162306a36Sopenharmony_cicheck_data_pointer: 250262306a36Sopenharmony_ci WARN_ONCE(data - p != i40e_get_stats_count(netdev) * ETH_GSTRING_LEN, 250362306a36Sopenharmony_ci "stat strings count mismatch!"); 250462306a36Sopenharmony_ci} 250562306a36Sopenharmony_ci 250662306a36Sopenharmony_cistatic void i40e_get_priv_flag_strings(struct net_device *netdev, u8 *data) 250762306a36Sopenharmony_ci{ 250862306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 250962306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 251062306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 251162306a36Sopenharmony_ci unsigned int i; 251262306a36Sopenharmony_ci u8 *p = data; 251362306a36Sopenharmony_ci 251462306a36Sopenharmony_ci for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) 251562306a36Sopenharmony_ci ethtool_sprintf(&p, i40e_gstrings_priv_flags[i].flag_string); 251662306a36Sopenharmony_ci if (pf->hw.pf_id != 0) 251762306a36Sopenharmony_ci return; 251862306a36Sopenharmony_ci for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) 251962306a36Sopenharmony_ci ethtool_sprintf(&p, i40e_gl_gstrings_priv_flags[i].flag_string); 252062306a36Sopenharmony_ci} 252162306a36Sopenharmony_ci 252262306a36Sopenharmony_cistatic void i40e_get_strings(struct net_device *netdev, u32 stringset, 252362306a36Sopenharmony_ci u8 *data) 252462306a36Sopenharmony_ci{ 252562306a36Sopenharmony_ci switch (stringset) { 252662306a36Sopenharmony_ci case ETH_SS_TEST: 252762306a36Sopenharmony_ci memcpy(data, i40e_gstrings_test, 252862306a36Sopenharmony_ci I40E_TEST_LEN * ETH_GSTRING_LEN); 252962306a36Sopenharmony_ci break; 253062306a36Sopenharmony_ci case ETH_SS_STATS: 253162306a36Sopenharmony_ci i40e_get_stat_strings(netdev, data); 253262306a36Sopenharmony_ci break; 253362306a36Sopenharmony_ci case ETH_SS_PRIV_FLAGS: 253462306a36Sopenharmony_ci i40e_get_priv_flag_strings(netdev, data); 253562306a36Sopenharmony_ci break; 253662306a36Sopenharmony_ci default: 253762306a36Sopenharmony_ci break; 253862306a36Sopenharmony_ci } 253962306a36Sopenharmony_ci} 254062306a36Sopenharmony_ci 254162306a36Sopenharmony_cistatic int i40e_get_ts_info(struct net_device *dev, 254262306a36Sopenharmony_ci struct ethtool_ts_info *info) 254362306a36Sopenharmony_ci{ 254462306a36Sopenharmony_ci struct i40e_pf *pf = i40e_netdev_to_pf(dev); 254562306a36Sopenharmony_ci 254662306a36Sopenharmony_ci /* only report HW timestamping if PTP is enabled */ 254762306a36Sopenharmony_ci if (!(pf->flags & I40E_FLAG_PTP)) 254862306a36Sopenharmony_ci return ethtool_op_get_ts_info(dev, info); 254962306a36Sopenharmony_ci 255062306a36Sopenharmony_ci info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | 255162306a36Sopenharmony_ci SOF_TIMESTAMPING_RX_SOFTWARE | 255262306a36Sopenharmony_ci SOF_TIMESTAMPING_SOFTWARE | 255362306a36Sopenharmony_ci SOF_TIMESTAMPING_TX_HARDWARE | 255462306a36Sopenharmony_ci SOF_TIMESTAMPING_RX_HARDWARE | 255562306a36Sopenharmony_ci SOF_TIMESTAMPING_RAW_HARDWARE; 255662306a36Sopenharmony_ci 255762306a36Sopenharmony_ci if (pf->ptp_clock) 255862306a36Sopenharmony_ci info->phc_index = ptp_clock_index(pf->ptp_clock); 255962306a36Sopenharmony_ci else 256062306a36Sopenharmony_ci info->phc_index = -1; 256162306a36Sopenharmony_ci 256262306a36Sopenharmony_ci info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON); 256362306a36Sopenharmony_ci 256462306a36Sopenharmony_ci info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | 256562306a36Sopenharmony_ci BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | 256662306a36Sopenharmony_ci BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) | 256762306a36Sopenharmony_ci BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ); 256862306a36Sopenharmony_ci 256962306a36Sopenharmony_ci if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE) 257062306a36Sopenharmony_ci info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | 257162306a36Sopenharmony_ci BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | 257262306a36Sopenharmony_ci BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) | 257362306a36Sopenharmony_ci BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) | 257462306a36Sopenharmony_ci BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) | 257562306a36Sopenharmony_ci BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) | 257662306a36Sopenharmony_ci BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) | 257762306a36Sopenharmony_ci BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ); 257862306a36Sopenharmony_ci 257962306a36Sopenharmony_ci return 0; 258062306a36Sopenharmony_ci} 258162306a36Sopenharmony_ci 258262306a36Sopenharmony_cistatic u64 i40e_link_test(struct net_device *netdev, u64 *data) 258362306a36Sopenharmony_ci{ 258462306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 258562306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 258662306a36Sopenharmony_ci bool link_up = false; 258762306a36Sopenharmony_ci int status; 258862306a36Sopenharmony_ci 258962306a36Sopenharmony_ci netif_info(pf, hw, netdev, "link test\n"); 259062306a36Sopenharmony_ci status = i40e_get_link_status(&pf->hw, &link_up); 259162306a36Sopenharmony_ci if (status) { 259262306a36Sopenharmony_ci netif_err(pf, drv, netdev, "link query timed out, please retry test\n"); 259362306a36Sopenharmony_ci *data = 1; 259462306a36Sopenharmony_ci return *data; 259562306a36Sopenharmony_ci } 259662306a36Sopenharmony_ci 259762306a36Sopenharmony_ci if (link_up) 259862306a36Sopenharmony_ci *data = 0; 259962306a36Sopenharmony_ci else 260062306a36Sopenharmony_ci *data = 1; 260162306a36Sopenharmony_ci 260262306a36Sopenharmony_ci return *data; 260362306a36Sopenharmony_ci} 260462306a36Sopenharmony_ci 260562306a36Sopenharmony_cistatic u64 i40e_reg_test(struct net_device *netdev, u64 *data) 260662306a36Sopenharmony_ci{ 260762306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 260862306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 260962306a36Sopenharmony_ci 261062306a36Sopenharmony_ci netif_info(pf, hw, netdev, "register test\n"); 261162306a36Sopenharmony_ci *data = i40e_diag_reg_test(&pf->hw); 261262306a36Sopenharmony_ci 261362306a36Sopenharmony_ci return *data; 261462306a36Sopenharmony_ci} 261562306a36Sopenharmony_ci 261662306a36Sopenharmony_cistatic u64 i40e_eeprom_test(struct net_device *netdev, u64 *data) 261762306a36Sopenharmony_ci{ 261862306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 261962306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 262062306a36Sopenharmony_ci 262162306a36Sopenharmony_ci netif_info(pf, hw, netdev, "eeprom test\n"); 262262306a36Sopenharmony_ci *data = i40e_diag_eeprom_test(&pf->hw); 262362306a36Sopenharmony_ci 262462306a36Sopenharmony_ci /* forcebly clear the NVM Update state machine */ 262562306a36Sopenharmony_ci pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT; 262662306a36Sopenharmony_ci 262762306a36Sopenharmony_ci return *data; 262862306a36Sopenharmony_ci} 262962306a36Sopenharmony_ci 263062306a36Sopenharmony_cistatic u64 i40e_intr_test(struct net_device *netdev, u64 *data) 263162306a36Sopenharmony_ci{ 263262306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 263362306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 263462306a36Sopenharmony_ci u16 swc_old = pf->sw_int_count; 263562306a36Sopenharmony_ci 263662306a36Sopenharmony_ci netif_info(pf, hw, netdev, "interrupt test\n"); 263762306a36Sopenharmony_ci wr32(&pf->hw, I40E_PFINT_DYN_CTL0, 263862306a36Sopenharmony_ci (I40E_PFINT_DYN_CTL0_INTENA_MASK | 263962306a36Sopenharmony_ci I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK | 264062306a36Sopenharmony_ci I40E_PFINT_DYN_CTL0_ITR_INDX_MASK | 264162306a36Sopenharmony_ci I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK | 264262306a36Sopenharmony_ci I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK)); 264362306a36Sopenharmony_ci usleep_range(1000, 2000); 264462306a36Sopenharmony_ci *data = (swc_old == pf->sw_int_count); 264562306a36Sopenharmony_ci 264662306a36Sopenharmony_ci return *data; 264762306a36Sopenharmony_ci} 264862306a36Sopenharmony_ci 264962306a36Sopenharmony_cistatic inline bool i40e_active_vfs(struct i40e_pf *pf) 265062306a36Sopenharmony_ci{ 265162306a36Sopenharmony_ci struct i40e_vf *vfs = pf->vf; 265262306a36Sopenharmony_ci int i; 265362306a36Sopenharmony_ci 265462306a36Sopenharmony_ci for (i = 0; i < pf->num_alloc_vfs; i++) 265562306a36Sopenharmony_ci if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states)) 265662306a36Sopenharmony_ci return true; 265762306a36Sopenharmony_ci return false; 265862306a36Sopenharmony_ci} 265962306a36Sopenharmony_ci 266062306a36Sopenharmony_cistatic inline bool i40e_active_vmdqs(struct i40e_pf *pf) 266162306a36Sopenharmony_ci{ 266262306a36Sopenharmony_ci return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2); 266362306a36Sopenharmony_ci} 266462306a36Sopenharmony_ci 266562306a36Sopenharmony_cistatic void i40e_diag_test(struct net_device *netdev, 266662306a36Sopenharmony_ci struct ethtool_test *eth_test, u64 *data) 266762306a36Sopenharmony_ci{ 266862306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 266962306a36Sopenharmony_ci bool if_running = netif_running(netdev); 267062306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 267162306a36Sopenharmony_ci 267262306a36Sopenharmony_ci if (eth_test->flags == ETH_TEST_FL_OFFLINE) { 267362306a36Sopenharmony_ci /* Offline tests */ 267462306a36Sopenharmony_ci netif_info(pf, drv, netdev, "offline testing starting\n"); 267562306a36Sopenharmony_ci 267662306a36Sopenharmony_ci set_bit(__I40E_TESTING, pf->state); 267762306a36Sopenharmony_ci 267862306a36Sopenharmony_ci if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) || 267962306a36Sopenharmony_ci test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) { 268062306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 268162306a36Sopenharmony_ci "Cannot start offline testing when PF is in reset state.\n"); 268262306a36Sopenharmony_ci goto skip_ol_tests; 268362306a36Sopenharmony_ci } 268462306a36Sopenharmony_ci 268562306a36Sopenharmony_ci if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) { 268662306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 268762306a36Sopenharmony_ci "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n"); 268862306a36Sopenharmony_ci goto skip_ol_tests; 268962306a36Sopenharmony_ci } 269062306a36Sopenharmony_ci 269162306a36Sopenharmony_ci /* If the device is online then take it offline */ 269262306a36Sopenharmony_ci if (if_running) 269362306a36Sopenharmony_ci /* indicate we're in test mode */ 269462306a36Sopenharmony_ci i40e_close(netdev); 269562306a36Sopenharmony_ci else 269662306a36Sopenharmony_ci /* This reset does not affect link - if it is 269762306a36Sopenharmony_ci * changed to a type of reset that does affect 269862306a36Sopenharmony_ci * link then the following link test would have 269962306a36Sopenharmony_ci * to be moved to before the reset 270062306a36Sopenharmony_ci */ 270162306a36Sopenharmony_ci i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true); 270262306a36Sopenharmony_ci 270362306a36Sopenharmony_ci if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) 270462306a36Sopenharmony_ci eth_test->flags |= ETH_TEST_FL_FAILED; 270562306a36Sopenharmony_ci 270662306a36Sopenharmony_ci if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM])) 270762306a36Sopenharmony_ci eth_test->flags |= ETH_TEST_FL_FAILED; 270862306a36Sopenharmony_ci 270962306a36Sopenharmony_ci if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR])) 271062306a36Sopenharmony_ci eth_test->flags |= ETH_TEST_FL_FAILED; 271162306a36Sopenharmony_ci 271262306a36Sopenharmony_ci /* run reg test last, a reset is required after it */ 271362306a36Sopenharmony_ci if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG])) 271462306a36Sopenharmony_ci eth_test->flags |= ETH_TEST_FL_FAILED; 271562306a36Sopenharmony_ci 271662306a36Sopenharmony_ci clear_bit(__I40E_TESTING, pf->state); 271762306a36Sopenharmony_ci i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true); 271862306a36Sopenharmony_ci 271962306a36Sopenharmony_ci if (if_running) 272062306a36Sopenharmony_ci i40e_open(netdev); 272162306a36Sopenharmony_ci } else { 272262306a36Sopenharmony_ci /* Online tests */ 272362306a36Sopenharmony_ci netif_info(pf, drv, netdev, "online testing starting\n"); 272462306a36Sopenharmony_ci 272562306a36Sopenharmony_ci if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) 272662306a36Sopenharmony_ci eth_test->flags |= ETH_TEST_FL_FAILED; 272762306a36Sopenharmony_ci 272862306a36Sopenharmony_ci /* Offline only tests, not run in online; pass by default */ 272962306a36Sopenharmony_ci data[I40E_ETH_TEST_REG] = 0; 273062306a36Sopenharmony_ci data[I40E_ETH_TEST_EEPROM] = 0; 273162306a36Sopenharmony_ci data[I40E_ETH_TEST_INTR] = 0; 273262306a36Sopenharmony_ci } 273362306a36Sopenharmony_ci 273462306a36Sopenharmony_ci netif_info(pf, drv, netdev, "testing finished\n"); 273562306a36Sopenharmony_ci return; 273662306a36Sopenharmony_ci 273762306a36Sopenharmony_ciskip_ol_tests: 273862306a36Sopenharmony_ci data[I40E_ETH_TEST_REG] = 1; 273962306a36Sopenharmony_ci data[I40E_ETH_TEST_EEPROM] = 1; 274062306a36Sopenharmony_ci data[I40E_ETH_TEST_INTR] = 1; 274162306a36Sopenharmony_ci data[I40E_ETH_TEST_LINK] = 1; 274262306a36Sopenharmony_ci eth_test->flags |= ETH_TEST_FL_FAILED; 274362306a36Sopenharmony_ci clear_bit(__I40E_TESTING, pf->state); 274462306a36Sopenharmony_ci netif_info(pf, drv, netdev, "testing failed\n"); 274562306a36Sopenharmony_ci} 274662306a36Sopenharmony_ci 274762306a36Sopenharmony_cistatic void i40e_get_wol(struct net_device *netdev, 274862306a36Sopenharmony_ci struct ethtool_wolinfo *wol) 274962306a36Sopenharmony_ci{ 275062306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 275162306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 275262306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 275362306a36Sopenharmony_ci u16 wol_nvm_bits; 275462306a36Sopenharmony_ci 275562306a36Sopenharmony_ci /* NVM bit on means WoL disabled for the port */ 275662306a36Sopenharmony_ci i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); 275762306a36Sopenharmony_ci if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) { 275862306a36Sopenharmony_ci wol->supported = 0; 275962306a36Sopenharmony_ci wol->wolopts = 0; 276062306a36Sopenharmony_ci } else { 276162306a36Sopenharmony_ci wol->supported = WAKE_MAGIC; 276262306a36Sopenharmony_ci wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0); 276362306a36Sopenharmony_ci } 276462306a36Sopenharmony_ci} 276562306a36Sopenharmony_ci 276662306a36Sopenharmony_ci/** 276762306a36Sopenharmony_ci * i40e_set_wol - set the WakeOnLAN configuration 276862306a36Sopenharmony_ci * @netdev: the netdev in question 276962306a36Sopenharmony_ci * @wol: the ethtool WoL setting data 277062306a36Sopenharmony_ci **/ 277162306a36Sopenharmony_cistatic int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 277262306a36Sopenharmony_ci{ 277362306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 277462306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 277562306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 277662306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 277762306a36Sopenharmony_ci u16 wol_nvm_bits; 277862306a36Sopenharmony_ci 277962306a36Sopenharmony_ci /* WoL not supported if this isn't the controlling PF on the port */ 278062306a36Sopenharmony_ci if (hw->partition_id != 1) { 278162306a36Sopenharmony_ci i40e_partition_setting_complaint(pf); 278262306a36Sopenharmony_ci return -EOPNOTSUPP; 278362306a36Sopenharmony_ci } 278462306a36Sopenharmony_ci 278562306a36Sopenharmony_ci if (vsi != pf->vsi[pf->lan_vsi]) 278662306a36Sopenharmony_ci return -EOPNOTSUPP; 278762306a36Sopenharmony_ci 278862306a36Sopenharmony_ci /* NVM bit on means WoL disabled for the port */ 278962306a36Sopenharmony_ci i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); 279062306a36Sopenharmony_ci if (BIT(hw->port) & wol_nvm_bits) 279162306a36Sopenharmony_ci return -EOPNOTSUPP; 279262306a36Sopenharmony_ci 279362306a36Sopenharmony_ci /* only magic packet is supported */ 279462306a36Sopenharmony_ci if (wol->wolopts & ~WAKE_MAGIC) 279562306a36Sopenharmony_ci return -EOPNOTSUPP; 279662306a36Sopenharmony_ci 279762306a36Sopenharmony_ci /* is this a new value? */ 279862306a36Sopenharmony_ci if (pf->wol_en != !!wol->wolopts) { 279962306a36Sopenharmony_ci pf->wol_en = !!wol->wolopts; 280062306a36Sopenharmony_ci device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); 280162306a36Sopenharmony_ci } 280262306a36Sopenharmony_ci 280362306a36Sopenharmony_ci return 0; 280462306a36Sopenharmony_ci} 280562306a36Sopenharmony_ci 280662306a36Sopenharmony_cistatic int i40e_set_phys_id(struct net_device *netdev, 280762306a36Sopenharmony_ci enum ethtool_phys_id_state state) 280862306a36Sopenharmony_ci{ 280962306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 281062306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 281162306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 281262306a36Sopenharmony_ci int blink_freq = 2; 281362306a36Sopenharmony_ci u16 temp_status; 281462306a36Sopenharmony_ci int ret = 0; 281562306a36Sopenharmony_ci 281662306a36Sopenharmony_ci switch (state) { 281762306a36Sopenharmony_ci case ETHTOOL_ID_ACTIVE: 281862306a36Sopenharmony_ci if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) { 281962306a36Sopenharmony_ci pf->led_status = i40e_led_get(hw); 282062306a36Sopenharmony_ci } else { 282162306a36Sopenharmony_ci if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) 282262306a36Sopenharmony_ci i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, 282362306a36Sopenharmony_ci NULL); 282462306a36Sopenharmony_ci ret = i40e_led_get_phy(hw, &temp_status, 282562306a36Sopenharmony_ci &pf->phy_led_val); 282662306a36Sopenharmony_ci pf->led_status = temp_status; 282762306a36Sopenharmony_ci } 282862306a36Sopenharmony_ci return blink_freq; 282962306a36Sopenharmony_ci case ETHTOOL_ID_ON: 283062306a36Sopenharmony_ci if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) 283162306a36Sopenharmony_ci i40e_led_set(hw, 0xf, false); 283262306a36Sopenharmony_ci else 283362306a36Sopenharmony_ci ret = i40e_led_set_phy(hw, true, pf->led_status, 0); 283462306a36Sopenharmony_ci break; 283562306a36Sopenharmony_ci case ETHTOOL_ID_OFF: 283662306a36Sopenharmony_ci if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) 283762306a36Sopenharmony_ci i40e_led_set(hw, 0x0, false); 283862306a36Sopenharmony_ci else 283962306a36Sopenharmony_ci ret = i40e_led_set_phy(hw, false, pf->led_status, 0); 284062306a36Sopenharmony_ci break; 284162306a36Sopenharmony_ci case ETHTOOL_ID_INACTIVE: 284262306a36Sopenharmony_ci if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) { 284362306a36Sopenharmony_ci i40e_led_set(hw, pf->led_status, false); 284462306a36Sopenharmony_ci } else { 284562306a36Sopenharmony_ci ret = i40e_led_set_phy(hw, false, pf->led_status, 284662306a36Sopenharmony_ci (pf->phy_led_val | 284762306a36Sopenharmony_ci I40E_PHY_LED_MODE_ORIG)); 284862306a36Sopenharmony_ci if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) 284962306a36Sopenharmony_ci i40e_aq_set_phy_debug(hw, 0, NULL); 285062306a36Sopenharmony_ci } 285162306a36Sopenharmony_ci break; 285262306a36Sopenharmony_ci default: 285362306a36Sopenharmony_ci break; 285462306a36Sopenharmony_ci } 285562306a36Sopenharmony_ci if (ret) 285662306a36Sopenharmony_ci return -ENOENT; 285762306a36Sopenharmony_ci else 285862306a36Sopenharmony_ci return 0; 285962306a36Sopenharmony_ci} 286062306a36Sopenharmony_ci 286162306a36Sopenharmony_ci/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt 286262306a36Sopenharmony_ci * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also 286362306a36Sopenharmony_ci * 125us (8000 interrupts per second) == ITR(62) 286462306a36Sopenharmony_ci */ 286562306a36Sopenharmony_ci 286662306a36Sopenharmony_ci/** 286762306a36Sopenharmony_ci * __i40e_get_coalesce - get per-queue coalesce settings 286862306a36Sopenharmony_ci * @netdev: the netdev to check 286962306a36Sopenharmony_ci * @ec: ethtool coalesce data structure 287062306a36Sopenharmony_ci * @queue: which queue to pick 287162306a36Sopenharmony_ci * 287262306a36Sopenharmony_ci * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs 287362306a36Sopenharmony_ci * are per queue. If queue is <0 then we default to queue 0 as the 287462306a36Sopenharmony_ci * representative value. 287562306a36Sopenharmony_ci **/ 287662306a36Sopenharmony_cistatic int __i40e_get_coalesce(struct net_device *netdev, 287762306a36Sopenharmony_ci struct ethtool_coalesce *ec, 287862306a36Sopenharmony_ci int queue) 287962306a36Sopenharmony_ci{ 288062306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 288162306a36Sopenharmony_ci struct i40e_ring *rx_ring, *tx_ring; 288262306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 288362306a36Sopenharmony_ci 288462306a36Sopenharmony_ci ec->tx_max_coalesced_frames_irq = vsi->work_limit; 288562306a36Sopenharmony_ci ec->rx_max_coalesced_frames_irq = vsi->work_limit; 288662306a36Sopenharmony_ci 288762306a36Sopenharmony_ci /* rx and tx usecs has per queue value. If user doesn't specify the 288862306a36Sopenharmony_ci * queue, return queue 0's value to represent. 288962306a36Sopenharmony_ci */ 289062306a36Sopenharmony_ci if (queue < 0) 289162306a36Sopenharmony_ci queue = 0; 289262306a36Sopenharmony_ci else if (queue >= vsi->num_queue_pairs) 289362306a36Sopenharmony_ci return -EINVAL; 289462306a36Sopenharmony_ci 289562306a36Sopenharmony_ci rx_ring = vsi->rx_rings[queue]; 289662306a36Sopenharmony_ci tx_ring = vsi->tx_rings[queue]; 289762306a36Sopenharmony_ci 289862306a36Sopenharmony_ci if (ITR_IS_DYNAMIC(rx_ring->itr_setting)) 289962306a36Sopenharmony_ci ec->use_adaptive_rx_coalesce = 1; 290062306a36Sopenharmony_ci 290162306a36Sopenharmony_ci if (ITR_IS_DYNAMIC(tx_ring->itr_setting)) 290262306a36Sopenharmony_ci ec->use_adaptive_tx_coalesce = 1; 290362306a36Sopenharmony_ci 290462306a36Sopenharmony_ci ec->rx_coalesce_usecs = rx_ring->itr_setting & ~I40E_ITR_DYNAMIC; 290562306a36Sopenharmony_ci ec->tx_coalesce_usecs = tx_ring->itr_setting & ~I40E_ITR_DYNAMIC; 290662306a36Sopenharmony_ci 290762306a36Sopenharmony_ci /* we use the _usecs_high to store/set the interrupt rate limit 290862306a36Sopenharmony_ci * that the hardware supports, that almost but not quite 290962306a36Sopenharmony_ci * fits the original intent of the ethtool variable, 291062306a36Sopenharmony_ci * the rx_coalesce_usecs_high limits total interrupts 291162306a36Sopenharmony_ci * per second from both tx/rx sources. 291262306a36Sopenharmony_ci */ 291362306a36Sopenharmony_ci ec->rx_coalesce_usecs_high = vsi->int_rate_limit; 291462306a36Sopenharmony_ci ec->tx_coalesce_usecs_high = vsi->int_rate_limit; 291562306a36Sopenharmony_ci 291662306a36Sopenharmony_ci return 0; 291762306a36Sopenharmony_ci} 291862306a36Sopenharmony_ci 291962306a36Sopenharmony_ci/** 292062306a36Sopenharmony_ci * i40e_get_coalesce - get a netdev's coalesce settings 292162306a36Sopenharmony_ci * @netdev: the netdev to check 292262306a36Sopenharmony_ci * @ec: ethtool coalesce data structure 292362306a36Sopenharmony_ci * @kernel_coal: ethtool CQE mode setting structure 292462306a36Sopenharmony_ci * @extack: extack for reporting error messages 292562306a36Sopenharmony_ci * 292662306a36Sopenharmony_ci * Gets the coalesce settings for a particular netdev. Note that if user has 292762306a36Sopenharmony_ci * modified per-queue settings, this only guarantees to represent queue 0. See 292862306a36Sopenharmony_ci * __i40e_get_coalesce for more details. 292962306a36Sopenharmony_ci **/ 293062306a36Sopenharmony_cistatic int i40e_get_coalesce(struct net_device *netdev, 293162306a36Sopenharmony_ci struct ethtool_coalesce *ec, 293262306a36Sopenharmony_ci struct kernel_ethtool_coalesce *kernel_coal, 293362306a36Sopenharmony_ci struct netlink_ext_ack *extack) 293462306a36Sopenharmony_ci{ 293562306a36Sopenharmony_ci return __i40e_get_coalesce(netdev, ec, -1); 293662306a36Sopenharmony_ci} 293762306a36Sopenharmony_ci 293862306a36Sopenharmony_ci/** 293962306a36Sopenharmony_ci * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue 294062306a36Sopenharmony_ci * @netdev: netdev structure 294162306a36Sopenharmony_ci * @ec: ethtool's coalesce settings 294262306a36Sopenharmony_ci * @queue: the particular queue to read 294362306a36Sopenharmony_ci * 294462306a36Sopenharmony_ci * Will read a specific queue's coalesce settings 294562306a36Sopenharmony_ci **/ 294662306a36Sopenharmony_cistatic int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue, 294762306a36Sopenharmony_ci struct ethtool_coalesce *ec) 294862306a36Sopenharmony_ci{ 294962306a36Sopenharmony_ci return __i40e_get_coalesce(netdev, ec, queue); 295062306a36Sopenharmony_ci} 295162306a36Sopenharmony_ci 295262306a36Sopenharmony_ci/** 295362306a36Sopenharmony_ci * i40e_set_itr_per_queue - set ITR values for specific queue 295462306a36Sopenharmony_ci * @vsi: the VSI to set values for 295562306a36Sopenharmony_ci * @ec: coalesce settings from ethtool 295662306a36Sopenharmony_ci * @queue: the queue to modify 295762306a36Sopenharmony_ci * 295862306a36Sopenharmony_ci * Change the ITR settings for a specific queue. 295962306a36Sopenharmony_ci **/ 296062306a36Sopenharmony_cistatic void i40e_set_itr_per_queue(struct i40e_vsi *vsi, 296162306a36Sopenharmony_ci struct ethtool_coalesce *ec, 296262306a36Sopenharmony_ci int queue) 296362306a36Sopenharmony_ci{ 296462306a36Sopenharmony_ci struct i40e_ring *rx_ring = vsi->rx_rings[queue]; 296562306a36Sopenharmony_ci struct i40e_ring *tx_ring = vsi->tx_rings[queue]; 296662306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 296762306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 296862306a36Sopenharmony_ci struct i40e_q_vector *q_vector; 296962306a36Sopenharmony_ci u16 intrl; 297062306a36Sopenharmony_ci 297162306a36Sopenharmony_ci intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit); 297262306a36Sopenharmony_ci 297362306a36Sopenharmony_ci rx_ring->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs); 297462306a36Sopenharmony_ci tx_ring->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs); 297562306a36Sopenharmony_ci 297662306a36Sopenharmony_ci if (ec->use_adaptive_rx_coalesce) 297762306a36Sopenharmony_ci rx_ring->itr_setting |= I40E_ITR_DYNAMIC; 297862306a36Sopenharmony_ci else 297962306a36Sopenharmony_ci rx_ring->itr_setting &= ~I40E_ITR_DYNAMIC; 298062306a36Sopenharmony_ci 298162306a36Sopenharmony_ci if (ec->use_adaptive_tx_coalesce) 298262306a36Sopenharmony_ci tx_ring->itr_setting |= I40E_ITR_DYNAMIC; 298362306a36Sopenharmony_ci else 298462306a36Sopenharmony_ci tx_ring->itr_setting &= ~I40E_ITR_DYNAMIC; 298562306a36Sopenharmony_ci 298662306a36Sopenharmony_ci q_vector = rx_ring->q_vector; 298762306a36Sopenharmony_ci q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting); 298862306a36Sopenharmony_ci 298962306a36Sopenharmony_ci q_vector = tx_ring->q_vector; 299062306a36Sopenharmony_ci q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting); 299162306a36Sopenharmony_ci 299262306a36Sopenharmony_ci /* The interrupt handler itself will take care of programming 299362306a36Sopenharmony_ci * the Tx and Rx ITR values based on the values we have entered 299462306a36Sopenharmony_ci * into the q_vector, no need to write the values now. 299562306a36Sopenharmony_ci */ 299662306a36Sopenharmony_ci 299762306a36Sopenharmony_ci wr32(hw, I40E_PFINT_RATEN(q_vector->reg_idx), intrl); 299862306a36Sopenharmony_ci i40e_flush(hw); 299962306a36Sopenharmony_ci} 300062306a36Sopenharmony_ci 300162306a36Sopenharmony_ci/** 300262306a36Sopenharmony_ci * __i40e_set_coalesce - set coalesce settings for particular queue 300362306a36Sopenharmony_ci * @netdev: the netdev to change 300462306a36Sopenharmony_ci * @ec: ethtool coalesce settings 300562306a36Sopenharmony_ci * @queue: the queue to change 300662306a36Sopenharmony_ci * 300762306a36Sopenharmony_ci * Sets the coalesce settings for a particular queue. 300862306a36Sopenharmony_ci **/ 300962306a36Sopenharmony_cistatic int __i40e_set_coalesce(struct net_device *netdev, 301062306a36Sopenharmony_ci struct ethtool_coalesce *ec, 301162306a36Sopenharmony_ci int queue) 301262306a36Sopenharmony_ci{ 301362306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 301462306a36Sopenharmony_ci u16 intrl_reg, cur_rx_itr, cur_tx_itr; 301562306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 301662306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 301762306a36Sopenharmony_ci int i; 301862306a36Sopenharmony_ci 301962306a36Sopenharmony_ci if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq) 302062306a36Sopenharmony_ci vsi->work_limit = ec->tx_max_coalesced_frames_irq; 302162306a36Sopenharmony_ci 302262306a36Sopenharmony_ci if (queue < 0) { 302362306a36Sopenharmony_ci cur_rx_itr = vsi->rx_rings[0]->itr_setting; 302462306a36Sopenharmony_ci cur_tx_itr = vsi->tx_rings[0]->itr_setting; 302562306a36Sopenharmony_ci } else if (queue < vsi->num_queue_pairs) { 302662306a36Sopenharmony_ci cur_rx_itr = vsi->rx_rings[queue]->itr_setting; 302762306a36Sopenharmony_ci cur_tx_itr = vsi->tx_rings[queue]->itr_setting; 302862306a36Sopenharmony_ci } else { 302962306a36Sopenharmony_ci netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n", 303062306a36Sopenharmony_ci vsi->num_queue_pairs - 1); 303162306a36Sopenharmony_ci return -EINVAL; 303262306a36Sopenharmony_ci } 303362306a36Sopenharmony_ci 303462306a36Sopenharmony_ci cur_tx_itr &= ~I40E_ITR_DYNAMIC; 303562306a36Sopenharmony_ci cur_rx_itr &= ~I40E_ITR_DYNAMIC; 303662306a36Sopenharmony_ci 303762306a36Sopenharmony_ci /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */ 303862306a36Sopenharmony_ci if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) { 303962306a36Sopenharmony_ci netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n"); 304062306a36Sopenharmony_ci return -EINVAL; 304162306a36Sopenharmony_ci } 304262306a36Sopenharmony_ci 304362306a36Sopenharmony_ci if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) { 304462306a36Sopenharmony_ci netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n", 304562306a36Sopenharmony_ci INTRL_REG_TO_USEC(I40E_MAX_INTRL)); 304662306a36Sopenharmony_ci return -EINVAL; 304762306a36Sopenharmony_ci } 304862306a36Sopenharmony_ci 304962306a36Sopenharmony_ci if (ec->rx_coalesce_usecs != cur_rx_itr && 305062306a36Sopenharmony_ci ec->use_adaptive_rx_coalesce) { 305162306a36Sopenharmony_ci netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n"); 305262306a36Sopenharmony_ci return -EINVAL; 305362306a36Sopenharmony_ci } 305462306a36Sopenharmony_ci 305562306a36Sopenharmony_ci if (ec->rx_coalesce_usecs > I40E_MAX_ITR) { 305662306a36Sopenharmony_ci netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n"); 305762306a36Sopenharmony_ci return -EINVAL; 305862306a36Sopenharmony_ci } 305962306a36Sopenharmony_ci 306062306a36Sopenharmony_ci if (ec->tx_coalesce_usecs != cur_tx_itr && 306162306a36Sopenharmony_ci ec->use_adaptive_tx_coalesce) { 306262306a36Sopenharmony_ci netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n"); 306362306a36Sopenharmony_ci return -EINVAL; 306462306a36Sopenharmony_ci } 306562306a36Sopenharmony_ci 306662306a36Sopenharmony_ci if (ec->tx_coalesce_usecs > I40E_MAX_ITR) { 306762306a36Sopenharmony_ci netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n"); 306862306a36Sopenharmony_ci return -EINVAL; 306962306a36Sopenharmony_ci } 307062306a36Sopenharmony_ci 307162306a36Sopenharmony_ci if (ec->use_adaptive_rx_coalesce && !cur_rx_itr) 307262306a36Sopenharmony_ci ec->rx_coalesce_usecs = I40E_MIN_ITR; 307362306a36Sopenharmony_ci 307462306a36Sopenharmony_ci if (ec->use_adaptive_tx_coalesce && !cur_tx_itr) 307562306a36Sopenharmony_ci ec->tx_coalesce_usecs = I40E_MIN_ITR; 307662306a36Sopenharmony_ci 307762306a36Sopenharmony_ci intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high); 307862306a36Sopenharmony_ci vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg); 307962306a36Sopenharmony_ci if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) { 308062306a36Sopenharmony_ci netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n", 308162306a36Sopenharmony_ci vsi->int_rate_limit); 308262306a36Sopenharmony_ci } 308362306a36Sopenharmony_ci 308462306a36Sopenharmony_ci /* rx and tx usecs has per queue value. If user doesn't specify the 308562306a36Sopenharmony_ci * queue, apply to all queues. 308662306a36Sopenharmony_ci */ 308762306a36Sopenharmony_ci if (queue < 0) { 308862306a36Sopenharmony_ci for (i = 0; i < vsi->num_queue_pairs; i++) 308962306a36Sopenharmony_ci i40e_set_itr_per_queue(vsi, ec, i); 309062306a36Sopenharmony_ci } else { 309162306a36Sopenharmony_ci i40e_set_itr_per_queue(vsi, ec, queue); 309262306a36Sopenharmony_ci } 309362306a36Sopenharmony_ci 309462306a36Sopenharmony_ci return 0; 309562306a36Sopenharmony_ci} 309662306a36Sopenharmony_ci 309762306a36Sopenharmony_ci/** 309862306a36Sopenharmony_ci * i40e_set_coalesce - set coalesce settings for every queue on the netdev 309962306a36Sopenharmony_ci * @netdev: the netdev to change 310062306a36Sopenharmony_ci * @ec: ethtool coalesce settings 310162306a36Sopenharmony_ci * @kernel_coal: ethtool CQE mode setting structure 310262306a36Sopenharmony_ci * @extack: extack for reporting error messages 310362306a36Sopenharmony_ci * 310462306a36Sopenharmony_ci * This will set each queue to the same coalesce settings. 310562306a36Sopenharmony_ci **/ 310662306a36Sopenharmony_cistatic int i40e_set_coalesce(struct net_device *netdev, 310762306a36Sopenharmony_ci struct ethtool_coalesce *ec, 310862306a36Sopenharmony_ci struct kernel_ethtool_coalesce *kernel_coal, 310962306a36Sopenharmony_ci struct netlink_ext_ack *extack) 311062306a36Sopenharmony_ci{ 311162306a36Sopenharmony_ci return __i40e_set_coalesce(netdev, ec, -1); 311262306a36Sopenharmony_ci} 311362306a36Sopenharmony_ci 311462306a36Sopenharmony_ci/** 311562306a36Sopenharmony_ci * i40e_set_per_queue_coalesce - set specific queue's coalesce settings 311662306a36Sopenharmony_ci * @netdev: the netdev to change 311762306a36Sopenharmony_ci * @ec: ethtool's coalesce settings 311862306a36Sopenharmony_ci * @queue: the queue to change 311962306a36Sopenharmony_ci * 312062306a36Sopenharmony_ci * Sets the specified queue's coalesce settings. 312162306a36Sopenharmony_ci **/ 312262306a36Sopenharmony_cistatic int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue, 312362306a36Sopenharmony_ci struct ethtool_coalesce *ec) 312462306a36Sopenharmony_ci{ 312562306a36Sopenharmony_ci return __i40e_set_coalesce(netdev, ec, queue); 312662306a36Sopenharmony_ci} 312762306a36Sopenharmony_ci 312862306a36Sopenharmony_ci/** 312962306a36Sopenharmony_ci * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type 313062306a36Sopenharmony_ci * @pf: pointer to the physical function struct 313162306a36Sopenharmony_ci * @cmd: ethtool rxnfc command 313262306a36Sopenharmony_ci * 313362306a36Sopenharmony_ci * Returns Success if the flow is supported, else Invalid Input. 313462306a36Sopenharmony_ci **/ 313562306a36Sopenharmony_cistatic int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd) 313662306a36Sopenharmony_ci{ 313762306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 313862306a36Sopenharmony_ci u8 flow_pctype = 0; 313962306a36Sopenharmony_ci u64 i_set = 0; 314062306a36Sopenharmony_ci 314162306a36Sopenharmony_ci cmd->data = 0; 314262306a36Sopenharmony_ci 314362306a36Sopenharmony_ci switch (cmd->flow_type) { 314462306a36Sopenharmony_ci case TCP_V4_FLOW: 314562306a36Sopenharmony_ci flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP; 314662306a36Sopenharmony_ci break; 314762306a36Sopenharmony_ci case UDP_V4_FLOW: 314862306a36Sopenharmony_ci flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP; 314962306a36Sopenharmony_ci break; 315062306a36Sopenharmony_ci case TCP_V6_FLOW: 315162306a36Sopenharmony_ci flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP; 315262306a36Sopenharmony_ci break; 315362306a36Sopenharmony_ci case UDP_V6_FLOW: 315462306a36Sopenharmony_ci flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP; 315562306a36Sopenharmony_ci break; 315662306a36Sopenharmony_ci case SCTP_V4_FLOW: 315762306a36Sopenharmony_ci case AH_ESP_V4_FLOW: 315862306a36Sopenharmony_ci case AH_V4_FLOW: 315962306a36Sopenharmony_ci case ESP_V4_FLOW: 316062306a36Sopenharmony_ci case IPV4_FLOW: 316162306a36Sopenharmony_ci case SCTP_V6_FLOW: 316262306a36Sopenharmony_ci case AH_ESP_V6_FLOW: 316362306a36Sopenharmony_ci case AH_V6_FLOW: 316462306a36Sopenharmony_ci case ESP_V6_FLOW: 316562306a36Sopenharmony_ci case IPV6_FLOW: 316662306a36Sopenharmony_ci /* Default is src/dest for IP, no matter the L4 hashing */ 316762306a36Sopenharmony_ci cmd->data |= RXH_IP_SRC | RXH_IP_DST; 316862306a36Sopenharmony_ci break; 316962306a36Sopenharmony_ci default: 317062306a36Sopenharmony_ci return -EINVAL; 317162306a36Sopenharmony_ci } 317262306a36Sopenharmony_ci 317362306a36Sopenharmony_ci /* Read flow based hash input set register */ 317462306a36Sopenharmony_ci if (flow_pctype) { 317562306a36Sopenharmony_ci i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, 317662306a36Sopenharmony_ci flow_pctype)) | 317762306a36Sopenharmony_ci ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, 317862306a36Sopenharmony_ci flow_pctype)) << 32); 317962306a36Sopenharmony_ci } 318062306a36Sopenharmony_ci 318162306a36Sopenharmony_ci /* Process bits of hash input set */ 318262306a36Sopenharmony_ci if (i_set) { 318362306a36Sopenharmony_ci if (i_set & I40E_L4_SRC_MASK) 318462306a36Sopenharmony_ci cmd->data |= RXH_L4_B_0_1; 318562306a36Sopenharmony_ci if (i_set & I40E_L4_DST_MASK) 318662306a36Sopenharmony_ci cmd->data |= RXH_L4_B_2_3; 318762306a36Sopenharmony_ci 318862306a36Sopenharmony_ci if (cmd->flow_type == TCP_V4_FLOW || 318962306a36Sopenharmony_ci cmd->flow_type == UDP_V4_FLOW) { 319062306a36Sopenharmony_ci if (hw->mac.type == I40E_MAC_X722) { 319162306a36Sopenharmony_ci if (i_set & I40E_X722_L3_SRC_MASK) 319262306a36Sopenharmony_ci cmd->data |= RXH_IP_SRC; 319362306a36Sopenharmony_ci if (i_set & I40E_X722_L3_DST_MASK) 319462306a36Sopenharmony_ci cmd->data |= RXH_IP_DST; 319562306a36Sopenharmony_ci } else { 319662306a36Sopenharmony_ci if (i_set & I40E_L3_SRC_MASK) 319762306a36Sopenharmony_ci cmd->data |= RXH_IP_SRC; 319862306a36Sopenharmony_ci if (i_set & I40E_L3_DST_MASK) 319962306a36Sopenharmony_ci cmd->data |= RXH_IP_DST; 320062306a36Sopenharmony_ci } 320162306a36Sopenharmony_ci } else if (cmd->flow_type == TCP_V6_FLOW || 320262306a36Sopenharmony_ci cmd->flow_type == UDP_V6_FLOW) { 320362306a36Sopenharmony_ci if (i_set & I40E_L3_V6_SRC_MASK) 320462306a36Sopenharmony_ci cmd->data |= RXH_IP_SRC; 320562306a36Sopenharmony_ci if (i_set & I40E_L3_V6_DST_MASK) 320662306a36Sopenharmony_ci cmd->data |= RXH_IP_DST; 320762306a36Sopenharmony_ci } 320862306a36Sopenharmony_ci } 320962306a36Sopenharmony_ci 321062306a36Sopenharmony_ci return 0; 321162306a36Sopenharmony_ci} 321262306a36Sopenharmony_ci 321362306a36Sopenharmony_ci/** 321462306a36Sopenharmony_ci * i40e_check_mask - Check whether a mask field is set 321562306a36Sopenharmony_ci * @mask: the full mask value 321662306a36Sopenharmony_ci * @field: mask of the field to check 321762306a36Sopenharmony_ci * 321862306a36Sopenharmony_ci * If the given mask is fully set, return positive value. If the mask for the 321962306a36Sopenharmony_ci * field is fully unset, return zero. Otherwise return a negative error code. 322062306a36Sopenharmony_ci **/ 322162306a36Sopenharmony_cistatic int i40e_check_mask(u64 mask, u64 field) 322262306a36Sopenharmony_ci{ 322362306a36Sopenharmony_ci u64 value = mask & field; 322462306a36Sopenharmony_ci 322562306a36Sopenharmony_ci if (value == field) 322662306a36Sopenharmony_ci return 1; 322762306a36Sopenharmony_ci else if (!value) 322862306a36Sopenharmony_ci return 0; 322962306a36Sopenharmony_ci else 323062306a36Sopenharmony_ci return -1; 323162306a36Sopenharmony_ci} 323262306a36Sopenharmony_ci 323362306a36Sopenharmony_ci/** 323462306a36Sopenharmony_ci * i40e_parse_rx_flow_user_data - Deconstruct user-defined data 323562306a36Sopenharmony_ci * @fsp: pointer to rx flow specification 323662306a36Sopenharmony_ci * @data: pointer to userdef data structure for storage 323762306a36Sopenharmony_ci * 323862306a36Sopenharmony_ci * Read the user-defined data and deconstruct the value into a structure. No 323962306a36Sopenharmony_ci * other code should read the user-defined data, so as to ensure that every 324062306a36Sopenharmony_ci * place consistently reads the value correctly. 324162306a36Sopenharmony_ci * 324262306a36Sopenharmony_ci * The user-defined field is a 64bit Big Endian format value, which we 324362306a36Sopenharmony_ci * deconstruct by reading bits or bit fields from it. Single bit flags shall 324462306a36Sopenharmony_ci * be defined starting from the highest bits, while small bit field values 324562306a36Sopenharmony_ci * shall be defined starting from the lowest bits. 324662306a36Sopenharmony_ci * 324762306a36Sopenharmony_ci * Returns 0 if the data is valid, and non-zero if the userdef data is invalid 324862306a36Sopenharmony_ci * and the filter should be rejected. The data structure will always be 324962306a36Sopenharmony_ci * modified even if FLOW_EXT is not set. 325062306a36Sopenharmony_ci * 325162306a36Sopenharmony_ci **/ 325262306a36Sopenharmony_cistatic int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp, 325362306a36Sopenharmony_ci struct i40e_rx_flow_userdef *data) 325462306a36Sopenharmony_ci{ 325562306a36Sopenharmony_ci u64 value, mask; 325662306a36Sopenharmony_ci int valid; 325762306a36Sopenharmony_ci 325862306a36Sopenharmony_ci /* Zero memory first so it's always consistent. */ 325962306a36Sopenharmony_ci memset(data, 0, sizeof(*data)); 326062306a36Sopenharmony_ci 326162306a36Sopenharmony_ci if (!(fsp->flow_type & FLOW_EXT)) 326262306a36Sopenharmony_ci return 0; 326362306a36Sopenharmony_ci 326462306a36Sopenharmony_ci value = be64_to_cpu(*((__be64 *)fsp->h_ext.data)); 326562306a36Sopenharmony_ci mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data)); 326662306a36Sopenharmony_ci 326762306a36Sopenharmony_ci#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0) 326862306a36Sopenharmony_ci#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16) 326962306a36Sopenharmony_ci#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0) 327062306a36Sopenharmony_ci 327162306a36Sopenharmony_ci valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER); 327262306a36Sopenharmony_ci if (valid < 0) { 327362306a36Sopenharmony_ci return -EINVAL; 327462306a36Sopenharmony_ci } else if (valid) { 327562306a36Sopenharmony_ci data->flex_word = value & I40E_USERDEF_FLEX_WORD; 327662306a36Sopenharmony_ci data->flex_offset = 327762306a36Sopenharmony_ci (value & I40E_USERDEF_FLEX_OFFSET) >> 16; 327862306a36Sopenharmony_ci data->flex_filter = true; 327962306a36Sopenharmony_ci } 328062306a36Sopenharmony_ci 328162306a36Sopenharmony_ci return 0; 328262306a36Sopenharmony_ci} 328362306a36Sopenharmony_ci 328462306a36Sopenharmony_ci/** 328562306a36Sopenharmony_ci * i40e_fill_rx_flow_user_data - Fill in user-defined data field 328662306a36Sopenharmony_ci * @fsp: pointer to rx_flow specification 328762306a36Sopenharmony_ci * @data: pointer to return userdef data 328862306a36Sopenharmony_ci * 328962306a36Sopenharmony_ci * Reads the userdef data structure and properly fills in the user defined 329062306a36Sopenharmony_ci * fields of the rx_flow_spec. 329162306a36Sopenharmony_ci **/ 329262306a36Sopenharmony_cistatic void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp, 329362306a36Sopenharmony_ci struct i40e_rx_flow_userdef *data) 329462306a36Sopenharmony_ci{ 329562306a36Sopenharmony_ci u64 value = 0, mask = 0; 329662306a36Sopenharmony_ci 329762306a36Sopenharmony_ci if (data->flex_filter) { 329862306a36Sopenharmony_ci value |= data->flex_word; 329962306a36Sopenharmony_ci value |= (u64)data->flex_offset << 16; 330062306a36Sopenharmony_ci mask |= I40E_USERDEF_FLEX_FILTER; 330162306a36Sopenharmony_ci } 330262306a36Sopenharmony_ci 330362306a36Sopenharmony_ci if (value || mask) 330462306a36Sopenharmony_ci fsp->flow_type |= FLOW_EXT; 330562306a36Sopenharmony_ci 330662306a36Sopenharmony_ci *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value); 330762306a36Sopenharmony_ci *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask); 330862306a36Sopenharmony_ci} 330962306a36Sopenharmony_ci 331062306a36Sopenharmony_ci/** 331162306a36Sopenharmony_ci * i40e_get_ethtool_fdir_all - Populates the rule count of a command 331262306a36Sopenharmony_ci * @pf: Pointer to the physical function struct 331362306a36Sopenharmony_ci * @cmd: The command to get or set Rx flow classification rules 331462306a36Sopenharmony_ci * @rule_locs: Array of used rule locations 331562306a36Sopenharmony_ci * 331662306a36Sopenharmony_ci * This function populates both the total and actual rule count of 331762306a36Sopenharmony_ci * the ethtool flow classification command 331862306a36Sopenharmony_ci * 331962306a36Sopenharmony_ci * Returns 0 on success or -EMSGSIZE if entry not found 332062306a36Sopenharmony_ci **/ 332162306a36Sopenharmony_cistatic int i40e_get_ethtool_fdir_all(struct i40e_pf *pf, 332262306a36Sopenharmony_ci struct ethtool_rxnfc *cmd, 332362306a36Sopenharmony_ci u32 *rule_locs) 332462306a36Sopenharmony_ci{ 332562306a36Sopenharmony_ci struct i40e_fdir_filter *rule; 332662306a36Sopenharmony_ci struct hlist_node *node2; 332762306a36Sopenharmony_ci int cnt = 0; 332862306a36Sopenharmony_ci 332962306a36Sopenharmony_ci /* report total rule count */ 333062306a36Sopenharmony_ci cmd->data = i40e_get_fd_cnt_all(pf); 333162306a36Sopenharmony_ci 333262306a36Sopenharmony_ci hlist_for_each_entry_safe(rule, node2, 333362306a36Sopenharmony_ci &pf->fdir_filter_list, fdir_node) { 333462306a36Sopenharmony_ci if (cnt == cmd->rule_cnt) 333562306a36Sopenharmony_ci return -EMSGSIZE; 333662306a36Sopenharmony_ci 333762306a36Sopenharmony_ci rule_locs[cnt] = rule->fd_id; 333862306a36Sopenharmony_ci cnt++; 333962306a36Sopenharmony_ci } 334062306a36Sopenharmony_ci 334162306a36Sopenharmony_ci cmd->rule_cnt = cnt; 334262306a36Sopenharmony_ci 334362306a36Sopenharmony_ci return 0; 334462306a36Sopenharmony_ci} 334562306a36Sopenharmony_ci 334662306a36Sopenharmony_ci/** 334762306a36Sopenharmony_ci * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow 334862306a36Sopenharmony_ci * @pf: Pointer to the physical function struct 334962306a36Sopenharmony_ci * @cmd: The command to get or set Rx flow classification rules 335062306a36Sopenharmony_ci * 335162306a36Sopenharmony_ci * This function looks up a filter based on the Rx flow classification 335262306a36Sopenharmony_ci * command and fills the flow spec info for it if found 335362306a36Sopenharmony_ci * 335462306a36Sopenharmony_ci * Returns 0 on success or -EINVAL if filter not found 335562306a36Sopenharmony_ci **/ 335662306a36Sopenharmony_cistatic int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf, 335762306a36Sopenharmony_ci struct ethtool_rxnfc *cmd) 335862306a36Sopenharmony_ci{ 335962306a36Sopenharmony_ci struct ethtool_rx_flow_spec *fsp = 336062306a36Sopenharmony_ci (struct ethtool_rx_flow_spec *)&cmd->fs; 336162306a36Sopenharmony_ci struct i40e_rx_flow_userdef userdef = {0}; 336262306a36Sopenharmony_ci struct i40e_fdir_filter *rule = NULL; 336362306a36Sopenharmony_ci struct hlist_node *node2; 336462306a36Sopenharmony_ci u64 input_set; 336562306a36Sopenharmony_ci u16 index; 336662306a36Sopenharmony_ci 336762306a36Sopenharmony_ci hlist_for_each_entry_safe(rule, node2, 336862306a36Sopenharmony_ci &pf->fdir_filter_list, fdir_node) { 336962306a36Sopenharmony_ci if (fsp->location <= rule->fd_id) 337062306a36Sopenharmony_ci break; 337162306a36Sopenharmony_ci } 337262306a36Sopenharmony_ci 337362306a36Sopenharmony_ci if (!rule || fsp->location != rule->fd_id) 337462306a36Sopenharmony_ci return -EINVAL; 337562306a36Sopenharmony_ci 337662306a36Sopenharmony_ci fsp->flow_type = rule->flow_type; 337762306a36Sopenharmony_ci if (fsp->flow_type == IP_USER_FLOW) { 337862306a36Sopenharmony_ci fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4; 337962306a36Sopenharmony_ci fsp->h_u.usr_ip4_spec.proto = 0; 338062306a36Sopenharmony_ci fsp->m_u.usr_ip4_spec.proto = 0; 338162306a36Sopenharmony_ci } 338262306a36Sopenharmony_ci 338362306a36Sopenharmony_ci if (fsp->flow_type == IPV6_USER_FLOW || 338462306a36Sopenharmony_ci fsp->flow_type == UDP_V6_FLOW || 338562306a36Sopenharmony_ci fsp->flow_type == TCP_V6_FLOW || 338662306a36Sopenharmony_ci fsp->flow_type == SCTP_V6_FLOW) { 338762306a36Sopenharmony_ci /* Reverse the src and dest notion, since the HW views them 338862306a36Sopenharmony_ci * from Tx perspective where as the user expects it from 338962306a36Sopenharmony_ci * Rx filter view. 339062306a36Sopenharmony_ci */ 339162306a36Sopenharmony_ci fsp->h_u.tcp_ip6_spec.psrc = rule->dst_port; 339262306a36Sopenharmony_ci fsp->h_u.tcp_ip6_spec.pdst = rule->src_port; 339362306a36Sopenharmony_ci memcpy(fsp->h_u.tcp_ip6_spec.ip6dst, rule->src_ip6, 339462306a36Sopenharmony_ci sizeof(__be32) * 4); 339562306a36Sopenharmony_ci memcpy(fsp->h_u.tcp_ip6_spec.ip6src, rule->dst_ip6, 339662306a36Sopenharmony_ci sizeof(__be32) * 4); 339762306a36Sopenharmony_ci } else { 339862306a36Sopenharmony_ci /* Reverse the src and dest notion, since the HW views them 339962306a36Sopenharmony_ci * from Tx perspective where as the user expects it from 340062306a36Sopenharmony_ci * Rx filter view. 340162306a36Sopenharmony_ci */ 340262306a36Sopenharmony_ci fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port; 340362306a36Sopenharmony_ci fsp->h_u.tcp_ip4_spec.pdst = rule->src_port; 340462306a36Sopenharmony_ci fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip; 340562306a36Sopenharmony_ci fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip; 340662306a36Sopenharmony_ci } 340762306a36Sopenharmony_ci 340862306a36Sopenharmony_ci switch (rule->flow_type) { 340962306a36Sopenharmony_ci case SCTP_V4_FLOW: 341062306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP; 341162306a36Sopenharmony_ci break; 341262306a36Sopenharmony_ci case TCP_V4_FLOW: 341362306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP; 341462306a36Sopenharmony_ci break; 341562306a36Sopenharmony_ci case UDP_V4_FLOW: 341662306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP; 341762306a36Sopenharmony_ci break; 341862306a36Sopenharmony_ci case SCTP_V6_FLOW: 341962306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV6_SCTP; 342062306a36Sopenharmony_ci break; 342162306a36Sopenharmony_ci case TCP_V6_FLOW: 342262306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV6_TCP; 342362306a36Sopenharmony_ci break; 342462306a36Sopenharmony_ci case UDP_V6_FLOW: 342562306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV6_UDP; 342662306a36Sopenharmony_ci break; 342762306a36Sopenharmony_ci case IP_USER_FLOW: 342862306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER; 342962306a36Sopenharmony_ci break; 343062306a36Sopenharmony_ci case IPV6_USER_FLOW: 343162306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV6_OTHER; 343262306a36Sopenharmony_ci break; 343362306a36Sopenharmony_ci default: 343462306a36Sopenharmony_ci /* If we have stored a filter with a flow type not listed here 343562306a36Sopenharmony_ci * it is almost certainly a driver bug. WARN(), and then 343662306a36Sopenharmony_ci * assign the input_set as if all fields are enabled to avoid 343762306a36Sopenharmony_ci * reading unassigned memory. 343862306a36Sopenharmony_ci */ 343962306a36Sopenharmony_ci WARN(1, "Missing input set index for flow_type %d\n", 344062306a36Sopenharmony_ci rule->flow_type); 344162306a36Sopenharmony_ci input_set = 0xFFFFFFFFFFFFFFFFULL; 344262306a36Sopenharmony_ci goto no_input_set; 344362306a36Sopenharmony_ci } 344462306a36Sopenharmony_ci 344562306a36Sopenharmony_ci input_set = i40e_read_fd_input_set(pf, index); 344662306a36Sopenharmony_ci 344762306a36Sopenharmony_cino_input_set: 344862306a36Sopenharmony_ci if (input_set & I40E_L3_V6_SRC_MASK) { 344962306a36Sopenharmony_ci fsp->m_u.tcp_ip6_spec.ip6src[0] = htonl(0xFFFFFFFF); 345062306a36Sopenharmony_ci fsp->m_u.tcp_ip6_spec.ip6src[1] = htonl(0xFFFFFFFF); 345162306a36Sopenharmony_ci fsp->m_u.tcp_ip6_spec.ip6src[2] = htonl(0xFFFFFFFF); 345262306a36Sopenharmony_ci fsp->m_u.tcp_ip6_spec.ip6src[3] = htonl(0xFFFFFFFF); 345362306a36Sopenharmony_ci } 345462306a36Sopenharmony_ci 345562306a36Sopenharmony_ci if (input_set & I40E_L3_V6_DST_MASK) { 345662306a36Sopenharmony_ci fsp->m_u.tcp_ip6_spec.ip6dst[0] = htonl(0xFFFFFFFF); 345762306a36Sopenharmony_ci fsp->m_u.tcp_ip6_spec.ip6dst[1] = htonl(0xFFFFFFFF); 345862306a36Sopenharmony_ci fsp->m_u.tcp_ip6_spec.ip6dst[2] = htonl(0xFFFFFFFF); 345962306a36Sopenharmony_ci fsp->m_u.tcp_ip6_spec.ip6dst[3] = htonl(0xFFFFFFFF); 346062306a36Sopenharmony_ci } 346162306a36Sopenharmony_ci 346262306a36Sopenharmony_ci if (input_set & I40E_L3_SRC_MASK) 346362306a36Sopenharmony_ci fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFFFFFF); 346462306a36Sopenharmony_ci 346562306a36Sopenharmony_ci if (input_set & I40E_L3_DST_MASK) 346662306a36Sopenharmony_ci fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFFFFFF); 346762306a36Sopenharmony_ci 346862306a36Sopenharmony_ci if (input_set & I40E_L4_SRC_MASK) 346962306a36Sopenharmony_ci fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFF); 347062306a36Sopenharmony_ci 347162306a36Sopenharmony_ci if (input_set & I40E_L4_DST_MASK) 347262306a36Sopenharmony_ci fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFF); 347362306a36Sopenharmony_ci 347462306a36Sopenharmony_ci if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET) 347562306a36Sopenharmony_ci fsp->ring_cookie = RX_CLS_FLOW_DISC; 347662306a36Sopenharmony_ci else 347762306a36Sopenharmony_ci fsp->ring_cookie = rule->q_index; 347862306a36Sopenharmony_ci 347962306a36Sopenharmony_ci if (rule->vlan_tag) { 348062306a36Sopenharmony_ci fsp->h_ext.vlan_etype = rule->vlan_etype; 348162306a36Sopenharmony_ci fsp->m_ext.vlan_etype = htons(0xFFFF); 348262306a36Sopenharmony_ci fsp->h_ext.vlan_tci = rule->vlan_tag; 348362306a36Sopenharmony_ci fsp->m_ext.vlan_tci = htons(0xFFFF); 348462306a36Sopenharmony_ci fsp->flow_type |= FLOW_EXT; 348562306a36Sopenharmony_ci } 348662306a36Sopenharmony_ci 348762306a36Sopenharmony_ci if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) { 348862306a36Sopenharmony_ci struct i40e_vsi *vsi; 348962306a36Sopenharmony_ci 349062306a36Sopenharmony_ci vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi); 349162306a36Sopenharmony_ci if (vsi && vsi->type == I40E_VSI_SRIOV) { 349262306a36Sopenharmony_ci /* VFs are zero-indexed by the driver, but ethtool 349362306a36Sopenharmony_ci * expects them to be one-indexed, so add one here 349462306a36Sopenharmony_ci */ 349562306a36Sopenharmony_ci u64 ring_vf = vsi->vf_id + 1; 349662306a36Sopenharmony_ci 349762306a36Sopenharmony_ci ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF; 349862306a36Sopenharmony_ci fsp->ring_cookie |= ring_vf; 349962306a36Sopenharmony_ci } 350062306a36Sopenharmony_ci } 350162306a36Sopenharmony_ci 350262306a36Sopenharmony_ci if (rule->flex_filter) { 350362306a36Sopenharmony_ci userdef.flex_filter = true; 350462306a36Sopenharmony_ci userdef.flex_word = be16_to_cpu(rule->flex_word); 350562306a36Sopenharmony_ci userdef.flex_offset = rule->flex_offset; 350662306a36Sopenharmony_ci } 350762306a36Sopenharmony_ci 350862306a36Sopenharmony_ci i40e_fill_rx_flow_user_data(fsp, &userdef); 350962306a36Sopenharmony_ci 351062306a36Sopenharmony_ci return 0; 351162306a36Sopenharmony_ci} 351262306a36Sopenharmony_ci 351362306a36Sopenharmony_ci/** 351462306a36Sopenharmony_ci * i40e_get_rxnfc - command to get RX flow classification rules 351562306a36Sopenharmony_ci * @netdev: network interface device structure 351662306a36Sopenharmony_ci * @cmd: ethtool rxnfc command 351762306a36Sopenharmony_ci * @rule_locs: pointer to store rule data 351862306a36Sopenharmony_ci * 351962306a36Sopenharmony_ci * Returns Success if the command is supported. 352062306a36Sopenharmony_ci **/ 352162306a36Sopenharmony_cistatic int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, 352262306a36Sopenharmony_ci u32 *rule_locs) 352362306a36Sopenharmony_ci{ 352462306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 352562306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 352662306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 352762306a36Sopenharmony_ci int ret = -EOPNOTSUPP; 352862306a36Sopenharmony_ci 352962306a36Sopenharmony_ci switch (cmd->cmd) { 353062306a36Sopenharmony_ci case ETHTOOL_GRXRINGS: 353162306a36Sopenharmony_ci cmd->data = vsi->rss_size; 353262306a36Sopenharmony_ci ret = 0; 353362306a36Sopenharmony_ci break; 353462306a36Sopenharmony_ci case ETHTOOL_GRXFH: 353562306a36Sopenharmony_ci ret = i40e_get_rss_hash_opts(pf, cmd); 353662306a36Sopenharmony_ci break; 353762306a36Sopenharmony_ci case ETHTOOL_GRXCLSRLCNT: 353862306a36Sopenharmony_ci cmd->rule_cnt = pf->fdir_pf_active_filters; 353962306a36Sopenharmony_ci /* report total rule count */ 354062306a36Sopenharmony_ci cmd->data = i40e_get_fd_cnt_all(pf); 354162306a36Sopenharmony_ci ret = 0; 354262306a36Sopenharmony_ci break; 354362306a36Sopenharmony_ci case ETHTOOL_GRXCLSRULE: 354462306a36Sopenharmony_ci ret = i40e_get_ethtool_fdir_entry(pf, cmd); 354562306a36Sopenharmony_ci break; 354662306a36Sopenharmony_ci case ETHTOOL_GRXCLSRLALL: 354762306a36Sopenharmony_ci ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs); 354862306a36Sopenharmony_ci break; 354962306a36Sopenharmony_ci default: 355062306a36Sopenharmony_ci break; 355162306a36Sopenharmony_ci } 355262306a36Sopenharmony_ci 355362306a36Sopenharmony_ci return ret; 355462306a36Sopenharmony_ci} 355562306a36Sopenharmony_ci 355662306a36Sopenharmony_ci/** 355762306a36Sopenharmony_ci * i40e_get_rss_hash_bits - Read RSS Hash bits from register 355862306a36Sopenharmony_ci * @hw: hw structure 355962306a36Sopenharmony_ci * @nfc: pointer to user request 356062306a36Sopenharmony_ci * @i_setc: bits currently set 356162306a36Sopenharmony_ci * 356262306a36Sopenharmony_ci * Returns value of bits to be set per user request 356362306a36Sopenharmony_ci **/ 356462306a36Sopenharmony_cistatic u64 i40e_get_rss_hash_bits(struct i40e_hw *hw, 356562306a36Sopenharmony_ci struct ethtool_rxnfc *nfc, 356662306a36Sopenharmony_ci u64 i_setc) 356762306a36Sopenharmony_ci{ 356862306a36Sopenharmony_ci u64 i_set = i_setc; 356962306a36Sopenharmony_ci u64 src_l3 = 0, dst_l3 = 0; 357062306a36Sopenharmony_ci 357162306a36Sopenharmony_ci if (nfc->data & RXH_L4_B_0_1) 357262306a36Sopenharmony_ci i_set |= I40E_L4_SRC_MASK; 357362306a36Sopenharmony_ci else 357462306a36Sopenharmony_ci i_set &= ~I40E_L4_SRC_MASK; 357562306a36Sopenharmony_ci if (nfc->data & RXH_L4_B_2_3) 357662306a36Sopenharmony_ci i_set |= I40E_L4_DST_MASK; 357762306a36Sopenharmony_ci else 357862306a36Sopenharmony_ci i_set &= ~I40E_L4_DST_MASK; 357962306a36Sopenharmony_ci 358062306a36Sopenharmony_ci if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) { 358162306a36Sopenharmony_ci src_l3 = I40E_L3_V6_SRC_MASK; 358262306a36Sopenharmony_ci dst_l3 = I40E_L3_V6_DST_MASK; 358362306a36Sopenharmony_ci } else if (nfc->flow_type == TCP_V4_FLOW || 358462306a36Sopenharmony_ci nfc->flow_type == UDP_V4_FLOW) { 358562306a36Sopenharmony_ci if (hw->mac.type == I40E_MAC_X722) { 358662306a36Sopenharmony_ci src_l3 = I40E_X722_L3_SRC_MASK; 358762306a36Sopenharmony_ci dst_l3 = I40E_X722_L3_DST_MASK; 358862306a36Sopenharmony_ci } else { 358962306a36Sopenharmony_ci src_l3 = I40E_L3_SRC_MASK; 359062306a36Sopenharmony_ci dst_l3 = I40E_L3_DST_MASK; 359162306a36Sopenharmony_ci } 359262306a36Sopenharmony_ci } else { 359362306a36Sopenharmony_ci /* Any other flow type are not supported here */ 359462306a36Sopenharmony_ci return i_set; 359562306a36Sopenharmony_ci } 359662306a36Sopenharmony_ci 359762306a36Sopenharmony_ci if (nfc->data & RXH_IP_SRC) 359862306a36Sopenharmony_ci i_set |= src_l3; 359962306a36Sopenharmony_ci else 360062306a36Sopenharmony_ci i_set &= ~src_l3; 360162306a36Sopenharmony_ci if (nfc->data & RXH_IP_DST) 360262306a36Sopenharmony_ci i_set |= dst_l3; 360362306a36Sopenharmony_ci else 360462306a36Sopenharmony_ci i_set &= ~dst_l3; 360562306a36Sopenharmony_ci 360662306a36Sopenharmony_ci return i_set; 360762306a36Sopenharmony_ci} 360862306a36Sopenharmony_ci 360962306a36Sopenharmony_ci#define FLOW_PCTYPES_SIZE 64 361062306a36Sopenharmony_ci/** 361162306a36Sopenharmony_ci * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash 361262306a36Sopenharmony_ci * @pf: pointer to the physical function struct 361362306a36Sopenharmony_ci * @nfc: ethtool rxnfc command 361462306a36Sopenharmony_ci * 361562306a36Sopenharmony_ci * Returns Success if the flow input set is supported. 361662306a36Sopenharmony_ci **/ 361762306a36Sopenharmony_cistatic int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc) 361862306a36Sopenharmony_ci{ 361962306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 362062306a36Sopenharmony_ci u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | 362162306a36Sopenharmony_ci ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); 362262306a36Sopenharmony_ci DECLARE_BITMAP(flow_pctypes, FLOW_PCTYPES_SIZE); 362362306a36Sopenharmony_ci u64 i_set, i_setc; 362462306a36Sopenharmony_ci 362562306a36Sopenharmony_ci bitmap_zero(flow_pctypes, FLOW_PCTYPES_SIZE); 362662306a36Sopenharmony_ci 362762306a36Sopenharmony_ci if (pf->flags & I40E_FLAG_MFP_ENABLED) { 362862306a36Sopenharmony_ci dev_err(&pf->pdev->dev, 362962306a36Sopenharmony_ci "Change of RSS hash input set is not supported when MFP mode is enabled\n"); 363062306a36Sopenharmony_ci return -EOPNOTSUPP; 363162306a36Sopenharmony_ci } 363262306a36Sopenharmony_ci 363362306a36Sopenharmony_ci /* RSS does not support anything other than hashing 363462306a36Sopenharmony_ci * to queues on src and dst IPs and ports 363562306a36Sopenharmony_ci */ 363662306a36Sopenharmony_ci if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST | 363762306a36Sopenharmony_ci RXH_L4_B_0_1 | RXH_L4_B_2_3)) 363862306a36Sopenharmony_ci return -EINVAL; 363962306a36Sopenharmony_ci 364062306a36Sopenharmony_ci switch (nfc->flow_type) { 364162306a36Sopenharmony_ci case TCP_V4_FLOW: 364262306a36Sopenharmony_ci set_bit(I40E_FILTER_PCTYPE_NONF_IPV4_TCP, flow_pctypes); 364362306a36Sopenharmony_ci if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE) 364462306a36Sopenharmony_ci set_bit(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK, 364562306a36Sopenharmony_ci flow_pctypes); 364662306a36Sopenharmony_ci break; 364762306a36Sopenharmony_ci case TCP_V6_FLOW: 364862306a36Sopenharmony_ci set_bit(I40E_FILTER_PCTYPE_NONF_IPV6_TCP, flow_pctypes); 364962306a36Sopenharmony_ci if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE) 365062306a36Sopenharmony_ci set_bit(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK, 365162306a36Sopenharmony_ci flow_pctypes); 365262306a36Sopenharmony_ci break; 365362306a36Sopenharmony_ci case UDP_V4_FLOW: 365462306a36Sopenharmony_ci set_bit(I40E_FILTER_PCTYPE_NONF_IPV4_UDP, flow_pctypes); 365562306a36Sopenharmony_ci if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE) { 365662306a36Sopenharmony_ci set_bit(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP, 365762306a36Sopenharmony_ci flow_pctypes); 365862306a36Sopenharmony_ci set_bit(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP, 365962306a36Sopenharmony_ci flow_pctypes); 366062306a36Sopenharmony_ci } 366162306a36Sopenharmony_ci hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4); 366262306a36Sopenharmony_ci break; 366362306a36Sopenharmony_ci case UDP_V6_FLOW: 366462306a36Sopenharmony_ci set_bit(I40E_FILTER_PCTYPE_NONF_IPV6_UDP, flow_pctypes); 366562306a36Sopenharmony_ci if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE) { 366662306a36Sopenharmony_ci set_bit(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP, 366762306a36Sopenharmony_ci flow_pctypes); 366862306a36Sopenharmony_ci set_bit(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP, 366962306a36Sopenharmony_ci flow_pctypes); 367062306a36Sopenharmony_ci } 367162306a36Sopenharmony_ci hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6); 367262306a36Sopenharmony_ci break; 367362306a36Sopenharmony_ci case AH_ESP_V4_FLOW: 367462306a36Sopenharmony_ci case AH_V4_FLOW: 367562306a36Sopenharmony_ci case ESP_V4_FLOW: 367662306a36Sopenharmony_ci case SCTP_V4_FLOW: 367762306a36Sopenharmony_ci if ((nfc->data & RXH_L4_B_0_1) || 367862306a36Sopenharmony_ci (nfc->data & RXH_L4_B_2_3)) 367962306a36Sopenharmony_ci return -EINVAL; 368062306a36Sopenharmony_ci hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER); 368162306a36Sopenharmony_ci break; 368262306a36Sopenharmony_ci case AH_ESP_V6_FLOW: 368362306a36Sopenharmony_ci case AH_V6_FLOW: 368462306a36Sopenharmony_ci case ESP_V6_FLOW: 368562306a36Sopenharmony_ci case SCTP_V6_FLOW: 368662306a36Sopenharmony_ci if ((nfc->data & RXH_L4_B_0_1) || 368762306a36Sopenharmony_ci (nfc->data & RXH_L4_B_2_3)) 368862306a36Sopenharmony_ci return -EINVAL; 368962306a36Sopenharmony_ci hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER); 369062306a36Sopenharmony_ci break; 369162306a36Sopenharmony_ci case IPV4_FLOW: 369262306a36Sopenharmony_ci hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | 369362306a36Sopenharmony_ci BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4); 369462306a36Sopenharmony_ci break; 369562306a36Sopenharmony_ci case IPV6_FLOW: 369662306a36Sopenharmony_ci hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | 369762306a36Sopenharmony_ci BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6); 369862306a36Sopenharmony_ci break; 369962306a36Sopenharmony_ci default: 370062306a36Sopenharmony_ci return -EINVAL; 370162306a36Sopenharmony_ci } 370262306a36Sopenharmony_ci 370362306a36Sopenharmony_ci if (bitmap_weight(flow_pctypes, FLOW_PCTYPES_SIZE)) { 370462306a36Sopenharmony_ci u8 flow_id; 370562306a36Sopenharmony_ci 370662306a36Sopenharmony_ci for_each_set_bit(flow_id, flow_pctypes, FLOW_PCTYPES_SIZE) { 370762306a36Sopenharmony_ci i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_id)) | 370862306a36Sopenharmony_ci ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_id)) << 32); 370962306a36Sopenharmony_ci i_set = i40e_get_rss_hash_bits(&pf->hw, nfc, i_setc); 371062306a36Sopenharmony_ci 371162306a36Sopenharmony_ci i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_id), 371262306a36Sopenharmony_ci (u32)i_set); 371362306a36Sopenharmony_ci i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_id), 371462306a36Sopenharmony_ci (u32)(i_set >> 32)); 371562306a36Sopenharmony_ci hena |= BIT_ULL(flow_id); 371662306a36Sopenharmony_ci } 371762306a36Sopenharmony_ci } 371862306a36Sopenharmony_ci 371962306a36Sopenharmony_ci i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); 372062306a36Sopenharmony_ci i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); 372162306a36Sopenharmony_ci i40e_flush(hw); 372262306a36Sopenharmony_ci 372362306a36Sopenharmony_ci return 0; 372462306a36Sopenharmony_ci} 372562306a36Sopenharmony_ci 372662306a36Sopenharmony_ci/** 372762306a36Sopenharmony_ci * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry 372862306a36Sopenharmony_ci * @vsi: Pointer to the targeted VSI 372962306a36Sopenharmony_ci * @input: The filter to update or NULL to indicate deletion 373062306a36Sopenharmony_ci * @sw_idx: Software index to the filter 373162306a36Sopenharmony_ci * @cmd: The command to get or set Rx flow classification rules 373262306a36Sopenharmony_ci * 373362306a36Sopenharmony_ci * This function updates (or deletes) a Flow Director entry from 373462306a36Sopenharmony_ci * the hlist of the corresponding PF 373562306a36Sopenharmony_ci * 373662306a36Sopenharmony_ci * Returns 0 on success 373762306a36Sopenharmony_ci **/ 373862306a36Sopenharmony_cistatic int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi, 373962306a36Sopenharmony_ci struct i40e_fdir_filter *input, 374062306a36Sopenharmony_ci u16 sw_idx, 374162306a36Sopenharmony_ci struct ethtool_rxnfc *cmd) 374262306a36Sopenharmony_ci{ 374362306a36Sopenharmony_ci struct i40e_fdir_filter *rule, *parent; 374462306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 374562306a36Sopenharmony_ci struct hlist_node *node2; 374662306a36Sopenharmony_ci int err = -EINVAL; 374762306a36Sopenharmony_ci 374862306a36Sopenharmony_ci parent = NULL; 374962306a36Sopenharmony_ci rule = NULL; 375062306a36Sopenharmony_ci 375162306a36Sopenharmony_ci hlist_for_each_entry_safe(rule, node2, 375262306a36Sopenharmony_ci &pf->fdir_filter_list, fdir_node) { 375362306a36Sopenharmony_ci /* hash found, or no matching entry */ 375462306a36Sopenharmony_ci if (rule->fd_id >= sw_idx) 375562306a36Sopenharmony_ci break; 375662306a36Sopenharmony_ci parent = rule; 375762306a36Sopenharmony_ci } 375862306a36Sopenharmony_ci 375962306a36Sopenharmony_ci /* if there is an old rule occupying our place remove it */ 376062306a36Sopenharmony_ci if (rule && (rule->fd_id == sw_idx)) { 376162306a36Sopenharmony_ci /* Remove this rule, since we're either deleting it, or 376262306a36Sopenharmony_ci * replacing it. 376362306a36Sopenharmony_ci */ 376462306a36Sopenharmony_ci err = i40e_add_del_fdir(vsi, rule, false); 376562306a36Sopenharmony_ci hlist_del(&rule->fdir_node); 376662306a36Sopenharmony_ci kfree(rule); 376762306a36Sopenharmony_ci pf->fdir_pf_active_filters--; 376862306a36Sopenharmony_ci } 376962306a36Sopenharmony_ci 377062306a36Sopenharmony_ci /* If we weren't given an input, this is a delete, so just return the 377162306a36Sopenharmony_ci * error code indicating if there was an entry at the requested slot 377262306a36Sopenharmony_ci */ 377362306a36Sopenharmony_ci if (!input) 377462306a36Sopenharmony_ci return err; 377562306a36Sopenharmony_ci 377662306a36Sopenharmony_ci /* Otherwise, install the new rule as requested */ 377762306a36Sopenharmony_ci INIT_HLIST_NODE(&input->fdir_node); 377862306a36Sopenharmony_ci 377962306a36Sopenharmony_ci /* add filter to the list */ 378062306a36Sopenharmony_ci if (parent) 378162306a36Sopenharmony_ci hlist_add_behind(&input->fdir_node, &parent->fdir_node); 378262306a36Sopenharmony_ci else 378362306a36Sopenharmony_ci hlist_add_head(&input->fdir_node, 378462306a36Sopenharmony_ci &pf->fdir_filter_list); 378562306a36Sopenharmony_ci 378662306a36Sopenharmony_ci /* update counts */ 378762306a36Sopenharmony_ci pf->fdir_pf_active_filters++; 378862306a36Sopenharmony_ci 378962306a36Sopenharmony_ci return 0; 379062306a36Sopenharmony_ci} 379162306a36Sopenharmony_ci 379262306a36Sopenharmony_ci/** 379362306a36Sopenharmony_ci * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table 379462306a36Sopenharmony_ci * @pf: pointer to PF structure 379562306a36Sopenharmony_ci * 379662306a36Sopenharmony_ci * This function searches the list of filters and determines which FLX_PIT 379762306a36Sopenharmony_ci * entries are still required. It will prune any entries which are no longer 379862306a36Sopenharmony_ci * in use after the deletion. 379962306a36Sopenharmony_ci **/ 380062306a36Sopenharmony_cistatic void i40e_prune_flex_pit_list(struct i40e_pf *pf) 380162306a36Sopenharmony_ci{ 380262306a36Sopenharmony_ci struct i40e_flex_pit *entry, *tmp; 380362306a36Sopenharmony_ci struct i40e_fdir_filter *rule; 380462306a36Sopenharmony_ci 380562306a36Sopenharmony_ci /* First, we'll check the l3 table */ 380662306a36Sopenharmony_ci list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) { 380762306a36Sopenharmony_ci bool found = false; 380862306a36Sopenharmony_ci 380962306a36Sopenharmony_ci hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) { 381062306a36Sopenharmony_ci if (rule->flow_type != IP_USER_FLOW) 381162306a36Sopenharmony_ci continue; 381262306a36Sopenharmony_ci if (rule->flex_filter && 381362306a36Sopenharmony_ci rule->flex_offset == entry->src_offset) { 381462306a36Sopenharmony_ci found = true; 381562306a36Sopenharmony_ci break; 381662306a36Sopenharmony_ci } 381762306a36Sopenharmony_ci } 381862306a36Sopenharmony_ci 381962306a36Sopenharmony_ci /* If we didn't find the filter, then we can prune this entry 382062306a36Sopenharmony_ci * from the list. 382162306a36Sopenharmony_ci */ 382262306a36Sopenharmony_ci if (!found) { 382362306a36Sopenharmony_ci list_del(&entry->list); 382462306a36Sopenharmony_ci kfree(entry); 382562306a36Sopenharmony_ci } 382662306a36Sopenharmony_ci } 382762306a36Sopenharmony_ci 382862306a36Sopenharmony_ci /* Followed by the L4 table */ 382962306a36Sopenharmony_ci list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) { 383062306a36Sopenharmony_ci bool found = false; 383162306a36Sopenharmony_ci 383262306a36Sopenharmony_ci hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) { 383362306a36Sopenharmony_ci /* Skip this filter if it's L3, since we already 383462306a36Sopenharmony_ci * checked those in the above loop 383562306a36Sopenharmony_ci */ 383662306a36Sopenharmony_ci if (rule->flow_type == IP_USER_FLOW) 383762306a36Sopenharmony_ci continue; 383862306a36Sopenharmony_ci if (rule->flex_filter && 383962306a36Sopenharmony_ci rule->flex_offset == entry->src_offset) { 384062306a36Sopenharmony_ci found = true; 384162306a36Sopenharmony_ci break; 384262306a36Sopenharmony_ci } 384362306a36Sopenharmony_ci } 384462306a36Sopenharmony_ci 384562306a36Sopenharmony_ci /* If we didn't find the filter, then we can prune this entry 384662306a36Sopenharmony_ci * from the list. 384762306a36Sopenharmony_ci */ 384862306a36Sopenharmony_ci if (!found) { 384962306a36Sopenharmony_ci list_del(&entry->list); 385062306a36Sopenharmony_ci kfree(entry); 385162306a36Sopenharmony_ci } 385262306a36Sopenharmony_ci } 385362306a36Sopenharmony_ci} 385462306a36Sopenharmony_ci 385562306a36Sopenharmony_ci/** 385662306a36Sopenharmony_ci * i40e_del_fdir_entry - Deletes a Flow Director filter entry 385762306a36Sopenharmony_ci * @vsi: Pointer to the targeted VSI 385862306a36Sopenharmony_ci * @cmd: The command to get or set Rx flow classification rules 385962306a36Sopenharmony_ci * 386062306a36Sopenharmony_ci * The function removes a Flow Director filter entry from the 386162306a36Sopenharmony_ci * hlist of the corresponding PF 386262306a36Sopenharmony_ci * 386362306a36Sopenharmony_ci * Returns 0 on success 386462306a36Sopenharmony_ci */ 386562306a36Sopenharmony_cistatic int i40e_del_fdir_entry(struct i40e_vsi *vsi, 386662306a36Sopenharmony_ci struct ethtool_rxnfc *cmd) 386762306a36Sopenharmony_ci{ 386862306a36Sopenharmony_ci struct ethtool_rx_flow_spec *fsp = 386962306a36Sopenharmony_ci (struct ethtool_rx_flow_spec *)&cmd->fs; 387062306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 387162306a36Sopenharmony_ci int ret = 0; 387262306a36Sopenharmony_ci 387362306a36Sopenharmony_ci if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) || 387462306a36Sopenharmony_ci test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) 387562306a36Sopenharmony_ci return -EBUSY; 387662306a36Sopenharmony_ci 387762306a36Sopenharmony_ci if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state)) 387862306a36Sopenharmony_ci return -EBUSY; 387962306a36Sopenharmony_ci 388062306a36Sopenharmony_ci ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd); 388162306a36Sopenharmony_ci 388262306a36Sopenharmony_ci i40e_prune_flex_pit_list(pf); 388362306a36Sopenharmony_ci 388462306a36Sopenharmony_ci i40e_fdir_check_and_reenable(pf); 388562306a36Sopenharmony_ci return ret; 388662306a36Sopenharmony_ci} 388762306a36Sopenharmony_ci 388862306a36Sopenharmony_ci/** 388962306a36Sopenharmony_ci * i40e_unused_pit_index - Find an unused PIT index for given list 389062306a36Sopenharmony_ci * @pf: the PF data structure 389162306a36Sopenharmony_ci * 389262306a36Sopenharmony_ci * Find the first unused flexible PIT index entry. We search both the L3 and 389362306a36Sopenharmony_ci * L4 flexible PIT lists so that the returned index is unique and unused by 389462306a36Sopenharmony_ci * either currently programmed L3 or L4 filters. We use a bit field as storage 389562306a36Sopenharmony_ci * to track which indexes are already used. 389662306a36Sopenharmony_ci **/ 389762306a36Sopenharmony_cistatic u8 i40e_unused_pit_index(struct i40e_pf *pf) 389862306a36Sopenharmony_ci{ 389962306a36Sopenharmony_ci unsigned long available_index = 0xFF; 390062306a36Sopenharmony_ci struct i40e_flex_pit *entry; 390162306a36Sopenharmony_ci 390262306a36Sopenharmony_ci /* We need to make sure that the new index isn't in use by either L3 390362306a36Sopenharmony_ci * or L4 filters so that IP_USER_FLOW filters can program both L3 and 390462306a36Sopenharmony_ci * L4 to use the same index. 390562306a36Sopenharmony_ci */ 390662306a36Sopenharmony_ci 390762306a36Sopenharmony_ci list_for_each_entry(entry, &pf->l4_flex_pit_list, list) 390862306a36Sopenharmony_ci clear_bit(entry->pit_index, &available_index); 390962306a36Sopenharmony_ci 391062306a36Sopenharmony_ci list_for_each_entry(entry, &pf->l3_flex_pit_list, list) 391162306a36Sopenharmony_ci clear_bit(entry->pit_index, &available_index); 391262306a36Sopenharmony_ci 391362306a36Sopenharmony_ci return find_first_bit(&available_index, 8); 391462306a36Sopenharmony_ci} 391562306a36Sopenharmony_ci 391662306a36Sopenharmony_ci/** 391762306a36Sopenharmony_ci * i40e_find_flex_offset - Find an existing flex src_offset 391862306a36Sopenharmony_ci * @flex_pit_list: L3 or L4 flex PIT list 391962306a36Sopenharmony_ci * @src_offset: new src_offset to find 392062306a36Sopenharmony_ci * 392162306a36Sopenharmony_ci * Searches the flex_pit_list for an existing offset. If no offset is 392262306a36Sopenharmony_ci * currently programmed, then this will return an ERR_PTR if there is no space 392362306a36Sopenharmony_ci * to add a new offset, otherwise it returns NULL. 392462306a36Sopenharmony_ci **/ 392562306a36Sopenharmony_cistatic 392662306a36Sopenharmony_cistruct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list, 392762306a36Sopenharmony_ci u16 src_offset) 392862306a36Sopenharmony_ci{ 392962306a36Sopenharmony_ci struct i40e_flex_pit *entry; 393062306a36Sopenharmony_ci int size = 0; 393162306a36Sopenharmony_ci 393262306a36Sopenharmony_ci /* Search for the src_offset first. If we find a matching entry 393362306a36Sopenharmony_ci * already programmed, we can simply re-use it. 393462306a36Sopenharmony_ci */ 393562306a36Sopenharmony_ci list_for_each_entry(entry, flex_pit_list, list) { 393662306a36Sopenharmony_ci size++; 393762306a36Sopenharmony_ci if (entry->src_offset == src_offset) 393862306a36Sopenharmony_ci return entry; 393962306a36Sopenharmony_ci } 394062306a36Sopenharmony_ci 394162306a36Sopenharmony_ci /* If we haven't found an entry yet, then the provided src offset has 394262306a36Sopenharmony_ci * not yet been programmed. We will program the src offset later on, 394362306a36Sopenharmony_ci * but we need to indicate whether there is enough space to do so 394462306a36Sopenharmony_ci * here. We'll make use of ERR_PTR for this purpose. 394562306a36Sopenharmony_ci */ 394662306a36Sopenharmony_ci if (size >= I40E_FLEX_PIT_TABLE_SIZE) 394762306a36Sopenharmony_ci return ERR_PTR(-ENOSPC); 394862306a36Sopenharmony_ci 394962306a36Sopenharmony_ci return NULL; 395062306a36Sopenharmony_ci} 395162306a36Sopenharmony_ci 395262306a36Sopenharmony_ci/** 395362306a36Sopenharmony_ci * i40e_add_flex_offset - Add src_offset to flex PIT table list 395462306a36Sopenharmony_ci * @flex_pit_list: L3 or L4 flex PIT list 395562306a36Sopenharmony_ci * @src_offset: new src_offset to add 395662306a36Sopenharmony_ci * @pit_index: the PIT index to program 395762306a36Sopenharmony_ci * 395862306a36Sopenharmony_ci * This function programs the new src_offset to the list. It is expected that 395962306a36Sopenharmony_ci * i40e_find_flex_offset has already been tried and returned NULL, indicating 396062306a36Sopenharmony_ci * that this offset is not programmed, and that the list has enough space to 396162306a36Sopenharmony_ci * store another offset. 396262306a36Sopenharmony_ci * 396362306a36Sopenharmony_ci * Returns 0 on success, and negative value on error. 396462306a36Sopenharmony_ci **/ 396562306a36Sopenharmony_cistatic int i40e_add_flex_offset(struct list_head *flex_pit_list, 396662306a36Sopenharmony_ci u16 src_offset, 396762306a36Sopenharmony_ci u8 pit_index) 396862306a36Sopenharmony_ci{ 396962306a36Sopenharmony_ci struct i40e_flex_pit *new_pit, *entry; 397062306a36Sopenharmony_ci 397162306a36Sopenharmony_ci new_pit = kzalloc(sizeof(*entry), GFP_KERNEL); 397262306a36Sopenharmony_ci if (!new_pit) 397362306a36Sopenharmony_ci return -ENOMEM; 397462306a36Sopenharmony_ci 397562306a36Sopenharmony_ci new_pit->src_offset = src_offset; 397662306a36Sopenharmony_ci new_pit->pit_index = pit_index; 397762306a36Sopenharmony_ci 397862306a36Sopenharmony_ci /* We need to insert this item such that the list is sorted by 397962306a36Sopenharmony_ci * src_offset in ascending order. 398062306a36Sopenharmony_ci */ 398162306a36Sopenharmony_ci list_for_each_entry(entry, flex_pit_list, list) { 398262306a36Sopenharmony_ci if (new_pit->src_offset < entry->src_offset) { 398362306a36Sopenharmony_ci list_add_tail(&new_pit->list, &entry->list); 398462306a36Sopenharmony_ci return 0; 398562306a36Sopenharmony_ci } 398662306a36Sopenharmony_ci 398762306a36Sopenharmony_ci /* If we found an entry with our offset already programmed we 398862306a36Sopenharmony_ci * can simply return here, after freeing the memory. However, 398962306a36Sopenharmony_ci * if the pit_index does not match we need to report an error. 399062306a36Sopenharmony_ci */ 399162306a36Sopenharmony_ci if (new_pit->src_offset == entry->src_offset) { 399262306a36Sopenharmony_ci int err = 0; 399362306a36Sopenharmony_ci 399462306a36Sopenharmony_ci /* If the PIT index is not the same we can't re-use 399562306a36Sopenharmony_ci * the entry, so we must report an error. 399662306a36Sopenharmony_ci */ 399762306a36Sopenharmony_ci if (new_pit->pit_index != entry->pit_index) 399862306a36Sopenharmony_ci err = -EINVAL; 399962306a36Sopenharmony_ci 400062306a36Sopenharmony_ci kfree(new_pit); 400162306a36Sopenharmony_ci return err; 400262306a36Sopenharmony_ci } 400362306a36Sopenharmony_ci } 400462306a36Sopenharmony_ci 400562306a36Sopenharmony_ci /* If we reached here, then we haven't yet added the item. This means 400662306a36Sopenharmony_ci * that we should add the item at the end of the list. 400762306a36Sopenharmony_ci */ 400862306a36Sopenharmony_ci list_add_tail(&new_pit->list, flex_pit_list); 400962306a36Sopenharmony_ci return 0; 401062306a36Sopenharmony_ci} 401162306a36Sopenharmony_ci 401262306a36Sopenharmony_ci/** 401362306a36Sopenharmony_ci * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table 401462306a36Sopenharmony_ci * @pf: Pointer to the PF structure 401562306a36Sopenharmony_ci * @flex_pit_list: list of flexible src offsets in use 401662306a36Sopenharmony_ci * @flex_pit_start: index to first entry for this section of the table 401762306a36Sopenharmony_ci * 401862306a36Sopenharmony_ci * In order to handle flexible data, the hardware uses a table of values 401962306a36Sopenharmony_ci * called the FLX_PIT table. This table is used to indicate which sections of 402062306a36Sopenharmony_ci * the input correspond to what PIT index values. Unfortunately, hardware is 402162306a36Sopenharmony_ci * very restrictive about programming this table. Entries must be ordered by 402262306a36Sopenharmony_ci * src_offset in ascending order, without duplicates. Additionally, unused 402362306a36Sopenharmony_ci * entries must be set to the unused index value, and must have valid size and 402462306a36Sopenharmony_ci * length according to the src_offset ordering. 402562306a36Sopenharmony_ci * 402662306a36Sopenharmony_ci * This function will reprogram the FLX_PIT register from a book-keeping 402762306a36Sopenharmony_ci * structure that we guarantee is already ordered correctly, and has no more 402862306a36Sopenharmony_ci * than 3 entries. 402962306a36Sopenharmony_ci * 403062306a36Sopenharmony_ci * To make things easier, we only support flexible values of one word length, 403162306a36Sopenharmony_ci * rather than allowing variable length flexible values. 403262306a36Sopenharmony_ci **/ 403362306a36Sopenharmony_cistatic void __i40e_reprogram_flex_pit(struct i40e_pf *pf, 403462306a36Sopenharmony_ci struct list_head *flex_pit_list, 403562306a36Sopenharmony_ci int flex_pit_start) 403662306a36Sopenharmony_ci{ 403762306a36Sopenharmony_ci struct i40e_flex_pit *entry = NULL; 403862306a36Sopenharmony_ci u16 last_offset = 0; 403962306a36Sopenharmony_ci int i = 0, j = 0; 404062306a36Sopenharmony_ci 404162306a36Sopenharmony_ci /* First, loop over the list of flex PIT entries, and reprogram the 404262306a36Sopenharmony_ci * registers. 404362306a36Sopenharmony_ci */ 404462306a36Sopenharmony_ci list_for_each_entry(entry, flex_pit_list, list) { 404562306a36Sopenharmony_ci /* We have to be careful when programming values for the 404662306a36Sopenharmony_ci * largest SRC_OFFSET value. It is possible that adding 404762306a36Sopenharmony_ci * additional empty values at the end would overflow the space 404862306a36Sopenharmony_ci * for the SRC_OFFSET in the FLX_PIT register. To avoid this, 404962306a36Sopenharmony_ci * we check here and add the empty values prior to adding the 405062306a36Sopenharmony_ci * largest value. 405162306a36Sopenharmony_ci * 405262306a36Sopenharmony_ci * To determine this, we will use a loop from i+1 to 3, which 405362306a36Sopenharmony_ci * will determine whether the unused entries would have valid 405462306a36Sopenharmony_ci * SRC_OFFSET. Note that there cannot be extra entries past 405562306a36Sopenharmony_ci * this value, because the only valid values would have been 405662306a36Sopenharmony_ci * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not 405762306a36Sopenharmony_ci * have been added to the list in the first place. 405862306a36Sopenharmony_ci */ 405962306a36Sopenharmony_ci for (j = i + 1; j < 3; j++) { 406062306a36Sopenharmony_ci u16 offset = entry->src_offset + j; 406162306a36Sopenharmony_ci int index = flex_pit_start + i; 406262306a36Sopenharmony_ci u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED, 406362306a36Sopenharmony_ci 1, 406462306a36Sopenharmony_ci offset - 3); 406562306a36Sopenharmony_ci 406662306a36Sopenharmony_ci if (offset > I40E_MAX_FLEX_SRC_OFFSET) { 406762306a36Sopenharmony_ci i40e_write_rx_ctl(&pf->hw, 406862306a36Sopenharmony_ci I40E_PRTQF_FLX_PIT(index), 406962306a36Sopenharmony_ci value); 407062306a36Sopenharmony_ci i++; 407162306a36Sopenharmony_ci } 407262306a36Sopenharmony_ci } 407362306a36Sopenharmony_ci 407462306a36Sopenharmony_ci /* Now, we can program the actual value into the table */ 407562306a36Sopenharmony_ci i40e_write_rx_ctl(&pf->hw, 407662306a36Sopenharmony_ci I40E_PRTQF_FLX_PIT(flex_pit_start + i), 407762306a36Sopenharmony_ci I40E_FLEX_PREP_VAL(entry->pit_index + 50, 407862306a36Sopenharmony_ci 1, 407962306a36Sopenharmony_ci entry->src_offset)); 408062306a36Sopenharmony_ci i++; 408162306a36Sopenharmony_ci } 408262306a36Sopenharmony_ci 408362306a36Sopenharmony_ci /* In order to program the last entries in the table, we need to 408462306a36Sopenharmony_ci * determine the valid offset. If the list is empty, we'll just start 408562306a36Sopenharmony_ci * with 0. Otherwise, we'll start with the last item offset and add 1. 408662306a36Sopenharmony_ci * This ensures that all entries have valid sizes. If we don't do this 408762306a36Sopenharmony_ci * correctly, the hardware will disable flexible field parsing. 408862306a36Sopenharmony_ci */ 408962306a36Sopenharmony_ci if (!list_empty(flex_pit_list)) 409062306a36Sopenharmony_ci last_offset = list_prev_entry(entry, list)->src_offset + 1; 409162306a36Sopenharmony_ci 409262306a36Sopenharmony_ci for (; i < 3; i++, last_offset++) { 409362306a36Sopenharmony_ci i40e_write_rx_ctl(&pf->hw, 409462306a36Sopenharmony_ci I40E_PRTQF_FLX_PIT(flex_pit_start + i), 409562306a36Sopenharmony_ci I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED, 409662306a36Sopenharmony_ci 1, 409762306a36Sopenharmony_ci last_offset)); 409862306a36Sopenharmony_ci } 409962306a36Sopenharmony_ci} 410062306a36Sopenharmony_ci 410162306a36Sopenharmony_ci/** 410262306a36Sopenharmony_ci * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change 410362306a36Sopenharmony_ci * @pf: pointer to the PF structure 410462306a36Sopenharmony_ci * 410562306a36Sopenharmony_ci * This function reprograms both the L3 and L4 FLX_PIT tables. See the 410662306a36Sopenharmony_ci * internal helper function for implementation details. 410762306a36Sopenharmony_ci **/ 410862306a36Sopenharmony_cistatic void i40e_reprogram_flex_pit(struct i40e_pf *pf) 410962306a36Sopenharmony_ci{ 411062306a36Sopenharmony_ci __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list, 411162306a36Sopenharmony_ci I40E_FLEX_PIT_IDX_START_L3); 411262306a36Sopenharmony_ci 411362306a36Sopenharmony_ci __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list, 411462306a36Sopenharmony_ci I40E_FLEX_PIT_IDX_START_L4); 411562306a36Sopenharmony_ci 411662306a36Sopenharmony_ci /* We also need to program the L3 and L4 GLQF ORT register */ 411762306a36Sopenharmony_ci i40e_write_rx_ctl(&pf->hw, 411862306a36Sopenharmony_ci I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX), 411962306a36Sopenharmony_ci I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3, 412062306a36Sopenharmony_ci 3, 1)); 412162306a36Sopenharmony_ci 412262306a36Sopenharmony_ci i40e_write_rx_ctl(&pf->hw, 412362306a36Sopenharmony_ci I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX), 412462306a36Sopenharmony_ci I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4, 412562306a36Sopenharmony_ci 3, 1)); 412662306a36Sopenharmony_ci} 412762306a36Sopenharmony_ci 412862306a36Sopenharmony_ci/** 412962306a36Sopenharmony_ci * i40e_flow_str - Converts a flow_type into a human readable string 413062306a36Sopenharmony_ci * @fsp: the flow specification 413162306a36Sopenharmony_ci * 413262306a36Sopenharmony_ci * Currently only flow types we support are included here, and the string 413362306a36Sopenharmony_ci * value attempts to match what ethtool would use to configure this flow type. 413462306a36Sopenharmony_ci **/ 413562306a36Sopenharmony_cistatic const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp) 413662306a36Sopenharmony_ci{ 413762306a36Sopenharmony_ci switch (fsp->flow_type & ~FLOW_EXT) { 413862306a36Sopenharmony_ci case TCP_V4_FLOW: 413962306a36Sopenharmony_ci return "tcp4"; 414062306a36Sopenharmony_ci case UDP_V4_FLOW: 414162306a36Sopenharmony_ci return "udp4"; 414262306a36Sopenharmony_ci case SCTP_V4_FLOW: 414362306a36Sopenharmony_ci return "sctp4"; 414462306a36Sopenharmony_ci case IP_USER_FLOW: 414562306a36Sopenharmony_ci return "ip4"; 414662306a36Sopenharmony_ci case TCP_V6_FLOW: 414762306a36Sopenharmony_ci return "tcp6"; 414862306a36Sopenharmony_ci case UDP_V6_FLOW: 414962306a36Sopenharmony_ci return "udp6"; 415062306a36Sopenharmony_ci case SCTP_V6_FLOW: 415162306a36Sopenharmony_ci return "sctp6"; 415262306a36Sopenharmony_ci case IPV6_USER_FLOW: 415362306a36Sopenharmony_ci return "ip6"; 415462306a36Sopenharmony_ci default: 415562306a36Sopenharmony_ci return "unknown"; 415662306a36Sopenharmony_ci } 415762306a36Sopenharmony_ci} 415862306a36Sopenharmony_ci 415962306a36Sopenharmony_ci/** 416062306a36Sopenharmony_ci * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index 416162306a36Sopenharmony_ci * @pit_index: PIT index to convert 416262306a36Sopenharmony_ci * 416362306a36Sopenharmony_ci * Returns the mask for a given PIT index. Will return 0 if the pit_index is 416462306a36Sopenharmony_ci * of range. 416562306a36Sopenharmony_ci **/ 416662306a36Sopenharmony_cistatic u64 i40e_pit_index_to_mask(int pit_index) 416762306a36Sopenharmony_ci{ 416862306a36Sopenharmony_ci switch (pit_index) { 416962306a36Sopenharmony_ci case 0: 417062306a36Sopenharmony_ci return I40E_FLEX_50_MASK; 417162306a36Sopenharmony_ci case 1: 417262306a36Sopenharmony_ci return I40E_FLEX_51_MASK; 417362306a36Sopenharmony_ci case 2: 417462306a36Sopenharmony_ci return I40E_FLEX_52_MASK; 417562306a36Sopenharmony_ci case 3: 417662306a36Sopenharmony_ci return I40E_FLEX_53_MASK; 417762306a36Sopenharmony_ci case 4: 417862306a36Sopenharmony_ci return I40E_FLEX_54_MASK; 417962306a36Sopenharmony_ci case 5: 418062306a36Sopenharmony_ci return I40E_FLEX_55_MASK; 418162306a36Sopenharmony_ci case 6: 418262306a36Sopenharmony_ci return I40E_FLEX_56_MASK; 418362306a36Sopenharmony_ci case 7: 418462306a36Sopenharmony_ci return I40E_FLEX_57_MASK; 418562306a36Sopenharmony_ci default: 418662306a36Sopenharmony_ci return 0; 418762306a36Sopenharmony_ci } 418862306a36Sopenharmony_ci} 418962306a36Sopenharmony_ci 419062306a36Sopenharmony_ci/** 419162306a36Sopenharmony_ci * i40e_print_input_set - Show changes between two input sets 419262306a36Sopenharmony_ci * @vsi: the vsi being configured 419362306a36Sopenharmony_ci * @old: the old input set 419462306a36Sopenharmony_ci * @new: the new input set 419562306a36Sopenharmony_ci * 419662306a36Sopenharmony_ci * Print the difference between old and new input sets by showing which series 419762306a36Sopenharmony_ci * of words are toggled on or off. Only displays the bits we actually support 419862306a36Sopenharmony_ci * changing. 419962306a36Sopenharmony_ci **/ 420062306a36Sopenharmony_cistatic void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new) 420162306a36Sopenharmony_ci{ 420262306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 420362306a36Sopenharmony_ci bool old_value, new_value; 420462306a36Sopenharmony_ci int i; 420562306a36Sopenharmony_ci 420662306a36Sopenharmony_ci old_value = !!(old & I40E_L3_SRC_MASK); 420762306a36Sopenharmony_ci new_value = !!(new & I40E_L3_SRC_MASK); 420862306a36Sopenharmony_ci if (old_value != new_value) 420962306a36Sopenharmony_ci netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n", 421062306a36Sopenharmony_ci old_value ? "ON" : "OFF", 421162306a36Sopenharmony_ci new_value ? "ON" : "OFF"); 421262306a36Sopenharmony_ci 421362306a36Sopenharmony_ci old_value = !!(old & I40E_L3_DST_MASK); 421462306a36Sopenharmony_ci new_value = !!(new & I40E_L3_DST_MASK); 421562306a36Sopenharmony_ci if (old_value != new_value) 421662306a36Sopenharmony_ci netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n", 421762306a36Sopenharmony_ci old_value ? "ON" : "OFF", 421862306a36Sopenharmony_ci new_value ? "ON" : "OFF"); 421962306a36Sopenharmony_ci 422062306a36Sopenharmony_ci old_value = !!(old & I40E_L4_SRC_MASK); 422162306a36Sopenharmony_ci new_value = !!(new & I40E_L4_SRC_MASK); 422262306a36Sopenharmony_ci if (old_value != new_value) 422362306a36Sopenharmony_ci netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n", 422462306a36Sopenharmony_ci old_value ? "ON" : "OFF", 422562306a36Sopenharmony_ci new_value ? "ON" : "OFF"); 422662306a36Sopenharmony_ci 422762306a36Sopenharmony_ci old_value = !!(old & I40E_L4_DST_MASK); 422862306a36Sopenharmony_ci new_value = !!(new & I40E_L4_DST_MASK); 422962306a36Sopenharmony_ci if (old_value != new_value) 423062306a36Sopenharmony_ci netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n", 423162306a36Sopenharmony_ci old_value ? "ON" : "OFF", 423262306a36Sopenharmony_ci new_value ? "ON" : "OFF"); 423362306a36Sopenharmony_ci 423462306a36Sopenharmony_ci old_value = !!(old & I40E_VERIFY_TAG_MASK); 423562306a36Sopenharmony_ci new_value = !!(new & I40E_VERIFY_TAG_MASK); 423662306a36Sopenharmony_ci if (old_value != new_value) 423762306a36Sopenharmony_ci netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n", 423862306a36Sopenharmony_ci old_value ? "ON" : "OFF", 423962306a36Sopenharmony_ci new_value ? "ON" : "OFF"); 424062306a36Sopenharmony_ci 424162306a36Sopenharmony_ci /* Show change of flexible filter entries */ 424262306a36Sopenharmony_ci for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) { 424362306a36Sopenharmony_ci u64 flex_mask = i40e_pit_index_to_mask(i); 424462306a36Sopenharmony_ci 424562306a36Sopenharmony_ci old_value = !!(old & flex_mask); 424662306a36Sopenharmony_ci new_value = !!(new & flex_mask); 424762306a36Sopenharmony_ci if (old_value != new_value) 424862306a36Sopenharmony_ci netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n", 424962306a36Sopenharmony_ci i, 425062306a36Sopenharmony_ci old_value ? "ON" : "OFF", 425162306a36Sopenharmony_ci new_value ? "ON" : "OFF"); 425262306a36Sopenharmony_ci } 425362306a36Sopenharmony_ci 425462306a36Sopenharmony_ci netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n", 425562306a36Sopenharmony_ci old); 425662306a36Sopenharmony_ci netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n", 425762306a36Sopenharmony_ci new); 425862306a36Sopenharmony_ci} 425962306a36Sopenharmony_ci 426062306a36Sopenharmony_ci/** 426162306a36Sopenharmony_ci * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid 426262306a36Sopenharmony_ci * @vsi: pointer to the targeted VSI 426362306a36Sopenharmony_ci * @fsp: pointer to Rx flow specification 426462306a36Sopenharmony_ci * @userdef: userdefined data from flow specification 426562306a36Sopenharmony_ci * 426662306a36Sopenharmony_ci * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support 426762306a36Sopenharmony_ci * for partial matches exists with a few limitations. First, hardware only 426862306a36Sopenharmony_ci * supports masking by word boundary (2 bytes) and not per individual bit. 426962306a36Sopenharmony_ci * Second, hardware is limited to using one mask for a flow type and cannot 427062306a36Sopenharmony_ci * use a separate mask for each filter. 427162306a36Sopenharmony_ci * 427262306a36Sopenharmony_ci * To support these limitations, if we already have a configured filter for 427362306a36Sopenharmony_ci * the specified type, this function enforces that new filters of the type 427462306a36Sopenharmony_ci * match the configured input set. Otherwise, if we do not have a filter of 427562306a36Sopenharmony_ci * the specified type, we allow the input set to be updated to match the 427662306a36Sopenharmony_ci * desired filter. 427762306a36Sopenharmony_ci * 427862306a36Sopenharmony_ci * To help ensure that administrators understand why filters weren't displayed 427962306a36Sopenharmony_ci * as supported, we print a diagnostic message displaying how the input set 428062306a36Sopenharmony_ci * would change and warning to delete the preexisting filters if required. 428162306a36Sopenharmony_ci * 428262306a36Sopenharmony_ci * Returns 0 on successful input set match, and a negative return code on 428362306a36Sopenharmony_ci * failure. 428462306a36Sopenharmony_ci **/ 428562306a36Sopenharmony_cistatic int i40e_check_fdir_input_set(struct i40e_vsi *vsi, 428662306a36Sopenharmony_ci struct ethtool_rx_flow_spec *fsp, 428762306a36Sopenharmony_ci struct i40e_rx_flow_userdef *userdef) 428862306a36Sopenharmony_ci{ 428962306a36Sopenharmony_ci static const __be32 ipv6_full_mask[4] = {cpu_to_be32(0xffffffff), 429062306a36Sopenharmony_ci cpu_to_be32(0xffffffff), cpu_to_be32(0xffffffff), 429162306a36Sopenharmony_ci cpu_to_be32(0xffffffff)}; 429262306a36Sopenharmony_ci struct ethtool_tcpip6_spec *tcp_ip6_spec; 429362306a36Sopenharmony_ci struct ethtool_usrip6_spec *usr_ip6_spec; 429462306a36Sopenharmony_ci struct ethtool_tcpip4_spec *tcp_ip4_spec; 429562306a36Sopenharmony_ci struct ethtool_usrip4_spec *usr_ip4_spec; 429662306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 429762306a36Sopenharmony_ci u64 current_mask, new_mask; 429862306a36Sopenharmony_ci bool new_flex_offset = false; 429962306a36Sopenharmony_ci bool flex_l3 = false; 430062306a36Sopenharmony_ci u16 *fdir_filter_count; 430162306a36Sopenharmony_ci u16 index, src_offset = 0; 430262306a36Sopenharmony_ci u8 pit_index = 0; 430362306a36Sopenharmony_ci int err; 430462306a36Sopenharmony_ci 430562306a36Sopenharmony_ci switch (fsp->flow_type & ~FLOW_EXT) { 430662306a36Sopenharmony_ci case SCTP_V4_FLOW: 430762306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP; 430862306a36Sopenharmony_ci fdir_filter_count = &pf->fd_sctp4_filter_cnt; 430962306a36Sopenharmony_ci break; 431062306a36Sopenharmony_ci case TCP_V4_FLOW: 431162306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP; 431262306a36Sopenharmony_ci fdir_filter_count = &pf->fd_tcp4_filter_cnt; 431362306a36Sopenharmony_ci break; 431462306a36Sopenharmony_ci case UDP_V4_FLOW: 431562306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP; 431662306a36Sopenharmony_ci fdir_filter_count = &pf->fd_udp4_filter_cnt; 431762306a36Sopenharmony_ci break; 431862306a36Sopenharmony_ci case SCTP_V6_FLOW: 431962306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV6_SCTP; 432062306a36Sopenharmony_ci fdir_filter_count = &pf->fd_sctp6_filter_cnt; 432162306a36Sopenharmony_ci break; 432262306a36Sopenharmony_ci case TCP_V6_FLOW: 432362306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV6_TCP; 432462306a36Sopenharmony_ci fdir_filter_count = &pf->fd_tcp6_filter_cnt; 432562306a36Sopenharmony_ci break; 432662306a36Sopenharmony_ci case UDP_V6_FLOW: 432762306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV6_UDP; 432862306a36Sopenharmony_ci fdir_filter_count = &pf->fd_udp6_filter_cnt; 432962306a36Sopenharmony_ci break; 433062306a36Sopenharmony_ci case IP_USER_FLOW: 433162306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER; 433262306a36Sopenharmony_ci fdir_filter_count = &pf->fd_ip4_filter_cnt; 433362306a36Sopenharmony_ci flex_l3 = true; 433462306a36Sopenharmony_ci break; 433562306a36Sopenharmony_ci case IPV6_USER_FLOW: 433662306a36Sopenharmony_ci index = I40E_FILTER_PCTYPE_NONF_IPV6_OTHER; 433762306a36Sopenharmony_ci fdir_filter_count = &pf->fd_ip6_filter_cnt; 433862306a36Sopenharmony_ci flex_l3 = true; 433962306a36Sopenharmony_ci break; 434062306a36Sopenharmony_ci default: 434162306a36Sopenharmony_ci return -EOPNOTSUPP; 434262306a36Sopenharmony_ci } 434362306a36Sopenharmony_ci 434462306a36Sopenharmony_ci /* Read the current input set from register memory. */ 434562306a36Sopenharmony_ci current_mask = i40e_read_fd_input_set(pf, index); 434662306a36Sopenharmony_ci new_mask = current_mask; 434762306a36Sopenharmony_ci 434862306a36Sopenharmony_ci /* Determine, if any, the required changes to the input set in order 434962306a36Sopenharmony_ci * to support the provided mask. 435062306a36Sopenharmony_ci * 435162306a36Sopenharmony_ci * Hardware only supports masking at word (2 byte) granularity and does 435262306a36Sopenharmony_ci * not support full bitwise masking. This implementation simplifies 435362306a36Sopenharmony_ci * even further and only supports fully enabled or fully disabled 435462306a36Sopenharmony_ci * masks for each field, even though we could split the ip4src and 435562306a36Sopenharmony_ci * ip4dst fields. 435662306a36Sopenharmony_ci */ 435762306a36Sopenharmony_ci switch (fsp->flow_type & ~FLOW_EXT) { 435862306a36Sopenharmony_ci case SCTP_V4_FLOW: 435962306a36Sopenharmony_ci new_mask &= ~I40E_VERIFY_TAG_MASK; 436062306a36Sopenharmony_ci fallthrough; 436162306a36Sopenharmony_ci case TCP_V4_FLOW: 436262306a36Sopenharmony_ci case UDP_V4_FLOW: 436362306a36Sopenharmony_ci tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec; 436462306a36Sopenharmony_ci 436562306a36Sopenharmony_ci /* IPv4 source address */ 436662306a36Sopenharmony_ci if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF)) 436762306a36Sopenharmony_ci new_mask |= I40E_L3_SRC_MASK; 436862306a36Sopenharmony_ci else if (!tcp_ip4_spec->ip4src) 436962306a36Sopenharmony_ci new_mask &= ~I40E_L3_SRC_MASK; 437062306a36Sopenharmony_ci else 437162306a36Sopenharmony_ci return -EOPNOTSUPP; 437262306a36Sopenharmony_ci 437362306a36Sopenharmony_ci /* IPv4 destination address */ 437462306a36Sopenharmony_ci if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF)) 437562306a36Sopenharmony_ci new_mask |= I40E_L3_DST_MASK; 437662306a36Sopenharmony_ci else if (!tcp_ip4_spec->ip4dst) 437762306a36Sopenharmony_ci new_mask &= ~I40E_L3_DST_MASK; 437862306a36Sopenharmony_ci else 437962306a36Sopenharmony_ci return -EOPNOTSUPP; 438062306a36Sopenharmony_ci 438162306a36Sopenharmony_ci /* L4 source port */ 438262306a36Sopenharmony_ci if (tcp_ip4_spec->psrc == htons(0xFFFF)) 438362306a36Sopenharmony_ci new_mask |= I40E_L4_SRC_MASK; 438462306a36Sopenharmony_ci else if (!tcp_ip4_spec->psrc) 438562306a36Sopenharmony_ci new_mask &= ~I40E_L4_SRC_MASK; 438662306a36Sopenharmony_ci else 438762306a36Sopenharmony_ci return -EOPNOTSUPP; 438862306a36Sopenharmony_ci 438962306a36Sopenharmony_ci /* L4 destination port */ 439062306a36Sopenharmony_ci if (tcp_ip4_spec->pdst == htons(0xFFFF)) 439162306a36Sopenharmony_ci new_mask |= I40E_L4_DST_MASK; 439262306a36Sopenharmony_ci else if (!tcp_ip4_spec->pdst) 439362306a36Sopenharmony_ci new_mask &= ~I40E_L4_DST_MASK; 439462306a36Sopenharmony_ci else 439562306a36Sopenharmony_ci return -EOPNOTSUPP; 439662306a36Sopenharmony_ci 439762306a36Sopenharmony_ci /* Filtering on Type of Service is not supported. */ 439862306a36Sopenharmony_ci if (tcp_ip4_spec->tos) 439962306a36Sopenharmony_ci return -EOPNOTSUPP; 440062306a36Sopenharmony_ci 440162306a36Sopenharmony_ci break; 440262306a36Sopenharmony_ci case SCTP_V6_FLOW: 440362306a36Sopenharmony_ci new_mask &= ~I40E_VERIFY_TAG_MASK; 440462306a36Sopenharmony_ci fallthrough; 440562306a36Sopenharmony_ci case TCP_V6_FLOW: 440662306a36Sopenharmony_ci case UDP_V6_FLOW: 440762306a36Sopenharmony_ci tcp_ip6_spec = &fsp->m_u.tcp_ip6_spec; 440862306a36Sopenharmony_ci 440962306a36Sopenharmony_ci /* Check if user provided IPv6 source address. */ 441062306a36Sopenharmony_ci if (ipv6_addr_equal((struct in6_addr *)&tcp_ip6_spec->ip6src, 441162306a36Sopenharmony_ci (struct in6_addr *)&ipv6_full_mask)) 441262306a36Sopenharmony_ci new_mask |= I40E_L3_V6_SRC_MASK; 441362306a36Sopenharmony_ci else if (ipv6_addr_any((struct in6_addr *) 441462306a36Sopenharmony_ci &tcp_ip6_spec->ip6src)) 441562306a36Sopenharmony_ci new_mask &= ~I40E_L3_V6_SRC_MASK; 441662306a36Sopenharmony_ci else 441762306a36Sopenharmony_ci return -EOPNOTSUPP; 441862306a36Sopenharmony_ci 441962306a36Sopenharmony_ci /* Check if user provided destination address. */ 442062306a36Sopenharmony_ci if (ipv6_addr_equal((struct in6_addr *)&tcp_ip6_spec->ip6dst, 442162306a36Sopenharmony_ci (struct in6_addr *)&ipv6_full_mask)) 442262306a36Sopenharmony_ci new_mask |= I40E_L3_V6_DST_MASK; 442362306a36Sopenharmony_ci else if (ipv6_addr_any((struct in6_addr *) 442462306a36Sopenharmony_ci &tcp_ip6_spec->ip6dst)) 442562306a36Sopenharmony_ci new_mask &= ~I40E_L3_V6_DST_MASK; 442662306a36Sopenharmony_ci else 442762306a36Sopenharmony_ci return -EOPNOTSUPP; 442862306a36Sopenharmony_ci 442962306a36Sopenharmony_ci /* L4 source port */ 443062306a36Sopenharmony_ci if (tcp_ip6_spec->psrc == htons(0xFFFF)) 443162306a36Sopenharmony_ci new_mask |= I40E_L4_SRC_MASK; 443262306a36Sopenharmony_ci else if (!tcp_ip6_spec->psrc) 443362306a36Sopenharmony_ci new_mask &= ~I40E_L4_SRC_MASK; 443462306a36Sopenharmony_ci else 443562306a36Sopenharmony_ci return -EOPNOTSUPP; 443662306a36Sopenharmony_ci 443762306a36Sopenharmony_ci /* L4 destination port */ 443862306a36Sopenharmony_ci if (tcp_ip6_spec->pdst == htons(0xFFFF)) 443962306a36Sopenharmony_ci new_mask |= I40E_L4_DST_MASK; 444062306a36Sopenharmony_ci else if (!tcp_ip6_spec->pdst) 444162306a36Sopenharmony_ci new_mask &= ~I40E_L4_DST_MASK; 444262306a36Sopenharmony_ci else 444362306a36Sopenharmony_ci return -EOPNOTSUPP; 444462306a36Sopenharmony_ci 444562306a36Sopenharmony_ci /* Filtering on Traffic Classes is not supported. */ 444662306a36Sopenharmony_ci if (tcp_ip6_spec->tclass) 444762306a36Sopenharmony_ci return -EOPNOTSUPP; 444862306a36Sopenharmony_ci break; 444962306a36Sopenharmony_ci case IP_USER_FLOW: 445062306a36Sopenharmony_ci usr_ip4_spec = &fsp->m_u.usr_ip4_spec; 445162306a36Sopenharmony_ci 445262306a36Sopenharmony_ci /* IPv4 source address */ 445362306a36Sopenharmony_ci if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF)) 445462306a36Sopenharmony_ci new_mask |= I40E_L3_SRC_MASK; 445562306a36Sopenharmony_ci else if (!usr_ip4_spec->ip4src) 445662306a36Sopenharmony_ci new_mask &= ~I40E_L3_SRC_MASK; 445762306a36Sopenharmony_ci else 445862306a36Sopenharmony_ci return -EOPNOTSUPP; 445962306a36Sopenharmony_ci 446062306a36Sopenharmony_ci /* IPv4 destination address */ 446162306a36Sopenharmony_ci if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF)) 446262306a36Sopenharmony_ci new_mask |= I40E_L3_DST_MASK; 446362306a36Sopenharmony_ci else if (!usr_ip4_spec->ip4dst) 446462306a36Sopenharmony_ci new_mask &= ~I40E_L3_DST_MASK; 446562306a36Sopenharmony_ci else 446662306a36Sopenharmony_ci return -EOPNOTSUPP; 446762306a36Sopenharmony_ci 446862306a36Sopenharmony_ci /* First 4 bytes of L4 header */ 446962306a36Sopenharmony_ci if (usr_ip4_spec->l4_4_bytes) 447062306a36Sopenharmony_ci return -EOPNOTSUPP; 447162306a36Sopenharmony_ci 447262306a36Sopenharmony_ci /* Filtering on Type of Service is not supported. */ 447362306a36Sopenharmony_ci if (usr_ip4_spec->tos) 447462306a36Sopenharmony_ci return -EOPNOTSUPP; 447562306a36Sopenharmony_ci 447662306a36Sopenharmony_ci /* Filtering on IP version is not supported */ 447762306a36Sopenharmony_ci if (usr_ip4_spec->ip_ver) 447862306a36Sopenharmony_ci return -EINVAL; 447962306a36Sopenharmony_ci 448062306a36Sopenharmony_ci /* Filtering on L4 protocol is not supported */ 448162306a36Sopenharmony_ci if (usr_ip4_spec->proto) 448262306a36Sopenharmony_ci return -EINVAL; 448362306a36Sopenharmony_ci 448462306a36Sopenharmony_ci break; 448562306a36Sopenharmony_ci case IPV6_USER_FLOW: 448662306a36Sopenharmony_ci usr_ip6_spec = &fsp->m_u.usr_ip6_spec; 448762306a36Sopenharmony_ci 448862306a36Sopenharmony_ci /* Check if user provided IPv6 source address. */ 448962306a36Sopenharmony_ci if (ipv6_addr_equal((struct in6_addr *)&usr_ip6_spec->ip6src, 449062306a36Sopenharmony_ci (struct in6_addr *)&ipv6_full_mask)) 449162306a36Sopenharmony_ci new_mask |= I40E_L3_V6_SRC_MASK; 449262306a36Sopenharmony_ci else if (ipv6_addr_any((struct in6_addr *) 449362306a36Sopenharmony_ci &usr_ip6_spec->ip6src)) 449462306a36Sopenharmony_ci new_mask &= ~I40E_L3_V6_SRC_MASK; 449562306a36Sopenharmony_ci else 449662306a36Sopenharmony_ci return -EOPNOTSUPP; 449762306a36Sopenharmony_ci 449862306a36Sopenharmony_ci /* Check if user provided destination address. */ 449962306a36Sopenharmony_ci if (ipv6_addr_equal((struct in6_addr *)&usr_ip6_spec->ip6dst, 450062306a36Sopenharmony_ci (struct in6_addr *)&ipv6_full_mask)) 450162306a36Sopenharmony_ci new_mask |= I40E_L3_V6_DST_MASK; 450262306a36Sopenharmony_ci else if (ipv6_addr_any((struct in6_addr *) 450362306a36Sopenharmony_ci &usr_ip6_spec->ip6dst)) 450462306a36Sopenharmony_ci new_mask &= ~I40E_L3_V6_DST_MASK; 450562306a36Sopenharmony_ci else 450662306a36Sopenharmony_ci return -EOPNOTSUPP; 450762306a36Sopenharmony_ci 450862306a36Sopenharmony_ci if (usr_ip6_spec->l4_4_bytes) 450962306a36Sopenharmony_ci return -EOPNOTSUPP; 451062306a36Sopenharmony_ci 451162306a36Sopenharmony_ci /* Filtering on Traffic class is not supported. */ 451262306a36Sopenharmony_ci if (usr_ip6_spec->tclass) 451362306a36Sopenharmony_ci return -EOPNOTSUPP; 451462306a36Sopenharmony_ci 451562306a36Sopenharmony_ci /* Filtering on L4 protocol is not supported */ 451662306a36Sopenharmony_ci if (usr_ip6_spec->l4_proto) 451762306a36Sopenharmony_ci return -EINVAL; 451862306a36Sopenharmony_ci 451962306a36Sopenharmony_ci break; 452062306a36Sopenharmony_ci default: 452162306a36Sopenharmony_ci return -EOPNOTSUPP; 452262306a36Sopenharmony_ci } 452362306a36Sopenharmony_ci 452462306a36Sopenharmony_ci if (fsp->flow_type & FLOW_EXT) { 452562306a36Sopenharmony_ci /* Allow only 802.1Q and no etype defined, as 452662306a36Sopenharmony_ci * later it's modified to 0x8100 452762306a36Sopenharmony_ci */ 452862306a36Sopenharmony_ci if (fsp->h_ext.vlan_etype != htons(ETH_P_8021Q) && 452962306a36Sopenharmony_ci fsp->h_ext.vlan_etype != 0) 453062306a36Sopenharmony_ci return -EOPNOTSUPP; 453162306a36Sopenharmony_ci if (fsp->m_ext.vlan_tci == htons(0xFFFF)) 453262306a36Sopenharmony_ci new_mask |= I40E_VLAN_SRC_MASK; 453362306a36Sopenharmony_ci else 453462306a36Sopenharmony_ci new_mask &= ~I40E_VLAN_SRC_MASK; 453562306a36Sopenharmony_ci } 453662306a36Sopenharmony_ci 453762306a36Sopenharmony_ci /* First, clear all flexible filter entries */ 453862306a36Sopenharmony_ci new_mask &= ~I40E_FLEX_INPUT_MASK; 453962306a36Sopenharmony_ci 454062306a36Sopenharmony_ci /* If we have a flexible filter, try to add this offset to the correct 454162306a36Sopenharmony_ci * flexible filter PIT list. Once finished, we can update the mask. 454262306a36Sopenharmony_ci * If the src_offset changed, we will get a new mask value which will 454362306a36Sopenharmony_ci * trigger an input set change. 454462306a36Sopenharmony_ci */ 454562306a36Sopenharmony_ci if (userdef->flex_filter) { 454662306a36Sopenharmony_ci struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL; 454762306a36Sopenharmony_ci 454862306a36Sopenharmony_ci /* Flexible offset must be even, since the flexible payload 454962306a36Sopenharmony_ci * must be aligned on 2-byte boundary. 455062306a36Sopenharmony_ci */ 455162306a36Sopenharmony_ci if (userdef->flex_offset & 0x1) { 455262306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 455362306a36Sopenharmony_ci "Flexible data offset must be 2-byte aligned\n"); 455462306a36Sopenharmony_ci return -EINVAL; 455562306a36Sopenharmony_ci } 455662306a36Sopenharmony_ci 455762306a36Sopenharmony_ci src_offset = userdef->flex_offset >> 1; 455862306a36Sopenharmony_ci 455962306a36Sopenharmony_ci /* FLX_PIT source offset value is only so large */ 456062306a36Sopenharmony_ci if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) { 456162306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 456262306a36Sopenharmony_ci "Flexible data must reside within first 64 bytes of the packet payload\n"); 456362306a36Sopenharmony_ci return -EINVAL; 456462306a36Sopenharmony_ci } 456562306a36Sopenharmony_ci 456662306a36Sopenharmony_ci /* See if this offset has already been programmed. If we get 456762306a36Sopenharmony_ci * an ERR_PTR, then the filter is not safe to add. Otherwise, 456862306a36Sopenharmony_ci * if we get a NULL pointer, this means we will need to add 456962306a36Sopenharmony_ci * the offset. 457062306a36Sopenharmony_ci */ 457162306a36Sopenharmony_ci flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list, 457262306a36Sopenharmony_ci src_offset); 457362306a36Sopenharmony_ci if (IS_ERR(flex_pit)) 457462306a36Sopenharmony_ci return PTR_ERR(flex_pit); 457562306a36Sopenharmony_ci 457662306a36Sopenharmony_ci /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown) 457762306a36Sopenharmony_ci * packet types, and thus we need to program both L3 and L4 457862306a36Sopenharmony_ci * flexible values. These must have identical flexible index, 457962306a36Sopenharmony_ci * as otherwise we can't correctly program the input set. So 458062306a36Sopenharmony_ci * we'll find both an L3 and L4 index and make sure they are 458162306a36Sopenharmony_ci * the same. 458262306a36Sopenharmony_ci */ 458362306a36Sopenharmony_ci if (flex_l3) { 458462306a36Sopenharmony_ci l3_flex_pit = 458562306a36Sopenharmony_ci i40e_find_flex_offset(&pf->l3_flex_pit_list, 458662306a36Sopenharmony_ci src_offset); 458762306a36Sopenharmony_ci if (IS_ERR(l3_flex_pit)) 458862306a36Sopenharmony_ci return PTR_ERR(l3_flex_pit); 458962306a36Sopenharmony_ci 459062306a36Sopenharmony_ci if (flex_pit) { 459162306a36Sopenharmony_ci /* If we already had a matching L4 entry, we 459262306a36Sopenharmony_ci * need to make sure that the L3 entry we 459362306a36Sopenharmony_ci * obtained uses the same index. 459462306a36Sopenharmony_ci */ 459562306a36Sopenharmony_ci if (l3_flex_pit) { 459662306a36Sopenharmony_ci if (l3_flex_pit->pit_index != 459762306a36Sopenharmony_ci flex_pit->pit_index) { 459862306a36Sopenharmony_ci return -EINVAL; 459962306a36Sopenharmony_ci } 460062306a36Sopenharmony_ci } else { 460162306a36Sopenharmony_ci new_flex_offset = true; 460262306a36Sopenharmony_ci } 460362306a36Sopenharmony_ci } else { 460462306a36Sopenharmony_ci flex_pit = l3_flex_pit; 460562306a36Sopenharmony_ci } 460662306a36Sopenharmony_ci } 460762306a36Sopenharmony_ci 460862306a36Sopenharmony_ci /* If we didn't find an existing flex offset, we need to 460962306a36Sopenharmony_ci * program a new one. However, we don't immediately program it 461062306a36Sopenharmony_ci * here because we will wait to program until after we check 461162306a36Sopenharmony_ci * that it is safe to change the input set. 461262306a36Sopenharmony_ci */ 461362306a36Sopenharmony_ci if (!flex_pit) { 461462306a36Sopenharmony_ci new_flex_offset = true; 461562306a36Sopenharmony_ci pit_index = i40e_unused_pit_index(pf); 461662306a36Sopenharmony_ci } else { 461762306a36Sopenharmony_ci pit_index = flex_pit->pit_index; 461862306a36Sopenharmony_ci } 461962306a36Sopenharmony_ci 462062306a36Sopenharmony_ci /* Update the mask with the new offset */ 462162306a36Sopenharmony_ci new_mask |= i40e_pit_index_to_mask(pit_index); 462262306a36Sopenharmony_ci } 462362306a36Sopenharmony_ci 462462306a36Sopenharmony_ci /* If the mask and flexible filter offsets for this filter match the 462562306a36Sopenharmony_ci * currently programmed values we don't need any input set change, so 462662306a36Sopenharmony_ci * this filter is safe to install. 462762306a36Sopenharmony_ci */ 462862306a36Sopenharmony_ci if (new_mask == current_mask && !new_flex_offset) 462962306a36Sopenharmony_ci return 0; 463062306a36Sopenharmony_ci 463162306a36Sopenharmony_ci netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n", 463262306a36Sopenharmony_ci i40e_flow_str(fsp)); 463362306a36Sopenharmony_ci i40e_print_input_set(vsi, current_mask, new_mask); 463462306a36Sopenharmony_ci if (new_flex_offset) { 463562306a36Sopenharmony_ci netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d", 463662306a36Sopenharmony_ci pit_index, src_offset); 463762306a36Sopenharmony_ci } 463862306a36Sopenharmony_ci 463962306a36Sopenharmony_ci /* Hardware input sets are global across multiple ports, so even the 464062306a36Sopenharmony_ci * main port cannot change them when in MFP mode as this would impact 464162306a36Sopenharmony_ci * any filters on the other ports. 464262306a36Sopenharmony_ci */ 464362306a36Sopenharmony_ci if (pf->flags & I40E_FLAG_MFP_ENABLED) { 464462306a36Sopenharmony_ci netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n"); 464562306a36Sopenharmony_ci return -EOPNOTSUPP; 464662306a36Sopenharmony_ci } 464762306a36Sopenharmony_ci 464862306a36Sopenharmony_ci /* This filter requires us to update the input set. However, hardware 464962306a36Sopenharmony_ci * only supports one input set per flow type, and does not support 465062306a36Sopenharmony_ci * separate masks for each filter. This means that we can only support 465162306a36Sopenharmony_ci * a single mask for all filters of a specific type. 465262306a36Sopenharmony_ci * 465362306a36Sopenharmony_ci * If we have preexisting filters, they obviously depend on the 465462306a36Sopenharmony_ci * current programmed input set. Display a diagnostic message in this 465562306a36Sopenharmony_ci * case explaining why the filter could not be accepted. 465662306a36Sopenharmony_ci */ 465762306a36Sopenharmony_ci if (*fdir_filter_count) { 465862306a36Sopenharmony_ci netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n", 465962306a36Sopenharmony_ci i40e_flow_str(fsp), 466062306a36Sopenharmony_ci *fdir_filter_count); 466162306a36Sopenharmony_ci return -EOPNOTSUPP; 466262306a36Sopenharmony_ci } 466362306a36Sopenharmony_ci 466462306a36Sopenharmony_ci i40e_write_fd_input_set(pf, index, new_mask); 466562306a36Sopenharmony_ci 466662306a36Sopenharmony_ci /* IP_USER_FLOW filters match both IPv4/Other and IPv4/Fragmented 466762306a36Sopenharmony_ci * frames. If we're programming the input set for IPv4/Other, we also 466862306a36Sopenharmony_ci * need to program the IPv4/Fragmented input set. Since we don't have 466962306a36Sopenharmony_ci * separate support, we'll always assume and enforce that the two flow 467062306a36Sopenharmony_ci * types must have matching input sets. 467162306a36Sopenharmony_ci */ 467262306a36Sopenharmony_ci if (index == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) 467362306a36Sopenharmony_ci i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4, 467462306a36Sopenharmony_ci new_mask); 467562306a36Sopenharmony_ci 467662306a36Sopenharmony_ci /* Add the new offset and update table, if necessary */ 467762306a36Sopenharmony_ci if (new_flex_offset) { 467862306a36Sopenharmony_ci err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset, 467962306a36Sopenharmony_ci pit_index); 468062306a36Sopenharmony_ci if (err) 468162306a36Sopenharmony_ci return err; 468262306a36Sopenharmony_ci 468362306a36Sopenharmony_ci if (flex_l3) { 468462306a36Sopenharmony_ci err = i40e_add_flex_offset(&pf->l3_flex_pit_list, 468562306a36Sopenharmony_ci src_offset, 468662306a36Sopenharmony_ci pit_index); 468762306a36Sopenharmony_ci if (err) 468862306a36Sopenharmony_ci return err; 468962306a36Sopenharmony_ci } 469062306a36Sopenharmony_ci 469162306a36Sopenharmony_ci i40e_reprogram_flex_pit(pf); 469262306a36Sopenharmony_ci } 469362306a36Sopenharmony_ci 469462306a36Sopenharmony_ci return 0; 469562306a36Sopenharmony_ci} 469662306a36Sopenharmony_ci 469762306a36Sopenharmony_ci/** 469862306a36Sopenharmony_ci * i40e_match_fdir_filter - Return true of two filters match 469962306a36Sopenharmony_ci * @a: pointer to filter struct 470062306a36Sopenharmony_ci * @b: pointer to filter struct 470162306a36Sopenharmony_ci * 470262306a36Sopenharmony_ci * Returns true if the two filters match exactly the same criteria. I.e. they 470362306a36Sopenharmony_ci * match the same flow type and have the same parameters. We don't need to 470462306a36Sopenharmony_ci * check any input-set since all filters of the same flow type must use the 470562306a36Sopenharmony_ci * same input set. 470662306a36Sopenharmony_ci **/ 470762306a36Sopenharmony_cistatic bool i40e_match_fdir_filter(struct i40e_fdir_filter *a, 470862306a36Sopenharmony_ci struct i40e_fdir_filter *b) 470962306a36Sopenharmony_ci{ 471062306a36Sopenharmony_ci /* The filters do not much if any of these criteria differ. */ 471162306a36Sopenharmony_ci if (a->dst_ip != b->dst_ip || 471262306a36Sopenharmony_ci a->src_ip != b->src_ip || 471362306a36Sopenharmony_ci a->dst_port != b->dst_port || 471462306a36Sopenharmony_ci a->src_port != b->src_port || 471562306a36Sopenharmony_ci a->flow_type != b->flow_type || 471662306a36Sopenharmony_ci a->ipl4_proto != b->ipl4_proto || 471762306a36Sopenharmony_ci a->vlan_tag != b->vlan_tag || 471862306a36Sopenharmony_ci a->vlan_etype != b->vlan_etype) 471962306a36Sopenharmony_ci return false; 472062306a36Sopenharmony_ci 472162306a36Sopenharmony_ci return true; 472262306a36Sopenharmony_ci} 472362306a36Sopenharmony_ci 472462306a36Sopenharmony_ci/** 472562306a36Sopenharmony_ci * i40e_disallow_matching_filters - Check that new filters differ 472662306a36Sopenharmony_ci * @vsi: pointer to the targeted VSI 472762306a36Sopenharmony_ci * @input: new filter to check 472862306a36Sopenharmony_ci * 472962306a36Sopenharmony_ci * Due to hardware limitations, it is not possible for two filters that match 473062306a36Sopenharmony_ci * similar criteria to be programmed at the same time. This is true for a few 473162306a36Sopenharmony_ci * reasons: 473262306a36Sopenharmony_ci * 473362306a36Sopenharmony_ci * (a) all filters matching a particular flow type must use the same input 473462306a36Sopenharmony_ci * set, that is they must match the same criteria. 473562306a36Sopenharmony_ci * (b) different flow types will never match the same packet, as the flow type 473662306a36Sopenharmony_ci * is decided by hardware before checking which rules apply. 473762306a36Sopenharmony_ci * (c) hardware has no way to distinguish which order filters apply in. 473862306a36Sopenharmony_ci * 473962306a36Sopenharmony_ci * Due to this, we can't really support using the location data to order 474062306a36Sopenharmony_ci * filters in the hardware parsing. It is technically possible for the user to 474162306a36Sopenharmony_ci * request two filters matching the same criteria but which select different 474262306a36Sopenharmony_ci * queues. In this case, rather than keep both filters in the list, we reject 474362306a36Sopenharmony_ci * the 2nd filter when the user requests adding it. 474462306a36Sopenharmony_ci * 474562306a36Sopenharmony_ci * This avoids needing to track location for programming the filter to 474662306a36Sopenharmony_ci * hardware, and ensures that we avoid some strange scenarios involving 474762306a36Sopenharmony_ci * deleting filters which match the same criteria. 474862306a36Sopenharmony_ci **/ 474962306a36Sopenharmony_cistatic int i40e_disallow_matching_filters(struct i40e_vsi *vsi, 475062306a36Sopenharmony_ci struct i40e_fdir_filter *input) 475162306a36Sopenharmony_ci{ 475262306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 475362306a36Sopenharmony_ci struct i40e_fdir_filter *rule; 475462306a36Sopenharmony_ci struct hlist_node *node2; 475562306a36Sopenharmony_ci 475662306a36Sopenharmony_ci /* Loop through every filter, and check that it doesn't match */ 475762306a36Sopenharmony_ci hlist_for_each_entry_safe(rule, node2, 475862306a36Sopenharmony_ci &pf->fdir_filter_list, fdir_node) { 475962306a36Sopenharmony_ci /* Don't check the filters match if they share the same fd_id, 476062306a36Sopenharmony_ci * since the new filter is actually just updating the target 476162306a36Sopenharmony_ci * of the old filter. 476262306a36Sopenharmony_ci */ 476362306a36Sopenharmony_ci if (rule->fd_id == input->fd_id) 476462306a36Sopenharmony_ci continue; 476562306a36Sopenharmony_ci 476662306a36Sopenharmony_ci /* If any filters match, then print a warning message to the 476762306a36Sopenharmony_ci * kernel message buffer and bail out. 476862306a36Sopenharmony_ci */ 476962306a36Sopenharmony_ci if (i40e_match_fdir_filter(rule, input)) { 477062306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 477162306a36Sopenharmony_ci "Existing user defined filter %d already matches this flow.\n", 477262306a36Sopenharmony_ci rule->fd_id); 477362306a36Sopenharmony_ci return -EINVAL; 477462306a36Sopenharmony_ci } 477562306a36Sopenharmony_ci } 477662306a36Sopenharmony_ci 477762306a36Sopenharmony_ci return 0; 477862306a36Sopenharmony_ci} 477962306a36Sopenharmony_ci 478062306a36Sopenharmony_ci/** 478162306a36Sopenharmony_ci * i40e_add_fdir_ethtool - Add/Remove Flow Director filters 478262306a36Sopenharmony_ci * @vsi: pointer to the targeted VSI 478362306a36Sopenharmony_ci * @cmd: command to get or set RX flow classification rules 478462306a36Sopenharmony_ci * 478562306a36Sopenharmony_ci * Add Flow Director filters for a specific flow spec based on their 478662306a36Sopenharmony_ci * protocol. Returns 0 if the filters were successfully added. 478762306a36Sopenharmony_ci **/ 478862306a36Sopenharmony_cistatic int i40e_add_fdir_ethtool(struct i40e_vsi *vsi, 478962306a36Sopenharmony_ci struct ethtool_rxnfc *cmd) 479062306a36Sopenharmony_ci{ 479162306a36Sopenharmony_ci struct i40e_rx_flow_userdef userdef; 479262306a36Sopenharmony_ci struct ethtool_rx_flow_spec *fsp; 479362306a36Sopenharmony_ci struct i40e_fdir_filter *input; 479462306a36Sopenharmony_ci u16 dest_vsi = 0, q_index = 0; 479562306a36Sopenharmony_ci struct i40e_pf *pf; 479662306a36Sopenharmony_ci int ret = -EINVAL; 479762306a36Sopenharmony_ci u8 dest_ctl; 479862306a36Sopenharmony_ci 479962306a36Sopenharmony_ci if (!vsi) 480062306a36Sopenharmony_ci return -EINVAL; 480162306a36Sopenharmony_ci pf = vsi->back; 480262306a36Sopenharmony_ci 480362306a36Sopenharmony_ci if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) 480462306a36Sopenharmony_ci return -EOPNOTSUPP; 480562306a36Sopenharmony_ci 480662306a36Sopenharmony_ci if (test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state)) 480762306a36Sopenharmony_ci return -ENOSPC; 480862306a36Sopenharmony_ci 480962306a36Sopenharmony_ci if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) || 481062306a36Sopenharmony_ci test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) 481162306a36Sopenharmony_ci return -EBUSY; 481262306a36Sopenharmony_ci 481362306a36Sopenharmony_ci if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state)) 481462306a36Sopenharmony_ci return -EBUSY; 481562306a36Sopenharmony_ci 481662306a36Sopenharmony_ci fsp = (struct ethtool_rx_flow_spec *)&cmd->fs; 481762306a36Sopenharmony_ci 481862306a36Sopenharmony_ci /* Parse the user-defined field */ 481962306a36Sopenharmony_ci if (i40e_parse_rx_flow_user_data(fsp, &userdef)) 482062306a36Sopenharmony_ci return -EINVAL; 482162306a36Sopenharmony_ci 482262306a36Sopenharmony_ci /* Extended MAC field is not supported */ 482362306a36Sopenharmony_ci if (fsp->flow_type & FLOW_MAC_EXT) 482462306a36Sopenharmony_ci return -EINVAL; 482562306a36Sopenharmony_ci 482662306a36Sopenharmony_ci ret = i40e_check_fdir_input_set(vsi, fsp, &userdef); 482762306a36Sopenharmony_ci if (ret) 482862306a36Sopenharmony_ci return ret; 482962306a36Sopenharmony_ci 483062306a36Sopenharmony_ci if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort + 483162306a36Sopenharmony_ci pf->hw.func_caps.fd_filters_guaranteed)) { 483262306a36Sopenharmony_ci return -EINVAL; 483362306a36Sopenharmony_ci } 483462306a36Sopenharmony_ci 483562306a36Sopenharmony_ci /* ring_cookie is either the drop index, or is a mask of the queue 483662306a36Sopenharmony_ci * index and VF id we wish to target. 483762306a36Sopenharmony_ci */ 483862306a36Sopenharmony_ci if (fsp->ring_cookie == RX_CLS_FLOW_DISC) { 483962306a36Sopenharmony_ci dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET; 484062306a36Sopenharmony_ci } else { 484162306a36Sopenharmony_ci u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie); 484262306a36Sopenharmony_ci u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie); 484362306a36Sopenharmony_ci 484462306a36Sopenharmony_ci if (!vf) { 484562306a36Sopenharmony_ci if (ring >= vsi->num_queue_pairs) 484662306a36Sopenharmony_ci return -EINVAL; 484762306a36Sopenharmony_ci dest_vsi = vsi->id; 484862306a36Sopenharmony_ci } else { 484962306a36Sopenharmony_ci /* VFs are zero-indexed, so we subtract one here */ 485062306a36Sopenharmony_ci vf--; 485162306a36Sopenharmony_ci 485262306a36Sopenharmony_ci if (vf >= pf->num_alloc_vfs) 485362306a36Sopenharmony_ci return -EINVAL; 485462306a36Sopenharmony_ci if (ring >= pf->vf[vf].num_queue_pairs) 485562306a36Sopenharmony_ci return -EINVAL; 485662306a36Sopenharmony_ci dest_vsi = pf->vf[vf].lan_vsi_id; 485762306a36Sopenharmony_ci } 485862306a36Sopenharmony_ci dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX; 485962306a36Sopenharmony_ci q_index = ring; 486062306a36Sopenharmony_ci } 486162306a36Sopenharmony_ci 486262306a36Sopenharmony_ci input = kzalloc(sizeof(*input), GFP_KERNEL); 486362306a36Sopenharmony_ci 486462306a36Sopenharmony_ci if (!input) 486562306a36Sopenharmony_ci return -ENOMEM; 486662306a36Sopenharmony_ci 486762306a36Sopenharmony_ci input->fd_id = fsp->location; 486862306a36Sopenharmony_ci input->q_index = q_index; 486962306a36Sopenharmony_ci input->dest_vsi = dest_vsi; 487062306a36Sopenharmony_ci input->dest_ctl = dest_ctl; 487162306a36Sopenharmony_ci input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID; 487262306a36Sopenharmony_ci input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id); 487362306a36Sopenharmony_ci input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src; 487462306a36Sopenharmony_ci input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst; 487562306a36Sopenharmony_ci input->flow_type = fsp->flow_type & ~FLOW_EXT; 487662306a36Sopenharmony_ci 487762306a36Sopenharmony_ci input->vlan_etype = fsp->h_ext.vlan_etype; 487862306a36Sopenharmony_ci if (!fsp->m_ext.vlan_etype && fsp->h_ext.vlan_tci) 487962306a36Sopenharmony_ci input->vlan_etype = cpu_to_be16(ETH_P_8021Q); 488062306a36Sopenharmony_ci if (fsp->m_ext.vlan_tci && input->vlan_etype) 488162306a36Sopenharmony_ci input->vlan_tag = fsp->h_ext.vlan_tci; 488262306a36Sopenharmony_ci if (input->flow_type == IPV6_USER_FLOW || 488362306a36Sopenharmony_ci input->flow_type == UDP_V6_FLOW || 488462306a36Sopenharmony_ci input->flow_type == TCP_V6_FLOW || 488562306a36Sopenharmony_ci input->flow_type == SCTP_V6_FLOW) { 488662306a36Sopenharmony_ci /* Reverse the src and dest notion, since the HW expects them 488762306a36Sopenharmony_ci * to be from Tx perspective where as the input from user is 488862306a36Sopenharmony_ci * from Rx filter view. 488962306a36Sopenharmony_ci */ 489062306a36Sopenharmony_ci input->ipl4_proto = fsp->h_u.usr_ip6_spec.l4_proto; 489162306a36Sopenharmony_ci input->dst_port = fsp->h_u.tcp_ip6_spec.psrc; 489262306a36Sopenharmony_ci input->src_port = fsp->h_u.tcp_ip6_spec.pdst; 489362306a36Sopenharmony_ci memcpy(input->dst_ip6, fsp->h_u.ah_ip6_spec.ip6src, 489462306a36Sopenharmony_ci sizeof(__be32) * 4); 489562306a36Sopenharmony_ci memcpy(input->src_ip6, fsp->h_u.ah_ip6_spec.ip6dst, 489662306a36Sopenharmony_ci sizeof(__be32) * 4); 489762306a36Sopenharmony_ci } else { 489862306a36Sopenharmony_ci /* Reverse the src and dest notion, since the HW expects them 489962306a36Sopenharmony_ci * to be from Tx perspective where as the input from user is 490062306a36Sopenharmony_ci * from Rx filter view. 490162306a36Sopenharmony_ci */ 490262306a36Sopenharmony_ci input->ipl4_proto = fsp->h_u.usr_ip4_spec.proto; 490362306a36Sopenharmony_ci input->dst_port = fsp->h_u.tcp_ip4_spec.psrc; 490462306a36Sopenharmony_ci input->src_port = fsp->h_u.tcp_ip4_spec.pdst; 490562306a36Sopenharmony_ci input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src; 490662306a36Sopenharmony_ci input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst; 490762306a36Sopenharmony_ci } 490862306a36Sopenharmony_ci 490962306a36Sopenharmony_ci if (userdef.flex_filter) { 491062306a36Sopenharmony_ci input->flex_filter = true; 491162306a36Sopenharmony_ci input->flex_word = cpu_to_be16(userdef.flex_word); 491262306a36Sopenharmony_ci input->flex_offset = userdef.flex_offset; 491362306a36Sopenharmony_ci } 491462306a36Sopenharmony_ci 491562306a36Sopenharmony_ci /* Avoid programming two filters with identical match criteria. */ 491662306a36Sopenharmony_ci ret = i40e_disallow_matching_filters(vsi, input); 491762306a36Sopenharmony_ci if (ret) 491862306a36Sopenharmony_ci goto free_filter_memory; 491962306a36Sopenharmony_ci 492062306a36Sopenharmony_ci /* Add the input filter to the fdir_input_list, possibly replacing 492162306a36Sopenharmony_ci * a previous filter. Do not free the input structure after adding it 492262306a36Sopenharmony_ci * to the list as this would cause a use-after-free bug. 492362306a36Sopenharmony_ci */ 492462306a36Sopenharmony_ci i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL); 492562306a36Sopenharmony_ci ret = i40e_add_del_fdir(vsi, input, true); 492662306a36Sopenharmony_ci if (ret) 492762306a36Sopenharmony_ci goto remove_sw_rule; 492862306a36Sopenharmony_ci return 0; 492962306a36Sopenharmony_ci 493062306a36Sopenharmony_ciremove_sw_rule: 493162306a36Sopenharmony_ci hlist_del(&input->fdir_node); 493262306a36Sopenharmony_ci pf->fdir_pf_active_filters--; 493362306a36Sopenharmony_cifree_filter_memory: 493462306a36Sopenharmony_ci kfree(input); 493562306a36Sopenharmony_ci return ret; 493662306a36Sopenharmony_ci} 493762306a36Sopenharmony_ci 493862306a36Sopenharmony_ci/** 493962306a36Sopenharmony_ci * i40e_set_rxnfc - command to set RX flow classification rules 494062306a36Sopenharmony_ci * @netdev: network interface device structure 494162306a36Sopenharmony_ci * @cmd: ethtool rxnfc command 494262306a36Sopenharmony_ci * 494362306a36Sopenharmony_ci * Returns Success if the command is supported. 494462306a36Sopenharmony_ci **/ 494562306a36Sopenharmony_cistatic int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) 494662306a36Sopenharmony_ci{ 494762306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 494862306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 494962306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 495062306a36Sopenharmony_ci int ret = -EOPNOTSUPP; 495162306a36Sopenharmony_ci 495262306a36Sopenharmony_ci switch (cmd->cmd) { 495362306a36Sopenharmony_ci case ETHTOOL_SRXFH: 495462306a36Sopenharmony_ci ret = i40e_set_rss_hash_opt(pf, cmd); 495562306a36Sopenharmony_ci break; 495662306a36Sopenharmony_ci case ETHTOOL_SRXCLSRLINS: 495762306a36Sopenharmony_ci ret = i40e_add_fdir_ethtool(vsi, cmd); 495862306a36Sopenharmony_ci break; 495962306a36Sopenharmony_ci case ETHTOOL_SRXCLSRLDEL: 496062306a36Sopenharmony_ci ret = i40e_del_fdir_entry(vsi, cmd); 496162306a36Sopenharmony_ci break; 496262306a36Sopenharmony_ci default: 496362306a36Sopenharmony_ci break; 496462306a36Sopenharmony_ci } 496562306a36Sopenharmony_ci 496662306a36Sopenharmony_ci return ret; 496762306a36Sopenharmony_ci} 496862306a36Sopenharmony_ci 496962306a36Sopenharmony_ci/** 497062306a36Sopenharmony_ci * i40e_max_channels - get Max number of combined channels supported 497162306a36Sopenharmony_ci * @vsi: vsi pointer 497262306a36Sopenharmony_ci **/ 497362306a36Sopenharmony_cistatic unsigned int i40e_max_channels(struct i40e_vsi *vsi) 497462306a36Sopenharmony_ci{ 497562306a36Sopenharmony_ci /* TODO: This code assumes DCB and FD is disabled for now. */ 497662306a36Sopenharmony_ci return vsi->alloc_queue_pairs; 497762306a36Sopenharmony_ci} 497862306a36Sopenharmony_ci 497962306a36Sopenharmony_ci/** 498062306a36Sopenharmony_ci * i40e_get_channels - Get the current channels enabled and max supported etc. 498162306a36Sopenharmony_ci * @dev: network interface device structure 498262306a36Sopenharmony_ci * @ch: ethtool channels structure 498362306a36Sopenharmony_ci * 498462306a36Sopenharmony_ci * We don't support separate tx and rx queues as channels. The other count 498562306a36Sopenharmony_ci * represents how many queues are being used for control. max_combined counts 498662306a36Sopenharmony_ci * how many queue pairs we can support. They may not be mapped 1 to 1 with 498762306a36Sopenharmony_ci * q_vectors since we support a lot more queue pairs than q_vectors. 498862306a36Sopenharmony_ci **/ 498962306a36Sopenharmony_cistatic void i40e_get_channels(struct net_device *dev, 499062306a36Sopenharmony_ci struct ethtool_channels *ch) 499162306a36Sopenharmony_ci{ 499262306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(dev); 499362306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 499462306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 499562306a36Sopenharmony_ci 499662306a36Sopenharmony_ci /* report maximum channels */ 499762306a36Sopenharmony_ci ch->max_combined = i40e_max_channels(vsi); 499862306a36Sopenharmony_ci 499962306a36Sopenharmony_ci /* report info for other vector */ 500062306a36Sopenharmony_ci ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0; 500162306a36Sopenharmony_ci ch->max_other = ch->other_count; 500262306a36Sopenharmony_ci 500362306a36Sopenharmony_ci /* Note: This code assumes DCB is disabled for now. */ 500462306a36Sopenharmony_ci ch->combined_count = vsi->num_queue_pairs; 500562306a36Sopenharmony_ci} 500662306a36Sopenharmony_ci 500762306a36Sopenharmony_ci/** 500862306a36Sopenharmony_ci * i40e_set_channels - Set the new channels count. 500962306a36Sopenharmony_ci * @dev: network interface device structure 501062306a36Sopenharmony_ci * @ch: ethtool channels structure 501162306a36Sopenharmony_ci * 501262306a36Sopenharmony_ci * The new channels count may not be the same as requested by the user 501362306a36Sopenharmony_ci * since it gets rounded down to a power of 2 value. 501462306a36Sopenharmony_ci **/ 501562306a36Sopenharmony_cistatic int i40e_set_channels(struct net_device *dev, 501662306a36Sopenharmony_ci struct ethtool_channels *ch) 501762306a36Sopenharmony_ci{ 501862306a36Sopenharmony_ci const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET; 501962306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(dev); 502062306a36Sopenharmony_ci unsigned int count = ch->combined_count; 502162306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 502262306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 502362306a36Sopenharmony_ci struct i40e_fdir_filter *rule; 502462306a36Sopenharmony_ci struct hlist_node *node2; 502562306a36Sopenharmony_ci int new_count; 502662306a36Sopenharmony_ci int err = 0; 502762306a36Sopenharmony_ci 502862306a36Sopenharmony_ci /* We do not support setting channels for any other VSI at present */ 502962306a36Sopenharmony_ci if (vsi->type != I40E_VSI_MAIN) 503062306a36Sopenharmony_ci return -EINVAL; 503162306a36Sopenharmony_ci 503262306a36Sopenharmony_ci /* We do not support setting channels via ethtool when TCs are 503362306a36Sopenharmony_ci * configured through mqprio 503462306a36Sopenharmony_ci */ 503562306a36Sopenharmony_ci if (i40e_is_tc_mqprio_enabled(pf)) 503662306a36Sopenharmony_ci return -EINVAL; 503762306a36Sopenharmony_ci 503862306a36Sopenharmony_ci /* verify they are not requesting separate vectors */ 503962306a36Sopenharmony_ci if (!count || ch->rx_count || ch->tx_count) 504062306a36Sopenharmony_ci return -EINVAL; 504162306a36Sopenharmony_ci 504262306a36Sopenharmony_ci /* verify other_count has not changed */ 504362306a36Sopenharmony_ci if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0)) 504462306a36Sopenharmony_ci return -EINVAL; 504562306a36Sopenharmony_ci 504662306a36Sopenharmony_ci /* verify the number of channels does not exceed hardware limits */ 504762306a36Sopenharmony_ci if (count > i40e_max_channels(vsi)) 504862306a36Sopenharmony_ci return -EINVAL; 504962306a36Sopenharmony_ci 505062306a36Sopenharmony_ci /* verify that the number of channels does not invalidate any current 505162306a36Sopenharmony_ci * flow director rules 505262306a36Sopenharmony_ci */ 505362306a36Sopenharmony_ci hlist_for_each_entry_safe(rule, node2, 505462306a36Sopenharmony_ci &pf->fdir_filter_list, fdir_node) { 505562306a36Sopenharmony_ci if (rule->dest_ctl != drop && count <= rule->q_index) { 505662306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 505762306a36Sopenharmony_ci "Existing user defined filter %d assigns flow to queue %d\n", 505862306a36Sopenharmony_ci rule->fd_id, rule->q_index); 505962306a36Sopenharmony_ci err = -EINVAL; 506062306a36Sopenharmony_ci } 506162306a36Sopenharmony_ci } 506262306a36Sopenharmony_ci 506362306a36Sopenharmony_ci if (err) { 506462306a36Sopenharmony_ci dev_err(&pf->pdev->dev, 506562306a36Sopenharmony_ci "Existing filter rules must be deleted to reduce combined channel count to %d\n", 506662306a36Sopenharmony_ci count); 506762306a36Sopenharmony_ci return err; 506862306a36Sopenharmony_ci } 506962306a36Sopenharmony_ci 507062306a36Sopenharmony_ci /* update feature limits from largest to smallest supported values */ 507162306a36Sopenharmony_ci /* TODO: Flow director limit, DCB etc */ 507262306a36Sopenharmony_ci 507362306a36Sopenharmony_ci /* use rss_reconfig to rebuild with new queue count and update traffic 507462306a36Sopenharmony_ci * class queue mapping 507562306a36Sopenharmony_ci */ 507662306a36Sopenharmony_ci new_count = i40e_reconfig_rss_queues(pf, count); 507762306a36Sopenharmony_ci if (new_count > 0) 507862306a36Sopenharmony_ci return 0; 507962306a36Sopenharmony_ci else 508062306a36Sopenharmony_ci return -EINVAL; 508162306a36Sopenharmony_ci} 508262306a36Sopenharmony_ci 508362306a36Sopenharmony_ci/** 508462306a36Sopenharmony_ci * i40e_get_rxfh_key_size - get the RSS hash key size 508562306a36Sopenharmony_ci * @netdev: network interface device structure 508662306a36Sopenharmony_ci * 508762306a36Sopenharmony_ci * Returns the table size. 508862306a36Sopenharmony_ci **/ 508962306a36Sopenharmony_cistatic u32 i40e_get_rxfh_key_size(struct net_device *netdev) 509062306a36Sopenharmony_ci{ 509162306a36Sopenharmony_ci return I40E_HKEY_ARRAY_SIZE; 509262306a36Sopenharmony_ci} 509362306a36Sopenharmony_ci 509462306a36Sopenharmony_ci/** 509562306a36Sopenharmony_ci * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size 509662306a36Sopenharmony_ci * @netdev: network interface device structure 509762306a36Sopenharmony_ci * 509862306a36Sopenharmony_ci * Returns the table size. 509962306a36Sopenharmony_ci **/ 510062306a36Sopenharmony_cistatic u32 i40e_get_rxfh_indir_size(struct net_device *netdev) 510162306a36Sopenharmony_ci{ 510262306a36Sopenharmony_ci return I40E_HLUT_ARRAY_SIZE; 510362306a36Sopenharmony_ci} 510462306a36Sopenharmony_ci 510562306a36Sopenharmony_ci/** 510662306a36Sopenharmony_ci * i40e_get_rxfh - get the rx flow hash indirection table 510762306a36Sopenharmony_ci * @netdev: network interface device structure 510862306a36Sopenharmony_ci * @indir: indirection table 510962306a36Sopenharmony_ci * @key: hash key 511062306a36Sopenharmony_ci * @hfunc: hash function 511162306a36Sopenharmony_ci * 511262306a36Sopenharmony_ci * Reads the indirection table directly from the hardware. Returns 0 on 511362306a36Sopenharmony_ci * success. 511462306a36Sopenharmony_ci **/ 511562306a36Sopenharmony_cistatic int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, 511662306a36Sopenharmony_ci u8 *hfunc) 511762306a36Sopenharmony_ci{ 511862306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 511962306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 512062306a36Sopenharmony_ci u8 *lut, *seed = NULL; 512162306a36Sopenharmony_ci int ret; 512262306a36Sopenharmony_ci u16 i; 512362306a36Sopenharmony_ci 512462306a36Sopenharmony_ci if (hfunc) 512562306a36Sopenharmony_ci *hfunc = ETH_RSS_HASH_TOP; 512662306a36Sopenharmony_ci 512762306a36Sopenharmony_ci if (!indir) 512862306a36Sopenharmony_ci return 0; 512962306a36Sopenharmony_ci 513062306a36Sopenharmony_ci seed = key; 513162306a36Sopenharmony_ci lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL); 513262306a36Sopenharmony_ci if (!lut) 513362306a36Sopenharmony_ci return -ENOMEM; 513462306a36Sopenharmony_ci ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE); 513562306a36Sopenharmony_ci if (ret) 513662306a36Sopenharmony_ci goto out; 513762306a36Sopenharmony_ci for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++) 513862306a36Sopenharmony_ci indir[i] = (u32)(lut[i]); 513962306a36Sopenharmony_ci 514062306a36Sopenharmony_ciout: 514162306a36Sopenharmony_ci kfree(lut); 514262306a36Sopenharmony_ci 514362306a36Sopenharmony_ci return ret; 514462306a36Sopenharmony_ci} 514562306a36Sopenharmony_ci 514662306a36Sopenharmony_ci/** 514762306a36Sopenharmony_ci * i40e_set_rxfh - set the rx flow hash indirection table 514862306a36Sopenharmony_ci * @netdev: network interface device structure 514962306a36Sopenharmony_ci * @indir: indirection table 515062306a36Sopenharmony_ci * @key: hash key 515162306a36Sopenharmony_ci * @hfunc: hash function to use 515262306a36Sopenharmony_ci * 515362306a36Sopenharmony_ci * Returns -EINVAL if the table specifies an invalid queue id, otherwise 515462306a36Sopenharmony_ci * returns 0 after programming the table. 515562306a36Sopenharmony_ci **/ 515662306a36Sopenharmony_cistatic int i40e_set_rxfh(struct net_device *netdev, const u32 *indir, 515762306a36Sopenharmony_ci const u8 *key, const u8 hfunc) 515862306a36Sopenharmony_ci{ 515962306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 516062306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 516162306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 516262306a36Sopenharmony_ci u8 *seed = NULL; 516362306a36Sopenharmony_ci u16 i; 516462306a36Sopenharmony_ci 516562306a36Sopenharmony_ci if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) 516662306a36Sopenharmony_ci return -EOPNOTSUPP; 516762306a36Sopenharmony_ci 516862306a36Sopenharmony_ci if (key) { 516962306a36Sopenharmony_ci if (!vsi->rss_hkey_user) { 517062306a36Sopenharmony_ci vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE, 517162306a36Sopenharmony_ci GFP_KERNEL); 517262306a36Sopenharmony_ci if (!vsi->rss_hkey_user) 517362306a36Sopenharmony_ci return -ENOMEM; 517462306a36Sopenharmony_ci } 517562306a36Sopenharmony_ci memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE); 517662306a36Sopenharmony_ci seed = vsi->rss_hkey_user; 517762306a36Sopenharmony_ci } 517862306a36Sopenharmony_ci if (!vsi->rss_lut_user) { 517962306a36Sopenharmony_ci vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL); 518062306a36Sopenharmony_ci if (!vsi->rss_lut_user) 518162306a36Sopenharmony_ci return -ENOMEM; 518262306a36Sopenharmony_ci } 518362306a36Sopenharmony_ci 518462306a36Sopenharmony_ci /* Each 32 bits pointed by 'indir' is stored with a lut entry */ 518562306a36Sopenharmony_ci if (indir) 518662306a36Sopenharmony_ci for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++) 518762306a36Sopenharmony_ci vsi->rss_lut_user[i] = (u8)(indir[i]); 518862306a36Sopenharmony_ci else 518962306a36Sopenharmony_ci i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE, 519062306a36Sopenharmony_ci vsi->rss_size); 519162306a36Sopenharmony_ci 519262306a36Sopenharmony_ci return i40e_config_rss(vsi, seed, vsi->rss_lut_user, 519362306a36Sopenharmony_ci I40E_HLUT_ARRAY_SIZE); 519462306a36Sopenharmony_ci} 519562306a36Sopenharmony_ci 519662306a36Sopenharmony_ci/** 519762306a36Sopenharmony_ci * i40e_get_priv_flags - report device private flags 519862306a36Sopenharmony_ci * @dev: network interface device structure 519962306a36Sopenharmony_ci * 520062306a36Sopenharmony_ci * The get string set count and the string set should be matched for each 520162306a36Sopenharmony_ci * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags 520262306a36Sopenharmony_ci * array. 520362306a36Sopenharmony_ci * 520462306a36Sopenharmony_ci * Returns a u32 bitmap of flags. 520562306a36Sopenharmony_ci **/ 520662306a36Sopenharmony_cistatic u32 i40e_get_priv_flags(struct net_device *dev) 520762306a36Sopenharmony_ci{ 520862306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(dev); 520962306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 521062306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 521162306a36Sopenharmony_ci u32 i, j, ret_flags = 0; 521262306a36Sopenharmony_ci 521362306a36Sopenharmony_ci for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) { 521462306a36Sopenharmony_ci const struct i40e_priv_flags *priv_flags; 521562306a36Sopenharmony_ci 521662306a36Sopenharmony_ci priv_flags = &i40e_gstrings_priv_flags[i]; 521762306a36Sopenharmony_ci 521862306a36Sopenharmony_ci if (priv_flags->flag & pf->flags) 521962306a36Sopenharmony_ci ret_flags |= BIT(i); 522062306a36Sopenharmony_ci } 522162306a36Sopenharmony_ci 522262306a36Sopenharmony_ci if (pf->hw.pf_id != 0) 522362306a36Sopenharmony_ci return ret_flags; 522462306a36Sopenharmony_ci 522562306a36Sopenharmony_ci for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) { 522662306a36Sopenharmony_ci const struct i40e_priv_flags *priv_flags; 522762306a36Sopenharmony_ci 522862306a36Sopenharmony_ci priv_flags = &i40e_gl_gstrings_priv_flags[j]; 522962306a36Sopenharmony_ci 523062306a36Sopenharmony_ci if (priv_flags->flag & pf->flags) 523162306a36Sopenharmony_ci ret_flags |= BIT(i + j); 523262306a36Sopenharmony_ci } 523362306a36Sopenharmony_ci 523462306a36Sopenharmony_ci return ret_flags; 523562306a36Sopenharmony_ci} 523662306a36Sopenharmony_ci 523762306a36Sopenharmony_ci/** 523862306a36Sopenharmony_ci * i40e_set_priv_flags - set private flags 523962306a36Sopenharmony_ci * @dev: network interface device structure 524062306a36Sopenharmony_ci * @flags: bit flags to be set 524162306a36Sopenharmony_ci **/ 524262306a36Sopenharmony_cistatic int i40e_set_priv_flags(struct net_device *dev, u32 flags) 524362306a36Sopenharmony_ci{ 524462306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(dev); 524562306a36Sopenharmony_ci u64 orig_flags, new_flags, changed_flags; 524662306a36Sopenharmony_ci enum i40e_admin_queue_err adq_err; 524762306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 524862306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 524962306a36Sopenharmony_ci u32 reset_needed = 0; 525062306a36Sopenharmony_ci int status; 525162306a36Sopenharmony_ci u32 i, j; 525262306a36Sopenharmony_ci 525362306a36Sopenharmony_ci orig_flags = READ_ONCE(pf->flags); 525462306a36Sopenharmony_ci new_flags = orig_flags; 525562306a36Sopenharmony_ci 525662306a36Sopenharmony_ci for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) { 525762306a36Sopenharmony_ci const struct i40e_priv_flags *priv_flags; 525862306a36Sopenharmony_ci 525962306a36Sopenharmony_ci priv_flags = &i40e_gstrings_priv_flags[i]; 526062306a36Sopenharmony_ci 526162306a36Sopenharmony_ci if (flags & BIT(i)) 526262306a36Sopenharmony_ci new_flags |= priv_flags->flag; 526362306a36Sopenharmony_ci else 526462306a36Sopenharmony_ci new_flags &= ~(priv_flags->flag); 526562306a36Sopenharmony_ci 526662306a36Sopenharmony_ci /* If this is a read-only flag, it can't be changed */ 526762306a36Sopenharmony_ci if (priv_flags->read_only && 526862306a36Sopenharmony_ci ((orig_flags ^ new_flags) & ~BIT(i))) 526962306a36Sopenharmony_ci return -EOPNOTSUPP; 527062306a36Sopenharmony_ci } 527162306a36Sopenharmony_ci 527262306a36Sopenharmony_ci if (pf->hw.pf_id != 0) 527362306a36Sopenharmony_ci goto flags_complete; 527462306a36Sopenharmony_ci 527562306a36Sopenharmony_ci for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) { 527662306a36Sopenharmony_ci const struct i40e_priv_flags *priv_flags; 527762306a36Sopenharmony_ci 527862306a36Sopenharmony_ci priv_flags = &i40e_gl_gstrings_priv_flags[j]; 527962306a36Sopenharmony_ci 528062306a36Sopenharmony_ci if (flags & BIT(i + j)) 528162306a36Sopenharmony_ci new_flags |= priv_flags->flag; 528262306a36Sopenharmony_ci else 528362306a36Sopenharmony_ci new_flags &= ~(priv_flags->flag); 528462306a36Sopenharmony_ci 528562306a36Sopenharmony_ci /* If this is a read-only flag, it can't be changed */ 528662306a36Sopenharmony_ci if (priv_flags->read_only && 528762306a36Sopenharmony_ci ((orig_flags ^ new_flags) & ~BIT(i))) 528862306a36Sopenharmony_ci return -EOPNOTSUPP; 528962306a36Sopenharmony_ci } 529062306a36Sopenharmony_ci 529162306a36Sopenharmony_ciflags_complete: 529262306a36Sopenharmony_ci changed_flags = orig_flags ^ new_flags; 529362306a36Sopenharmony_ci 529462306a36Sopenharmony_ci if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) 529562306a36Sopenharmony_ci reset_needed = I40E_PF_RESET_AND_REBUILD_FLAG; 529662306a36Sopenharmony_ci if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED | 529762306a36Sopenharmony_ci I40E_FLAG_LEGACY_RX | I40E_FLAG_SOURCE_PRUNING_DISABLED)) 529862306a36Sopenharmony_ci reset_needed = BIT(__I40E_PF_RESET_REQUESTED); 529962306a36Sopenharmony_ci 530062306a36Sopenharmony_ci /* Before we finalize any flag changes, we need to perform some 530162306a36Sopenharmony_ci * checks to ensure that the changes are supported and safe. 530262306a36Sopenharmony_ci */ 530362306a36Sopenharmony_ci 530462306a36Sopenharmony_ci /* ATR eviction is not supported on all devices */ 530562306a36Sopenharmony_ci if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) && 530662306a36Sopenharmony_ci !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE)) 530762306a36Sopenharmony_ci return -EOPNOTSUPP; 530862306a36Sopenharmony_ci 530962306a36Sopenharmony_ci /* If the driver detected FW LLDP was disabled on init, this flag could 531062306a36Sopenharmony_ci * be set, however we do not support _changing_ the flag: 531162306a36Sopenharmony_ci * - on XL710 if NPAR is enabled or FW API version < 1.7 531262306a36Sopenharmony_ci * - on X722 with FW API version < 1.6 531362306a36Sopenharmony_ci * There are situations where older FW versions/NPAR enabled PFs could 531462306a36Sopenharmony_ci * disable LLDP, however we _must_ not allow the user to enable/disable 531562306a36Sopenharmony_ci * LLDP with this flag on unsupported FW versions. 531662306a36Sopenharmony_ci */ 531762306a36Sopenharmony_ci if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) { 531862306a36Sopenharmony_ci if (!(pf->hw.flags & I40E_HW_FLAG_FW_LLDP_STOPPABLE)) { 531962306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 532062306a36Sopenharmony_ci "Device does not support changing FW LLDP\n"); 532162306a36Sopenharmony_ci return -EOPNOTSUPP; 532262306a36Sopenharmony_ci } 532362306a36Sopenharmony_ci } 532462306a36Sopenharmony_ci 532562306a36Sopenharmony_ci if (changed_flags & I40E_FLAG_RS_FEC && 532662306a36Sopenharmony_ci pf->hw.device_id != I40E_DEV_ID_25G_SFP28 && 532762306a36Sopenharmony_ci pf->hw.device_id != I40E_DEV_ID_25G_B) { 532862306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 532962306a36Sopenharmony_ci "Device does not support changing FEC configuration\n"); 533062306a36Sopenharmony_ci return -EOPNOTSUPP; 533162306a36Sopenharmony_ci } 533262306a36Sopenharmony_ci 533362306a36Sopenharmony_ci if (changed_flags & I40E_FLAG_BASE_R_FEC && 533462306a36Sopenharmony_ci pf->hw.device_id != I40E_DEV_ID_25G_SFP28 && 533562306a36Sopenharmony_ci pf->hw.device_id != I40E_DEV_ID_25G_B && 533662306a36Sopenharmony_ci pf->hw.device_id != I40E_DEV_ID_KX_X722) { 533762306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 533862306a36Sopenharmony_ci "Device does not support changing FEC configuration\n"); 533962306a36Sopenharmony_ci return -EOPNOTSUPP; 534062306a36Sopenharmony_ci } 534162306a36Sopenharmony_ci 534262306a36Sopenharmony_ci /* Process any additional changes needed as a result of flag changes. 534362306a36Sopenharmony_ci * The changed_flags value reflects the list of bits that were 534462306a36Sopenharmony_ci * changed in the code above. 534562306a36Sopenharmony_ci */ 534662306a36Sopenharmony_ci 534762306a36Sopenharmony_ci /* Flush current ATR settings if ATR was disabled */ 534862306a36Sopenharmony_ci if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) && 534962306a36Sopenharmony_ci !(new_flags & I40E_FLAG_FD_ATR_ENABLED)) { 535062306a36Sopenharmony_ci set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state); 535162306a36Sopenharmony_ci set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state); 535262306a36Sopenharmony_ci } 535362306a36Sopenharmony_ci 535462306a36Sopenharmony_ci if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) { 535562306a36Sopenharmony_ci u16 sw_flags = 0, valid_flags = 0; 535662306a36Sopenharmony_ci int ret; 535762306a36Sopenharmony_ci 535862306a36Sopenharmony_ci if (!(new_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) 535962306a36Sopenharmony_ci sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; 536062306a36Sopenharmony_ci valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; 536162306a36Sopenharmony_ci ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags, 536262306a36Sopenharmony_ci 0, NULL); 536362306a36Sopenharmony_ci if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { 536462306a36Sopenharmony_ci dev_info(&pf->pdev->dev, 536562306a36Sopenharmony_ci "couldn't set switch config bits, err %pe aq_err %s\n", 536662306a36Sopenharmony_ci ERR_PTR(ret), 536762306a36Sopenharmony_ci i40e_aq_str(&pf->hw, 536862306a36Sopenharmony_ci pf->hw.aq.asq_last_status)); 536962306a36Sopenharmony_ci /* not a fatal problem, just keep going */ 537062306a36Sopenharmony_ci } 537162306a36Sopenharmony_ci } 537262306a36Sopenharmony_ci 537362306a36Sopenharmony_ci if ((changed_flags & I40E_FLAG_RS_FEC) || 537462306a36Sopenharmony_ci (changed_flags & I40E_FLAG_BASE_R_FEC)) { 537562306a36Sopenharmony_ci u8 fec_cfg = 0; 537662306a36Sopenharmony_ci 537762306a36Sopenharmony_ci if (new_flags & I40E_FLAG_RS_FEC && 537862306a36Sopenharmony_ci new_flags & I40E_FLAG_BASE_R_FEC) { 537962306a36Sopenharmony_ci fec_cfg = I40E_AQ_SET_FEC_AUTO; 538062306a36Sopenharmony_ci } else if (new_flags & I40E_FLAG_RS_FEC) { 538162306a36Sopenharmony_ci fec_cfg = (I40E_AQ_SET_FEC_REQUEST_RS | 538262306a36Sopenharmony_ci I40E_AQ_SET_FEC_ABILITY_RS); 538362306a36Sopenharmony_ci } else if (new_flags & I40E_FLAG_BASE_R_FEC) { 538462306a36Sopenharmony_ci fec_cfg = (I40E_AQ_SET_FEC_REQUEST_KR | 538562306a36Sopenharmony_ci I40E_AQ_SET_FEC_ABILITY_KR); 538662306a36Sopenharmony_ci } 538762306a36Sopenharmony_ci if (i40e_set_fec_cfg(dev, fec_cfg)) 538862306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, "Cannot change FEC config\n"); 538962306a36Sopenharmony_ci } 539062306a36Sopenharmony_ci 539162306a36Sopenharmony_ci if ((changed_flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED) && 539262306a36Sopenharmony_ci (orig_flags & I40E_FLAG_TOTAL_PORT_SHUTDOWN_ENABLED)) { 539362306a36Sopenharmony_ci dev_err(&pf->pdev->dev, 539462306a36Sopenharmony_ci "Setting link-down-on-close not supported on this port (because total-port-shutdown is enabled)\n"); 539562306a36Sopenharmony_ci return -EOPNOTSUPP; 539662306a36Sopenharmony_ci } 539762306a36Sopenharmony_ci 539862306a36Sopenharmony_ci if ((changed_flags & I40E_FLAG_VF_VLAN_PRUNING) && 539962306a36Sopenharmony_ci pf->num_alloc_vfs) { 540062306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 540162306a36Sopenharmony_ci "Changing vf-vlan-pruning flag while VF(s) are active is not supported\n"); 540262306a36Sopenharmony_ci return -EOPNOTSUPP; 540362306a36Sopenharmony_ci } 540462306a36Sopenharmony_ci 540562306a36Sopenharmony_ci if ((changed_flags & I40E_FLAG_LEGACY_RX) && 540662306a36Sopenharmony_ci I40E_2K_TOO_SMALL_WITH_PADDING) { 540762306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 540862306a36Sopenharmony_ci "2k Rx buffer is too small to fit standard MTU and skb_shared_info\n"); 540962306a36Sopenharmony_ci return -EOPNOTSUPP; 541062306a36Sopenharmony_ci } 541162306a36Sopenharmony_ci 541262306a36Sopenharmony_ci if ((changed_flags & new_flags & 541362306a36Sopenharmony_ci I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED) && 541462306a36Sopenharmony_ci (new_flags & I40E_FLAG_MFP_ENABLED)) 541562306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 541662306a36Sopenharmony_ci "Turning on link-down-on-close flag may affect other partitions\n"); 541762306a36Sopenharmony_ci 541862306a36Sopenharmony_ci if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) { 541962306a36Sopenharmony_ci if (new_flags & I40E_FLAG_DISABLE_FW_LLDP) { 542062306a36Sopenharmony_ci#ifdef CONFIG_I40E_DCB 542162306a36Sopenharmony_ci i40e_dcb_sw_default_config(pf); 542262306a36Sopenharmony_ci#endif /* CONFIG_I40E_DCB */ 542362306a36Sopenharmony_ci i40e_aq_cfg_lldp_mib_change_event(&pf->hw, false, NULL); 542462306a36Sopenharmony_ci i40e_aq_stop_lldp(&pf->hw, true, false, NULL); 542562306a36Sopenharmony_ci } else { 542662306a36Sopenharmony_ci status = i40e_aq_start_lldp(&pf->hw, false, NULL); 542762306a36Sopenharmony_ci if (status) { 542862306a36Sopenharmony_ci adq_err = pf->hw.aq.asq_last_status; 542962306a36Sopenharmony_ci switch (adq_err) { 543062306a36Sopenharmony_ci case I40E_AQ_RC_EEXIST: 543162306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 543262306a36Sopenharmony_ci "FW LLDP agent is already running\n"); 543362306a36Sopenharmony_ci reset_needed = 0; 543462306a36Sopenharmony_ci break; 543562306a36Sopenharmony_ci case I40E_AQ_RC_EPERM: 543662306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 543762306a36Sopenharmony_ci "Device configuration forbids SW from starting the LLDP agent.\n"); 543862306a36Sopenharmony_ci return -EINVAL; 543962306a36Sopenharmony_ci case I40E_AQ_RC_EAGAIN: 544062306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 544162306a36Sopenharmony_ci "Stop FW LLDP agent command is still being processed, please try again in a second.\n"); 544262306a36Sopenharmony_ci return -EBUSY; 544362306a36Sopenharmony_ci default: 544462306a36Sopenharmony_ci dev_warn(&pf->pdev->dev, 544562306a36Sopenharmony_ci "Starting FW LLDP agent failed: error: %pe, %s\n", 544662306a36Sopenharmony_ci ERR_PTR(status), 544762306a36Sopenharmony_ci i40e_aq_str(&pf->hw, 544862306a36Sopenharmony_ci adq_err)); 544962306a36Sopenharmony_ci return -EINVAL; 545062306a36Sopenharmony_ci } 545162306a36Sopenharmony_ci } 545262306a36Sopenharmony_ci } 545362306a36Sopenharmony_ci } 545462306a36Sopenharmony_ci 545562306a36Sopenharmony_ci /* Now that we've checked to ensure that the new flags are valid, load 545662306a36Sopenharmony_ci * them into place. Since we only modify flags either (a) during 545762306a36Sopenharmony_ci * initialization or (b) while holding the RTNL lock, we don't need 545862306a36Sopenharmony_ci * anything fancy here. 545962306a36Sopenharmony_ci */ 546062306a36Sopenharmony_ci pf->flags = new_flags; 546162306a36Sopenharmony_ci 546262306a36Sopenharmony_ci /* Issue reset to cause things to take effect, as additional bits 546362306a36Sopenharmony_ci * are added we will need to create a mask of bits requiring reset 546462306a36Sopenharmony_ci */ 546562306a36Sopenharmony_ci if (reset_needed) 546662306a36Sopenharmony_ci i40e_do_reset(pf, reset_needed, true); 546762306a36Sopenharmony_ci 546862306a36Sopenharmony_ci return 0; 546962306a36Sopenharmony_ci} 547062306a36Sopenharmony_ci 547162306a36Sopenharmony_ci/** 547262306a36Sopenharmony_ci * i40e_get_module_info - get (Q)SFP+ module type info 547362306a36Sopenharmony_ci * @netdev: network interface device structure 547462306a36Sopenharmony_ci * @modinfo: module EEPROM size and layout information structure 547562306a36Sopenharmony_ci **/ 547662306a36Sopenharmony_cistatic int i40e_get_module_info(struct net_device *netdev, 547762306a36Sopenharmony_ci struct ethtool_modinfo *modinfo) 547862306a36Sopenharmony_ci{ 547962306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 548062306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 548162306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 548262306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 548362306a36Sopenharmony_ci u32 sff8472_comp = 0; 548462306a36Sopenharmony_ci u32 sff8472_swap = 0; 548562306a36Sopenharmony_ci u32 sff8636_rev = 0; 548662306a36Sopenharmony_ci u32 type = 0; 548762306a36Sopenharmony_ci int status; 548862306a36Sopenharmony_ci 548962306a36Sopenharmony_ci /* Check if firmware supports reading module EEPROM. */ 549062306a36Sopenharmony_ci if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) { 549162306a36Sopenharmony_ci netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n"); 549262306a36Sopenharmony_ci return -EINVAL; 549362306a36Sopenharmony_ci } 549462306a36Sopenharmony_ci 549562306a36Sopenharmony_ci status = i40e_update_link_info(hw); 549662306a36Sopenharmony_ci if (status) 549762306a36Sopenharmony_ci return -EIO; 549862306a36Sopenharmony_ci 549962306a36Sopenharmony_ci if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) { 550062306a36Sopenharmony_ci netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n"); 550162306a36Sopenharmony_ci return -EINVAL; 550262306a36Sopenharmony_ci } 550362306a36Sopenharmony_ci 550462306a36Sopenharmony_ci type = hw->phy.link_info.module_type[0]; 550562306a36Sopenharmony_ci 550662306a36Sopenharmony_ci switch (type) { 550762306a36Sopenharmony_ci case I40E_MODULE_TYPE_SFP: 550862306a36Sopenharmony_ci status = i40e_aq_get_phy_register(hw, 550962306a36Sopenharmony_ci I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE, 551062306a36Sopenharmony_ci I40E_I2C_EEPROM_DEV_ADDR, true, 551162306a36Sopenharmony_ci I40E_MODULE_SFF_8472_COMP, 551262306a36Sopenharmony_ci &sff8472_comp, NULL); 551362306a36Sopenharmony_ci if (status) 551462306a36Sopenharmony_ci return -EIO; 551562306a36Sopenharmony_ci 551662306a36Sopenharmony_ci status = i40e_aq_get_phy_register(hw, 551762306a36Sopenharmony_ci I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE, 551862306a36Sopenharmony_ci I40E_I2C_EEPROM_DEV_ADDR, true, 551962306a36Sopenharmony_ci I40E_MODULE_SFF_8472_SWAP, 552062306a36Sopenharmony_ci &sff8472_swap, NULL); 552162306a36Sopenharmony_ci if (status) 552262306a36Sopenharmony_ci return -EIO; 552362306a36Sopenharmony_ci 552462306a36Sopenharmony_ci /* Check if the module requires address swap to access 552562306a36Sopenharmony_ci * the other EEPROM memory page. 552662306a36Sopenharmony_ci */ 552762306a36Sopenharmony_ci if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) { 552862306a36Sopenharmony_ci netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n"); 552962306a36Sopenharmony_ci modinfo->type = ETH_MODULE_SFF_8079; 553062306a36Sopenharmony_ci modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; 553162306a36Sopenharmony_ci } else if (sff8472_comp == 0x00) { 553262306a36Sopenharmony_ci /* Module is not SFF-8472 compliant */ 553362306a36Sopenharmony_ci modinfo->type = ETH_MODULE_SFF_8079; 553462306a36Sopenharmony_ci modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; 553562306a36Sopenharmony_ci } else if (!(sff8472_swap & I40E_MODULE_SFF_DDM_IMPLEMENTED)) { 553662306a36Sopenharmony_ci /* Module is SFF-8472 compliant but doesn't implement 553762306a36Sopenharmony_ci * Digital Diagnostic Monitoring (DDM). 553862306a36Sopenharmony_ci */ 553962306a36Sopenharmony_ci modinfo->type = ETH_MODULE_SFF_8079; 554062306a36Sopenharmony_ci modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; 554162306a36Sopenharmony_ci } else { 554262306a36Sopenharmony_ci modinfo->type = ETH_MODULE_SFF_8472; 554362306a36Sopenharmony_ci modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; 554462306a36Sopenharmony_ci } 554562306a36Sopenharmony_ci break; 554662306a36Sopenharmony_ci case I40E_MODULE_TYPE_QSFP_PLUS: 554762306a36Sopenharmony_ci /* Read from memory page 0. */ 554862306a36Sopenharmony_ci status = i40e_aq_get_phy_register(hw, 554962306a36Sopenharmony_ci I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE, 555062306a36Sopenharmony_ci 0, true, 555162306a36Sopenharmony_ci I40E_MODULE_REVISION_ADDR, 555262306a36Sopenharmony_ci &sff8636_rev, NULL); 555362306a36Sopenharmony_ci if (status) 555462306a36Sopenharmony_ci return -EIO; 555562306a36Sopenharmony_ci /* Determine revision compliance byte */ 555662306a36Sopenharmony_ci if (sff8636_rev > 0x02) { 555762306a36Sopenharmony_ci /* Module is SFF-8636 compliant */ 555862306a36Sopenharmony_ci modinfo->type = ETH_MODULE_SFF_8636; 555962306a36Sopenharmony_ci modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN; 556062306a36Sopenharmony_ci } else { 556162306a36Sopenharmony_ci modinfo->type = ETH_MODULE_SFF_8436; 556262306a36Sopenharmony_ci modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN; 556362306a36Sopenharmony_ci } 556462306a36Sopenharmony_ci break; 556562306a36Sopenharmony_ci case I40E_MODULE_TYPE_QSFP28: 556662306a36Sopenharmony_ci modinfo->type = ETH_MODULE_SFF_8636; 556762306a36Sopenharmony_ci modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN; 556862306a36Sopenharmony_ci break; 556962306a36Sopenharmony_ci default: 557062306a36Sopenharmony_ci netdev_err(vsi->netdev, "Module type unrecognized\n"); 557162306a36Sopenharmony_ci return -EINVAL; 557262306a36Sopenharmony_ci } 557362306a36Sopenharmony_ci return 0; 557462306a36Sopenharmony_ci} 557562306a36Sopenharmony_ci 557662306a36Sopenharmony_ci/** 557762306a36Sopenharmony_ci * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents 557862306a36Sopenharmony_ci * @netdev: network interface device structure 557962306a36Sopenharmony_ci * @ee: EEPROM dump request structure 558062306a36Sopenharmony_ci * @data: buffer to be filled with EEPROM contents 558162306a36Sopenharmony_ci **/ 558262306a36Sopenharmony_cistatic int i40e_get_module_eeprom(struct net_device *netdev, 558362306a36Sopenharmony_ci struct ethtool_eeprom *ee, 558462306a36Sopenharmony_ci u8 *data) 558562306a36Sopenharmony_ci{ 558662306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 558762306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 558862306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 558962306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 559062306a36Sopenharmony_ci bool is_sfp = false; 559162306a36Sopenharmony_ci u32 value = 0; 559262306a36Sopenharmony_ci int status; 559362306a36Sopenharmony_ci int i; 559462306a36Sopenharmony_ci 559562306a36Sopenharmony_ci if (!ee || !ee->len || !data) 559662306a36Sopenharmony_ci return -EINVAL; 559762306a36Sopenharmony_ci 559862306a36Sopenharmony_ci if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP) 559962306a36Sopenharmony_ci is_sfp = true; 560062306a36Sopenharmony_ci 560162306a36Sopenharmony_ci for (i = 0; i < ee->len; i++) { 560262306a36Sopenharmony_ci u32 offset = i + ee->offset; 560362306a36Sopenharmony_ci u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0; 560462306a36Sopenharmony_ci 560562306a36Sopenharmony_ci /* Check if we need to access the other memory page */ 560662306a36Sopenharmony_ci if (is_sfp) { 560762306a36Sopenharmony_ci if (offset >= ETH_MODULE_SFF_8079_LEN) { 560862306a36Sopenharmony_ci offset -= ETH_MODULE_SFF_8079_LEN; 560962306a36Sopenharmony_ci addr = I40E_I2C_EEPROM_DEV_ADDR2; 561062306a36Sopenharmony_ci } 561162306a36Sopenharmony_ci } else { 561262306a36Sopenharmony_ci while (offset >= ETH_MODULE_SFF_8436_LEN) { 561362306a36Sopenharmony_ci /* Compute memory page number and offset. */ 561462306a36Sopenharmony_ci offset -= ETH_MODULE_SFF_8436_LEN / 2; 561562306a36Sopenharmony_ci addr++; 561662306a36Sopenharmony_ci } 561762306a36Sopenharmony_ci } 561862306a36Sopenharmony_ci 561962306a36Sopenharmony_ci status = i40e_aq_get_phy_register(hw, 562062306a36Sopenharmony_ci I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE, 562162306a36Sopenharmony_ci addr, true, offset, &value, NULL); 562262306a36Sopenharmony_ci if (status) 562362306a36Sopenharmony_ci return -EIO; 562462306a36Sopenharmony_ci data[i] = value; 562562306a36Sopenharmony_ci } 562662306a36Sopenharmony_ci return 0; 562762306a36Sopenharmony_ci} 562862306a36Sopenharmony_ci 562962306a36Sopenharmony_cistatic int i40e_get_eee(struct net_device *netdev, struct ethtool_eee *edata) 563062306a36Sopenharmony_ci{ 563162306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 563262306a36Sopenharmony_ci struct i40e_aq_get_phy_abilities_resp phy_cfg; 563362306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 563462306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 563562306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 563662306a36Sopenharmony_ci int status = 0; 563762306a36Sopenharmony_ci 563862306a36Sopenharmony_ci /* Get initial PHY capabilities */ 563962306a36Sopenharmony_ci status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_cfg, NULL); 564062306a36Sopenharmony_ci if (status) 564162306a36Sopenharmony_ci return -EAGAIN; 564262306a36Sopenharmony_ci 564362306a36Sopenharmony_ci /* Check whether NIC configuration is compatible with Energy Efficient 564462306a36Sopenharmony_ci * Ethernet (EEE) mode. 564562306a36Sopenharmony_ci */ 564662306a36Sopenharmony_ci if (phy_cfg.eee_capability == 0) 564762306a36Sopenharmony_ci return -EOPNOTSUPP; 564862306a36Sopenharmony_ci 564962306a36Sopenharmony_ci edata->supported = SUPPORTED_Autoneg; 565062306a36Sopenharmony_ci edata->lp_advertised = edata->supported; 565162306a36Sopenharmony_ci 565262306a36Sopenharmony_ci /* Get current configuration */ 565362306a36Sopenharmony_ci status = i40e_aq_get_phy_capabilities(hw, false, false, &phy_cfg, NULL); 565462306a36Sopenharmony_ci if (status) 565562306a36Sopenharmony_ci return -EAGAIN; 565662306a36Sopenharmony_ci 565762306a36Sopenharmony_ci edata->advertised = phy_cfg.eee_capability ? SUPPORTED_Autoneg : 0U; 565862306a36Sopenharmony_ci edata->eee_enabled = !!edata->advertised; 565962306a36Sopenharmony_ci edata->tx_lpi_enabled = pf->stats.tx_lpi_status; 566062306a36Sopenharmony_ci 566162306a36Sopenharmony_ci edata->eee_active = pf->stats.tx_lpi_status && pf->stats.rx_lpi_status; 566262306a36Sopenharmony_ci 566362306a36Sopenharmony_ci return 0; 566462306a36Sopenharmony_ci} 566562306a36Sopenharmony_ci 566662306a36Sopenharmony_cistatic int i40e_is_eee_param_supported(struct net_device *netdev, 566762306a36Sopenharmony_ci struct ethtool_eee *edata) 566862306a36Sopenharmony_ci{ 566962306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 567062306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 567162306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 567262306a36Sopenharmony_ci struct i40e_ethtool_not_used { 567362306a36Sopenharmony_ci u32 value; 567462306a36Sopenharmony_ci const char *name; 567562306a36Sopenharmony_ci } param[] = { 567662306a36Sopenharmony_ci {edata->advertised & ~SUPPORTED_Autoneg, "advertise"}, 567762306a36Sopenharmony_ci {edata->tx_lpi_timer, "tx-timer"}, 567862306a36Sopenharmony_ci {edata->tx_lpi_enabled != pf->stats.tx_lpi_status, "tx-lpi"} 567962306a36Sopenharmony_ci }; 568062306a36Sopenharmony_ci int i; 568162306a36Sopenharmony_ci 568262306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(param); i++) { 568362306a36Sopenharmony_ci if (param[i].value) { 568462306a36Sopenharmony_ci netdev_info(netdev, 568562306a36Sopenharmony_ci "EEE setting %s not supported\n", 568662306a36Sopenharmony_ci param[i].name); 568762306a36Sopenharmony_ci return -EOPNOTSUPP; 568862306a36Sopenharmony_ci } 568962306a36Sopenharmony_ci } 569062306a36Sopenharmony_ci 569162306a36Sopenharmony_ci return 0; 569262306a36Sopenharmony_ci} 569362306a36Sopenharmony_ci 569462306a36Sopenharmony_cistatic int i40e_set_eee(struct net_device *netdev, struct ethtool_eee *edata) 569562306a36Sopenharmony_ci{ 569662306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 569762306a36Sopenharmony_ci struct i40e_aq_get_phy_abilities_resp abilities; 569862306a36Sopenharmony_ci struct i40e_aq_set_phy_config config; 569962306a36Sopenharmony_ci struct i40e_vsi *vsi = np->vsi; 570062306a36Sopenharmony_ci struct i40e_pf *pf = vsi->back; 570162306a36Sopenharmony_ci struct i40e_hw *hw = &pf->hw; 570262306a36Sopenharmony_ci __le16 eee_capability; 570362306a36Sopenharmony_ci int status = 0; 570462306a36Sopenharmony_ci 570562306a36Sopenharmony_ci /* Deny parameters we don't support */ 570662306a36Sopenharmony_ci if (i40e_is_eee_param_supported(netdev, edata)) 570762306a36Sopenharmony_ci return -EOPNOTSUPP; 570862306a36Sopenharmony_ci 570962306a36Sopenharmony_ci /* Get initial PHY capabilities */ 571062306a36Sopenharmony_ci status = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, 571162306a36Sopenharmony_ci NULL); 571262306a36Sopenharmony_ci if (status) 571362306a36Sopenharmony_ci return -EAGAIN; 571462306a36Sopenharmony_ci 571562306a36Sopenharmony_ci /* Check whether NIC configuration is compatible with Energy Efficient 571662306a36Sopenharmony_ci * Ethernet (EEE) mode. 571762306a36Sopenharmony_ci */ 571862306a36Sopenharmony_ci if (abilities.eee_capability == 0) 571962306a36Sopenharmony_ci return -EOPNOTSUPP; 572062306a36Sopenharmony_ci 572162306a36Sopenharmony_ci /* Cache initial EEE capability */ 572262306a36Sopenharmony_ci eee_capability = abilities.eee_capability; 572362306a36Sopenharmony_ci 572462306a36Sopenharmony_ci /* Get current PHY configuration */ 572562306a36Sopenharmony_ci status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, 572662306a36Sopenharmony_ci NULL); 572762306a36Sopenharmony_ci if (status) 572862306a36Sopenharmony_ci return -EAGAIN; 572962306a36Sopenharmony_ci 573062306a36Sopenharmony_ci /* Cache current PHY configuration */ 573162306a36Sopenharmony_ci config.phy_type = abilities.phy_type; 573262306a36Sopenharmony_ci config.phy_type_ext = abilities.phy_type_ext; 573362306a36Sopenharmony_ci config.link_speed = abilities.link_speed; 573462306a36Sopenharmony_ci config.abilities = abilities.abilities | 573562306a36Sopenharmony_ci I40E_AQ_PHY_ENABLE_ATOMIC_LINK; 573662306a36Sopenharmony_ci config.eeer = abilities.eeer_val; 573762306a36Sopenharmony_ci config.low_power_ctrl = abilities.d3_lpan; 573862306a36Sopenharmony_ci config.fec_config = abilities.fec_cfg_curr_mod_ext_info & 573962306a36Sopenharmony_ci I40E_AQ_PHY_FEC_CONFIG_MASK; 574062306a36Sopenharmony_ci 574162306a36Sopenharmony_ci /* Set desired EEE state */ 574262306a36Sopenharmony_ci if (edata->eee_enabled) { 574362306a36Sopenharmony_ci config.eee_capability = eee_capability; 574462306a36Sopenharmony_ci config.eeer |= cpu_to_le32(I40E_PRTPM_EEER_TX_LPI_EN_MASK); 574562306a36Sopenharmony_ci } else { 574662306a36Sopenharmony_ci config.eee_capability = 0; 574762306a36Sopenharmony_ci config.eeer &= cpu_to_le32(~I40E_PRTPM_EEER_TX_LPI_EN_MASK); 574862306a36Sopenharmony_ci } 574962306a36Sopenharmony_ci 575062306a36Sopenharmony_ci /* Apply modified PHY configuration */ 575162306a36Sopenharmony_ci status = i40e_aq_set_phy_config(hw, &config, NULL); 575262306a36Sopenharmony_ci if (status) 575362306a36Sopenharmony_ci return -EAGAIN; 575462306a36Sopenharmony_ci 575562306a36Sopenharmony_ci return 0; 575662306a36Sopenharmony_ci} 575762306a36Sopenharmony_ci 575862306a36Sopenharmony_cistatic const struct ethtool_ops i40e_ethtool_recovery_mode_ops = { 575962306a36Sopenharmony_ci .get_drvinfo = i40e_get_drvinfo, 576062306a36Sopenharmony_ci .set_eeprom = i40e_set_eeprom, 576162306a36Sopenharmony_ci .get_eeprom_len = i40e_get_eeprom_len, 576262306a36Sopenharmony_ci .get_eeprom = i40e_get_eeprom, 576362306a36Sopenharmony_ci}; 576462306a36Sopenharmony_ci 576562306a36Sopenharmony_cistatic const struct ethtool_ops i40e_ethtool_ops = { 576662306a36Sopenharmony_ci .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 576762306a36Sopenharmony_ci ETHTOOL_COALESCE_MAX_FRAMES_IRQ | 576862306a36Sopenharmony_ci ETHTOOL_COALESCE_USE_ADAPTIVE | 576962306a36Sopenharmony_ci ETHTOOL_COALESCE_RX_USECS_HIGH | 577062306a36Sopenharmony_ci ETHTOOL_COALESCE_TX_USECS_HIGH, 577162306a36Sopenharmony_ci .get_drvinfo = i40e_get_drvinfo, 577262306a36Sopenharmony_ci .get_regs_len = i40e_get_regs_len, 577362306a36Sopenharmony_ci .get_regs = i40e_get_regs, 577462306a36Sopenharmony_ci .nway_reset = i40e_nway_reset, 577562306a36Sopenharmony_ci .get_link = ethtool_op_get_link, 577662306a36Sopenharmony_ci .get_wol = i40e_get_wol, 577762306a36Sopenharmony_ci .set_wol = i40e_set_wol, 577862306a36Sopenharmony_ci .set_eeprom = i40e_set_eeprom, 577962306a36Sopenharmony_ci .get_eeprom_len = i40e_get_eeprom_len, 578062306a36Sopenharmony_ci .get_eeprom = i40e_get_eeprom, 578162306a36Sopenharmony_ci .get_ringparam = i40e_get_ringparam, 578262306a36Sopenharmony_ci .set_ringparam = i40e_set_ringparam, 578362306a36Sopenharmony_ci .get_pauseparam = i40e_get_pauseparam, 578462306a36Sopenharmony_ci .set_pauseparam = i40e_set_pauseparam, 578562306a36Sopenharmony_ci .get_msglevel = i40e_get_msglevel, 578662306a36Sopenharmony_ci .set_msglevel = i40e_set_msglevel, 578762306a36Sopenharmony_ci .get_rxnfc = i40e_get_rxnfc, 578862306a36Sopenharmony_ci .set_rxnfc = i40e_set_rxnfc, 578962306a36Sopenharmony_ci .self_test = i40e_diag_test, 579062306a36Sopenharmony_ci .get_strings = i40e_get_strings, 579162306a36Sopenharmony_ci .get_eee = i40e_get_eee, 579262306a36Sopenharmony_ci .set_eee = i40e_set_eee, 579362306a36Sopenharmony_ci .set_phys_id = i40e_set_phys_id, 579462306a36Sopenharmony_ci .get_sset_count = i40e_get_sset_count, 579562306a36Sopenharmony_ci .get_ethtool_stats = i40e_get_ethtool_stats, 579662306a36Sopenharmony_ci .get_coalesce = i40e_get_coalesce, 579762306a36Sopenharmony_ci .set_coalesce = i40e_set_coalesce, 579862306a36Sopenharmony_ci .get_rxfh_key_size = i40e_get_rxfh_key_size, 579962306a36Sopenharmony_ci .get_rxfh_indir_size = i40e_get_rxfh_indir_size, 580062306a36Sopenharmony_ci .get_rxfh = i40e_get_rxfh, 580162306a36Sopenharmony_ci .set_rxfh = i40e_set_rxfh, 580262306a36Sopenharmony_ci .get_channels = i40e_get_channels, 580362306a36Sopenharmony_ci .set_channels = i40e_set_channels, 580462306a36Sopenharmony_ci .get_module_info = i40e_get_module_info, 580562306a36Sopenharmony_ci .get_module_eeprom = i40e_get_module_eeprom, 580662306a36Sopenharmony_ci .get_ts_info = i40e_get_ts_info, 580762306a36Sopenharmony_ci .get_priv_flags = i40e_get_priv_flags, 580862306a36Sopenharmony_ci .set_priv_flags = i40e_set_priv_flags, 580962306a36Sopenharmony_ci .get_per_queue_coalesce = i40e_get_per_queue_coalesce, 581062306a36Sopenharmony_ci .set_per_queue_coalesce = i40e_set_per_queue_coalesce, 581162306a36Sopenharmony_ci .get_link_ksettings = i40e_get_link_ksettings, 581262306a36Sopenharmony_ci .set_link_ksettings = i40e_set_link_ksettings, 581362306a36Sopenharmony_ci .get_fecparam = i40e_get_fec_param, 581462306a36Sopenharmony_ci .set_fecparam = i40e_set_fec_param, 581562306a36Sopenharmony_ci .flash_device = i40e_ddp_flash, 581662306a36Sopenharmony_ci}; 581762306a36Sopenharmony_ci 581862306a36Sopenharmony_civoid i40e_set_ethtool_ops(struct net_device *netdev) 581962306a36Sopenharmony_ci{ 582062306a36Sopenharmony_ci struct i40e_netdev_priv *np = netdev_priv(netdev); 582162306a36Sopenharmony_ci struct i40e_pf *pf = np->vsi->back; 582262306a36Sopenharmony_ci 582362306a36Sopenharmony_ci if (!test_bit(__I40E_RECOVERY_MODE, pf->state)) 582462306a36Sopenharmony_ci netdev->ethtool_ops = &i40e_ethtool_ops; 582562306a36Sopenharmony_ci else 582662306a36Sopenharmony_ci netdev->ethtool_ops = &i40e_ethtool_recovery_mode_ops; 582762306a36Sopenharmony_ci} 5828