4 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
5 * Copyright (c) 2016 NXP. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Freescale Semiconductor, Inc nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <sys/types.h>
42 #include <rte_malloc.h>
43 #include <rte_memcpy.h>
44 #include <rte_string_fns.h>
45 #include <rte_cycles.h>
46 #include <rte_kvargs.h>
48 #include <rte_ethdev.h>
50 #include <fslmc_logs.h>
51 #include <fslmc_vfio.h>
52 #include <mc/fsl_dpbp.h>
53 #include "portal/dpaa2_hw_pvt.h"
54 #include "portal/dpaa2_hw_dpio.h"
56 TAILQ_HEAD(dpbp_device_list, dpaa2_dpbp_dev);
57 static struct dpbp_device_list *dpbp_dev_list; /*!< DPBP device list */
60 dpaa2_create_dpbp_device(
63 struct dpaa2_dpbp_dev *dpbp_node;
67 dpbp_dev_list = malloc(sizeof(struct dpbp_device_list));
69 PMD_INIT_LOG(ERR, "Memory alloc failed in DPBP list\n");
72 /* Initialize the DPBP List */
73 TAILQ_INIT(dpbp_dev_list);
76 /* Allocate DPAA2 dpbp handle */
77 dpbp_node = (struct dpaa2_dpbp_dev *)
78 malloc(sizeof(struct dpaa2_dpbp_dev));
80 PMD_INIT_LOG(ERR, "Memory allocation failed for DPBP Device");
84 /* Open the dpbp object */
85 dpbp_node->dpbp.regs = rte_mcp_ptr_list[MC_PORTAL_INDEX];
86 ret = dpbp_open(&dpbp_node->dpbp,
87 CMD_PRI_LOW, dpbp_id, &dpbp_node->token);
89 PMD_INIT_LOG(ERR, "Resource alloc failure with err code: %d",
95 /* Clean the device first */
96 ret = dpbp_reset(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_node->token);
98 PMD_INIT_LOG(ERR, "Failure cleaning dpbp device with"
99 " error code %d\n", ret);
100 dpbp_close(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_node->token);
105 dpbp_node->dpbp_id = dpbp_id;
106 rte_atomic16_init(&dpbp_node->in_use);
108 TAILQ_INSERT_HEAD(dpbp_dev_list, dpbp_node, next);
110 PMD_INIT_LOG(DEBUG, "Buffer pool resource initialized %d", dpbp_id);
115 struct dpaa2_dpbp_dev *dpaa2_alloc_dpbp_dev(void)
117 struct dpaa2_dpbp_dev *dpbp_dev = NULL;
119 /* Get DPBP dev handle from list using index */
120 TAILQ_FOREACH(dpbp_dev, dpbp_dev_list, next) {
121 if (dpbp_dev && rte_atomic16_test_and_set(&dpbp_dev->in_use))
128 void dpaa2_free_dpbp_dev(struct dpaa2_dpbp_dev *dpbp)
130 struct dpaa2_dpbp_dev *dpbp_dev = NULL;
132 /* Match DPBP handle and mark it free */
133 TAILQ_FOREACH(dpbp_dev, dpbp_dev_list, next) {
134 if (dpbp_dev == dpbp) {
135 rte_atomic16_dec(&dpbp_dev->in_use);