1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2014 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) \
43 #define I40E_NETDEV_STAT(_net_stat) \
44 I40E_STAT(struct net_device_stats, #_net_stat, _net_stat)
45 #define I40E_PF_STAT(_name, _stat) \
46 I40E_STAT(struct i40e_pf, _name, _stat)
47 #define I40E_VSI_STAT(_name, _stat) \
48 I40E_STAT(struct i40e_vsi, _name, _stat)
49 #define I40E_VEB_STAT(_name, _stat) \
50 I40E_STAT(struct i40e_veb, _name, _stat)
52 static const struct i40e_stats i40e_gstrings_net_stats[] = {
53 I40E_NETDEV_STAT(rx_packets),
54 I40E_NETDEV_STAT(tx_packets),
55 I40E_NETDEV_STAT(rx_bytes),
56 I40E_NETDEV_STAT(tx_bytes),
57 I40E_NETDEV_STAT(rx_errors),
58 I40E_NETDEV_STAT(tx_errors),
59 I40E_NETDEV_STAT(rx_dropped),
60 I40E_NETDEV_STAT(tx_dropped),
61 I40E_NETDEV_STAT(collisions),
62 I40E_NETDEV_STAT(rx_length_errors),
63 I40E_NETDEV_STAT(rx_crc_errors),
66 static const struct i40e_stats i40e_gstrings_veb_stats[] = {
67 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
68 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
69 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
70 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
71 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
72 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
73 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
74 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
75 I40E_VEB_STAT("rx_discards", stats.rx_discards),
76 I40E_VEB_STAT("tx_discards", stats.tx_discards),
77 I40E_VEB_STAT("tx_errors", stats.tx_errors),
78 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
81 static const struct i40e_stats i40e_gstrings_misc_stats[] = {
82 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
83 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
84 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
85 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
86 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
87 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
88 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
91 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
92 struct ethtool_rxnfc *cmd);
94 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
95 * but they are separate. This device supports Virtualization, and
96 * as such might have several netdevs supporting VMDq and FCoE going
97 * through a single port. The NETDEV_STATs are for individual netdevs
98 * seen at the top of the stack, and the PF_STATs are for the physical
99 * function at the bottom of the stack hosting those netdevs.
101 * The PF_STATs are appended to the netdev stats only when ethtool -S
102 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
104 static struct i40e_stats i40e_gstrings_stats[] = {
105 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
106 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
107 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
108 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
109 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
110 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
111 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
112 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
113 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
114 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
115 I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
116 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
117 I40E_PF_STAT("crc_errors", stats.crc_errors),
118 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
119 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
120 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
121 I40E_PF_STAT("tx_timeout", tx_timeout_count),
122 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
123 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
124 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
125 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
126 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
127 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
128 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
129 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
130 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
131 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
132 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
133 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
134 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
135 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
136 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
137 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
138 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
139 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
140 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
141 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
142 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
143 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
144 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
145 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
146 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
147 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
148 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
149 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
150 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
153 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
154 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
155 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
156 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
160 static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
161 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
162 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
163 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
164 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
165 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
166 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
167 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
168 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
171 #endif /* I40E_FCOE */
172 #define I40E_QUEUE_STATS_LEN(n) \
173 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
174 * 2 /* Tx and Rx together */ \
175 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
176 #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
177 #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
178 #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
180 #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
181 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
182 I40E_FCOE_STATS_LEN + \
183 I40E_MISC_STATS_LEN + \
184 I40E_QUEUE_STATS_LEN((n)))
186 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
187 I40E_MISC_STATS_LEN + \
188 I40E_QUEUE_STATS_LEN((n)))
189 #endif /* I40E_FCOE */
190 #define I40E_PFC_STATS_LEN ( \
191 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
192 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
197 #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
198 #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
199 I40E_PFC_STATS_LEN + \
200 I40E_VSI_STATS_LEN((n)))
202 enum i40e_ethtool_test_id {
203 I40E_ETH_TEST_REG = 0,
204 I40E_ETH_TEST_EEPROM,
206 I40E_ETH_TEST_LOOPBACK,
210 static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
211 "Register test (offline)",
212 "Eeprom test (offline)",
213 "Interrupt test (offline)",
214 "Loopback test (offline)",
215 "Link test (on/offline)"
218 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
221 * i40e_get_settings - Get Link Speed and Duplex settings
222 * @netdev: network interface device structure
223 * @ecmd: ethtool command
225 * Reports speed/duplex settings based on media_type
227 static int i40e_get_settings(struct net_device *netdev,
228 struct ethtool_cmd *ecmd)
230 struct i40e_netdev_priv *np = netdev_priv(netdev);
231 struct i40e_pf *pf = np->vsi->back;
232 struct i40e_hw *hw = &pf->hw;
233 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
234 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
235 u32 link_speed = hw_link_info->link_speed;
237 /* hardware is either in 40G mode or 10G mode
238 * NOTE: this section initializes supported and advertising
241 /* link is down and the driver needs to fall back on
242 * device ID to determine what kinds of info to display,
243 * it's mostly a guess that may change when link is up
245 switch (hw->device_id) {
246 case I40E_DEV_ID_QSFP_A:
247 case I40E_DEV_ID_QSFP_B:
248 case I40E_DEV_ID_QSFP_C:
250 ecmd->supported = SUPPORTED_40000baseSR4_Full |
251 SUPPORTED_40000baseCR4_Full |
252 SUPPORTED_40000baseLR4_Full;
253 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
254 ADVERTISED_40000baseCR4_Full |
255 ADVERTISED_40000baseLR4_Full;
257 case I40E_DEV_ID_KX_B:
259 ecmd->supported = SUPPORTED_40000baseKR4_Full;
260 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
262 case I40E_DEV_ID_KX_C:
264 ecmd->supported = SUPPORTED_10000baseKR_Full;
265 ecmd->advertising = ADVERTISED_10000baseKR_Full;
267 case I40E_DEV_ID_10G_BASE_T:
268 ecmd->supported = SUPPORTED_10000baseT_Full |
269 SUPPORTED_1000baseT_Full |
270 SUPPORTED_100baseT_Full;
271 ecmd->advertising = ADVERTISED_10000baseT_Full |
272 ADVERTISED_1000baseT_Full |
273 ADVERTISED_100baseT_Full;
276 /* all the rest are 10G/1G */
277 ecmd->supported = SUPPORTED_10000baseT_Full |
278 SUPPORTED_1000baseT_Full;
279 ecmd->advertising = ADVERTISED_10000baseT_Full |
280 ADVERTISED_1000baseT_Full;
284 /* skip phy_type use as it is zero when link is down */
285 goto no_valid_phy_type;
288 switch (hw_link_info->phy_type) {
289 case I40E_PHY_TYPE_40GBASE_CR4:
290 case I40E_PHY_TYPE_40GBASE_CR4_CU:
291 ecmd->supported = SUPPORTED_Autoneg |
292 SUPPORTED_40000baseCR4_Full;
293 ecmd->advertising = ADVERTISED_Autoneg |
294 ADVERTISED_40000baseCR4_Full;
296 case I40E_PHY_TYPE_40GBASE_KR4:
297 ecmd->supported = SUPPORTED_Autoneg |
298 SUPPORTED_40000baseKR4_Full;
299 ecmd->advertising = ADVERTISED_Autoneg |
300 ADVERTISED_40000baseKR4_Full;
302 case I40E_PHY_TYPE_40GBASE_SR4:
303 case I40E_PHY_TYPE_XLPPI:
304 case I40E_PHY_TYPE_XLAUI:
305 ecmd->supported = SUPPORTED_40000baseSR4_Full;
307 case I40E_PHY_TYPE_40GBASE_LR4:
308 ecmd->supported = SUPPORTED_40000baseLR4_Full;
310 case I40E_PHY_TYPE_10GBASE_KX4:
311 ecmd->supported = SUPPORTED_Autoneg |
312 SUPPORTED_10000baseKX4_Full;
313 ecmd->advertising = ADVERTISED_Autoneg |
314 ADVERTISED_10000baseKX4_Full;
316 case I40E_PHY_TYPE_10GBASE_KR:
317 ecmd->supported = SUPPORTED_Autoneg |
318 SUPPORTED_10000baseKR_Full;
319 ecmd->advertising = ADVERTISED_Autoneg |
320 ADVERTISED_10000baseKR_Full;
322 case I40E_PHY_TYPE_10GBASE_SR:
323 case I40E_PHY_TYPE_10GBASE_LR:
324 case I40E_PHY_TYPE_1000BASE_SX:
325 case I40E_PHY_TYPE_1000BASE_LX:
326 ecmd->supported = SUPPORTED_10000baseT_Full;
327 ecmd->supported |= SUPPORTED_1000baseT_Full;
329 case I40E_PHY_TYPE_10GBASE_CR1_CU:
330 case I40E_PHY_TYPE_10GBASE_CR1:
331 case I40E_PHY_TYPE_10GBASE_T:
332 ecmd->supported = SUPPORTED_Autoneg |
333 SUPPORTED_10000baseT_Full |
334 SUPPORTED_1000baseT_Full |
335 SUPPORTED_100baseT_Full;
336 ecmd->advertising = ADVERTISED_Autoneg |
337 ADVERTISED_10000baseT_Full |
338 ADVERTISED_1000baseT_Full |
339 ADVERTISED_100baseT_Full;
341 case I40E_PHY_TYPE_XAUI:
342 case I40E_PHY_TYPE_XFI:
343 case I40E_PHY_TYPE_SFI:
344 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
345 ecmd->supported = SUPPORTED_10000baseT_Full;
347 case I40E_PHY_TYPE_1000BASE_KX:
348 case I40E_PHY_TYPE_1000BASE_T:
349 ecmd->supported = SUPPORTED_Autoneg |
350 SUPPORTED_10000baseT_Full |
351 SUPPORTED_1000baseT_Full |
352 SUPPORTED_100baseT_Full;
353 ecmd->advertising = ADVERTISED_Autoneg |
354 ADVERTISED_10000baseT_Full |
355 ADVERTISED_1000baseT_Full |
356 ADVERTISED_100baseT_Full;
358 case I40E_PHY_TYPE_100BASE_TX:
359 ecmd->supported = SUPPORTED_Autoneg |
360 SUPPORTED_10000baseT_Full |
361 SUPPORTED_1000baseT_Full |
362 SUPPORTED_100baseT_Full;
363 ecmd->advertising = ADVERTISED_Autoneg |
364 ADVERTISED_10000baseT_Full |
365 ADVERTISED_1000baseT_Full |
366 ADVERTISED_100baseT_Full;
368 case I40E_PHY_TYPE_SGMII:
369 ecmd->supported = SUPPORTED_Autoneg |
370 SUPPORTED_1000baseT_Full |
371 SUPPORTED_100baseT_Full;
372 ecmd->advertising = ADVERTISED_Autoneg |
373 ADVERTISED_1000baseT_Full |
374 ADVERTISED_100baseT_Full;
377 /* if we got here and link is up something bad is afoot */
378 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
379 hw_link_info->phy_type);
383 /* this is if autoneg is enabled or disabled */
384 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
385 AUTONEG_ENABLE : AUTONEG_DISABLE);
387 switch (hw->phy.media_type) {
388 case I40E_MEDIA_TYPE_BACKPLANE:
389 ecmd->supported |= SUPPORTED_Autoneg |
391 ecmd->advertising |= ADVERTISED_Autoneg |
392 ADVERTISED_Backplane;
393 ecmd->port = PORT_NONE;
395 case I40E_MEDIA_TYPE_BASET:
396 ecmd->supported |= SUPPORTED_TP;
397 ecmd->advertising |= ADVERTISED_TP;
398 ecmd->port = PORT_TP;
400 case I40E_MEDIA_TYPE_DA:
401 case I40E_MEDIA_TYPE_CX4:
402 ecmd->supported |= SUPPORTED_FIBRE;
403 ecmd->advertising |= ADVERTISED_FIBRE;
404 ecmd->port = PORT_DA;
406 case I40E_MEDIA_TYPE_FIBER:
407 ecmd->supported |= SUPPORTED_FIBRE;
408 ecmd->port = PORT_FIBRE;
410 case I40E_MEDIA_TYPE_UNKNOWN:
412 ecmd->port = PORT_OTHER;
416 ecmd->transceiver = XCVR_EXTERNAL;
418 ecmd->supported |= SUPPORTED_Pause;
420 switch (hw->fc.current_mode) {
422 ecmd->advertising |= ADVERTISED_Pause;
424 case I40E_FC_TX_PAUSE:
425 ecmd->advertising |= ADVERTISED_Asym_Pause;
427 case I40E_FC_RX_PAUSE:
428 ecmd->advertising |= (ADVERTISED_Pause |
429 ADVERTISED_Asym_Pause);
432 ecmd->advertising &= ~(ADVERTISED_Pause |
433 ADVERTISED_Asym_Pause);
438 switch (link_speed) {
439 case I40E_LINK_SPEED_40GB:
440 /* need a SPEED_40000 in ethtool.h */
441 ethtool_cmd_speed_set(ecmd, 40000);
443 case I40E_LINK_SPEED_10GB:
444 ethtool_cmd_speed_set(ecmd, SPEED_10000);
446 case I40E_LINK_SPEED_1GB:
447 ethtool_cmd_speed_set(ecmd, SPEED_1000);
449 case I40E_LINK_SPEED_100MB:
450 ethtool_cmd_speed_set(ecmd, SPEED_100);
455 ecmd->duplex = DUPLEX_FULL;
457 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
458 ecmd->duplex = DUPLEX_UNKNOWN;
465 * i40e_set_settings - Set Speed and Duplex
466 * @netdev: network interface device structure
467 * @ecmd: ethtool command
469 * Set speed/duplex per media_types advertised/forced
471 static int i40e_set_settings(struct net_device *netdev,
472 struct ethtool_cmd *ecmd)
474 struct i40e_netdev_priv *np = netdev_priv(netdev);
475 struct i40e_aq_get_phy_abilities_resp abilities;
476 struct i40e_aq_set_phy_config config;
477 struct i40e_pf *pf = np->vsi->back;
478 struct i40e_vsi *vsi = np->vsi;
479 struct i40e_hw *hw = &pf->hw;
480 struct ethtool_cmd safe_ecmd;
481 i40e_status status = 0;
487 if (vsi != pf->vsi[pf->lan_vsi])
490 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
491 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
492 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
493 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
496 /* get our own copy of the bits to check against */
497 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
498 i40e_get_settings(netdev, &safe_ecmd);
500 /* save autoneg and speed out of ecmd */
501 autoneg = ecmd->autoneg;
502 advertise = ecmd->advertising;
504 /* set autoneg and speed back to what they currently are */
505 ecmd->autoneg = safe_ecmd.autoneg;
506 ecmd->advertising = safe_ecmd.advertising;
508 ecmd->cmd = safe_ecmd.cmd;
509 /* If ecmd and safe_ecmd are not the same now, then they are
510 * trying to set something that we do not support
512 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
515 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
516 usleep_range(1000, 2000);
518 /* Get the current phy config */
519 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
524 /* Copy abilities to config in case autoneg is not
527 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
528 config.abilities = abilities.abilities;
531 if (autoneg == AUTONEG_ENABLE) {
532 /* If autoneg is not supported, return error */
533 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
534 netdev_info(netdev, "Autoneg not supported on this phy\n");
537 /* If autoneg was not already enabled */
538 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
539 config.abilities = abilities.abilities |
540 I40E_AQ_PHY_ENABLE_AN;
544 /* If autoneg is supported 10GBASE_T is the only phy that
545 * can disable it, so otherwise return error
547 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
548 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
549 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
552 /* If autoneg is currently enabled */
553 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
554 config.abilities = abilities.abilities &
555 ~I40E_AQ_PHY_ENABLE_AN;
560 if (advertise & ~safe_ecmd.supported)
563 if (advertise & ADVERTISED_100baseT_Full)
564 config.link_speed |= I40E_LINK_SPEED_100MB;
565 if (advertise & ADVERTISED_1000baseT_Full ||
566 advertise & ADVERTISED_1000baseKX_Full)
567 config.link_speed |= I40E_LINK_SPEED_1GB;
568 if (advertise & ADVERTISED_10000baseT_Full ||
569 advertise & ADVERTISED_10000baseKX4_Full ||
570 advertise & ADVERTISED_10000baseKR_Full)
571 config.link_speed |= I40E_LINK_SPEED_10GB;
572 if (advertise & ADVERTISED_40000baseKR4_Full ||
573 advertise & ADVERTISED_40000baseCR4_Full ||
574 advertise & ADVERTISED_40000baseSR4_Full ||
575 advertise & ADVERTISED_40000baseLR4_Full)
576 config.link_speed |= I40E_LINK_SPEED_40GB;
578 if (change || (abilities.link_speed != config.link_speed)) {
579 /* copy over the rest of the abilities */
580 config.phy_type = abilities.phy_type;
581 config.eee_capability = abilities.eee_capability;
582 config.eeer = abilities.eeer_val;
583 config.low_power_ctrl = abilities.d3_lpan;
585 /* set link and auto negotiation so changes take effect */
586 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
587 /* If link is up put link down */
588 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
589 /* Tell the OS link is going down, the link will go
590 * back up when fw says it is ready asynchronously
592 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
593 netif_carrier_off(netdev);
594 netif_tx_stop_all_queues(netdev);
597 /* make the aq call */
598 status = i40e_aq_set_phy_config(hw, &config, NULL);
600 netdev_info(netdev, "Set phy config failed with error %d.\n",
605 status = i40e_update_link_info(hw, true);
607 netdev_info(netdev, "Updating link info failed with error %d\n",
611 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
617 static int i40e_nway_reset(struct net_device *netdev)
619 /* restart autonegotiation */
620 struct i40e_netdev_priv *np = netdev_priv(netdev);
621 struct i40e_pf *pf = np->vsi->back;
622 struct i40e_hw *hw = &pf->hw;
623 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
626 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
628 netdev_info(netdev, "link restart failed, aq_err=%d\n",
629 pf->hw.aq.asq_last_status);
637 * i40e_get_pauseparam - Get Flow Control status
638 * Return tx/rx-pause status
640 static void i40e_get_pauseparam(struct net_device *netdev,
641 struct ethtool_pauseparam *pause)
643 struct i40e_netdev_priv *np = netdev_priv(netdev);
644 struct i40e_pf *pf = np->vsi->back;
645 struct i40e_hw *hw = &pf->hw;
646 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
649 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
650 AUTONEG_ENABLE : AUTONEG_DISABLE);
652 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
654 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
656 } else if (hw->fc.current_mode == I40E_FC_FULL) {
663 * i40e_set_pauseparam - Set Flow Control parameter
664 * @netdev: network interface device structure
665 * @pause: return tx/rx flow control status
667 static int i40e_set_pauseparam(struct net_device *netdev,
668 struct ethtool_pauseparam *pause)
670 struct i40e_netdev_priv *np = netdev_priv(netdev);
671 struct i40e_pf *pf = np->vsi->back;
672 struct i40e_vsi *vsi = np->vsi;
673 struct i40e_hw *hw = &pf->hw;
674 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
675 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
680 if (vsi != pf->vsi[pf->lan_vsi])
683 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
684 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
685 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
689 /* If we have link and don't have autoneg */
690 if (!test_bit(__I40E_DOWN, &pf->state) &&
691 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
692 /* Send message that it might not necessarily work*/
693 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
696 if (hw->fc.current_mode == I40E_FC_PFC) {
697 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
701 if (pause->rx_pause && pause->tx_pause)
702 hw->fc.requested_mode = I40E_FC_FULL;
703 else if (pause->rx_pause && !pause->tx_pause)
704 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
705 else if (!pause->rx_pause && pause->tx_pause)
706 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
707 else if (!pause->rx_pause && !pause->tx_pause)
708 hw->fc.requested_mode = I40E_FC_NONE;
712 /* Tell the OS link is going down, the link will go back up when fw
713 * says it is ready asynchronously
715 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
716 netif_carrier_off(netdev);
717 netif_tx_stop_all_queues(netdev);
719 /* Set the fc mode and only restart an if link is up*/
720 status = i40e_set_fc(hw, &aq_failures, link_up);
722 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
723 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
724 status, hw->aq.asq_last_status);
727 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
728 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
729 status, hw->aq.asq_last_status);
732 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
733 netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
734 status, hw->aq.asq_last_status);
738 if (!test_bit(__I40E_DOWN, &pf->state)) {
739 /* Give it a little more time to try to come back */
741 if (!test_bit(__I40E_DOWN, &pf->state))
742 return i40e_nway_reset(netdev);
748 static u32 i40e_get_msglevel(struct net_device *netdev)
750 struct i40e_netdev_priv *np = netdev_priv(netdev);
751 struct i40e_pf *pf = np->vsi->back;
753 return pf->msg_enable;
756 static void i40e_set_msglevel(struct net_device *netdev, u32 data)
758 struct i40e_netdev_priv *np = netdev_priv(netdev);
759 struct i40e_pf *pf = np->vsi->back;
761 if (I40E_DEBUG_USER & data)
762 pf->hw.debug_mask = data;
763 pf->msg_enable = data;
766 static int i40e_get_regs_len(struct net_device *netdev)
771 for (i = 0; i40e_reg_list[i].offset != 0; i++)
772 reg_count += i40e_reg_list[i].elements;
774 return reg_count * sizeof(u32);
777 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
780 struct i40e_netdev_priv *np = netdev_priv(netdev);
781 struct i40e_pf *pf = np->vsi->back;
782 struct i40e_hw *hw = &pf->hw;
787 /* Tell ethtool which driver-version-specific regs output we have.
789 * At some point, if we have ethtool doing special formatting of
790 * this data, it will rely on this version number to know how to
791 * interpret things. Hence, this needs to be updated if/when the
792 * diags register table is changed.
796 /* loop through the diags reg table for what to print */
798 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
799 for (j = 0; j < i40e_reg_list[i].elements; j++) {
800 reg = i40e_reg_list[i].offset
801 + (j * i40e_reg_list[i].stride);
802 reg_buf[ri++] = rd32(hw, reg);
808 static int i40e_get_eeprom(struct net_device *netdev,
809 struct ethtool_eeprom *eeprom, u8 *bytes)
811 struct i40e_netdev_priv *np = netdev_priv(netdev);
812 struct i40e_hw *hw = &np->vsi->back->hw;
813 struct i40e_pf *pf = np->vsi->back;
814 int ret_val = 0, len;
820 #define I40E_NVM_SECTOR_SIZE 4096
821 if (eeprom->len == 0)
824 /* check for NVMUpdate access method */
825 magic = hw->vendor_id | (hw->device_id << 16);
826 if (eeprom->magic && eeprom->magic != magic) {
829 /* make sure it is the right magic for NVMUpdate */
830 if ((eeprom->magic >> 16) != hw->device_id)
833 ret_val = i40e_nvmupd_command(hw,
834 (struct i40e_nvm_access *)eeprom,
837 dev_info(&pf->pdev->dev,
838 "NVMUpdate read failed err=%d status=0x%x\n",
839 ret_val, hw->aq.asq_last_status);
844 /* normal ethtool get_eeprom support */
845 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
847 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
851 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
853 dev_info(&pf->pdev->dev,
854 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
855 ret_val, hw->aq.asq_last_status);
859 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
860 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
861 len = I40E_NVM_SECTOR_SIZE;
863 for (i = 0; i < sectors; i++) {
864 if (i == (sectors - 1)) {
865 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
868 ret_val = i40e_aq_read_nvm(hw, 0x0,
869 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
871 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
874 dev_info(&pf->pdev->dev,
875 "read NVM failed err=%d status=0x%x\n",
876 ret_val, hw->aq.asq_last_status);
882 i40e_release_nvm(hw);
883 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
889 static int i40e_get_eeprom_len(struct net_device *netdev)
891 struct i40e_netdev_priv *np = netdev_priv(netdev);
892 struct i40e_hw *hw = &np->vsi->back->hw;
895 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
896 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
897 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
898 /* register returns value in power of 2, 64Kbyte chunks. */
899 val = (64 * 1024) * (1 << val);
903 static int i40e_set_eeprom(struct net_device *netdev,
904 struct ethtool_eeprom *eeprom, u8 *bytes)
906 struct i40e_netdev_priv *np = netdev_priv(netdev);
907 struct i40e_hw *hw = &np->vsi->back->hw;
908 struct i40e_pf *pf = np->vsi->back;
913 /* normal ethtool set_eeprom is not supported */
914 magic = hw->vendor_id | (hw->device_id << 16);
915 if (eeprom->magic == magic)
918 /* check for NVMUpdate access method */
919 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
922 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
923 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
926 ret_val = i40e_nvmupd_command(hw, (struct i40e_nvm_access *)eeprom,
929 dev_info(&pf->pdev->dev,
930 "NVMUpdate write failed err=%d status=0x%x\n",
931 ret_val, hw->aq.asq_last_status);
936 static void i40e_get_drvinfo(struct net_device *netdev,
937 struct ethtool_drvinfo *drvinfo)
939 struct i40e_netdev_priv *np = netdev_priv(netdev);
940 struct i40e_vsi *vsi = np->vsi;
941 struct i40e_pf *pf = vsi->back;
943 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
944 strlcpy(drvinfo->version, i40e_driver_version_str,
945 sizeof(drvinfo->version));
946 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
947 sizeof(drvinfo->fw_version));
948 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
949 sizeof(drvinfo->bus_info));
952 static void i40e_get_ringparam(struct net_device *netdev,
953 struct ethtool_ringparam *ring)
955 struct i40e_netdev_priv *np = netdev_priv(netdev);
956 struct i40e_pf *pf = np->vsi->back;
957 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
959 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
960 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
961 ring->rx_mini_max_pending = 0;
962 ring->rx_jumbo_max_pending = 0;
963 ring->rx_pending = vsi->rx_rings[0]->count;
964 ring->tx_pending = vsi->tx_rings[0]->count;
965 ring->rx_mini_pending = 0;
966 ring->rx_jumbo_pending = 0;
969 static int i40e_set_ringparam(struct net_device *netdev,
970 struct ethtool_ringparam *ring)
972 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
973 struct i40e_netdev_priv *np = netdev_priv(netdev);
974 struct i40e_vsi *vsi = np->vsi;
975 struct i40e_pf *pf = vsi->back;
976 u32 new_rx_count, new_tx_count;
979 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
982 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
983 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
984 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
985 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
987 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
988 ring->tx_pending, ring->rx_pending,
989 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
993 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
994 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
996 /* if nothing to do return success */
997 if ((new_tx_count == vsi->tx_rings[0]->count) &&
998 (new_rx_count == vsi->rx_rings[0]->count))
1001 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1002 usleep_range(1000, 2000);
1004 if (!netif_running(vsi->netdev)) {
1005 /* simple case - set for the next time the netdev is started */
1006 for (i = 0; i < vsi->num_queue_pairs; i++) {
1007 vsi->tx_rings[i]->count = new_tx_count;
1008 vsi->rx_rings[i]->count = new_rx_count;
1013 /* We can't just free everything and then setup again,
1014 * because the ISRs in MSI-X mode get passed pointers
1015 * to the Tx and Rx ring structs.
1018 /* alloc updated Tx resources */
1019 if (new_tx_count != vsi->tx_rings[0]->count) {
1021 "Changing Tx descriptor count from %d to %d.\n",
1022 vsi->tx_rings[0]->count, new_tx_count);
1023 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1024 sizeof(struct i40e_ring), GFP_KERNEL);
1030 for (i = 0; i < vsi->num_queue_pairs; i++) {
1031 /* clone ring and setup updated count */
1032 tx_rings[i] = *vsi->tx_rings[i];
1033 tx_rings[i].count = new_tx_count;
1034 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1038 i40e_free_tx_resources(&tx_rings[i]);
1048 /* alloc updated Rx resources */
1049 if (new_rx_count != vsi->rx_rings[0]->count) {
1051 "Changing Rx descriptor count from %d to %d\n",
1052 vsi->rx_rings[0]->count, new_rx_count);
1053 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1054 sizeof(struct i40e_ring), GFP_KERNEL);
1060 for (i = 0; i < vsi->num_queue_pairs; i++) {
1061 /* clone ring and setup updated count */
1062 rx_rings[i] = *vsi->rx_rings[i];
1063 rx_rings[i].count = new_rx_count;
1064 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1068 i40e_free_rx_resources(&rx_rings[i]);
1078 /* Bring interface down, copy in the new ring info,
1079 * then restore the interface
1084 for (i = 0; i < vsi->num_queue_pairs; i++) {
1085 i40e_free_tx_resources(vsi->tx_rings[i]);
1086 *vsi->tx_rings[i] = tx_rings[i];
1093 for (i = 0; i < vsi->num_queue_pairs; i++) {
1094 i40e_free_rx_resources(vsi->rx_rings[i]);
1095 *vsi->rx_rings[i] = rx_rings[i];
1104 /* error cleanup if the Rx allocations failed after getting Tx */
1106 for (i = 0; i < vsi->num_queue_pairs; i++)
1107 i40e_free_tx_resources(&tx_rings[i]);
1113 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1118 static int i40e_get_sset_count(struct net_device *netdev, int sset)
1120 struct i40e_netdev_priv *np = netdev_priv(netdev);
1121 struct i40e_vsi *vsi = np->vsi;
1122 struct i40e_pf *pf = vsi->back;
1126 return I40E_TEST_LEN;
1128 if (vsi == pf->vsi[pf->lan_vsi]) {
1129 int len = I40E_PF_STATS_LEN(netdev);
1131 if (pf->lan_veb != I40E_NO_VEB)
1132 len += I40E_VEB_STATS_LEN;
1135 return I40E_VSI_STATS_LEN(netdev);
1142 static void i40e_get_ethtool_stats(struct net_device *netdev,
1143 struct ethtool_stats *stats, u64 *data)
1145 struct i40e_netdev_priv *np = netdev_priv(netdev);
1146 struct i40e_ring *tx_ring, *rx_ring;
1147 struct i40e_vsi *vsi = np->vsi;
1148 struct i40e_pf *pf = vsi->back;
1152 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
1155 i40e_update_stats(vsi);
1157 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1158 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1159 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1160 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1162 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1163 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1164 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1165 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1168 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1169 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1170 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1171 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1175 for (j = 0; j < vsi->num_queue_pairs; j++) {
1176 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
1181 /* process Tx ring statistics */
1183 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
1184 data[i] = tx_ring->stats.packets;
1185 data[i + 1] = tx_ring->stats.bytes;
1186 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
1189 /* Rx ring is the 2nd half of the queue pair */
1190 rx_ring = &tx_ring[1];
1192 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
1193 data[i] = rx_ring->stats.packets;
1194 data[i + 1] = rx_ring->stats.bytes;
1195 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
1199 if (vsi != pf->vsi[pf->lan_vsi])
1202 if (pf->lan_veb != I40E_NO_VEB) {
1203 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1204 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1206 p += i40e_gstrings_veb_stats[j].stat_offset;
1207 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1208 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1211 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1212 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1213 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1214 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1216 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1217 data[i++] = pf->stats.priority_xon_tx[j];
1218 data[i++] = pf->stats.priority_xoff_tx[j];
1220 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1221 data[i++] = pf->stats.priority_xon_rx[j];
1222 data[i++] = pf->stats.priority_xoff_rx[j];
1224 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1225 data[i++] = pf->stats.priority_xon_2_xoff[j];
1228 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1231 struct i40e_netdev_priv *np = netdev_priv(netdev);
1232 struct i40e_vsi *vsi = np->vsi;
1233 struct i40e_pf *pf = vsi->back;
1234 char *p = (char *)data;
1237 switch (stringset) {
1239 for (i = 0; i < I40E_TEST_LEN; i++) {
1240 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1241 data += ETH_GSTRING_LEN;
1245 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1246 snprintf(p, ETH_GSTRING_LEN, "%s",
1247 i40e_gstrings_net_stats[i].stat_string);
1248 p += ETH_GSTRING_LEN;
1250 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1251 snprintf(p, ETH_GSTRING_LEN, "%s",
1252 i40e_gstrings_misc_stats[i].stat_string);
1253 p += ETH_GSTRING_LEN;
1256 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1257 snprintf(p, ETH_GSTRING_LEN, "%s",
1258 i40e_gstrings_fcoe_stats[i].stat_string);
1259 p += ETH_GSTRING_LEN;
1262 for (i = 0; i < vsi->num_queue_pairs; i++) {
1263 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1264 p += ETH_GSTRING_LEN;
1265 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1266 p += ETH_GSTRING_LEN;
1267 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1268 p += ETH_GSTRING_LEN;
1269 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1270 p += ETH_GSTRING_LEN;
1272 if (vsi != pf->vsi[pf->lan_vsi])
1275 if (pf->lan_veb != I40E_NO_VEB) {
1276 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1277 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1278 i40e_gstrings_veb_stats[i].stat_string);
1279 p += ETH_GSTRING_LEN;
1282 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1283 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1284 i40e_gstrings_stats[i].stat_string);
1285 p += ETH_GSTRING_LEN;
1287 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1288 snprintf(p, ETH_GSTRING_LEN,
1289 "port.tx_priority_%u_xon", i);
1290 p += ETH_GSTRING_LEN;
1291 snprintf(p, ETH_GSTRING_LEN,
1292 "port.tx_priority_%u_xoff", i);
1293 p += ETH_GSTRING_LEN;
1295 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1296 snprintf(p, ETH_GSTRING_LEN,
1297 "port.rx_priority_%u_xon", i);
1298 p += ETH_GSTRING_LEN;
1299 snprintf(p, ETH_GSTRING_LEN,
1300 "port.rx_priority_%u_xoff", i);
1301 p += ETH_GSTRING_LEN;
1303 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1304 snprintf(p, ETH_GSTRING_LEN,
1305 "port.rx_priority_%u_xon_2_xoff", i);
1306 p += ETH_GSTRING_LEN;
1308 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1313 static int i40e_get_ts_info(struct net_device *dev,
1314 struct ethtool_ts_info *info)
1316 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1318 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1319 SOF_TIMESTAMPING_RX_SOFTWARE |
1320 SOF_TIMESTAMPING_SOFTWARE |
1321 SOF_TIMESTAMPING_TX_HARDWARE |
1322 SOF_TIMESTAMPING_RX_HARDWARE |
1323 SOF_TIMESTAMPING_RAW_HARDWARE;
1326 info->phc_index = ptp_clock_index(pf->ptp_clock);
1328 info->phc_index = -1;
1330 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1332 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1333 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1334 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1335 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1336 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1337 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1338 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1339 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1340 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1341 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1342 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1343 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1348 static int i40e_link_test(struct net_device *netdev, u64 *data)
1350 struct i40e_netdev_priv *np = netdev_priv(netdev);
1351 struct i40e_pf *pf = np->vsi->back;
1353 netif_info(pf, hw, netdev, "link test\n");
1354 if (i40e_get_link_status(&pf->hw))
1362 static int i40e_reg_test(struct net_device *netdev, u64 *data)
1364 struct i40e_netdev_priv *np = netdev_priv(netdev);
1365 struct i40e_pf *pf = np->vsi->back;
1367 netif_info(pf, hw, netdev, "register test\n");
1368 *data = i40e_diag_reg_test(&pf->hw);
1373 static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
1375 struct i40e_netdev_priv *np = netdev_priv(netdev);
1376 struct i40e_pf *pf = np->vsi->back;
1378 netif_info(pf, hw, netdev, "eeprom test\n");
1379 *data = i40e_diag_eeprom_test(&pf->hw);
1384 static int i40e_intr_test(struct net_device *netdev, u64 *data)
1386 struct i40e_netdev_priv *np = netdev_priv(netdev);
1387 struct i40e_pf *pf = np->vsi->back;
1388 u16 swc_old = pf->sw_int_count;
1390 netif_info(pf, hw, netdev, "interrupt test\n");
1391 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1392 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1393 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
1394 usleep_range(1000, 2000);
1395 *data = (swc_old == pf->sw_int_count);
1400 static int i40e_loopback_test(struct net_device *netdev, u64 *data)
1402 struct i40e_netdev_priv *np = netdev_priv(netdev);
1403 struct i40e_pf *pf = np->vsi->back;
1405 netif_info(pf, hw, netdev, "loopback test not implemented\n");
1411 static void i40e_diag_test(struct net_device *netdev,
1412 struct ethtool_test *eth_test, u64 *data)
1414 struct i40e_netdev_priv *np = netdev_priv(netdev);
1415 struct i40e_pf *pf = np->vsi->back;
1417 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1419 netif_info(pf, drv, netdev, "offline testing starting\n");
1421 set_bit(__I40E_TESTING, &pf->state);
1423 /* Link test performed before hardware reset
1424 * so autoneg doesn't interfere with test result
1426 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1427 eth_test->flags |= ETH_TEST_FL_FAILED;
1429 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
1430 eth_test->flags |= ETH_TEST_FL_FAILED;
1432 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
1433 eth_test->flags |= ETH_TEST_FL_FAILED;
1435 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
1436 eth_test->flags |= ETH_TEST_FL_FAILED;
1438 /* run reg test last, a reset is required after it */
1439 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1440 eth_test->flags |= ETH_TEST_FL_FAILED;
1442 clear_bit(__I40E_TESTING, &pf->state);
1443 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
1446 netif_info(pf, drv, netdev, "online testing starting\n");
1448 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1449 eth_test->flags |= ETH_TEST_FL_FAILED;
1451 /* Offline only tests, not run in online; pass by default */
1452 data[I40E_ETH_TEST_REG] = 0;
1453 data[I40E_ETH_TEST_EEPROM] = 0;
1454 data[I40E_ETH_TEST_INTR] = 0;
1455 data[I40E_ETH_TEST_LOOPBACK] = 0;
1458 netif_info(pf, drv, netdev, "testing finished\n");
1461 static void i40e_get_wol(struct net_device *netdev,
1462 struct ethtool_wolinfo *wol)
1464 struct i40e_netdev_priv *np = netdev_priv(netdev);
1465 struct i40e_pf *pf = np->vsi->back;
1466 struct i40e_hw *hw = &pf->hw;
1469 /* NVM bit on means WoL disabled for the port */
1470 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1471 if ((1 << hw->port) & wol_nvm_bits) {
1475 wol->supported = WAKE_MAGIC;
1476 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1480 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1482 struct i40e_netdev_priv *np = netdev_priv(netdev);
1483 struct i40e_pf *pf = np->vsi->back;
1484 struct i40e_hw *hw = &pf->hw;
1487 /* NVM bit on means WoL disabled for the port */
1488 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1489 if (((1 << hw->port) & wol_nvm_bits))
1492 /* only magic packet is supported */
1493 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1496 /* is this a new value? */
1497 if (pf->wol_en != !!wol->wolopts) {
1498 pf->wol_en = !!wol->wolopts;
1499 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1505 static int i40e_set_phys_id(struct net_device *netdev,
1506 enum ethtool_phys_id_state state)
1508 struct i40e_netdev_priv *np = netdev_priv(netdev);
1509 struct i40e_pf *pf = np->vsi->back;
1510 struct i40e_hw *hw = &pf->hw;
1514 case ETHTOOL_ID_ACTIVE:
1515 pf->led_status = i40e_led_get(hw);
1518 i40e_led_set(hw, 0xF, false);
1520 case ETHTOOL_ID_OFF:
1521 i40e_led_set(hw, 0x0, false);
1523 case ETHTOOL_ID_INACTIVE:
1524 i40e_led_set(hw, pf->led_status, false);
1531 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1532 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1533 * 125us (8000 interrupts per second) == ITR(62)
1536 static int i40e_get_coalesce(struct net_device *netdev,
1537 struct ethtool_coalesce *ec)
1539 struct i40e_netdev_priv *np = netdev_priv(netdev);
1540 struct i40e_vsi *vsi = np->vsi;
1542 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1543 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1545 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
1546 ec->use_adaptive_rx_coalesce = 1;
1548 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
1549 ec->use_adaptive_tx_coalesce = 1;
1551 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1552 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1557 static int i40e_set_coalesce(struct net_device *netdev,
1558 struct ethtool_coalesce *ec)
1560 struct i40e_netdev_priv *np = netdev_priv(netdev);
1561 struct i40e_q_vector *q_vector;
1562 struct i40e_vsi *vsi = np->vsi;
1563 struct i40e_pf *pf = vsi->back;
1564 struct i40e_hw *hw = &pf->hw;
1568 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1569 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1571 vector = vsi->base_vector;
1572 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1573 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
1574 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1575 } else if (ec->rx_coalesce_usecs == 0) {
1576 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1577 if (ec->use_adaptive_rx_coalesce)
1578 netif_info(pf, drv, netdev,
1579 "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n");
1581 netif_info(pf, drv, netdev,
1582 "Invalid value, Rx-usecs range is 0, 8-8160\n");
1586 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1587 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
1588 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1589 } else if (ec->tx_coalesce_usecs == 0) {
1590 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1591 if (ec->use_adaptive_tx_coalesce)
1592 netif_info(pf, drv, netdev,
1593 "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n");
1595 netif_info(pf, drv, netdev,
1596 "Invalid value, Tx-usecs range is 0, 8-8160\n");
1600 if (ec->use_adaptive_rx_coalesce)
1601 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1603 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1605 if (ec->use_adaptive_tx_coalesce)
1606 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1608 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
1610 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1611 q_vector = vsi->q_vectors[i];
1612 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1613 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1614 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1615 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1623 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1624 * @pf: pointer to the physical function struct
1625 * @cmd: ethtool rxnfc command
1627 * Returns Success if the flow is supported, else Invalid Input.
1629 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1633 /* Report default options for RSS on i40e */
1634 switch (cmd->flow_type) {
1637 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1638 /* fall through to add IP fields */
1640 case AH_ESP_V4_FLOW:
1644 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1648 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1649 /* fall through to add IP fields */
1651 case AH_ESP_V6_FLOW:
1655 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1665 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1666 * @pf: Pointer to the physical function struct
1667 * @cmd: The command to get or set Rx flow classification rules
1668 * @rule_locs: Array of used rule locations
1670 * This function populates both the total and actual rule count of
1671 * the ethtool flow classification command
1673 * Returns 0 on success or -EMSGSIZE if entry not found
1675 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1676 struct ethtool_rxnfc *cmd,
1679 struct i40e_fdir_filter *rule;
1680 struct hlist_node *node2;
1683 /* report total rule count */
1684 cmd->data = i40e_get_fd_cnt_all(pf);
1686 hlist_for_each_entry_safe(rule, node2,
1687 &pf->fdir_filter_list, fdir_node) {
1688 if (cnt == cmd->rule_cnt)
1691 rule_locs[cnt] = rule->fd_id;
1695 cmd->rule_cnt = cnt;
1701 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1702 * @pf: Pointer to the physical function struct
1703 * @cmd: The command to get or set Rx flow classification rules
1705 * This function looks up a filter based on the Rx flow classification
1706 * command and fills the flow spec info for it if found
1708 * Returns 0 on success or -EINVAL if filter not found
1710 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1711 struct ethtool_rxnfc *cmd)
1713 struct ethtool_rx_flow_spec *fsp =
1714 (struct ethtool_rx_flow_spec *)&cmd->fs;
1715 struct i40e_fdir_filter *rule = NULL;
1716 struct hlist_node *node2;
1718 hlist_for_each_entry_safe(rule, node2,
1719 &pf->fdir_filter_list, fdir_node) {
1720 if (fsp->location <= rule->fd_id)
1724 if (!rule || fsp->location != rule->fd_id)
1727 fsp->flow_type = rule->flow_type;
1728 if (fsp->flow_type == IP_USER_FLOW) {
1729 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1730 fsp->h_u.usr_ip4_spec.proto = 0;
1731 fsp->m_u.usr_ip4_spec.proto = 0;
1734 /* Reverse the src and dest notion, since the HW views them from
1735 * Tx perspective where as the user expects it from Rx filter view.
1737 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1738 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1739 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1740 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
1742 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1743 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1745 fsp->ring_cookie = rule->q_index;
1751 * i40e_get_rxnfc - command to get RX flow classification rules
1752 * @netdev: network interface device structure
1753 * @cmd: ethtool rxnfc command
1755 * Returns Success if the command is supported.
1757 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1760 struct i40e_netdev_priv *np = netdev_priv(netdev);
1761 struct i40e_vsi *vsi = np->vsi;
1762 struct i40e_pf *pf = vsi->back;
1763 int ret = -EOPNOTSUPP;
1766 case ETHTOOL_GRXRINGS:
1767 cmd->data = vsi->alloc_queue_pairs;
1771 ret = i40e_get_rss_hash_opts(pf, cmd);
1773 case ETHTOOL_GRXCLSRLCNT:
1774 cmd->rule_cnt = pf->fdir_pf_active_filters;
1775 /* report total rule count */
1776 cmd->data = i40e_get_fd_cnt_all(pf);
1779 case ETHTOOL_GRXCLSRULE:
1780 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
1782 case ETHTOOL_GRXCLSRLALL:
1783 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1793 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1794 * @pf: pointer to the physical function struct
1795 * @cmd: ethtool rxnfc command
1797 * Returns Success if the flow input set is supported.
1799 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1801 struct i40e_hw *hw = &pf->hw;
1802 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1803 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1805 /* RSS does not support anything other than hashing
1806 * to queues on src and dst IPs and ports
1808 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1809 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1812 /* We need at least the IP SRC and DEST fields for hashing */
1813 if (!(nfc->data & RXH_IP_SRC) ||
1814 !(nfc->data & RXH_IP_DST))
1817 switch (nfc->flow_type) {
1819 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1821 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1823 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1824 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1831 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1833 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1835 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1836 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1843 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1845 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1846 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1848 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1849 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1850 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1857 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1859 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1860 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1862 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1863 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1864 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1870 case AH_ESP_V4_FLOW:
1874 if ((nfc->data & RXH_L4_B_0_1) ||
1875 (nfc->data & RXH_L4_B_2_3))
1877 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1879 case AH_ESP_V6_FLOW:
1883 if ((nfc->data & RXH_L4_B_0_1) ||
1884 (nfc->data & RXH_L4_B_2_3))
1886 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1889 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1890 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1893 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1894 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1900 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1901 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1908 * i40e_match_fdir_input_set - Match a new filter against an existing one
1909 * @rule: The filter already added
1910 * @input: The new filter to comapre against
1912 * Returns true if the two input set match
1914 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1915 struct i40e_fdir_filter *input)
1917 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1918 (rule->src_ip[0] != input->src_ip[0]) ||
1919 (rule->dst_port != input->dst_port) ||
1920 (rule->src_port != input->src_port))
1926 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1927 * @vsi: Pointer to the targeted VSI
1928 * @input: The filter to update or NULL to indicate deletion
1929 * @sw_idx: Software index to the filter
1930 * @cmd: The command to get or set Rx flow classification rules
1932 * This function updates (or deletes) a Flow Director entry from
1933 * the hlist of the corresponding PF
1935 * Returns 0 on success
1937 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1938 struct i40e_fdir_filter *input,
1940 struct ethtool_rxnfc *cmd)
1942 struct i40e_fdir_filter *rule, *parent;
1943 struct i40e_pf *pf = vsi->back;
1944 struct hlist_node *node2;
1950 hlist_for_each_entry_safe(rule, node2,
1951 &pf->fdir_filter_list, fdir_node) {
1952 /* hash found, or no matching entry */
1953 if (rule->fd_id >= sw_idx)
1958 /* if there is an old rule occupying our place remove it */
1959 if (rule && (rule->fd_id == sw_idx)) {
1960 if (input && !i40e_match_fdir_input_set(rule, input))
1961 err = i40e_add_del_fdir(vsi, rule, false);
1963 err = i40e_add_del_fdir(vsi, rule, false);
1964 hlist_del(&rule->fdir_node);
1966 pf->fdir_pf_active_filters--;
1969 /* If no input this was a delete, err should be 0 if a rule was
1970 * successfully found and removed from the list else -EINVAL
1975 /* initialize node and set software index */
1976 INIT_HLIST_NODE(&input->fdir_node);
1978 /* add filter to the list */
1980 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
1982 hlist_add_head(&input->fdir_node,
1983 &pf->fdir_filter_list);
1986 pf->fdir_pf_active_filters++;
1992 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1993 * @vsi: Pointer to the targeted VSI
1994 * @cmd: The command to get or set Rx flow classification rules
1996 * The function removes a Flow Director filter entry from the
1997 * hlist of the corresponding PF
1999 * Returns 0 on success
2001 static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2002 struct ethtool_rxnfc *cmd)
2004 struct ethtool_rx_flow_spec *fsp =
2005 (struct ethtool_rx_flow_spec *)&cmd->fs;
2006 struct i40e_pf *pf = vsi->back;
2009 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2010 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2013 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2016 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
2018 i40e_fdir_check_and_reenable(pf);
2023 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
2024 * @vsi: pointer to the targeted VSI
2025 * @cmd: command to get or set RX flow classification rules
2027 * Add Flow Director filters for a specific flow spec based on their
2028 * protocol. Returns 0 if the filters were successfully added.
2030 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2031 struct ethtool_rxnfc *cmd)
2033 struct ethtool_rx_flow_spec *fsp;
2034 struct i40e_fdir_filter *input;
2043 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2046 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
2049 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2050 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2053 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2056 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2058 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2059 pf->hw.func_caps.fd_filters_guaranteed)) {
2063 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2064 (fsp->ring_cookie >= vsi->num_queue_pairs))
2067 input = kzalloc(sizeof(*input), GFP_KERNEL);
2072 input->fd_id = fsp->location;
2074 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2075 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2078 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2080 input->q_index = fsp->ring_cookie;
2081 input->flex_off = 0;
2083 input->dest_vsi = vsi->id;
2084 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
2085 input->cnt_index = pf->fd_sb_cnt_idx;
2086 input->flow_type = fsp->flow_type;
2087 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
2089 /* Reverse the src and dest notion, since the HW expects them to be from
2090 * Tx perspective where as the input from user is from Rx filter view.
2092 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2093 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2094 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2095 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
2097 ret = i40e_add_del_fdir(vsi, input, true);
2101 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
2107 * i40e_set_rxnfc - command to set RX flow classification rules
2108 * @netdev: network interface device structure
2109 * @cmd: ethtool rxnfc command
2111 * Returns Success if the command is supported.
2113 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2115 struct i40e_netdev_priv *np = netdev_priv(netdev);
2116 struct i40e_vsi *vsi = np->vsi;
2117 struct i40e_pf *pf = vsi->back;
2118 int ret = -EOPNOTSUPP;
2122 ret = i40e_set_rss_hash_opt(pf, cmd);
2124 case ETHTOOL_SRXCLSRLINS:
2125 ret = i40e_add_fdir_ethtool(vsi, cmd);
2127 case ETHTOOL_SRXCLSRLDEL:
2128 ret = i40e_del_fdir_entry(vsi, cmd);
2138 * i40e_max_channels - get Max number of combined channels supported
2141 static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2143 /* TODO: This code assumes DCB and FD is disabled for now. */
2144 return vsi->alloc_queue_pairs;
2148 * i40e_get_channels - Get the current channels enabled and max supported etc.
2149 * @netdev: network interface device structure
2150 * @ch: ethtool channels structure
2152 * We don't support separate tx and rx queues as channels. The other count
2153 * represents how many queues are being used for control. max_combined counts
2154 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2155 * q_vectors since we support a lot more queue pairs than q_vectors.
2157 static void i40e_get_channels(struct net_device *dev,
2158 struct ethtool_channels *ch)
2160 struct i40e_netdev_priv *np = netdev_priv(dev);
2161 struct i40e_vsi *vsi = np->vsi;
2162 struct i40e_pf *pf = vsi->back;
2164 /* report maximum channels */
2165 ch->max_combined = i40e_max_channels(vsi);
2167 /* report info for other vector */
2168 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
2169 ch->max_other = ch->other_count;
2171 /* Note: This code assumes DCB is disabled for now. */
2172 ch->combined_count = vsi->num_queue_pairs;
2176 * i40e_set_channels - Set the new channels count.
2177 * @netdev: network interface device structure
2178 * @ch: ethtool channels structure
2180 * The new channels count may not be the same as requested by the user
2181 * since it gets rounded down to a power of 2 value.
2183 static int i40e_set_channels(struct net_device *dev,
2184 struct ethtool_channels *ch)
2186 struct i40e_netdev_priv *np = netdev_priv(dev);
2187 unsigned int count = ch->combined_count;
2188 struct i40e_vsi *vsi = np->vsi;
2189 struct i40e_pf *pf = vsi->back;
2192 /* We do not support setting channels for any other VSI at present */
2193 if (vsi->type != I40E_VSI_MAIN)
2196 /* verify they are not requesting separate vectors */
2197 if (!count || ch->rx_count || ch->tx_count)
2200 /* verify other_count has not changed */
2201 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
2204 /* verify the number of channels does not exceed hardware limits */
2205 if (count > i40e_max_channels(vsi))
2208 /* update feature limits from largest to smallest supported values */
2209 /* TODO: Flow director limit, DCB etc */
2212 if (count > pf->rss_size_max)
2213 count = pf->rss_size_max;
2215 /* use rss_reconfig to rebuild with new queue count and update traffic
2216 * class queue mapping
2218 new_count = i40e_reconfig_rss_queues(pf, count);
2225 static const struct ethtool_ops i40e_ethtool_ops = {
2226 .get_settings = i40e_get_settings,
2227 .set_settings = i40e_set_settings,
2228 .get_drvinfo = i40e_get_drvinfo,
2229 .get_regs_len = i40e_get_regs_len,
2230 .get_regs = i40e_get_regs,
2231 .nway_reset = i40e_nway_reset,
2232 .get_link = ethtool_op_get_link,
2233 .get_wol = i40e_get_wol,
2234 .set_wol = i40e_set_wol,
2235 .set_eeprom = i40e_set_eeprom,
2236 .get_eeprom_len = i40e_get_eeprom_len,
2237 .get_eeprom = i40e_get_eeprom,
2238 .get_ringparam = i40e_get_ringparam,
2239 .set_ringparam = i40e_set_ringparam,
2240 .get_pauseparam = i40e_get_pauseparam,
2241 .set_pauseparam = i40e_set_pauseparam,
2242 .get_msglevel = i40e_get_msglevel,
2243 .set_msglevel = i40e_set_msglevel,
2244 .get_rxnfc = i40e_get_rxnfc,
2245 .set_rxnfc = i40e_set_rxnfc,
2246 .self_test = i40e_diag_test,
2247 .get_strings = i40e_get_strings,
2248 .set_phys_id = i40e_set_phys_id,
2249 .get_sset_count = i40e_get_sset_count,
2250 .get_ethtool_stats = i40e_get_ethtool_stats,
2251 .get_coalesce = i40e_get_coalesce,
2252 .set_coalesce = i40e_set_coalesce,
2253 .get_channels = i40e_get_channels,
2254 .set_channels = i40e_set_channels,
2255 .get_ts_info = i40e_get_ts_info,
2258 void i40e_set_ethtool_ops(struct net_device *netdev)
2260 netdev->ethtool_ops = &i40e_ethtool_ops;