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),
42 #define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
43 #define QEDE_RQSTATS_DATA(dev, sindex, rqindex) \
44 (*((u64 *)(((char *)(dev->fp_array[(rqindex)].rxq)) +\
45 qede_rqstats_arr[(sindex)].offset)))
48 char string[ETH_GSTRING_LEN];
50 } qede_stats_arr[] = {
51 QEDE_STAT(rx_ucast_bytes),
52 QEDE_STAT(rx_mcast_bytes),
53 QEDE_STAT(rx_bcast_bytes),
54 QEDE_STAT(rx_ucast_pkts),
55 QEDE_STAT(rx_mcast_pkts),
56 QEDE_STAT(rx_bcast_pkts),
58 QEDE_STAT(tx_ucast_bytes),
59 QEDE_STAT(tx_mcast_bytes),
60 QEDE_STAT(tx_bcast_bytes),
61 QEDE_STAT(tx_ucast_pkts),
62 QEDE_STAT(tx_mcast_pkts),
63 QEDE_STAT(tx_bcast_pkts),
65 QEDE_PF_STAT(rx_64_byte_packets),
66 QEDE_PF_STAT(rx_65_to_127_byte_packets),
67 QEDE_PF_STAT(rx_128_to_255_byte_packets),
68 QEDE_PF_STAT(rx_256_to_511_byte_packets),
69 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
70 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
71 QEDE_PF_STAT(rx_1519_to_1522_byte_packets),
72 QEDE_PF_STAT(rx_1519_to_2047_byte_packets),
73 QEDE_PF_STAT(rx_2048_to_4095_byte_packets),
74 QEDE_PF_STAT(rx_4096_to_9216_byte_packets),
75 QEDE_PF_STAT(rx_9217_to_16383_byte_packets),
76 QEDE_PF_STAT(tx_64_byte_packets),
77 QEDE_PF_STAT(tx_65_to_127_byte_packets),
78 QEDE_PF_STAT(tx_128_to_255_byte_packets),
79 QEDE_PF_STAT(tx_256_to_511_byte_packets),
80 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
81 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
82 QEDE_PF_STAT(tx_1519_to_2047_byte_packets),
83 QEDE_PF_STAT(tx_2048_to_4095_byte_packets),
84 QEDE_PF_STAT(tx_4096_to_9216_byte_packets),
85 QEDE_PF_STAT(tx_9217_to_16383_byte_packets),
87 QEDE_PF_STAT(rx_mac_crtl_frames),
88 QEDE_PF_STAT(tx_mac_ctrl_frames),
89 QEDE_PF_STAT(rx_pause_frames),
90 QEDE_PF_STAT(tx_pause_frames),
91 QEDE_PF_STAT(rx_pfc_frames),
92 QEDE_PF_STAT(tx_pfc_frames),
94 QEDE_PF_STAT(rx_crc_errors),
95 QEDE_PF_STAT(rx_align_errors),
96 QEDE_PF_STAT(rx_carrier_errors),
97 QEDE_PF_STAT(rx_oversize_packets),
98 QEDE_PF_STAT(rx_jabbers),
99 QEDE_PF_STAT(rx_undersize_packets),
100 QEDE_PF_STAT(rx_fragments),
101 QEDE_PF_STAT(tx_lpi_entry_count),
102 QEDE_PF_STAT(tx_total_collisions),
103 QEDE_PF_STAT(brb_truncates),
104 QEDE_PF_STAT(brb_discards),
105 QEDE_STAT(no_buff_discards),
106 QEDE_PF_STAT(mftag_filter_discards),
107 QEDE_PF_STAT(mac_filter_discards),
108 QEDE_STAT(tx_err_drop_pkts),
110 QEDE_STAT(coalesced_pkts),
111 QEDE_STAT(coalesced_events),
112 QEDE_STAT(coalesced_aborts_num),
113 QEDE_STAT(non_coalesced_pkts),
114 QEDE_STAT(coalesced_bytes),
117 #define QEDE_STATS_DATA(dev, index) \
118 (*((u64 *)(((char *)(dev)) + offsetof(struct qede_dev, stats) \
119 + qede_stats_arr[(index)].offset)))
121 #define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
128 static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
132 enum qede_ethtool_tests {
133 QEDE_ETHTOOL_INT_LOOPBACK,
134 QEDE_ETHTOOL_INTERRUPT_TEST,
135 QEDE_ETHTOOL_MEMORY_TEST,
136 QEDE_ETHTOOL_REGISTER_TEST,
137 QEDE_ETHTOOL_CLOCK_TEST,
138 QEDE_ETHTOOL_TEST_MAX
141 static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
142 "Internal loopback (offline)",
143 "Interrupt (online)\t",
144 "Memory (online)\t\t",
145 "Register (online)\t",
146 "Clock (online)\t\t",
149 static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
153 for (i = 0, j = 0; i < QEDE_NUM_STATS; i++) {
154 strcpy(buf + j * ETH_GSTRING_LEN,
155 qede_stats_arr[i].string);
159 for (k = 0; k < QEDE_NUM_RQSTATS; k++, j++)
160 strcpy(buf + j * ETH_GSTRING_LEN,
161 qede_rqstats_arr[k].string);
164 static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
166 struct qede_dev *edev = netdev_priv(dev);
170 qede_get_strings_stats(edev, buf);
172 case ETH_SS_PRIV_FLAGS:
173 memcpy(buf, qede_private_arr,
174 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
177 memcpy(buf, qede_tests_str_arr,
178 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
181 DP_VERBOSE(edev, QED_MSG_DEBUG,
182 "Unsupported stringset 0x%08x\n", stringset);
186 static void qede_get_ethtool_stats(struct net_device *dev,
187 struct ethtool_stats *stats, u64 *buf)
189 struct qede_dev *edev = netdev_priv(dev);
193 qede_fill_by_demand_stats(edev);
195 mutex_lock(&edev->qede_lock);
197 for (sidx = 0; sidx < QEDE_NUM_STATS; sidx++)
198 buf[cnt++] = QEDE_STATS_DATA(edev, sidx);
200 for (sidx = 0; sidx < QEDE_NUM_RQSTATS; sidx++) {
202 for (qid = 0; qid < edev->num_rss; qid++)
203 buf[cnt] += QEDE_RQSTATS_DATA(edev, sidx, qid);
207 mutex_unlock(&edev->qede_lock);
210 static int qede_get_sset_count(struct net_device *dev, int stringset)
212 struct qede_dev *edev = netdev_priv(dev);
213 int num_stats = QEDE_NUM_STATS;
217 return num_stats + QEDE_NUM_RQSTATS;
218 case ETH_SS_PRIV_FLAGS:
219 return QEDE_PRI_FLAG_LEN;
221 return QEDE_ETHTOOL_TEST_MAX;
223 DP_VERBOSE(edev, QED_MSG_DEBUG,
224 "Unsupported stringset 0x%08x\n", stringset);
229 static u32 qede_get_priv_flags(struct net_device *dev)
231 struct qede_dev *edev = netdev_priv(dev);
233 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
236 static int qede_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
238 struct qede_dev *edev = netdev_priv(dev);
239 struct qed_link_output current_link;
241 memset(¤t_link, 0, sizeof(current_link));
242 edev->ops->common->get_link(edev->cdev, ¤t_link);
244 cmd->supported = current_link.supported_caps;
245 cmd->advertising = current_link.advertised_caps;
246 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
247 ethtool_cmd_speed_set(cmd, current_link.speed);
248 cmd->duplex = current_link.duplex;
250 cmd->duplex = DUPLEX_UNKNOWN;
251 ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN);
253 cmd->port = current_link.port;
254 cmd->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
256 cmd->lp_advertising = current_link.lp_caps;
261 static int qede_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
263 struct qede_dev *edev = netdev_priv(dev);
264 struct qed_link_output current_link;
265 struct qed_link_params params;
268 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
270 "Link settings are not allowed to be changed\n");
274 memset(¤t_link, 0, sizeof(current_link));
275 memset(¶ms, 0, sizeof(params));
276 edev->ops->common->get_link(edev->cdev, ¤t_link);
278 speed = ethtool_cmd_speed(cmd);
279 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
280 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
281 if (cmd->autoneg == AUTONEG_ENABLE) {
282 params.autoneg = true;
283 params.forced_speed = 0;
284 params.adv_speeds = cmd->advertising;
285 } else { /* forced speed */
286 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
287 params.autoneg = false;
288 params.forced_speed = speed;
291 if (!(current_link.supported_caps &
292 SUPPORTED_10000baseKR_Full)) {
293 DP_INFO(edev, "10G speed not supported\n");
296 params.adv_speeds = SUPPORTED_10000baseKR_Full;
299 if (!(current_link.supported_caps &
300 SUPPORTED_40000baseLR4_Full)) {
301 DP_INFO(edev, "40G speed not supported\n");
304 params.adv_speeds = SUPPORTED_40000baseLR4_Full;
307 DP_INFO(edev, "Unsupported speed %u\n", speed);
312 params.link_up = true;
313 edev->ops->common->set_link(edev->cdev, ¶ms);
318 static void qede_get_drvinfo(struct net_device *ndev,
319 struct ethtool_drvinfo *info)
321 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
322 struct qede_dev *edev = netdev_priv(ndev);
324 strlcpy(info->driver, "qede", sizeof(info->driver));
325 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
327 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
328 edev->dev_info.common.fw_major,
329 edev->dev_info.common.fw_minor,
330 edev->dev_info.common.fw_rev,
331 edev->dev_info.common.fw_eng);
333 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
334 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
335 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
336 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
337 edev->dev_info.common.mfw_rev & 0xFF);
339 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
340 sizeof(info->fw_version)) {
341 snprintf(info->fw_version, sizeof(info->fw_version),
342 "mfw %s storm %s", mfw, storm);
344 snprintf(info->fw_version, sizeof(info->fw_version),
345 "%s %s", mfw, storm);
348 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
351 static u32 qede_get_msglevel(struct net_device *ndev)
353 struct qede_dev *edev = netdev_priv(ndev);
355 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) |
359 static void qede_set_msglevel(struct net_device *ndev, u32 level)
361 struct qede_dev *edev = netdev_priv(ndev);
365 qede_config_debug(level, &dp_module, &dp_level);
367 edev->dp_level = dp_level;
368 edev->dp_module = dp_module;
369 edev->ops->common->update_msglvl(edev->cdev,
370 dp_module, dp_level);
373 static int qede_nway_reset(struct net_device *dev)
375 struct qede_dev *edev = netdev_priv(dev);
376 struct qed_link_output current_link;
377 struct qed_link_params link_params;
379 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
381 "Link settings are not allowed to be changed\n");
385 if (!netif_running(dev))
388 memset(¤t_link, 0, sizeof(current_link));
389 edev->ops->common->get_link(edev->cdev, ¤t_link);
390 if (!current_link.link_up)
393 /* Toggle the link */
394 memset(&link_params, 0, sizeof(link_params));
395 link_params.link_up = false;
396 edev->ops->common->set_link(edev->cdev, &link_params);
397 link_params.link_up = true;
398 edev->ops->common->set_link(edev->cdev, &link_params);
403 static u32 qede_get_link(struct net_device *dev)
405 struct qede_dev *edev = netdev_priv(dev);
406 struct qed_link_output current_link;
408 memset(¤t_link, 0, sizeof(current_link));
409 edev->ops->common->get_link(edev->cdev, ¤t_link);
411 return current_link.link_up;
414 static void qede_get_ringparam(struct net_device *dev,
415 struct ethtool_ringparam *ering)
417 struct qede_dev *edev = netdev_priv(dev);
419 ering->rx_max_pending = NUM_RX_BDS_MAX;
420 ering->rx_pending = edev->q_num_rx_buffers;
421 ering->tx_max_pending = NUM_TX_BDS_MAX;
422 ering->tx_pending = edev->q_num_tx_buffers;
425 static int qede_set_ringparam(struct net_device *dev,
426 struct ethtool_ringparam *ering)
428 struct qede_dev *edev = netdev_priv(dev);
430 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
431 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
432 ering->rx_pending, ering->tx_pending);
434 /* Validate legality of configuration */
435 if (ering->rx_pending > NUM_RX_BDS_MAX ||
436 ering->rx_pending < NUM_RX_BDS_MIN ||
437 ering->tx_pending > NUM_TX_BDS_MAX ||
438 ering->tx_pending < NUM_TX_BDS_MIN) {
439 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
440 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
441 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
442 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
446 /* Change ring size and re-load */
447 edev->q_num_rx_buffers = ering->rx_pending;
448 edev->q_num_tx_buffers = ering->tx_pending;
450 if (netif_running(edev->ndev))
451 qede_reload(edev, NULL, NULL);
456 static void qede_get_pauseparam(struct net_device *dev,
457 struct ethtool_pauseparam *epause)
459 struct qede_dev *edev = netdev_priv(dev);
460 struct qed_link_output current_link;
462 memset(¤t_link, 0, sizeof(current_link));
463 edev->ops->common->get_link(edev->cdev, ¤t_link);
465 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
466 epause->autoneg = true;
467 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
468 epause->rx_pause = true;
469 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
470 epause->tx_pause = true;
472 DP_VERBOSE(edev, QED_MSG_DEBUG,
473 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
474 epause->cmd, epause->autoneg, epause->rx_pause,
478 static int qede_set_pauseparam(struct net_device *dev,
479 struct ethtool_pauseparam *epause)
481 struct qede_dev *edev = netdev_priv(dev);
482 struct qed_link_params params;
483 struct qed_link_output current_link;
485 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
487 "Pause settings are not allowed to be changed\n");
491 memset(¤t_link, 0, sizeof(current_link));
492 edev->ops->common->get_link(edev->cdev, ¤t_link);
494 memset(¶ms, 0, sizeof(params));
495 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
496 if (epause->autoneg) {
497 if (!(current_link.supported_caps & SUPPORTED_Autoneg)) {
498 DP_INFO(edev, "autoneg not supported\n");
501 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
503 if (epause->rx_pause)
504 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
505 if (epause->tx_pause)
506 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
508 params.link_up = true;
509 edev->ops->common->set_link(edev->cdev, ¶ms);
514 static void qede_update_mtu(struct qede_dev *edev, union qede_reload_args *args)
516 edev->ndev->mtu = args->mtu;
520 #define ETH_MAX_JUMBO_PACKET_SIZE 9600
521 #define ETH_MIN_PACKET_SIZE 60
522 int qede_change_mtu(struct net_device *ndev, int new_mtu)
524 struct qede_dev *edev = netdev_priv(ndev);
525 union qede_reload_args args;
527 if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
528 ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE)) {
529 DP_ERR(edev, "Can't support requested MTU size\n");
533 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
534 "Configuring MTU size of %d\n", new_mtu);
536 /* Set the mtu field and re-start the interface if needed*/
539 if (netif_running(edev->ndev))
540 qede_reload(edev, &qede_update_mtu, &args);
542 qede_update_mtu(edev, &args);
547 static void qede_get_channels(struct net_device *dev,
548 struct ethtool_channels *channels)
550 struct qede_dev *edev = netdev_priv(dev);
552 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
553 channels->combined_count = QEDE_RSS_CNT(edev);
556 static int qede_set_channels(struct net_device *dev,
557 struct ethtool_channels *channels)
559 struct qede_dev *edev = netdev_priv(dev);
561 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
562 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
563 channels->rx_count, channels->tx_count,
564 channels->other_count, channels->combined_count);
566 /* We don't support separate rx / tx, nor `other' channels. */
567 if (channels->rx_count || channels->tx_count ||
568 channels->other_count || (channels->combined_count == 0) ||
569 (channels->combined_count > QEDE_MAX_RSS_CNT(edev))) {
570 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
571 "command parameters not supported\n");
575 /* Check if there was a change in the active parameters */
576 if (channels->combined_count == QEDE_RSS_CNT(edev)) {
577 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
578 "No change in active parameters\n");
582 /* We need the number of queues to be divisible between the hwfns */
583 if (channels->combined_count % edev->dev_info.common.num_hwfns) {
584 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
585 "Number of channels must be divisable by %04x\n",
586 edev->dev_info.common.num_hwfns);
590 /* Set number of queues and reload if necessary */
591 edev->req_rss = channels->combined_count;
592 if (netif_running(dev))
593 qede_reload(edev, NULL, NULL);
598 static int qede_set_phys_id(struct net_device *dev,
599 enum ethtool_phys_id_state state)
601 struct qede_dev *edev = netdev_priv(dev);
605 case ETHTOOL_ID_ACTIVE:
606 return 1; /* cycle on/off once per second */
609 led_state = QED_LED_MODE_ON;
613 led_state = QED_LED_MODE_OFF;
616 case ETHTOOL_ID_INACTIVE:
617 led_state = QED_LED_MODE_RESTORE;
621 edev->ops->common->set_led(edev->cdev, led_state);
626 static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
628 info->data = RXH_IP_SRC | RXH_IP_DST;
630 switch (info->flow_type) {
633 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
636 if (edev->rss_params.rss_caps & QED_RSS_IPV4_UDP)
637 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
640 if (edev->rss_params.rss_caps & QED_RSS_IPV6_UDP)
641 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
654 static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
655 u32 *rules __always_unused)
657 struct qede_dev *edev = netdev_priv(dev);
660 case ETHTOOL_GRXRINGS:
661 info->data = edev->num_rss;
664 return qede_get_rss_flags(edev, info);
666 DP_ERR(edev, "Command parameters not supported\n");
671 static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
673 struct qed_update_vport_params vport_update_params;
674 u8 set_caps = 0, clr_caps = 0;
676 DP_VERBOSE(edev, QED_MSG_DEBUG,
677 "Set rss flags command parameters: flow type = %d, data = %llu\n",
678 info->flow_type, info->data);
680 switch (info->flow_type) {
683 /* For TCP only 4-tuple hash is supported */
684 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
685 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
686 DP_INFO(edev, "Command parameters not supported\n");
691 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
692 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
693 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
694 set_caps = QED_RSS_IPV4_UDP;
695 DP_VERBOSE(edev, QED_MSG_DEBUG,
696 "UDP 4-tuple enabled\n");
697 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
698 clr_caps = QED_RSS_IPV4_UDP;
699 DP_VERBOSE(edev, QED_MSG_DEBUG,
700 "UDP 4-tuple disabled\n");
706 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
707 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
708 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
709 set_caps = QED_RSS_IPV6_UDP;
710 DP_VERBOSE(edev, QED_MSG_DEBUG,
711 "UDP 4-tuple enabled\n");
712 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
713 clr_caps = QED_RSS_IPV6_UDP;
714 DP_VERBOSE(edev, QED_MSG_DEBUG,
715 "UDP 4-tuple disabled\n");
722 /* For IP only 2-tuple hash is supported */
723 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
724 DP_INFO(edev, "Command parameters not supported\n");
738 /* RSS is not supported for these protocols */
740 DP_INFO(edev, "Command parameters not supported\n");
748 /* No action is needed if there is no change in the rss capability */
749 if (edev->rss_params.rss_caps == ((edev->rss_params.rss_caps &
750 ~clr_caps) | set_caps))
753 /* Update internal configuration */
754 edev->rss_params.rss_caps = (edev->rss_params.rss_caps & ~clr_caps) |
756 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
758 /* Re-configure if possible */
759 if (netif_running(edev->ndev)) {
760 memset(&vport_update_params, 0, sizeof(vport_update_params));
761 vport_update_params.update_rss_flg = 1;
762 vport_update_params.vport_id = 0;
763 memcpy(&vport_update_params.rss_params, &edev->rss_params,
764 sizeof(vport_update_params.rss_params));
765 return edev->ops->vport_update(edev->cdev,
766 &vport_update_params);
772 static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
774 struct qede_dev *edev = netdev_priv(dev);
778 return qede_set_rss_flags(edev, info);
780 DP_INFO(edev, "Command parameters not supported\n");
785 static u32 qede_get_rxfh_indir_size(struct net_device *dev)
787 return QED_RSS_IND_TABLE_SIZE;
790 static u32 qede_get_rxfh_key_size(struct net_device *dev)
792 struct qede_dev *edev = netdev_priv(dev);
794 return sizeof(edev->rss_params.rss_key);
797 static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
799 struct qede_dev *edev = netdev_priv(dev);
803 *hfunc = ETH_RSS_HASH_TOP;
808 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
809 indir[i] = edev->rss_params.rss_ind_table[i];
812 memcpy(key, edev->rss_params.rss_key,
813 qede_get_rxfh_key_size(dev));
818 static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
819 const u8 *key, const u8 hfunc)
821 struct qed_update_vport_params vport_update_params;
822 struct qede_dev *edev = netdev_priv(dev);
825 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
832 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
833 edev->rss_params.rss_ind_table[i] = indir[i];
834 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
838 memcpy(&edev->rss_params.rss_key, key,
839 qede_get_rxfh_key_size(dev));
840 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
843 if (netif_running(edev->ndev)) {
844 memset(&vport_update_params, 0, sizeof(vport_update_params));
845 vport_update_params.update_rss_flg = 1;
846 vport_update_params.vport_id = 0;
847 memcpy(&vport_update_params.rss_params, &edev->rss_params,
848 sizeof(vport_update_params.rss_params));
849 return edev->ops->vport_update(edev->cdev,
850 &vport_update_params);
856 /* This function enables the interrupt generation and the NAPI on the device */
857 static void qede_netif_start(struct qede_dev *edev)
861 if (!netif_running(edev->ndev))
865 /* Update and reenable interrupts */
866 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
867 napi_enable(&edev->fp_array[i].napi);
871 /* This function disables the NAPI and the interrupt generation on the device */
872 static void qede_netif_stop(struct qede_dev *edev)
877 napi_disable(&edev->fp_array[i].napi);
878 /* Disable interrupts */
879 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
883 static int qede_selftest_transmit_traffic(struct qede_dev *edev,
886 struct qede_tx_queue *txq = &edev->fp_array[0].txqs[0];
887 struct eth_tx_1st_bd *first_bd;
891 /* Fill the entry in the SW ring and the BDs in the FW ring */
892 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
893 txq->sw_tx_ring[idx].skb = skb;
894 first_bd = qed_chain_produce(&txq->tx_pbl);
895 memset(first_bd, 0, sizeof(*first_bd));
896 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
897 first_bd->data.bd_flags.bitfields = val;
899 /* Map skb linear data for DMA and set in the first BD */
900 mapping = dma_map_single(&edev->pdev->dev, skb->data,
901 skb_headlen(skb), DMA_TO_DEVICE);
902 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
903 DP_NOTICE(edev, "SKB mapping failed\n");
906 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
908 /* update the first BD with the actual num BDs */
909 first_bd->data.nbds = 1;
911 /* 'next page' entries are counted in the producer value */
912 val = cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
913 txq->tx_db.data.bd_prod = val;
915 /* wmb makes sure that the BDs data is updated before updating the
916 * producer, otherwise FW may read old data from the BDs.
920 writel(txq->tx_db.raw, txq->doorbell_addr);
922 /* mmiowb is needed to synchronize doorbell writes from more than one
923 * processor. It guarantees that the write arrives to the device before
924 * the queue lock is released and another start_xmit is called (possibly
925 * on another CPU). Without this barrier, the next doorbell can bypass
926 * this doorbell. This is applicable to IA64/Altix systems.
930 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
931 if (qede_txq_has_work(txq))
933 usleep_range(100, 200);
936 if (!qede_txq_has_work(txq)) {
937 DP_NOTICE(edev, "Tx completion didn't happen\n");
941 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
942 dma_unmap_page(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
943 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
945 txq->sw_tx_ring[idx].skb = NULL;
950 static int qede_selftest_receive_traffic(struct qede_dev *edev)
952 struct qede_rx_queue *rxq = edev->fp_array[0].rxq;
953 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
954 struct eth_fast_path_rx_reg_cqe *fp_cqe;
955 struct sw_rx_data *sw_rx_data;
956 union eth_rx_cqe *cqe;
960 /* The packet is expected to receive on rx-queue 0 even though RSS is
961 * enabled. This is because the queue 0 is configured as the default
962 * queue and that the loopback traffic is not IP.
964 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
965 if (qede_has_rx_work(rxq))
967 usleep_range(100, 200);
970 if (!qede_has_rx_work(rxq)) {
971 DP_NOTICE(edev, "Failed to receive the traffic\n");
975 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
976 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
978 /* Memory barrier to prevent the CPU from doing speculative reads of CQE
979 * / BD before reading hw_comp_cons. If the CQE is read before it is
980 * written by FW, then FW writes CQE and SB, and then the CPU reads the
981 * hw_comp_cons, it will use an old CQE.
985 /* Get the CQE from the completion ring */
986 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
988 /* Get the data from the SW ring */
989 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
990 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
991 fp_cqe = &cqe->fast_path_regular;
992 len = le16_to_cpu(fp_cqe->len_on_first_bd);
993 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
994 fp_cqe->placement_offset + sw_rx_data->page_offset);
995 for (i = ETH_HLEN; i < len; i++)
996 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
997 DP_NOTICE(edev, "Loopback test failed\n");
998 qede_recycle_rx_bd_ring(rxq, edev, 1);
1002 qede_recycle_rx_bd_ring(rxq, edev, 1);
1007 static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1009 struct qed_link_params link_params;
1010 struct sk_buff *skb = NULL;
1015 if (!netif_running(edev->ndev)) {
1016 DP_NOTICE(edev, "Interface is down\n");
1020 qede_netif_stop(edev);
1022 /* Bring up the link in Loopback mode */
1023 memset(&link_params, 0, sizeof(link_params));
1024 link_params.link_up = true;
1025 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1026 link_params.loopback_mode = loopback_mode;
1027 edev->ops->common->set_link(edev->cdev, &link_params);
1029 /* Wait for loopback configuration to apply */
1030 msleep_interruptible(500);
1032 /* prepare the loopback packet */
1033 pkt_size = edev->ndev->mtu + ETH_HLEN;
1035 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1037 DP_INFO(edev, "Can't allocate skb\n");
1039 goto test_loopback_exit;
1041 packet = skb_put(skb, pkt_size);
1042 ether_addr_copy(packet, edev->ndev->dev_addr);
1043 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1044 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1045 for (i = ETH_HLEN; i < pkt_size; i++)
1046 packet[i] = (unsigned char)(i & 0xff);
1048 rc = qede_selftest_transmit_traffic(edev, skb);
1050 goto test_loopback_exit;
1052 rc = qede_selftest_receive_traffic(edev);
1054 goto test_loopback_exit;
1056 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1061 /* Bring up the link in Normal mode */
1062 memset(&link_params, 0, sizeof(link_params));
1063 link_params.link_up = true;
1064 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1065 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1066 edev->ops->common->set_link(edev->cdev, &link_params);
1068 /* Wait for loopback configuration to apply */
1069 msleep_interruptible(500);
1071 qede_netif_start(edev);
1076 static void qede_self_test(struct net_device *dev,
1077 struct ethtool_test *etest, u64 *buf)
1079 struct qede_dev *edev = netdev_priv(dev);
1081 DP_VERBOSE(edev, QED_MSG_DEBUG,
1082 "Self-test command parameters: offline = %d, external_lb = %d\n",
1083 (etest->flags & ETH_TEST_FL_OFFLINE),
1084 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1086 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1088 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1089 if (qede_selftest_run_loopback(edev,
1090 QED_LINK_LOOPBACK_INT_PHY)) {
1091 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1092 etest->flags |= ETH_TEST_FL_FAILED;
1096 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1097 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1098 etest->flags |= ETH_TEST_FL_FAILED;
1101 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1102 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1103 etest->flags |= ETH_TEST_FL_FAILED;
1106 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1107 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1108 etest->flags |= ETH_TEST_FL_FAILED;
1111 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1112 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1113 etest->flags |= ETH_TEST_FL_FAILED;
1117 static const struct ethtool_ops qede_ethtool_ops = {
1118 .get_settings = qede_get_settings,
1119 .set_settings = qede_set_settings,
1120 .get_drvinfo = qede_get_drvinfo,
1121 .get_msglevel = qede_get_msglevel,
1122 .set_msglevel = qede_set_msglevel,
1123 .nway_reset = qede_nway_reset,
1124 .get_link = qede_get_link,
1125 .get_ringparam = qede_get_ringparam,
1126 .set_ringparam = qede_set_ringparam,
1127 .get_pauseparam = qede_get_pauseparam,
1128 .set_pauseparam = qede_set_pauseparam,
1129 .get_strings = qede_get_strings,
1130 .set_phys_id = qede_set_phys_id,
1131 .get_ethtool_stats = qede_get_ethtool_stats,
1132 .get_priv_flags = qede_get_priv_flags,
1133 .get_sset_count = qede_get_sset_count,
1134 .get_rxnfc = qede_get_rxnfc,
1135 .set_rxnfc = qede_set_rxnfc,
1136 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1137 .get_rxfh_key_size = qede_get_rxfh_key_size,
1138 .get_rxfh = qede_get_rxfh,
1139 .set_rxfh = qede_set_rxfh,
1140 .get_channels = qede_get_channels,
1141 .set_channels = qede_set_channels,
1142 .self_test = qede_self_test,
1145 void qede_set_ethtool_ops(struct net_device *dev)
1147 dev->ethtool_ops = &qede_ethtool_ops;