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