3 *------------------------------------------------------------------
4 * Copyright (c) 2019 - 2021 Intel and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *------------------------------------------------------------------
19 #include <vlib/vlib.h>
20 #include <vnet/crypto/crypto.h>
22 #include <dpdk/buffer.h>
23 #include <dpdk/device/dpdk.h>
24 #include <dpdk/device/dpdk_priv.h>
26 #include <rte_bus_vdev.h>
27 #include <rte_cryptodev.h>
28 #include <rte_crypto_sym.h>
29 #include <rte_crypto.h>
30 #include <rte_ring_peek_zc.h>
31 #include <rte_config.h>
33 #include "cryptodev.h"
36 #define always_inline static inline
38 #define always_inline static inline __attribute__ ((__always_inline__))
41 #define CRYPTODEV_AAD_OFFSET (offsetof (cryptodev_op_t, aad))
43 #define foreach_vnet_crypto_status_conversion \
44 _ (SUCCESS, COMPLETED) \
45 _ (NOT_PROCESSED, WORK_IN_PROGRESS) \
46 _ (AUTH_FAILED, FAIL_BAD_HMAC) \
47 _ (INVALID_SESSION, FAIL_ENGINE_ERR) \
48 _ (INVALID_ARGS, FAIL_ENGINE_ERR) \
49 _ (ERROR, FAIL_ENGINE_ERR)
51 static const vnet_crypto_op_status_t cryptodev_status_conversion[] = {
52 #define _(a, b) VNET_CRYPTO_OP_STATUS_##b,
53 foreach_vnet_crypto_status_conversion
57 static_always_inline rte_iova_t
58 cryptodev_get_iova (clib_pmalloc_main_t *pm, enum rte_iova_mode mode,
62 if (mode == RTE_IOVA_VA)
63 return (rte_iova_t) pointer_to_uword (data);
65 index = clib_pmalloc_get_page_index (pm, data);
66 return pointer_to_uword (data) - pm->lookup_table[index];
69 static_always_inline void
70 cryptodev_validate_mbuf (struct rte_mbuf *mb, vlib_buffer_t *b)
72 /* on vnet side vlib_buffer current_length is updated by cipher padding and
73 * icv_sh. mbuf needs to be sync with these changes */
74 u16 data_len = b->current_length +
75 (b->data + b->current_data - rte_pktmbuf_mtod (mb, u8 *));
77 /* for input nodes that are not dpdk-input, it is possible the mbuf
78 * was updated before as one of the chained mbufs. Setting nb_segs
79 * to 1 here to prevent the cryptodev PMD to access potentially
80 * invalid m_src->next pointers.
83 mb->pkt_len = mb->data_len = data_len;
86 static_always_inline void
87 cryptodev_validate_mbuf_chain (vlib_main_t *vm, struct rte_mbuf *mb,
90 struct rte_mbuf *first_mb = mb, *last_mb = mb; /**< last mbuf */
91 /* when input node is not dpdk, mbuf data len is not initialized, for
92 * single buffer it is not a problem since the data length is written
93 * into cryptodev operation. For chained buffer a reference data length
94 * has to be computed through vlib_buffer.
96 * even when input node is dpdk, it is possible chained vlib_buffers
97 * are updated (either added or removed a buffer) but not not mbuf fields.
98 * we have to re-link every mbuf in the chain.
100 u16 data_len = b->current_length +
101 (b->data + b->current_data - rte_pktmbuf_mtod (mb, u8 *));
103 first_mb->nb_segs = 1;
104 first_mb->pkt_len = first_mb->data_len = data_len;
106 while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
108 b = vlib_get_buffer (vm, b->next_buffer);
109 mb = rte_mbuf_from_vlib_buffer (b);
110 if (PREDICT_FALSE ((b->flags & VLIB_BUFFER_EXT_HDR_VALID) == 0))
111 rte_pktmbuf_reset (mb);
114 mb->data_len = b->current_length;
115 mb->pkt_len = b->current_length;
116 mb->data_off = VLIB_BUFFER_PRE_DATA_SIZE + b->current_data;
118 if (PREDICT_FALSE (b->ref_count > 1))
120 dpdk_no_cache_mempool_by_buffer_pool_index[b->buffer_pool_index];
124 static_always_inline void
125 crypto_op_init (struct rte_mempool *mempool,
126 void *_arg __attribute__ ((unused)), void *_obj,
127 unsigned i __attribute__ ((unused)))
129 struct rte_crypto_op *op = _obj;
131 op->sess_type = RTE_CRYPTO_OP_WITH_SESSION;
132 op->type = RTE_CRYPTO_OP_TYPE_SYMMETRIC;
133 op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
134 op->phys_addr = rte_mempool_virt2iova (_obj);
135 op->mempool = mempool;
138 static_always_inline int
139 cryptodev_frame_linked_algs_enqueue (vlib_main_t *vm,
140 vnet_crypto_async_frame_t *frame,
141 cryptodev_op_type_t op_type)
143 cryptodev_main_t *cmt = &cryptodev_main;
144 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
145 cryptodev_cache_ring_t *ring = &cet->cache_ring;
146 ERROR_ASSERT (frame != 0);
147 ERROR_ASSERT (frame->n_elts > 0);
148 cryptodev_cache_ring_elt_t *ring_elt =
149 cryptodev_cache_ring_push (ring, frame);
151 if (PREDICT_FALSE (ring_elt == NULL))
154 ring_elt->aad_len = 1;
155 ring_elt->op_type = (u8) op_type;
159 static_always_inline void
160 cryptodev_frame_linked_algs_enqueue_internal (vlib_main_t *vm,
161 vnet_crypto_async_frame_t *frame,
162 cryptodev_op_type_t op_type)
164 cryptodev_main_t *cmt = &cryptodev_main;
165 clib_pmalloc_main_t *pm = vm->physmem_main.pmalloc_main;
166 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
167 cryptodev_cache_ring_t *ring = &cet->cache_ring;
168 u16 *const enq = &ring->enq_head;
169 vnet_crypto_async_frame_elt_t *fe;
170 cryptodev_session_t *sess = 0;
171 cryptodev_op_t *cops[CRYPTODE_ENQ_MAX] = {};
172 cryptodev_op_t **cop = cops;
174 u32 n_enqueue, n_elts;
175 u32 last_key_index = ~0;
178 if (PREDICT_FALSE (frame == 0 || frame->n_elts == 0))
181 max_to_enq = clib_min (CRYPTODE_ENQ_MAX,
182 frame->n_elts - ring->frames[*enq].enq_elts_head);
184 if (cet->inflight + max_to_enq > CRYPTODEV_MAX_INFLIGHT)
190 rte_mempool_get_bulk (cet->cop_pool, (void **) cops, n_elts) < 0))
192 cryptodev_mark_frame_fill_err (
193 frame, ring->frames[*enq].frame_elts_errs_mask,
194 ring->frames[*enq].enq_elts_head, max_to_enq,
195 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
196 ring->frames[*enq].enq_elts_head += max_to_enq;
197 ring->frames[*enq].deq_elts_tail += max_to_enq;
198 cryptodev_cache_ring_update_enq_head (ring, frame);
202 fe = frame->elts + ring->frames[*enq].enq_elts_head;
203 bi = frame->buffer_indices + ring->frames[*enq].enq_elts_head;
207 vlib_buffer_t *b = vlib_get_buffer (vm, bi[0]);
208 struct rte_crypto_sym_op *sop = &cop[0]->sop;
209 i16 crypto_offset = fe->crypto_start_offset;
210 i16 integ_offset = fe->integ_start_offset;
211 u32 offset_diff = crypto_offset - integ_offset;
215 CLIB_PREFETCH (cop[1], sizeof (*cop[1]), STORE);
216 CLIB_PREFETCH (cop[2], sizeof (*cop[2]), STORE);
217 clib_prefetch_load (&fe[1]);
218 clib_prefetch_load (&fe[2]);
220 if (last_key_index != fe->key_index)
222 cryptodev_key_t *key = vec_elt_at_index (cmt->keys, fe->key_index);
223 last_key_index = fe->key_index;
225 if (key->keys[vm->numa_node][op_type] == 0)
228 cryptodev_session_create (vm, last_key_index, 0) < 0))
230 cryptodev_mark_frame_fill_err (
231 frame, ring->frames[*enq].frame_elts_errs_mask,
232 ring->frames[*enq].enq_elts_head, max_to_enq,
233 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
237 sess = key->keys[vm->numa_node][op_type];
240 sop->m_src = rte_mbuf_from_vlib_buffer (b);
241 sop->m_src->data_off = VLIB_BUFFER_PRE_DATA_SIZE;
243 /* mbuf prepend happens in the tx, but vlib_buffer happens in the nodes,
244 * so we have to manually adjust mbuf data_off here so cryptodev can
245 * correctly compute the data pointer. The prepend here will be later
246 * rewritten by tx. */
247 if (PREDICT_TRUE (fe->integ_start_offset < 0))
249 sop->m_src->data_off += fe->integ_start_offset;
251 crypto_offset = offset_diff;
254 sop->cipher.data.offset = crypto_offset;
255 sop->cipher.data.length = fe->crypto_total_length;
256 sop->auth.data.offset = integ_offset;
257 sop->auth.data.length = fe->crypto_total_length + fe->integ_length_adj;
258 sop->auth.digest.data = fe->digest;
259 sop->auth.digest.phys_addr =
260 cryptodev_get_iova (pm, cmt->iova_mode, fe->digest);
261 if (PREDICT_FALSE (fe->flags & VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS))
262 cryptodev_validate_mbuf_chain (vm, sop->m_src, b);
264 cryptodev_validate_mbuf (sop->m_src, b);
266 clib_memcpy_fast (cop[0]->iv, fe->iv, 16);
267 ring->frames[*enq].enq_elts_head++;
275 rte_cryptodev_enqueue_burst (cet->cryptodev_id, cet->cryptodev_q,
276 (struct rte_crypto_op **) cops, max_to_enq);
277 ERROR_ASSERT (n_enqueue == max_to_enq);
278 cet->inflight += max_to_enq;
279 cryptodev_cache_ring_update_enq_head (ring, frame);
283 ring->frames[*enq].enq_elts_head += max_to_enq;
284 ring->frames[*enq].deq_elts_tail += max_to_enq;
285 cryptodev_cache_ring_update_enq_head (ring, frame);
286 rte_mempool_put_bulk (cet->cop_pool, (void **) cops, max_to_enq);
289 static_always_inline int
290 cryptodev_frame_aead_enqueue (vlib_main_t *vm,
291 vnet_crypto_async_frame_t *frame,
292 cryptodev_op_type_t op_type, u8 aad_len)
294 cryptodev_main_t *cmt = &cryptodev_main;
295 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
296 cryptodev_cache_ring_t *ring = &cet->cache_ring;
297 ERROR_ASSERT (frame != 0);
298 ERROR_ASSERT (frame->n_elts > 0);
299 cryptodev_cache_ring_elt_t *ring_elt =
300 cryptodev_cache_ring_push (ring, frame);
302 if (PREDICT_FALSE (ring_elt == NULL))
305 ring_elt->aad_len = aad_len;
306 ring_elt->op_type = (u8) op_type;
310 static_always_inline int
311 cryptodev_aead_enqueue_internal (vlib_main_t *vm,
312 vnet_crypto_async_frame_t *frame,
313 cryptodev_op_type_t op_type, u8 aad_len)
315 cryptodev_main_t *cmt = &cryptodev_main;
316 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
317 cryptodev_cache_ring_t *ring = &cet->cache_ring;
318 u16 *const enq = &ring->enq_head;
319 clib_pmalloc_main_t *pm = vm->physmem_main.pmalloc_main;
320 vnet_crypto_async_frame_elt_t *fe;
321 cryptodev_session_t *sess = 0;
322 cryptodev_op_t *cops[CRYPTODE_ENQ_MAX] = {};
323 cryptodev_op_t **cop = cops;
325 u32 n_enqueue = 0, n_elts;
326 u32 last_key_index = ~0;
327 u16 left_to_enq = frame->n_elts - ring->frames[*enq].enq_elts_head;
328 const u16 max_to_enq = clib_min (CRYPTODE_ENQ_MAX, left_to_enq);
330 if (PREDICT_FALSE (frame == 0 || frame->n_elts == 0))
333 if (cet->inflight + max_to_enq > CRYPTODEV_MAX_INFLIGHT)
339 rte_mempool_get_bulk (cet->cop_pool, (void **) cops, n_elts) < 0))
341 cryptodev_mark_frame_fill_err (
342 frame, ring->frames[*enq].frame_elts_errs_mask,
343 ring->frames[*enq].enq_elts_head, max_to_enq,
344 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
345 ring->frames[*enq].enq_elts_head += max_to_enq;
346 ring->frames[*enq].deq_elts_tail += max_to_enq;
347 cryptodev_cache_ring_update_enq_head (ring, frame);
351 fe = frame->elts + ring->frames[*enq].enq_elts_head;
352 bi = frame->buffer_indices + ring->frames[*enq].enq_elts_head;
356 vlib_buffer_t *b = vlib_get_buffer (vm, bi[0]);
357 struct rte_crypto_sym_op *sop = &cop[0]->sop;
358 u16 crypto_offset = fe->crypto_start_offset;
362 CLIB_PREFETCH (cop[1], sizeof (*cop[1]), STORE);
363 CLIB_PREFETCH (cop[2], sizeof (*cop[2]), STORE);
364 clib_prefetch_load (&fe[1]);
365 clib_prefetch_load (&fe[2]);
367 if (last_key_index != fe->key_index)
369 cryptodev_key_t *key = vec_elt_at_index (cmt->keys, fe->key_index);
371 last_key_index = fe->key_index;
372 if (key->keys[vm->numa_node][op_type] == 0)
374 if (PREDICT_FALSE (cryptodev_session_create (vm, last_key_index,
377 cryptodev_mark_frame_fill_err (
378 frame, ring->frames[*enq].frame_elts_errs_mask,
379 ring->frames[*enq].enq_elts_head, max_to_enq,
380 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
384 else if (PREDICT_FALSE (
385 #if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0)
386 rte_cryptodev_sym_session_opaque_data_get (
387 key->keys[vm->numa_node][op_type]) != (u64) aad_len
389 key->keys[vm->numa_node][op_type]->opaque_data != aad_len
393 cryptodev_sess_handler (vm, VNET_CRYPTO_KEY_OP_DEL,
394 fe->key_index, aad_len);
395 if (PREDICT_FALSE (cryptodev_session_create (vm, last_key_index,
398 cryptodev_mark_frame_fill_err (
399 frame, ring->frames[*enq].frame_elts_errs_mask,
400 ring->frames[*enq].enq_elts_head, max_to_enq,
401 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
406 sess = key->keys[vm->numa_node][op_type];
409 sop->m_src = rte_mbuf_from_vlib_buffer (b);
410 sop->m_src->data_off = VLIB_BUFFER_PRE_DATA_SIZE;
412 /* mbuf prepend happens in the tx, but vlib_buffer happens in the nodes,
413 * so we have to manually adjust mbuf data_off here so cryptodev can
414 * correctly compute the data pointer. The prepend here will be later
415 * rewritten by tx. */
416 if (PREDICT_FALSE (fe->crypto_start_offset < 0))
418 rte_pktmbuf_prepend (sop->m_src, -fe->crypto_start_offset);
423 sop->aead.aad.data = cop[0]->aad;
424 sop->aead.aad.phys_addr = cop[0]->op.phys_addr + CRYPTODEV_AAD_OFFSET;
425 sop->aead.data.length = fe->crypto_total_length;
426 sop->aead.data.offset = crypto_offset;
427 sop->aead.digest.data = fe->tag;
428 sop->aead.digest.phys_addr =
429 cryptodev_get_iova (pm, cmt->iova_mode, fe->tag);
430 if (PREDICT_FALSE (fe->flags & VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS))
431 cryptodev_validate_mbuf_chain (vm, sop->m_src, b);
433 cryptodev_validate_mbuf (sop->m_src, b);
435 clib_memcpy_fast (cop[0]->iv, fe->iv, 12);
436 clib_memcpy_fast (cop[0]->aad, fe->aad, aad_len);
445 rte_cryptodev_enqueue_burst (cet->cryptodev_id, cet->cryptodev_q,
446 (struct rte_crypto_op **) cops, max_to_enq);
447 ERROR_ASSERT (n_enqueue == max_to_enq);
448 cet->inflight += max_to_enq;
449 ring->frames[*enq].enq_elts_head += max_to_enq;
450 cryptodev_cache_ring_update_enq_head (ring, frame);
455 ring->frames[*enq].enq_elts_head += max_to_enq;
456 ring->frames[*enq].deq_elts_tail += max_to_enq;
457 cryptodev_cache_ring_update_enq_head (ring, frame);
458 rte_mempool_put_bulk (cet->cop_pool, (void **) cops, max_to_enq);
463 static_always_inline u8
464 cryptodev_frame_dequeue_internal (vlib_main_t *vm, u32 *enqueue_thread_idx)
466 cryptodev_main_t *cmt = &cryptodev_main;
467 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
468 vnet_crypto_async_frame_t *frame = NULL;
469 cryptodev_cache_ring_t *ring = &cet->cache_ring;
470 u16 *const deq = &ring->deq_tail;
471 u16 n_deq, left_to_deq;
473 u16 inflight = cet->inflight;
475 cryptodev_op_t *cops[CRYPTODE_DEQ_MAX] = {};
476 cryptodev_op_t **cop = cops;
477 vnet_crypto_async_frame_elt_t *fe;
479 u64 err0 = 0, err1 = 0, err2 = 0, err3 = 0; /* partial errors mask */
482 ring->frames[*deq].f->n_elts - ring->frames[*deq].deq_elts_tail;
483 max_to_deq = clib_min (left_to_deq, CRYPTODE_DEQ_MAX);
485 /* deq field can be used to track frame that is currently dequeued
486 based on that you can specify the amount of elements to deq for the frame */
488 rte_cryptodev_dequeue_burst (cet->cryptodev_id, cet->cryptodev_q,
489 (struct rte_crypto_op **) cops, max_to_deq);
494 frame = ring->frames[*deq].f;
495 fe = frame->elts + ring->frames[*deq].deq_elts_tail;
498 n = ring->frames[*deq].deq_elts_tail;
502 fe[0].status = cryptodev_status_conversion[cop[0]->op.status];
503 fe[1].status = cryptodev_status_conversion[cop[1]->op.status];
504 fe[2].status = cryptodev_status_conversion[cop[2]->op.status];
505 fe[3].status = cryptodev_status_conversion[cop[3]->op.status];
507 err0 |= ((u64) (fe[0].status == VNET_CRYPTO_OP_STATUS_COMPLETED)) << n;
508 err1 |= ((u64) (fe[1].status == VNET_CRYPTO_OP_STATUS_COMPLETED))
510 err2 |= ((u64) (fe[2].status == VNET_CRYPTO_OP_STATUS_COMPLETED))
512 err3 |= ((u64) (fe[3].status == VNET_CRYPTO_OP_STATUS_COMPLETED))
523 fe[0].status = cryptodev_status_conversion[cop[0]->op.status];
524 err0 |= ((u64) (fe[0].status == VNET_CRYPTO_OP_STATUS_COMPLETED)) << n;
531 ring->frames[*deq].frame_elts_errs_mask |= (err0 | err1 | err2 | err3);
533 rte_mempool_put_bulk (cet->cop_pool, (void **) cops, n_deq);
536 ring->frames[*deq].deq_elts_tail += n_deq;
537 if (cryptodev_cache_ring_update_deq_tail (ring, deq))
540 (CRYPTODEV_CACHE_QUEUE_SIZE - ring->tail + ring->deq_tail) &
541 CRYPTODEV_CACHE_QUEUE_MASK;
543 *enqueue_thread_idx = frame->enqueue_thread_index;
544 dequeue_more = (fr_processed < CRYPTODEV_MAX_PROCESED_IN_CACHE_QUEUE);
547 cet->inflight = inflight;
551 static_always_inline void
552 cryptodev_enqueue_frame (vlib_main_t *vm, cryptodev_cache_ring_elt_t *ring_elt)
554 cryptodev_op_type_t op_type = (cryptodev_op_type_t) ring_elt->op_type;
555 u8 linked_or_aad_len = ring_elt->aad_len;
557 if (linked_or_aad_len == 1)
558 cryptodev_frame_linked_algs_enqueue_internal (vm, ring_elt->f, op_type);
560 cryptodev_aead_enqueue_internal (vm, ring_elt->f, op_type,
564 static_always_inline vnet_crypto_async_frame_t *
565 cryptodev_frame_dequeue (vlib_main_t *vm, u32 *nb_elts_processed,
566 u32 *enqueue_thread_idx)
568 cryptodev_main_t *cmt = &cryptodev_main;
569 vnet_crypto_main_t *cm = &crypto_main;
570 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
571 cryptodev_cache_ring_t *ring = &cet->cache_ring;
572 cryptodev_cache_ring_elt_t *ring_elt = &ring->frames[ring->tail];
574 vnet_crypto_async_frame_t *ret_frame = 0;
577 while (cet->inflight > 0 && dequeue_more)
579 dequeue_more = cryptodev_frame_dequeue_internal (vm, enqueue_thread_idx);
582 if (PREDICT_TRUE (ring->frames[ring->enq_head].f != 0))
583 cryptodev_enqueue_frame (vm, &ring->frames[ring->enq_head]);
585 if (PREDICT_TRUE (ring_elt->f != 0))
587 if (ring_elt->n_elts == ring_elt->deq_elts_tail)
589 *nb_elts_processed = ring_elt->n_elts;
590 vlib_node_set_interrupt_pending (
591 vlib_get_main_by_index (vm->thread_index), cm->crypto_node_index);
592 ret_frame = cryptodev_cache_ring_pop (ring);
599 static_always_inline int
600 cryptodev_enqueue_aead_aad_0_enc (vlib_main_t *vm,
601 vnet_crypto_async_frame_t *frame)
603 return cryptodev_frame_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_ENCRYPT,
606 static_always_inline int
607 cryptodev_enqueue_aead_aad_8_enc (vlib_main_t *vm,
608 vnet_crypto_async_frame_t *frame)
610 return cryptodev_frame_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_ENCRYPT,
613 static_always_inline int
614 cryptodev_enqueue_aead_aad_12_enc (vlib_main_t *vm,
615 vnet_crypto_async_frame_t *frame)
617 return cryptodev_frame_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_ENCRYPT,
621 static_always_inline int
622 cryptodev_enqueue_aead_aad_0_dec (vlib_main_t *vm,
623 vnet_crypto_async_frame_t *frame)
625 return cryptodev_frame_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_DECRYPT,
628 static_always_inline int
629 cryptodev_enqueue_aead_aad_8_dec (vlib_main_t *vm,
630 vnet_crypto_async_frame_t *frame)
632 return cryptodev_frame_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_DECRYPT,
635 static_always_inline int
636 cryptodev_enqueue_aead_aad_12_dec (vlib_main_t *vm,
637 vnet_crypto_async_frame_t *frame)
639 return cryptodev_frame_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_DECRYPT,
643 static_always_inline int
644 cryptodev_enqueue_linked_alg_enc (vlib_main_t *vm,
645 vnet_crypto_async_frame_t *frame)
647 return cryptodev_frame_linked_algs_enqueue (vm, frame,
648 CRYPTODEV_OP_TYPE_ENCRYPT);
651 static_always_inline int
652 cryptodev_enqueue_linked_alg_dec (vlib_main_t *vm,
653 vnet_crypto_async_frame_t *frame)
655 return cryptodev_frame_linked_algs_enqueue (vm, frame,
656 CRYPTODEV_OP_TYPE_DECRYPT);
660 cryptodev_register_cop_hdl (vlib_main_t *vm, u32 eidx)
662 cryptodev_main_t *cmt = &cryptodev_main;
663 cryptodev_engine_thread_t *cet;
664 struct rte_cryptodev_sym_capability_idx cap_auth_idx;
665 struct rte_cryptodev_sym_capability_idx cap_cipher_idx;
666 struct rte_cryptodev_sym_capability_idx cap_aead_idx;
668 clib_error_t *error = 0;
671 vec_foreach (cet, cmt->per_thread_data)
673 u32 thread_index = cet - cmt->per_thread_data;
674 u32 numa = vlib_get_main_by_index (thread_index)->numa_node;
675 name = format (0, "vpp_cop_pool_%u_%u", numa, thread_index);
676 cet->cop_pool = rte_mempool_create (
677 (char *) name, CRYPTODEV_NB_CRYPTO_OPS, sizeof (cryptodev_op_t), 0,
678 sizeof (struct rte_crypto_op_pool_private), NULL, NULL, crypto_op_init,
679 NULL, vm->numa_node, 0);
683 error = clib_error_return (
684 0, "Failed to create cryptodev op pool %s", name);
690 #define _(a, b, c, d, e, f, g) \
691 cap_aead_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; \
692 cap_aead_idx.algo.aead = RTE_CRYPTO_##b##_##c; \
693 if (cryptodev_check_cap_support (&cap_aead_idx, g, e, f)) \
695 vnet_crypto_register_enqueue_handler ( \
696 vm, eidx, VNET_CRYPTO_OP_##a##_TAG##e##_AAD##f##_ENC, \
697 cryptodev_enqueue_aead_aad_##f##_enc); \
698 vnet_crypto_register_enqueue_handler ( \
699 vm, eidx, VNET_CRYPTO_OP_##a##_TAG##e##_AAD##f##_DEC, \
700 cryptodev_enqueue_aead_aad_##f##_dec); \
703 foreach_vnet_aead_crypto_conversion
706 #define _(a, b, c, d, e) \
707 cap_auth_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; \
708 cap_auth_idx.algo.auth = RTE_CRYPTO_AUTH_##d##_HMAC; \
709 cap_cipher_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; \
710 cap_cipher_idx.algo.cipher = RTE_CRYPTO_CIPHER_##b; \
711 if (cryptodev_check_cap_support (&cap_cipher_idx, c, -1, -1) && \
712 cryptodev_check_cap_support (&cap_auth_idx, -1, e, -1)) \
714 vnet_crypto_register_enqueue_handler ( \
715 vm, eidx, VNET_CRYPTO_OP_##a##_##d##_TAG##e##_ENC, \
716 cryptodev_enqueue_linked_alg_enc); \
717 vnet_crypto_register_enqueue_handler ( \
718 vm, eidx, VNET_CRYPTO_OP_##a##_##d##_TAG##e##_DEC, \
719 cryptodev_enqueue_linked_alg_dec); \
722 foreach_cryptodev_link_async_alg
726 vnet_crypto_register_dequeue_handler (vm, eidx, cryptodev_frame_dequeue);
731 vec_foreach (cet, cmt->per_thread_data)
734 rte_mempool_free (cet->cop_pool);