6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Freescale Semiconductor, Inc nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/types.h>
41 #include <rte_malloc.h>
42 #include <rte_memcpy.h>
43 #include <rte_string_fns.h>
44 #include <rte_cycles.h>
45 #include <rte_kvargs.h>
47 #include <rte_ethdev.h>
49 #include <fslmc_logs.h>
50 #include <rte_fslmc.h>
51 #include <mc/fsl_dpci.h>
52 #include "portal/dpaa2_hw_pvt.h"
53 #include "portal/dpaa2_hw_dpio.h"
55 TAILQ_HEAD(dpci_dev_list, dpaa2_dpci_dev);
56 static struct dpci_dev_list dpci_dev_list
57 = TAILQ_HEAD_INITIALIZER(dpci_dev_list); /*!< DPCI device list */
60 rte_dpaa2_create_dpci_device(int vdev_fd __rte_unused,
61 struct vfio_device_info *obj_info __rte_unused,
64 struct dpaa2_dpci_dev *dpci_node;
65 struct dpci_attr attr;
66 struct dpci_rx_queue_cfg rx_queue_cfg;
67 struct dpci_rx_queue_attr rx_attr;
70 /* Allocate DPAA2 dpci handle */
71 dpci_node = rte_malloc(NULL, sizeof(struct dpaa2_dpci_dev), 0);
73 PMD_INIT_LOG(ERR, "Memory allocation failed for DPCI Device");
77 /* Open the dpci object */
78 dpci_node->dpci.regs = rte_mcp_ptr_list[MC_PORTAL_INDEX];
79 ret = dpci_open(&dpci_node->dpci,
80 CMD_PRI_LOW, dpci_id, &dpci_node->token);
82 PMD_INIT_LOG(ERR, "Resource alloc failure with err code: %d",
88 /* Get the device attributes */
89 ret = dpci_get_attributes(&dpci_node->dpci,
90 CMD_PRI_LOW, dpci_node->token, &attr);
92 PMD_INIT_LOG(ERR, "Reading device failed with err code: %d",
98 /* Set up the Rx Queue */
99 memset(&rx_queue_cfg, 0, sizeof(struct dpci_rx_queue_cfg));
100 ret = dpci_set_rx_queue(&dpci_node->dpci,
105 PMD_INIT_LOG(ERR, "Setting Rx queue failed with err code: %d",
111 /* Enable the device */
112 ret = dpci_enable(&dpci_node->dpci,
113 CMD_PRI_LOW, dpci_node->token);
115 PMD_INIT_LOG(ERR, "Enabling device failed with err code: %d",
121 for (i = 0; i < DPAA2_DPCI_MAX_QUEUES; i++) {
122 /* Get the Rx FQID's */
123 ret = dpci_get_rx_queue(&dpci_node->dpci,
129 "Reading device failed with err code: %d",
135 dpci_node->queue[i].fqid = rx_attr.fqid;
138 dpci_node->dpci_id = dpci_id;
139 rte_atomic16_init(&dpci_node->in_use);
141 TAILQ_INSERT_TAIL(&dpci_dev_list, dpci_node, next);
143 RTE_LOG(DEBUG, PMD, "DPAA2: Added [dpci.%d]\n", dpci_id);
148 struct dpaa2_dpci_dev *rte_dpaa2_alloc_dpci_dev(void)
150 struct dpaa2_dpci_dev *dpci_dev = NULL;
152 /* Get DPCI dev handle from list using index */
153 TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) {
154 if (dpci_dev && rte_atomic16_test_and_set(&dpci_dev->in_use))
161 void rte_dpaa2_free_dpci_dev(struct dpaa2_dpci_dev *dpci)
163 struct dpaa2_dpci_dev *dpci_dev = NULL;
165 /* Match DPCI handle and mark it free */
166 TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) {
167 if (dpci_dev == dpci) {
168 rte_atomic16_dec(&dpci_dev->in_use);
174 static struct rte_dpaa2_object rte_dpaa2_dpci_obj = {
175 .dev_type = DPAA2_CI,
176 .create = rte_dpaa2_create_dpci_device,
179 RTE_PMD_REGISTER_DPAA2_OBJECT(dpci, rte_dpaa2_dpci_obj);