Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2025 Marvell
3 : : */
4 : :
5 : : #include <stdint.h>
6 : : #include <stdlib.h>
7 : : #include <sys/types.h>
8 : : #include <unistd.h>
9 : : #include <fcntl.h>
10 : :
11 : : #include <rte_malloc.h>
12 : : #include <rte_kvargs.h>
13 : : #include <bus_vdev_driver.h>
14 : : #include <rte_cryptodev.h>
15 : : #include <cryptodev_pmd.h>
16 : : #include <rte_alarm.h>
17 : : #include <rte_cycles.h>
18 : : #include <rte_io.h>
19 : :
20 : : #include "virtio_user/virtio_user_dev.h"
21 : : #include "virtio_user/vhost.h"
22 : : #include "virtio_cryptodev.h"
23 : : #include "virtio_logs.h"
24 : : #include "virtio_pci.h"
25 : : #include "virtqueue.h"
26 : :
27 : : #define virtio_user_get_dev(hwp) container_of(hwp, struct virtio_user_dev, hw)
28 : :
29 : : uint8_t cryptodev_virtio_user_driver_id;
30 : :
31 : : static void
32 [ # # # # : 0 : virtio_user_read_dev_config(struct virtio_crypto_hw *hw, size_t offset,
# # # # #
# # ]
33 : : void *dst, int length __rte_unused)
34 : : {
35 : : struct virtio_user_dev *dev = virtio_user_get_dev(hw);
36 : :
37 : : if (offset == offsetof(struct virtio_crypto_config, status)) {
38 : 0 : crypto_virtio_user_dev_update_link_state(dev);
39 : 0 : *(uint32_t *)dst = dev->crypto_status;
40 : : } else if (offset == offsetof(struct virtio_crypto_config, max_dataqueues))
41 : 0 : *(uint16_t *)dst = dev->max_queue_pairs;
42 : : else if (offset == offsetof(struct virtio_crypto_config, crypto_services))
43 : 0 : *(uint32_t *)dst = dev->crypto_services;
44 : : else if (offset == offsetof(struct virtio_crypto_config, cipher_algo_l))
45 : 0 : *(uint32_t *)dst = dev->cipher_algo & 0xFFFF;
46 : : else if (offset == offsetof(struct virtio_crypto_config, cipher_algo_h))
47 : 0 : *(uint32_t *)dst = dev->cipher_algo >> 32;
48 : : else if (offset == offsetof(struct virtio_crypto_config, hash_algo))
49 : 0 : *(uint32_t *)dst = dev->hash_algo;
50 : : else if (offset == offsetof(struct virtio_crypto_config, mac_algo_l))
51 : 0 : *(uint32_t *)dst = dev->auth_algo & 0xFFFF;
52 : : else if (offset == offsetof(struct virtio_crypto_config, mac_algo_h))
53 : 0 : *(uint32_t *)dst = dev->auth_algo >> 32;
54 : : else if (offset == offsetof(struct virtio_crypto_config, aead_algo))
55 : 0 : *(uint32_t *)dst = dev->aead_algo;
56 : : else if (offset == offsetof(struct virtio_crypto_config, akcipher_algo))
57 : 0 : *(uint32_t *)dst = dev->akcipher_algo;
58 : 0 : }
59 : :
60 : : static void
61 : 0 : virtio_user_write_dev_config(struct virtio_crypto_hw *hw, size_t offset,
62 : : const void *src, int length)
63 : : {
64 : : RTE_SET_USED(hw);
65 : : RTE_SET_USED(src);
66 : :
67 : 0 : PMD_DRV_LOG(ERR, "not supported offset=%zu, len=%d",
68 : : offset, length);
69 : 0 : }
70 : :
71 : : static void
72 : 0 : virtio_user_reset(struct virtio_crypto_hw *hw)
73 : : {
74 : : struct virtio_user_dev *dev = virtio_user_get_dev(hw);
75 : :
76 [ # # # # ]: 0 : if (dev->status & VIRTIO_CONFIG_STATUS_DRIVER_OK)
77 : 0 : crypto_virtio_user_stop_device(dev);
78 : 0 : }
79 : :
80 : : static void
81 : 0 : virtio_user_set_status(struct virtio_crypto_hw *hw, uint8_t status)
82 : : {
83 : : struct virtio_user_dev *dev = virtio_user_get_dev(hw);
84 : 0 : uint8_t old_status = dev->status;
85 : :
86 [ # # # # ]: 0 : if (status & VIRTIO_CONFIG_STATUS_FEATURES_OK &&
87 : : ~old_status & VIRTIO_CONFIG_STATUS_FEATURES_OK) {
88 : 0 : crypto_virtio_user_dev_set_features(dev);
89 : : /* Feature negotiation should be only done in probe time.
90 : : * So we skip any more request here.
91 : : */
92 : 0 : dev->status |= VIRTIO_CONFIG_STATUS_FEATURES_OK;
93 : : }
94 : :
95 [ # # ]: 0 : if (status & VIRTIO_CONFIG_STATUS_DRIVER_OK) {
96 [ # # ]: 0 : if (crypto_virtio_user_start_device(dev)) {
97 : 0 : crypto_virtio_user_dev_update_status(dev);
98 : 0 : return;
99 : : }
100 [ # # ]: 0 : } else if (status == VIRTIO_CONFIG_STATUS_RESET) {
101 : : virtio_user_reset(hw);
102 : : }
103 : :
104 : 0 : crypto_virtio_user_dev_set_status(dev, status);
105 [ # # # # ]: 0 : if (status & VIRTIO_CONFIG_STATUS_DRIVER_OK && dev->scvq) {
106 [ # # ]: 0 : if (dev->ops->cvq_enable(dev, 1) < 0) {
107 : 0 : PMD_INIT_LOG(ERR, "(%s) Failed to start ctrlq", dev->path);
108 : 0 : crypto_virtio_user_dev_update_status(dev);
109 : 0 : return;
110 : : }
111 : : }
112 : : }
113 : :
114 : : static uint8_t
115 : 0 : virtio_user_get_status(struct virtio_crypto_hw *hw)
116 : : {
117 : : struct virtio_user_dev *dev = virtio_user_get_dev(hw);
118 : :
119 : 0 : crypto_virtio_user_dev_update_status(dev);
120 : :
121 : 0 : return dev->status;
122 : : }
123 : :
124 : : #define VIRTIO_USER_CRYPTO_PMD_GUEST_FEATURES \
125 : : (1ULL << VIRTIO_CRYPTO_SERVICE_CIPHER | \
126 : : 1ULL << VIRTIO_CRYPTO_SERVICE_AKCIPHER | \
127 : : 1ULL << VIRTIO_F_VERSION_1 | \
128 : : 1ULL << VIRTIO_F_IN_ORDER | \
129 : : 1ULL << VIRTIO_F_RING_PACKED | \
130 : : 1ULL << VIRTIO_F_NOTIFICATION_DATA | \
131 : : 1ULL << VIRTIO_RING_F_INDIRECT_DESC | \
132 : : 1ULL << VIRTIO_F_ORDER_PLATFORM)
133 : :
134 : : static uint64_t
135 : 0 : virtio_user_get_features(struct virtio_crypto_hw *hw)
136 : : {
137 : : struct virtio_user_dev *dev = virtio_user_get_dev(hw);
138 : :
139 : : /* unmask feature bits defined in vhost user protocol */
140 : 0 : return (dev->device_features | dev->frontend_features) &
141 : : VIRTIO_USER_CRYPTO_PMD_GUEST_FEATURES;
142 : : }
143 : :
144 : : static void
145 : 0 : virtio_user_set_features(struct virtio_crypto_hw *hw, uint64_t features)
146 : : {
147 : : struct virtio_user_dev *dev = virtio_user_get_dev(hw);
148 : :
149 : 0 : dev->features = features & (dev->device_features | dev->frontend_features);
150 : 0 : }
151 : :
152 : : static uint8_t
153 : 0 : virtio_user_get_isr(struct virtio_crypto_hw *hw __rte_unused)
154 : : {
155 : : /* rxq interrupts and config interrupt are separated in virtio-user,
156 : : * here we only report config change.
157 : : */
158 : 0 : return VIRTIO_PCI_CAP_ISR_CFG;
159 : : }
160 : :
161 : : static uint16_t
162 : 0 : virtio_user_set_config_irq(struct virtio_crypto_hw *hw __rte_unused,
163 : : uint16_t vec __rte_unused)
164 : : {
165 : 0 : return 0;
166 : : }
167 : :
168 : : static uint16_t
169 : 0 : virtio_user_set_queue_irq(struct virtio_crypto_hw *hw __rte_unused,
170 : : struct virtqueue *vq __rte_unused,
171 : : uint16_t vec)
172 : : {
173 : : /* pretend we have done that */
174 : 0 : return vec;
175 : : }
176 : :
177 : : /* This function is to get the queue size, aka, number of descs, of a specified
178 : : * queue. Different with the VHOST_USER_GET_QUEUE_NUM, which is used to get the
179 : : * max supported queues.
180 : : */
181 : : static uint16_t
182 : 0 : virtio_user_get_queue_num(struct virtio_crypto_hw *hw, uint16_t queue_id __rte_unused)
183 : : {
184 : : struct virtio_user_dev *dev = virtio_user_get_dev(hw);
185 : :
186 : : /* Currently, each queue has same queue size */
187 : 0 : return dev->queue_size;
188 : : }
189 : :
190 : : static void
191 : 0 : virtio_user_setup_queue_packed(struct virtqueue *vq,
192 : : struct virtio_user_dev *dev)
193 : : {
194 : 0 : uint16_t queue_idx = vq->vq_queue_index;
195 : : struct vring_packed *vring;
196 : : uint64_t desc_addr;
197 : : uint64_t avail_addr;
198 : : uint64_t used_addr;
199 : : uint16_t i;
200 : :
201 : 0 : vring = &dev->vrings.packed[queue_idx];
202 : 0 : desc_addr = (uintptr_t)vq->vq_ring_virt_mem;
203 : 0 : avail_addr = desc_addr + vq->vq_nentries *
204 : : sizeof(struct vring_packed_desc);
205 : 0 : used_addr = RTE_ALIGN_CEIL(avail_addr +
206 : : sizeof(struct vring_packed_desc_event),
207 : : VIRTIO_VRING_ALIGN);
208 : 0 : vring->num = vq->vq_nentries;
209 : 0 : vring->desc_iova = vq->vq_ring_mem;
210 : 0 : vring->desc = (void *)(uintptr_t)desc_addr;
211 : 0 : vring->driver = (void *)(uintptr_t)avail_addr;
212 : 0 : vring->device = (void *)(uintptr_t)used_addr;
213 : 0 : dev->packed_queues[queue_idx].avail_wrap_counter = true;
214 : 0 : dev->packed_queues[queue_idx].used_wrap_counter = true;
215 : 0 : dev->packed_queues[queue_idx].used_idx = 0;
216 : :
217 [ # # ]: 0 : for (i = 0; i < vring->num; i++)
218 : 0 : vring->desc[i].flags = 0;
219 : 0 : }
220 : :
221 : : static void
222 : : virtio_user_setup_queue_split(struct virtqueue *vq, struct virtio_user_dev *dev)
223 : : {
224 : 0 : uint16_t queue_idx = vq->vq_queue_index;
225 : : uint64_t desc_addr, avail_addr, used_addr;
226 : :
227 : 0 : desc_addr = (uintptr_t)vq->vq_ring_virt_mem;
228 : 0 : avail_addr = desc_addr + vq->vq_nentries * sizeof(struct vring_desc);
229 : 0 : used_addr = RTE_ALIGN_CEIL(avail_addr + offsetof(struct vring_avail,
230 : : ring[vq->vq_nentries]),
231 : : VIRTIO_VRING_ALIGN);
232 : :
233 : 0 : dev->vrings.split[queue_idx].num = vq->vq_nentries;
234 : 0 : dev->vrings.split[queue_idx].desc_iova = vq->vq_ring_mem;
235 : 0 : dev->vrings.split[queue_idx].desc = (void *)(uintptr_t)desc_addr;
236 : 0 : dev->vrings.split[queue_idx].avail = (void *)(uintptr_t)avail_addr;
237 : 0 : dev->vrings.split[queue_idx].used = (void *)(uintptr_t)used_addr;
238 : 0 : }
239 : :
240 : : static int
241 [ # # ]: 0 : virtio_user_setup_queue(struct virtio_crypto_hw *hw, struct virtqueue *vq)
242 : : {
243 : : struct virtio_user_dev *dev = virtio_user_get_dev(hw);
244 : :
245 [ # # ]: 0 : if (vtpci_with_packed_queue(hw))
246 : 0 : virtio_user_setup_queue_packed(vq, dev);
247 : : else
248 : : virtio_user_setup_queue_split(vq, dev);
249 : :
250 [ # # ]: 0 : if (dev->notify_area)
251 : 0 : vq->notify_addr = dev->notify_area[vq->vq_queue_index];
252 : :
253 [ # # ]: 0 : if (virtcrypto_cq_to_vq(hw->cvq) == vq)
254 : 0 : dev->scvq = virtcrypto_cq_to_vq(hw->cvq);
255 : :
256 : 0 : return 0;
257 : : }
258 : :
259 : : static void
260 : 0 : virtio_user_del_queue(struct virtio_crypto_hw *hw, struct virtqueue *vq)
261 : : {
262 : : RTE_SET_USED(hw);
263 : : RTE_SET_USED(vq);
264 : 0 : }
265 : :
266 : : static void
267 : 0 : virtio_user_notify_queue(struct virtio_crypto_hw *hw, struct virtqueue *vq)
268 : : {
269 : : struct virtio_user_dev *dev = virtio_user_get_dev(hw);
270 : 0 : uint64_t notify_data = 1;
271 : :
272 [ # # ]: 0 : if (!dev->notify_area) {
273 [ # # ]: 0 : if (write(dev->kickfds[vq->vq_queue_index], ¬ify_data,
274 : : sizeof(notify_data)) < 0)
275 : 0 : PMD_DRV_LOG(ERR, "failed to kick backend: %s",
276 : : strerror(errno));
277 : 0 : return;
278 [ # # ]: 0 : } else if (!vtpci_with_feature(hw, VIRTIO_F_NOTIFICATION_DATA)) {
279 : 0 : rte_write16(vq->vq_queue_index, vq->notify_addr);
280 : 0 : return;
281 : : }
282 : :
283 [ # # ]: 0 : if (vtpci_with_packed_queue(hw)) {
284 : : /* Bit[0:15]: vq queue index
285 : : * Bit[16:30]: avail index
286 : : * Bit[31]: avail wrap counter
287 : : */
288 : 0 : notify_data = ((uint32_t)(!!(vq->vq_packed.cached_flags &
289 : 0 : VRING_PACKED_DESC_F_AVAIL)) << 31) |
290 : 0 : ((uint32_t)vq->vq_avail_idx << 16) |
291 : 0 : vq->vq_queue_index;
292 : : } else {
293 : : /* Bit[0:15]: vq queue index
294 : : * Bit[16:31]: avail index
295 : : */
296 : 0 : notify_data = ((uint32_t)vq->vq_avail_idx << 16) |
297 : 0 : vq->vq_queue_index;
298 : : }
299 : 0 : rte_write32(notify_data, vq->notify_addr);
300 : : }
301 : :
302 : : const struct virtio_pci_ops crypto_virtio_user_ops = {
303 : : .read_dev_cfg = virtio_user_read_dev_config,
304 : : .write_dev_cfg = virtio_user_write_dev_config,
305 : : .reset = virtio_user_reset,
306 : : .get_status = virtio_user_get_status,
307 : : .set_status = virtio_user_set_status,
308 : : .get_features = virtio_user_get_features,
309 : : .set_features = virtio_user_set_features,
310 : : .get_isr = virtio_user_get_isr,
311 : : .set_config_irq = virtio_user_set_config_irq,
312 : : .set_queue_irq = virtio_user_set_queue_irq,
313 : : .get_queue_num = virtio_user_get_queue_num,
314 : : .setup_queue = virtio_user_setup_queue,
315 : : .del_queue = virtio_user_del_queue,
316 : : .notify_queue = virtio_user_notify_queue,
317 : : };
318 : :
319 : : static const char * const valid_args[] = {
320 : : #define VIRTIO_USER_ARG_QUEUES_NUM "queues"
321 : : VIRTIO_USER_ARG_QUEUES_NUM,
322 : : #define VIRTIO_USER_ARG_QUEUE_SIZE "queue_size"
323 : : VIRTIO_USER_ARG_QUEUE_SIZE,
324 : : #define VIRTIO_USER_ARG_PATH "path"
325 : : VIRTIO_USER_ARG_PATH,
326 : : NULL
327 : : };
328 : :
329 : : #define VIRTIO_USER_DEF_Q_NUM 1
330 : : #define VIRTIO_USER_DEF_Q_SZ 256
331 : : #define VIRTIO_USER_DEF_SERVER_MODE 0
332 : :
333 : : static int
334 : 0 : get_string_arg(const char *key __rte_unused,
335 : : const char *value, void *extra_args)
336 : : {
337 [ # # ]: 0 : if (!value || !extra_args)
338 : : return -EINVAL;
339 : :
340 : 0 : *(char **)extra_args = strdup(value);
341 : :
342 [ # # ]: 0 : if (!*(char **)extra_args)
343 : 0 : return -ENOMEM;
344 : :
345 : : return 0;
346 : : }
347 : :
348 : : static int
349 : 0 : get_integer_arg(const char *key __rte_unused,
350 : : const char *value, void *extra_args)
351 : : {
352 : : uint64_t integer = 0;
353 [ # # ]: 0 : if (!value || !extra_args)
354 : : return -EINVAL;
355 : 0 : errno = 0;
356 : 0 : integer = strtoull(value, NULL, 0);
357 : : /* extra_args keeps default value, it should be replaced
358 : : * only in case of successful parsing of the 'value' arg
359 : : */
360 [ # # ]: 0 : if (errno == 0)
361 : 0 : *(uint64_t *)extra_args = integer;
362 : 0 : return -errno;
363 : : }
364 : :
365 : : static struct rte_cryptodev *
366 : 0 : virtio_user_cryptodev_alloc(struct rte_vdev_device *vdev)
367 : : {
368 : 0 : struct rte_cryptodev_pmd_init_params init_params = {
369 : : .name = "",
370 : : .private_data_size = sizeof(struct virtio_user_dev),
371 : : };
372 : : struct rte_cryptodev_data *data;
373 : : struct rte_cryptodev *cryptodev;
374 : : struct virtio_user_dev *dev;
375 : : struct virtio_crypto_hw *hw;
376 : :
377 : 0 : init_params.socket_id = vdev->device.numa_node;
378 : : init_params.private_data_size = sizeof(struct virtio_user_dev);
379 : 0 : cryptodev = rte_cryptodev_pmd_create(vdev->device.name, &vdev->device, &init_params);
380 [ # # ]: 0 : if (cryptodev == NULL) {
381 : 0 : PMD_INIT_LOG(ERR, "failed to create cryptodev vdev");
382 : 0 : return NULL;
383 : : }
384 : :
385 : 0 : data = cryptodev->data;
386 : 0 : dev = data->dev_private;
387 : : hw = &dev->hw;
388 : :
389 : 0 : hw->dev_id = data->dev_id;
390 : 0 : VTPCI_OPS(hw) = &crypto_virtio_user_ops;
391 : :
392 : 0 : return cryptodev;
393 : : }
394 : :
395 : : static void
396 : : virtio_user_cryptodev_free(struct rte_cryptodev *cryptodev)
397 : : {
398 : 0 : rte_cryptodev_pmd_destroy(cryptodev);
399 : : }
400 : :
401 : : static int
402 : 0 : virtio_user_pmd_probe(struct rte_vdev_device *vdev)
403 : : {
404 : : uint64_t server_mode = VIRTIO_USER_DEF_SERVER_MODE;
405 : 0 : uint64_t queue_size = VIRTIO_USER_DEF_Q_SZ;
406 : 0 : uint64_t queues = VIRTIO_USER_DEF_Q_NUM;
407 : : struct rte_cryptodev *cryptodev = NULL;
408 : : struct rte_kvargs *kvlist = NULL;
409 : : struct virtio_user_dev *dev;
410 [ # # ]: 0 : char *path = NULL;
411 : : int ret = -1;
412 : :
413 : 0 : kvlist = rte_kvargs_parse(rte_vdev_device_args(vdev), valid_args);
414 : :
415 [ # # ]: 0 : if (!kvlist) {
416 : 0 : PMD_INIT_LOG(ERR, "error when parsing param");
417 : 0 : goto end;
418 : : }
419 : :
420 [ # # ]: 0 : if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_PATH) == 1) {
421 [ # # ]: 0 : if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_PATH,
422 : : &get_string_arg, &path) < 0) {
423 : 0 : PMD_INIT_LOG(ERR, "error to parse %s",
424 : : VIRTIO_USER_ARG_PATH);
425 : 0 : goto end;
426 : : }
427 : : } else {
428 : 0 : PMD_INIT_LOG(ERR, "arg %s is mandatory for virtio_user",
429 : : VIRTIO_USER_ARG_PATH);
430 : 0 : goto end;
431 : : }
432 : :
433 [ # # ]: 0 : if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_QUEUES_NUM) == 1) {
434 [ # # ]: 0 : if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_QUEUES_NUM,
435 : : &get_integer_arg, &queues) < 0) {
436 : 0 : PMD_INIT_LOG(ERR, "error to parse %s",
437 : : VIRTIO_USER_ARG_QUEUES_NUM);
438 : 0 : goto end;
439 : : }
440 : : }
441 : :
442 [ # # ]: 0 : if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_QUEUE_SIZE) == 1) {
443 [ # # ]: 0 : if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_QUEUE_SIZE,
444 : : &get_integer_arg, &queue_size) < 0) {
445 : 0 : PMD_INIT_LOG(ERR, "error to parse %s",
446 : : VIRTIO_USER_ARG_QUEUE_SIZE);
447 : 0 : goto end;
448 : : }
449 : : }
450 : :
451 : 0 : cryptodev = virtio_user_cryptodev_alloc(vdev);
452 [ # # ]: 0 : if (!cryptodev) {
453 : 0 : PMD_INIT_LOG(ERR, "virtio_user fails to alloc device");
454 : 0 : goto end;
455 : : }
456 : :
457 : 0 : dev = cryptodev->data->dev_private;
458 [ # # ]: 0 : if (crypto_virtio_user_dev_init(dev, path, queues, queue_size,
459 : : server_mode) < 0) {
460 : 0 : PMD_INIT_LOG(ERR, "virtio_user_dev_init fails");
461 : : virtio_user_cryptodev_free(cryptodev);
462 : 0 : goto end;
463 : : }
464 : :
465 : 0 : cryptodev->driver_id = cryptodev_virtio_user_driver_id;
466 [ # # ]: 0 : if (crypto_virtio_dev_init(cryptodev, VIRTIO_USER_CRYPTO_PMD_GUEST_FEATURES,
467 : : NULL) < 0) {
468 : 0 : PMD_INIT_LOG(ERR, "crypto_virtio_dev_init fails");
469 : 0 : crypto_virtio_user_dev_uninit(dev);
470 : : virtio_user_cryptodev_free(cryptodev);
471 : 0 : goto end;
472 : : }
473 : :
474 : 0 : rte_cryptodev_pmd_probing_finish(cryptodev);
475 : :
476 : : ret = 0;
477 : 0 : end:
478 : 0 : rte_kvargs_free(kvlist);
479 : 0 : free(path);
480 : 0 : return ret;
481 : : }
482 : :
483 : : static int
484 : 0 : virtio_user_pmd_remove(struct rte_vdev_device *vdev)
485 : : {
486 : : struct rte_cryptodev *cryptodev;
487 : : const char *name;
488 : : int devid;
489 : :
490 [ # # ]: 0 : if (!vdev)
491 : : return -EINVAL;
492 : :
493 : : name = rte_vdev_device_name(vdev);
494 : 0 : PMD_DRV_LOG(INFO, "Removing %s", name);
495 : :
496 : 0 : devid = rte_cryptodev_get_dev_id(name);
497 [ # # ]: 0 : if (devid < 0)
498 : : return -EINVAL;
499 : :
500 : 0 : rte_cryptodev_stop(devid);
501 : :
502 : 0 : cryptodev = rte_cryptodev_pmd_get_named_dev(name);
503 [ # # ]: 0 : if (cryptodev == NULL)
504 : : return -ENODEV;
505 : :
506 [ # # ]: 0 : if (rte_cryptodev_pmd_destroy(cryptodev) < 0) {
507 : 0 : PMD_DRV_LOG(ERR, "Failed to remove %s", name);
508 : 0 : return -EFAULT;
509 : : }
510 : :
511 : : return 0;
512 : : }
513 : :
514 : 0 : static int virtio_user_pmd_dma_map(struct rte_vdev_device *vdev, void *addr,
515 : : uint64_t iova, size_t len)
516 : : {
517 : : struct rte_cryptodev *cryptodev;
518 : : struct virtio_user_dev *dev;
519 : : const char *name;
520 : :
521 [ # # ]: 0 : if (!vdev)
522 : : return -EINVAL;
523 : :
524 : : name = rte_vdev_device_name(vdev);
525 : 0 : cryptodev = rte_cryptodev_pmd_get_named_dev(name);
526 [ # # ]: 0 : if (cryptodev == NULL)
527 : : return -EINVAL;
528 : :
529 : 0 : dev = cryptodev->data->dev_private;
530 : :
531 [ # # ]: 0 : if (dev->ops->dma_map)
532 : 0 : return dev->ops->dma_map(dev, addr, iova, len);
533 : :
534 : : return 0;
535 : : }
536 : :
537 : 0 : static int virtio_user_pmd_dma_unmap(struct rte_vdev_device *vdev, void *addr,
538 : : uint64_t iova, size_t len)
539 : : {
540 : : struct rte_cryptodev *cryptodev;
541 : : struct virtio_user_dev *dev;
542 : : const char *name;
543 : :
544 [ # # ]: 0 : if (!vdev)
545 : : return -EINVAL;
546 : :
547 : : name = rte_vdev_device_name(vdev);
548 : 0 : cryptodev = rte_cryptodev_pmd_get_named_dev(name);
549 [ # # ]: 0 : if (cryptodev == NULL)
550 : : return -EINVAL;
551 : :
552 : 0 : dev = cryptodev->data->dev_private;
553 : :
554 [ # # ]: 0 : if (dev->ops->dma_unmap)
555 : 0 : return dev->ops->dma_unmap(dev, addr, iova, len);
556 : :
557 : : return 0;
558 : : }
559 : :
560 : : static struct rte_vdev_driver virtio_user_driver = {
561 : : .probe = virtio_user_pmd_probe,
562 : : .remove = virtio_user_pmd_remove,
563 : : .dma_map = virtio_user_pmd_dma_map,
564 : : .dma_unmap = virtio_user_pmd_dma_unmap,
565 : : };
566 : :
567 : : static struct cryptodev_driver virtio_crypto_drv;
568 : :
569 : 254 : RTE_PMD_REGISTER_VDEV(crypto_virtio_user, virtio_user_driver);
570 : 254 : RTE_PMD_REGISTER_CRYPTO_DRIVER(virtio_crypto_drv,
571 : : virtio_user_driver.driver,
572 : : cryptodev_virtio_user_driver_id);
573 : : RTE_PMD_REGISTER_PARAM_STRING(crypto_virtio_user,
574 : : "path=<path> "
575 : : "queues=<int> "
576 : : "queue_size=<int>");
|