1 /* * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
12 #include <rte_ethdev_driver.h>
13 #include <rte_malloc.h>
14 #include <rte_memcpy.h>
15 #include <rte_string_fns.h>
16 #include <rte_cycles.h>
17 #include <rte_kvargs.h>
19 #include <rte_fslmc.h>
20 #include <rte_flow_driver.h>
22 #include "dpaa2_pmd_logs.h"
23 #include <fslmc_vfio.h>
24 #include <dpaa2_hw_pvt.h>
25 #include <dpaa2_hw_mempool.h>
26 #include <dpaa2_hw_dpio.h>
27 #include <mc/fsl_dpmng.h>
28 #include "dpaa2_ethdev.h"
29 #include <fsl_qbman_debug.h>
31 #define DRIVER_LOOPBACK_MODE "drv_loopback"
33 /* Supported Rx offloads */
34 static uint64_t dev_rx_offloads_sup =
35 DEV_RX_OFFLOAD_CHECKSUM |
36 DEV_RX_OFFLOAD_SCTP_CKSUM |
37 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
38 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM |
39 DEV_RX_OFFLOAD_VLAN_STRIP |
40 DEV_RX_OFFLOAD_VLAN_FILTER |
41 DEV_RX_OFFLOAD_JUMBO_FRAME;
43 /* Rx offloads which cannot be disabled */
44 static uint64_t dev_rx_offloads_nodis =
45 DEV_RX_OFFLOAD_SCATTER;
47 /* Supported Tx offloads */
48 static uint64_t dev_tx_offloads_sup =
49 DEV_TX_OFFLOAD_VLAN_INSERT |
50 DEV_TX_OFFLOAD_IPV4_CKSUM |
51 DEV_TX_OFFLOAD_UDP_CKSUM |
52 DEV_TX_OFFLOAD_TCP_CKSUM |
53 DEV_TX_OFFLOAD_SCTP_CKSUM |
54 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
55 DEV_TX_OFFLOAD_MT_LOCKFREE |
56 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
58 /* Tx offloads which cannot be disabled */
59 static uint64_t dev_tx_offloads_nodis =
60 DEV_TX_OFFLOAD_MULTI_SEGS;
62 /* enable timestamp in mbuf */
63 enum pmd_dpaa2_ts dpaa2_enable_ts;
65 struct rte_dpaa2_xstats_name_off {
66 char name[RTE_ETH_XSTATS_NAME_SIZE];
67 uint8_t page_id; /* dpni statistics page id */
68 uint8_t stats_id; /* stats id in the given page */
71 static const struct rte_dpaa2_xstats_name_off dpaa2_xstats_strings[] = {
72 {"ingress_multicast_frames", 0, 2},
73 {"ingress_multicast_bytes", 0, 3},
74 {"ingress_broadcast_frames", 0, 4},
75 {"ingress_broadcast_bytes", 0, 5},
76 {"egress_multicast_frames", 1, 2},
77 {"egress_multicast_bytes", 1, 3},
78 {"egress_broadcast_frames", 1, 4},
79 {"egress_broadcast_bytes", 1, 5},
80 {"ingress_filtered_frames", 2, 0},
81 {"ingress_discarded_frames", 2, 1},
82 {"ingress_nobuffer_discards", 2, 2},
83 {"egress_discarded_frames", 2, 3},
84 {"egress_confirmed_frames", 2, 4},
87 static const enum rte_filter_op dpaa2_supported_filter_ops[] = {
89 RTE_ETH_FILTER_DELETE,
90 RTE_ETH_FILTER_UPDATE,
95 static struct rte_dpaa2_driver rte_dpaa2_pmd;
96 static int dpaa2_dev_uninit(struct rte_eth_dev *eth_dev);
97 static int dpaa2_dev_link_update(struct rte_eth_dev *dev,
98 int wait_to_complete);
99 static int dpaa2_dev_set_link_up(struct rte_eth_dev *dev);
100 static int dpaa2_dev_set_link_down(struct rte_eth_dev *dev);
101 static int dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
103 int dpaa2_logtype_pmd;
106 rte_pmd_dpaa2_set_timestamp(enum pmd_dpaa2_ts enable)
108 dpaa2_enable_ts = enable;
112 dpaa2_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
115 struct dpaa2_dev_priv *priv = dev->data->dev_private;
116 struct fsl_mc_io *dpni = priv->hw;
118 PMD_INIT_FUNC_TRACE();
121 DPAA2_PMD_ERR("dpni is NULL");
126 ret = dpni_add_vlan_id(dpni, CMD_PRI_LOW,
127 priv->token, vlan_id);
129 ret = dpni_remove_vlan_id(dpni, CMD_PRI_LOW,
130 priv->token, vlan_id);
133 DPAA2_PMD_ERR("ret = %d Unable to add/rem vlan %d hwid =%d",
134 ret, vlan_id, priv->hw_id);
140 dpaa2_vlan_offload_set(struct rte_eth_dev *dev, int mask)
142 struct dpaa2_dev_priv *priv = dev->data->dev_private;
143 struct fsl_mc_io *dpni = priv->hw;
146 PMD_INIT_FUNC_TRACE();
148 if (mask & ETH_VLAN_FILTER_MASK) {
149 /* VLAN Filter not avaialble */
150 if (!priv->max_vlan_filters) {
151 DPAA2_PMD_INFO("VLAN filter not available");
155 if (dev->data->dev_conf.rxmode.offloads &
156 DEV_RX_OFFLOAD_VLAN_FILTER)
157 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
160 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
163 DPAA2_PMD_INFO("Unable to set vlan filter = %d", ret);
166 if (mask & ETH_VLAN_EXTEND_MASK) {
167 if (dev->data->dev_conf.rxmode.offloads &
168 DEV_RX_OFFLOAD_VLAN_EXTEND)
169 DPAA2_PMD_INFO("VLAN extend offload not supported");
176 dpaa2_vlan_tpid_set(struct rte_eth_dev *dev,
177 enum rte_vlan_type vlan_type __rte_unused,
180 struct dpaa2_dev_priv *priv = dev->data->dev_private;
181 struct fsl_mc_io *dpni = priv->hw;
184 PMD_INIT_FUNC_TRACE();
186 /* nothing to be done for standard vlan tpids */
187 if (tpid == 0x8100 || tpid == 0x88A8)
190 ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
193 DPAA2_PMD_INFO("Unable to set vlan tpid = %d", ret);
194 /* if already configured tpids, remove them first */
196 struct dpni_custom_tpid_cfg tpid_list = {0};
198 ret = dpni_get_custom_tpid(dpni, CMD_PRI_LOW,
199 priv->token, &tpid_list);
202 ret = dpni_remove_custom_tpid(dpni, CMD_PRI_LOW,
203 priv->token, tpid_list.tpid1);
206 ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
214 dpaa2_fw_version_get(struct rte_eth_dev *dev,
219 struct dpaa2_dev_priv *priv = dev->data->dev_private;
220 struct fsl_mc_io *dpni = priv->hw;
221 struct mc_soc_version mc_plat_info = {0};
222 struct mc_version mc_ver_info = {0};
224 PMD_INIT_FUNC_TRACE();
226 if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
227 DPAA2_PMD_WARN("\tmc_get_soc_version failed");
229 if (mc_get_version(dpni, CMD_PRI_LOW, &mc_ver_info))
230 DPAA2_PMD_WARN("\tmc_get_version failed");
232 ret = snprintf(fw_version, fw_size,
237 mc_ver_info.revision);
239 ret += 1; /* add the size of '\0' */
240 if (fw_size < (uint32_t)ret)
247 dpaa2_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
249 struct dpaa2_dev_priv *priv = dev->data->dev_private;
251 PMD_INIT_FUNC_TRACE();
253 dev_info->if_index = priv->hw_id;
255 dev_info->max_mac_addrs = priv->max_mac_filters;
256 dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
257 dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
258 dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
259 dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
260 dev_info->rx_offload_capa = dev_rx_offloads_sup |
261 dev_rx_offloads_nodis;
262 dev_info->tx_offload_capa = dev_tx_offloads_sup |
263 dev_tx_offloads_nodis;
264 dev_info->speed_capa = ETH_LINK_SPEED_1G |
265 ETH_LINK_SPEED_2_5G |
268 dev_info->max_hash_mac_addrs = 0;
269 dev_info->max_vfs = 0;
270 dev_info->max_vmdq_pools = ETH_16_POOLS;
271 dev_info->flow_type_rss_offloads = DPAA2_RSS_OFFLOAD_ALL;
277 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
279 struct dpaa2_dev_priv *priv = dev->data->dev_private;
282 uint8_t num_rxqueue_per_tc;
283 struct dpaa2_queue *mc_q, *mcq;
286 struct dpaa2_queue *dpaa2_q;
288 PMD_INIT_FUNC_TRACE();
290 num_rxqueue_per_tc = (priv->nb_rx_queues / priv->num_rx_tc);
291 tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
292 mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
293 RTE_CACHE_LINE_SIZE);
295 DPAA2_PMD_ERR("Memory allocation failed for rx/tx queues");
299 for (i = 0; i < priv->nb_rx_queues; i++) {
300 mc_q->eth_data = dev->data;
301 priv->rx_vq[i] = mc_q++;
302 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
303 dpaa2_q->q_storage = rte_malloc("dq_storage",
304 sizeof(struct queue_storage_info_t),
305 RTE_CACHE_LINE_SIZE);
306 if (!dpaa2_q->q_storage)
309 memset(dpaa2_q->q_storage, 0,
310 sizeof(struct queue_storage_info_t));
311 if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
315 for (i = 0; i < priv->nb_tx_queues; i++) {
316 mc_q->eth_data = dev->data;
317 mc_q->flow_id = 0xffff;
318 priv->tx_vq[i] = mc_q++;
319 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
320 dpaa2_q->cscn = rte_malloc(NULL,
321 sizeof(struct qbman_result), 16);
327 for (dist_idx = 0; dist_idx < priv->nb_rx_queues; dist_idx++) {
328 mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
329 mcq->tc_index = dist_idx / num_rxqueue_per_tc;
330 mcq->flow_id = dist_idx % num_rxqueue_per_tc;
338 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
339 rte_free(dpaa2_q->cscn);
340 priv->tx_vq[i--] = NULL;
342 i = priv->nb_rx_queues;
345 mc_q = priv->rx_vq[0];
347 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
348 dpaa2_free_dq_storage(dpaa2_q->q_storage);
349 rte_free(dpaa2_q->q_storage);
350 priv->rx_vq[i--] = NULL;
357 dpaa2_free_rx_tx_queues(struct rte_eth_dev *dev)
359 struct dpaa2_dev_priv *priv = dev->data->dev_private;
360 struct dpaa2_queue *dpaa2_q;
363 PMD_INIT_FUNC_TRACE();
365 /* Queue allocation base */
366 if (priv->rx_vq[0]) {
367 /* cleaning up queue storage */
368 for (i = 0; i < priv->nb_rx_queues; i++) {
369 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
370 if (dpaa2_q->q_storage)
371 rte_free(dpaa2_q->q_storage);
373 /* cleanup tx queue cscn */
374 for (i = 0; i < priv->nb_tx_queues; i++) {
375 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
376 rte_free(dpaa2_q->cscn);
378 /*free memory for all queues (RX+TX) */
379 rte_free(priv->rx_vq[0]);
380 priv->rx_vq[0] = NULL;
385 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
387 struct dpaa2_dev_priv *priv = dev->data->dev_private;
388 struct fsl_mc_io *dpni = priv->hw;
389 struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
390 uint64_t rx_offloads = eth_conf->rxmode.offloads;
391 uint64_t tx_offloads = eth_conf->txmode.offloads;
392 int rx_l3_csum_offload = false;
393 int rx_l4_csum_offload = false;
394 int tx_l3_csum_offload = false;
395 int tx_l4_csum_offload = false;
398 PMD_INIT_FUNC_TRACE();
400 /* Rx offloads which are enabled by default */
401 if (dev_rx_offloads_nodis & ~rx_offloads) {
403 "Some of rx offloads enabled by default - requested 0x%" PRIx64
404 " fixed are 0x%" PRIx64,
405 rx_offloads, dev_rx_offloads_nodis);
408 /* Tx offloads which are enabled by default */
409 if (dev_tx_offloads_nodis & ~tx_offloads) {
411 "Some of tx offloads enabled by default - requested 0x%" PRIx64
412 " fixed are 0x%" PRIx64,
413 tx_offloads, dev_tx_offloads_nodis);
416 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
417 if (eth_conf->rxmode.max_rx_pkt_len <= DPAA2_MAX_RX_PKT_LEN) {
418 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW,
419 priv->token, eth_conf->rxmode.max_rx_pkt_len);
422 "Unable to set mtu. check config");
430 if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
431 ret = dpaa2_setup_flow_dist(dev,
432 eth_conf->rx_adv_conf.rss_conf.rss_hf);
434 DPAA2_PMD_ERR("Unable to set flow distribution."
435 "Check queue config");
440 if (rx_offloads & DEV_RX_OFFLOAD_IPV4_CKSUM)
441 rx_l3_csum_offload = true;
443 if ((rx_offloads & DEV_RX_OFFLOAD_UDP_CKSUM) ||
444 (rx_offloads & DEV_RX_OFFLOAD_TCP_CKSUM) ||
445 (rx_offloads & DEV_RX_OFFLOAD_SCTP_CKSUM))
446 rx_l4_csum_offload = true;
448 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
449 DPNI_OFF_RX_L3_CSUM, rx_l3_csum_offload);
451 DPAA2_PMD_ERR("Error to set RX l3 csum:Error = %d", ret);
455 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
456 DPNI_OFF_RX_L4_CSUM, rx_l4_csum_offload);
458 DPAA2_PMD_ERR("Error to get RX l4 csum:Error = %d", ret);
462 if (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM)
463 tx_l3_csum_offload = true;
465 if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ||
466 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ||
467 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
468 tx_l4_csum_offload = true;
470 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
471 DPNI_OFF_TX_L3_CSUM, tx_l3_csum_offload);
473 DPAA2_PMD_ERR("Error to set TX l3 csum:Error = %d", ret);
477 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
478 DPNI_OFF_TX_L4_CSUM, tx_l4_csum_offload);
480 DPAA2_PMD_ERR("Error to get TX l4 csum:Error = %d", ret);
484 /* Enabling hash results in FD requires setting DPNI_FLCTYPE_HASH in
485 * dpni_set_offload API. Setting this FLCTYPE for DPNI sets the FD[SC]
486 * to 0 for LS2 in the hardware thus disabling data/annotation
487 * stashing. For LX2 this is fixed in hardware and thus hash result and
488 * parse results can be received in FD using this option.
490 if (dpaa2_svr_family == SVR_LX2160A) {
491 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
492 DPNI_FLCTYPE_HASH, true);
494 DPAA2_PMD_ERR("Error setting FLCTYPE: Err = %d", ret);
499 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
500 dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
502 /* update the current status */
503 dpaa2_dev_link_update(dev, 0);
508 /* Function to setup RX flow information. It contains traffic class ID,
509 * flow ID, destination configuration etc.
512 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
513 uint16_t rx_queue_id,
514 uint16_t nb_rx_desc __rte_unused,
515 unsigned int socket_id __rte_unused,
516 const struct rte_eth_rxconf *rx_conf __rte_unused,
517 struct rte_mempool *mb_pool)
519 struct dpaa2_dev_priv *priv = dev->data->dev_private;
520 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
521 struct dpaa2_queue *dpaa2_q;
522 struct dpni_queue cfg;
528 PMD_INIT_FUNC_TRACE();
530 DPAA2_PMD_DEBUG("dev =%p, queue =%d, pool = %p, conf =%p",
531 dev, rx_queue_id, mb_pool, rx_conf);
533 if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
534 bpid = mempool_to_bpid(mb_pool);
535 ret = dpaa2_attach_bp_list(priv,
536 rte_dpaa2_bpid_info[bpid].bp_list);
540 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
541 dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
542 dpaa2_q->bp_array = rte_dpaa2_bpid_info;
544 /*Get the flow id from given VQ id*/
545 flow_id = rx_queue_id % priv->nb_rx_queues;
546 memset(&cfg, 0, sizeof(struct dpni_queue));
548 options = options | DPNI_QUEUE_OPT_USER_CTX;
549 cfg.user_context = (size_t)(dpaa2_q);
551 /*if ls2088 or rev2 device, enable the stashing */
553 if ((dpaa2_svr_family & 0xffff0000) != SVR_LS2080A) {
554 options |= DPNI_QUEUE_OPT_FLC;
555 cfg.flc.stash_control = true;
556 cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
557 /* 00 00 00 - last 6 bit represent annotation, context stashing,
558 * data stashing setting 01 01 00 (0x14)
559 * (in following order ->DS AS CS)
560 * to enable 1 line data, 1 line annotation.
561 * For LX2, this setting should be 01 00 00 (0x10)
563 if ((dpaa2_svr_family & 0xffff0000) == SVR_LX2160A)
564 cfg.flc.value |= 0x10;
566 cfg.flc.value |= 0x14;
568 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
569 dpaa2_q->tc_index, flow_id, options, &cfg);
571 DPAA2_PMD_ERR("Error in setting the rx flow: = %d", ret);
575 if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
576 struct dpni_taildrop taildrop;
579 /*enabling per rx queue congestion control */
580 taildrop.threshold = CONG_THRESHOLD_RX_Q;
581 taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
582 taildrop.oal = CONG_RX_OAL;
583 DPAA2_PMD_DEBUG("Enabling Early Drop on queue = %d",
585 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
586 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
587 dpaa2_q->tc_index, flow_id, &taildrop);
589 DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
595 dev->data->rx_queues[rx_queue_id] = dpaa2_q;
600 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
601 uint16_t tx_queue_id,
602 uint16_t nb_tx_desc __rte_unused,
603 unsigned int socket_id __rte_unused,
604 const struct rte_eth_txconf *tx_conf __rte_unused)
606 struct dpaa2_dev_priv *priv = dev->data->dev_private;
607 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
608 priv->tx_vq[tx_queue_id];
609 struct fsl_mc_io *dpni = priv->hw;
610 struct dpni_queue tx_conf_cfg;
611 struct dpni_queue tx_flow_cfg;
612 uint8_t options = 0, flow_id;
616 PMD_INIT_FUNC_TRACE();
618 /* Return if queue already configured */
619 if (dpaa2_q->flow_id != 0xffff) {
620 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
624 memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
625 memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
630 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
631 tc_id, flow_id, options, &tx_flow_cfg);
633 DPAA2_PMD_ERR("Error in setting the tx flow: "
634 "tc_id=%d, flow=%d err=%d",
635 tc_id, flow_id, ret);
639 dpaa2_q->flow_id = flow_id;
641 if (tx_queue_id == 0) {
642 /*Set tx-conf and error configuration*/
643 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
647 DPAA2_PMD_ERR("Error in set tx conf mode settings: "
652 dpaa2_q->tc_index = tc_id;
654 if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
655 struct dpni_congestion_notification_cfg cong_notif_cfg;
657 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
658 cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
659 /* Notify that the queue is not congested when the data in
660 * the queue is below this thershold.
662 cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
663 cong_notif_cfg.message_ctx = 0;
664 cong_notif_cfg.message_iova =
665 (size_t)DPAA2_VADDR_TO_IOVA(dpaa2_q->cscn);
666 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
667 cong_notif_cfg.notification_mode =
668 DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
669 DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
670 DPNI_CONG_OPT_COHERENT_WRITE;
671 cong_notif_cfg.cg_point = DPNI_CP_QUEUE;
673 ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
680 "Error in setting tx congestion notification: "
685 dpaa2_q->cb_eqresp_free = dpaa2_dev_free_eqresp_buf;
686 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
691 dpaa2_dev_rx_queue_release(void *q __rte_unused)
693 PMD_INIT_FUNC_TRACE();
697 dpaa2_dev_tx_queue_release(void *q __rte_unused)
699 PMD_INIT_FUNC_TRACE();
703 dpaa2_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
706 struct dpaa2_dev_priv *priv = dev->data->dev_private;
707 struct dpaa2_queue *dpaa2_q;
708 struct qbman_swp *swp;
709 struct qbman_fq_query_np_rslt state;
710 uint32_t frame_cnt = 0;
712 PMD_INIT_FUNC_TRACE();
714 if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
715 ret = dpaa2_affine_qbman_swp();
717 DPAA2_PMD_ERR("Failure in affining portal");
721 swp = DPAA2_PER_LCORE_PORTAL;
723 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
725 if (qbman_fq_query_state(swp, dpaa2_q->fqid, &state) == 0) {
726 frame_cnt = qbman_fq_state_frame_count(&state);
727 DPAA2_PMD_DEBUG("RX frame count for q(%d) is %u",
728 rx_queue_id, frame_cnt);
733 static const uint32_t *
734 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
736 static const uint32_t ptypes[] = {
737 /*todo -= add more types */
740 RTE_PTYPE_L3_IPV4_EXT,
742 RTE_PTYPE_L3_IPV6_EXT,
750 if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx ||
751 dev->rx_pkt_burst == dpaa2_dev_loopback_rx)
757 * Dpaa2 link Interrupt handler
760 * The address of parameter (struct rte_eth_dev *) regsitered before.
766 dpaa2_interrupt_handler(void *param)
768 struct rte_eth_dev *dev = param;
769 struct dpaa2_dev_priv *priv = dev->data->dev_private;
770 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
772 int irq_index = DPNI_IRQ_INDEX;
773 unsigned int status = 0, clear = 0;
775 PMD_INIT_FUNC_TRACE();
778 DPAA2_PMD_ERR("dpni is NULL");
782 ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
785 DPAA2_PMD_ERR("Can't get irq status (err %d)", ret);
790 if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
791 clear = DPNI_IRQ_EVENT_LINK_CHANGED;
792 dpaa2_dev_link_update(dev, 0);
793 /* calling all the apps registered for link status event */
794 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
798 ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
801 DPAA2_PMD_ERR("Can't clear irq status (err %d)", ret);
805 dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
808 struct dpaa2_dev_priv *priv = dev->data->dev_private;
809 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
810 int irq_index = DPNI_IRQ_INDEX;
811 unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
813 PMD_INIT_FUNC_TRACE();
815 err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
818 DPAA2_PMD_ERR("Error: dpni_set_irq_mask():%d (%s)", err,
823 err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
826 DPAA2_PMD_ERR("Error: dpni_set_irq_enable():%d (%s)", err,
833 dpaa2_dev_start(struct rte_eth_dev *dev)
835 struct rte_device *rdev = dev->device;
836 struct rte_dpaa2_device *dpaa2_dev;
837 struct rte_eth_dev_data *data = dev->data;
838 struct dpaa2_dev_priv *priv = data->dev_private;
839 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
840 struct dpni_queue cfg;
841 struct dpni_error_cfg err_cfg;
843 struct dpni_queue_id qid;
844 struct dpaa2_queue *dpaa2_q;
846 struct rte_intr_handle *intr_handle;
848 dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
849 intr_handle = &dpaa2_dev->intr_handle;
851 PMD_INIT_FUNC_TRACE();
853 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
855 DPAA2_PMD_ERR("Failure in enabling dpni %d device: err=%d",
860 /* Power up the phy. Needed to make the link go UP */
861 dpaa2_dev_set_link_up(dev);
863 ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
864 DPNI_QUEUE_TX, &qdid);
866 DPAA2_PMD_ERR("Error in getting qdid: err=%d", ret);
871 for (i = 0; i < data->nb_rx_queues; i++) {
872 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
873 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
874 DPNI_QUEUE_RX, dpaa2_q->tc_index,
875 dpaa2_q->flow_id, &cfg, &qid);
877 DPAA2_PMD_ERR("Error in getting flow information: "
881 dpaa2_q->fqid = qid.fqid;
884 /*checksum errors, send them to normal path and set it in annotation */
885 err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
886 err_cfg.errors |= DPNI_ERROR_PHE;
888 err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
889 err_cfg.set_frame_annotation = true;
891 ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
892 priv->token, &err_cfg);
894 DPAA2_PMD_ERR("Error to dpni_set_errors_behavior: code = %d",
899 /* if the interrupts were configured on this devices*/
900 if (intr_handle && (intr_handle->fd) &&
901 (dev->data->dev_conf.intr_conf.lsc != 0)) {
902 /* Registering LSC interrupt handler */
903 rte_intr_callback_register(intr_handle,
904 dpaa2_interrupt_handler,
907 /* enable vfio intr/eventfd mapping
908 * Interrupt index 0 is required, so we can not use
911 rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
913 /* enable dpni_irqs */
914 dpaa2_eth_setup_irqs(dev, 1);
917 /* Change the tx burst function if ordered queues are used */
918 if (priv->en_ordered)
919 dev->tx_pkt_burst = dpaa2_dev_tx_ordered;
925 * This routine disables all traffic on the adapter by issuing a
926 * global reset on the MAC.
929 dpaa2_dev_stop(struct rte_eth_dev *dev)
931 struct dpaa2_dev_priv *priv = dev->data->dev_private;
932 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
934 struct rte_eth_link link;
935 struct rte_intr_handle *intr_handle = dev->intr_handle;
937 PMD_INIT_FUNC_TRACE();
939 /* reset interrupt callback */
940 if (intr_handle && (intr_handle->fd) &&
941 (dev->data->dev_conf.intr_conf.lsc != 0)) {
942 /*disable dpni irqs */
943 dpaa2_eth_setup_irqs(dev, 0);
945 /* disable vfio intr before callback unregister */
946 rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
948 /* Unregistering LSC interrupt handler */
949 rte_intr_callback_unregister(intr_handle,
950 dpaa2_interrupt_handler,
954 dpaa2_dev_set_link_down(dev);
956 ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
958 DPAA2_PMD_ERR("Failure (ret %d) in disabling dpni %d dev",
963 /* clear the recorded link status */
964 memset(&link, 0, sizeof(link));
965 rte_eth_linkstatus_set(dev, &link);
969 dpaa2_dev_close(struct rte_eth_dev *dev)
971 struct dpaa2_dev_priv *priv = dev->data->dev_private;
972 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
974 struct rte_eth_link link;
976 PMD_INIT_FUNC_TRACE();
978 dpaa2_flow_clean(dev);
980 /* Clean the device first */
981 ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
983 DPAA2_PMD_ERR("Failure cleaning dpni device: err=%d", ret);
987 memset(&link, 0, sizeof(link));
988 rte_eth_linkstatus_set(dev, &link);
992 dpaa2_dev_promiscuous_enable(
993 struct rte_eth_dev *dev)
996 struct dpaa2_dev_priv *priv = dev->data->dev_private;
997 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
999 PMD_INIT_FUNC_TRACE();
1002 DPAA2_PMD_ERR("dpni is NULL");
1006 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1008 DPAA2_PMD_ERR("Unable to enable U promisc mode %d", ret);
1010 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1012 DPAA2_PMD_ERR("Unable to enable M promisc mode %d", ret);
1018 dpaa2_dev_promiscuous_disable(
1019 struct rte_eth_dev *dev)
1022 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1023 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1025 PMD_INIT_FUNC_TRACE();
1028 DPAA2_PMD_ERR("dpni is NULL");
1032 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1034 DPAA2_PMD_ERR("Unable to disable U promisc mode %d", ret);
1036 if (dev->data->all_multicast == 0) {
1037 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
1038 priv->token, false);
1040 DPAA2_PMD_ERR("Unable to disable M promisc mode %d",
1048 dpaa2_dev_allmulticast_enable(
1049 struct rte_eth_dev *dev)
1052 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1053 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1055 PMD_INIT_FUNC_TRACE();
1058 DPAA2_PMD_ERR("dpni is NULL");
1062 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1064 DPAA2_PMD_ERR("Unable to enable multicast mode %d", ret);
1070 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
1073 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1074 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1076 PMD_INIT_FUNC_TRACE();
1079 DPAA2_PMD_ERR("dpni is NULL");
1083 /* must remain on for all promiscuous */
1084 if (dev->data->promiscuous == 1)
1087 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1089 DPAA2_PMD_ERR("Unable to disable multicast mode %d", ret);
1095 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1098 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1099 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1100 uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN
1103 PMD_INIT_FUNC_TRACE();
1106 DPAA2_PMD_ERR("dpni is NULL");
1110 /* check that mtu is within the allowed range */
1111 if (mtu < RTE_ETHER_MIN_MTU || frame_size > DPAA2_MAX_RX_PKT_LEN)
1114 if (frame_size > RTE_ETHER_MAX_LEN)
1115 dev->data->dev_conf.rxmode.offloads &=
1116 DEV_RX_OFFLOAD_JUMBO_FRAME;
1118 dev->data->dev_conf.rxmode.offloads &=
1119 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1121 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1123 /* Set the Max Rx frame length as 'mtu' +
1124 * Maximum Ethernet header length
1126 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
1129 DPAA2_PMD_ERR("Setting the max frame length failed");
1132 DPAA2_PMD_INFO("MTU configured for the device: %d", mtu);
1137 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
1138 struct rte_ether_addr *addr,
1139 __rte_unused uint32_t index,
1140 __rte_unused uint32_t pool)
1143 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1144 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1146 PMD_INIT_FUNC_TRACE();
1149 DPAA2_PMD_ERR("dpni is NULL");
1153 ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
1154 priv->token, addr->addr_bytes);
1157 "error: Adding the MAC ADDR failed: err = %d", ret);
1162 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
1166 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1167 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1168 struct rte_eth_dev_data *data = dev->data;
1169 struct rte_ether_addr *macaddr;
1171 PMD_INIT_FUNC_TRACE();
1173 macaddr = &data->mac_addrs[index];
1176 DPAA2_PMD_ERR("dpni is NULL");
1180 ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
1181 priv->token, macaddr->addr_bytes);
1184 "error: Removing the MAC ADDR failed: err = %d", ret);
1188 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
1189 struct rte_ether_addr *addr)
1192 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1193 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1195 PMD_INIT_FUNC_TRACE();
1198 DPAA2_PMD_ERR("dpni is NULL");
1202 ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
1203 priv->token, addr->addr_bytes);
1207 "error: Setting the MAC ADDR failed %d", ret);
1213 int dpaa2_dev_stats_get(struct rte_eth_dev *dev,
1214 struct rte_eth_stats *stats)
1216 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1217 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1219 uint8_t page0 = 0, page1 = 1, page2 = 2;
1220 union dpni_statistics value;
1222 struct dpaa2_queue *dpaa2_rxq, *dpaa2_txq;
1224 memset(&value, 0, sizeof(union dpni_statistics));
1226 PMD_INIT_FUNC_TRACE();
1229 DPAA2_PMD_ERR("dpni is NULL");
1234 DPAA2_PMD_ERR("stats is NULL");
1238 /*Get Counters from page_0*/
1239 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1244 stats->ipackets = value.page_0.ingress_all_frames;
1245 stats->ibytes = value.page_0.ingress_all_bytes;
1247 /*Get Counters from page_1*/
1248 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1253 stats->opackets = value.page_1.egress_all_frames;
1254 stats->obytes = value.page_1.egress_all_bytes;
1256 /*Get Counters from page_2*/
1257 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1262 /* Ingress drop frame count due to configured rules */
1263 stats->ierrors = value.page_2.ingress_filtered_frames;
1264 /* Ingress drop frame count due to error */
1265 stats->ierrors += value.page_2.ingress_discarded_frames;
1267 stats->oerrors = value.page_2.egress_discarded_frames;
1268 stats->imissed = value.page_2.ingress_nobuffer_discards;
1270 /* Fill in per queue stats */
1271 for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
1272 (i < priv->nb_rx_queues || i < priv->nb_tx_queues); ++i) {
1273 dpaa2_rxq = (struct dpaa2_queue *)priv->rx_vq[i];
1274 dpaa2_txq = (struct dpaa2_queue *)priv->tx_vq[i];
1276 stats->q_ipackets[i] = dpaa2_rxq->rx_pkts;
1278 stats->q_opackets[i] = dpaa2_txq->tx_pkts;
1280 /* Byte counting is not implemented */
1281 stats->q_ibytes[i] = 0;
1282 stats->q_obytes[i] = 0;
1288 DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1293 dpaa2_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1296 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1297 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1299 union dpni_statistics value[3] = {};
1300 unsigned int i = 0, num = RTE_DIM(dpaa2_xstats_strings);
1308 /* Get Counters from page_0*/
1309 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1314 /* Get Counters from page_1*/
1315 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1320 /* Get Counters from page_2*/
1321 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1326 for (i = 0; i < num; i++) {
1328 xstats[i].value = value[dpaa2_xstats_strings[i].page_id].
1329 raw.counter[dpaa2_xstats_strings[i].stats_id];
1333 DPAA2_PMD_ERR("Error in obtaining extended stats (%d)", retcode);
1338 dpaa2_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1339 struct rte_eth_xstat_name *xstats_names,
1342 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1344 if (limit < stat_cnt)
1347 if (xstats_names != NULL)
1348 for (i = 0; i < stat_cnt; i++)
1349 strlcpy(xstats_names[i].name,
1350 dpaa2_xstats_strings[i].name,
1351 sizeof(xstats_names[i].name));
1357 dpaa2_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1358 uint64_t *values, unsigned int n)
1360 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1361 uint64_t values_copy[stat_cnt];
1364 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1365 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1367 union dpni_statistics value[3] = {};
1375 /* Get Counters from page_0*/
1376 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1381 /* Get Counters from page_1*/
1382 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1387 /* Get Counters from page_2*/
1388 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1393 for (i = 0; i < stat_cnt; i++) {
1394 values[i] = value[dpaa2_xstats_strings[i].page_id].
1395 raw.counter[dpaa2_xstats_strings[i].stats_id];
1400 dpaa2_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
1402 for (i = 0; i < n; i++) {
1403 if (ids[i] >= stat_cnt) {
1404 DPAA2_PMD_ERR("xstats id value isn't valid");
1407 values[i] = values_copy[ids[i]];
1413 dpaa2_xstats_get_names_by_id(
1414 struct rte_eth_dev *dev,
1415 struct rte_eth_xstat_name *xstats_names,
1416 const uint64_t *ids,
1419 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1420 struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
1423 return dpaa2_xstats_get_names(dev, xstats_names, limit);
1425 dpaa2_xstats_get_names(dev, xstats_names_copy, limit);
1427 for (i = 0; i < limit; i++) {
1428 if (ids[i] >= stat_cnt) {
1429 DPAA2_PMD_ERR("xstats id value isn't valid");
1432 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
1438 dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
1440 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1441 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1444 struct dpaa2_queue *dpaa2_q;
1446 PMD_INIT_FUNC_TRACE();
1449 DPAA2_PMD_ERR("dpni is NULL");
1453 retcode = dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
1457 /* Reset the per queue stats in dpaa2_queue structure */
1458 for (i = 0; i < priv->nb_rx_queues; i++) {
1459 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
1461 dpaa2_q->rx_pkts = 0;
1464 for (i = 0; i < priv->nb_tx_queues; i++) {
1465 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
1467 dpaa2_q->tx_pkts = 0;
1473 DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1477 /* return 0 means link status changed, -1 means not changed */
1479 dpaa2_dev_link_update(struct rte_eth_dev *dev,
1480 int wait_to_complete __rte_unused)
1483 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1484 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1485 struct rte_eth_link link;
1486 struct dpni_link_state state = {0};
1489 DPAA2_PMD_ERR("dpni is NULL");
1493 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1495 DPAA2_PMD_DEBUG("error: dpni_get_link_state %d", ret);
1499 memset(&link, 0, sizeof(struct rte_eth_link));
1500 link.link_status = state.up;
1501 link.link_speed = state.rate;
1503 if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1504 link.link_duplex = ETH_LINK_HALF_DUPLEX;
1506 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1508 ret = rte_eth_linkstatus_set(dev, &link);
1510 DPAA2_PMD_DEBUG("No change in status");
1512 DPAA2_PMD_INFO("Port %d Link is %s\n", dev->data->port_id,
1513 link.link_status ? "Up" : "Down");
1519 * Toggle the DPNI to enable, if not already enabled.
1520 * This is not strictly PHY up/down - it is more of logical toggling.
1523 dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
1526 struct dpaa2_dev_priv *priv;
1527 struct fsl_mc_io *dpni;
1529 struct dpni_link_state state = {0};
1531 priv = dev->data->dev_private;
1532 dpni = (struct fsl_mc_io *)priv->hw;
1535 DPAA2_PMD_ERR("dpni is NULL");
1539 /* Check if DPNI is currently enabled */
1540 ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
1542 /* Unable to obtain dpni status; Not continuing */
1543 DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1547 /* Enable link if not already enabled */
1549 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1551 DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1555 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1557 DPAA2_PMD_DEBUG("Unable to get link state (%d)", ret);
1561 /* changing tx burst function to start enqueues */
1562 dev->tx_pkt_burst = dpaa2_dev_tx;
1563 dev->data->dev_link.link_status = state.up;
1566 DPAA2_PMD_INFO("Port %d Link is Up", dev->data->port_id);
1568 DPAA2_PMD_INFO("Port %d Link is Down", dev->data->port_id);
1573 * Toggle the DPNI to disable, if not already disabled.
1574 * This is not strictly PHY up/down - it is more of logical toggling.
1577 dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
1580 struct dpaa2_dev_priv *priv;
1581 struct fsl_mc_io *dpni;
1582 int dpni_enabled = 0;
1585 PMD_INIT_FUNC_TRACE();
1587 priv = dev->data->dev_private;
1588 dpni = (struct fsl_mc_io *)priv->hw;
1591 DPAA2_PMD_ERR("Device has not yet been configured");
1595 /*changing tx burst function to avoid any more enqueues */
1596 dev->tx_pkt_burst = dummy_dev_tx;
1598 /* Loop while dpni_disable() attempts to drain the egress FQs
1599 * and confirm them back to us.
1602 ret = dpni_disable(dpni, 0, priv->token);
1604 DPAA2_PMD_ERR("dpni disable failed (%d)", ret);
1607 ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
1609 DPAA2_PMD_ERR("dpni enable check failed (%d)", ret);
1613 /* Allow the MC some slack */
1614 rte_delay_us(100 * 1000);
1615 } while (dpni_enabled && --retries);
1618 DPAA2_PMD_WARN("Retry count exceeded disabling dpni");
1619 /* todo- we may have to manually cleanup queues.
1622 DPAA2_PMD_INFO("Port %d Link DOWN successful",
1623 dev->data->port_id);
1626 dev->data->dev_link.link_status = 0;
1632 dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1635 struct dpaa2_dev_priv *priv;
1636 struct fsl_mc_io *dpni;
1637 struct dpni_link_state state = {0};
1639 PMD_INIT_FUNC_TRACE();
1641 priv = dev->data->dev_private;
1642 dpni = (struct fsl_mc_io *)priv->hw;
1644 if (dpni == NULL || fc_conf == NULL) {
1645 DPAA2_PMD_ERR("device not configured");
1649 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1651 DPAA2_PMD_ERR("error: dpni_get_link_state %d", ret);
1655 memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
1656 if (state.options & DPNI_LINK_OPT_PAUSE) {
1657 /* DPNI_LINK_OPT_PAUSE set
1658 * if ASYM_PAUSE not set,
1659 * RX Side flow control (handle received Pause frame)
1660 * TX side flow control (send Pause frame)
1661 * if ASYM_PAUSE set,
1662 * RX Side flow control (handle received Pause frame)
1663 * No TX side flow control (send Pause frame disabled)
1665 if (!(state.options & DPNI_LINK_OPT_ASYM_PAUSE))
1666 fc_conf->mode = RTE_FC_FULL;
1668 fc_conf->mode = RTE_FC_RX_PAUSE;
1670 /* DPNI_LINK_OPT_PAUSE not set
1671 * if ASYM_PAUSE set,
1672 * TX side flow control (send Pause frame)
1673 * No RX side flow control (No action on pause frame rx)
1674 * if ASYM_PAUSE not set,
1675 * Flow control disabled
1677 if (state.options & DPNI_LINK_OPT_ASYM_PAUSE)
1678 fc_conf->mode = RTE_FC_TX_PAUSE;
1680 fc_conf->mode = RTE_FC_NONE;
1687 dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1690 struct dpaa2_dev_priv *priv;
1691 struct fsl_mc_io *dpni;
1692 struct dpni_link_state state = {0};
1693 struct dpni_link_cfg cfg = {0};
1695 PMD_INIT_FUNC_TRACE();
1697 priv = dev->data->dev_private;
1698 dpni = (struct fsl_mc_io *)priv->hw;
1701 DPAA2_PMD_ERR("dpni is NULL");
1705 /* It is necessary to obtain the current state before setting fc_conf
1706 * as MC would return error in case rate, autoneg or duplex values are
1709 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1711 DPAA2_PMD_ERR("Unable to get link state (err=%d)", ret);
1715 /* Disable link before setting configuration */
1716 dpaa2_dev_set_link_down(dev);
1718 /* Based on fc_conf, update cfg */
1719 cfg.rate = state.rate;
1720 cfg.options = state.options;
1722 /* update cfg with fc_conf */
1723 switch (fc_conf->mode) {
1725 /* Full flow control;
1726 * OPT_PAUSE set, ASYM_PAUSE not set
1728 cfg.options |= DPNI_LINK_OPT_PAUSE;
1729 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1731 case RTE_FC_TX_PAUSE:
1732 /* Enable RX flow control
1733 * OPT_PAUSE not set;
1736 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1737 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1739 case RTE_FC_RX_PAUSE:
1740 /* Enable TX Flow control
1744 cfg.options |= DPNI_LINK_OPT_PAUSE;
1745 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1748 /* Disable Flow control
1750 * ASYM_PAUSE not set
1752 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1753 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1756 DPAA2_PMD_ERR("Incorrect Flow control flag (%d)",
1761 ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
1763 DPAA2_PMD_ERR("Unable to set Link configuration (err=%d)",
1767 dpaa2_dev_set_link_up(dev);
1773 dpaa2_dev_rss_hash_update(struct rte_eth_dev *dev,
1774 struct rte_eth_rss_conf *rss_conf)
1776 struct rte_eth_dev_data *data = dev->data;
1777 struct rte_eth_conf *eth_conf = &data->dev_conf;
1780 PMD_INIT_FUNC_TRACE();
1782 if (rss_conf->rss_hf) {
1783 ret = dpaa2_setup_flow_dist(dev, rss_conf->rss_hf);
1785 DPAA2_PMD_ERR("Unable to set flow dist");
1789 ret = dpaa2_remove_flow_dist(dev, 0);
1791 DPAA2_PMD_ERR("Unable to remove flow dist");
1795 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
1800 dpaa2_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1801 struct rte_eth_rss_conf *rss_conf)
1803 struct rte_eth_dev_data *data = dev->data;
1804 struct rte_eth_conf *eth_conf = &data->dev_conf;
1806 /* dpaa2 does not support rss_key, so length should be 0*/
1807 rss_conf->rss_key_len = 0;
1808 rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
1812 int dpaa2_eth_eventq_attach(const struct rte_eth_dev *dev,
1813 int eth_rx_queue_id,
1815 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
1817 struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1818 struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1819 struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1820 uint8_t flow_id = dpaa2_ethq->flow_id;
1821 struct dpni_queue cfg;
1825 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
1826 dpaa2_ethq->cb = dpaa2_dev_process_parallel_event;
1827 else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC)
1828 dpaa2_ethq->cb = dpaa2_dev_process_atomic_event;
1829 else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED)
1830 dpaa2_ethq->cb = dpaa2_dev_process_ordered_event;
1834 memset(&cfg, 0, sizeof(struct dpni_queue));
1835 options = DPNI_QUEUE_OPT_DEST;
1836 cfg.destination.type = DPNI_DEST_DPCON;
1837 cfg.destination.id = dpcon_id;
1838 cfg.destination.priority = queue_conf->ev.priority;
1840 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC) {
1841 options |= DPNI_QUEUE_OPT_HOLD_ACTIVE;
1842 cfg.destination.hold_active = 1;
1845 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED &&
1846 !eth_priv->en_ordered) {
1847 struct opr_cfg ocfg;
1849 /* Restoration window size = 256 frames */
1851 /* Restoration window size = 512 frames for LX2 */
1852 if (dpaa2_svr_family == SVR_LX2160A)
1854 /* Auto advance NESN window enabled */
1856 /* Late arrival window size disabled */
1858 /* ORL resource exhaustaion advance NESN disabled */
1860 /* Loose ordering enabled */
1862 eth_priv->en_loose_ordered = 1;
1863 /* Strict ordering enabled if explicitly set */
1864 if (getenv("DPAA2_STRICT_ORDERING_ENABLE")) {
1866 eth_priv->en_loose_ordered = 0;
1869 ret = dpni_set_opr(dpni, CMD_PRI_LOW, eth_priv->token,
1870 dpaa2_ethq->tc_index, flow_id,
1871 OPR_OPT_CREATE, &ocfg);
1873 DPAA2_PMD_ERR("Error setting opr: ret: %d\n", ret);
1877 eth_priv->en_ordered = 1;
1880 options |= DPNI_QUEUE_OPT_USER_CTX;
1881 cfg.user_context = (size_t)(dpaa2_ethq);
1883 ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
1884 dpaa2_ethq->tc_index, flow_id, options, &cfg);
1886 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
1890 memcpy(&dpaa2_ethq->ev, &queue_conf->ev, sizeof(struct rte_event));
1895 int dpaa2_eth_eventq_detach(const struct rte_eth_dev *dev,
1896 int eth_rx_queue_id)
1898 struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1899 struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1900 struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1901 uint8_t flow_id = dpaa2_ethq->flow_id;
1902 struct dpni_queue cfg;
1906 memset(&cfg, 0, sizeof(struct dpni_queue));
1907 options = DPNI_QUEUE_OPT_DEST;
1908 cfg.destination.type = DPNI_DEST_NONE;
1910 ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
1911 dpaa2_ethq->tc_index, flow_id, options, &cfg);
1913 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
1919 dpaa2_dev_verify_filter_ops(enum rte_filter_op filter_op)
1923 for (i = 0; i < RTE_DIM(dpaa2_supported_filter_ops); i++) {
1924 if (dpaa2_supported_filter_ops[i] == filter_op)
1931 dpaa2_dev_flow_ctrl(struct rte_eth_dev *dev,
1932 enum rte_filter_type filter_type,
1933 enum rte_filter_op filter_op,
1941 switch (filter_type) {
1942 case RTE_ETH_FILTER_GENERIC:
1943 if (dpaa2_dev_verify_filter_ops(filter_op) < 0) {
1947 *(const void **)arg = &dpaa2_flow_ops;
1948 dpaa2_filter_type |= filter_type;
1951 RTE_LOG(ERR, PMD, "Filter type (%d) not supported",
1959 static struct eth_dev_ops dpaa2_ethdev_ops = {
1960 .dev_configure = dpaa2_eth_dev_configure,
1961 .dev_start = dpaa2_dev_start,
1962 .dev_stop = dpaa2_dev_stop,
1963 .dev_close = dpaa2_dev_close,
1964 .promiscuous_enable = dpaa2_dev_promiscuous_enable,
1965 .promiscuous_disable = dpaa2_dev_promiscuous_disable,
1966 .allmulticast_enable = dpaa2_dev_allmulticast_enable,
1967 .allmulticast_disable = dpaa2_dev_allmulticast_disable,
1968 .dev_set_link_up = dpaa2_dev_set_link_up,
1969 .dev_set_link_down = dpaa2_dev_set_link_down,
1970 .link_update = dpaa2_dev_link_update,
1971 .stats_get = dpaa2_dev_stats_get,
1972 .xstats_get = dpaa2_dev_xstats_get,
1973 .xstats_get_by_id = dpaa2_xstats_get_by_id,
1974 .xstats_get_names_by_id = dpaa2_xstats_get_names_by_id,
1975 .xstats_get_names = dpaa2_xstats_get_names,
1976 .stats_reset = dpaa2_dev_stats_reset,
1977 .xstats_reset = dpaa2_dev_stats_reset,
1978 .fw_version_get = dpaa2_fw_version_get,
1979 .dev_infos_get = dpaa2_dev_info_get,
1980 .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
1981 .mtu_set = dpaa2_dev_mtu_set,
1982 .vlan_filter_set = dpaa2_vlan_filter_set,
1983 .vlan_offload_set = dpaa2_vlan_offload_set,
1984 .vlan_tpid_set = dpaa2_vlan_tpid_set,
1985 .rx_queue_setup = dpaa2_dev_rx_queue_setup,
1986 .rx_queue_release = dpaa2_dev_rx_queue_release,
1987 .tx_queue_setup = dpaa2_dev_tx_queue_setup,
1988 .tx_queue_release = dpaa2_dev_tx_queue_release,
1989 .rx_queue_count = dpaa2_dev_rx_queue_count,
1990 .flow_ctrl_get = dpaa2_flow_ctrl_get,
1991 .flow_ctrl_set = dpaa2_flow_ctrl_set,
1992 .mac_addr_add = dpaa2_dev_add_mac_addr,
1993 .mac_addr_remove = dpaa2_dev_remove_mac_addr,
1994 .mac_addr_set = dpaa2_dev_set_mac_addr,
1995 .rss_hash_update = dpaa2_dev_rss_hash_update,
1996 .rss_hash_conf_get = dpaa2_dev_rss_hash_conf_get,
1997 .filter_ctrl = dpaa2_dev_flow_ctrl,
2000 /* Populate the mac address from physically available (u-boot/firmware) and/or
2001 * one set by higher layers like MC (restool) etc.
2002 * Returns the table of MAC entries (multiple entries)
2005 populate_mac_addr(struct fsl_mc_io *dpni_dev, struct dpaa2_dev_priv *priv,
2006 struct rte_ether_addr *mac_entry)
2009 struct rte_ether_addr phy_mac, prime_mac;
2011 memset(&phy_mac, 0, sizeof(struct rte_ether_addr));
2012 memset(&prime_mac, 0, sizeof(struct rte_ether_addr));
2014 /* Get the physical device MAC address */
2015 ret = dpni_get_port_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2016 phy_mac.addr_bytes);
2018 DPAA2_PMD_ERR("DPNI get physical port MAC failed: %d", ret);
2022 ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2023 prime_mac.addr_bytes);
2025 DPAA2_PMD_ERR("DPNI get Prime port MAC failed: %d", ret);
2029 /* Now that both MAC have been obtained, do:
2030 * if not_empty_mac(phy) && phy != Prime, overwrite prime with Phy
2032 * If empty_mac(phy), return prime.
2033 * if both are empty, create random MAC, set as prime and return
2035 if (!rte_is_zero_ether_addr(&phy_mac)) {
2036 /* If the addresses are not same, overwrite prime */
2037 if (!rte_is_same_ether_addr(&phy_mac, &prime_mac)) {
2038 ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2040 phy_mac.addr_bytes);
2042 DPAA2_PMD_ERR("Unable to set MAC Address: %d",
2046 memcpy(&prime_mac, &phy_mac,
2047 sizeof(struct rte_ether_addr));
2049 } else if (rte_is_zero_ether_addr(&prime_mac)) {
2050 /* In case phys and prime, both are zero, create random MAC */
2051 rte_eth_random_addr(prime_mac.addr_bytes);
2052 ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2054 prime_mac.addr_bytes);
2056 DPAA2_PMD_ERR("Unable to set MAC Address: %d", ret);
2061 /* prime_mac the final MAC address */
2062 memcpy(mac_entry, &prime_mac, sizeof(struct rte_ether_addr));
2070 check_devargs_handler(__rte_unused const char *key, const char *value,
2071 __rte_unused void *opaque)
2073 if (strcmp(value, "1"))
2080 dpaa2_get_devargs(struct rte_devargs *devargs, const char *key)
2082 struct rte_kvargs *kvlist;
2087 kvlist = rte_kvargs_parse(devargs->args, NULL);
2091 if (!rte_kvargs_count(kvlist, key)) {
2092 rte_kvargs_free(kvlist);
2096 if (rte_kvargs_process(kvlist, key,
2097 check_devargs_handler, NULL) < 0) {
2098 rte_kvargs_free(kvlist);
2101 rte_kvargs_free(kvlist);
2107 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
2109 struct rte_device *dev = eth_dev->device;
2110 struct rte_dpaa2_device *dpaa2_dev;
2111 struct fsl_mc_io *dpni_dev;
2112 struct dpni_attr attr;
2113 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2114 struct dpni_buffer_layout layout;
2117 PMD_INIT_FUNC_TRACE();
2119 /* For secondary processes, the primary has done all the work */
2120 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2121 /* In case of secondary, only burst and ops API need to be
2124 eth_dev->dev_ops = &dpaa2_ethdev_ops;
2125 if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE))
2126 eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2128 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2129 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2133 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
2135 hw_id = dpaa2_dev->object_id;
2137 dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
2139 DPAA2_PMD_ERR("Memory allocation failed for dpni device");
2143 dpni_dev->regs = rte_mcp_ptr_list[0];
2144 ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
2147 "Failure in opening dpni@%d with err code %d",
2153 /* Clean the device first */
2154 ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
2156 DPAA2_PMD_ERR("Failure cleaning dpni@%d with err code %d",
2161 ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
2164 "Failure in get dpni@%d attribute, err code %d",
2169 priv->num_rx_tc = attr.num_rx_tcs;
2171 for (i = 0; i < attr.num_rx_tcs; i++)
2172 priv->nb_rx_queues += attr.num_queues;
2174 /* Using number of TX queues as number of TX TCs */
2175 priv->nb_tx_queues = attr.num_tx_tcs;
2177 DPAA2_PMD_DEBUG("RX-TC= %d, nb_rx_queues= %d, nb_tx_queues=%d",
2178 priv->num_rx_tc, priv->nb_rx_queues,
2179 priv->nb_tx_queues);
2181 priv->hw = dpni_dev;
2182 priv->hw_id = hw_id;
2183 priv->options = attr.options;
2184 priv->max_mac_filters = attr.mac_filter_entries;
2185 priv->max_vlan_filters = attr.vlan_filter_entries;
2188 /* Allocate memory for hardware structure for queues */
2189 ret = dpaa2_alloc_rx_tx_queues(eth_dev);
2191 DPAA2_PMD_ERR("Queue allocation Failed");
2195 /* Allocate memory for storing MAC addresses.
2196 * Table of mac_filter_entries size is allocated so that RTE ether lib
2197 * can add MAC entries when rte_eth_dev_mac_addr_add is called.
2199 eth_dev->data->mac_addrs = rte_zmalloc("dpni",
2200 RTE_ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
2201 if (eth_dev->data->mac_addrs == NULL) {
2203 "Failed to allocate %d bytes needed to store MAC addresses",
2204 RTE_ETHER_ADDR_LEN * attr.mac_filter_entries);
2209 ret = populate_mac_addr(dpni_dev, priv, ð_dev->data->mac_addrs[0]);
2211 DPAA2_PMD_ERR("Unable to fetch MAC Address for device");
2212 rte_free(eth_dev->data->mac_addrs);
2213 eth_dev->data->mac_addrs = NULL;
2217 /* ... tx buffer layout ... */
2218 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2219 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2220 layout.pass_frame_status = 1;
2221 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2222 DPNI_QUEUE_TX, &layout);
2224 DPAA2_PMD_ERR("Error (%d) in setting tx buffer layout", ret);
2228 /* ... tx-conf and error buffer layout ... */
2229 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2230 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2231 layout.pass_frame_status = 1;
2232 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2233 DPNI_QUEUE_TX_CONFIRM, &layout);
2235 DPAA2_PMD_ERR("Error (%d) in setting tx-conf buffer layout",
2240 eth_dev->dev_ops = &dpaa2_ethdev_ops;
2242 if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE)) {
2243 eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2244 DPAA2_PMD_INFO("Loopback mode");
2246 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2248 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2250 /*Init fields w.r.t. classficaition*/
2251 memset(&priv->extract.qos_key_cfg, 0, sizeof(struct dpkg_profile_cfg));
2252 priv->extract.qos_extract_param = (size_t)rte_malloc(NULL, 256, 64);
2253 if (!priv->extract.qos_extract_param) {
2254 DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow "
2255 " classificaiton ", ret);
2258 for (i = 0; i < MAX_TCS; i++) {
2259 memset(&priv->extract.fs_key_cfg[i], 0,
2260 sizeof(struct dpkg_profile_cfg));
2261 priv->extract.fs_extract_param[i] =
2262 (size_t)rte_malloc(NULL, 256, 64);
2263 if (!priv->extract.fs_extract_param[i]) {
2264 DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow classificaiton",
2270 RTE_LOG(INFO, PMD, "%s: netdev created\n", eth_dev->data->name);
2273 dpaa2_dev_uninit(eth_dev);
2278 dpaa2_dev_uninit(struct rte_eth_dev *eth_dev)
2280 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2281 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
2284 PMD_INIT_FUNC_TRACE();
2286 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2290 DPAA2_PMD_WARN("Already closed or not started");
2294 dpaa2_dev_close(eth_dev);
2296 dpaa2_free_rx_tx_queues(eth_dev);
2298 /* Close the device at underlying layer*/
2299 ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
2302 "Failure closing dpni device with err code %d",
2306 /* Free the allocated memory for ethernet private data and dpni*/
2310 for (i = 0; i < MAX_TCS; i++) {
2311 if (priv->extract.fs_extract_param[i])
2312 rte_free((void *)(size_t)priv->extract.fs_extract_param[i]);
2315 if (priv->extract.qos_extract_param)
2316 rte_free((void *)(size_t)priv->extract.qos_extract_param);
2318 eth_dev->dev_ops = NULL;
2319 eth_dev->rx_pkt_burst = NULL;
2320 eth_dev->tx_pkt_burst = NULL;
2322 DPAA2_PMD_INFO("%s: netdev deleted", eth_dev->data->name);
2327 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
2328 struct rte_dpaa2_device *dpaa2_dev)
2330 struct rte_eth_dev *eth_dev;
2333 if ((DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE) >
2334 RTE_PKTMBUF_HEADROOM) {
2336 "RTE_PKTMBUF_HEADROOM(%d) shall be > DPAA2 Annotation req(%d)",
2337 RTE_PKTMBUF_HEADROOM,
2338 DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE);
2343 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2344 eth_dev = rte_eth_dev_allocate(dpaa2_dev->device.name);
2347 eth_dev->data->dev_private = rte_zmalloc(
2348 "ethdev private structure",
2349 sizeof(struct dpaa2_dev_priv),
2350 RTE_CACHE_LINE_SIZE);
2351 if (eth_dev->data->dev_private == NULL) {
2353 "Unable to allocate memory for private data");
2354 rte_eth_dev_release_port(eth_dev);
2358 eth_dev = rte_eth_dev_attach_secondary(dpaa2_dev->device.name);
2363 eth_dev->device = &dpaa2_dev->device;
2365 dpaa2_dev->eth_dev = eth_dev;
2366 eth_dev->data->rx_mbuf_alloc_failed = 0;
2368 if (dpaa2_drv->drv_flags & RTE_DPAA2_DRV_INTR_LSC)
2369 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
2371 /* Invoke PMD device initialization function */
2372 diag = dpaa2_dev_init(eth_dev);
2374 rte_eth_dev_probing_finish(eth_dev);
2378 rte_eth_dev_release_port(eth_dev);
2383 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
2385 struct rte_eth_dev *eth_dev;
2387 eth_dev = dpaa2_dev->eth_dev;
2388 dpaa2_dev_uninit(eth_dev);
2390 rte_eth_dev_release_port(eth_dev);
2395 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
2396 .drv_flags = RTE_DPAA2_DRV_INTR_LSC | RTE_DPAA2_DRV_IOVA_AS_VA,
2397 .drv_type = DPAA2_ETH,
2398 .probe = rte_dpaa2_probe,
2399 .remove = rte_dpaa2_remove,
2402 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);
2403 RTE_PMD_REGISTER_PARAM_STRING(net_dpaa2,
2404 DRIVER_LOOPBACK_MODE "=<int>");
2405 RTE_INIT(dpaa2_pmd_init_log)
2407 dpaa2_logtype_pmd = rte_log_register("pmd.net.dpaa2");
2408 if (dpaa2_logtype_pmd >= 0)
2409 rte_log_set_level(dpaa2_logtype_pmd, RTE_LOG_NOTICE);