1 /* QLogic qede NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include <linux/version.h>
33 #include <linux/types.h>
34 #include <linux/netdevice.h>
35 #include <linux/etherdevice.h>
36 #include <linux/ethtool.h>
37 #include <linux/string.h>
38 #include <linux/pci.h>
39 #include <linux/capability.h>
40 #include <linux/vmalloc.h>
44 #define QEDE_RQSTAT_OFFSET(stat_name) \
45 (offsetof(struct qede_rx_queue, stat_name))
46 #define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
47 #define QEDE_RQSTAT(stat_name) \
48 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
50 #define QEDE_SELFTEST_POLL_COUNT 100
54 char string[ETH_GSTRING_LEN];
55 } qede_rqstats_arr[] = {
56 QEDE_RQSTAT(rcv_pkts),
57 QEDE_RQSTAT(rx_hw_errors),
58 QEDE_RQSTAT(rx_alloc_errors),
59 QEDE_RQSTAT(rx_ip_frags),
60 QEDE_RQSTAT(xdp_no_pass),
63 #define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
64 #define QEDE_TQSTAT_OFFSET(stat_name) \
65 (offsetof(struct qede_tx_queue, stat_name))
66 #define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
67 #define QEDE_TQSTAT(stat_name) \
68 {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
69 #define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
72 char string[ETH_GSTRING_LEN];
73 } qede_tqstats_arr[] = {
74 QEDE_TQSTAT(xmit_pkts),
75 QEDE_TQSTAT(stopped_cnt),
78 #define QEDE_STAT_OFFSET(stat_name, type, base) \
79 (offsetof(type, stat_name) + (base))
80 #define QEDE_STAT_STRING(stat_name) (#stat_name)
81 #define _QEDE_STAT(stat_name, type, base, attr) \
82 {QEDE_STAT_OFFSET(stat_name, type, base), \
83 QEDE_STAT_STRING(stat_name), \
85 #define QEDE_STAT(stat_name) \
86 _QEDE_STAT(stat_name, struct qede_stats_common, 0, 0x0)
87 #define QEDE_PF_STAT(stat_name) \
88 _QEDE_STAT(stat_name, struct qede_stats_common, 0, \
89 BIT(QEDE_STAT_PF_ONLY))
90 #define QEDE_PF_BB_STAT(stat_name) \
91 _QEDE_STAT(stat_name, struct qede_stats_bb, \
92 offsetof(struct qede_stats, bb), \
93 BIT(QEDE_STAT_PF_ONLY) | BIT(QEDE_STAT_BB_ONLY))
94 #define QEDE_PF_AH_STAT(stat_name) \
95 _QEDE_STAT(stat_name, struct qede_stats_ah, \
96 offsetof(struct qede_stats, ah), \
97 BIT(QEDE_STAT_PF_ONLY) | BIT(QEDE_STAT_AH_ONLY))
100 char string[ETH_GSTRING_LEN];
102 #define QEDE_STAT_PF_ONLY 0
103 #define QEDE_STAT_BB_ONLY 1
104 #define QEDE_STAT_AH_ONLY 2
105 } qede_stats_arr[] = {
106 QEDE_STAT(rx_ucast_bytes),
107 QEDE_STAT(rx_mcast_bytes),
108 QEDE_STAT(rx_bcast_bytes),
109 QEDE_STAT(rx_ucast_pkts),
110 QEDE_STAT(rx_mcast_pkts),
111 QEDE_STAT(rx_bcast_pkts),
113 QEDE_STAT(tx_ucast_bytes),
114 QEDE_STAT(tx_mcast_bytes),
115 QEDE_STAT(tx_bcast_bytes),
116 QEDE_STAT(tx_ucast_pkts),
117 QEDE_STAT(tx_mcast_pkts),
118 QEDE_STAT(tx_bcast_pkts),
120 QEDE_PF_STAT(rx_64_byte_packets),
121 QEDE_PF_STAT(rx_65_to_127_byte_packets),
122 QEDE_PF_STAT(rx_128_to_255_byte_packets),
123 QEDE_PF_STAT(rx_256_to_511_byte_packets),
124 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
125 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
126 QEDE_PF_BB_STAT(rx_1519_to_1522_byte_packets),
127 QEDE_PF_BB_STAT(rx_1519_to_2047_byte_packets),
128 QEDE_PF_BB_STAT(rx_2048_to_4095_byte_packets),
129 QEDE_PF_BB_STAT(rx_4096_to_9216_byte_packets),
130 QEDE_PF_BB_STAT(rx_9217_to_16383_byte_packets),
131 QEDE_PF_AH_STAT(rx_1519_to_max_byte_packets),
132 QEDE_PF_STAT(tx_64_byte_packets),
133 QEDE_PF_STAT(tx_65_to_127_byte_packets),
134 QEDE_PF_STAT(tx_128_to_255_byte_packets),
135 QEDE_PF_STAT(tx_256_to_511_byte_packets),
136 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
137 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
138 QEDE_PF_BB_STAT(tx_1519_to_2047_byte_packets),
139 QEDE_PF_BB_STAT(tx_2048_to_4095_byte_packets),
140 QEDE_PF_BB_STAT(tx_4096_to_9216_byte_packets),
141 QEDE_PF_BB_STAT(tx_9217_to_16383_byte_packets),
142 QEDE_PF_AH_STAT(tx_1519_to_max_byte_packets),
143 QEDE_PF_STAT(rx_mac_crtl_frames),
144 QEDE_PF_STAT(tx_mac_ctrl_frames),
145 QEDE_PF_STAT(rx_pause_frames),
146 QEDE_PF_STAT(tx_pause_frames),
147 QEDE_PF_STAT(rx_pfc_frames),
148 QEDE_PF_STAT(tx_pfc_frames),
150 QEDE_PF_STAT(rx_crc_errors),
151 QEDE_PF_STAT(rx_align_errors),
152 QEDE_PF_STAT(rx_carrier_errors),
153 QEDE_PF_STAT(rx_oversize_packets),
154 QEDE_PF_STAT(rx_jabbers),
155 QEDE_PF_STAT(rx_undersize_packets),
156 QEDE_PF_STAT(rx_fragments),
157 QEDE_PF_BB_STAT(tx_lpi_entry_count),
158 QEDE_PF_BB_STAT(tx_total_collisions),
159 QEDE_PF_STAT(brb_truncates),
160 QEDE_PF_STAT(brb_discards),
161 QEDE_STAT(no_buff_discards),
162 QEDE_PF_STAT(mftag_filter_discards),
163 QEDE_PF_STAT(mac_filter_discards),
164 QEDE_PF_STAT(gft_filter_drop),
165 QEDE_STAT(tx_err_drop_pkts),
166 QEDE_STAT(ttl0_discard),
167 QEDE_STAT(packet_too_big_discard),
169 QEDE_STAT(coalesced_pkts),
170 QEDE_STAT(coalesced_events),
171 QEDE_STAT(coalesced_aborts_num),
172 QEDE_STAT(non_coalesced_pkts),
173 QEDE_STAT(coalesced_bytes),
175 QEDE_STAT(link_change_count),
178 #define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
179 #define QEDE_STAT_IS_PF_ONLY(i) \
180 test_bit(QEDE_STAT_PF_ONLY, &qede_stats_arr[i].attr)
181 #define QEDE_STAT_IS_BB_ONLY(i) \
182 test_bit(QEDE_STAT_BB_ONLY, &qede_stats_arr[i].attr)
183 #define QEDE_STAT_IS_AH_ONLY(i) \
184 test_bit(QEDE_STAT_AH_ONLY, &qede_stats_arr[i].attr)
191 static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
195 enum qede_ethtool_tests {
196 QEDE_ETHTOOL_INT_LOOPBACK,
197 QEDE_ETHTOOL_INTERRUPT_TEST,
198 QEDE_ETHTOOL_MEMORY_TEST,
199 QEDE_ETHTOOL_REGISTER_TEST,
200 QEDE_ETHTOOL_CLOCK_TEST,
201 QEDE_ETHTOOL_NVRAM_TEST,
202 QEDE_ETHTOOL_TEST_MAX
205 static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
206 "Internal loopback (offline)",
207 "Interrupt (online)\t",
208 "Memory (online)\t\t",
209 "Register (online)\t",
210 "Clock (online)\t\t",
211 "Nvram (online)\t\t",
214 static void qede_get_strings_stats_txq(struct qede_dev *edev,
215 struct qede_tx_queue *txq, u8 **buf)
219 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
221 sprintf(*buf, "%d [XDP]: %s",
222 QEDE_TXQ_XDP_TO_IDX(edev, txq),
223 qede_tqstats_arr[i].string);
225 sprintf(*buf, "%d_%d: %s", txq->index, txq->cos,
226 qede_tqstats_arr[i].string);
227 *buf += ETH_GSTRING_LEN;
231 static void qede_get_strings_stats_rxq(struct qede_dev *edev,
232 struct qede_rx_queue *rxq, u8 **buf)
236 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
237 sprintf(*buf, "%d: %s", rxq->rxq_id,
238 qede_rqstats_arr[i].string);
239 *buf += ETH_GSTRING_LEN;
243 static bool qede_is_irrelevant_stat(struct qede_dev *edev, int stat_index)
245 return (IS_VF(edev) && QEDE_STAT_IS_PF_ONLY(stat_index)) ||
246 (QEDE_IS_BB(edev) && QEDE_STAT_IS_AH_ONLY(stat_index)) ||
247 (QEDE_IS_AH(edev) && QEDE_STAT_IS_BB_ONLY(stat_index));
250 static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
252 struct qede_fastpath *fp;
255 /* Account for queue statistics */
256 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
257 fp = &edev->fp_array[i];
259 if (fp->type & QEDE_FASTPATH_RX)
260 qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
262 if (fp->type & QEDE_FASTPATH_XDP)
263 qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf);
265 if (fp->type & QEDE_FASTPATH_TX) {
268 for_each_cos_in_txq(edev, cos)
269 qede_get_strings_stats_txq(edev,
270 &fp->txq[cos], &buf);
274 /* Account for non-queue statistics */
275 for (i = 0; i < QEDE_NUM_STATS; i++) {
276 if (qede_is_irrelevant_stat(edev, i))
278 strcpy(buf, qede_stats_arr[i].string);
279 buf += ETH_GSTRING_LEN;
283 static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
285 struct qede_dev *edev = netdev_priv(dev);
289 qede_get_strings_stats(edev, buf);
291 case ETH_SS_PRIV_FLAGS:
292 memcpy(buf, qede_private_arr,
293 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
296 memcpy(buf, qede_tests_str_arr,
297 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
300 DP_VERBOSE(edev, QED_MSG_DEBUG,
301 "Unsupported stringset 0x%08x\n", stringset);
305 static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
309 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
310 **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
315 static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
319 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
320 **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
325 static void qede_get_ethtool_stats(struct net_device *dev,
326 struct ethtool_stats *stats, u64 *buf)
328 struct qede_dev *edev = netdev_priv(dev);
329 struct qede_fastpath *fp;
332 qede_fill_by_demand_stats(edev);
334 /* Need to protect the access to the fastpath array */
337 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
338 fp = &edev->fp_array[i];
340 if (fp->type & QEDE_FASTPATH_RX)
341 qede_get_ethtool_stats_rxq(fp->rxq, &buf);
343 if (fp->type & QEDE_FASTPATH_XDP)
344 qede_get_ethtool_stats_txq(fp->xdp_tx, &buf);
346 if (fp->type & QEDE_FASTPATH_TX) {
349 for_each_cos_in_txq(edev, cos)
350 qede_get_ethtool_stats_txq(&fp->txq[cos], &buf);
354 for (i = 0; i < QEDE_NUM_STATS; i++) {
355 if (qede_is_irrelevant_stat(edev, i))
357 *buf = *((u64 *)(((void *)&edev->stats) +
358 qede_stats_arr[i].offset));
366 static int qede_get_sset_count(struct net_device *dev, int stringset)
368 struct qede_dev *edev = netdev_priv(dev);
369 int num_stats = QEDE_NUM_STATS, i;
373 for (i = 0; i < QEDE_NUM_STATS; i++)
374 if (qede_is_irrelevant_stat(edev, i))
377 /* Account for the Regular Tx statistics */
378 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS *
379 edev->dev_info.num_tc;
381 /* Account for the Regular Rx statistics */
382 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
384 /* Account for XDP statistics [if needed] */
386 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS;
389 case ETH_SS_PRIV_FLAGS:
390 return QEDE_PRI_FLAG_LEN;
393 return QEDE_ETHTOOL_TEST_MAX;
397 DP_VERBOSE(edev, QED_MSG_DEBUG,
398 "Unsupported stringset 0x%08x\n", stringset);
403 static u32 qede_get_priv_flags(struct net_device *dev)
405 struct qede_dev *edev = netdev_priv(dev);
407 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
410 struct qede_link_mode_mapping {
412 u32 ethtool_link_mode;
415 static const struct qede_link_mode_mapping qed_lm_map[] = {
416 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
417 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
418 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
419 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
420 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
421 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
422 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
423 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
424 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
425 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
426 {QED_LM_100000baseKR4_Full_BIT,
427 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
430 #define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
434 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
435 if ((caps) & (qed_lm_map[i].qed_link_mode)) \
436 __set_bit(qed_lm_map[i].ethtool_link_mode,\
437 lk_ksettings->link_modes.name); \
441 #define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
445 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
446 if (test_bit(qed_lm_map[i].ethtool_link_mode, \
447 lk_ksettings->link_modes.name)) \
448 caps |= qed_lm_map[i].qed_link_mode; \
452 static int qede_get_link_ksettings(struct net_device *dev,
453 struct ethtool_link_ksettings *cmd)
455 struct ethtool_link_settings *base = &cmd->base;
456 struct qede_dev *edev = netdev_priv(dev);
457 struct qed_link_output current_link;
461 memset(¤t_link, 0, sizeof(current_link));
462 edev->ops->common->get_link(edev->cdev, ¤t_link);
464 ethtool_link_ksettings_zero_link_mode(cmd, supported);
465 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
467 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
468 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
470 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
471 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
473 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
474 base->speed = current_link.speed;
475 base->duplex = current_link.duplex;
477 base->speed = SPEED_UNKNOWN;
478 base->duplex = DUPLEX_UNKNOWN;
483 base->port = current_link.port;
484 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
490 static int qede_set_link_ksettings(struct net_device *dev,
491 const struct ethtool_link_ksettings *cmd)
493 const struct ethtool_link_settings *base = &cmd->base;
494 struct qede_dev *edev = netdev_priv(dev);
495 struct qed_link_output current_link;
496 struct qed_link_params params;
498 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
499 DP_INFO(edev, "Link settings are not allowed to be changed\n");
502 memset(¤t_link, 0, sizeof(current_link));
503 memset(¶ms, 0, sizeof(params));
504 edev->ops->common->get_link(edev->cdev, ¤t_link);
506 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
507 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
508 if (base->autoneg == AUTONEG_ENABLE) {
509 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
510 DP_INFO(edev, "Auto negotiation is not supported\n");
514 params.autoneg = true;
515 params.forced_speed = 0;
516 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
517 } else { /* forced speed */
518 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
519 params.autoneg = false;
520 params.forced_speed = base->speed;
521 switch (base->speed) {
523 if (!(current_link.supported_caps &
524 QED_LM_1000baseT_Full_BIT)) {
525 DP_INFO(edev, "1G speed not supported\n");
528 params.adv_speeds = QED_LM_1000baseT_Full_BIT;
531 if (!(current_link.supported_caps &
532 QED_LM_10000baseKR_Full_BIT)) {
533 DP_INFO(edev, "10G speed not supported\n");
536 params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
539 if (!(current_link.supported_caps &
540 QED_LM_25000baseKR_Full_BIT)) {
541 DP_INFO(edev, "25G speed not supported\n");
544 params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
547 if (!(current_link.supported_caps &
548 QED_LM_40000baseLR4_Full_BIT)) {
549 DP_INFO(edev, "40G speed not supported\n");
552 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
555 if (!(current_link.supported_caps &
556 QED_LM_50000baseKR2_Full_BIT)) {
557 DP_INFO(edev, "50G speed not supported\n");
560 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
563 if (!(current_link.supported_caps &
564 QED_LM_100000baseKR4_Full_BIT)) {
565 DP_INFO(edev, "100G speed not supported\n");
568 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
571 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
576 params.link_up = true;
577 edev->ops->common->set_link(edev->cdev, ¶ms);
582 static void qede_get_drvinfo(struct net_device *ndev,
583 struct ethtool_drvinfo *info)
585 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
586 struct qede_dev *edev = netdev_priv(ndev);
588 strlcpy(info->driver, "qede", sizeof(info->driver));
589 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
591 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
592 edev->dev_info.common.fw_major,
593 edev->dev_info.common.fw_minor,
594 edev->dev_info.common.fw_rev,
595 edev->dev_info.common.fw_eng);
597 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
598 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
599 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
600 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
601 edev->dev_info.common.mfw_rev & 0xFF);
603 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
604 sizeof(info->fw_version)) {
605 snprintf(info->fw_version, sizeof(info->fw_version),
606 "mfw %s storm %s", mfw, storm);
608 snprintf(info->fw_version, sizeof(info->fw_version),
609 "%s %s", mfw, storm);
612 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
615 static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
617 struct qede_dev *edev = netdev_priv(ndev);
619 if (edev->dev_info.common.wol_support) {
620 wol->supported = WAKE_MAGIC;
621 wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
625 static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
627 struct qede_dev *edev = netdev_priv(ndev);
631 if (wol->wolopts & ~WAKE_MAGIC) {
633 "Can't support WoL options other than magic-packet\n");
637 wol_requested = !!(wol->wolopts & WAKE_MAGIC);
638 if (wol_requested == edev->wol_enabled)
641 /* Need to actually change configuration */
642 if (!edev->dev_info.common.wol_support) {
643 DP_INFO(edev, "Device doesn't support WoL\n");
647 rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
649 edev->wol_enabled = wol_requested;
654 static u32 qede_get_msglevel(struct net_device *ndev)
656 struct qede_dev *edev = netdev_priv(ndev);
658 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
661 static void qede_set_msglevel(struct net_device *ndev, u32 level)
663 struct qede_dev *edev = netdev_priv(ndev);
667 qede_config_debug(level, &dp_module, &dp_level);
669 edev->dp_level = dp_level;
670 edev->dp_module = dp_module;
671 edev->ops->common->update_msglvl(edev->cdev,
672 dp_module, dp_level);
675 static int qede_nway_reset(struct net_device *dev)
677 struct qede_dev *edev = netdev_priv(dev);
678 struct qed_link_output current_link;
679 struct qed_link_params link_params;
681 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
682 DP_INFO(edev, "Link settings are not allowed to be changed\n");
686 if (!netif_running(dev))
689 memset(¤t_link, 0, sizeof(current_link));
690 edev->ops->common->get_link(edev->cdev, ¤t_link);
691 if (!current_link.link_up)
694 /* Toggle the link */
695 memset(&link_params, 0, sizeof(link_params));
696 link_params.link_up = false;
697 edev->ops->common->set_link(edev->cdev, &link_params);
698 link_params.link_up = true;
699 edev->ops->common->set_link(edev->cdev, &link_params);
704 static u32 qede_get_link(struct net_device *dev)
706 struct qede_dev *edev = netdev_priv(dev);
707 struct qed_link_output current_link;
709 memset(¤t_link, 0, sizeof(current_link));
710 edev->ops->common->get_link(edev->cdev, ¤t_link);
712 return current_link.link_up;
715 static int qede_flash_device(struct net_device *dev,
716 struct ethtool_flash *flash)
718 struct qede_dev *edev = netdev_priv(dev);
720 return edev->ops->common->nvm_flash(edev->cdev, flash->data);
723 static int qede_get_coalesce(struct net_device *dev,
724 struct ethtool_coalesce *coal)
726 void *rx_handle = NULL, *tx_handle = NULL;
727 struct qede_dev *edev = netdev_priv(dev);
728 u16 rx_coal, tx_coal, i, rc = 0;
729 struct qede_fastpath *fp;
731 rx_coal = QED_DEFAULT_RX_USECS;
732 tx_coal = QED_DEFAULT_TX_USECS;
734 memset(coal, 0, sizeof(struct ethtool_coalesce));
737 if (edev->state == QEDE_STATE_OPEN) {
739 fp = &edev->fp_array[i];
741 if (fp->type & QEDE_FASTPATH_RX) {
742 rx_handle = fp->rxq->handle;
747 rc = edev->ops->get_coalesce(edev->cdev, &rx_coal, rx_handle);
749 DP_INFO(edev, "Read Rx coalesce error\n");
754 struct qede_tx_queue *txq;
756 fp = &edev->fp_array[i];
758 /* All TX queues of given fastpath uses same
759 * coalescing value, so no need to iterate over
760 * all TCs, TC0 txq should suffice.
762 if (fp->type & QEDE_FASTPATH_TX) {
763 txq = QEDE_FP_TC0_TXQ(fp);
764 tx_handle = txq->handle;
769 rc = edev->ops->get_coalesce(edev->cdev, &tx_coal, tx_handle);
771 DP_INFO(edev, "Read Tx coalesce error\n");
777 coal->rx_coalesce_usecs = rx_coal;
778 coal->tx_coalesce_usecs = tx_coal;
783 static int qede_set_coalesce(struct net_device *dev,
784 struct ethtool_coalesce *coal)
786 struct qede_dev *edev = netdev_priv(dev);
787 struct qede_fastpath *fp;
791 if (!netif_running(dev)) {
792 DP_INFO(edev, "Interface is down\n");
796 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
797 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
799 "Can't support requested %s coalesce value [max supported value %d]\n",
800 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx" :
801 "tx", QED_COALESCE_MAX);
805 rxc = (u16)coal->rx_coalesce_usecs;
806 txc = (u16)coal->tx_coalesce_usecs;
808 fp = &edev->fp_array[i];
810 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
811 rc = edev->ops->common->set_coalesce(edev->cdev,
816 "Set RX coalesce error, rc = %d\n", rc);
821 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
822 struct qede_tx_queue *txq;
824 /* All TX queues of given fastpath uses same
825 * coalescing value, so no need to iterate over
826 * all TCs, TC0 txq should suffice.
828 txq = QEDE_FP_TC0_TXQ(fp);
830 rc = edev->ops->common->set_coalesce(edev->cdev,
835 "Set TX coalesce error, rc = %d\n", rc);
844 static void qede_get_ringparam(struct net_device *dev,
845 struct ethtool_ringparam *ering)
847 struct qede_dev *edev = netdev_priv(dev);
849 ering->rx_max_pending = NUM_RX_BDS_MAX;
850 ering->rx_pending = edev->q_num_rx_buffers;
851 ering->tx_max_pending = NUM_TX_BDS_MAX;
852 ering->tx_pending = edev->q_num_tx_buffers;
855 static int qede_set_ringparam(struct net_device *dev,
856 struct ethtool_ringparam *ering)
858 struct qede_dev *edev = netdev_priv(dev);
860 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
861 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
862 ering->rx_pending, ering->tx_pending);
864 /* Validate legality of configuration */
865 if (ering->rx_pending > NUM_RX_BDS_MAX ||
866 ering->rx_pending < NUM_RX_BDS_MIN ||
867 ering->tx_pending > NUM_TX_BDS_MAX ||
868 ering->tx_pending < NUM_TX_BDS_MIN) {
869 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
870 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
871 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
872 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
876 /* Change ring size and re-load */
877 edev->q_num_rx_buffers = ering->rx_pending;
878 edev->q_num_tx_buffers = ering->tx_pending;
880 qede_reload(edev, NULL, false);
885 static void qede_get_pauseparam(struct net_device *dev,
886 struct ethtool_pauseparam *epause)
888 struct qede_dev *edev = netdev_priv(dev);
889 struct qed_link_output current_link;
891 memset(¤t_link, 0, sizeof(current_link));
892 edev->ops->common->get_link(edev->cdev, ¤t_link);
894 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
895 epause->autoneg = true;
896 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
897 epause->rx_pause = true;
898 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
899 epause->tx_pause = true;
901 DP_VERBOSE(edev, QED_MSG_DEBUG,
902 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
903 epause->cmd, epause->autoneg, epause->rx_pause,
907 static int qede_set_pauseparam(struct net_device *dev,
908 struct ethtool_pauseparam *epause)
910 struct qede_dev *edev = netdev_priv(dev);
911 struct qed_link_params params;
912 struct qed_link_output current_link;
914 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
916 "Pause settings are not allowed to be changed\n");
920 memset(¤t_link, 0, sizeof(current_link));
921 edev->ops->common->get_link(edev->cdev, ¤t_link);
923 memset(¶ms, 0, sizeof(params));
924 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
925 if (epause->autoneg) {
926 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
927 DP_INFO(edev, "autoneg not supported\n");
930 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
932 if (epause->rx_pause)
933 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
934 if (epause->tx_pause)
935 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
937 params.link_up = true;
938 edev->ops->common->set_link(edev->cdev, ¶ms);
943 static void qede_get_regs(struct net_device *ndev,
944 struct ethtool_regs *regs, void *buffer)
946 struct qede_dev *edev = netdev_priv(ndev);
949 memset(buffer, 0, regs->len);
951 if (edev->ops && edev->ops->common)
952 edev->ops->common->dbg_all_data(edev->cdev, buffer);
955 static int qede_get_regs_len(struct net_device *ndev)
957 struct qede_dev *edev = netdev_priv(ndev);
959 if (edev->ops && edev->ops->common)
960 return edev->ops->common->dbg_all_data_size(edev->cdev);
965 static void qede_update_mtu(struct qede_dev *edev,
966 struct qede_reload_args *args)
968 edev->ndev->mtu = args->u.mtu;
972 int qede_change_mtu(struct net_device *ndev, int new_mtu)
974 struct qede_dev *edev = netdev_priv(ndev);
975 struct qede_reload_args args;
977 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
978 "Configuring MTU size of %d\n", new_mtu);
980 if (new_mtu > PAGE_SIZE)
981 ndev->features &= ~NETIF_F_GRO_HW;
983 /* Set the mtu field and re-start the interface if needed */
984 args.u.mtu = new_mtu;
985 args.func = &qede_update_mtu;
986 qede_reload(edev, &args, false);
988 edev->ops->common->update_mtu(edev->cdev, new_mtu);
993 static void qede_get_channels(struct net_device *dev,
994 struct ethtool_channels *channels)
996 struct qede_dev *edev = netdev_priv(dev);
998 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
999 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
1000 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
1001 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
1003 channels->tx_count = edev->fp_num_tx;
1004 channels->rx_count = edev->fp_num_rx;
1007 static int qede_set_channels(struct net_device *dev,
1008 struct ethtool_channels *channels)
1010 struct qede_dev *edev = netdev_priv(dev);
1013 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1014 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
1015 channels->rx_count, channels->tx_count,
1016 channels->other_count, channels->combined_count);
1018 count = channels->rx_count + channels->tx_count +
1019 channels->combined_count;
1021 /* We don't support `other' channels */
1022 if (channels->other_count) {
1023 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1024 "command parameters not supported\n");
1028 if (!(channels->combined_count || (channels->rx_count &&
1029 channels->tx_count))) {
1030 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1031 "need to request at least one transmit and one receive channel\n");
1035 if (count > QEDE_MAX_RSS_CNT(edev)) {
1036 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1037 "requested channels = %d max supported channels = %d\n",
1038 count, QEDE_MAX_RSS_CNT(edev));
1042 /* Check if there was a change in the active parameters */
1043 if ((count == QEDE_QUEUE_CNT(edev)) &&
1044 (channels->tx_count == edev->fp_num_tx) &&
1045 (channels->rx_count == edev->fp_num_rx)) {
1046 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1047 "No change in active parameters\n");
1051 /* We need the number of queues to be divisible between the hwfns */
1052 if ((count % edev->dev_info.common.num_hwfns) ||
1053 (channels->tx_count % edev->dev_info.common.num_hwfns) ||
1054 (channels->rx_count % edev->dev_info.common.num_hwfns)) {
1055 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1056 "Number of channels must be divisible by %04x\n",
1057 edev->dev_info.common.num_hwfns);
1061 /* Set number of queues and reload if necessary */
1062 edev->req_queues = count;
1063 edev->req_num_tx = channels->tx_count;
1064 edev->req_num_rx = channels->rx_count;
1065 /* Reset the indirection table if rx queue count is updated */
1066 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
1067 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
1068 memset(edev->rss_ind_table, 0, sizeof(edev->rss_ind_table));
1071 qede_reload(edev, NULL, false);
1076 static int qede_get_ts_info(struct net_device *dev,
1077 struct ethtool_ts_info *info)
1079 struct qede_dev *edev = netdev_priv(dev);
1081 return qede_ptp_get_ts_info(edev, info);
1084 static int qede_set_phys_id(struct net_device *dev,
1085 enum ethtool_phys_id_state state)
1087 struct qede_dev *edev = netdev_priv(dev);
1091 case ETHTOOL_ID_ACTIVE:
1092 return 1; /* cycle on/off once per second */
1095 led_state = QED_LED_MODE_ON;
1098 case ETHTOOL_ID_OFF:
1099 led_state = QED_LED_MODE_OFF;
1102 case ETHTOOL_ID_INACTIVE:
1103 led_state = QED_LED_MODE_RESTORE;
1107 edev->ops->common->set_led(edev->cdev, led_state);
1112 static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1114 info->data = RXH_IP_SRC | RXH_IP_DST;
1116 switch (info->flow_type) {
1119 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1122 if (edev->rss_caps & QED_RSS_IPV4_UDP)
1123 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1126 if (edev->rss_caps & QED_RSS_IPV6_UDP)
1127 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1140 static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
1143 struct qede_dev *edev = netdev_priv(dev);
1146 switch (info->cmd) {
1147 case ETHTOOL_GRXRINGS:
1148 info->data = QEDE_RSS_COUNT(edev);
1151 rc = qede_get_rss_flags(edev, info);
1153 case ETHTOOL_GRXCLSRLCNT:
1154 info->rule_cnt = qede_get_arfs_filter_count(edev);
1155 info->data = QEDE_RFS_MAX_FLTR;
1157 case ETHTOOL_GRXCLSRULE:
1158 rc = qede_get_cls_rule_entry(edev, info);
1160 case ETHTOOL_GRXCLSRLALL:
1161 rc = qede_get_cls_rule_all(edev, info, rule_locs);
1164 DP_ERR(edev, "Command parameters not supported\n");
1171 static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1173 struct qed_update_vport_params *vport_update_params;
1174 u8 set_caps = 0, clr_caps = 0;
1177 DP_VERBOSE(edev, QED_MSG_DEBUG,
1178 "Set rss flags command parameters: flow type = %d, data = %llu\n",
1179 info->flow_type, info->data);
1181 switch (info->flow_type) {
1184 /* For TCP only 4-tuple hash is supported */
1185 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
1186 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1187 DP_INFO(edev, "Command parameters not supported\n");
1192 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1193 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1194 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1195 set_caps = QED_RSS_IPV4_UDP;
1196 DP_VERBOSE(edev, QED_MSG_DEBUG,
1197 "UDP 4-tuple enabled\n");
1198 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1199 clr_caps = QED_RSS_IPV4_UDP;
1200 DP_VERBOSE(edev, QED_MSG_DEBUG,
1201 "UDP 4-tuple disabled\n");
1207 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1208 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1209 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1210 set_caps = QED_RSS_IPV6_UDP;
1211 DP_VERBOSE(edev, QED_MSG_DEBUG,
1212 "UDP 4-tuple enabled\n");
1213 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1214 clr_caps = QED_RSS_IPV6_UDP;
1215 DP_VERBOSE(edev, QED_MSG_DEBUG,
1216 "UDP 4-tuple disabled\n");
1223 /* For IP only 2-tuple hash is supported */
1224 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1225 DP_INFO(edev, "Command parameters not supported\n");
1230 case AH_ESP_V4_FLOW:
1234 case AH_ESP_V6_FLOW:
1239 /* RSS is not supported for these protocols */
1241 DP_INFO(edev, "Command parameters not supported\n");
1249 /* No action is needed if there is no change in the rss capability */
1250 if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps))
1253 /* Update internal configuration */
1254 edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps);
1255 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1257 /* Re-configure if possible */
1259 if (edev->state == QEDE_STATE_OPEN) {
1260 vport_update_params = vzalloc(sizeof(*vport_update_params));
1261 if (!vport_update_params) {
1262 __qede_unlock(edev);
1265 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1266 &vport_update_params->update_rss_flg);
1267 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1268 vfree(vport_update_params);
1270 __qede_unlock(edev);
1275 static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1277 struct qede_dev *edev = netdev_priv(dev);
1280 switch (info->cmd) {
1282 rc = qede_set_rss_flags(edev, info);
1284 case ETHTOOL_SRXCLSRLINS:
1285 rc = qede_add_cls_rule(edev, info);
1287 case ETHTOOL_SRXCLSRLDEL:
1288 rc = qede_delete_flow_filter(edev, info->fs.location);
1291 DP_INFO(edev, "Command parameters not supported\n");
1298 static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1300 return QED_RSS_IND_TABLE_SIZE;
1303 static u32 qede_get_rxfh_key_size(struct net_device *dev)
1305 struct qede_dev *edev = netdev_priv(dev);
1307 return sizeof(edev->rss_key);
1310 static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1312 struct qede_dev *edev = netdev_priv(dev);
1316 *hfunc = ETH_RSS_HASH_TOP;
1321 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1322 indir[i] = edev->rss_ind_table[i];
1325 memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev));
1330 static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1331 const u8 *key, const u8 hfunc)
1333 struct qed_update_vport_params *vport_update_params;
1334 struct qede_dev *edev = netdev_priv(dev);
1337 if (edev->dev_info.common.num_hwfns > 1) {
1339 "RSS configuration is not supported for 100G devices\n");
1343 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1350 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1351 edev->rss_ind_table[i] = indir[i];
1352 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1356 memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev));
1357 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1361 if (edev->state == QEDE_STATE_OPEN) {
1362 vport_update_params = vzalloc(sizeof(*vport_update_params));
1363 if (!vport_update_params) {
1364 __qede_unlock(edev);
1367 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1368 &vport_update_params->update_rss_flg);
1369 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1370 vfree(vport_update_params);
1372 __qede_unlock(edev);
1377 /* This function enables the interrupt generation and the NAPI on the device */
1378 static void qede_netif_start(struct qede_dev *edev)
1382 if (!netif_running(edev->ndev))
1386 /* Update and reenable interrupts */
1387 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1388 napi_enable(&edev->fp_array[i].napi);
1392 /* This function disables the NAPI and the interrupt generation on the device */
1393 static void qede_netif_stop(struct qede_dev *edev)
1398 napi_disable(&edev->fp_array[i].napi);
1399 /* Disable interrupts */
1400 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1404 static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1405 struct sk_buff *skb)
1407 struct qede_tx_queue *txq = NULL;
1408 struct eth_tx_1st_bd *first_bd;
1414 struct qede_fastpath *fp = &edev->fp_array[i];
1416 if (fp->type & QEDE_FASTPATH_TX) {
1417 txq = QEDE_FP_TC0_TXQ(fp);
1423 DP_NOTICE(edev, "Tx path is not available\n");
1427 /* Fill the entry in the SW ring and the BDs in the FW ring */
1428 idx = txq->sw_tx_prod;
1429 txq->sw_tx_ring.skbs[idx].skb = skb;
1430 first_bd = qed_chain_produce(&txq->tx_pbl);
1431 memset(first_bd, 0, sizeof(*first_bd));
1432 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1433 first_bd->data.bd_flags.bitfields = val;
1434 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1435 val = val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
1436 first_bd->data.bitfields |= cpu_to_le16(val);
1438 /* Map skb linear data for DMA and set in the first BD */
1439 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1440 skb_headlen(skb), DMA_TO_DEVICE);
1441 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1442 DP_NOTICE(edev, "SKB mapping failed\n");
1445 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1447 /* update the first BD with the actual num BDs */
1448 first_bd->data.nbds = 1;
1449 txq->sw_tx_prod = (txq->sw_tx_prod + 1) % txq->num_tx_buffers;
1450 /* 'next page' entries are counted in the producer value */
1451 val = qed_chain_get_prod_idx(&txq->tx_pbl);
1452 txq->tx_db.data.bd_prod = cpu_to_le16(val);
1454 /* wmb makes sure that the BDs data is updated before updating the
1455 * producer, otherwise FW may read old data from the BDs.
1459 writel(txq->tx_db.raw, txq->doorbell_addr);
1461 /* mmiowb is needed to synchronize doorbell writes from more than one
1462 * processor. It guarantees that the write arrives to the device before
1463 * the queue lock is released and another start_xmit is called (possibly
1464 * on another CPU). Without this barrier, the next doorbell can bypass
1465 * this doorbell. This is applicable to IA64/Altix systems.
1469 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1470 if (qede_txq_has_work(txq))
1472 usleep_range(100, 200);
1475 if (!qede_txq_has_work(txq)) {
1476 DP_NOTICE(edev, "Tx completion didn't happen\n");
1480 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
1481 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1482 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
1483 txq->sw_tx_cons = (txq->sw_tx_cons + 1) % txq->num_tx_buffers;
1484 txq->sw_tx_ring.skbs[idx].skb = NULL;
1489 static int qede_selftest_receive_traffic(struct qede_dev *edev)
1491 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
1492 struct eth_fast_path_rx_reg_cqe *fp_cqe;
1493 struct qede_rx_queue *rxq = NULL;
1494 struct sw_rx_data *sw_rx_data;
1495 union eth_rx_cqe *cqe;
1496 int i, iter, rc = 0;
1500 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1501 rxq = edev->fp_array[i].rxq;
1507 DP_NOTICE(edev, "Rx path is not available\n");
1511 /* The packet is expected to receive on rx-queue 0 even though RSS is
1512 * enabled. This is because the queue 0 is configured as the default
1513 * queue and that the loopback traffic is not IP.
1515 for (iter = 0; iter < QEDE_SELFTEST_POLL_COUNT; iter++) {
1516 if (!qede_has_rx_work(rxq)) {
1517 usleep_range(100, 200);
1521 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1522 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1524 /* Memory barrier to prevent the CPU from doing speculative
1525 * reads of CQE/BD before reading hw_comp_cons. If the CQE is
1526 * read before it is written by FW, then FW writes CQE and SB,
1527 * and then the CPU reads the hw_comp_cons, it will use an old
1532 /* Get the CQE from the completion ring */
1533 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1535 /* Get the data from the SW ring */
1536 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1537 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1538 fp_cqe = &cqe->fast_path_regular;
1539 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1540 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1541 fp_cqe->placement_offset +
1542 sw_rx_data->page_offset +
1544 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1545 ether_addr_equal(data_ptr + ETH_ALEN,
1546 edev->ndev->dev_addr)) {
1547 for (i = ETH_HLEN; i < len; i++)
1548 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1553 qede_recycle_rx_bd_ring(rxq, 1);
1554 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1558 DP_INFO(edev, "Not the transmitted packet\n");
1559 qede_recycle_rx_bd_ring(rxq, 1);
1560 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1563 if (iter == QEDE_SELFTEST_POLL_COUNT) {
1564 DP_NOTICE(edev, "Failed to receive the traffic\n");
1568 qede_update_rx_prod(edev, rxq);
1573 static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1575 struct qed_link_params link_params;
1576 struct sk_buff *skb = NULL;
1581 if (!netif_running(edev->ndev)) {
1582 DP_NOTICE(edev, "Interface is down\n");
1586 qede_netif_stop(edev);
1588 /* Bring up the link in Loopback mode */
1589 memset(&link_params, 0, sizeof(link_params));
1590 link_params.link_up = true;
1591 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1592 link_params.loopback_mode = loopback_mode;
1593 edev->ops->common->set_link(edev->cdev, &link_params);
1595 /* Wait for loopback configuration to apply */
1596 msleep_interruptible(500);
1598 /* prepare the loopback packet */
1599 pkt_size = edev->ndev->mtu + ETH_HLEN;
1601 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1603 DP_INFO(edev, "Can't allocate skb\n");
1605 goto test_loopback_exit;
1607 packet = skb_put(skb, pkt_size);
1608 ether_addr_copy(packet, edev->ndev->dev_addr);
1609 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1610 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1611 for (i = ETH_HLEN; i < pkt_size; i++)
1612 packet[i] = (unsigned char)(i & 0xff);
1614 rc = qede_selftest_transmit_traffic(edev, skb);
1616 goto test_loopback_exit;
1618 rc = qede_selftest_receive_traffic(edev);
1620 goto test_loopback_exit;
1622 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1627 /* Bring up the link in Normal mode */
1628 memset(&link_params, 0, sizeof(link_params));
1629 link_params.link_up = true;
1630 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1631 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1632 edev->ops->common->set_link(edev->cdev, &link_params);
1634 /* Wait for loopback configuration to apply */
1635 msleep_interruptible(500);
1637 qede_netif_start(edev);
1642 static void qede_self_test(struct net_device *dev,
1643 struct ethtool_test *etest, u64 *buf)
1645 struct qede_dev *edev = netdev_priv(dev);
1647 DP_VERBOSE(edev, QED_MSG_DEBUG,
1648 "Self-test command parameters: offline = %d, external_lb = %d\n",
1649 (etest->flags & ETH_TEST_FL_OFFLINE),
1650 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1652 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1654 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1655 if (qede_selftest_run_loopback(edev,
1656 QED_LINK_LOOPBACK_INT_PHY)) {
1657 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1658 etest->flags |= ETH_TEST_FL_FAILED;
1662 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1663 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1664 etest->flags |= ETH_TEST_FL_FAILED;
1667 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1668 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1669 etest->flags |= ETH_TEST_FL_FAILED;
1672 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1673 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1674 etest->flags |= ETH_TEST_FL_FAILED;
1677 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1678 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1679 etest->flags |= ETH_TEST_FL_FAILED;
1682 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1683 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1684 etest->flags |= ETH_TEST_FL_FAILED;
1688 static int qede_set_tunable(struct net_device *dev,
1689 const struct ethtool_tunable *tuna,
1692 struct qede_dev *edev = netdev_priv(dev);
1696 case ETHTOOL_RX_COPYBREAK:
1698 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1699 DP_VERBOSE(edev, QED_MSG_DEBUG,
1700 "Invalid rx copy break value, range is [%u, %u]",
1701 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1705 edev->rx_copybreak = *(u32 *)data;
1714 static int qede_get_tunable(struct net_device *dev,
1715 const struct ethtool_tunable *tuna, void *data)
1717 struct qede_dev *edev = netdev_priv(dev);
1720 case ETHTOOL_RX_COPYBREAK:
1721 *(u32 *)data = edev->rx_copybreak;
1730 static int qede_get_eee(struct net_device *dev, struct ethtool_eee *edata)
1732 struct qede_dev *edev = netdev_priv(dev);
1733 struct qed_link_output current_link;
1735 memset(¤t_link, 0, sizeof(current_link));
1736 edev->ops->common->get_link(edev->cdev, ¤t_link);
1738 if (!current_link.eee_supported) {
1739 DP_INFO(edev, "EEE is not supported\n");
1743 if (current_link.eee.adv_caps & QED_EEE_1G_ADV)
1744 edata->advertised = ADVERTISED_1000baseT_Full;
1745 if (current_link.eee.adv_caps & QED_EEE_10G_ADV)
1746 edata->advertised |= ADVERTISED_10000baseT_Full;
1747 if (current_link.sup_caps & QED_EEE_1G_ADV)
1748 edata->supported = ADVERTISED_1000baseT_Full;
1749 if (current_link.sup_caps & QED_EEE_10G_ADV)
1750 edata->supported |= ADVERTISED_10000baseT_Full;
1751 if (current_link.eee.lp_adv_caps & QED_EEE_1G_ADV)
1752 edata->lp_advertised = ADVERTISED_1000baseT_Full;
1753 if (current_link.eee.lp_adv_caps & QED_EEE_10G_ADV)
1754 edata->lp_advertised |= ADVERTISED_10000baseT_Full;
1756 edata->tx_lpi_timer = current_link.eee.tx_lpi_timer;
1757 edata->eee_enabled = current_link.eee.enable;
1758 edata->tx_lpi_enabled = current_link.eee.tx_lpi_enable;
1759 edata->eee_active = current_link.eee_active;
1764 static int qede_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1766 struct qede_dev *edev = netdev_priv(dev);
1767 struct qed_link_output current_link;
1768 struct qed_link_params params;
1770 if (!edev->ops->common->can_link_change(edev->cdev)) {
1771 DP_INFO(edev, "Link settings are not allowed to be changed\n");
1775 memset(¤t_link, 0, sizeof(current_link));
1776 edev->ops->common->get_link(edev->cdev, ¤t_link);
1778 if (!current_link.eee_supported) {
1779 DP_INFO(edev, "EEE is not supported\n");
1783 memset(¶ms, 0, sizeof(params));
1784 params.override_flags |= QED_LINK_OVERRIDE_EEE_CONFIG;
1786 if (!(edata->advertised & (ADVERTISED_1000baseT_Full |
1787 ADVERTISED_10000baseT_Full)) ||
1788 ((edata->advertised & (ADVERTISED_1000baseT_Full |
1789 ADVERTISED_10000baseT_Full)) !=
1790 edata->advertised)) {
1791 DP_VERBOSE(edev, QED_MSG_DEBUG,
1792 "Invalid advertised capabilities %d\n",
1797 if (edata->advertised & ADVERTISED_1000baseT_Full)
1798 params.eee.adv_caps = QED_EEE_1G_ADV;
1799 if (edata->advertised & ADVERTISED_10000baseT_Full)
1800 params.eee.adv_caps |= QED_EEE_10G_ADV;
1801 params.eee.enable = edata->eee_enabled;
1802 params.eee.tx_lpi_enable = edata->tx_lpi_enabled;
1803 params.eee.tx_lpi_timer = edata->tx_lpi_timer;
1805 params.link_up = true;
1806 edev->ops->common->set_link(edev->cdev, ¶ms);
1811 static int qede_get_module_info(struct net_device *dev,
1812 struct ethtool_modinfo *modinfo)
1814 struct qede_dev *edev = netdev_priv(dev);
1818 /* Read first 4 bytes to find the sfp type */
1819 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1820 QED_I2C_DEV_ADDR_A0, 0, 4);
1822 DP_ERR(edev, "Failed reading EEPROM data %d\n", rc);
1827 case 0x3: /* SFP, SFP+, SFP-28 */
1828 modinfo->type = ETH_MODULE_SFF_8472;
1829 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1831 case 0xc: /* QSFP */
1832 case 0xd: /* QSFP+ */
1833 modinfo->type = ETH_MODULE_SFF_8436;
1834 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1836 case 0x11: /* QSFP-28 */
1837 modinfo->type = ETH_MODULE_SFF_8636;
1838 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1841 DP_ERR(edev, "Unknown transceiver type 0x%x\n", buf[0]);
1848 static int qede_get_module_eeprom(struct net_device *dev,
1849 struct ethtool_eeprom *ee, u8 *data)
1851 struct qede_dev *edev = netdev_priv(dev);
1852 u32 start_addr = ee->offset, size = 0;
1856 /* Read A0 section */
1857 if (ee->offset < ETH_MODULE_SFF_8079_LEN) {
1858 /* Limit transfer size to the A0 section boundary */
1859 if (ee->offset + ee->len > ETH_MODULE_SFF_8079_LEN)
1860 size = ETH_MODULE_SFF_8079_LEN - ee->offset;
1864 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1865 QED_I2C_DEV_ADDR_A0,
1868 DP_ERR(edev, "Failed reading A0 section %d\n", rc);
1876 /* Read A2 section */
1877 if (start_addr >= ETH_MODULE_SFF_8079_LEN &&
1878 start_addr < ETH_MODULE_SFF_8472_LEN) {
1879 size = ee->len - size;
1880 /* Limit transfer size to the A2 section boundary */
1881 if (start_addr + size > ETH_MODULE_SFF_8472_LEN)
1882 size = ETH_MODULE_SFF_8472_LEN - start_addr;
1883 start_addr -= ETH_MODULE_SFF_8079_LEN;
1884 rc = edev->ops->common->read_module_eeprom(edev->cdev, buf,
1885 QED_I2C_DEV_ADDR_A2,
1888 DP_VERBOSE(edev, QED_MSG_DEBUG,
1889 "Failed reading A2 section %d\n", rc);
1897 static const struct ethtool_ops qede_ethtool_ops = {
1898 .get_link_ksettings = qede_get_link_ksettings,
1899 .set_link_ksettings = qede_set_link_ksettings,
1900 .get_drvinfo = qede_get_drvinfo,
1901 .get_regs_len = qede_get_regs_len,
1902 .get_regs = qede_get_regs,
1903 .get_wol = qede_get_wol,
1904 .set_wol = qede_set_wol,
1905 .get_msglevel = qede_get_msglevel,
1906 .set_msglevel = qede_set_msglevel,
1907 .nway_reset = qede_nway_reset,
1908 .get_link = qede_get_link,
1909 .get_coalesce = qede_get_coalesce,
1910 .set_coalesce = qede_set_coalesce,
1911 .get_ringparam = qede_get_ringparam,
1912 .set_ringparam = qede_set_ringparam,
1913 .get_pauseparam = qede_get_pauseparam,
1914 .set_pauseparam = qede_set_pauseparam,
1915 .get_strings = qede_get_strings,
1916 .set_phys_id = qede_set_phys_id,
1917 .get_ethtool_stats = qede_get_ethtool_stats,
1918 .get_priv_flags = qede_get_priv_flags,
1919 .get_sset_count = qede_get_sset_count,
1920 .get_rxnfc = qede_get_rxnfc,
1921 .set_rxnfc = qede_set_rxnfc,
1922 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1923 .get_rxfh_key_size = qede_get_rxfh_key_size,
1924 .get_rxfh = qede_get_rxfh,
1925 .set_rxfh = qede_set_rxfh,
1926 .get_ts_info = qede_get_ts_info,
1927 .get_channels = qede_get_channels,
1928 .set_channels = qede_set_channels,
1929 .self_test = qede_self_test,
1930 .get_module_info = qede_get_module_info,
1931 .get_module_eeprom = qede_get_module_eeprom,
1932 .get_eee = qede_get_eee,
1933 .set_eee = qede_set_eee,
1935 .get_tunable = qede_get_tunable,
1936 .set_tunable = qede_set_tunable,
1937 .flash_device = qede_flash_device,
1940 static const struct ethtool_ops qede_vf_ethtool_ops = {
1941 .get_link_ksettings = qede_get_link_ksettings,
1942 .get_drvinfo = qede_get_drvinfo,
1943 .get_msglevel = qede_get_msglevel,
1944 .set_msglevel = qede_set_msglevel,
1945 .get_link = qede_get_link,
1946 .get_coalesce = qede_get_coalesce,
1947 .set_coalesce = qede_set_coalesce,
1948 .get_ringparam = qede_get_ringparam,
1949 .set_ringparam = qede_set_ringparam,
1950 .get_strings = qede_get_strings,
1951 .get_ethtool_stats = qede_get_ethtool_stats,
1952 .get_priv_flags = qede_get_priv_flags,
1953 .get_sset_count = qede_get_sset_count,
1954 .get_rxnfc = qede_get_rxnfc,
1955 .set_rxnfc = qede_set_rxnfc,
1956 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1957 .get_rxfh_key_size = qede_get_rxfh_key_size,
1958 .get_rxfh = qede_get_rxfh,
1959 .set_rxfh = qede_set_rxfh,
1960 .get_channels = qede_get_channels,
1961 .set_channels = qede_set_channels,
1962 .get_tunable = qede_get_tunable,
1963 .set_tunable = qede_set_tunable,
1966 void qede_set_ethtool_ops(struct net_device *dev)
1968 struct qede_dev *edev = netdev_priv(dev);
1971 dev->ethtool_ops = &qede_vf_ethtool_ops;
1973 dev->ethtool_ops = &qede_ethtool_ops;