1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2016 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
27 /* ethtool support for i40e */
30 #include "i40e_diag.h"
33 char stat_string[ETH_GSTRING_LEN];
38 #define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
44 #define I40E_NETDEV_STAT(_net_stat) \
45 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
46 #define I40E_PF_STAT(_name, _stat) \
47 I40E_STAT(struct i40e_pf, _name, _stat)
48 #define I40E_VSI_STAT(_name, _stat) \
49 I40E_STAT(struct i40e_vsi, _name, _stat)
50 #define I40E_VEB_STAT(_name, _stat) \
51 I40E_STAT(struct i40e_veb, _name, _stat)
53 static const struct i40e_stats i40e_gstrings_net_stats[] = {
54 I40E_NETDEV_STAT(rx_packets),
55 I40E_NETDEV_STAT(tx_packets),
56 I40E_NETDEV_STAT(rx_bytes),
57 I40E_NETDEV_STAT(tx_bytes),
58 I40E_NETDEV_STAT(rx_errors),
59 I40E_NETDEV_STAT(tx_errors),
60 I40E_NETDEV_STAT(rx_dropped),
61 I40E_NETDEV_STAT(tx_dropped),
62 I40E_NETDEV_STAT(collisions),
63 I40E_NETDEV_STAT(rx_length_errors),
64 I40E_NETDEV_STAT(rx_crc_errors),
67 static const struct i40e_stats i40e_gstrings_veb_stats[] = {
68 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
69 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
70 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
71 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
72 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
73 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
74 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
75 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
76 I40E_VEB_STAT("rx_discards", stats.rx_discards),
77 I40E_VEB_STAT("tx_discards", stats.tx_discards),
78 I40E_VEB_STAT("tx_errors", stats.tx_errors),
79 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
82 static const struct i40e_stats i40e_gstrings_misc_stats[] = {
83 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
84 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
85 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
86 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
87 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
88 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
89 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
90 I40E_VSI_STAT("tx_linearize", tx_linearize),
91 I40E_VSI_STAT("tx_force_wb", tx_force_wb),
92 I40E_VSI_STAT("tx_lost_interrupt", tx_lost_interrupt),
93 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
94 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
97 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
98 * but they are separate. This device supports Virtualization, and
99 * as such might have several netdevs supporting VMDq and FCoE going
100 * through a single port. The NETDEV_STATs are for individual netdevs
101 * seen at the top of the stack, and the PF_STATs are for the physical
102 * function at the bottom of the stack hosting those netdevs.
104 * The PF_STATs are appended to the netdev stats only when ethtool -S
105 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
107 static struct i40e_stats i40e_gstrings_stats[] = {
108 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
109 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
110 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
111 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
112 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
113 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
114 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
115 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
116 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
117 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
118 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
119 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
120 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
121 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
122 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
123 I40E_PF_STAT("tx_timeout", tx_timeout_count),
124 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
125 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
126 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
127 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
128 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
129 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
130 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
131 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
132 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
133 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
134 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
135 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
136 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
137 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
138 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
139 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
140 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
141 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
142 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
143 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
144 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
145 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
146 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
147 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
148 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
149 I40E_PF_STAT("arq_overflows", arq_overflows),
150 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
151 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
152 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
153 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
154 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
155 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
156 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
159 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
160 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
161 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
162 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
166 static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
167 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
168 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
169 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
170 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
171 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
172 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
173 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
174 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
177 #endif /* I40E_FCOE */
178 #define I40E_QUEUE_STATS_LEN(n) \
179 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
180 * 2 /* Tx and Rx together */ \
181 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
182 #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
183 #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
184 #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
186 #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
187 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
188 I40E_FCOE_STATS_LEN + \
189 I40E_MISC_STATS_LEN + \
190 I40E_QUEUE_STATS_LEN((n)))
192 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
193 I40E_MISC_STATS_LEN + \
194 I40E_QUEUE_STATS_LEN((n)))
195 #endif /* I40E_FCOE */
196 #define I40E_PFC_STATS_LEN ( \
197 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
200 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
201 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
203 #define I40E_VEB_TC_STATS_LEN ( \
204 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
206 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
207 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
209 #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
210 #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
211 #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
212 I40E_PFC_STATS_LEN + \
213 I40E_VSI_STATS_LEN((n)))
215 enum i40e_ethtool_test_id {
216 I40E_ETH_TEST_REG = 0,
217 I40E_ETH_TEST_EEPROM,
219 I40E_ETH_TEST_LOOPBACK,
223 static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
224 "Register test (offline)",
225 "Eeprom test (offline)",
226 "Interrupt test (offline)",
227 "Loopback test (offline)",
228 "Link test (on/offline)"
231 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
233 static const char i40e_priv_flags_strings_gl[][ETH_GSTRING_LEN] = {
239 "vf-true-promisc-support",
242 #define I40E_PRIV_FLAGS_GL_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings_gl)
244 static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
252 #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
255 * i40e_partition_setting_complaint - generic complaint for MFP restriction
258 static void i40e_partition_setting_complaint(struct i40e_pf *pf)
260 dev_info(&pf->pdev->dev,
261 "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");
265 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
266 * @phy_types: PHY types to convert
267 * @supported: pointer to the ethtool supported variable to fill in
268 * @advertising: pointer to the ethtool advertising variable to fill in
271 static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
274 enum i40e_aq_capabilities_phy_type phy_types = pf->hw.phy.phy_types;
279 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
280 *supported |= SUPPORTED_Autoneg |
281 SUPPORTED_1000baseT_Full;
282 *advertising |= ADVERTISED_Autoneg |
283 ADVERTISED_1000baseT_Full;
284 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
285 *supported |= SUPPORTED_100baseT_Full;
286 *advertising |= ADVERTISED_100baseT_Full;
289 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
290 phy_types & I40E_CAP_PHY_TYPE_XFI ||
291 phy_types & I40E_CAP_PHY_TYPE_SFI ||
292 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
293 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
294 *supported |= SUPPORTED_10000baseT_Full;
295 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
296 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
297 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
298 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
299 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
300 *supported |= SUPPORTED_Autoneg |
301 SUPPORTED_10000baseT_Full;
302 *advertising |= ADVERTISED_Autoneg |
303 ADVERTISED_10000baseT_Full;
305 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
306 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
307 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
308 *supported |= SUPPORTED_40000baseCR4_Full;
309 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
310 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
311 *supported |= SUPPORTED_Autoneg |
312 SUPPORTED_40000baseCR4_Full;
313 *advertising |= ADVERTISED_Autoneg |
314 ADVERTISED_40000baseCR4_Full;
316 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
317 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
318 *supported |= SUPPORTED_Autoneg |
319 SUPPORTED_100baseT_Full;
320 *advertising |= ADVERTISED_Autoneg |
321 ADVERTISED_100baseT_Full;
323 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
324 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
325 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
326 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
327 *supported |= SUPPORTED_Autoneg |
328 SUPPORTED_1000baseT_Full;
329 *advertising |= ADVERTISED_Autoneg |
330 ADVERTISED_1000baseT_Full;
332 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
333 *supported |= SUPPORTED_40000baseSR4_Full;
334 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
335 *supported |= SUPPORTED_40000baseLR4_Full;
336 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
337 *supported |= SUPPORTED_40000baseKR4_Full |
339 *advertising |= ADVERTISED_40000baseKR4_Full |
342 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
343 *supported |= SUPPORTED_20000baseKR2_Full |
345 *advertising |= ADVERTISED_20000baseKR2_Full |
348 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
349 *supported |= SUPPORTED_10000baseKR_Full |
351 *advertising |= ADVERTISED_10000baseKR_Full |
354 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
355 *supported |= SUPPORTED_10000baseKX4_Full |
357 *advertising |= ADVERTISED_10000baseKX4_Full |
360 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
361 *supported |= SUPPORTED_1000baseKX_Full |
363 *advertising |= ADVERTISED_1000baseKX_Full |
369 * i40e_get_settings_link_up - Get the Link settings for when link is up
371 * @ecmd: ethtool command to fill in
372 * @netdev: network interface device structure
375 static void i40e_get_settings_link_up(struct i40e_hw *hw,
376 struct ethtool_cmd *ecmd,
377 struct net_device *netdev,
380 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
381 u32 link_speed = hw_link_info->link_speed;
382 u32 e_advertising = 0x0;
383 u32 e_supported = 0x0;
385 /* Initialize supported and advertised settings based on phy settings */
386 switch (hw_link_info->phy_type) {
387 case I40E_PHY_TYPE_40GBASE_CR4:
388 case I40E_PHY_TYPE_40GBASE_CR4_CU:
389 ecmd->supported = SUPPORTED_Autoneg |
390 SUPPORTED_40000baseCR4_Full;
391 ecmd->advertising = ADVERTISED_Autoneg |
392 ADVERTISED_40000baseCR4_Full;
394 case I40E_PHY_TYPE_XLAUI:
395 case I40E_PHY_TYPE_XLPPI:
396 case I40E_PHY_TYPE_40GBASE_AOC:
397 ecmd->supported = SUPPORTED_40000baseCR4_Full;
399 case I40E_PHY_TYPE_40GBASE_SR4:
400 ecmd->supported = SUPPORTED_40000baseSR4_Full;
402 case I40E_PHY_TYPE_40GBASE_LR4:
403 ecmd->supported = SUPPORTED_40000baseLR4_Full;
405 case I40E_PHY_TYPE_10GBASE_SR:
406 case I40E_PHY_TYPE_10GBASE_LR:
407 case I40E_PHY_TYPE_1000BASE_SX:
408 case I40E_PHY_TYPE_1000BASE_LX:
409 ecmd->supported = SUPPORTED_10000baseT_Full;
410 if (hw_link_info->module_type[2] &
411 I40E_MODULE_TYPE_1000BASE_SX ||
412 hw_link_info->module_type[2] &
413 I40E_MODULE_TYPE_1000BASE_LX) {
414 ecmd->supported |= SUPPORTED_1000baseT_Full;
415 if (hw_link_info->requested_speeds &
417 ecmd->advertising |= ADVERTISED_1000baseT_Full;
419 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
420 ecmd->advertising |= ADVERTISED_10000baseT_Full;
422 case I40E_PHY_TYPE_10GBASE_T:
423 case I40E_PHY_TYPE_1000BASE_T:
424 case I40E_PHY_TYPE_100BASE_TX:
425 ecmd->supported = SUPPORTED_Autoneg |
426 SUPPORTED_10000baseT_Full |
427 SUPPORTED_1000baseT_Full |
428 SUPPORTED_100baseT_Full;
429 ecmd->advertising = ADVERTISED_Autoneg;
430 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
431 ecmd->advertising |= ADVERTISED_10000baseT_Full;
432 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
433 ecmd->advertising |= ADVERTISED_1000baseT_Full;
434 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
435 ecmd->advertising |= ADVERTISED_100baseT_Full;
437 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
438 ecmd->supported = SUPPORTED_Autoneg |
439 SUPPORTED_1000baseT_Full;
440 ecmd->advertising = ADVERTISED_Autoneg |
441 ADVERTISED_1000baseT_Full;
443 case I40E_PHY_TYPE_10GBASE_CR1_CU:
444 case I40E_PHY_TYPE_10GBASE_CR1:
445 ecmd->supported = SUPPORTED_Autoneg |
446 SUPPORTED_10000baseT_Full;
447 ecmd->advertising = ADVERTISED_Autoneg |
448 ADVERTISED_10000baseT_Full;
450 case I40E_PHY_TYPE_XAUI:
451 case I40E_PHY_TYPE_XFI:
452 case I40E_PHY_TYPE_SFI:
453 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
454 case I40E_PHY_TYPE_10GBASE_AOC:
455 ecmd->supported = SUPPORTED_10000baseT_Full;
457 case I40E_PHY_TYPE_SGMII:
458 ecmd->supported = SUPPORTED_Autoneg |
459 SUPPORTED_1000baseT_Full;
460 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
461 ecmd->advertising |= ADVERTISED_1000baseT_Full;
462 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
463 ecmd->supported |= SUPPORTED_100baseT_Full;
464 if (hw_link_info->requested_speeds &
465 I40E_LINK_SPEED_100MB)
466 ecmd->advertising |= ADVERTISED_100baseT_Full;
469 case I40E_PHY_TYPE_40GBASE_KR4:
470 case I40E_PHY_TYPE_20GBASE_KR2:
471 case I40E_PHY_TYPE_10GBASE_KR:
472 case I40E_PHY_TYPE_10GBASE_KX4:
473 case I40E_PHY_TYPE_1000BASE_KX:
474 ecmd->supported |= SUPPORTED_40000baseKR4_Full |
475 SUPPORTED_20000baseKR2_Full |
476 SUPPORTED_10000baseKR_Full |
477 SUPPORTED_10000baseKX4_Full |
478 SUPPORTED_1000baseKX_Full |
480 ecmd->advertising |= ADVERTISED_40000baseKR4_Full |
481 ADVERTISED_20000baseKR2_Full |
482 ADVERTISED_10000baseKR_Full |
483 ADVERTISED_10000baseKX4_Full |
484 ADVERTISED_1000baseKX_Full |
488 /* if we got here and link is up something bad is afoot */
489 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
490 hw_link_info->phy_type);
493 /* Now that we've worked out everything that could be supported by the
494 * current PHY type, get what is supported by the NVM and them to
495 * get what is truly supported
497 i40e_phy_type_to_ethtool(pf, &e_supported,
500 ecmd->supported = ecmd->supported & e_supported;
501 ecmd->advertising = ecmd->advertising & e_advertising;
503 /* Set speed and duplex */
504 switch (link_speed) {
505 case I40E_LINK_SPEED_40GB:
506 ethtool_cmd_speed_set(ecmd, SPEED_40000);
508 case I40E_LINK_SPEED_20GB:
509 ethtool_cmd_speed_set(ecmd, SPEED_20000);
511 case I40E_LINK_SPEED_10GB:
512 ethtool_cmd_speed_set(ecmd, SPEED_10000);
514 case I40E_LINK_SPEED_1GB:
515 ethtool_cmd_speed_set(ecmd, SPEED_1000);
517 case I40E_LINK_SPEED_100MB:
518 ethtool_cmd_speed_set(ecmd, SPEED_100);
523 ecmd->duplex = DUPLEX_FULL;
527 * i40e_get_settings_link_down - Get the Link settings for when link is down
529 * @ecmd: ethtool command to fill in
531 * Reports link settings that can be determined when link is down
533 static void i40e_get_settings_link_down(struct i40e_hw *hw,
534 struct ethtool_cmd *ecmd,
537 /* link is down and the driver needs to fall back on
538 * supported phy types to figure out what info to display
540 i40e_phy_type_to_ethtool(pf, &ecmd->supported,
543 /* With no link speed and duplex are unknown */
544 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
545 ecmd->duplex = DUPLEX_UNKNOWN;
549 * i40e_get_settings - Get Link Speed and Duplex settings
550 * @netdev: network interface device structure
551 * @ecmd: ethtool command
553 * Reports speed/duplex settings based on media_type
555 static int i40e_get_settings(struct net_device *netdev,
556 struct ethtool_cmd *ecmd)
558 struct i40e_netdev_priv *np = netdev_priv(netdev);
559 struct i40e_pf *pf = np->vsi->back;
560 struct i40e_hw *hw = &pf->hw;
561 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
562 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
565 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
567 i40e_get_settings_link_down(hw, ecmd, pf);
569 /* Now set the settings that don't rely on link being up/down */
570 /* Set autoneg settings */
571 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
572 AUTONEG_ENABLE : AUTONEG_DISABLE);
574 switch (hw->phy.media_type) {
575 case I40E_MEDIA_TYPE_BACKPLANE:
576 ecmd->supported |= SUPPORTED_Autoneg |
578 ecmd->advertising |= ADVERTISED_Autoneg |
579 ADVERTISED_Backplane;
580 ecmd->port = PORT_NONE;
582 case I40E_MEDIA_TYPE_BASET:
583 ecmd->supported |= SUPPORTED_TP;
584 ecmd->advertising |= ADVERTISED_TP;
585 ecmd->port = PORT_TP;
587 case I40E_MEDIA_TYPE_DA:
588 case I40E_MEDIA_TYPE_CX4:
589 ecmd->supported |= SUPPORTED_FIBRE;
590 ecmd->advertising |= ADVERTISED_FIBRE;
591 ecmd->port = PORT_DA;
593 case I40E_MEDIA_TYPE_FIBER:
594 ecmd->supported |= SUPPORTED_FIBRE;
595 ecmd->port = PORT_FIBRE;
597 case I40E_MEDIA_TYPE_UNKNOWN:
599 ecmd->port = PORT_OTHER;
603 /* Set transceiver */
604 ecmd->transceiver = XCVR_EXTERNAL;
606 /* Set flow control settings */
607 ecmd->supported |= SUPPORTED_Pause;
609 switch (hw->fc.requested_mode) {
611 ecmd->advertising |= ADVERTISED_Pause;
613 case I40E_FC_TX_PAUSE:
614 ecmd->advertising |= ADVERTISED_Asym_Pause;
616 case I40E_FC_RX_PAUSE:
617 ecmd->advertising |= (ADVERTISED_Pause |
618 ADVERTISED_Asym_Pause);
621 ecmd->advertising &= ~(ADVERTISED_Pause |
622 ADVERTISED_Asym_Pause);
630 * i40e_set_settings - Set Speed and Duplex
631 * @netdev: network interface device structure
632 * @ecmd: ethtool command
634 * Set speed/duplex per media_types advertised/forced
636 static int i40e_set_settings(struct net_device *netdev,
637 struct ethtool_cmd *ecmd)
639 struct i40e_netdev_priv *np = netdev_priv(netdev);
640 struct i40e_aq_get_phy_abilities_resp abilities;
641 struct i40e_aq_set_phy_config config;
642 struct i40e_pf *pf = np->vsi->back;
643 struct i40e_vsi *vsi = np->vsi;
644 struct i40e_hw *hw = &pf->hw;
645 struct ethtool_cmd safe_ecmd;
646 i40e_status status = 0;
652 /* Changing port settings is not supported if this isn't the
653 * port's controlling PF
655 if (hw->partition_id != 1) {
656 i40e_partition_setting_complaint(pf);
660 if (vsi != pf->vsi[pf->lan_vsi])
663 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
664 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
665 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
666 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
669 if (hw->device_id == I40E_DEV_ID_KX_B ||
670 hw->device_id == I40E_DEV_ID_KX_C ||
671 hw->device_id == I40E_DEV_ID_20G_KR2 ||
672 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
673 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
677 /* get our own copy of the bits to check against */
678 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
679 i40e_get_settings(netdev, &safe_ecmd);
681 /* save autoneg and speed out of ecmd */
682 autoneg = ecmd->autoneg;
683 advertise = ecmd->advertising;
685 /* set autoneg and speed back to what they currently are */
686 ecmd->autoneg = safe_ecmd.autoneg;
687 ecmd->advertising = safe_ecmd.advertising;
689 ecmd->cmd = safe_ecmd.cmd;
690 /* If ecmd and safe_ecmd are not the same now, then they are
691 * trying to set something that we do not support
693 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
696 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
697 usleep_range(1000, 2000);
699 /* Get the current phy config */
700 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
705 /* Copy abilities to config in case autoneg is not
708 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
709 config.abilities = abilities.abilities;
712 if (autoneg == AUTONEG_ENABLE) {
713 /* If autoneg was not already enabled */
714 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
715 /* If autoneg is not supported, return error */
716 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
717 netdev_info(netdev, "Autoneg not supported on this phy\n");
720 /* Autoneg is allowed to change */
721 config.abilities = abilities.abilities |
722 I40E_AQ_PHY_ENABLE_AN;
726 /* If autoneg is currently enabled */
727 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
728 /* If autoneg is supported 10GBASE_T is the only PHY
729 * that can disable it, so otherwise return error
731 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
732 hw->phy.link_info.phy_type !=
733 I40E_PHY_TYPE_10GBASE_T) {
734 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
737 /* Autoneg is allowed to change */
738 config.abilities = abilities.abilities &
739 ~I40E_AQ_PHY_ENABLE_AN;
744 if (advertise & ~safe_ecmd.supported)
747 if (advertise & ADVERTISED_100baseT_Full)
748 config.link_speed |= I40E_LINK_SPEED_100MB;
749 if (advertise & ADVERTISED_1000baseT_Full ||
750 advertise & ADVERTISED_1000baseKX_Full)
751 config.link_speed |= I40E_LINK_SPEED_1GB;
752 if (advertise & ADVERTISED_10000baseT_Full ||
753 advertise & ADVERTISED_10000baseKX4_Full ||
754 advertise & ADVERTISED_10000baseKR_Full)
755 config.link_speed |= I40E_LINK_SPEED_10GB;
756 if (advertise & ADVERTISED_20000baseKR2_Full)
757 config.link_speed |= I40E_LINK_SPEED_20GB;
758 if (advertise & ADVERTISED_40000baseKR4_Full ||
759 advertise & ADVERTISED_40000baseCR4_Full ||
760 advertise & ADVERTISED_40000baseSR4_Full ||
761 advertise & ADVERTISED_40000baseLR4_Full)
762 config.link_speed |= I40E_LINK_SPEED_40GB;
764 /* If speed didn't get set, set it to what it currently is.
765 * This is needed because if advertise is 0 (as it is when autoneg
766 * is disabled) then speed won't get set.
768 if (!config.link_speed)
769 config.link_speed = abilities.link_speed;
771 if (change || (abilities.link_speed != config.link_speed)) {
772 /* copy over the rest of the abilities */
773 config.phy_type = abilities.phy_type;
774 config.eee_capability = abilities.eee_capability;
775 config.eeer = abilities.eeer_val;
776 config.low_power_ctrl = abilities.d3_lpan;
778 /* save the requested speeds */
779 hw->phy.link_info.requested_speeds = config.link_speed;
780 /* set link and auto negotiation so changes take effect */
781 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
782 /* If link is up put link down */
783 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
784 /* Tell the OS link is going down, the link will go
785 * back up when fw says it is ready asynchronously
787 i40e_print_link_message(vsi, false);
788 netif_carrier_off(netdev);
789 netif_tx_stop_all_queues(netdev);
792 /* make the aq call */
793 status = i40e_aq_set_phy_config(hw, &config, NULL);
795 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
796 i40e_stat_str(hw, status),
797 i40e_aq_str(hw, hw->aq.asq_last_status));
801 status = i40e_update_link_info(hw);
803 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
804 i40e_stat_str(hw, status),
805 i40e_aq_str(hw, hw->aq.asq_last_status));
808 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
814 static int i40e_nway_reset(struct net_device *netdev)
816 /* restart autonegotiation */
817 struct i40e_netdev_priv *np = netdev_priv(netdev);
818 struct i40e_pf *pf = np->vsi->back;
819 struct i40e_hw *hw = &pf->hw;
820 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
823 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
825 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
826 i40e_stat_str(hw, ret),
827 i40e_aq_str(hw, hw->aq.asq_last_status));
835 * i40e_get_pauseparam - Get Flow Control status
836 * Return tx/rx-pause status
838 static void i40e_get_pauseparam(struct net_device *netdev,
839 struct ethtool_pauseparam *pause)
841 struct i40e_netdev_priv *np = netdev_priv(netdev);
842 struct i40e_pf *pf = np->vsi->back;
843 struct i40e_hw *hw = &pf->hw;
844 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
845 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
848 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
849 AUTONEG_ENABLE : AUTONEG_DISABLE);
851 /* PFC enabled so report LFC as off */
852 if (dcbx_cfg->pfc.pfcenable) {
858 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
860 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
862 } else if (hw->fc.current_mode == I40E_FC_FULL) {
869 * i40e_set_pauseparam - Set Flow Control parameter
870 * @netdev: network interface device structure
871 * @pause: return tx/rx flow control status
873 static int i40e_set_pauseparam(struct net_device *netdev,
874 struct ethtool_pauseparam *pause)
876 struct i40e_netdev_priv *np = netdev_priv(netdev);
877 struct i40e_pf *pf = np->vsi->back;
878 struct i40e_vsi *vsi = np->vsi;
879 struct i40e_hw *hw = &pf->hw;
880 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
881 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
882 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
887 /* Changing the port's flow control is not supported if this isn't the
888 * port's controlling PF
890 if (hw->partition_id != 1) {
891 i40e_partition_setting_complaint(pf);
895 if (vsi != pf->vsi[pf->lan_vsi])
898 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
899 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
900 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
904 /* If we have link and don't have autoneg */
905 if (!test_bit(__I40E_DOWN, &pf->state) &&
906 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
907 /* Send message that it might not necessarily work*/
908 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
911 if (dcbx_cfg->pfc.pfcenable) {
913 "Priority flow control enabled. Cannot set link flow control.\n");
917 if (pause->rx_pause && pause->tx_pause)
918 hw->fc.requested_mode = I40E_FC_FULL;
919 else if (pause->rx_pause && !pause->tx_pause)
920 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
921 else if (!pause->rx_pause && pause->tx_pause)
922 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
923 else if (!pause->rx_pause && !pause->tx_pause)
924 hw->fc.requested_mode = I40E_FC_NONE;
928 /* Tell the OS link is going down, the link will go back up when fw
929 * says it is ready asynchronously
931 i40e_print_link_message(vsi, false);
932 netif_carrier_off(netdev);
933 netif_tx_stop_all_queues(netdev);
935 /* Set the fc mode and only restart an if link is up*/
936 status = i40e_set_fc(hw, &aq_failures, link_up);
938 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
939 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
940 i40e_stat_str(hw, status),
941 i40e_aq_str(hw, hw->aq.asq_last_status));
944 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
945 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
946 i40e_stat_str(hw, status),
947 i40e_aq_str(hw, hw->aq.asq_last_status));
950 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
951 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
952 i40e_stat_str(hw, status),
953 i40e_aq_str(hw, hw->aq.asq_last_status));
957 if (!test_bit(__I40E_DOWN, &pf->state)) {
958 /* Give it a little more time to try to come back */
960 if (!test_bit(__I40E_DOWN, &pf->state))
961 return i40e_nway_reset(netdev);
967 static u32 i40e_get_msglevel(struct net_device *netdev)
969 struct i40e_netdev_priv *np = netdev_priv(netdev);
970 struct i40e_pf *pf = np->vsi->back;
972 return pf->msg_enable;
975 static void i40e_set_msglevel(struct net_device *netdev, u32 data)
977 struct i40e_netdev_priv *np = netdev_priv(netdev);
978 struct i40e_pf *pf = np->vsi->back;
980 if (I40E_DEBUG_USER & data)
981 pf->hw.debug_mask = data;
982 pf->msg_enable = data;
985 static int i40e_get_regs_len(struct net_device *netdev)
990 for (i = 0; i40e_reg_list[i].offset != 0; i++)
991 reg_count += i40e_reg_list[i].elements;
993 return reg_count * sizeof(u32);
996 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
999 struct i40e_netdev_priv *np = netdev_priv(netdev);
1000 struct i40e_pf *pf = np->vsi->back;
1001 struct i40e_hw *hw = &pf->hw;
1006 /* Tell ethtool which driver-version-specific regs output we have.
1008 * At some point, if we have ethtool doing special formatting of
1009 * this data, it will rely on this version number to know how to
1010 * interpret things. Hence, this needs to be updated if/when the
1011 * diags register table is changed.
1015 /* loop through the diags reg table for what to print */
1017 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1018 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1019 reg = i40e_reg_list[i].offset
1020 + (j * i40e_reg_list[i].stride);
1021 reg_buf[ri++] = rd32(hw, reg);
1027 static int i40e_get_eeprom(struct net_device *netdev,
1028 struct ethtool_eeprom *eeprom, u8 *bytes)
1030 struct i40e_netdev_priv *np = netdev_priv(netdev);
1031 struct i40e_hw *hw = &np->vsi->back->hw;
1032 struct i40e_pf *pf = np->vsi->back;
1033 int ret_val = 0, len, offset;
1039 #define I40E_NVM_SECTOR_SIZE 4096
1040 if (eeprom->len == 0)
1043 /* check for NVMUpdate access method */
1044 magic = hw->vendor_id | (hw->device_id << 16);
1045 if (eeprom->magic && eeprom->magic != magic) {
1046 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1049 /* make sure it is the right magic for NVMUpdate */
1050 if ((eeprom->magic >> 16) != hw->device_id)
1052 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1053 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1056 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1058 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
1059 dev_info(&pf->pdev->dev,
1060 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1061 ret_val, hw->aq.asq_last_status, errno,
1062 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1063 cmd->offset, cmd->data_size);
1068 /* normal ethtool get_eeprom support */
1069 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1071 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
1075 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1077 dev_info(&pf->pdev->dev,
1078 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1079 ret_val, hw->aq.asq_last_status);
1083 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1084 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1085 len = I40E_NVM_SECTOR_SIZE;
1087 for (i = 0; i < sectors; i++) {
1088 if (i == (sectors - 1)) {
1089 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1092 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1093 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
1094 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
1096 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
1097 dev_info(&pf->pdev->dev,
1098 "read NVM failed, invalid offset 0x%x\n",
1101 } else if (ret_val &&
1102 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1103 dev_info(&pf->pdev->dev,
1104 "read NVM failed, access, offset 0x%x\n",
1107 } else if (ret_val) {
1108 dev_info(&pf->pdev->dev,
1109 "read NVM failed offset %d err=%d status=0x%x\n",
1110 offset, ret_val, hw->aq.asq_last_status);
1115 i40e_release_nvm(hw);
1116 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
1122 static int i40e_get_eeprom_len(struct net_device *netdev)
1124 struct i40e_netdev_priv *np = netdev_priv(netdev);
1125 struct i40e_hw *hw = &np->vsi->back->hw;
1128 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1129 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1130 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1131 /* register returns value in power of 2, 64Kbyte chunks. */
1132 val = (64 * 1024) * BIT(val);
1136 static int i40e_set_eeprom(struct net_device *netdev,
1137 struct ethtool_eeprom *eeprom, u8 *bytes)
1139 struct i40e_netdev_priv *np = netdev_priv(netdev);
1140 struct i40e_hw *hw = &np->vsi->back->hw;
1141 struct i40e_pf *pf = np->vsi->back;
1142 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1147 /* normal ethtool set_eeprom is not supported */
1148 magic = hw->vendor_id | (hw->device_id << 16);
1149 if (eeprom->magic == magic)
1150 errno = -EOPNOTSUPP;
1151 /* check for NVMUpdate access method */
1152 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1154 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1155 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1158 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1160 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
1161 dev_info(&pf->pdev->dev,
1162 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1163 ret_val, hw->aq.asq_last_status, errno,
1164 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1165 cmd->offset, cmd->data_size);
1170 static void i40e_get_drvinfo(struct net_device *netdev,
1171 struct ethtool_drvinfo *drvinfo)
1173 struct i40e_netdev_priv *np = netdev_priv(netdev);
1174 struct i40e_vsi *vsi = np->vsi;
1175 struct i40e_pf *pf = vsi->back;
1177 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1178 strlcpy(drvinfo->version, i40e_driver_version_str,
1179 sizeof(drvinfo->version));
1180 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
1181 sizeof(drvinfo->fw_version));
1182 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1183 sizeof(drvinfo->bus_info));
1184 if (pf->hw.pf_id == 0)
1185 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_GL_STR_LEN;
1187 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
1190 static void i40e_get_ringparam(struct net_device *netdev,
1191 struct ethtool_ringparam *ring)
1193 struct i40e_netdev_priv *np = netdev_priv(netdev);
1194 struct i40e_pf *pf = np->vsi->back;
1195 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1197 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1198 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1199 ring->rx_mini_max_pending = 0;
1200 ring->rx_jumbo_max_pending = 0;
1201 ring->rx_pending = vsi->rx_rings[0]->count;
1202 ring->tx_pending = vsi->tx_rings[0]->count;
1203 ring->rx_mini_pending = 0;
1204 ring->rx_jumbo_pending = 0;
1207 static int i40e_set_ringparam(struct net_device *netdev,
1208 struct ethtool_ringparam *ring)
1210 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1211 struct i40e_netdev_priv *np = netdev_priv(netdev);
1212 struct i40e_vsi *vsi = np->vsi;
1213 struct i40e_pf *pf = vsi->back;
1214 u32 new_rx_count, new_tx_count;
1217 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1220 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1221 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1222 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1223 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1225 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1226 ring->tx_pending, ring->rx_pending,
1227 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1231 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1232 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1234 /* if nothing to do return success */
1235 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1236 (new_rx_count == vsi->rx_rings[0]->count))
1239 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1240 usleep_range(1000, 2000);
1242 if (!netif_running(vsi->netdev)) {
1243 /* simple case - set for the next time the netdev is started */
1244 for (i = 0; i < vsi->num_queue_pairs; i++) {
1245 vsi->tx_rings[i]->count = new_tx_count;
1246 vsi->rx_rings[i]->count = new_rx_count;
1251 /* We can't just free everything and then setup again,
1252 * because the ISRs in MSI-X mode get passed pointers
1253 * to the Tx and Rx ring structs.
1256 /* alloc updated Tx resources */
1257 if (new_tx_count != vsi->tx_rings[0]->count) {
1259 "Changing Tx descriptor count from %d to %d.\n",
1260 vsi->tx_rings[0]->count, new_tx_count);
1261 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1262 sizeof(struct i40e_ring), GFP_KERNEL);
1268 for (i = 0; i < vsi->num_queue_pairs; i++) {
1269 /* clone ring and setup updated count */
1270 tx_rings[i] = *vsi->tx_rings[i];
1271 tx_rings[i].count = new_tx_count;
1272 /* the desc and bi pointers will be reallocated in the
1275 tx_rings[i].desc = NULL;
1276 tx_rings[i].rx_bi = NULL;
1277 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1281 i40e_free_tx_resources(&tx_rings[i]);
1291 /* alloc updated Rx resources */
1292 if (new_rx_count != vsi->rx_rings[0]->count) {
1294 "Changing Rx descriptor count from %d to %d\n",
1295 vsi->rx_rings[0]->count, new_rx_count);
1296 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1297 sizeof(struct i40e_ring), GFP_KERNEL);
1303 for (i = 0; i < vsi->num_queue_pairs; i++) {
1304 /* this is to allow wr32 to have something to write to
1305 * during early allocation of Rx buffers
1307 u32 __iomem faketail = 0;
1308 struct i40e_ring *ring;
1311 /* clone ring and setup updated count */
1312 rx_rings[i] = *vsi->rx_rings[i];
1313 rx_rings[i].count = new_rx_count;
1314 /* the desc and bi pointers will be reallocated in the
1317 rx_rings[i].desc = NULL;
1318 rx_rings[i].rx_bi = NULL;
1319 rx_rings[i].tail = (u8 __iomem *)&faketail;
1320 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1324 /* now allocate the Rx buffers to make sure the OS
1325 * has enough memory, any failure here means abort
1327 ring = &rx_rings[i];
1328 unused = I40E_DESC_UNUSED(ring);
1329 err = i40e_alloc_rx_buffers(ring, unused);
1333 i40e_free_rx_resources(&rx_rings[i]);
1343 /* Bring interface down, copy in the new ring info,
1344 * then restore the interface
1349 for (i = 0; i < vsi->num_queue_pairs; i++) {
1350 i40e_free_tx_resources(vsi->tx_rings[i]);
1351 *vsi->tx_rings[i] = tx_rings[i];
1358 for (i = 0; i < vsi->num_queue_pairs; i++) {
1359 i40e_free_rx_resources(vsi->rx_rings[i]);
1360 /* get the real tail offset */
1361 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1362 /* this is to fake out the allocation routine
1363 * into thinking it has to realloc everything
1364 * but the recycling logic will let us re-use
1365 * the buffers allocated above
1367 rx_rings[i].next_to_use = 0;
1368 rx_rings[i].next_to_clean = 0;
1369 rx_rings[i].next_to_alloc = 0;
1370 /* do a struct copy */
1371 *vsi->rx_rings[i] = rx_rings[i];
1380 /* error cleanup if the Rx allocations failed after getting Tx */
1382 for (i = 0; i < vsi->num_queue_pairs; i++)
1383 i40e_free_tx_resources(&tx_rings[i]);
1389 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1394 static int i40e_get_sset_count(struct net_device *netdev, int sset)
1396 struct i40e_netdev_priv *np = netdev_priv(netdev);
1397 struct i40e_vsi *vsi = np->vsi;
1398 struct i40e_pf *pf = vsi->back;
1402 return I40E_TEST_LEN;
1404 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
1405 int len = I40E_PF_STATS_LEN(netdev);
1407 if ((pf->lan_veb != I40E_NO_VEB) &&
1408 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
1409 len += I40E_VEB_STATS_TOTAL;
1412 return I40E_VSI_STATS_LEN(netdev);
1414 case ETH_SS_PRIV_FLAGS:
1415 if (pf->hw.pf_id == 0)
1416 return I40E_PRIV_FLAGS_GL_STR_LEN;
1418 return I40E_PRIV_FLAGS_STR_LEN;
1424 static void i40e_get_ethtool_stats(struct net_device *netdev,
1425 struct ethtool_stats *stats, u64 *data)
1427 struct i40e_netdev_priv *np = netdev_priv(netdev);
1428 struct i40e_ring *tx_ring, *rx_ring;
1429 struct i40e_vsi *vsi = np->vsi;
1430 struct i40e_pf *pf = vsi->back;
1434 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
1437 i40e_update_stats(vsi);
1439 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1440 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1441 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1442 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1444 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1445 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1446 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1447 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1450 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1451 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1452 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1453 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1457 for (j = 0; j < vsi->num_queue_pairs; j++) {
1458 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
1463 /* process Tx ring statistics */
1465 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
1466 data[i] = tx_ring->stats.packets;
1467 data[i + 1] = tx_ring->stats.bytes;
1468 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
1471 /* Rx ring is the 2nd half of the queue pair */
1472 rx_ring = &tx_ring[1];
1474 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
1475 data[i] = rx_ring->stats.packets;
1476 data[i + 1] = rx_ring->stats.bytes;
1477 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
1481 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1484 if ((pf->lan_veb != I40E_NO_VEB) &&
1485 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
1486 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1488 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1490 p += i40e_gstrings_veb_stats[j].stat_offset;
1491 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1492 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1494 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1495 data[i++] = veb->tc_stats.tc_tx_packets[j];
1496 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1497 data[i++] = veb->tc_stats.tc_rx_packets[j];
1498 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1501 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1502 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1503 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1504 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1506 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1507 data[i++] = pf->stats.priority_xon_tx[j];
1508 data[i++] = pf->stats.priority_xoff_tx[j];
1510 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1511 data[i++] = pf->stats.priority_xon_rx[j];
1512 data[i++] = pf->stats.priority_xoff_rx[j];
1514 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1515 data[i++] = pf->stats.priority_xon_2_xoff[j];
1518 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1521 struct i40e_netdev_priv *np = netdev_priv(netdev);
1522 struct i40e_vsi *vsi = np->vsi;
1523 struct i40e_pf *pf = vsi->back;
1524 char *p = (char *)data;
1527 switch (stringset) {
1529 for (i = 0; i < I40E_TEST_LEN; i++) {
1530 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1531 data += ETH_GSTRING_LEN;
1535 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1536 snprintf(p, ETH_GSTRING_LEN, "%s",
1537 i40e_gstrings_net_stats[i].stat_string);
1538 p += ETH_GSTRING_LEN;
1540 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1541 snprintf(p, ETH_GSTRING_LEN, "%s",
1542 i40e_gstrings_misc_stats[i].stat_string);
1543 p += ETH_GSTRING_LEN;
1546 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1547 snprintf(p, ETH_GSTRING_LEN, "%s",
1548 i40e_gstrings_fcoe_stats[i].stat_string);
1549 p += ETH_GSTRING_LEN;
1552 for (i = 0; i < vsi->num_queue_pairs; i++) {
1553 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1554 p += ETH_GSTRING_LEN;
1555 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1556 p += ETH_GSTRING_LEN;
1557 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1558 p += ETH_GSTRING_LEN;
1559 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1560 p += ETH_GSTRING_LEN;
1562 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1565 if ((pf->lan_veb != I40E_NO_VEB) &&
1566 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
1567 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1568 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1569 i40e_gstrings_veb_stats[i].stat_string);
1570 p += ETH_GSTRING_LEN;
1572 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1573 snprintf(p, ETH_GSTRING_LEN,
1574 "veb.tc_%u_tx_packets", i);
1575 p += ETH_GSTRING_LEN;
1576 snprintf(p, ETH_GSTRING_LEN,
1577 "veb.tc_%u_tx_bytes", i);
1578 p += ETH_GSTRING_LEN;
1579 snprintf(p, ETH_GSTRING_LEN,
1580 "veb.tc_%u_rx_packets", i);
1581 p += ETH_GSTRING_LEN;
1582 snprintf(p, ETH_GSTRING_LEN,
1583 "veb.tc_%u_rx_bytes", i);
1584 p += ETH_GSTRING_LEN;
1587 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1588 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1589 i40e_gstrings_stats[i].stat_string);
1590 p += ETH_GSTRING_LEN;
1592 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1593 snprintf(p, ETH_GSTRING_LEN,
1594 "port.tx_priority_%u_xon", i);
1595 p += ETH_GSTRING_LEN;
1596 snprintf(p, ETH_GSTRING_LEN,
1597 "port.tx_priority_%u_xoff", i);
1598 p += ETH_GSTRING_LEN;
1600 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1601 snprintf(p, ETH_GSTRING_LEN,
1602 "port.rx_priority_%u_xon", i);
1603 p += ETH_GSTRING_LEN;
1604 snprintf(p, ETH_GSTRING_LEN,
1605 "port.rx_priority_%u_xoff", i);
1606 p += ETH_GSTRING_LEN;
1608 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1609 snprintf(p, ETH_GSTRING_LEN,
1610 "port.rx_priority_%u_xon_2_xoff", i);
1611 p += ETH_GSTRING_LEN;
1613 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1615 case ETH_SS_PRIV_FLAGS:
1616 if (pf->hw.pf_id == 0) {
1617 for (i = 0; i < I40E_PRIV_FLAGS_GL_STR_LEN; i++) {
1618 memcpy(data, i40e_priv_flags_strings_gl[i],
1620 data += ETH_GSTRING_LEN;
1623 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1624 memcpy(data, i40e_priv_flags_strings[i],
1626 data += ETH_GSTRING_LEN;
1635 static int i40e_get_ts_info(struct net_device *dev,
1636 struct ethtool_ts_info *info)
1638 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1640 /* only report HW timestamping if PTP is enabled */
1641 if (!(pf->flags & I40E_FLAG_PTP))
1642 return ethtool_op_get_ts_info(dev, info);
1644 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1645 SOF_TIMESTAMPING_RX_SOFTWARE |
1646 SOF_TIMESTAMPING_SOFTWARE |
1647 SOF_TIMESTAMPING_TX_HARDWARE |
1648 SOF_TIMESTAMPING_RX_HARDWARE |
1649 SOF_TIMESTAMPING_RAW_HARDWARE;
1652 info->phc_index = ptp_clock_index(pf->ptp_clock);
1654 info->phc_index = -1;
1656 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
1658 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1659 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1660 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
1665 static int i40e_link_test(struct net_device *netdev, u64 *data)
1667 struct i40e_netdev_priv *np = netdev_priv(netdev);
1668 struct i40e_pf *pf = np->vsi->back;
1670 bool link_up = false;
1672 netif_info(pf, hw, netdev, "link test\n");
1673 status = i40e_get_link_status(&pf->hw, &link_up);
1675 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1688 static int i40e_reg_test(struct net_device *netdev, u64 *data)
1690 struct i40e_netdev_priv *np = netdev_priv(netdev);
1691 struct i40e_pf *pf = np->vsi->back;
1693 netif_info(pf, hw, netdev, "register test\n");
1694 *data = i40e_diag_reg_test(&pf->hw);
1699 static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
1701 struct i40e_netdev_priv *np = netdev_priv(netdev);
1702 struct i40e_pf *pf = np->vsi->back;
1704 netif_info(pf, hw, netdev, "eeprom test\n");
1705 *data = i40e_diag_eeprom_test(&pf->hw);
1707 /* forcebly clear the NVM Update state machine */
1708 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1713 static int i40e_intr_test(struct net_device *netdev, u64 *data)
1715 struct i40e_netdev_priv *np = netdev_priv(netdev);
1716 struct i40e_pf *pf = np->vsi->back;
1717 u16 swc_old = pf->sw_int_count;
1719 netif_info(pf, hw, netdev, "interrupt test\n");
1720 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1721 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1722 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1723 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1724 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1725 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
1726 usleep_range(1000, 2000);
1727 *data = (swc_old == pf->sw_int_count);
1732 static int i40e_loopback_test(struct net_device *netdev, u64 *data)
1734 struct i40e_netdev_priv *np = netdev_priv(netdev);
1735 struct i40e_pf *pf = np->vsi->back;
1737 netif_info(pf, hw, netdev, "loopback test not implemented\n");
1743 static inline bool i40e_active_vfs(struct i40e_pf *pf)
1745 struct i40e_vf *vfs = pf->vf;
1748 for (i = 0; i < pf->num_alloc_vfs; i++)
1749 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
1754 static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1756 struct i40e_vsi **vsi = pf->vsi;
1759 for (i = 0; i < pf->num_alloc_vsi; i++) {
1762 if (vsi[i]->type == I40E_VSI_VMDQ2)
1769 static void i40e_diag_test(struct net_device *netdev,
1770 struct ethtool_test *eth_test, u64 *data)
1772 struct i40e_netdev_priv *np = netdev_priv(netdev);
1773 bool if_running = netif_running(netdev);
1774 struct i40e_pf *pf = np->vsi->back;
1776 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1778 netif_info(pf, drv, netdev, "offline testing starting\n");
1780 set_bit(__I40E_TESTING, &pf->state);
1782 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
1783 dev_warn(&pf->pdev->dev,
1784 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
1785 data[I40E_ETH_TEST_REG] = 1;
1786 data[I40E_ETH_TEST_EEPROM] = 1;
1787 data[I40E_ETH_TEST_INTR] = 1;
1788 data[I40E_ETH_TEST_LOOPBACK] = 1;
1789 data[I40E_ETH_TEST_LINK] = 1;
1790 eth_test->flags |= ETH_TEST_FL_FAILED;
1791 clear_bit(__I40E_TESTING, &pf->state);
1795 /* If the device is online then take it offline */
1797 /* indicate we're in test mode */
1800 /* This reset does not affect link - if it is
1801 * changed to a type of reset that does affect
1802 * link then the following link test would have
1803 * to be moved to before the reset
1805 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
1807 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1808 eth_test->flags |= ETH_TEST_FL_FAILED;
1810 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
1811 eth_test->flags |= ETH_TEST_FL_FAILED;
1813 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
1814 eth_test->flags |= ETH_TEST_FL_FAILED;
1816 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
1817 eth_test->flags |= ETH_TEST_FL_FAILED;
1819 /* run reg test last, a reset is required after it */
1820 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1821 eth_test->flags |= ETH_TEST_FL_FAILED;
1823 clear_bit(__I40E_TESTING, &pf->state);
1824 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
1830 netif_info(pf, drv, netdev, "online testing starting\n");
1832 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1833 eth_test->flags |= ETH_TEST_FL_FAILED;
1835 /* Offline only tests, not run in online; pass by default */
1836 data[I40E_ETH_TEST_REG] = 0;
1837 data[I40E_ETH_TEST_EEPROM] = 0;
1838 data[I40E_ETH_TEST_INTR] = 0;
1839 data[I40E_ETH_TEST_LOOPBACK] = 0;
1844 netif_info(pf, drv, netdev, "testing finished\n");
1847 static void i40e_get_wol(struct net_device *netdev,
1848 struct ethtool_wolinfo *wol)
1850 struct i40e_netdev_priv *np = netdev_priv(netdev);
1851 struct i40e_pf *pf = np->vsi->back;
1852 struct i40e_hw *hw = &pf->hw;
1855 /* NVM bit on means WoL disabled for the port */
1856 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1857 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
1861 wol->supported = WAKE_MAGIC;
1862 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1867 * i40e_set_wol - set the WakeOnLAN configuration
1868 * @netdev: the netdev in question
1869 * @wol: the ethtool WoL setting data
1871 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1873 struct i40e_netdev_priv *np = netdev_priv(netdev);
1874 struct i40e_pf *pf = np->vsi->back;
1875 struct i40e_vsi *vsi = np->vsi;
1876 struct i40e_hw *hw = &pf->hw;
1879 /* WoL not supported if this isn't the controlling PF on the port */
1880 if (hw->partition_id != 1) {
1881 i40e_partition_setting_complaint(pf);
1885 if (vsi != pf->vsi[pf->lan_vsi])
1888 /* NVM bit on means WoL disabled for the port */
1889 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1890 if (BIT(hw->port) & wol_nvm_bits)
1893 /* only magic packet is supported */
1894 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1897 /* is this a new value? */
1898 if (pf->wol_en != !!wol->wolopts) {
1899 pf->wol_en = !!wol->wolopts;
1900 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1906 static int i40e_set_phys_id(struct net_device *netdev,
1907 enum ethtool_phys_id_state state)
1909 struct i40e_netdev_priv *np = netdev_priv(netdev);
1910 i40e_status ret = 0;
1911 struct i40e_pf *pf = np->vsi->back;
1912 struct i40e_hw *hw = &pf->hw;
1917 case ETHTOOL_ID_ACTIVE:
1918 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1919 pf->led_status = i40e_led_get(hw);
1921 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
1922 ret = i40e_led_get_phy(hw, &temp_status,
1924 pf->led_status = temp_status;
1928 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1929 i40e_led_set(hw, 0xf, false);
1931 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
1933 case ETHTOOL_ID_OFF:
1934 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1935 i40e_led_set(hw, 0x0, false);
1937 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
1939 case ETHTOOL_ID_INACTIVE:
1940 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1941 i40e_led_set(hw, false, pf->led_status);
1943 ret = i40e_led_set_phy(hw, false, pf->led_status,
1945 I40E_PHY_LED_MODE_ORIG));
1946 i40e_aq_set_phy_debug(hw, 0, NULL);
1958 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1959 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1960 * 125us (8000 interrupts per second) == ITR(62)
1963 static int __i40e_get_coalesce(struct net_device *netdev,
1964 struct ethtool_coalesce *ec,
1967 struct i40e_netdev_priv *np = netdev_priv(netdev);
1968 struct i40e_vsi *vsi = np->vsi;
1970 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1971 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1973 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
1974 * return queue 0's value to represent.
1978 } else if (queue >= vsi->num_queue_pairs) {
1982 if (ITR_IS_DYNAMIC(vsi->rx_rings[queue]->rx_itr_setting))
1983 ec->use_adaptive_rx_coalesce = 1;
1985 if (ITR_IS_DYNAMIC(vsi->tx_rings[queue]->tx_itr_setting))
1986 ec->use_adaptive_tx_coalesce = 1;
1988 ec->rx_coalesce_usecs = vsi->rx_rings[queue]->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1989 ec->tx_coalesce_usecs = vsi->tx_rings[queue]->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1991 /* we use the _usecs_high to store/set the interrupt rate limit
1992 * that the hardware supports, that almost but not quite
1993 * fits the original intent of the ethtool variable,
1994 * the rx_coalesce_usecs_high limits total interrupts
1995 * per second from both tx/rx sources.
1997 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1998 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
2003 static int i40e_get_coalesce(struct net_device *netdev,
2004 struct ethtool_coalesce *ec)
2006 return __i40e_get_coalesce(netdev, ec, -1);
2009 static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2010 struct ethtool_coalesce *ec)
2012 return __i40e_get_coalesce(netdev, ec, queue);
2015 static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2016 struct ethtool_coalesce *ec,
2019 struct i40e_pf *pf = vsi->back;
2020 struct i40e_hw *hw = &pf->hw;
2021 struct i40e_q_vector *q_vector;
2024 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
2026 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2027 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2029 if (ec->use_adaptive_rx_coalesce)
2030 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2032 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2034 if (ec->use_adaptive_tx_coalesce)
2035 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2037 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2039 q_vector = vsi->rx_rings[queue]->q_vector;
2040 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2041 vector = vsi->base_vector + q_vector->v_idx;
2042 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2044 q_vector = vsi->tx_rings[queue]->q_vector;
2045 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2046 vector = vsi->base_vector + q_vector->v_idx;
2047 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2049 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2053 static int __i40e_set_coalesce(struct net_device *netdev,
2054 struct ethtool_coalesce *ec,
2057 struct i40e_netdev_priv *np = netdev_priv(netdev);
2058 struct i40e_vsi *vsi = np->vsi;
2059 struct i40e_pf *pf = vsi->back;
2062 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2063 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2065 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2066 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2067 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2071 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2072 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
2076 if (ec->rx_coalesce_usecs == 0) {
2077 if (ec->use_adaptive_rx_coalesce)
2078 netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
2079 } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2080 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2081 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2085 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
2087 if (ec->tx_coalesce_usecs == 0) {
2088 if (ec->use_adaptive_tx_coalesce)
2089 netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
2090 } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2091 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2092 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2096 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2097 * apply to all queues.
2100 for (i = 0; i < vsi->num_queue_pairs; i++)
2101 i40e_set_itr_per_queue(vsi, ec, i);
2102 } else if (queue < vsi->num_queue_pairs) {
2103 i40e_set_itr_per_queue(vsi, ec, queue);
2105 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2106 vsi->num_queue_pairs - 1);
2113 static int i40e_set_coalesce(struct net_device *netdev,
2114 struct ethtool_coalesce *ec)
2116 return __i40e_set_coalesce(netdev, ec, -1);
2119 static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2120 struct ethtool_coalesce *ec)
2122 return __i40e_set_coalesce(netdev, ec, queue);
2126 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2127 * @pf: pointer to the physical function struct
2128 * @cmd: ethtool rxnfc command
2130 * Returns Success if the flow is supported, else Invalid Input.
2132 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2136 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
2137 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
2138 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
2141 /* Report default options for RSS on i40e */
2142 switch (cmd->flow_type) {
2145 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2146 /* fall through to add IP fields */
2148 case AH_ESP_V4_FLOW:
2152 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2156 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2157 /* fall through to add IP fields */
2159 case AH_ESP_V6_FLOW:
2163 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2173 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2174 * @pf: Pointer to the physical function struct
2175 * @cmd: The command to get or set Rx flow classification rules
2176 * @rule_locs: Array of used rule locations
2178 * This function populates both the total and actual rule count of
2179 * the ethtool flow classification command
2181 * Returns 0 on success or -EMSGSIZE if entry not found
2183 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2184 struct ethtool_rxnfc *cmd,
2187 struct i40e_fdir_filter *rule;
2188 struct hlist_node *node2;
2191 /* report total rule count */
2192 cmd->data = i40e_get_fd_cnt_all(pf);
2194 hlist_for_each_entry_safe(rule, node2,
2195 &pf->fdir_filter_list, fdir_node) {
2196 if (cnt == cmd->rule_cnt)
2199 rule_locs[cnt] = rule->fd_id;
2203 cmd->rule_cnt = cnt;
2209 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2210 * @pf: Pointer to the physical function struct
2211 * @cmd: The command to get or set Rx flow classification rules
2213 * This function looks up a filter based on the Rx flow classification
2214 * command and fills the flow spec info for it if found
2216 * Returns 0 on success or -EINVAL if filter not found
2218 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2219 struct ethtool_rxnfc *cmd)
2221 struct ethtool_rx_flow_spec *fsp =
2222 (struct ethtool_rx_flow_spec *)&cmd->fs;
2223 struct i40e_fdir_filter *rule = NULL;
2224 struct hlist_node *node2;
2226 hlist_for_each_entry_safe(rule, node2,
2227 &pf->fdir_filter_list, fdir_node) {
2228 if (fsp->location <= rule->fd_id)
2232 if (!rule || fsp->location != rule->fd_id)
2235 fsp->flow_type = rule->flow_type;
2236 if (fsp->flow_type == IP_USER_FLOW) {
2237 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2238 fsp->h_u.usr_ip4_spec.proto = 0;
2239 fsp->m_u.usr_ip4_spec.proto = 0;
2242 /* Reverse the src and dest notion, since the HW views them from
2243 * Tx perspective where as the user expects it from Rx filter view.
2245 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2246 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2247 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2248 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
2250 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2251 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2253 fsp->ring_cookie = rule->q_index;
2255 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2256 struct i40e_vsi *vsi;
2258 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2259 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2260 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2261 fsp->m_ext.data[1] = htonl(0x1);
2269 * i40e_get_rxnfc - command to get RX flow classification rules
2270 * @netdev: network interface device structure
2271 * @cmd: ethtool rxnfc command
2273 * Returns Success if the command is supported.
2275 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2278 struct i40e_netdev_priv *np = netdev_priv(netdev);
2279 struct i40e_vsi *vsi = np->vsi;
2280 struct i40e_pf *pf = vsi->back;
2281 int ret = -EOPNOTSUPP;
2284 case ETHTOOL_GRXRINGS:
2285 cmd->data = vsi->num_queue_pairs;
2289 ret = i40e_get_rss_hash_opts(pf, cmd);
2291 case ETHTOOL_GRXCLSRLCNT:
2292 cmd->rule_cnt = pf->fdir_pf_active_filters;
2293 /* report total rule count */
2294 cmd->data = i40e_get_fd_cnt_all(pf);
2297 case ETHTOOL_GRXCLSRULE:
2298 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
2300 case ETHTOOL_GRXCLSRLALL:
2301 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2311 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2312 * @pf: pointer to the physical function struct
2313 * @cmd: ethtool rxnfc command
2315 * Returns Success if the flow input set is supported.
2317 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2319 struct i40e_hw *hw = &pf->hw;
2320 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2321 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
2323 /* RSS does not support anything other than hashing
2324 * to queues on src and dst IPs and ports
2326 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2327 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2330 /* We need at least the IP SRC and DEST fields for hashing */
2331 if (!(nfc->data & RXH_IP_SRC) ||
2332 !(nfc->data & RXH_IP_DST))
2335 switch (nfc->flow_type) {
2337 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2340 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2341 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2343 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2345 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2352 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2355 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2356 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2358 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
2360 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2367 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2370 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2371 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2373 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2374 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
2376 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2377 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
2384 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2387 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2388 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2390 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2391 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
2393 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2394 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
2400 case AH_ESP_V4_FLOW:
2404 if ((nfc->data & RXH_L4_B_0_1) ||
2405 (nfc->data & RXH_L4_B_2_3))
2407 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2409 case AH_ESP_V6_FLOW:
2413 if ((nfc->data & RXH_L4_B_0_1) ||
2414 (nfc->data & RXH_L4_B_2_3))
2416 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2419 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2420 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
2423 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2424 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
2430 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2431 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2434 /* Save setting for future output/update */
2435 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2441 * i40e_match_fdir_input_set - Match a new filter against an existing one
2442 * @rule: The filter already added
2443 * @input: The new filter to comapre against
2445 * Returns true if the two input set match
2447 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2448 struct i40e_fdir_filter *input)
2450 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2451 (rule->src_ip[0] != input->src_ip[0]) ||
2452 (rule->dst_port != input->dst_port) ||
2453 (rule->src_port != input->src_port))
2459 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2460 * @vsi: Pointer to the targeted VSI
2461 * @input: The filter to update or NULL to indicate deletion
2462 * @sw_idx: Software index to the filter
2463 * @cmd: The command to get or set Rx flow classification rules
2465 * This function updates (or deletes) a Flow Director entry from
2466 * the hlist of the corresponding PF
2468 * Returns 0 on success
2470 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2471 struct i40e_fdir_filter *input,
2473 struct ethtool_rxnfc *cmd)
2475 struct i40e_fdir_filter *rule, *parent;
2476 struct i40e_pf *pf = vsi->back;
2477 struct hlist_node *node2;
2483 hlist_for_each_entry_safe(rule, node2,
2484 &pf->fdir_filter_list, fdir_node) {
2485 /* hash found, or no matching entry */
2486 if (rule->fd_id >= sw_idx)
2491 /* if there is an old rule occupying our place remove it */
2492 if (rule && (rule->fd_id == sw_idx)) {
2493 if (input && !i40e_match_fdir_input_set(rule, input))
2494 err = i40e_add_del_fdir(vsi, rule, false);
2496 err = i40e_add_del_fdir(vsi, rule, false);
2497 hlist_del(&rule->fdir_node);
2499 pf->fdir_pf_active_filters--;
2502 /* If no input this was a delete, err should be 0 if a rule was
2503 * successfully found and removed from the list else -EINVAL
2508 /* initialize node and set software index */
2509 INIT_HLIST_NODE(&input->fdir_node);
2511 /* add filter to the list */
2513 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
2515 hlist_add_head(&input->fdir_node,
2516 &pf->fdir_filter_list);
2519 pf->fdir_pf_active_filters++;
2525 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2526 * @vsi: Pointer to the targeted VSI
2527 * @cmd: The command to get or set Rx flow classification rules
2529 * The function removes a Flow Director filter entry from the
2530 * hlist of the corresponding PF
2532 * Returns 0 on success
2534 static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2535 struct ethtool_rxnfc *cmd)
2537 struct ethtool_rx_flow_spec *fsp =
2538 (struct ethtool_rx_flow_spec *)&cmd->fs;
2539 struct i40e_pf *pf = vsi->back;
2542 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2543 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2546 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2549 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
2551 i40e_fdir_check_and_reenable(pf);
2556 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
2557 * @vsi: pointer to the targeted VSI
2558 * @cmd: command to get or set RX flow classification rules
2560 * Add Flow Director filters for a specific flow spec based on their
2561 * protocol. Returns 0 if the filters were successfully added.
2563 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2564 struct ethtool_rxnfc *cmd)
2566 struct ethtool_rx_flow_spec *fsp;
2567 struct i40e_fdir_filter *input;
2576 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2579 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
2582 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2583 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2586 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2589 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2591 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2592 pf->hw.func_caps.fd_filters_guaranteed)) {
2596 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2597 (fsp->ring_cookie >= vsi->num_queue_pairs))
2600 input = kzalloc(sizeof(*input), GFP_KERNEL);
2605 input->fd_id = fsp->location;
2607 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2608 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2611 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2613 input->q_index = fsp->ring_cookie;
2614 input->flex_off = 0;
2616 input->dest_vsi = vsi->id;
2617 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
2618 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
2619 input->flow_type = fsp->flow_type;
2620 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
2622 /* Reverse the src and dest notion, since the HW expects them to be from
2623 * Tx perspective where as the input from user is from Rx filter view.
2625 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2626 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2627 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2628 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
2630 if (ntohl(fsp->m_ext.data[1])) {
2631 vf_id = ntohl(fsp->h_ext.data[1]);
2632 if (vf_id >= pf->num_alloc_vfs) {
2633 netif_info(pf, drv, vsi->netdev,
2634 "Invalid VF id %d\n", vf_id);
2637 /* Find vsi id from vf id and override dest vsi */
2638 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2639 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2640 netif_info(pf, drv, vsi->netdev,
2641 "Invalid queue id %d for VF %d\n",
2642 input->q_index, vf_id);
2647 ret = i40e_add_del_fdir(vsi, input, true);
2652 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
2658 * i40e_set_rxnfc - command to set RX flow classification rules
2659 * @netdev: network interface device structure
2660 * @cmd: ethtool rxnfc command
2662 * Returns Success if the command is supported.
2664 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2666 struct i40e_netdev_priv *np = netdev_priv(netdev);
2667 struct i40e_vsi *vsi = np->vsi;
2668 struct i40e_pf *pf = vsi->back;
2669 int ret = -EOPNOTSUPP;
2673 ret = i40e_set_rss_hash_opt(pf, cmd);
2675 case ETHTOOL_SRXCLSRLINS:
2676 ret = i40e_add_fdir_ethtool(vsi, cmd);
2678 case ETHTOOL_SRXCLSRLDEL:
2679 ret = i40e_del_fdir_entry(vsi, cmd);
2689 * i40e_max_channels - get Max number of combined channels supported
2692 static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2694 /* TODO: This code assumes DCB and FD is disabled for now. */
2695 return vsi->alloc_queue_pairs;
2699 * i40e_get_channels - Get the current channels enabled and max supported etc.
2700 * @netdev: network interface device structure
2701 * @ch: ethtool channels structure
2703 * We don't support separate tx and rx queues as channels. The other count
2704 * represents how many queues are being used for control. max_combined counts
2705 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2706 * q_vectors since we support a lot more queue pairs than q_vectors.
2708 static void i40e_get_channels(struct net_device *dev,
2709 struct ethtool_channels *ch)
2711 struct i40e_netdev_priv *np = netdev_priv(dev);
2712 struct i40e_vsi *vsi = np->vsi;
2713 struct i40e_pf *pf = vsi->back;
2715 /* report maximum channels */
2716 ch->max_combined = i40e_max_channels(vsi);
2718 /* report info for other vector */
2719 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
2720 ch->max_other = ch->other_count;
2722 /* Note: This code assumes DCB is disabled for now. */
2723 ch->combined_count = vsi->num_queue_pairs;
2727 * i40e_set_channels - Set the new channels count.
2728 * @netdev: network interface device structure
2729 * @ch: ethtool channels structure
2731 * The new channels count may not be the same as requested by the user
2732 * since it gets rounded down to a power of 2 value.
2734 static int i40e_set_channels(struct net_device *dev,
2735 struct ethtool_channels *ch)
2737 struct i40e_netdev_priv *np = netdev_priv(dev);
2738 unsigned int count = ch->combined_count;
2739 struct i40e_vsi *vsi = np->vsi;
2740 struct i40e_pf *pf = vsi->back;
2743 /* We do not support setting channels for any other VSI at present */
2744 if (vsi->type != I40E_VSI_MAIN)
2747 /* verify they are not requesting separate vectors */
2748 if (!count || ch->rx_count || ch->tx_count)
2751 /* verify other_count has not changed */
2752 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
2755 /* verify the number of channels does not exceed hardware limits */
2756 if (count > i40e_max_channels(vsi))
2759 /* update feature limits from largest to smallest supported values */
2760 /* TODO: Flow director limit, DCB etc */
2762 /* use rss_reconfig to rebuild with new queue count and update traffic
2763 * class queue mapping
2765 new_count = i40e_reconfig_rss_queues(pf, count);
2773 * i40e_get_rxfh_key_size - get the RSS hash key size
2774 * @netdev: network interface device structure
2776 * Returns the table size.
2778 static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2780 return I40E_HKEY_ARRAY_SIZE;
2784 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2785 * @netdev: network interface device structure
2787 * Returns the table size.
2789 static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2791 return I40E_HLUT_ARRAY_SIZE;
2794 static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2797 struct i40e_netdev_priv *np = netdev_priv(netdev);
2798 struct i40e_vsi *vsi = np->vsi;
2799 u8 *lut, *seed = NULL;
2804 *hfunc = ETH_RSS_HASH_TOP;
2810 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2813 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2816 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2817 indir[i] = (u32)(lut[i]);
2826 * i40e_set_rxfh - set the rx flow hash indirection table
2827 * @netdev: network interface device structure
2828 * @indir: indirection table
2831 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
2832 * returns 0 after programming the table.
2834 static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2835 const u8 *key, const u8 hfunc)
2837 struct i40e_netdev_priv *np = netdev_priv(netdev);
2838 struct i40e_vsi *vsi = np->vsi;
2842 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2849 if (!vsi->rss_hkey_user) {
2850 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
2852 if (!vsi->rss_hkey_user)
2855 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
2856 seed = vsi->rss_hkey_user;
2858 if (!vsi->rss_lut_user) {
2859 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2860 if (!vsi->rss_lut_user)
2864 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
2865 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2866 vsi->rss_lut_user[i] = (u8)(indir[i]);
2868 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
2869 I40E_HLUT_ARRAY_SIZE);
2873 * i40e_get_priv_flags - report device private flags
2874 * @dev: network interface device structure
2876 * The get string set count and the string set should be matched for each
2877 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2880 * Returns a u32 bitmap of flags.
2882 static u32 i40e_get_priv_flags(struct net_device *dev)
2884 struct i40e_netdev_priv *np = netdev_priv(dev);
2885 struct i40e_vsi *vsi = np->vsi;
2886 struct i40e_pf *pf = vsi->back;
2889 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2890 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
2891 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2892 I40E_PRIV_FLAGS_FD_ATR : 0;
2893 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2894 I40E_PRIV_FLAGS_VEB_STATS : 0;
2895 ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
2896 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
2897 if (pf->hw.pf_id == 0) {
2898 ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ?
2899 I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0;
2906 * i40e_set_priv_flags - set private flags
2907 * @dev: network interface device structure
2908 * @flags: bit flags to be set
2910 static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2912 struct i40e_netdev_priv *np = netdev_priv(dev);
2913 struct i40e_vsi *vsi = np->vsi;
2914 struct i40e_pf *pf = vsi->back;
2915 u16 sw_flags = 0, valid_flags = 0;
2916 bool reset_required = false;
2917 bool promisc_change = false;
2920 /* NOTE: MFP is not settable */
2922 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2923 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2925 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2927 /* allow the user to control the state of the Flow
2928 * Director ATR (Application Targeted Routing) feature
2931 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2932 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2934 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2935 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2938 if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
2939 !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
2940 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
2941 reset_required = true;
2942 } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
2943 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
2944 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
2945 reset_required = true;
2948 if (pf->hw.pf_id == 0) {
2949 if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
2950 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
2951 pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT;
2952 promisc_change = true;
2953 } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
2954 (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
2955 pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT;
2956 promisc_change = true;
2959 if (promisc_change) {
2960 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
2961 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
2962 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
2963 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
2965 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
2966 dev_info(&pf->pdev->dev,
2967 "couldn't set switch config bits, err %s aq_err %s\n",
2968 i40e_stat_str(&pf->hw, ret),
2969 i40e_aq_str(&pf->hw,
2970 pf->hw.aq.asq_last_status));
2971 /* not a fatal problem, just keep going */
2975 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
2976 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
2977 pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2979 pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2981 /* if needed, issue reset to cause things to take effect */
2983 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
2988 static const struct ethtool_ops i40e_ethtool_ops = {
2989 .get_settings = i40e_get_settings,
2990 .set_settings = i40e_set_settings,
2991 .get_drvinfo = i40e_get_drvinfo,
2992 .get_regs_len = i40e_get_regs_len,
2993 .get_regs = i40e_get_regs,
2994 .nway_reset = i40e_nway_reset,
2995 .get_link = ethtool_op_get_link,
2996 .get_wol = i40e_get_wol,
2997 .set_wol = i40e_set_wol,
2998 .set_eeprom = i40e_set_eeprom,
2999 .get_eeprom_len = i40e_get_eeprom_len,
3000 .get_eeprom = i40e_get_eeprom,
3001 .get_ringparam = i40e_get_ringparam,
3002 .set_ringparam = i40e_set_ringparam,
3003 .get_pauseparam = i40e_get_pauseparam,
3004 .set_pauseparam = i40e_set_pauseparam,
3005 .get_msglevel = i40e_get_msglevel,
3006 .set_msglevel = i40e_set_msglevel,
3007 .get_rxnfc = i40e_get_rxnfc,
3008 .set_rxnfc = i40e_set_rxnfc,
3009 .self_test = i40e_diag_test,
3010 .get_strings = i40e_get_strings,
3011 .set_phys_id = i40e_set_phys_id,
3012 .get_sset_count = i40e_get_sset_count,
3013 .get_ethtool_stats = i40e_get_ethtool_stats,
3014 .get_coalesce = i40e_get_coalesce,
3015 .set_coalesce = i40e_set_coalesce,
3016 .get_rxfh_key_size = i40e_get_rxfh_key_size,
3017 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
3018 .get_rxfh = i40e_get_rxfh,
3019 .set_rxfh = i40e_set_rxfh,
3020 .get_channels = i40e_get_channels,
3021 .set_channels = i40e_set_channels,
3022 .get_ts_info = i40e_get_ts_info,
3023 .get_priv_flags = i40e_get_priv_flags,
3024 .set_priv_flags = i40e_set_priv_flags,
3025 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
3026 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
3029 void i40e_set_ethtool_ops(struct net_device *netdev)
3031 netdev->ethtool_ops = &i40e_ethtool_ops;