1 /* QLogic qede NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
9 #include <linux/version.h>
10 #include <linux/types.h>
11 #include <linux/netdevice.h>
12 #include <linux/etherdevice.h>
13 #include <linux/ethtool.h>
14 #include <linux/string.h>
15 #include <linux/pci.h>
16 #include <linux/capability.h>
19 #define QEDE_RQSTAT_OFFSET(stat_name) \
20 (offsetof(struct qede_rx_queue, stat_name))
21 #define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
22 #define QEDE_RQSTAT(stat_name) \
23 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
25 #define QEDE_SELFTEST_POLL_COUNT 100
29 char string[ETH_GSTRING_LEN];
30 } qede_rqstats_arr[] = {
31 QEDE_RQSTAT(rcv_pkts),
32 QEDE_RQSTAT(rx_hw_errors),
33 QEDE_RQSTAT(rx_alloc_errors),
34 QEDE_RQSTAT(rx_ip_frags),
37 #define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
38 #define QEDE_TQSTAT_OFFSET(stat_name) \
39 (offsetof(struct qede_tx_queue, stat_name))
40 #define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
41 #define QEDE_TQSTAT(stat_name) \
42 {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
43 #define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
46 char string[ETH_GSTRING_LEN];
47 } qede_tqstats_arr[] = {
48 QEDE_TQSTAT(xmit_pkts),
49 QEDE_TQSTAT(stopped_cnt),
52 #define QEDE_STAT_OFFSET(stat_name) (offsetof(struct qede_stats, stat_name))
53 #define QEDE_STAT_STRING(stat_name) (#stat_name)
54 #define _QEDE_STAT(stat_name, pf_only) \
55 {QEDE_STAT_OFFSET(stat_name), QEDE_STAT_STRING(stat_name), pf_only}
56 #define QEDE_PF_STAT(stat_name) _QEDE_STAT(stat_name, true)
57 #define QEDE_STAT(stat_name) _QEDE_STAT(stat_name, false)
60 char string[ETH_GSTRING_LEN];
62 } qede_stats_arr[] = {
63 QEDE_STAT(rx_ucast_bytes),
64 QEDE_STAT(rx_mcast_bytes),
65 QEDE_STAT(rx_bcast_bytes),
66 QEDE_STAT(rx_ucast_pkts),
67 QEDE_STAT(rx_mcast_pkts),
68 QEDE_STAT(rx_bcast_pkts),
70 QEDE_STAT(tx_ucast_bytes),
71 QEDE_STAT(tx_mcast_bytes),
72 QEDE_STAT(tx_bcast_bytes),
73 QEDE_STAT(tx_ucast_pkts),
74 QEDE_STAT(tx_mcast_pkts),
75 QEDE_STAT(tx_bcast_pkts),
77 QEDE_PF_STAT(rx_64_byte_packets),
78 QEDE_PF_STAT(rx_65_to_127_byte_packets),
79 QEDE_PF_STAT(rx_128_to_255_byte_packets),
80 QEDE_PF_STAT(rx_256_to_511_byte_packets),
81 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
82 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
83 QEDE_PF_STAT(rx_1519_to_1522_byte_packets),
84 QEDE_PF_STAT(rx_1519_to_2047_byte_packets),
85 QEDE_PF_STAT(rx_2048_to_4095_byte_packets),
86 QEDE_PF_STAT(rx_4096_to_9216_byte_packets),
87 QEDE_PF_STAT(rx_9217_to_16383_byte_packets),
88 QEDE_PF_STAT(tx_64_byte_packets),
89 QEDE_PF_STAT(tx_65_to_127_byte_packets),
90 QEDE_PF_STAT(tx_128_to_255_byte_packets),
91 QEDE_PF_STAT(tx_256_to_511_byte_packets),
92 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
93 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
94 QEDE_PF_STAT(tx_1519_to_2047_byte_packets),
95 QEDE_PF_STAT(tx_2048_to_4095_byte_packets),
96 QEDE_PF_STAT(tx_4096_to_9216_byte_packets),
97 QEDE_PF_STAT(tx_9217_to_16383_byte_packets),
99 QEDE_PF_STAT(rx_mac_crtl_frames),
100 QEDE_PF_STAT(tx_mac_ctrl_frames),
101 QEDE_PF_STAT(rx_pause_frames),
102 QEDE_PF_STAT(tx_pause_frames),
103 QEDE_PF_STAT(rx_pfc_frames),
104 QEDE_PF_STAT(tx_pfc_frames),
106 QEDE_PF_STAT(rx_crc_errors),
107 QEDE_PF_STAT(rx_align_errors),
108 QEDE_PF_STAT(rx_carrier_errors),
109 QEDE_PF_STAT(rx_oversize_packets),
110 QEDE_PF_STAT(rx_jabbers),
111 QEDE_PF_STAT(rx_undersize_packets),
112 QEDE_PF_STAT(rx_fragments),
113 QEDE_PF_STAT(tx_lpi_entry_count),
114 QEDE_PF_STAT(tx_total_collisions),
115 QEDE_PF_STAT(brb_truncates),
116 QEDE_PF_STAT(brb_discards),
117 QEDE_STAT(no_buff_discards),
118 QEDE_PF_STAT(mftag_filter_discards),
119 QEDE_PF_STAT(mac_filter_discards),
120 QEDE_STAT(tx_err_drop_pkts),
121 QEDE_STAT(ttl0_discard),
122 QEDE_STAT(packet_too_big_discard),
124 QEDE_STAT(coalesced_pkts),
125 QEDE_STAT(coalesced_events),
126 QEDE_STAT(coalesced_aborts_num),
127 QEDE_STAT(non_coalesced_pkts),
128 QEDE_STAT(coalesced_bytes),
131 #define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
138 static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
142 enum qede_ethtool_tests {
143 QEDE_ETHTOOL_INT_LOOPBACK,
144 QEDE_ETHTOOL_INTERRUPT_TEST,
145 QEDE_ETHTOOL_MEMORY_TEST,
146 QEDE_ETHTOOL_REGISTER_TEST,
147 QEDE_ETHTOOL_CLOCK_TEST,
148 QEDE_ETHTOOL_NVRAM_TEST,
149 QEDE_ETHTOOL_TEST_MAX
152 static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
153 "Internal loopback (offline)",
154 "Interrupt (online)\t",
155 "Memory (online)\t\t",
156 "Register (online)\t",
157 "Clock (online)\t\t",
158 "Nvram (online)\t\t",
161 static void qede_get_strings_stats_txq(struct qede_dev *edev,
162 struct qede_tx_queue *txq, u8 **buf)
166 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
167 sprintf(*buf, "%d: %s", txq->index,
168 qede_tqstats_arr[i].string);
169 *buf += ETH_GSTRING_LEN;
173 static void qede_get_strings_stats_rxq(struct qede_dev *edev,
174 struct qede_rx_queue *rxq, u8 **buf)
178 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
179 sprintf(*buf, "%d: %s", rxq->rxq_id,
180 qede_rqstats_arr[i].string);
181 *buf += ETH_GSTRING_LEN;
185 static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
187 struct qede_fastpath *fp;
190 /* Account for queue statistics */
191 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
192 fp = &edev->fp_array[i];
194 if (fp->type & QEDE_FASTPATH_RX)
195 qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
197 if (fp->type & QEDE_FASTPATH_TX)
198 qede_get_strings_stats_txq(edev, fp->txq, &buf);
201 /* Account for non-queue statistics */
202 for (i = 0; i < QEDE_NUM_STATS; i++) {
203 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
205 strcpy(buf, qede_stats_arr[i].string);
206 buf += ETH_GSTRING_LEN;
210 static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
212 struct qede_dev *edev = netdev_priv(dev);
216 qede_get_strings_stats(edev, buf);
218 case ETH_SS_PRIV_FLAGS:
219 memcpy(buf, qede_private_arr,
220 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
223 memcpy(buf, qede_tests_str_arr,
224 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
227 DP_VERBOSE(edev, QED_MSG_DEBUG,
228 "Unsupported stringset 0x%08x\n", stringset);
232 static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
236 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
237 **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
242 static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
246 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
247 **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
252 static void qede_get_ethtool_stats(struct net_device *dev,
253 struct ethtool_stats *stats, u64 *buf)
255 struct qede_dev *edev = netdev_priv(dev);
256 struct qede_fastpath *fp;
259 qede_fill_by_demand_stats(edev);
261 /* Need to protect the access to the fastpath array */
264 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
265 fp = &edev->fp_array[i];
267 if (fp->type & QEDE_FASTPATH_RX)
268 qede_get_ethtool_stats_rxq(fp->rxq, &buf);
270 if (fp->type & QEDE_FASTPATH_TX)
271 qede_get_ethtool_stats_txq(fp->txq, &buf);
274 for (i = 0; i < QEDE_NUM_STATS; i++) {
275 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
277 *buf = *((u64 *)(((void *)&edev->stats) +
278 qede_stats_arr[i].offset));
286 static int qede_get_sset_count(struct net_device *dev, int stringset)
288 struct qede_dev *edev = netdev_priv(dev);
289 int num_stats = QEDE_NUM_STATS;
296 for (i = 0; i < QEDE_NUM_STATS; i++)
297 if (qede_stats_arr[i].pf_only)
301 /* Account for the Regular Tx statistics */
302 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS;
304 /* Account for the Regular Rx statistics */
305 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
309 case ETH_SS_PRIV_FLAGS:
310 return QEDE_PRI_FLAG_LEN;
313 return QEDE_ETHTOOL_TEST_MAX;
317 DP_VERBOSE(edev, QED_MSG_DEBUG,
318 "Unsupported stringset 0x%08x\n", stringset);
323 static u32 qede_get_priv_flags(struct net_device *dev)
325 struct qede_dev *edev = netdev_priv(dev);
327 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
330 struct qede_link_mode_mapping {
332 u32 ethtool_link_mode;
335 static const struct qede_link_mode_mapping qed_lm_map[] = {
336 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
337 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
338 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
339 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
340 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
341 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
342 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
343 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
344 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
345 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
346 {QED_LM_100000baseKR4_Full_BIT,
347 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
350 #define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
354 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
355 if ((caps) & (qed_lm_map[i].qed_link_mode)) \
356 __set_bit(qed_lm_map[i].ethtool_link_mode,\
357 lk_ksettings->link_modes.name); \
361 #define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
365 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
366 if (test_bit(qed_lm_map[i].ethtool_link_mode, \
367 lk_ksettings->link_modes.name)) \
368 caps |= qed_lm_map[i].qed_link_mode; \
372 static int qede_get_link_ksettings(struct net_device *dev,
373 struct ethtool_link_ksettings *cmd)
375 struct ethtool_link_settings *base = &cmd->base;
376 struct qede_dev *edev = netdev_priv(dev);
377 struct qed_link_output current_link;
381 memset(¤t_link, 0, sizeof(current_link));
382 edev->ops->common->get_link(edev->cdev, ¤t_link);
384 ethtool_link_ksettings_zero_link_mode(cmd, supported);
385 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
387 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
388 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
390 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
391 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
393 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
394 base->speed = current_link.speed;
395 base->duplex = current_link.duplex;
397 base->speed = SPEED_UNKNOWN;
398 base->duplex = DUPLEX_UNKNOWN;
403 base->port = current_link.port;
404 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
410 static int qede_set_link_ksettings(struct net_device *dev,
411 const struct ethtool_link_ksettings *cmd)
413 const struct ethtool_link_settings *base = &cmd->base;
414 struct qede_dev *edev = netdev_priv(dev);
415 struct qed_link_output current_link;
416 struct qed_link_params params;
418 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
419 DP_INFO(edev, "Link settings are not allowed to be changed\n");
422 memset(¤t_link, 0, sizeof(current_link));
423 memset(¶ms, 0, sizeof(params));
424 edev->ops->common->get_link(edev->cdev, ¤t_link);
426 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
427 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
428 if (base->autoneg == AUTONEG_ENABLE) {
429 params.autoneg = true;
430 params.forced_speed = 0;
431 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
432 } else { /* forced speed */
433 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
434 params.autoneg = false;
435 params.forced_speed = base->speed;
436 switch (base->speed) {
438 if (!(current_link.supported_caps &
439 QED_LM_10000baseKR_Full_BIT)) {
440 DP_INFO(edev, "10G speed not supported\n");
443 params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
446 if (!(current_link.supported_caps &
447 QED_LM_25000baseKR_Full_BIT)) {
448 DP_INFO(edev, "25G speed not supported\n");
451 params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
454 if (!(current_link.supported_caps &
455 QED_LM_40000baseLR4_Full_BIT)) {
456 DP_INFO(edev, "40G speed not supported\n");
459 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
462 if (!(current_link.supported_caps &
463 QED_LM_50000baseKR2_Full_BIT)) {
464 DP_INFO(edev, "50G speed not supported\n");
467 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
470 if (!(current_link.supported_caps &
471 QED_LM_100000baseKR4_Full_BIT)) {
472 DP_INFO(edev, "100G speed not supported\n");
475 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
478 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
483 params.link_up = true;
484 edev->ops->common->set_link(edev->cdev, ¶ms);
489 static void qede_get_drvinfo(struct net_device *ndev,
490 struct ethtool_drvinfo *info)
492 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
493 struct qede_dev *edev = netdev_priv(ndev);
495 strlcpy(info->driver, "qede", sizeof(info->driver));
496 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
498 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
499 edev->dev_info.common.fw_major,
500 edev->dev_info.common.fw_minor,
501 edev->dev_info.common.fw_rev,
502 edev->dev_info.common.fw_eng);
504 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
505 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
506 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
507 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
508 edev->dev_info.common.mfw_rev & 0xFF);
510 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
511 sizeof(info->fw_version)) {
512 snprintf(info->fw_version, sizeof(info->fw_version),
513 "mfw %s storm %s", mfw, storm);
515 snprintf(info->fw_version, sizeof(info->fw_version),
516 "%s %s", mfw, storm);
519 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
522 static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
524 struct qede_dev *edev = netdev_priv(ndev);
526 if (edev->dev_info.common.wol_support) {
527 wol->supported = WAKE_MAGIC;
528 wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
532 static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
534 struct qede_dev *edev = netdev_priv(ndev);
538 if (wol->wolopts & ~WAKE_MAGIC) {
540 "Can't support WoL options other than magic-packet\n");
544 wol_requested = !!(wol->wolopts & WAKE_MAGIC);
545 if (wol_requested == edev->wol_enabled)
548 /* Need to actually change configuration */
549 if (!edev->dev_info.common.wol_support) {
550 DP_INFO(edev, "Device doesn't support WoL\n");
554 rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
556 edev->wol_enabled = wol_requested;
561 static u32 qede_get_msglevel(struct net_device *ndev)
563 struct qede_dev *edev = netdev_priv(ndev);
565 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
568 static void qede_set_msglevel(struct net_device *ndev, u32 level)
570 struct qede_dev *edev = netdev_priv(ndev);
574 qede_config_debug(level, &dp_module, &dp_level);
576 edev->dp_level = dp_level;
577 edev->dp_module = dp_module;
578 edev->ops->common->update_msglvl(edev->cdev,
579 dp_module, dp_level);
582 static int qede_nway_reset(struct net_device *dev)
584 struct qede_dev *edev = netdev_priv(dev);
585 struct qed_link_output current_link;
586 struct qed_link_params link_params;
588 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
589 DP_INFO(edev, "Link settings are not allowed to be changed\n");
593 if (!netif_running(dev))
596 memset(¤t_link, 0, sizeof(current_link));
597 edev->ops->common->get_link(edev->cdev, ¤t_link);
598 if (!current_link.link_up)
601 /* Toggle the link */
602 memset(&link_params, 0, sizeof(link_params));
603 link_params.link_up = false;
604 edev->ops->common->set_link(edev->cdev, &link_params);
605 link_params.link_up = true;
606 edev->ops->common->set_link(edev->cdev, &link_params);
611 static u32 qede_get_link(struct net_device *dev)
613 struct qede_dev *edev = netdev_priv(dev);
614 struct qed_link_output current_link;
616 memset(¤t_link, 0, sizeof(current_link));
617 edev->ops->common->get_link(edev->cdev, ¤t_link);
619 return current_link.link_up;
622 static int qede_get_coalesce(struct net_device *dev,
623 struct ethtool_coalesce *coal)
625 struct qede_dev *edev = netdev_priv(dev);
628 memset(coal, 0, sizeof(struct ethtool_coalesce));
629 edev->ops->common->get_coalesce(edev->cdev, &rxc, &txc);
631 coal->rx_coalesce_usecs = rxc;
632 coal->tx_coalesce_usecs = txc;
637 static int qede_set_coalesce(struct net_device *dev,
638 struct ethtool_coalesce *coal)
640 struct qede_dev *edev = netdev_priv(dev);
645 if (!netif_running(dev)) {
646 DP_INFO(edev, "Interface is down\n");
650 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
651 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
653 "Can't support requested %s coalesce value [max supported value %d]\n",
654 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
660 rxc = (u16)coal->rx_coalesce_usecs;
661 txc = (u16)coal->tx_coalesce_usecs;
663 sb_id = edev->fp_array[i].sb_info->igu_sb_id;
664 rc = edev->ops->common->set_coalesce(edev->cdev, rxc, txc,
667 DP_INFO(edev, "Set coalesce error, rc = %d\n", rc);
675 static void qede_get_ringparam(struct net_device *dev,
676 struct ethtool_ringparam *ering)
678 struct qede_dev *edev = netdev_priv(dev);
680 ering->rx_max_pending = NUM_RX_BDS_MAX;
681 ering->rx_pending = edev->q_num_rx_buffers;
682 ering->tx_max_pending = NUM_TX_BDS_MAX;
683 ering->tx_pending = edev->q_num_tx_buffers;
686 static int qede_set_ringparam(struct net_device *dev,
687 struct ethtool_ringparam *ering)
689 struct qede_dev *edev = netdev_priv(dev);
691 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
692 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
693 ering->rx_pending, ering->tx_pending);
695 /* Validate legality of configuration */
696 if (ering->rx_pending > NUM_RX_BDS_MAX ||
697 ering->rx_pending < NUM_RX_BDS_MIN ||
698 ering->tx_pending > NUM_TX_BDS_MAX ||
699 ering->tx_pending < NUM_TX_BDS_MIN) {
700 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
701 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
702 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
703 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
707 /* Change ring size and re-load */
708 edev->q_num_rx_buffers = ering->rx_pending;
709 edev->q_num_tx_buffers = ering->tx_pending;
711 qede_reload(edev, NULL, false);
716 static void qede_get_pauseparam(struct net_device *dev,
717 struct ethtool_pauseparam *epause)
719 struct qede_dev *edev = netdev_priv(dev);
720 struct qed_link_output current_link;
722 memset(¤t_link, 0, sizeof(current_link));
723 edev->ops->common->get_link(edev->cdev, ¤t_link);
725 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
726 epause->autoneg = true;
727 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
728 epause->rx_pause = true;
729 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
730 epause->tx_pause = true;
732 DP_VERBOSE(edev, QED_MSG_DEBUG,
733 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
734 epause->cmd, epause->autoneg, epause->rx_pause,
738 static int qede_set_pauseparam(struct net_device *dev,
739 struct ethtool_pauseparam *epause)
741 struct qede_dev *edev = netdev_priv(dev);
742 struct qed_link_params params;
743 struct qed_link_output current_link;
745 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
747 "Pause settings are not allowed to be changed\n");
751 memset(¤t_link, 0, sizeof(current_link));
752 edev->ops->common->get_link(edev->cdev, ¤t_link);
754 memset(¶ms, 0, sizeof(params));
755 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
756 if (epause->autoneg) {
757 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
758 DP_INFO(edev, "autoneg not supported\n");
761 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
763 if (epause->rx_pause)
764 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
765 if (epause->tx_pause)
766 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
768 params.link_up = true;
769 edev->ops->common->set_link(edev->cdev, ¶ms);
774 static void qede_get_regs(struct net_device *ndev,
775 struct ethtool_regs *regs, void *buffer)
777 struct qede_dev *edev = netdev_priv(ndev);
780 memset(buffer, 0, regs->len);
782 if (edev->ops && edev->ops->common)
783 edev->ops->common->dbg_all_data(edev->cdev, buffer);
786 static int qede_get_regs_len(struct net_device *ndev)
788 struct qede_dev *edev = netdev_priv(ndev);
790 if (edev->ops && edev->ops->common)
791 return edev->ops->common->dbg_all_data_size(edev->cdev);
796 static void qede_update_mtu(struct qede_dev *edev,
797 struct qede_reload_args *args)
799 edev->ndev->mtu = args->u.mtu;
803 int qede_change_mtu(struct net_device *ndev, int new_mtu)
805 struct qede_dev *edev = netdev_priv(ndev);
806 struct qede_reload_args args;
808 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
809 "Configuring MTU size of %d\n", new_mtu);
811 /* Set the mtu field and re-start the interface if needed */
812 args.u.mtu = new_mtu;
813 args.func = &qede_update_mtu;
814 qede_reload(edev, &args, false);
816 edev->ops->common->update_mtu(edev->cdev, new_mtu);
821 static void qede_get_channels(struct net_device *dev,
822 struct ethtool_channels *channels)
824 struct qede_dev *edev = netdev_priv(dev);
826 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
827 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
828 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
829 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
831 channels->tx_count = edev->fp_num_tx;
832 channels->rx_count = edev->fp_num_rx;
835 static int qede_set_channels(struct net_device *dev,
836 struct ethtool_channels *channels)
838 struct qede_dev *edev = netdev_priv(dev);
841 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
842 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
843 channels->rx_count, channels->tx_count,
844 channels->other_count, channels->combined_count);
846 count = channels->rx_count + channels->tx_count +
847 channels->combined_count;
849 /* We don't support `other' channels */
850 if (channels->other_count) {
851 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
852 "command parameters not supported\n");
856 if (!(channels->combined_count || (channels->rx_count &&
857 channels->tx_count))) {
858 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
859 "need to request at least one transmit and one receive channel\n");
863 if (count > QEDE_MAX_RSS_CNT(edev)) {
864 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
865 "requested channels = %d max supported channels = %d\n",
866 count, QEDE_MAX_RSS_CNT(edev));
870 /* Check if there was a change in the active parameters */
871 if ((count == QEDE_QUEUE_CNT(edev)) &&
872 (channels->tx_count == edev->fp_num_tx) &&
873 (channels->rx_count == edev->fp_num_rx)) {
874 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
875 "No change in active parameters\n");
879 /* We need the number of queues to be divisible between the hwfns */
880 if ((count % edev->dev_info.common.num_hwfns) ||
881 (channels->tx_count % edev->dev_info.common.num_hwfns) ||
882 (channels->rx_count % edev->dev_info.common.num_hwfns)) {
883 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
884 "Number of channels must be divisible by %04x\n",
885 edev->dev_info.common.num_hwfns);
889 /* Set number of queues and reload if necessary */
890 edev->req_queues = count;
891 edev->req_num_tx = channels->tx_count;
892 edev->req_num_rx = channels->rx_count;
893 /* Reset the indirection table if rx queue count is updated */
894 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
895 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
896 memset(&edev->rss_params.rss_ind_table, 0,
897 sizeof(edev->rss_params.rss_ind_table));
900 qede_reload(edev, NULL, false);
905 static int qede_set_phys_id(struct net_device *dev,
906 enum ethtool_phys_id_state state)
908 struct qede_dev *edev = netdev_priv(dev);
912 case ETHTOOL_ID_ACTIVE:
913 return 1; /* cycle on/off once per second */
916 led_state = QED_LED_MODE_ON;
920 led_state = QED_LED_MODE_OFF;
923 case ETHTOOL_ID_INACTIVE:
924 led_state = QED_LED_MODE_RESTORE;
928 edev->ops->common->set_led(edev->cdev, led_state);
933 static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
935 info->data = RXH_IP_SRC | RXH_IP_DST;
937 switch (info->flow_type) {
940 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
943 if (edev->rss_params.rss_caps & QED_RSS_IPV4_UDP)
944 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
947 if (edev->rss_params.rss_caps & QED_RSS_IPV6_UDP)
948 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
961 static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
962 u32 *rules __always_unused)
964 struct qede_dev *edev = netdev_priv(dev);
967 case ETHTOOL_GRXRINGS:
968 info->data = QEDE_RSS_COUNT(edev);
971 return qede_get_rss_flags(edev, info);
973 DP_ERR(edev, "Command parameters not supported\n");
978 static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
980 struct qed_update_vport_params vport_update_params;
981 u8 set_caps = 0, clr_caps = 0;
983 DP_VERBOSE(edev, QED_MSG_DEBUG,
984 "Set rss flags command parameters: flow type = %d, data = %llu\n",
985 info->flow_type, info->data);
987 switch (info->flow_type) {
990 /* For TCP only 4-tuple hash is supported */
991 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
992 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
993 DP_INFO(edev, "Command parameters not supported\n");
998 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
999 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1000 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1001 set_caps = QED_RSS_IPV4_UDP;
1002 DP_VERBOSE(edev, QED_MSG_DEBUG,
1003 "UDP 4-tuple enabled\n");
1004 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1005 clr_caps = QED_RSS_IPV4_UDP;
1006 DP_VERBOSE(edev, QED_MSG_DEBUG,
1007 "UDP 4-tuple disabled\n");
1013 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1014 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1015 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1016 set_caps = QED_RSS_IPV6_UDP;
1017 DP_VERBOSE(edev, QED_MSG_DEBUG,
1018 "UDP 4-tuple enabled\n");
1019 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1020 clr_caps = QED_RSS_IPV6_UDP;
1021 DP_VERBOSE(edev, QED_MSG_DEBUG,
1022 "UDP 4-tuple disabled\n");
1029 /* For IP only 2-tuple hash is supported */
1030 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1031 DP_INFO(edev, "Command parameters not supported\n");
1036 case AH_ESP_V4_FLOW:
1040 case AH_ESP_V6_FLOW:
1045 /* RSS is not supported for these protocols */
1047 DP_INFO(edev, "Command parameters not supported\n");
1055 /* No action is needed if there is no change in the rss capability */
1056 if (edev->rss_params.rss_caps == ((edev->rss_params.rss_caps &
1057 ~clr_caps) | set_caps))
1060 /* Update internal configuration */
1061 edev->rss_params.rss_caps = (edev->rss_params.rss_caps & ~clr_caps) |
1063 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1065 /* Re-configure if possible */
1066 if (netif_running(edev->ndev)) {
1067 memset(&vport_update_params, 0, sizeof(vport_update_params));
1068 vport_update_params.update_rss_flg = 1;
1069 vport_update_params.vport_id = 0;
1070 memcpy(&vport_update_params.rss_params, &edev->rss_params,
1071 sizeof(vport_update_params.rss_params));
1072 return edev->ops->vport_update(edev->cdev,
1073 &vport_update_params);
1079 static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1081 struct qede_dev *edev = netdev_priv(dev);
1083 switch (info->cmd) {
1085 return qede_set_rss_flags(edev, info);
1087 DP_INFO(edev, "Command parameters not supported\n");
1092 static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1094 return QED_RSS_IND_TABLE_SIZE;
1097 static u32 qede_get_rxfh_key_size(struct net_device *dev)
1099 struct qede_dev *edev = netdev_priv(dev);
1101 return sizeof(edev->rss_params.rss_key);
1104 static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1106 struct qede_dev *edev = netdev_priv(dev);
1110 *hfunc = ETH_RSS_HASH_TOP;
1115 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1116 indir[i] = edev->rss_params.rss_ind_table[i];
1119 memcpy(key, edev->rss_params.rss_key,
1120 qede_get_rxfh_key_size(dev));
1125 static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1126 const u8 *key, const u8 hfunc)
1128 struct qed_update_vport_params vport_update_params;
1129 struct qede_dev *edev = netdev_priv(dev);
1132 if (edev->dev_info.common.num_hwfns > 1) {
1134 "RSS configuration is not supported for 100G devices\n");
1138 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1145 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1146 edev->rss_params.rss_ind_table[i] = indir[i];
1147 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1151 memcpy(&edev->rss_params.rss_key, key,
1152 qede_get_rxfh_key_size(dev));
1153 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1156 if (netif_running(edev->ndev)) {
1157 memset(&vport_update_params, 0, sizeof(vport_update_params));
1158 vport_update_params.update_rss_flg = 1;
1159 vport_update_params.vport_id = 0;
1160 memcpy(&vport_update_params.rss_params, &edev->rss_params,
1161 sizeof(vport_update_params.rss_params));
1162 return edev->ops->vport_update(edev->cdev,
1163 &vport_update_params);
1169 /* This function enables the interrupt generation and the NAPI on the device */
1170 static void qede_netif_start(struct qede_dev *edev)
1174 if (!netif_running(edev->ndev))
1178 /* Update and reenable interrupts */
1179 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1180 napi_enable(&edev->fp_array[i].napi);
1184 /* This function disables the NAPI and the interrupt generation on the device */
1185 static void qede_netif_stop(struct qede_dev *edev)
1190 napi_disable(&edev->fp_array[i].napi);
1191 /* Disable interrupts */
1192 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1196 static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1197 struct sk_buff *skb)
1199 struct qede_tx_queue *txq = NULL;
1200 struct eth_tx_1st_bd *first_bd;
1205 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
1206 txq = edev->fp_array[i].txq;
1212 DP_NOTICE(edev, "Tx path is not available\n");
1216 /* Fill the entry in the SW ring and the BDs in the FW ring */
1217 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
1218 txq->sw_tx_ring[idx].skb = skb;
1219 first_bd = qed_chain_produce(&txq->tx_pbl);
1220 memset(first_bd, 0, sizeof(*first_bd));
1221 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1222 first_bd->data.bd_flags.bitfields = val;
1223 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1224 first_bd->data.bitfields |= (val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT);
1226 /* Map skb linear data for DMA and set in the first BD */
1227 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1228 skb_headlen(skb), DMA_TO_DEVICE);
1229 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1230 DP_NOTICE(edev, "SKB mapping failed\n");
1233 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1235 /* update the first BD with the actual num BDs */
1236 first_bd->data.nbds = 1;
1238 /* 'next page' entries are counted in the producer value */
1239 val = cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
1240 txq->tx_db.data.bd_prod = val;
1242 /* wmb makes sure that the BDs data is updated before updating the
1243 * producer, otherwise FW may read old data from the BDs.
1247 writel(txq->tx_db.raw, txq->doorbell_addr);
1249 /* mmiowb is needed to synchronize doorbell writes from more than one
1250 * processor. It guarantees that the write arrives to the device before
1251 * the queue lock is released and another start_xmit is called (possibly
1252 * on another CPU). Without this barrier, the next doorbell can bypass
1253 * this doorbell. This is applicable to IA64/Altix systems.
1257 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1258 if (qede_txq_has_work(txq))
1260 usleep_range(100, 200);
1263 if (!qede_txq_has_work(txq)) {
1264 DP_NOTICE(edev, "Tx completion didn't happen\n");
1268 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
1269 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1270 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
1272 txq->sw_tx_ring[idx].skb = NULL;
1277 static int qede_selftest_receive_traffic(struct qede_dev *edev)
1279 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
1280 struct eth_fast_path_rx_reg_cqe *fp_cqe;
1281 struct qede_rx_queue *rxq = NULL;
1282 struct sw_rx_data *sw_rx_data;
1283 union eth_rx_cqe *cqe;
1288 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1289 rxq = edev->fp_array[i].rxq;
1295 DP_NOTICE(edev, "Rx path is not available\n");
1299 /* The packet is expected to receive on rx-queue 0 even though RSS is
1300 * enabled. This is because the queue 0 is configured as the default
1301 * queue and that the loopback traffic is not IP.
1303 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1304 if (!qede_has_rx_work(rxq)) {
1305 usleep_range(100, 200);
1309 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1310 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1312 /* Memory barrier to prevent the CPU from doing speculative
1313 * reads of CQE/BD before reading hw_comp_cons. If the CQE is
1314 * read before it is written by FW, then FW writes CQE and SB,
1315 * and then the CPU reads the hw_comp_cons, it will use an old
1320 /* Get the CQE from the completion ring */
1321 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1323 /* Get the data from the SW ring */
1324 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1325 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1326 fp_cqe = &cqe->fast_path_regular;
1327 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1328 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1329 fp_cqe->placement_offset +
1330 sw_rx_data->page_offset);
1331 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1332 ether_addr_equal(data_ptr + ETH_ALEN,
1333 edev->ndev->dev_addr)) {
1334 for (i = ETH_HLEN; i < len; i++)
1335 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1340 qede_recycle_rx_bd_ring(rxq, edev, 1);
1341 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1345 DP_INFO(edev, "Not the transmitted packet\n");
1346 qede_recycle_rx_bd_ring(rxq, edev, 1);
1347 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1350 if (i == QEDE_SELFTEST_POLL_COUNT) {
1351 DP_NOTICE(edev, "Failed to receive the traffic\n");
1355 qede_update_rx_prod(edev, rxq);
1360 static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1362 struct qed_link_params link_params;
1363 struct sk_buff *skb = NULL;
1368 if (!netif_running(edev->ndev)) {
1369 DP_NOTICE(edev, "Interface is down\n");
1373 qede_netif_stop(edev);
1375 /* Bring up the link in Loopback mode */
1376 memset(&link_params, 0, sizeof(link_params));
1377 link_params.link_up = true;
1378 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1379 link_params.loopback_mode = loopback_mode;
1380 edev->ops->common->set_link(edev->cdev, &link_params);
1382 /* Wait for loopback configuration to apply */
1383 msleep_interruptible(500);
1385 /* prepare the loopback packet */
1386 pkt_size = edev->ndev->mtu + ETH_HLEN;
1388 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1390 DP_INFO(edev, "Can't allocate skb\n");
1392 goto test_loopback_exit;
1394 packet = skb_put(skb, pkt_size);
1395 ether_addr_copy(packet, edev->ndev->dev_addr);
1396 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1397 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1398 for (i = ETH_HLEN; i < pkt_size; i++)
1399 packet[i] = (unsigned char)(i & 0xff);
1401 rc = qede_selftest_transmit_traffic(edev, skb);
1403 goto test_loopback_exit;
1405 rc = qede_selftest_receive_traffic(edev);
1407 goto test_loopback_exit;
1409 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1414 /* Bring up the link in Normal mode */
1415 memset(&link_params, 0, sizeof(link_params));
1416 link_params.link_up = true;
1417 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1418 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1419 edev->ops->common->set_link(edev->cdev, &link_params);
1421 /* Wait for loopback configuration to apply */
1422 msleep_interruptible(500);
1424 qede_netif_start(edev);
1429 static void qede_self_test(struct net_device *dev,
1430 struct ethtool_test *etest, u64 *buf)
1432 struct qede_dev *edev = netdev_priv(dev);
1434 DP_VERBOSE(edev, QED_MSG_DEBUG,
1435 "Self-test command parameters: offline = %d, external_lb = %d\n",
1436 (etest->flags & ETH_TEST_FL_OFFLINE),
1437 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1439 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1441 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1442 if (qede_selftest_run_loopback(edev,
1443 QED_LINK_LOOPBACK_INT_PHY)) {
1444 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1445 etest->flags |= ETH_TEST_FL_FAILED;
1449 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1450 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1451 etest->flags |= ETH_TEST_FL_FAILED;
1454 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1455 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1456 etest->flags |= ETH_TEST_FL_FAILED;
1459 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1460 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1461 etest->flags |= ETH_TEST_FL_FAILED;
1464 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1465 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1466 etest->flags |= ETH_TEST_FL_FAILED;
1469 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1470 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1471 etest->flags |= ETH_TEST_FL_FAILED;
1475 static int qede_set_tunable(struct net_device *dev,
1476 const struct ethtool_tunable *tuna,
1479 struct qede_dev *edev = netdev_priv(dev);
1483 case ETHTOOL_RX_COPYBREAK:
1485 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1486 DP_VERBOSE(edev, QED_MSG_DEBUG,
1487 "Invalid rx copy break value, range is [%u, %u]",
1488 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1492 edev->rx_copybreak = *(u32 *)data;
1501 static int qede_get_tunable(struct net_device *dev,
1502 const struct ethtool_tunable *tuna, void *data)
1504 struct qede_dev *edev = netdev_priv(dev);
1507 case ETHTOOL_RX_COPYBREAK:
1508 *(u32 *)data = edev->rx_copybreak;
1517 static const struct ethtool_ops qede_ethtool_ops = {
1518 .get_link_ksettings = qede_get_link_ksettings,
1519 .set_link_ksettings = qede_set_link_ksettings,
1520 .get_drvinfo = qede_get_drvinfo,
1521 .get_regs_len = qede_get_regs_len,
1522 .get_regs = qede_get_regs,
1523 .get_wol = qede_get_wol,
1524 .set_wol = qede_set_wol,
1525 .get_msglevel = qede_get_msglevel,
1526 .set_msglevel = qede_set_msglevel,
1527 .nway_reset = qede_nway_reset,
1528 .get_link = qede_get_link,
1529 .get_coalesce = qede_get_coalesce,
1530 .set_coalesce = qede_set_coalesce,
1531 .get_ringparam = qede_get_ringparam,
1532 .set_ringparam = qede_set_ringparam,
1533 .get_pauseparam = qede_get_pauseparam,
1534 .set_pauseparam = qede_set_pauseparam,
1535 .get_strings = qede_get_strings,
1536 .set_phys_id = qede_set_phys_id,
1537 .get_ethtool_stats = qede_get_ethtool_stats,
1538 .get_priv_flags = qede_get_priv_flags,
1539 .get_sset_count = qede_get_sset_count,
1540 .get_rxnfc = qede_get_rxnfc,
1541 .set_rxnfc = qede_set_rxnfc,
1542 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1543 .get_rxfh_key_size = qede_get_rxfh_key_size,
1544 .get_rxfh = qede_get_rxfh,
1545 .set_rxfh = qede_set_rxfh,
1546 .get_channels = qede_get_channels,
1547 .set_channels = qede_set_channels,
1548 .self_test = qede_self_test,
1549 .get_tunable = qede_get_tunable,
1550 .set_tunable = qede_set_tunable,
1553 static const struct ethtool_ops qede_vf_ethtool_ops = {
1554 .get_link_ksettings = qede_get_link_ksettings,
1555 .get_drvinfo = qede_get_drvinfo,
1556 .get_msglevel = qede_get_msglevel,
1557 .set_msglevel = qede_set_msglevel,
1558 .get_link = qede_get_link,
1559 .get_ringparam = qede_get_ringparam,
1560 .set_ringparam = qede_set_ringparam,
1561 .get_strings = qede_get_strings,
1562 .get_ethtool_stats = qede_get_ethtool_stats,
1563 .get_priv_flags = qede_get_priv_flags,
1564 .get_sset_count = qede_get_sset_count,
1565 .get_rxnfc = qede_get_rxnfc,
1566 .set_rxnfc = qede_set_rxnfc,
1567 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1568 .get_rxfh_key_size = qede_get_rxfh_key_size,
1569 .get_rxfh = qede_get_rxfh,
1570 .set_rxfh = qede_set_rxfh,
1571 .get_channels = qede_get_channels,
1572 .set_channels = qede_set_channels,
1573 .get_tunable = qede_get_tunable,
1574 .set_tunable = qede_set_tunable,
1577 void qede_set_ethtool_ops(struct net_device *dev)
1579 struct qede_dev *edev = netdev_priv(dev);
1582 dev->ethtool_ops = &qede_vf_ethtool_ops;
1584 dev->ethtool_ops = &qede_ethtool_ops;