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(rx_hw_errors),
39 QEDE_RQSTAT(rx_alloc_errors),
40 QEDE_RQSTAT(rx_ip_frags),
43 #define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
44 #define QEDE_RQSTATS_DATA(dev, sindex, rqindex) \
45 (*((u64 *)(((char *)(dev->fp_array[(rqindex)].rxq)) +\
46 qede_rqstats_arr[(sindex)].offset)))
49 char string[ETH_GSTRING_LEN];
51 } qede_stats_arr[] = {
52 QEDE_STAT(rx_ucast_bytes),
53 QEDE_STAT(rx_mcast_bytes),
54 QEDE_STAT(rx_bcast_bytes),
55 QEDE_STAT(rx_ucast_pkts),
56 QEDE_STAT(rx_mcast_pkts),
57 QEDE_STAT(rx_bcast_pkts),
59 QEDE_STAT(tx_ucast_bytes),
60 QEDE_STAT(tx_mcast_bytes),
61 QEDE_STAT(tx_bcast_bytes),
62 QEDE_STAT(tx_ucast_pkts),
63 QEDE_STAT(tx_mcast_pkts),
64 QEDE_STAT(tx_bcast_pkts),
66 QEDE_PF_STAT(rx_64_byte_packets),
67 QEDE_PF_STAT(rx_65_to_127_byte_packets),
68 QEDE_PF_STAT(rx_128_to_255_byte_packets),
69 QEDE_PF_STAT(rx_256_to_511_byte_packets),
70 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
71 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
72 QEDE_PF_STAT(rx_1519_to_1522_byte_packets),
73 QEDE_PF_STAT(rx_1519_to_2047_byte_packets),
74 QEDE_PF_STAT(rx_2048_to_4095_byte_packets),
75 QEDE_PF_STAT(rx_4096_to_9216_byte_packets),
76 QEDE_PF_STAT(rx_9217_to_16383_byte_packets),
77 QEDE_PF_STAT(tx_64_byte_packets),
78 QEDE_PF_STAT(tx_65_to_127_byte_packets),
79 QEDE_PF_STAT(tx_128_to_255_byte_packets),
80 QEDE_PF_STAT(tx_256_to_511_byte_packets),
81 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
82 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
83 QEDE_PF_STAT(tx_1519_to_2047_byte_packets),
84 QEDE_PF_STAT(tx_2048_to_4095_byte_packets),
85 QEDE_PF_STAT(tx_4096_to_9216_byte_packets),
86 QEDE_PF_STAT(tx_9217_to_16383_byte_packets),
88 QEDE_PF_STAT(rx_mac_crtl_frames),
89 QEDE_PF_STAT(tx_mac_ctrl_frames),
90 QEDE_PF_STAT(rx_pause_frames),
91 QEDE_PF_STAT(tx_pause_frames),
92 QEDE_PF_STAT(rx_pfc_frames),
93 QEDE_PF_STAT(tx_pfc_frames),
95 QEDE_PF_STAT(rx_crc_errors),
96 QEDE_PF_STAT(rx_align_errors),
97 QEDE_PF_STAT(rx_carrier_errors),
98 QEDE_PF_STAT(rx_oversize_packets),
99 QEDE_PF_STAT(rx_jabbers),
100 QEDE_PF_STAT(rx_undersize_packets),
101 QEDE_PF_STAT(rx_fragments),
102 QEDE_PF_STAT(tx_lpi_entry_count),
103 QEDE_PF_STAT(tx_total_collisions),
104 QEDE_PF_STAT(brb_truncates),
105 QEDE_PF_STAT(brb_discards),
106 QEDE_STAT(no_buff_discards),
107 QEDE_PF_STAT(mftag_filter_discards),
108 QEDE_PF_STAT(mac_filter_discards),
109 QEDE_STAT(tx_err_drop_pkts),
110 QEDE_STAT(ttl0_discard),
111 QEDE_STAT(packet_too_big_discard),
113 QEDE_STAT(coalesced_pkts),
114 QEDE_STAT(coalesced_events),
115 QEDE_STAT(coalesced_aborts_num),
116 QEDE_STAT(non_coalesced_pkts),
117 QEDE_STAT(coalesced_bytes),
120 #define QEDE_STATS_DATA(dev, index) \
121 (*((u64 *)(((char *)(dev)) + offsetof(struct qede_dev, stats) \
122 + qede_stats_arr[(index)].offset)))
124 #define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
131 static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
135 enum qede_ethtool_tests {
136 QEDE_ETHTOOL_INT_LOOPBACK,
137 QEDE_ETHTOOL_INTERRUPT_TEST,
138 QEDE_ETHTOOL_MEMORY_TEST,
139 QEDE_ETHTOOL_REGISTER_TEST,
140 QEDE_ETHTOOL_CLOCK_TEST,
141 QEDE_ETHTOOL_TEST_MAX
144 static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
145 "Internal loopback (offline)",
146 "Interrupt (online)\t",
147 "Memory (online)\t\t",
148 "Register (online)\t",
149 "Clock (online)\t\t",
152 static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
156 for (i = 0, j = 0; i < QEDE_NUM_STATS; i++) {
157 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
159 strcpy(buf + j * ETH_GSTRING_LEN,
160 qede_stats_arr[i].string);
164 for (k = 0; k < QEDE_NUM_RQSTATS; k++, j++)
165 strcpy(buf + j * ETH_GSTRING_LEN,
166 qede_rqstats_arr[k].string);
169 static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
171 struct qede_dev *edev = netdev_priv(dev);
175 qede_get_strings_stats(edev, buf);
177 case ETH_SS_PRIV_FLAGS:
178 memcpy(buf, qede_private_arr,
179 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
182 memcpy(buf, qede_tests_str_arr,
183 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
186 DP_VERBOSE(edev, QED_MSG_DEBUG,
187 "Unsupported stringset 0x%08x\n", stringset);
191 static void qede_get_ethtool_stats(struct net_device *dev,
192 struct ethtool_stats *stats, u64 *buf)
194 struct qede_dev *edev = netdev_priv(dev);
198 qede_fill_by_demand_stats(edev);
200 mutex_lock(&edev->qede_lock);
202 for (sidx = 0; sidx < QEDE_NUM_STATS; sidx++) {
203 if (IS_VF(edev) && qede_stats_arr[sidx].pf_only)
205 buf[cnt++] = QEDE_STATS_DATA(edev, sidx);
208 for (sidx = 0; sidx < QEDE_NUM_RQSTATS; sidx++) {
210 for (qid = 0; qid < edev->num_rss; qid++)
211 buf[cnt] += QEDE_RQSTATS_DATA(edev, sidx, qid);
215 mutex_unlock(&edev->qede_lock);
218 static int qede_get_sset_count(struct net_device *dev, int stringset)
220 struct qede_dev *edev = netdev_priv(dev);
221 int num_stats = QEDE_NUM_STATS;
228 for (i = 0; i < QEDE_NUM_STATS; i++)
229 if (qede_stats_arr[i].pf_only)
232 return num_stats + QEDE_NUM_RQSTATS;
233 case ETH_SS_PRIV_FLAGS:
234 return QEDE_PRI_FLAG_LEN;
237 return QEDE_ETHTOOL_TEST_MAX;
241 DP_VERBOSE(edev, QED_MSG_DEBUG,
242 "Unsupported stringset 0x%08x\n", stringset);
247 static u32 qede_get_priv_flags(struct net_device *dev)
249 struct qede_dev *edev = netdev_priv(dev);
251 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
254 struct qede_link_mode_mapping {
256 u32 ethtool_link_mode;
259 static const struct qede_link_mode_mapping qed_lm_map[] = {
260 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
261 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
262 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
263 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
264 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
265 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
266 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
267 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
268 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
269 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
270 {QED_LM_100000baseKR4_Full_BIT,
271 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
274 #define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
278 for (i = 0; i < QED_LM_COUNT; i++) { \
279 if ((caps) & (qed_lm_map[i].qed_link_mode)) \
280 __set_bit(qed_lm_map[i].ethtool_link_mode,\
281 lk_ksettings->link_modes.name); \
285 #define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
289 for (i = 0; i < QED_LM_COUNT; i++) { \
290 if (test_bit(qed_lm_map[i].ethtool_link_mode, \
291 lk_ksettings->link_modes.name)) \
292 caps |= qed_lm_map[i].qed_link_mode; \
296 static int qede_get_link_ksettings(struct net_device *dev,
297 struct ethtool_link_ksettings *cmd)
299 struct ethtool_link_settings *base = &cmd->base;
300 struct qede_dev *edev = netdev_priv(dev);
301 struct qed_link_output current_link;
303 memset(¤t_link, 0, sizeof(current_link));
304 edev->ops->common->get_link(edev->cdev, ¤t_link);
306 ethtool_link_ksettings_zero_link_mode(cmd, supported);
307 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
309 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
310 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
312 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
313 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
315 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
316 base->speed = current_link.speed;
317 base->duplex = current_link.duplex;
319 base->speed = SPEED_UNKNOWN;
320 base->duplex = DUPLEX_UNKNOWN;
322 base->port = current_link.port;
323 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
329 static int qede_set_link_ksettings(struct net_device *dev,
330 const struct ethtool_link_ksettings *cmd)
332 const struct ethtool_link_settings *base = &cmd->base;
333 struct qede_dev *edev = netdev_priv(dev);
334 struct qed_link_output current_link;
335 struct qed_link_params params;
337 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
338 DP_INFO(edev, "Link settings are not allowed to be changed\n");
341 memset(¤t_link, 0, sizeof(current_link));
342 memset(¶ms, 0, sizeof(params));
343 edev->ops->common->get_link(edev->cdev, ¤t_link);
345 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
346 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
347 if (base->autoneg == AUTONEG_ENABLE) {
348 params.autoneg = true;
349 params.forced_speed = 0;
350 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
351 } else { /* forced speed */
352 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
353 params.autoneg = false;
354 params.forced_speed = base->speed;
355 switch (base->speed) {
357 if (!(current_link.supported_caps &
358 QED_LM_10000baseKR_Full_BIT)) {
359 DP_INFO(edev, "10G speed not supported\n");
362 params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
365 if (!(current_link.supported_caps &
366 QED_LM_25000baseKR_Full_BIT)) {
367 DP_INFO(edev, "25G speed not supported\n");
370 params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
373 if (!(current_link.supported_caps &
374 QED_LM_40000baseLR4_Full_BIT)) {
375 DP_INFO(edev, "40G speed not supported\n");
378 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
381 if (!(current_link.supported_caps &
382 QED_LM_50000baseKR2_Full_BIT)) {
383 DP_INFO(edev, "50G speed not supported\n");
386 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
389 if (!(current_link.supported_caps &
390 QED_LM_100000baseKR4_Full_BIT)) {
391 DP_INFO(edev, "100G speed not supported\n");
394 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
397 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
402 params.link_up = true;
403 edev->ops->common->set_link(edev->cdev, ¶ms);
408 static void qede_get_drvinfo(struct net_device *ndev,
409 struct ethtool_drvinfo *info)
411 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
412 struct qede_dev *edev = netdev_priv(ndev);
414 strlcpy(info->driver, "qede", sizeof(info->driver));
415 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
417 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
418 edev->dev_info.common.fw_major,
419 edev->dev_info.common.fw_minor,
420 edev->dev_info.common.fw_rev,
421 edev->dev_info.common.fw_eng);
423 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
424 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
425 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
426 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
427 edev->dev_info.common.mfw_rev & 0xFF);
429 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
430 sizeof(info->fw_version)) {
431 snprintf(info->fw_version, sizeof(info->fw_version),
432 "mfw %s storm %s", mfw, storm);
434 snprintf(info->fw_version, sizeof(info->fw_version),
435 "%s %s", mfw, storm);
438 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
441 static u32 qede_get_msglevel(struct net_device *ndev)
443 struct qede_dev *edev = netdev_priv(ndev);
445 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
448 static void qede_set_msglevel(struct net_device *ndev, u32 level)
450 struct qede_dev *edev = netdev_priv(ndev);
454 qede_config_debug(level, &dp_module, &dp_level);
456 edev->dp_level = dp_level;
457 edev->dp_module = dp_module;
458 edev->ops->common->update_msglvl(edev->cdev,
459 dp_module, dp_level);
462 static int qede_nway_reset(struct net_device *dev)
464 struct qede_dev *edev = netdev_priv(dev);
465 struct qed_link_output current_link;
466 struct qed_link_params link_params;
468 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
469 DP_INFO(edev, "Link settings are not allowed to be changed\n");
473 if (!netif_running(dev))
476 memset(¤t_link, 0, sizeof(current_link));
477 edev->ops->common->get_link(edev->cdev, ¤t_link);
478 if (!current_link.link_up)
481 /* Toggle the link */
482 memset(&link_params, 0, sizeof(link_params));
483 link_params.link_up = false;
484 edev->ops->common->set_link(edev->cdev, &link_params);
485 link_params.link_up = true;
486 edev->ops->common->set_link(edev->cdev, &link_params);
491 static u32 qede_get_link(struct net_device *dev)
493 struct qede_dev *edev = netdev_priv(dev);
494 struct qed_link_output current_link;
496 memset(¤t_link, 0, sizeof(current_link));
497 edev->ops->common->get_link(edev->cdev, ¤t_link);
499 return current_link.link_up;
502 static int qede_get_coalesce(struct net_device *dev,
503 struct ethtool_coalesce *coal)
505 struct qede_dev *edev = netdev_priv(dev);
508 memset(coal, 0, sizeof(struct ethtool_coalesce));
509 edev->ops->common->get_coalesce(edev->cdev, &rxc, &txc);
511 coal->rx_coalesce_usecs = rxc;
512 coal->tx_coalesce_usecs = txc;
517 static int qede_set_coalesce(struct net_device *dev,
518 struct ethtool_coalesce *coal)
520 struct qede_dev *edev = netdev_priv(dev);
525 if (!netif_running(dev)) {
526 DP_INFO(edev, "Interface is down\n");
530 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
531 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
533 "Can't support requested %s coalesce value [max supported value %d]\n",
534 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
540 rxc = (u16)coal->rx_coalesce_usecs;
541 txc = (u16)coal->tx_coalesce_usecs;
543 sb_id = edev->fp_array[i].sb_info->igu_sb_id;
544 rc = edev->ops->common->set_coalesce(edev->cdev, rxc, txc,
547 DP_INFO(edev, "Set coalesce error, rc = %d\n", rc);
555 static void qede_get_ringparam(struct net_device *dev,
556 struct ethtool_ringparam *ering)
558 struct qede_dev *edev = netdev_priv(dev);
560 ering->rx_max_pending = NUM_RX_BDS_MAX;
561 ering->rx_pending = edev->q_num_rx_buffers;
562 ering->tx_max_pending = NUM_TX_BDS_MAX;
563 ering->tx_pending = edev->q_num_tx_buffers;
566 static int qede_set_ringparam(struct net_device *dev,
567 struct ethtool_ringparam *ering)
569 struct qede_dev *edev = netdev_priv(dev);
571 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
572 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
573 ering->rx_pending, ering->tx_pending);
575 /* Validate legality of configuration */
576 if (ering->rx_pending > NUM_RX_BDS_MAX ||
577 ering->rx_pending < NUM_RX_BDS_MIN ||
578 ering->tx_pending > NUM_TX_BDS_MAX ||
579 ering->tx_pending < NUM_TX_BDS_MIN) {
580 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
581 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
582 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
583 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
587 /* Change ring size and re-load */
588 edev->q_num_rx_buffers = ering->rx_pending;
589 edev->q_num_tx_buffers = ering->tx_pending;
591 if (netif_running(edev->ndev))
592 qede_reload(edev, NULL, NULL);
597 static void qede_get_pauseparam(struct net_device *dev,
598 struct ethtool_pauseparam *epause)
600 struct qede_dev *edev = netdev_priv(dev);
601 struct qed_link_output current_link;
603 memset(¤t_link, 0, sizeof(current_link));
604 edev->ops->common->get_link(edev->cdev, ¤t_link);
606 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
607 epause->autoneg = true;
608 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
609 epause->rx_pause = true;
610 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
611 epause->tx_pause = true;
613 DP_VERBOSE(edev, QED_MSG_DEBUG,
614 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
615 epause->cmd, epause->autoneg, epause->rx_pause,
619 static int qede_set_pauseparam(struct net_device *dev,
620 struct ethtool_pauseparam *epause)
622 struct qede_dev *edev = netdev_priv(dev);
623 struct qed_link_params params;
624 struct qed_link_output current_link;
626 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
628 "Pause settings are not allowed to be changed\n");
632 memset(¤t_link, 0, sizeof(current_link));
633 edev->ops->common->get_link(edev->cdev, ¤t_link);
635 memset(¶ms, 0, sizeof(params));
636 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
637 if (epause->autoneg) {
638 if (!(current_link.supported_caps & SUPPORTED_Autoneg)) {
639 DP_INFO(edev, "autoneg not supported\n");
642 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
644 if (epause->rx_pause)
645 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
646 if (epause->tx_pause)
647 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
649 params.link_up = true;
650 edev->ops->common->set_link(edev->cdev, ¶ms);
655 static void qede_update_mtu(struct qede_dev *edev, union qede_reload_args *args)
657 edev->ndev->mtu = args->mtu;
661 #define ETH_MAX_JUMBO_PACKET_SIZE 9600
662 #define ETH_MIN_PACKET_SIZE 60
663 int qede_change_mtu(struct net_device *ndev, int new_mtu)
665 struct qede_dev *edev = netdev_priv(ndev);
666 union qede_reload_args args;
668 if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
669 ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE)) {
670 DP_ERR(edev, "Can't support requested MTU size\n");
674 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
675 "Configuring MTU size of %d\n", new_mtu);
677 /* Set the mtu field and re-start the interface if needed*/
680 if (netif_running(edev->ndev))
681 qede_reload(edev, &qede_update_mtu, &args);
683 qede_update_mtu(edev, &args);
688 static void qede_get_channels(struct net_device *dev,
689 struct ethtool_channels *channels)
691 struct qede_dev *edev = netdev_priv(dev);
693 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
694 channels->combined_count = QEDE_RSS_CNT(edev);
697 static int qede_set_channels(struct net_device *dev,
698 struct ethtool_channels *channels)
700 struct qede_dev *edev = netdev_priv(dev);
702 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
703 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
704 channels->rx_count, channels->tx_count,
705 channels->other_count, channels->combined_count);
707 /* We don't support separate rx / tx, nor `other' channels. */
708 if (channels->rx_count || channels->tx_count ||
709 channels->other_count || (channels->combined_count == 0) ||
710 (channels->combined_count > QEDE_MAX_RSS_CNT(edev))) {
711 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
712 "command parameters not supported\n");
716 /* Check if there was a change in the active parameters */
717 if (channels->combined_count == QEDE_RSS_CNT(edev)) {
718 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
719 "No change in active parameters\n");
723 /* We need the number of queues to be divisible between the hwfns */
724 if (channels->combined_count % edev->dev_info.common.num_hwfns) {
725 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
726 "Number of channels must be divisable by %04x\n",
727 edev->dev_info.common.num_hwfns);
731 /* Set number of queues and reload if necessary */
732 edev->req_rss = channels->combined_count;
733 if (netif_running(dev))
734 qede_reload(edev, NULL, NULL);
739 static int qede_set_phys_id(struct net_device *dev,
740 enum ethtool_phys_id_state state)
742 struct qede_dev *edev = netdev_priv(dev);
746 case ETHTOOL_ID_ACTIVE:
747 return 1; /* cycle on/off once per second */
750 led_state = QED_LED_MODE_ON;
754 led_state = QED_LED_MODE_OFF;
757 case ETHTOOL_ID_INACTIVE:
758 led_state = QED_LED_MODE_RESTORE;
762 edev->ops->common->set_led(edev->cdev, led_state);
767 static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
769 info->data = RXH_IP_SRC | RXH_IP_DST;
771 switch (info->flow_type) {
774 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
777 if (edev->rss_params.rss_caps & QED_RSS_IPV4_UDP)
778 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
781 if (edev->rss_params.rss_caps & QED_RSS_IPV6_UDP)
782 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
795 static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
796 u32 *rules __always_unused)
798 struct qede_dev *edev = netdev_priv(dev);
801 case ETHTOOL_GRXRINGS:
802 info->data = edev->num_rss;
805 return qede_get_rss_flags(edev, info);
807 DP_ERR(edev, "Command parameters not supported\n");
812 static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
814 struct qed_update_vport_params vport_update_params;
815 u8 set_caps = 0, clr_caps = 0;
817 DP_VERBOSE(edev, QED_MSG_DEBUG,
818 "Set rss flags command parameters: flow type = %d, data = %llu\n",
819 info->flow_type, info->data);
821 switch (info->flow_type) {
824 /* For TCP only 4-tuple hash is supported */
825 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
826 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
827 DP_INFO(edev, "Command parameters not supported\n");
832 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
833 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
834 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
835 set_caps = QED_RSS_IPV4_UDP;
836 DP_VERBOSE(edev, QED_MSG_DEBUG,
837 "UDP 4-tuple enabled\n");
838 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
839 clr_caps = QED_RSS_IPV4_UDP;
840 DP_VERBOSE(edev, QED_MSG_DEBUG,
841 "UDP 4-tuple disabled\n");
847 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
848 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
849 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
850 set_caps = QED_RSS_IPV6_UDP;
851 DP_VERBOSE(edev, QED_MSG_DEBUG,
852 "UDP 4-tuple enabled\n");
853 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
854 clr_caps = QED_RSS_IPV6_UDP;
855 DP_VERBOSE(edev, QED_MSG_DEBUG,
856 "UDP 4-tuple disabled\n");
863 /* For IP only 2-tuple hash is supported */
864 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
865 DP_INFO(edev, "Command parameters not supported\n");
879 /* RSS is not supported for these protocols */
881 DP_INFO(edev, "Command parameters not supported\n");
889 /* No action is needed if there is no change in the rss capability */
890 if (edev->rss_params.rss_caps == ((edev->rss_params.rss_caps &
891 ~clr_caps) | set_caps))
894 /* Update internal configuration */
895 edev->rss_params.rss_caps = (edev->rss_params.rss_caps & ~clr_caps) |
897 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
899 /* Re-configure if possible */
900 if (netif_running(edev->ndev)) {
901 memset(&vport_update_params, 0, sizeof(vport_update_params));
902 vport_update_params.update_rss_flg = 1;
903 vport_update_params.vport_id = 0;
904 memcpy(&vport_update_params.rss_params, &edev->rss_params,
905 sizeof(vport_update_params.rss_params));
906 return edev->ops->vport_update(edev->cdev,
907 &vport_update_params);
913 static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
915 struct qede_dev *edev = netdev_priv(dev);
919 return qede_set_rss_flags(edev, info);
921 DP_INFO(edev, "Command parameters not supported\n");
926 static u32 qede_get_rxfh_indir_size(struct net_device *dev)
928 return QED_RSS_IND_TABLE_SIZE;
931 static u32 qede_get_rxfh_key_size(struct net_device *dev)
933 struct qede_dev *edev = netdev_priv(dev);
935 return sizeof(edev->rss_params.rss_key);
938 static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
940 struct qede_dev *edev = netdev_priv(dev);
944 *hfunc = ETH_RSS_HASH_TOP;
949 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
950 indir[i] = edev->rss_params.rss_ind_table[i];
953 memcpy(key, edev->rss_params.rss_key,
954 qede_get_rxfh_key_size(dev));
959 static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
960 const u8 *key, const u8 hfunc)
962 struct qed_update_vport_params vport_update_params;
963 struct qede_dev *edev = netdev_priv(dev);
966 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
973 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
974 edev->rss_params.rss_ind_table[i] = indir[i];
975 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
979 memcpy(&edev->rss_params.rss_key, key,
980 qede_get_rxfh_key_size(dev));
981 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
984 if (netif_running(edev->ndev)) {
985 memset(&vport_update_params, 0, sizeof(vport_update_params));
986 vport_update_params.update_rss_flg = 1;
987 vport_update_params.vport_id = 0;
988 memcpy(&vport_update_params.rss_params, &edev->rss_params,
989 sizeof(vport_update_params.rss_params));
990 return edev->ops->vport_update(edev->cdev,
991 &vport_update_params);
997 /* This function enables the interrupt generation and the NAPI on the device */
998 static void qede_netif_start(struct qede_dev *edev)
1002 if (!netif_running(edev->ndev))
1006 /* Update and reenable interrupts */
1007 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1008 napi_enable(&edev->fp_array[i].napi);
1012 /* This function disables the NAPI and the interrupt generation on the device */
1013 static void qede_netif_stop(struct qede_dev *edev)
1018 napi_disable(&edev->fp_array[i].napi);
1019 /* Disable interrupts */
1020 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1024 static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1025 struct sk_buff *skb)
1027 struct qede_tx_queue *txq = &edev->fp_array[0].txqs[0];
1028 struct eth_tx_1st_bd *first_bd;
1032 /* Fill the entry in the SW ring and the BDs in the FW ring */
1033 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
1034 txq->sw_tx_ring[idx].skb = skb;
1035 first_bd = qed_chain_produce(&txq->tx_pbl);
1036 memset(first_bd, 0, sizeof(*first_bd));
1037 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1038 first_bd->data.bd_flags.bitfields = val;
1039 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1040 first_bd->data.bitfields |= (val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT);
1042 /* Map skb linear data for DMA and set in the first BD */
1043 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1044 skb_headlen(skb), DMA_TO_DEVICE);
1045 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1046 DP_NOTICE(edev, "SKB mapping failed\n");
1049 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1051 /* update the first BD with the actual num BDs */
1052 first_bd->data.nbds = 1;
1054 /* 'next page' entries are counted in the producer value */
1055 val = cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
1056 txq->tx_db.data.bd_prod = val;
1058 /* wmb makes sure that the BDs data is updated before updating the
1059 * producer, otherwise FW may read old data from the BDs.
1063 writel(txq->tx_db.raw, txq->doorbell_addr);
1065 /* mmiowb is needed to synchronize doorbell writes from more than one
1066 * processor. It guarantees that the write arrives to the device before
1067 * the queue lock is released and another start_xmit is called (possibly
1068 * on another CPU). Without this barrier, the next doorbell can bypass
1069 * this doorbell. This is applicable to IA64/Altix systems.
1073 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1074 if (qede_txq_has_work(txq))
1076 usleep_range(100, 200);
1079 if (!qede_txq_has_work(txq)) {
1080 DP_NOTICE(edev, "Tx completion didn't happen\n");
1084 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
1085 dma_unmap_page(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1086 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
1088 txq->sw_tx_ring[idx].skb = NULL;
1093 static int qede_selftest_receive_traffic(struct qede_dev *edev)
1095 struct qede_rx_queue *rxq = edev->fp_array[0].rxq;
1096 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
1097 struct eth_fast_path_rx_reg_cqe *fp_cqe;
1098 struct sw_rx_data *sw_rx_data;
1099 union eth_rx_cqe *cqe;
1103 /* The packet is expected to receive on rx-queue 0 even though RSS is
1104 * enabled. This is because the queue 0 is configured as the default
1105 * queue and that the loopback traffic is not IP.
1107 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1108 if (qede_has_rx_work(rxq))
1110 usleep_range(100, 200);
1113 if (!qede_has_rx_work(rxq)) {
1114 DP_NOTICE(edev, "Failed to receive the traffic\n");
1118 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1119 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1121 /* Memory barrier to prevent the CPU from doing speculative reads of CQE
1122 * / BD before reading hw_comp_cons. If the CQE is read before it is
1123 * written by FW, then FW writes CQE and SB, and then the CPU reads the
1124 * hw_comp_cons, it will use an old CQE.
1128 /* Get the CQE from the completion ring */
1129 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1131 /* Get the data from the SW ring */
1132 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1133 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1134 fp_cqe = &cqe->fast_path_regular;
1135 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1136 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1137 fp_cqe->placement_offset + sw_rx_data->page_offset);
1138 for (i = ETH_HLEN; i < len; i++)
1139 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1140 DP_NOTICE(edev, "Loopback test failed\n");
1141 qede_recycle_rx_bd_ring(rxq, edev, 1);
1145 qede_recycle_rx_bd_ring(rxq, edev, 1);
1150 static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1152 struct qed_link_params link_params;
1153 struct sk_buff *skb = NULL;
1158 if (!netif_running(edev->ndev)) {
1159 DP_NOTICE(edev, "Interface is down\n");
1163 qede_netif_stop(edev);
1165 /* Bring up the link in Loopback mode */
1166 memset(&link_params, 0, sizeof(link_params));
1167 link_params.link_up = true;
1168 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1169 link_params.loopback_mode = loopback_mode;
1170 edev->ops->common->set_link(edev->cdev, &link_params);
1172 /* Wait for loopback configuration to apply */
1173 msleep_interruptible(500);
1175 /* prepare the loopback packet */
1176 pkt_size = edev->ndev->mtu + ETH_HLEN;
1178 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1180 DP_INFO(edev, "Can't allocate skb\n");
1182 goto test_loopback_exit;
1184 packet = skb_put(skb, pkt_size);
1185 ether_addr_copy(packet, edev->ndev->dev_addr);
1186 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1187 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1188 for (i = ETH_HLEN; i < pkt_size; i++)
1189 packet[i] = (unsigned char)(i & 0xff);
1191 rc = qede_selftest_transmit_traffic(edev, skb);
1193 goto test_loopback_exit;
1195 rc = qede_selftest_receive_traffic(edev);
1197 goto test_loopback_exit;
1199 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1204 /* Bring up the link in Normal mode */
1205 memset(&link_params, 0, sizeof(link_params));
1206 link_params.link_up = true;
1207 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1208 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1209 edev->ops->common->set_link(edev->cdev, &link_params);
1211 /* Wait for loopback configuration to apply */
1212 msleep_interruptible(500);
1214 qede_netif_start(edev);
1219 static void qede_self_test(struct net_device *dev,
1220 struct ethtool_test *etest, u64 *buf)
1222 struct qede_dev *edev = netdev_priv(dev);
1224 DP_VERBOSE(edev, QED_MSG_DEBUG,
1225 "Self-test command parameters: offline = %d, external_lb = %d\n",
1226 (etest->flags & ETH_TEST_FL_OFFLINE),
1227 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1229 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1231 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1232 if (qede_selftest_run_loopback(edev,
1233 QED_LINK_LOOPBACK_INT_PHY)) {
1234 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1235 etest->flags |= ETH_TEST_FL_FAILED;
1239 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1240 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1241 etest->flags |= ETH_TEST_FL_FAILED;
1244 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1245 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1246 etest->flags |= ETH_TEST_FL_FAILED;
1249 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1250 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1251 etest->flags |= ETH_TEST_FL_FAILED;
1254 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1255 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1256 etest->flags |= ETH_TEST_FL_FAILED;
1260 static int qede_set_tunable(struct net_device *dev,
1261 const struct ethtool_tunable *tuna,
1264 struct qede_dev *edev = netdev_priv(dev);
1268 case ETHTOOL_RX_COPYBREAK:
1270 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1271 DP_VERBOSE(edev, QED_MSG_DEBUG,
1272 "Invalid rx copy break value, range is [%u, %u]",
1273 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1277 edev->rx_copybreak = *(u32 *)data;
1286 static int qede_get_tunable(struct net_device *dev,
1287 const struct ethtool_tunable *tuna, void *data)
1289 struct qede_dev *edev = netdev_priv(dev);
1292 case ETHTOOL_RX_COPYBREAK:
1293 *(u32 *)data = edev->rx_copybreak;
1302 static const struct ethtool_ops qede_ethtool_ops = {
1303 .get_link_ksettings = qede_get_link_ksettings,
1304 .set_link_ksettings = qede_set_link_ksettings,
1305 .get_drvinfo = qede_get_drvinfo,
1306 .get_msglevel = qede_get_msglevel,
1307 .set_msglevel = qede_set_msglevel,
1308 .nway_reset = qede_nway_reset,
1309 .get_link = qede_get_link,
1310 .get_coalesce = qede_get_coalesce,
1311 .set_coalesce = qede_set_coalesce,
1312 .get_ringparam = qede_get_ringparam,
1313 .set_ringparam = qede_set_ringparam,
1314 .get_pauseparam = qede_get_pauseparam,
1315 .set_pauseparam = qede_set_pauseparam,
1316 .get_strings = qede_get_strings,
1317 .set_phys_id = qede_set_phys_id,
1318 .get_ethtool_stats = qede_get_ethtool_stats,
1319 .get_priv_flags = qede_get_priv_flags,
1320 .get_sset_count = qede_get_sset_count,
1321 .get_rxnfc = qede_get_rxnfc,
1322 .set_rxnfc = qede_set_rxnfc,
1323 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1324 .get_rxfh_key_size = qede_get_rxfh_key_size,
1325 .get_rxfh = qede_get_rxfh,
1326 .set_rxfh = qede_set_rxfh,
1327 .get_channels = qede_get_channels,
1328 .set_channels = qede_set_channels,
1329 .self_test = qede_self_test,
1330 .get_tunable = qede_get_tunable,
1331 .set_tunable = qede_set_tunable,
1334 static const struct ethtool_ops qede_vf_ethtool_ops = {
1335 .get_link_ksettings = qede_get_link_ksettings,
1336 .get_drvinfo = qede_get_drvinfo,
1337 .get_msglevel = qede_get_msglevel,
1338 .set_msglevel = qede_set_msglevel,
1339 .get_link = qede_get_link,
1340 .get_ringparam = qede_get_ringparam,
1341 .set_ringparam = qede_set_ringparam,
1342 .get_strings = qede_get_strings,
1343 .get_ethtool_stats = qede_get_ethtool_stats,
1344 .get_priv_flags = qede_get_priv_flags,
1345 .get_sset_count = qede_get_sset_count,
1346 .get_rxnfc = qede_get_rxnfc,
1347 .set_rxnfc = qede_set_rxnfc,
1348 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1349 .get_rxfh_key_size = qede_get_rxfh_key_size,
1350 .get_rxfh = qede_get_rxfh,
1351 .set_rxfh = qede_set_rxfh,
1352 .get_channels = qede_get_channels,
1353 .set_channels = qede_set_channels,
1354 .get_tunable = qede_get_tunable,
1355 .set_tunable = qede_set_tunable,
1358 void qede_set_ethtool_ops(struct net_device *dev)
1360 struct qede_dev *edev = netdev_priv(dev);
1363 dev->ethtool_ops = &qede_vf_ethtool_ops;
1365 dev->ethtool_ops = &qede_ethtool_ops;