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_STAT(tx_err_drop_pkts),
165 QEDE_STAT(ttl0_discard),
166 QEDE_STAT(packet_too_big_discard),
168 QEDE_STAT(coalesced_pkts),
169 QEDE_STAT(coalesced_events),
170 QEDE_STAT(coalesced_aborts_num),
171 QEDE_STAT(non_coalesced_pkts),
172 QEDE_STAT(coalesced_bytes),
175 #define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
176 #define QEDE_STAT_IS_PF_ONLY(i) \
177 test_bit(QEDE_STAT_PF_ONLY, &qede_stats_arr[i].attr)
178 #define QEDE_STAT_IS_BB_ONLY(i) \
179 test_bit(QEDE_STAT_BB_ONLY, &qede_stats_arr[i].attr)
180 #define QEDE_STAT_IS_AH_ONLY(i) \
181 test_bit(QEDE_STAT_AH_ONLY, &qede_stats_arr[i].attr)
188 static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
192 enum qede_ethtool_tests {
193 QEDE_ETHTOOL_INT_LOOPBACK,
194 QEDE_ETHTOOL_INTERRUPT_TEST,
195 QEDE_ETHTOOL_MEMORY_TEST,
196 QEDE_ETHTOOL_REGISTER_TEST,
197 QEDE_ETHTOOL_CLOCK_TEST,
198 QEDE_ETHTOOL_NVRAM_TEST,
199 QEDE_ETHTOOL_TEST_MAX
202 static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
203 "Internal loopback (offline)",
204 "Interrupt (online)\t",
205 "Memory (online)\t\t",
206 "Register (online)\t",
207 "Clock (online)\t\t",
208 "Nvram (online)\t\t",
211 static void qede_get_strings_stats_txq(struct qede_dev *edev,
212 struct qede_tx_queue *txq, u8 **buf)
216 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
218 sprintf(*buf, "%d [XDP]: %s",
219 QEDE_TXQ_XDP_TO_IDX(edev, txq),
220 qede_tqstats_arr[i].string);
222 sprintf(*buf, "%d: %s", txq->index,
223 qede_tqstats_arr[i].string);
224 *buf += ETH_GSTRING_LEN;
228 static void qede_get_strings_stats_rxq(struct qede_dev *edev,
229 struct qede_rx_queue *rxq, u8 **buf)
233 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
234 sprintf(*buf, "%d: %s", rxq->rxq_id,
235 qede_rqstats_arr[i].string);
236 *buf += ETH_GSTRING_LEN;
240 static bool qede_is_irrelevant_stat(struct qede_dev *edev, int stat_index)
242 return (IS_VF(edev) && QEDE_STAT_IS_PF_ONLY(stat_index)) ||
243 (QEDE_IS_BB(edev) && QEDE_STAT_IS_AH_ONLY(stat_index)) ||
244 (QEDE_IS_AH(edev) && QEDE_STAT_IS_BB_ONLY(stat_index));
247 static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
249 struct qede_fastpath *fp;
252 /* Account for queue statistics */
253 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
254 fp = &edev->fp_array[i];
256 if (fp->type & QEDE_FASTPATH_RX)
257 qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
259 if (fp->type & QEDE_FASTPATH_XDP)
260 qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf);
262 if (fp->type & QEDE_FASTPATH_TX)
263 qede_get_strings_stats_txq(edev, fp->txq, &buf);
266 /* Account for non-queue statistics */
267 for (i = 0; i < QEDE_NUM_STATS; i++) {
268 if (qede_is_irrelevant_stat(edev, i))
270 strcpy(buf, qede_stats_arr[i].string);
271 buf += ETH_GSTRING_LEN;
275 static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
277 struct qede_dev *edev = netdev_priv(dev);
281 qede_get_strings_stats(edev, buf);
283 case ETH_SS_PRIV_FLAGS:
284 memcpy(buf, qede_private_arr,
285 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
288 memcpy(buf, qede_tests_str_arr,
289 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
292 DP_VERBOSE(edev, QED_MSG_DEBUG,
293 "Unsupported stringset 0x%08x\n", stringset);
297 static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
301 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
302 **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
307 static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
311 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
312 **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
317 static void qede_get_ethtool_stats(struct net_device *dev,
318 struct ethtool_stats *stats, u64 *buf)
320 struct qede_dev *edev = netdev_priv(dev);
321 struct qede_fastpath *fp;
324 qede_fill_by_demand_stats(edev);
326 /* Need to protect the access to the fastpath array */
329 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
330 fp = &edev->fp_array[i];
332 if (fp->type & QEDE_FASTPATH_RX)
333 qede_get_ethtool_stats_rxq(fp->rxq, &buf);
335 if (fp->type & QEDE_FASTPATH_XDP)
336 qede_get_ethtool_stats_txq(fp->xdp_tx, &buf);
338 if (fp->type & QEDE_FASTPATH_TX)
339 qede_get_ethtool_stats_txq(fp->txq, &buf);
342 for (i = 0; i < QEDE_NUM_STATS; i++) {
343 if (qede_is_irrelevant_stat(edev, i))
345 *buf = *((u64 *)(((void *)&edev->stats) +
346 qede_stats_arr[i].offset));
354 static int qede_get_sset_count(struct net_device *dev, int stringset)
356 struct qede_dev *edev = netdev_priv(dev);
357 int num_stats = QEDE_NUM_STATS, i;
361 for (i = 0; i < QEDE_NUM_STATS; i++)
362 if (qede_is_irrelevant_stat(edev, i))
365 /* Account for the Regular Tx statistics */
366 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS;
368 /* Account for the Regular Rx statistics */
369 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
371 /* Account for XDP statistics [if needed] */
373 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS;
376 case ETH_SS_PRIV_FLAGS:
377 return QEDE_PRI_FLAG_LEN;
380 return QEDE_ETHTOOL_TEST_MAX;
384 DP_VERBOSE(edev, QED_MSG_DEBUG,
385 "Unsupported stringset 0x%08x\n", stringset);
390 static u32 qede_get_priv_flags(struct net_device *dev)
392 struct qede_dev *edev = netdev_priv(dev);
394 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
397 struct qede_link_mode_mapping {
399 u32 ethtool_link_mode;
402 static const struct qede_link_mode_mapping qed_lm_map[] = {
403 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
404 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
405 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
406 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
407 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
408 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
409 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
410 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
411 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
412 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
413 {QED_LM_100000baseKR4_Full_BIT,
414 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
417 #define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
421 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
422 if ((caps) & (qed_lm_map[i].qed_link_mode)) \
423 __set_bit(qed_lm_map[i].ethtool_link_mode,\
424 lk_ksettings->link_modes.name); \
428 #define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
432 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
433 if (test_bit(qed_lm_map[i].ethtool_link_mode, \
434 lk_ksettings->link_modes.name)) \
435 caps |= qed_lm_map[i].qed_link_mode; \
439 static int qede_get_link_ksettings(struct net_device *dev,
440 struct ethtool_link_ksettings *cmd)
442 struct ethtool_link_settings *base = &cmd->base;
443 struct qede_dev *edev = netdev_priv(dev);
444 struct qed_link_output current_link;
448 memset(¤t_link, 0, sizeof(current_link));
449 edev->ops->common->get_link(edev->cdev, ¤t_link);
451 ethtool_link_ksettings_zero_link_mode(cmd, supported);
452 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
454 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
455 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
457 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
458 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
460 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
461 base->speed = current_link.speed;
462 base->duplex = current_link.duplex;
464 base->speed = SPEED_UNKNOWN;
465 base->duplex = DUPLEX_UNKNOWN;
470 base->port = current_link.port;
471 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
477 static int qede_set_link_ksettings(struct net_device *dev,
478 const struct ethtool_link_ksettings *cmd)
480 const struct ethtool_link_settings *base = &cmd->base;
481 struct qede_dev *edev = netdev_priv(dev);
482 struct qed_link_output current_link;
483 struct qed_link_params params;
485 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
486 DP_INFO(edev, "Link settings are not allowed to be changed\n");
489 memset(¤t_link, 0, sizeof(current_link));
490 memset(¶ms, 0, sizeof(params));
491 edev->ops->common->get_link(edev->cdev, ¤t_link);
493 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
494 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
495 if (base->autoneg == AUTONEG_ENABLE) {
496 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
497 DP_INFO(edev, "Auto negotiation is not supported\n");
501 params.autoneg = true;
502 params.forced_speed = 0;
503 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
504 } else { /* forced speed */
505 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
506 params.autoneg = false;
507 params.forced_speed = base->speed;
508 switch (base->speed) {
510 if (!(current_link.supported_caps &
511 QED_LM_1000baseT_Full_BIT)) {
512 DP_INFO(edev, "1G speed not supported\n");
515 params.adv_speeds = QED_LM_1000baseT_Full_BIT;
518 if (!(current_link.supported_caps &
519 QED_LM_10000baseKR_Full_BIT)) {
520 DP_INFO(edev, "10G speed not supported\n");
523 params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
526 if (!(current_link.supported_caps &
527 QED_LM_25000baseKR_Full_BIT)) {
528 DP_INFO(edev, "25G speed not supported\n");
531 params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
534 if (!(current_link.supported_caps &
535 QED_LM_40000baseLR4_Full_BIT)) {
536 DP_INFO(edev, "40G speed not supported\n");
539 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
542 if (!(current_link.supported_caps &
543 QED_LM_50000baseKR2_Full_BIT)) {
544 DP_INFO(edev, "50G speed not supported\n");
547 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
550 if (!(current_link.supported_caps &
551 QED_LM_100000baseKR4_Full_BIT)) {
552 DP_INFO(edev, "100G speed not supported\n");
555 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
558 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
563 params.link_up = true;
564 edev->ops->common->set_link(edev->cdev, ¶ms);
569 static void qede_get_drvinfo(struct net_device *ndev,
570 struct ethtool_drvinfo *info)
572 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
573 struct qede_dev *edev = netdev_priv(ndev);
575 strlcpy(info->driver, "qede", sizeof(info->driver));
576 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
578 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
579 edev->dev_info.common.fw_major,
580 edev->dev_info.common.fw_minor,
581 edev->dev_info.common.fw_rev,
582 edev->dev_info.common.fw_eng);
584 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
585 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
586 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
587 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
588 edev->dev_info.common.mfw_rev & 0xFF);
590 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
591 sizeof(info->fw_version)) {
592 snprintf(info->fw_version, sizeof(info->fw_version),
593 "mfw %s storm %s", mfw, storm);
595 snprintf(info->fw_version, sizeof(info->fw_version),
596 "%s %s", mfw, storm);
599 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
602 static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
604 struct qede_dev *edev = netdev_priv(ndev);
606 if (edev->dev_info.common.wol_support) {
607 wol->supported = WAKE_MAGIC;
608 wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
612 static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
614 struct qede_dev *edev = netdev_priv(ndev);
618 if (wol->wolopts & ~WAKE_MAGIC) {
620 "Can't support WoL options other than magic-packet\n");
624 wol_requested = !!(wol->wolopts & WAKE_MAGIC);
625 if (wol_requested == edev->wol_enabled)
628 /* Need to actually change configuration */
629 if (!edev->dev_info.common.wol_support) {
630 DP_INFO(edev, "Device doesn't support WoL\n");
634 rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
636 edev->wol_enabled = wol_requested;
641 static u32 qede_get_msglevel(struct net_device *ndev)
643 struct qede_dev *edev = netdev_priv(ndev);
645 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
648 static void qede_set_msglevel(struct net_device *ndev, u32 level)
650 struct qede_dev *edev = netdev_priv(ndev);
654 qede_config_debug(level, &dp_module, &dp_level);
656 edev->dp_level = dp_level;
657 edev->dp_module = dp_module;
658 edev->ops->common->update_msglvl(edev->cdev,
659 dp_module, dp_level);
662 static int qede_nway_reset(struct net_device *dev)
664 struct qede_dev *edev = netdev_priv(dev);
665 struct qed_link_output current_link;
666 struct qed_link_params link_params;
668 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
669 DP_INFO(edev, "Link settings are not allowed to be changed\n");
673 if (!netif_running(dev))
676 memset(¤t_link, 0, sizeof(current_link));
677 edev->ops->common->get_link(edev->cdev, ¤t_link);
678 if (!current_link.link_up)
681 /* Toggle the link */
682 memset(&link_params, 0, sizeof(link_params));
683 link_params.link_up = false;
684 edev->ops->common->set_link(edev->cdev, &link_params);
685 link_params.link_up = true;
686 edev->ops->common->set_link(edev->cdev, &link_params);
691 static u32 qede_get_link(struct net_device *dev)
693 struct qede_dev *edev = netdev_priv(dev);
694 struct qed_link_output current_link;
696 memset(¤t_link, 0, sizeof(current_link));
697 edev->ops->common->get_link(edev->cdev, ¤t_link);
699 return current_link.link_up;
702 static int qede_get_coalesce(struct net_device *dev,
703 struct ethtool_coalesce *coal)
705 void *rx_handle = NULL, *tx_handle = NULL;
706 struct qede_dev *edev = netdev_priv(dev);
707 u16 rx_coal, tx_coal, i, rc = 0;
708 struct qede_fastpath *fp;
710 rx_coal = QED_DEFAULT_RX_USECS;
711 tx_coal = QED_DEFAULT_TX_USECS;
713 memset(coal, 0, sizeof(struct ethtool_coalesce));
716 if (edev->state == QEDE_STATE_OPEN) {
718 fp = &edev->fp_array[i];
720 if (fp->type & QEDE_FASTPATH_RX) {
721 rx_handle = fp->rxq->handle;
726 rc = edev->ops->get_coalesce(edev->cdev, &rx_coal, rx_handle);
728 DP_INFO(edev, "Read Rx coalesce error\n");
733 fp = &edev->fp_array[i];
734 if (fp->type & QEDE_FASTPATH_TX) {
735 tx_handle = fp->txq->handle;
740 rc = edev->ops->get_coalesce(edev->cdev, &tx_coal, tx_handle);
742 DP_INFO(edev, "Read Tx coalesce error\n");
748 coal->rx_coalesce_usecs = rx_coal;
749 coal->tx_coalesce_usecs = tx_coal;
754 static int qede_set_coalesce(struct net_device *dev,
755 struct ethtool_coalesce *coal)
757 struct qede_dev *edev = netdev_priv(dev);
758 struct qede_fastpath *fp;
762 if (!netif_running(dev)) {
763 DP_INFO(edev, "Interface is down\n");
767 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
768 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
770 "Can't support requested %s coalesce value [max supported value %d]\n",
771 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx" :
772 "tx", QED_COALESCE_MAX);
776 rxc = (u16)coal->rx_coalesce_usecs;
777 txc = (u16)coal->tx_coalesce_usecs;
779 fp = &edev->fp_array[i];
781 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
782 rc = edev->ops->common->set_coalesce(edev->cdev,
787 "Set RX coalesce error, rc = %d\n", rc);
792 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
793 rc = edev->ops->common->set_coalesce(edev->cdev,
798 "Set TX coalesce error, rc = %d\n", rc);
807 static void qede_get_ringparam(struct net_device *dev,
808 struct ethtool_ringparam *ering)
810 struct qede_dev *edev = netdev_priv(dev);
812 ering->rx_max_pending = NUM_RX_BDS_MAX;
813 ering->rx_pending = edev->q_num_rx_buffers;
814 ering->tx_max_pending = NUM_TX_BDS_MAX;
815 ering->tx_pending = edev->q_num_tx_buffers;
818 static int qede_set_ringparam(struct net_device *dev,
819 struct ethtool_ringparam *ering)
821 struct qede_dev *edev = netdev_priv(dev);
823 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
824 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
825 ering->rx_pending, ering->tx_pending);
827 /* Validate legality of configuration */
828 if (ering->rx_pending > NUM_RX_BDS_MAX ||
829 ering->rx_pending < NUM_RX_BDS_MIN ||
830 ering->tx_pending > NUM_TX_BDS_MAX ||
831 ering->tx_pending < NUM_TX_BDS_MIN) {
832 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
833 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
834 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
835 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
839 /* Change ring size and re-load */
840 edev->q_num_rx_buffers = ering->rx_pending;
841 edev->q_num_tx_buffers = ering->tx_pending;
843 qede_reload(edev, NULL, false);
848 static void qede_get_pauseparam(struct net_device *dev,
849 struct ethtool_pauseparam *epause)
851 struct qede_dev *edev = netdev_priv(dev);
852 struct qed_link_output current_link;
854 memset(¤t_link, 0, sizeof(current_link));
855 edev->ops->common->get_link(edev->cdev, ¤t_link);
857 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
858 epause->autoneg = true;
859 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
860 epause->rx_pause = true;
861 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
862 epause->tx_pause = true;
864 DP_VERBOSE(edev, QED_MSG_DEBUG,
865 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
866 epause->cmd, epause->autoneg, epause->rx_pause,
870 static int qede_set_pauseparam(struct net_device *dev,
871 struct ethtool_pauseparam *epause)
873 struct qede_dev *edev = netdev_priv(dev);
874 struct qed_link_params params;
875 struct qed_link_output current_link;
877 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
879 "Pause settings are not allowed to be changed\n");
883 memset(¤t_link, 0, sizeof(current_link));
884 edev->ops->common->get_link(edev->cdev, ¤t_link);
886 memset(¶ms, 0, sizeof(params));
887 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
888 if (epause->autoneg) {
889 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
890 DP_INFO(edev, "autoneg not supported\n");
893 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
895 if (epause->rx_pause)
896 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
897 if (epause->tx_pause)
898 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
900 params.link_up = true;
901 edev->ops->common->set_link(edev->cdev, ¶ms);
906 static void qede_get_regs(struct net_device *ndev,
907 struct ethtool_regs *regs, void *buffer)
909 struct qede_dev *edev = netdev_priv(ndev);
912 memset(buffer, 0, regs->len);
914 if (edev->ops && edev->ops->common)
915 edev->ops->common->dbg_all_data(edev->cdev, buffer);
918 static int qede_get_regs_len(struct net_device *ndev)
920 struct qede_dev *edev = netdev_priv(ndev);
922 if (edev->ops && edev->ops->common)
923 return edev->ops->common->dbg_all_data_size(edev->cdev);
928 static void qede_update_mtu(struct qede_dev *edev,
929 struct qede_reload_args *args)
931 edev->ndev->mtu = args->u.mtu;
935 int qede_change_mtu(struct net_device *ndev, int new_mtu)
937 struct qede_dev *edev = netdev_priv(ndev);
938 struct qede_reload_args args;
940 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
941 "Configuring MTU size of %d\n", new_mtu);
943 /* Set the mtu field and re-start the interface if needed */
944 args.u.mtu = new_mtu;
945 args.func = &qede_update_mtu;
946 qede_reload(edev, &args, false);
948 edev->ops->common->update_mtu(edev->cdev, new_mtu);
953 static void qede_get_channels(struct net_device *dev,
954 struct ethtool_channels *channels)
956 struct qede_dev *edev = netdev_priv(dev);
958 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
959 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
960 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
961 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
963 channels->tx_count = edev->fp_num_tx;
964 channels->rx_count = edev->fp_num_rx;
967 static int qede_set_channels(struct net_device *dev,
968 struct ethtool_channels *channels)
970 struct qede_dev *edev = netdev_priv(dev);
973 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
974 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
975 channels->rx_count, channels->tx_count,
976 channels->other_count, channels->combined_count);
978 count = channels->rx_count + channels->tx_count +
979 channels->combined_count;
981 /* We don't support `other' channels */
982 if (channels->other_count) {
983 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
984 "command parameters not supported\n");
988 if (!(channels->combined_count || (channels->rx_count &&
989 channels->tx_count))) {
990 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
991 "need to request at least one transmit and one receive channel\n");
995 if (count > QEDE_MAX_RSS_CNT(edev)) {
996 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
997 "requested channels = %d max supported channels = %d\n",
998 count, QEDE_MAX_RSS_CNT(edev));
1002 /* Check if there was a change in the active parameters */
1003 if ((count == QEDE_QUEUE_CNT(edev)) &&
1004 (channels->tx_count == edev->fp_num_tx) &&
1005 (channels->rx_count == edev->fp_num_rx)) {
1006 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1007 "No change in active parameters\n");
1011 /* We need the number of queues to be divisible between the hwfns */
1012 if ((count % edev->dev_info.common.num_hwfns) ||
1013 (channels->tx_count % edev->dev_info.common.num_hwfns) ||
1014 (channels->rx_count % edev->dev_info.common.num_hwfns)) {
1015 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1016 "Number of channels must be divisible by %04x\n",
1017 edev->dev_info.common.num_hwfns);
1021 /* Set number of queues and reload if necessary */
1022 edev->req_queues = count;
1023 edev->req_num_tx = channels->tx_count;
1024 edev->req_num_rx = channels->rx_count;
1025 /* Reset the indirection table if rx queue count is updated */
1026 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
1027 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
1028 memset(edev->rss_ind_table, 0, sizeof(edev->rss_ind_table));
1031 qede_reload(edev, NULL, false);
1036 static int qede_get_ts_info(struct net_device *dev,
1037 struct ethtool_ts_info *info)
1039 struct qede_dev *edev = netdev_priv(dev);
1041 return qede_ptp_get_ts_info(edev, info);
1044 static int qede_set_phys_id(struct net_device *dev,
1045 enum ethtool_phys_id_state state)
1047 struct qede_dev *edev = netdev_priv(dev);
1051 case ETHTOOL_ID_ACTIVE:
1052 return 1; /* cycle on/off once per second */
1055 led_state = QED_LED_MODE_ON;
1058 case ETHTOOL_ID_OFF:
1059 led_state = QED_LED_MODE_OFF;
1062 case ETHTOOL_ID_INACTIVE:
1063 led_state = QED_LED_MODE_RESTORE;
1067 edev->ops->common->set_led(edev->cdev, led_state);
1072 static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1074 info->data = RXH_IP_SRC | RXH_IP_DST;
1076 switch (info->flow_type) {
1079 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1082 if (edev->rss_caps & QED_RSS_IPV4_UDP)
1083 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1086 if (edev->rss_caps & QED_RSS_IPV6_UDP)
1087 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1100 static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
1103 struct qede_dev *edev = netdev_priv(dev);
1106 switch (info->cmd) {
1107 case ETHTOOL_GRXRINGS:
1108 info->data = QEDE_RSS_COUNT(edev);
1111 rc = qede_get_rss_flags(edev, info);
1113 case ETHTOOL_GRXCLSRLCNT:
1114 info->rule_cnt = qede_get_arfs_filter_count(edev);
1115 info->data = QEDE_RFS_MAX_FLTR;
1117 case ETHTOOL_GRXCLSRULE:
1118 rc = qede_get_cls_rule_entry(edev, info);
1120 case ETHTOOL_GRXCLSRLALL:
1121 rc = qede_get_cls_rule_all(edev, info, rule_locs);
1124 DP_ERR(edev, "Command parameters not supported\n");
1131 static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1133 struct qed_update_vport_params *vport_update_params;
1134 u8 set_caps = 0, clr_caps = 0;
1137 DP_VERBOSE(edev, QED_MSG_DEBUG,
1138 "Set rss flags command parameters: flow type = %d, data = %llu\n",
1139 info->flow_type, info->data);
1141 switch (info->flow_type) {
1144 /* For TCP only 4-tuple hash is supported */
1145 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
1146 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1147 DP_INFO(edev, "Command parameters not supported\n");
1152 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1153 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1154 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1155 set_caps = QED_RSS_IPV4_UDP;
1156 DP_VERBOSE(edev, QED_MSG_DEBUG,
1157 "UDP 4-tuple enabled\n");
1158 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1159 clr_caps = QED_RSS_IPV4_UDP;
1160 DP_VERBOSE(edev, QED_MSG_DEBUG,
1161 "UDP 4-tuple disabled\n");
1167 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1168 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1169 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1170 set_caps = QED_RSS_IPV6_UDP;
1171 DP_VERBOSE(edev, QED_MSG_DEBUG,
1172 "UDP 4-tuple enabled\n");
1173 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1174 clr_caps = QED_RSS_IPV6_UDP;
1175 DP_VERBOSE(edev, QED_MSG_DEBUG,
1176 "UDP 4-tuple disabled\n");
1183 /* For IP only 2-tuple hash is supported */
1184 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1185 DP_INFO(edev, "Command parameters not supported\n");
1190 case AH_ESP_V4_FLOW:
1194 case AH_ESP_V6_FLOW:
1199 /* RSS is not supported for these protocols */
1201 DP_INFO(edev, "Command parameters not supported\n");
1209 /* No action is needed if there is no change in the rss capability */
1210 if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps))
1213 /* Update internal configuration */
1214 edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps);
1215 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1217 /* Re-configure if possible */
1219 if (edev->state == QEDE_STATE_OPEN) {
1220 vport_update_params = vzalloc(sizeof(*vport_update_params));
1221 if (!vport_update_params) {
1222 __qede_unlock(edev);
1225 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1226 &vport_update_params->update_rss_flg);
1227 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1228 vfree(vport_update_params);
1230 __qede_unlock(edev);
1235 static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1237 struct qede_dev *edev = netdev_priv(dev);
1240 switch (info->cmd) {
1242 rc = qede_set_rss_flags(edev, info);
1244 case ETHTOOL_SRXCLSRLINS:
1245 rc = qede_add_cls_rule(edev, info);
1247 case ETHTOOL_SRXCLSRLDEL:
1248 rc = qede_del_cls_rule(edev, info);
1251 DP_INFO(edev, "Command parameters not supported\n");
1258 static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1260 return QED_RSS_IND_TABLE_SIZE;
1263 static u32 qede_get_rxfh_key_size(struct net_device *dev)
1265 struct qede_dev *edev = netdev_priv(dev);
1267 return sizeof(edev->rss_key);
1270 static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1272 struct qede_dev *edev = netdev_priv(dev);
1276 *hfunc = ETH_RSS_HASH_TOP;
1281 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1282 indir[i] = edev->rss_ind_table[i];
1285 memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev));
1290 static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1291 const u8 *key, const u8 hfunc)
1293 struct qed_update_vport_params *vport_update_params;
1294 struct qede_dev *edev = netdev_priv(dev);
1297 if (edev->dev_info.common.num_hwfns > 1) {
1299 "RSS configuration is not supported for 100G devices\n");
1303 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1310 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1311 edev->rss_ind_table[i] = indir[i];
1312 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1316 memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev));
1317 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1321 if (edev->state == QEDE_STATE_OPEN) {
1322 vport_update_params = vzalloc(sizeof(*vport_update_params));
1323 if (!vport_update_params) {
1324 __qede_unlock(edev);
1327 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1328 &vport_update_params->update_rss_flg);
1329 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1330 vfree(vport_update_params);
1332 __qede_unlock(edev);
1337 /* This function enables the interrupt generation and the NAPI on the device */
1338 static void qede_netif_start(struct qede_dev *edev)
1342 if (!netif_running(edev->ndev))
1346 /* Update and reenable interrupts */
1347 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1348 napi_enable(&edev->fp_array[i].napi);
1352 /* This function disables the NAPI and the interrupt generation on the device */
1353 static void qede_netif_stop(struct qede_dev *edev)
1358 napi_disable(&edev->fp_array[i].napi);
1359 /* Disable interrupts */
1360 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1364 static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1365 struct sk_buff *skb)
1367 struct qede_tx_queue *txq = NULL;
1368 struct eth_tx_1st_bd *first_bd;
1374 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
1375 txq = edev->fp_array[i].txq;
1381 DP_NOTICE(edev, "Tx path is not available\n");
1385 /* Fill the entry in the SW ring and the BDs in the FW ring */
1386 idx = txq->sw_tx_prod;
1387 txq->sw_tx_ring.skbs[idx].skb = skb;
1388 first_bd = qed_chain_produce(&txq->tx_pbl);
1389 memset(first_bd, 0, sizeof(*first_bd));
1390 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1391 first_bd->data.bd_flags.bitfields = val;
1392 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1393 val = val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
1394 first_bd->data.bitfields |= cpu_to_le16(val);
1396 /* Map skb linear data for DMA and set in the first BD */
1397 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1398 skb_headlen(skb), DMA_TO_DEVICE);
1399 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1400 DP_NOTICE(edev, "SKB mapping failed\n");
1403 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1405 /* update the first BD with the actual num BDs */
1406 first_bd->data.nbds = 1;
1407 txq->sw_tx_prod = (txq->sw_tx_prod + 1) % txq->num_tx_buffers;
1408 /* 'next page' entries are counted in the producer value */
1409 val = qed_chain_get_prod_idx(&txq->tx_pbl);
1410 txq->tx_db.data.bd_prod = cpu_to_le16(val);
1412 /* wmb makes sure that the BDs data is updated before updating the
1413 * producer, otherwise FW may read old data from the BDs.
1417 writel(txq->tx_db.raw, txq->doorbell_addr);
1419 /* mmiowb is needed to synchronize doorbell writes from more than one
1420 * processor. It guarantees that the write arrives to the device before
1421 * the queue lock is released and another start_xmit is called (possibly
1422 * on another CPU). Without this barrier, the next doorbell can bypass
1423 * this doorbell. This is applicable to IA64/Altix systems.
1427 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1428 if (qede_txq_has_work(txq))
1430 usleep_range(100, 200);
1433 if (!qede_txq_has_work(txq)) {
1434 DP_NOTICE(edev, "Tx completion didn't happen\n");
1438 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
1439 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1440 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
1441 txq->sw_tx_cons = (txq->sw_tx_cons + 1) % txq->num_tx_buffers;
1442 txq->sw_tx_ring.skbs[idx].skb = NULL;
1447 static int qede_selftest_receive_traffic(struct qede_dev *edev)
1449 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
1450 struct eth_fast_path_rx_reg_cqe *fp_cqe;
1451 struct qede_rx_queue *rxq = NULL;
1452 struct sw_rx_data *sw_rx_data;
1453 union eth_rx_cqe *cqe;
1454 int i, iter, rc = 0;
1458 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1459 rxq = edev->fp_array[i].rxq;
1465 DP_NOTICE(edev, "Rx path is not available\n");
1469 /* The packet is expected to receive on rx-queue 0 even though RSS is
1470 * enabled. This is because the queue 0 is configured as the default
1471 * queue and that the loopback traffic is not IP.
1473 for (iter = 0; iter < QEDE_SELFTEST_POLL_COUNT; iter++) {
1474 if (!qede_has_rx_work(rxq)) {
1475 usleep_range(100, 200);
1479 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1480 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1482 /* Memory barrier to prevent the CPU from doing speculative
1483 * reads of CQE/BD before reading hw_comp_cons. If the CQE is
1484 * read before it is written by FW, then FW writes CQE and SB,
1485 * and then the CPU reads the hw_comp_cons, it will use an old
1490 /* Get the CQE from the completion ring */
1491 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1493 /* Get the data from the SW ring */
1494 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1495 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1496 fp_cqe = &cqe->fast_path_regular;
1497 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1498 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1499 fp_cqe->placement_offset +
1500 sw_rx_data->page_offset);
1501 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1502 ether_addr_equal(data_ptr + ETH_ALEN,
1503 edev->ndev->dev_addr)) {
1504 for (i = ETH_HLEN; i < len; i++)
1505 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1510 qede_recycle_rx_bd_ring(rxq, 1);
1511 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1515 DP_INFO(edev, "Not the transmitted packet\n");
1516 qede_recycle_rx_bd_ring(rxq, 1);
1517 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1520 if (iter == QEDE_SELFTEST_POLL_COUNT) {
1521 DP_NOTICE(edev, "Failed to receive the traffic\n");
1525 qede_update_rx_prod(edev, rxq);
1530 static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1532 struct qed_link_params link_params;
1533 struct sk_buff *skb = NULL;
1538 if (!netif_running(edev->ndev)) {
1539 DP_NOTICE(edev, "Interface is down\n");
1543 qede_netif_stop(edev);
1545 /* Bring up the link in Loopback mode */
1546 memset(&link_params, 0, sizeof(link_params));
1547 link_params.link_up = true;
1548 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1549 link_params.loopback_mode = loopback_mode;
1550 edev->ops->common->set_link(edev->cdev, &link_params);
1552 /* Wait for loopback configuration to apply */
1553 msleep_interruptible(500);
1555 /* prepare the loopback packet */
1556 pkt_size = edev->ndev->mtu + ETH_HLEN;
1558 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1560 DP_INFO(edev, "Can't allocate skb\n");
1562 goto test_loopback_exit;
1564 packet = skb_put(skb, pkt_size);
1565 ether_addr_copy(packet, edev->ndev->dev_addr);
1566 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1567 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1568 for (i = ETH_HLEN; i < pkt_size; i++)
1569 packet[i] = (unsigned char)(i & 0xff);
1571 rc = qede_selftest_transmit_traffic(edev, skb);
1573 goto test_loopback_exit;
1575 rc = qede_selftest_receive_traffic(edev);
1577 goto test_loopback_exit;
1579 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1584 /* Bring up the link in Normal mode */
1585 memset(&link_params, 0, sizeof(link_params));
1586 link_params.link_up = true;
1587 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1588 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1589 edev->ops->common->set_link(edev->cdev, &link_params);
1591 /* Wait for loopback configuration to apply */
1592 msleep_interruptible(500);
1594 qede_netif_start(edev);
1599 static void qede_self_test(struct net_device *dev,
1600 struct ethtool_test *etest, u64 *buf)
1602 struct qede_dev *edev = netdev_priv(dev);
1604 DP_VERBOSE(edev, QED_MSG_DEBUG,
1605 "Self-test command parameters: offline = %d, external_lb = %d\n",
1606 (etest->flags & ETH_TEST_FL_OFFLINE),
1607 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1609 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1611 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1612 if (qede_selftest_run_loopback(edev,
1613 QED_LINK_LOOPBACK_INT_PHY)) {
1614 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1615 etest->flags |= ETH_TEST_FL_FAILED;
1619 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1620 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1621 etest->flags |= ETH_TEST_FL_FAILED;
1624 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1625 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1626 etest->flags |= ETH_TEST_FL_FAILED;
1629 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1630 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1631 etest->flags |= ETH_TEST_FL_FAILED;
1634 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1635 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1636 etest->flags |= ETH_TEST_FL_FAILED;
1639 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1640 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1641 etest->flags |= ETH_TEST_FL_FAILED;
1645 static int qede_set_tunable(struct net_device *dev,
1646 const struct ethtool_tunable *tuna,
1649 struct qede_dev *edev = netdev_priv(dev);
1653 case ETHTOOL_RX_COPYBREAK:
1655 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1656 DP_VERBOSE(edev, QED_MSG_DEBUG,
1657 "Invalid rx copy break value, range is [%u, %u]",
1658 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1662 edev->rx_copybreak = *(u32 *)data;
1671 static int qede_get_tunable(struct net_device *dev,
1672 const struct ethtool_tunable *tuna, void *data)
1674 struct qede_dev *edev = netdev_priv(dev);
1677 case ETHTOOL_RX_COPYBREAK:
1678 *(u32 *)data = edev->rx_copybreak;
1687 static int qede_get_eee(struct net_device *dev, struct ethtool_eee *edata)
1689 struct qede_dev *edev = netdev_priv(dev);
1690 struct qed_link_output current_link;
1692 memset(¤t_link, 0, sizeof(current_link));
1693 edev->ops->common->get_link(edev->cdev, ¤t_link);
1695 if (!current_link.eee_supported) {
1696 DP_INFO(edev, "EEE is not supported\n");
1700 if (current_link.eee.adv_caps & QED_EEE_1G_ADV)
1701 edata->advertised = ADVERTISED_1000baseT_Full;
1702 if (current_link.eee.adv_caps & QED_EEE_10G_ADV)
1703 edata->advertised |= ADVERTISED_10000baseT_Full;
1704 if (current_link.sup_caps & QED_EEE_1G_ADV)
1705 edata->supported = ADVERTISED_1000baseT_Full;
1706 if (current_link.sup_caps & QED_EEE_10G_ADV)
1707 edata->supported |= ADVERTISED_10000baseT_Full;
1708 if (current_link.eee.lp_adv_caps & QED_EEE_1G_ADV)
1709 edata->lp_advertised = ADVERTISED_1000baseT_Full;
1710 if (current_link.eee.lp_adv_caps & QED_EEE_10G_ADV)
1711 edata->lp_advertised |= ADVERTISED_10000baseT_Full;
1713 edata->tx_lpi_timer = current_link.eee.tx_lpi_timer;
1714 edata->eee_enabled = current_link.eee.enable;
1715 edata->tx_lpi_enabled = current_link.eee.tx_lpi_enable;
1716 edata->eee_active = current_link.eee_active;
1721 static int qede_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1723 struct qede_dev *edev = netdev_priv(dev);
1724 struct qed_link_output current_link;
1725 struct qed_link_params params;
1727 if (!edev->ops->common->can_link_change(edev->cdev)) {
1728 DP_INFO(edev, "Link settings are not allowed to be changed\n");
1732 memset(¤t_link, 0, sizeof(current_link));
1733 edev->ops->common->get_link(edev->cdev, ¤t_link);
1735 if (!current_link.eee_supported) {
1736 DP_INFO(edev, "EEE is not supported\n");
1740 memset(¶ms, 0, sizeof(params));
1741 params.override_flags |= QED_LINK_OVERRIDE_EEE_CONFIG;
1743 if (!(edata->advertised & (ADVERTISED_1000baseT_Full |
1744 ADVERTISED_10000baseT_Full)) ||
1745 ((edata->advertised & (ADVERTISED_1000baseT_Full |
1746 ADVERTISED_10000baseT_Full)) !=
1747 edata->advertised)) {
1748 DP_VERBOSE(edev, QED_MSG_DEBUG,
1749 "Invalid advertised capabilities %d\n",
1754 if (edata->advertised & ADVERTISED_1000baseT_Full)
1755 params.eee.adv_caps = QED_EEE_1G_ADV;
1756 if (edata->advertised & ADVERTISED_10000baseT_Full)
1757 params.eee.adv_caps |= QED_EEE_10G_ADV;
1758 params.eee.enable = edata->eee_enabled;
1759 params.eee.tx_lpi_enable = edata->tx_lpi_enabled;
1760 params.eee.tx_lpi_timer = edata->tx_lpi_timer;
1762 params.link_up = true;
1763 edev->ops->common->set_link(edev->cdev, ¶ms);
1768 static const struct ethtool_ops qede_ethtool_ops = {
1769 .get_link_ksettings = qede_get_link_ksettings,
1770 .set_link_ksettings = qede_set_link_ksettings,
1771 .get_drvinfo = qede_get_drvinfo,
1772 .get_regs_len = qede_get_regs_len,
1773 .get_regs = qede_get_regs,
1774 .get_wol = qede_get_wol,
1775 .set_wol = qede_set_wol,
1776 .get_msglevel = qede_get_msglevel,
1777 .set_msglevel = qede_set_msglevel,
1778 .nway_reset = qede_nway_reset,
1779 .get_link = qede_get_link,
1780 .get_coalesce = qede_get_coalesce,
1781 .set_coalesce = qede_set_coalesce,
1782 .get_ringparam = qede_get_ringparam,
1783 .set_ringparam = qede_set_ringparam,
1784 .get_pauseparam = qede_get_pauseparam,
1785 .set_pauseparam = qede_set_pauseparam,
1786 .get_strings = qede_get_strings,
1787 .set_phys_id = qede_set_phys_id,
1788 .get_ethtool_stats = qede_get_ethtool_stats,
1789 .get_priv_flags = qede_get_priv_flags,
1790 .get_sset_count = qede_get_sset_count,
1791 .get_rxnfc = qede_get_rxnfc,
1792 .set_rxnfc = qede_set_rxnfc,
1793 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1794 .get_rxfh_key_size = qede_get_rxfh_key_size,
1795 .get_rxfh = qede_get_rxfh,
1796 .set_rxfh = qede_set_rxfh,
1797 .get_ts_info = qede_get_ts_info,
1798 .get_channels = qede_get_channels,
1799 .set_channels = qede_set_channels,
1800 .self_test = qede_self_test,
1801 .get_eee = qede_get_eee,
1802 .set_eee = qede_set_eee,
1804 .get_tunable = qede_get_tunable,
1805 .set_tunable = qede_set_tunable,
1808 static const struct ethtool_ops qede_vf_ethtool_ops = {
1809 .get_link_ksettings = qede_get_link_ksettings,
1810 .get_drvinfo = qede_get_drvinfo,
1811 .get_msglevel = qede_get_msglevel,
1812 .set_msglevel = qede_set_msglevel,
1813 .get_link = qede_get_link,
1814 .get_coalesce = qede_get_coalesce,
1815 .set_coalesce = qede_set_coalesce,
1816 .get_ringparam = qede_get_ringparam,
1817 .set_ringparam = qede_set_ringparam,
1818 .get_strings = qede_get_strings,
1819 .get_ethtool_stats = qede_get_ethtool_stats,
1820 .get_priv_flags = qede_get_priv_flags,
1821 .get_sset_count = qede_get_sset_count,
1822 .get_rxnfc = qede_get_rxnfc,
1823 .set_rxnfc = qede_set_rxnfc,
1824 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1825 .get_rxfh_key_size = qede_get_rxfh_key_size,
1826 .get_rxfh = qede_get_rxfh,
1827 .set_rxfh = qede_set_rxfh,
1828 .get_channels = qede_get_channels,
1829 .set_channels = qede_set_channels,
1830 .get_tunable = qede_get_tunable,
1831 .set_tunable = qede_set_tunable,
1834 void qede_set_ethtool_ops(struct net_device *dev)
1836 struct qede_dev *edev = netdev_priv(dev);
1839 dev->ethtool_ops = &qede_vf_ethtool_ops;
1841 dev->ethtool_ops = &qede_ethtool_ops;