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.
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>
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)}
27 #define QEDE_SELFTEST_POLL_COUNT 100
28 #define QEDE_DUMP_VERSION 0x1
29 #define QEDE_DUMP_NVM_ARG_COUNT 2
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),
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)
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),
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), \
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))
80 char string[ETH_GSTRING_LEN];
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),
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),
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),
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),
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),
155 QEDE_STAT(link_change_count),
156 QEDE_STAT(ptp_skip_txts),
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)
169 QEDE_PRI_FLAG_SMART_AN_SUPPORT, /* MFW supports SmartAN */
170 QEDE_PRI_FLAG_RECOVER_ON_ERROR,
174 static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
180 enum qede_ethtool_tests {
181 QEDE_ETHTOOL_INT_LOOPBACK,
182 QEDE_ETHTOOL_INTERRUPT_TEST,
183 QEDE_ETHTOOL_MEMORY_TEST,
184 QEDE_ETHTOOL_REGISTER_TEST,
185 QEDE_ETHTOOL_CLOCK_TEST,
186 QEDE_ETHTOOL_NVRAM_TEST,
187 QEDE_ETHTOOL_TEST_MAX
190 static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
191 "Internal loopback (offline)",
192 "Interrupt (online)\t",
193 "Memory (online)\t\t",
194 "Register (online)\t",
195 "Clock (online)\t\t",
196 "Nvram (online)\t\t",
199 /* Forced speed capabilities maps */
201 struct qede_forced_speed_map {
203 __ETHTOOL_DECLARE_LINK_MODE_MASK(caps);
209 #define QEDE_FORCED_SPEED_MAP(value) \
211 .speed = SPEED_##value, \
212 .cap_arr = qede_forced_speed_##value, \
213 .arr_size = ARRAY_SIZE(qede_forced_speed_##value), \
216 static const u32 qede_forced_speed_1000[] __initconst = {
217 ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
218 ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
219 ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
222 static const u32 qede_forced_speed_10000[] __initconst = {
223 ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
224 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
225 ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
226 ETHTOOL_LINK_MODE_10000baseR_FEC_BIT,
227 ETHTOOL_LINK_MODE_10000baseCR_Full_BIT,
228 ETHTOOL_LINK_MODE_10000baseSR_Full_BIT,
229 ETHTOOL_LINK_MODE_10000baseLR_Full_BIT,
230 ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT,
233 static const u32 qede_forced_speed_20000[] __initconst = {
234 ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT,
237 static const u32 qede_forced_speed_25000[] __initconst = {
238 ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
239 ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
240 ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
243 static const u32 qede_forced_speed_40000[] __initconst = {
244 ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT,
245 ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT,
246 ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
247 ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT,
250 static const u32 qede_forced_speed_50000[] __initconst = {
251 ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT,
252 ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT,
253 ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT,
256 static const u32 qede_forced_speed_100000[] __initconst = {
257 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
258 ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT,
259 ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
260 ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT,
263 static struct qede_forced_speed_map qede_forced_speed_maps[] __ro_after_init = {
264 QEDE_FORCED_SPEED_MAP(1000),
265 QEDE_FORCED_SPEED_MAP(10000),
266 QEDE_FORCED_SPEED_MAP(20000),
267 QEDE_FORCED_SPEED_MAP(25000),
268 QEDE_FORCED_SPEED_MAP(40000),
269 QEDE_FORCED_SPEED_MAP(50000),
270 QEDE_FORCED_SPEED_MAP(100000),
273 void __init qede_forced_speed_maps_init(void)
275 struct qede_forced_speed_map *map;
278 for (i = 0; i < ARRAY_SIZE(qede_forced_speed_maps); i++) {
279 map = qede_forced_speed_maps + i;
281 linkmode_set_bit_array(map->cap_arr, map->arr_size, map->caps);
287 /* Ethtool callbacks */
289 static void qede_get_strings_stats_txq(struct qede_dev *edev,
290 struct qede_tx_queue *txq, u8 **buf)
294 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
296 sprintf(*buf, "%d [XDP]: %s",
297 QEDE_TXQ_XDP_TO_IDX(edev, txq),
298 qede_tqstats_arr[i].string);
300 sprintf(*buf, "%d_%d: %s", txq->index, txq->cos,
301 qede_tqstats_arr[i].string);
302 *buf += ETH_GSTRING_LEN;
306 static void qede_get_strings_stats_rxq(struct qede_dev *edev,
307 struct qede_rx_queue *rxq, u8 **buf)
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;
318 static bool qede_is_irrelevant_stat(struct qede_dev *edev, int stat_index)
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));
325 static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
327 struct qede_fastpath *fp;
330 /* Account for queue statistics */
331 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
332 fp = &edev->fp_array[i];
334 if (fp->type & QEDE_FASTPATH_RX)
335 qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
337 if (fp->type & QEDE_FASTPATH_XDP)
338 qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf);
340 if (fp->type & QEDE_FASTPATH_TX) {
343 for_each_cos_in_txq(edev, cos)
344 qede_get_strings_stats_txq(edev,
345 &fp->txq[cos], &buf);
349 /* Account for non-queue statistics */
350 for (i = 0; i < QEDE_NUM_STATS; i++) {
351 if (qede_is_irrelevant_stat(edev, i))
353 strcpy(buf, qede_stats_arr[i].string);
354 buf += ETH_GSTRING_LEN;
358 static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
360 struct qede_dev *edev = netdev_priv(dev);
364 qede_get_strings_stats(edev, buf);
366 case ETH_SS_PRIV_FLAGS:
367 memcpy(buf, qede_private_arr,
368 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
371 memcpy(buf, qede_tests_str_arr,
372 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
375 DP_VERBOSE(edev, QED_MSG_DEBUG,
376 "Unsupported stringset 0x%08x\n", stringset);
380 static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
384 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
385 **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
390 static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
394 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
395 **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
400 static void qede_get_ethtool_stats(struct net_device *dev,
401 struct ethtool_stats *stats, u64 *buf)
403 struct qede_dev *edev = netdev_priv(dev);
404 struct qede_fastpath *fp;
407 qede_fill_by_demand_stats(edev);
409 /* Need to protect the access to the fastpath array */
412 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
413 fp = &edev->fp_array[i];
415 if (fp->type & QEDE_FASTPATH_RX)
416 qede_get_ethtool_stats_rxq(fp->rxq, &buf);
418 if (fp->type & QEDE_FASTPATH_XDP)
419 qede_get_ethtool_stats_txq(fp->xdp_tx, &buf);
421 if (fp->type & QEDE_FASTPATH_TX) {
424 for_each_cos_in_txq(edev, cos)
425 qede_get_ethtool_stats_txq(&fp->txq[cos], &buf);
429 for (i = 0; i < QEDE_NUM_STATS; i++) {
430 if (qede_is_irrelevant_stat(edev, i))
432 *buf = *((u64 *)(((void *)&edev->stats) +
433 qede_stats_arr[i].offset));
441 static int qede_get_sset_count(struct net_device *dev, int stringset)
443 struct qede_dev *edev = netdev_priv(dev);
444 int num_stats = QEDE_NUM_STATS, i;
448 for (i = 0; i < QEDE_NUM_STATS; i++)
449 if (qede_is_irrelevant_stat(edev, i))
452 /* Account for the Regular Tx statistics */
453 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS *
454 edev->dev_info.num_tc;
456 /* Account for the Regular Rx statistics */
457 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
459 /* Account for XDP statistics [if needed] */
461 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS;
464 case ETH_SS_PRIV_FLAGS:
465 return QEDE_PRI_FLAG_LEN;
468 return QEDE_ETHTOOL_TEST_MAX;
472 DP_VERBOSE(edev, QED_MSG_DEBUG,
473 "Unsupported stringset 0x%08x\n", stringset);
478 static u32 qede_get_priv_flags(struct net_device *dev)
480 struct qede_dev *edev = netdev_priv(dev);
483 if (edev->dev_info.common.num_hwfns > 1)
484 flags |= BIT(QEDE_PRI_FLAG_CMT);
486 if (edev->dev_info.common.smart_an)
487 flags |= BIT(QEDE_PRI_FLAG_SMART_AN_SUPPORT);
489 if (edev->err_flags & BIT(QEDE_ERR_IS_RECOVERABLE))
490 flags |= BIT(QEDE_PRI_FLAG_RECOVER_ON_ERROR);
495 static int qede_set_priv_flags(struct net_device *dev, u32 flags)
497 struct qede_dev *edev = netdev_priv(dev);
498 u32 cflags = qede_get_priv_flags(dev);
499 u32 dflags = flags ^ cflags;
501 /* can only change RECOVER_ON_ERROR flag */
502 if (dflags & ~BIT(QEDE_PRI_FLAG_RECOVER_ON_ERROR))
505 if (flags & BIT(QEDE_PRI_FLAG_RECOVER_ON_ERROR))
506 set_bit(QEDE_ERR_IS_RECOVERABLE, &edev->err_flags);
508 clear_bit(QEDE_ERR_IS_RECOVERABLE, &edev->err_flags);
513 static int qede_get_link_ksettings(struct net_device *dev,
514 struct ethtool_link_ksettings *cmd)
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;
523 memset(¤t_link, 0, sizeof(current_link));
524 edev->ops->common->get_link(edev->cdev, ¤t_link);
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);
530 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
531 base->speed = current_link.speed;
532 base->duplex = current_link.duplex;
534 base->speed = SPEED_UNKNOWN;
535 base->duplex = DUPLEX_UNKNOWN;
540 base->port = current_link.port;
541 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
547 static int qede_set_link_ksettings(struct net_device *dev,
548 const struct ethtool_link_ksettings *cmd)
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;
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");
561 memset(¤t_link, 0, sizeof(current_link));
562 memset(¶ms, 0, sizeof(params));
563 edev->ops->common->get_link(edev->cdev, ¤t_link);
565 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
566 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
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");
574 params.autoneg = true;
575 params.forced_speed = 0;
577 linkmode_copy(params.adv_speeds, cmd->link_modes.advertising);
578 } else { /* forced speed */
579 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
580 params.autoneg = false;
581 params.forced_speed = base->speed;
583 for (i = 0; i < ARRAY_SIZE(qede_forced_speed_maps); i++) {
584 map = qede_forced_speed_maps + i;
586 if (base->speed != map->speed ||
587 !linkmode_intersects(current_link.supported_caps,
591 linkmode_and(params.adv_speeds,
592 current_link.supported_caps, map->caps);
596 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
601 params.link_up = true;
602 edev->ops->common->set_link(edev->cdev, ¶ms);
607 static void qede_get_drvinfo(struct net_device *ndev,
608 struct ethtool_drvinfo *info)
610 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
611 struct qede_dev *edev = netdev_priv(ndev);
612 char mbi[ETHTOOL_FWVERS_LEN];
614 strlcpy(info->driver, "qede", sizeof(info->driver));
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);
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);
628 if ((strlen(storm) + strlen("[storm]")) <
629 sizeof(info->version))
630 snprintf(info->version, sizeof(info->version),
631 "[storm %s]", storm);
633 snprintf(info->version, sizeof(info->version),
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);
647 snprintf(info->fw_version, sizeof(info->fw_version),
651 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
654 static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
656 struct qede_dev *edev = netdev_priv(ndev);
658 if (edev->dev_info.common.wol_support) {
659 wol->supported = WAKE_MAGIC;
660 wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
664 static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
666 struct qede_dev *edev = netdev_priv(ndev);
670 if (wol->wolopts & ~WAKE_MAGIC) {
672 "Can't support WoL options other than magic-packet\n");
676 wol_requested = !!(wol->wolopts & WAKE_MAGIC);
677 if (wol_requested == edev->wol_enabled)
680 /* Need to actually change configuration */
681 if (!edev->dev_info.common.wol_support) {
682 DP_INFO(edev, "Device doesn't support WoL\n");
686 rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
688 edev->wol_enabled = wol_requested;
693 static u32 qede_get_msglevel(struct net_device *ndev)
695 struct qede_dev *edev = netdev_priv(ndev);
697 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
700 static void qede_set_msglevel(struct net_device *ndev, u32 level)
702 struct qede_dev *edev = netdev_priv(ndev);
706 qede_config_debug(level, &dp_module, &dp_level);
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);
714 static int qede_nway_reset(struct net_device *dev)
716 struct qede_dev *edev = netdev_priv(dev);
717 struct qed_link_output current_link;
718 struct qed_link_params link_params;
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");
725 if (!netif_running(dev))
728 memset(¤t_link, 0, sizeof(current_link));
729 edev->ops->common->get_link(edev->cdev, ¤t_link);
730 if (!current_link.link_up)
733 /* Toggle the link */
734 memset(&link_params, 0, sizeof(link_params));
735 link_params.link_up = false;
736 edev->ops->common->set_link(edev->cdev, &link_params);
737 link_params.link_up = true;
738 edev->ops->common->set_link(edev->cdev, &link_params);
743 static u32 qede_get_link(struct net_device *dev)
745 struct qede_dev *edev = netdev_priv(dev);
746 struct qed_link_output current_link;
748 memset(¤t_link, 0, sizeof(current_link));
749 edev->ops->common->get_link(edev->cdev, ¤t_link);
751 return current_link.link_up;
754 static int qede_flash_device(struct net_device *dev,
755 struct ethtool_flash *flash)
757 struct qede_dev *edev = netdev_priv(dev);
759 return edev->ops->common->nvm_flash(edev->cdev, flash->data);
762 static int qede_get_coalesce(struct net_device *dev,
763 struct ethtool_coalesce *coal,
764 struct kernel_ethtool_coalesce *kernel_coal,
765 struct netlink_ext_ack *extack)
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;
772 rx_coal = QED_DEFAULT_RX_USECS;
773 tx_coal = QED_DEFAULT_TX_USECS;
775 memset(coal, 0, sizeof(struct ethtool_coalesce));
778 if (edev->state == QEDE_STATE_OPEN) {
780 fp = &edev->fp_array[i];
782 if (fp->type & QEDE_FASTPATH_RX) {
783 rx_handle = fp->rxq->handle;
788 rc = edev->ops->get_coalesce(edev->cdev, &rx_coal, rx_handle);
790 DP_INFO(edev, "Read Rx coalesce error\n");
795 struct qede_tx_queue *txq;
797 fp = &edev->fp_array[i];
799 /* All TX queues of given fastpath uses same
800 * coalescing value, so no need to iterate over
801 * all TCs, TC0 txq should suffice.
803 if (fp->type & QEDE_FASTPATH_TX) {
804 txq = QEDE_FP_TC0_TXQ(fp);
805 tx_handle = txq->handle;
810 rc = edev->ops->get_coalesce(edev->cdev, &tx_coal, tx_handle);
812 DP_INFO(edev, "Read Tx coalesce error\n");
818 coal->rx_coalesce_usecs = rx_coal;
819 coal->tx_coalesce_usecs = tx_coal;
824 int qede_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal,
825 struct kernel_ethtool_coalesce *kernel_coal,
826 struct netlink_ext_ack *extack)
828 struct qede_dev *edev = netdev_priv(dev);
829 struct qede_fastpath *fp;
833 if (!netif_running(dev)) {
834 DP_INFO(edev, "Interface is down\n");
838 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
839 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
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);
847 rxc = (u16)coal->rx_coalesce_usecs;
848 txc = (u16)coal->tx_coalesce_usecs;
850 fp = &edev->fp_array[i];
852 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
853 rc = edev->ops->common->set_coalesce(edev->cdev,
858 "Set RX coalesce error, rc = %d\n", rc);
861 edev->coal_entry[i].rxc = rxc;
862 edev->coal_entry[i].isvalid = true;
865 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
866 struct qede_tx_queue *txq;
868 /* All TX queues of given fastpath uses same
869 * coalescing value, so no need to iterate over
870 * all TCs, TC0 txq should suffice.
872 txq = QEDE_FP_TC0_TXQ(fp);
874 rc = edev->ops->common->set_coalesce(edev->cdev,
879 "Set TX coalesce error, rc = %d\n", rc);
882 edev->coal_entry[i].txc = txc;
883 edev->coal_entry[i].isvalid = true;
890 static void qede_get_ringparam(struct net_device *dev,
891 struct ethtool_ringparam *ering)
893 struct qede_dev *edev = netdev_priv(dev);
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;
901 static int qede_set_ringparam(struct net_device *dev,
902 struct ethtool_ringparam *ering)
904 struct qede_dev *edev = netdev_priv(dev);
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);
910 /* Validate legality of configuration */
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);
922 /* Change ring size and re-load */
923 edev->q_num_rx_buffers = ering->rx_pending;
924 edev->q_num_tx_buffers = ering->tx_pending;
926 qede_reload(edev, NULL, false);
931 static void qede_get_pauseparam(struct net_device *dev,
932 struct ethtool_pauseparam *epause)
934 struct qede_dev *edev = netdev_priv(dev);
935 struct qed_link_output current_link;
937 memset(¤t_link, 0, sizeof(current_link));
938 edev->ops->common->get_link(edev->cdev, ¤t_link);
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;
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,
953 static int qede_set_pauseparam(struct net_device *dev,
954 struct ethtool_pauseparam *epause)
956 struct qede_dev *edev = netdev_priv(dev);
957 struct qed_link_params params;
958 struct qed_link_output current_link;
960 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
962 "Pause settings are not allowed to be changed\n");
966 memset(¤t_link, 0, sizeof(current_link));
967 edev->ops->common->get_link(edev->cdev, ¤t_link);
969 memset(¶ms, 0, sizeof(params));
970 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
972 if (epause->autoneg) {
973 if (!phylink_test(current_link.supported_caps, Autoneg)) {
974 DP_INFO(edev, "autoneg not supported\n");
978 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
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;
986 params.link_up = true;
987 edev->ops->common->set_link(edev->cdev, ¶ms);
992 static void qede_get_regs(struct net_device *ndev,
993 struct ethtool_regs *regs, void *buffer)
995 struct qede_dev *edev = netdev_priv(ndev);
998 memset(buffer, 0, regs->len);
1000 if (edev->ops && edev->ops->common)
1001 edev->ops->common->dbg_all_data(edev->cdev, buffer);
1004 static int qede_get_regs_len(struct net_device *ndev)
1006 struct qede_dev *edev = netdev_priv(ndev);
1008 if (edev->ops && edev->ops->common)
1009 return edev->ops->common->dbg_all_data_size(edev->cdev);
1014 static void qede_update_mtu(struct qede_dev *edev,
1015 struct qede_reload_args *args)
1017 edev->ndev->mtu = args->u.mtu;
1020 /* Netdevice NDOs */
1021 int qede_change_mtu(struct net_device *ndev, int new_mtu)
1023 struct qede_dev *edev = netdev_priv(ndev);
1024 struct qede_reload_args args;
1026 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1027 "Configuring MTU size of %d\n", new_mtu);
1029 if (new_mtu > PAGE_SIZE)
1030 ndev->features &= ~NETIF_F_GRO_HW;
1032 /* Set the mtu field and re-start the interface if needed */
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);
1039 edev->ops->common->update_mtu(edev->cdev, new_mtu);
1044 static void qede_get_channels(struct net_device *dev,
1045 struct ethtool_channels *channels)
1047 struct qede_dev *edev = netdev_priv(dev);
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 -
1054 channels->tx_count = edev->fp_num_tx;
1055 channels->rx_count = edev->fp_num_rx;
1058 static int qede_set_channels(struct net_device *dev,
1059 struct ethtool_channels *channels)
1061 struct qede_dev *edev = netdev_priv(dev);
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);
1069 count = channels->rx_count + channels->tx_count +
1070 channels->combined_count;
1072 /* We don't support `other' channels */
1073 if (channels->other_count) {
1074 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1075 "command parameters not supported\n");
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");
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));
1093 /* Check if there was a change in the active parameters */
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");
1102 /* We need the number of queues to be divisible between the hwfns */
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);
1112 /* Set number of queues and reload if necessary */
1113 edev->req_queues = count;
1114 edev->req_num_tx = channels->tx_count;
1115 edev->req_num_rx = channels->rx_count;
1116 /* Reset the indirection table if rx queue count is updated */
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));
1122 qede_reload(edev, NULL, false);
1127 static int qede_get_ts_info(struct net_device *dev,
1128 struct ethtool_ts_info *info)
1130 struct qede_dev *edev = netdev_priv(dev);
1132 return qede_ptp_get_ts_info(edev, info);
1135 static int qede_set_phys_id(struct net_device *dev,
1136 enum ethtool_phys_id_state state)
1138 struct qede_dev *edev = netdev_priv(dev);
1142 case ETHTOOL_ID_ACTIVE:
1143 return 1; /* cycle on/off once per second */
1146 led_state = QED_LED_MODE_ON;
1149 case ETHTOOL_ID_OFF:
1150 led_state = QED_LED_MODE_OFF;
1153 case ETHTOOL_ID_INACTIVE:
1154 led_state = QED_LED_MODE_RESTORE;
1158 edev->ops->common->set_led(edev->cdev, led_state);
1163 static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1165 info->data = RXH_IP_SRC | RXH_IP_DST;
1167 switch (info->flow_type) {
1170 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1173 if (edev->rss_caps & QED_RSS_IPV4_UDP)
1174 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1177 if (edev->rss_caps & QED_RSS_IPV6_UDP)
1178 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1191 static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
1194 struct qede_dev *edev = netdev_priv(dev);
1197 switch (info->cmd) {
1198 case ETHTOOL_GRXRINGS:
1199 info->data = QEDE_RSS_COUNT(edev);
1202 rc = qede_get_rss_flags(edev, info);
1204 case ETHTOOL_GRXCLSRLCNT:
1205 info->rule_cnt = qede_get_arfs_filter_count(edev);
1206 info->data = QEDE_RFS_MAX_FLTR;
1208 case ETHTOOL_GRXCLSRULE:
1209 rc = qede_get_cls_rule_entry(edev, info);
1211 case ETHTOOL_GRXCLSRLALL:
1212 rc = qede_get_cls_rule_all(edev, info, rule_locs);
1215 DP_ERR(edev, "Command parameters not supported\n");
1222 static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1224 struct qed_update_vport_params *vport_update_params;
1225 u8 set_caps = 0, clr_caps = 0;
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);
1232 switch (info->flow_type) {
1235 /* For TCP only 4-tuple hash is supported */
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");
1243 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
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");
1258 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
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");
1274 /* For IP only 2-tuple hash is supported */
1275 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1276 DP_INFO(edev, "Command parameters not supported\n");
1281 case AH_ESP_V4_FLOW:
1285 case AH_ESP_V6_FLOW:
1290 /* RSS is not supported for these protocols */
1292 DP_INFO(edev, "Command parameters not supported\n");
1300 /* No action is needed if there is no change in the rss capability */
1301 if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps))
1304 /* Update internal configuration */
1305 edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps);
1306 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1308 /* Re-configure if possible */
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);
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);
1321 __qede_unlock(edev);
1326 static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1328 struct qede_dev *edev = netdev_priv(dev);
1331 switch (info->cmd) {
1333 rc = qede_set_rss_flags(edev, info);
1335 case ETHTOOL_SRXCLSRLINS:
1336 rc = qede_add_cls_rule(edev, info);
1338 case ETHTOOL_SRXCLSRLDEL:
1339 rc = qede_delete_flow_filter(edev, info->fs.location);
1342 DP_INFO(edev, "Command parameters not supported\n");
1349 static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1351 return QED_RSS_IND_TABLE_SIZE;
1354 static u32 qede_get_rxfh_key_size(struct net_device *dev)
1356 struct qede_dev *edev = netdev_priv(dev);
1358 return sizeof(edev->rss_key);
1361 static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1363 struct qede_dev *edev = netdev_priv(dev);
1367 *hfunc = ETH_RSS_HASH_TOP;
1372 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1373 indir[i] = edev->rss_ind_table[i];
1376 memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev));
1381 static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1382 const u8 *key, const u8 hfunc)
1384 struct qed_update_vport_params *vport_update_params;
1385 struct qede_dev *edev = netdev_priv(dev);
1388 if (edev->dev_info.common.num_hwfns > 1) {
1390 "RSS configuration is not supported for 100G devices\n");
1394 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
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;
1407 memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev));
1408 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
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);
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);
1423 __qede_unlock(edev);
1428 /* This function enables the interrupt generation and the NAPI on the device */
1429 static void qede_netif_start(struct qede_dev *edev)
1433 if (!netif_running(edev->ndev))
1437 /* Update and reenable interrupts */
1438 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1439 napi_enable(&edev->fp_array[i].napi);
1443 /* This function disables the NAPI and the interrupt generation on the device */
1444 static void qede_netif_stop(struct qede_dev *edev)
1449 napi_disable(&edev->fp_array[i].napi);
1450 /* Disable interrupts */
1451 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1455 static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1456 struct sk_buff *skb)
1458 struct qede_tx_queue *txq = NULL;
1459 struct eth_tx_1st_bd *first_bd;
1465 struct qede_fastpath *fp = &edev->fp_array[i];
1467 if (fp->type & QEDE_FASTPATH_TX) {
1468 txq = QEDE_FP_TC0_TXQ(fp);
1474 DP_NOTICE(edev, "Tx path is not available\n");
1478 /* Fill the entry in the SW ring and the BDs in the FW ring */
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);
1489 /* Map skb linear data for DMA and set in the first BD */
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");
1496 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1498 /* update the first BD with the actual num BDs */
1499 first_bd->data.nbds = 1;
1500 txq->sw_tx_prod = (txq->sw_tx_prod + 1) % txq->num_tx_buffers;
1501 /* 'next page' entries are counted in the producer value */
1502 val = qed_chain_get_prod_idx(&txq->tx_pbl);
1503 txq->tx_db.data.bd_prod = cpu_to_le16(val);
1505 /* wmb makes sure that the BDs data is updated before updating the
1506 * producer, otherwise FW may read old data from the BDs.
1510 writel(txq->tx_db.raw, txq->doorbell_addr);
1512 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1513 if (qede_txq_has_work(txq))
1515 usleep_range(100, 200);
1518 if (!qede_txq_has_work(txq)) {
1519 DP_NOTICE(edev, "Tx completion didn't happen\n");
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;
1532 static int qede_selftest_receive_traffic(struct qede_dev *edev)
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;
1543 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1544 rxq = edev->fp_array[i].rxq;
1550 DP_NOTICE(edev, "Rx path is not available\n");
1554 /* The packet is expected to receive on rx-queue 0 even though RSS is
1555 * enabled. This is because the queue 0 is configured as the default
1556 * queue and that the loopback traffic is not IP.
1558 for (iter = 0; iter < QEDE_SELFTEST_POLL_COUNT; iter++) {
1559 if (!qede_has_rx_work(rxq)) {
1560 usleep_range(100, 200);
1564 /* Get the CQE from the completion ring */
1565 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1567 /* Get the data from the SW ring */
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 +
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)) {
1585 qede_recycle_rx_bd_ring(rxq, 1);
1586 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
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);
1595 if (iter == QEDE_SELFTEST_POLL_COUNT) {
1596 DP_NOTICE(edev, "Failed to receive the traffic\n");
1600 qede_update_rx_prod(edev, rxq);
1605 static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1607 struct qed_link_params link_params;
1608 struct sk_buff *skb = NULL;
1613 if (!netif_running(edev->ndev)) {
1614 DP_NOTICE(edev, "Interface is down\n");
1618 qede_netif_stop(edev);
1620 /* Bring up the link in Loopback mode */
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);
1627 /* Wait for loopback configuration to apply */
1628 msleep_interruptible(500);
1630 /* Setting max packet size to 1.5K to avoid data being split over
1631 * multiple BDs in cases where MTU > PAGE_SIZE.
1633 pkt_size = (((edev->ndev->mtu < ETH_DATA_LEN) ?
1634 edev->ndev->mtu : ETH_DATA_LEN) + ETH_HLEN);
1636 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1638 DP_INFO(edev, "Can't allocate skb\n");
1640 goto test_loopback_exit;
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);
1649 rc = qede_selftest_transmit_traffic(edev, skb);
1651 goto test_loopback_exit;
1653 rc = qede_selftest_receive_traffic(edev);
1655 goto test_loopback_exit;
1657 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1662 /* Bring up the link in Normal mode */
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);
1669 /* Wait for loopback configuration to apply */
1670 msleep_interruptible(500);
1672 qede_netif_start(edev);
1677 static void qede_self_test(struct net_device *dev,
1678 struct ethtool_test *etest, u64 *buf)
1680 struct qede_dev *edev = netdev_priv(dev);
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);
1687 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
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;
1697 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1698 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1699 etest->flags |= ETH_TEST_FL_FAILED;
1702 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1703 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1704 etest->flags |= ETH_TEST_FL_FAILED;
1707 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1708 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1709 etest->flags |= ETH_TEST_FL_FAILED;
1712 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1713 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1714 etest->flags |= ETH_TEST_FL_FAILED;
1717 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1718 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1719 etest->flags |= ETH_TEST_FL_FAILED;
1723 static int qede_set_tunable(struct net_device *dev,
1724 const struct ethtool_tunable *tuna,
1727 struct qede_dev *edev = netdev_priv(dev);
1731 case ETHTOOL_RX_COPYBREAK:
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);
1740 edev->rx_copybreak = *(u32 *)data;
1749 static int qede_get_tunable(struct net_device *dev,
1750 const struct ethtool_tunable *tuna, void *data)
1752 struct qede_dev *edev = netdev_priv(dev);
1755 case ETHTOOL_RX_COPYBREAK:
1756 *(u32 *)data = edev->rx_copybreak;
1765 static int qede_get_eee(struct net_device *dev, struct ethtool_eee *edata)
1767 struct qede_dev *edev = netdev_priv(dev);
1768 struct qed_link_output current_link;
1770 memset(¤t_link, 0, sizeof(current_link));
1771 edev->ops->common->get_link(edev->cdev, ¤t_link);
1773 if (!current_link.eee_supported) {
1774 DP_INFO(edev, "EEE is not supported\n");
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;
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;
1799 static int qede_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1801 struct qede_dev *edev = netdev_priv(dev);
1802 struct qed_link_output current_link;
1803 struct qed_link_params params;
1805 if (!edev->ops->common->can_link_change(edev->cdev)) {
1806 DP_INFO(edev, "Link settings are not allowed to be changed\n");
1810 memset(¤t_link, 0, sizeof(current_link));
1811 edev->ops->common->get_link(edev->cdev, ¤t_link);
1813 if (!current_link.eee_supported) {
1814 DP_INFO(edev, "EEE is not supported\n");
1818 memset(¶ms, 0, sizeof(params));
1819 params.override_flags |= QED_LINK_OVERRIDE_EEE_CONFIG;
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",
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;
1840 params.link_up = true;
1841 edev->ops->common->set_link(edev->cdev, ¶ms);
1846 static u32 qede_link_to_ethtool_fec(u32 link_fec)
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;
1864 static u32 qede_ethtool_to_link_fec(u32 eth_fec)
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;
1882 static int qede_get_fecparam(struct net_device *dev,
1883 struct ethtool_fecparam *fecparam)
1885 struct qede_dev *edev = netdev_priv(dev);
1886 struct qed_link_output curr_link;
1888 memset(&curr_link, 0, sizeof(curr_link));
1889 edev->ops->common->get_link(edev->cdev, &curr_link);
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);
1897 static int qede_set_fecparam(struct net_device *dev,
1898 struct ethtool_fecparam *fecparam)
1900 struct qede_dev *edev = netdev_priv(dev);
1901 struct qed_link_params params;
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");
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;
1913 edev->ops->common->set_link(edev->cdev, ¶ms);
1918 static int qede_get_module_info(struct net_device *dev,
1919 struct ethtool_modinfo *modinfo)
1921 struct qede_dev *edev = netdev_priv(dev);
1925 /* Read first 4 bytes to find the sfp type */
1926 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1927 QED_I2C_DEV_ADDR_A0, 0, 4);
1929 DP_ERR(edev, "Failed reading EEPROM data %d\n", rc);
1934 case 0x3: /* SFP, SFP+, SFP-28 */
1935 modinfo->type = ETH_MODULE_SFF_8472;
1936 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1938 case 0xc: /* QSFP */
1939 case 0xd: /* QSFP+ */
1940 modinfo->type = ETH_MODULE_SFF_8436;
1941 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1943 case 0x11: /* QSFP-28 */
1944 modinfo->type = ETH_MODULE_SFF_8636;
1945 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1948 DP_ERR(edev, "Unknown transceiver type 0x%x\n", buf[0]);
1955 static int qede_get_module_eeprom(struct net_device *dev,
1956 struct ethtool_eeprom *ee, u8 *data)
1958 struct qede_dev *edev = netdev_priv(dev);
1959 u32 start_addr = ee->offset, size = 0;
1963 /* Read A0 section */
1964 if (ee->offset < ETH_MODULE_SFF_8079_LEN) {
1965 /* Limit transfer size to the A0 section boundary */
1966 if (ee->offset + ee->len > ETH_MODULE_SFF_8079_LEN)
1967 size = ETH_MODULE_SFF_8079_LEN - ee->offset;
1971 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1972 QED_I2C_DEV_ADDR_A0,
1975 DP_ERR(edev, "Failed reading A0 section %d\n", rc);
1983 /* Read A2 section */
1984 if (start_addr >= ETH_MODULE_SFF_8079_LEN &&
1985 start_addr < ETH_MODULE_SFF_8472_LEN) {
1986 size = ee->len - size;
1987 /* Limit transfer size to the A2 section boundary */
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,
1995 DP_VERBOSE(edev, QED_MSG_DEBUG,
1996 "Failed reading A2 section %d\n", rc);
2004 static int qede_set_dump(struct net_device *dev, struct ethtool_dump *val)
2006 struct qede_dev *edev = netdev_priv(dev);
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);
2014 edev->dump_info.cmd = val->flag;
2015 edev->dump_info.num_args = 0;
2019 if (edev->dump_info.num_args == QEDE_DUMP_MAX_ARGS) {
2020 DP_ERR(edev, "Arg count = %d\n", edev->dump_info.num_args);
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++;
2029 case QEDE_DUMP_CMD_GRCDUMP:
2030 rc = edev->ops->common->set_grc_config(edev->cdev,
2040 static int qede_get_dump_flag(struct net_device *dev,
2041 struct ethtool_dump *dump)
2043 struct qede_dev *edev = netdev_priv(dev);
2045 if (!edev->ops || !edev->ops->common) {
2046 DP_ERR(edev, "Edev ops not populated\n");
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]);
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);
2062 DP_ERR(edev, "Invalid cmd = %d\n", edev->dump_info.cmd);
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);
2072 static int qede_get_dump_data(struct net_device *dev,
2073 struct ethtool_dump *dump, void *buf)
2075 struct qede_dev *edev = netdev_priv(dev);
2078 if (!edev->ops || !edev->ops->common) {
2079 DP_ERR(edev, "Edev ops not populated\n");
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);
2093 rc = edev->ops->common->read_nvm_cfg(edev->cdev, (u8 **)&buf,
2094 edev->dump_info.args[0],
2095 edev->dump_info.args[1]);
2097 case QEDE_DUMP_CMD_GRCDUMP:
2098 memset(buf, 0, dump->len);
2099 rc = edev->ops->common->dbg_all_data(edev->cdev, buf);
2102 DP_ERR(edev, "Invalid cmd = %d\n", edev->dump_info.cmd);
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));
2115 int qede_set_per_coalesce(struct net_device *dev, u32 queue,
2116 struct ethtool_coalesce *coal)
2118 struct qede_dev *edev = netdev_priv(dev);
2119 struct qede_fastpath *fp;
2123 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
2124 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
2126 "Can't support requested %s coalesce value [max supported value %d]\n",
2127 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
2133 rxc = (u16)coal->rx_coalesce_usecs;
2134 txc = (u16)coal->tx_coalesce_usecs;
2137 if (queue >= edev->num_queues) {
2138 DP_INFO(edev, "Invalid queue\n");
2143 if (edev->state != QEDE_STATE_OPEN) {
2148 fp = &edev->fp_array[queue];
2150 if (edev->fp_array[queue].type & QEDE_FASTPATH_RX) {
2151 rc = edev->ops->common->set_coalesce(edev->cdev,
2156 "Set RX coalesce error, rc = %d\n", rc);
2159 edev->coal_entry[queue].rxc = rxc;
2160 edev->coal_entry[queue].isvalid = true;
2163 if (edev->fp_array[queue].type & QEDE_FASTPATH_TX) {
2164 rc = edev->ops->common->set_coalesce(edev->cdev,
2169 "Set TX coalesce error, rc = %d\n", rc);
2172 edev->coal_entry[queue].txc = txc;
2173 edev->coal_entry[queue].isvalid = true;
2176 __qede_unlock(edev);
2181 static int qede_get_per_coalesce(struct net_device *dev,
2183 struct ethtool_coalesce *coal)
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;
2191 rx_coal = QED_DEFAULT_RX_USECS;
2192 tx_coal = QED_DEFAULT_TX_USECS;
2194 memset(coal, 0, sizeof(struct ethtool_coalesce));
2197 if (queue >= edev->num_queues) {
2198 DP_INFO(edev, "Invalid queue\n");
2203 if (edev->state != QEDE_STATE_OPEN) {
2208 fp = &edev->fp_array[queue];
2210 if (fp->type & QEDE_FASTPATH_RX)
2211 rx_handle = fp->rxq->handle;
2213 rc = edev->ops->get_coalesce(edev->cdev, &rx_coal,
2216 DP_INFO(edev, "Read Rx coalesce error\n");
2220 fp = &edev->fp_array[queue];
2221 if (fp->type & QEDE_FASTPATH_TX)
2222 tx_handle = fp->txq->handle;
2224 rc = edev->ops->get_coalesce(edev->cdev, &tx_coal,
2227 DP_INFO(edev, "Read Tx coalesce error\n");
2230 __qede_unlock(edev);
2232 coal->rx_coalesce_usecs = rx_coal;
2233 coal->tx_coalesce_usecs = tx_coal;
2238 static 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,
2289 static 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,
2318 void qede_set_ethtool_ops(struct net_device *dev)
2320 struct qede_dev *edev = netdev_priv(dev);
2323 dev->ethtool_ops = &qede_vf_ethtool_ops;
2325 dev->ethtool_ops = &qede_ethtool_ops;