xref: /openbmc/linux/drivers/net/ethernet/intel/i40e/i40e_ethtool.c (revision bbde9fc1824aab58bc78c084163007dd6c03fe5b)
1 /*******************************************************************************
2  *
3  * Intel Ethernet Controller XL710 Family Linux Driver
4  * Copyright(c) 2013 - 2015 Intel Corporation.
5  *
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.
9  *
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
13  * more details.
14  *
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/>.
17  *
18  * The full GNU General Public License is included in this distribution in
19  * the file called "COPYING".
20  *
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
24  *
25  ******************************************************************************/
26 
27 /* ethtool support for i40e */
28 
29 #include "i40e.h"
30 #include "i40e_diag.h"
31 
32 struct i40e_stats {
33 	char stat_string[ETH_GSTRING_LEN];
34 	int sizeof_stat;
35 	int stat_offset;
36 };
37 
38 #define I40E_STAT(_type, _name, _stat) { \
39 	.stat_string = _name, \
40 	.sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 	.stat_offset = offsetof(_type, _stat) \
42 }
43 
44 #define I40E_NETDEV_STAT(_net_stat) \
45 		I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
46 #define I40E_PF_STAT(_name, _stat) \
47 		I40E_STAT(struct i40e_pf, _name, _stat)
48 #define I40E_VSI_STAT(_name, _stat) \
49 		I40E_STAT(struct i40e_vsi, _name, _stat)
50 #define I40E_VEB_STAT(_name, _stat) \
51 		I40E_STAT(struct i40e_veb, _name, _stat)
52 
53 static const struct i40e_stats i40e_gstrings_net_stats[] = {
54 	I40E_NETDEV_STAT(rx_packets),
55 	I40E_NETDEV_STAT(tx_packets),
56 	I40E_NETDEV_STAT(rx_bytes),
57 	I40E_NETDEV_STAT(tx_bytes),
58 	I40E_NETDEV_STAT(rx_errors),
59 	I40E_NETDEV_STAT(tx_errors),
60 	I40E_NETDEV_STAT(rx_dropped),
61 	I40E_NETDEV_STAT(tx_dropped),
62 	I40E_NETDEV_STAT(collisions),
63 	I40E_NETDEV_STAT(rx_length_errors),
64 	I40E_NETDEV_STAT(rx_crc_errors),
65 };
66 
67 static const struct i40e_stats i40e_gstrings_veb_stats[] = {
68 	I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
69 	I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
70 	I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
71 	I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
72 	I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
73 	I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
74 	I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
75 	I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
76 	I40E_VEB_STAT("rx_discards", stats.rx_discards),
77 	I40E_VEB_STAT("tx_discards", stats.tx_discards),
78 	I40E_VEB_STAT("tx_errors", stats.tx_errors),
79 	I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
80 };
81 
82 static const struct i40e_stats i40e_gstrings_misc_stats[] = {
83 	I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
84 	I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
85 	I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
86 	I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
87 	I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
88 	I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
89 	I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
90 };
91 
92 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
93 				 struct ethtool_rxnfc *cmd);
94 
95 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
96  * but they are separate.  This device supports Virtualization, and
97  * as such might have several netdevs supporting VMDq and FCoE going
98  * through a single port.  The NETDEV_STATs are for individual netdevs
99  * seen at the top of the stack, and the PF_STATs are for the physical
100  * function at the bottom of the stack hosting those netdevs.
101  *
102  * The PF_STATs are appended to the netdev stats only when ethtool -S
103  * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
104  */
105 static struct i40e_stats i40e_gstrings_stats[] = {
106 	I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
107 	I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
108 	I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
109 	I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
110 	I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
111 	I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
112 	I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
113 	I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
114 	I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
115 	I40E_PF_STAT("rx_dropped", stats.eth.rx_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_atr_tunnel_match", stats.fd_atr_tunnel_match),
151 	I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
152 	I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
153 	I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
154 
155 	/* LPI stats */
156 	I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
157 	I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
158 	I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
159 	I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
160 };
161 
162 #ifdef I40E_FCOE
163 static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
164 	I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
165 	I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
166 	I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
167 	I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
168 	I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
169 	I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
170 	I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
171 	I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
172 };
173 
174 #endif /* I40E_FCOE */
175 #define I40E_QUEUE_STATS_LEN(n) \
176 	(((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
177 	    * 2 /* Tx and Rx together */                                     \
178 	    * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
179 #define I40E_GLOBAL_STATS_LEN	ARRAY_SIZE(i40e_gstrings_stats)
180 #define I40E_NETDEV_STATS_LEN   ARRAY_SIZE(i40e_gstrings_net_stats)
181 #define I40E_MISC_STATS_LEN	ARRAY_SIZE(i40e_gstrings_misc_stats)
182 #ifdef I40E_FCOE
183 #define I40E_FCOE_STATS_LEN	ARRAY_SIZE(i40e_gstrings_fcoe_stats)
184 #define I40E_VSI_STATS_LEN(n)	(I40E_NETDEV_STATS_LEN + \
185 				 I40E_FCOE_STATS_LEN + \
186 				 I40E_MISC_STATS_LEN + \
187 				 I40E_QUEUE_STATS_LEN((n)))
188 #else
189 #define I40E_VSI_STATS_LEN(n)   (I40E_NETDEV_STATS_LEN + \
190 				 I40E_MISC_STATS_LEN + \
191 				 I40E_QUEUE_STATS_LEN((n)))
192 #endif /* I40E_FCOE */
193 #define I40E_PFC_STATS_LEN ( \
194 		(FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
195 		 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
196 		 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
197 		 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
198 		 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
199 		 / sizeof(u64))
200 #define I40E_VEB_STATS_LEN	ARRAY_SIZE(i40e_gstrings_veb_stats)
201 #define I40E_PF_STATS_LEN(n)	(I40E_GLOBAL_STATS_LEN + \
202 				 I40E_PFC_STATS_LEN + \
203 				 I40E_VSI_STATS_LEN((n)))
204 
205 enum i40e_ethtool_test_id {
206 	I40E_ETH_TEST_REG = 0,
207 	I40E_ETH_TEST_EEPROM,
208 	I40E_ETH_TEST_INTR,
209 	I40E_ETH_TEST_LOOPBACK,
210 	I40E_ETH_TEST_LINK,
211 };
212 
213 static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
214 	"Register test  (offline)",
215 	"Eeprom test    (offline)",
216 	"Interrupt test (offline)",
217 	"Loopback test  (offline)",
218 	"Link test   (on/offline)"
219 };
220 
221 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
222 
223 static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
224 	"NPAR",
225 };
226 
227 #define I40E_PRIV_FLAGS_STR_LEN \
228 	(sizeof(i40e_priv_flags_strings) / ETH_GSTRING_LEN)
229 
230 /**
231  * i40e_partition_setting_complaint - generic complaint for MFP restriction
232  * @pf: the PF struct
233  **/
234 static void i40e_partition_setting_complaint(struct i40e_pf *pf)
235 {
236 	dev_info(&pf->pdev->dev,
237 		 "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
238 }
239 
240 /**
241  * i40e_get_settings_link_up - Get the Link settings for when link is up
242  * @hw: hw structure
243  * @ecmd: ethtool command to fill in
244  * @netdev: network interface device structure
245  *
246  **/
247 static void i40e_get_settings_link_up(struct i40e_hw *hw,
248 				      struct ethtool_cmd *ecmd,
249 				      struct net_device *netdev)
250 {
251 	struct i40e_link_status *hw_link_info = &hw->phy.link_info;
252 	u32 link_speed = hw_link_info->link_speed;
253 
254 	/* Initialize supported and advertised settings based on phy settings */
255 	switch (hw_link_info->phy_type) {
256 	case I40E_PHY_TYPE_40GBASE_CR4:
257 	case I40E_PHY_TYPE_40GBASE_CR4_CU:
258 		ecmd->supported = SUPPORTED_Autoneg |
259 				  SUPPORTED_40000baseCR4_Full;
260 		ecmd->advertising = ADVERTISED_Autoneg |
261 				    ADVERTISED_40000baseCR4_Full;
262 		break;
263 	case I40E_PHY_TYPE_XLAUI:
264 	case I40E_PHY_TYPE_XLPPI:
265 	case I40E_PHY_TYPE_40GBASE_AOC:
266 		ecmd->supported = SUPPORTED_40000baseCR4_Full;
267 		break;
268 	case I40E_PHY_TYPE_40GBASE_KR4:
269 		ecmd->supported = SUPPORTED_Autoneg |
270 				  SUPPORTED_40000baseKR4_Full;
271 		ecmd->advertising = ADVERTISED_Autoneg |
272 				    ADVERTISED_40000baseKR4_Full;
273 		break;
274 	case I40E_PHY_TYPE_40GBASE_SR4:
275 		ecmd->supported = SUPPORTED_40000baseSR4_Full;
276 		break;
277 	case I40E_PHY_TYPE_40GBASE_LR4:
278 		ecmd->supported = SUPPORTED_40000baseLR4_Full;
279 		break;
280 	case I40E_PHY_TYPE_20GBASE_KR2:
281 		ecmd->supported = SUPPORTED_Autoneg |
282 				  SUPPORTED_20000baseKR2_Full;
283 		ecmd->advertising = ADVERTISED_Autoneg |
284 				    ADVERTISED_20000baseKR2_Full;
285 		break;
286 	case I40E_PHY_TYPE_10GBASE_KX4:
287 		ecmd->supported = SUPPORTED_Autoneg |
288 				  SUPPORTED_10000baseKX4_Full;
289 		ecmd->advertising = ADVERTISED_Autoneg |
290 				    ADVERTISED_10000baseKX4_Full;
291 		break;
292 	case I40E_PHY_TYPE_10GBASE_KR:
293 		ecmd->supported = SUPPORTED_Autoneg |
294 				  SUPPORTED_10000baseKR_Full;
295 		ecmd->advertising = ADVERTISED_Autoneg |
296 				    ADVERTISED_10000baseKR_Full;
297 		break;
298 	case I40E_PHY_TYPE_10GBASE_SR:
299 	case I40E_PHY_TYPE_10GBASE_LR:
300 	case I40E_PHY_TYPE_1000BASE_SX:
301 	case I40E_PHY_TYPE_1000BASE_LX:
302 		ecmd->supported = SUPPORTED_10000baseT_Full |
303 				  SUPPORTED_1000baseT_Full;
304 		if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
305 			ecmd->advertising |= ADVERTISED_10000baseT_Full;
306 		if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
307 			ecmd->advertising |= ADVERTISED_1000baseT_Full;
308 		break;
309 	case I40E_PHY_TYPE_1000BASE_KX:
310 		ecmd->supported = SUPPORTED_Autoneg |
311 				  SUPPORTED_1000baseKX_Full;
312 		ecmd->advertising = ADVERTISED_Autoneg |
313 				    ADVERTISED_1000baseKX_Full;
314 		break;
315 	case I40E_PHY_TYPE_10GBASE_T:
316 	case I40E_PHY_TYPE_1000BASE_T:
317 	case I40E_PHY_TYPE_100BASE_TX:
318 		ecmd->supported = SUPPORTED_Autoneg |
319 				  SUPPORTED_10000baseT_Full |
320 				  SUPPORTED_1000baseT_Full |
321 				  SUPPORTED_100baseT_Full;
322 		ecmd->advertising = ADVERTISED_Autoneg;
323 		if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
324 			ecmd->advertising |= ADVERTISED_10000baseT_Full;
325 		if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
326 			ecmd->advertising |= ADVERTISED_1000baseT_Full;
327 		if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
328 			ecmd->advertising |= ADVERTISED_100baseT_Full;
329 		break;
330 	case I40E_PHY_TYPE_10GBASE_CR1_CU:
331 	case I40E_PHY_TYPE_10GBASE_CR1:
332 		ecmd->supported = SUPPORTED_Autoneg |
333 				  SUPPORTED_10000baseT_Full;
334 		ecmd->advertising = ADVERTISED_Autoneg |
335 				    ADVERTISED_10000baseT_Full;
336 		break;
337 	case I40E_PHY_TYPE_XAUI:
338 	case I40E_PHY_TYPE_XFI:
339 	case I40E_PHY_TYPE_SFI:
340 	case I40E_PHY_TYPE_10GBASE_SFPP_CU:
341 	case I40E_PHY_TYPE_10GBASE_AOC:
342 		ecmd->supported = SUPPORTED_10000baseT_Full;
343 		break;
344 	case I40E_PHY_TYPE_SGMII:
345 		ecmd->supported = SUPPORTED_Autoneg |
346 				  SUPPORTED_1000baseT_Full |
347 				  SUPPORTED_100baseT_Full;
348 		if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
349 			ecmd->advertising |= ADVERTISED_1000baseT_Full;
350 		if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
351 			ecmd->advertising |= ADVERTISED_100baseT_Full;
352 		break;
353 	default:
354 		/* if we got here and link is up something bad is afoot */
355 		netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
356 			    hw_link_info->phy_type);
357 	}
358 
359 	/* Set speed and duplex */
360 	switch (link_speed) {
361 	case I40E_LINK_SPEED_40GB:
362 		ethtool_cmd_speed_set(ecmd, SPEED_40000);
363 		break;
364 	case I40E_LINK_SPEED_20GB:
365 		ethtool_cmd_speed_set(ecmd, SPEED_20000);
366 		break;
367 	case I40E_LINK_SPEED_10GB:
368 		ethtool_cmd_speed_set(ecmd, SPEED_10000);
369 		break;
370 	case I40E_LINK_SPEED_1GB:
371 		ethtool_cmd_speed_set(ecmd, SPEED_1000);
372 		break;
373 	case I40E_LINK_SPEED_100MB:
374 		ethtool_cmd_speed_set(ecmd, SPEED_100);
375 		break;
376 	default:
377 		break;
378 	}
379 	ecmd->duplex = DUPLEX_FULL;
380 }
381 
382 /**
383  * i40e_get_settings_link_down - Get the Link settings for when link is down
384  * @hw: hw structure
385  * @ecmd: ethtool command to fill in
386  *
387  * Reports link settings that can be determined when link is down
388  **/
389 static void i40e_get_settings_link_down(struct i40e_hw *hw,
390 					struct ethtool_cmd *ecmd)
391 {
392 	struct i40e_link_status *hw_link_info = &hw->phy.link_info;
393 
394 	/* link is down and the driver needs to fall back on
395 	 * device ID to determine what kinds of info to display,
396 	 * it's mostly a guess that may change when link is up
397 	 */
398 	switch (hw->device_id) {
399 	case I40E_DEV_ID_QSFP_A:
400 	case I40E_DEV_ID_QSFP_B:
401 	case I40E_DEV_ID_QSFP_C:
402 		/* pluggable QSFP */
403 		ecmd->supported = SUPPORTED_40000baseSR4_Full |
404 				  SUPPORTED_40000baseCR4_Full |
405 				  SUPPORTED_40000baseLR4_Full;
406 		ecmd->advertising = ADVERTISED_40000baseSR4_Full |
407 				    ADVERTISED_40000baseCR4_Full |
408 				    ADVERTISED_40000baseLR4_Full;
409 		break;
410 	case I40E_DEV_ID_KX_B:
411 		/* backplane 40G */
412 		ecmd->supported = SUPPORTED_40000baseKR4_Full;
413 		ecmd->advertising = ADVERTISED_40000baseKR4_Full;
414 		break;
415 	case I40E_DEV_ID_KX_C:
416 		/* backplane 10G */
417 		ecmd->supported = SUPPORTED_10000baseKR_Full;
418 		ecmd->advertising = ADVERTISED_10000baseKR_Full;
419 		break;
420 	case I40E_DEV_ID_10G_BASE_T:
421 		ecmd->supported = SUPPORTED_10000baseT_Full |
422 				  SUPPORTED_1000baseT_Full |
423 				  SUPPORTED_100baseT_Full;
424 		/* Figure out what has been requested */
425 		if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
426 			ecmd->advertising |= ADVERTISED_10000baseT_Full;
427 		if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
428 			ecmd->advertising |= ADVERTISED_1000baseT_Full;
429 		if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
430 			ecmd->advertising |= ADVERTISED_100baseT_Full;
431 		break;
432 	case I40E_DEV_ID_20G_KR2:
433 		/* backplane 20G */
434 		ecmd->supported = SUPPORTED_20000baseKR2_Full;
435 		ecmd->advertising = ADVERTISED_20000baseKR2_Full;
436 		break;
437 	default:
438 		/* all the rest are 10G/1G */
439 		ecmd->supported = SUPPORTED_10000baseT_Full |
440 				  SUPPORTED_1000baseT_Full;
441 		/* Figure out what has been requested */
442 		if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
443 			ecmd->advertising |= ADVERTISED_10000baseT_Full;
444 		if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
445 			ecmd->advertising |= ADVERTISED_1000baseT_Full;
446 		break;
447 	}
448 
449 	/* With no link speed and duplex are unknown */
450 	ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
451 	ecmd->duplex = DUPLEX_UNKNOWN;
452 }
453 
454 /**
455  * i40e_get_settings - Get Link Speed and Duplex settings
456  * @netdev: network interface device structure
457  * @ecmd: ethtool command
458  *
459  * Reports speed/duplex settings based on media_type
460  **/
461 static int i40e_get_settings(struct net_device *netdev,
462 			     struct ethtool_cmd *ecmd)
463 {
464 	struct i40e_netdev_priv *np = netdev_priv(netdev);
465 	struct i40e_pf *pf = np->vsi->back;
466 	struct i40e_hw *hw = &pf->hw;
467 	struct i40e_link_status *hw_link_info = &hw->phy.link_info;
468 	bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
469 
470 	if (link_up)
471 		i40e_get_settings_link_up(hw, ecmd, netdev);
472 	else
473 		i40e_get_settings_link_down(hw, ecmd);
474 
475 	/* Now set the settings that don't rely on link being up/down */
476 
477 	/* Set autoneg settings */
478 	ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
479 			  AUTONEG_ENABLE : AUTONEG_DISABLE);
480 
481 	switch (hw->phy.media_type) {
482 	case I40E_MEDIA_TYPE_BACKPLANE:
483 		ecmd->supported |= SUPPORTED_Autoneg |
484 				   SUPPORTED_Backplane;
485 		ecmd->advertising |= ADVERTISED_Autoneg |
486 				     ADVERTISED_Backplane;
487 		ecmd->port = PORT_NONE;
488 		break;
489 	case I40E_MEDIA_TYPE_BASET:
490 		ecmd->supported |= SUPPORTED_TP;
491 		ecmd->advertising |= ADVERTISED_TP;
492 		ecmd->port = PORT_TP;
493 		break;
494 	case I40E_MEDIA_TYPE_DA:
495 	case I40E_MEDIA_TYPE_CX4:
496 		ecmd->supported |= SUPPORTED_FIBRE;
497 		ecmd->advertising |= ADVERTISED_FIBRE;
498 		ecmd->port = PORT_DA;
499 		break;
500 	case I40E_MEDIA_TYPE_FIBER:
501 		ecmd->supported |= SUPPORTED_FIBRE;
502 		ecmd->port = PORT_FIBRE;
503 		break;
504 	case I40E_MEDIA_TYPE_UNKNOWN:
505 	default:
506 		ecmd->port = PORT_OTHER;
507 		break;
508 	}
509 
510 	/* Set transceiver */
511 	ecmd->transceiver = XCVR_EXTERNAL;
512 
513 	/* Set flow control settings */
514 	ecmd->supported |= SUPPORTED_Pause;
515 
516 	switch (hw->fc.requested_mode) {
517 	case I40E_FC_FULL:
518 		ecmd->advertising |= ADVERTISED_Pause;
519 		break;
520 	case I40E_FC_TX_PAUSE:
521 		ecmd->advertising |= ADVERTISED_Asym_Pause;
522 		break;
523 	case I40E_FC_RX_PAUSE:
524 		ecmd->advertising |= (ADVERTISED_Pause |
525 				      ADVERTISED_Asym_Pause);
526 		break;
527 	default:
528 		ecmd->advertising &= ~(ADVERTISED_Pause |
529 				       ADVERTISED_Asym_Pause);
530 		break;
531 	}
532 
533 	return 0;
534 }
535 
536 /**
537  * i40e_set_settings - Set Speed and Duplex
538  * @netdev: network interface device structure
539  * @ecmd: ethtool command
540  *
541  * Set speed/duplex per media_types advertised/forced
542  **/
543 static int i40e_set_settings(struct net_device *netdev,
544 			     struct ethtool_cmd *ecmd)
545 {
546 	struct i40e_netdev_priv *np = netdev_priv(netdev);
547 	struct i40e_aq_get_phy_abilities_resp abilities;
548 	struct i40e_aq_set_phy_config config;
549 	struct i40e_pf *pf = np->vsi->back;
550 	struct i40e_vsi *vsi = np->vsi;
551 	struct i40e_hw *hw = &pf->hw;
552 	struct ethtool_cmd safe_ecmd;
553 	i40e_status status = 0;
554 	bool change = false;
555 	int err = 0;
556 	u8 autoneg;
557 	u32 advertise;
558 
559 	/* Changing port settings is not supported if this isn't the
560 	 * port's controlling PF
561 	 */
562 	if (hw->partition_id != 1) {
563 		i40e_partition_setting_complaint(pf);
564 		return -EOPNOTSUPP;
565 	}
566 
567 	if (vsi != pf->vsi[pf->lan_vsi])
568 		return -EOPNOTSUPP;
569 
570 	if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
571 	    hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
572 	    hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
573 	    hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
574 		return -EOPNOTSUPP;
575 
576 	/* get our own copy of the bits to check against */
577 	memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
578 	i40e_get_settings(netdev, &safe_ecmd);
579 
580 	/* save autoneg and speed out of ecmd */
581 	autoneg = ecmd->autoneg;
582 	advertise = ecmd->advertising;
583 
584 	/* set autoneg and speed back to what they currently are */
585 	ecmd->autoneg = safe_ecmd.autoneg;
586 	ecmd->advertising = safe_ecmd.advertising;
587 
588 	ecmd->cmd = safe_ecmd.cmd;
589 	/* If ecmd and safe_ecmd are not the same now, then they are
590 	 * trying to set something that we do not support
591 	 */
592 	if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
593 		return -EOPNOTSUPP;
594 
595 	while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
596 		usleep_range(1000, 2000);
597 
598 	/* Get the current phy config */
599 	status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
600 					      NULL);
601 	if (status)
602 		return -EAGAIN;
603 
604 	/* Copy abilities to config in case autoneg is not
605 	 * set below
606 	 */
607 	memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
608 	config.abilities = abilities.abilities;
609 
610 	/* Check autoneg */
611 	if (autoneg == AUTONEG_ENABLE) {
612 		/* If autoneg is not supported, return error */
613 		if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
614 			netdev_info(netdev, "Autoneg not supported on this phy\n");
615 			return -EINVAL;
616 		}
617 		/* If autoneg was not already enabled */
618 		if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
619 			config.abilities = abilities.abilities |
620 					   I40E_AQ_PHY_ENABLE_AN;
621 			change = true;
622 		}
623 	} else {
624 		/* If autoneg is supported 10GBASE_T is the only phy that
625 		 * can disable it, so otherwise return error
626 		 */
627 		if (safe_ecmd.supported & SUPPORTED_Autoneg &&
628 		    hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
629 			netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
630 			return -EINVAL;
631 		}
632 		/* If autoneg is currently enabled */
633 		if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
634 			config.abilities = abilities.abilities &
635 					   ~I40E_AQ_PHY_ENABLE_AN;
636 			change = true;
637 		}
638 	}
639 
640 	if (advertise & ~safe_ecmd.supported)
641 		return -EINVAL;
642 
643 	if (advertise & ADVERTISED_100baseT_Full)
644 		config.link_speed |= I40E_LINK_SPEED_100MB;
645 	if (advertise & ADVERTISED_1000baseT_Full ||
646 	    advertise & ADVERTISED_1000baseKX_Full)
647 		config.link_speed |= I40E_LINK_SPEED_1GB;
648 	if (advertise & ADVERTISED_10000baseT_Full ||
649 	    advertise & ADVERTISED_10000baseKX4_Full ||
650 	    advertise & ADVERTISED_10000baseKR_Full)
651 		config.link_speed |= I40E_LINK_SPEED_10GB;
652 	if (advertise & ADVERTISED_20000baseKR2_Full)
653 		config.link_speed |= I40E_LINK_SPEED_20GB;
654 	if (advertise & ADVERTISED_40000baseKR4_Full ||
655 	    advertise & ADVERTISED_40000baseCR4_Full ||
656 	    advertise & ADVERTISED_40000baseSR4_Full ||
657 	    advertise & ADVERTISED_40000baseLR4_Full)
658 		config.link_speed |= I40E_LINK_SPEED_40GB;
659 
660 	if (change || (abilities.link_speed != config.link_speed)) {
661 		/* copy over the rest of the abilities */
662 		config.phy_type = abilities.phy_type;
663 		config.eee_capability = abilities.eee_capability;
664 		config.eeer = abilities.eeer_val;
665 		config.low_power_ctrl = abilities.d3_lpan;
666 
667 		/* save the requested speeds */
668 		hw->phy.link_info.requested_speeds = config.link_speed;
669 		/* set link and auto negotiation so changes take effect */
670 		config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
671 		/* If link is up put link down */
672 		if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
673 			/* Tell the OS link is going down, the link will go
674 			 * back up when fw says it is ready asynchronously
675 			 */
676 			netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
677 			netif_carrier_off(netdev);
678 			netif_tx_stop_all_queues(netdev);
679 		}
680 
681 		/* make the aq call */
682 		status = i40e_aq_set_phy_config(hw, &config, NULL);
683 		if (status) {
684 			netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
685 				    i40e_stat_str(hw, status),
686 				    i40e_aq_str(hw, hw->aq.asq_last_status));
687 			return -EAGAIN;
688 		}
689 
690 		status = i40e_aq_get_link_info(hw, true, NULL, NULL);
691 		if (status)
692 			netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
693 				    i40e_stat_str(hw, status),
694 				    i40e_aq_str(hw, hw->aq.asq_last_status));
695 
696 	} else {
697 		netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
698 	}
699 
700 	return err;
701 }
702 
703 static int i40e_nway_reset(struct net_device *netdev)
704 {
705 	/* restart autonegotiation */
706 	struct i40e_netdev_priv *np = netdev_priv(netdev);
707 	struct i40e_pf *pf = np->vsi->back;
708 	struct i40e_hw *hw = &pf->hw;
709 	bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
710 	i40e_status ret = 0;
711 
712 	ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
713 	if (ret) {
714 		netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
715 			    i40e_stat_str(hw, ret),
716 			    i40e_aq_str(hw, hw->aq.asq_last_status));
717 		return -EIO;
718 	}
719 
720 	return 0;
721 }
722 
723 /**
724  * i40e_get_pauseparam -  Get Flow Control status
725  * Return tx/rx-pause status
726  **/
727 static void i40e_get_pauseparam(struct net_device *netdev,
728 				struct ethtool_pauseparam *pause)
729 {
730 	struct i40e_netdev_priv *np = netdev_priv(netdev);
731 	struct i40e_pf *pf = np->vsi->back;
732 	struct i40e_hw *hw = &pf->hw;
733 	struct i40e_link_status *hw_link_info = &hw->phy.link_info;
734 	struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
735 
736 	pause->autoneg =
737 		((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
738 		  AUTONEG_ENABLE : AUTONEG_DISABLE);
739 
740 	/* PFC enabled so report LFC as off */
741 	if (dcbx_cfg->pfc.pfcenable) {
742 		pause->rx_pause = 0;
743 		pause->tx_pause = 0;
744 		return;
745 	}
746 
747 	if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
748 		pause->rx_pause = 1;
749 	} else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
750 		pause->tx_pause = 1;
751 	} else if (hw->fc.current_mode == I40E_FC_FULL) {
752 		pause->rx_pause = 1;
753 		pause->tx_pause = 1;
754 	}
755 }
756 
757 /**
758  * i40e_set_pauseparam - Set Flow Control parameter
759  * @netdev: network interface device structure
760  * @pause: return tx/rx flow control status
761  **/
762 static int i40e_set_pauseparam(struct net_device *netdev,
763 			       struct ethtool_pauseparam *pause)
764 {
765 	struct i40e_netdev_priv *np = netdev_priv(netdev);
766 	struct i40e_pf *pf = np->vsi->back;
767 	struct i40e_vsi *vsi = np->vsi;
768 	struct i40e_hw *hw = &pf->hw;
769 	struct i40e_link_status *hw_link_info = &hw->phy.link_info;
770 	struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
771 	bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
772 	i40e_status status;
773 	u8 aq_failures;
774 	int err = 0;
775 
776 	/* Changing the port's flow control is not supported if this isn't the
777 	 * port's controlling PF
778 	 */
779 	if (hw->partition_id != 1) {
780 		i40e_partition_setting_complaint(pf);
781 		return -EOPNOTSUPP;
782 	}
783 
784 	if (vsi != pf->vsi[pf->lan_vsi])
785 		return -EOPNOTSUPP;
786 
787 	if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
788 	    AUTONEG_ENABLE : AUTONEG_DISABLE)) {
789 		netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
790 		return -EOPNOTSUPP;
791 	}
792 
793 	/* If we have link and don't have autoneg */
794 	if (!test_bit(__I40E_DOWN, &pf->state) &&
795 	    !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
796 		/* Send message that it might not necessarily work*/
797 		netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
798 	}
799 
800 	if (dcbx_cfg->pfc.pfcenable) {
801 		netdev_info(netdev,
802 			    "Priority flow control enabled. Cannot set link flow control.\n");
803 		return -EOPNOTSUPP;
804 	}
805 
806 	if (pause->rx_pause && pause->tx_pause)
807 		hw->fc.requested_mode = I40E_FC_FULL;
808 	else if (pause->rx_pause && !pause->tx_pause)
809 		hw->fc.requested_mode = I40E_FC_RX_PAUSE;
810 	else if (!pause->rx_pause && pause->tx_pause)
811 		hw->fc.requested_mode = I40E_FC_TX_PAUSE;
812 	else if (!pause->rx_pause && !pause->tx_pause)
813 		hw->fc.requested_mode = I40E_FC_NONE;
814 	else
815 		 return -EINVAL;
816 
817 	/* Tell the OS link is going down, the link will go back up when fw
818 	 * says it is ready asynchronously
819 	 */
820 	netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
821 	netif_carrier_off(netdev);
822 	netif_tx_stop_all_queues(netdev);
823 
824 	/* Set the fc mode and only restart an if link is up*/
825 	status = i40e_set_fc(hw, &aq_failures, link_up);
826 
827 	if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
828 		netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
829 			    i40e_stat_str(hw, status),
830 			    i40e_aq_str(hw, hw->aq.asq_last_status));
831 		err = -EAGAIN;
832 	}
833 	if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
834 		netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
835 			    i40e_stat_str(hw, status),
836 			    i40e_aq_str(hw, hw->aq.asq_last_status));
837 		err = -EAGAIN;
838 	}
839 	if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
840 		netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
841 			    i40e_stat_str(hw, status),
842 			    i40e_aq_str(hw, hw->aq.asq_last_status));
843 		err = -EAGAIN;
844 	}
845 
846 	if (!test_bit(__I40E_DOWN, &pf->state)) {
847 		/* Give it a little more time to try to come back */
848 		msleep(75);
849 		if (!test_bit(__I40E_DOWN, &pf->state))
850 			return i40e_nway_reset(netdev);
851 	}
852 
853 	return err;
854 }
855 
856 static u32 i40e_get_msglevel(struct net_device *netdev)
857 {
858 	struct i40e_netdev_priv *np = netdev_priv(netdev);
859 	struct i40e_pf *pf = np->vsi->back;
860 
861 	return pf->msg_enable;
862 }
863 
864 static void i40e_set_msglevel(struct net_device *netdev, u32 data)
865 {
866 	struct i40e_netdev_priv *np = netdev_priv(netdev);
867 	struct i40e_pf *pf = np->vsi->back;
868 
869 	if (I40E_DEBUG_USER & data)
870 		pf->hw.debug_mask = data;
871 	pf->msg_enable = data;
872 }
873 
874 static int i40e_get_regs_len(struct net_device *netdev)
875 {
876 	int reg_count = 0;
877 	int i;
878 
879 	for (i = 0; i40e_reg_list[i].offset != 0; i++)
880 		reg_count += i40e_reg_list[i].elements;
881 
882 	return reg_count * sizeof(u32);
883 }
884 
885 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
886 			  void *p)
887 {
888 	struct i40e_netdev_priv *np = netdev_priv(netdev);
889 	struct i40e_pf *pf = np->vsi->back;
890 	struct i40e_hw *hw = &pf->hw;
891 	u32 *reg_buf = p;
892 	int i, j, ri;
893 	u32 reg;
894 
895 	/* Tell ethtool which driver-version-specific regs output we have.
896 	 *
897 	 * At some point, if we have ethtool doing special formatting of
898 	 * this data, it will rely on this version number to know how to
899 	 * interpret things.  Hence, this needs to be updated if/when the
900 	 * diags register table is changed.
901 	 */
902 	regs->version = 1;
903 
904 	/* loop through the diags reg table for what to print */
905 	ri = 0;
906 	for (i = 0; i40e_reg_list[i].offset != 0; i++) {
907 		for (j = 0; j < i40e_reg_list[i].elements; j++) {
908 			reg = i40e_reg_list[i].offset
909 				+ (j * i40e_reg_list[i].stride);
910 			reg_buf[ri++] = rd32(hw, reg);
911 		}
912 	}
913 
914 }
915 
916 static int i40e_get_eeprom(struct net_device *netdev,
917 			   struct ethtool_eeprom *eeprom, u8 *bytes)
918 {
919 	struct i40e_netdev_priv *np = netdev_priv(netdev);
920 	struct i40e_hw *hw = &np->vsi->back->hw;
921 	struct i40e_pf *pf = np->vsi->back;
922 	int ret_val = 0, len, offset;
923 	u8 *eeprom_buff;
924 	u16 i, sectors;
925 	bool last;
926 	u32 magic;
927 
928 #define I40E_NVM_SECTOR_SIZE  4096
929 	if (eeprom->len == 0)
930 		return -EINVAL;
931 
932 	/* check for NVMUpdate access method */
933 	magic = hw->vendor_id | (hw->device_id << 16);
934 	if (eeprom->magic && eeprom->magic != magic) {
935 		struct i40e_nvm_access *cmd;
936 		int errno;
937 
938 		/* make sure it is the right magic for NVMUpdate */
939 		if ((eeprom->magic >> 16) != hw->device_id)
940 			return -EINVAL;
941 
942 		cmd = (struct i40e_nvm_access *)eeprom;
943 		ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
944 		if (ret_val &&
945 		    ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
946 		     (hw->debug_mask & I40E_DEBUG_NVM)))
947 			dev_info(&pf->pdev->dev,
948 				 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
949 				 ret_val, hw->aq.asq_last_status, errno,
950 				 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
951 				 cmd->offset, cmd->data_size);
952 
953 		return errno;
954 	}
955 
956 	/* normal ethtool get_eeprom support */
957 	eeprom->magic = hw->vendor_id | (hw->device_id << 16);
958 
959 	eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
960 	if (!eeprom_buff)
961 		return -ENOMEM;
962 
963 	ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
964 	if (ret_val) {
965 		dev_info(&pf->pdev->dev,
966 			 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
967 			 ret_val, hw->aq.asq_last_status);
968 		goto free_buff;
969 	}
970 
971 	sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
972 	sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
973 	len = I40E_NVM_SECTOR_SIZE;
974 	last = false;
975 	for (i = 0; i < sectors; i++) {
976 		if (i == (sectors - 1)) {
977 			len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
978 			last = true;
979 		}
980 		offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
981 		ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
982 				(u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
983 				last, NULL);
984 		if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
985 			dev_info(&pf->pdev->dev,
986 				 "read NVM failed, invalid offset 0x%x\n",
987 				 offset);
988 			break;
989 		} else if (ret_val &&
990 			   hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
991 			dev_info(&pf->pdev->dev,
992 				 "read NVM failed, access, offset 0x%x\n",
993 				 offset);
994 			break;
995 		} else if (ret_val) {
996 			dev_info(&pf->pdev->dev,
997 				 "read NVM failed offset %d err=%d status=0x%x\n",
998 				 offset, ret_val, hw->aq.asq_last_status);
999 			break;
1000 		}
1001 	}
1002 
1003 	i40e_release_nvm(hw);
1004 	memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
1005 free_buff:
1006 	kfree(eeprom_buff);
1007 	return ret_val;
1008 }
1009 
1010 static int i40e_get_eeprom_len(struct net_device *netdev)
1011 {
1012 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1013 	struct i40e_hw *hw = &np->vsi->back->hw;
1014 	u32 val;
1015 
1016 	val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1017 		& I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1018 		>> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1019 	/* register returns value in power of 2, 64Kbyte chunks. */
1020 	val = (64 * 1024) * BIT(val);
1021 	return val;
1022 }
1023 
1024 static int i40e_set_eeprom(struct net_device *netdev,
1025 			   struct ethtool_eeprom *eeprom, u8 *bytes)
1026 {
1027 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1028 	struct i40e_hw *hw = &np->vsi->back->hw;
1029 	struct i40e_pf *pf = np->vsi->back;
1030 	struct i40e_nvm_access *cmd;
1031 	int ret_val = 0;
1032 	int errno;
1033 	u32 magic;
1034 
1035 	/* normal ethtool set_eeprom is not supported */
1036 	magic = hw->vendor_id | (hw->device_id << 16);
1037 	if (eeprom->magic == magic)
1038 		return -EOPNOTSUPP;
1039 
1040 	/* check for NVMUpdate access method */
1041 	if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1042 		return -EINVAL;
1043 
1044 	if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1045 	    test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1046 		return -EBUSY;
1047 
1048 	cmd = (struct i40e_nvm_access *)eeprom;
1049 	ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1050 	if (ret_val &&
1051 	    ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1052 	      hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1053 	     (hw->debug_mask & I40E_DEBUG_NVM)))
1054 		dev_info(&pf->pdev->dev,
1055 			 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1056 			 ret_val, hw->aq.asq_last_status, errno,
1057 			 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1058 			 cmd->offset, cmd->data_size);
1059 
1060 	return errno;
1061 }
1062 
1063 static void i40e_get_drvinfo(struct net_device *netdev,
1064 			     struct ethtool_drvinfo *drvinfo)
1065 {
1066 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1067 	struct i40e_vsi *vsi = np->vsi;
1068 	struct i40e_pf *pf = vsi->back;
1069 
1070 	strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1071 	strlcpy(drvinfo->version, i40e_driver_version_str,
1072 		sizeof(drvinfo->version));
1073 	strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1074 		sizeof(drvinfo->fw_version));
1075 	strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1076 		sizeof(drvinfo->bus_info));
1077 	drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
1078 }
1079 
1080 static void i40e_get_ringparam(struct net_device *netdev,
1081 			       struct ethtool_ringparam *ring)
1082 {
1083 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1084 	struct i40e_pf *pf = np->vsi->back;
1085 	struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1086 
1087 	ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1088 	ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1089 	ring->rx_mini_max_pending = 0;
1090 	ring->rx_jumbo_max_pending = 0;
1091 	ring->rx_pending = vsi->rx_rings[0]->count;
1092 	ring->tx_pending = vsi->tx_rings[0]->count;
1093 	ring->rx_mini_pending = 0;
1094 	ring->rx_jumbo_pending = 0;
1095 }
1096 
1097 static int i40e_set_ringparam(struct net_device *netdev,
1098 			      struct ethtool_ringparam *ring)
1099 {
1100 	struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1101 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1102 	struct i40e_vsi *vsi = np->vsi;
1103 	struct i40e_pf *pf = vsi->back;
1104 	u32 new_rx_count, new_tx_count;
1105 	int i, err = 0;
1106 
1107 	if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1108 		return -EINVAL;
1109 
1110 	if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1111 	    ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1112 	    ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1113 	    ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1114 		netdev_info(netdev,
1115 			    "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1116 			    ring->tx_pending, ring->rx_pending,
1117 			    I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1118 		return -EINVAL;
1119 	}
1120 
1121 	new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1122 	new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1123 
1124 	/* if nothing to do return success */
1125 	if ((new_tx_count == vsi->tx_rings[0]->count) &&
1126 	    (new_rx_count == vsi->rx_rings[0]->count))
1127 		return 0;
1128 
1129 	while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1130 		usleep_range(1000, 2000);
1131 
1132 	if (!netif_running(vsi->netdev)) {
1133 		/* simple case - set for the next time the netdev is started */
1134 		for (i = 0; i < vsi->num_queue_pairs; i++) {
1135 			vsi->tx_rings[i]->count = new_tx_count;
1136 			vsi->rx_rings[i]->count = new_rx_count;
1137 		}
1138 		goto done;
1139 	}
1140 
1141 	/* We can't just free everything and then setup again,
1142 	 * because the ISRs in MSI-X mode get passed pointers
1143 	 * to the Tx and Rx ring structs.
1144 	 */
1145 
1146 	/* alloc updated Tx resources */
1147 	if (new_tx_count != vsi->tx_rings[0]->count) {
1148 		netdev_info(netdev,
1149 			    "Changing Tx descriptor count from %d to %d.\n",
1150 			    vsi->tx_rings[0]->count, new_tx_count);
1151 		tx_rings = kcalloc(vsi->alloc_queue_pairs,
1152 				   sizeof(struct i40e_ring), GFP_KERNEL);
1153 		if (!tx_rings) {
1154 			err = -ENOMEM;
1155 			goto done;
1156 		}
1157 
1158 		for (i = 0; i < vsi->num_queue_pairs; i++) {
1159 			/* clone ring and setup updated count */
1160 			tx_rings[i] = *vsi->tx_rings[i];
1161 			tx_rings[i].count = new_tx_count;
1162 			err = i40e_setup_tx_descriptors(&tx_rings[i]);
1163 			if (err) {
1164 				while (i) {
1165 					i--;
1166 					i40e_free_tx_resources(&tx_rings[i]);
1167 				}
1168 				kfree(tx_rings);
1169 				tx_rings = NULL;
1170 
1171 				goto done;
1172 			}
1173 		}
1174 	}
1175 
1176 	/* alloc updated Rx resources */
1177 	if (new_rx_count != vsi->rx_rings[0]->count) {
1178 		netdev_info(netdev,
1179 			    "Changing Rx descriptor count from %d to %d\n",
1180 			    vsi->rx_rings[0]->count, new_rx_count);
1181 		rx_rings = kcalloc(vsi->alloc_queue_pairs,
1182 				   sizeof(struct i40e_ring), GFP_KERNEL);
1183 		if (!rx_rings) {
1184 			err = -ENOMEM;
1185 			goto free_tx;
1186 		}
1187 
1188 		for (i = 0; i < vsi->num_queue_pairs; i++) {
1189 			/* clone ring and setup updated count */
1190 			rx_rings[i] = *vsi->rx_rings[i];
1191 			rx_rings[i].count = new_rx_count;
1192 			err = i40e_setup_rx_descriptors(&rx_rings[i]);
1193 			if (err) {
1194 				while (i) {
1195 					i--;
1196 					i40e_free_rx_resources(&rx_rings[i]);
1197 				}
1198 				kfree(rx_rings);
1199 				rx_rings = NULL;
1200 
1201 				goto free_tx;
1202 			}
1203 		}
1204 	}
1205 
1206 	/* Bring interface down, copy in the new ring info,
1207 	 * then restore the interface
1208 	 */
1209 	i40e_down(vsi);
1210 
1211 	if (tx_rings) {
1212 		for (i = 0; i < vsi->num_queue_pairs; i++) {
1213 			i40e_free_tx_resources(vsi->tx_rings[i]);
1214 			*vsi->tx_rings[i] = tx_rings[i];
1215 		}
1216 		kfree(tx_rings);
1217 		tx_rings = NULL;
1218 	}
1219 
1220 	if (rx_rings) {
1221 		for (i = 0; i < vsi->num_queue_pairs; i++) {
1222 			i40e_free_rx_resources(vsi->rx_rings[i]);
1223 			*vsi->rx_rings[i] = rx_rings[i];
1224 		}
1225 		kfree(rx_rings);
1226 		rx_rings = NULL;
1227 	}
1228 
1229 	i40e_up(vsi);
1230 
1231 free_tx:
1232 	/* error cleanup if the Rx allocations failed after getting Tx */
1233 	if (tx_rings) {
1234 		for (i = 0; i < vsi->num_queue_pairs; i++)
1235 			i40e_free_tx_resources(&tx_rings[i]);
1236 		kfree(tx_rings);
1237 		tx_rings = NULL;
1238 	}
1239 
1240 done:
1241 	clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1242 
1243 	return err;
1244 }
1245 
1246 static int i40e_get_sset_count(struct net_device *netdev, int sset)
1247 {
1248 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1249 	struct i40e_vsi *vsi = np->vsi;
1250 	struct i40e_pf *pf = vsi->back;
1251 
1252 	switch (sset) {
1253 	case ETH_SS_TEST:
1254 		return I40E_TEST_LEN;
1255 	case ETH_SS_STATS:
1256 		if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
1257 			int len = I40E_PF_STATS_LEN(netdev);
1258 
1259 			if (pf->lan_veb != I40E_NO_VEB)
1260 				len += I40E_VEB_STATS_LEN;
1261 			return len;
1262 		} else {
1263 			return I40E_VSI_STATS_LEN(netdev);
1264 		}
1265 	case ETH_SS_PRIV_FLAGS:
1266 		return I40E_PRIV_FLAGS_STR_LEN;
1267 	default:
1268 		return -EOPNOTSUPP;
1269 	}
1270 }
1271 
1272 static void i40e_get_ethtool_stats(struct net_device *netdev,
1273 				   struct ethtool_stats *stats, u64 *data)
1274 {
1275 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1276 	struct i40e_ring *tx_ring, *rx_ring;
1277 	struct i40e_vsi *vsi = np->vsi;
1278 	struct i40e_pf *pf = vsi->back;
1279 	int i = 0;
1280 	char *p;
1281 	int j;
1282 	struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
1283 	unsigned int start;
1284 
1285 	i40e_update_stats(vsi);
1286 
1287 	for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1288 		p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1289 		data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1290 			sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1291 	}
1292 	for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1293 		p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1294 		data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1295 			    sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1296 	}
1297 #ifdef I40E_FCOE
1298 	for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1299 		p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1300 		data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1301 			sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1302 	}
1303 #endif
1304 	rcu_read_lock();
1305 	for (j = 0; j < vsi->num_queue_pairs; j++) {
1306 		tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
1307 
1308 		if (!tx_ring)
1309 			continue;
1310 
1311 		/* process Tx ring statistics */
1312 		do {
1313 			start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
1314 			data[i] = tx_ring->stats.packets;
1315 			data[i + 1] = tx_ring->stats.bytes;
1316 		} while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
1317 		i += 2;
1318 
1319 		/* Rx ring is the 2nd half of the queue pair */
1320 		rx_ring = &tx_ring[1];
1321 		do {
1322 			start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
1323 			data[i] = rx_ring->stats.packets;
1324 			data[i + 1] = rx_ring->stats.bytes;
1325 		} while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
1326 		i += 2;
1327 	}
1328 	rcu_read_unlock();
1329 	if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1330 		return;
1331 
1332 	if (pf->lan_veb != I40E_NO_VEB) {
1333 		struct i40e_veb *veb = pf->veb[pf->lan_veb];
1334 		for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1335 			p = (char *)veb;
1336 			p += i40e_gstrings_veb_stats[j].stat_offset;
1337 			data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1338 				     sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1339 		}
1340 	}
1341 	for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1342 		p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1343 		data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1344 			     sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1345 	}
1346 	for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1347 		data[i++] = pf->stats.priority_xon_tx[j];
1348 		data[i++] = pf->stats.priority_xoff_tx[j];
1349 	}
1350 	for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1351 		data[i++] = pf->stats.priority_xon_rx[j];
1352 		data[i++] = pf->stats.priority_xoff_rx[j];
1353 	}
1354 	for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1355 		data[i++] = pf->stats.priority_xon_2_xoff[j];
1356 }
1357 
1358 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1359 			     u8 *data)
1360 {
1361 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1362 	struct i40e_vsi *vsi = np->vsi;
1363 	struct i40e_pf *pf = vsi->back;
1364 	char *p = (char *)data;
1365 	int i;
1366 
1367 	switch (stringset) {
1368 	case ETH_SS_TEST:
1369 		for (i = 0; i < I40E_TEST_LEN; i++) {
1370 			memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1371 			data += ETH_GSTRING_LEN;
1372 		}
1373 		break;
1374 	case ETH_SS_STATS:
1375 		for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1376 			snprintf(p, ETH_GSTRING_LEN, "%s",
1377 				 i40e_gstrings_net_stats[i].stat_string);
1378 			p += ETH_GSTRING_LEN;
1379 		}
1380 		for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1381 			snprintf(p, ETH_GSTRING_LEN, "%s",
1382 				 i40e_gstrings_misc_stats[i].stat_string);
1383 			p += ETH_GSTRING_LEN;
1384 		}
1385 #ifdef I40E_FCOE
1386 		for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1387 			snprintf(p, ETH_GSTRING_LEN, "%s",
1388 				 i40e_gstrings_fcoe_stats[i].stat_string);
1389 			p += ETH_GSTRING_LEN;
1390 		}
1391 #endif
1392 		for (i = 0; i < vsi->num_queue_pairs; i++) {
1393 			snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1394 			p += ETH_GSTRING_LEN;
1395 			snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1396 			p += ETH_GSTRING_LEN;
1397 			snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1398 			p += ETH_GSTRING_LEN;
1399 			snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1400 			p += ETH_GSTRING_LEN;
1401 		}
1402 		if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1403 			return;
1404 
1405 		if (pf->lan_veb != I40E_NO_VEB) {
1406 			for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1407 				snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1408 					i40e_gstrings_veb_stats[i].stat_string);
1409 				p += ETH_GSTRING_LEN;
1410 			}
1411 		}
1412 		for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1413 			snprintf(p, ETH_GSTRING_LEN, "port.%s",
1414 				 i40e_gstrings_stats[i].stat_string);
1415 			p += ETH_GSTRING_LEN;
1416 		}
1417 		for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1418 			snprintf(p, ETH_GSTRING_LEN,
1419 				 "port.tx_priority_%u_xon", i);
1420 			p += ETH_GSTRING_LEN;
1421 			snprintf(p, ETH_GSTRING_LEN,
1422 				 "port.tx_priority_%u_xoff", i);
1423 			p += ETH_GSTRING_LEN;
1424 		}
1425 		for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1426 			snprintf(p, ETH_GSTRING_LEN,
1427 				 "port.rx_priority_%u_xon", i);
1428 			p += ETH_GSTRING_LEN;
1429 			snprintf(p, ETH_GSTRING_LEN,
1430 				 "port.rx_priority_%u_xoff", i);
1431 			p += ETH_GSTRING_LEN;
1432 		}
1433 		for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1434 			snprintf(p, ETH_GSTRING_LEN,
1435 				 "port.rx_priority_%u_xon_2_xoff", i);
1436 			p += ETH_GSTRING_LEN;
1437 		}
1438 		/* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1439 		break;
1440 	case ETH_SS_PRIV_FLAGS:
1441 		for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1442 			memcpy(data, i40e_priv_flags_strings[i],
1443 			       ETH_GSTRING_LEN);
1444 			data += ETH_GSTRING_LEN;
1445 		}
1446 		break;
1447 	default:
1448 		break;
1449 	}
1450 }
1451 
1452 static int i40e_get_ts_info(struct net_device *dev,
1453 			    struct ethtool_ts_info *info)
1454 {
1455 	struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1456 
1457 	/* only report HW timestamping if PTP is enabled */
1458 	if (!(pf->flags & I40E_FLAG_PTP))
1459 		return ethtool_op_get_ts_info(dev, info);
1460 
1461 	info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1462 				SOF_TIMESTAMPING_RX_SOFTWARE |
1463 				SOF_TIMESTAMPING_SOFTWARE |
1464 				SOF_TIMESTAMPING_TX_HARDWARE |
1465 				SOF_TIMESTAMPING_RX_HARDWARE |
1466 				SOF_TIMESTAMPING_RAW_HARDWARE;
1467 
1468 	if (pf->ptp_clock)
1469 		info->phc_index = ptp_clock_index(pf->ptp_clock);
1470 	else
1471 		info->phc_index = -1;
1472 
1473 	info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
1474 
1475 	info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1476 			   BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1477 			   BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
1478 
1479 	return 0;
1480 }
1481 
1482 static int i40e_link_test(struct net_device *netdev, u64 *data)
1483 {
1484 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1485 	struct i40e_pf *pf = np->vsi->back;
1486 
1487 	netif_info(pf, hw, netdev, "link test\n");
1488 	if (i40e_get_link_status(&pf->hw))
1489 		*data = 0;
1490 	else
1491 		*data = 1;
1492 
1493 	return *data;
1494 }
1495 
1496 static int i40e_reg_test(struct net_device *netdev, u64 *data)
1497 {
1498 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1499 	struct i40e_pf *pf = np->vsi->back;
1500 
1501 	netif_info(pf, hw, netdev, "register test\n");
1502 	*data = i40e_diag_reg_test(&pf->hw);
1503 
1504 	return *data;
1505 }
1506 
1507 static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
1508 {
1509 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1510 	struct i40e_pf *pf = np->vsi->back;
1511 
1512 	netif_info(pf, hw, netdev, "eeprom test\n");
1513 	*data = i40e_diag_eeprom_test(&pf->hw);
1514 
1515 	/* forcebly clear the NVM Update state machine */
1516 	pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1517 
1518 	return *data;
1519 }
1520 
1521 static int i40e_intr_test(struct net_device *netdev, u64 *data)
1522 {
1523 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1524 	struct i40e_pf *pf = np->vsi->back;
1525 	u16 swc_old = pf->sw_int_count;
1526 
1527 	netif_info(pf, hw, netdev, "interrupt test\n");
1528 	wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1529 	     (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1530 	      I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1531 	      I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1532 	      I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1533 	      I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
1534 	usleep_range(1000, 2000);
1535 	*data = (swc_old == pf->sw_int_count);
1536 
1537 	return *data;
1538 }
1539 
1540 static int i40e_loopback_test(struct net_device *netdev, u64 *data)
1541 {
1542 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1543 	struct i40e_pf *pf = np->vsi->back;
1544 
1545 	netif_info(pf, hw, netdev, "loopback test not implemented\n");
1546 	*data = 0;
1547 
1548 	return *data;
1549 }
1550 
1551 static inline bool i40e_active_vfs(struct i40e_pf *pf)
1552 {
1553 	struct i40e_vf *vfs = pf->vf;
1554 	int i;
1555 
1556 	for (i = 0; i < pf->num_alloc_vfs; i++)
1557 		if (vfs[i].vf_states & I40E_VF_STAT_ACTIVE)
1558 			return true;
1559 	return false;
1560 }
1561 
1562 static void i40e_diag_test(struct net_device *netdev,
1563 			   struct ethtool_test *eth_test, u64 *data)
1564 {
1565 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1566 	bool if_running = netif_running(netdev);
1567 	struct i40e_pf *pf = np->vsi->back;
1568 
1569 	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1570 		/* Offline tests */
1571 		netif_info(pf, drv, netdev, "offline testing starting\n");
1572 
1573 		set_bit(__I40E_TESTING, &pf->state);
1574 
1575 		if (i40e_active_vfs(pf)) {
1576 			dev_warn(&pf->pdev->dev,
1577 				 "Please take active VFS offline and restart the adapter before running NIC diagnostics\n");
1578 			data[I40E_ETH_TEST_REG]		= 1;
1579 			data[I40E_ETH_TEST_EEPROM]	= 1;
1580 			data[I40E_ETH_TEST_INTR]	= 1;
1581 			data[I40E_ETH_TEST_LOOPBACK]	= 1;
1582 			data[I40E_ETH_TEST_LINK]	= 1;
1583 			eth_test->flags |= ETH_TEST_FL_FAILED;
1584 			clear_bit(__I40E_TESTING, &pf->state);
1585 			goto skip_ol_tests;
1586 		}
1587 
1588 		/* If the device is online then take it offline */
1589 		if (if_running)
1590 			/* indicate we're in test mode */
1591 			dev_close(netdev);
1592 		else
1593 			i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
1594 
1595 		/* Link test performed before hardware reset
1596 		 * so autoneg doesn't interfere with test result
1597 		 */
1598 		if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1599 			eth_test->flags |= ETH_TEST_FL_FAILED;
1600 
1601 		if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
1602 			eth_test->flags |= ETH_TEST_FL_FAILED;
1603 
1604 		if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
1605 			eth_test->flags |= ETH_TEST_FL_FAILED;
1606 
1607 		if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
1608 			eth_test->flags |= ETH_TEST_FL_FAILED;
1609 
1610 		/* run reg test last, a reset is required after it */
1611 		if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1612 			eth_test->flags |= ETH_TEST_FL_FAILED;
1613 
1614 		clear_bit(__I40E_TESTING, &pf->state);
1615 		i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
1616 
1617 		if (if_running)
1618 			dev_open(netdev);
1619 	} else {
1620 		/* Online tests */
1621 		netif_info(pf, drv, netdev, "online testing starting\n");
1622 
1623 		if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1624 			eth_test->flags |= ETH_TEST_FL_FAILED;
1625 
1626 		/* Offline only tests, not run in online; pass by default */
1627 		data[I40E_ETH_TEST_REG] = 0;
1628 		data[I40E_ETH_TEST_EEPROM] = 0;
1629 		data[I40E_ETH_TEST_INTR] = 0;
1630 		data[I40E_ETH_TEST_LOOPBACK] = 0;
1631 	}
1632 
1633 skip_ol_tests:
1634 
1635 	netif_info(pf, drv, netdev, "testing finished\n");
1636 }
1637 
1638 static void i40e_get_wol(struct net_device *netdev,
1639 			 struct ethtool_wolinfo *wol)
1640 {
1641 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1642 	struct i40e_pf *pf = np->vsi->back;
1643 	struct i40e_hw *hw = &pf->hw;
1644 	u16 wol_nvm_bits;
1645 
1646 	/* NVM bit on means WoL disabled for the port */
1647 	i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1648 	if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
1649 		wol->supported = 0;
1650 		wol->wolopts = 0;
1651 	} else {
1652 		wol->supported = WAKE_MAGIC;
1653 		wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1654 	}
1655 }
1656 
1657 /**
1658  * i40e_set_wol - set the WakeOnLAN configuration
1659  * @netdev: the netdev in question
1660  * @wol: the ethtool WoL setting data
1661  **/
1662 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1663 {
1664 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1665 	struct i40e_pf *pf = np->vsi->back;
1666 	struct i40e_vsi *vsi = np->vsi;
1667 	struct i40e_hw *hw = &pf->hw;
1668 	u16 wol_nvm_bits;
1669 
1670 	/* WoL not supported if this isn't the controlling PF on the port */
1671 	if (hw->partition_id != 1) {
1672 		i40e_partition_setting_complaint(pf);
1673 		return -EOPNOTSUPP;
1674 	}
1675 
1676 	if (vsi != pf->vsi[pf->lan_vsi])
1677 		return -EOPNOTSUPP;
1678 
1679 	/* NVM bit on means WoL disabled for the port */
1680 	i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1681 	if (BIT(hw->port) & wol_nvm_bits)
1682 		return -EOPNOTSUPP;
1683 
1684 	/* only magic packet is supported */
1685 	if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1686 		return -EOPNOTSUPP;
1687 
1688 	/* is this a new value? */
1689 	if (pf->wol_en != !!wol->wolopts) {
1690 		pf->wol_en = !!wol->wolopts;
1691 		device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1692 	}
1693 
1694 	return 0;
1695 }
1696 
1697 static int i40e_set_phys_id(struct net_device *netdev,
1698 			    enum ethtool_phys_id_state state)
1699 {
1700 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1701 	struct i40e_pf *pf = np->vsi->back;
1702 	struct i40e_hw *hw = &pf->hw;
1703 	int blink_freq = 2;
1704 
1705 	switch (state) {
1706 	case ETHTOOL_ID_ACTIVE:
1707 		pf->led_status = i40e_led_get(hw);
1708 		return blink_freq;
1709 	case ETHTOOL_ID_ON:
1710 		i40e_led_set(hw, 0xF, false);
1711 		break;
1712 	case ETHTOOL_ID_OFF:
1713 		i40e_led_set(hw, 0x0, false);
1714 		break;
1715 	case ETHTOOL_ID_INACTIVE:
1716 		i40e_led_set(hw, pf->led_status, false);
1717 		break;
1718 	default:
1719 		break;
1720 	}
1721 
1722 	return 0;
1723 }
1724 
1725 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1726  * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1727  * 125us (8000 interrupts per second) == ITR(62)
1728  */
1729 
1730 static int i40e_get_coalesce(struct net_device *netdev,
1731 			     struct ethtool_coalesce *ec)
1732 {
1733 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1734 	struct i40e_vsi *vsi = np->vsi;
1735 
1736 	ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1737 	ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1738 
1739 	if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
1740 		ec->use_adaptive_rx_coalesce = 1;
1741 
1742 	if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
1743 		ec->use_adaptive_tx_coalesce = 1;
1744 
1745 	ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1746 	ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1747 
1748 	return 0;
1749 }
1750 
1751 static int i40e_set_coalesce(struct net_device *netdev,
1752 			     struct ethtool_coalesce *ec)
1753 {
1754 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1755 	struct i40e_q_vector *q_vector;
1756 	struct i40e_vsi *vsi = np->vsi;
1757 	struct i40e_pf *pf = vsi->back;
1758 	struct i40e_hw *hw = &pf->hw;
1759 	u16 vector;
1760 	int i;
1761 
1762 	if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1763 		vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1764 
1765 	vector = vsi->base_vector;
1766 	if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1767 	    (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
1768 		vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1769 	} else if (ec->rx_coalesce_usecs == 0) {
1770 		vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1771 		if (ec->use_adaptive_rx_coalesce)
1772 			netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
1773 	} else {
1774 		netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
1775 		return -EINVAL;
1776 	}
1777 
1778 	if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1779 	    (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
1780 		vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1781 	} else if (ec->tx_coalesce_usecs == 0) {
1782 		vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1783 		if (ec->use_adaptive_tx_coalesce)
1784 			netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
1785 	} else {
1786 		netif_info(pf, drv, netdev,
1787 			   "Invalid value, tx-usecs range is 0-8160\n");
1788 		return -EINVAL;
1789 	}
1790 
1791 	if (ec->use_adaptive_rx_coalesce)
1792 		vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1793 	else
1794 		vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1795 
1796 	if (ec->use_adaptive_tx_coalesce)
1797 		vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1798 	else
1799 		vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
1800 
1801 	for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1802 		q_vector = vsi->q_vectors[i];
1803 		q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1804 		wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1805 		q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1806 		wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1807 		i40e_flush(hw);
1808 	}
1809 
1810 	return 0;
1811 }
1812 
1813 /**
1814  * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1815  * @pf: pointer to the physical function struct
1816  * @cmd: ethtool rxnfc command
1817  *
1818  * Returns Success if the flow is supported, else Invalid Input.
1819  **/
1820 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1821 {
1822 	cmd->data = 0;
1823 
1824 	if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1825 		cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1826 		cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1827 		return 0;
1828 	}
1829 	/* Report default options for RSS on i40e */
1830 	switch (cmd->flow_type) {
1831 	case TCP_V4_FLOW:
1832 	case UDP_V4_FLOW:
1833 		cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1834 	/* fall through to add IP fields */
1835 	case SCTP_V4_FLOW:
1836 	case AH_ESP_V4_FLOW:
1837 	case AH_V4_FLOW:
1838 	case ESP_V4_FLOW:
1839 	case IPV4_FLOW:
1840 		cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1841 		break;
1842 	case TCP_V6_FLOW:
1843 	case UDP_V6_FLOW:
1844 		cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1845 	/* fall through to add IP fields */
1846 	case SCTP_V6_FLOW:
1847 	case AH_ESP_V6_FLOW:
1848 	case AH_V6_FLOW:
1849 	case ESP_V6_FLOW:
1850 	case IPV6_FLOW:
1851 		cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1852 		break;
1853 	default:
1854 		return -EINVAL;
1855 	}
1856 
1857 	return 0;
1858 }
1859 
1860 /**
1861  * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1862  * @pf: Pointer to the physical function struct
1863  * @cmd: The command to get or set Rx flow classification rules
1864  * @rule_locs: Array of used rule locations
1865  *
1866  * This function populates both the total and actual rule count of
1867  * the ethtool flow classification command
1868  *
1869  * Returns 0 on success or -EMSGSIZE if entry not found
1870  **/
1871 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1872 				     struct ethtool_rxnfc *cmd,
1873 				     u32 *rule_locs)
1874 {
1875 	struct i40e_fdir_filter *rule;
1876 	struct hlist_node *node2;
1877 	int cnt = 0;
1878 
1879 	/* report total rule count */
1880 	cmd->data = i40e_get_fd_cnt_all(pf);
1881 
1882 	hlist_for_each_entry_safe(rule, node2,
1883 				  &pf->fdir_filter_list, fdir_node) {
1884 		if (cnt == cmd->rule_cnt)
1885 			return -EMSGSIZE;
1886 
1887 		rule_locs[cnt] = rule->fd_id;
1888 		cnt++;
1889 	}
1890 
1891 	cmd->rule_cnt = cnt;
1892 
1893 	return 0;
1894 }
1895 
1896 /**
1897  * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1898  * @pf: Pointer to the physical function struct
1899  * @cmd: The command to get or set Rx flow classification rules
1900  *
1901  * This function looks up a filter based on the Rx flow classification
1902  * command and fills the flow spec info for it if found
1903  *
1904  * Returns 0 on success or -EINVAL if filter not found
1905  **/
1906 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1907 				       struct ethtool_rxnfc *cmd)
1908 {
1909 	struct ethtool_rx_flow_spec *fsp =
1910 			(struct ethtool_rx_flow_spec *)&cmd->fs;
1911 	struct i40e_fdir_filter *rule = NULL;
1912 	struct hlist_node *node2;
1913 
1914 	hlist_for_each_entry_safe(rule, node2,
1915 				  &pf->fdir_filter_list, fdir_node) {
1916 		if (fsp->location <= rule->fd_id)
1917 			break;
1918 	}
1919 
1920 	if (!rule || fsp->location != rule->fd_id)
1921 		return -EINVAL;
1922 
1923 	fsp->flow_type = rule->flow_type;
1924 	if (fsp->flow_type == IP_USER_FLOW) {
1925 		fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1926 		fsp->h_u.usr_ip4_spec.proto = 0;
1927 		fsp->m_u.usr_ip4_spec.proto = 0;
1928 	}
1929 
1930 	/* Reverse the src and dest notion, since the HW views them from
1931 	 * Tx perspective where as the user expects it from Rx filter view.
1932 	 */
1933 	fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1934 	fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1935 	fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1936 	fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
1937 
1938 	if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1939 		fsp->ring_cookie = RX_CLS_FLOW_DISC;
1940 	else
1941 		fsp->ring_cookie = rule->q_index;
1942 
1943 	if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
1944 		struct i40e_vsi *vsi;
1945 
1946 		vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
1947 		if (vsi && vsi->type == I40E_VSI_SRIOV) {
1948 			fsp->h_ext.data[1] = htonl(vsi->vf_id);
1949 			fsp->m_ext.data[1] = htonl(0x1);
1950 		}
1951 	}
1952 
1953 	return 0;
1954 }
1955 
1956 /**
1957  * i40e_get_rxnfc - command to get RX flow classification rules
1958  * @netdev: network interface device structure
1959  * @cmd: ethtool rxnfc command
1960  *
1961  * Returns Success if the command is supported.
1962  **/
1963 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1964 			  u32 *rule_locs)
1965 {
1966 	struct i40e_netdev_priv *np = netdev_priv(netdev);
1967 	struct i40e_vsi *vsi = np->vsi;
1968 	struct i40e_pf *pf = vsi->back;
1969 	int ret = -EOPNOTSUPP;
1970 
1971 	switch (cmd->cmd) {
1972 	case ETHTOOL_GRXRINGS:
1973 		cmd->data = vsi->alloc_queue_pairs;
1974 		ret = 0;
1975 		break;
1976 	case ETHTOOL_GRXFH:
1977 		ret = i40e_get_rss_hash_opts(pf, cmd);
1978 		break;
1979 	case ETHTOOL_GRXCLSRLCNT:
1980 		cmd->rule_cnt = pf->fdir_pf_active_filters;
1981 		/* report total rule count */
1982 		cmd->data = i40e_get_fd_cnt_all(pf);
1983 		ret = 0;
1984 		break;
1985 	case ETHTOOL_GRXCLSRULE:
1986 		ret = i40e_get_ethtool_fdir_entry(pf, cmd);
1987 		break;
1988 	case ETHTOOL_GRXCLSRLALL:
1989 		ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1990 		break;
1991 	default:
1992 		break;
1993 	}
1994 
1995 	return ret;
1996 }
1997 
1998 /**
1999  * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2000  * @pf: pointer to the physical function struct
2001  * @cmd: ethtool rxnfc command
2002  *
2003  * Returns Success if the flow input set is supported.
2004  **/
2005 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2006 {
2007 	struct i40e_hw *hw = &pf->hw;
2008 	u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2009 		   ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2010 
2011 	/* RSS does not support anything other than hashing
2012 	 * to queues on src and dst IPs and ports
2013 	 */
2014 	if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2015 			  RXH_L4_B_0_1 | RXH_L4_B_2_3))
2016 		return -EINVAL;
2017 
2018 	/* We need at least the IP SRC and DEST fields for hashing */
2019 	if (!(nfc->data & RXH_IP_SRC) ||
2020 	    !(nfc->data & RXH_IP_DST))
2021 		return -EINVAL;
2022 
2023 	switch (nfc->flow_type) {
2024 	case TCP_V4_FLOW:
2025 		switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2026 		case 0:
2027 			hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2028 			break;
2029 		case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2030 			hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2031 			break;
2032 		default:
2033 			return -EINVAL;
2034 		}
2035 		break;
2036 	case TCP_V6_FLOW:
2037 		switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2038 		case 0:
2039 			hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2040 			break;
2041 		case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2042 			hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2043 			break;
2044 		default:
2045 			return -EINVAL;
2046 		}
2047 		break;
2048 	case UDP_V4_FLOW:
2049 		switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2050 		case 0:
2051 			hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2052 				  BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
2053 			break;
2054 		case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2055 			hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2056 				 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
2057 			break;
2058 		default:
2059 			return -EINVAL;
2060 		}
2061 		break;
2062 	case UDP_V6_FLOW:
2063 		switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2064 		case 0:
2065 			hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2066 				  BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
2067 			break;
2068 		case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2069 			hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2070 				 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
2071 			break;
2072 		default:
2073 			return -EINVAL;
2074 		}
2075 		break;
2076 	case AH_ESP_V4_FLOW:
2077 	case AH_V4_FLOW:
2078 	case ESP_V4_FLOW:
2079 	case SCTP_V4_FLOW:
2080 		if ((nfc->data & RXH_L4_B_0_1) ||
2081 		    (nfc->data & RXH_L4_B_2_3))
2082 			return -EINVAL;
2083 		hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2084 		break;
2085 	case AH_ESP_V6_FLOW:
2086 	case AH_V6_FLOW:
2087 	case ESP_V6_FLOW:
2088 	case SCTP_V6_FLOW:
2089 		if ((nfc->data & RXH_L4_B_0_1) ||
2090 		    (nfc->data & RXH_L4_B_2_3))
2091 			return -EINVAL;
2092 		hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2093 		break;
2094 	case IPV4_FLOW:
2095 		hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2096 			BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
2097 		break;
2098 	case IPV6_FLOW:
2099 		hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2100 			BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
2101 		break;
2102 	default:
2103 		return -EINVAL;
2104 	}
2105 
2106 	wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2107 	wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2108 	i40e_flush(hw);
2109 
2110 	/* Save setting for future output/update */
2111 	pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2112 
2113 	return 0;
2114 }
2115 
2116 /**
2117  * i40e_match_fdir_input_set - Match a new filter against an existing one
2118  * @rule: The filter already added
2119  * @input: The new filter to comapre against
2120  *
2121  * Returns true if the two input set match
2122  **/
2123 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2124 				      struct i40e_fdir_filter *input)
2125 {
2126 	if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2127 	    (rule->src_ip[0] != input->src_ip[0]) ||
2128 	    (rule->dst_port != input->dst_port) ||
2129 	    (rule->src_port != input->src_port))
2130 		return false;
2131 	return true;
2132 }
2133 
2134 /**
2135  * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2136  * @vsi: Pointer to the targeted VSI
2137  * @input: The filter to update or NULL to indicate deletion
2138  * @sw_idx: Software index to the filter
2139  * @cmd: The command to get or set Rx flow classification rules
2140  *
2141  * This function updates (or deletes) a Flow Director entry from
2142  * the hlist of the corresponding PF
2143  *
2144  * Returns 0 on success
2145  **/
2146 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2147 					  struct i40e_fdir_filter *input,
2148 					  u16 sw_idx,
2149 					  struct ethtool_rxnfc *cmd)
2150 {
2151 	struct i40e_fdir_filter *rule, *parent;
2152 	struct i40e_pf *pf = vsi->back;
2153 	struct hlist_node *node2;
2154 	int err = -EINVAL;
2155 
2156 	parent = NULL;
2157 	rule = NULL;
2158 
2159 	hlist_for_each_entry_safe(rule, node2,
2160 				  &pf->fdir_filter_list, fdir_node) {
2161 		/* hash found, or no matching entry */
2162 		if (rule->fd_id >= sw_idx)
2163 			break;
2164 		parent = rule;
2165 	}
2166 
2167 	/* if there is an old rule occupying our place remove it */
2168 	if (rule && (rule->fd_id == sw_idx)) {
2169 		if (input && !i40e_match_fdir_input_set(rule, input))
2170 			err = i40e_add_del_fdir(vsi, rule, false);
2171 		else if (!input)
2172 			err = i40e_add_del_fdir(vsi, rule, false);
2173 		hlist_del(&rule->fdir_node);
2174 		kfree(rule);
2175 		pf->fdir_pf_active_filters--;
2176 	}
2177 
2178 	/* If no input this was a delete, err should be 0 if a rule was
2179 	 * successfully found and removed from the list else -EINVAL
2180 	 */
2181 	if (!input)
2182 		return err;
2183 
2184 	/* initialize node and set software index */
2185 	INIT_HLIST_NODE(&input->fdir_node);
2186 
2187 	/* add filter to the list */
2188 	if (parent)
2189 		hlist_add_behind(&input->fdir_node, &parent->fdir_node);
2190 	else
2191 		hlist_add_head(&input->fdir_node,
2192 			       &pf->fdir_filter_list);
2193 
2194 	/* update counts */
2195 	pf->fdir_pf_active_filters++;
2196 
2197 	return 0;
2198 }
2199 
2200 /**
2201  * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2202  * @vsi: Pointer to the targeted VSI
2203  * @cmd: The command to get or set Rx flow classification rules
2204  *
2205  * The function removes a Flow Director filter entry from the
2206  * hlist of the corresponding PF
2207  *
2208  * Returns 0 on success
2209  */
2210 static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2211 			       struct ethtool_rxnfc *cmd)
2212 {
2213 	struct ethtool_rx_flow_spec *fsp =
2214 		(struct ethtool_rx_flow_spec *)&cmd->fs;
2215 	struct i40e_pf *pf = vsi->back;
2216 	int ret = 0;
2217 
2218 	if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2219 	    test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2220 		return -EBUSY;
2221 
2222 	if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2223 		return -EBUSY;
2224 
2225 	ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
2226 
2227 	i40e_fdir_check_and_reenable(pf);
2228 	return ret;
2229 }
2230 
2231 /**
2232  * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
2233  * @vsi: pointer to the targeted VSI
2234  * @cmd: command to get or set RX flow classification rules
2235  *
2236  * Add Flow Director filters for a specific flow spec based on their
2237  * protocol.  Returns 0 if the filters were successfully added.
2238  **/
2239 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2240 				 struct ethtool_rxnfc *cmd)
2241 {
2242 	struct ethtool_rx_flow_spec *fsp;
2243 	struct i40e_fdir_filter *input;
2244 	struct i40e_pf *pf;
2245 	int ret = -EINVAL;
2246 	u16 vf_id;
2247 
2248 	if (!vsi)
2249 		return -EINVAL;
2250 
2251 	pf = vsi->back;
2252 
2253 	if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2254 		return -EOPNOTSUPP;
2255 
2256 	if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
2257 		return -ENOSPC;
2258 
2259 	if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2260 	    test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2261 		return -EBUSY;
2262 
2263 	if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2264 		return -EBUSY;
2265 
2266 	fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2267 
2268 	if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2269 			      pf->hw.func_caps.fd_filters_guaranteed)) {
2270 		return -EINVAL;
2271 	}
2272 
2273 	if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2274 	    (fsp->ring_cookie >= vsi->num_queue_pairs))
2275 		return -EINVAL;
2276 
2277 	input = kzalloc(sizeof(*input), GFP_KERNEL);
2278 
2279 	if (!input)
2280 		return -ENOMEM;
2281 
2282 	input->fd_id = fsp->location;
2283 
2284 	if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2285 		input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2286 	else
2287 		input->dest_ctl =
2288 			     I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2289 
2290 	input->q_index = fsp->ring_cookie;
2291 	input->flex_off = 0;
2292 	input->pctype = 0;
2293 	input->dest_vsi = vsi->id;
2294 	input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
2295 	input->cnt_index  = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
2296 	input->flow_type = fsp->flow_type;
2297 	input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
2298 
2299 	/* Reverse the src and dest notion, since the HW expects them to be from
2300 	 * Tx perspective where as the input from user is from Rx filter view.
2301 	 */
2302 	input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2303 	input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2304 	input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2305 	input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
2306 
2307 	if (ntohl(fsp->m_ext.data[1])) {
2308 		if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2309 			netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2310 			goto free_input;
2311 		}
2312 		vf_id = ntohl(fsp->h_ext.data[1]);
2313 		/* Find vsi id from vf id and override dest vsi */
2314 		input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2315 		if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2316 			netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2317 			goto free_input;
2318 		}
2319 	}
2320 
2321 	ret = i40e_add_del_fdir(vsi, input, true);
2322 free_input:
2323 	if (ret)
2324 		kfree(input);
2325 	else
2326 		i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
2327 
2328 	return ret;
2329 }
2330 
2331 /**
2332  * i40e_set_rxnfc - command to set RX flow classification rules
2333  * @netdev: network interface device structure
2334  * @cmd: ethtool rxnfc command
2335  *
2336  * Returns Success if the command is supported.
2337  **/
2338 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2339 {
2340 	struct i40e_netdev_priv *np = netdev_priv(netdev);
2341 	struct i40e_vsi *vsi = np->vsi;
2342 	struct i40e_pf *pf = vsi->back;
2343 	int ret = -EOPNOTSUPP;
2344 
2345 	switch (cmd->cmd) {
2346 	case ETHTOOL_SRXFH:
2347 		ret = i40e_set_rss_hash_opt(pf, cmd);
2348 		break;
2349 	case ETHTOOL_SRXCLSRLINS:
2350 		ret = i40e_add_fdir_ethtool(vsi, cmd);
2351 		break;
2352 	case ETHTOOL_SRXCLSRLDEL:
2353 		ret = i40e_del_fdir_entry(vsi, cmd);
2354 		break;
2355 	default:
2356 		break;
2357 	}
2358 
2359 	return ret;
2360 }
2361 
2362 /**
2363  * i40e_max_channels - get Max number of combined channels supported
2364  * @vsi: vsi pointer
2365  **/
2366 static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2367 {
2368 	/* TODO: This code assumes DCB and FD is disabled for now. */
2369 	return vsi->alloc_queue_pairs;
2370 }
2371 
2372 /**
2373  * i40e_get_channels - Get the current channels enabled and max supported etc.
2374  * @netdev: network interface device structure
2375  * @ch: ethtool channels structure
2376  *
2377  * We don't support separate tx and rx queues as channels. The other count
2378  * represents how many queues are being used for control. max_combined counts
2379  * how many queue pairs we can support. They may not be mapped 1 to 1 with
2380  * q_vectors since we support a lot more queue pairs than q_vectors.
2381  **/
2382 static void i40e_get_channels(struct net_device *dev,
2383 			       struct ethtool_channels *ch)
2384 {
2385 	struct i40e_netdev_priv *np = netdev_priv(dev);
2386 	struct i40e_vsi *vsi = np->vsi;
2387 	struct i40e_pf *pf = vsi->back;
2388 
2389 	/* report maximum channels */
2390 	ch->max_combined = i40e_max_channels(vsi);
2391 
2392 	/* report info for other vector */
2393 	ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
2394 	ch->max_other = ch->other_count;
2395 
2396 	/* Note: This code assumes DCB is disabled for now. */
2397 	ch->combined_count = vsi->num_queue_pairs;
2398 }
2399 
2400 /**
2401  * i40e_set_channels - Set the new channels count.
2402  * @netdev: network interface device structure
2403  * @ch: ethtool channels structure
2404  *
2405  * The new channels count may not be the same as requested by the user
2406  * since it gets rounded down to a power of 2 value.
2407  **/
2408 static int i40e_set_channels(struct net_device *dev,
2409 			      struct ethtool_channels *ch)
2410 {
2411 	struct i40e_netdev_priv *np = netdev_priv(dev);
2412 	unsigned int count = ch->combined_count;
2413 	struct i40e_vsi *vsi = np->vsi;
2414 	struct i40e_pf *pf = vsi->back;
2415 	int new_count;
2416 
2417 	/* We do not support setting channels for any other VSI at present */
2418 	if (vsi->type != I40E_VSI_MAIN)
2419 		return -EINVAL;
2420 
2421 	/* verify they are not requesting separate vectors */
2422 	if (!count || ch->rx_count || ch->tx_count)
2423 		return -EINVAL;
2424 
2425 	/* verify other_count has not changed */
2426 	if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
2427 		return -EINVAL;
2428 
2429 	/* verify the number of channels does not exceed hardware limits */
2430 	if (count > i40e_max_channels(vsi))
2431 		return -EINVAL;
2432 
2433 	/* update feature limits from largest to smallest supported values */
2434 	/* TODO: Flow director limit, DCB etc */
2435 
2436 	/* use rss_reconfig to rebuild with new queue count and update traffic
2437 	 * class queue mapping
2438 	 */
2439 	new_count = i40e_reconfig_rss_queues(pf, count);
2440 	if (new_count > 0)
2441 		return 0;
2442 	else
2443 		return -EINVAL;
2444 }
2445 
2446 #define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2447 /**
2448  * i40e_get_rxfh_key_size - get the RSS hash key size
2449  * @netdev: network interface device structure
2450  *
2451  * Returns the table size.
2452  **/
2453 static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2454 {
2455 	return I40E_HKEY_ARRAY_SIZE;
2456 }
2457 
2458 /**
2459  * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2460  * @netdev: network interface device structure
2461  *
2462  * Returns the table size.
2463  **/
2464 static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2465 {
2466 	return I40E_HLUT_ARRAY_SIZE;
2467 }
2468 
2469 static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2470 			 u8 *hfunc)
2471 {
2472 	struct i40e_netdev_priv *np = netdev_priv(netdev);
2473 	struct i40e_vsi *vsi = np->vsi;
2474 	struct i40e_pf *pf = vsi->back;
2475 	struct i40e_hw *hw = &pf->hw;
2476 	u32 reg_val;
2477 	int i, j;
2478 
2479 	if (hfunc)
2480 		*hfunc = ETH_RSS_HASH_TOP;
2481 
2482 	if (!indir)
2483 		return 0;
2484 
2485 	for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2486 		reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2487 		indir[j++] = reg_val & 0xff;
2488 		indir[j++] = (reg_val >> 8) & 0xff;
2489 		indir[j++] = (reg_val >> 16) & 0xff;
2490 		indir[j++] = (reg_val >> 24) & 0xff;
2491 	}
2492 
2493 	if (key) {
2494 		for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2495 			reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2496 			key[j++] = (u8)(reg_val & 0xff);
2497 			key[j++] = (u8)((reg_val >> 8) & 0xff);
2498 			key[j++] = (u8)((reg_val >> 16) & 0xff);
2499 			key[j++] = (u8)((reg_val >> 24) & 0xff);
2500 		}
2501 	}
2502 	return 0;
2503 }
2504 
2505 /**
2506  * i40e_set_rxfh - set the rx flow hash indirection table
2507  * @netdev: network interface device structure
2508  * @indir: indirection table
2509  * @key: hash key
2510  *
2511  * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
2512  * returns 0 after programming the table.
2513  **/
2514 static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2515 			 const u8 *key, const u8 hfunc)
2516 {
2517 	struct i40e_netdev_priv *np = netdev_priv(netdev);
2518 	struct i40e_vsi *vsi = np->vsi;
2519 	struct i40e_pf *pf = vsi->back;
2520 	struct i40e_hw *hw = &pf->hw;
2521 	u32 reg_val;
2522 	int i, j;
2523 
2524 	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2525 		return -EOPNOTSUPP;
2526 
2527 	if (!indir)
2528 		return 0;
2529 
2530 	for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2531 		reg_val = indir[j++];
2532 		reg_val |= indir[j++] << 8;
2533 		reg_val |= indir[j++] << 16;
2534 		reg_val |= indir[j++] << 24;
2535 		wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2536 	}
2537 
2538 	if (key) {
2539 		for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2540 			reg_val = key[j++];
2541 			reg_val |= key[j++] << 8;
2542 			reg_val |= key[j++] << 16;
2543 			reg_val |= key[j++] << 24;
2544 			wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2545 		}
2546 	}
2547 	return 0;
2548 }
2549 
2550 /**
2551  * i40e_get_priv_flags - report device private flags
2552  * @dev: network interface device structure
2553  *
2554  * The get string set count and the string set should be matched for each
2555  * flag returned.  Add new strings for each flag to the i40e_priv_flags_strings
2556  * array.
2557  *
2558  * Returns a u32 bitmap of flags.
2559  **/
2560 static u32 i40e_get_priv_flags(struct net_device *dev)
2561 {
2562 	struct i40e_netdev_priv *np = netdev_priv(dev);
2563 	struct i40e_vsi *vsi = np->vsi;
2564 	struct i40e_pf *pf = vsi->back;
2565 	u32 ret_flags = 0;
2566 
2567 	ret_flags |= pf->hw.func_caps.npar_enable ?
2568 		I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2569 
2570 	return ret_flags;
2571 }
2572 
2573 static const struct ethtool_ops i40e_ethtool_ops = {
2574 	.get_settings		= i40e_get_settings,
2575 	.set_settings		= i40e_set_settings,
2576 	.get_drvinfo		= i40e_get_drvinfo,
2577 	.get_regs_len		= i40e_get_regs_len,
2578 	.get_regs		= i40e_get_regs,
2579 	.nway_reset		= i40e_nway_reset,
2580 	.get_link		= ethtool_op_get_link,
2581 	.get_wol		= i40e_get_wol,
2582 	.set_wol		= i40e_set_wol,
2583 	.set_eeprom		= i40e_set_eeprom,
2584 	.get_eeprom_len		= i40e_get_eeprom_len,
2585 	.get_eeprom		= i40e_get_eeprom,
2586 	.get_ringparam		= i40e_get_ringparam,
2587 	.set_ringparam		= i40e_set_ringparam,
2588 	.get_pauseparam		= i40e_get_pauseparam,
2589 	.set_pauseparam		= i40e_set_pauseparam,
2590 	.get_msglevel		= i40e_get_msglevel,
2591 	.set_msglevel		= i40e_set_msglevel,
2592 	.get_rxnfc		= i40e_get_rxnfc,
2593 	.set_rxnfc		= i40e_set_rxnfc,
2594 	.self_test		= i40e_diag_test,
2595 	.get_strings		= i40e_get_strings,
2596 	.set_phys_id		= i40e_set_phys_id,
2597 	.get_sset_count		= i40e_get_sset_count,
2598 	.get_ethtool_stats	= i40e_get_ethtool_stats,
2599 	.get_coalesce		= i40e_get_coalesce,
2600 	.set_coalesce		= i40e_set_coalesce,
2601 	.get_rxfh_key_size	= i40e_get_rxfh_key_size,
2602 	.get_rxfh_indir_size	= i40e_get_rxfh_indir_size,
2603 	.get_rxfh		= i40e_get_rxfh,
2604 	.set_rxfh		= i40e_set_rxfh,
2605 	.get_channels		= i40e_get_channels,
2606 	.set_channels		= i40e_set_channels,
2607 	.get_ts_info		= i40e_get_ts_info,
2608 	.get_priv_flags		= i40e_get_priv_flags,
2609 };
2610 
2611 void i40e_set_ethtool_ops(struct net_device *netdev)
2612 {
2613 	netdev->ethtool_ops = &i40e_ethtool_ops;
2614 }
2615