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 <ethdev_driver.h>
23 #include <fslmc_logs.h>
24 #include <rte_fslmc.h>
25 #include <mc/fsl_dpci.h>
26 #include "portal/dpaa2_hw_pvt.h"
27 #include "portal/dpaa2_hw_dpio.h"
29 TAILQ_HEAD(dpci_dev_list, dpaa2_dpci_dev);
30 static struct dpci_dev_list dpci_dev_list
31 = TAILQ_HEAD_INITIALIZER(dpci_dev_list); /*!< DPCI device list */
34 rte_dpaa2_create_dpci_device(int vdev_fd __rte_unused,
35 struct vfio_device_info *obj_info __rte_unused,
38 struct dpaa2_dpci_dev *dpci_node;
39 struct dpci_attr attr;
40 struct dpci_rx_queue_cfg rx_queue_cfg;
41 struct dpci_rx_queue_attr rx_attr;
42 struct dpci_tx_queue_attr tx_attr;
45 /* Allocate DPAA2 dpci handle */
46 dpci_node = rte_malloc(NULL, sizeof(struct dpaa2_dpci_dev), 0);
48 DPAA2_BUS_ERR("Memory allocation failed for DPCI Device");
52 /* Open the dpci object */
53 dpci_node->dpci.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
54 ret = dpci_open(&dpci_node->dpci,
55 CMD_PRI_LOW, dpci_id, &dpci_node->token);
57 DPAA2_BUS_ERR("Resource alloc failure with err code: %d", ret);
61 /* Get the device attributes */
62 ret = dpci_get_attributes(&dpci_node->dpci,
63 CMD_PRI_LOW, dpci_node->token, &attr);
65 DPAA2_BUS_ERR("Reading device failed with err code: %d", ret);
69 for (i = 0; i < DPAA2_DPCI_MAX_QUEUES; i++) {
70 struct dpaa2_queue *rxq;
72 memset(&rx_queue_cfg, 0, sizeof(struct dpci_rx_queue_cfg));
73 ret = dpci_set_rx_queue(&dpci_node->dpci,
78 DPAA2_BUS_ERR("Setting Rx queue failed with err code: %d",
83 /* Allocate DQ storage for the DPCI Rx queues */
84 rxq = &(dpci_node->rx_queue[i]);
85 rxq->q_storage = rte_malloc("dq_storage",
86 sizeof(struct queue_storage_info_t),
88 if (!rxq->q_storage) {
89 DPAA2_BUS_ERR("q_storage allocation failed\n");
94 memset(rxq->q_storage, 0, sizeof(struct queue_storage_info_t));
95 ret = dpaa2_alloc_dq_storage(rxq->q_storage);
97 DPAA2_BUS_ERR("dpaa2_alloc_dq_storage failed\n");
102 /* Enable the device */
103 ret = dpci_enable(&dpci_node->dpci,
104 CMD_PRI_LOW, dpci_node->token);
106 DPAA2_BUS_ERR("Enabling device failed with err code: %d", ret);
110 for (i = 0; i < DPAA2_DPCI_MAX_QUEUES; i++) {
111 /* Get the Rx FQID's */
112 ret = dpci_get_rx_queue(&dpci_node->dpci,
117 DPAA2_BUS_ERR("Rx queue fetch failed with err code: %d",
121 dpci_node->rx_queue[i].fqid = rx_attr.fqid;
123 ret = dpci_get_tx_queue(&dpci_node->dpci,
128 DPAA2_BUS_ERR("Reading device failed with err code: %d",
132 dpci_node->tx_queue[i].fqid = tx_attr.fqid;
135 dpci_node->dpci_id = dpci_id;
136 rte_atomic16_init(&dpci_node->in_use);
138 TAILQ_INSERT_TAIL(&dpci_dev_list, dpci_node, next);
143 for (i = 0; i < DPAA2_DPCI_MAX_QUEUES; i++) {
144 struct dpaa2_queue *rxq = &(dpci_node->rx_queue[i]);
146 if (rxq->q_storage) {
147 dpaa2_free_dq_storage(rxq->q_storage);
148 rte_free(rxq->q_storage);
156 struct dpaa2_dpci_dev *rte_dpaa2_alloc_dpci_dev(void)
158 struct dpaa2_dpci_dev *dpci_dev = NULL;
160 /* Get DPCI dev handle from list using index */
161 TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) {
162 if (dpci_dev && rte_atomic16_test_and_set(&dpci_dev->in_use))
169 void rte_dpaa2_free_dpci_dev(struct dpaa2_dpci_dev *dpci)
171 struct dpaa2_dpci_dev *dpci_dev = NULL;
173 /* Match DPCI handle and mark it free */
174 TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) {
175 if (dpci_dev == dpci) {
176 rte_atomic16_dec(&dpci_dev->in_use);
182 static struct rte_dpaa2_object rte_dpaa2_dpci_obj = {
183 .dev_type = DPAA2_CI,
184 .create = rte_dpaa2_create_dpci_device,
187 RTE_PMD_REGISTER_DPAA2_OBJECT(dpci, rte_dpaa2_dpci_obj);