1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018-2019 NXP
9 #include <rte_bus_vdev.h>
10 #include <rte_atomic.h>
11 #include <rte_interrupts.h>
12 #include <rte_branch_prediction.h>
13 #include <rte_lcore.h>
15 #include <rte_rawdev.h>
16 #include <rte_rawdev_pmd.h>
18 #include <portal/dpaa2_hw_pvt.h>
19 #include <portal/dpaa2_hw_dpio.h>
20 #include "dpaa2_cmdif_logs.h"
21 #include "rte_pmd_dpaa2_cmdif.h"
23 /* CMDIF driver name */
24 #define DPAA2_CMDIF_PMD_NAME dpaa2_dpci
27 * This API provides the DPCI device ID in 'attr_value'.
28 * The device ID shall be passed by GPP to the AIOP using CMDIF commands.
31 dpaa2_cmdif_get_attr(struct rte_rawdev *dev,
32 const char *attr_name,
35 struct dpaa2_dpci_dev *cidev = dev->dev_private;
37 DPAA2_CMDIF_FUNC_TRACE();
39 RTE_SET_USED(attr_name);
42 DPAA2_CMDIF_ERR("Invalid arguments for getting attributes");
45 *attr_value = cidev->dpci_id;
51 dpaa2_cmdif_enqueue_bufs(struct rte_rawdev *dev,
52 struct rte_rawdev_buf **buffers,
54 rte_rawdev_obj_t context)
56 struct dpaa2_dpci_dev *cidev = dev->dev_private;
57 struct rte_dpaa2_cmdif_context *cmdif_send_cnxt;
58 struct dpaa2_queue *txq;
60 struct qbman_eq_desc eqdesc;
61 struct qbman_swp *swp;
62 uint32_t retry_count = 0;
67 if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
68 ret = dpaa2_affine_qbman_swp();
71 "Failed to allocate IO portal, tid: %d\n",
76 swp = DPAA2_PER_LCORE_PORTAL;
78 cmdif_send_cnxt = (struct rte_dpaa2_cmdif_context *)(context);
79 txq = &(cidev->tx_queue[cmdif_send_cnxt->priority]);
81 /* Prepare enqueue descriptor */
82 qbman_eq_desc_clear(&eqdesc);
83 qbman_eq_desc_set_fq(&eqdesc, txq->fqid);
84 qbman_eq_desc_set_no_orp(&eqdesc, 0);
85 qbman_eq_desc_set_response(&eqdesc, 0, 0);
87 /* Set some of the FD parameters to i.
88 * For performance reasons do not memset
90 fd.simple.bpid_offset = 0;
93 DPAA2_SET_FD_ADDR(&fd, DPAA2_VADDR_TO_IOVA(buffers[0]->buf_addr));
94 DPAA2_SET_FD_LEN(&fd, cmdif_send_cnxt->size);
95 DPAA2_SET_FD_FRC(&fd, cmdif_send_cnxt->frc);
96 DPAA2_SET_FD_FLC(&fd, cmdif_send_cnxt->flc);
98 /* Enqueue a packet to the QBMAN */
100 ret = qbman_swp_enqueue_multiple(swp, &eqdesc, &fd, NULL, 1);
101 if (ret < 0 && ret != -EBUSY)
102 DPAA2_CMDIF_ERR("Transmit failure with err: %d\n", ret);
104 } while ((ret == -EBUSY) && (retry_count < DPAA2_MAX_TX_RETRY_COUNT));
109 DPAA2_CMDIF_DP_DEBUG("Successfully transmitted a packet\n");
115 dpaa2_cmdif_dequeue_bufs(struct rte_rawdev *dev,
116 struct rte_rawdev_buf **buffers,
118 rte_rawdev_obj_t context)
120 struct dpaa2_dpci_dev *cidev = dev->dev_private;
121 struct rte_dpaa2_cmdif_context *cmdif_rcv_cnxt;
122 struct dpaa2_queue *rxq;
123 struct qbman_swp *swp;
124 struct qbman_result *dq_storage;
125 const struct qbman_fd *fd;
126 struct qbman_pull_desc pulldesc;
132 if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
133 ret = dpaa2_affine_qbman_swp();
136 "Failed to allocate IO portal, tid: %d\n",
141 swp = DPAA2_PER_LCORE_PORTAL;
143 cmdif_rcv_cnxt = (struct rte_dpaa2_cmdif_context *)(context);
144 rxq = &(cidev->rx_queue[cmdif_rcv_cnxt->priority]);
145 dq_storage = rxq->q_storage->dq_storage[0];
147 qbman_pull_desc_clear(&pulldesc);
148 qbman_pull_desc_set_fq(&pulldesc, rxq->fqid);
149 qbman_pull_desc_set_numframes(&pulldesc, 1);
150 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
151 (uint64_t)(DPAA2_VADDR_TO_IOVA(dq_storage)), 1);
154 if (qbman_swp_pull(swp, &pulldesc)) {
155 DPAA2_CMDIF_DP_WARN("VDQ cmd not issued. QBMAN is busy\n");
156 /* Portal was busy, try again */
162 /* Check if previous issued command is completed. */
163 while (!qbman_check_command_complete(dq_storage))
165 /* Loop until the dq_storage is updated with new token by QBMAN */
166 while (!qbman_result_has_new_result(swp, dq_storage))
169 /* Check for valid frame. */
170 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
171 if (unlikely((status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
172 DPAA2_CMDIF_DP_DEBUG("No frame is delivered\n");
176 fd = qbman_result_DQ_fd(dq_storage);
178 buffers[0]->buf_addr = (void *)DPAA2_IOVA_TO_VADDR(
179 DPAA2_GET_FD_ADDR(fd) + DPAA2_GET_FD_OFFSET(fd));
180 cmdif_rcv_cnxt->size = DPAA2_GET_FD_LEN(fd);
181 cmdif_rcv_cnxt->flc = DPAA2_GET_FD_FLC(fd);
182 cmdif_rcv_cnxt->frc = DPAA2_GET_FD_FRC(fd);
184 DPAA2_CMDIF_DP_DEBUG("packet received\n");
189 static const struct rte_rawdev_ops dpaa2_cmdif_ops = {
190 .attr_get = dpaa2_cmdif_get_attr,
191 .enqueue_bufs = dpaa2_cmdif_enqueue_bufs,
192 .dequeue_bufs = dpaa2_cmdif_dequeue_bufs,
196 dpaa2_cmdif_create(const char *name,
197 struct rte_vdev_device *vdev,
200 struct rte_rawdev *rawdev;
201 struct dpaa2_dpci_dev *cidev;
203 /* Allocate device structure */
204 rawdev = rte_rawdev_pmd_allocate(name, sizeof(struct dpaa2_dpci_dev),
207 DPAA2_CMDIF_ERR("Unable to allocate rawdevice");
211 rawdev->dev_ops = &dpaa2_cmdif_ops;
212 rawdev->device = &vdev->device;
214 /* For secondary processes, the primary has done all the work */
215 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
218 cidev = rte_dpaa2_alloc_dpci_dev();
220 DPAA2_CMDIF_ERR("Unable to allocate CI device");
221 rte_rawdev_pmd_release(rawdev);
225 rawdev->dev_private = cidev;
231 dpaa2_cmdif_destroy(const char *name)
234 struct rte_rawdev *rdev;
236 rdev = rte_rawdev_pmd_get_named_dev(name);
238 DPAA2_CMDIF_ERR("Invalid device name (%s)", name);
242 /* The primary process will only free the DPCI device */
243 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
244 rte_dpaa2_free_dpci_dev(rdev->dev_private);
246 ret = rte_rawdev_pmd_release(rdev);
248 DPAA2_CMDIF_DEBUG("Device cleanup failed");
254 dpaa2_cmdif_probe(struct rte_vdev_device *vdev)
259 name = rte_vdev_device_name(vdev);
261 DPAA2_CMDIF_INFO("Init %s on NUMA node %d", name, rte_socket_id());
263 ret = dpaa2_cmdif_create(name, vdev, rte_socket_id());
269 dpaa2_cmdif_remove(struct rte_vdev_device *vdev)
274 name = rte_vdev_device_name(vdev);
278 DPAA2_CMDIF_INFO("Closing %s on NUMA node %d", name, rte_socket_id());
280 ret = dpaa2_cmdif_destroy(name);
285 static struct rte_vdev_driver dpaa2_cmdif_drv = {
286 .probe = dpaa2_cmdif_probe,
287 .remove = dpaa2_cmdif_remove
290 RTE_PMD_REGISTER_VDEV(DPAA2_CMDIF_PMD_NAME, dpaa2_cmdif_drv);
291 RTE_LOG_REGISTER(dpaa2_cmdif_logtype, pmd.raw.dpaa2.cmdif, INFO);