Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2021 HiSilicon Limited
3 : : */
4 : :
5 : : #include <inttypes.h>
6 : : #include <stdlib.h>
7 : :
8 : : #include <pthread.h>
9 : :
10 : : #include <bus_vdev_driver.h>
11 : : #include <rte_cycles.h>
12 : : #include <rte_eal.h>
13 : : #include <rte_kvargs.h>
14 : : #include <rte_lcore.h>
15 : : #include <rte_log.h>
16 : : #include <rte_malloc.h>
17 : : #include <rte_memcpy.h>
18 : :
19 : : #include <rte_dmadev_pmd.h>
20 : :
21 : : #include "skeleton_dmadev.h"
22 : :
23 [ - + ]: 235 : RTE_LOG_REGISTER_DEFAULT(skeldma_logtype, INFO);
24 : : #define SKELDMA_LOG(level, fmt, args...) \
25 : : rte_log(RTE_LOG_ ## level, skeldma_logtype, "%s(): " fmt "\n", \
26 : : __func__, ##args)
27 : :
28 : : static int
29 : 0 : skeldma_info_get(const struct rte_dma_dev *dev, struct rte_dma_info *dev_info,
30 : : uint32_t info_sz)
31 : : {
32 : : #define SKELDMA_MAX_DESC 8192
33 : : #define SKELDMA_MIN_DESC 32
34 : :
35 : : RTE_SET_USED(dev);
36 : : RTE_SET_USED(info_sz);
37 : :
38 : 0 : dev_info->dev_capa = RTE_DMA_CAPA_MEM_TO_MEM |
39 : : RTE_DMA_CAPA_SVA |
40 : : RTE_DMA_CAPA_OPS_COPY;
41 : 0 : dev_info->max_vchans = 1;
42 : 0 : dev_info->max_desc = SKELDMA_MAX_DESC;
43 : 0 : dev_info->min_desc = SKELDMA_MIN_DESC;
44 : :
45 : 0 : return 0;
46 : : }
47 : :
48 : : static int
49 : 0 : skeldma_configure(struct rte_dma_dev *dev, const struct rte_dma_conf *conf,
50 : : uint32_t conf_sz)
51 : : {
52 : : RTE_SET_USED(dev);
53 : : RTE_SET_USED(conf);
54 : : RTE_SET_USED(conf_sz);
55 : 0 : return 0;
56 : : }
57 : :
58 : : static uint32_t
59 : 0 : cpucopy_thread(void *param)
60 : : {
61 : : #define SLEEP_THRESHOLD 10000
62 : : #define SLEEP_US_VAL 10
63 : :
64 : : struct rte_dma_dev *dev = param;
65 : 0 : struct skeldma_hw *hw = dev->data->dev_private;
66 : 0 : struct skeldma_desc *desc = NULL;
67 : : int ret;
68 : :
69 [ # # ]: 0 : while (!hw->exit_flag) {
70 [ # # # # : 0 : ret = rte_ring_dequeue(hw->desc_running, (void **)&desc);
# ]
71 : 0 : if (ret) {
72 : 0 : hw->zero_req_count++;
73 [ # # ]: 0 : if (hw->zero_req_count == 0)
74 : 0 : hw->zero_req_count = SLEEP_THRESHOLD;
75 [ # # ]: 0 : if (hw->zero_req_count >= SLEEP_THRESHOLD)
76 : 0 : rte_delay_us_sleep(SLEEP_US_VAL);
77 : 0 : continue;
78 : : }
79 : :
80 : 0 : hw->zero_req_count = 0;
81 [ # # ]: 0 : rte_memcpy(desc->dst, desc->src, desc->len);
82 : 0 : __atomic_fetch_add(&hw->completed_count, 1, __ATOMIC_RELEASE);
83 [ # # # # : 0 : (void)rte_ring_enqueue(hw->desc_completed, (void *)desc);
# ]
84 : : }
85 : :
86 : 0 : return 0;
87 : : }
88 : :
89 : : static void
90 : 0 : fflush_ring(struct skeldma_hw *hw, struct rte_ring *ring)
91 : : {
92 : 0 : struct skeldma_desc *desc = NULL;
93 [ # # ]: 0 : while (rte_ring_count(ring) > 0) {
94 : : (void)rte_ring_dequeue(ring, (void **)&desc);
95 [ # # # # : 0 : (void)rte_ring_enqueue(hw->desc_empty, (void *)desc);
# ]
96 : : }
97 : 0 : }
98 : :
99 : : static int
100 : 0 : skeldma_start(struct rte_dma_dev *dev)
101 : : {
102 : 0 : struct skeldma_hw *hw = dev->data->dev_private;
103 : : char name[RTE_THREAD_INTERNAL_NAME_SIZE];
104 : : rte_cpuset_t cpuset;
105 : : int ret;
106 : :
107 [ # # ]: 0 : if (hw->desc_mem == NULL) {
108 : 0 : SKELDMA_LOG(ERR, "Vchan was not setup, start fail!");
109 : 0 : return -EINVAL;
110 : : }
111 : :
112 : : /* Reset the dmadev to a known state, include:
113 : : * 1) fflush pending/running/completed ring to empty ring.
114 : : * 2) init ring idx to zero.
115 : : * 3) init running statistics.
116 : : * 4) mark cpucopy task exit_flag to false.
117 : : */
118 : 0 : fflush_ring(hw, hw->desc_pending);
119 : 0 : fflush_ring(hw, hw->desc_running);
120 : 0 : fflush_ring(hw, hw->desc_completed);
121 : 0 : hw->ridx = 0;
122 : 0 : hw->last_ridx = hw->ridx - 1;
123 : 0 : hw->submitted_count = 0;
124 : 0 : hw->zero_req_count = 0;
125 : 0 : hw->completed_count = 0;
126 : 0 : hw->exit_flag = false;
127 : :
128 : : rte_mb();
129 : :
130 : 0 : snprintf(name, sizeof(name), "dma-skel%d", dev->data->dev_id);
131 : 0 : ret = rte_thread_create_internal_control(&hw->thread, name,
132 : : cpucopy_thread, dev);
133 [ # # ]: 0 : if (ret) {
134 : 0 : SKELDMA_LOG(ERR, "Start cpucopy thread fail!");
135 : 0 : return -EINVAL;
136 : : }
137 : :
138 [ # # ]: 0 : if (hw->lcore_id != -1) {
139 : 0 : cpuset = rte_lcore_cpuset(hw->lcore_id);
140 : 0 : ret = rte_thread_set_affinity_by_id(hw->thread, &cpuset);
141 [ # # ]: 0 : if (ret)
142 : 0 : SKELDMA_LOG(WARNING,
143 : : "Set thread affinity lcore = %d fail!",
144 : : hw->lcore_id);
145 : : }
146 : :
147 : : return 0;
148 : : }
149 : :
150 : : static int
151 : 0 : skeldma_stop(struct rte_dma_dev *dev)
152 : : {
153 : 0 : struct skeldma_hw *hw = dev->data->dev_private;
154 : :
155 : 0 : hw->exit_flag = true;
156 : : rte_delay_ms(1);
157 : :
158 : 0 : (void)pthread_cancel((pthread_t)hw->thread.opaque_id);
159 : 0 : rte_thread_join(hw->thread, NULL);
160 : :
161 : 0 : return 0;
162 : : }
163 : :
164 : : static int
165 : 0 : vchan_setup(struct skeldma_hw *hw, int16_t dev_id, uint16_t nb_desc)
166 : : {
167 : : char name[RTE_RING_NAMESIZE];
168 : : struct skeldma_desc *desc;
169 : : struct rte_ring *empty;
170 : : struct rte_ring *pending;
171 : : struct rte_ring *running;
172 : : struct rte_ring *completed;
173 : : uint16_t i;
174 : :
175 : 0 : desc = rte_zmalloc_socket(NULL, nb_desc * sizeof(struct skeldma_desc),
176 : : RTE_CACHE_LINE_SIZE, hw->socket_id);
177 [ # # ]: 0 : if (desc == NULL) {
178 : 0 : SKELDMA_LOG(ERR, "Malloc dma skeleton desc fail!");
179 : 0 : return -ENOMEM;
180 : : }
181 : :
182 : 0 : snprintf(name, RTE_RING_NAMESIZE, "dma_skel_desc_empty_%d", dev_id);
183 : 0 : empty = rte_ring_create(name, nb_desc, hw->socket_id,
184 : : RING_F_SP_ENQ | RING_F_SC_DEQ);
185 : : snprintf(name, RTE_RING_NAMESIZE, "dma_skel_desc_pend_%d", dev_id);
186 : 0 : pending = rte_ring_create(name, nb_desc, hw->socket_id,
187 : : RING_F_SP_ENQ | RING_F_SC_DEQ);
188 : : snprintf(name, RTE_RING_NAMESIZE, "dma_skel_desc_run_%d", dev_id);
189 : 0 : running = rte_ring_create(name, nb_desc, hw->socket_id,
190 : : RING_F_SP_ENQ | RING_F_SC_DEQ);
191 : : snprintf(name, RTE_RING_NAMESIZE, "dma_skel_desc_comp_%d", dev_id);
192 : 0 : completed = rte_ring_create(name, nb_desc, hw->socket_id,
193 : : RING_F_SP_ENQ | RING_F_SC_DEQ);
194 [ # # ]: 0 : if (empty == NULL || pending == NULL || running == NULL ||
195 [ # # ]: 0 : completed == NULL) {
196 : 0 : SKELDMA_LOG(ERR, "Create dma skeleton desc ring fail!");
197 : 0 : rte_ring_free(empty);
198 : 0 : rte_ring_free(pending);
199 : 0 : rte_ring_free(running);
200 : 0 : rte_ring_free(completed);
201 : 0 : rte_free(desc);
202 : 0 : return -ENOMEM;
203 : : }
204 : :
205 : : /* The real usable ring size is *count-1* instead of *count* to
206 : : * differentiate a free ring from an empty ring.
207 : : * @see rte_ring_create
208 : : */
209 [ # # ]: 0 : for (i = 0; i < nb_desc - 1; i++)
210 [ # # # # : 0 : (void)rte_ring_enqueue(empty, (void *)(desc + i));
# ]
211 : :
212 : 0 : hw->desc_mem = desc;
213 : 0 : hw->desc_empty = empty;
214 : 0 : hw->desc_pending = pending;
215 : 0 : hw->desc_running = running;
216 : 0 : hw->desc_completed = completed;
217 : :
218 : 0 : return 0;
219 : : }
220 : :
221 : : static void
222 : 1 : vchan_release(struct skeldma_hw *hw)
223 : : {
224 [ - + ]: 1 : if (hw->desc_mem == NULL)
225 : : return;
226 : :
227 : 0 : rte_free(hw->desc_mem);
228 : 0 : hw->desc_mem = NULL;
229 : 0 : rte_ring_free(hw->desc_empty);
230 : 0 : hw->desc_empty = NULL;
231 : 0 : rte_ring_free(hw->desc_pending);
232 : 0 : hw->desc_pending = NULL;
233 : 0 : rte_ring_free(hw->desc_running);
234 : 0 : hw->desc_running = NULL;
235 : 0 : rte_ring_free(hw->desc_completed);
236 : 0 : hw->desc_completed = NULL;
237 : : }
238 : :
239 : : static int
240 : 1 : skeldma_close(struct rte_dma_dev *dev)
241 : : {
242 : : /* The device already stopped */
243 : 1 : vchan_release(dev->data->dev_private);
244 : 1 : return 0;
245 : : }
246 : :
247 : : static int
248 : 0 : skeldma_vchan_setup(struct rte_dma_dev *dev, uint16_t vchan,
249 : : const struct rte_dma_vchan_conf *conf,
250 : : uint32_t conf_sz)
251 : : {
252 : 0 : struct skeldma_hw *hw = dev->data->dev_private;
253 : :
254 : : RTE_SET_USED(vchan);
255 : : RTE_SET_USED(conf_sz);
256 : :
257 [ # # ]: 0 : if (!rte_is_power_of_2(conf->nb_desc)) {
258 : 0 : SKELDMA_LOG(ERR, "Number of desc must be power of 2!");
259 : 0 : return -EINVAL;
260 : : }
261 : :
262 : 0 : vchan_release(hw);
263 : 0 : return vchan_setup(hw, dev->data->dev_id, conf->nb_desc);
264 : : }
265 : :
266 : : static int
267 : 0 : skeldma_vchan_status(const struct rte_dma_dev *dev,
268 : : uint16_t vchan, enum rte_dma_vchan_status *status)
269 : : {
270 : 0 : struct skeldma_hw *hw = dev->data->dev_private;
271 : :
272 : : RTE_SET_USED(vchan);
273 : :
274 : 0 : *status = RTE_DMA_VCHAN_IDLE;
275 [ # # ]: 0 : if (hw->submitted_count != __atomic_load_n(&hw->completed_count, __ATOMIC_ACQUIRE)
276 [ # # ]: 0 : || hw->zero_req_count == 0)
277 : 0 : *status = RTE_DMA_VCHAN_ACTIVE;
278 : 0 : return 0;
279 : : }
280 : :
281 : : static int
282 : 0 : skeldma_stats_get(const struct rte_dma_dev *dev, uint16_t vchan,
283 : : struct rte_dma_stats *stats, uint32_t stats_sz)
284 : : {
285 : 0 : struct skeldma_hw *hw = dev->data->dev_private;
286 : :
287 : : RTE_SET_USED(vchan);
288 : : RTE_SET_USED(stats_sz);
289 : :
290 : 0 : stats->submitted = hw->submitted_count;
291 : 0 : stats->completed = hw->completed_count;
292 : 0 : stats->errors = 0;
293 : :
294 : 0 : return 0;
295 : : }
296 : :
297 : : static int
298 : 0 : skeldma_stats_reset(struct rte_dma_dev *dev, uint16_t vchan)
299 : : {
300 : 0 : struct skeldma_hw *hw = dev->data->dev_private;
301 : :
302 : : RTE_SET_USED(vchan);
303 : :
304 : 0 : hw->submitted_count = 0;
305 : 0 : hw->completed_count = 0;
306 : :
307 : 0 : return 0;
308 : : }
309 : :
310 : : static int
311 : 0 : skeldma_dump(const struct rte_dma_dev *dev, FILE *f)
312 : : {
313 : : #define GET_RING_COUNT(ring) ((ring) ? (rte_ring_count(ring)) : 0)
314 : :
315 : 0 : struct skeldma_hw *hw = dev->data->dev_private;
316 : :
317 : 0 : (void)fprintf(f,
318 : : " lcore_id: %d\n"
319 : : " socket_id: %d\n"
320 : : " desc_empty_ring_count: %u\n"
321 : : " desc_pending_ring_count: %u\n"
322 : : " desc_running_ring_count: %u\n"
323 : : " desc_completed_ring_count: %u\n",
324 : : hw->lcore_id, hw->socket_id,
325 [ # # ]: 0 : GET_RING_COUNT(hw->desc_empty),
326 [ # # ]: 0 : GET_RING_COUNT(hw->desc_pending),
327 [ # # ]: 0 : GET_RING_COUNT(hw->desc_running),
328 [ # # ]: 0 : GET_RING_COUNT(hw->desc_completed));
329 : 0 : (void)fprintf(f,
330 : : " next_ring_idx: %u\n"
331 : : " last_ring_idx: %u\n"
332 : : " submitted_count: %" PRIu64 "\n"
333 : : " completed_count: %" PRIu64 "\n",
334 : 0 : hw->ridx, hw->last_ridx,
335 : : hw->submitted_count, hw->completed_count);
336 : :
337 : 0 : return 0;
338 : : }
339 : :
340 : : static inline void
341 : 0 : submit(struct skeldma_hw *hw, struct skeldma_desc *desc)
342 : : {
343 : 0 : uint16_t count = rte_ring_count(hw->desc_pending);
344 : 0 : struct skeldma_desc *pend_desc = NULL;
345 : :
346 [ # # ]: 0 : while (count > 0) {
347 [ # # # # : 0 : (void)rte_ring_dequeue(hw->desc_pending, (void **)&pend_desc);
# ]
348 [ # # # # : 0 : (void)rte_ring_enqueue(hw->desc_running, (void *)pend_desc);
# ]
349 : 0 : count--;
350 : : }
351 : :
352 [ # # ]: 0 : if (desc)
353 [ # # # # : 0 : (void)rte_ring_enqueue(hw->desc_running, (void *)desc);
# ]
354 : 0 : }
355 : :
356 : : static int
357 : 0 : skeldma_copy(void *dev_private, uint16_t vchan,
358 : : rte_iova_t src, rte_iova_t dst,
359 : : uint32_t length, uint64_t flags)
360 : : {
361 : : struct skeldma_hw *hw = dev_private;
362 : : struct skeldma_desc *desc;
363 : : int ret;
364 : :
365 : : RTE_SET_USED(vchan);
366 : : RTE_SET_USED(flags);
367 : :
368 [ # # # # : 0 : ret = rte_ring_dequeue(hw->desc_empty, (void **)&desc);
# ]
369 : : if (ret)
370 : 0 : return -ENOSPC;
371 : 0 : desc->src = (void *)(uintptr_t)src;
372 : 0 : desc->dst = (void *)(uintptr_t)dst;
373 : 0 : desc->len = length;
374 : 0 : desc->ridx = hw->ridx;
375 [ # # ]: 0 : if (flags & RTE_DMA_OP_FLAG_SUBMIT)
376 : 0 : submit(hw, desc);
377 : : else
378 [ # # # # : 0 : (void)rte_ring_enqueue(hw->desc_pending, (void *)desc);
# ]
379 : 0 : hw->submitted_count++;
380 : :
381 : 0 : return hw->ridx++;
382 : : }
383 : :
384 : : static int
385 : 0 : skeldma_submit(void *dev_private, uint16_t vchan)
386 : : {
387 : : struct skeldma_hw *hw = dev_private;
388 : : RTE_SET_USED(vchan);
389 : 0 : submit(hw, NULL);
390 : 0 : return 0;
391 : : }
392 : :
393 : : static uint16_t
394 : 0 : skeldma_completed(void *dev_private,
395 : : uint16_t vchan, const uint16_t nb_cpls,
396 : : uint16_t *last_idx, bool *has_error)
397 : : {
398 : : struct skeldma_hw *hw = dev_private;
399 : 0 : struct skeldma_desc *desc = NULL;
400 : : uint16_t index = 0;
401 : : uint16_t count;
402 : :
403 : : RTE_SET_USED(vchan);
404 : : RTE_SET_USED(has_error);
405 : :
406 : 0 : count = RTE_MIN(nb_cpls, rte_ring_count(hw->desc_completed));
407 [ # # ]: 0 : while (index < count) {
408 [ # # # # : 0 : (void)rte_ring_dequeue(hw->desc_completed, (void **)&desc);
# ]
409 [ # # ]: 0 : if (index == count - 1) {
410 : 0 : hw->last_ridx = desc->ridx;
411 : 0 : *last_idx = desc->ridx;
412 : : }
413 : 0 : index++;
414 [ # # # # : 0 : (void)rte_ring_enqueue(hw->desc_empty, (void *)desc);
# ]
415 : : }
416 [ # # ]: 0 : if (unlikely(count == 0))
417 : 0 : *last_idx = hw->last_ridx;
418 : :
419 : 0 : return count;
420 : : }
421 : :
422 : : static uint16_t
423 : 0 : skeldma_completed_status(void *dev_private,
424 : : uint16_t vchan, const uint16_t nb_cpls,
425 : : uint16_t *last_idx, enum rte_dma_status_code *status)
426 : : {
427 : : struct skeldma_hw *hw = dev_private;
428 : 0 : struct skeldma_desc *desc = NULL;
429 : : uint16_t index = 0;
430 : : uint16_t count;
431 : :
432 : : RTE_SET_USED(vchan);
433 : :
434 : 0 : count = RTE_MIN(nb_cpls, rte_ring_count(hw->desc_completed));
435 [ # # ]: 0 : while (index < count) {
436 [ # # # # : 0 : (void)rte_ring_dequeue(hw->desc_completed, (void **)&desc);
# ]
437 [ # # ]: 0 : if (index == count - 1) {
438 : 0 : hw->last_ridx = desc->ridx;
439 : 0 : *last_idx = desc->ridx;
440 : : }
441 : 0 : status[index++] = RTE_DMA_STATUS_SUCCESSFUL;
442 [ # # # # : 0 : (void)rte_ring_enqueue(hw->desc_empty, (void *)desc);
# ]
443 : : }
444 [ # # ]: 0 : if (unlikely(count == 0))
445 : 0 : *last_idx = hw->last_ridx;
446 : :
447 : 0 : return count;
448 : : }
449 : :
450 : : static uint16_t
451 : 0 : skeldma_burst_capacity(const void *dev_private, uint16_t vchan)
452 : : {
453 : : const struct skeldma_hw *hw = dev_private;
454 : :
455 : : RTE_SET_USED(vchan);
456 : 0 : return rte_ring_count(hw->desc_empty);
457 : : }
458 : :
459 : : static const struct rte_dma_dev_ops skeldma_ops = {
460 : : .dev_info_get = skeldma_info_get,
461 : : .dev_configure = skeldma_configure,
462 : : .dev_start = skeldma_start,
463 : : .dev_stop = skeldma_stop,
464 : : .dev_close = skeldma_close,
465 : :
466 : : .vchan_setup = skeldma_vchan_setup,
467 : : .vchan_status = skeldma_vchan_status,
468 : :
469 : : .stats_get = skeldma_stats_get,
470 : : .stats_reset = skeldma_stats_reset,
471 : :
472 : : .dev_dump = skeldma_dump,
473 : : };
474 : :
475 : : static int
476 : 1 : skeldma_create(const char *name, struct rte_vdev_device *vdev, int lcore_id)
477 : : {
478 : : struct rte_dma_dev *dev;
479 : : struct skeldma_hw *hw;
480 : : int socket_id;
481 : :
482 [ + - ]: 1 : socket_id = (lcore_id < 0) ? rte_socket_id() :
483 : 0 : rte_lcore_to_socket_id(lcore_id);
484 : 1 : dev = rte_dma_pmd_allocate(name, socket_id, sizeof(struct skeldma_hw));
485 [ - + ]: 1 : if (dev == NULL) {
486 : 0 : SKELDMA_LOG(ERR, "Unable to allocate dmadev: %s", name);
487 : 0 : return -EINVAL;
488 : : }
489 : :
490 : 1 : dev->device = &vdev->device;
491 : 1 : dev->dev_ops = &skeldma_ops;
492 : 1 : dev->fp_obj->dev_private = dev->data->dev_private;
493 : 1 : dev->fp_obj->copy = skeldma_copy;
494 : 1 : dev->fp_obj->submit = skeldma_submit;
495 : 1 : dev->fp_obj->completed = skeldma_completed;
496 : 1 : dev->fp_obj->completed_status = skeldma_completed_status;
497 : 1 : dev->fp_obj->burst_capacity = skeldma_burst_capacity;
498 : :
499 : : hw = dev->data->dev_private;
500 : 1 : hw->lcore_id = lcore_id;
501 : 1 : hw->socket_id = socket_id;
502 : :
503 : 1 : dev->state = RTE_DMA_DEV_READY;
504 : :
505 : 1 : return dev->data->dev_id;
506 : : }
507 : :
508 : : static int
509 : : skeldma_destroy(const char *name)
510 : : {
511 : 1 : return rte_dma_pmd_release(name);
512 : : }
513 : :
514 : : static int
515 : 0 : skeldma_parse_lcore(const char *key __rte_unused,
516 : : const char *value,
517 : : void *opaque)
518 : : {
519 : : int lcore_id;
520 : :
521 [ # # ]: 0 : if (value == NULL || opaque == NULL)
522 : : return -EINVAL;
523 : :
524 : : lcore_id = atoi(value);
525 [ # # ]: 0 : if (lcore_id >= 0 && lcore_id < RTE_MAX_LCORE)
526 : 0 : *(int *)opaque = lcore_id;
527 : :
528 : : return 0;
529 : : }
530 : :
531 : : static void
532 [ + - ]: 1 : skeldma_parse_vdev_args(struct rte_vdev_device *vdev, int *lcore_id)
533 : : {
534 : : static const char *const args[] = {
535 : : SKELDMA_ARG_LCORE,
536 : : NULL
537 : : };
538 : :
539 : : struct rte_kvargs *kvlist;
540 : : const char *params;
541 : :
542 : : params = rte_vdev_device_args(vdev);
543 [ + - - + ]: 1 : if (params == NULL || params[0] == '\0')
544 : : return;
545 : :
546 : 0 : kvlist = rte_kvargs_parse(params, args);
547 [ # # ]: 0 : if (!kvlist)
548 : : return;
549 : :
550 : 0 : (void)rte_kvargs_process(kvlist, SKELDMA_ARG_LCORE,
551 : : skeldma_parse_lcore, lcore_id);
552 : 0 : SKELDMA_LOG(INFO, "Parse lcore_id = %d", *lcore_id);
553 : :
554 : 0 : rte_kvargs_free(kvlist);
555 : : }
556 : :
557 : : static int
558 : 1 : skeldma_probe(struct rte_vdev_device *vdev)
559 : : {
560 : : const char *name;
561 [ + - ]: 1 : int lcore_id = -1;
562 : : int ret;
563 : :
564 : : name = rte_vdev_device_name(vdev);
565 : : if (name == NULL)
566 : : return -EINVAL;
567 : :
568 [ - + ]: 1 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
569 : 0 : SKELDMA_LOG(ERR, "Multiple process not supported for %s", name);
570 : 0 : return -EINVAL;
571 : : }
572 : :
573 : 1 : skeldma_parse_vdev_args(vdev, &lcore_id);
574 : :
575 : 1 : ret = skeldma_create(name, vdev, lcore_id);
576 [ + - ]: 1 : if (ret >= 0)
577 : 1 : SKELDMA_LOG(INFO, "Create %s dmadev with lcore-id %d",
578 : : name, lcore_id);
579 : :
580 : 1 : return ret < 0 ? ret : 0;
581 : : }
582 : :
583 : : static int
584 [ + - ]: 1 : skeldma_remove(struct rte_vdev_device *vdev)
585 : : {
586 : : const char *name;
587 : : int ret;
588 : :
589 : : name = rte_vdev_device_name(vdev);
590 : : if (name == NULL)
591 : : return -1;
592 : :
593 : : ret = skeldma_destroy(name);
594 [ + - ]: 1 : if (!ret)
595 : 1 : SKELDMA_LOG(INFO, "Remove %s dmadev", name);
596 : :
597 : : return ret;
598 : : }
599 : :
600 : : static struct rte_vdev_driver skeldma_pmd_drv = {
601 : : .probe = skeldma_probe,
602 : : .remove = skeldma_remove,
603 : : .drv_flags = RTE_VDEV_DRV_NEED_IOVA_AS_VA,
604 : : };
605 : :
606 : 235 : RTE_PMD_REGISTER_VDEV(dma_skeleton, skeldma_pmd_drv);
607 : : RTE_PMD_REGISTER_PARAM_STRING(dma_skeleton,
608 : : SKELDMA_ARG_LCORE "=<uint16> ");
|