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_STAT_OFFSET(stat_name) (offsetof(struct qede_stats, stat_name))
20 #define QEDE_STAT_STRING(stat_name) (#stat_name)
21 #define _QEDE_STAT(stat_name, pf_only) \
22 {QEDE_STAT_OFFSET(stat_name), QEDE_STAT_STRING(stat_name), pf_only}
23 #define QEDE_PF_STAT(stat_name) _QEDE_STAT(stat_name, true)
24 #define QEDE_STAT(stat_name) _QEDE_STAT(stat_name, false)
26 #define QEDE_RQSTAT_OFFSET(stat_name) \
27 (offsetof(struct qede_rx_queue, stat_name))
28 #define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
29 #define QEDE_RQSTAT(stat_name) \
30 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
32 #define QEDE_SELFTEST_POLL_COUNT 100
36 char string[ETH_GSTRING_LEN];
37 } qede_rqstats_arr[] = {
38 QEDE_RQSTAT(rcv_pkts),
39 QEDE_RQSTAT(rx_hw_errors),
40 QEDE_RQSTAT(rx_alloc_errors),
41 QEDE_RQSTAT(rx_ip_frags),
44 #define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
45 #define QEDE_RQSTATS_DATA(dev, sindex, rqindex) \
46 (*((u64 *)(((char *)(dev->fp_array[(rqindex)].rxq)) +\
47 qede_rqstats_arr[(sindex)].offset)))
48 #define QEDE_TQSTAT_OFFSET(stat_name) \
49 (offsetof(struct qede_tx_queue, stat_name))
50 #define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
51 #define QEDE_TQSTAT(stat_name) \
52 {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
53 #define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
56 char string[ETH_GSTRING_LEN];
57 } qede_tqstats_arr[] = {
58 QEDE_TQSTAT(xmit_pkts),
59 QEDE_TQSTAT(stopped_cnt),
62 #define QEDE_TQSTATS_DATA(dev, sindex, tssid, tcid) \
63 (*((u64 *)(((void *)(&dev->fp_array[tssid].txqs[tcid])) +\
64 qede_tqstats_arr[(sindex)].offset)))
68 char string[ETH_GSTRING_LEN];
70 } qede_stats_arr[] = {
71 QEDE_STAT(rx_ucast_bytes),
72 QEDE_STAT(rx_mcast_bytes),
73 QEDE_STAT(rx_bcast_bytes),
74 QEDE_STAT(rx_ucast_pkts),
75 QEDE_STAT(rx_mcast_pkts),
76 QEDE_STAT(rx_bcast_pkts),
78 QEDE_STAT(tx_ucast_bytes),
79 QEDE_STAT(tx_mcast_bytes),
80 QEDE_STAT(tx_bcast_bytes),
81 QEDE_STAT(tx_ucast_pkts),
82 QEDE_STAT(tx_mcast_pkts),
83 QEDE_STAT(tx_bcast_pkts),
85 QEDE_PF_STAT(rx_64_byte_packets),
86 QEDE_PF_STAT(rx_65_to_127_byte_packets),
87 QEDE_PF_STAT(rx_128_to_255_byte_packets),
88 QEDE_PF_STAT(rx_256_to_511_byte_packets),
89 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
90 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
91 QEDE_PF_STAT(rx_1519_to_1522_byte_packets),
92 QEDE_PF_STAT(rx_1519_to_2047_byte_packets),
93 QEDE_PF_STAT(rx_2048_to_4095_byte_packets),
94 QEDE_PF_STAT(rx_4096_to_9216_byte_packets),
95 QEDE_PF_STAT(rx_9217_to_16383_byte_packets),
96 QEDE_PF_STAT(tx_64_byte_packets),
97 QEDE_PF_STAT(tx_65_to_127_byte_packets),
98 QEDE_PF_STAT(tx_128_to_255_byte_packets),
99 QEDE_PF_STAT(tx_256_to_511_byte_packets),
100 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
101 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
102 QEDE_PF_STAT(tx_1519_to_2047_byte_packets),
103 QEDE_PF_STAT(tx_2048_to_4095_byte_packets),
104 QEDE_PF_STAT(tx_4096_to_9216_byte_packets),
105 QEDE_PF_STAT(tx_9217_to_16383_byte_packets),
107 QEDE_PF_STAT(rx_mac_crtl_frames),
108 QEDE_PF_STAT(tx_mac_ctrl_frames),
109 QEDE_PF_STAT(rx_pause_frames),
110 QEDE_PF_STAT(tx_pause_frames),
111 QEDE_PF_STAT(rx_pfc_frames),
112 QEDE_PF_STAT(tx_pfc_frames),
114 QEDE_PF_STAT(rx_crc_errors),
115 QEDE_PF_STAT(rx_align_errors),
116 QEDE_PF_STAT(rx_carrier_errors),
117 QEDE_PF_STAT(rx_oversize_packets),
118 QEDE_PF_STAT(rx_jabbers),
119 QEDE_PF_STAT(rx_undersize_packets),
120 QEDE_PF_STAT(rx_fragments),
121 QEDE_PF_STAT(tx_lpi_entry_count),
122 QEDE_PF_STAT(tx_total_collisions),
123 QEDE_PF_STAT(brb_truncates),
124 QEDE_PF_STAT(brb_discards),
125 QEDE_STAT(no_buff_discards),
126 QEDE_PF_STAT(mftag_filter_discards),
127 QEDE_PF_STAT(mac_filter_discards),
128 QEDE_STAT(tx_err_drop_pkts),
129 QEDE_STAT(ttl0_discard),
130 QEDE_STAT(packet_too_big_discard),
132 QEDE_STAT(coalesced_pkts),
133 QEDE_STAT(coalesced_events),
134 QEDE_STAT(coalesced_aborts_num),
135 QEDE_STAT(non_coalesced_pkts),
136 QEDE_STAT(coalesced_bytes),
139 #define QEDE_STATS_DATA(dev, index) \
140 (*((u64 *)(((char *)(dev)) + offsetof(struct qede_dev, stats) \
141 + qede_stats_arr[(index)].offset)))
143 #define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
150 static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
154 enum qede_ethtool_tests {
155 QEDE_ETHTOOL_INT_LOOPBACK,
156 QEDE_ETHTOOL_INTERRUPT_TEST,
157 QEDE_ETHTOOL_MEMORY_TEST,
158 QEDE_ETHTOOL_REGISTER_TEST,
159 QEDE_ETHTOOL_CLOCK_TEST,
160 QEDE_ETHTOOL_TEST_MAX
163 static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
164 "Internal loopback (offline)",
165 "Interrupt (online)\t",
166 "Memory (online)\t\t",
167 "Register (online)\t",
168 "Clock (online)\t\t",
171 static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
175 for (i = 0, k = 0; i < QEDE_QUEUE_CNT(edev); i++) {
178 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
179 for (j = 0; j < QEDE_NUM_RQSTATS; j++)
180 sprintf(buf + (k + j) * ETH_GSTRING_LEN,
182 qede_rqstats_arr[j].string);
183 k += QEDE_NUM_RQSTATS;
186 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
187 for (tc = 0; tc < edev->num_tc; tc++) {
188 for (j = 0; j < QEDE_NUM_TQSTATS; j++)
189 sprintf(buf + (k + j) *
192 qede_tqstats_arr[j].string);
193 k += QEDE_NUM_TQSTATS;
198 for (i = 0, j = 0; i < QEDE_NUM_STATS; i++) {
199 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
201 strcpy(buf + (k + j) * ETH_GSTRING_LEN,
202 qede_stats_arr[i].string);
207 static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
209 struct qede_dev *edev = netdev_priv(dev);
213 qede_get_strings_stats(edev, buf);
215 case ETH_SS_PRIV_FLAGS:
216 memcpy(buf, qede_private_arr,
217 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
220 memcpy(buf, qede_tests_str_arr,
221 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
224 DP_VERBOSE(edev, QED_MSG_DEBUG,
225 "Unsupported stringset 0x%08x\n", stringset);
229 static void qede_get_ethtool_stats(struct net_device *dev,
230 struct ethtool_stats *stats, u64 *buf)
232 struct qede_dev *edev = netdev_priv(dev);
236 qede_fill_by_demand_stats(edev);
238 mutex_lock(&edev->qede_lock);
240 for (qid = 0; qid < QEDE_QUEUE_CNT(edev); qid++) {
243 if (edev->fp_array[qid].type & QEDE_FASTPATH_RX) {
244 for (sidx = 0; sidx < QEDE_NUM_RQSTATS; sidx++)
245 buf[cnt++] = QEDE_RQSTATS_DATA(edev, sidx, qid);
248 if (edev->fp_array[qid].type & QEDE_FASTPATH_TX) {
249 for (tc = 0; tc < edev->num_tc; tc++) {
250 for (sidx = 0; sidx < QEDE_NUM_TQSTATS; sidx++)
251 buf[cnt++] = QEDE_TQSTATS_DATA(edev,
258 for (sidx = 0; sidx < QEDE_NUM_STATS; sidx++) {
259 if (IS_VF(edev) && qede_stats_arr[sidx].pf_only)
261 buf[cnt++] = QEDE_STATS_DATA(edev, sidx);
264 mutex_unlock(&edev->qede_lock);
267 static int qede_get_sset_count(struct net_device *dev, int stringset)
269 struct qede_dev *edev = netdev_priv(dev);
270 int num_stats = QEDE_NUM_STATS;
277 for (i = 0; i < QEDE_NUM_STATS; i++)
278 if (qede_stats_arr[i].pf_only)
281 return num_stats + QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS +
282 QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS * edev->num_tc;
283 case ETH_SS_PRIV_FLAGS:
284 return QEDE_PRI_FLAG_LEN;
287 return QEDE_ETHTOOL_TEST_MAX;
291 DP_VERBOSE(edev, QED_MSG_DEBUG,
292 "Unsupported stringset 0x%08x\n", stringset);
297 static u32 qede_get_priv_flags(struct net_device *dev)
299 struct qede_dev *edev = netdev_priv(dev);
301 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
304 struct qede_link_mode_mapping {
306 u32 ethtool_link_mode;
309 static const struct qede_link_mode_mapping qed_lm_map[] = {
310 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
311 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
312 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
313 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
314 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
315 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
316 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
317 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
318 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
319 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
320 {QED_LM_100000baseKR4_Full_BIT,
321 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
324 #define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
328 for (i = 0; i < QED_LM_COUNT; i++) { \
329 if ((caps) & (qed_lm_map[i].qed_link_mode)) \
330 __set_bit(qed_lm_map[i].ethtool_link_mode,\
331 lk_ksettings->link_modes.name); \
335 #define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
339 for (i = 0; i < QED_LM_COUNT; i++) { \
340 if (test_bit(qed_lm_map[i].ethtool_link_mode, \
341 lk_ksettings->link_modes.name)) \
342 caps |= qed_lm_map[i].qed_link_mode; \
346 static int qede_get_link_ksettings(struct net_device *dev,
347 struct ethtool_link_ksettings *cmd)
349 struct ethtool_link_settings *base = &cmd->base;
350 struct qede_dev *edev = netdev_priv(dev);
351 struct qed_link_output current_link;
353 memset(¤t_link, 0, sizeof(current_link));
354 edev->ops->common->get_link(edev->cdev, ¤t_link);
356 ethtool_link_ksettings_zero_link_mode(cmd, supported);
357 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
359 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
360 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
362 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
363 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
365 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
366 base->speed = current_link.speed;
367 base->duplex = current_link.duplex;
369 base->speed = SPEED_UNKNOWN;
370 base->duplex = DUPLEX_UNKNOWN;
372 base->port = current_link.port;
373 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
379 static int qede_set_link_ksettings(struct net_device *dev,
380 const struct ethtool_link_ksettings *cmd)
382 const struct ethtool_link_settings *base = &cmd->base;
383 struct qede_dev *edev = netdev_priv(dev);
384 struct qed_link_output current_link;
385 struct qed_link_params params;
387 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
388 DP_INFO(edev, "Link settings are not allowed to be changed\n");
391 memset(¤t_link, 0, sizeof(current_link));
392 memset(¶ms, 0, sizeof(params));
393 edev->ops->common->get_link(edev->cdev, ¤t_link);
395 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
396 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
397 if (base->autoneg == AUTONEG_ENABLE) {
398 params.autoneg = true;
399 params.forced_speed = 0;
400 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
401 } else { /* forced speed */
402 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
403 params.autoneg = false;
404 params.forced_speed = base->speed;
405 switch (base->speed) {
407 if (!(current_link.supported_caps &
408 QED_LM_10000baseKR_Full_BIT)) {
409 DP_INFO(edev, "10G speed not supported\n");
412 params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
415 if (!(current_link.supported_caps &
416 QED_LM_25000baseKR_Full_BIT)) {
417 DP_INFO(edev, "25G speed not supported\n");
420 params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
423 if (!(current_link.supported_caps &
424 QED_LM_40000baseLR4_Full_BIT)) {
425 DP_INFO(edev, "40G speed not supported\n");
428 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
431 if (!(current_link.supported_caps &
432 QED_LM_50000baseKR2_Full_BIT)) {
433 DP_INFO(edev, "50G speed not supported\n");
436 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
439 if (!(current_link.supported_caps &
440 QED_LM_100000baseKR4_Full_BIT)) {
441 DP_INFO(edev, "100G speed not supported\n");
444 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
447 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
452 params.link_up = true;
453 edev->ops->common->set_link(edev->cdev, ¶ms);
458 static void qede_get_drvinfo(struct net_device *ndev,
459 struct ethtool_drvinfo *info)
461 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
462 struct qede_dev *edev = netdev_priv(ndev);
464 strlcpy(info->driver, "qede", sizeof(info->driver));
465 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
467 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
468 edev->dev_info.common.fw_major,
469 edev->dev_info.common.fw_minor,
470 edev->dev_info.common.fw_rev,
471 edev->dev_info.common.fw_eng);
473 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
474 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
475 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
476 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
477 edev->dev_info.common.mfw_rev & 0xFF);
479 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
480 sizeof(info->fw_version)) {
481 snprintf(info->fw_version, sizeof(info->fw_version),
482 "mfw %s storm %s", mfw, storm);
484 snprintf(info->fw_version, sizeof(info->fw_version),
485 "%s %s", mfw, storm);
488 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
491 static u32 qede_get_msglevel(struct net_device *ndev)
493 struct qede_dev *edev = netdev_priv(ndev);
495 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
498 static void qede_set_msglevel(struct net_device *ndev, u32 level)
500 struct qede_dev *edev = netdev_priv(ndev);
504 qede_config_debug(level, &dp_module, &dp_level);
506 edev->dp_level = dp_level;
507 edev->dp_module = dp_module;
508 edev->ops->common->update_msglvl(edev->cdev,
509 dp_module, dp_level);
512 static int qede_nway_reset(struct net_device *dev)
514 struct qede_dev *edev = netdev_priv(dev);
515 struct qed_link_output current_link;
516 struct qed_link_params link_params;
518 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
519 DP_INFO(edev, "Link settings are not allowed to be changed\n");
523 if (!netif_running(dev))
526 memset(¤t_link, 0, sizeof(current_link));
527 edev->ops->common->get_link(edev->cdev, ¤t_link);
528 if (!current_link.link_up)
531 /* Toggle the link */
532 memset(&link_params, 0, sizeof(link_params));
533 link_params.link_up = false;
534 edev->ops->common->set_link(edev->cdev, &link_params);
535 link_params.link_up = true;
536 edev->ops->common->set_link(edev->cdev, &link_params);
541 static u32 qede_get_link(struct net_device *dev)
543 struct qede_dev *edev = netdev_priv(dev);
544 struct qed_link_output current_link;
546 memset(¤t_link, 0, sizeof(current_link));
547 edev->ops->common->get_link(edev->cdev, ¤t_link);
549 return current_link.link_up;
552 static int qede_get_coalesce(struct net_device *dev,
553 struct ethtool_coalesce *coal)
555 struct qede_dev *edev = netdev_priv(dev);
558 memset(coal, 0, sizeof(struct ethtool_coalesce));
559 edev->ops->common->get_coalesce(edev->cdev, &rxc, &txc);
561 coal->rx_coalesce_usecs = rxc;
562 coal->tx_coalesce_usecs = txc;
567 static int qede_set_coalesce(struct net_device *dev,
568 struct ethtool_coalesce *coal)
570 struct qede_dev *edev = netdev_priv(dev);
575 if (!netif_running(dev)) {
576 DP_INFO(edev, "Interface is down\n");
580 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
581 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
583 "Can't support requested %s coalesce value [max supported value %d]\n",
584 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
590 rxc = (u16)coal->rx_coalesce_usecs;
591 txc = (u16)coal->tx_coalesce_usecs;
593 sb_id = edev->fp_array[i].sb_info->igu_sb_id;
594 rc = edev->ops->common->set_coalesce(edev->cdev, rxc, txc,
597 DP_INFO(edev, "Set coalesce error, rc = %d\n", rc);
605 static void qede_get_ringparam(struct net_device *dev,
606 struct ethtool_ringparam *ering)
608 struct qede_dev *edev = netdev_priv(dev);
610 ering->rx_max_pending = NUM_RX_BDS_MAX;
611 ering->rx_pending = edev->q_num_rx_buffers;
612 ering->tx_max_pending = NUM_TX_BDS_MAX;
613 ering->tx_pending = edev->q_num_tx_buffers;
616 static int qede_set_ringparam(struct net_device *dev,
617 struct ethtool_ringparam *ering)
619 struct qede_dev *edev = netdev_priv(dev);
621 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
622 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
623 ering->rx_pending, ering->tx_pending);
625 /* Validate legality of configuration */
626 if (ering->rx_pending > NUM_RX_BDS_MAX ||
627 ering->rx_pending < NUM_RX_BDS_MIN ||
628 ering->tx_pending > NUM_TX_BDS_MAX ||
629 ering->tx_pending < NUM_TX_BDS_MIN) {
630 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
631 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
632 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
633 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
637 /* Change ring size and re-load */
638 edev->q_num_rx_buffers = ering->rx_pending;
639 edev->q_num_tx_buffers = ering->tx_pending;
641 if (netif_running(edev->ndev))
642 qede_reload(edev, NULL, NULL);
647 static void qede_get_pauseparam(struct net_device *dev,
648 struct ethtool_pauseparam *epause)
650 struct qede_dev *edev = netdev_priv(dev);
651 struct qed_link_output current_link;
653 memset(¤t_link, 0, sizeof(current_link));
654 edev->ops->common->get_link(edev->cdev, ¤t_link);
656 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
657 epause->autoneg = true;
658 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
659 epause->rx_pause = true;
660 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
661 epause->tx_pause = true;
663 DP_VERBOSE(edev, QED_MSG_DEBUG,
664 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
665 epause->cmd, epause->autoneg, epause->rx_pause,
669 static int qede_set_pauseparam(struct net_device *dev,
670 struct ethtool_pauseparam *epause)
672 struct qede_dev *edev = netdev_priv(dev);
673 struct qed_link_params params;
674 struct qed_link_output current_link;
676 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
678 "Pause settings are not allowed to be changed\n");
682 memset(¤t_link, 0, sizeof(current_link));
683 edev->ops->common->get_link(edev->cdev, ¤t_link);
685 memset(¶ms, 0, sizeof(params));
686 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
687 if (epause->autoneg) {
688 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
689 DP_INFO(edev, "autoneg not supported\n");
692 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
694 if (epause->rx_pause)
695 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
696 if (epause->tx_pause)
697 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
699 params.link_up = true;
700 edev->ops->common->set_link(edev->cdev, ¶ms);
705 static void qede_get_regs(struct net_device *ndev,
706 struct ethtool_regs *regs, void *buffer)
708 struct qede_dev *edev = netdev_priv(ndev);
711 memset(buffer, 0, regs->len);
713 if (edev->ops && edev->ops->common)
714 edev->ops->common->dbg_all_data(edev->cdev, buffer);
717 static int qede_get_regs_len(struct net_device *ndev)
719 struct qede_dev *edev = netdev_priv(ndev);
721 if (edev->ops && edev->ops->common)
722 return edev->ops->common->dbg_all_data_size(edev->cdev);
727 static void qede_update_mtu(struct qede_dev *edev, union qede_reload_args *args)
729 edev->ndev->mtu = args->mtu;
733 #define ETH_MAX_JUMBO_PACKET_SIZE 9600
734 #define ETH_MIN_PACKET_SIZE 60
735 int qede_change_mtu(struct net_device *ndev, int new_mtu)
737 struct qede_dev *edev = netdev_priv(ndev);
738 union qede_reload_args args;
740 if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
741 ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE)) {
742 DP_ERR(edev, "Can't support requested MTU size\n");
746 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
747 "Configuring MTU size of %d\n", new_mtu);
749 /* Set the mtu field and re-start the interface if needed*/
752 if (netif_running(edev->ndev))
753 qede_reload(edev, &qede_update_mtu, &args);
755 qede_update_mtu(edev, &args);
760 static void qede_get_channels(struct net_device *dev,
761 struct ethtool_channels *channels)
763 struct qede_dev *edev = netdev_priv(dev);
765 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
766 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
767 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
768 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
770 channels->tx_count = edev->fp_num_tx;
771 channels->rx_count = edev->fp_num_rx;
774 static int qede_set_channels(struct net_device *dev,
775 struct ethtool_channels *channels)
777 struct qede_dev *edev = netdev_priv(dev);
780 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
781 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
782 channels->rx_count, channels->tx_count,
783 channels->other_count, channels->combined_count);
785 count = channels->rx_count + channels->tx_count +
786 channels->combined_count;
788 /* We don't support `other' channels */
789 if (channels->other_count) {
790 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
791 "command parameters not supported\n");
795 if (!(channels->combined_count || (channels->rx_count &&
796 channels->tx_count))) {
797 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
798 "need to request at least one transmit and one receive channel\n");
802 if (count > QEDE_MAX_RSS_CNT(edev)) {
803 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
804 "requested channels = %d max supported channels = %d\n",
805 count, QEDE_MAX_RSS_CNT(edev));
809 /* Check if there was a change in the active parameters */
810 if ((count == QEDE_QUEUE_CNT(edev)) &&
811 (channels->tx_count == edev->fp_num_tx) &&
812 (channels->rx_count == edev->fp_num_rx)) {
813 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
814 "No change in active parameters\n");
818 /* We need the number of queues to be divisible between the hwfns */
819 if ((count % edev->dev_info.common.num_hwfns) ||
820 (channels->tx_count % edev->dev_info.common.num_hwfns) ||
821 (channels->rx_count % edev->dev_info.common.num_hwfns)) {
822 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
823 "Number of channels must be divisible by %04x\n",
824 edev->dev_info.common.num_hwfns);
828 /* Set number of queues and reload if necessary */
829 edev->req_queues = count;
830 edev->req_num_tx = channels->tx_count;
831 edev->req_num_rx = channels->rx_count;
832 /* Reset the indirection table if rx queue count is updated */
833 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
834 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
835 memset(&edev->rss_params.rss_ind_table, 0,
836 sizeof(edev->rss_params.rss_ind_table));
839 if (netif_running(dev))
840 qede_reload(edev, NULL, NULL);
845 static int qede_set_phys_id(struct net_device *dev,
846 enum ethtool_phys_id_state state)
848 struct qede_dev *edev = netdev_priv(dev);
852 case ETHTOOL_ID_ACTIVE:
853 return 1; /* cycle on/off once per second */
856 led_state = QED_LED_MODE_ON;
860 led_state = QED_LED_MODE_OFF;
863 case ETHTOOL_ID_INACTIVE:
864 led_state = QED_LED_MODE_RESTORE;
868 edev->ops->common->set_led(edev->cdev, led_state);
873 static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
875 info->data = RXH_IP_SRC | RXH_IP_DST;
877 switch (info->flow_type) {
880 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
883 if (edev->rss_params.rss_caps & QED_RSS_IPV4_UDP)
884 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
887 if (edev->rss_params.rss_caps & QED_RSS_IPV6_UDP)
888 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
901 static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
902 u32 *rules __always_unused)
904 struct qede_dev *edev = netdev_priv(dev);
907 case ETHTOOL_GRXRINGS:
908 info->data = QEDE_RSS_COUNT(edev);
911 return qede_get_rss_flags(edev, info);
913 DP_ERR(edev, "Command parameters not supported\n");
918 static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
920 struct qed_update_vport_params vport_update_params;
921 u8 set_caps = 0, clr_caps = 0;
923 DP_VERBOSE(edev, QED_MSG_DEBUG,
924 "Set rss flags command parameters: flow type = %d, data = %llu\n",
925 info->flow_type, info->data);
927 switch (info->flow_type) {
930 /* For TCP only 4-tuple hash is supported */
931 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
932 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
933 DP_INFO(edev, "Command parameters not supported\n");
938 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
939 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
940 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
941 set_caps = QED_RSS_IPV4_UDP;
942 DP_VERBOSE(edev, QED_MSG_DEBUG,
943 "UDP 4-tuple enabled\n");
944 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
945 clr_caps = QED_RSS_IPV4_UDP;
946 DP_VERBOSE(edev, QED_MSG_DEBUG,
947 "UDP 4-tuple disabled\n");
953 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
954 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
955 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
956 set_caps = QED_RSS_IPV6_UDP;
957 DP_VERBOSE(edev, QED_MSG_DEBUG,
958 "UDP 4-tuple enabled\n");
959 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
960 clr_caps = QED_RSS_IPV6_UDP;
961 DP_VERBOSE(edev, QED_MSG_DEBUG,
962 "UDP 4-tuple disabled\n");
969 /* For IP only 2-tuple hash is supported */
970 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
971 DP_INFO(edev, "Command parameters not supported\n");
985 /* RSS is not supported for these protocols */
987 DP_INFO(edev, "Command parameters not supported\n");
995 /* No action is needed if there is no change in the rss capability */
996 if (edev->rss_params.rss_caps == ((edev->rss_params.rss_caps &
997 ~clr_caps) | set_caps))
1000 /* Update internal configuration */
1001 edev->rss_params.rss_caps = (edev->rss_params.rss_caps & ~clr_caps) |
1003 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1005 /* Re-configure if possible */
1006 if (netif_running(edev->ndev)) {
1007 memset(&vport_update_params, 0, sizeof(vport_update_params));
1008 vport_update_params.update_rss_flg = 1;
1009 vport_update_params.vport_id = 0;
1010 memcpy(&vport_update_params.rss_params, &edev->rss_params,
1011 sizeof(vport_update_params.rss_params));
1012 return edev->ops->vport_update(edev->cdev,
1013 &vport_update_params);
1019 static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1021 struct qede_dev *edev = netdev_priv(dev);
1023 switch (info->cmd) {
1025 return qede_set_rss_flags(edev, info);
1027 DP_INFO(edev, "Command parameters not supported\n");
1032 static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1034 return QED_RSS_IND_TABLE_SIZE;
1037 static u32 qede_get_rxfh_key_size(struct net_device *dev)
1039 struct qede_dev *edev = netdev_priv(dev);
1041 return sizeof(edev->rss_params.rss_key);
1044 static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1046 struct qede_dev *edev = netdev_priv(dev);
1050 *hfunc = ETH_RSS_HASH_TOP;
1055 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1056 indir[i] = edev->rss_params.rss_ind_table[i];
1059 memcpy(key, edev->rss_params.rss_key,
1060 qede_get_rxfh_key_size(dev));
1065 static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1066 const u8 *key, const u8 hfunc)
1068 struct qed_update_vport_params vport_update_params;
1069 struct qede_dev *edev = netdev_priv(dev);
1072 if (edev->dev_info.common.num_hwfns > 1) {
1074 "RSS configuration is not supported for 100G devices\n");
1078 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1085 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1086 edev->rss_params.rss_ind_table[i] = indir[i];
1087 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1091 memcpy(&edev->rss_params.rss_key, key,
1092 qede_get_rxfh_key_size(dev));
1093 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1096 if (netif_running(edev->ndev)) {
1097 memset(&vport_update_params, 0, sizeof(vport_update_params));
1098 vport_update_params.update_rss_flg = 1;
1099 vport_update_params.vport_id = 0;
1100 memcpy(&vport_update_params.rss_params, &edev->rss_params,
1101 sizeof(vport_update_params.rss_params));
1102 return edev->ops->vport_update(edev->cdev,
1103 &vport_update_params);
1109 /* This function enables the interrupt generation and the NAPI on the device */
1110 static void qede_netif_start(struct qede_dev *edev)
1114 if (!netif_running(edev->ndev))
1118 /* Update and reenable interrupts */
1119 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1120 napi_enable(&edev->fp_array[i].napi);
1124 /* This function disables the NAPI and the interrupt generation on the device */
1125 static void qede_netif_stop(struct qede_dev *edev)
1130 napi_disable(&edev->fp_array[i].napi);
1131 /* Disable interrupts */
1132 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1136 static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1137 struct sk_buff *skb)
1139 struct qede_tx_queue *txq = NULL;
1140 struct eth_tx_1st_bd *first_bd;
1145 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
1146 txq = edev->fp_array[i].txqs;
1152 DP_NOTICE(edev, "Tx path is not available\n");
1156 /* Fill the entry in the SW ring and the BDs in the FW ring */
1157 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
1158 txq->sw_tx_ring[idx].skb = skb;
1159 first_bd = qed_chain_produce(&txq->tx_pbl);
1160 memset(first_bd, 0, sizeof(*first_bd));
1161 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1162 first_bd->data.bd_flags.bitfields = val;
1163 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1164 first_bd->data.bitfields |= (val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT);
1166 /* Map skb linear data for DMA and set in the first BD */
1167 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1168 skb_headlen(skb), DMA_TO_DEVICE);
1169 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1170 DP_NOTICE(edev, "SKB mapping failed\n");
1173 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1175 /* update the first BD with the actual num BDs */
1176 first_bd->data.nbds = 1;
1178 /* 'next page' entries are counted in the producer value */
1179 val = cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
1180 txq->tx_db.data.bd_prod = val;
1182 /* wmb makes sure that the BDs data is updated before updating the
1183 * producer, otherwise FW may read old data from the BDs.
1187 writel(txq->tx_db.raw, txq->doorbell_addr);
1189 /* mmiowb is needed to synchronize doorbell writes from more than one
1190 * processor. It guarantees that the write arrives to the device before
1191 * the queue lock is released and another start_xmit is called (possibly
1192 * on another CPU). Without this barrier, the next doorbell can bypass
1193 * this doorbell. This is applicable to IA64/Altix systems.
1197 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1198 if (qede_txq_has_work(txq))
1200 usleep_range(100, 200);
1203 if (!qede_txq_has_work(txq)) {
1204 DP_NOTICE(edev, "Tx completion didn't happen\n");
1208 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
1209 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1210 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
1212 txq->sw_tx_ring[idx].skb = NULL;
1217 static int qede_selftest_receive_traffic(struct qede_dev *edev)
1219 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
1220 struct eth_fast_path_rx_reg_cqe *fp_cqe;
1221 struct qede_rx_queue *rxq = NULL;
1222 struct sw_rx_data *sw_rx_data;
1223 union eth_rx_cqe *cqe;
1224 int i, iter, rc = 0;
1228 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1229 rxq = edev->fp_array[i].rxq;
1235 DP_NOTICE(edev, "Rx path is not available\n");
1239 /* The packet is expected to receive on rx-queue 0 even though RSS is
1240 * enabled. This is because the queue 0 is configured as the default
1241 * queue and that the loopback traffic is not IP.
1243 for (iter = 0; iter < QEDE_SELFTEST_POLL_COUNT; iter++) {
1244 if (!qede_has_rx_work(rxq)) {
1245 usleep_range(100, 200);
1249 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1250 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1252 /* Memory barrier to prevent the CPU from doing speculative
1253 * reads of CQE/BD before reading hw_comp_cons. If the CQE is
1254 * read before it is written by FW, then FW writes CQE and SB,
1255 * and then the CPU reads the hw_comp_cons, it will use an old
1260 /* Get the CQE from the completion ring */
1261 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1263 /* Get the data from the SW ring */
1264 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1265 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1266 fp_cqe = &cqe->fast_path_regular;
1267 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1268 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1269 fp_cqe->placement_offset +
1270 sw_rx_data->page_offset);
1271 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1272 ether_addr_equal(data_ptr + ETH_ALEN,
1273 edev->ndev->dev_addr)) {
1274 for (i = ETH_HLEN; i < len; i++)
1275 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1280 qede_recycle_rx_bd_ring(rxq, edev, 1);
1281 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1285 DP_INFO(edev, "Not the transmitted packet\n");
1286 qede_recycle_rx_bd_ring(rxq, edev, 1);
1287 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1290 if (iter == QEDE_SELFTEST_POLL_COUNT) {
1291 DP_NOTICE(edev, "Failed to receive the traffic\n");
1295 qede_update_rx_prod(edev, rxq);
1300 static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1302 struct qed_link_params link_params;
1303 struct sk_buff *skb = NULL;
1308 if (!netif_running(edev->ndev)) {
1309 DP_NOTICE(edev, "Interface is down\n");
1313 qede_netif_stop(edev);
1315 /* Bring up the link in Loopback mode */
1316 memset(&link_params, 0, sizeof(link_params));
1317 link_params.link_up = true;
1318 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1319 link_params.loopback_mode = loopback_mode;
1320 edev->ops->common->set_link(edev->cdev, &link_params);
1322 /* Wait for loopback configuration to apply */
1323 msleep_interruptible(500);
1325 /* prepare the loopback packet */
1326 pkt_size = edev->ndev->mtu + ETH_HLEN;
1328 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1330 DP_INFO(edev, "Can't allocate skb\n");
1332 goto test_loopback_exit;
1334 packet = skb_put(skb, pkt_size);
1335 ether_addr_copy(packet, edev->ndev->dev_addr);
1336 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1337 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1338 for (i = ETH_HLEN; i < pkt_size; i++)
1339 packet[i] = (unsigned char)(i & 0xff);
1341 rc = qede_selftest_transmit_traffic(edev, skb);
1343 goto test_loopback_exit;
1345 rc = qede_selftest_receive_traffic(edev);
1347 goto test_loopback_exit;
1349 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1354 /* Bring up the link in Normal mode */
1355 memset(&link_params, 0, sizeof(link_params));
1356 link_params.link_up = true;
1357 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1358 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1359 edev->ops->common->set_link(edev->cdev, &link_params);
1361 /* Wait for loopback configuration to apply */
1362 msleep_interruptible(500);
1364 qede_netif_start(edev);
1369 static void qede_self_test(struct net_device *dev,
1370 struct ethtool_test *etest, u64 *buf)
1372 struct qede_dev *edev = netdev_priv(dev);
1374 DP_VERBOSE(edev, QED_MSG_DEBUG,
1375 "Self-test command parameters: offline = %d, external_lb = %d\n",
1376 (etest->flags & ETH_TEST_FL_OFFLINE),
1377 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1379 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1381 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1382 if (qede_selftest_run_loopback(edev,
1383 QED_LINK_LOOPBACK_INT_PHY)) {
1384 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1385 etest->flags |= ETH_TEST_FL_FAILED;
1389 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1390 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1391 etest->flags |= ETH_TEST_FL_FAILED;
1394 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1395 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1396 etest->flags |= ETH_TEST_FL_FAILED;
1399 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1400 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1401 etest->flags |= ETH_TEST_FL_FAILED;
1404 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1405 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1406 etest->flags |= ETH_TEST_FL_FAILED;
1410 static int qede_set_tunable(struct net_device *dev,
1411 const struct ethtool_tunable *tuna,
1414 struct qede_dev *edev = netdev_priv(dev);
1418 case ETHTOOL_RX_COPYBREAK:
1420 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1421 DP_VERBOSE(edev, QED_MSG_DEBUG,
1422 "Invalid rx copy break value, range is [%u, %u]",
1423 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1427 edev->rx_copybreak = *(u32 *)data;
1436 static int qede_get_tunable(struct net_device *dev,
1437 const struct ethtool_tunable *tuna, void *data)
1439 struct qede_dev *edev = netdev_priv(dev);
1442 case ETHTOOL_RX_COPYBREAK:
1443 *(u32 *)data = edev->rx_copybreak;
1452 static const struct ethtool_ops qede_ethtool_ops = {
1453 .get_link_ksettings = qede_get_link_ksettings,
1454 .set_link_ksettings = qede_set_link_ksettings,
1455 .get_drvinfo = qede_get_drvinfo,
1456 .get_regs_len = qede_get_regs_len,
1457 .get_regs = qede_get_regs,
1458 .get_msglevel = qede_get_msglevel,
1459 .set_msglevel = qede_set_msglevel,
1460 .nway_reset = qede_nway_reset,
1461 .get_link = qede_get_link,
1462 .get_coalesce = qede_get_coalesce,
1463 .set_coalesce = qede_set_coalesce,
1464 .get_ringparam = qede_get_ringparam,
1465 .set_ringparam = qede_set_ringparam,
1466 .get_pauseparam = qede_get_pauseparam,
1467 .set_pauseparam = qede_set_pauseparam,
1468 .get_strings = qede_get_strings,
1469 .set_phys_id = qede_set_phys_id,
1470 .get_ethtool_stats = qede_get_ethtool_stats,
1471 .get_priv_flags = qede_get_priv_flags,
1472 .get_sset_count = qede_get_sset_count,
1473 .get_rxnfc = qede_get_rxnfc,
1474 .set_rxnfc = qede_set_rxnfc,
1475 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1476 .get_rxfh_key_size = qede_get_rxfh_key_size,
1477 .get_rxfh = qede_get_rxfh,
1478 .set_rxfh = qede_set_rxfh,
1479 .get_channels = qede_get_channels,
1480 .set_channels = qede_set_channels,
1481 .self_test = qede_self_test,
1482 .get_tunable = qede_get_tunable,
1483 .set_tunable = qede_set_tunable,
1486 static const struct ethtool_ops qede_vf_ethtool_ops = {
1487 .get_link_ksettings = qede_get_link_ksettings,
1488 .get_drvinfo = qede_get_drvinfo,
1489 .get_msglevel = qede_get_msglevel,
1490 .set_msglevel = qede_set_msglevel,
1491 .get_link = qede_get_link,
1492 .get_ringparam = qede_get_ringparam,
1493 .set_ringparam = qede_set_ringparam,
1494 .get_strings = qede_get_strings,
1495 .get_ethtool_stats = qede_get_ethtool_stats,
1496 .get_priv_flags = qede_get_priv_flags,
1497 .get_sset_count = qede_get_sset_count,
1498 .get_rxnfc = qede_get_rxnfc,
1499 .set_rxnfc = qede_set_rxnfc,
1500 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1501 .get_rxfh_key_size = qede_get_rxfh_key_size,
1502 .get_rxfh = qede_get_rxfh,
1503 .set_rxfh = qede_set_rxfh,
1504 .get_channels = qede_get_channels,
1505 .set_channels = qede_set_channels,
1506 .get_tunable = qede_get_tunable,
1507 .set_tunable = qede_set_tunable,
1510 void qede_set_ethtool_ops(struct net_device *dev)
1512 struct qede_dev *edev = netdev_priv(dev);
1515 dev->ethtool_ops = &qede_vf_ethtool_ops;
1517 dev->ethtool_ops = &qede_ethtool_ops;