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_looback"
33 /* Supported Rx offloads */
34 static uint64_t dev_rx_offloads_sup =
35 DEV_RX_OFFLOAD_VLAN_STRIP |
36 DEV_RX_OFFLOAD_IPV4_CKSUM |
37 DEV_RX_OFFLOAD_UDP_CKSUM |
38 DEV_RX_OFFLOAD_TCP_CKSUM |
39 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
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;
56 /* Tx offloads which cannot be disabled */
57 static uint64_t dev_tx_offloads_nodis =
58 DEV_TX_OFFLOAD_MULTI_SEGS |
59 DEV_TX_OFFLOAD_MT_LOCKFREE |
60 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
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;
105 __rte_experimental void
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;
275 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
277 struct dpaa2_dev_priv *priv = dev->data->dev_private;
280 uint8_t num_rxqueue_per_tc;
281 struct dpaa2_queue *mc_q, *mcq;
284 struct dpaa2_queue *dpaa2_q;
286 PMD_INIT_FUNC_TRACE();
288 num_rxqueue_per_tc = (priv->nb_rx_queues / priv->num_rx_tc);
289 tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
290 mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
291 RTE_CACHE_LINE_SIZE);
293 DPAA2_PMD_ERR("Memory allocation failed for rx/tx queues");
297 for (i = 0; i < priv->nb_rx_queues; i++) {
298 mc_q->eth_data = dev->data;
299 priv->rx_vq[i] = mc_q++;
300 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
301 dpaa2_q->q_storage = rte_malloc("dq_storage",
302 sizeof(struct queue_storage_info_t),
303 RTE_CACHE_LINE_SIZE);
304 if (!dpaa2_q->q_storage)
307 memset(dpaa2_q->q_storage, 0,
308 sizeof(struct queue_storage_info_t));
309 if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
313 for (i = 0; i < priv->nb_tx_queues; i++) {
314 mc_q->eth_data = dev->data;
315 mc_q->flow_id = 0xffff;
316 priv->tx_vq[i] = mc_q++;
317 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
318 dpaa2_q->cscn = rte_malloc(NULL,
319 sizeof(struct qbman_result), 16);
325 for (dist_idx = 0; dist_idx < priv->nb_rx_queues; dist_idx++) {
326 mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
327 mcq->tc_index = dist_idx / num_rxqueue_per_tc;
328 mcq->flow_id = dist_idx % num_rxqueue_per_tc;
336 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
337 rte_free(dpaa2_q->cscn);
338 priv->tx_vq[i--] = NULL;
340 i = priv->nb_rx_queues;
343 mc_q = priv->rx_vq[0];
345 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
346 dpaa2_free_dq_storage(dpaa2_q->q_storage);
347 rte_free(dpaa2_q->q_storage);
348 priv->rx_vq[i--] = NULL;
355 dpaa2_free_rx_tx_queues(struct rte_eth_dev *dev)
357 struct dpaa2_dev_priv *priv = dev->data->dev_private;
358 struct dpaa2_queue *dpaa2_q;
361 PMD_INIT_FUNC_TRACE();
363 /* Queue allocation base */
364 if (priv->rx_vq[0]) {
365 /* cleaning up queue storage */
366 for (i = 0; i < priv->nb_rx_queues; i++) {
367 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
368 if (dpaa2_q->q_storage)
369 rte_free(dpaa2_q->q_storage);
371 /* cleanup tx queue cscn */
372 for (i = 0; i < priv->nb_tx_queues; i++) {
373 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
374 rte_free(dpaa2_q->cscn);
376 /*free memory for all queues (RX+TX) */
377 rte_free(priv->rx_vq[0]);
378 priv->rx_vq[0] = NULL;
383 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
385 struct dpaa2_dev_priv *priv = dev->data->dev_private;
386 struct fsl_mc_io *dpni = priv->hw;
387 struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
388 uint64_t rx_offloads = eth_conf->rxmode.offloads;
389 uint64_t tx_offloads = eth_conf->txmode.offloads;
390 int rx_l3_csum_offload = false;
391 int rx_l4_csum_offload = false;
392 int tx_l3_csum_offload = false;
393 int tx_l4_csum_offload = false;
396 PMD_INIT_FUNC_TRACE();
398 /* Rx offloads validation */
399 if (dev_rx_offloads_nodis & ~rx_offloads) {
401 "Rx offloads non configurable - requested 0x%" PRIx64
402 " ignored 0x%" PRIx64,
403 rx_offloads, dev_rx_offloads_nodis);
406 /* Tx offloads validation */
407 if (dev_tx_offloads_nodis & ~tx_offloads) {
409 "Tx offloads non configurable - requested 0x%" PRIx64
410 " ignored 0x%" PRIx64,
411 tx_offloads, dev_tx_offloads_nodis);
414 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
415 if (eth_conf->rxmode.max_rx_pkt_len <= DPAA2_MAX_RX_PKT_LEN) {
416 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW,
417 priv->token, eth_conf->rxmode.max_rx_pkt_len);
420 "Unable to set mtu. check config");
428 if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
429 ret = dpaa2_setup_flow_dist(dev,
430 eth_conf->rx_adv_conf.rss_conf.rss_hf);
432 DPAA2_PMD_ERR("Unable to set flow distribution."
433 "Check queue config");
438 if (rx_offloads & DEV_RX_OFFLOAD_IPV4_CKSUM)
439 rx_l3_csum_offload = true;
441 if ((rx_offloads & DEV_RX_OFFLOAD_UDP_CKSUM) ||
442 (rx_offloads & DEV_RX_OFFLOAD_TCP_CKSUM))
443 rx_l4_csum_offload = true;
445 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
446 DPNI_OFF_RX_L3_CSUM, rx_l3_csum_offload);
448 DPAA2_PMD_ERR("Error to set RX l3 csum:Error = %d", ret);
452 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
453 DPNI_OFF_RX_L4_CSUM, rx_l4_csum_offload);
455 DPAA2_PMD_ERR("Error to get RX l4 csum:Error = %d", ret);
459 if (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM)
460 tx_l3_csum_offload = true;
462 if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ||
463 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ||
464 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
465 tx_l4_csum_offload = true;
467 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
468 DPNI_OFF_TX_L3_CSUM, tx_l3_csum_offload);
470 DPAA2_PMD_ERR("Error to set TX l3 csum:Error = %d", ret);
474 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
475 DPNI_OFF_TX_L4_CSUM, tx_l4_csum_offload);
477 DPAA2_PMD_ERR("Error to get TX l4 csum:Error = %d", ret);
481 /* Enabling hash results in FD requires setting DPNI_FLCTYPE_HASH in
482 * dpni_set_offload API. Setting this FLCTYPE for DPNI sets the FD[SC]
483 * to 0 for LS2 in the hardware thus disabling data/annotation
484 * stashing. For LX2 this is fixed in hardware and thus hash result and
485 * parse results can be received in FD using this option.
487 if (dpaa2_svr_family == SVR_LX2160A) {
488 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
489 DPNI_FLCTYPE_HASH, true);
491 DPAA2_PMD_ERR("Error setting FLCTYPE: Err = %d", ret);
496 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
497 dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
499 /* update the current status */
500 dpaa2_dev_link_update(dev, 0);
505 /* Function to setup RX flow information. It contains traffic class ID,
506 * flow ID, destination configuration etc.
509 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
510 uint16_t rx_queue_id,
511 uint16_t nb_rx_desc __rte_unused,
512 unsigned int socket_id __rte_unused,
513 const struct rte_eth_rxconf *rx_conf __rte_unused,
514 struct rte_mempool *mb_pool)
516 struct dpaa2_dev_priv *priv = dev->data->dev_private;
517 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
518 struct dpaa2_queue *dpaa2_q;
519 struct dpni_queue cfg;
525 PMD_INIT_FUNC_TRACE();
527 DPAA2_PMD_DEBUG("dev =%p, queue =%d, pool = %p, conf =%p",
528 dev, rx_queue_id, mb_pool, rx_conf);
530 if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
531 bpid = mempool_to_bpid(mb_pool);
532 ret = dpaa2_attach_bp_list(priv,
533 rte_dpaa2_bpid_info[bpid].bp_list);
537 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
538 dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
539 dpaa2_q->bp_array = rte_dpaa2_bpid_info;
541 /*Get the flow id from given VQ id*/
542 flow_id = rx_queue_id % priv->nb_rx_queues;
543 memset(&cfg, 0, sizeof(struct dpni_queue));
545 options = options | DPNI_QUEUE_OPT_USER_CTX;
546 cfg.user_context = (size_t)(dpaa2_q);
548 /*if ls2088 or rev2 device, enable the stashing */
550 if ((dpaa2_svr_family & 0xffff0000) != SVR_LS2080A) {
551 options |= DPNI_QUEUE_OPT_FLC;
552 cfg.flc.stash_control = true;
553 cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
554 /* 00 00 00 - last 6 bit represent annotation, context stashing,
555 * data stashing setting 01 01 00 (0x14)
556 * (in following order ->DS AS CS)
557 * to enable 1 line data, 1 line annotation.
558 * For LX2, this setting should be 01 00 00 (0x10)
560 if ((dpaa2_svr_family & 0xffff0000) == SVR_LX2160A)
561 cfg.flc.value |= 0x10;
563 cfg.flc.value |= 0x14;
565 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
566 dpaa2_q->tc_index, flow_id, options, &cfg);
568 DPAA2_PMD_ERR("Error in setting the rx flow: = %d", ret);
572 if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
573 struct dpni_taildrop taildrop;
576 /*enabling per rx queue congestion control */
577 taildrop.threshold = CONG_THRESHOLD_RX_Q;
578 taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
579 taildrop.oal = CONG_RX_OAL;
580 DPAA2_PMD_DEBUG("Enabling Early Drop on queue = %d",
582 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
583 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
584 dpaa2_q->tc_index, flow_id, &taildrop);
586 DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
592 dev->data->rx_queues[rx_queue_id] = dpaa2_q;
597 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
598 uint16_t tx_queue_id,
599 uint16_t nb_tx_desc __rte_unused,
600 unsigned int socket_id __rte_unused,
601 const struct rte_eth_txconf *tx_conf __rte_unused)
603 struct dpaa2_dev_priv *priv = dev->data->dev_private;
604 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
605 priv->tx_vq[tx_queue_id];
606 struct fsl_mc_io *dpni = priv->hw;
607 struct dpni_queue tx_conf_cfg;
608 struct dpni_queue tx_flow_cfg;
609 uint8_t options = 0, flow_id;
613 PMD_INIT_FUNC_TRACE();
615 /* Return if queue already configured */
616 if (dpaa2_q->flow_id != 0xffff) {
617 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
621 memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
622 memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
627 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
628 tc_id, flow_id, options, &tx_flow_cfg);
630 DPAA2_PMD_ERR("Error in setting the tx flow: "
631 "tc_id=%d, flow=%d err=%d",
632 tc_id, flow_id, ret);
636 dpaa2_q->flow_id = flow_id;
638 if (tx_queue_id == 0) {
639 /*Set tx-conf and error configuration*/
640 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
644 DPAA2_PMD_ERR("Error in set tx conf mode settings: "
649 dpaa2_q->tc_index = tc_id;
651 if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
652 struct dpni_congestion_notification_cfg cong_notif_cfg;
654 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
655 cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
656 /* Notify that the queue is not congested when the data in
657 * the queue is below this thershold.
659 cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
660 cong_notif_cfg.message_ctx = 0;
661 cong_notif_cfg.message_iova =
662 (size_t)DPAA2_VADDR_TO_IOVA(dpaa2_q->cscn);
663 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
664 cong_notif_cfg.notification_mode =
665 DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
666 DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
667 DPNI_CONG_OPT_COHERENT_WRITE;
669 ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
676 "Error in setting tx congestion notification: "
681 dpaa2_q->cb_eqresp_free = dpaa2_dev_free_eqresp_buf;
682 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
687 dpaa2_dev_rx_queue_release(void *q __rte_unused)
689 PMD_INIT_FUNC_TRACE();
693 dpaa2_dev_tx_queue_release(void *q __rte_unused)
695 PMD_INIT_FUNC_TRACE();
699 dpaa2_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
702 struct dpaa2_dev_priv *priv = dev->data->dev_private;
703 struct dpaa2_queue *dpaa2_q;
704 struct qbman_swp *swp;
705 struct qbman_fq_query_np_rslt state;
706 uint32_t frame_cnt = 0;
708 PMD_INIT_FUNC_TRACE();
710 if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
711 ret = dpaa2_affine_qbman_swp();
713 DPAA2_PMD_ERR("Failure in affining portal");
717 swp = DPAA2_PER_LCORE_PORTAL;
719 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
721 if (qbman_fq_query_state(swp, dpaa2_q->fqid, &state) == 0) {
722 frame_cnt = qbman_fq_state_frame_count(&state);
723 DPAA2_PMD_DEBUG("RX frame count for q(%d) is %u",
724 rx_queue_id, frame_cnt);
729 static const uint32_t *
730 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
732 static const uint32_t ptypes[] = {
733 /*todo -= add more types */
736 RTE_PTYPE_L3_IPV4_EXT,
738 RTE_PTYPE_L3_IPV6_EXT,
746 if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx ||
747 dev->rx_pkt_burst == dpaa2_dev_loopback_rx)
753 * Dpaa2 link Interrupt handler
756 * The address of parameter (struct rte_eth_dev *) regsitered before.
762 dpaa2_interrupt_handler(void *param)
764 struct rte_eth_dev *dev = param;
765 struct dpaa2_dev_priv *priv = dev->data->dev_private;
766 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
768 int irq_index = DPNI_IRQ_INDEX;
769 unsigned int status = 0, clear = 0;
771 PMD_INIT_FUNC_TRACE();
774 DPAA2_PMD_ERR("dpni is NULL");
778 ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
781 DPAA2_PMD_ERR("Can't get irq status (err %d)", ret);
786 if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
787 clear = DPNI_IRQ_EVENT_LINK_CHANGED;
788 dpaa2_dev_link_update(dev, 0);
789 /* calling all the apps registered for link status event */
790 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
794 ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
797 DPAA2_PMD_ERR("Can't clear irq status (err %d)", ret);
801 dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
804 struct dpaa2_dev_priv *priv = dev->data->dev_private;
805 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
806 int irq_index = DPNI_IRQ_INDEX;
807 unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
809 PMD_INIT_FUNC_TRACE();
811 err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
814 DPAA2_PMD_ERR("Error: dpni_set_irq_mask():%d (%s)", err,
819 err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
822 DPAA2_PMD_ERR("Error: dpni_set_irq_enable():%d (%s)", err,
829 dpaa2_dev_start(struct rte_eth_dev *dev)
831 struct rte_device *rdev = dev->device;
832 struct rte_dpaa2_device *dpaa2_dev;
833 struct rte_eth_dev_data *data = dev->data;
834 struct dpaa2_dev_priv *priv = data->dev_private;
835 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
836 struct dpni_queue cfg;
837 struct dpni_error_cfg err_cfg;
839 struct dpni_queue_id qid;
840 struct dpaa2_queue *dpaa2_q;
842 struct rte_intr_handle *intr_handle;
844 dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
845 intr_handle = &dpaa2_dev->intr_handle;
847 PMD_INIT_FUNC_TRACE();
849 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
851 DPAA2_PMD_ERR("Failure in enabling dpni %d device: err=%d",
856 /* Power up the phy. Needed to make the link go UP */
857 dpaa2_dev_set_link_up(dev);
859 ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
860 DPNI_QUEUE_TX, &qdid);
862 DPAA2_PMD_ERR("Error in getting qdid: err=%d", ret);
867 for (i = 0; i < data->nb_rx_queues; i++) {
868 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
869 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
870 DPNI_QUEUE_RX, dpaa2_q->tc_index,
871 dpaa2_q->flow_id, &cfg, &qid);
873 DPAA2_PMD_ERR("Error in getting flow information: "
877 dpaa2_q->fqid = qid.fqid;
880 /*checksum errors, send them to normal path and set it in annotation */
881 err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
882 err_cfg.errors |= DPNI_ERROR_PHE;
884 err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
885 err_cfg.set_frame_annotation = true;
887 ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
888 priv->token, &err_cfg);
890 DPAA2_PMD_ERR("Error to dpni_set_errors_behavior: code = %d",
895 /* if the interrupts were configured on this devices*/
896 if (intr_handle && (intr_handle->fd) &&
897 (dev->data->dev_conf.intr_conf.lsc != 0)) {
898 /* Registering LSC interrupt handler */
899 rte_intr_callback_register(intr_handle,
900 dpaa2_interrupt_handler,
903 /* enable vfio intr/eventfd mapping
904 * Interrupt index 0 is required, so we can not use
907 rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
909 /* enable dpni_irqs */
910 dpaa2_eth_setup_irqs(dev, 1);
913 /* Change the tx burst function if ordered queues are used */
914 if (priv->en_ordered)
915 dev->tx_pkt_burst = dpaa2_dev_tx_ordered;
921 * This routine disables all traffic on the adapter by issuing a
922 * global reset on the MAC.
925 dpaa2_dev_stop(struct rte_eth_dev *dev)
927 struct dpaa2_dev_priv *priv = dev->data->dev_private;
928 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
930 struct rte_eth_link link;
931 struct rte_intr_handle *intr_handle = dev->intr_handle;
933 PMD_INIT_FUNC_TRACE();
935 /* reset interrupt callback */
936 if (intr_handle && (intr_handle->fd) &&
937 (dev->data->dev_conf.intr_conf.lsc != 0)) {
938 /*disable dpni irqs */
939 dpaa2_eth_setup_irqs(dev, 0);
941 /* disable vfio intr before callback unregister */
942 rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
944 /* Unregistering LSC interrupt handler */
945 rte_intr_callback_unregister(intr_handle,
946 dpaa2_interrupt_handler,
950 dpaa2_dev_set_link_down(dev);
952 ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
954 DPAA2_PMD_ERR("Failure (ret %d) in disabling dpni %d dev",
959 /* clear the recorded link status */
960 memset(&link, 0, sizeof(link));
961 rte_eth_linkstatus_set(dev, &link);
965 dpaa2_dev_close(struct rte_eth_dev *dev)
967 struct dpaa2_dev_priv *priv = dev->data->dev_private;
968 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
970 struct rte_eth_link link;
972 PMD_INIT_FUNC_TRACE();
974 /* Clean the device first */
975 ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
977 DPAA2_PMD_ERR("Failure cleaning dpni device: err=%d", ret);
981 memset(&link, 0, sizeof(link));
982 rte_eth_linkstatus_set(dev, &link);
986 dpaa2_dev_promiscuous_enable(
987 struct rte_eth_dev *dev)
990 struct dpaa2_dev_priv *priv = dev->data->dev_private;
991 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
993 PMD_INIT_FUNC_TRACE();
996 DPAA2_PMD_ERR("dpni is NULL");
1000 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1002 DPAA2_PMD_ERR("Unable to enable U promisc mode %d", ret);
1004 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1006 DPAA2_PMD_ERR("Unable to enable M promisc mode %d", ret);
1010 dpaa2_dev_promiscuous_disable(
1011 struct rte_eth_dev *dev)
1014 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1015 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1017 PMD_INIT_FUNC_TRACE();
1020 DPAA2_PMD_ERR("dpni is NULL");
1024 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1026 DPAA2_PMD_ERR("Unable to disable U promisc mode %d", ret);
1028 if (dev->data->all_multicast == 0) {
1029 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
1030 priv->token, false);
1032 DPAA2_PMD_ERR("Unable to disable M promisc mode %d",
1038 dpaa2_dev_allmulticast_enable(
1039 struct rte_eth_dev *dev)
1042 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1043 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1045 PMD_INIT_FUNC_TRACE();
1048 DPAA2_PMD_ERR("dpni is NULL");
1052 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1054 DPAA2_PMD_ERR("Unable to enable multicast mode %d", ret);
1058 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
1061 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1062 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1064 PMD_INIT_FUNC_TRACE();
1067 DPAA2_PMD_ERR("dpni is NULL");
1071 /* must remain on for all promiscuous */
1072 if (dev->data->promiscuous == 1)
1075 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1077 DPAA2_PMD_ERR("Unable to disable multicast mode %d", ret);
1081 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1084 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1085 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1086 uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN
1089 PMD_INIT_FUNC_TRACE();
1092 DPAA2_PMD_ERR("dpni is NULL");
1096 /* check that mtu is within the allowed range */
1097 if ((mtu < ETHER_MIN_MTU) || (frame_size > DPAA2_MAX_RX_PKT_LEN))
1100 if (frame_size > ETHER_MAX_LEN)
1101 dev->data->dev_conf.rxmode.offloads &=
1102 DEV_RX_OFFLOAD_JUMBO_FRAME;
1104 dev->data->dev_conf.rxmode.offloads &=
1105 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1107 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1109 /* Set the Max Rx frame length as 'mtu' +
1110 * Maximum Ethernet header length
1112 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
1115 DPAA2_PMD_ERR("Setting the max frame length failed");
1118 DPAA2_PMD_INFO("MTU configured for the device: %d", mtu);
1123 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
1124 struct ether_addr *addr,
1125 __rte_unused uint32_t index,
1126 __rte_unused uint32_t pool)
1129 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1130 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1132 PMD_INIT_FUNC_TRACE();
1135 DPAA2_PMD_ERR("dpni is NULL");
1139 ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
1140 priv->token, addr->addr_bytes);
1143 "error: Adding the MAC ADDR failed: err = %d", ret);
1148 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
1152 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1153 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1154 struct rte_eth_dev_data *data = dev->data;
1155 struct ether_addr *macaddr;
1157 PMD_INIT_FUNC_TRACE();
1159 macaddr = &data->mac_addrs[index];
1162 DPAA2_PMD_ERR("dpni is NULL");
1166 ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
1167 priv->token, macaddr->addr_bytes);
1170 "error: Removing the MAC ADDR failed: err = %d", ret);
1174 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
1175 struct ether_addr *addr)
1178 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1179 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1181 PMD_INIT_FUNC_TRACE();
1184 DPAA2_PMD_ERR("dpni is NULL");
1188 ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
1189 priv->token, addr->addr_bytes);
1193 "error: Setting the MAC ADDR failed %d", ret);
1199 int dpaa2_dev_stats_get(struct rte_eth_dev *dev,
1200 struct rte_eth_stats *stats)
1202 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1203 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1205 uint8_t page0 = 0, page1 = 1, page2 = 2;
1206 union dpni_statistics value;
1208 struct dpaa2_queue *dpaa2_rxq, *dpaa2_txq;
1210 memset(&value, 0, sizeof(union dpni_statistics));
1212 PMD_INIT_FUNC_TRACE();
1215 DPAA2_PMD_ERR("dpni is NULL");
1220 DPAA2_PMD_ERR("stats is NULL");
1224 /*Get Counters from page_0*/
1225 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1230 stats->ipackets = value.page_0.ingress_all_frames;
1231 stats->ibytes = value.page_0.ingress_all_bytes;
1233 /*Get Counters from page_1*/
1234 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1239 stats->opackets = value.page_1.egress_all_frames;
1240 stats->obytes = value.page_1.egress_all_bytes;
1242 /*Get Counters from page_2*/
1243 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1248 /* Ingress drop frame count due to configured rules */
1249 stats->ierrors = value.page_2.ingress_filtered_frames;
1250 /* Ingress drop frame count due to error */
1251 stats->ierrors += value.page_2.ingress_discarded_frames;
1253 stats->oerrors = value.page_2.egress_discarded_frames;
1254 stats->imissed = value.page_2.ingress_nobuffer_discards;
1256 /* Fill in per queue stats */
1257 for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
1258 (i < priv->nb_rx_queues || i < priv->nb_tx_queues); ++i) {
1259 dpaa2_rxq = (struct dpaa2_queue *)priv->rx_vq[i];
1260 dpaa2_txq = (struct dpaa2_queue *)priv->tx_vq[i];
1262 stats->q_ipackets[i] = dpaa2_rxq->rx_pkts;
1264 stats->q_opackets[i] = dpaa2_txq->tx_pkts;
1266 /* Byte counting is not implemented */
1267 stats->q_ibytes[i] = 0;
1268 stats->q_obytes[i] = 0;
1274 DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1279 dpaa2_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1282 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1283 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1285 union dpni_statistics value[3] = {};
1286 unsigned int i = 0, num = RTE_DIM(dpaa2_xstats_strings);
1294 /* Get Counters from page_0*/
1295 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1300 /* Get Counters from page_1*/
1301 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1306 /* Get Counters from page_2*/
1307 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1312 for (i = 0; i < num; i++) {
1314 xstats[i].value = value[dpaa2_xstats_strings[i].page_id].
1315 raw.counter[dpaa2_xstats_strings[i].stats_id];
1319 DPAA2_PMD_ERR("Error in obtaining extended stats (%d)", retcode);
1324 dpaa2_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1325 struct rte_eth_xstat_name *xstats_names,
1328 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1330 if (limit < stat_cnt)
1333 if (xstats_names != NULL)
1334 for (i = 0; i < stat_cnt; i++)
1335 snprintf(xstats_names[i].name,
1336 sizeof(xstats_names[i].name),
1338 dpaa2_xstats_strings[i].name);
1344 dpaa2_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1345 uint64_t *values, unsigned int n)
1347 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1348 uint64_t values_copy[stat_cnt];
1351 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1352 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1354 union dpni_statistics value[3] = {};
1362 /* Get Counters from page_0*/
1363 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1368 /* Get Counters from page_1*/
1369 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1374 /* Get Counters from page_2*/
1375 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1380 for (i = 0; i < stat_cnt; i++) {
1381 values[i] = value[dpaa2_xstats_strings[i].page_id].
1382 raw.counter[dpaa2_xstats_strings[i].stats_id];
1387 dpaa2_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
1389 for (i = 0; i < n; i++) {
1390 if (ids[i] >= stat_cnt) {
1391 DPAA2_PMD_ERR("xstats id value isn't valid");
1394 values[i] = values_copy[ids[i]];
1400 dpaa2_xstats_get_names_by_id(
1401 struct rte_eth_dev *dev,
1402 struct rte_eth_xstat_name *xstats_names,
1403 const uint64_t *ids,
1406 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1407 struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
1410 return dpaa2_xstats_get_names(dev, xstats_names, limit);
1412 dpaa2_xstats_get_names(dev, xstats_names_copy, limit);
1414 for (i = 0; i < limit; i++) {
1415 if (ids[i] >= stat_cnt) {
1416 DPAA2_PMD_ERR("xstats id value isn't valid");
1419 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
1425 dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
1427 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1428 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1431 struct dpaa2_queue *dpaa2_q;
1433 PMD_INIT_FUNC_TRACE();
1436 DPAA2_PMD_ERR("dpni is NULL");
1440 retcode = dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
1444 /* Reset the per queue stats in dpaa2_queue structure */
1445 for (i = 0; i < priv->nb_rx_queues; i++) {
1446 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
1448 dpaa2_q->rx_pkts = 0;
1451 for (i = 0; i < priv->nb_tx_queues; i++) {
1452 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
1454 dpaa2_q->tx_pkts = 0;
1460 DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1464 /* return 0 means link status changed, -1 means not changed */
1466 dpaa2_dev_link_update(struct rte_eth_dev *dev,
1467 int wait_to_complete __rte_unused)
1470 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1471 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1472 struct rte_eth_link link;
1473 struct dpni_link_state state = {0};
1476 DPAA2_PMD_ERR("dpni is NULL");
1480 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1482 DPAA2_PMD_DEBUG("error: dpni_get_link_state %d", ret);
1486 memset(&link, 0, sizeof(struct rte_eth_link));
1487 link.link_status = state.up;
1488 link.link_speed = state.rate;
1490 if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1491 link.link_duplex = ETH_LINK_HALF_DUPLEX;
1493 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1495 ret = rte_eth_linkstatus_set(dev, &link);
1497 DPAA2_PMD_DEBUG("No change in status");
1499 DPAA2_PMD_INFO("Port %d Link is %s\n", dev->data->port_id,
1500 link.link_status ? "Up" : "Down");
1506 * Toggle the DPNI to enable, if not already enabled.
1507 * This is not strictly PHY up/down - it is more of logical toggling.
1510 dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
1513 struct dpaa2_dev_priv *priv;
1514 struct fsl_mc_io *dpni;
1516 struct dpni_link_state state = {0};
1518 priv = dev->data->dev_private;
1519 dpni = (struct fsl_mc_io *)priv->hw;
1522 DPAA2_PMD_ERR("dpni is NULL");
1526 /* Check if DPNI is currently enabled */
1527 ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
1529 /* Unable to obtain dpni status; Not continuing */
1530 DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1534 /* Enable link if not already enabled */
1536 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1538 DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1542 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1544 DPAA2_PMD_DEBUG("Unable to get link state (%d)", ret);
1548 /* changing tx burst function to start enqueues */
1549 dev->tx_pkt_burst = dpaa2_dev_tx;
1550 dev->data->dev_link.link_status = state.up;
1553 DPAA2_PMD_INFO("Port %d Link is Up", dev->data->port_id);
1555 DPAA2_PMD_INFO("Port %d Link is Down", dev->data->port_id);
1560 * Toggle the DPNI to disable, if not already disabled.
1561 * This is not strictly PHY up/down - it is more of logical toggling.
1564 dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
1567 struct dpaa2_dev_priv *priv;
1568 struct fsl_mc_io *dpni;
1569 int dpni_enabled = 0;
1572 PMD_INIT_FUNC_TRACE();
1574 priv = dev->data->dev_private;
1575 dpni = (struct fsl_mc_io *)priv->hw;
1578 DPAA2_PMD_ERR("Device has not yet been configured");
1582 /*changing tx burst function to avoid any more enqueues */
1583 dev->tx_pkt_burst = dummy_dev_tx;
1585 /* Loop while dpni_disable() attempts to drain the egress FQs
1586 * and confirm them back to us.
1589 ret = dpni_disable(dpni, 0, priv->token);
1591 DPAA2_PMD_ERR("dpni disable failed (%d)", ret);
1594 ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
1596 DPAA2_PMD_ERR("dpni enable check failed (%d)", ret);
1600 /* Allow the MC some slack */
1601 rte_delay_us(100 * 1000);
1602 } while (dpni_enabled && --retries);
1605 DPAA2_PMD_WARN("Retry count exceeded disabling dpni");
1606 /* todo- we may have to manually cleanup queues.
1609 DPAA2_PMD_INFO("Port %d Link DOWN successful",
1610 dev->data->port_id);
1613 dev->data->dev_link.link_status = 0;
1619 dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1622 struct dpaa2_dev_priv *priv;
1623 struct fsl_mc_io *dpni;
1624 struct dpni_link_state state = {0};
1626 PMD_INIT_FUNC_TRACE();
1628 priv = dev->data->dev_private;
1629 dpni = (struct fsl_mc_io *)priv->hw;
1631 if (dpni == NULL || fc_conf == NULL) {
1632 DPAA2_PMD_ERR("device not configured");
1636 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1638 DPAA2_PMD_ERR("error: dpni_get_link_state %d", ret);
1642 memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
1643 if (state.options & DPNI_LINK_OPT_PAUSE) {
1644 /* DPNI_LINK_OPT_PAUSE set
1645 * if ASYM_PAUSE not set,
1646 * RX Side flow control (handle received Pause frame)
1647 * TX side flow control (send Pause frame)
1648 * if ASYM_PAUSE set,
1649 * RX Side flow control (handle received Pause frame)
1650 * No TX side flow control (send Pause frame disabled)
1652 if (!(state.options & DPNI_LINK_OPT_ASYM_PAUSE))
1653 fc_conf->mode = RTE_FC_FULL;
1655 fc_conf->mode = RTE_FC_RX_PAUSE;
1657 /* DPNI_LINK_OPT_PAUSE not set
1658 * if ASYM_PAUSE set,
1659 * TX side flow control (send Pause frame)
1660 * No RX side flow control (No action on pause frame rx)
1661 * if ASYM_PAUSE not set,
1662 * Flow control disabled
1664 if (state.options & DPNI_LINK_OPT_ASYM_PAUSE)
1665 fc_conf->mode = RTE_FC_TX_PAUSE;
1667 fc_conf->mode = RTE_FC_NONE;
1674 dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1677 struct dpaa2_dev_priv *priv;
1678 struct fsl_mc_io *dpni;
1679 struct dpni_link_state state = {0};
1680 struct dpni_link_cfg cfg = {0};
1682 PMD_INIT_FUNC_TRACE();
1684 priv = dev->data->dev_private;
1685 dpni = (struct fsl_mc_io *)priv->hw;
1688 DPAA2_PMD_ERR("dpni is NULL");
1692 /* It is necessary to obtain the current state before setting fc_conf
1693 * as MC would return error in case rate, autoneg or duplex values are
1696 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1698 DPAA2_PMD_ERR("Unable to get link state (err=%d)", ret);
1702 /* Disable link before setting configuration */
1703 dpaa2_dev_set_link_down(dev);
1705 /* Based on fc_conf, update cfg */
1706 cfg.rate = state.rate;
1707 cfg.options = state.options;
1709 /* update cfg with fc_conf */
1710 switch (fc_conf->mode) {
1712 /* Full flow control;
1713 * OPT_PAUSE set, ASYM_PAUSE not set
1715 cfg.options |= DPNI_LINK_OPT_PAUSE;
1716 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1718 case RTE_FC_TX_PAUSE:
1719 /* Enable RX flow control
1720 * OPT_PAUSE not set;
1723 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1724 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1726 case RTE_FC_RX_PAUSE:
1727 /* Enable TX Flow control
1731 cfg.options |= DPNI_LINK_OPT_PAUSE;
1732 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1735 /* Disable Flow control
1737 * ASYM_PAUSE not set
1739 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1740 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1743 DPAA2_PMD_ERR("Incorrect Flow control flag (%d)",
1748 ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
1750 DPAA2_PMD_ERR("Unable to set Link configuration (err=%d)",
1754 dpaa2_dev_set_link_up(dev);
1760 dpaa2_dev_rss_hash_update(struct rte_eth_dev *dev,
1761 struct rte_eth_rss_conf *rss_conf)
1763 struct rte_eth_dev_data *data = dev->data;
1764 struct rte_eth_conf *eth_conf = &data->dev_conf;
1767 PMD_INIT_FUNC_TRACE();
1769 if (rss_conf->rss_hf) {
1770 ret = dpaa2_setup_flow_dist(dev, rss_conf->rss_hf);
1772 DPAA2_PMD_ERR("Unable to set flow dist");
1776 ret = dpaa2_remove_flow_dist(dev, 0);
1778 DPAA2_PMD_ERR("Unable to remove flow dist");
1782 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
1787 dpaa2_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1788 struct rte_eth_rss_conf *rss_conf)
1790 struct rte_eth_dev_data *data = dev->data;
1791 struct rte_eth_conf *eth_conf = &data->dev_conf;
1793 /* dpaa2 does not support rss_key, so length should be 0*/
1794 rss_conf->rss_key_len = 0;
1795 rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
1799 int dpaa2_eth_eventq_attach(const struct rte_eth_dev *dev,
1800 int eth_rx_queue_id,
1802 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
1804 struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1805 struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1806 struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1807 uint8_t flow_id = dpaa2_ethq->flow_id;
1808 struct dpni_queue cfg;
1812 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
1813 dpaa2_ethq->cb = dpaa2_dev_process_parallel_event;
1814 else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC)
1815 dpaa2_ethq->cb = dpaa2_dev_process_atomic_event;
1816 else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED)
1817 dpaa2_ethq->cb = dpaa2_dev_process_ordered_event;
1821 memset(&cfg, 0, sizeof(struct dpni_queue));
1822 options = DPNI_QUEUE_OPT_DEST;
1823 cfg.destination.type = DPNI_DEST_DPCON;
1824 cfg.destination.id = dpcon_id;
1825 cfg.destination.priority = queue_conf->ev.priority;
1827 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC) {
1828 options |= DPNI_QUEUE_OPT_HOLD_ACTIVE;
1829 cfg.destination.hold_active = 1;
1832 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED &&
1833 !eth_priv->en_ordered) {
1834 struct opr_cfg ocfg;
1836 /* Restoration window size = 256 frames */
1838 /* Restoration window size = 512 frames for LX2 */
1839 if (dpaa2_svr_family == SVR_LX2160A)
1841 /* Auto advance NESN window enabled */
1843 /* Late arrival window size disabled */
1845 /* ORL resource exhaustaion advance NESN disabled */
1847 /* Loose ordering enabled */
1849 eth_priv->en_loose_ordered = 1;
1850 /* Strict ordering enabled if explicitly set */
1851 if (getenv("DPAA2_STRICT_ORDERING_ENABLE")) {
1853 eth_priv->en_loose_ordered = 0;
1856 ret = dpni_set_opr(dpni, CMD_PRI_LOW, eth_priv->token,
1857 dpaa2_ethq->tc_index, flow_id,
1858 OPR_OPT_CREATE, &ocfg);
1860 DPAA2_PMD_ERR("Error setting opr: ret: %d\n", ret);
1864 eth_priv->en_ordered = 1;
1867 options |= DPNI_QUEUE_OPT_USER_CTX;
1868 cfg.user_context = (size_t)(dpaa2_ethq);
1870 ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
1871 dpaa2_ethq->tc_index, flow_id, options, &cfg);
1873 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
1877 memcpy(&dpaa2_ethq->ev, &queue_conf->ev, sizeof(struct rte_event));
1882 int dpaa2_eth_eventq_detach(const struct rte_eth_dev *dev,
1883 int eth_rx_queue_id)
1885 struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1886 struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1887 struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1888 uint8_t flow_id = dpaa2_ethq->flow_id;
1889 struct dpni_queue cfg;
1893 memset(&cfg, 0, sizeof(struct dpni_queue));
1894 options = DPNI_QUEUE_OPT_DEST;
1895 cfg.destination.type = DPNI_DEST_NONE;
1897 ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
1898 dpaa2_ethq->tc_index, flow_id, options, &cfg);
1900 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
1906 dpaa2_dev_verify_filter_ops(enum rte_filter_op filter_op)
1910 for (i = 0; i < RTE_DIM(dpaa2_supported_filter_ops); i++) {
1911 if (dpaa2_supported_filter_ops[i] == filter_op)
1918 dpaa2_dev_flow_ctrl(struct rte_eth_dev *dev,
1919 enum rte_filter_type filter_type,
1920 enum rte_filter_op filter_op,
1928 switch (filter_type) {
1929 case RTE_ETH_FILTER_GENERIC:
1930 if (dpaa2_dev_verify_filter_ops(filter_op) < 0) {
1934 *(const void **)arg = &dpaa2_flow_ops;
1935 dpaa2_filter_type |= filter_type;
1938 RTE_LOG(ERR, PMD, "Filter type (%d) not supported",
1946 static struct eth_dev_ops dpaa2_ethdev_ops = {
1947 .dev_configure = dpaa2_eth_dev_configure,
1948 .dev_start = dpaa2_dev_start,
1949 .dev_stop = dpaa2_dev_stop,
1950 .dev_close = dpaa2_dev_close,
1951 .promiscuous_enable = dpaa2_dev_promiscuous_enable,
1952 .promiscuous_disable = dpaa2_dev_promiscuous_disable,
1953 .allmulticast_enable = dpaa2_dev_allmulticast_enable,
1954 .allmulticast_disable = dpaa2_dev_allmulticast_disable,
1955 .dev_set_link_up = dpaa2_dev_set_link_up,
1956 .dev_set_link_down = dpaa2_dev_set_link_down,
1957 .link_update = dpaa2_dev_link_update,
1958 .stats_get = dpaa2_dev_stats_get,
1959 .xstats_get = dpaa2_dev_xstats_get,
1960 .xstats_get_by_id = dpaa2_xstats_get_by_id,
1961 .xstats_get_names_by_id = dpaa2_xstats_get_names_by_id,
1962 .xstats_get_names = dpaa2_xstats_get_names,
1963 .stats_reset = dpaa2_dev_stats_reset,
1964 .xstats_reset = dpaa2_dev_stats_reset,
1965 .fw_version_get = dpaa2_fw_version_get,
1966 .dev_infos_get = dpaa2_dev_info_get,
1967 .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
1968 .mtu_set = dpaa2_dev_mtu_set,
1969 .vlan_filter_set = dpaa2_vlan_filter_set,
1970 .vlan_offload_set = dpaa2_vlan_offload_set,
1971 .vlan_tpid_set = dpaa2_vlan_tpid_set,
1972 .rx_queue_setup = dpaa2_dev_rx_queue_setup,
1973 .rx_queue_release = dpaa2_dev_rx_queue_release,
1974 .tx_queue_setup = dpaa2_dev_tx_queue_setup,
1975 .tx_queue_release = dpaa2_dev_tx_queue_release,
1976 .rx_queue_count = dpaa2_dev_rx_queue_count,
1977 .flow_ctrl_get = dpaa2_flow_ctrl_get,
1978 .flow_ctrl_set = dpaa2_flow_ctrl_set,
1979 .mac_addr_add = dpaa2_dev_add_mac_addr,
1980 .mac_addr_remove = dpaa2_dev_remove_mac_addr,
1981 .mac_addr_set = dpaa2_dev_set_mac_addr,
1982 .rss_hash_update = dpaa2_dev_rss_hash_update,
1983 .rss_hash_conf_get = dpaa2_dev_rss_hash_conf_get,
1984 .filter_ctrl = dpaa2_dev_flow_ctrl,
1987 /* Populate the mac address from physically available (u-boot/firmware) and/or
1988 * one set by higher layers like MC (restool) etc.
1989 * Returns the table of MAC entries (multiple entries)
1992 populate_mac_addr(struct fsl_mc_io *dpni_dev, struct dpaa2_dev_priv *priv,
1993 struct ether_addr *mac_entry)
1996 struct ether_addr phy_mac, prime_mac;
1998 memset(&phy_mac, 0, sizeof(struct ether_addr));
1999 memset(&prime_mac, 0, sizeof(struct ether_addr));
2001 /* Get the physical device MAC address */
2002 ret = dpni_get_port_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2003 phy_mac.addr_bytes);
2005 DPAA2_PMD_ERR("DPNI get physical port MAC failed: %d", ret);
2009 ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2010 prime_mac.addr_bytes);
2012 DPAA2_PMD_ERR("DPNI get Prime port MAC failed: %d", ret);
2016 /* Now that both MAC have been obtained, do:
2017 * if not_empty_mac(phy) && phy != Prime, overwrite prime with Phy
2019 * If empty_mac(phy), return prime.
2020 * if both are empty, create random MAC, set as prime and return
2022 if (!is_zero_ether_addr(&phy_mac)) {
2023 /* If the addresses are not same, overwrite prime */
2024 if (!is_same_ether_addr(&phy_mac, &prime_mac)) {
2025 ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2027 phy_mac.addr_bytes);
2029 DPAA2_PMD_ERR("Unable to set MAC Address: %d",
2033 memcpy(&prime_mac, &phy_mac, sizeof(struct ether_addr));
2035 } else if (is_zero_ether_addr(&prime_mac)) {
2036 /* In case phys and prime, both are zero, create random MAC */
2037 eth_random_addr(prime_mac.addr_bytes);
2038 ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2040 prime_mac.addr_bytes);
2042 DPAA2_PMD_ERR("Unable to set MAC Address: %d", ret);
2047 /* prime_mac the final MAC address */
2048 memcpy(mac_entry, &prime_mac, sizeof(struct ether_addr));
2056 check_devargs_handler(__rte_unused const char *key, const char *value,
2057 __rte_unused void *opaque)
2059 if (strcmp(value, "1"))
2066 dpaa2_get_devargs(struct rte_devargs *devargs, const char *key)
2068 struct rte_kvargs *kvlist;
2073 kvlist = rte_kvargs_parse(devargs->args, NULL);
2077 if (!rte_kvargs_count(kvlist, key)) {
2078 rte_kvargs_free(kvlist);
2082 if (rte_kvargs_process(kvlist, key,
2083 check_devargs_handler, NULL) < 0) {
2084 rte_kvargs_free(kvlist);
2087 rte_kvargs_free(kvlist);
2093 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
2095 struct rte_device *dev = eth_dev->device;
2096 struct rte_dpaa2_device *dpaa2_dev;
2097 struct fsl_mc_io *dpni_dev;
2098 struct dpni_attr attr;
2099 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2100 struct dpni_buffer_layout layout;
2103 PMD_INIT_FUNC_TRACE();
2105 /* For secondary processes, the primary has done all the work */
2106 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2107 /* In case of secondary, only burst and ops API need to be
2110 eth_dev->dev_ops = &dpaa2_ethdev_ops;
2111 if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE))
2112 eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2114 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2115 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2119 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
2121 hw_id = dpaa2_dev->object_id;
2123 dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
2125 DPAA2_PMD_ERR("Memory allocation failed for dpni device");
2129 dpni_dev->regs = rte_mcp_ptr_list[0];
2130 ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
2133 "Failure in opening dpni@%d with err code %d",
2139 /* Clean the device first */
2140 ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
2142 DPAA2_PMD_ERR("Failure cleaning dpni@%d with err code %d",
2147 ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
2150 "Failure in get dpni@%d attribute, err code %d",
2155 priv->num_rx_tc = attr.num_rx_tcs;
2157 for (i = 0; i < attr.num_rx_tcs; i++)
2158 priv->nb_rx_queues += attr.num_queues;
2160 /* Using number of TX queues as number of TX TCs */
2161 priv->nb_tx_queues = attr.num_tx_tcs;
2163 DPAA2_PMD_DEBUG("RX-TC= %d, nb_rx_queues= %d, nb_tx_queues=%d",
2164 priv->num_rx_tc, priv->nb_rx_queues,
2165 priv->nb_tx_queues);
2167 priv->hw = dpni_dev;
2168 priv->hw_id = hw_id;
2169 priv->options = attr.options;
2170 priv->max_mac_filters = attr.mac_filter_entries;
2171 priv->max_vlan_filters = attr.vlan_filter_entries;
2174 /* Allocate memory for hardware structure for queues */
2175 ret = dpaa2_alloc_rx_tx_queues(eth_dev);
2177 DPAA2_PMD_ERR("Queue allocation Failed");
2181 /* Allocate memory for storing MAC addresses.
2182 * Table of mac_filter_entries size is allocated so that RTE ether lib
2183 * can add MAC entries when rte_eth_dev_mac_addr_add is called.
2185 eth_dev->data->mac_addrs = rte_zmalloc("dpni",
2186 ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
2187 if (eth_dev->data->mac_addrs == NULL) {
2189 "Failed to allocate %d bytes needed to store MAC addresses",
2190 ETHER_ADDR_LEN * attr.mac_filter_entries);
2195 ret = populate_mac_addr(dpni_dev, priv, ð_dev->data->mac_addrs[0]);
2197 DPAA2_PMD_ERR("Unable to fetch MAC Address for device");
2198 rte_free(eth_dev->data->mac_addrs);
2199 eth_dev->data->mac_addrs = NULL;
2203 /* ... tx buffer layout ... */
2204 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2205 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2206 layout.pass_frame_status = 1;
2207 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2208 DPNI_QUEUE_TX, &layout);
2210 DPAA2_PMD_ERR("Error (%d) in setting tx buffer layout", ret);
2214 /* ... tx-conf and error buffer layout ... */
2215 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2216 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2217 layout.pass_frame_status = 1;
2218 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2219 DPNI_QUEUE_TX_CONFIRM, &layout);
2221 DPAA2_PMD_ERR("Error (%d) in setting tx-conf buffer layout",
2226 eth_dev->dev_ops = &dpaa2_ethdev_ops;
2228 if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE)) {
2229 eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2230 DPAA2_PMD_INFO("Loopback mode");
2232 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2234 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2236 /*Init fields w.r.t. classficaition*/
2237 memset(&priv->extract.qos_key_cfg, 0, sizeof(struct dpkg_profile_cfg));
2238 priv->extract.qos_extract_param = (size_t)rte_malloc(NULL, 256, 64);
2239 if (!priv->extract.qos_extract_param) {
2240 DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow "
2241 " classificaiton ", ret);
2244 for (i = 0; i < MAX_TCS; i++) {
2245 memset(&priv->extract.fs_key_cfg[i], 0,
2246 sizeof(struct dpkg_profile_cfg));
2247 priv->extract.fs_extract_param[i] =
2248 (size_t)rte_malloc(NULL, 256, 64);
2249 if (!priv->extract.fs_extract_param[i]) {
2250 DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow classificaiton",
2256 RTE_LOG(INFO, PMD, "%s: netdev created\n", eth_dev->data->name);
2259 dpaa2_dev_uninit(eth_dev);
2264 dpaa2_dev_uninit(struct rte_eth_dev *eth_dev)
2266 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2267 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
2270 PMD_INIT_FUNC_TRACE();
2272 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2276 DPAA2_PMD_WARN("Already closed or not started");
2280 dpaa2_dev_close(eth_dev);
2282 dpaa2_free_rx_tx_queues(eth_dev);
2284 /* Close the device at underlying layer*/
2285 ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
2288 "Failure closing dpni device with err code %d",
2292 /* Free the allocated memory for ethernet private data and dpni*/
2296 for (i = 0; i < MAX_TCS; i++) {
2297 if (priv->extract.fs_extract_param[i])
2298 rte_free((void *)(size_t)priv->extract.fs_extract_param[i]);
2301 if (priv->extract.qos_extract_param)
2302 rte_free((void *)(size_t)priv->extract.qos_extract_param);
2304 eth_dev->dev_ops = NULL;
2305 eth_dev->rx_pkt_burst = NULL;
2306 eth_dev->tx_pkt_burst = NULL;
2308 DPAA2_PMD_INFO("%s: netdev deleted", eth_dev->data->name);
2313 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
2314 struct rte_dpaa2_device *dpaa2_dev)
2316 struct rte_eth_dev *eth_dev;
2319 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2320 eth_dev = rte_eth_dev_allocate(dpaa2_dev->device.name);
2323 eth_dev->data->dev_private = rte_zmalloc(
2324 "ethdev private structure",
2325 sizeof(struct dpaa2_dev_priv),
2326 RTE_CACHE_LINE_SIZE);
2327 if (eth_dev->data->dev_private == NULL) {
2329 "Unable to allocate memory for private data");
2330 rte_eth_dev_release_port(eth_dev);
2334 eth_dev = rte_eth_dev_attach_secondary(dpaa2_dev->device.name);
2339 eth_dev->device = &dpaa2_dev->device;
2341 dpaa2_dev->eth_dev = eth_dev;
2342 eth_dev->data->rx_mbuf_alloc_failed = 0;
2344 if (dpaa2_drv->drv_flags & RTE_DPAA2_DRV_INTR_LSC)
2345 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
2347 /* Invoke PMD device initialization function */
2348 diag = dpaa2_dev_init(eth_dev);
2350 rte_eth_dev_probing_finish(eth_dev);
2354 rte_eth_dev_release_port(eth_dev);
2359 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
2361 struct rte_eth_dev *eth_dev;
2363 eth_dev = dpaa2_dev->eth_dev;
2364 dpaa2_dev_uninit(eth_dev);
2366 rte_eth_dev_release_port(eth_dev);
2371 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
2372 .drv_flags = RTE_DPAA2_DRV_INTR_LSC | RTE_DPAA2_DRV_IOVA_AS_VA,
2373 .drv_type = DPAA2_ETH,
2374 .probe = rte_dpaa2_probe,
2375 .remove = rte_dpaa2_remove,
2378 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);
2379 RTE_PMD_REGISTER_PARAM_STRING(net_dpaa2,
2380 DRIVER_LOOPBACK_MODE "=<int>");
2381 RTE_INIT(dpaa2_pmd_init_log)
2383 dpaa2_logtype_pmd = rte_log_register("pmd.net.dpaa2");
2384 if (dpaa2_logtype_pmd >= 0)
2385 rte_log_set_level(dpaa2_logtype_pmd, RTE_LOG_NOTICE);