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;
268 /* all the rest are 10G/1G */
269 ecmd->supported = SUPPORTED_10000baseT_Full |
270 SUPPORTED_1000baseT_Full;
271 ecmd->advertising = ADVERTISED_10000baseT_Full |
272 ADVERTISED_1000baseT_Full;
276 /* skip phy_type use as it is zero when link is down */
277 goto no_valid_phy_type;
280 switch (hw_link_info->phy_type) {
281 case I40E_PHY_TYPE_40GBASE_CR4:
282 case I40E_PHY_TYPE_40GBASE_CR4_CU:
283 ecmd->supported = SUPPORTED_Autoneg |
284 SUPPORTED_40000baseCR4_Full;
285 ecmd->advertising = ADVERTISED_Autoneg |
286 ADVERTISED_40000baseCR4_Full;
288 case I40E_PHY_TYPE_40GBASE_KR4:
289 ecmd->supported = SUPPORTED_Autoneg |
290 SUPPORTED_40000baseKR4_Full;
291 ecmd->advertising = ADVERTISED_Autoneg |
292 ADVERTISED_40000baseKR4_Full;
294 case I40E_PHY_TYPE_40GBASE_SR4:
295 case I40E_PHY_TYPE_XLPPI:
296 case I40E_PHY_TYPE_XLAUI:
297 ecmd->supported = SUPPORTED_40000baseSR4_Full;
299 case I40E_PHY_TYPE_40GBASE_LR4:
300 ecmd->supported = SUPPORTED_40000baseLR4_Full;
302 case I40E_PHY_TYPE_10GBASE_KX4:
303 ecmd->supported = SUPPORTED_Autoneg |
304 SUPPORTED_10000baseKX4_Full;
305 ecmd->advertising = ADVERTISED_Autoneg |
306 ADVERTISED_10000baseKX4_Full;
308 case I40E_PHY_TYPE_10GBASE_KR:
309 ecmd->supported = SUPPORTED_Autoneg |
310 SUPPORTED_10000baseKR_Full;
311 ecmd->advertising = ADVERTISED_Autoneg |
312 ADVERTISED_10000baseKR_Full;
314 case I40E_PHY_TYPE_10GBASE_SR:
315 case I40E_PHY_TYPE_10GBASE_LR:
316 case I40E_PHY_TYPE_1000BASE_SX:
317 case I40E_PHY_TYPE_1000BASE_LX:
318 ecmd->supported = SUPPORTED_10000baseT_Full;
319 ecmd->supported |= SUPPORTED_1000baseT_Full;
321 case I40E_PHY_TYPE_10GBASE_CR1_CU:
322 case I40E_PHY_TYPE_10GBASE_CR1:
323 case I40E_PHY_TYPE_10GBASE_T:
324 ecmd->supported = SUPPORTED_Autoneg |
325 SUPPORTED_10000baseT_Full;
326 ecmd->advertising = ADVERTISED_Autoneg |
327 ADVERTISED_10000baseT_Full;
329 case I40E_PHY_TYPE_XAUI:
330 case I40E_PHY_TYPE_XFI:
331 case I40E_PHY_TYPE_SFI:
332 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
333 ecmd->supported = SUPPORTED_10000baseT_Full;
335 case I40E_PHY_TYPE_1000BASE_KX:
336 case I40E_PHY_TYPE_1000BASE_T:
337 ecmd->supported = SUPPORTED_Autoneg |
338 SUPPORTED_1000baseT_Full;
339 ecmd->advertising = ADVERTISED_Autoneg |
340 ADVERTISED_1000baseT_Full;
342 case I40E_PHY_TYPE_100BASE_TX:
343 ecmd->supported = SUPPORTED_Autoneg |
344 SUPPORTED_100baseT_Full;
345 ecmd->advertising = ADVERTISED_Autoneg |
346 ADVERTISED_100baseT_Full;
348 case I40E_PHY_TYPE_SGMII:
349 ecmd->supported = SUPPORTED_Autoneg |
350 SUPPORTED_1000baseT_Full |
351 SUPPORTED_100baseT_Full;
352 ecmd->advertising = ADVERTISED_Autoneg |
353 ADVERTISED_1000baseT_Full |
354 ADVERTISED_100baseT_Full;
357 /* if we got here and link is up something bad is afoot */
358 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
359 hw_link_info->phy_type);
363 /* this is if autoneg is enabled or disabled */
364 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
365 AUTONEG_ENABLE : AUTONEG_DISABLE);
367 switch (hw->phy.media_type) {
368 case I40E_MEDIA_TYPE_BACKPLANE:
369 ecmd->supported |= SUPPORTED_Autoneg |
371 ecmd->advertising |= ADVERTISED_Autoneg |
372 ADVERTISED_Backplane;
373 ecmd->port = PORT_NONE;
375 case I40E_MEDIA_TYPE_BASET:
376 ecmd->supported |= SUPPORTED_TP;
377 ecmd->advertising |= ADVERTISED_TP;
378 ecmd->port = PORT_TP;
380 case I40E_MEDIA_TYPE_DA:
381 case I40E_MEDIA_TYPE_CX4:
382 ecmd->supported |= SUPPORTED_FIBRE;
383 ecmd->advertising |= ADVERTISED_FIBRE;
384 ecmd->port = PORT_DA;
386 case I40E_MEDIA_TYPE_FIBER:
387 ecmd->supported |= SUPPORTED_FIBRE;
388 ecmd->port = PORT_FIBRE;
390 case I40E_MEDIA_TYPE_UNKNOWN:
392 ecmd->port = PORT_OTHER;
396 ecmd->transceiver = XCVR_EXTERNAL;
398 ecmd->supported |= SUPPORTED_Pause;
400 switch (hw->fc.current_mode) {
402 ecmd->advertising |= ADVERTISED_Pause;
404 case I40E_FC_TX_PAUSE:
405 ecmd->advertising |= ADVERTISED_Asym_Pause;
407 case I40E_FC_RX_PAUSE:
408 ecmd->advertising |= (ADVERTISED_Pause |
409 ADVERTISED_Asym_Pause);
412 ecmd->advertising &= ~(ADVERTISED_Pause |
413 ADVERTISED_Asym_Pause);
418 switch (link_speed) {
419 case I40E_LINK_SPEED_40GB:
420 /* need a SPEED_40000 in ethtool.h */
421 ethtool_cmd_speed_set(ecmd, 40000);
423 case I40E_LINK_SPEED_10GB:
424 ethtool_cmd_speed_set(ecmd, SPEED_10000);
426 case I40E_LINK_SPEED_1GB:
427 ethtool_cmd_speed_set(ecmd, SPEED_1000);
432 ecmd->duplex = DUPLEX_FULL;
434 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
435 ecmd->duplex = DUPLEX_UNKNOWN;
442 * i40e_set_settings - Set Speed and Duplex
443 * @netdev: network interface device structure
444 * @ecmd: ethtool command
446 * Set speed/duplex per media_types advertised/forced
448 static int i40e_set_settings(struct net_device *netdev,
449 struct ethtool_cmd *ecmd)
451 struct i40e_netdev_priv *np = netdev_priv(netdev);
452 struct i40e_aq_get_phy_abilities_resp abilities;
453 struct i40e_aq_set_phy_config config;
454 struct i40e_pf *pf = np->vsi->back;
455 struct i40e_vsi *vsi = np->vsi;
456 struct i40e_hw *hw = &pf->hw;
457 struct ethtool_cmd safe_ecmd;
458 i40e_status status = 0;
464 if (vsi != pf->vsi[pf->lan_vsi])
467 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
468 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
469 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
470 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
473 /* get our own copy of the bits to check against */
474 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
475 i40e_get_settings(netdev, &safe_ecmd);
477 /* save autoneg and speed out of ecmd */
478 autoneg = ecmd->autoneg;
479 advertise = ecmd->advertising;
481 /* set autoneg and speed back to what they currently are */
482 ecmd->autoneg = safe_ecmd.autoneg;
483 ecmd->advertising = safe_ecmd.advertising;
485 ecmd->cmd = safe_ecmd.cmd;
486 /* If ecmd and safe_ecmd are not the same now, then they are
487 * trying to set something that we do not support
489 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
492 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
493 usleep_range(1000, 2000);
495 /* Get the current phy config */
496 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
501 /* Copy abilities to config in case autoneg is not
504 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
505 config.abilities = abilities.abilities;
508 if (autoneg == AUTONEG_ENABLE) {
509 /* If autoneg is not supported, return error */
510 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
511 netdev_info(netdev, "Autoneg not supported on this phy\n");
514 /* If autoneg was not already enabled */
515 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
516 config.abilities = abilities.abilities |
517 I40E_AQ_PHY_ENABLE_AN;
521 /* If autoneg is supported 10GBASE_T is the only phy that
522 * can disable it, so otherwise return error
524 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
525 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
526 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
529 /* If autoneg is currently enabled */
530 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
531 config.abilities = abilities.abilities |
532 ~I40E_AQ_PHY_ENABLE_AN;
537 if (advertise & ~safe_ecmd.supported)
540 if (advertise & ADVERTISED_100baseT_Full)
541 config.link_speed |= I40E_LINK_SPEED_100MB;
542 if (advertise & ADVERTISED_1000baseT_Full ||
543 advertise & ADVERTISED_1000baseKX_Full)
544 config.link_speed |= I40E_LINK_SPEED_1GB;
545 if (advertise & ADVERTISED_10000baseT_Full ||
546 advertise & ADVERTISED_10000baseKX4_Full ||
547 advertise & ADVERTISED_10000baseKR_Full)
548 config.link_speed |= I40E_LINK_SPEED_10GB;
549 if (advertise & ADVERTISED_40000baseKR4_Full ||
550 advertise & ADVERTISED_40000baseCR4_Full ||
551 advertise & ADVERTISED_40000baseSR4_Full ||
552 advertise & ADVERTISED_40000baseLR4_Full)
553 config.link_speed |= I40E_LINK_SPEED_40GB;
555 if (change || (abilities.link_speed != config.link_speed)) {
556 /* copy over the rest of the abilities */
557 config.phy_type = abilities.phy_type;
558 config.eee_capability = abilities.eee_capability;
559 config.eeer = abilities.eeer_val;
560 config.low_power_ctrl = abilities.d3_lpan;
562 /* If link is up set link and an so changes take effect */
563 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
564 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
566 /* make the aq call */
567 status = i40e_aq_set_phy_config(hw, &config, NULL);
569 netdev_info(netdev, "Set phy config failed with error %d.\n",
574 status = i40e_update_link_info(hw, true);
576 netdev_info(netdev, "Updating link info failed with error %d\n",
580 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
586 static int i40e_nway_reset(struct net_device *netdev)
588 /* restart autonegotiation */
589 struct i40e_netdev_priv *np = netdev_priv(netdev);
590 struct i40e_pf *pf = np->vsi->back;
591 struct i40e_hw *hw = &pf->hw;
592 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
595 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
597 netdev_info(netdev, "link restart failed, aq_err=%d\n",
598 pf->hw.aq.asq_last_status);
606 * i40e_get_pauseparam - Get Flow Control status
607 * Return tx/rx-pause status
609 static void i40e_get_pauseparam(struct net_device *netdev,
610 struct ethtool_pauseparam *pause)
612 struct i40e_netdev_priv *np = netdev_priv(netdev);
613 struct i40e_pf *pf = np->vsi->back;
614 struct i40e_hw *hw = &pf->hw;
615 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
618 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
619 AUTONEG_ENABLE : AUTONEG_DISABLE);
621 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
623 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
625 } else if (hw->fc.current_mode == I40E_FC_FULL) {
632 * i40e_set_pauseparam - Set Flow Control parameter
633 * @netdev: network interface device structure
634 * @pause: return tx/rx flow control status
636 static int i40e_set_pauseparam(struct net_device *netdev,
637 struct ethtool_pauseparam *pause)
639 struct i40e_netdev_priv *np = netdev_priv(netdev);
640 struct i40e_pf *pf = np->vsi->back;
641 struct i40e_vsi *vsi = np->vsi;
642 struct i40e_hw *hw = &pf->hw;
643 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
644 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
649 if (vsi != pf->vsi[pf->lan_vsi])
652 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
653 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
654 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
658 /* If we have link and don't have autoneg */
659 if (!test_bit(__I40E_DOWN, &pf->state) &&
660 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
661 /* Send message that it might not necessarily work*/
662 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
665 if (hw->fc.current_mode == I40E_FC_PFC) {
666 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
670 if (pause->rx_pause && pause->tx_pause)
671 hw->fc.requested_mode = I40E_FC_FULL;
672 else if (pause->rx_pause && !pause->tx_pause)
673 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
674 else if (!pause->rx_pause && pause->tx_pause)
675 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
676 else if (!pause->rx_pause && !pause->tx_pause)
677 hw->fc.requested_mode = I40E_FC_NONE;
681 /* Set the fc mode and only restart an if link is up*/
682 status = i40e_set_fc(hw, &aq_failures, link_up);
684 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
685 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
686 status, hw->aq.asq_last_status);
689 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
690 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
691 status, hw->aq.asq_last_status);
694 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
695 netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
696 status, hw->aq.asq_last_status);
700 if (!test_bit(__I40E_DOWN, &pf->state)) {
701 /* Give it a little more time to try to come back */
703 if (!test_bit(__I40E_DOWN, &pf->state))
704 return i40e_nway_reset(netdev);
710 static u32 i40e_get_msglevel(struct net_device *netdev)
712 struct i40e_netdev_priv *np = netdev_priv(netdev);
713 struct i40e_pf *pf = np->vsi->back;
715 return pf->msg_enable;
718 static void i40e_set_msglevel(struct net_device *netdev, u32 data)
720 struct i40e_netdev_priv *np = netdev_priv(netdev);
721 struct i40e_pf *pf = np->vsi->back;
723 if (I40E_DEBUG_USER & data)
724 pf->hw.debug_mask = data;
725 pf->msg_enable = data;
728 static int i40e_get_regs_len(struct net_device *netdev)
733 for (i = 0; i40e_reg_list[i].offset != 0; i++)
734 reg_count += i40e_reg_list[i].elements;
736 return reg_count * sizeof(u32);
739 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
742 struct i40e_netdev_priv *np = netdev_priv(netdev);
743 struct i40e_pf *pf = np->vsi->back;
744 struct i40e_hw *hw = &pf->hw;
749 /* Tell ethtool which driver-version-specific regs output we have.
751 * At some point, if we have ethtool doing special formatting of
752 * this data, it will rely on this version number to know how to
753 * interpret things. Hence, this needs to be updated if/when the
754 * diags register table is changed.
758 /* loop through the diags reg table for what to print */
760 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
761 for (j = 0; j < i40e_reg_list[i].elements; j++) {
762 reg = i40e_reg_list[i].offset
763 + (j * i40e_reg_list[i].stride);
764 reg_buf[ri++] = rd32(hw, reg);
770 static int i40e_get_eeprom(struct net_device *netdev,
771 struct ethtool_eeprom *eeprom, u8 *bytes)
773 struct i40e_netdev_priv *np = netdev_priv(netdev);
774 struct i40e_hw *hw = &np->vsi->back->hw;
775 struct i40e_pf *pf = np->vsi->back;
776 int ret_val = 0, len;
782 #define I40E_NVM_SECTOR_SIZE 4096
783 if (eeprom->len == 0)
786 /* check for NVMUpdate access method */
787 magic = hw->vendor_id | (hw->device_id << 16);
788 if (eeprom->magic && eeprom->magic != magic) {
791 /* make sure it is the right magic for NVMUpdate */
792 if ((eeprom->magic >> 16) != hw->device_id)
795 ret_val = i40e_nvmupd_command(hw,
796 (struct i40e_nvm_access *)eeprom,
799 dev_info(&pf->pdev->dev,
800 "NVMUpdate read failed err=%d status=0x%x\n",
801 ret_val, hw->aq.asq_last_status);
806 /* normal ethtool get_eeprom support */
807 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
809 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
813 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
815 dev_info(&pf->pdev->dev,
816 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
817 ret_val, hw->aq.asq_last_status);
821 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
822 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
823 len = I40E_NVM_SECTOR_SIZE;
825 for (i = 0; i < sectors; i++) {
826 if (i == (sectors - 1)) {
827 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
830 ret_val = i40e_aq_read_nvm(hw, 0x0,
831 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
833 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
836 dev_info(&pf->pdev->dev,
837 "read NVM failed err=%d status=0x%x\n",
838 ret_val, hw->aq.asq_last_status);
844 i40e_release_nvm(hw);
845 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
851 static int i40e_get_eeprom_len(struct net_device *netdev)
853 struct i40e_netdev_priv *np = netdev_priv(netdev);
854 struct i40e_hw *hw = &np->vsi->back->hw;
857 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
858 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
859 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
860 /* register returns value in power of 2, 64Kbyte chunks. */
861 val = (64 * 1024) * (1 << val);
865 static int i40e_set_eeprom(struct net_device *netdev,
866 struct ethtool_eeprom *eeprom, u8 *bytes)
868 struct i40e_netdev_priv *np = netdev_priv(netdev);
869 struct i40e_hw *hw = &np->vsi->back->hw;
870 struct i40e_pf *pf = np->vsi->back;
875 /* normal ethtool set_eeprom is not supported */
876 magic = hw->vendor_id | (hw->device_id << 16);
877 if (eeprom->magic == magic)
880 /* check for NVMUpdate access method */
881 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
884 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
885 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
888 ret_val = i40e_nvmupd_command(hw, (struct i40e_nvm_access *)eeprom,
891 dev_info(&pf->pdev->dev,
892 "NVMUpdate write failed err=%d status=0x%x\n",
893 ret_val, hw->aq.asq_last_status);
898 static void i40e_get_drvinfo(struct net_device *netdev,
899 struct ethtool_drvinfo *drvinfo)
901 struct i40e_netdev_priv *np = netdev_priv(netdev);
902 struct i40e_vsi *vsi = np->vsi;
903 struct i40e_pf *pf = vsi->back;
905 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
906 strlcpy(drvinfo->version, i40e_driver_version_str,
907 sizeof(drvinfo->version));
908 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
909 sizeof(drvinfo->fw_version));
910 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
911 sizeof(drvinfo->bus_info));
914 static void i40e_get_ringparam(struct net_device *netdev,
915 struct ethtool_ringparam *ring)
917 struct i40e_netdev_priv *np = netdev_priv(netdev);
918 struct i40e_pf *pf = np->vsi->back;
919 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
921 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
922 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
923 ring->rx_mini_max_pending = 0;
924 ring->rx_jumbo_max_pending = 0;
925 ring->rx_pending = vsi->rx_rings[0]->count;
926 ring->tx_pending = vsi->tx_rings[0]->count;
927 ring->rx_mini_pending = 0;
928 ring->rx_jumbo_pending = 0;
931 static int i40e_set_ringparam(struct net_device *netdev,
932 struct ethtool_ringparam *ring)
934 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
935 struct i40e_netdev_priv *np = netdev_priv(netdev);
936 struct i40e_vsi *vsi = np->vsi;
937 struct i40e_pf *pf = vsi->back;
938 u32 new_rx_count, new_tx_count;
941 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
944 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
945 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
946 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
947 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
949 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
950 ring->tx_pending, ring->rx_pending,
951 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
955 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
956 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
958 /* if nothing to do return success */
959 if ((new_tx_count == vsi->tx_rings[0]->count) &&
960 (new_rx_count == vsi->rx_rings[0]->count))
963 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
964 usleep_range(1000, 2000);
966 if (!netif_running(vsi->netdev)) {
967 /* simple case - set for the next time the netdev is started */
968 for (i = 0; i < vsi->num_queue_pairs; i++) {
969 vsi->tx_rings[i]->count = new_tx_count;
970 vsi->rx_rings[i]->count = new_rx_count;
975 /* We can't just free everything and then setup again,
976 * because the ISRs in MSI-X mode get passed pointers
977 * to the Tx and Rx ring structs.
980 /* alloc updated Tx resources */
981 if (new_tx_count != vsi->tx_rings[0]->count) {
983 "Changing Tx descriptor count from %d to %d.\n",
984 vsi->tx_rings[0]->count, new_tx_count);
985 tx_rings = kcalloc(vsi->alloc_queue_pairs,
986 sizeof(struct i40e_ring), GFP_KERNEL);
992 for (i = 0; i < vsi->num_queue_pairs; i++) {
993 /* clone ring and setup updated count */
994 tx_rings[i] = *vsi->tx_rings[i];
995 tx_rings[i].count = new_tx_count;
996 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1000 i40e_free_tx_resources(&tx_rings[i]);
1010 /* alloc updated Rx resources */
1011 if (new_rx_count != vsi->rx_rings[0]->count) {
1013 "Changing Rx descriptor count from %d to %d\n",
1014 vsi->rx_rings[0]->count, new_rx_count);
1015 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1016 sizeof(struct i40e_ring), GFP_KERNEL);
1022 for (i = 0; i < vsi->num_queue_pairs; i++) {
1023 /* clone ring and setup updated count */
1024 rx_rings[i] = *vsi->rx_rings[i];
1025 rx_rings[i].count = new_rx_count;
1026 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1030 i40e_free_rx_resources(&rx_rings[i]);
1040 /* Bring interface down, copy in the new ring info,
1041 * then restore the interface
1046 for (i = 0; i < vsi->num_queue_pairs; i++) {
1047 i40e_free_tx_resources(vsi->tx_rings[i]);
1048 *vsi->tx_rings[i] = tx_rings[i];
1055 for (i = 0; i < vsi->num_queue_pairs; i++) {
1056 i40e_free_rx_resources(vsi->rx_rings[i]);
1057 *vsi->rx_rings[i] = rx_rings[i];
1066 /* error cleanup if the Rx allocations failed after getting Tx */
1068 for (i = 0; i < vsi->num_queue_pairs; i++)
1069 i40e_free_tx_resources(&tx_rings[i]);
1075 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1080 static int i40e_get_sset_count(struct net_device *netdev, int sset)
1082 struct i40e_netdev_priv *np = netdev_priv(netdev);
1083 struct i40e_vsi *vsi = np->vsi;
1084 struct i40e_pf *pf = vsi->back;
1088 return I40E_TEST_LEN;
1090 if (vsi == pf->vsi[pf->lan_vsi]) {
1091 int len = I40E_PF_STATS_LEN(netdev);
1093 if (pf->lan_veb != I40E_NO_VEB)
1094 len += I40E_VEB_STATS_LEN;
1097 return I40E_VSI_STATS_LEN(netdev);
1104 static void i40e_get_ethtool_stats(struct net_device *netdev,
1105 struct ethtool_stats *stats, u64 *data)
1107 struct i40e_netdev_priv *np = netdev_priv(netdev);
1108 struct i40e_ring *tx_ring, *rx_ring;
1109 struct i40e_vsi *vsi = np->vsi;
1110 struct i40e_pf *pf = vsi->back;
1114 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
1117 i40e_update_stats(vsi);
1119 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1120 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1121 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1122 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1124 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1125 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1126 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1127 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1130 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1131 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1132 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1133 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1137 for (j = 0; j < vsi->num_queue_pairs; j++) {
1138 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
1143 /* process Tx ring statistics */
1145 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
1146 data[i] = tx_ring->stats.packets;
1147 data[i + 1] = tx_ring->stats.bytes;
1148 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
1151 /* Rx ring is the 2nd half of the queue pair */
1152 rx_ring = &tx_ring[1];
1154 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
1155 data[i] = rx_ring->stats.packets;
1156 data[i + 1] = rx_ring->stats.bytes;
1157 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
1161 if (vsi != pf->vsi[pf->lan_vsi])
1164 if (pf->lan_veb != I40E_NO_VEB) {
1165 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1166 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1168 p += i40e_gstrings_veb_stats[j].stat_offset;
1169 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1170 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1173 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1174 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1175 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1176 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1178 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1179 data[i++] = pf->stats.priority_xon_tx[j];
1180 data[i++] = pf->stats.priority_xoff_tx[j];
1182 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1183 data[i++] = pf->stats.priority_xon_rx[j];
1184 data[i++] = pf->stats.priority_xoff_rx[j];
1186 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1187 data[i++] = pf->stats.priority_xon_2_xoff[j];
1190 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1193 struct i40e_netdev_priv *np = netdev_priv(netdev);
1194 struct i40e_vsi *vsi = np->vsi;
1195 struct i40e_pf *pf = vsi->back;
1196 char *p = (char *)data;
1199 switch (stringset) {
1201 for (i = 0; i < I40E_TEST_LEN; i++) {
1202 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1203 data += ETH_GSTRING_LEN;
1207 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1208 snprintf(p, ETH_GSTRING_LEN, "%s",
1209 i40e_gstrings_net_stats[i].stat_string);
1210 p += ETH_GSTRING_LEN;
1212 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1213 snprintf(p, ETH_GSTRING_LEN, "%s",
1214 i40e_gstrings_misc_stats[i].stat_string);
1215 p += ETH_GSTRING_LEN;
1218 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1219 snprintf(p, ETH_GSTRING_LEN, "%s",
1220 i40e_gstrings_fcoe_stats[i].stat_string);
1221 p += ETH_GSTRING_LEN;
1224 for (i = 0; i < vsi->num_queue_pairs; i++) {
1225 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1226 p += ETH_GSTRING_LEN;
1227 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1228 p += ETH_GSTRING_LEN;
1229 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1230 p += ETH_GSTRING_LEN;
1231 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1232 p += ETH_GSTRING_LEN;
1234 if (vsi != pf->vsi[pf->lan_vsi])
1237 if (pf->lan_veb != I40E_NO_VEB) {
1238 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1239 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1240 i40e_gstrings_veb_stats[i].stat_string);
1241 p += ETH_GSTRING_LEN;
1244 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1245 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1246 i40e_gstrings_stats[i].stat_string);
1247 p += ETH_GSTRING_LEN;
1249 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1250 snprintf(p, ETH_GSTRING_LEN,
1251 "port.tx_priority_%u_xon", i);
1252 p += ETH_GSTRING_LEN;
1253 snprintf(p, ETH_GSTRING_LEN,
1254 "port.tx_priority_%u_xoff", i);
1255 p += ETH_GSTRING_LEN;
1257 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1258 snprintf(p, ETH_GSTRING_LEN,
1259 "port.rx_priority_%u_xon", i);
1260 p += ETH_GSTRING_LEN;
1261 snprintf(p, ETH_GSTRING_LEN,
1262 "port.rx_priority_%u_xoff", i);
1263 p += ETH_GSTRING_LEN;
1265 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1266 snprintf(p, ETH_GSTRING_LEN,
1267 "port.rx_priority_%u_xon_2_xoff", i);
1268 p += ETH_GSTRING_LEN;
1270 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1275 static int i40e_get_ts_info(struct net_device *dev,
1276 struct ethtool_ts_info *info)
1278 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1280 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1281 SOF_TIMESTAMPING_RX_SOFTWARE |
1282 SOF_TIMESTAMPING_SOFTWARE |
1283 SOF_TIMESTAMPING_TX_HARDWARE |
1284 SOF_TIMESTAMPING_RX_HARDWARE |
1285 SOF_TIMESTAMPING_RAW_HARDWARE;
1288 info->phc_index = ptp_clock_index(pf->ptp_clock);
1290 info->phc_index = -1;
1292 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1294 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1295 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1296 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1297 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1298 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1299 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1300 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1301 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1302 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1303 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1304 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1305 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1310 static int i40e_link_test(struct net_device *netdev, u64 *data)
1312 struct i40e_netdev_priv *np = netdev_priv(netdev);
1313 struct i40e_pf *pf = np->vsi->back;
1315 netif_info(pf, hw, netdev, "link test\n");
1316 if (i40e_get_link_status(&pf->hw))
1324 static int i40e_reg_test(struct net_device *netdev, u64 *data)
1326 struct i40e_netdev_priv *np = netdev_priv(netdev);
1327 struct i40e_pf *pf = np->vsi->back;
1329 netif_info(pf, hw, netdev, "register test\n");
1330 *data = i40e_diag_reg_test(&pf->hw);
1335 static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
1337 struct i40e_netdev_priv *np = netdev_priv(netdev);
1338 struct i40e_pf *pf = np->vsi->back;
1340 netif_info(pf, hw, netdev, "eeprom test\n");
1341 *data = i40e_diag_eeprom_test(&pf->hw);
1346 static int i40e_intr_test(struct net_device *netdev, u64 *data)
1348 struct i40e_netdev_priv *np = netdev_priv(netdev);
1349 struct i40e_pf *pf = np->vsi->back;
1350 u16 swc_old = pf->sw_int_count;
1352 netif_info(pf, hw, netdev, "interrupt test\n");
1353 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1354 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1355 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
1356 usleep_range(1000, 2000);
1357 *data = (swc_old == pf->sw_int_count);
1362 static int i40e_loopback_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, "loopback test not implemented\n");
1373 static void i40e_diag_test(struct net_device *netdev,
1374 struct ethtool_test *eth_test, u64 *data)
1376 struct i40e_netdev_priv *np = netdev_priv(netdev);
1377 struct i40e_pf *pf = np->vsi->back;
1379 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1381 netif_info(pf, drv, netdev, "offline testing starting\n");
1383 set_bit(__I40E_TESTING, &pf->state);
1385 /* Link test performed before hardware reset
1386 * so autoneg doesn't interfere with test result
1388 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1389 eth_test->flags |= ETH_TEST_FL_FAILED;
1391 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
1392 eth_test->flags |= ETH_TEST_FL_FAILED;
1394 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
1395 eth_test->flags |= ETH_TEST_FL_FAILED;
1397 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
1398 eth_test->flags |= ETH_TEST_FL_FAILED;
1400 /* run reg test last, a reset is required after it */
1401 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1402 eth_test->flags |= ETH_TEST_FL_FAILED;
1404 clear_bit(__I40E_TESTING, &pf->state);
1405 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
1408 netif_info(pf, drv, netdev, "online testing starting\n");
1410 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1411 eth_test->flags |= ETH_TEST_FL_FAILED;
1413 /* Offline only tests, not run in online; pass by default */
1414 data[I40E_ETH_TEST_REG] = 0;
1415 data[I40E_ETH_TEST_EEPROM] = 0;
1416 data[I40E_ETH_TEST_INTR] = 0;
1417 data[I40E_ETH_TEST_LOOPBACK] = 0;
1420 netif_info(pf, drv, netdev, "testing finished\n");
1423 static void i40e_get_wol(struct net_device *netdev,
1424 struct ethtool_wolinfo *wol)
1426 struct i40e_netdev_priv *np = netdev_priv(netdev);
1427 struct i40e_pf *pf = np->vsi->back;
1428 struct i40e_hw *hw = &pf->hw;
1431 /* NVM bit on means WoL disabled for the port */
1432 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1433 if ((1 << hw->port) & wol_nvm_bits) {
1437 wol->supported = WAKE_MAGIC;
1438 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1442 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1444 struct i40e_netdev_priv *np = netdev_priv(netdev);
1445 struct i40e_pf *pf = np->vsi->back;
1446 struct i40e_hw *hw = &pf->hw;
1449 /* NVM bit on means WoL disabled for the port */
1450 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1451 if (((1 << hw->port) & wol_nvm_bits))
1454 /* only magic packet is supported */
1455 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1458 /* is this a new value? */
1459 if (pf->wol_en != !!wol->wolopts) {
1460 pf->wol_en = !!wol->wolopts;
1461 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1467 static int i40e_set_phys_id(struct net_device *netdev,
1468 enum ethtool_phys_id_state state)
1470 struct i40e_netdev_priv *np = netdev_priv(netdev);
1471 struct i40e_pf *pf = np->vsi->back;
1472 struct i40e_hw *hw = &pf->hw;
1476 case ETHTOOL_ID_ACTIVE:
1477 pf->led_status = i40e_led_get(hw);
1480 i40e_led_set(hw, 0xF, false);
1482 case ETHTOOL_ID_OFF:
1483 i40e_led_set(hw, 0x0, false);
1485 case ETHTOOL_ID_INACTIVE:
1486 i40e_led_set(hw, pf->led_status, false);
1493 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1494 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1495 * 125us (8000 interrupts per second) == ITR(62)
1498 static int i40e_get_coalesce(struct net_device *netdev,
1499 struct ethtool_coalesce *ec)
1501 struct i40e_netdev_priv *np = netdev_priv(netdev);
1502 struct i40e_vsi *vsi = np->vsi;
1504 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1505 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1507 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
1508 ec->use_adaptive_rx_coalesce = 1;
1510 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
1511 ec->use_adaptive_tx_coalesce = 1;
1513 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1514 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1519 static int i40e_set_coalesce(struct net_device *netdev,
1520 struct ethtool_coalesce *ec)
1522 struct i40e_netdev_priv *np = netdev_priv(netdev);
1523 struct i40e_q_vector *q_vector;
1524 struct i40e_vsi *vsi = np->vsi;
1525 struct i40e_pf *pf = vsi->back;
1526 struct i40e_hw *hw = &pf->hw;
1530 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1531 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1533 vector = vsi->base_vector;
1534 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1535 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
1536 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1537 } else if (ec->rx_coalesce_usecs == 0) {
1538 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1539 i40e_irq_dynamic_disable(vsi, vector);
1540 if (ec->use_adaptive_rx_coalesce)
1541 netif_info(pf, drv, netdev,
1542 "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n");
1544 netif_info(pf, drv, netdev,
1545 "Invalid value, Rx-usecs range is 0, 8-8160\n");
1549 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1550 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
1551 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1552 } else if (ec->tx_coalesce_usecs == 0) {
1553 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1554 i40e_irq_dynamic_disable(vsi, vector);
1555 if (ec->use_adaptive_tx_coalesce)
1556 netif_info(pf, drv, netdev,
1557 "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n");
1559 netif_info(pf, drv, netdev,
1560 "Invalid value, Tx-usecs range is 0, 8-8160\n");
1564 if (ec->use_adaptive_rx_coalesce)
1565 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1567 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1569 if (ec->use_adaptive_tx_coalesce)
1570 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1572 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
1574 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1575 q_vector = vsi->q_vectors[i];
1576 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1577 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1578 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1579 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1587 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1588 * @pf: pointer to the physical function struct
1589 * @cmd: ethtool rxnfc command
1591 * Returns Success if the flow is supported, else Invalid Input.
1593 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1597 /* Report default options for RSS on i40e */
1598 switch (cmd->flow_type) {
1601 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1602 /* fall through to add IP fields */
1604 case AH_ESP_V4_FLOW:
1608 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1612 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1613 /* fall through to add IP fields */
1615 case AH_ESP_V6_FLOW:
1619 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1629 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1630 * @pf: Pointer to the physical function struct
1631 * @cmd: The command to get or set Rx flow classification rules
1632 * @rule_locs: Array of used rule locations
1634 * This function populates both the total and actual rule count of
1635 * the ethtool flow classification command
1637 * Returns 0 on success or -EMSGSIZE if entry not found
1639 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1640 struct ethtool_rxnfc *cmd,
1643 struct i40e_fdir_filter *rule;
1644 struct hlist_node *node2;
1647 /* report total rule count */
1648 cmd->data = i40e_get_fd_cnt_all(pf);
1650 hlist_for_each_entry_safe(rule, node2,
1651 &pf->fdir_filter_list, fdir_node) {
1652 if (cnt == cmd->rule_cnt)
1655 rule_locs[cnt] = rule->fd_id;
1659 cmd->rule_cnt = cnt;
1665 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1666 * @pf: Pointer to the physical function struct
1667 * @cmd: The command to get or set Rx flow classification rules
1669 * This function looks up a filter based on the Rx flow classification
1670 * command and fills the flow spec info for it if found
1672 * Returns 0 on success or -EINVAL if filter not found
1674 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1675 struct ethtool_rxnfc *cmd)
1677 struct ethtool_rx_flow_spec *fsp =
1678 (struct ethtool_rx_flow_spec *)&cmd->fs;
1679 struct i40e_fdir_filter *rule = NULL;
1680 struct hlist_node *node2;
1682 hlist_for_each_entry_safe(rule, node2,
1683 &pf->fdir_filter_list, fdir_node) {
1684 if (fsp->location <= rule->fd_id)
1688 if (!rule || fsp->location != rule->fd_id)
1691 fsp->flow_type = rule->flow_type;
1692 if (fsp->flow_type == IP_USER_FLOW) {
1693 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1694 fsp->h_u.usr_ip4_spec.proto = 0;
1695 fsp->m_u.usr_ip4_spec.proto = 0;
1698 /* Reverse the src and dest notion, since the HW views them from
1699 * Tx perspective where as the user expects it from Rx filter view.
1701 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1702 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1703 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1704 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
1706 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1707 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1709 fsp->ring_cookie = rule->q_index;
1715 * i40e_get_rxnfc - command to get RX flow classification rules
1716 * @netdev: network interface device structure
1717 * @cmd: ethtool rxnfc command
1719 * Returns Success if the command is supported.
1721 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1724 struct i40e_netdev_priv *np = netdev_priv(netdev);
1725 struct i40e_vsi *vsi = np->vsi;
1726 struct i40e_pf *pf = vsi->back;
1727 int ret = -EOPNOTSUPP;
1730 case ETHTOOL_GRXRINGS:
1731 cmd->data = vsi->alloc_queue_pairs;
1735 ret = i40e_get_rss_hash_opts(pf, cmd);
1737 case ETHTOOL_GRXCLSRLCNT:
1738 cmd->rule_cnt = pf->fdir_pf_active_filters;
1739 /* report total rule count */
1740 cmd->data = i40e_get_fd_cnt_all(pf);
1743 case ETHTOOL_GRXCLSRULE:
1744 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
1746 case ETHTOOL_GRXCLSRLALL:
1747 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1757 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1758 * @pf: pointer to the physical function struct
1759 * @cmd: ethtool rxnfc command
1761 * Returns Success if the flow input set is supported.
1763 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1765 struct i40e_hw *hw = &pf->hw;
1766 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1767 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1769 /* RSS does not support anything other than hashing
1770 * to queues on src and dst IPs and ports
1772 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1773 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1776 /* We need at least the IP SRC and DEST fields for hashing */
1777 if (!(nfc->data & RXH_IP_SRC) ||
1778 !(nfc->data & RXH_IP_DST))
1781 switch (nfc->flow_type) {
1783 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1785 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1787 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1788 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1795 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1797 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1799 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1800 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1807 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1809 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1810 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1812 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1813 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1814 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1821 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1823 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1824 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1826 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1827 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1828 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1834 case AH_ESP_V4_FLOW:
1838 if ((nfc->data & RXH_L4_B_0_1) ||
1839 (nfc->data & RXH_L4_B_2_3))
1841 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1843 case AH_ESP_V6_FLOW:
1847 if ((nfc->data & RXH_L4_B_0_1) ||
1848 (nfc->data & RXH_L4_B_2_3))
1850 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1853 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1854 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1857 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1858 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1864 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1865 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1872 * i40e_match_fdir_input_set - Match a new filter against an existing one
1873 * @rule: The filter already added
1874 * @input: The new filter to comapre against
1876 * Returns true if the two input set match
1878 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1879 struct i40e_fdir_filter *input)
1881 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1882 (rule->src_ip[0] != input->src_ip[0]) ||
1883 (rule->dst_port != input->dst_port) ||
1884 (rule->src_port != input->src_port))
1890 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1891 * @vsi: Pointer to the targeted VSI
1892 * @input: The filter to update or NULL to indicate deletion
1893 * @sw_idx: Software index to the filter
1894 * @cmd: The command to get or set Rx flow classification rules
1896 * This function updates (or deletes) a Flow Director entry from
1897 * the hlist of the corresponding PF
1899 * Returns 0 on success
1901 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1902 struct i40e_fdir_filter *input,
1904 struct ethtool_rxnfc *cmd)
1906 struct i40e_fdir_filter *rule, *parent;
1907 struct i40e_pf *pf = vsi->back;
1908 struct hlist_node *node2;
1914 hlist_for_each_entry_safe(rule, node2,
1915 &pf->fdir_filter_list, fdir_node) {
1916 /* hash found, or no matching entry */
1917 if (rule->fd_id >= sw_idx)
1922 /* if there is an old rule occupying our place remove it */
1923 if (rule && (rule->fd_id == sw_idx)) {
1924 if (input && !i40e_match_fdir_input_set(rule, input))
1925 err = i40e_add_del_fdir(vsi, rule, false);
1927 err = i40e_add_del_fdir(vsi, rule, false);
1928 hlist_del(&rule->fdir_node);
1930 pf->fdir_pf_active_filters--;
1933 /* If no input this was a delete, err should be 0 if a rule was
1934 * successfully found and removed from the list else -EINVAL
1939 /* initialize node and set software index */
1940 INIT_HLIST_NODE(&input->fdir_node);
1942 /* add filter to the list */
1944 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
1946 hlist_add_head(&input->fdir_node,
1947 &pf->fdir_filter_list);
1950 pf->fdir_pf_active_filters++;
1956 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1957 * @vsi: Pointer to the targeted VSI
1958 * @cmd: The command to get or set Rx flow classification rules
1960 * The function removes a Flow Director filter entry from the
1961 * hlist of the corresponding PF
1963 * Returns 0 on success
1965 static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1966 struct ethtool_rxnfc *cmd)
1968 struct ethtool_rx_flow_spec *fsp =
1969 (struct ethtool_rx_flow_spec *)&cmd->fs;
1970 struct i40e_pf *pf = vsi->back;
1973 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1974 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1977 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
1980 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
1982 i40e_fdir_check_and_reenable(pf);
1987 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
1988 * @vsi: pointer to the targeted VSI
1989 * @cmd: command to get or set RX flow classification rules
1991 * Add Flow Director filters for a specific flow spec based on their
1992 * protocol. Returns 0 if the filters were successfully added.
1994 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1995 struct ethtool_rxnfc *cmd)
1997 struct ethtool_rx_flow_spec *fsp;
1998 struct i40e_fdir_filter *input;
2007 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2010 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
2013 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2014 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2017 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2020 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2022 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2023 pf->hw.func_caps.fd_filters_guaranteed)) {
2027 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2028 (fsp->ring_cookie >= vsi->num_queue_pairs))
2031 input = kzalloc(sizeof(*input), GFP_KERNEL);
2036 input->fd_id = fsp->location;
2038 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2039 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2042 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2044 input->q_index = fsp->ring_cookie;
2045 input->flex_off = 0;
2047 input->dest_vsi = vsi->id;
2048 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
2049 input->cnt_index = pf->fd_sb_cnt_idx;
2050 input->flow_type = fsp->flow_type;
2051 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
2053 /* Reverse the src and dest notion, since the HW expects them to be from
2054 * Tx perspective where as the input from user is from Rx filter view.
2056 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2057 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2058 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2059 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
2061 ret = i40e_add_del_fdir(vsi, input, true);
2065 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
2071 * i40e_set_rxnfc - command to set RX flow classification rules
2072 * @netdev: network interface device structure
2073 * @cmd: ethtool rxnfc command
2075 * Returns Success if the command is supported.
2077 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2079 struct i40e_netdev_priv *np = netdev_priv(netdev);
2080 struct i40e_vsi *vsi = np->vsi;
2081 struct i40e_pf *pf = vsi->back;
2082 int ret = -EOPNOTSUPP;
2086 ret = i40e_set_rss_hash_opt(pf, cmd);
2088 case ETHTOOL_SRXCLSRLINS:
2089 ret = i40e_add_fdir_ethtool(vsi, cmd);
2091 case ETHTOOL_SRXCLSRLDEL:
2092 ret = i40e_del_fdir_entry(vsi, cmd);
2102 * i40e_max_channels - get Max number of combined channels supported
2105 static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2107 /* TODO: This code assumes DCB and FD is disabled for now. */
2108 return vsi->alloc_queue_pairs;
2112 * i40e_get_channels - Get the current channels enabled and max supported etc.
2113 * @netdev: network interface device structure
2114 * @ch: ethtool channels structure
2116 * We don't support separate tx and rx queues as channels. The other count
2117 * represents how many queues are being used for control. max_combined counts
2118 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2119 * q_vectors since we support a lot more queue pairs than q_vectors.
2121 static void i40e_get_channels(struct net_device *dev,
2122 struct ethtool_channels *ch)
2124 struct i40e_netdev_priv *np = netdev_priv(dev);
2125 struct i40e_vsi *vsi = np->vsi;
2126 struct i40e_pf *pf = vsi->back;
2128 /* report maximum channels */
2129 ch->max_combined = i40e_max_channels(vsi);
2131 /* report info for other vector */
2132 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
2133 ch->max_other = ch->other_count;
2135 /* Note: This code assumes DCB is disabled for now. */
2136 ch->combined_count = vsi->num_queue_pairs;
2140 * i40e_set_channels - Set the new channels count.
2141 * @netdev: network interface device structure
2142 * @ch: ethtool channels structure
2144 * The new channels count may not be the same as requested by the user
2145 * since it gets rounded down to a power of 2 value.
2147 static int i40e_set_channels(struct net_device *dev,
2148 struct ethtool_channels *ch)
2150 struct i40e_netdev_priv *np = netdev_priv(dev);
2151 unsigned int count = ch->combined_count;
2152 struct i40e_vsi *vsi = np->vsi;
2153 struct i40e_pf *pf = vsi->back;
2156 /* We do not support setting channels for any other VSI at present */
2157 if (vsi->type != I40E_VSI_MAIN)
2160 /* verify they are not requesting separate vectors */
2161 if (!count || ch->rx_count || ch->tx_count)
2164 /* verify other_count has not changed */
2165 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
2168 /* verify the number of channels does not exceed hardware limits */
2169 if (count > i40e_max_channels(vsi))
2172 /* update feature limits from largest to smallest supported values */
2173 /* TODO: Flow director limit, DCB etc */
2176 if (count > pf->rss_size_max)
2177 count = pf->rss_size_max;
2179 /* use rss_reconfig to rebuild with new queue count and update traffic
2180 * class queue mapping
2182 new_count = i40e_reconfig_rss_queues(pf, count);
2189 static const struct ethtool_ops i40e_ethtool_ops = {
2190 .get_settings = i40e_get_settings,
2191 .set_settings = i40e_set_settings,
2192 .get_drvinfo = i40e_get_drvinfo,
2193 .get_regs_len = i40e_get_regs_len,
2194 .get_regs = i40e_get_regs,
2195 .nway_reset = i40e_nway_reset,
2196 .get_link = ethtool_op_get_link,
2197 .get_wol = i40e_get_wol,
2198 .set_wol = i40e_set_wol,
2199 .set_eeprom = i40e_set_eeprom,
2200 .get_eeprom_len = i40e_get_eeprom_len,
2201 .get_eeprom = i40e_get_eeprom,
2202 .get_ringparam = i40e_get_ringparam,
2203 .set_ringparam = i40e_set_ringparam,
2204 .get_pauseparam = i40e_get_pauseparam,
2205 .set_pauseparam = i40e_set_pauseparam,
2206 .get_msglevel = i40e_get_msglevel,
2207 .set_msglevel = i40e_set_msglevel,
2208 .get_rxnfc = i40e_get_rxnfc,
2209 .set_rxnfc = i40e_set_rxnfc,
2210 .self_test = i40e_diag_test,
2211 .get_strings = i40e_get_strings,
2212 .set_phys_id = i40e_set_phys_id,
2213 .get_sset_count = i40e_get_sset_count,
2214 .get_ethtool_stats = i40e_get_ethtool_stats,
2215 .get_coalesce = i40e_get_coalesce,
2216 .set_coalesce = i40e_set_coalesce,
2217 .get_channels = i40e_get_channels,
2218 .set_channels = i40e_set_channels,
2219 .get_ts_info = i40e_get_ts_info,
2222 void i40e_set_ethtool_ops(struct net_device *netdev)
2224 netdev->ethtool_ops = &i40e_ethtool_ops;