1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2015 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),
93 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
94 struct ethtool_rxnfc *cmd);
96 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
97 * but they are separate. This device supports Virtualization, and
98 * as such might have several netdevs supporting VMDq and FCoE going
99 * through a single port. The NETDEV_STATs are for individual netdevs
100 * seen at the top of the stack, and the PF_STATs are for the physical
101 * function at the bottom of the stack hosting those netdevs.
103 * The PF_STATs are appended to the netdev stats only when ethtool -S
104 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
106 static struct i40e_stats i40e_gstrings_stats[] = {
107 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
108 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
109 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
110 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
111 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
112 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
113 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
114 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
115 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
116 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
117 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
118 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
119 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
120 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
121 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
122 I40E_PF_STAT("tx_timeout", tx_timeout_count),
123 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
124 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
125 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
126 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
127 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
128 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
129 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
130 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
131 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
132 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
133 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
134 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
135 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
136 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
137 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
138 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
139 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
140 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
141 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
142 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
143 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
144 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
145 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
146 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
147 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
148 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
149 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
150 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
151 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
152 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
153 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
154 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
157 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
158 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
159 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
160 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
164 static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
165 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
166 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
167 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
168 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
169 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
170 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
171 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
172 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
175 #endif /* I40E_FCOE */
176 #define I40E_QUEUE_STATS_LEN(n) \
177 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
178 * 2 /* Tx and Rx together */ \
179 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
180 #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
181 #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
182 #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
184 #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
185 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
186 I40E_FCOE_STATS_LEN + \
187 I40E_MISC_STATS_LEN + \
188 I40E_QUEUE_STATS_LEN((n)))
190 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
191 I40E_MISC_STATS_LEN + \
192 I40E_QUEUE_STATS_LEN((n)))
193 #endif /* I40E_FCOE */
194 #define I40E_PFC_STATS_LEN ( \
195 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
201 #define I40E_VEB_TC_STATS_LEN ( \
202 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
203 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
204 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
207 #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
208 #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
209 #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
210 I40E_PFC_STATS_LEN + \
211 I40E_VSI_STATS_LEN((n)))
213 enum i40e_ethtool_test_id {
214 I40E_ETH_TEST_REG = 0,
215 I40E_ETH_TEST_EEPROM,
217 I40E_ETH_TEST_LOOPBACK,
221 static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
222 "Register test (offline)",
223 "Eeprom test (offline)",
224 "Interrupt test (offline)",
225 "Loopback test (offline)",
226 "Link test (on/offline)"
229 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
231 static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
236 #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
239 * i40e_partition_setting_complaint - generic complaint for MFP restriction
242 static void i40e_partition_setting_complaint(struct i40e_pf *pf)
244 dev_info(&pf->pdev->dev,
245 "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");
249 * i40e_get_settings_link_up - Get the Link settings for when link is up
251 * @ecmd: ethtool command to fill in
252 * @netdev: network interface device structure
255 static void i40e_get_settings_link_up(struct i40e_hw *hw,
256 struct ethtool_cmd *ecmd,
257 struct net_device *netdev)
259 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
260 u32 link_speed = hw_link_info->link_speed;
262 /* Initialize supported and advertised settings based on phy settings */
263 switch (hw_link_info->phy_type) {
264 case I40E_PHY_TYPE_40GBASE_CR4:
265 case I40E_PHY_TYPE_40GBASE_CR4_CU:
266 ecmd->supported = SUPPORTED_Autoneg |
267 SUPPORTED_40000baseCR4_Full;
268 ecmd->advertising = ADVERTISED_Autoneg |
269 ADVERTISED_40000baseCR4_Full;
271 case I40E_PHY_TYPE_XLAUI:
272 case I40E_PHY_TYPE_XLPPI:
273 case I40E_PHY_TYPE_40GBASE_AOC:
274 ecmd->supported = SUPPORTED_40000baseCR4_Full;
276 case I40E_PHY_TYPE_40GBASE_SR4:
277 ecmd->supported = SUPPORTED_40000baseSR4_Full;
279 case I40E_PHY_TYPE_40GBASE_LR4:
280 ecmd->supported = SUPPORTED_40000baseLR4_Full;
282 case I40E_PHY_TYPE_10GBASE_SR:
283 case I40E_PHY_TYPE_10GBASE_LR:
284 case I40E_PHY_TYPE_1000BASE_SX:
285 case I40E_PHY_TYPE_1000BASE_LX:
286 ecmd->supported = SUPPORTED_10000baseT_Full;
287 if (hw_link_info->module_type[2] &
288 I40E_MODULE_TYPE_1000BASE_SX ||
289 hw_link_info->module_type[2] &
290 I40E_MODULE_TYPE_1000BASE_LX) {
291 ecmd->supported |= SUPPORTED_1000baseT_Full;
292 if (hw_link_info->requested_speeds &
294 ecmd->advertising |= ADVERTISED_1000baseT_Full;
296 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
297 ecmd->advertising |= ADVERTISED_10000baseT_Full;
299 case I40E_PHY_TYPE_10GBASE_T:
300 case I40E_PHY_TYPE_1000BASE_T:
301 case I40E_PHY_TYPE_100BASE_TX:
302 ecmd->supported = SUPPORTED_Autoneg |
303 SUPPORTED_10000baseT_Full |
304 SUPPORTED_1000baseT_Full |
305 SUPPORTED_100baseT_Full;
306 ecmd->advertising = ADVERTISED_Autoneg;
307 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
308 ecmd->advertising |= ADVERTISED_10000baseT_Full;
309 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
310 ecmd->advertising |= ADVERTISED_1000baseT_Full;
311 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
312 ecmd->advertising |= ADVERTISED_100baseT_Full;
314 case I40E_PHY_TYPE_10GBASE_CR1_CU:
315 case I40E_PHY_TYPE_10GBASE_CR1:
316 ecmd->supported = SUPPORTED_Autoneg |
317 SUPPORTED_10000baseT_Full;
318 ecmd->advertising = ADVERTISED_Autoneg |
319 ADVERTISED_10000baseT_Full;
321 case I40E_PHY_TYPE_XAUI:
322 case I40E_PHY_TYPE_XFI:
323 case I40E_PHY_TYPE_SFI:
324 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
325 case I40E_PHY_TYPE_10GBASE_AOC:
326 ecmd->supported = SUPPORTED_10000baseT_Full;
328 case I40E_PHY_TYPE_SGMII:
329 ecmd->supported = SUPPORTED_Autoneg |
330 SUPPORTED_1000baseT_Full |
331 SUPPORTED_100baseT_Full;
332 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
333 ecmd->advertising |= ADVERTISED_1000baseT_Full;
334 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
335 ecmd->advertising |= ADVERTISED_100baseT_Full;
337 /* Backplane is set based on supported phy types in get_settings
338 * so don't set anything here but don't warn either
340 case I40E_PHY_TYPE_40GBASE_KR4:
341 case I40E_PHY_TYPE_20GBASE_KR2:
342 case I40E_PHY_TYPE_10GBASE_KR:
343 case I40E_PHY_TYPE_10GBASE_KX4:
344 case I40E_PHY_TYPE_1000BASE_KX:
347 /* if we got here and link is up something bad is afoot */
348 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
349 hw_link_info->phy_type);
352 /* Set speed and duplex */
353 switch (link_speed) {
354 case I40E_LINK_SPEED_40GB:
355 ethtool_cmd_speed_set(ecmd, SPEED_40000);
357 case I40E_LINK_SPEED_20GB:
358 ethtool_cmd_speed_set(ecmd, SPEED_20000);
360 case I40E_LINK_SPEED_10GB:
361 ethtool_cmd_speed_set(ecmd, SPEED_10000);
363 case I40E_LINK_SPEED_1GB:
364 ethtool_cmd_speed_set(ecmd, SPEED_1000);
366 case I40E_LINK_SPEED_100MB:
367 ethtool_cmd_speed_set(ecmd, SPEED_100);
372 ecmd->duplex = DUPLEX_FULL;
376 * i40e_get_settings_link_down - Get the Link settings for when link is down
378 * @ecmd: ethtool command to fill in
380 * Reports link settings that can be determined when link is down
382 static void i40e_get_settings_link_down(struct i40e_hw *hw,
383 struct ethtool_cmd *ecmd)
385 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
387 /* link is down and the driver needs to fall back on
388 * supported phy types to figure out what info to display
390 ecmd->supported = 0x0;
391 ecmd->advertising = 0x0;
392 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
393 ecmd->supported |= SUPPORTED_Autoneg |
394 SUPPORTED_1000baseT_Full |
395 SUPPORTED_100baseT_Full;
396 ecmd->advertising |= ADVERTISED_Autoneg |
397 ADVERTISED_1000baseT_Full |
398 ADVERTISED_100baseT_Full;
400 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
401 phy_types & I40E_CAP_PHY_TYPE_XFI ||
402 phy_types & I40E_CAP_PHY_TYPE_SFI ||
403 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
404 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
405 ecmd->supported |= SUPPORTED_10000baseT_Full;
406 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
407 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
408 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
409 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
410 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
411 ecmd->supported |= SUPPORTED_Autoneg |
412 SUPPORTED_10000baseT_Full;
413 ecmd->advertising |= ADVERTISED_Autoneg |
414 ADVERTISED_10000baseT_Full;
416 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
417 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
418 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
419 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
420 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
421 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
422 ecmd->supported |= SUPPORTED_Autoneg |
423 SUPPORTED_40000baseCR4_Full;
424 ecmd->advertising |= ADVERTISED_Autoneg |
425 ADVERTISED_40000baseCR4_Full;
427 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
428 ecmd->supported |= SUPPORTED_Autoneg |
429 SUPPORTED_100baseT_Full;
430 ecmd->advertising |= ADVERTISED_Autoneg |
431 ADVERTISED_100baseT_Full;
433 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
434 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
435 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
436 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
437 ecmd->supported |= SUPPORTED_Autoneg |
438 SUPPORTED_1000baseT_Full;
439 ecmd->advertising |= ADVERTISED_Autoneg |
440 ADVERTISED_1000baseT_Full;
442 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
443 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
444 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
445 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
447 /* With no link speed and duplex are unknown */
448 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
449 ecmd->duplex = DUPLEX_UNKNOWN;
453 * i40e_get_settings - Get Link Speed and Duplex settings
454 * @netdev: network interface device structure
455 * @ecmd: ethtool command
457 * Reports speed/duplex settings based on media_type
459 static int i40e_get_settings(struct net_device *netdev,
460 struct ethtool_cmd *ecmd)
462 struct i40e_netdev_priv *np = netdev_priv(netdev);
463 struct i40e_pf *pf = np->vsi->back;
464 struct i40e_hw *hw = &pf->hw;
465 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
466 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
469 i40e_get_settings_link_up(hw, ecmd, netdev);
471 i40e_get_settings_link_down(hw, ecmd);
473 /* Now set the settings that don't rely on link being up/down */
475 /* For backplane, supported and advertised are only reliant on the
476 * phy types the NVM specifies are supported.
478 if (hw->device_id == I40E_DEV_ID_KX_B ||
479 hw->device_id == I40E_DEV_ID_KX_C ||
480 hw->device_id == I40E_DEV_ID_20G_KR2 ||
481 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
482 ecmd->supported = SUPPORTED_Autoneg;
483 ecmd->advertising = ADVERTISED_Autoneg;
484 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
485 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
486 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
488 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
489 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
490 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
492 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
493 ecmd->supported |= SUPPORTED_10000baseKR_Full;
494 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
496 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
497 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
498 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
500 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
501 ecmd->supported |= SUPPORTED_1000baseKX_Full;
502 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
506 /* Set autoneg settings */
507 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
508 AUTONEG_ENABLE : AUTONEG_DISABLE);
510 switch (hw->phy.media_type) {
511 case I40E_MEDIA_TYPE_BACKPLANE:
512 ecmd->supported |= SUPPORTED_Autoneg |
514 ecmd->advertising |= ADVERTISED_Autoneg |
515 ADVERTISED_Backplane;
516 ecmd->port = PORT_NONE;
518 case I40E_MEDIA_TYPE_BASET:
519 ecmd->supported |= SUPPORTED_TP;
520 ecmd->advertising |= ADVERTISED_TP;
521 ecmd->port = PORT_TP;
523 case I40E_MEDIA_TYPE_DA:
524 case I40E_MEDIA_TYPE_CX4:
525 ecmd->supported |= SUPPORTED_FIBRE;
526 ecmd->advertising |= ADVERTISED_FIBRE;
527 ecmd->port = PORT_DA;
529 case I40E_MEDIA_TYPE_FIBER:
530 ecmd->supported |= SUPPORTED_FIBRE;
531 ecmd->port = PORT_FIBRE;
533 case I40E_MEDIA_TYPE_UNKNOWN:
535 ecmd->port = PORT_OTHER;
539 /* Set transceiver */
540 ecmd->transceiver = XCVR_EXTERNAL;
542 /* Set flow control settings */
543 ecmd->supported |= SUPPORTED_Pause;
545 switch (hw->fc.requested_mode) {
547 ecmd->advertising |= ADVERTISED_Pause;
549 case I40E_FC_TX_PAUSE:
550 ecmd->advertising |= ADVERTISED_Asym_Pause;
552 case I40E_FC_RX_PAUSE:
553 ecmd->advertising |= (ADVERTISED_Pause |
554 ADVERTISED_Asym_Pause);
557 ecmd->advertising &= ~(ADVERTISED_Pause |
558 ADVERTISED_Asym_Pause);
566 * i40e_set_settings - Set Speed and Duplex
567 * @netdev: network interface device structure
568 * @ecmd: ethtool command
570 * Set speed/duplex per media_types advertised/forced
572 static int i40e_set_settings(struct net_device *netdev,
573 struct ethtool_cmd *ecmd)
575 struct i40e_netdev_priv *np = netdev_priv(netdev);
576 struct i40e_aq_get_phy_abilities_resp abilities;
577 struct i40e_aq_set_phy_config config;
578 struct i40e_pf *pf = np->vsi->back;
579 struct i40e_vsi *vsi = np->vsi;
580 struct i40e_hw *hw = &pf->hw;
581 struct ethtool_cmd safe_ecmd;
582 i40e_status status = 0;
588 /* Changing port settings is not supported if this isn't the
589 * port's controlling PF
591 if (hw->partition_id != 1) {
592 i40e_partition_setting_complaint(pf);
596 if (vsi != pf->vsi[pf->lan_vsi])
599 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
600 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
601 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
602 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
605 if (hw->device_id == I40E_DEV_ID_KX_B ||
606 hw->device_id == I40E_DEV_ID_KX_C ||
607 hw->device_id == I40E_DEV_ID_20G_KR2 ||
608 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
609 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
613 /* get our own copy of the bits to check against */
614 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
615 i40e_get_settings(netdev, &safe_ecmd);
617 /* save autoneg and speed out of ecmd */
618 autoneg = ecmd->autoneg;
619 advertise = ecmd->advertising;
621 /* set autoneg and speed back to what they currently are */
622 ecmd->autoneg = safe_ecmd.autoneg;
623 ecmd->advertising = safe_ecmd.advertising;
625 ecmd->cmd = safe_ecmd.cmd;
626 /* If ecmd and safe_ecmd are not the same now, then they are
627 * trying to set something that we do not support
629 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
632 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
633 usleep_range(1000, 2000);
635 /* Get the current phy config */
636 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
641 /* Copy abilities to config in case autoneg is not
644 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
645 config.abilities = abilities.abilities;
648 if (autoneg == AUTONEG_ENABLE) {
649 /* If autoneg is not supported, return error */
650 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
651 netdev_info(netdev, "Autoneg not supported on this phy\n");
654 /* If autoneg was not already enabled */
655 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
656 config.abilities = abilities.abilities |
657 I40E_AQ_PHY_ENABLE_AN;
661 /* If autoneg is supported 10GBASE_T is the only phy that
662 * can disable it, so otherwise return error
664 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
665 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
666 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
669 /* If autoneg is currently enabled */
670 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
671 config.abilities = abilities.abilities &
672 ~I40E_AQ_PHY_ENABLE_AN;
677 if (advertise & ~safe_ecmd.supported)
680 if (advertise & ADVERTISED_100baseT_Full)
681 config.link_speed |= I40E_LINK_SPEED_100MB;
682 if (advertise & ADVERTISED_1000baseT_Full ||
683 advertise & ADVERTISED_1000baseKX_Full)
684 config.link_speed |= I40E_LINK_SPEED_1GB;
685 if (advertise & ADVERTISED_10000baseT_Full ||
686 advertise & ADVERTISED_10000baseKX4_Full ||
687 advertise & ADVERTISED_10000baseKR_Full)
688 config.link_speed |= I40E_LINK_SPEED_10GB;
689 if (advertise & ADVERTISED_20000baseKR2_Full)
690 config.link_speed |= I40E_LINK_SPEED_20GB;
691 if (advertise & ADVERTISED_40000baseKR4_Full ||
692 advertise & ADVERTISED_40000baseCR4_Full ||
693 advertise & ADVERTISED_40000baseSR4_Full ||
694 advertise & ADVERTISED_40000baseLR4_Full)
695 config.link_speed |= I40E_LINK_SPEED_40GB;
697 /* If speed didn't get set, set it to what it currently is.
698 * This is needed because if advertise is 0 (as it is when autoneg
699 * is disabled) then speed won't get set.
701 if (!config.link_speed)
702 config.link_speed = abilities.link_speed;
704 if (change || (abilities.link_speed != config.link_speed)) {
705 /* copy over the rest of the abilities */
706 config.phy_type = abilities.phy_type;
707 config.eee_capability = abilities.eee_capability;
708 config.eeer = abilities.eeer_val;
709 config.low_power_ctrl = abilities.d3_lpan;
711 /* save the requested speeds */
712 hw->phy.link_info.requested_speeds = config.link_speed;
713 /* set link and auto negotiation so changes take effect */
714 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
715 /* If link is up put link down */
716 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
717 /* Tell the OS link is going down, the link will go
718 * back up when fw says it is ready asynchronously
720 i40e_print_link_message(vsi, false);
721 netif_carrier_off(netdev);
722 netif_tx_stop_all_queues(netdev);
725 /* make the aq call */
726 status = i40e_aq_set_phy_config(hw, &config, NULL);
728 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
729 i40e_stat_str(hw, status),
730 i40e_aq_str(hw, hw->aq.asq_last_status));
734 status = i40e_update_link_info(hw);
736 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
737 i40e_stat_str(hw, status),
738 i40e_aq_str(hw, hw->aq.asq_last_status));
741 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
747 static int i40e_nway_reset(struct net_device *netdev)
749 /* restart autonegotiation */
750 struct i40e_netdev_priv *np = netdev_priv(netdev);
751 struct i40e_pf *pf = np->vsi->back;
752 struct i40e_hw *hw = &pf->hw;
753 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
756 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
758 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
759 i40e_stat_str(hw, ret),
760 i40e_aq_str(hw, hw->aq.asq_last_status));
768 * i40e_get_pauseparam - Get Flow Control status
769 * Return tx/rx-pause status
771 static void i40e_get_pauseparam(struct net_device *netdev,
772 struct ethtool_pauseparam *pause)
774 struct i40e_netdev_priv *np = netdev_priv(netdev);
775 struct i40e_pf *pf = np->vsi->back;
776 struct i40e_hw *hw = &pf->hw;
777 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
778 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
781 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
782 AUTONEG_ENABLE : AUTONEG_DISABLE);
784 /* PFC enabled so report LFC as off */
785 if (dcbx_cfg->pfc.pfcenable) {
791 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
793 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
795 } else if (hw->fc.current_mode == I40E_FC_FULL) {
802 * i40e_set_pauseparam - Set Flow Control parameter
803 * @netdev: network interface device structure
804 * @pause: return tx/rx flow control status
806 static int i40e_set_pauseparam(struct net_device *netdev,
807 struct ethtool_pauseparam *pause)
809 struct i40e_netdev_priv *np = netdev_priv(netdev);
810 struct i40e_pf *pf = np->vsi->back;
811 struct i40e_vsi *vsi = np->vsi;
812 struct i40e_hw *hw = &pf->hw;
813 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
814 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
815 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
820 /* Changing the port's flow control is not supported if this isn't the
821 * port's controlling PF
823 if (hw->partition_id != 1) {
824 i40e_partition_setting_complaint(pf);
828 if (vsi != pf->vsi[pf->lan_vsi])
831 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
832 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
833 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
837 /* If we have link and don't have autoneg */
838 if (!test_bit(__I40E_DOWN, &pf->state) &&
839 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
840 /* Send message that it might not necessarily work*/
841 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
844 if (dcbx_cfg->pfc.pfcenable) {
846 "Priority flow control enabled. Cannot set link flow control.\n");
850 if (pause->rx_pause && pause->tx_pause)
851 hw->fc.requested_mode = I40E_FC_FULL;
852 else if (pause->rx_pause && !pause->tx_pause)
853 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
854 else if (!pause->rx_pause && pause->tx_pause)
855 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
856 else if (!pause->rx_pause && !pause->tx_pause)
857 hw->fc.requested_mode = I40E_FC_NONE;
861 /* Tell the OS link is going down, the link will go back up when fw
862 * says it is ready asynchronously
864 i40e_print_link_message(vsi, false);
865 netif_carrier_off(netdev);
866 netif_tx_stop_all_queues(netdev);
868 /* Set the fc mode and only restart an if link is up*/
869 status = i40e_set_fc(hw, &aq_failures, link_up);
871 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
872 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
873 i40e_stat_str(hw, status),
874 i40e_aq_str(hw, hw->aq.asq_last_status));
877 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
878 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
879 i40e_stat_str(hw, status),
880 i40e_aq_str(hw, hw->aq.asq_last_status));
883 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
884 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
885 i40e_stat_str(hw, status),
886 i40e_aq_str(hw, hw->aq.asq_last_status));
890 if (!test_bit(__I40E_DOWN, &pf->state)) {
891 /* Give it a little more time to try to come back */
893 if (!test_bit(__I40E_DOWN, &pf->state))
894 return i40e_nway_reset(netdev);
900 static u32 i40e_get_msglevel(struct net_device *netdev)
902 struct i40e_netdev_priv *np = netdev_priv(netdev);
903 struct i40e_pf *pf = np->vsi->back;
905 return pf->msg_enable;
908 static void i40e_set_msglevel(struct net_device *netdev, u32 data)
910 struct i40e_netdev_priv *np = netdev_priv(netdev);
911 struct i40e_pf *pf = np->vsi->back;
913 if (I40E_DEBUG_USER & data)
914 pf->hw.debug_mask = data;
915 pf->msg_enable = data;
918 static int i40e_get_regs_len(struct net_device *netdev)
923 for (i = 0; i40e_reg_list[i].offset != 0; i++)
924 reg_count += i40e_reg_list[i].elements;
926 return reg_count * sizeof(u32);
929 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
932 struct i40e_netdev_priv *np = netdev_priv(netdev);
933 struct i40e_pf *pf = np->vsi->back;
934 struct i40e_hw *hw = &pf->hw;
939 /* Tell ethtool which driver-version-specific regs output we have.
941 * At some point, if we have ethtool doing special formatting of
942 * this data, it will rely on this version number to know how to
943 * interpret things. Hence, this needs to be updated if/when the
944 * diags register table is changed.
948 /* loop through the diags reg table for what to print */
950 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
951 for (j = 0; j < i40e_reg_list[i].elements; j++) {
952 reg = i40e_reg_list[i].offset
953 + (j * i40e_reg_list[i].stride);
954 reg_buf[ri++] = rd32(hw, reg);
960 static int i40e_get_eeprom(struct net_device *netdev,
961 struct ethtool_eeprom *eeprom, u8 *bytes)
963 struct i40e_netdev_priv *np = netdev_priv(netdev);
964 struct i40e_hw *hw = &np->vsi->back->hw;
965 struct i40e_pf *pf = np->vsi->back;
966 int ret_val = 0, len, offset;
972 #define I40E_NVM_SECTOR_SIZE 4096
973 if (eeprom->len == 0)
976 /* check for NVMUpdate access method */
977 magic = hw->vendor_id | (hw->device_id << 16);
978 if (eeprom->magic && eeprom->magic != magic) {
979 struct i40e_nvm_access *cmd;
982 /* make sure it is the right magic for NVMUpdate */
983 if ((eeprom->magic >> 16) != hw->device_id)
986 cmd = (struct i40e_nvm_access *)eeprom;
987 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
989 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
990 (hw->debug_mask & I40E_DEBUG_NVM)))
991 dev_info(&pf->pdev->dev,
992 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
993 ret_val, hw->aq.asq_last_status, errno,
994 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
995 cmd->offset, cmd->data_size);
1000 /* normal ethtool get_eeprom support */
1001 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1003 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
1007 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1009 dev_info(&pf->pdev->dev,
1010 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1011 ret_val, hw->aq.asq_last_status);
1015 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1016 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1017 len = I40E_NVM_SECTOR_SIZE;
1019 for (i = 0; i < sectors; i++) {
1020 if (i == (sectors - 1)) {
1021 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1024 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1025 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
1026 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
1028 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
1029 dev_info(&pf->pdev->dev,
1030 "read NVM failed, invalid offset 0x%x\n",
1033 } else if (ret_val &&
1034 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1035 dev_info(&pf->pdev->dev,
1036 "read NVM failed, access, offset 0x%x\n",
1039 } else if (ret_val) {
1040 dev_info(&pf->pdev->dev,
1041 "read NVM failed offset %d err=%d status=0x%x\n",
1042 offset, ret_val, hw->aq.asq_last_status);
1047 i40e_release_nvm(hw);
1048 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
1054 static int i40e_get_eeprom_len(struct net_device *netdev)
1056 struct i40e_netdev_priv *np = netdev_priv(netdev);
1057 struct i40e_hw *hw = &np->vsi->back->hw;
1060 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1061 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1062 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1063 /* register returns value in power of 2, 64Kbyte chunks. */
1064 val = (64 * 1024) * BIT(val);
1068 static int i40e_set_eeprom(struct net_device *netdev,
1069 struct ethtool_eeprom *eeprom, u8 *bytes)
1071 struct i40e_netdev_priv *np = netdev_priv(netdev);
1072 struct i40e_hw *hw = &np->vsi->back->hw;
1073 struct i40e_pf *pf = np->vsi->back;
1074 struct i40e_nvm_access *cmd;
1079 /* normal ethtool set_eeprom is not supported */
1080 magic = hw->vendor_id | (hw->device_id << 16);
1081 if (eeprom->magic == magic)
1084 /* check for NVMUpdate access method */
1085 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1088 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1089 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1092 cmd = (struct i40e_nvm_access *)eeprom;
1093 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1095 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1096 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1097 (hw->debug_mask & I40E_DEBUG_NVM)))
1098 dev_info(&pf->pdev->dev,
1099 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1100 ret_val, hw->aq.asq_last_status, errno,
1101 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1102 cmd->offset, cmd->data_size);
1107 static void i40e_get_drvinfo(struct net_device *netdev,
1108 struct ethtool_drvinfo *drvinfo)
1110 struct i40e_netdev_priv *np = netdev_priv(netdev);
1111 struct i40e_vsi *vsi = np->vsi;
1112 struct i40e_pf *pf = vsi->back;
1114 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1115 strlcpy(drvinfo->version, i40e_driver_version_str,
1116 sizeof(drvinfo->version));
1117 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1118 sizeof(drvinfo->fw_version));
1119 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1120 sizeof(drvinfo->bus_info));
1121 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
1124 static void i40e_get_ringparam(struct net_device *netdev,
1125 struct ethtool_ringparam *ring)
1127 struct i40e_netdev_priv *np = netdev_priv(netdev);
1128 struct i40e_pf *pf = np->vsi->back;
1129 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1131 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1132 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1133 ring->rx_mini_max_pending = 0;
1134 ring->rx_jumbo_max_pending = 0;
1135 ring->rx_pending = vsi->rx_rings[0]->count;
1136 ring->tx_pending = vsi->tx_rings[0]->count;
1137 ring->rx_mini_pending = 0;
1138 ring->rx_jumbo_pending = 0;
1141 static int i40e_set_ringparam(struct net_device *netdev,
1142 struct ethtool_ringparam *ring)
1144 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1145 struct i40e_netdev_priv *np = netdev_priv(netdev);
1146 struct i40e_vsi *vsi = np->vsi;
1147 struct i40e_pf *pf = vsi->back;
1148 u32 new_rx_count, new_tx_count;
1151 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1154 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1155 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1156 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1157 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1159 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1160 ring->tx_pending, ring->rx_pending,
1161 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1165 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1166 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1168 /* if nothing to do return success */
1169 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1170 (new_rx_count == vsi->rx_rings[0]->count))
1173 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1174 usleep_range(1000, 2000);
1176 if (!netif_running(vsi->netdev)) {
1177 /* simple case - set for the next time the netdev is started */
1178 for (i = 0; i < vsi->num_queue_pairs; i++) {
1179 vsi->tx_rings[i]->count = new_tx_count;
1180 vsi->rx_rings[i]->count = new_rx_count;
1185 /* We can't just free everything and then setup again,
1186 * because the ISRs in MSI-X mode get passed pointers
1187 * to the Tx and Rx ring structs.
1190 /* alloc updated Tx resources */
1191 if (new_tx_count != vsi->tx_rings[0]->count) {
1193 "Changing Tx descriptor count from %d to %d.\n",
1194 vsi->tx_rings[0]->count, new_tx_count);
1195 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1196 sizeof(struct i40e_ring), GFP_KERNEL);
1202 for (i = 0; i < vsi->num_queue_pairs; i++) {
1203 /* clone ring and setup updated count */
1204 tx_rings[i] = *vsi->tx_rings[i];
1205 tx_rings[i].count = new_tx_count;
1206 /* the desc and bi pointers will be reallocated in the
1209 tx_rings[i].desc = NULL;
1210 tx_rings[i].rx_bi = NULL;
1211 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1215 i40e_free_tx_resources(&tx_rings[i]);
1225 /* alloc updated Rx resources */
1226 if (new_rx_count != vsi->rx_rings[0]->count) {
1228 "Changing Rx descriptor count from %d to %d\n",
1229 vsi->rx_rings[0]->count, new_rx_count);
1230 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1231 sizeof(struct i40e_ring), GFP_KERNEL);
1237 for (i = 0; i < vsi->num_queue_pairs; i++) {
1238 /* clone ring and setup updated count */
1239 rx_rings[i] = *vsi->rx_rings[i];
1240 rx_rings[i].count = new_rx_count;
1241 /* the desc and bi pointers will be reallocated in the
1244 rx_rings[i].desc = NULL;
1245 rx_rings[i].rx_bi = NULL;
1246 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1250 i40e_free_rx_resources(&rx_rings[i]);
1260 /* Bring interface down, copy in the new ring info,
1261 * then restore the interface
1266 for (i = 0; i < vsi->num_queue_pairs; i++) {
1267 i40e_free_tx_resources(vsi->tx_rings[i]);
1268 *vsi->tx_rings[i] = tx_rings[i];
1275 for (i = 0; i < vsi->num_queue_pairs; i++) {
1276 i40e_free_rx_resources(vsi->rx_rings[i]);
1277 *vsi->rx_rings[i] = rx_rings[i];
1286 /* error cleanup if the Rx allocations failed after getting Tx */
1288 for (i = 0; i < vsi->num_queue_pairs; i++)
1289 i40e_free_tx_resources(&tx_rings[i]);
1295 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1300 static int i40e_get_sset_count(struct net_device *netdev, int sset)
1302 struct i40e_netdev_priv *np = netdev_priv(netdev);
1303 struct i40e_vsi *vsi = np->vsi;
1304 struct i40e_pf *pf = vsi->back;
1308 return I40E_TEST_LEN;
1310 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
1311 int len = I40E_PF_STATS_LEN(netdev);
1313 if ((pf->lan_veb != I40E_NO_VEB) &&
1314 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
1315 len += I40E_VEB_STATS_TOTAL;
1318 return I40E_VSI_STATS_LEN(netdev);
1320 case ETH_SS_PRIV_FLAGS:
1321 return I40E_PRIV_FLAGS_STR_LEN;
1327 static void i40e_get_ethtool_stats(struct net_device *netdev,
1328 struct ethtool_stats *stats, u64 *data)
1330 struct i40e_netdev_priv *np = netdev_priv(netdev);
1331 struct i40e_ring *tx_ring, *rx_ring;
1332 struct i40e_vsi *vsi = np->vsi;
1333 struct i40e_pf *pf = vsi->back;
1337 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
1340 i40e_update_stats(vsi);
1342 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1343 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1344 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1345 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1347 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1348 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1349 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1350 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1353 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1354 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1355 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1356 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1360 for (j = 0; j < vsi->num_queue_pairs; j++) {
1361 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
1366 /* process Tx ring statistics */
1368 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
1369 data[i] = tx_ring->stats.packets;
1370 data[i + 1] = tx_ring->stats.bytes;
1371 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
1374 /* Rx ring is the 2nd half of the queue pair */
1375 rx_ring = &tx_ring[1];
1377 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
1378 data[i] = rx_ring->stats.packets;
1379 data[i + 1] = rx_ring->stats.bytes;
1380 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
1384 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1387 if ((pf->lan_veb != I40E_NO_VEB) &&
1388 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
1389 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1391 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1393 p += i40e_gstrings_veb_stats[j].stat_offset;
1394 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1395 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1398 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1399 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1400 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1401 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1403 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1404 data[i++] = pf->stats.priority_xon_tx[j];
1405 data[i++] = pf->stats.priority_xoff_tx[j];
1407 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1408 data[i++] = pf->stats.priority_xon_rx[j];
1409 data[i++] = pf->stats.priority_xoff_rx[j];
1411 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1412 data[i++] = pf->stats.priority_xon_2_xoff[j];
1415 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1418 struct i40e_netdev_priv *np = netdev_priv(netdev);
1419 struct i40e_vsi *vsi = np->vsi;
1420 struct i40e_pf *pf = vsi->back;
1421 char *p = (char *)data;
1424 switch (stringset) {
1426 for (i = 0; i < I40E_TEST_LEN; i++) {
1427 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1428 data += ETH_GSTRING_LEN;
1432 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1433 snprintf(p, ETH_GSTRING_LEN, "%s",
1434 i40e_gstrings_net_stats[i].stat_string);
1435 p += ETH_GSTRING_LEN;
1437 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1438 snprintf(p, ETH_GSTRING_LEN, "%s",
1439 i40e_gstrings_misc_stats[i].stat_string);
1440 p += ETH_GSTRING_LEN;
1443 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1444 snprintf(p, ETH_GSTRING_LEN, "%s",
1445 i40e_gstrings_fcoe_stats[i].stat_string);
1446 p += ETH_GSTRING_LEN;
1449 for (i = 0; i < vsi->num_queue_pairs; i++) {
1450 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1451 p += ETH_GSTRING_LEN;
1452 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1453 p += ETH_GSTRING_LEN;
1454 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1455 p += ETH_GSTRING_LEN;
1456 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1457 p += ETH_GSTRING_LEN;
1459 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1462 if ((pf->lan_veb != I40E_NO_VEB) &&
1463 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
1464 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1465 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1466 i40e_gstrings_veb_stats[i].stat_string);
1467 p += ETH_GSTRING_LEN;
1469 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1470 snprintf(p, ETH_GSTRING_LEN,
1471 "veb.tc_%u_tx_packets", i);
1472 p += ETH_GSTRING_LEN;
1473 snprintf(p, ETH_GSTRING_LEN,
1474 "veb.tc_%u_tx_bytes", i);
1475 p += ETH_GSTRING_LEN;
1476 snprintf(p, ETH_GSTRING_LEN,
1477 "veb.tc_%u_rx_packets", i);
1478 p += ETH_GSTRING_LEN;
1479 snprintf(p, ETH_GSTRING_LEN,
1480 "veb.tc_%u_rx_bytes", i);
1481 p += ETH_GSTRING_LEN;
1484 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1485 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1486 i40e_gstrings_stats[i].stat_string);
1487 p += ETH_GSTRING_LEN;
1489 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1490 snprintf(p, ETH_GSTRING_LEN,
1491 "port.tx_priority_%u_xon", i);
1492 p += ETH_GSTRING_LEN;
1493 snprintf(p, ETH_GSTRING_LEN,
1494 "port.tx_priority_%u_xoff", i);
1495 p += ETH_GSTRING_LEN;
1497 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1498 snprintf(p, ETH_GSTRING_LEN,
1499 "port.rx_priority_%u_xon", i);
1500 p += ETH_GSTRING_LEN;
1501 snprintf(p, ETH_GSTRING_LEN,
1502 "port.rx_priority_%u_xoff", i);
1503 p += ETH_GSTRING_LEN;
1505 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1506 snprintf(p, ETH_GSTRING_LEN,
1507 "port.rx_priority_%u_xon_2_xoff", i);
1508 p += ETH_GSTRING_LEN;
1510 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1512 case ETH_SS_PRIV_FLAGS:
1513 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1514 memcpy(data, i40e_priv_flags_strings[i],
1516 data += ETH_GSTRING_LEN;
1524 static int i40e_get_ts_info(struct net_device *dev,
1525 struct ethtool_ts_info *info)
1527 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1529 /* only report HW timestamping if PTP is enabled */
1530 if (!(pf->flags & I40E_FLAG_PTP))
1531 return ethtool_op_get_ts_info(dev, info);
1533 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1534 SOF_TIMESTAMPING_RX_SOFTWARE |
1535 SOF_TIMESTAMPING_SOFTWARE |
1536 SOF_TIMESTAMPING_TX_HARDWARE |
1537 SOF_TIMESTAMPING_RX_HARDWARE |
1538 SOF_TIMESTAMPING_RAW_HARDWARE;
1541 info->phc_index = ptp_clock_index(pf->ptp_clock);
1543 info->phc_index = -1;
1545 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
1547 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1548 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1549 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
1554 static int i40e_link_test(struct net_device *netdev, u64 *data)
1556 struct i40e_netdev_priv *np = netdev_priv(netdev);
1557 struct i40e_pf *pf = np->vsi->back;
1559 bool link_up = false;
1561 netif_info(pf, hw, netdev, "link test\n");
1562 status = i40e_get_link_status(&pf->hw, &link_up);
1564 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1577 static int i40e_reg_test(struct net_device *netdev, u64 *data)
1579 struct i40e_netdev_priv *np = netdev_priv(netdev);
1580 struct i40e_pf *pf = np->vsi->back;
1582 netif_info(pf, hw, netdev, "register test\n");
1583 *data = i40e_diag_reg_test(&pf->hw);
1588 static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
1590 struct i40e_netdev_priv *np = netdev_priv(netdev);
1591 struct i40e_pf *pf = np->vsi->back;
1593 netif_info(pf, hw, netdev, "eeprom test\n");
1594 *data = i40e_diag_eeprom_test(&pf->hw);
1596 /* forcebly clear the NVM Update state machine */
1597 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1602 static int i40e_intr_test(struct net_device *netdev, u64 *data)
1604 struct i40e_netdev_priv *np = netdev_priv(netdev);
1605 struct i40e_pf *pf = np->vsi->back;
1606 u16 swc_old = pf->sw_int_count;
1608 netif_info(pf, hw, netdev, "interrupt test\n");
1609 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1610 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1611 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1612 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1613 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1614 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
1615 usleep_range(1000, 2000);
1616 *data = (swc_old == pf->sw_int_count);
1621 static int i40e_loopback_test(struct net_device *netdev, u64 *data)
1623 struct i40e_netdev_priv *np = netdev_priv(netdev);
1624 struct i40e_pf *pf = np->vsi->back;
1626 netif_info(pf, hw, netdev, "loopback test not implemented\n");
1632 static inline bool i40e_active_vfs(struct i40e_pf *pf)
1634 struct i40e_vf *vfs = pf->vf;
1637 for (i = 0; i < pf->num_alloc_vfs; i++)
1638 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
1643 static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1645 struct i40e_vsi **vsi = pf->vsi;
1648 for (i = 0; i < pf->num_alloc_vsi; i++) {
1651 if (vsi[i]->type == I40E_VSI_VMDQ2)
1658 static void i40e_diag_test(struct net_device *netdev,
1659 struct ethtool_test *eth_test, u64 *data)
1661 struct i40e_netdev_priv *np = netdev_priv(netdev);
1662 bool if_running = netif_running(netdev);
1663 struct i40e_pf *pf = np->vsi->back;
1665 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1667 netif_info(pf, drv, netdev, "offline testing starting\n");
1669 set_bit(__I40E_TESTING, &pf->state);
1671 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
1672 dev_warn(&pf->pdev->dev,
1673 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
1674 data[I40E_ETH_TEST_REG] = 1;
1675 data[I40E_ETH_TEST_EEPROM] = 1;
1676 data[I40E_ETH_TEST_INTR] = 1;
1677 data[I40E_ETH_TEST_LOOPBACK] = 1;
1678 data[I40E_ETH_TEST_LINK] = 1;
1679 eth_test->flags |= ETH_TEST_FL_FAILED;
1680 clear_bit(__I40E_TESTING, &pf->state);
1684 /* If the device is online then take it offline */
1686 /* indicate we're in test mode */
1689 /* This reset does not affect link - if it is
1690 * changed to a type of reset that does affect
1691 * link then the following link test would have
1692 * to be moved to before the reset
1694 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
1696 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1697 eth_test->flags |= ETH_TEST_FL_FAILED;
1699 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
1700 eth_test->flags |= ETH_TEST_FL_FAILED;
1702 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
1703 eth_test->flags |= ETH_TEST_FL_FAILED;
1705 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
1706 eth_test->flags |= ETH_TEST_FL_FAILED;
1708 /* run reg test last, a reset is required after it */
1709 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1710 eth_test->flags |= ETH_TEST_FL_FAILED;
1712 clear_bit(__I40E_TESTING, &pf->state);
1713 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
1719 netif_info(pf, drv, netdev, "online testing starting\n");
1721 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1722 eth_test->flags |= ETH_TEST_FL_FAILED;
1724 /* Offline only tests, not run in online; pass by default */
1725 data[I40E_ETH_TEST_REG] = 0;
1726 data[I40E_ETH_TEST_EEPROM] = 0;
1727 data[I40E_ETH_TEST_INTR] = 0;
1728 data[I40E_ETH_TEST_LOOPBACK] = 0;
1733 netif_info(pf, drv, netdev, "testing finished\n");
1736 static void i40e_get_wol(struct net_device *netdev,
1737 struct ethtool_wolinfo *wol)
1739 struct i40e_netdev_priv *np = netdev_priv(netdev);
1740 struct i40e_pf *pf = np->vsi->back;
1741 struct i40e_hw *hw = &pf->hw;
1744 /* NVM bit on means WoL disabled for the port */
1745 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1746 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
1750 wol->supported = WAKE_MAGIC;
1751 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1756 * i40e_set_wol - set the WakeOnLAN configuration
1757 * @netdev: the netdev in question
1758 * @wol: the ethtool WoL setting data
1760 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1762 struct i40e_netdev_priv *np = netdev_priv(netdev);
1763 struct i40e_pf *pf = np->vsi->back;
1764 struct i40e_vsi *vsi = np->vsi;
1765 struct i40e_hw *hw = &pf->hw;
1768 /* WoL not supported if this isn't the controlling PF on the port */
1769 if (hw->partition_id != 1) {
1770 i40e_partition_setting_complaint(pf);
1774 if (vsi != pf->vsi[pf->lan_vsi])
1777 /* NVM bit on means WoL disabled for the port */
1778 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1779 if (BIT(hw->port) & wol_nvm_bits)
1782 /* only magic packet is supported */
1783 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1786 /* is this a new value? */
1787 if (pf->wol_en != !!wol->wolopts) {
1788 pf->wol_en = !!wol->wolopts;
1789 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1795 static int i40e_set_phys_id(struct net_device *netdev,
1796 enum ethtool_phys_id_state state)
1798 struct i40e_netdev_priv *np = netdev_priv(netdev);
1799 struct i40e_pf *pf = np->vsi->back;
1800 struct i40e_hw *hw = &pf->hw;
1804 case ETHTOOL_ID_ACTIVE:
1805 pf->led_status = i40e_led_get(hw);
1808 i40e_led_set(hw, 0xF, false);
1810 case ETHTOOL_ID_OFF:
1811 i40e_led_set(hw, 0x0, false);
1813 case ETHTOOL_ID_INACTIVE:
1814 i40e_led_set(hw, pf->led_status, false);
1823 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1824 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1825 * 125us (8000 interrupts per second) == ITR(62)
1828 static int i40e_get_coalesce(struct net_device *netdev,
1829 struct ethtool_coalesce *ec)
1831 struct i40e_netdev_priv *np = netdev_priv(netdev);
1832 struct i40e_vsi *vsi = np->vsi;
1834 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1835 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1837 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
1838 ec->use_adaptive_rx_coalesce = 1;
1840 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
1841 ec->use_adaptive_tx_coalesce = 1;
1843 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1844 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1849 static int i40e_set_coalesce(struct net_device *netdev,
1850 struct ethtool_coalesce *ec)
1852 struct i40e_netdev_priv *np = netdev_priv(netdev);
1853 struct i40e_q_vector *q_vector;
1854 struct i40e_vsi *vsi = np->vsi;
1855 struct i40e_pf *pf = vsi->back;
1856 struct i40e_hw *hw = &pf->hw;
1860 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1861 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1863 vector = vsi->base_vector;
1864 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1865 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
1866 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1867 } else if (ec->rx_coalesce_usecs == 0) {
1868 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1869 if (ec->use_adaptive_rx_coalesce)
1870 netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
1872 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
1876 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1877 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
1878 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1879 } else if (ec->tx_coalesce_usecs == 0) {
1880 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1881 if (ec->use_adaptive_tx_coalesce)
1882 netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
1884 netif_info(pf, drv, netdev,
1885 "Invalid value, tx-usecs range is 0-8160\n");
1889 if (ec->use_adaptive_rx_coalesce)
1890 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1892 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1894 if (ec->use_adaptive_tx_coalesce)
1895 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1897 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
1899 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1900 q_vector = vsi->q_vectors[i];
1901 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1902 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1903 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1904 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1912 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1913 * @pf: pointer to the physical function struct
1914 * @cmd: ethtool rxnfc command
1916 * Returns Success if the flow is supported, else Invalid Input.
1918 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1922 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1923 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1924 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1927 /* Report default options for RSS on i40e */
1928 switch (cmd->flow_type) {
1931 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1932 /* fall through to add IP fields */
1934 case AH_ESP_V4_FLOW:
1938 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1942 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1943 /* fall through to add IP fields */
1945 case AH_ESP_V6_FLOW:
1949 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1959 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1960 * @pf: Pointer to the physical function struct
1961 * @cmd: The command to get or set Rx flow classification rules
1962 * @rule_locs: Array of used rule locations
1964 * This function populates both the total and actual rule count of
1965 * the ethtool flow classification command
1967 * Returns 0 on success or -EMSGSIZE if entry not found
1969 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1970 struct ethtool_rxnfc *cmd,
1973 struct i40e_fdir_filter *rule;
1974 struct hlist_node *node2;
1977 /* report total rule count */
1978 cmd->data = i40e_get_fd_cnt_all(pf);
1980 hlist_for_each_entry_safe(rule, node2,
1981 &pf->fdir_filter_list, fdir_node) {
1982 if (cnt == cmd->rule_cnt)
1985 rule_locs[cnt] = rule->fd_id;
1989 cmd->rule_cnt = cnt;
1995 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1996 * @pf: Pointer to the physical function struct
1997 * @cmd: The command to get or set Rx flow classification rules
1999 * This function looks up a filter based on the Rx flow classification
2000 * command and fills the flow spec info for it if found
2002 * Returns 0 on success or -EINVAL if filter not found
2004 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2005 struct ethtool_rxnfc *cmd)
2007 struct ethtool_rx_flow_spec *fsp =
2008 (struct ethtool_rx_flow_spec *)&cmd->fs;
2009 struct i40e_fdir_filter *rule = NULL;
2010 struct hlist_node *node2;
2012 hlist_for_each_entry_safe(rule, node2,
2013 &pf->fdir_filter_list, fdir_node) {
2014 if (fsp->location <= rule->fd_id)
2018 if (!rule || fsp->location != rule->fd_id)
2021 fsp->flow_type = rule->flow_type;
2022 if (fsp->flow_type == IP_USER_FLOW) {
2023 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2024 fsp->h_u.usr_ip4_spec.proto = 0;
2025 fsp->m_u.usr_ip4_spec.proto = 0;
2028 /* Reverse the src and dest notion, since the HW views them from
2029 * Tx perspective where as the user expects it from Rx filter view.
2031 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2032 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2033 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2034 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
2036 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2037 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2039 fsp->ring_cookie = rule->q_index;
2041 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2042 struct i40e_vsi *vsi;
2044 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2045 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2046 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2047 fsp->m_ext.data[1] = htonl(0x1);
2055 * i40e_get_rxnfc - command to get RX flow classification rules
2056 * @netdev: network interface device structure
2057 * @cmd: ethtool rxnfc command
2059 * Returns Success if the command is supported.
2061 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2064 struct i40e_netdev_priv *np = netdev_priv(netdev);
2065 struct i40e_vsi *vsi = np->vsi;
2066 struct i40e_pf *pf = vsi->back;
2067 int ret = -EOPNOTSUPP;
2070 case ETHTOOL_GRXRINGS:
2071 cmd->data = vsi->alloc_queue_pairs;
2075 ret = i40e_get_rss_hash_opts(pf, cmd);
2077 case ETHTOOL_GRXCLSRLCNT:
2078 cmd->rule_cnt = pf->fdir_pf_active_filters;
2079 /* report total rule count */
2080 cmd->data = i40e_get_fd_cnt_all(pf);
2083 case ETHTOOL_GRXCLSRULE:
2084 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
2086 case ETHTOOL_GRXCLSRLALL:
2087 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2097 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2098 * @pf: pointer to the physical function struct
2099 * @cmd: ethtool rxnfc command
2101 * Returns Success if the flow input set is supported.
2103 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2105 struct i40e_hw *hw = &pf->hw;
2106 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2107 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2109 /* RSS does not support anything other than hashing
2110 * to queues on src and dst IPs and ports
2112 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2113 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2116 /* We need at least the IP SRC and DEST fields for hashing */
2117 if (!(nfc->data & RXH_IP_SRC) ||
2118 !(nfc->data & RXH_IP_DST))
2121 switch (nfc->flow_type) {
2123 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2125 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2127 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2128 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2135 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2137 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2139 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2140 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2147 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2149 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2150 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
2152 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2153 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2154 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
2161 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2163 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2164 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
2166 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2167 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2168 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
2174 case AH_ESP_V4_FLOW:
2178 if ((nfc->data & RXH_L4_B_0_1) ||
2179 (nfc->data & RXH_L4_B_2_3))
2181 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2183 case AH_ESP_V6_FLOW:
2187 if ((nfc->data & RXH_L4_B_0_1) ||
2188 (nfc->data & RXH_L4_B_2_3))
2190 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2193 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2194 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
2197 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2198 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
2204 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2205 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2208 /* Save setting for future output/update */
2209 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2215 * i40e_match_fdir_input_set - Match a new filter against an existing one
2216 * @rule: The filter already added
2217 * @input: The new filter to comapre against
2219 * Returns true if the two input set match
2221 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2222 struct i40e_fdir_filter *input)
2224 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2225 (rule->src_ip[0] != input->src_ip[0]) ||
2226 (rule->dst_port != input->dst_port) ||
2227 (rule->src_port != input->src_port))
2233 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2234 * @vsi: Pointer to the targeted VSI
2235 * @input: The filter to update or NULL to indicate deletion
2236 * @sw_idx: Software index to the filter
2237 * @cmd: The command to get or set Rx flow classification rules
2239 * This function updates (or deletes) a Flow Director entry from
2240 * the hlist of the corresponding PF
2242 * Returns 0 on success
2244 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2245 struct i40e_fdir_filter *input,
2247 struct ethtool_rxnfc *cmd)
2249 struct i40e_fdir_filter *rule, *parent;
2250 struct i40e_pf *pf = vsi->back;
2251 struct hlist_node *node2;
2257 hlist_for_each_entry_safe(rule, node2,
2258 &pf->fdir_filter_list, fdir_node) {
2259 /* hash found, or no matching entry */
2260 if (rule->fd_id >= sw_idx)
2265 /* if there is an old rule occupying our place remove it */
2266 if (rule && (rule->fd_id == sw_idx)) {
2267 if (input && !i40e_match_fdir_input_set(rule, input))
2268 err = i40e_add_del_fdir(vsi, rule, false);
2270 err = i40e_add_del_fdir(vsi, rule, false);
2271 hlist_del(&rule->fdir_node);
2273 pf->fdir_pf_active_filters--;
2276 /* If no input this was a delete, err should be 0 if a rule was
2277 * successfully found and removed from the list else -EINVAL
2282 /* initialize node and set software index */
2283 INIT_HLIST_NODE(&input->fdir_node);
2285 /* add filter to the list */
2287 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
2289 hlist_add_head(&input->fdir_node,
2290 &pf->fdir_filter_list);
2293 pf->fdir_pf_active_filters++;
2299 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2300 * @vsi: Pointer to the targeted VSI
2301 * @cmd: The command to get or set Rx flow classification rules
2303 * The function removes a Flow Director filter entry from the
2304 * hlist of the corresponding PF
2306 * Returns 0 on success
2308 static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2309 struct ethtool_rxnfc *cmd)
2311 struct ethtool_rx_flow_spec *fsp =
2312 (struct ethtool_rx_flow_spec *)&cmd->fs;
2313 struct i40e_pf *pf = vsi->back;
2316 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2317 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2320 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2323 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
2325 i40e_fdir_check_and_reenable(pf);
2330 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
2331 * @vsi: pointer to the targeted VSI
2332 * @cmd: command to get or set RX flow classification rules
2334 * Add Flow Director filters for a specific flow spec based on their
2335 * protocol. Returns 0 if the filters were successfully added.
2337 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2338 struct ethtool_rxnfc *cmd)
2340 struct ethtool_rx_flow_spec *fsp;
2341 struct i40e_fdir_filter *input;
2351 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2354 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
2357 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2358 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2361 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2364 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2366 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2367 pf->hw.func_caps.fd_filters_guaranteed)) {
2371 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2372 (fsp->ring_cookie >= vsi->num_queue_pairs))
2375 input = kzalloc(sizeof(*input), GFP_KERNEL);
2380 input->fd_id = fsp->location;
2382 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2383 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2386 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2388 input->q_index = fsp->ring_cookie;
2389 input->flex_off = 0;
2391 input->dest_vsi = vsi->id;
2392 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
2393 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
2394 input->flow_type = fsp->flow_type;
2395 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
2397 /* Reverse the src and dest notion, since the HW expects them to be from
2398 * Tx perspective where as the input from user is from Rx filter view.
2400 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2401 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2402 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2403 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
2405 if (ntohl(fsp->m_ext.data[1])) {
2406 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2407 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2410 vf_id = ntohl(fsp->h_ext.data[1]);
2411 /* Find vsi id from vf id and override dest vsi */
2412 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2413 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2414 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2419 ret = i40e_add_del_fdir(vsi, input, true);
2424 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
2430 * i40e_set_rxnfc - command to set RX flow classification rules
2431 * @netdev: network interface device structure
2432 * @cmd: ethtool rxnfc command
2434 * Returns Success if the command is supported.
2436 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2438 struct i40e_netdev_priv *np = netdev_priv(netdev);
2439 struct i40e_vsi *vsi = np->vsi;
2440 struct i40e_pf *pf = vsi->back;
2441 int ret = -EOPNOTSUPP;
2445 ret = i40e_set_rss_hash_opt(pf, cmd);
2447 case ETHTOOL_SRXCLSRLINS:
2448 ret = i40e_add_fdir_ethtool(vsi, cmd);
2450 case ETHTOOL_SRXCLSRLDEL:
2451 ret = i40e_del_fdir_entry(vsi, cmd);
2461 * i40e_max_channels - get Max number of combined channels supported
2464 static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2466 /* TODO: This code assumes DCB and FD is disabled for now. */
2467 return vsi->alloc_queue_pairs;
2471 * i40e_get_channels - Get the current channels enabled and max supported etc.
2472 * @netdev: network interface device structure
2473 * @ch: ethtool channels structure
2475 * We don't support separate tx and rx queues as channels. The other count
2476 * represents how many queues are being used for control. max_combined counts
2477 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2478 * q_vectors since we support a lot more queue pairs than q_vectors.
2480 static void i40e_get_channels(struct net_device *dev,
2481 struct ethtool_channels *ch)
2483 struct i40e_netdev_priv *np = netdev_priv(dev);
2484 struct i40e_vsi *vsi = np->vsi;
2485 struct i40e_pf *pf = vsi->back;
2487 /* report maximum channels */
2488 ch->max_combined = i40e_max_channels(vsi);
2490 /* report info for other vector */
2491 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
2492 ch->max_other = ch->other_count;
2494 /* Note: This code assumes DCB is disabled for now. */
2495 ch->combined_count = vsi->num_queue_pairs;
2499 * i40e_set_channels - Set the new channels count.
2500 * @netdev: network interface device structure
2501 * @ch: ethtool channels structure
2503 * The new channels count may not be the same as requested by the user
2504 * since it gets rounded down to a power of 2 value.
2506 static int i40e_set_channels(struct net_device *dev,
2507 struct ethtool_channels *ch)
2509 struct i40e_netdev_priv *np = netdev_priv(dev);
2510 unsigned int count = ch->combined_count;
2511 struct i40e_vsi *vsi = np->vsi;
2512 struct i40e_pf *pf = vsi->back;
2515 /* We do not support setting channels for any other VSI at present */
2516 if (vsi->type != I40E_VSI_MAIN)
2519 /* verify they are not requesting separate vectors */
2520 if (!count || ch->rx_count || ch->tx_count)
2523 /* verify other_count has not changed */
2524 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
2527 /* verify the number of channels does not exceed hardware limits */
2528 if (count > i40e_max_channels(vsi))
2531 /* update feature limits from largest to smallest supported values */
2532 /* TODO: Flow director limit, DCB etc */
2534 /* use rss_reconfig to rebuild with new queue count and update traffic
2535 * class queue mapping
2537 new_count = i40e_reconfig_rss_queues(pf, count);
2544 #define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2546 * i40e_get_rxfh_key_size - get the RSS hash key size
2547 * @netdev: network interface device structure
2549 * Returns the table size.
2551 static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2553 return I40E_HKEY_ARRAY_SIZE;
2557 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2558 * @netdev: network interface device structure
2560 * Returns the table size.
2562 static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2564 return I40E_HLUT_ARRAY_SIZE;
2567 static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2570 struct i40e_netdev_priv *np = netdev_priv(netdev);
2571 struct i40e_vsi *vsi = np->vsi;
2572 struct i40e_pf *pf = vsi->back;
2573 struct i40e_hw *hw = &pf->hw;
2578 *hfunc = ETH_RSS_HASH_TOP;
2583 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2584 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2585 indir[j++] = reg_val & 0xff;
2586 indir[j++] = (reg_val >> 8) & 0xff;
2587 indir[j++] = (reg_val >> 16) & 0xff;
2588 indir[j++] = (reg_val >> 24) & 0xff;
2592 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2593 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2594 key[j++] = (u8)(reg_val & 0xff);
2595 key[j++] = (u8)((reg_val >> 8) & 0xff);
2596 key[j++] = (u8)((reg_val >> 16) & 0xff);
2597 key[j++] = (u8)((reg_val >> 24) & 0xff);
2604 * i40e_set_rxfh - set the rx flow hash indirection table
2605 * @netdev: network interface device structure
2606 * @indir: indirection table
2609 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
2610 * returns 0 after programming the table.
2612 static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2613 const u8 *key, const u8 hfunc)
2615 struct i40e_netdev_priv *np = netdev_priv(netdev);
2616 struct i40e_vsi *vsi = np->vsi;
2617 struct i40e_pf *pf = vsi->back;
2618 struct i40e_hw *hw = &pf->hw;
2622 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2628 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2629 reg_val = indir[j++];
2630 reg_val |= indir[j++] << 8;
2631 reg_val |= indir[j++] << 16;
2632 reg_val |= indir[j++] << 24;
2633 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2637 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2639 reg_val |= key[j++] << 8;
2640 reg_val |= key[j++] << 16;
2641 reg_val |= key[j++] << 24;
2642 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2649 * i40e_get_priv_flags - report device private flags
2650 * @dev: network interface device structure
2652 * The get string set count and the string set should be matched for each
2653 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2656 * Returns a u32 bitmap of flags.
2658 static u32 i40e_get_priv_flags(struct net_device *dev)
2660 struct i40e_netdev_priv *np = netdev_priv(dev);
2661 struct i40e_vsi *vsi = np->vsi;
2662 struct i40e_pf *pf = vsi->back;
2665 ret_flags |= pf->hw.func_caps.npar_enable ?
2666 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2667 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2668 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
2674 * i40e_set_priv_flags - set private flags
2675 * @dev: network interface device structure
2676 * @flags: bit flags to be set
2678 static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2680 struct i40e_netdev_priv *np = netdev_priv(dev);
2681 struct i40e_vsi *vsi = np->vsi;
2682 struct i40e_pf *pf = vsi->back;
2684 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2685 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2687 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2692 static const struct ethtool_ops i40e_ethtool_ops = {
2693 .get_settings = i40e_get_settings,
2694 .set_settings = i40e_set_settings,
2695 .get_drvinfo = i40e_get_drvinfo,
2696 .get_regs_len = i40e_get_regs_len,
2697 .get_regs = i40e_get_regs,
2698 .nway_reset = i40e_nway_reset,
2699 .get_link = ethtool_op_get_link,
2700 .get_wol = i40e_get_wol,
2701 .set_wol = i40e_set_wol,
2702 .set_eeprom = i40e_set_eeprom,
2703 .get_eeprom_len = i40e_get_eeprom_len,
2704 .get_eeprom = i40e_get_eeprom,
2705 .get_ringparam = i40e_get_ringparam,
2706 .set_ringparam = i40e_set_ringparam,
2707 .get_pauseparam = i40e_get_pauseparam,
2708 .set_pauseparam = i40e_set_pauseparam,
2709 .get_msglevel = i40e_get_msglevel,
2710 .set_msglevel = i40e_set_msglevel,
2711 .get_rxnfc = i40e_get_rxnfc,
2712 .set_rxnfc = i40e_set_rxnfc,
2713 .self_test = i40e_diag_test,
2714 .get_strings = i40e_get_strings,
2715 .set_phys_id = i40e_set_phys_id,
2716 .get_sset_count = i40e_get_sset_count,
2717 .get_ethtool_stats = i40e_get_ethtool_stats,
2718 .get_coalesce = i40e_get_coalesce,
2719 .set_coalesce = i40e_set_coalesce,
2720 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2721 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2722 .get_rxfh = i40e_get_rxfh,
2723 .set_rxfh = i40e_set_rxfh,
2724 .get_channels = i40e_get_channels,
2725 .set_channels = i40e_set_channels,
2726 .get_ts_info = i40e_get_ts_info,
2727 .get_priv_flags = i40e_get_priv_flags,
2728 .set_priv_flags = i40e_set_priv_flags,
2731 void i40e_set_ethtool_ops(struct net_device *netdev)
2733 netdev->ethtool_ops = &i40e_ethtool_ops;