1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
10 #include <sys/types.h>
16 #include <rte_malloc.h>
17 #include <rte_memcpy.h>
18 #include <rte_string_fns.h>
19 #include <rte_cycles.h>
20 #include <rte_kvargs.h>
22 #include <rte_ethdev_driver.h>
23 #include <rte_mbuf_pool_ops.h>
25 #include <fslmc_logs.h>
26 #include <rte_fslmc.h>
27 #include <mc/fsl_dpbp.h>
28 #include "portal/dpaa2_hw_pvt.h"
29 #include "portal/dpaa2_hw_dpio.h"
31 TAILQ_HEAD(dpbp_dev_list, dpaa2_dpbp_dev);
32 static struct dpbp_dev_list dpbp_dev_list
33 = TAILQ_HEAD_INITIALIZER(dpbp_dev_list); /*!< DPBP device list */
36 dpaa2_create_dpbp_device(int vdev_fd __rte_unused,
37 struct vfio_device_info *obj_info __rte_unused,
40 struct dpaa2_dpbp_dev *dpbp_node;
42 static int register_once;
44 /* Allocate DPAA2 dpbp handle */
45 dpbp_node = rte_malloc(NULL, sizeof(struct dpaa2_dpbp_dev), 0);
47 PMD_INIT_LOG(ERR, "Memory allocation failed for DPBP Device");
51 /* Open the dpbp object */
52 dpbp_node->dpbp.regs = rte_mcp_ptr_list[MC_PORTAL_INDEX];
53 ret = dpbp_open(&dpbp_node->dpbp,
54 CMD_PRI_LOW, dpbp_id, &dpbp_node->token);
56 PMD_INIT_LOG(ERR, "Resource alloc failure with err code: %d",
62 /* Clean the device first */
63 ret = dpbp_reset(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_node->token);
65 PMD_INIT_LOG(ERR, "Failure cleaning dpbp device with"
66 " error code %d\n", ret);
67 dpbp_close(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_node->token);
72 dpbp_node->dpbp_id = dpbp_id;
73 rte_atomic16_init(&dpbp_node->in_use);
75 TAILQ_INSERT_TAIL(&dpbp_dev_list, dpbp_node, next);
77 RTE_LOG(DEBUG, PMD, "DPAA2: Added [dpbp.%d]\n", dpbp_id);
80 if (rte_mbuf_set_platform_mempool_ops(DPAA2_MEMPOOL_OPS_NAME))
87 struct dpaa2_dpbp_dev *dpaa2_alloc_dpbp_dev(void)
89 struct dpaa2_dpbp_dev *dpbp_dev = NULL;
91 /* Get DPBP dev handle from list using index */
92 TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) {
93 if (dpbp_dev && rte_atomic16_test_and_set(&dpbp_dev->in_use))
100 void dpaa2_free_dpbp_dev(struct dpaa2_dpbp_dev *dpbp)
102 struct dpaa2_dpbp_dev *dpbp_dev = NULL;
104 /* Match DPBP handle and mark it free */
105 TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) {
106 if (dpbp_dev == dpbp) {
107 rte_atomic16_dec(&dpbp_dev->in_use);
113 int dpaa2_dpbp_supported(void)
115 if (TAILQ_EMPTY(&dpbp_dev_list))
120 static struct rte_dpaa2_object rte_dpaa2_dpbp_obj = {
121 .dev_type = DPAA2_BPOOL,
122 .create = dpaa2_create_dpbp_device,
125 RTE_PMD_REGISTER_DPAA2_OBJECT(dpbp, rte_dpaa2_dpbp_obj);