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 DPAA2_BUS_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 DPAA2_BUS_ERR("Resource alloc failure with err code: %d", ret);
61 /* Get the device attributes */
62 ret = dpci_get_attributes(&dpci_node->dpci,
63 CMD_PRI_LOW, dpci_node->token, &attr);
65 DPAA2_BUS_ERR("Reading device failed with err code: %d", ret);
70 /* Set up the Rx Queue */
71 memset(&rx_queue_cfg, 0, sizeof(struct dpci_rx_queue_cfg));
72 ret = dpci_set_rx_queue(&dpci_node->dpci,
77 DPAA2_BUS_ERR("Setting Rx queue failed with err code: %d",
83 /* Enable the device */
84 ret = dpci_enable(&dpci_node->dpci,
85 CMD_PRI_LOW, dpci_node->token);
87 DPAA2_BUS_ERR("Enabling device failed with err code: %d", ret);
92 for (i = 0; i < DPAA2_DPCI_MAX_QUEUES; i++) {
93 /* Get the Rx FQID's */
94 ret = dpci_get_rx_queue(&dpci_node->dpci,
99 DPAA2_BUS_ERR("Rx queue fetch failed with err code:"
105 dpci_node->queue[i].fqid = rx_attr.fqid;
108 dpci_node->dpci_id = dpci_id;
109 rte_atomic16_init(&dpci_node->in_use);
111 TAILQ_INSERT_TAIL(&dpci_dev_list, dpci_node, next);
116 struct dpaa2_dpci_dev *rte_dpaa2_alloc_dpci_dev(void)
118 struct dpaa2_dpci_dev *dpci_dev = NULL;
120 /* Get DPCI dev handle from list using index */
121 TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) {
122 if (dpci_dev && rte_atomic16_test_and_set(&dpci_dev->in_use))
129 void rte_dpaa2_free_dpci_dev(struct dpaa2_dpci_dev *dpci)
131 struct dpaa2_dpci_dev *dpci_dev = NULL;
133 /* Match DPCI handle and mark it free */
134 TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) {
135 if (dpci_dev == dpci) {
136 rte_atomic16_dec(&dpci_dev->in_use);
142 static struct rte_dpaa2_object rte_dpaa2_dpci_obj = {
143 .dev_type = DPAA2_CI,
144 .create = rte_dpaa2_create_dpci_device,
147 RTE_PMD_REGISTER_DPAA2_OBJECT(dpci, rte_dpaa2_dpci_obj);