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(DRV_MODULE_VERSION) + strlen("[storm] ")) <
629 sizeof(info->version))
630 snprintf(info->version, sizeof(info->version),
631 "%s [storm %s]", DRV_MODULE_VERSION, storm);
633 snprintf(info->version, sizeof(info->version),
634 "%s %s", DRV_MODULE_VERSION, storm);
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)
765 void *rx_handle = NULL, *tx_handle = NULL;
766 struct qede_dev *edev = netdev_priv(dev);
767 u16 rx_coal, tx_coal, i, rc = 0;
768 struct qede_fastpath *fp;
770 rx_coal = QED_DEFAULT_RX_USECS;
771 tx_coal = QED_DEFAULT_TX_USECS;
773 memset(coal, 0, sizeof(struct ethtool_coalesce));
776 if (edev->state == QEDE_STATE_OPEN) {
778 fp = &edev->fp_array[i];
780 if (fp->type & QEDE_FASTPATH_RX) {
781 rx_handle = fp->rxq->handle;
786 rc = edev->ops->get_coalesce(edev->cdev, &rx_coal, rx_handle);
788 DP_INFO(edev, "Read Rx coalesce error\n");
793 struct qede_tx_queue *txq;
795 fp = &edev->fp_array[i];
797 /* All TX queues of given fastpath uses same
798 * coalescing value, so no need to iterate over
799 * all TCs, TC0 txq should suffice.
801 if (fp->type & QEDE_FASTPATH_TX) {
802 txq = QEDE_FP_TC0_TXQ(fp);
803 tx_handle = txq->handle;
808 rc = edev->ops->get_coalesce(edev->cdev, &tx_coal, tx_handle);
810 DP_INFO(edev, "Read Tx coalesce error\n");
816 coal->rx_coalesce_usecs = rx_coal;
817 coal->tx_coalesce_usecs = tx_coal;
822 int qede_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
824 struct qede_dev *edev = netdev_priv(dev);
825 struct qede_fastpath *fp;
829 if (!netif_running(dev)) {
830 DP_INFO(edev, "Interface is down\n");
834 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
835 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
837 "Can't support requested %s coalesce value [max supported value %d]\n",
838 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx" :
839 "tx", QED_COALESCE_MAX);
843 rxc = (u16)coal->rx_coalesce_usecs;
844 txc = (u16)coal->tx_coalesce_usecs;
846 fp = &edev->fp_array[i];
848 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
849 rc = edev->ops->common->set_coalesce(edev->cdev,
854 "Set RX coalesce error, rc = %d\n", rc);
857 edev->coal_entry[i].rxc = rxc;
858 edev->coal_entry[i].isvalid = true;
861 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
862 struct qede_tx_queue *txq;
864 /* All TX queues of given fastpath uses same
865 * coalescing value, so no need to iterate over
866 * all TCs, TC0 txq should suffice.
868 txq = QEDE_FP_TC0_TXQ(fp);
870 rc = edev->ops->common->set_coalesce(edev->cdev,
875 "Set TX coalesce error, rc = %d\n", rc);
878 edev->coal_entry[i].txc = txc;
879 edev->coal_entry[i].isvalid = true;
886 static void qede_get_ringparam(struct net_device *dev,
887 struct ethtool_ringparam *ering)
889 struct qede_dev *edev = netdev_priv(dev);
891 ering->rx_max_pending = NUM_RX_BDS_MAX;
892 ering->rx_pending = edev->q_num_rx_buffers;
893 ering->tx_max_pending = NUM_TX_BDS_MAX;
894 ering->tx_pending = edev->q_num_tx_buffers;
897 static int qede_set_ringparam(struct net_device *dev,
898 struct ethtool_ringparam *ering)
900 struct qede_dev *edev = netdev_priv(dev);
902 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
903 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
904 ering->rx_pending, ering->tx_pending);
906 /* Validate legality of configuration */
907 if (ering->rx_pending > NUM_RX_BDS_MAX ||
908 ering->rx_pending < NUM_RX_BDS_MIN ||
909 ering->tx_pending > NUM_TX_BDS_MAX ||
910 ering->tx_pending < NUM_TX_BDS_MIN) {
911 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
912 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
913 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
914 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
918 /* Change ring size and re-load */
919 edev->q_num_rx_buffers = ering->rx_pending;
920 edev->q_num_tx_buffers = ering->tx_pending;
922 qede_reload(edev, NULL, false);
927 static void qede_get_pauseparam(struct net_device *dev,
928 struct ethtool_pauseparam *epause)
930 struct qede_dev *edev = netdev_priv(dev);
931 struct qed_link_output current_link;
933 memset(¤t_link, 0, sizeof(current_link));
934 edev->ops->common->get_link(edev->cdev, ¤t_link);
936 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
937 epause->autoneg = true;
938 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
939 epause->rx_pause = true;
940 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
941 epause->tx_pause = true;
943 DP_VERBOSE(edev, QED_MSG_DEBUG,
944 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
945 epause->cmd, epause->autoneg, epause->rx_pause,
949 static int qede_set_pauseparam(struct net_device *dev,
950 struct ethtool_pauseparam *epause)
952 struct qede_dev *edev = netdev_priv(dev);
953 struct qed_link_params params;
954 struct qed_link_output current_link;
956 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
958 "Pause settings are not allowed to be changed\n");
962 memset(¤t_link, 0, sizeof(current_link));
963 edev->ops->common->get_link(edev->cdev, ¤t_link);
965 memset(¶ms, 0, sizeof(params));
966 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
968 if (epause->autoneg) {
969 if (!phylink_test(current_link.supported_caps, Autoneg)) {
970 DP_INFO(edev, "autoneg not supported\n");
974 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
977 if (epause->rx_pause)
978 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
979 if (epause->tx_pause)
980 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
982 params.link_up = true;
983 edev->ops->common->set_link(edev->cdev, ¶ms);
988 static void qede_get_regs(struct net_device *ndev,
989 struct ethtool_regs *regs, void *buffer)
991 struct qede_dev *edev = netdev_priv(ndev);
994 memset(buffer, 0, regs->len);
996 if (edev->ops && edev->ops->common)
997 edev->ops->common->dbg_all_data(edev->cdev, buffer);
1000 static int qede_get_regs_len(struct net_device *ndev)
1002 struct qede_dev *edev = netdev_priv(ndev);
1004 if (edev->ops && edev->ops->common)
1005 return edev->ops->common->dbg_all_data_size(edev->cdev);
1010 static void qede_update_mtu(struct qede_dev *edev,
1011 struct qede_reload_args *args)
1013 edev->ndev->mtu = args->u.mtu;
1016 /* Netdevice NDOs */
1017 int qede_change_mtu(struct net_device *ndev, int new_mtu)
1019 struct qede_dev *edev = netdev_priv(ndev);
1020 struct qede_reload_args args;
1022 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1023 "Configuring MTU size of %d\n", new_mtu);
1025 if (new_mtu > PAGE_SIZE)
1026 ndev->features &= ~NETIF_F_GRO_HW;
1028 /* Set the mtu field and re-start the interface if needed */
1029 args.u.mtu = new_mtu;
1030 args.func = &qede_update_mtu;
1031 qede_reload(edev, &args, false);
1032 #if IS_ENABLED(CONFIG_QED_RDMA)
1033 qede_rdma_event_change_mtu(edev);
1035 edev->ops->common->update_mtu(edev->cdev, new_mtu);
1040 static void qede_get_channels(struct net_device *dev,
1041 struct ethtool_channels *channels)
1043 struct qede_dev *edev = netdev_priv(dev);
1045 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
1046 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
1047 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
1048 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
1050 channels->tx_count = edev->fp_num_tx;
1051 channels->rx_count = edev->fp_num_rx;
1054 static int qede_set_channels(struct net_device *dev,
1055 struct ethtool_channels *channels)
1057 struct qede_dev *edev = netdev_priv(dev);
1060 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1061 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
1062 channels->rx_count, channels->tx_count,
1063 channels->other_count, channels->combined_count);
1065 count = channels->rx_count + channels->tx_count +
1066 channels->combined_count;
1068 /* We don't support `other' channels */
1069 if (channels->other_count) {
1070 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1071 "command parameters not supported\n");
1075 if (!(channels->combined_count || (channels->rx_count &&
1076 channels->tx_count))) {
1077 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1078 "need to request at least one transmit and one receive channel\n");
1082 if (count > QEDE_MAX_RSS_CNT(edev)) {
1083 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1084 "requested channels = %d max supported channels = %d\n",
1085 count, QEDE_MAX_RSS_CNT(edev));
1089 /* Check if there was a change in the active parameters */
1090 if ((count == QEDE_QUEUE_CNT(edev)) &&
1091 (channels->tx_count == edev->fp_num_tx) &&
1092 (channels->rx_count == edev->fp_num_rx)) {
1093 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1094 "No change in active parameters\n");
1098 /* We need the number of queues to be divisible between the hwfns */
1099 if ((count % edev->dev_info.common.num_hwfns) ||
1100 (channels->tx_count % edev->dev_info.common.num_hwfns) ||
1101 (channels->rx_count % edev->dev_info.common.num_hwfns)) {
1102 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1103 "Number of channels must be divisible by %04x\n",
1104 edev->dev_info.common.num_hwfns);
1108 /* Set number of queues and reload if necessary */
1109 edev->req_queues = count;
1110 edev->req_num_tx = channels->tx_count;
1111 edev->req_num_rx = channels->rx_count;
1112 /* Reset the indirection table if rx queue count is updated */
1113 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
1114 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
1115 memset(edev->rss_ind_table, 0, sizeof(edev->rss_ind_table));
1118 qede_reload(edev, NULL, false);
1123 static int qede_get_ts_info(struct net_device *dev,
1124 struct ethtool_ts_info *info)
1126 struct qede_dev *edev = netdev_priv(dev);
1128 return qede_ptp_get_ts_info(edev, info);
1131 static int qede_set_phys_id(struct net_device *dev,
1132 enum ethtool_phys_id_state state)
1134 struct qede_dev *edev = netdev_priv(dev);
1138 case ETHTOOL_ID_ACTIVE:
1139 return 1; /* cycle on/off once per second */
1142 led_state = QED_LED_MODE_ON;
1145 case ETHTOOL_ID_OFF:
1146 led_state = QED_LED_MODE_OFF;
1149 case ETHTOOL_ID_INACTIVE:
1150 led_state = QED_LED_MODE_RESTORE;
1154 edev->ops->common->set_led(edev->cdev, led_state);
1159 static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1161 info->data = RXH_IP_SRC | RXH_IP_DST;
1163 switch (info->flow_type) {
1166 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1169 if (edev->rss_caps & QED_RSS_IPV4_UDP)
1170 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1173 if (edev->rss_caps & QED_RSS_IPV6_UDP)
1174 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1187 static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
1190 struct qede_dev *edev = netdev_priv(dev);
1193 switch (info->cmd) {
1194 case ETHTOOL_GRXRINGS:
1195 info->data = QEDE_RSS_COUNT(edev);
1198 rc = qede_get_rss_flags(edev, info);
1200 case ETHTOOL_GRXCLSRLCNT:
1201 info->rule_cnt = qede_get_arfs_filter_count(edev);
1202 info->data = QEDE_RFS_MAX_FLTR;
1204 case ETHTOOL_GRXCLSRULE:
1205 rc = qede_get_cls_rule_entry(edev, info);
1207 case ETHTOOL_GRXCLSRLALL:
1208 rc = qede_get_cls_rule_all(edev, info, rule_locs);
1211 DP_ERR(edev, "Command parameters not supported\n");
1218 static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1220 struct qed_update_vport_params *vport_update_params;
1221 u8 set_caps = 0, clr_caps = 0;
1224 DP_VERBOSE(edev, QED_MSG_DEBUG,
1225 "Set rss flags command parameters: flow type = %d, data = %llu\n",
1226 info->flow_type, info->data);
1228 switch (info->flow_type) {
1231 /* For TCP only 4-tuple hash is supported */
1232 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
1233 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1234 DP_INFO(edev, "Command parameters not supported\n");
1239 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1240 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1241 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1242 set_caps = QED_RSS_IPV4_UDP;
1243 DP_VERBOSE(edev, QED_MSG_DEBUG,
1244 "UDP 4-tuple enabled\n");
1245 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1246 clr_caps = QED_RSS_IPV4_UDP;
1247 DP_VERBOSE(edev, QED_MSG_DEBUG,
1248 "UDP 4-tuple disabled\n");
1254 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1255 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1256 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1257 set_caps = QED_RSS_IPV6_UDP;
1258 DP_VERBOSE(edev, QED_MSG_DEBUG,
1259 "UDP 4-tuple enabled\n");
1260 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1261 clr_caps = QED_RSS_IPV6_UDP;
1262 DP_VERBOSE(edev, QED_MSG_DEBUG,
1263 "UDP 4-tuple disabled\n");
1270 /* For IP only 2-tuple hash is supported */
1271 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1272 DP_INFO(edev, "Command parameters not supported\n");
1277 case AH_ESP_V4_FLOW:
1281 case AH_ESP_V6_FLOW:
1286 /* RSS is not supported for these protocols */
1288 DP_INFO(edev, "Command parameters not supported\n");
1296 /* No action is needed if there is no change in the rss capability */
1297 if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps))
1300 /* Update internal configuration */
1301 edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps);
1302 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1304 /* Re-configure if possible */
1306 if (edev->state == QEDE_STATE_OPEN) {
1307 vport_update_params = vzalloc(sizeof(*vport_update_params));
1308 if (!vport_update_params) {
1309 __qede_unlock(edev);
1312 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1313 &vport_update_params->update_rss_flg);
1314 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1315 vfree(vport_update_params);
1317 __qede_unlock(edev);
1322 static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1324 struct qede_dev *edev = netdev_priv(dev);
1327 switch (info->cmd) {
1329 rc = qede_set_rss_flags(edev, info);
1331 case ETHTOOL_SRXCLSRLINS:
1332 rc = qede_add_cls_rule(edev, info);
1334 case ETHTOOL_SRXCLSRLDEL:
1335 rc = qede_delete_flow_filter(edev, info->fs.location);
1338 DP_INFO(edev, "Command parameters not supported\n");
1345 static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1347 return QED_RSS_IND_TABLE_SIZE;
1350 static u32 qede_get_rxfh_key_size(struct net_device *dev)
1352 struct qede_dev *edev = netdev_priv(dev);
1354 return sizeof(edev->rss_key);
1357 static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1359 struct qede_dev *edev = netdev_priv(dev);
1363 *hfunc = ETH_RSS_HASH_TOP;
1368 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1369 indir[i] = edev->rss_ind_table[i];
1372 memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev));
1377 static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1378 const u8 *key, const u8 hfunc)
1380 struct qed_update_vport_params *vport_update_params;
1381 struct qede_dev *edev = netdev_priv(dev);
1384 if (edev->dev_info.common.num_hwfns > 1) {
1386 "RSS configuration is not supported for 100G devices\n");
1390 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1397 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1398 edev->rss_ind_table[i] = indir[i];
1399 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1403 memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev));
1404 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1408 if (edev->state == QEDE_STATE_OPEN) {
1409 vport_update_params = vzalloc(sizeof(*vport_update_params));
1410 if (!vport_update_params) {
1411 __qede_unlock(edev);
1414 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1415 &vport_update_params->update_rss_flg);
1416 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1417 vfree(vport_update_params);
1419 __qede_unlock(edev);
1424 /* This function enables the interrupt generation and the NAPI on the device */
1425 static void qede_netif_start(struct qede_dev *edev)
1429 if (!netif_running(edev->ndev))
1433 /* Update and reenable interrupts */
1434 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1435 napi_enable(&edev->fp_array[i].napi);
1439 /* This function disables the NAPI and the interrupt generation on the device */
1440 static void qede_netif_stop(struct qede_dev *edev)
1445 napi_disable(&edev->fp_array[i].napi);
1446 /* Disable interrupts */
1447 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1451 static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1452 struct sk_buff *skb)
1454 struct qede_tx_queue *txq = NULL;
1455 struct eth_tx_1st_bd *first_bd;
1461 struct qede_fastpath *fp = &edev->fp_array[i];
1463 if (fp->type & QEDE_FASTPATH_TX) {
1464 txq = QEDE_FP_TC0_TXQ(fp);
1470 DP_NOTICE(edev, "Tx path is not available\n");
1474 /* Fill the entry in the SW ring and the BDs in the FW ring */
1475 idx = txq->sw_tx_prod;
1476 txq->sw_tx_ring.skbs[idx].skb = skb;
1477 first_bd = qed_chain_produce(&txq->tx_pbl);
1478 memset(first_bd, 0, sizeof(*first_bd));
1479 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1480 first_bd->data.bd_flags.bitfields = val;
1481 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1482 val = val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
1483 first_bd->data.bitfields |= cpu_to_le16(val);
1485 /* Map skb linear data for DMA and set in the first BD */
1486 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1487 skb_headlen(skb), DMA_TO_DEVICE);
1488 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1489 DP_NOTICE(edev, "SKB mapping failed\n");
1492 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1494 /* update the first BD with the actual num BDs */
1495 first_bd->data.nbds = 1;
1496 txq->sw_tx_prod = (txq->sw_tx_prod + 1) % txq->num_tx_buffers;
1497 /* 'next page' entries are counted in the producer value */
1498 val = qed_chain_get_prod_idx(&txq->tx_pbl);
1499 txq->tx_db.data.bd_prod = cpu_to_le16(val);
1501 /* wmb makes sure that the BDs data is updated before updating the
1502 * producer, otherwise FW may read old data from the BDs.
1506 writel(txq->tx_db.raw, txq->doorbell_addr);
1508 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1509 if (qede_txq_has_work(txq))
1511 usleep_range(100, 200);
1514 if (!qede_txq_has_work(txq)) {
1515 DP_NOTICE(edev, "Tx completion didn't happen\n");
1519 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
1520 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1521 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
1522 txq->sw_tx_cons = (txq->sw_tx_cons + 1) % txq->num_tx_buffers;
1523 txq->sw_tx_ring.skbs[idx].skb = NULL;
1528 static int qede_selftest_receive_traffic(struct qede_dev *edev)
1530 u16 sw_rx_index, len;
1531 struct eth_fast_path_rx_reg_cqe *fp_cqe;
1532 struct qede_rx_queue *rxq = NULL;
1533 struct sw_rx_data *sw_rx_data;
1534 union eth_rx_cqe *cqe;
1535 int i, iter, rc = 0;
1539 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1540 rxq = edev->fp_array[i].rxq;
1546 DP_NOTICE(edev, "Rx path is not available\n");
1550 /* The packet is expected to receive on rx-queue 0 even though RSS is
1551 * enabled. This is because the queue 0 is configured as the default
1552 * queue and that the loopback traffic is not IP.
1554 for (iter = 0; iter < QEDE_SELFTEST_POLL_COUNT; iter++) {
1555 if (!qede_has_rx_work(rxq)) {
1556 usleep_range(100, 200);
1560 /* Get the CQE from the completion ring */
1561 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1563 /* Get the data from the SW ring */
1564 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1565 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1566 fp_cqe = &cqe->fast_path_regular;
1567 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1568 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1569 fp_cqe->placement_offset +
1570 sw_rx_data->page_offset +
1572 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1573 ether_addr_equal(data_ptr + ETH_ALEN,
1574 edev->ndev->dev_addr)) {
1575 for (i = ETH_HLEN; i < len; i++)
1576 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1581 qede_recycle_rx_bd_ring(rxq, 1);
1582 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1586 DP_INFO(edev, "Not the transmitted packet\n");
1587 qede_recycle_rx_bd_ring(rxq, 1);
1588 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1591 if (iter == QEDE_SELFTEST_POLL_COUNT) {
1592 DP_NOTICE(edev, "Failed to receive the traffic\n");
1596 qede_update_rx_prod(edev, rxq);
1601 static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1603 struct qed_link_params link_params;
1604 struct sk_buff *skb = NULL;
1609 if (!netif_running(edev->ndev)) {
1610 DP_NOTICE(edev, "Interface is down\n");
1614 qede_netif_stop(edev);
1616 /* Bring up the link in Loopback mode */
1617 memset(&link_params, 0, sizeof(link_params));
1618 link_params.link_up = true;
1619 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1620 link_params.loopback_mode = loopback_mode;
1621 edev->ops->common->set_link(edev->cdev, &link_params);
1623 /* Wait for loopback configuration to apply */
1624 msleep_interruptible(500);
1626 /* Setting max packet size to 1.5K to avoid data being split over
1627 * multiple BDs in cases where MTU > PAGE_SIZE.
1629 pkt_size = (((edev->ndev->mtu < ETH_DATA_LEN) ?
1630 edev->ndev->mtu : ETH_DATA_LEN) + ETH_HLEN);
1632 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1634 DP_INFO(edev, "Can't allocate skb\n");
1636 goto test_loopback_exit;
1638 packet = skb_put(skb, pkt_size);
1639 ether_addr_copy(packet, edev->ndev->dev_addr);
1640 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1641 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1642 for (i = ETH_HLEN; i < pkt_size; i++)
1643 packet[i] = (unsigned char)(i & 0xff);
1645 rc = qede_selftest_transmit_traffic(edev, skb);
1647 goto test_loopback_exit;
1649 rc = qede_selftest_receive_traffic(edev);
1651 goto test_loopback_exit;
1653 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1658 /* Bring up the link in Normal mode */
1659 memset(&link_params, 0, sizeof(link_params));
1660 link_params.link_up = true;
1661 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1662 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1663 edev->ops->common->set_link(edev->cdev, &link_params);
1665 /* Wait for loopback configuration to apply */
1666 msleep_interruptible(500);
1668 qede_netif_start(edev);
1673 static void qede_self_test(struct net_device *dev,
1674 struct ethtool_test *etest, u64 *buf)
1676 struct qede_dev *edev = netdev_priv(dev);
1678 DP_VERBOSE(edev, QED_MSG_DEBUG,
1679 "Self-test command parameters: offline = %d, external_lb = %d\n",
1680 (etest->flags & ETH_TEST_FL_OFFLINE),
1681 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1683 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1685 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1686 if (qede_selftest_run_loopback(edev,
1687 QED_LINK_LOOPBACK_INT_PHY)) {
1688 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1689 etest->flags |= ETH_TEST_FL_FAILED;
1693 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1694 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1695 etest->flags |= ETH_TEST_FL_FAILED;
1698 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1699 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1700 etest->flags |= ETH_TEST_FL_FAILED;
1703 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1704 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1705 etest->flags |= ETH_TEST_FL_FAILED;
1708 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1709 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1710 etest->flags |= ETH_TEST_FL_FAILED;
1713 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1714 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1715 etest->flags |= ETH_TEST_FL_FAILED;
1719 static int qede_set_tunable(struct net_device *dev,
1720 const struct ethtool_tunable *tuna,
1723 struct qede_dev *edev = netdev_priv(dev);
1727 case ETHTOOL_RX_COPYBREAK:
1729 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1730 DP_VERBOSE(edev, QED_MSG_DEBUG,
1731 "Invalid rx copy break value, range is [%u, %u]",
1732 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1736 edev->rx_copybreak = *(u32 *)data;
1745 static int qede_get_tunable(struct net_device *dev,
1746 const struct ethtool_tunable *tuna, void *data)
1748 struct qede_dev *edev = netdev_priv(dev);
1751 case ETHTOOL_RX_COPYBREAK:
1752 *(u32 *)data = edev->rx_copybreak;
1761 static int qede_get_eee(struct net_device *dev, struct ethtool_eee *edata)
1763 struct qede_dev *edev = netdev_priv(dev);
1764 struct qed_link_output current_link;
1766 memset(¤t_link, 0, sizeof(current_link));
1767 edev->ops->common->get_link(edev->cdev, ¤t_link);
1769 if (!current_link.eee_supported) {
1770 DP_INFO(edev, "EEE is not supported\n");
1774 if (current_link.eee.adv_caps & QED_EEE_1G_ADV)
1775 edata->advertised = ADVERTISED_1000baseT_Full;
1776 if (current_link.eee.adv_caps & QED_EEE_10G_ADV)
1777 edata->advertised |= ADVERTISED_10000baseT_Full;
1778 if (current_link.sup_caps & QED_EEE_1G_ADV)
1779 edata->supported = ADVERTISED_1000baseT_Full;
1780 if (current_link.sup_caps & QED_EEE_10G_ADV)
1781 edata->supported |= ADVERTISED_10000baseT_Full;
1782 if (current_link.eee.lp_adv_caps & QED_EEE_1G_ADV)
1783 edata->lp_advertised = ADVERTISED_1000baseT_Full;
1784 if (current_link.eee.lp_adv_caps & QED_EEE_10G_ADV)
1785 edata->lp_advertised |= ADVERTISED_10000baseT_Full;
1787 edata->tx_lpi_timer = current_link.eee.tx_lpi_timer;
1788 edata->eee_enabled = current_link.eee.enable;
1789 edata->tx_lpi_enabled = current_link.eee.tx_lpi_enable;
1790 edata->eee_active = current_link.eee_active;
1795 static int qede_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1797 struct qede_dev *edev = netdev_priv(dev);
1798 struct qed_link_output current_link;
1799 struct qed_link_params params;
1801 if (!edev->ops->common->can_link_change(edev->cdev)) {
1802 DP_INFO(edev, "Link settings are not allowed to be changed\n");
1806 memset(¤t_link, 0, sizeof(current_link));
1807 edev->ops->common->get_link(edev->cdev, ¤t_link);
1809 if (!current_link.eee_supported) {
1810 DP_INFO(edev, "EEE is not supported\n");
1814 memset(¶ms, 0, sizeof(params));
1815 params.override_flags |= QED_LINK_OVERRIDE_EEE_CONFIG;
1817 if (!(edata->advertised & (ADVERTISED_1000baseT_Full |
1818 ADVERTISED_10000baseT_Full)) ||
1819 ((edata->advertised & (ADVERTISED_1000baseT_Full |
1820 ADVERTISED_10000baseT_Full)) !=
1821 edata->advertised)) {
1822 DP_VERBOSE(edev, QED_MSG_DEBUG,
1823 "Invalid advertised capabilities %d\n",
1828 if (edata->advertised & ADVERTISED_1000baseT_Full)
1829 params.eee.adv_caps = QED_EEE_1G_ADV;
1830 if (edata->advertised & ADVERTISED_10000baseT_Full)
1831 params.eee.adv_caps |= QED_EEE_10G_ADV;
1832 params.eee.enable = edata->eee_enabled;
1833 params.eee.tx_lpi_enable = edata->tx_lpi_enabled;
1834 params.eee.tx_lpi_timer = edata->tx_lpi_timer;
1836 params.link_up = true;
1837 edev->ops->common->set_link(edev->cdev, ¶ms);
1842 static u32 qede_link_to_ethtool_fec(u32 link_fec)
1846 if (link_fec & QED_FEC_MODE_NONE)
1847 eth_fec |= ETHTOOL_FEC_OFF;
1848 if (link_fec & QED_FEC_MODE_FIRECODE)
1849 eth_fec |= ETHTOOL_FEC_BASER;
1850 if (link_fec & QED_FEC_MODE_RS)
1851 eth_fec |= ETHTOOL_FEC_RS;
1852 if (link_fec & QED_FEC_MODE_AUTO)
1853 eth_fec |= ETHTOOL_FEC_AUTO;
1854 if (link_fec & QED_FEC_MODE_UNSUPPORTED)
1855 eth_fec |= ETHTOOL_FEC_NONE;
1860 static u32 qede_ethtool_to_link_fec(u32 eth_fec)
1864 if (eth_fec & ETHTOOL_FEC_OFF)
1865 link_fec |= QED_FEC_MODE_NONE;
1866 if (eth_fec & ETHTOOL_FEC_BASER)
1867 link_fec |= QED_FEC_MODE_FIRECODE;
1868 if (eth_fec & ETHTOOL_FEC_RS)
1869 link_fec |= QED_FEC_MODE_RS;
1870 if (eth_fec & ETHTOOL_FEC_AUTO)
1871 link_fec |= QED_FEC_MODE_AUTO;
1872 if (eth_fec & ETHTOOL_FEC_NONE)
1873 link_fec |= QED_FEC_MODE_UNSUPPORTED;
1878 static int qede_get_fecparam(struct net_device *dev,
1879 struct ethtool_fecparam *fecparam)
1881 struct qede_dev *edev = netdev_priv(dev);
1882 struct qed_link_output curr_link;
1884 memset(&curr_link, 0, sizeof(curr_link));
1885 edev->ops->common->get_link(edev->cdev, &curr_link);
1887 fecparam->active_fec = qede_link_to_ethtool_fec(curr_link.active_fec);
1888 fecparam->fec = qede_link_to_ethtool_fec(curr_link.sup_fec);
1893 static int qede_set_fecparam(struct net_device *dev,
1894 struct ethtool_fecparam *fecparam)
1896 struct qede_dev *edev = netdev_priv(dev);
1897 struct qed_link_params params;
1899 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
1900 DP_INFO(edev, "Link settings are not allowed to be changed\n");
1904 memset(¶ms, 0, sizeof(params));
1905 params.override_flags |= QED_LINK_OVERRIDE_FEC_CONFIG;
1906 params.fec = qede_ethtool_to_link_fec(fecparam->fec);
1907 params.link_up = true;
1909 edev->ops->common->set_link(edev->cdev, ¶ms);
1914 static int qede_get_module_info(struct net_device *dev,
1915 struct ethtool_modinfo *modinfo)
1917 struct qede_dev *edev = netdev_priv(dev);
1921 /* Read first 4 bytes to find the sfp type */
1922 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1923 QED_I2C_DEV_ADDR_A0, 0, 4);
1925 DP_ERR(edev, "Failed reading EEPROM data %d\n", rc);
1930 case 0x3: /* SFP, SFP+, SFP-28 */
1931 modinfo->type = ETH_MODULE_SFF_8472;
1932 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1934 case 0xc: /* QSFP */
1935 case 0xd: /* QSFP+ */
1936 modinfo->type = ETH_MODULE_SFF_8436;
1937 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1939 case 0x11: /* QSFP-28 */
1940 modinfo->type = ETH_MODULE_SFF_8636;
1941 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1944 DP_ERR(edev, "Unknown transceiver type 0x%x\n", buf[0]);
1951 static int qede_get_module_eeprom(struct net_device *dev,
1952 struct ethtool_eeprom *ee, u8 *data)
1954 struct qede_dev *edev = netdev_priv(dev);
1955 u32 start_addr = ee->offset, size = 0;
1959 /* Read A0 section */
1960 if (ee->offset < ETH_MODULE_SFF_8079_LEN) {
1961 /* Limit transfer size to the A0 section boundary */
1962 if (ee->offset + ee->len > ETH_MODULE_SFF_8079_LEN)
1963 size = ETH_MODULE_SFF_8079_LEN - ee->offset;
1967 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1968 QED_I2C_DEV_ADDR_A0,
1971 DP_ERR(edev, "Failed reading A0 section %d\n", rc);
1979 /* Read A2 section */
1980 if (start_addr >= ETH_MODULE_SFF_8079_LEN &&
1981 start_addr < ETH_MODULE_SFF_8472_LEN) {
1982 size = ee->len - size;
1983 /* Limit transfer size to the A2 section boundary */
1984 if (start_addr + size > ETH_MODULE_SFF_8472_LEN)
1985 size = ETH_MODULE_SFF_8472_LEN - start_addr;
1986 start_addr -= ETH_MODULE_SFF_8079_LEN;
1987 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1988 QED_I2C_DEV_ADDR_A2,
1991 DP_VERBOSE(edev, QED_MSG_DEBUG,
1992 "Failed reading A2 section %d\n", rc);
2000 static int qede_set_dump(struct net_device *dev, struct ethtool_dump *val)
2002 struct qede_dev *edev = netdev_priv(dev);
2005 if (edev->dump_info.cmd == QEDE_DUMP_CMD_NONE) {
2006 if (val->flag > QEDE_DUMP_CMD_MAX) {
2007 DP_ERR(edev, "Invalid command %d\n", val->flag);
2010 edev->dump_info.cmd = val->flag;
2011 edev->dump_info.num_args = 0;
2015 if (edev->dump_info.num_args == QEDE_DUMP_MAX_ARGS) {
2016 DP_ERR(edev, "Arg count = %d\n", edev->dump_info.num_args);
2020 switch (edev->dump_info.cmd) {
2021 case QEDE_DUMP_CMD_NVM_CFG:
2022 edev->dump_info.args[edev->dump_info.num_args] = val->flag;
2023 edev->dump_info.num_args++;
2025 case QEDE_DUMP_CMD_GRCDUMP:
2026 rc = edev->ops->common->set_grc_config(edev->cdev,
2036 static int qede_get_dump_flag(struct net_device *dev,
2037 struct ethtool_dump *dump)
2039 struct qede_dev *edev = netdev_priv(dev);
2041 if (!edev->ops || !edev->ops->common) {
2042 DP_ERR(edev, "Edev ops not populated\n");
2046 dump->version = QEDE_DUMP_VERSION;
2047 switch (edev->dump_info.cmd) {
2048 case QEDE_DUMP_CMD_NVM_CFG:
2049 dump->flag = QEDE_DUMP_CMD_NVM_CFG;
2050 dump->len = edev->ops->common->read_nvm_cfg_len(edev->cdev,
2051 edev->dump_info.args[0]);
2053 case QEDE_DUMP_CMD_GRCDUMP:
2054 dump->flag = QEDE_DUMP_CMD_GRCDUMP;
2055 dump->len = edev->ops->common->dbg_all_data_size(edev->cdev);
2058 DP_ERR(edev, "Invalid cmd = %d\n", edev->dump_info.cmd);
2062 DP_VERBOSE(edev, QED_MSG_DEBUG,
2063 "dump->version = 0x%x dump->flag = %d dump->len = %d\n",
2064 dump->version, dump->flag, dump->len);
2068 static int qede_get_dump_data(struct net_device *dev,
2069 struct ethtool_dump *dump, void *buf)
2071 struct qede_dev *edev = netdev_priv(dev);
2074 if (!edev->ops || !edev->ops->common) {
2075 DP_ERR(edev, "Edev ops not populated\n");
2080 switch (edev->dump_info.cmd) {
2081 case QEDE_DUMP_CMD_NVM_CFG:
2082 if (edev->dump_info.num_args != QEDE_DUMP_NVM_ARG_COUNT) {
2083 DP_ERR(edev, "Arg count = %d required = %d\n",
2084 edev->dump_info.num_args,
2085 QEDE_DUMP_NVM_ARG_COUNT);
2089 rc = edev->ops->common->read_nvm_cfg(edev->cdev, (u8 **)&buf,
2090 edev->dump_info.args[0],
2091 edev->dump_info.args[1]);
2093 case QEDE_DUMP_CMD_GRCDUMP:
2094 memset(buf, 0, dump->len);
2095 rc = edev->ops->common->dbg_all_data(edev->cdev, buf);
2098 DP_ERR(edev, "Invalid cmd = %d\n", edev->dump_info.cmd);
2104 edev->dump_info.cmd = QEDE_DUMP_CMD_NONE;
2105 edev->dump_info.num_args = 0;
2106 memset(edev->dump_info.args, 0, sizeof(edev->dump_info.args));
2111 int qede_set_per_coalesce(struct net_device *dev, u32 queue,
2112 struct ethtool_coalesce *coal)
2114 struct qede_dev *edev = netdev_priv(dev);
2115 struct qede_fastpath *fp;
2119 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
2120 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
2122 "Can't support requested %s coalesce value [max supported value %d]\n",
2123 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
2129 rxc = (u16)coal->rx_coalesce_usecs;
2130 txc = (u16)coal->tx_coalesce_usecs;
2133 if (queue >= edev->num_queues) {
2134 DP_INFO(edev, "Invalid queue\n");
2139 if (edev->state != QEDE_STATE_OPEN) {
2144 fp = &edev->fp_array[queue];
2146 if (edev->fp_array[queue].type & QEDE_FASTPATH_RX) {
2147 rc = edev->ops->common->set_coalesce(edev->cdev,
2152 "Set RX coalesce error, rc = %d\n", rc);
2155 edev->coal_entry[queue].rxc = rxc;
2156 edev->coal_entry[queue].isvalid = true;
2159 if (edev->fp_array[queue].type & QEDE_FASTPATH_TX) {
2160 rc = edev->ops->common->set_coalesce(edev->cdev,
2165 "Set TX coalesce error, rc = %d\n", rc);
2168 edev->coal_entry[queue].txc = txc;
2169 edev->coal_entry[queue].isvalid = true;
2172 __qede_unlock(edev);
2177 static int qede_get_per_coalesce(struct net_device *dev,
2179 struct ethtool_coalesce *coal)
2181 void *rx_handle = NULL, *tx_handle = NULL;
2182 struct qede_dev *edev = netdev_priv(dev);
2183 struct qede_fastpath *fp;
2184 u16 rx_coal, tx_coal;
2187 rx_coal = QED_DEFAULT_RX_USECS;
2188 tx_coal = QED_DEFAULT_TX_USECS;
2190 memset(coal, 0, sizeof(struct ethtool_coalesce));
2193 if (queue >= edev->num_queues) {
2194 DP_INFO(edev, "Invalid queue\n");
2199 if (edev->state != QEDE_STATE_OPEN) {
2204 fp = &edev->fp_array[queue];
2206 if (fp->type & QEDE_FASTPATH_RX)
2207 rx_handle = fp->rxq->handle;
2209 rc = edev->ops->get_coalesce(edev->cdev, &rx_coal,
2212 DP_INFO(edev, "Read Rx coalesce error\n");
2216 fp = &edev->fp_array[queue];
2217 if (fp->type & QEDE_FASTPATH_TX)
2218 tx_handle = fp->txq->handle;
2220 rc = edev->ops->get_coalesce(edev->cdev, &tx_coal,
2223 DP_INFO(edev, "Read Tx coalesce error\n");
2226 __qede_unlock(edev);
2228 coal->rx_coalesce_usecs = rx_coal;
2229 coal->tx_coalesce_usecs = tx_coal;
2234 static const struct ethtool_ops qede_ethtool_ops = {
2235 .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
2236 .get_link_ksettings = qede_get_link_ksettings,
2237 .set_link_ksettings = qede_set_link_ksettings,
2238 .get_drvinfo = qede_get_drvinfo,
2239 .get_regs_len = qede_get_regs_len,
2240 .get_regs = qede_get_regs,
2241 .get_wol = qede_get_wol,
2242 .set_wol = qede_set_wol,
2243 .get_msglevel = qede_get_msglevel,
2244 .set_msglevel = qede_set_msglevel,
2245 .nway_reset = qede_nway_reset,
2246 .get_link = qede_get_link,
2247 .get_coalesce = qede_get_coalesce,
2248 .set_coalesce = qede_set_coalesce,
2249 .get_ringparam = qede_get_ringparam,
2250 .set_ringparam = qede_set_ringparam,
2251 .get_pauseparam = qede_get_pauseparam,
2252 .set_pauseparam = qede_set_pauseparam,
2253 .get_strings = qede_get_strings,
2254 .set_phys_id = qede_set_phys_id,
2255 .get_ethtool_stats = qede_get_ethtool_stats,
2256 .get_priv_flags = qede_get_priv_flags,
2257 .set_priv_flags = qede_set_priv_flags,
2258 .get_sset_count = qede_get_sset_count,
2259 .get_rxnfc = qede_get_rxnfc,
2260 .set_rxnfc = qede_set_rxnfc,
2261 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
2262 .get_rxfh_key_size = qede_get_rxfh_key_size,
2263 .get_rxfh = qede_get_rxfh,
2264 .set_rxfh = qede_set_rxfh,
2265 .get_ts_info = qede_get_ts_info,
2266 .get_channels = qede_get_channels,
2267 .set_channels = qede_set_channels,
2268 .self_test = qede_self_test,
2269 .get_module_info = qede_get_module_info,
2270 .get_module_eeprom = qede_get_module_eeprom,
2271 .get_eee = qede_get_eee,
2272 .set_eee = qede_set_eee,
2273 .get_fecparam = qede_get_fecparam,
2274 .set_fecparam = qede_set_fecparam,
2275 .get_tunable = qede_get_tunable,
2276 .set_tunable = qede_set_tunable,
2277 .get_per_queue_coalesce = qede_get_per_coalesce,
2278 .set_per_queue_coalesce = qede_set_per_coalesce,
2279 .flash_device = qede_flash_device,
2280 .get_dump_flag = qede_get_dump_flag,
2281 .get_dump_data = qede_get_dump_data,
2282 .set_dump = qede_set_dump,
2285 static const struct ethtool_ops qede_vf_ethtool_ops = {
2286 .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
2287 .get_link_ksettings = qede_get_link_ksettings,
2288 .get_drvinfo = qede_get_drvinfo,
2289 .get_msglevel = qede_get_msglevel,
2290 .set_msglevel = qede_set_msglevel,
2291 .get_link = qede_get_link,
2292 .get_coalesce = qede_get_coalesce,
2293 .set_coalesce = qede_set_coalesce,
2294 .get_ringparam = qede_get_ringparam,
2295 .set_ringparam = qede_set_ringparam,
2296 .get_strings = qede_get_strings,
2297 .get_ethtool_stats = qede_get_ethtool_stats,
2298 .get_priv_flags = qede_get_priv_flags,
2299 .get_sset_count = qede_get_sset_count,
2300 .get_rxnfc = qede_get_rxnfc,
2301 .set_rxnfc = qede_set_rxnfc,
2302 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
2303 .get_rxfh_key_size = qede_get_rxfh_key_size,
2304 .get_rxfh = qede_get_rxfh,
2305 .set_rxfh = qede_set_rxfh,
2306 .get_channels = qede_get_channels,
2307 .set_channels = qede_set_channels,
2308 .get_per_queue_coalesce = qede_get_per_coalesce,
2309 .set_per_queue_coalesce = qede_set_per_coalesce,
2310 .get_tunable = qede_get_tunable,
2311 .set_tunable = qede_set_tunable,
2314 void qede_set_ethtool_ops(struct net_device *dev)
2316 struct qede_dev *edev = netdev_priv(dev);
2319 dev->ethtool_ops = &qede_vf_ethtool_ops;
2321 dev->ethtool_ops = &qede_ethtool_ops;