xref: /openbmc/linux/drivers/net/ethernet/qlogic/qede/qede_ethtool.c (revision c64d01b3ceba873aa8e8605598cec4a6bc6d1601)
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 /* QLogic qede NIC Driver
3  * Copyright (c) 2015-2017  QLogic Corporation
4  * Copyright (c) 2019-2020 Marvell International Ltd.
5  */
6 
7 #include <linux/version.h>
8 #include <linux/types.h>
9 #include <linux/netdevice.h>
10 #include <linux/etherdevice.h>
11 #include <linux/ethtool.h>
12 #include <linux/string.h>
13 #include <linux/pci.h>
14 #include <linux/capability.h>
15 #include <linux/vmalloc.h>
16 #include <linux/phylink.h>
17 
18 #include "qede.h"
19 #include "qede_ptp.h"
20 
21 #define QEDE_RQSTAT_OFFSET(stat_name) \
22 	 (offsetof(struct qede_rx_queue, stat_name))
23 #define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
24 #define QEDE_RQSTAT(stat_name) \
25 	 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
26 
27 #define QEDE_SELFTEST_POLL_COUNT 100
28 #define QEDE_DUMP_VERSION	0x1
29 #define QEDE_DUMP_NVM_ARG_COUNT	2
30 
31 static const struct {
32 	u64 offset;
33 	char string[ETH_GSTRING_LEN];
34 } qede_rqstats_arr[] = {
35 	QEDE_RQSTAT(rcv_pkts),
36 	QEDE_RQSTAT(rx_hw_errors),
37 	QEDE_RQSTAT(rx_alloc_errors),
38 	QEDE_RQSTAT(rx_ip_frags),
39 	QEDE_RQSTAT(xdp_no_pass),
40 };
41 
42 #define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
43 #define QEDE_TQSTAT_OFFSET(stat_name) \
44 	(offsetof(struct qede_tx_queue, stat_name))
45 #define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
46 #define QEDE_TQSTAT(stat_name) \
47 	{QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
48 #define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
49 static const struct {
50 	u64 offset;
51 	char string[ETH_GSTRING_LEN];
52 } qede_tqstats_arr[] = {
53 	QEDE_TQSTAT(xmit_pkts),
54 	QEDE_TQSTAT(stopped_cnt),
55 	QEDE_TQSTAT(tx_mem_alloc_err),
56 };
57 
58 #define QEDE_STAT_OFFSET(stat_name, type, base) \
59 	(offsetof(type, stat_name) + (base))
60 #define QEDE_STAT_STRING(stat_name)	(#stat_name)
61 #define _QEDE_STAT(stat_name, type, base, attr) \
62 	{QEDE_STAT_OFFSET(stat_name, type, base), \
63 	 QEDE_STAT_STRING(stat_name), \
64 	 attr}
65 #define QEDE_STAT(stat_name) \
66 	_QEDE_STAT(stat_name, struct qede_stats_common, 0, 0x0)
67 #define QEDE_PF_STAT(stat_name) \
68 	_QEDE_STAT(stat_name, struct qede_stats_common, 0, \
69 		   BIT(QEDE_STAT_PF_ONLY))
70 #define QEDE_PF_BB_STAT(stat_name) \
71 	_QEDE_STAT(stat_name, struct qede_stats_bb, \
72 		   offsetof(struct qede_stats, bb), \
73 		   BIT(QEDE_STAT_PF_ONLY) | BIT(QEDE_STAT_BB_ONLY))
74 #define QEDE_PF_AH_STAT(stat_name) \
75 	_QEDE_STAT(stat_name, struct qede_stats_ah, \
76 		   offsetof(struct qede_stats, ah), \
77 		   BIT(QEDE_STAT_PF_ONLY) | BIT(QEDE_STAT_AH_ONLY))
78 static const struct {
79 	u64 offset;
80 	char string[ETH_GSTRING_LEN];
81 	unsigned long attr;
82 #define QEDE_STAT_PF_ONLY	0
83 #define QEDE_STAT_BB_ONLY	1
84 #define QEDE_STAT_AH_ONLY	2
85 } qede_stats_arr[] = {
86 	QEDE_STAT(rx_ucast_bytes),
87 	QEDE_STAT(rx_mcast_bytes),
88 	QEDE_STAT(rx_bcast_bytes),
89 	QEDE_STAT(rx_ucast_pkts),
90 	QEDE_STAT(rx_mcast_pkts),
91 	QEDE_STAT(rx_bcast_pkts),
92 
93 	QEDE_STAT(tx_ucast_bytes),
94 	QEDE_STAT(tx_mcast_bytes),
95 	QEDE_STAT(tx_bcast_bytes),
96 	QEDE_STAT(tx_ucast_pkts),
97 	QEDE_STAT(tx_mcast_pkts),
98 	QEDE_STAT(tx_bcast_pkts),
99 
100 	QEDE_PF_STAT(rx_64_byte_packets),
101 	QEDE_PF_STAT(rx_65_to_127_byte_packets),
102 	QEDE_PF_STAT(rx_128_to_255_byte_packets),
103 	QEDE_PF_STAT(rx_256_to_511_byte_packets),
104 	QEDE_PF_STAT(rx_512_to_1023_byte_packets),
105 	QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
106 	QEDE_PF_BB_STAT(rx_1519_to_1522_byte_packets),
107 	QEDE_PF_BB_STAT(rx_1519_to_2047_byte_packets),
108 	QEDE_PF_BB_STAT(rx_2048_to_4095_byte_packets),
109 	QEDE_PF_BB_STAT(rx_4096_to_9216_byte_packets),
110 	QEDE_PF_BB_STAT(rx_9217_to_16383_byte_packets),
111 	QEDE_PF_AH_STAT(rx_1519_to_max_byte_packets),
112 	QEDE_PF_STAT(tx_64_byte_packets),
113 	QEDE_PF_STAT(tx_65_to_127_byte_packets),
114 	QEDE_PF_STAT(tx_128_to_255_byte_packets),
115 	QEDE_PF_STAT(tx_256_to_511_byte_packets),
116 	QEDE_PF_STAT(tx_512_to_1023_byte_packets),
117 	QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
118 	QEDE_PF_BB_STAT(tx_1519_to_2047_byte_packets),
119 	QEDE_PF_BB_STAT(tx_2048_to_4095_byte_packets),
120 	QEDE_PF_BB_STAT(tx_4096_to_9216_byte_packets),
121 	QEDE_PF_BB_STAT(tx_9217_to_16383_byte_packets),
122 	QEDE_PF_AH_STAT(tx_1519_to_max_byte_packets),
123 	QEDE_PF_STAT(rx_mac_crtl_frames),
124 	QEDE_PF_STAT(tx_mac_ctrl_frames),
125 	QEDE_PF_STAT(rx_pause_frames),
126 	QEDE_PF_STAT(tx_pause_frames),
127 	QEDE_PF_STAT(rx_pfc_frames),
128 	QEDE_PF_STAT(tx_pfc_frames),
129 
130 	QEDE_PF_STAT(rx_crc_errors),
131 	QEDE_PF_STAT(rx_align_errors),
132 	QEDE_PF_STAT(rx_carrier_errors),
133 	QEDE_PF_STAT(rx_oversize_packets),
134 	QEDE_PF_STAT(rx_jabbers),
135 	QEDE_PF_STAT(rx_undersize_packets),
136 	QEDE_PF_STAT(rx_fragments),
137 	QEDE_PF_BB_STAT(tx_lpi_entry_count),
138 	QEDE_PF_BB_STAT(tx_total_collisions),
139 	QEDE_PF_STAT(brb_truncates),
140 	QEDE_PF_STAT(brb_discards),
141 	QEDE_STAT(no_buff_discards),
142 	QEDE_PF_STAT(mftag_filter_discards),
143 	QEDE_PF_STAT(mac_filter_discards),
144 	QEDE_PF_STAT(gft_filter_drop),
145 	QEDE_STAT(tx_err_drop_pkts),
146 	QEDE_STAT(ttl0_discard),
147 	QEDE_STAT(packet_too_big_discard),
148 
149 	QEDE_STAT(coalesced_pkts),
150 	QEDE_STAT(coalesced_events),
151 	QEDE_STAT(coalesced_aborts_num),
152 	QEDE_STAT(non_coalesced_pkts),
153 	QEDE_STAT(coalesced_bytes),
154 
155 	QEDE_STAT(link_change_count),
156 	QEDE_STAT(ptp_skip_txts),
157 };
158 
159 #define QEDE_NUM_STATS	ARRAY_SIZE(qede_stats_arr)
160 #define QEDE_STAT_IS_PF_ONLY(i) \
161 	test_bit(QEDE_STAT_PF_ONLY, &qede_stats_arr[i].attr)
162 #define QEDE_STAT_IS_BB_ONLY(i) \
163 	test_bit(QEDE_STAT_BB_ONLY, &qede_stats_arr[i].attr)
164 #define QEDE_STAT_IS_AH_ONLY(i) \
165 	test_bit(QEDE_STAT_AH_ONLY, &qede_stats_arr[i].attr)
166 
167 enum {
168 	QEDE_PRI_FLAG_CMT,
169 	QEDE_PRI_FLAG_SMART_AN_SUPPORT, /* MFW supports SmartAN */
170 	QEDE_PRI_FLAG_RECOVER_ON_ERROR,
171 	QEDE_PRI_FLAG_LEN,
172 };
173 
174 static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
175 	"Coupled-Function",
176 	"SmartAN capable",
177 	"Recover on error",
178 };
179 
180 enum qede_ethtool_tests {
181 	QEDE_ETHTOOL_INT_LOOPBACK,
182 	QEDE_ETHTOOL_INTERRUPT_TEST,
183 	QEDE_ETHTOOL_MEMORY_TEST,
184 	QEDE_ETHTOOL_REGISTER_TEST,
185 	QEDE_ETHTOOL_CLOCK_TEST,
186 	QEDE_ETHTOOL_NVRAM_TEST,
187 	QEDE_ETHTOOL_TEST_MAX
188 };
189 
190 static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
191 	"Internal loopback (offline)",
192 	"Interrupt (online)\t",
193 	"Memory (online)\t\t",
194 	"Register (online)\t",
195 	"Clock (online)\t\t",
196 	"Nvram (online)\t\t",
197 };
198 
199 /* Forced speed capabilities maps */
200 
201 struct qede_forced_speed_map {
202 	u32		speed;
203 	__ETHTOOL_DECLARE_LINK_MODE_MASK(caps);
204 
205 	const u32	*cap_arr;
206 	u32		arr_size;
207 };
208 
209 #define QEDE_FORCED_SPEED_MAP(value)					\
210 {									\
211 	.speed		= SPEED_##value,				\
212 	.cap_arr	= qede_forced_speed_##value,			\
213 	.arr_size	= ARRAY_SIZE(qede_forced_speed_##value),	\
214 }
215 
216 static const u32 qede_forced_speed_1000[] __initconst = {
217 	ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
218 	ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
219 	ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
220 };
221 
222 static const u32 qede_forced_speed_10000[] __initconst = {
223 	ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
224 	ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
225 	ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
226 	ETHTOOL_LINK_MODE_10000baseR_FEC_BIT,
227 	ETHTOOL_LINK_MODE_10000baseCR_Full_BIT,
228 	ETHTOOL_LINK_MODE_10000baseSR_Full_BIT,
229 	ETHTOOL_LINK_MODE_10000baseLR_Full_BIT,
230 	ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT,
231 };
232 
233 static const u32 qede_forced_speed_20000[] __initconst = {
234 	ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT,
235 };
236 
237 static const u32 qede_forced_speed_25000[] __initconst = {
238 	ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
239 	ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
240 	ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
241 };
242 
243 static const u32 qede_forced_speed_40000[] __initconst = {
244 	ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT,
245 	ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT,
246 	ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
247 	ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT,
248 };
249 
250 static const u32 qede_forced_speed_50000[] __initconst = {
251 	ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT,
252 	ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT,
253 	ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT,
254 };
255 
256 static const u32 qede_forced_speed_100000[] __initconst = {
257 	ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
258 	ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT,
259 	ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
260 	ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT,
261 };
262 
263 static struct qede_forced_speed_map qede_forced_speed_maps[] __ro_after_init = {
264 	QEDE_FORCED_SPEED_MAP(1000),
265 	QEDE_FORCED_SPEED_MAP(10000),
266 	QEDE_FORCED_SPEED_MAP(20000),
267 	QEDE_FORCED_SPEED_MAP(25000),
268 	QEDE_FORCED_SPEED_MAP(40000),
269 	QEDE_FORCED_SPEED_MAP(50000),
270 	QEDE_FORCED_SPEED_MAP(100000),
271 };
272 
273 void __init qede_forced_speed_maps_init(void)
274 {
275 	struct qede_forced_speed_map *map;
276 	u32 i;
277 
278 	for (i = 0; i < ARRAY_SIZE(qede_forced_speed_maps); i++) {
279 		map = qede_forced_speed_maps + i;
280 
281 		linkmode_set_bit_array(map->cap_arr, map->arr_size, map->caps);
282 		map->cap_arr = NULL;
283 		map->arr_size = 0;
284 	}
285 }
286 
287 /* Ethtool callbacks */
288 
289 static void qede_get_strings_stats_txq(struct qede_dev *edev,
290 				       struct qede_tx_queue *txq, u8 **buf)
291 {
292 	int i;
293 
294 	for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
295 		if (txq->is_xdp)
296 			sprintf(*buf, "%d [XDP]: %s",
297 				QEDE_TXQ_XDP_TO_IDX(edev, txq),
298 				qede_tqstats_arr[i].string);
299 		else
300 			sprintf(*buf, "%d_%d: %s", txq->index, txq->cos,
301 				qede_tqstats_arr[i].string);
302 		*buf += ETH_GSTRING_LEN;
303 	}
304 }
305 
306 static void qede_get_strings_stats_rxq(struct qede_dev *edev,
307 				       struct qede_rx_queue *rxq, u8 **buf)
308 {
309 	int i;
310 
311 	for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
312 		sprintf(*buf, "%d: %s", rxq->rxq_id,
313 			qede_rqstats_arr[i].string);
314 		*buf += ETH_GSTRING_LEN;
315 	}
316 }
317 
318 static bool qede_is_irrelevant_stat(struct qede_dev *edev, int stat_index)
319 {
320 	return (IS_VF(edev) && QEDE_STAT_IS_PF_ONLY(stat_index)) ||
321 	       (QEDE_IS_BB(edev) && QEDE_STAT_IS_AH_ONLY(stat_index)) ||
322 	       (QEDE_IS_AH(edev) && QEDE_STAT_IS_BB_ONLY(stat_index));
323 }
324 
325 static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
326 {
327 	struct qede_fastpath *fp;
328 	int i;
329 
330 	/* Account for queue statistics */
331 	for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
332 		fp = &edev->fp_array[i];
333 
334 		if (fp->type & QEDE_FASTPATH_RX)
335 			qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
336 
337 		if (fp->type & QEDE_FASTPATH_XDP)
338 			qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf);
339 
340 		if (fp->type & QEDE_FASTPATH_TX) {
341 			int cos;
342 
343 			for_each_cos_in_txq(edev, cos)
344 				qede_get_strings_stats_txq(edev,
345 							   &fp->txq[cos], &buf);
346 		}
347 	}
348 
349 	/* Account for non-queue statistics */
350 	for (i = 0; i < QEDE_NUM_STATS; i++) {
351 		if (qede_is_irrelevant_stat(edev, i))
352 			continue;
353 		strcpy(buf, qede_stats_arr[i].string);
354 		buf += ETH_GSTRING_LEN;
355 	}
356 }
357 
358 static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
359 {
360 	struct qede_dev *edev = netdev_priv(dev);
361 
362 	switch (stringset) {
363 	case ETH_SS_STATS:
364 		qede_get_strings_stats(edev, buf);
365 		break;
366 	case ETH_SS_PRIV_FLAGS:
367 		memcpy(buf, qede_private_arr,
368 		       ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
369 		break;
370 	case ETH_SS_TEST:
371 		memcpy(buf, qede_tests_str_arr,
372 		       ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
373 		break;
374 	default:
375 		DP_VERBOSE(edev, QED_MSG_DEBUG,
376 			   "Unsupported stringset 0x%08x\n", stringset);
377 	}
378 }
379 
380 static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
381 {
382 	int i;
383 
384 	for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
385 		**buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
386 		(*buf)++;
387 	}
388 }
389 
390 static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
391 {
392 	int i;
393 
394 	for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
395 		**buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
396 		(*buf)++;
397 	}
398 }
399 
400 static void qede_get_ethtool_stats(struct net_device *dev,
401 				   struct ethtool_stats *stats, u64 *buf)
402 {
403 	struct qede_dev *edev = netdev_priv(dev);
404 	struct qede_fastpath *fp;
405 	int i;
406 
407 	qede_fill_by_demand_stats(edev);
408 
409 	/* Need to protect the access to the fastpath array */
410 	__qede_lock(edev);
411 
412 	for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
413 		fp = &edev->fp_array[i];
414 
415 		if (fp->type & QEDE_FASTPATH_RX)
416 			qede_get_ethtool_stats_rxq(fp->rxq, &buf);
417 
418 		if (fp->type & QEDE_FASTPATH_XDP)
419 			qede_get_ethtool_stats_txq(fp->xdp_tx, &buf);
420 
421 		if (fp->type & QEDE_FASTPATH_TX) {
422 			int cos;
423 
424 			for_each_cos_in_txq(edev, cos)
425 				qede_get_ethtool_stats_txq(&fp->txq[cos], &buf);
426 		}
427 	}
428 
429 	for (i = 0; i < QEDE_NUM_STATS; i++) {
430 		if (qede_is_irrelevant_stat(edev, i))
431 			continue;
432 		*buf = *((u64 *)(((void *)&edev->stats) +
433 				 qede_stats_arr[i].offset));
434 
435 		buf++;
436 	}
437 
438 	__qede_unlock(edev);
439 }
440 
441 static int qede_get_sset_count(struct net_device *dev, int stringset)
442 {
443 	struct qede_dev *edev = netdev_priv(dev);
444 	int num_stats = QEDE_NUM_STATS, i;
445 
446 	switch (stringset) {
447 	case ETH_SS_STATS:
448 		for (i = 0; i < QEDE_NUM_STATS; i++)
449 			if (qede_is_irrelevant_stat(edev, i))
450 				num_stats--;
451 
452 		/* Account for the Regular Tx statistics */
453 		num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS *
454 				edev->dev_info.num_tc;
455 
456 		/* Account for the Regular Rx statistics */
457 		num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
458 
459 		/* Account for XDP statistics [if needed] */
460 		if (edev->xdp_prog)
461 			num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS;
462 		return num_stats;
463 
464 	case ETH_SS_PRIV_FLAGS:
465 		return QEDE_PRI_FLAG_LEN;
466 	case ETH_SS_TEST:
467 		if (!IS_VF(edev))
468 			return QEDE_ETHTOOL_TEST_MAX;
469 		else
470 			return 0;
471 	default:
472 		DP_VERBOSE(edev, QED_MSG_DEBUG,
473 			   "Unsupported stringset 0x%08x\n", stringset);
474 		return -EINVAL;
475 	}
476 }
477 
478 static u32 qede_get_priv_flags(struct net_device *dev)
479 {
480 	struct qede_dev *edev = netdev_priv(dev);
481 	u32 flags = 0;
482 
483 	if (edev->dev_info.common.num_hwfns > 1)
484 		flags |= BIT(QEDE_PRI_FLAG_CMT);
485 
486 	if (edev->dev_info.common.smart_an)
487 		flags |= BIT(QEDE_PRI_FLAG_SMART_AN_SUPPORT);
488 
489 	if (edev->err_flags & BIT(QEDE_ERR_IS_RECOVERABLE))
490 		flags |= BIT(QEDE_PRI_FLAG_RECOVER_ON_ERROR);
491 
492 	return flags;
493 }
494 
495 static int qede_set_priv_flags(struct net_device *dev, u32 flags)
496 {
497 	struct qede_dev *edev = netdev_priv(dev);
498 	u32 cflags = qede_get_priv_flags(dev);
499 	u32 dflags = flags ^ cflags;
500 
501 	/* can only change RECOVER_ON_ERROR flag */
502 	if (dflags & ~BIT(QEDE_PRI_FLAG_RECOVER_ON_ERROR))
503 		return -EINVAL;
504 
505 	if (flags & BIT(QEDE_PRI_FLAG_RECOVER_ON_ERROR))
506 		set_bit(QEDE_ERR_IS_RECOVERABLE, &edev->err_flags);
507 	else
508 		clear_bit(QEDE_ERR_IS_RECOVERABLE, &edev->err_flags);
509 
510 	return 0;
511 }
512 
513 static int qede_get_link_ksettings(struct net_device *dev,
514 				   struct ethtool_link_ksettings *cmd)
515 {
516 	typeof(cmd->link_modes) *link_modes = &cmd->link_modes;
517 	struct ethtool_link_settings *base = &cmd->base;
518 	struct qede_dev *edev = netdev_priv(dev);
519 	struct qed_link_output current_link;
520 
521 	__qede_lock(edev);
522 
523 	memset(&current_link, 0, sizeof(current_link));
524 	edev->ops->common->get_link(edev->cdev, &current_link);
525 
526 	linkmode_copy(link_modes->supported, current_link.supported_caps);
527 	linkmode_copy(link_modes->advertising, current_link.advertised_caps);
528 	linkmode_copy(link_modes->lp_advertising, current_link.lp_caps);
529 
530 	if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
531 		base->speed = current_link.speed;
532 		base->duplex = current_link.duplex;
533 	} else {
534 		base->speed = SPEED_UNKNOWN;
535 		base->duplex = DUPLEX_UNKNOWN;
536 	}
537 
538 	__qede_unlock(edev);
539 
540 	base->port = current_link.port;
541 	base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
542 			AUTONEG_DISABLE;
543 
544 	return 0;
545 }
546 
547 static int qede_set_link_ksettings(struct net_device *dev,
548 				   const struct ethtool_link_ksettings *cmd)
549 {
550 	const struct ethtool_link_settings *base = &cmd->base;
551 	struct qede_dev *edev = netdev_priv(dev);
552 	const struct qede_forced_speed_map *map;
553 	struct qed_link_output current_link;
554 	struct qed_link_params params;
555 	u32 i;
556 
557 	if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
558 		DP_INFO(edev, "Link settings are not allowed to be changed\n");
559 		return -EOPNOTSUPP;
560 	}
561 	memset(&current_link, 0, sizeof(current_link));
562 	memset(&params, 0, sizeof(params));
563 	edev->ops->common->get_link(edev->cdev, &current_link);
564 
565 	params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
566 	params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
567 
568 	if (base->autoneg == AUTONEG_ENABLE) {
569 		if (!phylink_test(current_link.supported_caps, Autoneg)) {
570 			DP_INFO(edev, "Auto negotiation is not supported\n");
571 			return -EOPNOTSUPP;
572 		}
573 
574 		params.autoneg = true;
575 		params.forced_speed = 0;
576 
577 		linkmode_copy(params.adv_speeds, cmd->link_modes.advertising);
578 	} else {		/* forced speed */
579 		params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
580 		params.autoneg = false;
581 		params.forced_speed = base->speed;
582 
583 		for (i = 0; i < ARRAY_SIZE(qede_forced_speed_maps); i++) {
584 			map = qede_forced_speed_maps + i;
585 
586 			if (base->speed != map->speed ||
587 			    !linkmode_intersects(current_link.supported_caps,
588 						 map->caps))
589 				continue;
590 
591 			linkmode_and(params.adv_speeds,
592 				     current_link.supported_caps, map->caps);
593 			goto set_link;
594 		}
595 
596 		DP_INFO(edev, "Unsupported speed %u\n", base->speed);
597 		return -EINVAL;
598 	}
599 
600 set_link:
601 	params.link_up = true;
602 	edev->ops->common->set_link(edev->cdev, &params);
603 
604 	return 0;
605 }
606 
607 static void qede_get_drvinfo(struct net_device *ndev,
608 			     struct ethtool_drvinfo *info)
609 {
610 	char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
611 	struct qede_dev *edev = netdev_priv(ndev);
612 	char mbi[ETHTOOL_FWVERS_LEN];
613 
614 	strlcpy(info->driver, "qede", sizeof(info->driver));
615 
616 	snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
617 		 edev->dev_info.common.fw_major,
618 		 edev->dev_info.common.fw_minor,
619 		 edev->dev_info.common.fw_rev,
620 		 edev->dev_info.common.fw_eng);
621 
622 	snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
623 		 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
624 		 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
625 		 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
626 		 edev->dev_info.common.mfw_rev & 0xFF);
627 
628 	if ((strlen(storm) + strlen("[storm]")) <
629 	    sizeof(info->version))
630 		snprintf(info->version, sizeof(info->version),
631 			 "[storm %s]", storm);
632 	else
633 		snprintf(info->version, sizeof(info->version),
634 			 "%s", storm);
635 
636 	if (edev->dev_info.common.mbi_version) {
637 		snprintf(mbi, ETHTOOL_FWVERS_LEN, "%d.%d.%d",
638 			 (edev->dev_info.common.mbi_version &
639 			  QED_MBI_VERSION_2_MASK) >> QED_MBI_VERSION_2_OFFSET,
640 			 (edev->dev_info.common.mbi_version &
641 			  QED_MBI_VERSION_1_MASK) >> QED_MBI_VERSION_1_OFFSET,
642 			 (edev->dev_info.common.mbi_version &
643 			  QED_MBI_VERSION_0_MASK) >> QED_MBI_VERSION_0_OFFSET);
644 		snprintf(info->fw_version, sizeof(info->fw_version),
645 			 "mbi %s [mfw %s]", mbi, mfw);
646 	} else {
647 		snprintf(info->fw_version, sizeof(info->fw_version),
648 			 "mfw %s", mfw);
649 	}
650 
651 	strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
652 }
653 
654 static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
655 {
656 	struct qede_dev *edev = netdev_priv(ndev);
657 
658 	if (edev->dev_info.common.wol_support) {
659 		wol->supported = WAKE_MAGIC;
660 		wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
661 	}
662 }
663 
664 static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
665 {
666 	struct qede_dev *edev = netdev_priv(ndev);
667 	bool wol_requested;
668 	int rc;
669 
670 	if (wol->wolopts & ~WAKE_MAGIC) {
671 		DP_INFO(edev,
672 			"Can't support WoL options other than magic-packet\n");
673 		return -EINVAL;
674 	}
675 
676 	wol_requested = !!(wol->wolopts & WAKE_MAGIC);
677 	if (wol_requested == edev->wol_enabled)
678 		return 0;
679 
680 	/* Need to actually change configuration */
681 	if (!edev->dev_info.common.wol_support) {
682 		DP_INFO(edev, "Device doesn't support WoL\n");
683 		return -EINVAL;
684 	}
685 
686 	rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
687 	if (!rc)
688 		edev->wol_enabled = wol_requested;
689 
690 	return rc;
691 }
692 
693 static u32 qede_get_msglevel(struct net_device *ndev)
694 {
695 	struct qede_dev *edev = netdev_priv(ndev);
696 
697 	return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
698 }
699 
700 static void qede_set_msglevel(struct net_device *ndev, u32 level)
701 {
702 	struct qede_dev *edev = netdev_priv(ndev);
703 	u32 dp_module = 0;
704 	u8 dp_level = 0;
705 
706 	qede_config_debug(level, &dp_module, &dp_level);
707 
708 	edev->dp_level = dp_level;
709 	edev->dp_module = dp_module;
710 	edev->ops->common->update_msglvl(edev->cdev,
711 					 dp_module, dp_level);
712 }
713 
714 static int qede_nway_reset(struct net_device *dev)
715 {
716 	struct qede_dev *edev = netdev_priv(dev);
717 	struct qed_link_output current_link;
718 	struct qed_link_params link_params;
719 
720 	if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
721 		DP_INFO(edev, "Link settings are not allowed to be changed\n");
722 		return -EOPNOTSUPP;
723 	}
724 
725 	if (!netif_running(dev))
726 		return 0;
727 
728 	memset(&current_link, 0, sizeof(current_link));
729 	edev->ops->common->get_link(edev->cdev, &current_link);
730 	if (!current_link.link_up)
731 		return 0;
732 
733 	/* Toggle the link */
734 	memset(&link_params, 0, sizeof(link_params));
735 	link_params.link_up = false;
736 	edev->ops->common->set_link(edev->cdev, &link_params);
737 	link_params.link_up = true;
738 	edev->ops->common->set_link(edev->cdev, &link_params);
739 
740 	return 0;
741 }
742 
743 static u32 qede_get_link(struct net_device *dev)
744 {
745 	struct qede_dev *edev = netdev_priv(dev);
746 	struct qed_link_output current_link;
747 
748 	memset(&current_link, 0, sizeof(current_link));
749 	edev->ops->common->get_link(edev->cdev, &current_link);
750 
751 	return current_link.link_up;
752 }
753 
754 static int qede_flash_device(struct net_device *dev,
755 			     struct ethtool_flash *flash)
756 {
757 	struct qede_dev *edev = netdev_priv(dev);
758 
759 	return edev->ops->common->nvm_flash(edev->cdev, flash->data);
760 }
761 
762 static int qede_get_coalesce(struct net_device *dev,
763 			     struct ethtool_coalesce *coal,
764 			     struct kernel_ethtool_coalesce *kernel_coal,
765 			     struct netlink_ext_ack *extack)
766 {
767 	void *rx_handle = NULL, *tx_handle = NULL;
768 	struct qede_dev *edev = netdev_priv(dev);
769 	u16 rx_coal, tx_coal, i, rc = 0;
770 	struct qede_fastpath *fp;
771 
772 	rx_coal = QED_DEFAULT_RX_USECS;
773 	tx_coal = QED_DEFAULT_TX_USECS;
774 
775 	memset(coal, 0, sizeof(struct ethtool_coalesce));
776 
777 	__qede_lock(edev);
778 	if (edev->state == QEDE_STATE_OPEN) {
779 		for_each_queue(i) {
780 			fp = &edev->fp_array[i];
781 
782 			if (fp->type & QEDE_FASTPATH_RX) {
783 				rx_handle = fp->rxq->handle;
784 				break;
785 			}
786 		}
787 
788 		rc = edev->ops->get_coalesce(edev->cdev, &rx_coal, rx_handle);
789 		if (rc) {
790 			DP_INFO(edev, "Read Rx coalesce error\n");
791 			goto out;
792 		}
793 
794 		for_each_queue(i) {
795 			struct qede_tx_queue *txq;
796 
797 			fp = &edev->fp_array[i];
798 
799 			/* All TX queues of given fastpath uses same
800 			 * coalescing value, so no need to iterate over
801 			 * all TCs, TC0 txq should suffice.
802 			 */
803 			if (fp->type & QEDE_FASTPATH_TX) {
804 				txq = QEDE_FP_TC0_TXQ(fp);
805 				tx_handle = txq->handle;
806 				break;
807 			}
808 		}
809 
810 		rc = edev->ops->get_coalesce(edev->cdev, &tx_coal, tx_handle);
811 		if (rc)
812 			DP_INFO(edev, "Read Tx coalesce error\n");
813 	}
814 
815 out:
816 	__qede_unlock(edev);
817 
818 	coal->rx_coalesce_usecs = rx_coal;
819 	coal->tx_coalesce_usecs = tx_coal;
820 
821 	return rc;
822 }
823 
824 int qede_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal,
825 		      struct kernel_ethtool_coalesce *kernel_coal,
826 		      struct netlink_ext_ack *extack)
827 {
828 	struct qede_dev *edev = netdev_priv(dev);
829 	struct qede_fastpath *fp;
830 	int i, rc = 0;
831 	u16 rxc, txc;
832 
833 	if (!netif_running(dev)) {
834 		DP_INFO(edev, "Interface is down\n");
835 		return -EINVAL;
836 	}
837 
838 	if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
839 	    coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
840 		DP_INFO(edev,
841 			"Can't support requested %s coalesce value [max supported value %d]\n",
842 			coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx" :
843 			"tx", QED_COALESCE_MAX);
844 		return -EINVAL;
845 	}
846 
847 	rxc = (u16)coal->rx_coalesce_usecs;
848 	txc = (u16)coal->tx_coalesce_usecs;
849 	for_each_queue(i) {
850 		fp = &edev->fp_array[i];
851 
852 		if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
853 			rc = edev->ops->common->set_coalesce(edev->cdev,
854 							     rxc, 0,
855 							     fp->rxq->handle);
856 			if (rc) {
857 				DP_INFO(edev,
858 					"Set RX coalesce error, rc = %d\n", rc);
859 				return rc;
860 			}
861 			edev->coal_entry[i].rxc = rxc;
862 			edev->coal_entry[i].isvalid = true;
863 		}
864 
865 		if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
866 			struct qede_tx_queue *txq;
867 
868 			/* All TX queues of given fastpath uses same
869 			 * coalescing value, so no need to iterate over
870 			 * all TCs, TC0 txq should suffice.
871 			 */
872 			txq = QEDE_FP_TC0_TXQ(fp);
873 
874 			rc = edev->ops->common->set_coalesce(edev->cdev,
875 							     0, txc,
876 							     txq->handle);
877 			if (rc) {
878 				DP_INFO(edev,
879 					"Set TX coalesce error, rc = %d\n", rc);
880 				return rc;
881 			}
882 			edev->coal_entry[i].txc = txc;
883 			edev->coal_entry[i].isvalid = true;
884 		}
885 	}
886 
887 	return rc;
888 }
889 
890 static void qede_get_ringparam(struct net_device *dev,
891 			       struct ethtool_ringparam *ering,
892 			       struct kernel_ethtool_ringparam *kernel_ering,
893 			       struct netlink_ext_ack *extack)
894 {
895 	struct qede_dev *edev = netdev_priv(dev);
896 
897 	ering->rx_max_pending = NUM_RX_BDS_MAX;
898 	ering->rx_pending = edev->q_num_rx_buffers;
899 	ering->tx_max_pending = NUM_TX_BDS_MAX;
900 	ering->tx_pending = edev->q_num_tx_buffers;
901 }
902 
903 static int qede_set_ringparam(struct net_device *dev,
904 			      struct ethtool_ringparam *ering,
905 			      struct kernel_ethtool_ringparam *kernel_ering,
906 			      struct netlink_ext_ack *extack)
907 {
908 	struct qede_dev *edev = netdev_priv(dev);
909 
910 	DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
911 		   "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
912 		   ering->rx_pending, ering->tx_pending);
913 
914 	/* Validate legality of configuration */
915 	if (ering->rx_pending > NUM_RX_BDS_MAX ||
916 	    ering->rx_pending < NUM_RX_BDS_MIN ||
917 	    ering->tx_pending > NUM_TX_BDS_MAX ||
918 	    ering->tx_pending < NUM_TX_BDS_MIN) {
919 		DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
920 			   "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
921 			   NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
922 			   NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
923 		return -EINVAL;
924 	}
925 
926 	/* Change ring size and re-load */
927 	edev->q_num_rx_buffers = ering->rx_pending;
928 	edev->q_num_tx_buffers = ering->tx_pending;
929 
930 	qede_reload(edev, NULL, false);
931 
932 	return 0;
933 }
934 
935 static void qede_get_pauseparam(struct net_device *dev,
936 				struct ethtool_pauseparam *epause)
937 {
938 	struct qede_dev *edev = netdev_priv(dev);
939 	struct qed_link_output current_link;
940 
941 	memset(&current_link, 0, sizeof(current_link));
942 	edev->ops->common->get_link(edev->cdev, &current_link);
943 
944 	if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
945 		epause->autoneg = true;
946 	if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
947 		epause->rx_pause = true;
948 	if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
949 		epause->tx_pause = true;
950 
951 	DP_VERBOSE(edev, QED_MSG_DEBUG,
952 		   "ethtool_pauseparam: cmd %d  autoneg %d  rx_pause %d  tx_pause %d\n",
953 		   epause->cmd, epause->autoneg, epause->rx_pause,
954 		   epause->tx_pause);
955 }
956 
957 static int qede_set_pauseparam(struct net_device *dev,
958 			       struct ethtool_pauseparam *epause)
959 {
960 	struct qede_dev *edev = netdev_priv(dev);
961 	struct qed_link_params params;
962 	struct qed_link_output current_link;
963 
964 	if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
965 		DP_INFO(edev,
966 			"Pause settings are not allowed to be changed\n");
967 		return -EOPNOTSUPP;
968 	}
969 
970 	memset(&current_link, 0, sizeof(current_link));
971 	edev->ops->common->get_link(edev->cdev, &current_link);
972 
973 	memset(&params, 0, sizeof(params));
974 	params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
975 
976 	if (epause->autoneg) {
977 		if (!phylink_test(current_link.supported_caps, Autoneg)) {
978 			DP_INFO(edev, "autoneg not supported\n");
979 			return -EINVAL;
980 		}
981 
982 		params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
983 	}
984 
985 	if (epause->rx_pause)
986 		params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
987 	if (epause->tx_pause)
988 		params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
989 
990 	params.link_up = true;
991 	edev->ops->common->set_link(edev->cdev, &params);
992 
993 	return 0;
994 }
995 
996 static void qede_get_regs(struct net_device *ndev,
997 			  struct ethtool_regs *regs, void *buffer)
998 {
999 	struct qede_dev *edev = netdev_priv(ndev);
1000 
1001 	regs->version = 0;
1002 	memset(buffer, 0, regs->len);
1003 
1004 	if (edev->ops && edev->ops->common)
1005 		edev->ops->common->dbg_all_data(edev->cdev, buffer);
1006 }
1007 
1008 static int qede_get_regs_len(struct net_device *ndev)
1009 {
1010 	struct qede_dev *edev = netdev_priv(ndev);
1011 
1012 	if (edev->ops && edev->ops->common)
1013 		return edev->ops->common->dbg_all_data_size(edev->cdev);
1014 	else
1015 		return -EINVAL;
1016 }
1017 
1018 static void qede_update_mtu(struct qede_dev *edev,
1019 			    struct qede_reload_args *args)
1020 {
1021 	edev->ndev->mtu = args->u.mtu;
1022 }
1023 
1024 /* Netdevice NDOs */
1025 int qede_change_mtu(struct net_device *ndev, int new_mtu)
1026 {
1027 	struct qede_dev *edev = netdev_priv(ndev);
1028 	struct qede_reload_args args;
1029 
1030 	DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1031 		   "Configuring MTU size of %d\n", new_mtu);
1032 
1033 	if (new_mtu > PAGE_SIZE)
1034 		ndev->features &= ~NETIF_F_GRO_HW;
1035 
1036 	/* Set the mtu field and re-start the interface if needed */
1037 	args.u.mtu = new_mtu;
1038 	args.func = &qede_update_mtu;
1039 	qede_reload(edev, &args, false);
1040 #if IS_ENABLED(CONFIG_QED_RDMA)
1041 	qede_rdma_event_change_mtu(edev);
1042 #endif
1043 	edev->ops->common->update_mtu(edev->cdev, new_mtu);
1044 
1045 	return 0;
1046 }
1047 
1048 static void qede_get_channels(struct net_device *dev,
1049 			      struct ethtool_channels *channels)
1050 {
1051 	struct qede_dev *edev = netdev_priv(dev);
1052 
1053 	channels->max_combined = QEDE_MAX_RSS_CNT(edev);
1054 	channels->max_rx = QEDE_MAX_RSS_CNT(edev);
1055 	channels->max_tx = QEDE_MAX_RSS_CNT(edev);
1056 	channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
1057 					edev->fp_num_rx;
1058 	channels->tx_count = edev->fp_num_tx;
1059 	channels->rx_count = edev->fp_num_rx;
1060 }
1061 
1062 static int qede_set_channels(struct net_device *dev,
1063 			     struct ethtool_channels *channels)
1064 {
1065 	struct qede_dev *edev = netdev_priv(dev);
1066 	u32 count;
1067 
1068 	DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1069 		   "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
1070 		   channels->rx_count, channels->tx_count,
1071 		   channels->other_count, channels->combined_count);
1072 
1073 	count = channels->rx_count + channels->tx_count +
1074 			channels->combined_count;
1075 
1076 	/* We don't support `other' channels */
1077 	if (channels->other_count) {
1078 		DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1079 			   "command parameters not supported\n");
1080 		return -EINVAL;
1081 	}
1082 
1083 	if (!(channels->combined_count || (channels->rx_count &&
1084 					   channels->tx_count))) {
1085 		DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1086 			   "need to request at least one transmit and one receive channel\n");
1087 		return -EINVAL;
1088 	}
1089 
1090 	if (count > QEDE_MAX_RSS_CNT(edev)) {
1091 		DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1092 			   "requested channels = %d max supported channels = %d\n",
1093 			   count, QEDE_MAX_RSS_CNT(edev));
1094 		return -EINVAL;
1095 	}
1096 
1097 	/* Check if there was a change in the active parameters */
1098 	if ((count == QEDE_QUEUE_CNT(edev)) &&
1099 	    (channels->tx_count == edev->fp_num_tx) &&
1100 	    (channels->rx_count == edev->fp_num_rx)) {
1101 		DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1102 			   "No change in active parameters\n");
1103 		return 0;
1104 	}
1105 
1106 	/* We need the number of queues to be divisible between the hwfns */
1107 	if ((count % edev->dev_info.common.num_hwfns) ||
1108 	    (channels->tx_count % edev->dev_info.common.num_hwfns) ||
1109 	    (channels->rx_count % edev->dev_info.common.num_hwfns)) {
1110 		DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1111 			   "Number of channels must be divisible by %04x\n",
1112 			   edev->dev_info.common.num_hwfns);
1113 		return -EINVAL;
1114 	}
1115 
1116 	/* Set number of queues and reload if necessary */
1117 	edev->req_queues = count;
1118 	edev->req_num_tx = channels->tx_count;
1119 	edev->req_num_rx = channels->rx_count;
1120 	/* Reset the indirection table if rx queue count is updated */
1121 	if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
1122 		edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
1123 		memset(edev->rss_ind_table, 0, sizeof(edev->rss_ind_table));
1124 	}
1125 
1126 	qede_reload(edev, NULL, false);
1127 
1128 	return 0;
1129 }
1130 
1131 static int qede_get_ts_info(struct net_device *dev,
1132 			    struct ethtool_ts_info *info)
1133 {
1134 	struct qede_dev *edev = netdev_priv(dev);
1135 
1136 	return qede_ptp_get_ts_info(edev, info);
1137 }
1138 
1139 static int qede_set_phys_id(struct net_device *dev,
1140 			    enum ethtool_phys_id_state state)
1141 {
1142 	struct qede_dev *edev = netdev_priv(dev);
1143 	u8 led_state = 0;
1144 
1145 	switch (state) {
1146 	case ETHTOOL_ID_ACTIVE:
1147 		return 1;	/* cycle on/off once per second */
1148 
1149 	case ETHTOOL_ID_ON:
1150 		led_state = QED_LED_MODE_ON;
1151 		break;
1152 
1153 	case ETHTOOL_ID_OFF:
1154 		led_state = QED_LED_MODE_OFF;
1155 		break;
1156 
1157 	case ETHTOOL_ID_INACTIVE:
1158 		led_state = QED_LED_MODE_RESTORE;
1159 		break;
1160 	}
1161 
1162 	edev->ops->common->set_led(edev->cdev, led_state);
1163 
1164 	return 0;
1165 }
1166 
1167 static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1168 {
1169 	info->data = RXH_IP_SRC | RXH_IP_DST;
1170 
1171 	switch (info->flow_type) {
1172 	case TCP_V4_FLOW:
1173 	case TCP_V6_FLOW:
1174 		info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1175 		break;
1176 	case UDP_V4_FLOW:
1177 		if (edev->rss_caps & QED_RSS_IPV4_UDP)
1178 			info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1179 		break;
1180 	case UDP_V6_FLOW:
1181 		if (edev->rss_caps & QED_RSS_IPV6_UDP)
1182 			info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1183 		break;
1184 	case IPV4_FLOW:
1185 	case IPV6_FLOW:
1186 		break;
1187 	default:
1188 		info->data = 0;
1189 		break;
1190 	}
1191 
1192 	return 0;
1193 }
1194 
1195 static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
1196 			  u32 *rule_locs)
1197 {
1198 	struct qede_dev *edev = netdev_priv(dev);
1199 	int rc = 0;
1200 
1201 	switch (info->cmd) {
1202 	case ETHTOOL_GRXRINGS:
1203 		info->data = QEDE_RSS_COUNT(edev);
1204 		break;
1205 	case ETHTOOL_GRXFH:
1206 		rc = qede_get_rss_flags(edev, info);
1207 		break;
1208 	case ETHTOOL_GRXCLSRLCNT:
1209 		info->rule_cnt = qede_get_arfs_filter_count(edev);
1210 		info->data = QEDE_RFS_MAX_FLTR;
1211 		break;
1212 	case ETHTOOL_GRXCLSRULE:
1213 		rc = qede_get_cls_rule_entry(edev, info);
1214 		break;
1215 	case ETHTOOL_GRXCLSRLALL:
1216 		rc = qede_get_cls_rule_all(edev, info, rule_locs);
1217 		break;
1218 	default:
1219 		DP_ERR(edev, "Command parameters not supported\n");
1220 		rc = -EOPNOTSUPP;
1221 	}
1222 
1223 	return rc;
1224 }
1225 
1226 static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1227 {
1228 	struct qed_update_vport_params *vport_update_params;
1229 	u8 set_caps = 0, clr_caps = 0;
1230 	int rc = 0;
1231 
1232 	DP_VERBOSE(edev, QED_MSG_DEBUG,
1233 		   "Set rss flags command parameters: flow type = %d, data = %llu\n",
1234 		   info->flow_type, info->data);
1235 
1236 	switch (info->flow_type) {
1237 	case TCP_V4_FLOW:
1238 	case TCP_V6_FLOW:
1239 		/* For TCP only 4-tuple hash is supported */
1240 		if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
1241 				  RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1242 			DP_INFO(edev, "Command parameters not supported\n");
1243 			return -EINVAL;
1244 		}
1245 		return 0;
1246 	case UDP_V4_FLOW:
1247 		/* For UDP either 2-tuple hash or 4-tuple hash is supported */
1248 		if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1249 				   RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1250 			set_caps = QED_RSS_IPV4_UDP;
1251 			DP_VERBOSE(edev, QED_MSG_DEBUG,
1252 				   "UDP 4-tuple enabled\n");
1253 		} else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1254 			clr_caps = QED_RSS_IPV4_UDP;
1255 			DP_VERBOSE(edev, QED_MSG_DEBUG,
1256 				   "UDP 4-tuple disabled\n");
1257 		} else {
1258 			return -EINVAL;
1259 		}
1260 		break;
1261 	case UDP_V6_FLOW:
1262 		/* For UDP either 2-tuple hash or 4-tuple hash is supported */
1263 		if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1264 				   RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1265 			set_caps = QED_RSS_IPV6_UDP;
1266 			DP_VERBOSE(edev, QED_MSG_DEBUG,
1267 				   "UDP 4-tuple enabled\n");
1268 		} else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1269 			clr_caps = QED_RSS_IPV6_UDP;
1270 			DP_VERBOSE(edev, QED_MSG_DEBUG,
1271 				   "UDP 4-tuple disabled\n");
1272 		} else {
1273 			return -EINVAL;
1274 		}
1275 		break;
1276 	case IPV4_FLOW:
1277 	case IPV6_FLOW:
1278 		/* For IP only 2-tuple hash is supported */
1279 		if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1280 			DP_INFO(edev, "Command parameters not supported\n");
1281 			return -EINVAL;
1282 		}
1283 		return 0;
1284 	case SCTP_V4_FLOW:
1285 	case AH_ESP_V4_FLOW:
1286 	case AH_V4_FLOW:
1287 	case ESP_V4_FLOW:
1288 	case SCTP_V6_FLOW:
1289 	case AH_ESP_V6_FLOW:
1290 	case AH_V6_FLOW:
1291 	case ESP_V6_FLOW:
1292 	case IP_USER_FLOW:
1293 	case ETHER_FLOW:
1294 		/* RSS is not supported for these protocols */
1295 		if (info->data) {
1296 			DP_INFO(edev, "Command parameters not supported\n");
1297 			return -EINVAL;
1298 		}
1299 		return 0;
1300 	default:
1301 		return -EINVAL;
1302 	}
1303 
1304 	/* No action is needed if there is no change in the rss capability */
1305 	if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps))
1306 		return 0;
1307 
1308 	/* Update internal configuration */
1309 	edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps);
1310 	edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1311 
1312 	/* Re-configure if possible */
1313 	__qede_lock(edev);
1314 	if (edev->state == QEDE_STATE_OPEN) {
1315 		vport_update_params = vzalloc(sizeof(*vport_update_params));
1316 		if (!vport_update_params) {
1317 			__qede_unlock(edev);
1318 			return -ENOMEM;
1319 		}
1320 		qede_fill_rss_params(edev, &vport_update_params->rss_params,
1321 				     &vport_update_params->update_rss_flg);
1322 		rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1323 		vfree(vport_update_params);
1324 	}
1325 	__qede_unlock(edev);
1326 
1327 	return rc;
1328 }
1329 
1330 static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1331 {
1332 	struct qede_dev *edev = netdev_priv(dev);
1333 	int rc;
1334 
1335 	switch (info->cmd) {
1336 	case ETHTOOL_SRXFH:
1337 		rc = qede_set_rss_flags(edev, info);
1338 		break;
1339 	case ETHTOOL_SRXCLSRLINS:
1340 		rc = qede_add_cls_rule(edev, info);
1341 		break;
1342 	case ETHTOOL_SRXCLSRLDEL:
1343 		rc = qede_delete_flow_filter(edev, info->fs.location);
1344 		break;
1345 	default:
1346 		DP_INFO(edev, "Command parameters not supported\n");
1347 		rc = -EOPNOTSUPP;
1348 	}
1349 
1350 	return rc;
1351 }
1352 
1353 static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1354 {
1355 	return QED_RSS_IND_TABLE_SIZE;
1356 }
1357 
1358 static u32 qede_get_rxfh_key_size(struct net_device *dev)
1359 {
1360 	struct qede_dev *edev = netdev_priv(dev);
1361 
1362 	return sizeof(edev->rss_key);
1363 }
1364 
1365 static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1366 {
1367 	struct qede_dev *edev = netdev_priv(dev);
1368 	int i;
1369 
1370 	if (hfunc)
1371 		*hfunc = ETH_RSS_HASH_TOP;
1372 
1373 	if (!indir)
1374 		return 0;
1375 
1376 	for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1377 		indir[i] = edev->rss_ind_table[i];
1378 
1379 	if (key)
1380 		memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev));
1381 
1382 	return 0;
1383 }
1384 
1385 static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1386 			 const u8 *key, const u8 hfunc)
1387 {
1388 	struct qed_update_vport_params *vport_update_params;
1389 	struct qede_dev *edev = netdev_priv(dev);
1390 	int i, rc = 0;
1391 
1392 	if (edev->dev_info.common.num_hwfns > 1) {
1393 		DP_INFO(edev,
1394 			"RSS configuration is not supported for 100G devices\n");
1395 		return -EOPNOTSUPP;
1396 	}
1397 
1398 	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1399 		return -EOPNOTSUPP;
1400 
1401 	if (!indir && !key)
1402 		return 0;
1403 
1404 	if (indir) {
1405 		for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1406 			edev->rss_ind_table[i] = indir[i];
1407 		edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1408 	}
1409 
1410 	if (key) {
1411 		memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev));
1412 		edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1413 	}
1414 
1415 	__qede_lock(edev);
1416 	if (edev->state == QEDE_STATE_OPEN) {
1417 		vport_update_params = vzalloc(sizeof(*vport_update_params));
1418 		if (!vport_update_params) {
1419 			__qede_unlock(edev);
1420 			return -ENOMEM;
1421 		}
1422 		qede_fill_rss_params(edev, &vport_update_params->rss_params,
1423 				     &vport_update_params->update_rss_flg);
1424 		rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1425 		vfree(vport_update_params);
1426 	}
1427 	__qede_unlock(edev);
1428 
1429 	return rc;
1430 }
1431 
1432 /* This function enables the interrupt generation and the NAPI on the device */
1433 static void qede_netif_start(struct qede_dev *edev)
1434 {
1435 	int i;
1436 
1437 	if (!netif_running(edev->ndev))
1438 		return;
1439 
1440 	for_each_queue(i) {
1441 		/* Update and reenable interrupts */
1442 		qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1443 		napi_enable(&edev->fp_array[i].napi);
1444 	}
1445 }
1446 
1447 /* This function disables the NAPI and the interrupt generation on the device */
1448 static void qede_netif_stop(struct qede_dev *edev)
1449 {
1450 	int i;
1451 
1452 	for_each_queue(i) {
1453 		napi_disable(&edev->fp_array[i].napi);
1454 		/* Disable interrupts */
1455 		qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1456 	}
1457 }
1458 
1459 static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1460 					  struct sk_buff *skb)
1461 {
1462 	struct qede_tx_queue *txq = NULL;
1463 	struct eth_tx_1st_bd *first_bd;
1464 	dma_addr_t mapping;
1465 	int i, idx;
1466 	u16 val;
1467 
1468 	for_each_queue(i) {
1469 		struct qede_fastpath *fp = &edev->fp_array[i];
1470 
1471 		if (fp->type & QEDE_FASTPATH_TX) {
1472 			txq = QEDE_FP_TC0_TXQ(fp);
1473 			break;
1474 		}
1475 	}
1476 
1477 	if (!txq) {
1478 		DP_NOTICE(edev, "Tx path is not available\n");
1479 		return -1;
1480 	}
1481 
1482 	/* Fill the entry in the SW ring and the BDs in the FW ring */
1483 	idx = txq->sw_tx_prod;
1484 	txq->sw_tx_ring.skbs[idx].skb = skb;
1485 	first_bd = qed_chain_produce(&txq->tx_pbl);
1486 	memset(first_bd, 0, sizeof(*first_bd));
1487 	val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1488 	first_bd->data.bd_flags.bitfields = val;
1489 	val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1490 	val = val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
1491 	first_bd->data.bitfields |= cpu_to_le16(val);
1492 
1493 	/* Map skb linear data for DMA and set in the first BD */
1494 	mapping = dma_map_single(&edev->pdev->dev, skb->data,
1495 				 skb_headlen(skb), DMA_TO_DEVICE);
1496 	if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1497 		DP_NOTICE(edev, "SKB mapping failed\n");
1498 		return -ENOMEM;
1499 	}
1500 	BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1501 
1502 	/* update the first BD with the actual num BDs */
1503 	first_bd->data.nbds = 1;
1504 	txq->sw_tx_prod = (txq->sw_tx_prod + 1) % txq->num_tx_buffers;
1505 	/* 'next page' entries are counted in the producer value */
1506 	val = qed_chain_get_prod_idx(&txq->tx_pbl);
1507 	txq->tx_db.data.bd_prod = cpu_to_le16(val);
1508 
1509 	/* wmb makes sure that the BDs data is updated before updating the
1510 	 * producer, otherwise FW may read old data from the BDs.
1511 	 */
1512 	wmb();
1513 	barrier();
1514 	writel(txq->tx_db.raw, txq->doorbell_addr);
1515 
1516 	for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1517 		if (qede_txq_has_work(txq))
1518 			break;
1519 		usleep_range(100, 200);
1520 	}
1521 
1522 	if (!qede_txq_has_work(txq)) {
1523 		DP_NOTICE(edev, "Tx completion didn't happen\n");
1524 		return -1;
1525 	}
1526 
1527 	first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
1528 	dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1529 			 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
1530 	txq->sw_tx_cons = (txq->sw_tx_cons + 1) % txq->num_tx_buffers;
1531 	txq->sw_tx_ring.skbs[idx].skb = NULL;
1532 
1533 	return 0;
1534 }
1535 
1536 static int qede_selftest_receive_traffic(struct qede_dev *edev)
1537 {
1538 	u16 sw_rx_index, len;
1539 	struct eth_fast_path_rx_reg_cqe *fp_cqe;
1540 	struct qede_rx_queue *rxq = NULL;
1541 	struct sw_rx_data *sw_rx_data;
1542 	union eth_rx_cqe *cqe;
1543 	int i, iter, rc = 0;
1544 	u8 *data_ptr;
1545 
1546 	for_each_queue(i) {
1547 		if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1548 			rxq = edev->fp_array[i].rxq;
1549 			break;
1550 		}
1551 	}
1552 
1553 	if (!rxq) {
1554 		DP_NOTICE(edev, "Rx path is not available\n");
1555 		return -1;
1556 	}
1557 
1558 	/* The packet is expected to receive on rx-queue 0 even though RSS is
1559 	 * enabled. This is because the queue 0 is configured as the default
1560 	 * queue and that the loopback traffic is not IP.
1561 	 */
1562 	for (iter = 0; iter < QEDE_SELFTEST_POLL_COUNT; iter++) {
1563 		if (!qede_has_rx_work(rxq)) {
1564 			usleep_range(100, 200);
1565 			continue;
1566 		}
1567 
1568 		/* Get the CQE from the completion ring */
1569 		cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1570 
1571 		/* Get the data from the SW ring */
1572 		sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1573 		sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1574 		fp_cqe = &cqe->fast_path_regular;
1575 		len =  le16_to_cpu(fp_cqe->len_on_first_bd);
1576 		data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1577 				  fp_cqe->placement_offset +
1578 				  sw_rx_data->page_offset +
1579 				  rxq->rx_headroom);
1580 		if (ether_addr_equal(data_ptr,  edev->ndev->dev_addr) &&
1581 		    ether_addr_equal(data_ptr + ETH_ALEN,
1582 				     edev->ndev->dev_addr)) {
1583 			for (i = ETH_HLEN; i < len; i++)
1584 				if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1585 					rc = -1;
1586 					break;
1587 				}
1588 
1589 			qede_recycle_rx_bd_ring(rxq, 1);
1590 			qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1591 			break;
1592 		}
1593 
1594 		DP_INFO(edev, "Not the transmitted packet\n");
1595 		qede_recycle_rx_bd_ring(rxq, 1);
1596 		qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1597 	}
1598 
1599 	if (iter == QEDE_SELFTEST_POLL_COUNT) {
1600 		DP_NOTICE(edev, "Failed to receive the traffic\n");
1601 		return -1;
1602 	}
1603 
1604 	qede_update_rx_prod(edev, rxq);
1605 
1606 	return rc;
1607 }
1608 
1609 static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1610 {
1611 	struct qed_link_params link_params;
1612 	struct sk_buff *skb = NULL;
1613 	int rc = 0, i;
1614 	u32 pkt_size;
1615 	u8 *packet;
1616 
1617 	if (!netif_running(edev->ndev)) {
1618 		DP_NOTICE(edev, "Interface is down\n");
1619 		return -EINVAL;
1620 	}
1621 
1622 	qede_netif_stop(edev);
1623 
1624 	/* Bring up the link in Loopback mode */
1625 	memset(&link_params, 0, sizeof(link_params));
1626 	link_params.link_up = true;
1627 	link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1628 	link_params.loopback_mode = loopback_mode;
1629 	edev->ops->common->set_link(edev->cdev, &link_params);
1630 
1631 	/* Wait for loopback configuration to apply */
1632 	msleep_interruptible(500);
1633 
1634 	/* Setting max packet size to 1.5K to avoid data being split over
1635 	 * multiple BDs in cases where MTU > PAGE_SIZE.
1636 	 */
1637 	pkt_size = (((edev->ndev->mtu < ETH_DATA_LEN) ?
1638 		     edev->ndev->mtu : ETH_DATA_LEN) + ETH_HLEN);
1639 
1640 	skb = netdev_alloc_skb(edev->ndev, pkt_size);
1641 	if (!skb) {
1642 		DP_INFO(edev, "Can't allocate skb\n");
1643 		rc = -ENOMEM;
1644 		goto test_loopback_exit;
1645 	}
1646 	packet = skb_put(skb, pkt_size);
1647 	ether_addr_copy(packet, edev->ndev->dev_addr);
1648 	ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1649 	memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1650 	for (i = ETH_HLEN; i < pkt_size; i++)
1651 		packet[i] = (unsigned char)(i & 0xff);
1652 
1653 	rc = qede_selftest_transmit_traffic(edev, skb);
1654 	if (rc)
1655 		goto test_loopback_exit;
1656 
1657 	rc = qede_selftest_receive_traffic(edev);
1658 	if (rc)
1659 		goto test_loopback_exit;
1660 
1661 	DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1662 
1663 test_loopback_exit:
1664 	dev_kfree_skb(skb);
1665 
1666 	/* Bring up the link in Normal mode */
1667 	memset(&link_params, 0, sizeof(link_params));
1668 	link_params.link_up = true;
1669 	link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1670 	link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1671 	edev->ops->common->set_link(edev->cdev, &link_params);
1672 
1673 	/* Wait for loopback configuration to apply */
1674 	msleep_interruptible(500);
1675 
1676 	qede_netif_start(edev);
1677 
1678 	return rc;
1679 }
1680 
1681 static void qede_self_test(struct net_device *dev,
1682 			   struct ethtool_test *etest, u64 *buf)
1683 {
1684 	struct qede_dev *edev = netdev_priv(dev);
1685 
1686 	DP_VERBOSE(edev, QED_MSG_DEBUG,
1687 		   "Self-test command parameters: offline = %d, external_lb = %d\n",
1688 		   (etest->flags & ETH_TEST_FL_OFFLINE),
1689 		   (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1690 
1691 	memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1692 
1693 	if (etest->flags & ETH_TEST_FL_OFFLINE) {
1694 		if (qede_selftest_run_loopback(edev,
1695 					       QED_LINK_LOOPBACK_INT_PHY)) {
1696 			buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1697 			etest->flags |= ETH_TEST_FL_FAILED;
1698 		}
1699 	}
1700 
1701 	if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1702 		buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1703 		etest->flags |= ETH_TEST_FL_FAILED;
1704 	}
1705 
1706 	if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1707 		buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1708 		etest->flags |= ETH_TEST_FL_FAILED;
1709 	}
1710 
1711 	if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1712 		buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1713 		etest->flags |= ETH_TEST_FL_FAILED;
1714 	}
1715 
1716 	if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1717 		buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1718 		etest->flags |= ETH_TEST_FL_FAILED;
1719 	}
1720 
1721 	if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1722 		buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1723 		etest->flags |= ETH_TEST_FL_FAILED;
1724 	}
1725 }
1726 
1727 static int qede_set_tunable(struct net_device *dev,
1728 			    const struct ethtool_tunable *tuna,
1729 			    const void *data)
1730 {
1731 	struct qede_dev *edev = netdev_priv(dev);
1732 	u32 val;
1733 
1734 	switch (tuna->id) {
1735 	case ETHTOOL_RX_COPYBREAK:
1736 		val = *(u32 *)data;
1737 		if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1738 			DP_VERBOSE(edev, QED_MSG_DEBUG,
1739 				   "Invalid rx copy break value, range is [%u, %u]",
1740 				   QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1741 			return -EINVAL;
1742 		}
1743 
1744 		edev->rx_copybreak = *(u32 *)data;
1745 		break;
1746 	default:
1747 		return -EOPNOTSUPP;
1748 	}
1749 
1750 	return 0;
1751 }
1752 
1753 static int qede_get_tunable(struct net_device *dev,
1754 			    const struct ethtool_tunable *tuna, void *data)
1755 {
1756 	struct qede_dev *edev = netdev_priv(dev);
1757 
1758 	switch (tuna->id) {
1759 	case ETHTOOL_RX_COPYBREAK:
1760 		*(u32 *)data = edev->rx_copybreak;
1761 		break;
1762 	default:
1763 		return -EOPNOTSUPP;
1764 	}
1765 
1766 	return 0;
1767 }
1768 
1769 static int qede_get_eee(struct net_device *dev, struct ethtool_eee *edata)
1770 {
1771 	struct qede_dev *edev = netdev_priv(dev);
1772 	struct qed_link_output current_link;
1773 
1774 	memset(&current_link, 0, sizeof(current_link));
1775 	edev->ops->common->get_link(edev->cdev, &current_link);
1776 
1777 	if (!current_link.eee_supported) {
1778 		DP_INFO(edev, "EEE is not supported\n");
1779 		return -EOPNOTSUPP;
1780 	}
1781 
1782 	if (current_link.eee.adv_caps & QED_EEE_1G_ADV)
1783 		edata->advertised = ADVERTISED_1000baseT_Full;
1784 	if (current_link.eee.adv_caps & QED_EEE_10G_ADV)
1785 		edata->advertised |= ADVERTISED_10000baseT_Full;
1786 	if (current_link.sup_caps & QED_EEE_1G_ADV)
1787 		edata->supported = ADVERTISED_1000baseT_Full;
1788 	if (current_link.sup_caps & QED_EEE_10G_ADV)
1789 		edata->supported |= ADVERTISED_10000baseT_Full;
1790 	if (current_link.eee.lp_adv_caps & QED_EEE_1G_ADV)
1791 		edata->lp_advertised = ADVERTISED_1000baseT_Full;
1792 	if (current_link.eee.lp_adv_caps & QED_EEE_10G_ADV)
1793 		edata->lp_advertised |= ADVERTISED_10000baseT_Full;
1794 
1795 	edata->tx_lpi_timer = current_link.eee.tx_lpi_timer;
1796 	edata->eee_enabled = current_link.eee.enable;
1797 	edata->tx_lpi_enabled = current_link.eee.tx_lpi_enable;
1798 	edata->eee_active = current_link.eee_active;
1799 
1800 	return 0;
1801 }
1802 
1803 static int qede_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1804 {
1805 	struct qede_dev *edev = netdev_priv(dev);
1806 	struct qed_link_output current_link;
1807 	struct qed_link_params params;
1808 
1809 	if (!edev->ops->common->can_link_change(edev->cdev)) {
1810 		DP_INFO(edev, "Link settings are not allowed to be changed\n");
1811 		return -EOPNOTSUPP;
1812 	}
1813 
1814 	memset(&current_link, 0, sizeof(current_link));
1815 	edev->ops->common->get_link(edev->cdev, &current_link);
1816 
1817 	if (!current_link.eee_supported) {
1818 		DP_INFO(edev, "EEE is not supported\n");
1819 		return -EOPNOTSUPP;
1820 	}
1821 
1822 	memset(&params, 0, sizeof(params));
1823 	params.override_flags |= QED_LINK_OVERRIDE_EEE_CONFIG;
1824 
1825 	if (!(edata->advertised & (ADVERTISED_1000baseT_Full |
1826 				   ADVERTISED_10000baseT_Full)) ||
1827 	    ((edata->advertised & (ADVERTISED_1000baseT_Full |
1828 				   ADVERTISED_10000baseT_Full)) !=
1829 	     edata->advertised)) {
1830 		DP_VERBOSE(edev, QED_MSG_DEBUG,
1831 			   "Invalid advertised capabilities %d\n",
1832 			   edata->advertised);
1833 		return -EINVAL;
1834 	}
1835 
1836 	if (edata->advertised & ADVERTISED_1000baseT_Full)
1837 		params.eee.adv_caps = QED_EEE_1G_ADV;
1838 	if (edata->advertised & ADVERTISED_10000baseT_Full)
1839 		params.eee.adv_caps |= QED_EEE_10G_ADV;
1840 	params.eee.enable = edata->eee_enabled;
1841 	params.eee.tx_lpi_enable = edata->tx_lpi_enabled;
1842 	params.eee.tx_lpi_timer = edata->tx_lpi_timer;
1843 
1844 	params.link_up = true;
1845 	edev->ops->common->set_link(edev->cdev, &params);
1846 
1847 	return 0;
1848 }
1849 
1850 static u32 qede_link_to_ethtool_fec(u32 link_fec)
1851 {
1852 	u32 eth_fec = 0;
1853 
1854 	if (link_fec & QED_FEC_MODE_NONE)
1855 		eth_fec |= ETHTOOL_FEC_OFF;
1856 	if (link_fec & QED_FEC_MODE_FIRECODE)
1857 		eth_fec |= ETHTOOL_FEC_BASER;
1858 	if (link_fec & QED_FEC_MODE_RS)
1859 		eth_fec |= ETHTOOL_FEC_RS;
1860 	if (link_fec & QED_FEC_MODE_AUTO)
1861 		eth_fec |= ETHTOOL_FEC_AUTO;
1862 	if (link_fec & QED_FEC_MODE_UNSUPPORTED)
1863 		eth_fec |= ETHTOOL_FEC_NONE;
1864 
1865 	return eth_fec;
1866 }
1867 
1868 static u32 qede_ethtool_to_link_fec(u32 eth_fec)
1869 {
1870 	u32 link_fec = 0;
1871 
1872 	if (eth_fec & ETHTOOL_FEC_OFF)
1873 		link_fec |= QED_FEC_MODE_NONE;
1874 	if (eth_fec & ETHTOOL_FEC_BASER)
1875 		link_fec |= QED_FEC_MODE_FIRECODE;
1876 	if (eth_fec & ETHTOOL_FEC_RS)
1877 		link_fec |= QED_FEC_MODE_RS;
1878 	if (eth_fec & ETHTOOL_FEC_AUTO)
1879 		link_fec |= QED_FEC_MODE_AUTO;
1880 	if (eth_fec & ETHTOOL_FEC_NONE)
1881 		link_fec |= QED_FEC_MODE_UNSUPPORTED;
1882 
1883 	return link_fec;
1884 }
1885 
1886 static int qede_get_fecparam(struct net_device *dev,
1887 			     struct ethtool_fecparam *fecparam)
1888 {
1889 	struct qede_dev *edev = netdev_priv(dev);
1890 	struct qed_link_output curr_link;
1891 
1892 	memset(&curr_link, 0, sizeof(curr_link));
1893 	edev->ops->common->get_link(edev->cdev, &curr_link);
1894 
1895 	fecparam->active_fec = qede_link_to_ethtool_fec(curr_link.active_fec);
1896 	fecparam->fec = qede_link_to_ethtool_fec(curr_link.sup_fec);
1897 
1898 	return 0;
1899 }
1900 
1901 static int qede_set_fecparam(struct net_device *dev,
1902 			     struct ethtool_fecparam *fecparam)
1903 {
1904 	struct qede_dev *edev = netdev_priv(dev);
1905 	struct qed_link_params params;
1906 
1907 	if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
1908 		DP_INFO(edev, "Link settings are not allowed to be changed\n");
1909 		return -EOPNOTSUPP;
1910 	}
1911 
1912 	memset(&params, 0, sizeof(params));
1913 	params.override_flags |= QED_LINK_OVERRIDE_FEC_CONFIG;
1914 	params.fec = qede_ethtool_to_link_fec(fecparam->fec);
1915 	params.link_up = true;
1916 
1917 	edev->ops->common->set_link(edev->cdev, &params);
1918 
1919 	return 0;
1920 }
1921 
1922 static int qede_get_module_info(struct net_device *dev,
1923 				struct ethtool_modinfo *modinfo)
1924 {
1925 	struct qede_dev *edev = netdev_priv(dev);
1926 	u8 buf[4];
1927 	int rc;
1928 
1929 	/* Read first 4 bytes to find the sfp type */
1930 	rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1931 						   QED_I2C_DEV_ADDR_A0, 0, 4);
1932 	if (rc) {
1933 		DP_ERR(edev, "Failed reading EEPROM data %d\n", rc);
1934 		return rc;
1935 	}
1936 
1937 	switch (buf[0]) {
1938 	case 0x3: /* SFP, SFP+, SFP-28 */
1939 		modinfo->type = ETH_MODULE_SFF_8472;
1940 		modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1941 		break;
1942 	case 0xc: /* QSFP */
1943 	case 0xd: /* QSFP+ */
1944 		modinfo->type = ETH_MODULE_SFF_8436;
1945 		modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1946 		break;
1947 	case 0x11: /* QSFP-28 */
1948 		modinfo->type = ETH_MODULE_SFF_8636;
1949 		modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1950 		break;
1951 	default:
1952 		DP_ERR(edev, "Unknown transceiver type 0x%x\n", buf[0]);
1953 		return -EINVAL;
1954 	}
1955 
1956 	return 0;
1957 }
1958 
1959 static int qede_get_module_eeprom(struct net_device *dev,
1960 				  struct ethtool_eeprom *ee, u8 *data)
1961 {
1962 	struct qede_dev *edev = netdev_priv(dev);
1963 	u32 start_addr = ee->offset, size = 0;
1964 	u8 *buf = data;
1965 	int rc = 0;
1966 
1967 	/* Read A0 section */
1968 	if (ee->offset < ETH_MODULE_SFF_8079_LEN) {
1969 		/* Limit transfer size to the A0 section boundary */
1970 		if (ee->offset + ee->len > ETH_MODULE_SFF_8079_LEN)
1971 			size = ETH_MODULE_SFF_8079_LEN - ee->offset;
1972 		else
1973 			size = ee->len;
1974 
1975 		rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1976 							   QED_I2C_DEV_ADDR_A0,
1977 							   start_addr, size);
1978 		if (rc) {
1979 			DP_ERR(edev, "Failed reading A0 section  %d\n", rc);
1980 			return rc;
1981 		}
1982 
1983 		buf += size;
1984 		start_addr += size;
1985 	}
1986 
1987 	/* Read A2 section */
1988 	if (start_addr >= ETH_MODULE_SFF_8079_LEN &&
1989 	    start_addr < ETH_MODULE_SFF_8472_LEN) {
1990 		size = ee->len - size;
1991 		/* Limit transfer size to the A2 section boundary */
1992 		if (start_addr + size > ETH_MODULE_SFF_8472_LEN)
1993 			size = ETH_MODULE_SFF_8472_LEN - start_addr;
1994 		start_addr -= ETH_MODULE_SFF_8079_LEN;
1995 		rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1996 							   QED_I2C_DEV_ADDR_A2,
1997 							   start_addr, size);
1998 		if (rc) {
1999 			DP_VERBOSE(edev, QED_MSG_DEBUG,
2000 				   "Failed reading A2 section %d\n", rc);
2001 			return 0;
2002 		}
2003 	}
2004 
2005 	return rc;
2006 }
2007 
2008 static int qede_set_dump(struct net_device *dev, struct ethtool_dump *val)
2009 {
2010 	struct qede_dev *edev = netdev_priv(dev);
2011 	int rc = 0;
2012 
2013 	if (edev->dump_info.cmd == QEDE_DUMP_CMD_NONE) {
2014 		if (val->flag > QEDE_DUMP_CMD_MAX) {
2015 			DP_ERR(edev, "Invalid command %d\n", val->flag);
2016 			return -EINVAL;
2017 		}
2018 		edev->dump_info.cmd = val->flag;
2019 		edev->dump_info.num_args = 0;
2020 		return 0;
2021 	}
2022 
2023 	if (edev->dump_info.num_args == QEDE_DUMP_MAX_ARGS) {
2024 		DP_ERR(edev, "Arg count = %d\n", edev->dump_info.num_args);
2025 		return -EINVAL;
2026 	}
2027 
2028 	switch (edev->dump_info.cmd) {
2029 	case QEDE_DUMP_CMD_NVM_CFG:
2030 		edev->dump_info.args[edev->dump_info.num_args] = val->flag;
2031 		edev->dump_info.num_args++;
2032 		break;
2033 	case QEDE_DUMP_CMD_GRCDUMP:
2034 		rc = edev->ops->common->set_grc_config(edev->cdev,
2035 						       val->flag, 1);
2036 		break;
2037 	default:
2038 		break;
2039 	}
2040 
2041 	return rc;
2042 }
2043 
2044 static int qede_get_dump_flag(struct net_device *dev,
2045 			      struct ethtool_dump *dump)
2046 {
2047 	struct qede_dev *edev = netdev_priv(dev);
2048 
2049 	if (!edev->ops || !edev->ops->common) {
2050 		DP_ERR(edev, "Edev ops not populated\n");
2051 		return -EINVAL;
2052 	}
2053 
2054 	dump->version = QEDE_DUMP_VERSION;
2055 	switch (edev->dump_info.cmd) {
2056 	case QEDE_DUMP_CMD_NVM_CFG:
2057 		dump->flag = QEDE_DUMP_CMD_NVM_CFG;
2058 		dump->len = edev->ops->common->read_nvm_cfg_len(edev->cdev,
2059 						edev->dump_info.args[0]);
2060 		break;
2061 	case QEDE_DUMP_CMD_GRCDUMP:
2062 		dump->flag = QEDE_DUMP_CMD_GRCDUMP;
2063 		dump->len = edev->ops->common->dbg_all_data_size(edev->cdev);
2064 		break;
2065 	default:
2066 		DP_ERR(edev, "Invalid cmd = %d\n", edev->dump_info.cmd);
2067 		return -EINVAL;
2068 	}
2069 
2070 	DP_VERBOSE(edev, QED_MSG_DEBUG,
2071 		   "dump->version = 0x%x dump->flag = %d dump->len = %d\n",
2072 		   dump->version, dump->flag, dump->len);
2073 	return 0;
2074 }
2075 
2076 static int qede_get_dump_data(struct net_device *dev,
2077 			      struct ethtool_dump *dump, void *buf)
2078 {
2079 	struct qede_dev *edev = netdev_priv(dev);
2080 	int rc = 0;
2081 
2082 	if (!edev->ops || !edev->ops->common) {
2083 		DP_ERR(edev, "Edev ops not populated\n");
2084 		rc = -EINVAL;
2085 		goto err;
2086 	}
2087 
2088 	switch (edev->dump_info.cmd) {
2089 	case QEDE_DUMP_CMD_NVM_CFG:
2090 		if (edev->dump_info.num_args != QEDE_DUMP_NVM_ARG_COUNT) {
2091 			DP_ERR(edev, "Arg count = %d required = %d\n",
2092 			       edev->dump_info.num_args,
2093 			       QEDE_DUMP_NVM_ARG_COUNT);
2094 			rc = -EINVAL;
2095 			goto err;
2096 		}
2097 		rc =  edev->ops->common->read_nvm_cfg(edev->cdev, (u8 **)&buf,
2098 						      edev->dump_info.args[0],
2099 						      edev->dump_info.args[1]);
2100 		break;
2101 	case QEDE_DUMP_CMD_GRCDUMP:
2102 		memset(buf, 0, dump->len);
2103 		rc = edev->ops->common->dbg_all_data(edev->cdev, buf);
2104 		break;
2105 	default:
2106 		DP_ERR(edev, "Invalid cmd = %d\n", edev->dump_info.cmd);
2107 		rc = -EINVAL;
2108 		break;
2109 	}
2110 
2111 err:
2112 	edev->dump_info.cmd = QEDE_DUMP_CMD_NONE;
2113 	edev->dump_info.num_args = 0;
2114 	memset(edev->dump_info.args, 0, sizeof(edev->dump_info.args));
2115 
2116 	return rc;
2117 }
2118 
2119 int qede_set_per_coalesce(struct net_device *dev, u32 queue,
2120 			  struct ethtool_coalesce *coal)
2121 {
2122 	struct qede_dev *edev = netdev_priv(dev);
2123 	struct qede_fastpath *fp;
2124 	u16 rxc, txc;
2125 	int rc = 0;
2126 
2127 	if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
2128 	    coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
2129 		DP_INFO(edev,
2130 			"Can't support requested %s coalesce value [max supported value %d]\n",
2131 			coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
2132 								   : "tx",
2133 			QED_COALESCE_MAX);
2134 		return -EINVAL;
2135 	}
2136 
2137 	rxc = (u16)coal->rx_coalesce_usecs;
2138 	txc = (u16)coal->tx_coalesce_usecs;
2139 
2140 	__qede_lock(edev);
2141 	if (queue >= edev->num_queues) {
2142 		DP_INFO(edev, "Invalid queue\n");
2143 		rc = -EINVAL;
2144 		goto out;
2145 	}
2146 
2147 	if (edev->state != QEDE_STATE_OPEN) {
2148 		rc = -EINVAL;
2149 		goto out;
2150 	}
2151 
2152 	fp = &edev->fp_array[queue];
2153 
2154 	if (edev->fp_array[queue].type & QEDE_FASTPATH_RX) {
2155 		rc = edev->ops->common->set_coalesce(edev->cdev,
2156 						     rxc, 0,
2157 						     fp->rxq->handle);
2158 		if (rc) {
2159 			DP_INFO(edev,
2160 				"Set RX coalesce error, rc = %d\n", rc);
2161 			goto out;
2162 		}
2163 		edev->coal_entry[queue].rxc = rxc;
2164 		edev->coal_entry[queue].isvalid = true;
2165 	}
2166 
2167 	if (edev->fp_array[queue].type & QEDE_FASTPATH_TX) {
2168 		rc = edev->ops->common->set_coalesce(edev->cdev,
2169 						     0, txc,
2170 						     fp->txq->handle);
2171 		if (rc) {
2172 			DP_INFO(edev,
2173 				"Set TX coalesce error, rc = %d\n", rc);
2174 			goto out;
2175 		}
2176 		edev->coal_entry[queue].txc = txc;
2177 		edev->coal_entry[queue].isvalid = true;
2178 	}
2179 out:
2180 	__qede_unlock(edev);
2181 
2182 	return rc;
2183 }
2184 
2185 static int qede_get_per_coalesce(struct net_device *dev,
2186 				 u32 queue,
2187 				 struct ethtool_coalesce *coal)
2188 {
2189 	void *rx_handle = NULL, *tx_handle = NULL;
2190 	struct qede_dev *edev = netdev_priv(dev);
2191 	struct qede_fastpath *fp;
2192 	u16 rx_coal, tx_coal;
2193 	int rc = 0;
2194 
2195 	rx_coal = QED_DEFAULT_RX_USECS;
2196 	tx_coal = QED_DEFAULT_TX_USECS;
2197 
2198 	memset(coal, 0, sizeof(struct ethtool_coalesce));
2199 
2200 	__qede_lock(edev);
2201 	if (queue >= edev->num_queues) {
2202 		DP_INFO(edev, "Invalid queue\n");
2203 		rc = -EINVAL;
2204 		goto out;
2205 	}
2206 
2207 	if (edev->state != QEDE_STATE_OPEN) {
2208 		rc = -EINVAL;
2209 		goto out;
2210 	}
2211 
2212 	fp = &edev->fp_array[queue];
2213 
2214 	if (fp->type & QEDE_FASTPATH_RX)
2215 		rx_handle = fp->rxq->handle;
2216 
2217 	rc = edev->ops->get_coalesce(edev->cdev, &rx_coal,
2218 				     rx_handle);
2219 	if (rc) {
2220 		DP_INFO(edev, "Read Rx coalesce error\n");
2221 		goto out;
2222 	}
2223 
2224 	fp = &edev->fp_array[queue];
2225 	if (fp->type & QEDE_FASTPATH_TX)
2226 		tx_handle = fp->txq->handle;
2227 
2228 	rc = edev->ops->get_coalesce(edev->cdev, &tx_coal,
2229 				      tx_handle);
2230 	if (rc)
2231 		DP_INFO(edev, "Read Tx coalesce error\n");
2232 
2233 out:
2234 	__qede_unlock(edev);
2235 
2236 	coal->rx_coalesce_usecs = rx_coal;
2237 	coal->tx_coalesce_usecs = tx_coal;
2238 
2239 	return rc;
2240 }
2241 
2242 static const struct ethtool_ops qede_ethtool_ops = {
2243 	.supported_coalesce_params	= ETHTOOL_COALESCE_USECS,
2244 	.get_link_ksettings		= qede_get_link_ksettings,
2245 	.set_link_ksettings		= qede_set_link_ksettings,
2246 	.get_drvinfo			= qede_get_drvinfo,
2247 	.get_regs_len			= qede_get_regs_len,
2248 	.get_regs			= qede_get_regs,
2249 	.get_wol			= qede_get_wol,
2250 	.set_wol			= qede_set_wol,
2251 	.get_msglevel			= qede_get_msglevel,
2252 	.set_msglevel			= qede_set_msglevel,
2253 	.nway_reset			= qede_nway_reset,
2254 	.get_link			= qede_get_link,
2255 	.get_coalesce			= qede_get_coalesce,
2256 	.set_coalesce			= qede_set_coalesce,
2257 	.get_ringparam			= qede_get_ringparam,
2258 	.set_ringparam			= qede_set_ringparam,
2259 	.get_pauseparam			= qede_get_pauseparam,
2260 	.set_pauseparam			= qede_set_pauseparam,
2261 	.get_strings			= qede_get_strings,
2262 	.set_phys_id			= qede_set_phys_id,
2263 	.get_ethtool_stats		= qede_get_ethtool_stats,
2264 	.get_priv_flags			= qede_get_priv_flags,
2265 	.set_priv_flags			= qede_set_priv_flags,
2266 	.get_sset_count			= qede_get_sset_count,
2267 	.get_rxnfc			= qede_get_rxnfc,
2268 	.set_rxnfc			= qede_set_rxnfc,
2269 	.get_rxfh_indir_size		= qede_get_rxfh_indir_size,
2270 	.get_rxfh_key_size		= qede_get_rxfh_key_size,
2271 	.get_rxfh			= qede_get_rxfh,
2272 	.set_rxfh			= qede_set_rxfh,
2273 	.get_ts_info			= qede_get_ts_info,
2274 	.get_channels			= qede_get_channels,
2275 	.set_channels			= qede_set_channels,
2276 	.self_test			= qede_self_test,
2277 	.get_module_info		= qede_get_module_info,
2278 	.get_module_eeprom		= qede_get_module_eeprom,
2279 	.get_eee			= qede_get_eee,
2280 	.set_eee			= qede_set_eee,
2281 	.get_fecparam			= qede_get_fecparam,
2282 	.set_fecparam			= qede_set_fecparam,
2283 	.get_tunable			= qede_get_tunable,
2284 	.set_tunable			= qede_set_tunable,
2285 	.get_per_queue_coalesce		= qede_get_per_coalesce,
2286 	.set_per_queue_coalesce		= qede_set_per_coalesce,
2287 	.flash_device			= qede_flash_device,
2288 	.get_dump_flag			= qede_get_dump_flag,
2289 	.get_dump_data			= qede_get_dump_data,
2290 	.set_dump			= qede_set_dump,
2291 };
2292 
2293 static const struct ethtool_ops qede_vf_ethtool_ops = {
2294 	.supported_coalesce_params	= ETHTOOL_COALESCE_USECS,
2295 	.get_link_ksettings		= qede_get_link_ksettings,
2296 	.get_drvinfo			= qede_get_drvinfo,
2297 	.get_msglevel			= qede_get_msglevel,
2298 	.set_msglevel			= qede_set_msglevel,
2299 	.get_link			= qede_get_link,
2300 	.get_coalesce			= qede_get_coalesce,
2301 	.set_coalesce			= qede_set_coalesce,
2302 	.get_ringparam			= qede_get_ringparam,
2303 	.set_ringparam			= qede_set_ringparam,
2304 	.get_strings			= qede_get_strings,
2305 	.get_ethtool_stats		= qede_get_ethtool_stats,
2306 	.get_priv_flags			= qede_get_priv_flags,
2307 	.get_sset_count			= qede_get_sset_count,
2308 	.get_rxnfc			= qede_get_rxnfc,
2309 	.set_rxnfc			= qede_set_rxnfc,
2310 	.get_rxfh_indir_size		= qede_get_rxfh_indir_size,
2311 	.get_rxfh_key_size		= qede_get_rxfh_key_size,
2312 	.get_rxfh			= qede_get_rxfh,
2313 	.set_rxfh			= qede_set_rxfh,
2314 	.get_channels			= qede_get_channels,
2315 	.set_channels			= qede_set_channels,
2316 	.get_per_queue_coalesce		= qede_get_per_coalesce,
2317 	.set_per_queue_coalesce		= qede_set_per_coalesce,
2318 	.get_tunable			= qede_get_tunable,
2319 	.set_tunable			= qede_set_tunable,
2320 };
2321 
2322 void qede_set_ethtool_ops(struct net_device *dev)
2323 {
2324 	struct qede_dev *edev = netdev_priv(dev);
2325 
2326 	if (IS_VF(edev))
2327 		dev->ethtool_ops = &qede_vf_ethtool_ops;
2328 	else
2329 		dev->ethtool_ops = &qede_ethtool_ops;
2330 }
2331