1
2
3
4
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
31static 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)
49static 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))
78static 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
167enum {
168 QEDE_PRI_FLAG_CMT,
169 QEDE_PRI_FLAG_SMART_AN_SUPPORT,
170 QEDE_PRI_FLAG_RECOVER_ON_ERROR,
171 QEDE_PRI_FLAG_LEN,
172};
173
174static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
175 "Coupled-Function",
176 "SmartAN capable",
177 "Recover on error",
178};
179
180enum 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
190static 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
200
201struct 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
216static 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
222static 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
233static const u32 qede_forced_speed_20000[] __initconst = {
234 ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT,
235};
236
237static 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
243static 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
250static 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
256static 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
263static 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
273void __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
288
289static 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
306static 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
318static 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
325static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
326{
327 struct qede_fastpath *fp;
328 int i;
329
330
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
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
358static 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
380static 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
390static 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
400static 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
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
441static 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
453 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS *
454 edev->dev_info.num_tc;
455
456
457 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
458
459
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
478static 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
495static 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
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
513static 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(¤t_link, 0, sizeof(current_link));
524 edev->ops->common->get_link(edev->cdev, ¤t_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
547static 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(¤t_link, 0, sizeof(current_link));
562 memset(¶ms, 0, sizeof(params));
563 edev->ops->common->get_link(edev->cdev, ¤t_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 {
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
600set_link:
601 params.link_up = true;
602 edev->ops->common->set_link(edev->cdev, ¶ms);
603
604 return 0;
605}
606
607static 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
654static 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
664static 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
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
693static 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
700static 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
714static 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(¤t_link, 0, sizeof(current_link));
729 edev->ops->common->get_link(edev->cdev, ¤t_link);
730 if (!current_link.link_up)
731 return 0;
732
733
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
743static 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(¤t_link, 0, sizeof(current_link));
749 edev->ops->common->get_link(edev->cdev, ¤t_link);
750
751 return current_link.link_up;
752}
753
754static 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
762static 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
800
801
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
815out:
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
824int 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
869
870
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
890static void qede_get_ringparam(struct net_device *dev,
891 struct ethtool_ringparam *ering)
892{
893 struct qede_dev *edev = netdev_priv(dev);
894
895 ering->rx_max_pending = NUM_RX_BDS_MAX;
896 ering->rx_pending = edev->q_num_rx_buffers;
897 ering->tx_max_pending = NUM_TX_BDS_MAX;
898 ering->tx_pending = edev->q_num_tx_buffers;
899}
900
901static int qede_set_ringparam(struct net_device *dev,
902 struct ethtool_ringparam *ering)
903{
904 struct qede_dev *edev = netdev_priv(dev);
905
906 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
907 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
908 ering->rx_pending, ering->tx_pending);
909
910
911 if (ering->rx_pending > NUM_RX_BDS_MAX ||
912 ering->rx_pending < NUM_RX_BDS_MIN ||
913 ering->tx_pending > NUM_TX_BDS_MAX ||
914 ering->tx_pending < NUM_TX_BDS_MIN) {
915 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
916 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
917 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
918 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
919 return -EINVAL;
920 }
921
922
923 edev->q_num_rx_buffers = ering->rx_pending;
924 edev->q_num_tx_buffers = ering->tx_pending;
925
926 qede_reload(edev, NULL, false);
927
928 return 0;
929}
930
931static void qede_get_pauseparam(struct net_device *dev,
932 struct ethtool_pauseparam *epause)
933{
934 struct qede_dev *edev = netdev_priv(dev);
935 struct qed_link_output current_link;
936
937 memset(¤t_link, 0, sizeof(current_link));
938 edev->ops->common->get_link(edev->cdev, ¤t_link);
939
940 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
941 epause->autoneg = true;
942 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
943 epause->rx_pause = true;
944 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
945 epause->tx_pause = true;
946
947 DP_VERBOSE(edev, QED_MSG_DEBUG,
948 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
949 epause->cmd, epause->autoneg, epause->rx_pause,
950 epause->tx_pause);
951}
952
953static int qede_set_pauseparam(struct net_device *dev,
954 struct ethtool_pauseparam *epause)
955{
956 struct qede_dev *edev = netdev_priv(dev);
957 struct qed_link_params params;
958 struct qed_link_output current_link;
959
960 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
961 DP_INFO(edev,
962 "Pause settings are not allowed to be changed\n");
963 return -EOPNOTSUPP;
964 }
965
966 memset(¤t_link, 0, sizeof(current_link));
967 edev->ops->common->get_link(edev->cdev, ¤t_link);
968
969 memset(¶ms, 0, sizeof(params));
970 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
971
972 if (epause->autoneg) {
973 if (!phylink_test(current_link.supported_caps, Autoneg)) {
974 DP_INFO(edev, "autoneg not supported\n");
975 return -EINVAL;
976 }
977
978 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
979 }
980
981 if (epause->rx_pause)
982 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
983 if (epause->tx_pause)
984 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
985
986 params.link_up = true;
987 edev->ops->common->set_link(edev->cdev, ¶ms);
988
989 return 0;
990}
991
992static void qede_get_regs(struct net_device *ndev,
993 struct ethtool_regs *regs, void *buffer)
994{
995 struct qede_dev *edev = netdev_priv(ndev);
996
997 regs->version = 0;
998 memset(buffer, 0, regs->len);
999
1000 if (edev->ops && edev->ops->common)
1001 edev->ops->common->dbg_all_data(edev->cdev, buffer);
1002}
1003
1004static int qede_get_regs_len(struct net_device *ndev)
1005{
1006 struct qede_dev *edev = netdev_priv(ndev);
1007
1008 if (edev->ops && edev->ops->common)
1009 return edev->ops->common->dbg_all_data_size(edev->cdev);
1010 else
1011 return -EINVAL;
1012}
1013
1014static void qede_update_mtu(struct qede_dev *edev,
1015 struct qede_reload_args *args)
1016{
1017 edev->ndev->mtu = args->u.mtu;
1018}
1019
1020
1021int qede_change_mtu(struct net_device *ndev, int new_mtu)
1022{
1023 struct qede_dev *edev = netdev_priv(ndev);
1024 struct qede_reload_args args;
1025
1026 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1027 "Configuring MTU size of %d\n", new_mtu);
1028
1029 if (new_mtu > PAGE_SIZE)
1030 ndev->features &= ~NETIF_F_GRO_HW;
1031
1032
1033 args.u.mtu = new_mtu;
1034 args.func = &qede_update_mtu;
1035 qede_reload(edev, &args, false);
1036#if IS_ENABLED(CONFIG_QED_RDMA)
1037 qede_rdma_event_change_mtu(edev);
1038#endif
1039 edev->ops->common->update_mtu(edev->cdev, new_mtu);
1040
1041 return 0;
1042}
1043
1044static void qede_get_channels(struct net_device *dev,
1045 struct ethtool_channels *channels)
1046{
1047 struct qede_dev *edev = netdev_priv(dev);
1048
1049 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
1050 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
1051 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
1052 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
1053 edev->fp_num_rx;
1054 channels->tx_count = edev->fp_num_tx;
1055 channels->rx_count = edev->fp_num_rx;
1056}
1057
1058static int qede_set_channels(struct net_device *dev,
1059 struct ethtool_channels *channels)
1060{
1061 struct qede_dev *edev = netdev_priv(dev);
1062 u32 count;
1063
1064 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1065 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
1066 channels->rx_count, channels->tx_count,
1067 channels->other_count, channels->combined_count);
1068
1069 count = channels->rx_count + channels->tx_count +
1070 channels->combined_count;
1071
1072
1073 if (channels->other_count) {
1074 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1075 "command parameters not supported\n");
1076 return -EINVAL;
1077 }
1078
1079 if (!(channels->combined_count || (channels->rx_count &&
1080 channels->tx_count))) {
1081 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1082 "need to request at least one transmit and one receive channel\n");
1083 return -EINVAL;
1084 }
1085
1086 if (count > QEDE_MAX_RSS_CNT(edev)) {
1087 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1088 "requested channels = %d max supported channels = %d\n",
1089 count, QEDE_MAX_RSS_CNT(edev));
1090 return -EINVAL;
1091 }
1092
1093
1094 if ((count == QEDE_QUEUE_CNT(edev)) &&
1095 (channels->tx_count == edev->fp_num_tx) &&
1096 (channels->rx_count == edev->fp_num_rx)) {
1097 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1098 "No change in active parameters\n");
1099 return 0;
1100 }
1101
1102
1103 if ((count % edev->dev_info.common.num_hwfns) ||
1104 (channels->tx_count % edev->dev_info.common.num_hwfns) ||
1105 (channels->rx_count % edev->dev_info.common.num_hwfns)) {
1106 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1107 "Number of channels must be divisible by %04x\n",
1108 edev->dev_info.common.num_hwfns);
1109 return -EINVAL;
1110 }
1111
1112
1113 edev->req_queues = count;
1114 edev->req_num_tx = channels->tx_count;
1115 edev->req_num_rx = channels->rx_count;
1116
1117 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
1118 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
1119 memset(edev->rss_ind_table, 0, sizeof(edev->rss_ind_table));
1120 }
1121
1122 qede_reload(edev, NULL, false);
1123
1124 return 0;
1125}
1126
1127static int qede_get_ts_info(struct net_device *dev,
1128 struct ethtool_ts_info *info)
1129{
1130 struct qede_dev *edev = netdev_priv(dev);
1131
1132 return qede_ptp_get_ts_info(edev, info);
1133}
1134
1135static int qede_set_phys_id(struct net_device *dev,
1136 enum ethtool_phys_id_state state)
1137{
1138 struct qede_dev *edev = netdev_priv(dev);
1139 u8 led_state = 0;
1140
1141 switch (state) {
1142 case ETHTOOL_ID_ACTIVE:
1143 return 1;
1144
1145 case ETHTOOL_ID_ON:
1146 led_state = QED_LED_MODE_ON;
1147 break;
1148
1149 case ETHTOOL_ID_OFF:
1150 led_state = QED_LED_MODE_OFF;
1151 break;
1152
1153 case ETHTOOL_ID_INACTIVE:
1154 led_state = QED_LED_MODE_RESTORE;
1155 break;
1156 }
1157
1158 edev->ops->common->set_led(edev->cdev, led_state);
1159
1160 return 0;
1161}
1162
1163static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1164{
1165 info->data = RXH_IP_SRC | RXH_IP_DST;
1166
1167 switch (info->flow_type) {
1168 case TCP_V4_FLOW:
1169 case TCP_V6_FLOW:
1170 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1171 break;
1172 case UDP_V4_FLOW:
1173 if (edev->rss_caps & QED_RSS_IPV4_UDP)
1174 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1175 break;
1176 case UDP_V6_FLOW:
1177 if (edev->rss_caps & QED_RSS_IPV6_UDP)
1178 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1179 break;
1180 case IPV4_FLOW:
1181 case IPV6_FLOW:
1182 break;
1183 default:
1184 info->data = 0;
1185 break;
1186 }
1187
1188 return 0;
1189}
1190
1191static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
1192 u32 *rule_locs)
1193{
1194 struct qede_dev *edev = netdev_priv(dev);
1195 int rc = 0;
1196
1197 switch (info->cmd) {
1198 case ETHTOOL_GRXRINGS:
1199 info->data = QEDE_RSS_COUNT(edev);
1200 break;
1201 case ETHTOOL_GRXFH:
1202 rc = qede_get_rss_flags(edev, info);
1203 break;
1204 case ETHTOOL_GRXCLSRLCNT:
1205 info->rule_cnt = qede_get_arfs_filter_count(edev);
1206 info->data = QEDE_RFS_MAX_FLTR;
1207 break;
1208 case ETHTOOL_GRXCLSRULE:
1209 rc = qede_get_cls_rule_entry(edev, info);
1210 break;
1211 case ETHTOOL_GRXCLSRLALL:
1212 rc = qede_get_cls_rule_all(edev, info, rule_locs);
1213 break;
1214 default:
1215 DP_ERR(edev, "Command parameters not supported\n");
1216 rc = -EOPNOTSUPP;
1217 }
1218
1219 return rc;
1220}
1221
1222static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1223{
1224 struct qed_update_vport_params *vport_update_params;
1225 u8 set_caps = 0, clr_caps = 0;
1226 int rc = 0;
1227
1228 DP_VERBOSE(edev, QED_MSG_DEBUG,
1229 "Set rss flags command parameters: flow type = %d, data = %llu\n",
1230 info->flow_type, info->data);
1231
1232 switch (info->flow_type) {
1233 case TCP_V4_FLOW:
1234 case TCP_V6_FLOW:
1235
1236 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
1237 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1238 DP_INFO(edev, "Command parameters not supported\n");
1239 return -EINVAL;
1240 }
1241 return 0;
1242 case UDP_V4_FLOW:
1243
1244 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1245 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1246 set_caps = QED_RSS_IPV4_UDP;
1247 DP_VERBOSE(edev, QED_MSG_DEBUG,
1248 "UDP 4-tuple enabled\n");
1249 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1250 clr_caps = QED_RSS_IPV4_UDP;
1251 DP_VERBOSE(edev, QED_MSG_DEBUG,
1252 "UDP 4-tuple disabled\n");
1253 } else {
1254 return -EINVAL;
1255 }
1256 break;
1257 case UDP_V6_FLOW:
1258
1259 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1260 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1261 set_caps = QED_RSS_IPV6_UDP;
1262 DP_VERBOSE(edev, QED_MSG_DEBUG,
1263 "UDP 4-tuple enabled\n");
1264 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1265 clr_caps = QED_RSS_IPV6_UDP;
1266 DP_VERBOSE(edev, QED_MSG_DEBUG,
1267 "UDP 4-tuple disabled\n");
1268 } else {
1269 return -EINVAL;
1270 }
1271 break;
1272 case IPV4_FLOW:
1273 case IPV6_FLOW:
1274
1275 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1276 DP_INFO(edev, "Command parameters not supported\n");
1277 return -EINVAL;
1278 }
1279 return 0;
1280 case SCTP_V4_FLOW:
1281 case AH_ESP_V4_FLOW:
1282 case AH_V4_FLOW:
1283 case ESP_V4_FLOW:
1284 case SCTP_V6_FLOW:
1285 case AH_ESP_V6_FLOW:
1286 case AH_V6_FLOW:
1287 case ESP_V6_FLOW:
1288 case IP_USER_FLOW:
1289 case ETHER_FLOW:
1290
1291 if (info->data) {
1292 DP_INFO(edev, "Command parameters not supported\n");
1293 return -EINVAL;
1294 }
1295 return 0;
1296 default:
1297 return -EINVAL;
1298 }
1299
1300
1301 if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps))
1302 return 0;
1303
1304
1305 edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps);
1306 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1307
1308
1309 __qede_lock(edev);
1310 if (edev->state == QEDE_STATE_OPEN) {
1311 vport_update_params = vzalloc(sizeof(*vport_update_params));
1312 if (!vport_update_params) {
1313 __qede_unlock(edev);
1314 return -ENOMEM;
1315 }
1316 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1317 &vport_update_params->update_rss_flg);
1318 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1319 vfree(vport_update_params);
1320 }
1321 __qede_unlock(edev);
1322
1323 return rc;
1324}
1325
1326static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1327{
1328 struct qede_dev *edev = netdev_priv(dev);
1329 int rc;
1330
1331 switch (info->cmd) {
1332 case ETHTOOL_SRXFH:
1333 rc = qede_set_rss_flags(edev, info);
1334 break;
1335 case ETHTOOL_SRXCLSRLINS:
1336 rc = qede_add_cls_rule(edev, info);
1337 break;
1338 case ETHTOOL_SRXCLSRLDEL:
1339 rc = qede_delete_flow_filter(edev, info->fs.location);
1340 break;
1341 default:
1342 DP_INFO(edev, "Command parameters not supported\n");
1343 rc = -EOPNOTSUPP;
1344 }
1345
1346 return rc;
1347}
1348
1349static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1350{
1351 return QED_RSS_IND_TABLE_SIZE;
1352}
1353
1354static u32 qede_get_rxfh_key_size(struct net_device *dev)
1355{
1356 struct qede_dev *edev = netdev_priv(dev);
1357
1358 return sizeof(edev->rss_key);
1359}
1360
1361static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1362{
1363 struct qede_dev *edev = netdev_priv(dev);
1364 int i;
1365
1366 if (hfunc)
1367 *hfunc = ETH_RSS_HASH_TOP;
1368
1369 if (!indir)
1370 return 0;
1371
1372 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1373 indir[i] = edev->rss_ind_table[i];
1374
1375 if (key)
1376 memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev));
1377
1378 return 0;
1379}
1380
1381static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1382 const u8 *key, const u8 hfunc)
1383{
1384 struct qed_update_vport_params *vport_update_params;
1385 struct qede_dev *edev = netdev_priv(dev);
1386 int i, rc = 0;
1387
1388 if (edev->dev_info.common.num_hwfns > 1) {
1389 DP_INFO(edev,
1390 "RSS configuration is not supported for 100G devices\n");
1391 return -EOPNOTSUPP;
1392 }
1393
1394 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1395 return -EOPNOTSUPP;
1396
1397 if (!indir && !key)
1398 return 0;
1399
1400 if (indir) {
1401 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1402 edev->rss_ind_table[i] = indir[i];
1403 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1404 }
1405
1406 if (key) {
1407 memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev));
1408 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1409 }
1410
1411 __qede_lock(edev);
1412 if (edev->state == QEDE_STATE_OPEN) {
1413 vport_update_params = vzalloc(sizeof(*vport_update_params));
1414 if (!vport_update_params) {
1415 __qede_unlock(edev);
1416 return -ENOMEM;
1417 }
1418 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1419 &vport_update_params->update_rss_flg);
1420 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1421 vfree(vport_update_params);
1422 }
1423 __qede_unlock(edev);
1424
1425 return rc;
1426}
1427
1428
1429static void qede_netif_start(struct qede_dev *edev)
1430{
1431 int i;
1432
1433 if (!netif_running(edev->ndev))
1434 return;
1435
1436 for_each_queue(i) {
1437
1438 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1439 napi_enable(&edev->fp_array[i].napi);
1440 }
1441}
1442
1443
1444static void qede_netif_stop(struct qede_dev *edev)
1445{
1446 int i;
1447
1448 for_each_queue(i) {
1449 napi_disable(&edev->fp_array[i].napi);
1450
1451 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1452 }
1453}
1454
1455static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1456 struct sk_buff *skb)
1457{
1458 struct qede_tx_queue *txq = NULL;
1459 struct eth_tx_1st_bd *first_bd;
1460 dma_addr_t mapping;
1461 int i, idx;
1462 u16 val;
1463
1464 for_each_queue(i) {
1465 struct qede_fastpath *fp = &edev->fp_array[i];
1466
1467 if (fp->type & QEDE_FASTPATH_TX) {
1468 txq = QEDE_FP_TC0_TXQ(fp);
1469 break;
1470 }
1471 }
1472
1473 if (!txq) {
1474 DP_NOTICE(edev, "Tx path is not available\n");
1475 return -1;
1476 }
1477
1478
1479 idx = txq->sw_tx_prod;
1480 txq->sw_tx_ring.skbs[idx].skb = skb;
1481 first_bd = qed_chain_produce(&txq->tx_pbl);
1482 memset(first_bd, 0, sizeof(*first_bd));
1483 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1484 first_bd->data.bd_flags.bitfields = val;
1485 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1486 val = val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
1487 first_bd->data.bitfields |= cpu_to_le16(val);
1488
1489
1490 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1491 skb_headlen(skb), DMA_TO_DEVICE);
1492 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1493 DP_NOTICE(edev, "SKB mapping failed\n");
1494 return -ENOMEM;
1495 }
1496 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1497
1498
1499 first_bd->data.nbds = 1;
1500 txq->sw_tx_prod = (txq->sw_tx_prod + 1) % txq->num_tx_buffers;
1501
1502 val = qed_chain_get_prod_idx(&txq->tx_pbl);
1503 txq->tx_db.data.bd_prod = cpu_to_le16(val);
1504
1505
1506
1507
1508 wmb();
1509 barrier();
1510 writel(txq->tx_db.raw, txq->doorbell_addr);
1511
1512 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1513 if (qede_txq_has_work(txq))
1514 break;
1515 usleep_range(100, 200);
1516 }
1517
1518 if (!qede_txq_has_work(txq)) {
1519 DP_NOTICE(edev, "Tx completion didn't happen\n");
1520 return -1;
1521 }
1522
1523 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
1524 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1525 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
1526 txq->sw_tx_cons = (txq->sw_tx_cons + 1) % txq->num_tx_buffers;
1527 txq->sw_tx_ring.skbs[idx].skb = NULL;
1528
1529 return 0;
1530}
1531
1532static int qede_selftest_receive_traffic(struct qede_dev *edev)
1533{
1534 u16 sw_rx_index, len;
1535 struct eth_fast_path_rx_reg_cqe *fp_cqe;
1536 struct qede_rx_queue *rxq = NULL;
1537 struct sw_rx_data *sw_rx_data;
1538 union eth_rx_cqe *cqe;
1539 int i, iter, rc = 0;
1540 u8 *data_ptr;
1541
1542 for_each_queue(i) {
1543 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1544 rxq = edev->fp_array[i].rxq;
1545 break;
1546 }
1547 }
1548
1549 if (!rxq) {
1550 DP_NOTICE(edev, "Rx path is not available\n");
1551 return -1;
1552 }
1553
1554
1555
1556
1557
1558 for (iter = 0; iter < QEDE_SELFTEST_POLL_COUNT; iter++) {
1559 if (!qede_has_rx_work(rxq)) {
1560 usleep_range(100, 200);
1561 continue;
1562 }
1563
1564
1565 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1566
1567
1568 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1569 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1570 fp_cqe = &cqe->fast_path_regular;
1571 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1572 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1573 fp_cqe->placement_offset +
1574 sw_rx_data->page_offset +
1575 rxq->rx_headroom);
1576 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1577 ether_addr_equal(data_ptr + ETH_ALEN,
1578 edev->ndev->dev_addr)) {
1579 for (i = ETH_HLEN; i < len; i++)
1580 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1581 rc = -1;
1582 break;
1583 }
1584
1585 qede_recycle_rx_bd_ring(rxq, 1);
1586 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1587 break;
1588 }
1589
1590 DP_INFO(edev, "Not the transmitted packet\n");
1591 qede_recycle_rx_bd_ring(rxq, 1);
1592 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1593 }
1594
1595 if (iter == QEDE_SELFTEST_POLL_COUNT) {
1596 DP_NOTICE(edev, "Failed to receive the traffic\n");
1597 return -1;
1598 }
1599
1600 qede_update_rx_prod(edev, rxq);
1601
1602 return rc;
1603}
1604
1605static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1606{
1607 struct qed_link_params link_params;
1608 struct sk_buff *skb = NULL;
1609 int rc = 0, i;
1610 u32 pkt_size;
1611 u8 *packet;
1612
1613 if (!netif_running(edev->ndev)) {
1614 DP_NOTICE(edev, "Interface is down\n");
1615 return -EINVAL;
1616 }
1617
1618 qede_netif_stop(edev);
1619
1620
1621 memset(&link_params, 0, sizeof(link_params));
1622 link_params.link_up = true;
1623 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1624 link_params.loopback_mode = loopback_mode;
1625 edev->ops->common->set_link(edev->cdev, &link_params);
1626
1627
1628 msleep_interruptible(500);
1629
1630
1631
1632
1633 pkt_size = (((edev->ndev->mtu < ETH_DATA_LEN) ?
1634 edev->ndev->mtu : ETH_DATA_LEN) + ETH_HLEN);
1635
1636 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1637 if (!skb) {
1638 DP_INFO(edev, "Can't allocate skb\n");
1639 rc = -ENOMEM;
1640 goto test_loopback_exit;
1641 }
1642 packet = skb_put(skb, pkt_size);
1643 ether_addr_copy(packet, edev->ndev->dev_addr);
1644 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1645 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1646 for (i = ETH_HLEN; i < pkt_size; i++)
1647 packet[i] = (unsigned char)(i & 0xff);
1648
1649 rc = qede_selftest_transmit_traffic(edev, skb);
1650 if (rc)
1651 goto test_loopback_exit;
1652
1653 rc = qede_selftest_receive_traffic(edev);
1654 if (rc)
1655 goto test_loopback_exit;
1656
1657 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1658
1659test_loopback_exit:
1660 dev_kfree_skb(skb);
1661
1662
1663 memset(&link_params, 0, sizeof(link_params));
1664 link_params.link_up = true;
1665 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1666 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1667 edev->ops->common->set_link(edev->cdev, &link_params);
1668
1669
1670 msleep_interruptible(500);
1671
1672 qede_netif_start(edev);
1673
1674 return rc;
1675}
1676
1677static void qede_self_test(struct net_device *dev,
1678 struct ethtool_test *etest, u64 *buf)
1679{
1680 struct qede_dev *edev = netdev_priv(dev);
1681
1682 DP_VERBOSE(edev, QED_MSG_DEBUG,
1683 "Self-test command parameters: offline = %d, external_lb = %d\n",
1684 (etest->flags & ETH_TEST_FL_OFFLINE),
1685 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1686
1687 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1688
1689 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1690 if (qede_selftest_run_loopback(edev,
1691 QED_LINK_LOOPBACK_INT_PHY)) {
1692 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1693 etest->flags |= ETH_TEST_FL_FAILED;
1694 }
1695 }
1696
1697 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1698 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1699 etest->flags |= ETH_TEST_FL_FAILED;
1700 }
1701
1702 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1703 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1704 etest->flags |= ETH_TEST_FL_FAILED;
1705 }
1706
1707 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1708 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1709 etest->flags |= ETH_TEST_FL_FAILED;
1710 }
1711
1712 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1713 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1714 etest->flags |= ETH_TEST_FL_FAILED;
1715 }
1716
1717 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1718 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1719 etest->flags |= ETH_TEST_FL_FAILED;
1720 }
1721}
1722
1723static int qede_set_tunable(struct net_device *dev,
1724 const struct ethtool_tunable *tuna,
1725 const void *data)
1726{
1727 struct qede_dev *edev = netdev_priv(dev);
1728 u32 val;
1729
1730 switch (tuna->id) {
1731 case ETHTOOL_RX_COPYBREAK:
1732 val = *(u32 *)data;
1733 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1734 DP_VERBOSE(edev, QED_MSG_DEBUG,
1735 "Invalid rx copy break value, range is [%u, %u]",
1736 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1737 return -EINVAL;
1738 }
1739
1740 edev->rx_copybreak = *(u32 *)data;
1741 break;
1742 default:
1743 return -EOPNOTSUPP;
1744 }
1745
1746 return 0;
1747}
1748
1749static int qede_get_tunable(struct net_device *dev,
1750 const struct ethtool_tunable *tuna, void *data)
1751{
1752 struct qede_dev *edev = netdev_priv(dev);
1753
1754 switch (tuna->id) {
1755 case ETHTOOL_RX_COPYBREAK:
1756 *(u32 *)data = edev->rx_copybreak;
1757 break;
1758 default:
1759 return -EOPNOTSUPP;
1760 }
1761
1762 return 0;
1763}
1764
1765static int qede_get_eee(struct net_device *dev, struct ethtool_eee *edata)
1766{
1767 struct qede_dev *edev = netdev_priv(dev);
1768 struct qed_link_output current_link;
1769
1770 memset(¤t_link, 0, sizeof(current_link));
1771 edev->ops->common->get_link(edev->cdev, ¤t_link);
1772
1773 if (!current_link.eee_supported) {
1774 DP_INFO(edev, "EEE is not supported\n");
1775 return -EOPNOTSUPP;
1776 }
1777
1778 if (current_link.eee.adv_caps & QED_EEE_1G_ADV)
1779 edata->advertised = ADVERTISED_1000baseT_Full;
1780 if (current_link.eee.adv_caps & QED_EEE_10G_ADV)
1781 edata->advertised |= ADVERTISED_10000baseT_Full;
1782 if (current_link.sup_caps & QED_EEE_1G_ADV)
1783 edata->supported = ADVERTISED_1000baseT_Full;
1784 if (current_link.sup_caps & QED_EEE_10G_ADV)
1785 edata->supported |= ADVERTISED_10000baseT_Full;
1786 if (current_link.eee.lp_adv_caps & QED_EEE_1G_ADV)
1787 edata->lp_advertised = ADVERTISED_1000baseT_Full;
1788 if (current_link.eee.lp_adv_caps & QED_EEE_10G_ADV)
1789 edata->lp_advertised |= ADVERTISED_10000baseT_Full;
1790
1791 edata->tx_lpi_timer = current_link.eee.tx_lpi_timer;
1792 edata->eee_enabled = current_link.eee.enable;
1793 edata->tx_lpi_enabled = current_link.eee.tx_lpi_enable;
1794 edata->eee_active = current_link.eee_active;
1795
1796 return 0;
1797}
1798
1799static int qede_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1800{
1801 struct qede_dev *edev = netdev_priv(dev);
1802 struct qed_link_output current_link;
1803 struct qed_link_params params;
1804
1805 if (!edev->ops->common->can_link_change(edev->cdev)) {
1806 DP_INFO(edev, "Link settings are not allowed to be changed\n");
1807 return -EOPNOTSUPP;
1808 }
1809
1810 memset(¤t_link, 0, sizeof(current_link));
1811 edev->ops->common->get_link(edev->cdev, ¤t_link);
1812
1813 if (!current_link.eee_supported) {
1814 DP_INFO(edev, "EEE is not supported\n");
1815 return -EOPNOTSUPP;
1816 }
1817
1818 memset(¶ms, 0, sizeof(params));
1819 params.override_flags |= QED_LINK_OVERRIDE_EEE_CONFIG;
1820
1821 if (!(edata->advertised & (ADVERTISED_1000baseT_Full |
1822 ADVERTISED_10000baseT_Full)) ||
1823 ((edata->advertised & (ADVERTISED_1000baseT_Full |
1824 ADVERTISED_10000baseT_Full)) !=
1825 edata->advertised)) {
1826 DP_VERBOSE(edev, QED_MSG_DEBUG,
1827 "Invalid advertised capabilities %d\n",
1828 edata->advertised);
1829 return -EINVAL;
1830 }
1831
1832 if (edata->advertised & ADVERTISED_1000baseT_Full)
1833 params.eee.adv_caps = QED_EEE_1G_ADV;
1834 if (edata->advertised & ADVERTISED_10000baseT_Full)
1835 params.eee.adv_caps |= QED_EEE_10G_ADV;
1836 params.eee.enable = edata->eee_enabled;
1837 params.eee.tx_lpi_enable = edata->tx_lpi_enabled;
1838 params.eee.tx_lpi_timer = edata->tx_lpi_timer;
1839
1840 params.link_up = true;
1841 edev->ops->common->set_link(edev->cdev, ¶ms);
1842
1843 return 0;
1844}
1845
1846static u32 qede_link_to_ethtool_fec(u32 link_fec)
1847{
1848 u32 eth_fec = 0;
1849
1850 if (link_fec & QED_FEC_MODE_NONE)
1851 eth_fec |= ETHTOOL_FEC_OFF;
1852 if (link_fec & QED_FEC_MODE_FIRECODE)
1853 eth_fec |= ETHTOOL_FEC_BASER;
1854 if (link_fec & QED_FEC_MODE_RS)
1855 eth_fec |= ETHTOOL_FEC_RS;
1856 if (link_fec & QED_FEC_MODE_AUTO)
1857 eth_fec |= ETHTOOL_FEC_AUTO;
1858 if (link_fec & QED_FEC_MODE_UNSUPPORTED)
1859 eth_fec |= ETHTOOL_FEC_NONE;
1860
1861 return eth_fec;
1862}
1863
1864static u32 qede_ethtool_to_link_fec(u32 eth_fec)
1865{
1866 u32 link_fec = 0;
1867
1868 if (eth_fec & ETHTOOL_FEC_OFF)
1869 link_fec |= QED_FEC_MODE_NONE;
1870 if (eth_fec & ETHTOOL_FEC_BASER)
1871 link_fec |= QED_FEC_MODE_FIRECODE;
1872 if (eth_fec & ETHTOOL_FEC_RS)
1873 link_fec |= QED_FEC_MODE_RS;
1874 if (eth_fec & ETHTOOL_FEC_AUTO)
1875 link_fec |= QED_FEC_MODE_AUTO;
1876 if (eth_fec & ETHTOOL_FEC_NONE)
1877 link_fec |= QED_FEC_MODE_UNSUPPORTED;
1878
1879 return link_fec;
1880}
1881
1882static int qede_get_fecparam(struct net_device *dev,
1883 struct ethtool_fecparam *fecparam)
1884{
1885 struct qede_dev *edev = netdev_priv(dev);
1886 struct qed_link_output curr_link;
1887
1888 memset(&curr_link, 0, sizeof(curr_link));
1889 edev->ops->common->get_link(edev->cdev, &curr_link);
1890
1891 fecparam->active_fec = qede_link_to_ethtool_fec(curr_link.active_fec);
1892 fecparam->fec = qede_link_to_ethtool_fec(curr_link.sup_fec);
1893
1894 return 0;
1895}
1896
1897static int qede_set_fecparam(struct net_device *dev,
1898 struct ethtool_fecparam *fecparam)
1899{
1900 struct qede_dev *edev = netdev_priv(dev);
1901 struct qed_link_params params;
1902
1903 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
1904 DP_INFO(edev, "Link settings are not allowed to be changed\n");
1905 return -EOPNOTSUPP;
1906 }
1907
1908 memset(¶ms, 0, sizeof(params));
1909 params.override_flags |= QED_LINK_OVERRIDE_FEC_CONFIG;
1910 params.fec = qede_ethtool_to_link_fec(fecparam->fec);
1911 params.link_up = true;
1912
1913 edev->ops->common->set_link(edev->cdev, ¶ms);
1914
1915 return 0;
1916}
1917
1918static int qede_get_module_info(struct net_device *dev,
1919 struct ethtool_modinfo *modinfo)
1920{
1921 struct qede_dev *edev = netdev_priv(dev);
1922 u8 buf[4];
1923 int rc;
1924
1925
1926 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1927 QED_I2C_DEV_ADDR_A0, 0, 4);
1928 if (rc) {
1929 DP_ERR(edev, "Failed reading EEPROM data %d\n", rc);
1930 return rc;
1931 }
1932
1933 switch (buf[0]) {
1934 case 0x3:
1935 modinfo->type = ETH_MODULE_SFF_8472;
1936 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1937 break;
1938 case 0xc:
1939 case 0xd:
1940 modinfo->type = ETH_MODULE_SFF_8436;
1941 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1942 break;
1943 case 0x11:
1944 modinfo->type = ETH_MODULE_SFF_8636;
1945 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1946 break;
1947 default:
1948 DP_ERR(edev, "Unknown transceiver type 0x%x\n", buf[0]);
1949 return -EINVAL;
1950 }
1951
1952 return 0;
1953}
1954
1955static int qede_get_module_eeprom(struct net_device *dev,
1956 struct ethtool_eeprom *ee, u8 *data)
1957{
1958 struct qede_dev *edev = netdev_priv(dev);
1959 u32 start_addr = ee->offset, size = 0;
1960 u8 *buf = data;
1961 int rc = 0;
1962
1963
1964 if (ee->offset < ETH_MODULE_SFF_8079_LEN) {
1965
1966 if (ee->offset + ee->len > ETH_MODULE_SFF_8079_LEN)
1967 size = ETH_MODULE_SFF_8079_LEN - ee->offset;
1968 else
1969 size = ee->len;
1970
1971 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1972 QED_I2C_DEV_ADDR_A0,
1973 start_addr, size);
1974 if (rc) {
1975 DP_ERR(edev, "Failed reading A0 section %d\n", rc);
1976 return rc;
1977 }
1978
1979 buf += size;
1980 start_addr += size;
1981 }
1982
1983
1984 if (start_addr >= ETH_MODULE_SFF_8079_LEN &&
1985 start_addr < ETH_MODULE_SFF_8472_LEN) {
1986 size = ee->len - size;
1987
1988 if (start_addr + size > ETH_MODULE_SFF_8472_LEN)
1989 size = ETH_MODULE_SFF_8472_LEN - start_addr;
1990 start_addr -= ETH_MODULE_SFF_8079_LEN;
1991 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1992 QED_I2C_DEV_ADDR_A2,
1993 start_addr, size);
1994 if (rc) {
1995 DP_VERBOSE(edev, QED_MSG_DEBUG,
1996 "Failed reading A2 section %d\n", rc);
1997 return 0;
1998 }
1999 }
2000
2001 return rc;
2002}
2003
2004static int qede_set_dump(struct net_device *dev, struct ethtool_dump *val)
2005{
2006 struct qede_dev *edev = netdev_priv(dev);
2007 int rc = 0;
2008
2009 if (edev->dump_info.cmd == QEDE_DUMP_CMD_NONE) {
2010 if (val->flag > QEDE_DUMP_CMD_MAX) {
2011 DP_ERR(edev, "Invalid command %d\n", val->flag);
2012 return -EINVAL;
2013 }
2014 edev->dump_info.cmd = val->flag;
2015 edev->dump_info.num_args = 0;
2016 return 0;
2017 }
2018
2019 if (edev->dump_info.num_args == QEDE_DUMP_MAX_ARGS) {
2020 DP_ERR(edev, "Arg count = %d\n", edev->dump_info.num_args);
2021 return -EINVAL;
2022 }
2023
2024 switch (edev->dump_info.cmd) {
2025 case QEDE_DUMP_CMD_NVM_CFG:
2026 edev->dump_info.args[edev->dump_info.num_args] = val->flag;
2027 edev->dump_info.num_args++;
2028 break;
2029 case QEDE_DUMP_CMD_GRCDUMP:
2030 rc = edev->ops->common->set_grc_config(edev->cdev,
2031 val->flag, 1);
2032 break;
2033 default:
2034 break;
2035 }
2036
2037 return rc;
2038}
2039
2040static int qede_get_dump_flag(struct net_device *dev,
2041 struct ethtool_dump *dump)
2042{
2043 struct qede_dev *edev = netdev_priv(dev);
2044
2045 if (!edev->ops || !edev->ops->common) {
2046 DP_ERR(edev, "Edev ops not populated\n");
2047 return -EINVAL;
2048 }
2049
2050 dump->version = QEDE_DUMP_VERSION;
2051 switch (edev->dump_info.cmd) {
2052 case QEDE_DUMP_CMD_NVM_CFG:
2053 dump->flag = QEDE_DUMP_CMD_NVM_CFG;
2054 dump->len = edev->ops->common->read_nvm_cfg_len(edev->cdev,
2055 edev->dump_info.args[0]);
2056 break;
2057 case QEDE_DUMP_CMD_GRCDUMP:
2058 dump->flag = QEDE_DUMP_CMD_GRCDUMP;
2059 dump->len = edev->ops->common->dbg_all_data_size(edev->cdev);
2060 break;
2061 default:
2062 DP_ERR(edev, "Invalid cmd = %d\n", edev->dump_info.cmd);
2063 return -EINVAL;
2064 }
2065
2066 DP_VERBOSE(edev, QED_MSG_DEBUG,
2067 "dump->version = 0x%x dump->flag = %d dump->len = %d\n",
2068 dump->version, dump->flag, dump->len);
2069 return 0;
2070}
2071
2072static int qede_get_dump_data(struct net_device *dev,
2073 struct ethtool_dump *dump, void *buf)
2074{
2075 struct qede_dev *edev = netdev_priv(dev);
2076 int rc = 0;
2077
2078 if (!edev->ops || !edev->ops->common) {
2079 DP_ERR(edev, "Edev ops not populated\n");
2080 rc = -EINVAL;
2081 goto err;
2082 }
2083
2084 switch (edev->dump_info.cmd) {
2085 case QEDE_DUMP_CMD_NVM_CFG:
2086 if (edev->dump_info.num_args != QEDE_DUMP_NVM_ARG_COUNT) {
2087 DP_ERR(edev, "Arg count = %d required = %d\n",
2088 edev->dump_info.num_args,
2089 QEDE_DUMP_NVM_ARG_COUNT);
2090 rc = -EINVAL;
2091 goto err;
2092 }
2093 rc = edev->ops->common->read_nvm_cfg(edev->cdev, (u8 **)&buf,
2094 edev->dump_info.args[0],
2095 edev->dump_info.args[1]);
2096 break;
2097 case QEDE_DUMP_CMD_GRCDUMP:
2098 memset(buf, 0, dump->len);
2099 rc = edev->ops->common->dbg_all_data(edev->cdev, buf);
2100 break;
2101 default:
2102 DP_ERR(edev, "Invalid cmd = %d\n", edev->dump_info.cmd);
2103 rc = -EINVAL;
2104 break;
2105 }
2106
2107err:
2108 edev->dump_info.cmd = QEDE_DUMP_CMD_NONE;
2109 edev->dump_info.num_args = 0;
2110 memset(edev->dump_info.args, 0, sizeof(edev->dump_info.args));
2111
2112 return rc;
2113}
2114
2115int qede_set_per_coalesce(struct net_device *dev, u32 queue,
2116 struct ethtool_coalesce *coal)
2117{
2118 struct qede_dev *edev = netdev_priv(dev);
2119 struct qede_fastpath *fp;
2120 u16 rxc, txc;
2121 int rc = 0;
2122
2123 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
2124 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
2125 DP_INFO(edev,
2126 "Can't support requested %s coalesce value [max supported value %d]\n",
2127 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
2128 : "tx",
2129 QED_COALESCE_MAX);
2130 return -EINVAL;
2131 }
2132
2133 rxc = (u16)coal->rx_coalesce_usecs;
2134 txc = (u16)coal->tx_coalesce_usecs;
2135
2136 __qede_lock(edev);
2137 if (queue >= edev->num_queues) {
2138 DP_INFO(edev, "Invalid queue\n");
2139 rc = -EINVAL;
2140 goto out;
2141 }
2142
2143 if (edev->state != QEDE_STATE_OPEN) {
2144 rc = -EINVAL;
2145 goto out;
2146 }
2147
2148 fp = &edev->fp_array[queue];
2149
2150 if (edev->fp_array[queue].type & QEDE_FASTPATH_RX) {
2151 rc = edev->ops->common->set_coalesce(edev->cdev,
2152 rxc, 0,
2153 fp->rxq->handle);
2154 if (rc) {
2155 DP_INFO(edev,
2156 "Set RX coalesce error, rc = %d\n", rc);
2157 goto out;
2158 }
2159 edev->coal_entry[queue].rxc = rxc;
2160 edev->coal_entry[queue].isvalid = true;
2161 }
2162
2163 if (edev->fp_array[queue].type & QEDE_FASTPATH_TX) {
2164 rc = edev->ops->common->set_coalesce(edev->cdev,
2165 0, txc,
2166 fp->txq->handle);
2167 if (rc) {
2168 DP_INFO(edev,
2169 "Set TX coalesce error, rc = %d\n", rc);
2170 goto out;
2171 }
2172 edev->coal_entry[queue].txc = txc;
2173 edev->coal_entry[queue].isvalid = true;
2174 }
2175out:
2176 __qede_unlock(edev);
2177
2178 return rc;
2179}
2180
2181static int qede_get_per_coalesce(struct net_device *dev,
2182 u32 queue,
2183 struct ethtool_coalesce *coal)
2184{
2185 void *rx_handle = NULL, *tx_handle = NULL;
2186 struct qede_dev *edev = netdev_priv(dev);
2187 struct qede_fastpath *fp;
2188 u16 rx_coal, tx_coal;
2189 int rc = 0;
2190
2191 rx_coal = QED_DEFAULT_RX_USECS;
2192 tx_coal = QED_DEFAULT_TX_USECS;
2193
2194 memset(coal, 0, sizeof(struct ethtool_coalesce));
2195
2196 __qede_lock(edev);
2197 if (queue >= edev->num_queues) {
2198 DP_INFO(edev, "Invalid queue\n");
2199 rc = -EINVAL;
2200 goto out;
2201 }
2202
2203 if (edev->state != QEDE_STATE_OPEN) {
2204 rc = -EINVAL;
2205 goto out;
2206 }
2207
2208 fp = &edev->fp_array[queue];
2209
2210 if (fp->type & QEDE_FASTPATH_RX)
2211 rx_handle = fp->rxq->handle;
2212
2213 rc = edev->ops->get_coalesce(edev->cdev, &rx_coal,
2214 rx_handle);
2215 if (rc) {
2216 DP_INFO(edev, "Read Rx coalesce error\n");
2217 goto out;
2218 }
2219
2220 fp = &edev->fp_array[queue];
2221 if (fp->type & QEDE_FASTPATH_TX)
2222 tx_handle = fp->txq->handle;
2223
2224 rc = edev->ops->get_coalesce(edev->cdev, &tx_coal,
2225 tx_handle);
2226 if (rc)
2227 DP_INFO(edev, "Read Tx coalesce error\n");
2228
2229out:
2230 __qede_unlock(edev);
2231
2232 coal->rx_coalesce_usecs = rx_coal;
2233 coal->tx_coalesce_usecs = tx_coal;
2234
2235 return rc;
2236}
2237
2238static const struct ethtool_ops qede_ethtool_ops = {
2239 .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
2240 .get_link_ksettings = qede_get_link_ksettings,
2241 .set_link_ksettings = qede_set_link_ksettings,
2242 .get_drvinfo = qede_get_drvinfo,
2243 .get_regs_len = qede_get_regs_len,
2244 .get_regs = qede_get_regs,
2245 .get_wol = qede_get_wol,
2246 .set_wol = qede_set_wol,
2247 .get_msglevel = qede_get_msglevel,
2248 .set_msglevel = qede_set_msglevel,
2249 .nway_reset = qede_nway_reset,
2250 .get_link = qede_get_link,
2251 .get_coalesce = qede_get_coalesce,
2252 .set_coalesce = qede_set_coalesce,
2253 .get_ringparam = qede_get_ringparam,
2254 .set_ringparam = qede_set_ringparam,
2255 .get_pauseparam = qede_get_pauseparam,
2256 .set_pauseparam = qede_set_pauseparam,
2257 .get_strings = qede_get_strings,
2258 .set_phys_id = qede_set_phys_id,
2259 .get_ethtool_stats = qede_get_ethtool_stats,
2260 .get_priv_flags = qede_get_priv_flags,
2261 .set_priv_flags = qede_set_priv_flags,
2262 .get_sset_count = qede_get_sset_count,
2263 .get_rxnfc = qede_get_rxnfc,
2264 .set_rxnfc = qede_set_rxnfc,
2265 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
2266 .get_rxfh_key_size = qede_get_rxfh_key_size,
2267 .get_rxfh = qede_get_rxfh,
2268 .set_rxfh = qede_set_rxfh,
2269 .get_ts_info = qede_get_ts_info,
2270 .get_channels = qede_get_channels,
2271 .set_channels = qede_set_channels,
2272 .self_test = qede_self_test,
2273 .get_module_info = qede_get_module_info,
2274 .get_module_eeprom = qede_get_module_eeprom,
2275 .get_eee = qede_get_eee,
2276 .set_eee = qede_set_eee,
2277 .get_fecparam = qede_get_fecparam,
2278 .set_fecparam = qede_set_fecparam,
2279 .get_tunable = qede_get_tunable,
2280 .set_tunable = qede_set_tunable,
2281 .get_per_queue_coalesce = qede_get_per_coalesce,
2282 .set_per_queue_coalesce = qede_set_per_coalesce,
2283 .flash_device = qede_flash_device,
2284 .get_dump_flag = qede_get_dump_flag,
2285 .get_dump_data = qede_get_dump_data,
2286 .set_dump = qede_set_dump,
2287};
2288
2289static const struct ethtool_ops qede_vf_ethtool_ops = {
2290 .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
2291 .get_link_ksettings = qede_get_link_ksettings,
2292 .get_drvinfo = qede_get_drvinfo,
2293 .get_msglevel = qede_get_msglevel,
2294 .set_msglevel = qede_set_msglevel,
2295 .get_link = qede_get_link,
2296 .get_coalesce = qede_get_coalesce,
2297 .set_coalesce = qede_set_coalesce,
2298 .get_ringparam = qede_get_ringparam,
2299 .set_ringparam = qede_set_ringparam,
2300 .get_strings = qede_get_strings,
2301 .get_ethtool_stats = qede_get_ethtool_stats,
2302 .get_priv_flags = qede_get_priv_flags,
2303 .get_sset_count = qede_get_sset_count,
2304 .get_rxnfc = qede_get_rxnfc,
2305 .set_rxnfc = qede_set_rxnfc,
2306 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
2307 .get_rxfh_key_size = qede_get_rxfh_key_size,
2308 .get_rxfh = qede_get_rxfh,
2309 .set_rxfh = qede_set_rxfh,
2310 .get_channels = qede_get_channels,
2311 .set_channels = qede_set_channels,
2312 .get_per_queue_coalesce = qede_get_per_coalesce,
2313 .set_per_queue_coalesce = qede_set_per_coalesce,
2314 .get_tunable = qede_get_tunable,
2315 .set_tunable = qede_set_tunable,
2316};
2317
2318void qede_set_ethtool_ops(struct net_device *dev)
2319{
2320 struct qede_dev *edev = netdev_priv(dev);
2321
2322 if (IS_VF(edev))
2323 dev->ethtool_ops = &qede_vf_ethtool_ops;
2324 else
2325 dev->ethtool_ops = &qede_ethtool_ops;
2326}
2327