1 /* SPDX-License-Identifier: BSD-3-Clause
15 #include <rte_malloc.h>
16 #include <rte_memcpy.h>
17 #include <rte_string_fns.h>
18 #include <rte_cycles.h>
19 #include <rte_kvargs.h>
21 #include <rte_ethdev_driver.h>
23 #include <fslmc_logs.h>
24 #include <rte_fslmc.h>
25 #include <mc/fsl_dpci.h>
26 #include "portal/dpaa2_hw_pvt.h"
27 #include "portal/dpaa2_hw_dpio.h"
29 TAILQ_HEAD(dpci_dev_list, dpaa2_dpci_dev);
30 static struct dpci_dev_list dpci_dev_list
31 = TAILQ_HEAD_INITIALIZER(dpci_dev_list); /*!< DPCI device list */
34 rte_dpaa2_create_dpci_device(int vdev_fd __rte_unused,
35 struct vfio_device_info *obj_info __rte_unused,
38 struct dpaa2_dpci_dev *dpci_node;
39 struct dpci_attr attr;
40 struct dpci_rx_queue_cfg rx_queue_cfg;
41 struct dpci_rx_queue_attr rx_attr;
44 /* Allocate DPAA2 dpci handle */
45 dpci_node = rte_malloc(NULL, sizeof(struct dpaa2_dpci_dev), 0);
47 PMD_INIT_LOG(ERR, "Memory allocation failed for DPCI Device");
51 /* Open the dpci object */
52 dpci_node->dpci.regs = rte_mcp_ptr_list[MC_PORTAL_INDEX];
53 ret = dpci_open(&dpci_node->dpci,
54 CMD_PRI_LOW, dpci_id, &dpci_node->token);
56 PMD_INIT_LOG(ERR, "Resource alloc failure with err code: %d",
62 /* Get the device attributes */
63 ret = dpci_get_attributes(&dpci_node->dpci,
64 CMD_PRI_LOW, dpci_node->token, &attr);
66 PMD_INIT_LOG(ERR, "Reading device failed with err code: %d",
72 /* Set up the Rx Queue */
73 memset(&rx_queue_cfg, 0, sizeof(struct dpci_rx_queue_cfg));
74 ret = dpci_set_rx_queue(&dpci_node->dpci,
79 PMD_INIT_LOG(ERR, "Setting Rx queue failed with err code: %d",
85 /* Enable the device */
86 ret = dpci_enable(&dpci_node->dpci,
87 CMD_PRI_LOW, dpci_node->token);
89 PMD_INIT_LOG(ERR, "Enabling device failed with err code: %d",
95 for (i = 0; i < DPAA2_DPCI_MAX_QUEUES; i++) {
96 /* Get the Rx FQID's */
97 ret = dpci_get_rx_queue(&dpci_node->dpci,
103 "Reading device failed with err code: %d",
109 dpci_node->queue[i].fqid = rx_attr.fqid;
112 dpci_node->dpci_id = dpci_id;
113 rte_atomic16_init(&dpci_node->in_use);
115 TAILQ_INSERT_TAIL(&dpci_dev_list, dpci_node, next);
117 RTE_LOG(DEBUG, PMD, "DPAA2: Added [dpci.%d]\n", dpci_id);
122 struct dpaa2_dpci_dev *rte_dpaa2_alloc_dpci_dev(void)
124 struct dpaa2_dpci_dev *dpci_dev = NULL;
126 /* Get DPCI dev handle from list using index */
127 TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) {
128 if (dpci_dev && rte_atomic16_test_and_set(&dpci_dev->in_use))
135 void rte_dpaa2_free_dpci_dev(struct dpaa2_dpci_dev *dpci)
137 struct dpaa2_dpci_dev *dpci_dev = NULL;
139 /* Match DPCI handle and mark it free */
140 TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) {
141 if (dpci_dev == dpci) {
142 rte_atomic16_dec(&dpci_dev->in_use);
148 static struct rte_dpaa2_object rte_dpaa2_dpci_obj = {
149 .dev_type = DPAA2_CI,
150 .create = rte_dpaa2_create_dpci_device,
153 RTE_PMD_REGISTER_DPAA2_OBJECT(dpci, rte_dpaa2_dpci_obj);