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