Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2018-2019, 2024 NXP
3 : : */
4 : :
5 : : #include <stdio.h>
6 : : #include <errno.h>
7 : : #include <stdint.h>
8 : :
9 : : #include <bus_vdev_driver.h>
10 : : #include <rte_atomic.h>
11 : : #include <rte_interrupts.h>
12 : : #include <rte_branch_prediction.h>
13 : : #include <rte_lcore.h>
14 : :
15 : : #include <rte_rawdev.h>
16 : : #include <rte_rawdev_pmd.h>
17 : :
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"
22 : :
23 : : /* CMDIF driver name */
24 : : #define DPAA2_CMDIF_PMD_NAME dpaa2_dpci
25 : :
26 : : /*
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.
29 : : */
30 : : static int
31 : 0 : dpaa2_cmdif_get_attr(struct rte_rawdev *dev,
32 : : const char *attr_name,
33 : : uint64_t *attr_value)
34 : : {
35 : 0 : struct dpaa2_dpci_dev *cidev = dev->dev_private;
36 : :
37 : 0 : DPAA2_CMDIF_FUNC_TRACE();
38 : :
39 : : RTE_SET_USED(attr_name);
40 : :
41 [ # # ]: 0 : if (!attr_value) {
42 : 0 : DPAA2_CMDIF_ERR("Invalid arguments for getting attributes");
43 : 0 : return -EINVAL;
44 : : }
45 : 0 : *attr_value = cidev->dpci_id;
46 : :
47 : 0 : return 0;
48 : : }
49 : :
50 : : static int
51 : 0 : dpaa2_cmdif_enqueue_bufs(struct rte_rawdev *dev,
52 : : struct rte_rawdev_buf **buffers,
53 : : unsigned int count,
54 : : rte_rawdev_obj_t context)
55 : : {
56 : 0 : struct dpaa2_dpci_dev *cidev = dev->dev_private;
57 : : struct rte_dpaa2_cmdif_context *cmdif_send_cnxt;
58 : : struct dpaa2_queue *txq;
59 : : struct qbman_fd fd;
60 : : struct qbman_eq_desc eqdesc;
61 : : struct qbman_swp *swp;
62 : : uint32_t retry_count = 0;
63 : : int ret;
64 : :
65 : : RTE_SET_USED(count);
66 : :
67 [ # # ]: 0 : if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
68 : 0 : ret = dpaa2_affine_qbman_swp();
69 [ # # ]: 0 : if (ret) {
70 : 0 : DPAA2_CMDIF_ERR(
71 : : "Failed to allocate IO portal, tid: %d",
72 : : rte_gettid());
73 : 0 : return 0;
74 : : }
75 : : }
76 : 0 : swp = DPAA2_PER_LCORE_PORTAL;
77 : :
78 : : cmdif_send_cnxt = (struct rte_dpaa2_cmdif_context *)(context);
79 : 0 : txq = &(cidev->tx_queue[cmdif_send_cnxt->priority]);
80 : :
81 : : /* Prepare enqueue descriptor */
82 : 0 : qbman_eq_desc_clear(&eqdesc);
83 : 0 : qbman_eq_desc_set_fq(&eqdesc, txq->fqid);
84 : 0 : qbman_eq_desc_set_no_orp(&eqdesc, 0);
85 : 0 : qbman_eq_desc_set_response(&eqdesc, 0, 0);
86 : :
87 : : /* Set some of the FD parameters to i.
88 : : * For performance reasons do not memset
89 : : */
90 : 0 : fd.simple.bpid_offset = 0;
91 : 0 : fd.simple.ctrl = 0;
92 : :
93 : 0 : DPAA2_SET_FD_ADDR(&fd, DPAA2_VADDR_TO_IOVA(buffers[0]->buf_addr));
94 : 0 : DPAA2_SET_FD_LEN(&fd, cmdif_send_cnxt->size);
95 : 0 : DPAA2_SET_FD_FRC(&fd, cmdif_send_cnxt->frc);
96 : 0 : DPAA2_SET_FD_FLC(&fd, cmdif_send_cnxt->flc);
97 : :
98 : : /* Enqueue a packet to the QBMAN */
99 : : do {
100 : 0 : ret = qbman_swp_enqueue_multiple(swp, &eqdesc, &fd, NULL, 1);
101 [ # # ]: 0 : if (ret < 0 && ret != -EBUSY)
102 : 0 : DPAA2_CMDIF_ERR("Transmit failure with err: %d", ret);
103 : 0 : retry_count++;
104 [ # # ]: 0 : } while ((ret == -EBUSY) && (retry_count < DPAA2_MAX_TX_RETRY_COUNT));
105 : :
106 [ # # ]: 0 : if (ret < 0)
107 : 0 : return ret;
108 : :
109 : : DPAA2_CMDIF_DP_DEBUG("Successfully transmitted a packet");
110 : :
111 : : return 1;
112 : : }
113 : :
114 : : static int
115 : 0 : dpaa2_cmdif_dequeue_bufs(struct rte_rawdev *dev,
116 : : struct rte_rawdev_buf **buffers,
117 : : unsigned int count,
118 : : rte_rawdev_obj_t context)
119 : : {
120 : 0 : 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;
127 : : uint8_t status;
128 : : int ret;
129 : :
130 : : RTE_SET_USED(count);
131 : :
132 [ # # ]: 0 : if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
133 : 0 : ret = dpaa2_affine_qbman_swp();
134 [ # # ]: 0 : if (ret) {
135 : 0 : DPAA2_CMDIF_ERR(
136 : : "Failed to allocate IO portal, tid: %d",
137 : : rte_gettid());
138 : 0 : return 0;
139 : : }
140 : : }
141 : 0 : swp = DPAA2_PER_LCORE_PORTAL;
142 : :
143 : : cmdif_rcv_cnxt = (struct rte_dpaa2_cmdif_context *)(context);
144 : 0 : rxq = &(cidev->rx_queue[cmdif_rcv_cnxt->priority]);
145 : 0 : dq_storage = rxq->q_storage[0]->dq_storage[0];
146 : :
147 : 0 : qbman_pull_desc_clear(&pulldesc);
148 : 0 : qbman_pull_desc_set_fq(&pulldesc, rxq->fqid);
149 : 0 : qbman_pull_desc_set_numframes(&pulldesc, 1);
150 : 0 : qbman_pull_desc_set_storage(&pulldesc, dq_storage,
151 : : (uint64_t)(DPAA2_VADDR_TO_IOVA(dq_storage)), 1);
152 : :
153 : : while (1) {
154 [ # # ]: 0 : if (qbman_swp_pull(swp, &pulldesc)) {
155 : 0 : DPAA2_CMDIF_DP_WARN("VDQ cmd not issued. QBMAN is busy");
156 : : /* Portal was busy, try again */
157 : : continue;
158 : : }
159 : : break;
160 : : }
161 : :
162 : : /* Check if previous issued command is completed. */
163 [ # # ]: 0 : while (!qbman_check_command_complete(dq_storage))
164 : : ;
165 : : /* Loop until the dq_storage is updated with new token by QBMAN */
166 [ # # ]: 0 : while (!qbman_result_has_new_result(swp, dq_storage))
167 : : ;
168 : :
169 : : /* Check for valid frame. */
170 : 0 : status = (uint8_t)qbman_result_DQ_flags(dq_storage);
171 [ # # ]: 0 : if (unlikely((status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
172 : : DPAA2_CMDIF_DP_DEBUG("No frame is delivered");
173 : : return 0;
174 : : }
175 : :
176 : 0 : fd = qbman_result_DQ_fd(dq_storage);
177 : :
178 : 0 : buffers[0]->buf_addr = (void *)DPAA2_IOVA_TO_VADDR(
179 : : DPAA2_GET_FD_ADDR(fd) + DPAA2_GET_FD_OFFSET(fd));
180 : 0 : cmdif_rcv_cnxt->size = DPAA2_GET_FD_LEN(fd);
181 : 0 : cmdif_rcv_cnxt->flc = DPAA2_GET_FD_FLC(fd);
182 : 0 : cmdif_rcv_cnxt->frc = DPAA2_GET_FD_FRC(fd);
183 : :
184 : : DPAA2_CMDIF_DP_DEBUG("packet received");
185 : :
186 : 0 : return 1;
187 : : }
188 : :
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,
193 : : };
194 : :
195 : : static int
196 : 0 : dpaa2_cmdif_create(const char *name,
197 : : struct rte_vdev_device *vdev,
198 : : int socket_id)
199 : : {
200 : : struct rte_rawdev *rawdev;
201 : : struct dpaa2_dpci_dev *cidev;
202 : :
203 : : /* Allocate device structure */
204 : 0 : rawdev = rte_rawdev_pmd_allocate(name, sizeof(struct dpaa2_dpci_dev),
205 : : socket_id);
206 [ # # ]: 0 : if (!rawdev) {
207 : 0 : DPAA2_CMDIF_ERR("Unable to allocate rawdevice");
208 : 0 : return -EINVAL;
209 : : }
210 : :
211 : 0 : rawdev->dev_ops = &dpaa2_cmdif_ops;
212 : 0 : rawdev->device = &vdev->device;
213 : :
214 : : /* For secondary processes, the primary has done all the work */
215 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
216 : : return 0;
217 : :
218 : 0 : cidev = rte_dpaa2_alloc_dpci_dev();
219 [ # # ]: 0 : if (!cidev) {
220 : 0 : DPAA2_CMDIF_ERR("Unable to allocate CI device");
221 : 0 : rte_rawdev_pmd_release(rawdev);
222 : 0 : return -ENODEV;
223 : : }
224 : :
225 : 0 : rawdev->dev_private = cidev;
226 : :
227 : 0 : return 0;
228 : : }
229 : :
230 : : static int
231 : 0 : dpaa2_cmdif_destroy(const char *name)
232 : : {
233 : : int ret;
234 : : struct rte_rawdev *rdev;
235 : :
236 : 0 : rdev = rte_rawdev_pmd_get_named_dev(name);
237 [ # # ]: 0 : if (!rdev) {
238 : 0 : DPAA2_CMDIF_ERR("Invalid device name (%s)", name);
239 : 0 : return -EINVAL;
240 : : }
241 : :
242 : : /* The primary process will only free the DPCI device */
243 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY)
244 : 0 : rte_dpaa2_free_dpci_dev(rdev->dev_private);
245 : :
246 : 0 : ret = rte_rawdev_pmd_release(rdev);
247 [ # # ]: 0 : if (ret)
248 : 0 : DPAA2_CMDIF_DEBUG("Device cleanup failed");
249 : :
250 : : return 0;
251 : : }
252 : :
253 : : static int
254 [ # # ]: 0 : dpaa2_cmdif_probe(struct rte_vdev_device *vdev)
255 : : {
256 : : const char *name;
257 : : int ret = 0;
258 : :
259 : : name = rte_vdev_device_name(vdev);
260 : :
261 : 0 : DPAA2_CMDIF_INFO("Init %s on NUMA node %d", name, rte_socket_id());
262 : :
263 : 0 : ret = dpaa2_cmdif_create(name, vdev, rte_socket_id());
264 : :
265 : 0 : return ret;
266 : : }
267 : :
268 : : static int
269 [ # # ]: 0 : dpaa2_cmdif_remove(struct rte_vdev_device *vdev)
270 : : {
271 : : const char *name;
272 : : int ret;
273 : :
274 : : name = rte_vdev_device_name(vdev);
275 : : if (name == NULL)
276 : : return -1;
277 : :
278 : 0 : DPAA2_CMDIF_INFO("Closing %s on NUMA node %d", name, rte_socket_id());
279 : :
280 : 0 : ret = dpaa2_cmdif_destroy(name);
281 : :
282 : 0 : return ret;
283 : : }
284 : :
285 : : static struct rte_vdev_driver dpaa2_cmdif_drv = {
286 : : .probe = dpaa2_cmdif_probe,
287 : : .remove = dpaa2_cmdif_remove
288 : : };
289 : :
290 : 251 : RTE_PMD_REGISTER_VDEV(DPAA2_CMDIF_PMD_NAME, dpaa2_cmdif_drv);
291 [ - + ]: 251 : RTE_LOG_REGISTER(dpaa2_cmdif_logtype, pmd.raw.dpaa2.cmdif, INFO);
|