4 * Copyright (c) 2016 Freescale Semiconductor, Inc. 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_dev_list, dpaa2_dpbp_dev);
57 static struct dpbp_dev_list dpbp_dev_list
58 = TAILQ_HEAD_INITIALIZER(dpbp_dev_list); /*!< DPBP device list */
61 dpaa2_create_dpbp_device(struct fslmc_vfio_device *vdev __rte_unused,
62 struct vfio_device_info *obj_info __rte_unused,
65 struct dpaa2_dpbp_dev *dpbp_node;
68 /* Allocate DPAA2 dpbp handle */
69 dpbp_node = rte_malloc(NULL, sizeof(struct dpaa2_dpbp_dev), 0);
71 PMD_INIT_LOG(ERR, "Memory allocation failed for DPBP Device");
75 /* Open the dpbp object */
76 dpbp_node->dpbp.regs = rte_mcp_ptr_list[MC_PORTAL_INDEX];
77 ret = dpbp_open(&dpbp_node->dpbp,
78 CMD_PRI_LOW, dpbp_id, &dpbp_node->token);
80 PMD_INIT_LOG(ERR, "Resource alloc failure with err code: %d",
86 /* Clean the device first */
87 ret = dpbp_reset(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_node->token);
89 PMD_INIT_LOG(ERR, "Failure cleaning dpbp device with"
90 " error code %d\n", ret);
91 dpbp_close(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_node->token);
96 dpbp_node->dpbp_id = dpbp_id;
97 rte_atomic16_init(&dpbp_node->in_use);
99 TAILQ_INSERT_TAIL(&dpbp_dev_list, dpbp_node, next);
101 PMD_INIT_LOG(DEBUG, "DPAA2: Added [dpbp.%d]", dpbp_id);
106 struct dpaa2_dpbp_dev *dpaa2_alloc_dpbp_dev(void)
108 struct dpaa2_dpbp_dev *dpbp_dev = NULL;
110 /* Get DPBP dev handle from list using index */
111 TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) {
112 if (dpbp_dev && rte_atomic16_test_and_set(&dpbp_dev->in_use))
119 void dpaa2_free_dpbp_dev(struct dpaa2_dpbp_dev *dpbp)
121 struct dpaa2_dpbp_dev *dpbp_dev = NULL;
123 /* Match DPBP handle and mark it free */
124 TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) {
125 if (dpbp_dev == dpbp) {
126 rte_atomic16_dec(&dpbp_dev->in_use);
132 static struct rte_dpaa2_object rte_dpaa2_dpbp_obj = {
133 .object_id = DPAA2_MC_DPBP_DEVID,
134 .create = dpaa2_create_dpbp_device,
137 RTE_PMD_REGISTER_DPAA2_OBJECT(dpbp, rte_dpaa2_dpbp_obj);