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 <rte_fslmc.h>
24 #include <mc/fsl_dpcon.h>
25 #include <portal/dpaa2_hw_pvt.h>
26 #include "dpaa2_eventdev.h"
27 #include "dpaa2_eventdev_logs.h"
29 TAILQ_HEAD(dpcon_dev_list, dpaa2_dpcon_dev);
30 static struct dpcon_dev_list dpcon_dev_list
31 = TAILQ_HEAD_INITIALIZER(dpcon_dev_list); /*!< DPCON device list */
34 rte_dpaa2_create_dpcon_device(int dev_fd __rte_unused,
35 struct vfio_device_info *obj_info __rte_unused,
38 struct dpaa2_dpcon_dev *dpcon_node;
39 struct dpcon_attr attr;
42 /* Allocate DPAA2 dpcon handle */
43 dpcon_node = rte_malloc(NULL, sizeof(struct dpaa2_dpcon_dev), 0);
46 "Memory allocation failed for dpcon device");
50 /* Open the dpcon object */
51 dpcon_node->dpcon.regs = rte_mcp_ptr_list[MC_PORTAL_INDEX];
52 ret = dpcon_open(&dpcon_node->dpcon,
53 CMD_PRI_LOW, dpcon_id, &dpcon_node->token);
55 DPAA2_EVENTDEV_ERR("Unable to open dpcon device: err(%d)",
61 /* Get the device attributes */
62 ret = dpcon_get_attributes(&dpcon_node->dpcon,
63 CMD_PRI_LOW, dpcon_node->token, &attr);
65 DPAA2_EVENTDEV_ERR("dpcon attribute fetch failed: err(%d)",
71 /* Updating device specific private information*/
72 dpcon_node->qbman_ch_id = attr.qbman_ch_id;
73 dpcon_node->num_priorities = attr.num_priorities;
74 dpcon_node->dpcon_id = dpcon_id;
75 rte_atomic16_init(&dpcon_node->in_use);
77 TAILQ_INSERT_TAIL(&dpcon_dev_list, dpcon_node, next);
82 struct dpaa2_dpcon_dev *rte_dpaa2_alloc_dpcon_dev(void)
84 struct dpaa2_dpcon_dev *dpcon_dev = NULL;
86 /* Get DPCON dev handle from list using index */
87 TAILQ_FOREACH(dpcon_dev, &dpcon_dev_list, next) {
88 if (dpcon_dev && rte_atomic16_test_and_set(&dpcon_dev->in_use))
95 void rte_dpaa2_free_dpcon_dev(struct dpaa2_dpcon_dev *dpcon)
97 struct dpaa2_dpcon_dev *dpcon_dev = NULL;
99 /* Match DPCON handle and mark it free */
100 TAILQ_FOREACH(dpcon_dev, &dpcon_dev_list, next) {
101 if (dpcon_dev == dpcon) {
102 rte_atomic16_dec(&dpcon_dev->in_use);
108 static struct rte_dpaa2_object rte_dpaa2_dpcon_obj = {
109 .dev_type = DPAA2_CON,
110 .create = rte_dpaa2_create_dpcon_device,
113 RTE_PMD_REGISTER_DPAA2_OBJECT(dpcon, rte_dpaa2_dpcon_obj);