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