1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
4 /* ethtool support for i40e */
8 #include "i40e_txrx_common.h"
10 /* ethtool statistics helpers */
13 * struct i40e_stats - definition for an ethtool statistic
14 * @stat_string: statistic name to display in ethtool -S output
15 * @sizeof_stat: the sizeof() the stat, must be no greater than sizeof(u64)
16 * @stat_offset: offsetof() the stat from a base pointer
18 * This structure defines a statistic to be added to the ethtool stats buffer.
19 * It defines a statistic as offset from a common base pointer. Stats should
20 * be defined in constant arrays using the I40E_STAT macro, with every element
21 * of the array using the same _type for calculating the sizeof_stat and
24 * The @sizeof_stat is expected to be sizeof(u8), sizeof(u16), sizeof(u32) or
25 * sizeof(u64). Other sizes are not expected and will produce a WARN_ONCE from
26 * the i40e_add_ethtool_stat() helper function.
28 * The @stat_string is interpreted as a format string, allowing formatted
29 * values to be inserted while looping over multiple structures for a given
30 * statistics array. Thus, every statistic string in an array should have the
31 * same type and number of format specifiers, to be formatted by variadic
32 * arguments to the i40e_add_stat_string() helper function.
35 char stat_string[ETH_GSTRING_LEN];
40 /* Helper macro to define an i40e_stat structure with proper size and type.
41 * Use this when defining constant statistics arrays. Note that @_type expects
42 * only a type name and is used multiple times.
44 #define I40E_STAT(_type, _name, _stat) { \
45 .stat_string = _name, \
46 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
47 .stat_offset = offsetof(_type, _stat) \
50 /* Helper macro for defining some statistics directly copied from the netdev
53 #define I40E_NETDEV_STAT(_net_stat) \
54 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
56 /* Helper macro for defining some statistics related to queues */
57 #define I40E_QUEUE_STAT(_name, _stat) \
58 I40E_STAT(struct i40e_ring, _name, _stat)
60 /* Stats associated with a Tx or Rx ring */
61 static const struct i40e_stats i40e_gstrings_queue_stats[] = {
62 I40E_QUEUE_STAT("%s-%u.packets", stats.packets),
63 I40E_QUEUE_STAT("%s-%u.bytes", stats.bytes),
67 * i40e_add_one_ethtool_stat - copy the stat into the supplied buffer
68 * @data: location to store the stat value
69 * @pointer: basis for where to copy from
70 * @stat: the stat definition
72 * Copies the stat data defined by the pointer and stat structure pair into
73 * the memory supplied as data. Used to implement i40e_add_ethtool_stats and
74 * i40e_add_queue_stats. If the pointer is null, data will be zero'd.
77 i40e_add_one_ethtool_stat(u64 *data, void *pointer,
78 const struct i40e_stats *stat)
83 /* ensure that the ethtool data buffer is zero'd for any stats
84 * which don't have a valid pointer.
90 p = (char *)pointer + stat->stat_offset;
91 switch (stat->sizeof_stat) {
105 WARN_ONCE(1, "unexpected stat size for %s",
112 * __i40e_add_ethtool_stats - copy stats into the ethtool supplied buffer
113 * @data: ethtool stats buffer
114 * @pointer: location to copy stats from
115 * @stats: array of stats to copy
116 * @size: the size of the stats definition
118 * Copy the stats defined by the stats array using the pointer as a base into
119 * the data buffer supplied by ethtool. Updates the data pointer to point to
120 * the next empty location for successive calls to __i40e_add_ethtool_stats.
121 * If pointer is null, set the data values to zero and update the pointer to
125 __i40e_add_ethtool_stats(u64 **data, void *pointer,
126 const struct i40e_stats stats[],
127 const unsigned int size)
131 for (i = 0; i < size; i++)
132 i40e_add_one_ethtool_stat((*data)++, pointer, &stats[i]);
136 * i40e_add_ethtool_stats - copy stats into ethtool supplied buffer
137 * @data: ethtool stats buffer
138 * @pointer: location where stats are stored
139 * @stats: static const array of stat definitions
141 * Macro to ease the use of __i40e_add_ethtool_stats by taking a static
142 * constant stats array and passing the ARRAY_SIZE(). This avoids typos by
143 * ensuring that we pass the size associated with the given stats array.
145 * The parameter @stats is evaluated twice, so parameters with side effects
148 #define i40e_add_ethtool_stats(data, pointer, stats) \
149 __i40e_add_ethtool_stats(data, pointer, stats, ARRAY_SIZE(stats))
152 * i40e_add_queue_stats - copy queue statistics into supplied buffer
153 * @data: ethtool stats buffer
154 * @ring: the ring to copy
156 * Queue statistics must be copied while protected by
157 * u64_stats_fetch_begin_irq, so we can't directly use i40e_add_ethtool_stats.
158 * Assumes that queue stats are defined in i40e_gstrings_queue_stats. If the
159 * ring pointer is null, zero out the queue stat values and update the data
160 * pointer. Otherwise safely copy the stats from the ring into the supplied
161 * buffer and update the data pointer when finished.
163 * This function expects to be called while under rcu_read_lock().
166 i40e_add_queue_stats(u64 **data, struct i40e_ring *ring)
168 const unsigned int size = ARRAY_SIZE(i40e_gstrings_queue_stats);
169 const struct i40e_stats *stats = i40e_gstrings_queue_stats;
173 /* To avoid invalid statistics values, ensure that we keep retrying
174 * the copy until we get a consistent value according to
175 * u64_stats_fetch_retry_irq. But first, make sure our ring is
176 * non-null before attempting to access its syncp.
179 start = !ring ? 0 : u64_stats_fetch_begin_irq(&ring->syncp);
180 for (i = 0; i < size; i++) {
181 i40e_add_one_ethtool_stat(&(*data)[i], ring,
184 } while (ring && u64_stats_fetch_retry_irq(&ring->syncp, start));
186 /* Once we successfully copy the stats in, update the data pointer */
191 * __i40e_add_stat_strings - copy stat strings into ethtool buffer
192 * @p: ethtool supplied buffer
193 * @stats: stat definitions array
194 * @size: size of the stats array
196 * Format and copy the strings described by stats into the buffer pointed at
199 static void __i40e_add_stat_strings(u8 **p, const struct i40e_stats stats[],
200 const unsigned int size, ...)
204 for (i = 0; i < size; i++) {
207 va_start(args, size);
208 vsnprintf(*p, ETH_GSTRING_LEN, stats[i].stat_string, args);
209 *p += ETH_GSTRING_LEN;
215 * 40e_add_stat_strings - copy stat strings into ethtool buffer
216 * @p: ethtool supplied buffer
217 * @stats: stat definitions array
219 * Format and copy the strings described by the const static stats value into
220 * the buffer pointed at by p.
222 * The parameter @stats is evaluated twice, so parameters with side effects
223 * should be avoided. Additionally, stats must be an array such that
224 * ARRAY_SIZE can be called on it.
226 #define i40e_add_stat_strings(p, stats, ...) \
227 __i40e_add_stat_strings(p, stats, ARRAY_SIZE(stats), ## __VA_ARGS__)
229 #define I40E_PF_STAT(_name, _stat) \
230 I40E_STAT(struct i40e_pf, _name, _stat)
231 #define I40E_VSI_STAT(_name, _stat) \
232 I40E_STAT(struct i40e_vsi, _name, _stat)
233 #define I40E_VEB_STAT(_name, _stat) \
234 I40E_STAT(struct i40e_veb, _name, _stat)
235 #define I40E_PFC_STAT(_name, _stat) \
236 I40E_STAT(struct i40e_pfc_stats, _name, _stat)
237 #define I40E_QUEUE_STAT(_name, _stat) \
238 I40E_STAT(struct i40e_ring, _name, _stat)
240 static const struct i40e_stats i40e_gstrings_net_stats[] = {
241 I40E_NETDEV_STAT(rx_packets),
242 I40E_NETDEV_STAT(tx_packets),
243 I40E_NETDEV_STAT(rx_bytes),
244 I40E_NETDEV_STAT(tx_bytes),
245 I40E_NETDEV_STAT(rx_errors),
246 I40E_NETDEV_STAT(tx_errors),
247 I40E_NETDEV_STAT(rx_dropped),
248 I40E_NETDEV_STAT(tx_dropped),
249 I40E_NETDEV_STAT(collisions),
250 I40E_NETDEV_STAT(rx_length_errors),
251 I40E_NETDEV_STAT(rx_crc_errors),
254 static const struct i40e_stats i40e_gstrings_veb_stats[] = {
255 I40E_VEB_STAT("veb.rx_bytes", stats.rx_bytes),
256 I40E_VEB_STAT("veb.tx_bytes", stats.tx_bytes),
257 I40E_VEB_STAT("veb.rx_unicast", stats.rx_unicast),
258 I40E_VEB_STAT("veb.tx_unicast", stats.tx_unicast),
259 I40E_VEB_STAT("veb.rx_multicast", stats.rx_multicast),
260 I40E_VEB_STAT("veb.tx_multicast", stats.tx_multicast),
261 I40E_VEB_STAT("veb.rx_broadcast", stats.rx_broadcast),
262 I40E_VEB_STAT("veb.tx_broadcast", stats.tx_broadcast),
263 I40E_VEB_STAT("veb.rx_discards", stats.rx_discards),
264 I40E_VEB_STAT("veb.tx_discards", stats.tx_discards),
265 I40E_VEB_STAT("veb.tx_errors", stats.tx_errors),
266 I40E_VEB_STAT("veb.rx_unknown_protocol", stats.rx_unknown_protocol),
269 static const struct i40e_stats i40e_gstrings_veb_tc_stats[] = {
270 I40E_VEB_STAT("veb.tc_%u_tx_packets", tc_stats.tc_tx_packets),
271 I40E_VEB_STAT("veb.tc_%u_tx_bytes", tc_stats.tc_tx_bytes),
272 I40E_VEB_STAT("veb.tc_%u_rx_packets", tc_stats.tc_rx_packets),
273 I40E_VEB_STAT("veb.tc_%u_rx_bytes", tc_stats.tc_rx_bytes),
276 static const struct i40e_stats i40e_gstrings_misc_stats[] = {
277 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
278 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
279 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
280 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
281 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
282 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
283 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
284 I40E_VSI_STAT("tx_linearize", tx_linearize),
285 I40E_VSI_STAT("tx_force_wb", tx_force_wb),
286 I40E_VSI_STAT("tx_busy", tx_busy),
287 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
288 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
291 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
292 * but they are separate. This device supports Virtualization, and
293 * as such might have several netdevs supporting VMDq and FCoE going
294 * through a single port. The NETDEV_STATs are for individual netdevs
295 * seen at the top of the stack, and the PF_STATs are for the physical
296 * function at the bottom of the stack hosting those netdevs.
298 * The PF_STATs are appended to the netdev stats only when ethtool -S
299 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
301 static const struct i40e_stats i40e_gstrings_stats[] = {
302 I40E_PF_STAT("port.rx_bytes", stats.eth.rx_bytes),
303 I40E_PF_STAT("port.tx_bytes", stats.eth.tx_bytes),
304 I40E_PF_STAT("port.rx_unicast", stats.eth.rx_unicast),
305 I40E_PF_STAT("port.tx_unicast", stats.eth.tx_unicast),
306 I40E_PF_STAT("port.rx_multicast", stats.eth.rx_multicast),
307 I40E_PF_STAT("port.tx_multicast", stats.eth.tx_multicast),
308 I40E_PF_STAT("port.rx_broadcast", stats.eth.rx_broadcast),
309 I40E_PF_STAT("port.tx_broadcast", stats.eth.tx_broadcast),
310 I40E_PF_STAT("port.tx_errors", stats.eth.tx_errors),
311 I40E_PF_STAT("port.rx_dropped", stats.eth.rx_discards),
312 I40E_PF_STAT("port.tx_dropped_link_down", stats.tx_dropped_link_down),
313 I40E_PF_STAT("port.rx_crc_errors", stats.crc_errors),
314 I40E_PF_STAT("port.illegal_bytes", stats.illegal_bytes),
315 I40E_PF_STAT("port.mac_local_faults", stats.mac_local_faults),
316 I40E_PF_STAT("port.mac_remote_faults", stats.mac_remote_faults),
317 I40E_PF_STAT("port.tx_timeout", tx_timeout_count),
318 I40E_PF_STAT("port.rx_csum_bad", hw_csum_rx_error),
319 I40E_PF_STAT("port.rx_length_errors", stats.rx_length_errors),
320 I40E_PF_STAT("port.link_xon_rx", stats.link_xon_rx),
321 I40E_PF_STAT("port.link_xoff_rx", stats.link_xoff_rx),
322 I40E_PF_STAT("port.link_xon_tx", stats.link_xon_tx),
323 I40E_PF_STAT("port.link_xoff_tx", stats.link_xoff_tx),
324 I40E_PF_STAT("port.rx_size_64", stats.rx_size_64),
325 I40E_PF_STAT("port.rx_size_127", stats.rx_size_127),
326 I40E_PF_STAT("port.rx_size_255", stats.rx_size_255),
327 I40E_PF_STAT("port.rx_size_511", stats.rx_size_511),
328 I40E_PF_STAT("port.rx_size_1023", stats.rx_size_1023),
329 I40E_PF_STAT("port.rx_size_1522", stats.rx_size_1522),
330 I40E_PF_STAT("port.rx_size_big", stats.rx_size_big),
331 I40E_PF_STAT("port.tx_size_64", stats.tx_size_64),
332 I40E_PF_STAT("port.tx_size_127", stats.tx_size_127),
333 I40E_PF_STAT("port.tx_size_255", stats.tx_size_255),
334 I40E_PF_STAT("port.tx_size_511", stats.tx_size_511),
335 I40E_PF_STAT("port.tx_size_1023", stats.tx_size_1023),
336 I40E_PF_STAT("port.tx_size_1522", stats.tx_size_1522),
337 I40E_PF_STAT("port.tx_size_big", stats.tx_size_big),
338 I40E_PF_STAT("port.rx_undersize", stats.rx_undersize),
339 I40E_PF_STAT("port.rx_fragments", stats.rx_fragments),
340 I40E_PF_STAT("port.rx_oversize", stats.rx_oversize),
341 I40E_PF_STAT("port.rx_jabber", stats.rx_jabber),
342 I40E_PF_STAT("port.VF_admin_queue_requests", vf_aq_requests),
343 I40E_PF_STAT("port.arq_overflows", arq_overflows),
344 I40E_PF_STAT("port.tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
345 I40E_PF_STAT("port.rx_hwtstamp_cleared", rx_hwtstamp_cleared),
346 I40E_PF_STAT("port.tx_hwtstamp_skipped", tx_hwtstamp_skipped),
347 I40E_PF_STAT("port.fdir_flush_cnt", fd_flush_cnt),
348 I40E_PF_STAT("port.fdir_atr_match", stats.fd_atr_match),
349 I40E_PF_STAT("port.fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
350 I40E_PF_STAT("port.fdir_atr_status", stats.fd_atr_status),
351 I40E_PF_STAT("port.fdir_sb_match", stats.fd_sb_match),
352 I40E_PF_STAT("port.fdir_sb_status", stats.fd_sb_status),
355 I40E_PF_STAT("port.tx_lpi_status", stats.tx_lpi_status),
356 I40E_PF_STAT("port.rx_lpi_status", stats.rx_lpi_status),
357 I40E_PF_STAT("port.tx_lpi_count", stats.tx_lpi_count),
358 I40E_PF_STAT("port.rx_lpi_count", stats.rx_lpi_count),
361 struct i40e_pfc_stats {
363 u64 priority_xoff_rx;
365 u64 priority_xoff_tx;
366 u64 priority_xon_2_xoff;
369 static const struct i40e_stats i40e_gstrings_pfc_stats[] = {
370 I40E_PFC_STAT("port.tx_priority_%u_xon_tx", priority_xon_tx),
371 I40E_PFC_STAT("port.tx_priority_%u_xoff_tx", priority_xoff_tx),
372 I40E_PFC_STAT("port.rx_priority_%u_xon_rx", priority_xon_rx),
373 I40E_PFC_STAT("port.rx_priority_%u_xoff_rx", priority_xoff_rx),
374 I40E_PFC_STAT("port.rx_priority_%u_xon_2_xoff", priority_xon_2_xoff),
377 #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
379 #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
381 #define I40E_VSI_STATS_LEN (I40E_NETDEV_STATS_LEN + I40E_MISC_STATS_LEN)
383 #define I40E_PFC_STATS_LEN (ARRAY_SIZE(i40e_gstrings_pfc_stats) * \
384 I40E_MAX_USER_PRIORITY)
386 #define I40E_VEB_STATS_LEN (ARRAY_SIZE(i40e_gstrings_veb_stats) + \
387 (ARRAY_SIZE(i40e_gstrings_veb_tc_stats) * \
388 I40E_MAX_TRAFFIC_CLASS))
390 #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
392 #define I40E_PF_STATS_LEN (I40E_GLOBAL_STATS_LEN + \
393 I40E_PFC_STATS_LEN + \
394 I40E_VEB_STATS_LEN + \
397 /* Length of stats for a single queue */
398 #define I40E_QUEUE_STATS_LEN ARRAY_SIZE(i40e_gstrings_queue_stats)
400 enum i40e_ethtool_test_id {
401 I40E_ETH_TEST_REG = 0,
402 I40E_ETH_TEST_EEPROM,
407 static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
408 "Register test (offline)",
409 "Eeprom test (offline)",
410 "Interrupt test (offline)",
411 "Link test (on/offline)"
414 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
416 struct i40e_priv_flags {
417 char flag_string[ETH_GSTRING_LEN];
422 #define I40E_PRIV_FLAG(_name, _flag, _read_only) { \
423 .flag_string = _name, \
425 .read_only = _read_only, \
428 static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
429 /* NOTE: MFP setting cannot be changed */
430 I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1),
431 I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0),
432 I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
433 I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
434 I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0),
435 I40E_PRIV_FLAG("link-down-on-close",
436 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED, 0),
437 I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
438 I40E_PRIV_FLAG("disable-source-pruning",
439 I40E_FLAG_SOURCE_PRUNING_DISABLED, 0),
440 I40E_PRIV_FLAG("disable-fw-lldp", I40E_FLAG_DISABLE_FW_LLDP, 0),
443 #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
445 /* Private flags with a global effect, restricted to PF 0 */
446 static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
447 I40E_PRIV_FLAG("vf-true-promisc-support",
448 I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
451 #define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
454 * i40e_partition_setting_complaint - generic complaint for MFP restriction
457 static void i40e_partition_setting_complaint(struct i40e_pf *pf)
459 dev_info(&pf->pdev->dev,
460 "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");
464 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
465 * @pf: PF struct with phy_types
466 * @ks: ethtool link ksettings struct to fill out
469 static void i40e_phy_type_to_ethtool(struct i40e_pf *pf,
470 struct ethtool_link_ksettings *ks)
472 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
473 u64 phy_types = pf->hw.phy.phy_types;
475 ethtool_link_ksettings_zero_link_mode(ks, supported);
476 ethtool_link_ksettings_zero_link_mode(ks, advertising);
478 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
479 ethtool_link_ksettings_add_link_mode(ks, supported,
481 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
482 ethtool_link_ksettings_add_link_mode(ks, advertising,
484 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
485 ethtool_link_ksettings_add_link_mode(ks, supported,
487 ethtool_link_ksettings_add_link_mode(ks, advertising,
491 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
492 phy_types & I40E_CAP_PHY_TYPE_XFI ||
493 phy_types & I40E_CAP_PHY_TYPE_SFI ||
494 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
495 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC) {
496 ethtool_link_ksettings_add_link_mode(ks, supported,
498 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
499 ethtool_link_ksettings_add_link_mode(ks, advertising,
502 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_T) {
503 ethtool_link_ksettings_add_link_mode(ks, supported,
505 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
506 ethtool_link_ksettings_add_link_mode(ks, advertising,
509 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
510 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
511 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
512 ethtool_link_ksettings_add_link_mode(ks, supported,
514 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
515 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
516 ethtool_link_ksettings_add_link_mode(ks, supported,
518 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
519 ethtool_link_ksettings_add_link_mode(ks, advertising,
522 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
523 ethtool_link_ksettings_add_link_mode(ks, supported,
525 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
526 ethtool_link_ksettings_add_link_mode(ks, advertising,
529 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T) {
530 ethtool_link_ksettings_add_link_mode(ks, supported,
532 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
533 ethtool_link_ksettings_add_link_mode(ks, advertising,
536 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
537 ethtool_link_ksettings_add_link_mode(ks, supported,
539 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
540 ethtool_link_ksettings_add_link_mode(ks, supported,
542 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
543 ethtool_link_ksettings_add_link_mode(ks, supported,
545 ethtool_link_ksettings_add_link_mode(ks, advertising,
548 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
549 ethtool_link_ksettings_add_link_mode(ks, supported,
551 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
552 ethtool_link_ksettings_add_link_mode(ks, advertising,
555 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
556 ethtool_link_ksettings_add_link_mode(ks, supported,
558 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
559 ethtool_link_ksettings_add_link_mode(ks, advertising,
562 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR &&
563 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
564 ethtool_link_ksettings_add_link_mode(ks, supported,
566 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
567 ethtool_link_ksettings_add_link_mode(ks, advertising,
570 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX &&
571 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
572 ethtool_link_ksettings_add_link_mode(ks, supported,
574 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
575 ethtool_link_ksettings_add_link_mode(ks, advertising,
578 /* need to add 25G PHY types */
579 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR) {
580 ethtool_link_ksettings_add_link_mode(ks, supported,
582 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
583 ethtool_link_ksettings_add_link_mode(ks, advertising,
586 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR) {
587 ethtool_link_ksettings_add_link_mode(ks, supported,
589 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
590 ethtool_link_ksettings_add_link_mode(ks, advertising,
593 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
594 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
595 ethtool_link_ksettings_add_link_mode(ks, supported,
597 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
598 ethtool_link_ksettings_add_link_mode(ks, advertising,
601 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_AOC ||
602 phy_types & I40E_CAP_PHY_TYPE_25GBASE_ACC) {
603 ethtool_link_ksettings_add_link_mode(ks, supported,
605 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
606 ethtool_link_ksettings_add_link_mode(ks, advertising,
609 /* need to add new 10G PHY types */
610 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
611 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU) {
612 ethtool_link_ksettings_add_link_mode(ks, supported,
614 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
615 ethtool_link_ksettings_add_link_mode(ks, advertising,
618 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR) {
619 ethtool_link_ksettings_add_link_mode(ks, supported,
621 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
622 ethtool_link_ksettings_add_link_mode(ks, advertising,
625 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
626 ethtool_link_ksettings_add_link_mode(ks, supported,
628 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
629 ethtool_link_ksettings_add_link_mode(ks, advertising,
632 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
633 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
634 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
635 ethtool_link_ksettings_add_link_mode(ks, supported,
637 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
638 ethtool_link_ksettings_add_link_mode(ks, advertising,
641 /* Autoneg PHY types */
642 if (phy_types & I40E_CAP_PHY_TYPE_SGMII ||
643 phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4 ||
644 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
645 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4 ||
646 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
647 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR ||
648 phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
649 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
650 phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2 ||
651 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
652 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
653 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR ||
654 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4 ||
655 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR ||
656 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
657 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
658 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL ||
659 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
660 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
661 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
662 phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX ||
663 phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
664 ethtool_link_ksettings_add_link_mode(ks, supported,
666 ethtool_link_ksettings_add_link_mode(ks, advertising,
672 * i40e_get_settings_link_up - Get the Link settings for when link is up
674 * @ks: ethtool ksettings to fill in
675 * @netdev: network interface device structure
676 * @pf: pointer to physical function struct
678 static void i40e_get_settings_link_up(struct i40e_hw *hw,
679 struct ethtool_link_ksettings *ks,
680 struct net_device *netdev,
683 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
684 struct ethtool_link_ksettings cap_ksettings;
685 u32 link_speed = hw_link_info->link_speed;
687 /* Initialize supported and advertised settings based on phy settings */
688 switch (hw_link_info->phy_type) {
689 case I40E_PHY_TYPE_40GBASE_CR4:
690 case I40E_PHY_TYPE_40GBASE_CR4_CU:
691 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
692 ethtool_link_ksettings_add_link_mode(ks, supported,
694 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
695 ethtool_link_ksettings_add_link_mode(ks, advertising,
698 case I40E_PHY_TYPE_XLAUI:
699 case I40E_PHY_TYPE_XLPPI:
700 case I40E_PHY_TYPE_40GBASE_AOC:
701 ethtool_link_ksettings_add_link_mode(ks, supported,
704 case I40E_PHY_TYPE_40GBASE_SR4:
705 ethtool_link_ksettings_add_link_mode(ks, supported,
708 case I40E_PHY_TYPE_40GBASE_LR4:
709 ethtool_link_ksettings_add_link_mode(ks, supported,
712 case I40E_PHY_TYPE_25GBASE_SR:
713 case I40E_PHY_TYPE_25GBASE_LR:
714 case I40E_PHY_TYPE_10GBASE_SR:
715 case I40E_PHY_TYPE_10GBASE_LR:
716 case I40E_PHY_TYPE_1000BASE_SX:
717 case I40E_PHY_TYPE_1000BASE_LX:
718 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
719 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
720 ethtool_link_ksettings_add_link_mode(ks, supported,
722 ethtool_link_ksettings_add_link_mode(ks, advertising,
724 ethtool_link_ksettings_add_link_mode(ks, supported,
726 ethtool_link_ksettings_add_link_mode(ks, advertising,
728 ethtool_link_ksettings_add_link_mode(ks, supported,
730 ethtool_link_ksettings_add_link_mode(ks, advertising,
732 ethtool_link_ksettings_add_link_mode(ks, supported,
734 ethtool_link_ksettings_add_link_mode(ks, advertising,
736 ethtool_link_ksettings_add_link_mode(ks, supported,
738 if (hw_link_info->module_type[2] &
739 I40E_MODULE_TYPE_1000BASE_SX ||
740 hw_link_info->module_type[2] &
741 I40E_MODULE_TYPE_1000BASE_LX) {
742 ethtool_link_ksettings_add_link_mode(ks, supported,
744 if (hw_link_info->requested_speeds &
746 ethtool_link_ksettings_add_link_mode(
747 ks, advertising, 1000baseT_Full);
749 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
750 ethtool_link_ksettings_add_link_mode(ks, advertising,
753 case I40E_PHY_TYPE_10GBASE_T:
754 case I40E_PHY_TYPE_1000BASE_T:
755 case I40E_PHY_TYPE_100BASE_TX:
756 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
757 ethtool_link_ksettings_add_link_mode(ks, supported,
759 ethtool_link_ksettings_add_link_mode(ks, supported,
761 ethtool_link_ksettings_add_link_mode(ks, supported,
763 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
764 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
765 ethtool_link_ksettings_add_link_mode(ks, advertising,
767 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
768 ethtool_link_ksettings_add_link_mode(ks, advertising,
770 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
771 ethtool_link_ksettings_add_link_mode(ks, advertising,
774 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
775 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
776 ethtool_link_ksettings_add_link_mode(ks, supported,
778 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
779 ethtool_link_ksettings_add_link_mode(ks, advertising,
782 case I40E_PHY_TYPE_10GBASE_CR1_CU:
783 case I40E_PHY_TYPE_10GBASE_CR1:
784 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
785 ethtool_link_ksettings_add_link_mode(ks, supported,
787 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
788 ethtool_link_ksettings_add_link_mode(ks, advertising,
791 case I40E_PHY_TYPE_XAUI:
792 case I40E_PHY_TYPE_XFI:
793 case I40E_PHY_TYPE_SFI:
794 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
795 case I40E_PHY_TYPE_10GBASE_AOC:
796 ethtool_link_ksettings_add_link_mode(ks, supported,
798 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
799 ethtool_link_ksettings_add_link_mode(ks, advertising,
802 case I40E_PHY_TYPE_SGMII:
803 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
804 ethtool_link_ksettings_add_link_mode(ks, supported,
806 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
807 ethtool_link_ksettings_add_link_mode(ks, advertising,
809 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
810 ethtool_link_ksettings_add_link_mode(ks, supported,
812 if (hw_link_info->requested_speeds &
813 I40E_LINK_SPEED_100MB)
814 ethtool_link_ksettings_add_link_mode(
815 ks, advertising, 100baseT_Full);
818 case I40E_PHY_TYPE_40GBASE_KR4:
819 case I40E_PHY_TYPE_25GBASE_KR:
820 case I40E_PHY_TYPE_20GBASE_KR2:
821 case I40E_PHY_TYPE_10GBASE_KR:
822 case I40E_PHY_TYPE_10GBASE_KX4:
823 case I40E_PHY_TYPE_1000BASE_KX:
824 ethtool_link_ksettings_add_link_mode(ks, supported,
826 ethtool_link_ksettings_add_link_mode(ks, supported,
828 ethtool_link_ksettings_add_link_mode(ks, supported,
830 ethtool_link_ksettings_add_link_mode(ks, supported,
832 ethtool_link_ksettings_add_link_mode(ks, supported,
834 ethtool_link_ksettings_add_link_mode(ks, supported,
836 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
837 ethtool_link_ksettings_add_link_mode(ks, advertising,
839 ethtool_link_ksettings_add_link_mode(ks, advertising,
841 ethtool_link_ksettings_add_link_mode(ks, advertising,
843 ethtool_link_ksettings_add_link_mode(ks, advertising,
845 ethtool_link_ksettings_add_link_mode(ks, advertising,
847 ethtool_link_ksettings_add_link_mode(ks, advertising,
849 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
851 case I40E_PHY_TYPE_25GBASE_CR:
852 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
853 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
854 ethtool_link_ksettings_add_link_mode(ks, supported,
856 ethtool_link_ksettings_add_link_mode(ks, advertising,
859 case I40E_PHY_TYPE_25GBASE_AOC:
860 case I40E_PHY_TYPE_25GBASE_ACC:
861 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
862 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
863 ethtool_link_ksettings_add_link_mode(ks, supported,
866 ethtool_link_ksettings_add_link_mode(ks, advertising,
868 ethtool_link_ksettings_add_link_mode(ks, supported,
870 ethtool_link_ksettings_add_link_mode(ks, advertising,
874 /* if we got here and link is up something bad is afoot */
876 "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
877 hw_link_info->phy_type);
880 /* Now that we've worked out everything that could be supported by the
881 * current PHY type, get what is supported by the NVM and intersect
882 * them to get what is truly supported
884 memset(&cap_ksettings, 0, sizeof(struct ethtool_link_ksettings));
885 i40e_phy_type_to_ethtool(pf, &cap_ksettings);
886 ethtool_intersect_link_masks(ks, &cap_ksettings);
888 /* Set speed and duplex */
889 switch (link_speed) {
890 case I40E_LINK_SPEED_40GB:
891 ks->base.speed = SPEED_40000;
893 case I40E_LINK_SPEED_25GB:
894 ks->base.speed = SPEED_25000;
896 case I40E_LINK_SPEED_20GB:
897 ks->base.speed = SPEED_20000;
899 case I40E_LINK_SPEED_10GB:
900 ks->base.speed = SPEED_10000;
902 case I40E_LINK_SPEED_1GB:
903 ks->base.speed = SPEED_1000;
905 case I40E_LINK_SPEED_100MB:
906 ks->base.speed = SPEED_100;
909 ks->base.speed = SPEED_UNKNOWN;
912 ks->base.duplex = DUPLEX_FULL;
916 * i40e_get_settings_link_down - Get the Link settings for when link is down
918 * @ks: ethtool ksettings to fill in
919 * @pf: pointer to physical function struct
921 * Reports link settings that can be determined when link is down
923 static void i40e_get_settings_link_down(struct i40e_hw *hw,
924 struct ethtool_link_ksettings *ks,
927 /* link is down and the driver needs to fall back on
928 * supported phy types to figure out what info to display
930 i40e_phy_type_to_ethtool(pf, ks);
932 /* With no link speed and duplex are unknown */
933 ks->base.speed = SPEED_UNKNOWN;
934 ks->base.duplex = DUPLEX_UNKNOWN;
938 * i40e_get_link_ksettings - Get Link Speed and Duplex settings
939 * @netdev: network interface device structure
940 * @ks: ethtool ksettings
942 * Reports speed/duplex settings based on media_type
944 static int i40e_get_link_ksettings(struct net_device *netdev,
945 struct ethtool_link_ksettings *ks)
947 struct i40e_netdev_priv *np = netdev_priv(netdev);
948 struct i40e_pf *pf = np->vsi->back;
949 struct i40e_hw *hw = &pf->hw;
950 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
951 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
953 ethtool_link_ksettings_zero_link_mode(ks, supported);
954 ethtool_link_ksettings_zero_link_mode(ks, advertising);
957 i40e_get_settings_link_up(hw, ks, netdev, pf);
959 i40e_get_settings_link_down(hw, ks, pf);
961 /* Now set the settings that don't rely on link being up/down */
962 /* Set autoneg settings */
963 ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
964 AUTONEG_ENABLE : AUTONEG_DISABLE);
966 /* Set media type settings */
967 switch (hw->phy.media_type) {
968 case I40E_MEDIA_TYPE_BACKPLANE:
969 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
970 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
971 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
972 ethtool_link_ksettings_add_link_mode(ks, advertising,
974 ks->base.port = PORT_NONE;
976 case I40E_MEDIA_TYPE_BASET:
977 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
978 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
979 ks->base.port = PORT_TP;
981 case I40E_MEDIA_TYPE_DA:
982 case I40E_MEDIA_TYPE_CX4:
983 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
984 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
985 ks->base.port = PORT_DA;
987 case I40E_MEDIA_TYPE_FIBER:
988 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
989 ks->base.port = PORT_FIBRE;
991 case I40E_MEDIA_TYPE_UNKNOWN:
993 ks->base.port = PORT_OTHER;
997 /* Set flow control settings */
998 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
1000 switch (hw->fc.requested_mode) {
1002 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
1004 case I40E_FC_TX_PAUSE:
1005 ethtool_link_ksettings_add_link_mode(ks, advertising,
1008 case I40E_FC_RX_PAUSE:
1009 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
1010 ethtool_link_ksettings_add_link_mode(ks, advertising,
1014 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
1015 ethtool_link_ksettings_del_link_mode(ks, advertising,
1024 * i40e_set_link_ksettings - Set Speed and Duplex
1025 * @netdev: network interface device structure
1026 * @ks: ethtool ksettings
1028 * Set speed/duplex per media_types advertised/forced
1030 static int i40e_set_link_ksettings(struct net_device *netdev,
1031 const struct ethtool_link_ksettings *ks)
1033 struct i40e_netdev_priv *np = netdev_priv(netdev);
1034 struct i40e_aq_get_phy_abilities_resp abilities;
1035 struct ethtool_link_ksettings safe_ks;
1036 struct ethtool_link_ksettings copy_ks;
1037 struct i40e_aq_set_phy_config config;
1038 struct i40e_pf *pf = np->vsi->back;
1039 struct i40e_vsi *vsi = np->vsi;
1040 struct i40e_hw *hw = &pf->hw;
1041 bool autoneg_changed = false;
1042 i40e_status status = 0;
1047 /* Changing port settings is not supported if this isn't the
1048 * port's controlling PF
1050 if (hw->partition_id != 1) {
1051 i40e_partition_setting_complaint(pf);
1054 if (vsi != pf->vsi[pf->lan_vsi])
1056 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
1057 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
1058 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
1059 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
1060 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
1062 if (hw->device_id == I40E_DEV_ID_KX_B ||
1063 hw->device_id == I40E_DEV_ID_KX_C ||
1064 hw->device_id == I40E_DEV_ID_20G_KR2 ||
1065 hw->device_id == I40E_DEV_ID_20G_KR2_A ||
1066 hw->device_id == I40E_DEV_ID_25G_B ||
1067 hw->device_id == I40E_DEV_ID_KX_X722) {
1068 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
1072 /* copy the ksettings to copy_ks to avoid modifying the origin */
1073 memcpy(©_ks, ks, sizeof(struct ethtool_link_ksettings));
1075 /* save autoneg out of ksettings */
1076 autoneg = copy_ks.base.autoneg;
1078 /* get our own copy of the bits to check against */
1079 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
1080 safe_ks.base.cmd = copy_ks.base.cmd;
1081 safe_ks.base.link_mode_masks_nwords =
1082 copy_ks.base.link_mode_masks_nwords;
1083 i40e_get_link_ksettings(netdev, &safe_ks);
1085 /* Get link modes supported by hardware and check against modes
1086 * requested by the user. Return an error if unsupported mode was set.
1088 if (!bitmap_subset(copy_ks.link_modes.advertising,
1089 safe_ks.link_modes.supported,
1090 __ETHTOOL_LINK_MODE_MASK_NBITS))
1093 /* set autoneg back to what it currently is */
1094 copy_ks.base.autoneg = safe_ks.base.autoneg;
1096 /* If copy_ks.base and safe_ks.base are not the same now, then they are
1097 * trying to set something that we do not support.
1099 if (memcmp(©_ks.base, &safe_ks.base,
1100 sizeof(struct ethtool_link_settings)))
1103 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
1107 usleep_range(1000, 2000);
1110 /* Get the current phy config */
1111 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
1118 /* Copy abilities to config in case autoneg is not
1121 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
1122 config.abilities = abilities.abilities;
1125 if (autoneg == AUTONEG_ENABLE) {
1126 /* If autoneg was not already enabled */
1127 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
1128 /* If autoneg is not supported, return error */
1129 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
1132 netdev_info(netdev, "Autoneg not supported on this phy\n");
1136 /* Autoneg is allowed to change */
1137 config.abilities = abilities.abilities |
1138 I40E_AQ_PHY_ENABLE_AN;
1139 autoneg_changed = true;
1142 /* If autoneg is currently enabled */
1143 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
1144 /* If autoneg is supported 10GBASE_T is the only PHY
1145 * that can disable it, so otherwise return error
1147 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
1150 hw->phy.link_info.phy_type !=
1151 I40E_PHY_TYPE_10GBASE_T) {
1152 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
1156 /* Autoneg is allowed to change */
1157 config.abilities = abilities.abilities &
1158 ~I40E_AQ_PHY_ENABLE_AN;
1159 autoneg_changed = true;
1163 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1165 config.link_speed |= I40E_LINK_SPEED_100MB;
1166 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1168 ethtool_link_ksettings_test_link_mode(ks, advertising,
1170 ethtool_link_ksettings_test_link_mode(ks, advertising,
1172 config.link_speed |= I40E_LINK_SPEED_1GB;
1173 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1175 ethtool_link_ksettings_test_link_mode(ks, advertising,
1176 10000baseKX4_Full) ||
1177 ethtool_link_ksettings_test_link_mode(ks, advertising,
1178 10000baseKR_Full) ||
1179 ethtool_link_ksettings_test_link_mode(ks, advertising,
1180 10000baseCR_Full) ||
1181 ethtool_link_ksettings_test_link_mode(ks, advertising,
1182 10000baseSR_Full) ||
1183 ethtool_link_ksettings_test_link_mode(ks, advertising,
1185 config.link_speed |= I40E_LINK_SPEED_10GB;
1186 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1188 config.link_speed |= I40E_LINK_SPEED_20GB;
1189 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1190 25000baseCR_Full) ||
1191 ethtool_link_ksettings_test_link_mode(ks, advertising,
1192 25000baseKR_Full) ||
1193 ethtool_link_ksettings_test_link_mode(ks, advertising,
1195 config.link_speed |= I40E_LINK_SPEED_25GB;
1196 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1197 40000baseKR4_Full) ||
1198 ethtool_link_ksettings_test_link_mode(ks, advertising,
1199 40000baseCR4_Full) ||
1200 ethtool_link_ksettings_test_link_mode(ks, advertising,
1201 40000baseSR4_Full) ||
1202 ethtool_link_ksettings_test_link_mode(ks, advertising,
1204 config.link_speed |= I40E_LINK_SPEED_40GB;
1206 /* If speed didn't get set, set it to what it currently is.
1207 * This is needed because if advertise is 0 (as it is when autoneg
1208 * is disabled) then speed won't get set.
1210 if (!config.link_speed)
1211 config.link_speed = abilities.link_speed;
1212 if (autoneg_changed || abilities.link_speed != config.link_speed) {
1213 /* copy over the rest of the abilities */
1214 config.phy_type = abilities.phy_type;
1215 config.phy_type_ext = abilities.phy_type_ext;
1216 config.eee_capability = abilities.eee_capability;
1217 config.eeer = abilities.eeer_val;
1218 config.low_power_ctrl = abilities.d3_lpan;
1219 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
1220 I40E_AQ_PHY_FEC_CONFIG_MASK;
1222 /* save the requested speeds */
1223 hw->phy.link_info.requested_speeds = config.link_speed;
1224 /* set link and auto negotiation so changes take effect */
1225 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1226 /* If link is up put link down */
1227 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
1228 /* Tell the OS link is going down, the link will go
1229 * back up when fw says it is ready asynchronously
1231 i40e_print_link_message(vsi, false);
1232 netif_carrier_off(netdev);
1233 netif_tx_stop_all_queues(netdev);
1236 /* make the aq call */
1237 status = i40e_aq_set_phy_config(hw, &config, NULL);
1240 "Set phy config failed, err %s aq_err %s\n",
1241 i40e_stat_str(hw, status),
1242 i40e_aq_str(hw, hw->aq.asq_last_status));
1247 status = i40e_update_link_info(hw);
1250 "Updating link info failed with err %s aq_err %s\n",
1251 i40e_stat_str(hw, status),
1252 i40e_aq_str(hw, hw->aq.asq_last_status));
1255 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
1259 clear_bit(__I40E_CONFIG_BUSY, pf->state);
1264 static int i40e_nway_reset(struct net_device *netdev)
1266 /* restart autonegotiation */
1267 struct i40e_netdev_priv *np = netdev_priv(netdev);
1268 struct i40e_pf *pf = np->vsi->back;
1269 struct i40e_hw *hw = &pf->hw;
1270 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
1271 i40e_status ret = 0;
1273 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
1275 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
1276 i40e_stat_str(hw, ret),
1277 i40e_aq_str(hw, hw->aq.asq_last_status));
1285 * i40e_get_pauseparam - Get Flow Control status
1286 * @netdev: netdevice structure
1287 * @pause: buffer to return pause parameters
1289 * Return tx/rx-pause status
1291 static void i40e_get_pauseparam(struct net_device *netdev,
1292 struct ethtool_pauseparam *pause)
1294 struct i40e_netdev_priv *np = netdev_priv(netdev);
1295 struct i40e_pf *pf = np->vsi->back;
1296 struct i40e_hw *hw = &pf->hw;
1297 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1298 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
1301 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1302 AUTONEG_ENABLE : AUTONEG_DISABLE);
1304 /* PFC enabled so report LFC as off */
1305 if (dcbx_cfg->pfc.pfcenable) {
1306 pause->rx_pause = 0;
1307 pause->tx_pause = 0;
1311 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
1312 pause->rx_pause = 1;
1313 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
1314 pause->tx_pause = 1;
1315 } else if (hw->fc.current_mode == I40E_FC_FULL) {
1316 pause->rx_pause = 1;
1317 pause->tx_pause = 1;
1322 * i40e_set_pauseparam - Set Flow Control parameter
1323 * @netdev: network interface device structure
1324 * @pause: return tx/rx flow control status
1326 static int i40e_set_pauseparam(struct net_device *netdev,
1327 struct ethtool_pauseparam *pause)
1329 struct i40e_netdev_priv *np = netdev_priv(netdev);
1330 struct i40e_pf *pf = np->vsi->back;
1331 struct i40e_vsi *vsi = np->vsi;
1332 struct i40e_hw *hw = &pf->hw;
1333 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1334 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
1335 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
1341 /* Changing the port's flow control is not supported if this isn't the
1342 * port's controlling PF
1344 if (hw->partition_id != 1) {
1345 i40e_partition_setting_complaint(pf);
1349 if (vsi != pf->vsi[pf->lan_vsi])
1352 is_an = hw_link_info->an_info & I40E_AQ_AN_COMPLETED;
1353 if (pause->autoneg != is_an) {
1354 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
1358 /* If we have link and don't have autoneg */
1359 if (!test_bit(__I40E_DOWN, pf->state) && !is_an) {
1360 /* Send message that it might not necessarily work*/
1361 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
1364 if (dcbx_cfg->pfc.pfcenable) {
1366 "Priority flow control enabled. Cannot set link flow control.\n");
1370 if (pause->rx_pause && pause->tx_pause)
1371 hw->fc.requested_mode = I40E_FC_FULL;
1372 else if (pause->rx_pause && !pause->tx_pause)
1373 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1374 else if (!pause->rx_pause && pause->tx_pause)
1375 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1376 else if (!pause->rx_pause && !pause->tx_pause)
1377 hw->fc.requested_mode = I40E_FC_NONE;
1381 /* Tell the OS link is going down, the link will go back up when fw
1382 * says it is ready asynchronously
1384 i40e_print_link_message(vsi, false);
1385 netif_carrier_off(netdev);
1386 netif_tx_stop_all_queues(netdev);
1388 /* Set the fc mode and only restart an if link is up*/
1389 status = i40e_set_fc(hw, &aq_failures, link_up);
1391 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
1392 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1393 i40e_stat_str(hw, status),
1394 i40e_aq_str(hw, hw->aq.asq_last_status));
1397 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
1398 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1399 i40e_stat_str(hw, status),
1400 i40e_aq_str(hw, hw->aq.asq_last_status));
1403 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
1404 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1405 i40e_stat_str(hw, status),
1406 i40e_aq_str(hw, hw->aq.asq_last_status));
1410 if (!test_bit(__I40E_DOWN, pf->state) && is_an) {
1411 /* Give it a little more time to try to come back */
1413 if (!test_bit(__I40E_DOWN, pf->state))
1414 return i40e_nway_reset(netdev);
1420 static u32 i40e_get_msglevel(struct net_device *netdev)
1422 struct i40e_netdev_priv *np = netdev_priv(netdev);
1423 struct i40e_pf *pf = np->vsi->back;
1424 u32 debug_mask = pf->hw.debug_mask;
1427 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
1429 return pf->msg_enable;
1432 static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1434 struct i40e_netdev_priv *np = netdev_priv(netdev);
1435 struct i40e_pf *pf = np->vsi->back;
1437 if (I40E_DEBUG_USER & data)
1438 pf->hw.debug_mask = data;
1440 pf->msg_enable = data;
1443 static int i40e_get_regs_len(struct net_device *netdev)
1448 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1449 reg_count += i40e_reg_list[i].elements;
1451 return reg_count * sizeof(u32);
1454 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1457 struct i40e_netdev_priv *np = netdev_priv(netdev);
1458 struct i40e_pf *pf = np->vsi->back;
1459 struct i40e_hw *hw = &pf->hw;
1461 unsigned int i, j, ri;
1464 /* Tell ethtool which driver-version-specific regs output we have.
1466 * At some point, if we have ethtool doing special formatting of
1467 * this data, it will rely on this version number to know how to
1468 * interpret things. Hence, this needs to be updated if/when the
1469 * diags register table is changed.
1473 /* loop through the diags reg table for what to print */
1475 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1476 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1477 reg = i40e_reg_list[i].offset
1478 + (j * i40e_reg_list[i].stride);
1479 reg_buf[ri++] = rd32(hw, reg);
1485 static int i40e_get_eeprom(struct net_device *netdev,
1486 struct ethtool_eeprom *eeprom, u8 *bytes)
1488 struct i40e_netdev_priv *np = netdev_priv(netdev);
1489 struct i40e_hw *hw = &np->vsi->back->hw;
1490 struct i40e_pf *pf = np->vsi->back;
1491 int ret_val = 0, len, offset;
1497 #define I40E_NVM_SECTOR_SIZE 4096
1498 if (eeprom->len == 0)
1501 /* check for NVMUpdate access method */
1502 magic = hw->vendor_id | (hw->device_id << 16);
1503 if (eeprom->magic && eeprom->magic != magic) {
1504 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1507 /* make sure it is the right magic for NVMUpdate */
1508 if ((eeprom->magic >> 16) != hw->device_id)
1510 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1511 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
1514 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1516 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
1517 dev_info(&pf->pdev->dev,
1518 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1519 ret_val, hw->aq.asq_last_status, errno,
1520 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1521 cmd->offset, cmd->data_size);
1526 /* normal ethtool get_eeprom support */
1527 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1529 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
1533 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1535 dev_info(&pf->pdev->dev,
1536 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1537 ret_val, hw->aq.asq_last_status);
1541 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1542 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1543 len = I40E_NVM_SECTOR_SIZE;
1545 for (i = 0; i < sectors; i++) {
1546 if (i == (sectors - 1)) {
1547 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1550 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1551 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
1552 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
1554 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
1555 dev_info(&pf->pdev->dev,
1556 "read NVM failed, invalid offset 0x%x\n",
1559 } else if (ret_val &&
1560 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1561 dev_info(&pf->pdev->dev,
1562 "read NVM failed, access, offset 0x%x\n",
1565 } else if (ret_val) {
1566 dev_info(&pf->pdev->dev,
1567 "read NVM failed offset %d err=%d status=0x%x\n",
1568 offset, ret_val, hw->aq.asq_last_status);
1573 i40e_release_nvm(hw);
1574 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
1580 static int i40e_get_eeprom_len(struct net_device *netdev)
1582 struct i40e_netdev_priv *np = netdev_priv(netdev);
1583 struct i40e_hw *hw = &np->vsi->back->hw;
1586 #define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1587 if (hw->mac.type == I40E_MAC_X722) {
1588 val = X722_EEPROM_SCOPE_LIMIT + 1;
1591 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1592 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1593 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1594 /* register returns value in power of 2, 64Kbyte chunks. */
1595 val = (64 * 1024) * BIT(val);
1599 static int i40e_set_eeprom(struct net_device *netdev,
1600 struct ethtool_eeprom *eeprom, u8 *bytes)
1602 struct i40e_netdev_priv *np = netdev_priv(netdev);
1603 struct i40e_hw *hw = &np->vsi->back->hw;
1604 struct i40e_pf *pf = np->vsi->back;
1605 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1610 /* normal ethtool set_eeprom is not supported */
1611 magic = hw->vendor_id | (hw->device_id << 16);
1612 if (eeprom->magic == magic)
1613 errno = -EOPNOTSUPP;
1614 /* check for NVMUpdate access method */
1615 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1617 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1618 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
1621 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1623 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
1624 dev_info(&pf->pdev->dev,
1625 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1626 ret_val, hw->aq.asq_last_status, errno,
1627 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1628 cmd->offset, cmd->data_size);
1633 static void i40e_get_drvinfo(struct net_device *netdev,
1634 struct ethtool_drvinfo *drvinfo)
1636 struct i40e_netdev_priv *np = netdev_priv(netdev);
1637 struct i40e_vsi *vsi = np->vsi;
1638 struct i40e_pf *pf = vsi->back;
1640 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1641 strlcpy(drvinfo->version, i40e_driver_version_str,
1642 sizeof(drvinfo->version));
1643 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
1644 sizeof(drvinfo->fw_version));
1645 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1646 sizeof(drvinfo->bus_info));
1647 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
1648 if (pf->hw.pf_id == 0)
1649 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
1652 static void i40e_get_ringparam(struct net_device *netdev,
1653 struct ethtool_ringparam *ring)
1655 struct i40e_netdev_priv *np = netdev_priv(netdev);
1656 struct i40e_pf *pf = np->vsi->back;
1657 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1659 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1660 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1661 ring->rx_mini_max_pending = 0;
1662 ring->rx_jumbo_max_pending = 0;
1663 ring->rx_pending = vsi->rx_rings[0]->count;
1664 ring->tx_pending = vsi->tx_rings[0]->count;
1665 ring->rx_mini_pending = 0;
1666 ring->rx_jumbo_pending = 0;
1669 static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1671 if (i40e_enabled_xdp_vsi(vsi)) {
1672 return index < vsi->num_queue_pairs ||
1673 (index >= vsi->alloc_queue_pairs &&
1674 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1677 return index < vsi->num_queue_pairs;
1680 static int i40e_set_ringparam(struct net_device *netdev,
1681 struct ethtool_ringparam *ring)
1683 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1684 struct i40e_netdev_priv *np = netdev_priv(netdev);
1685 struct i40e_hw *hw = &np->vsi->back->hw;
1686 struct i40e_vsi *vsi = np->vsi;
1687 struct i40e_pf *pf = vsi->back;
1688 u32 new_rx_count, new_tx_count;
1689 u16 tx_alloc_queue_pairs;
1693 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1696 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1697 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1698 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1699 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1701 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1702 ring->tx_pending, ring->rx_pending,
1703 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1707 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1708 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1710 /* if nothing to do return success */
1711 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1712 (new_rx_count == vsi->rx_rings[0]->count))
1715 /* If there is a AF_XDP UMEM attached to any of Rx rings,
1716 * disallow changing the number of descriptors -- regardless
1717 * if the netdev is running or not.
1719 if (i40e_xsk_any_rx_ring_enabled(vsi))
1722 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
1726 usleep_range(1000, 2000);
1729 if (!netif_running(vsi->netdev)) {
1730 /* simple case - set for the next time the netdev is started */
1731 for (i = 0; i < vsi->num_queue_pairs; i++) {
1732 vsi->tx_rings[i]->count = new_tx_count;
1733 vsi->rx_rings[i]->count = new_rx_count;
1734 if (i40e_enabled_xdp_vsi(vsi))
1735 vsi->xdp_rings[i]->count = new_tx_count;
1740 /* We can't just free everything and then setup again,
1741 * because the ISRs in MSI-X mode get passed pointers
1742 * to the Tx and Rx ring structs.
1745 /* alloc updated Tx and XDP Tx resources */
1746 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1747 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
1748 if (new_tx_count != vsi->tx_rings[0]->count) {
1750 "Changing Tx descriptor count from %d to %d.\n",
1751 vsi->tx_rings[0]->count, new_tx_count);
1752 tx_rings = kcalloc(tx_alloc_queue_pairs,
1753 sizeof(struct i40e_ring), GFP_KERNEL);
1759 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1760 if (!i40e_active_tx_ring_index(vsi, i))
1763 tx_rings[i] = *vsi->tx_rings[i];
1764 tx_rings[i].count = new_tx_count;
1765 /* the desc and bi pointers will be reallocated in the
1768 tx_rings[i].desc = NULL;
1769 tx_rings[i].rx_bi = NULL;
1770 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1774 if (!i40e_active_tx_ring_index(vsi, i))
1776 i40e_free_tx_resources(&tx_rings[i]);
1786 /* alloc updated Rx resources */
1787 if (new_rx_count != vsi->rx_rings[0]->count) {
1789 "Changing Rx descriptor count from %d to %d\n",
1790 vsi->rx_rings[0]->count, new_rx_count);
1791 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1792 sizeof(struct i40e_ring), GFP_KERNEL);
1798 for (i = 0; i < vsi->num_queue_pairs; i++) {
1801 /* clone ring and setup updated count */
1802 rx_rings[i] = *vsi->rx_rings[i];
1803 rx_rings[i].count = new_rx_count;
1804 /* the desc and bi pointers will be reallocated in the
1807 rx_rings[i].desc = NULL;
1808 rx_rings[i].rx_bi = NULL;
1809 /* Clear cloned XDP RX-queue info before setup call */
1810 memset(&rx_rings[i].xdp_rxq, 0, sizeof(rx_rings[i].xdp_rxq));
1811 /* this is to allow wr32 to have something to write to
1812 * during early allocation of Rx buffers
1814 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
1815 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1819 /* now allocate the Rx buffers to make sure the OS
1820 * has enough memory, any failure here means abort
1822 unused = I40E_DESC_UNUSED(&rx_rings[i]);
1823 err = i40e_alloc_rx_buffers(&rx_rings[i], unused);
1827 i40e_free_rx_resources(&rx_rings[i]);
1837 /* Bring interface down, copy in the new ring info,
1838 * then restore the interface
1843 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1844 if (i40e_active_tx_ring_index(vsi, i)) {
1845 i40e_free_tx_resources(vsi->tx_rings[i]);
1846 *vsi->tx_rings[i] = tx_rings[i];
1854 for (i = 0; i < vsi->num_queue_pairs; i++) {
1855 i40e_free_rx_resources(vsi->rx_rings[i]);
1856 /* get the real tail offset */
1857 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1858 /* this is to fake out the allocation routine
1859 * into thinking it has to realloc everything
1860 * but the recycling logic will let us re-use
1861 * the buffers allocated above
1863 rx_rings[i].next_to_use = 0;
1864 rx_rings[i].next_to_clean = 0;
1865 rx_rings[i].next_to_alloc = 0;
1866 /* do a struct copy */
1867 *vsi->rx_rings[i] = rx_rings[i];
1876 /* error cleanup if the Rx allocations failed after getting Tx */
1878 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1879 if (i40e_active_tx_ring_index(vsi, i))
1880 i40e_free_tx_resources(vsi->tx_rings[i]);
1887 clear_bit(__I40E_CONFIG_BUSY, pf->state);
1893 * i40e_get_stats_count - return the stats count for a device
1894 * @netdev: the netdev to return the count for
1896 * Returns the total number of statistics for this netdev. Note that even
1897 * though this is a function, it is required that the count for a specific
1898 * netdev must never change. Basing the count on static values such as the
1899 * maximum number of queues or the device type is ok. However, the API for
1900 * obtaining stats is *not* safe against changes based on non-static
1901 * values such as the *current* number of queues, or runtime flags.
1903 * If a statistic is not always enabled, return it as part of the count
1904 * anyways, always return its string, and report its value as zero.
1906 static int i40e_get_stats_count(struct net_device *netdev)
1908 struct i40e_netdev_priv *np = netdev_priv(netdev);
1909 struct i40e_vsi *vsi = np->vsi;
1910 struct i40e_pf *pf = vsi->back;
1913 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1)
1914 stats_len = I40E_PF_STATS_LEN;
1916 stats_len = I40E_VSI_STATS_LEN;
1918 /* The number of stats reported for a given net_device must remain
1919 * constant throughout the life of that device.
1921 * This is because the API for obtaining the size, strings, and stats
1922 * is spread out over three separate ethtool ioctls. There is no safe
1923 * way to lock the number of stats across these calls, so we must
1924 * assume that they will never change.
1926 * Due to this, we report the maximum number of queues, even if not
1927 * every queue is currently configured. Since we always allocate
1928 * queues in pairs, we'll just use netdev->num_tx_queues * 2. This
1929 * works because the num_tx_queues is set at device creation and never
1932 stats_len += I40E_QUEUE_STATS_LEN * 2 * netdev->num_tx_queues;
1937 static int i40e_get_sset_count(struct net_device *netdev, int sset)
1939 struct i40e_netdev_priv *np = netdev_priv(netdev);
1940 struct i40e_vsi *vsi = np->vsi;
1941 struct i40e_pf *pf = vsi->back;
1945 return I40E_TEST_LEN;
1947 return i40e_get_stats_count(netdev);
1948 case ETH_SS_PRIV_FLAGS:
1949 return I40E_PRIV_FLAGS_STR_LEN +
1950 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
1957 * i40e_get_pfc_stats - copy HW PFC statistics to formatted structure
1958 * @pf: the PF device structure
1959 * @i: the priority value to copy
1961 * The PFC stats are found as arrays in pf->stats, which is not easy to pass
1962 * into i40e_add_ethtool_stats. Produce a formatted i40e_pfc_stats structure
1963 * of the PFC stats for the given priority.
1965 static inline struct i40e_pfc_stats
1966 i40e_get_pfc_stats(struct i40e_pf *pf, unsigned int i)
1968 #define I40E_GET_PFC_STAT(stat, priority) \
1969 .stat = pf->stats.stat[priority]
1971 struct i40e_pfc_stats pfc = {
1972 I40E_GET_PFC_STAT(priority_xon_rx, i),
1973 I40E_GET_PFC_STAT(priority_xoff_rx, i),
1974 I40E_GET_PFC_STAT(priority_xon_tx, i),
1975 I40E_GET_PFC_STAT(priority_xoff_tx, i),
1976 I40E_GET_PFC_STAT(priority_xon_2_xoff, i),
1982 * i40e_get_ethtool_stats - copy stat values into supplied buffer
1983 * @netdev: the netdev to collect stats for
1984 * @stats: ethtool stats command structure
1985 * @data: ethtool supplied buffer
1987 * Copy the stats values for this netdev into the buffer. Expects data to be
1988 * pre-allocated to the size returned by i40e_get_stats_count.. Note that all
1989 * statistics must be copied in a static order, and the count must not change
1990 * for a given netdev. See i40e_get_stats_count for more details.
1992 * If a statistic is not currently valid (such as a disabled queue), this
1993 * function reports its value as zero.
1995 static void i40e_get_ethtool_stats(struct net_device *netdev,
1996 struct ethtool_stats *stats, u64 *data)
1998 struct i40e_netdev_priv *np = netdev_priv(netdev);
1999 struct i40e_vsi *vsi = np->vsi;
2000 struct i40e_pf *pf = vsi->back;
2001 struct i40e_veb *veb = pf->veb[pf->lan_veb];
2006 i40e_update_stats(vsi);
2008 i40e_add_ethtool_stats(&data, i40e_get_vsi_stats_struct(vsi),
2009 i40e_gstrings_net_stats);
2011 i40e_add_ethtool_stats(&data, vsi, i40e_gstrings_misc_stats);
2014 for (i = 0; i < netdev->num_tx_queues; i++) {
2015 i40e_add_queue_stats(&data, READ_ONCE(vsi->tx_rings[i]));
2016 i40e_add_queue_stats(&data, READ_ONCE(vsi->rx_rings[i]));
2020 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
2021 goto check_data_pointer;
2023 veb_stats = ((pf->lan_veb != I40E_NO_VEB) &&
2024 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED));
2026 /* If veb stats aren't enabled, pass NULL instead of the veb so that
2027 * we initialize stats to zero and update the data pointer
2030 i40e_add_ethtool_stats(&data, veb_stats ? veb : NULL,
2031 i40e_gstrings_veb_stats);
2033 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
2034 i40e_add_ethtool_stats(&data, veb_stats ? veb : NULL,
2035 i40e_gstrings_veb_tc_stats);
2037 i40e_add_ethtool_stats(&data, pf, i40e_gstrings_stats);
2039 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
2040 struct i40e_pfc_stats pfc = i40e_get_pfc_stats(pf, i);
2042 i40e_add_ethtool_stats(&data, &pfc, i40e_gstrings_pfc_stats);
2046 WARN_ONCE(data - p != i40e_get_stats_count(netdev),
2047 "ethtool stats count mismatch!");
2051 * i40e_get_stat_strings - copy stat strings into supplied buffer
2052 * @netdev: the netdev to collect strings for
2053 * @data: supplied buffer to copy strings into
2055 * Copy the strings related to stats for this netdev. Expects data to be
2056 * pre-allocated with the size reported by i40e_get_stats_count. Note that the
2057 * strings must be copied in a static order and the total count must not
2058 * change for a given netdev. See i40e_get_stats_count for more details.
2060 static void i40e_get_stat_strings(struct net_device *netdev, u8 *data)
2062 struct i40e_netdev_priv *np = netdev_priv(netdev);
2063 struct i40e_vsi *vsi = np->vsi;
2064 struct i40e_pf *pf = vsi->back;
2068 i40e_add_stat_strings(&data, i40e_gstrings_net_stats);
2070 i40e_add_stat_strings(&data, i40e_gstrings_misc_stats);
2072 for (i = 0; i < netdev->num_tx_queues; i++) {
2073 i40e_add_stat_strings(&data, i40e_gstrings_queue_stats,
2075 i40e_add_stat_strings(&data, i40e_gstrings_queue_stats,
2079 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
2082 i40e_add_stat_strings(&data, i40e_gstrings_veb_stats);
2084 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
2085 i40e_add_stat_strings(&data, i40e_gstrings_veb_tc_stats, i);
2087 i40e_add_stat_strings(&data, i40e_gstrings_stats);
2089 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
2090 i40e_add_stat_strings(&data, i40e_gstrings_pfc_stats, i);
2092 WARN_ONCE(data - p != i40e_get_stats_count(netdev) * ETH_GSTRING_LEN,
2093 "stat strings count mismatch!");
2096 static void i40e_get_priv_flag_strings(struct net_device *netdev, u8 *data)
2098 struct i40e_netdev_priv *np = netdev_priv(netdev);
2099 struct i40e_vsi *vsi = np->vsi;
2100 struct i40e_pf *pf = vsi->back;
2101 char *p = (char *)data;
2104 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
2105 snprintf(p, ETH_GSTRING_LEN, "%s",
2106 i40e_gstrings_priv_flags[i].flag_string);
2107 p += ETH_GSTRING_LEN;
2109 if (pf->hw.pf_id != 0)
2111 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
2112 snprintf(p, ETH_GSTRING_LEN, "%s",
2113 i40e_gl_gstrings_priv_flags[i].flag_string);
2114 p += ETH_GSTRING_LEN;
2118 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
2121 switch (stringset) {
2123 memcpy(data, i40e_gstrings_test,
2124 I40E_TEST_LEN * ETH_GSTRING_LEN);
2127 i40e_get_stat_strings(netdev, data);
2129 case ETH_SS_PRIV_FLAGS:
2130 i40e_get_priv_flag_strings(netdev, data);
2137 static int i40e_get_ts_info(struct net_device *dev,
2138 struct ethtool_ts_info *info)
2140 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
2142 /* only report HW timestamping if PTP is enabled */
2143 if (!(pf->flags & I40E_FLAG_PTP))
2144 return ethtool_op_get_ts_info(dev, info);
2146 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
2147 SOF_TIMESTAMPING_RX_SOFTWARE |
2148 SOF_TIMESTAMPING_SOFTWARE |
2149 SOF_TIMESTAMPING_TX_HARDWARE |
2150 SOF_TIMESTAMPING_RX_HARDWARE |
2151 SOF_TIMESTAMPING_RAW_HARDWARE;
2154 info->phc_index = ptp_clock_index(pf->ptp_clock);
2156 info->phc_index = -1;
2158 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
2160 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
2161 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
2162 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
2163 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
2165 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
2166 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
2167 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
2168 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
2169 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
2170 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
2171 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
2172 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
2173 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
2178 static int i40e_link_test(struct net_device *netdev, u64 *data)
2180 struct i40e_netdev_priv *np = netdev_priv(netdev);
2181 struct i40e_pf *pf = np->vsi->back;
2183 bool link_up = false;
2185 netif_info(pf, hw, netdev, "link test\n");
2186 status = i40e_get_link_status(&pf->hw, &link_up);
2188 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
2201 static int i40e_reg_test(struct net_device *netdev, u64 *data)
2203 struct i40e_netdev_priv *np = netdev_priv(netdev);
2204 struct i40e_pf *pf = np->vsi->back;
2206 netif_info(pf, hw, netdev, "register test\n");
2207 *data = i40e_diag_reg_test(&pf->hw);
2212 static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
2214 struct i40e_netdev_priv *np = netdev_priv(netdev);
2215 struct i40e_pf *pf = np->vsi->back;
2217 netif_info(pf, hw, netdev, "eeprom test\n");
2218 *data = i40e_diag_eeprom_test(&pf->hw);
2220 /* forcebly clear the NVM Update state machine */
2221 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
2226 static int i40e_intr_test(struct net_device *netdev, u64 *data)
2228 struct i40e_netdev_priv *np = netdev_priv(netdev);
2229 struct i40e_pf *pf = np->vsi->back;
2230 u16 swc_old = pf->sw_int_count;
2232 netif_info(pf, hw, netdev, "interrupt test\n");
2233 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
2234 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
2235 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
2236 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
2237 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
2238 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
2239 usleep_range(1000, 2000);
2240 *data = (swc_old == pf->sw_int_count);
2245 static inline bool i40e_active_vfs(struct i40e_pf *pf)
2247 struct i40e_vf *vfs = pf->vf;
2250 for (i = 0; i < pf->num_alloc_vfs; i++)
2251 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
2256 static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
2258 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
2261 static void i40e_diag_test(struct net_device *netdev,
2262 struct ethtool_test *eth_test, u64 *data)
2264 struct i40e_netdev_priv *np = netdev_priv(netdev);
2265 bool if_running = netif_running(netdev);
2266 struct i40e_pf *pf = np->vsi->back;
2268 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
2270 netif_info(pf, drv, netdev, "offline testing starting\n");
2272 set_bit(__I40E_TESTING, pf->state);
2274 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
2275 dev_warn(&pf->pdev->dev,
2276 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
2277 data[I40E_ETH_TEST_REG] = 1;
2278 data[I40E_ETH_TEST_EEPROM] = 1;
2279 data[I40E_ETH_TEST_INTR] = 1;
2280 data[I40E_ETH_TEST_LINK] = 1;
2281 eth_test->flags |= ETH_TEST_FL_FAILED;
2282 clear_bit(__I40E_TESTING, pf->state);
2286 /* If the device is online then take it offline */
2288 /* indicate we're in test mode */
2291 /* This reset does not affect link - if it is
2292 * changed to a type of reset that does affect
2293 * link then the following link test would have
2294 * to be moved to before the reset
2296 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
2298 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
2299 eth_test->flags |= ETH_TEST_FL_FAILED;
2301 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
2302 eth_test->flags |= ETH_TEST_FL_FAILED;
2304 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
2305 eth_test->flags |= ETH_TEST_FL_FAILED;
2307 /* run reg test last, a reset is required after it */
2308 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
2309 eth_test->flags |= ETH_TEST_FL_FAILED;
2311 clear_bit(__I40E_TESTING, pf->state);
2312 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
2318 netif_info(pf, drv, netdev, "online testing starting\n");
2320 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
2321 eth_test->flags |= ETH_TEST_FL_FAILED;
2323 /* Offline only tests, not run in online; pass by default */
2324 data[I40E_ETH_TEST_REG] = 0;
2325 data[I40E_ETH_TEST_EEPROM] = 0;
2326 data[I40E_ETH_TEST_INTR] = 0;
2331 netif_info(pf, drv, netdev, "testing finished\n");
2334 static void i40e_get_wol(struct net_device *netdev,
2335 struct ethtool_wolinfo *wol)
2337 struct i40e_netdev_priv *np = netdev_priv(netdev);
2338 struct i40e_pf *pf = np->vsi->back;
2339 struct i40e_hw *hw = &pf->hw;
2342 /* NVM bit on means WoL disabled for the port */
2343 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
2344 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
2348 wol->supported = WAKE_MAGIC;
2349 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
2354 * i40e_set_wol - set the WakeOnLAN configuration
2355 * @netdev: the netdev in question
2356 * @wol: the ethtool WoL setting data
2358 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2360 struct i40e_netdev_priv *np = netdev_priv(netdev);
2361 struct i40e_pf *pf = np->vsi->back;
2362 struct i40e_vsi *vsi = np->vsi;
2363 struct i40e_hw *hw = &pf->hw;
2366 /* WoL not supported if this isn't the controlling PF on the port */
2367 if (hw->partition_id != 1) {
2368 i40e_partition_setting_complaint(pf);
2372 if (vsi != pf->vsi[pf->lan_vsi])
2375 /* NVM bit on means WoL disabled for the port */
2376 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
2377 if (BIT(hw->port) & wol_nvm_bits)
2380 /* only magic packet is supported */
2381 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC)
2382 | (wol->wolopts != WAKE_FILTER))
2385 /* is this a new value? */
2386 if (pf->wol_en != !!wol->wolopts) {
2387 pf->wol_en = !!wol->wolopts;
2388 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
2394 static int i40e_set_phys_id(struct net_device *netdev,
2395 enum ethtool_phys_id_state state)
2397 struct i40e_netdev_priv *np = netdev_priv(netdev);
2398 i40e_status ret = 0;
2399 struct i40e_pf *pf = np->vsi->back;
2400 struct i40e_hw *hw = &pf->hw;
2405 case ETHTOOL_ID_ACTIVE:
2406 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
2407 pf->led_status = i40e_led_get(hw);
2409 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2410 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2412 ret = i40e_led_get_phy(hw, &temp_status,
2414 pf->led_status = temp_status;
2418 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
2419 i40e_led_set(hw, 0xf, false);
2421 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
2423 case ETHTOOL_ID_OFF:
2424 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
2425 i40e_led_set(hw, 0x0, false);
2427 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
2429 case ETHTOOL_ID_INACTIVE:
2430 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
2431 i40e_led_set(hw, pf->led_status, false);
2433 ret = i40e_led_set_phy(hw, false, pf->led_status,
2435 I40E_PHY_LED_MODE_ORIG));
2436 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2437 i40e_aq_set_phy_debug(hw, 0, NULL);
2449 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2450 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2451 * 125us (8000 interrupts per second) == ITR(62)
2455 * __i40e_get_coalesce - get per-queue coalesce settings
2456 * @netdev: the netdev to check
2457 * @ec: ethtool coalesce data structure
2458 * @queue: which queue to pick
2460 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2461 * are per queue. If queue is <0 then we default to queue 0 as the
2462 * representative value.
2464 static int __i40e_get_coalesce(struct net_device *netdev,
2465 struct ethtool_coalesce *ec,
2468 struct i40e_netdev_priv *np = netdev_priv(netdev);
2469 struct i40e_ring *rx_ring, *tx_ring;
2470 struct i40e_vsi *vsi = np->vsi;
2472 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2473 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2475 /* rx and tx usecs has per queue value. If user doesn't specify the
2476 * queue, return queue 0's value to represent.
2480 else if (queue >= vsi->num_queue_pairs)
2483 rx_ring = vsi->rx_rings[queue];
2484 tx_ring = vsi->tx_rings[queue];
2486 if (ITR_IS_DYNAMIC(rx_ring->itr_setting))
2487 ec->use_adaptive_rx_coalesce = 1;
2489 if (ITR_IS_DYNAMIC(tx_ring->itr_setting))
2490 ec->use_adaptive_tx_coalesce = 1;
2492 ec->rx_coalesce_usecs = rx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
2493 ec->tx_coalesce_usecs = tx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
2495 /* we use the _usecs_high to store/set the interrupt rate limit
2496 * that the hardware supports, that almost but not quite
2497 * fits the original intent of the ethtool variable,
2498 * the rx_coalesce_usecs_high limits total interrupts
2499 * per second from both tx/rx sources.
2501 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2502 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
2508 * i40e_get_coalesce - get a netdev's coalesce settings
2509 * @netdev: the netdev to check
2510 * @ec: ethtool coalesce data structure
2512 * Gets the coalesce settings for a particular netdev. Note that if user has
2513 * modified per-queue settings, this only guarantees to represent queue 0. See
2514 * __i40e_get_coalesce for more details.
2516 static int i40e_get_coalesce(struct net_device *netdev,
2517 struct ethtool_coalesce *ec)
2519 return __i40e_get_coalesce(netdev, ec, -1);
2523 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2524 * @netdev: netdev structure
2525 * @ec: ethtool's coalesce settings
2526 * @queue: the particular queue to read
2528 * Will read a specific queue's coalesce settings
2530 static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2531 struct ethtool_coalesce *ec)
2533 return __i40e_get_coalesce(netdev, ec, queue);
2537 * i40e_set_itr_per_queue - set ITR values for specific queue
2538 * @vsi: the VSI to set values for
2539 * @ec: coalesce settings from ethtool
2540 * @queue: the queue to modify
2542 * Change the ITR settings for a specific queue.
2544 static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2545 struct ethtool_coalesce *ec,
2548 struct i40e_ring *rx_ring = vsi->rx_rings[queue];
2549 struct i40e_ring *tx_ring = vsi->tx_rings[queue];
2550 struct i40e_pf *pf = vsi->back;
2551 struct i40e_hw *hw = &pf->hw;
2552 struct i40e_q_vector *q_vector;
2555 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
2557 rx_ring->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs);
2558 tx_ring->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs);
2560 if (ec->use_adaptive_rx_coalesce)
2561 rx_ring->itr_setting |= I40E_ITR_DYNAMIC;
2563 rx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
2565 if (ec->use_adaptive_tx_coalesce)
2566 tx_ring->itr_setting |= I40E_ITR_DYNAMIC;
2568 tx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
2570 q_vector = rx_ring->q_vector;
2571 q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting);
2573 q_vector = tx_ring->q_vector;
2574 q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting);
2576 /* The interrupt handler itself will take care of programming
2577 * the Tx and Rx ITR values based on the values we have entered
2578 * into the q_vector, no need to write the values now.
2581 wr32(hw, I40E_PFINT_RATEN(q_vector->reg_idx), intrl);
2586 * __i40e_set_coalesce - set coalesce settings for particular queue
2587 * @netdev: the netdev to change
2588 * @ec: ethtool coalesce settings
2589 * @queue: the queue to change
2591 * Sets the coalesce settings for a particular queue.
2593 static int __i40e_set_coalesce(struct net_device *netdev,
2594 struct ethtool_coalesce *ec,
2597 struct i40e_netdev_priv *np = netdev_priv(netdev);
2598 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
2599 struct i40e_vsi *vsi = np->vsi;
2600 struct i40e_pf *pf = vsi->back;
2603 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2604 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2607 cur_rx_itr = vsi->rx_rings[0]->itr_setting;
2608 cur_tx_itr = vsi->tx_rings[0]->itr_setting;
2609 } else if (queue < vsi->num_queue_pairs) {
2610 cur_rx_itr = vsi->rx_rings[queue]->itr_setting;
2611 cur_tx_itr = vsi->tx_rings[queue]->itr_setting;
2613 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2614 vsi->num_queue_pairs - 1);
2618 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2619 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2621 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2622 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2623 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2627 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2628 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2629 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
2633 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2634 ec->use_adaptive_rx_coalesce) {
2635 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2639 if (ec->rx_coalesce_usecs > I40E_MAX_ITR) {
2640 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2644 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2645 ec->use_adaptive_tx_coalesce) {
2646 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2650 if (ec->tx_coalesce_usecs > I40E_MAX_ITR) {
2651 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2655 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
2656 ec->rx_coalesce_usecs = I40E_MIN_ITR;
2658 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
2659 ec->tx_coalesce_usecs = I40E_MIN_ITR;
2661 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2662 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2663 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2664 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2665 vsi->int_rate_limit);
2668 /* rx and tx usecs has per queue value. If user doesn't specify the
2669 * queue, apply to all queues.
2672 for (i = 0; i < vsi->num_queue_pairs; i++)
2673 i40e_set_itr_per_queue(vsi, ec, i);
2675 i40e_set_itr_per_queue(vsi, ec, queue);
2682 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2683 * @netdev: the netdev to change
2684 * @ec: ethtool coalesce settings
2686 * This will set each queue to the same coalesce settings.
2688 static int i40e_set_coalesce(struct net_device *netdev,
2689 struct ethtool_coalesce *ec)
2691 return __i40e_set_coalesce(netdev, ec, -1);
2695 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2696 * @netdev: the netdev to change
2697 * @ec: ethtool's coalesce settings
2698 * @queue: the queue to change
2700 * Sets the specified queue's coalesce settings.
2702 static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2703 struct ethtool_coalesce *ec)
2705 return __i40e_set_coalesce(netdev, ec, queue);
2709 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2710 * @pf: pointer to the physical function struct
2711 * @cmd: ethtool rxnfc command
2713 * Returns Success if the flow is supported, else Invalid Input.
2715 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2717 struct i40e_hw *hw = &pf->hw;
2723 switch (cmd->flow_type) {
2725 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2728 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2731 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2734 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2737 case AH_ESP_V4_FLOW:
2742 case AH_ESP_V6_FLOW:
2746 /* Default is src/dest for IP, no matter the L4 hashing */
2747 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2753 /* Read flow based hash input set register */
2755 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2757 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2758 flow_pctype)) << 32);
2761 /* Process bits of hash input set */
2763 if (i_set & I40E_L4_SRC_MASK)
2764 cmd->data |= RXH_L4_B_0_1;
2765 if (i_set & I40E_L4_DST_MASK)
2766 cmd->data |= RXH_L4_B_2_3;
2768 if (cmd->flow_type == TCP_V4_FLOW ||
2769 cmd->flow_type == UDP_V4_FLOW) {
2770 if (i_set & I40E_L3_SRC_MASK)
2771 cmd->data |= RXH_IP_SRC;
2772 if (i_set & I40E_L3_DST_MASK)
2773 cmd->data |= RXH_IP_DST;
2774 } else if (cmd->flow_type == TCP_V6_FLOW ||
2775 cmd->flow_type == UDP_V6_FLOW) {
2776 if (i_set & I40E_L3_V6_SRC_MASK)
2777 cmd->data |= RXH_IP_SRC;
2778 if (i_set & I40E_L3_V6_DST_MASK)
2779 cmd->data |= RXH_IP_DST;
2787 * i40e_check_mask - Check whether a mask field is set
2788 * @mask: the full mask value
2789 * @field: mask of the field to check
2791 * If the given mask is fully set, return positive value. If the mask for the
2792 * field is fully unset, return zero. Otherwise return a negative error code.
2794 static int i40e_check_mask(u64 mask, u64 field)
2796 u64 value = mask & field;
2807 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2808 * @fsp: pointer to rx flow specification
2809 * @data: pointer to userdef data structure for storage
2811 * Read the user-defined data and deconstruct the value into a structure. No
2812 * other code should read the user-defined data, so as to ensure that every
2813 * place consistently reads the value correctly.
2815 * The user-defined field is a 64bit Big Endian format value, which we
2816 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2817 * be defined starting from the highest bits, while small bit field values
2818 * shall be defined starting from the lowest bits.
2820 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2821 * and the filter should be rejected. The data structure will always be
2822 * modified even if FLOW_EXT is not set.
2825 static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2826 struct i40e_rx_flow_userdef *data)
2831 /* Zero memory first so it's always consistent. */
2832 memset(data, 0, sizeof(*data));
2834 if (!(fsp->flow_type & FLOW_EXT))
2837 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2838 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2840 #define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2841 #define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2842 #define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2844 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2848 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2850 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2851 data->flex_filter = true;
2858 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2859 * @fsp: pointer to rx_flow specification
2860 * @data: pointer to return userdef data
2862 * Reads the userdef data structure and properly fills in the user defined
2863 * fields of the rx_flow_spec.
2865 static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2866 struct i40e_rx_flow_userdef *data)
2868 u64 value = 0, mask = 0;
2870 if (data->flex_filter) {
2871 value |= data->flex_word;
2872 value |= (u64)data->flex_offset << 16;
2873 mask |= I40E_USERDEF_FLEX_FILTER;
2877 fsp->flow_type |= FLOW_EXT;
2879 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2880 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2884 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2885 * @pf: Pointer to the physical function struct
2886 * @cmd: The command to get or set Rx flow classification rules
2887 * @rule_locs: Array of used rule locations
2889 * This function populates both the total and actual rule count of
2890 * the ethtool flow classification command
2892 * Returns 0 on success or -EMSGSIZE if entry not found
2894 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2895 struct ethtool_rxnfc *cmd,
2898 struct i40e_fdir_filter *rule;
2899 struct hlist_node *node2;
2902 /* report total rule count */
2903 cmd->data = i40e_get_fd_cnt_all(pf);
2905 hlist_for_each_entry_safe(rule, node2,
2906 &pf->fdir_filter_list, fdir_node) {
2907 if (cnt == cmd->rule_cnt)
2910 rule_locs[cnt] = rule->fd_id;
2914 cmd->rule_cnt = cnt;
2920 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2921 * @pf: Pointer to the physical function struct
2922 * @cmd: The command to get or set Rx flow classification rules
2924 * This function looks up a filter based on the Rx flow classification
2925 * command and fills the flow spec info for it if found
2927 * Returns 0 on success or -EINVAL if filter not found
2929 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2930 struct ethtool_rxnfc *cmd)
2932 struct ethtool_rx_flow_spec *fsp =
2933 (struct ethtool_rx_flow_spec *)&cmd->fs;
2934 struct i40e_rx_flow_userdef userdef = {0};
2935 struct i40e_fdir_filter *rule = NULL;
2936 struct hlist_node *node2;
2940 hlist_for_each_entry_safe(rule, node2,
2941 &pf->fdir_filter_list, fdir_node) {
2942 if (fsp->location <= rule->fd_id)
2946 if (!rule || fsp->location != rule->fd_id)
2949 fsp->flow_type = rule->flow_type;
2950 if (fsp->flow_type == IP_USER_FLOW) {
2951 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2952 fsp->h_u.usr_ip4_spec.proto = 0;
2953 fsp->m_u.usr_ip4_spec.proto = 0;
2956 /* Reverse the src and dest notion, since the HW views them from
2957 * Tx perspective where as the user expects it from Rx filter view.
2959 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2960 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2961 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2962 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
2964 switch (rule->flow_type) {
2966 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2969 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2972 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2975 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2978 /* If we have stored a filter with a flow type not listed here
2979 * it is almost certainly a driver bug. WARN(), and then
2980 * assign the input_set as if all fields are enabled to avoid
2981 * reading unassigned memory.
2983 WARN(1, "Missing input set index for flow_type %d\n",
2985 input_set = 0xFFFFFFFFFFFFFFFFULL;
2989 input_set = i40e_read_fd_input_set(pf, index);
2992 if (input_set & I40E_L3_SRC_MASK)
2993 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFFFFFF);
2995 if (input_set & I40E_L3_DST_MASK)
2996 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFFFFFF);
2998 if (input_set & I40E_L4_SRC_MASK)
2999 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFF);
3001 if (input_set & I40E_L4_DST_MASK)
3002 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFF);
3004 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
3005 fsp->ring_cookie = RX_CLS_FLOW_DISC;
3007 fsp->ring_cookie = rule->q_index;
3009 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
3010 struct i40e_vsi *vsi;
3012 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
3013 if (vsi && vsi->type == I40E_VSI_SRIOV) {
3014 /* VFs are zero-indexed by the driver, but ethtool
3015 * expects them to be one-indexed, so add one here
3017 u64 ring_vf = vsi->vf_id + 1;
3019 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
3020 fsp->ring_cookie |= ring_vf;
3024 if (rule->flex_filter) {
3025 userdef.flex_filter = true;
3026 userdef.flex_word = be16_to_cpu(rule->flex_word);
3027 userdef.flex_offset = rule->flex_offset;
3030 i40e_fill_rx_flow_user_data(fsp, &userdef);
3036 * i40e_get_rxnfc - command to get RX flow classification rules
3037 * @netdev: network interface device structure
3038 * @cmd: ethtool rxnfc command
3039 * @rule_locs: pointer to store rule data
3041 * Returns Success if the command is supported.
3043 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
3046 struct i40e_netdev_priv *np = netdev_priv(netdev);
3047 struct i40e_vsi *vsi = np->vsi;
3048 struct i40e_pf *pf = vsi->back;
3049 int ret = -EOPNOTSUPP;
3052 case ETHTOOL_GRXRINGS:
3053 cmd->data = vsi->rss_size;
3057 ret = i40e_get_rss_hash_opts(pf, cmd);
3059 case ETHTOOL_GRXCLSRLCNT:
3060 cmd->rule_cnt = pf->fdir_pf_active_filters;
3061 /* report total rule count */
3062 cmd->data = i40e_get_fd_cnt_all(pf);
3065 case ETHTOOL_GRXCLSRULE:
3066 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
3068 case ETHTOOL_GRXCLSRLALL:
3069 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
3079 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
3080 * @nfc: pointer to user request
3081 * @i_setc: bits currently set
3083 * Returns value of bits to be set per user request
3085 static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
3088 u64 src_l3 = 0, dst_l3 = 0;
3090 if (nfc->data & RXH_L4_B_0_1)
3091 i_set |= I40E_L4_SRC_MASK;
3093 i_set &= ~I40E_L4_SRC_MASK;
3094 if (nfc->data & RXH_L4_B_2_3)
3095 i_set |= I40E_L4_DST_MASK;
3097 i_set &= ~I40E_L4_DST_MASK;
3099 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
3100 src_l3 = I40E_L3_V6_SRC_MASK;
3101 dst_l3 = I40E_L3_V6_DST_MASK;
3102 } else if (nfc->flow_type == TCP_V4_FLOW ||
3103 nfc->flow_type == UDP_V4_FLOW) {
3104 src_l3 = I40E_L3_SRC_MASK;
3105 dst_l3 = I40E_L3_DST_MASK;
3107 /* Any other flow type are not supported here */
3111 if (nfc->data & RXH_IP_SRC)
3115 if (nfc->data & RXH_IP_DST)
3124 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
3125 * @pf: pointer to the physical function struct
3126 * @nfc: ethtool rxnfc command
3128 * Returns Success if the flow input set is supported.
3130 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
3132 struct i40e_hw *hw = &pf->hw;
3133 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
3134 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
3138 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3139 dev_err(&pf->pdev->dev,
3140 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
3144 /* RSS does not support anything other than hashing
3145 * to queues on src and dst IPs and ports
3147 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
3148 RXH_L4_B_0_1 | RXH_L4_B_2_3))
3151 switch (nfc->flow_type) {
3153 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
3154 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
3156 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
3159 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
3160 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
3162 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
3163 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
3165 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
3168 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
3169 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
3171 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
3172 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
3174 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
3177 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
3178 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
3180 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
3181 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
3183 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
3185 case AH_ESP_V4_FLOW:
3189 if ((nfc->data & RXH_L4_B_0_1) ||
3190 (nfc->data & RXH_L4_B_2_3))
3192 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
3194 case AH_ESP_V6_FLOW:
3198 if ((nfc->data & RXH_L4_B_0_1) ||
3199 (nfc->data & RXH_L4_B_2_3))
3201 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
3204 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
3205 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
3208 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
3209 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
3216 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
3218 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
3219 flow_pctype)) << 32);
3220 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
3221 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
3223 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
3224 (u32)(i_set >> 32));
3225 hena |= BIT_ULL(flow_pctype);
3228 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
3229 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
3236 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
3237 * @vsi: Pointer to the targeted VSI
3238 * @input: The filter to update or NULL to indicate deletion
3239 * @sw_idx: Software index to the filter
3240 * @cmd: The command to get or set Rx flow classification rules
3242 * This function updates (or deletes) a Flow Director entry from
3243 * the hlist of the corresponding PF
3245 * Returns 0 on success
3247 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
3248 struct i40e_fdir_filter *input,
3250 struct ethtool_rxnfc *cmd)
3252 struct i40e_fdir_filter *rule, *parent;
3253 struct i40e_pf *pf = vsi->back;
3254 struct hlist_node *node2;
3260 hlist_for_each_entry_safe(rule, node2,
3261 &pf->fdir_filter_list, fdir_node) {
3262 /* hash found, or no matching entry */
3263 if (rule->fd_id >= sw_idx)
3268 /* if there is an old rule occupying our place remove it */
3269 if (rule && (rule->fd_id == sw_idx)) {
3270 /* Remove this rule, since we're either deleting it, or
3273 err = i40e_add_del_fdir(vsi, rule, false);
3274 hlist_del(&rule->fdir_node);
3276 pf->fdir_pf_active_filters--;
3279 /* If we weren't given an input, this is a delete, so just return the
3280 * error code indicating if there was an entry at the requested slot
3285 /* Otherwise, install the new rule as requested */
3286 INIT_HLIST_NODE(&input->fdir_node);
3288 /* add filter to the list */
3290 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
3292 hlist_add_head(&input->fdir_node,
3293 &pf->fdir_filter_list);
3296 pf->fdir_pf_active_filters++;
3302 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
3303 * @pf: pointer to PF structure
3305 * This function searches the list of filters and determines which FLX_PIT
3306 * entries are still required. It will prune any entries which are no longer
3307 * in use after the deletion.
3309 static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
3311 struct i40e_flex_pit *entry, *tmp;
3312 struct i40e_fdir_filter *rule;
3314 /* First, we'll check the l3 table */
3315 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
3318 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3319 if (rule->flow_type != IP_USER_FLOW)
3321 if (rule->flex_filter &&
3322 rule->flex_offset == entry->src_offset) {
3328 /* If we didn't find the filter, then we can prune this entry
3332 list_del(&entry->list);
3337 /* Followed by the L4 table */
3338 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
3341 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3342 /* Skip this filter if it's L3, since we already
3343 * checked those in the above loop
3345 if (rule->flow_type == IP_USER_FLOW)
3347 if (rule->flex_filter &&
3348 rule->flex_offset == entry->src_offset) {
3354 /* If we didn't find the filter, then we can prune this entry
3358 list_del(&entry->list);
3365 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
3366 * @vsi: Pointer to the targeted VSI
3367 * @cmd: The command to get or set Rx flow classification rules
3369 * The function removes a Flow Director filter entry from the
3370 * hlist of the corresponding PF
3372 * Returns 0 on success
3374 static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
3375 struct ethtool_rxnfc *cmd)
3377 struct ethtool_rx_flow_spec *fsp =
3378 (struct ethtool_rx_flow_spec *)&cmd->fs;
3379 struct i40e_pf *pf = vsi->back;
3382 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3383 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
3386 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
3389 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
3391 i40e_prune_flex_pit_list(pf);
3393 i40e_fdir_check_and_reenable(pf);
3398 * i40e_unused_pit_index - Find an unused PIT index for given list
3399 * @pf: the PF data structure
3401 * Find the first unused flexible PIT index entry. We search both the L3 and
3402 * L4 flexible PIT lists so that the returned index is unique and unused by
3403 * either currently programmed L3 or L4 filters. We use a bit field as storage
3404 * to track which indexes are already used.
3406 static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3408 unsigned long available_index = 0xFF;
3409 struct i40e_flex_pit *entry;
3411 /* We need to make sure that the new index isn't in use by either L3
3412 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3413 * L4 to use the same index.
3416 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3417 clear_bit(entry->pit_index, &available_index);
3419 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3420 clear_bit(entry->pit_index, &available_index);
3422 return find_first_bit(&available_index, 8);
3426 * i40e_find_flex_offset - Find an existing flex src_offset
3427 * @flex_pit_list: L3 or L4 flex PIT list
3428 * @src_offset: new src_offset to find
3430 * Searches the flex_pit_list for an existing offset. If no offset is
3431 * currently programmed, then this will return an ERR_PTR if there is no space
3432 * to add a new offset, otherwise it returns NULL.
3435 struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3438 struct i40e_flex_pit *entry;
3441 /* Search for the src_offset first. If we find a matching entry
3442 * already programmed, we can simply re-use it.
3444 list_for_each_entry(entry, flex_pit_list, list) {
3446 if (entry->src_offset == src_offset)
3450 /* If we haven't found an entry yet, then the provided src offset has
3451 * not yet been programmed. We will program the src offset later on,
3452 * but we need to indicate whether there is enough space to do so
3453 * here. We'll make use of ERR_PTR for this purpose.
3455 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3456 return ERR_PTR(-ENOSPC);
3462 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3463 * @flex_pit_list: L3 or L4 flex PIT list
3464 * @src_offset: new src_offset to add
3465 * @pit_index: the PIT index to program
3467 * This function programs the new src_offset to the list. It is expected that
3468 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3469 * that this offset is not programmed, and that the list has enough space to
3470 * store another offset.
3472 * Returns 0 on success, and negative value on error.
3474 static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3478 struct i40e_flex_pit *new_pit, *entry;
3480 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3484 new_pit->src_offset = src_offset;
3485 new_pit->pit_index = pit_index;
3487 /* We need to insert this item such that the list is sorted by
3488 * src_offset in ascending order.
3490 list_for_each_entry(entry, flex_pit_list, list) {
3491 if (new_pit->src_offset < entry->src_offset) {
3492 list_add_tail(&new_pit->list, &entry->list);
3496 /* If we found an entry with our offset already programmed we
3497 * can simply return here, after freeing the memory. However,
3498 * if the pit_index does not match we need to report an error.
3500 if (new_pit->src_offset == entry->src_offset) {
3503 /* If the PIT index is not the same we can't re-use
3504 * the entry, so we must report an error.
3506 if (new_pit->pit_index != entry->pit_index)
3514 /* If we reached here, then we haven't yet added the item. This means
3515 * that we should add the item at the end of the list.
3517 list_add_tail(&new_pit->list, flex_pit_list);
3522 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3523 * @pf: Pointer to the PF structure
3524 * @flex_pit_list: list of flexible src offsets in use
3525 * @flex_pit_start: index to first entry for this section of the table
3527 * In order to handle flexible data, the hardware uses a table of values
3528 * called the FLX_PIT table. This table is used to indicate which sections of
3529 * the input correspond to what PIT index values. Unfortunately, hardware is
3530 * very restrictive about programming this table. Entries must be ordered by
3531 * src_offset in ascending order, without duplicates. Additionally, unused
3532 * entries must be set to the unused index value, and must have valid size and
3533 * length according to the src_offset ordering.
3535 * This function will reprogram the FLX_PIT register from a book-keeping
3536 * structure that we guarantee is already ordered correctly, and has no more
3539 * To make things easier, we only support flexible values of one word length,
3540 * rather than allowing variable length flexible values.
3542 static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3543 struct list_head *flex_pit_list,
3546 struct i40e_flex_pit *entry = NULL;
3547 u16 last_offset = 0;
3550 /* First, loop over the list of flex PIT entries, and reprogram the
3553 list_for_each_entry(entry, flex_pit_list, list) {
3554 /* We have to be careful when programming values for the
3555 * largest SRC_OFFSET value. It is possible that adding
3556 * additional empty values at the end would overflow the space
3557 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3558 * we check here and add the empty values prior to adding the
3561 * To determine this, we will use a loop from i+1 to 3, which
3562 * will determine whether the unused entries would have valid
3563 * SRC_OFFSET. Note that there cannot be extra entries past
3564 * this value, because the only valid values would have been
3565 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3566 * have been added to the list in the first place.
3568 for (j = i + 1; j < 3; j++) {
3569 u16 offset = entry->src_offset + j;
3570 int index = flex_pit_start + i;
3571 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3575 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3576 i40e_write_rx_ctl(&pf->hw,
3577 I40E_PRTQF_FLX_PIT(index),
3583 /* Now, we can program the actual value into the table */
3584 i40e_write_rx_ctl(&pf->hw,
3585 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3586 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3588 entry->src_offset));
3592 /* In order to program the last entries in the table, we need to
3593 * determine the valid offset. If the list is empty, we'll just start
3594 * with 0. Otherwise, we'll start with the last item offset and add 1.
3595 * This ensures that all entries have valid sizes. If we don't do this
3596 * correctly, the hardware will disable flexible field parsing.
3598 if (!list_empty(flex_pit_list))
3599 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3601 for (; i < 3; i++, last_offset++) {
3602 i40e_write_rx_ctl(&pf->hw,
3603 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3604 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3611 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3612 * @pf: pointer to the PF structure
3614 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3615 * internal helper function for implementation details.
3617 static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3619 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3620 I40E_FLEX_PIT_IDX_START_L3);
3622 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3623 I40E_FLEX_PIT_IDX_START_L4);
3625 /* We also need to program the L3 and L4 GLQF ORT register */
3626 i40e_write_rx_ctl(&pf->hw,
3627 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3628 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3631 i40e_write_rx_ctl(&pf->hw,
3632 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3633 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3638 * i40e_flow_str - Converts a flow_type into a human readable string
3639 * @fsp: the flow specification
3641 * Currently only flow types we support are included here, and the string
3642 * value attempts to match what ethtool would use to configure this flow type.
3644 static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3646 switch (fsp->flow_type & ~FLOW_EXT) {
3661 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3662 * @pit_index: PIT index to convert
3664 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3667 static u64 i40e_pit_index_to_mask(int pit_index)
3669 switch (pit_index) {
3671 return I40E_FLEX_50_MASK;
3673 return I40E_FLEX_51_MASK;
3675 return I40E_FLEX_52_MASK;
3677 return I40E_FLEX_53_MASK;
3679 return I40E_FLEX_54_MASK;
3681 return I40E_FLEX_55_MASK;
3683 return I40E_FLEX_56_MASK;
3685 return I40E_FLEX_57_MASK;
3692 * i40e_print_input_set - Show changes between two input sets
3693 * @vsi: the vsi being configured
3694 * @old: the old input set
3695 * @new: the new input set
3697 * Print the difference between old and new input sets by showing which series
3698 * of words are toggled on or off. Only displays the bits we actually support
3701 static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3703 struct i40e_pf *pf = vsi->back;
3704 bool old_value, new_value;
3707 old_value = !!(old & I40E_L3_SRC_MASK);
3708 new_value = !!(new & I40E_L3_SRC_MASK);
3709 if (old_value != new_value)
3710 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3711 old_value ? "ON" : "OFF",
3712 new_value ? "ON" : "OFF");
3714 old_value = !!(old & I40E_L3_DST_MASK);
3715 new_value = !!(new & I40E_L3_DST_MASK);
3716 if (old_value != new_value)
3717 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3718 old_value ? "ON" : "OFF",
3719 new_value ? "ON" : "OFF");
3721 old_value = !!(old & I40E_L4_SRC_MASK);
3722 new_value = !!(new & I40E_L4_SRC_MASK);
3723 if (old_value != new_value)
3724 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3725 old_value ? "ON" : "OFF",
3726 new_value ? "ON" : "OFF");
3728 old_value = !!(old & I40E_L4_DST_MASK);
3729 new_value = !!(new & I40E_L4_DST_MASK);
3730 if (old_value != new_value)
3731 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3732 old_value ? "ON" : "OFF",
3733 new_value ? "ON" : "OFF");
3735 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3736 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3737 if (old_value != new_value)
3738 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3739 old_value ? "ON" : "OFF",
3740 new_value ? "ON" : "OFF");
3742 /* Show change of flexible filter entries */
3743 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3744 u64 flex_mask = i40e_pit_index_to_mask(i);
3746 old_value = !!(old & flex_mask);
3747 new_value = !!(new & flex_mask);
3748 if (old_value != new_value)
3749 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3751 old_value ? "ON" : "OFF",
3752 new_value ? "ON" : "OFF");
3755 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3757 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3762 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
3763 * @vsi: pointer to the targeted VSI
3764 * @fsp: pointer to Rx flow specification
3765 * @userdef: userdefined data from flow specification
3767 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3768 * for partial matches exists with a few limitations. First, hardware only
3769 * supports masking by word boundary (2 bytes) and not per individual bit.
3770 * Second, hardware is limited to using one mask for a flow type and cannot
3771 * use a separate mask for each filter.
3773 * To support these limitations, if we already have a configured filter for
3774 * the specified type, this function enforces that new filters of the type
3775 * match the configured input set. Otherwise, if we do not have a filter of
3776 * the specified type, we allow the input set to be updated to match the
3779 * To help ensure that administrators understand why filters weren't displayed
3780 * as supported, we print a diagnostic message displaying how the input set
3781 * would change and warning to delete the preexisting filters if required.
3783 * Returns 0 on successful input set match, and a negative return code on
3786 static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
3787 struct ethtool_rx_flow_spec *fsp,
3788 struct i40e_rx_flow_userdef *userdef)
3790 struct i40e_pf *pf = vsi->back;
3791 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3792 struct ethtool_usrip4_spec *usr_ip4_spec;
3793 u64 current_mask, new_mask;
3794 bool new_flex_offset = false;
3795 bool flex_l3 = false;
3796 u16 *fdir_filter_count;
3797 u16 index, src_offset = 0;
3801 switch (fsp->flow_type & ~FLOW_EXT) {
3803 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3804 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3807 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
3808 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
3811 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
3812 fdir_filter_count = &pf->fd_udp4_filter_cnt;
3815 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
3816 fdir_filter_count = &pf->fd_ip4_filter_cnt;
3823 /* Read the current input set from register memory. */
3824 current_mask = i40e_read_fd_input_set(pf, index);
3825 new_mask = current_mask;
3827 /* Determine, if any, the required changes to the input set in order
3828 * to support the provided mask.
3830 * Hardware only supports masking at word (2 byte) granularity and does
3831 * not support full bitwise masking. This implementation simplifies
3832 * even further and only supports fully enabled or fully disabled
3833 * masks for each field, even though we could split the ip4src and
3836 switch (fsp->flow_type & ~FLOW_EXT) {
3838 new_mask &= ~I40E_VERIFY_TAG_MASK;
3842 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3844 /* IPv4 source address */
3845 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3846 new_mask |= I40E_L3_SRC_MASK;
3847 else if (!tcp_ip4_spec->ip4src)
3848 new_mask &= ~I40E_L3_SRC_MASK;
3852 /* IPv4 destination address */
3853 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3854 new_mask |= I40E_L3_DST_MASK;
3855 else if (!tcp_ip4_spec->ip4dst)
3856 new_mask &= ~I40E_L3_DST_MASK;
3860 /* L4 source port */
3861 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3862 new_mask |= I40E_L4_SRC_MASK;
3863 else if (!tcp_ip4_spec->psrc)
3864 new_mask &= ~I40E_L4_SRC_MASK;
3868 /* L4 destination port */
3869 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3870 new_mask |= I40E_L4_DST_MASK;
3871 else if (!tcp_ip4_spec->pdst)
3872 new_mask &= ~I40E_L4_DST_MASK;
3876 /* Filtering on Type of Service is not supported. */
3877 if (tcp_ip4_spec->tos)
3882 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3884 /* IPv4 source address */
3885 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3886 new_mask |= I40E_L3_SRC_MASK;
3887 else if (!usr_ip4_spec->ip4src)
3888 new_mask &= ~I40E_L3_SRC_MASK;
3892 /* IPv4 destination address */
3893 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3894 new_mask |= I40E_L3_DST_MASK;
3895 else if (!usr_ip4_spec->ip4dst)
3896 new_mask &= ~I40E_L3_DST_MASK;
3900 /* First 4 bytes of L4 header */
3901 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3902 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3903 else if (!usr_ip4_spec->l4_4_bytes)
3904 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3908 /* Filtering on Type of Service is not supported. */
3909 if (usr_ip4_spec->tos)
3912 /* Filtering on IP version is not supported */
3913 if (usr_ip4_spec->ip_ver)
3916 /* Filtering on L4 protocol is not supported */
3917 if (usr_ip4_spec->proto)
3925 /* First, clear all flexible filter entries */
3926 new_mask &= ~I40E_FLEX_INPUT_MASK;
3928 /* If we have a flexible filter, try to add this offset to the correct
3929 * flexible filter PIT list. Once finished, we can update the mask.
3930 * If the src_offset changed, we will get a new mask value which will
3931 * trigger an input set change.
3933 if (userdef->flex_filter) {
3934 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3936 /* Flexible offset must be even, since the flexible payload
3937 * must be aligned on 2-byte boundary.
3939 if (userdef->flex_offset & 0x1) {
3940 dev_warn(&pf->pdev->dev,
3941 "Flexible data offset must be 2-byte aligned\n");
3945 src_offset = userdef->flex_offset >> 1;
3947 /* FLX_PIT source offset value is only so large */
3948 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3949 dev_warn(&pf->pdev->dev,
3950 "Flexible data must reside within first 64 bytes of the packet payload\n");
3954 /* See if this offset has already been programmed. If we get
3955 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3956 * if we get a NULL pointer, this means we will need to add
3959 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3961 if (IS_ERR(flex_pit))
3962 return PTR_ERR(flex_pit);
3964 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3965 * packet types, and thus we need to program both L3 and L4
3966 * flexible values. These must have identical flexible index,
3967 * as otherwise we can't correctly program the input set. So
3968 * we'll find both an L3 and L4 index and make sure they are
3973 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3975 if (IS_ERR(l3_flex_pit))
3976 return PTR_ERR(l3_flex_pit);
3979 /* If we already had a matching L4 entry, we
3980 * need to make sure that the L3 entry we
3981 * obtained uses the same index.
3984 if (l3_flex_pit->pit_index !=
3985 flex_pit->pit_index) {
3989 new_flex_offset = true;
3992 flex_pit = l3_flex_pit;
3996 /* If we didn't find an existing flex offset, we need to
3997 * program a new one. However, we don't immediately program it
3998 * here because we will wait to program until after we check
3999 * that it is safe to change the input set.
4002 new_flex_offset = true;
4003 pit_index = i40e_unused_pit_index(pf);
4005 pit_index = flex_pit->pit_index;
4008 /* Update the mask with the new offset */
4009 new_mask |= i40e_pit_index_to_mask(pit_index);
4012 /* If the mask and flexible filter offsets for this filter match the
4013 * currently programmed values we don't need any input set change, so
4014 * this filter is safe to install.
4016 if (new_mask == current_mask && !new_flex_offset)
4019 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
4020 i40e_flow_str(fsp));
4021 i40e_print_input_set(vsi, current_mask, new_mask);
4022 if (new_flex_offset) {
4023 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
4024 pit_index, src_offset);
4027 /* Hardware input sets are global across multiple ports, so even the
4028 * main port cannot change them when in MFP mode as this would impact
4029 * any filters on the other ports.
4031 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
4032 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
4036 /* This filter requires us to update the input set. However, hardware
4037 * only supports one input set per flow type, and does not support
4038 * separate masks for each filter. This means that we can only support
4039 * a single mask for all filters of a specific type.
4041 * If we have preexisting filters, they obviously depend on the
4042 * current programmed input set. Display a diagnostic message in this
4043 * case explaining why the filter could not be accepted.
4045 if (*fdir_filter_count) {
4046 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
4048 *fdir_filter_count);
4052 i40e_write_fd_input_set(pf, index, new_mask);
4054 /* IP_USER_FLOW filters match both IPv4/Other and IPv4/Fragmented
4055 * frames. If we're programming the input set for IPv4/Other, we also
4056 * need to program the IPv4/Fragmented input set. Since we don't have
4057 * separate support, we'll always assume and enforce that the two flow
4058 * types must have matching input sets.
4060 if (index == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER)
4061 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
4064 /* Add the new offset and update table, if necessary */
4065 if (new_flex_offset) {
4066 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
4072 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
4079 i40e_reprogram_flex_pit(pf);
4086 * i40e_match_fdir_filter - Return true of two filters match
4087 * @a: pointer to filter struct
4088 * @b: pointer to filter struct
4090 * Returns true if the two filters match exactly the same criteria. I.e. they
4091 * match the same flow type and have the same parameters. We don't need to
4092 * check any input-set since all filters of the same flow type must use the
4095 static bool i40e_match_fdir_filter(struct i40e_fdir_filter *a,
4096 struct i40e_fdir_filter *b)
4098 /* The filters do not much if any of these criteria differ. */
4099 if (a->dst_ip != b->dst_ip ||
4100 a->src_ip != b->src_ip ||
4101 a->dst_port != b->dst_port ||
4102 a->src_port != b->src_port ||
4103 a->flow_type != b->flow_type ||
4104 a->ip4_proto != b->ip4_proto)
4111 * i40e_disallow_matching_filters - Check that new filters differ
4112 * @vsi: pointer to the targeted VSI
4113 * @input: new filter to check
4115 * Due to hardware limitations, it is not possible for two filters that match
4116 * similar criteria to be programmed at the same time. This is true for a few
4119 * (a) all filters matching a particular flow type must use the same input
4120 * set, that is they must match the same criteria.
4121 * (b) different flow types will never match the same packet, as the flow type
4122 * is decided by hardware before checking which rules apply.
4123 * (c) hardware has no way to distinguish which order filters apply in.
4125 * Due to this, we can't really support using the location data to order
4126 * filters in the hardware parsing. It is technically possible for the user to
4127 * request two filters matching the same criteria but which select different
4128 * queues. In this case, rather than keep both filters in the list, we reject
4129 * the 2nd filter when the user requests adding it.
4131 * This avoids needing to track location for programming the filter to
4132 * hardware, and ensures that we avoid some strange scenarios involving
4133 * deleting filters which match the same criteria.
4135 static int i40e_disallow_matching_filters(struct i40e_vsi *vsi,
4136 struct i40e_fdir_filter *input)
4138 struct i40e_pf *pf = vsi->back;
4139 struct i40e_fdir_filter *rule;
4140 struct hlist_node *node2;
4142 /* Loop through every filter, and check that it doesn't match */
4143 hlist_for_each_entry_safe(rule, node2,
4144 &pf->fdir_filter_list, fdir_node) {
4145 /* Don't check the filters match if they share the same fd_id,
4146 * since the new filter is actually just updating the target
4147 * of the old filter.
4149 if (rule->fd_id == input->fd_id)
4152 /* If any filters match, then print a warning message to the
4153 * kernel message buffer and bail out.
4155 if (i40e_match_fdir_filter(rule, input)) {
4156 dev_warn(&pf->pdev->dev,
4157 "Existing user defined filter %d already matches this flow.\n",
4167 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
4168 * @vsi: pointer to the targeted VSI
4169 * @cmd: command to get or set RX flow classification rules
4171 * Add Flow Director filters for a specific flow spec based on their
4172 * protocol. Returns 0 if the filters were successfully added.
4174 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
4175 struct ethtool_rxnfc *cmd)
4177 struct i40e_rx_flow_userdef userdef;
4178 struct ethtool_rx_flow_spec *fsp;
4179 struct i40e_fdir_filter *input;
4180 u16 dest_vsi = 0, q_index = 0;
4189 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
4192 if (test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
4195 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
4196 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
4199 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
4202 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
4204 /* Parse the user-defined field */
4205 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
4208 /* Extended MAC field is not supported */
4209 if (fsp->flow_type & FLOW_MAC_EXT)
4212 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
4216 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
4217 pf->hw.func_caps.fd_filters_guaranteed)) {
4221 /* ring_cookie is either the drop index, or is a mask of the queue
4222 * index and VF id we wish to target.
4224 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
4225 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
4227 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
4228 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
4231 if (ring >= vsi->num_queue_pairs)
4235 /* VFs are zero-indexed, so we subtract one here */
4238 if (vf >= pf->num_alloc_vfs)
4240 if (ring >= pf->vf[vf].num_queue_pairs)
4242 dest_vsi = pf->vf[vf].lan_vsi_id;
4244 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
4248 input = kzalloc(sizeof(*input), GFP_KERNEL);
4253 input->fd_id = fsp->location;
4254 input->q_index = q_index;
4255 input->dest_vsi = dest_vsi;
4256 input->dest_ctl = dest_ctl;
4257 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
4258 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
4259 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4260 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
4261 input->flow_type = fsp->flow_type & ~FLOW_EXT;
4262 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
4264 /* Reverse the src and dest notion, since the HW expects them to be from
4265 * Tx perspective where as the input from user is from Rx filter view.
4267 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
4268 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
4269 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4270 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
4272 if (userdef.flex_filter) {
4273 input->flex_filter = true;
4274 input->flex_word = cpu_to_be16(userdef.flex_word);
4275 input->flex_offset = userdef.flex_offset;
4278 /* Avoid programming two filters with identical match criteria. */
4279 ret = i40e_disallow_matching_filters(vsi, input);
4281 goto free_filter_memory;
4283 /* Add the input filter to the fdir_input_list, possibly replacing
4284 * a previous filter. Do not free the input structure after adding it
4285 * to the list as this would cause a use-after-free bug.
4287 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
4288 ret = i40e_add_del_fdir(vsi, input, true);
4290 goto remove_sw_rule;
4294 hlist_del(&input->fdir_node);
4295 pf->fdir_pf_active_filters--;
4302 * i40e_set_rxnfc - command to set RX flow classification rules
4303 * @netdev: network interface device structure
4304 * @cmd: ethtool rxnfc command
4306 * Returns Success if the command is supported.
4308 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
4310 struct i40e_netdev_priv *np = netdev_priv(netdev);
4311 struct i40e_vsi *vsi = np->vsi;
4312 struct i40e_pf *pf = vsi->back;
4313 int ret = -EOPNOTSUPP;
4317 ret = i40e_set_rss_hash_opt(pf, cmd);
4319 case ETHTOOL_SRXCLSRLINS:
4320 ret = i40e_add_fdir_ethtool(vsi, cmd);
4322 case ETHTOOL_SRXCLSRLDEL:
4323 ret = i40e_del_fdir_entry(vsi, cmd);
4333 * i40e_max_channels - get Max number of combined channels supported
4336 static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
4338 /* TODO: This code assumes DCB and FD is disabled for now. */
4339 return vsi->alloc_queue_pairs;
4343 * i40e_get_channels - Get the current channels enabled and max supported etc.
4344 * @dev: network interface device structure
4345 * @ch: ethtool channels structure
4347 * We don't support separate tx and rx queues as channels. The other count
4348 * represents how many queues are being used for control. max_combined counts
4349 * how many queue pairs we can support. They may not be mapped 1 to 1 with
4350 * q_vectors since we support a lot more queue pairs than q_vectors.
4352 static void i40e_get_channels(struct net_device *dev,
4353 struct ethtool_channels *ch)
4355 struct i40e_netdev_priv *np = netdev_priv(dev);
4356 struct i40e_vsi *vsi = np->vsi;
4357 struct i40e_pf *pf = vsi->back;
4359 /* report maximum channels */
4360 ch->max_combined = i40e_max_channels(vsi);
4362 /* report info for other vector */
4363 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
4364 ch->max_other = ch->other_count;
4366 /* Note: This code assumes DCB is disabled for now. */
4367 ch->combined_count = vsi->num_queue_pairs;
4371 * i40e_set_channels - Set the new channels count.
4372 * @dev: network interface device structure
4373 * @ch: ethtool channels structure
4375 * The new channels count may not be the same as requested by the user
4376 * since it gets rounded down to a power of 2 value.
4378 static int i40e_set_channels(struct net_device *dev,
4379 struct ethtool_channels *ch)
4381 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
4382 struct i40e_netdev_priv *np = netdev_priv(dev);
4383 unsigned int count = ch->combined_count;
4384 struct i40e_vsi *vsi = np->vsi;
4385 struct i40e_pf *pf = vsi->back;
4386 struct i40e_fdir_filter *rule;
4387 struct hlist_node *node2;
4391 /* We do not support setting channels for any other VSI at present */
4392 if (vsi->type != I40E_VSI_MAIN)
4395 /* We do not support setting channels via ethtool when TCs are
4396 * configured through mqprio
4398 if (pf->flags & I40E_FLAG_TC_MQPRIO)
4401 /* verify they are not requesting separate vectors */
4402 if (!count || ch->rx_count || ch->tx_count)
4405 /* verify other_count has not changed */
4406 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
4409 /* verify the number of channels does not exceed hardware limits */
4410 if (count > i40e_max_channels(vsi))
4413 /* verify that the number of channels does not invalidate any current
4414 * flow director rules
4416 hlist_for_each_entry_safe(rule, node2,
4417 &pf->fdir_filter_list, fdir_node) {
4418 if (rule->dest_ctl != drop && count <= rule->q_index) {
4419 dev_warn(&pf->pdev->dev,
4420 "Existing user defined filter %d assigns flow to queue %d\n",
4421 rule->fd_id, rule->q_index);
4427 dev_err(&pf->pdev->dev,
4428 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
4433 /* update feature limits from largest to smallest supported values */
4434 /* TODO: Flow director limit, DCB etc */
4436 /* use rss_reconfig to rebuild with new queue count and update traffic
4437 * class queue mapping
4439 new_count = i40e_reconfig_rss_queues(pf, count);
4447 * i40e_get_rxfh_key_size - get the RSS hash key size
4448 * @netdev: network interface device structure
4450 * Returns the table size.
4452 static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
4454 return I40E_HKEY_ARRAY_SIZE;
4458 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
4459 * @netdev: network interface device structure
4461 * Returns the table size.
4463 static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
4465 return I40E_HLUT_ARRAY_SIZE;
4469 * i40e_get_rxfh - get the rx flow hash indirection table
4470 * @netdev: network interface device structure
4471 * @indir: indirection table
4473 * @hfunc: hash function
4475 * Reads the indirection table directly from the hardware. Returns 0 on
4478 static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
4481 struct i40e_netdev_priv *np = netdev_priv(netdev);
4482 struct i40e_vsi *vsi = np->vsi;
4483 u8 *lut, *seed = NULL;
4488 *hfunc = ETH_RSS_HASH_TOP;
4494 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4497 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
4500 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4501 indir[i] = (u32)(lut[i]);
4510 * i40e_set_rxfh - set the rx flow hash indirection table
4511 * @netdev: network interface device structure
4512 * @indir: indirection table
4514 * @hfunc: hash function to use
4516 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
4517 * returns 0 after programming the table.
4519 static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4520 const u8 *key, const u8 hfunc)
4522 struct i40e_netdev_priv *np = netdev_priv(netdev);
4523 struct i40e_vsi *vsi = np->vsi;
4524 struct i40e_pf *pf = vsi->back;
4528 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4532 if (!vsi->rss_hkey_user) {
4533 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4535 if (!vsi->rss_hkey_user)
4538 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4539 seed = vsi->rss_hkey_user;
4541 if (!vsi->rss_lut_user) {
4542 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4543 if (!vsi->rss_lut_user)
4547 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
4549 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4550 vsi->rss_lut_user[i] = (u8)(indir[i]);
4552 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4555 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4556 I40E_HLUT_ARRAY_SIZE);
4560 * i40e_get_priv_flags - report device private flags
4561 * @dev: network interface device structure
4563 * The get string set count and the string set should be matched for each
4564 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
4567 * Returns a u32 bitmap of flags.
4569 static u32 i40e_get_priv_flags(struct net_device *dev)
4571 struct i40e_netdev_priv *np = netdev_priv(dev);
4572 struct i40e_vsi *vsi = np->vsi;
4573 struct i40e_pf *pf = vsi->back;
4574 u32 i, j, ret_flags = 0;
4576 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4577 const struct i40e_priv_flags *priv_flags;
4579 priv_flags = &i40e_gstrings_priv_flags[i];
4581 if (priv_flags->flag & pf->flags)
4582 ret_flags |= BIT(i);
4585 if (pf->hw.pf_id != 0)
4588 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4589 const struct i40e_priv_flags *priv_flags;
4591 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4593 if (priv_flags->flag & pf->flags)
4594 ret_flags |= BIT(i + j);
4601 * i40e_set_priv_flags - set private flags
4602 * @dev: network interface device structure
4603 * @flags: bit flags to be set
4605 static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4607 struct i40e_netdev_priv *np = netdev_priv(dev);
4608 struct i40e_vsi *vsi = np->vsi;
4609 struct i40e_pf *pf = vsi->back;
4610 u64 orig_flags, new_flags, changed_flags;
4613 orig_flags = READ_ONCE(pf->flags);
4614 new_flags = orig_flags;
4616 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4617 const struct i40e_priv_flags *priv_flags;
4619 priv_flags = &i40e_gstrings_priv_flags[i];
4622 new_flags |= priv_flags->flag;
4624 new_flags &= ~(priv_flags->flag);
4626 /* If this is a read-only flag, it can't be changed */
4627 if (priv_flags->read_only &&
4628 ((orig_flags ^ new_flags) & ~BIT(i)))
4632 if (pf->hw.pf_id != 0)
4633 goto flags_complete;
4635 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4636 const struct i40e_priv_flags *priv_flags;
4638 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4640 if (flags & BIT(i + j))
4641 new_flags |= priv_flags->flag;
4643 new_flags &= ~(priv_flags->flag);
4645 /* If this is a read-only flag, it can't be changed */
4646 if (priv_flags->read_only &&
4647 ((orig_flags ^ new_flags) & ~BIT(i)))
4652 changed_flags = orig_flags ^ new_flags;
4654 /* Before we finalize any flag changes, we need to perform some
4655 * checks to ensure that the changes are supported and safe.
4658 /* ATR eviction is not supported on all devices */
4659 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4660 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4663 /* If the driver detected FW LLDP was disabled on init, this flag could
4664 * be set, however we do not support _changing_ the flag:
4665 * - on XL710 if NPAR is enabled or FW API version < 1.7
4666 * - on X722 with FW API version < 1.6
4667 * There are situations where older FW versions/NPAR enabled PFs could
4668 * disable LLDP, however we _must_ not allow the user to enable/disable
4669 * LLDP with this flag on unsupported FW versions.
4671 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
4672 if (!(pf->hw.flags & I40E_HW_FLAG_FW_LLDP_STOPPABLE)) {
4673 dev_warn(&pf->pdev->dev,
4674 "Device does not support changing FW LLDP\n");
4679 /* Now that we've checked to ensure that the new flags are valid, load
4680 * them into place. Since we only modify flags either (a) during
4681 * initialization or (b) while holding the RTNL lock, we don't need
4682 * anything fancy here.
4684 pf->flags = new_flags;
4686 /* Process any additional changes needed as a result of flag changes.
4687 * The changed_flags value reflects the list of bits that were
4688 * changed in the code above.
4691 /* Flush current ATR settings if ATR was disabled */
4692 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4693 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
4694 set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
4695 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
4698 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4699 u16 sw_flags = 0, valid_flags = 0;
4702 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4703 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4704 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4705 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
4707 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4708 dev_info(&pf->pdev->dev,
4709 "couldn't set switch config bits, err %s aq_err %s\n",
4710 i40e_stat_str(&pf->hw, ret),
4711 i40e_aq_str(&pf->hw,
4712 pf->hw.aq.asq_last_status));
4713 /* not a fatal problem, just keep going */
4717 if ((changed_flags & pf->flags &
4718 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED) &&
4719 (pf->flags & I40E_FLAG_MFP_ENABLED))
4720 dev_warn(&pf->pdev->dev,
4721 "Turning on link-down-on-close flag may affect other partitions\n");
4723 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
4724 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP) {
4725 struct i40e_dcbx_config *dcbcfg;
4727 i40e_aq_stop_lldp(&pf->hw, true, NULL);
4728 i40e_aq_set_dcb_parameters(&pf->hw, true, NULL);
4729 /* reset local_dcbx_config to default */
4730 dcbcfg = &pf->hw.local_dcbx_config;
4731 dcbcfg->etscfg.willing = 1;
4732 dcbcfg->etscfg.maxtcs = 0;
4733 dcbcfg->etscfg.tcbwtable[0] = 100;
4734 for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++)
4735 dcbcfg->etscfg.tcbwtable[i] = 0;
4736 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4737 dcbcfg->etscfg.prioritytable[i] = 0;
4738 dcbcfg->etscfg.tsatable[0] = I40E_IEEE_TSA_ETS;
4739 dcbcfg->pfc.willing = 1;
4740 dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
4742 i40e_aq_start_lldp(&pf->hw, NULL);
4746 /* Issue reset to cause things to take effect, as additional bits
4747 * are added we will need to create a mask of bits requiring reset
4749 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4750 I40E_FLAG_LEGACY_RX |
4751 I40E_FLAG_SOURCE_PRUNING_DISABLED |
4752 I40E_FLAG_DISABLE_FW_LLDP))
4753 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
4759 * i40e_get_module_info - get (Q)SFP+ module type info
4760 * @netdev: network interface device structure
4761 * @modinfo: module EEPROM size and layout information structure
4763 static int i40e_get_module_info(struct net_device *netdev,
4764 struct ethtool_modinfo *modinfo)
4766 struct i40e_netdev_priv *np = netdev_priv(netdev);
4767 struct i40e_vsi *vsi = np->vsi;
4768 struct i40e_pf *pf = vsi->back;
4769 struct i40e_hw *hw = &pf->hw;
4770 u32 sff8472_comp = 0;
4771 u32 sff8472_swap = 0;
4772 u32 sff8636_rev = 0;
4776 /* Check if firmware supports reading module EEPROM. */
4777 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4778 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4782 status = i40e_update_link_info(hw);
4786 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4787 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4791 type = hw->phy.link_info.module_type[0];
4794 case I40E_MODULE_TYPE_SFP:
4795 status = i40e_aq_get_phy_register(hw,
4796 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4797 I40E_I2C_EEPROM_DEV_ADDR,
4798 I40E_MODULE_SFF_8472_COMP,
4799 &sff8472_comp, NULL);
4803 status = i40e_aq_get_phy_register(hw,
4804 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4805 I40E_I2C_EEPROM_DEV_ADDR,
4806 I40E_MODULE_SFF_8472_SWAP,
4807 &sff8472_swap, NULL);
4811 /* Check if the module requires address swap to access
4812 * the other EEPROM memory page.
4814 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4815 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4816 modinfo->type = ETH_MODULE_SFF_8079;
4817 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4818 } else if (sff8472_comp == 0x00) {
4819 /* Module is not SFF-8472 compliant */
4820 modinfo->type = ETH_MODULE_SFF_8079;
4821 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4823 modinfo->type = ETH_MODULE_SFF_8472;
4824 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4827 case I40E_MODULE_TYPE_QSFP_PLUS:
4828 /* Read from memory page 0. */
4829 status = i40e_aq_get_phy_register(hw,
4830 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4832 I40E_MODULE_REVISION_ADDR,
4833 &sff8636_rev, NULL);
4836 /* Determine revision compliance byte */
4837 if (sff8636_rev > 0x02) {
4838 /* Module is SFF-8636 compliant */
4839 modinfo->type = ETH_MODULE_SFF_8636;
4840 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4842 modinfo->type = ETH_MODULE_SFF_8436;
4843 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4846 case I40E_MODULE_TYPE_QSFP28:
4847 modinfo->type = ETH_MODULE_SFF_8636;
4848 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4851 netdev_err(vsi->netdev, "Module type unrecognized\n");
4858 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4859 * @netdev: network interface device structure
4860 * @ee: EEPROM dump request structure
4861 * @data: buffer to be filled with EEPROM contents
4863 static int i40e_get_module_eeprom(struct net_device *netdev,
4864 struct ethtool_eeprom *ee,
4867 struct i40e_netdev_priv *np = netdev_priv(netdev);
4868 struct i40e_vsi *vsi = np->vsi;
4869 struct i40e_pf *pf = vsi->back;
4870 struct i40e_hw *hw = &pf->hw;
4871 bool is_sfp = false;
4876 if (!ee || !ee->len || !data)
4879 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4882 for (i = 0; i < ee->len; i++) {
4883 u32 offset = i + ee->offset;
4884 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4886 /* Check if we need to access the other memory page */
4888 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4889 offset -= ETH_MODULE_SFF_8079_LEN;
4890 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4893 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4894 /* Compute memory page number and offset. */
4895 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4900 status = i40e_aq_get_phy_register(hw,
4901 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4902 addr, offset, &value, NULL);
4910 static const struct ethtool_ops i40e_ethtool_ops = {
4911 .get_drvinfo = i40e_get_drvinfo,
4912 .get_regs_len = i40e_get_regs_len,
4913 .get_regs = i40e_get_regs,
4914 .nway_reset = i40e_nway_reset,
4915 .get_link = ethtool_op_get_link,
4916 .get_wol = i40e_get_wol,
4917 .set_wol = i40e_set_wol,
4918 .set_eeprom = i40e_set_eeprom,
4919 .get_eeprom_len = i40e_get_eeprom_len,
4920 .get_eeprom = i40e_get_eeprom,
4921 .get_ringparam = i40e_get_ringparam,
4922 .set_ringparam = i40e_set_ringparam,
4923 .get_pauseparam = i40e_get_pauseparam,
4924 .set_pauseparam = i40e_set_pauseparam,
4925 .get_msglevel = i40e_get_msglevel,
4926 .set_msglevel = i40e_set_msglevel,
4927 .get_rxnfc = i40e_get_rxnfc,
4928 .set_rxnfc = i40e_set_rxnfc,
4929 .self_test = i40e_diag_test,
4930 .get_strings = i40e_get_strings,
4931 .set_phys_id = i40e_set_phys_id,
4932 .get_sset_count = i40e_get_sset_count,
4933 .get_ethtool_stats = i40e_get_ethtool_stats,
4934 .get_coalesce = i40e_get_coalesce,
4935 .set_coalesce = i40e_set_coalesce,
4936 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4937 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4938 .get_rxfh = i40e_get_rxfh,
4939 .set_rxfh = i40e_set_rxfh,
4940 .get_channels = i40e_get_channels,
4941 .set_channels = i40e_set_channels,
4942 .get_module_info = i40e_get_module_info,
4943 .get_module_eeprom = i40e_get_module_eeprom,
4944 .get_ts_info = i40e_get_ts_info,
4945 .get_priv_flags = i40e_get_priv_flags,
4946 .set_priv_flags = i40e_set_priv_flags,
4947 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
4948 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
4949 .get_link_ksettings = i40e_get_link_ksettings,
4950 .set_link_ksettings = i40e_set_link_ksettings,
4953 void i40e_set_ethtool_ops(struct net_device *netdev)
4955 netdev->ethtool_ops = &i40e_ethtool_ops;