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 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
94 * but they are separate. This device supports Virtualization, and
95 * as such might have several netdevs supporting VMDq and FCoE going
96 * through a single port. The NETDEV_STATs are for individual netdevs
97 * seen at the top of the stack, and the PF_STATs are for the physical
98 * function at the bottom of the stack hosting those netdevs.
100 * The PF_STATs are appended to the netdev stats only when ethtool -S
101 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
103 static struct i40e_stats i40e_gstrings_stats[] = {
104 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
105 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
106 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
107 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
108 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
109 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
110 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
111 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
112 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
113 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
114 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
115 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
116 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
117 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
118 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
119 I40E_PF_STAT("tx_timeout", tx_timeout_count),
120 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
121 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
122 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
123 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
124 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
125 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
126 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
127 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
128 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
129 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
130 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
131 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
132 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
133 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
134 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
135 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
136 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
137 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
138 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
139 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
140 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
141 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
142 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
143 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
144 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
145 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
146 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
147 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
148 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
149 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
150 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
151 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
154 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
155 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
156 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
157 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
161 static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
162 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
163 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
164 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
165 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
166 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
167 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
168 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
169 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
172 #endif /* I40E_FCOE */
173 #define I40E_QUEUE_STATS_LEN(n) \
174 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
175 * 2 /* Tx and Rx together */ \
176 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
177 #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
178 #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
179 #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
181 #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
182 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
183 I40E_FCOE_STATS_LEN + \
184 I40E_MISC_STATS_LEN + \
185 I40E_QUEUE_STATS_LEN((n)))
187 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
188 I40E_MISC_STATS_LEN + \
189 I40E_QUEUE_STATS_LEN((n)))
190 #endif /* I40E_FCOE */
191 #define I40E_PFC_STATS_LEN ( \
192 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
198 #define I40E_VEB_TC_STATS_LEN ( \
199 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
200 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
201 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
202 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
204 #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
205 #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
206 #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
207 I40E_PFC_STATS_LEN + \
208 I40E_VSI_STATS_LEN((n)))
210 enum i40e_ethtool_test_id {
211 I40E_ETH_TEST_REG = 0,
212 I40E_ETH_TEST_EEPROM,
214 I40E_ETH_TEST_LOOPBACK,
218 static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
219 "Register test (offline)",
220 "Eeprom test (offline)",
221 "Interrupt test (offline)",
222 "Loopback test (offline)",
223 "Link test (on/offline)"
226 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
228 static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
234 #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
237 * i40e_partition_setting_complaint - generic complaint for MFP restriction
240 static void i40e_partition_setting_complaint(struct i40e_pf *pf)
242 dev_info(&pf->pdev->dev,
243 "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");
247 * i40e_get_settings_link_up - Get the Link settings for when link is up
249 * @ecmd: ethtool command to fill in
250 * @netdev: network interface device structure
253 static void i40e_get_settings_link_up(struct i40e_hw *hw,
254 struct ethtool_cmd *ecmd,
255 struct net_device *netdev,
258 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
259 u32 link_speed = hw_link_info->link_speed;
261 /* Initialize supported and advertised settings based on phy settings */
262 switch (hw_link_info->phy_type) {
263 case I40E_PHY_TYPE_40GBASE_CR4:
264 case I40E_PHY_TYPE_40GBASE_CR4_CU:
265 ecmd->supported = SUPPORTED_Autoneg |
266 SUPPORTED_40000baseCR4_Full;
267 ecmd->advertising = ADVERTISED_Autoneg |
268 ADVERTISED_40000baseCR4_Full;
270 case I40E_PHY_TYPE_XLAUI:
271 case I40E_PHY_TYPE_XLPPI:
272 case I40E_PHY_TYPE_40GBASE_AOC:
273 ecmd->supported = SUPPORTED_40000baseCR4_Full;
275 case I40E_PHY_TYPE_40GBASE_SR4:
276 ecmd->supported = SUPPORTED_40000baseSR4_Full;
278 case I40E_PHY_TYPE_40GBASE_LR4:
279 ecmd->supported = SUPPORTED_40000baseLR4_Full;
281 case I40E_PHY_TYPE_10GBASE_SR:
282 case I40E_PHY_TYPE_10GBASE_LR:
283 case I40E_PHY_TYPE_1000BASE_SX:
284 case I40E_PHY_TYPE_1000BASE_LX:
285 ecmd->supported = SUPPORTED_10000baseT_Full;
286 if (hw_link_info->module_type[2] &
287 I40E_MODULE_TYPE_1000BASE_SX ||
288 hw_link_info->module_type[2] &
289 I40E_MODULE_TYPE_1000BASE_LX) {
290 ecmd->supported |= SUPPORTED_1000baseT_Full;
291 if (hw_link_info->requested_speeds &
293 ecmd->advertising |= ADVERTISED_1000baseT_Full;
295 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
296 ecmd->advertising |= ADVERTISED_10000baseT_Full;
298 case I40E_PHY_TYPE_10GBASE_T:
299 case I40E_PHY_TYPE_1000BASE_T:
300 ecmd->supported = SUPPORTED_Autoneg |
301 SUPPORTED_10000baseT_Full |
302 SUPPORTED_1000baseT_Full;
303 ecmd->advertising = ADVERTISED_Autoneg;
304 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
305 ecmd->advertising |= ADVERTISED_10000baseT_Full;
306 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
307 ecmd->advertising |= ADVERTISED_1000baseT_Full;
309 case I40E_PHY_TYPE_100BASE_TX:
310 ecmd->supported = SUPPORTED_Autoneg |
311 SUPPORTED_100baseT_Full;
312 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
313 ecmd->advertising |= ADVERTISED_100baseT_Full;
315 case I40E_PHY_TYPE_10GBASE_CR1_CU:
316 case I40E_PHY_TYPE_10GBASE_CR1:
317 ecmd->supported = SUPPORTED_Autoneg |
318 SUPPORTED_10000baseT_Full;
319 ecmd->advertising = ADVERTISED_Autoneg |
320 ADVERTISED_10000baseT_Full;
322 case I40E_PHY_TYPE_XAUI:
323 case I40E_PHY_TYPE_XFI:
324 case I40E_PHY_TYPE_SFI:
325 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
326 case I40E_PHY_TYPE_10GBASE_AOC:
327 ecmd->supported = SUPPORTED_10000baseT_Full;
329 case I40E_PHY_TYPE_SGMII:
330 ecmd->supported = SUPPORTED_Autoneg |
331 SUPPORTED_1000baseT_Full;
332 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
333 ecmd->advertising |= ADVERTISED_1000baseT_Full;
334 if (pf->hw.mac.type == I40E_MAC_X722) {
335 ecmd->supported |= SUPPORTED_100baseT_Full;
336 if (hw_link_info->requested_speeds &
337 I40E_LINK_SPEED_100MB)
338 ecmd->advertising |= ADVERTISED_100baseT_Full;
341 /* Backplane is set based on supported phy types in get_settings
342 * so don't set anything here but don't warn either
344 case I40E_PHY_TYPE_40GBASE_KR4:
345 case I40E_PHY_TYPE_20GBASE_KR2:
346 case I40E_PHY_TYPE_10GBASE_KR:
347 case I40E_PHY_TYPE_10GBASE_KX4:
348 case I40E_PHY_TYPE_1000BASE_KX:
351 /* if we got here and link is up something bad is afoot */
352 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
353 hw_link_info->phy_type);
356 /* Set speed and duplex */
357 switch (link_speed) {
358 case I40E_LINK_SPEED_40GB:
359 ethtool_cmd_speed_set(ecmd, SPEED_40000);
361 case I40E_LINK_SPEED_20GB:
362 ethtool_cmd_speed_set(ecmd, SPEED_20000);
364 case I40E_LINK_SPEED_10GB:
365 ethtool_cmd_speed_set(ecmd, SPEED_10000);
367 case I40E_LINK_SPEED_1GB:
368 ethtool_cmd_speed_set(ecmd, SPEED_1000);
370 case I40E_LINK_SPEED_100MB:
371 ethtool_cmd_speed_set(ecmd, SPEED_100);
376 ecmd->duplex = DUPLEX_FULL;
380 * i40e_get_settings_link_down - Get the Link settings for when link is down
382 * @ecmd: ethtool command to fill in
384 * Reports link settings that can be determined when link is down
386 static void i40e_get_settings_link_down(struct i40e_hw *hw,
387 struct ethtool_cmd *ecmd,
390 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
392 /* link is down and the driver needs to fall back on
393 * supported phy types to figure out what info to display
395 ecmd->supported = 0x0;
396 ecmd->advertising = 0x0;
397 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
398 ecmd->supported |= SUPPORTED_Autoneg |
399 SUPPORTED_1000baseT_Full;
400 ecmd->advertising |= ADVERTISED_Autoneg |
401 ADVERTISED_1000baseT_Full;
402 if (pf->hw.mac.type == I40E_MAC_X722) {
403 ecmd->supported |= SUPPORTED_100baseT_Full;
404 ecmd->advertising |= ADVERTISED_100baseT_Full;
407 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
408 phy_types & I40E_CAP_PHY_TYPE_XFI ||
409 phy_types & I40E_CAP_PHY_TYPE_SFI ||
410 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
411 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
412 ecmd->supported |= SUPPORTED_10000baseT_Full;
413 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
414 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
415 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
416 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
417 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
418 ecmd->supported |= SUPPORTED_Autoneg |
419 SUPPORTED_10000baseT_Full;
420 ecmd->advertising |= ADVERTISED_Autoneg |
421 ADVERTISED_10000baseT_Full;
423 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
424 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
425 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
426 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
427 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
428 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
429 ecmd->supported |= SUPPORTED_Autoneg |
430 SUPPORTED_40000baseCR4_Full;
431 ecmd->advertising |= ADVERTISED_Autoneg |
432 ADVERTISED_40000baseCR4_Full;
434 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
435 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
436 ecmd->supported |= SUPPORTED_Autoneg |
437 SUPPORTED_100baseT_Full;
438 ecmd->advertising |= ADVERTISED_Autoneg |
439 ADVERTISED_100baseT_Full;
441 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
442 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
443 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
444 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
445 ecmd->supported |= SUPPORTED_Autoneg |
446 SUPPORTED_1000baseT_Full;
447 ecmd->advertising |= ADVERTISED_Autoneg |
448 ADVERTISED_1000baseT_Full;
450 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
451 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
452 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
453 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
455 /* With no link speed and duplex are unknown */
456 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
457 ecmd->duplex = DUPLEX_UNKNOWN;
461 * i40e_get_settings - Get Link Speed and Duplex settings
462 * @netdev: network interface device structure
463 * @ecmd: ethtool command
465 * Reports speed/duplex settings based on media_type
467 static int i40e_get_settings(struct net_device *netdev,
468 struct ethtool_cmd *ecmd)
470 struct i40e_netdev_priv *np = netdev_priv(netdev);
471 struct i40e_pf *pf = np->vsi->back;
472 struct i40e_hw *hw = &pf->hw;
473 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
474 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
477 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
479 i40e_get_settings_link_down(hw, ecmd, pf);
481 /* Now set the settings that don't rely on link being up/down */
483 /* For backplane, supported and advertised are only reliant on the
484 * phy types the NVM specifies are supported.
486 if (hw->device_id == I40E_DEV_ID_KX_B ||
487 hw->device_id == I40E_DEV_ID_KX_C ||
488 hw->device_id == I40E_DEV_ID_20G_KR2 ||
489 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
490 ecmd->supported = SUPPORTED_Autoneg;
491 ecmd->advertising = ADVERTISED_Autoneg;
492 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
493 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
494 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
496 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
497 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
498 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
500 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
501 ecmd->supported |= SUPPORTED_10000baseKR_Full;
502 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
504 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
505 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
506 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
508 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
509 ecmd->supported |= SUPPORTED_1000baseKX_Full;
510 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
514 /* Set autoneg settings */
515 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
516 AUTONEG_ENABLE : AUTONEG_DISABLE);
518 switch (hw->phy.media_type) {
519 case I40E_MEDIA_TYPE_BACKPLANE:
520 ecmd->supported |= SUPPORTED_Autoneg |
522 ecmd->advertising |= ADVERTISED_Autoneg |
523 ADVERTISED_Backplane;
524 ecmd->port = PORT_NONE;
526 case I40E_MEDIA_TYPE_BASET:
527 ecmd->supported |= SUPPORTED_TP;
528 ecmd->advertising |= ADVERTISED_TP;
529 ecmd->port = PORT_TP;
531 case I40E_MEDIA_TYPE_DA:
532 case I40E_MEDIA_TYPE_CX4:
533 ecmd->supported |= SUPPORTED_FIBRE;
534 ecmd->advertising |= ADVERTISED_FIBRE;
535 ecmd->port = PORT_DA;
537 case I40E_MEDIA_TYPE_FIBER:
538 ecmd->supported |= SUPPORTED_FIBRE;
539 ecmd->port = PORT_FIBRE;
541 case I40E_MEDIA_TYPE_UNKNOWN:
543 ecmd->port = PORT_OTHER;
547 /* Set transceiver */
548 ecmd->transceiver = XCVR_EXTERNAL;
550 /* Set flow control settings */
551 ecmd->supported |= SUPPORTED_Pause;
553 switch (hw->fc.requested_mode) {
555 ecmd->advertising |= ADVERTISED_Pause;
557 case I40E_FC_TX_PAUSE:
558 ecmd->advertising |= ADVERTISED_Asym_Pause;
560 case I40E_FC_RX_PAUSE:
561 ecmd->advertising |= (ADVERTISED_Pause |
562 ADVERTISED_Asym_Pause);
565 ecmd->advertising &= ~(ADVERTISED_Pause |
566 ADVERTISED_Asym_Pause);
574 * i40e_set_settings - Set Speed and Duplex
575 * @netdev: network interface device structure
576 * @ecmd: ethtool command
578 * Set speed/duplex per media_types advertised/forced
580 static int i40e_set_settings(struct net_device *netdev,
581 struct ethtool_cmd *ecmd)
583 struct i40e_netdev_priv *np = netdev_priv(netdev);
584 struct i40e_aq_get_phy_abilities_resp abilities;
585 struct i40e_aq_set_phy_config config;
586 struct i40e_pf *pf = np->vsi->back;
587 struct i40e_vsi *vsi = np->vsi;
588 struct i40e_hw *hw = &pf->hw;
589 struct ethtool_cmd safe_ecmd;
590 i40e_status status = 0;
596 /* Changing port settings is not supported if this isn't the
597 * port's controlling PF
599 if (hw->partition_id != 1) {
600 i40e_partition_setting_complaint(pf);
604 if (vsi != pf->vsi[pf->lan_vsi])
607 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
608 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
609 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
610 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
613 if (hw->device_id == I40E_DEV_ID_KX_B ||
614 hw->device_id == I40E_DEV_ID_KX_C ||
615 hw->device_id == I40E_DEV_ID_20G_KR2 ||
616 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
617 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
621 /* get our own copy of the bits to check against */
622 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
623 i40e_get_settings(netdev, &safe_ecmd);
625 /* save autoneg and speed out of ecmd */
626 autoneg = ecmd->autoneg;
627 advertise = ecmd->advertising;
629 /* set autoneg and speed back to what they currently are */
630 ecmd->autoneg = safe_ecmd.autoneg;
631 ecmd->advertising = safe_ecmd.advertising;
633 ecmd->cmd = safe_ecmd.cmd;
634 /* If ecmd and safe_ecmd are not the same now, then they are
635 * trying to set something that we do not support
637 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
640 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
641 usleep_range(1000, 2000);
643 /* Get the current phy config */
644 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
649 /* Copy abilities to config in case autoneg is not
652 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
653 config.abilities = abilities.abilities;
656 if (autoneg == AUTONEG_ENABLE) {
657 /* If autoneg is not supported, return error */
658 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
659 netdev_info(netdev, "Autoneg not supported on this phy\n");
662 /* If autoneg was not already enabled */
663 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
664 config.abilities = abilities.abilities |
665 I40E_AQ_PHY_ENABLE_AN;
669 /* If autoneg is supported 10GBASE_T is the only phy that
670 * can disable it, so otherwise return error
672 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
673 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
674 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
677 /* If autoneg is currently enabled */
678 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
679 config.abilities = abilities.abilities &
680 ~I40E_AQ_PHY_ENABLE_AN;
685 if (advertise & ~safe_ecmd.supported)
688 if (advertise & ADVERTISED_100baseT_Full)
689 config.link_speed |= I40E_LINK_SPEED_100MB;
690 if (advertise & ADVERTISED_1000baseT_Full ||
691 advertise & ADVERTISED_1000baseKX_Full)
692 config.link_speed |= I40E_LINK_SPEED_1GB;
693 if (advertise & ADVERTISED_10000baseT_Full ||
694 advertise & ADVERTISED_10000baseKX4_Full ||
695 advertise & ADVERTISED_10000baseKR_Full)
696 config.link_speed |= I40E_LINK_SPEED_10GB;
697 if (advertise & ADVERTISED_20000baseKR2_Full)
698 config.link_speed |= I40E_LINK_SPEED_20GB;
699 if (advertise & ADVERTISED_40000baseKR4_Full ||
700 advertise & ADVERTISED_40000baseCR4_Full ||
701 advertise & ADVERTISED_40000baseSR4_Full ||
702 advertise & ADVERTISED_40000baseLR4_Full)
703 config.link_speed |= I40E_LINK_SPEED_40GB;
705 /* If speed didn't get set, set it to what it currently is.
706 * This is needed because if advertise is 0 (as it is when autoneg
707 * is disabled) then speed won't get set.
709 if (!config.link_speed)
710 config.link_speed = abilities.link_speed;
712 if (change || (abilities.link_speed != config.link_speed)) {
713 /* copy over the rest of the abilities */
714 config.phy_type = abilities.phy_type;
715 config.eee_capability = abilities.eee_capability;
716 config.eeer = abilities.eeer_val;
717 config.low_power_ctrl = abilities.d3_lpan;
719 /* save the requested speeds */
720 hw->phy.link_info.requested_speeds = config.link_speed;
721 /* set link and auto negotiation so changes take effect */
722 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
723 /* If link is up put link down */
724 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
725 /* Tell the OS link is going down, the link will go
726 * back up when fw says it is ready asynchronously
728 i40e_print_link_message(vsi, false);
729 netif_carrier_off(netdev);
730 netif_tx_stop_all_queues(netdev);
733 /* make the aq call */
734 status = i40e_aq_set_phy_config(hw, &config, NULL);
736 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
737 i40e_stat_str(hw, status),
738 i40e_aq_str(hw, hw->aq.asq_last_status));
742 status = i40e_update_link_info(hw);
744 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
745 i40e_stat_str(hw, status),
746 i40e_aq_str(hw, hw->aq.asq_last_status));
749 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
755 static int i40e_nway_reset(struct net_device *netdev)
757 /* restart autonegotiation */
758 struct i40e_netdev_priv *np = netdev_priv(netdev);
759 struct i40e_pf *pf = np->vsi->back;
760 struct i40e_hw *hw = &pf->hw;
761 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
764 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
766 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
767 i40e_stat_str(hw, ret),
768 i40e_aq_str(hw, hw->aq.asq_last_status));
776 * i40e_get_pauseparam - Get Flow Control status
777 * Return tx/rx-pause status
779 static void i40e_get_pauseparam(struct net_device *netdev,
780 struct ethtool_pauseparam *pause)
782 struct i40e_netdev_priv *np = netdev_priv(netdev);
783 struct i40e_pf *pf = np->vsi->back;
784 struct i40e_hw *hw = &pf->hw;
785 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
786 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
789 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
790 AUTONEG_ENABLE : AUTONEG_DISABLE);
792 /* PFC enabled so report LFC as off */
793 if (dcbx_cfg->pfc.pfcenable) {
799 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
801 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
803 } else if (hw->fc.current_mode == I40E_FC_FULL) {
810 * i40e_set_pauseparam - Set Flow Control parameter
811 * @netdev: network interface device structure
812 * @pause: return tx/rx flow control status
814 static int i40e_set_pauseparam(struct net_device *netdev,
815 struct ethtool_pauseparam *pause)
817 struct i40e_netdev_priv *np = netdev_priv(netdev);
818 struct i40e_pf *pf = np->vsi->back;
819 struct i40e_vsi *vsi = np->vsi;
820 struct i40e_hw *hw = &pf->hw;
821 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
822 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
823 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
828 /* Changing the port's flow control is not supported if this isn't the
829 * port's controlling PF
831 if (hw->partition_id != 1) {
832 i40e_partition_setting_complaint(pf);
836 if (vsi != pf->vsi[pf->lan_vsi])
839 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
840 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
841 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
845 /* If we have link and don't have autoneg */
846 if (!test_bit(__I40E_DOWN, &pf->state) &&
847 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
848 /* Send message that it might not necessarily work*/
849 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
852 if (dcbx_cfg->pfc.pfcenable) {
854 "Priority flow control enabled. Cannot set link flow control.\n");
858 if (pause->rx_pause && pause->tx_pause)
859 hw->fc.requested_mode = I40E_FC_FULL;
860 else if (pause->rx_pause && !pause->tx_pause)
861 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
862 else if (!pause->rx_pause && pause->tx_pause)
863 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
864 else if (!pause->rx_pause && !pause->tx_pause)
865 hw->fc.requested_mode = I40E_FC_NONE;
869 /* Tell the OS link is going down, the link will go back up when fw
870 * says it is ready asynchronously
872 i40e_print_link_message(vsi, false);
873 netif_carrier_off(netdev);
874 netif_tx_stop_all_queues(netdev);
876 /* Set the fc mode and only restart an if link is up*/
877 status = i40e_set_fc(hw, &aq_failures, link_up);
879 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
880 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
881 i40e_stat_str(hw, status),
882 i40e_aq_str(hw, hw->aq.asq_last_status));
885 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
886 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
887 i40e_stat_str(hw, status),
888 i40e_aq_str(hw, hw->aq.asq_last_status));
891 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
892 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
893 i40e_stat_str(hw, status),
894 i40e_aq_str(hw, hw->aq.asq_last_status));
898 if (!test_bit(__I40E_DOWN, &pf->state)) {
899 /* Give it a little more time to try to come back */
901 if (!test_bit(__I40E_DOWN, &pf->state))
902 return i40e_nway_reset(netdev);
908 static u32 i40e_get_msglevel(struct net_device *netdev)
910 struct i40e_netdev_priv *np = netdev_priv(netdev);
911 struct i40e_pf *pf = np->vsi->back;
913 return pf->msg_enable;
916 static void i40e_set_msglevel(struct net_device *netdev, u32 data)
918 struct i40e_netdev_priv *np = netdev_priv(netdev);
919 struct i40e_pf *pf = np->vsi->back;
921 if (I40E_DEBUG_USER & data)
922 pf->hw.debug_mask = data;
923 pf->msg_enable = data;
926 static int i40e_get_regs_len(struct net_device *netdev)
931 for (i = 0; i40e_reg_list[i].offset != 0; i++)
932 reg_count += i40e_reg_list[i].elements;
934 return reg_count * sizeof(u32);
937 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
940 struct i40e_netdev_priv *np = netdev_priv(netdev);
941 struct i40e_pf *pf = np->vsi->back;
942 struct i40e_hw *hw = &pf->hw;
947 /* Tell ethtool which driver-version-specific regs output we have.
949 * At some point, if we have ethtool doing special formatting of
950 * this data, it will rely on this version number to know how to
951 * interpret things. Hence, this needs to be updated if/when the
952 * diags register table is changed.
956 /* loop through the diags reg table for what to print */
958 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
959 for (j = 0; j < i40e_reg_list[i].elements; j++) {
960 reg = i40e_reg_list[i].offset
961 + (j * i40e_reg_list[i].stride);
962 reg_buf[ri++] = rd32(hw, reg);
968 static int i40e_get_eeprom(struct net_device *netdev,
969 struct ethtool_eeprom *eeprom, u8 *bytes)
971 struct i40e_netdev_priv *np = netdev_priv(netdev);
972 struct i40e_hw *hw = &np->vsi->back->hw;
973 struct i40e_pf *pf = np->vsi->back;
974 int ret_val = 0, len, offset;
980 #define I40E_NVM_SECTOR_SIZE 4096
981 if (eeprom->len == 0)
984 /* check for NVMUpdate access method */
985 magic = hw->vendor_id | (hw->device_id << 16);
986 if (eeprom->magic && eeprom->magic != magic) {
987 struct i40e_nvm_access *cmd;
990 /* make sure it is the right magic for NVMUpdate */
991 if ((eeprom->magic >> 16) != hw->device_id)
994 cmd = (struct i40e_nvm_access *)eeprom;
995 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
997 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
998 (hw->debug_mask & I40E_DEBUG_NVM)))
999 dev_info(&pf->pdev->dev,
1000 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1001 ret_val, hw->aq.asq_last_status, errno,
1002 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1003 cmd->offset, cmd->data_size);
1008 /* normal ethtool get_eeprom support */
1009 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1011 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
1015 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1017 dev_info(&pf->pdev->dev,
1018 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1019 ret_val, hw->aq.asq_last_status);
1023 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1024 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1025 len = I40E_NVM_SECTOR_SIZE;
1027 for (i = 0; i < sectors; i++) {
1028 if (i == (sectors - 1)) {
1029 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1032 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1033 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
1034 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
1036 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
1037 dev_info(&pf->pdev->dev,
1038 "read NVM failed, invalid offset 0x%x\n",
1041 } else if (ret_val &&
1042 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1043 dev_info(&pf->pdev->dev,
1044 "read NVM failed, access, offset 0x%x\n",
1047 } else if (ret_val) {
1048 dev_info(&pf->pdev->dev,
1049 "read NVM failed offset %d err=%d status=0x%x\n",
1050 offset, ret_val, hw->aq.asq_last_status);
1055 i40e_release_nvm(hw);
1056 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
1062 static int i40e_get_eeprom_len(struct net_device *netdev)
1064 struct i40e_netdev_priv *np = netdev_priv(netdev);
1065 struct i40e_hw *hw = &np->vsi->back->hw;
1068 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1069 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1070 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1071 /* register returns value in power of 2, 64Kbyte chunks. */
1072 val = (64 * 1024) * BIT(val);
1076 static int i40e_set_eeprom(struct net_device *netdev,
1077 struct ethtool_eeprom *eeprom, u8 *bytes)
1079 struct i40e_netdev_priv *np = netdev_priv(netdev);
1080 struct i40e_hw *hw = &np->vsi->back->hw;
1081 struct i40e_pf *pf = np->vsi->back;
1082 struct i40e_nvm_access *cmd;
1087 /* normal ethtool set_eeprom is not supported */
1088 magic = hw->vendor_id | (hw->device_id << 16);
1089 if (eeprom->magic == magic)
1092 /* check for NVMUpdate access method */
1093 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1096 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1097 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1100 cmd = (struct i40e_nvm_access *)eeprom;
1101 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1103 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1104 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1105 (hw->debug_mask & I40E_DEBUG_NVM)))
1106 dev_info(&pf->pdev->dev,
1107 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1108 ret_val, hw->aq.asq_last_status, errno,
1109 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1110 cmd->offset, cmd->data_size);
1115 static void i40e_get_drvinfo(struct net_device *netdev,
1116 struct ethtool_drvinfo *drvinfo)
1118 struct i40e_netdev_priv *np = netdev_priv(netdev);
1119 struct i40e_vsi *vsi = np->vsi;
1120 struct i40e_pf *pf = vsi->back;
1122 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1123 strlcpy(drvinfo->version, i40e_driver_version_str,
1124 sizeof(drvinfo->version));
1125 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1126 sizeof(drvinfo->fw_version));
1127 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1128 sizeof(drvinfo->bus_info));
1129 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
1132 static void i40e_get_ringparam(struct net_device *netdev,
1133 struct ethtool_ringparam *ring)
1135 struct i40e_netdev_priv *np = netdev_priv(netdev);
1136 struct i40e_pf *pf = np->vsi->back;
1137 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1139 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1140 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1141 ring->rx_mini_max_pending = 0;
1142 ring->rx_jumbo_max_pending = 0;
1143 ring->rx_pending = vsi->rx_rings[0]->count;
1144 ring->tx_pending = vsi->tx_rings[0]->count;
1145 ring->rx_mini_pending = 0;
1146 ring->rx_jumbo_pending = 0;
1149 static int i40e_set_ringparam(struct net_device *netdev,
1150 struct ethtool_ringparam *ring)
1152 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1153 struct i40e_netdev_priv *np = netdev_priv(netdev);
1154 struct i40e_vsi *vsi = np->vsi;
1155 struct i40e_pf *pf = vsi->back;
1156 u32 new_rx_count, new_tx_count;
1159 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1162 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1163 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1164 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1165 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1167 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1168 ring->tx_pending, ring->rx_pending,
1169 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1173 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1174 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1176 /* if nothing to do return success */
1177 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1178 (new_rx_count == vsi->rx_rings[0]->count))
1181 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1182 usleep_range(1000, 2000);
1184 if (!netif_running(vsi->netdev)) {
1185 /* simple case - set for the next time the netdev is started */
1186 for (i = 0; i < vsi->num_queue_pairs; i++) {
1187 vsi->tx_rings[i]->count = new_tx_count;
1188 vsi->rx_rings[i]->count = new_rx_count;
1193 /* We can't just free everything and then setup again,
1194 * because the ISRs in MSI-X mode get passed pointers
1195 * to the Tx and Rx ring structs.
1198 /* alloc updated Tx resources */
1199 if (new_tx_count != vsi->tx_rings[0]->count) {
1201 "Changing Tx descriptor count from %d to %d.\n",
1202 vsi->tx_rings[0]->count, new_tx_count);
1203 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1204 sizeof(struct i40e_ring), GFP_KERNEL);
1210 for (i = 0; i < vsi->num_queue_pairs; i++) {
1211 /* clone ring and setup updated count */
1212 tx_rings[i] = *vsi->tx_rings[i];
1213 tx_rings[i].count = new_tx_count;
1214 /* the desc and bi pointers will be reallocated in the
1217 tx_rings[i].desc = NULL;
1218 tx_rings[i].rx_bi = NULL;
1219 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1223 i40e_free_tx_resources(&tx_rings[i]);
1233 /* alloc updated Rx resources */
1234 if (new_rx_count != vsi->rx_rings[0]->count) {
1236 "Changing Rx descriptor count from %d to %d\n",
1237 vsi->rx_rings[0]->count, new_rx_count);
1238 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1239 sizeof(struct i40e_ring), GFP_KERNEL);
1245 for (i = 0; i < vsi->num_queue_pairs; i++) {
1246 /* clone ring and setup updated count */
1247 rx_rings[i] = *vsi->rx_rings[i];
1248 rx_rings[i].count = new_rx_count;
1249 /* the desc and bi pointers will be reallocated in the
1252 rx_rings[i].desc = NULL;
1253 rx_rings[i].rx_bi = NULL;
1254 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1258 i40e_free_rx_resources(&rx_rings[i]);
1268 /* Bring interface down, copy in the new ring info,
1269 * then restore the interface
1274 for (i = 0; i < vsi->num_queue_pairs; i++) {
1275 i40e_free_tx_resources(vsi->tx_rings[i]);
1276 *vsi->tx_rings[i] = tx_rings[i];
1283 for (i = 0; i < vsi->num_queue_pairs; i++) {
1284 i40e_free_rx_resources(vsi->rx_rings[i]);
1285 *vsi->rx_rings[i] = rx_rings[i];
1294 /* error cleanup if the Rx allocations failed after getting Tx */
1296 for (i = 0; i < vsi->num_queue_pairs; i++)
1297 i40e_free_tx_resources(&tx_rings[i]);
1303 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1308 static int i40e_get_sset_count(struct net_device *netdev, int sset)
1310 struct i40e_netdev_priv *np = netdev_priv(netdev);
1311 struct i40e_vsi *vsi = np->vsi;
1312 struct i40e_pf *pf = vsi->back;
1316 return I40E_TEST_LEN;
1318 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
1319 int len = I40E_PF_STATS_LEN(netdev);
1321 if ((pf->lan_veb != I40E_NO_VEB) &&
1322 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
1323 len += I40E_VEB_STATS_TOTAL;
1326 return I40E_VSI_STATS_LEN(netdev);
1328 case ETH_SS_PRIV_FLAGS:
1329 return I40E_PRIV_FLAGS_STR_LEN;
1335 static void i40e_get_ethtool_stats(struct net_device *netdev,
1336 struct ethtool_stats *stats, u64 *data)
1338 struct i40e_netdev_priv *np = netdev_priv(netdev);
1339 struct i40e_ring *tx_ring, *rx_ring;
1340 struct i40e_vsi *vsi = np->vsi;
1341 struct i40e_pf *pf = vsi->back;
1345 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
1348 i40e_update_stats(vsi);
1350 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1351 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1352 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1353 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1355 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1356 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1357 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1358 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1361 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1362 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1363 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1364 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1368 for (j = 0; j < vsi->num_queue_pairs; j++) {
1369 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
1374 /* process Tx ring statistics */
1376 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
1377 data[i] = tx_ring->stats.packets;
1378 data[i + 1] = tx_ring->stats.bytes;
1379 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
1382 /* Rx ring is the 2nd half of the queue pair */
1383 rx_ring = &tx_ring[1];
1385 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
1386 data[i] = rx_ring->stats.packets;
1387 data[i + 1] = rx_ring->stats.bytes;
1388 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
1392 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1395 if ((pf->lan_veb != I40E_NO_VEB) &&
1396 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
1397 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1399 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1401 p += i40e_gstrings_veb_stats[j].stat_offset;
1402 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1403 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1406 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1407 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1408 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1409 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1411 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1412 data[i++] = pf->stats.priority_xon_tx[j];
1413 data[i++] = pf->stats.priority_xoff_tx[j];
1415 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1416 data[i++] = pf->stats.priority_xon_rx[j];
1417 data[i++] = pf->stats.priority_xoff_rx[j];
1419 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1420 data[i++] = pf->stats.priority_xon_2_xoff[j];
1423 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1426 struct i40e_netdev_priv *np = netdev_priv(netdev);
1427 struct i40e_vsi *vsi = np->vsi;
1428 struct i40e_pf *pf = vsi->back;
1429 char *p = (char *)data;
1432 switch (stringset) {
1434 for (i = 0; i < I40E_TEST_LEN; i++) {
1435 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1436 data += ETH_GSTRING_LEN;
1440 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1441 snprintf(p, ETH_GSTRING_LEN, "%s",
1442 i40e_gstrings_net_stats[i].stat_string);
1443 p += ETH_GSTRING_LEN;
1445 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1446 snprintf(p, ETH_GSTRING_LEN, "%s",
1447 i40e_gstrings_misc_stats[i].stat_string);
1448 p += ETH_GSTRING_LEN;
1451 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1452 snprintf(p, ETH_GSTRING_LEN, "%s",
1453 i40e_gstrings_fcoe_stats[i].stat_string);
1454 p += ETH_GSTRING_LEN;
1457 for (i = 0; i < vsi->num_queue_pairs; i++) {
1458 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1459 p += ETH_GSTRING_LEN;
1460 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1461 p += ETH_GSTRING_LEN;
1462 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1463 p += ETH_GSTRING_LEN;
1464 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1465 p += ETH_GSTRING_LEN;
1467 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1470 if ((pf->lan_veb != I40E_NO_VEB) &&
1471 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
1472 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1473 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1474 i40e_gstrings_veb_stats[i].stat_string);
1475 p += ETH_GSTRING_LEN;
1477 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1478 snprintf(p, ETH_GSTRING_LEN,
1479 "veb.tc_%u_tx_packets", i);
1480 p += ETH_GSTRING_LEN;
1481 snprintf(p, ETH_GSTRING_LEN,
1482 "veb.tc_%u_tx_bytes", i);
1483 p += ETH_GSTRING_LEN;
1484 snprintf(p, ETH_GSTRING_LEN,
1485 "veb.tc_%u_rx_packets", i);
1486 p += ETH_GSTRING_LEN;
1487 snprintf(p, ETH_GSTRING_LEN,
1488 "veb.tc_%u_rx_bytes", i);
1489 p += ETH_GSTRING_LEN;
1492 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1493 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1494 i40e_gstrings_stats[i].stat_string);
1495 p += ETH_GSTRING_LEN;
1497 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1498 snprintf(p, ETH_GSTRING_LEN,
1499 "port.tx_priority_%u_xon", i);
1500 p += ETH_GSTRING_LEN;
1501 snprintf(p, ETH_GSTRING_LEN,
1502 "port.tx_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", i);
1508 p += ETH_GSTRING_LEN;
1509 snprintf(p, ETH_GSTRING_LEN,
1510 "port.rx_priority_%u_xoff", i);
1511 p += ETH_GSTRING_LEN;
1513 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1514 snprintf(p, ETH_GSTRING_LEN,
1515 "port.rx_priority_%u_xon_2_xoff", i);
1516 p += ETH_GSTRING_LEN;
1518 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1520 case ETH_SS_PRIV_FLAGS:
1521 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1522 memcpy(data, i40e_priv_flags_strings[i],
1524 data += ETH_GSTRING_LEN;
1532 static int i40e_get_ts_info(struct net_device *dev,
1533 struct ethtool_ts_info *info)
1535 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1537 /* only report HW timestamping if PTP is enabled */
1538 if (!(pf->flags & I40E_FLAG_PTP))
1539 return ethtool_op_get_ts_info(dev, info);
1541 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1542 SOF_TIMESTAMPING_RX_SOFTWARE |
1543 SOF_TIMESTAMPING_SOFTWARE |
1544 SOF_TIMESTAMPING_TX_HARDWARE |
1545 SOF_TIMESTAMPING_RX_HARDWARE |
1546 SOF_TIMESTAMPING_RAW_HARDWARE;
1549 info->phc_index = ptp_clock_index(pf->ptp_clock);
1551 info->phc_index = -1;
1553 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
1555 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1556 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1557 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
1562 static int i40e_link_test(struct net_device *netdev, u64 *data)
1564 struct i40e_netdev_priv *np = netdev_priv(netdev);
1565 struct i40e_pf *pf = np->vsi->back;
1567 bool link_up = false;
1569 netif_info(pf, hw, netdev, "link test\n");
1570 status = i40e_get_link_status(&pf->hw, &link_up);
1572 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1585 static int i40e_reg_test(struct net_device *netdev, u64 *data)
1587 struct i40e_netdev_priv *np = netdev_priv(netdev);
1588 struct i40e_pf *pf = np->vsi->back;
1590 netif_info(pf, hw, netdev, "register test\n");
1591 *data = i40e_diag_reg_test(&pf->hw);
1596 static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
1598 struct i40e_netdev_priv *np = netdev_priv(netdev);
1599 struct i40e_pf *pf = np->vsi->back;
1601 netif_info(pf, hw, netdev, "eeprom test\n");
1602 *data = i40e_diag_eeprom_test(&pf->hw);
1604 /* forcebly clear the NVM Update state machine */
1605 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1610 static int i40e_intr_test(struct net_device *netdev, u64 *data)
1612 struct i40e_netdev_priv *np = netdev_priv(netdev);
1613 struct i40e_pf *pf = np->vsi->back;
1614 u16 swc_old = pf->sw_int_count;
1616 netif_info(pf, hw, netdev, "interrupt test\n");
1617 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1618 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1619 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1620 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1621 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1622 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
1623 usleep_range(1000, 2000);
1624 *data = (swc_old == pf->sw_int_count);
1629 static int i40e_loopback_test(struct net_device *netdev, u64 *data)
1631 struct i40e_netdev_priv *np = netdev_priv(netdev);
1632 struct i40e_pf *pf = np->vsi->back;
1634 netif_info(pf, hw, netdev, "loopback test not implemented\n");
1640 static inline bool i40e_active_vfs(struct i40e_pf *pf)
1642 struct i40e_vf *vfs = pf->vf;
1645 for (i = 0; i < pf->num_alloc_vfs; i++)
1646 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
1651 static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1653 struct i40e_vsi **vsi = pf->vsi;
1656 for (i = 0; i < pf->num_alloc_vsi; i++) {
1659 if (vsi[i]->type == I40E_VSI_VMDQ2)
1666 static void i40e_diag_test(struct net_device *netdev,
1667 struct ethtool_test *eth_test, u64 *data)
1669 struct i40e_netdev_priv *np = netdev_priv(netdev);
1670 bool if_running = netif_running(netdev);
1671 struct i40e_pf *pf = np->vsi->back;
1673 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1675 netif_info(pf, drv, netdev, "offline testing starting\n");
1677 set_bit(__I40E_TESTING, &pf->state);
1679 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
1680 dev_warn(&pf->pdev->dev,
1681 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
1682 data[I40E_ETH_TEST_REG] = 1;
1683 data[I40E_ETH_TEST_EEPROM] = 1;
1684 data[I40E_ETH_TEST_INTR] = 1;
1685 data[I40E_ETH_TEST_LOOPBACK] = 1;
1686 data[I40E_ETH_TEST_LINK] = 1;
1687 eth_test->flags |= ETH_TEST_FL_FAILED;
1688 clear_bit(__I40E_TESTING, &pf->state);
1692 /* If the device is online then take it offline */
1694 /* indicate we're in test mode */
1697 /* This reset does not affect link - if it is
1698 * changed to a type of reset that does affect
1699 * link then the following link test would have
1700 * to be moved to before the reset
1702 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
1704 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1705 eth_test->flags |= ETH_TEST_FL_FAILED;
1707 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
1708 eth_test->flags |= ETH_TEST_FL_FAILED;
1710 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
1711 eth_test->flags |= ETH_TEST_FL_FAILED;
1713 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
1714 eth_test->flags |= ETH_TEST_FL_FAILED;
1716 /* run reg test last, a reset is required after it */
1717 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1718 eth_test->flags |= ETH_TEST_FL_FAILED;
1720 clear_bit(__I40E_TESTING, &pf->state);
1721 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
1727 netif_info(pf, drv, netdev, "online testing starting\n");
1729 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1730 eth_test->flags |= ETH_TEST_FL_FAILED;
1732 /* Offline only tests, not run in online; pass by default */
1733 data[I40E_ETH_TEST_REG] = 0;
1734 data[I40E_ETH_TEST_EEPROM] = 0;
1735 data[I40E_ETH_TEST_INTR] = 0;
1736 data[I40E_ETH_TEST_LOOPBACK] = 0;
1741 netif_info(pf, drv, netdev, "testing finished\n");
1744 static void i40e_get_wol(struct net_device *netdev,
1745 struct ethtool_wolinfo *wol)
1747 struct i40e_netdev_priv *np = netdev_priv(netdev);
1748 struct i40e_pf *pf = np->vsi->back;
1749 struct i40e_hw *hw = &pf->hw;
1752 /* NVM bit on means WoL disabled for the port */
1753 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1754 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
1758 wol->supported = WAKE_MAGIC;
1759 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1764 * i40e_set_wol - set the WakeOnLAN configuration
1765 * @netdev: the netdev in question
1766 * @wol: the ethtool WoL setting data
1768 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1770 struct i40e_netdev_priv *np = netdev_priv(netdev);
1771 struct i40e_pf *pf = np->vsi->back;
1772 struct i40e_vsi *vsi = np->vsi;
1773 struct i40e_hw *hw = &pf->hw;
1776 /* WoL not supported if this isn't the controlling PF on the port */
1777 if (hw->partition_id != 1) {
1778 i40e_partition_setting_complaint(pf);
1782 if (vsi != pf->vsi[pf->lan_vsi])
1785 /* NVM bit on means WoL disabled for the port */
1786 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1787 if (BIT(hw->port) & wol_nvm_bits)
1790 /* only magic packet is supported */
1791 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1794 /* is this a new value? */
1795 if (pf->wol_en != !!wol->wolopts) {
1796 pf->wol_en = !!wol->wolopts;
1797 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1803 static int i40e_set_phys_id(struct net_device *netdev,
1804 enum ethtool_phys_id_state state)
1806 struct i40e_netdev_priv *np = netdev_priv(netdev);
1807 struct i40e_pf *pf = np->vsi->back;
1808 struct i40e_hw *hw = &pf->hw;
1812 case ETHTOOL_ID_ACTIVE:
1813 pf->led_status = i40e_led_get(hw);
1816 i40e_led_set(hw, 0xF, false);
1818 case ETHTOOL_ID_OFF:
1819 i40e_led_set(hw, 0x0, false);
1821 case ETHTOOL_ID_INACTIVE:
1822 i40e_led_set(hw, pf->led_status, false);
1831 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1832 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1833 * 125us (8000 interrupts per second) == ITR(62)
1836 static int i40e_get_coalesce(struct net_device *netdev,
1837 struct ethtool_coalesce *ec)
1839 struct i40e_netdev_priv *np = netdev_priv(netdev);
1840 struct i40e_vsi *vsi = np->vsi;
1842 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1843 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1845 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
1846 ec->use_adaptive_rx_coalesce = 1;
1848 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
1849 ec->use_adaptive_tx_coalesce = 1;
1851 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1852 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1857 static int i40e_set_coalesce(struct net_device *netdev,
1858 struct ethtool_coalesce *ec)
1860 struct i40e_netdev_priv *np = netdev_priv(netdev);
1861 struct i40e_q_vector *q_vector;
1862 struct i40e_vsi *vsi = np->vsi;
1863 struct i40e_pf *pf = vsi->back;
1864 struct i40e_hw *hw = &pf->hw;
1868 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1869 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1871 vector = vsi->base_vector;
1872 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1873 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
1874 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1875 } else if (ec->rx_coalesce_usecs == 0) {
1876 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1877 if (ec->use_adaptive_rx_coalesce)
1878 netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
1880 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
1884 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1885 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
1886 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1887 } else if (ec->tx_coalesce_usecs == 0) {
1888 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1889 if (ec->use_adaptive_tx_coalesce)
1890 netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
1892 netif_info(pf, drv, netdev,
1893 "Invalid value, tx-usecs range is 0-8160\n");
1897 if (ec->use_adaptive_rx_coalesce)
1898 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1900 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1902 if (ec->use_adaptive_tx_coalesce)
1903 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1905 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
1907 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1908 q_vector = vsi->q_vectors[i];
1909 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1910 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1911 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1912 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1920 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1921 * @pf: pointer to the physical function struct
1922 * @cmd: ethtool rxnfc command
1924 * Returns Success if the flow is supported, else Invalid Input.
1926 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1930 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1931 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1932 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1935 /* Report default options for RSS on i40e */
1936 switch (cmd->flow_type) {
1939 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1940 /* fall through to add IP fields */
1942 case AH_ESP_V4_FLOW:
1946 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1950 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1951 /* fall through to add IP fields */
1953 case AH_ESP_V6_FLOW:
1957 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1967 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1968 * @pf: Pointer to the physical function struct
1969 * @cmd: The command to get or set Rx flow classification rules
1970 * @rule_locs: Array of used rule locations
1972 * This function populates both the total and actual rule count of
1973 * the ethtool flow classification command
1975 * Returns 0 on success or -EMSGSIZE if entry not found
1977 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1978 struct ethtool_rxnfc *cmd,
1981 struct i40e_fdir_filter *rule;
1982 struct hlist_node *node2;
1985 /* report total rule count */
1986 cmd->data = i40e_get_fd_cnt_all(pf);
1988 hlist_for_each_entry_safe(rule, node2,
1989 &pf->fdir_filter_list, fdir_node) {
1990 if (cnt == cmd->rule_cnt)
1993 rule_locs[cnt] = rule->fd_id;
1997 cmd->rule_cnt = cnt;
2003 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2004 * @pf: Pointer to the physical function struct
2005 * @cmd: The command to get or set Rx flow classification rules
2007 * This function looks up a filter based on the Rx flow classification
2008 * command and fills the flow spec info for it if found
2010 * Returns 0 on success or -EINVAL if filter not found
2012 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2013 struct ethtool_rxnfc *cmd)
2015 struct ethtool_rx_flow_spec *fsp =
2016 (struct ethtool_rx_flow_spec *)&cmd->fs;
2017 struct i40e_fdir_filter *rule = NULL;
2018 struct hlist_node *node2;
2020 hlist_for_each_entry_safe(rule, node2,
2021 &pf->fdir_filter_list, fdir_node) {
2022 if (fsp->location <= rule->fd_id)
2026 if (!rule || fsp->location != rule->fd_id)
2029 fsp->flow_type = rule->flow_type;
2030 if (fsp->flow_type == IP_USER_FLOW) {
2031 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2032 fsp->h_u.usr_ip4_spec.proto = 0;
2033 fsp->m_u.usr_ip4_spec.proto = 0;
2036 /* Reverse the src and dest notion, since the HW views them from
2037 * Tx perspective where as the user expects it from Rx filter view.
2039 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2040 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2041 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2042 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
2044 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2045 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2047 fsp->ring_cookie = rule->q_index;
2049 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2050 struct i40e_vsi *vsi;
2052 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2053 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2054 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2055 fsp->m_ext.data[1] = htonl(0x1);
2063 * i40e_get_rxnfc - command to get RX flow classification rules
2064 * @netdev: network interface device structure
2065 * @cmd: ethtool rxnfc command
2067 * Returns Success if the command is supported.
2069 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2072 struct i40e_netdev_priv *np = netdev_priv(netdev);
2073 struct i40e_vsi *vsi = np->vsi;
2074 struct i40e_pf *pf = vsi->back;
2075 int ret = -EOPNOTSUPP;
2078 case ETHTOOL_GRXRINGS:
2079 cmd->data = vsi->alloc_queue_pairs;
2083 ret = i40e_get_rss_hash_opts(pf, cmd);
2085 case ETHTOOL_GRXCLSRLCNT:
2086 cmd->rule_cnt = pf->fdir_pf_active_filters;
2087 /* report total rule count */
2088 cmd->data = i40e_get_fd_cnt_all(pf);
2091 case ETHTOOL_GRXCLSRULE:
2092 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
2094 case ETHTOOL_GRXCLSRLALL:
2095 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2105 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2106 * @pf: pointer to the physical function struct
2107 * @cmd: ethtool rxnfc command
2109 * Returns Success if the flow input set is supported.
2111 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2113 struct i40e_hw *hw = &pf->hw;
2114 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2115 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2117 /* RSS does not support anything other than hashing
2118 * to queues on src and dst IPs and ports
2120 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2121 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2124 /* We need at least the IP SRC and DEST fields for hashing */
2125 if (!(nfc->data & RXH_IP_SRC) ||
2126 !(nfc->data & RXH_IP_DST))
2129 switch (nfc->flow_type) {
2131 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2133 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2135 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2136 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2143 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2145 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2147 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2148 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2155 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2157 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2158 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
2160 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2161 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2162 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
2169 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2171 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2172 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
2174 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2175 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2176 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
2182 case AH_ESP_V4_FLOW:
2186 if ((nfc->data & RXH_L4_B_0_1) ||
2187 (nfc->data & RXH_L4_B_2_3))
2189 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2191 case AH_ESP_V6_FLOW:
2195 if ((nfc->data & RXH_L4_B_0_1) ||
2196 (nfc->data & RXH_L4_B_2_3))
2198 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2201 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2202 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
2205 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2206 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
2212 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2213 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2216 /* Save setting for future output/update */
2217 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2223 * i40e_match_fdir_input_set - Match a new filter against an existing one
2224 * @rule: The filter already added
2225 * @input: The new filter to comapre against
2227 * Returns true if the two input set match
2229 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2230 struct i40e_fdir_filter *input)
2232 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2233 (rule->src_ip[0] != input->src_ip[0]) ||
2234 (rule->dst_port != input->dst_port) ||
2235 (rule->src_port != input->src_port))
2241 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2242 * @vsi: Pointer to the targeted VSI
2243 * @input: The filter to update or NULL to indicate deletion
2244 * @sw_idx: Software index to the filter
2245 * @cmd: The command to get or set Rx flow classification rules
2247 * This function updates (or deletes) a Flow Director entry from
2248 * the hlist of the corresponding PF
2250 * Returns 0 on success
2252 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2253 struct i40e_fdir_filter *input,
2255 struct ethtool_rxnfc *cmd)
2257 struct i40e_fdir_filter *rule, *parent;
2258 struct i40e_pf *pf = vsi->back;
2259 struct hlist_node *node2;
2265 hlist_for_each_entry_safe(rule, node2,
2266 &pf->fdir_filter_list, fdir_node) {
2267 /* hash found, or no matching entry */
2268 if (rule->fd_id >= sw_idx)
2273 /* if there is an old rule occupying our place remove it */
2274 if (rule && (rule->fd_id == sw_idx)) {
2275 if (input && !i40e_match_fdir_input_set(rule, input))
2276 err = i40e_add_del_fdir(vsi, rule, false);
2278 err = i40e_add_del_fdir(vsi, rule, false);
2279 hlist_del(&rule->fdir_node);
2281 pf->fdir_pf_active_filters--;
2284 /* If no input this was a delete, err should be 0 if a rule was
2285 * successfully found and removed from the list else -EINVAL
2290 /* initialize node and set software index */
2291 INIT_HLIST_NODE(&input->fdir_node);
2293 /* add filter to the list */
2295 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
2297 hlist_add_head(&input->fdir_node,
2298 &pf->fdir_filter_list);
2301 pf->fdir_pf_active_filters++;
2307 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2308 * @vsi: Pointer to the targeted VSI
2309 * @cmd: The command to get or set Rx flow classification rules
2311 * The function removes a Flow Director filter entry from the
2312 * hlist of the corresponding PF
2314 * Returns 0 on success
2316 static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2317 struct ethtool_rxnfc *cmd)
2319 struct ethtool_rx_flow_spec *fsp =
2320 (struct ethtool_rx_flow_spec *)&cmd->fs;
2321 struct i40e_pf *pf = vsi->back;
2324 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2325 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2328 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2331 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
2333 i40e_fdir_check_and_reenable(pf);
2338 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
2339 * @vsi: pointer to the targeted VSI
2340 * @cmd: command to get or set RX flow classification rules
2342 * Add Flow Director filters for a specific flow spec based on their
2343 * protocol. Returns 0 if the filters were successfully added.
2345 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2346 struct ethtool_rxnfc *cmd)
2348 struct ethtool_rx_flow_spec *fsp;
2349 struct i40e_fdir_filter *input;
2359 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2362 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
2365 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2366 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2369 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2372 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2374 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2375 pf->hw.func_caps.fd_filters_guaranteed)) {
2379 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2380 (fsp->ring_cookie >= vsi->num_queue_pairs))
2383 input = kzalloc(sizeof(*input), GFP_KERNEL);
2388 input->fd_id = fsp->location;
2390 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2391 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2394 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2396 input->q_index = fsp->ring_cookie;
2397 input->flex_off = 0;
2399 input->dest_vsi = vsi->id;
2400 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
2401 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
2402 input->flow_type = fsp->flow_type;
2403 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
2405 /* Reverse the src and dest notion, since the HW expects them to be from
2406 * Tx perspective where as the input from user is from Rx filter view.
2408 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2409 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2410 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2411 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
2413 if (ntohl(fsp->m_ext.data[1])) {
2414 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2415 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2418 vf_id = ntohl(fsp->h_ext.data[1]);
2419 /* Find vsi id from vf id and override dest vsi */
2420 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2421 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2422 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2427 ret = i40e_add_del_fdir(vsi, input, true);
2432 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
2438 * i40e_set_rxnfc - command to set RX flow classification rules
2439 * @netdev: network interface device structure
2440 * @cmd: ethtool rxnfc command
2442 * Returns Success if the command is supported.
2444 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2446 struct i40e_netdev_priv *np = netdev_priv(netdev);
2447 struct i40e_vsi *vsi = np->vsi;
2448 struct i40e_pf *pf = vsi->back;
2449 int ret = -EOPNOTSUPP;
2453 ret = i40e_set_rss_hash_opt(pf, cmd);
2455 case ETHTOOL_SRXCLSRLINS:
2456 ret = i40e_add_fdir_ethtool(vsi, cmd);
2458 case ETHTOOL_SRXCLSRLDEL:
2459 ret = i40e_del_fdir_entry(vsi, cmd);
2469 * i40e_max_channels - get Max number of combined channels supported
2472 static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2474 /* TODO: This code assumes DCB and FD is disabled for now. */
2475 return vsi->alloc_queue_pairs;
2479 * i40e_get_channels - Get the current channels enabled and max supported etc.
2480 * @netdev: network interface device structure
2481 * @ch: ethtool channels structure
2483 * We don't support separate tx and rx queues as channels. The other count
2484 * represents how many queues are being used for control. max_combined counts
2485 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2486 * q_vectors since we support a lot more queue pairs than q_vectors.
2488 static void i40e_get_channels(struct net_device *dev,
2489 struct ethtool_channels *ch)
2491 struct i40e_netdev_priv *np = netdev_priv(dev);
2492 struct i40e_vsi *vsi = np->vsi;
2493 struct i40e_pf *pf = vsi->back;
2495 /* report maximum channels */
2496 ch->max_combined = i40e_max_channels(vsi);
2498 /* report info for other vector */
2499 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
2500 ch->max_other = ch->other_count;
2502 /* Note: This code assumes DCB is disabled for now. */
2503 ch->combined_count = vsi->num_queue_pairs;
2507 * i40e_set_channels - Set the new channels count.
2508 * @netdev: network interface device structure
2509 * @ch: ethtool channels structure
2511 * The new channels count may not be the same as requested by the user
2512 * since it gets rounded down to a power of 2 value.
2514 static int i40e_set_channels(struct net_device *dev,
2515 struct ethtool_channels *ch)
2517 struct i40e_netdev_priv *np = netdev_priv(dev);
2518 unsigned int count = ch->combined_count;
2519 struct i40e_vsi *vsi = np->vsi;
2520 struct i40e_pf *pf = vsi->back;
2523 /* We do not support setting channels for any other VSI at present */
2524 if (vsi->type != I40E_VSI_MAIN)
2527 /* verify they are not requesting separate vectors */
2528 if (!count || ch->rx_count || ch->tx_count)
2531 /* verify other_count has not changed */
2532 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
2535 /* verify the number of channels does not exceed hardware limits */
2536 if (count > i40e_max_channels(vsi))
2539 /* update feature limits from largest to smallest supported values */
2540 /* TODO: Flow director limit, DCB etc */
2542 /* use rss_reconfig to rebuild with new queue count and update traffic
2543 * class queue mapping
2545 new_count = i40e_reconfig_rss_queues(pf, count);
2552 #define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2554 * i40e_get_rxfh_key_size - get the RSS hash key size
2555 * @netdev: network interface device structure
2557 * Returns the table size.
2559 static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2561 return I40E_HKEY_ARRAY_SIZE;
2565 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2566 * @netdev: network interface device structure
2568 * Returns the table size.
2570 static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2572 return I40E_HLUT_ARRAY_SIZE;
2575 static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2578 struct i40e_netdev_priv *np = netdev_priv(netdev);
2579 struct i40e_vsi *vsi = np->vsi;
2580 struct i40e_pf *pf = vsi->back;
2581 struct i40e_hw *hw = &pf->hw;
2586 *hfunc = ETH_RSS_HASH_TOP;
2591 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2592 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2593 indir[j++] = reg_val & 0xff;
2594 indir[j++] = (reg_val >> 8) & 0xff;
2595 indir[j++] = (reg_val >> 16) & 0xff;
2596 indir[j++] = (reg_val >> 24) & 0xff;
2600 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2601 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2602 key[j++] = (u8)(reg_val & 0xff);
2603 key[j++] = (u8)((reg_val >> 8) & 0xff);
2604 key[j++] = (u8)((reg_val >> 16) & 0xff);
2605 key[j++] = (u8)((reg_val >> 24) & 0xff);
2612 * i40e_set_rxfh - set the rx flow hash indirection table
2613 * @netdev: network interface device structure
2614 * @indir: indirection table
2617 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
2618 * returns 0 after programming the table.
2620 static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2621 const u8 *key, const u8 hfunc)
2623 struct i40e_netdev_priv *np = netdev_priv(netdev);
2624 struct i40e_vsi *vsi = np->vsi;
2625 struct i40e_pf *pf = vsi->back;
2626 struct i40e_hw *hw = &pf->hw;
2630 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2636 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2637 reg_val = indir[j++];
2638 reg_val |= indir[j++] << 8;
2639 reg_val |= indir[j++] << 16;
2640 reg_val |= indir[j++] << 24;
2641 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2645 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2647 reg_val |= key[j++] << 8;
2648 reg_val |= key[j++] << 16;
2649 reg_val |= key[j++] << 24;
2650 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2657 * i40e_get_priv_flags - report device private flags
2658 * @dev: network interface device structure
2660 * The get string set count and the string set should be matched for each
2661 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2664 * Returns a u32 bitmap of flags.
2666 static u32 i40e_get_priv_flags(struct net_device *dev)
2668 struct i40e_netdev_priv *np = netdev_priv(dev);
2669 struct i40e_vsi *vsi = np->vsi;
2670 struct i40e_pf *pf = vsi->back;
2673 ret_flags |= pf->hw.func_caps.npar_enable ?
2674 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2675 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2676 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
2677 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2678 I40E_PRIV_FLAGS_FD_ATR : 0;
2684 * i40e_set_priv_flags - set private flags
2685 * @dev: network interface device structure
2686 * @flags: bit flags to be set
2688 static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2690 struct i40e_netdev_priv *np = netdev_priv(dev);
2691 struct i40e_vsi *vsi = np->vsi;
2692 struct i40e_pf *pf = vsi->back;
2694 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2695 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2697 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2699 /* allow the user to control the state of the Flow
2700 * Director ATR (Application Targeted Routing) feature
2703 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2704 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2706 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2707 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2713 static const struct ethtool_ops i40e_ethtool_ops = {
2714 .get_settings = i40e_get_settings,
2715 .set_settings = i40e_set_settings,
2716 .get_drvinfo = i40e_get_drvinfo,
2717 .get_regs_len = i40e_get_regs_len,
2718 .get_regs = i40e_get_regs,
2719 .nway_reset = i40e_nway_reset,
2720 .get_link = ethtool_op_get_link,
2721 .get_wol = i40e_get_wol,
2722 .set_wol = i40e_set_wol,
2723 .set_eeprom = i40e_set_eeprom,
2724 .get_eeprom_len = i40e_get_eeprom_len,
2725 .get_eeprom = i40e_get_eeprom,
2726 .get_ringparam = i40e_get_ringparam,
2727 .set_ringparam = i40e_set_ringparam,
2728 .get_pauseparam = i40e_get_pauseparam,
2729 .set_pauseparam = i40e_set_pauseparam,
2730 .get_msglevel = i40e_get_msglevel,
2731 .set_msglevel = i40e_set_msglevel,
2732 .get_rxnfc = i40e_get_rxnfc,
2733 .set_rxnfc = i40e_set_rxnfc,
2734 .self_test = i40e_diag_test,
2735 .get_strings = i40e_get_strings,
2736 .set_phys_id = i40e_set_phys_id,
2737 .get_sset_count = i40e_get_sset_count,
2738 .get_ethtool_stats = i40e_get_ethtool_stats,
2739 .get_coalesce = i40e_get_coalesce,
2740 .set_coalesce = i40e_set_coalesce,
2741 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2742 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2743 .get_rxfh = i40e_get_rxfh,
2744 .set_rxfh = i40e_set_rxfh,
2745 .get_channels = i40e_get_channels,
2746 .set_channels = i40e_set_channels,
2747 .get_ts_info = i40e_get_ts_info,
2748 .get_priv_flags = i40e_get_priv_flags,
2749 .set_priv_flags = i40e_set_priv_flags,
2752 void i40e_set_ethtool_ops(struct net_device *netdev)
2754 netdev->ethtool_ops = &i40e_ethtool_ops;