2 *------------------------------------------------------------------
3 * Copyright (c) 2020 Intel and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
18 #include <vlib/vlib.h>
19 #include <vnet/plugin/plugin.h>
20 #include <vnet/crypto/crypto.h>
21 #include <vnet/ipsec/ipsec.h>
22 #include <vpp/app/version.h>
24 #include <dpdk/buffer.h>
25 #include <dpdk/device/dpdk.h>
26 #include <dpdk/device/dpdk_priv.h>
28 #include <rte_bus_vdev.h>
29 #include <rte_cryptodev.h>
30 #include <rte_crypto_sym.h>
31 #include <rte_crypto.h>
32 #include <rte_malloc.h>
33 #include <rte_config.h>
35 #include "cryptodev.h"
38 #define always_inline static inline
40 #define always_inline static inline __attribute__ ((__always_inline__))
43 static_always_inline u64
44 compute_ofs_linked_alg (vnet_crypto_async_frame_elt_t *fe, i16 *min_ofs,
47 union rte_crypto_sym_ofs ofs;
48 u32 crypto_end = fe->crypto_start_offset + fe->crypto_total_length;
50 fe->integ_start_offset + fe->crypto_total_length + fe->integ_length_adj;
52 *min_ofs = clib_min (fe->crypto_start_offset, fe->integ_start_offset);
53 *max_end = clib_max (crypto_end, integ_end);
55 ofs.ofs.cipher.head = fe->crypto_start_offset - *min_ofs;
56 ofs.ofs.cipher.tail = *max_end - crypto_end;
57 ofs.ofs.auth.head = fe->integ_start_offset - *min_ofs;
58 ofs.ofs.auth.tail = *max_end - integ_end;
63 static_always_inline int
64 cryptodev_frame_build_sgl (vlib_main_t *vm, enum rte_iova_mode iova_mode,
65 struct rte_crypto_vec *data_vec, u16 *n_seg,
66 vlib_buffer_t *b, u32 size)
68 struct rte_crypto_vec *vec = data_vec + 1;
69 if (vlib_buffer_chain_linearize (vm, b) > CRYPTODEV_MAX_N_SGL)
72 while ((b->flags & VLIB_BUFFER_NEXT_PRESENT) && size)
75 b = vlib_get_buffer (vm, b->next_buffer);
76 len = clib_min (b->current_length, size);
77 vec->base = (void *) vlib_buffer_get_current (b);
78 if (iova_mode == RTE_IOVA_VA)
79 vec->iova = pointer_to_uword (vec->base);
81 vec->iova = vlib_buffer_get_current_pa (vm, b);
94 static_always_inline void
95 cryptodev_reset_ctx (cryptodev_engine_thread_t *cet)
97 union rte_cryptodev_session_ctx sess_ctx;
99 ERROR_ASSERT (cet->reset_sess != 0);
101 sess_ctx.crypto_sess = cet->reset_sess;
103 rte_cryptodev_configure_raw_dp_ctx (cet->cryptodev_id, cet->cryptodev_q,
104 cet->ctx, RTE_CRYPTO_OP_WITH_SESSION,
108 static_always_inline int
109 cryptodev_frame_linked_algs_enqueue (vlib_main_t *vm,
110 vnet_crypto_async_frame_t *frame,
111 cryptodev_op_type_t op_type)
113 cryptodev_main_t *cmt = &cryptodev_main;
114 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
115 cryptodev_cache_ring_t *ring = &cet->cache_ring;
116 ERROR_ASSERT (frame != 0);
117 ERROR_ASSERT (frame->n_elts > 0);
118 cryptodev_cache_ring_elt_t *ring_elt =
119 cryptodev_cache_ring_push (ring, frame);
121 ring_elt->aad_len = 1;
122 ring_elt->op_type = (u8) op_type;
126 static_always_inline void
127 cryptodev_frame_linked_algs_enqueue_internal (vlib_main_t *vm,
128 vnet_crypto_async_frame_t *frame,
129 cryptodev_op_type_t op_type)
131 cryptodev_main_t *cmt = &cryptodev_main;
132 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
133 vnet_crypto_async_frame_elt_t *fe;
135 struct rte_crypto_vec vec[CRYPTODEV_MAX_N_SGL];
136 struct rte_crypto_va_iova_ptr iv_vec, digest_vec;
137 cryptodev_cache_ring_t *ring = &cet->cache_ring;
138 u16 *const enq = &ring->enq_head;
140 u32 last_key_index = ~0;
143 u32 max_to_enq = clib_min (CRYPTODE_ENQ_MAX,
144 frame->n_elts - ring->frames[*enq].enq_elts_head);
148 if (cet->inflight + max_to_enq > CRYPTODEV_MAX_INFLIGHT)
153 vlib_get_buffers (vm, frame->buffer_indices, cet->b, frame->n_elts);
155 b = cet->b + ring->frames[*enq].enq_elts_head;
156 fe = frame->elts + ring->frames[*enq].enq_elts_head;
160 union rte_crypto_sym_ofs cofs;
165 clib_prefetch_load (&fe[1]);
166 clib_prefetch_load (&fe[2]);
167 vlib_prefetch_buffer_header (b[1], LOAD);
168 vlib_prefetch_buffer_header (b[2], LOAD);
171 if (PREDICT_FALSE (last_key_index != fe->key_index))
173 cryptodev_key_t *key = vec_elt_at_index (cmt->keys, fe->key_index);
174 union rte_cryptodev_session_ctx sess_ctx;
176 if (PREDICT_FALSE (key->keys[vm->numa_node][op_type] == 0))
178 status = cryptodev_session_create (vm, fe->key_index, 0);
179 if (PREDICT_FALSE (status < 0))
183 /* Borrow a created session to reset session ctx, based on a valid
184 * assumption that the session reset won't happen until first valid
185 * packet is processed */
186 if (PREDICT_FALSE (cet->reset_sess == 0))
187 cet->reset_sess = key->keys[vm->numa_node][op_type];
189 sess_ctx.crypto_sess = key->keys[vm->numa_node][op_type];
191 status = rte_cryptodev_configure_raw_dp_ctx (
192 cet->cryptodev_id, cet->cryptodev_q, cet->ctx,
193 RTE_CRYPTO_OP_WITH_SESSION, sess_ctx, is_update);
194 if (PREDICT_FALSE (status < 0))
197 last_key_index = fe->key_index;
201 cofs.raw = compute_ofs_linked_alg (fe, &min_ofs, &max_end);
203 vec->len = max_end - min_ofs;
204 if (cmt->iova_mode == RTE_IOVA_VA)
206 vec[0].base = (void *) (b[0]->data + min_ofs);
207 vec[0].iova = pointer_to_uword (b[0]->data) + min_ofs;
208 iv_vec.va = (void *) fe->iv;
209 iv_vec.iova = pointer_to_uword (fe->iv);
210 digest_vec.va = (void *) fe->tag;
211 digest_vec.iova = pointer_to_uword (fe->tag);
215 vec[0].base = (void *) (b[0]->data + min_ofs);
216 vec[0].iova = vlib_buffer_get_pa (vm, b[0]) + min_ofs;
217 iv_vec.va = (void *) fe->iv;
218 iv_vec.iova = vlib_physmem_get_pa (vm, fe->iv);
219 digest_vec.va = (void *) fe->tag;
220 digest_vec.iova = vlib_physmem_get_pa (vm, fe->digest);
223 if (PREDICT_FALSE (fe->flags & VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS))
225 vec[0].len = b[0]->current_data + b[0]->current_length - min_ofs;
226 if (cryptodev_frame_build_sgl (vm, cmt->iova_mode, vec, &n_seg, b[0],
227 max_end - min_ofs - vec->len) < 0)
231 status = rte_cryptodev_raw_enqueue (cet->ctx, vec, n_seg, cofs, &iv_vec,
232 &digest_vec, 0, (void *) frame);
233 if (PREDICT_FALSE (status < 0))
236 ring->frames[*enq].enq_elts_head += 1;
242 status = rte_cryptodev_raw_enqueue_done (cet->ctx, max_to_enq);
243 if (PREDICT_FALSE (status < 0))
246 cet->inflight += max_to_enq;
247 cryptodev_cache_ring_update_enq_head (ring, frame);
251 cryptodev_mark_frame_fill_err (frame,
252 ring->frames[*enq].frame_elts_errs_mask,
253 ring->frames[*enq].enq_elts_head, max_to_enq,
254 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
255 ring->frames[*enq].enq_elts_head += max_to_enq;
256 ring->frames[*enq].deq_elts_tail += max_to_enq;
257 cryptodev_cache_ring_update_enq_head (ring, frame);
258 cryptodev_reset_ctx (cet);
263 static_always_inline int
264 cryptodev_raw_aead_enqueue (vlib_main_t *vm, vnet_crypto_async_frame_t *frame,
265 cryptodev_op_type_t op_type, u8 aad_len)
267 cryptodev_main_t *cmt = &cryptodev_main;
268 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
269 cryptodev_cache_ring_t *ring = &cet->cache_ring;
270 ERROR_ASSERT (frame != 0);
271 ERROR_ASSERT (frame->n_elts > 0);
272 cryptodev_cache_ring_elt_t *ring_elt =
273 cryptodev_cache_ring_push (ring, frame);
275 ring_elt->aad_len = aad_len;
276 ring_elt->op_type = (u8) op_type;
280 static_always_inline void
281 cryptodev_raw_aead_enqueue_internal (vlib_main_t *vm,
282 vnet_crypto_async_frame_t *frame,
283 cryptodev_op_type_t op_type, u8 aad_len)
285 cryptodev_main_t *cmt = &cryptodev_main;
286 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
287 cryptodev_cache_ring_t *ring = &cet->cache_ring;
288 vnet_crypto_async_frame_elt_t *fe;
291 union rte_crypto_sym_ofs cofs;
292 struct rte_crypto_vec vec[CRYPTODEV_MAX_N_SGL];
293 struct rte_crypto_va_iova_ptr iv_vec, digest_vec, aad_vec;
294 u32 last_key_index = ~0;
295 u16 *const enq = &ring->enq_head;
296 u16 left_to_enq = frame->n_elts - ring->frames[*enq].enq_elts_head;
297 u16 max_to_enq = clib_min (CRYPTODE_ENQ_MAX, left_to_enq);
301 if (cet->inflight + max_to_enq > CRYPTODEV_MAX_INFLIGHT)
308 vlib_get_buffers (vm, frame->buffer_indices, cet->b, frame->n_elts);
310 fe = frame->elts + ring->frames[*enq].enq_elts_head;
311 b = cet->b + ring->frames[*enq].enq_elts_head;
316 u32 aad_offset = ((cet->aad_index++) & CRYPTODEV_AAD_MASK) << 4;
321 clib_prefetch_load (&fe[1]);
322 vlib_prefetch_buffer_header (b[1], LOAD);
325 if (PREDICT_FALSE (last_key_index != fe->key_index))
327 cryptodev_key_t *key = vec_elt_at_index (cmt->keys, fe->key_index);
328 union rte_cryptodev_session_ctx sess_ctx;
330 if (PREDICT_FALSE (key->keys[vm->numa_node][op_type] == 0))
332 status = cryptodev_session_create (vm, fe->key_index, aad_len);
333 if (PREDICT_FALSE (status < 0))
338 #if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0)
339 rte_cryptodev_sym_session_opaque_data_get (
340 key->keys[vm->numa_node][op_type]) != (u64) aad_len
342 (u8) key->keys[vm->numa_node][op_type]->opaque_data != aad_len
346 cryptodev_sess_handler (vm, VNET_CRYPTO_KEY_OP_DEL,
347 fe->key_index, aad_len);
348 status = cryptodev_session_create (vm, fe->key_index, aad_len);
349 if (PREDICT_FALSE (status < 0))
353 /* Borrow a created session to reset session ctx, based on a valid
354 * assumption that the session reset won't happen until first valid
355 * packet is processed */
357 if (PREDICT_FALSE (cet->reset_sess == 0))
358 cet->reset_sess = key->keys[vm->numa_node][op_type];
360 sess_ctx.crypto_sess = key->keys[vm->numa_node][op_type];
362 status = rte_cryptodev_configure_raw_dp_ctx (
363 cet->cryptodev_id, cet->cryptodev_q, cet->ctx,
364 RTE_CRYPTO_OP_WITH_SESSION, sess_ctx, is_update);
365 if (PREDICT_FALSE (status < 0))
368 last_key_index = fe->key_index;
372 if (cmt->iova_mode == RTE_IOVA_VA)
374 vec[0].base = (void *) (b[0]->data + fe->crypto_start_offset);
375 vec[0].iova = pointer_to_uword (vec[0].base);
376 vec[0].len = fe->crypto_total_length;
377 iv_vec.va = (void *) fe->iv;
378 iv_vec.iova = pointer_to_uword (fe->iv);
379 digest_vec.va = (void *) fe->tag;
380 digest_vec.iova = pointer_to_uword (fe->tag);
381 aad_vec.va = (void *) (cet->aad_buf + aad_offset);
382 aad_vec.iova = cet->aad_phy_addr + aad_offset;
386 vec[0].base = (void *) (b[0]->data + fe->crypto_start_offset);
388 vlib_buffer_get_pa (vm, b[0]) + fe->crypto_start_offset;
389 vec[0].len = fe->crypto_total_length;
390 iv_vec.va = (void *) fe->iv;
391 iv_vec.iova = vlib_physmem_get_pa (vm, fe->iv);
392 aad_vec.va = (void *) (cet->aad_buf + aad_offset);
393 aad_vec.iova = cet->aad_phy_addr + aad_offset;
394 digest_vec.va = (void *) fe->tag;
395 digest_vec.iova = vlib_physmem_get_pa (vm, fe->tag);
399 *(u64 *) (cet->aad_buf + aad_offset) = *(u64 *) fe->aad;
400 else if (aad_len != 0)
403 *(u64 *) (cet->aad_buf + aad_offset) = *(u64 *) fe->aad;
404 *(u32 *) (cet->aad_buf + aad_offset + 8) = *(u32 *) (fe->aad + 8);
407 if (PREDICT_FALSE (fe->flags & VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS))
409 vec[0].len = b[0]->current_data + b[0]->current_length -
410 fe->crypto_start_offset;
412 cryptodev_frame_build_sgl (vm, cmt->iova_mode, vec, &n_seg, b[0],
413 fe->crypto_total_length - vec[0].len);
419 rte_cryptodev_raw_enqueue (cet->ctx, vec, n_seg, cofs, &iv_vec,
420 &digest_vec, &aad_vec, (void *) frame);
421 if (PREDICT_FALSE (status < 0))
424 ring->frames[*enq].enq_elts_head += 1;
430 status = rte_cryptodev_raw_enqueue_done (cet->ctx, max_to_enq);
431 if (PREDICT_FALSE (status < 0))
434 cet->inflight += max_to_enq;
435 cryptodev_cache_ring_update_enq_head (ring, frame);
439 cryptodev_mark_frame_fill_err (frame,
440 ring->frames[*enq].frame_elts_errs_mask,
441 ring->frames[*enq].enq_elts_head, max_to_enq,
442 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
443 ring->frames[*enq].enq_elts_head += max_to_enq;
444 ring->frames[*enq].deq_elts_tail += max_to_enq;
445 cryptodev_cache_ring_update_enq_head (ring, frame);
446 cryptodev_reset_ctx (cet);
450 static_always_inline void
451 cryptodev_post_dequeue (void *frame, u32 index, u8 is_op_success)
453 vnet_crypto_async_frame_t *f = (vnet_crypto_async_frame_t *) frame;
455 f->elts[index].status = is_op_success ? VNET_CRYPTO_OP_STATUS_COMPLETED :
456 VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC;
459 static_always_inline u8
460 cryptodev_raw_dequeue_internal (vlib_main_t *vm, u32 *nb_elts_processed,
461 u32 *enqueue_thread_idx)
463 cryptodev_main_t *cmt = &cryptodev_main;
464 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
465 vnet_crypto_async_frame_t *frame;
466 cryptodev_cache_ring_t *ring = &cet->cache_ring;
467 u16 *const deq = &ring->deq_tail;
469 u16 n_deq, indice, i, left_to_deq;
471 u16 inflight = cet->inflight;
477 for (i = 0; i < VNET_CRYPTO_FRAME_POOL_SIZE; i++)
480 CRYPTODEV_CACHE_RING_GET_FRAME_ELTS_INFLIGHT (ring, indice) > 0))
483 indice &= CRYPTODEV_CACHE_QUEUE_MASK;
486 ERROR_ASSERT (i != VNET_CRYPTO_FRAME_POOL_SIZE);
490 left_to_deq = ring->frames[*deq].n_elts - ring->frames[*deq].deq_elts_tail;
491 max_to_deq = clib_min (left_to_deq, CRYPTODE_DEQ_MAX);
493 /* you can use deq field to track frame that is currently dequeued */
494 /* based on that you can specify the amount of elements to deq for the frame
497 n_deq = rte_cryptodev_raw_dequeue_burst (
498 cet->ctx, NULL, max_to_deq, cryptodev_post_dequeue, (void **) &frame, 0,
499 &n_success, &dequeue_status);
505 if (PREDICT_FALSE (n_success < n_deq))
507 u16 idx = ring->frames[*deq].deq_elts_tail;
509 for (i = 0; i < n_deq; i++)
511 if (frame->elts[idx + i].status != VNET_CRYPTO_OP_STATUS_COMPLETED)
512 ring->frames[*deq].frame_elts_errs_mask |= 1 << (idx + i);
515 ring->frames[*deq].deq_elts_tail += n_deq;
517 if (cryptodev_cache_ring_update_deq_tail (ring, deq))
519 *nb_elts_processed = frame->n_elts;
520 *enqueue_thread_idx = frame->enqueue_thread_index;
521 dequeue_more = max_to_deq < CRYPTODE_DEQ_MAX;
525 rte_cryptodev_raw_dequeue_done (cet->ctx, cet->inflight - inflight);
526 ERROR_ASSERT (res == 0);
527 cet->inflight = inflight;
531 static_always_inline void
532 cryptodev_enqueue_frame_to_qat (vlib_main_t *vm,
533 cryptodev_cache_ring_elt_t *ring_elt)
535 cryptodev_op_type_t op_type = (cryptodev_op_type_t) ring_elt->op_type;
536 u8 linked_or_aad_len = ring_elt->aad_len;
538 if (linked_or_aad_len == 1)
539 cryptodev_frame_linked_algs_enqueue_internal (vm, ring_elt->f, op_type);
541 cryptodev_raw_aead_enqueue_internal (vm, ring_elt->f, op_type,
545 static_always_inline vnet_crypto_async_frame_t *
546 cryptodev_raw_dequeue (vlib_main_t *vm, u32 *nb_elts_processed,
547 u32 *enqueue_thread_idx)
549 cryptodev_main_t *cmt = &cryptodev_main;
550 vnet_crypto_main_t *cm = &crypto_main;
551 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
552 cryptodev_cache_ring_t *ring = &cet->cache_ring;
553 cryptodev_cache_ring_elt_t *ring_elt = &ring->frames[ring->tail];
554 vnet_crypto_async_frame_t *ret_frame = 0;
557 while (cet->inflight > 0 && dequeue_more)
559 dequeue_more = cryptodev_raw_dequeue_internal (vm, nb_elts_processed,
563 if (PREDICT_TRUE (ring->frames[ring->enq_head].f != 0))
564 cryptodev_enqueue_frame_to_qat (vm, &ring->frames[ring->enq_head]);
566 if (PREDICT_TRUE (ring_elt->f != 0))
568 if (ring_elt->enq_elts_head == ring_elt->deq_elts_tail)
570 vlib_node_set_interrupt_pending (
571 vlib_get_main_by_index (vm->thread_index), cm->crypto_node_index);
572 ret_frame = cryptodev_cache_ring_pop (ring);
581 static_always_inline int
582 cryptodev_raw_enq_aead_aad_0_enc (vlib_main_t *vm,
583 vnet_crypto_async_frame_t *frame)
585 return cryptodev_raw_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_ENCRYPT, 0);
588 static_always_inline int
589 cryptodev_raw_enq_aead_aad_8_enc (vlib_main_t *vm,
590 vnet_crypto_async_frame_t *frame)
592 return cryptodev_raw_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_ENCRYPT, 8);
594 static_always_inline int
595 cryptodev_raw_enq_aead_aad_12_enc (vlib_main_t *vm,
596 vnet_crypto_async_frame_t *frame)
598 return cryptodev_raw_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_ENCRYPT, 12);
601 static_always_inline int
602 cryptodev_raw_enq_aead_aad_0_dec (vlib_main_t *vm,
603 vnet_crypto_async_frame_t *frame)
605 return cryptodev_raw_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_DECRYPT, 0);
608 static_always_inline int
609 cryptodev_raw_enq_aead_aad_8_dec (vlib_main_t *vm,
610 vnet_crypto_async_frame_t *frame)
612 return cryptodev_raw_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_DECRYPT, 8);
614 static_always_inline int
615 cryptodev_raw_enq_aead_aad_12_dec (vlib_main_t *vm,
616 vnet_crypto_async_frame_t *frame)
618 return cryptodev_raw_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_DECRYPT, 12);
621 static_always_inline int
622 cryptodev_raw_enq_linked_alg_enc (vlib_main_t *vm,
623 vnet_crypto_async_frame_t *frame)
625 return cryptodev_frame_linked_algs_enqueue (vm, frame,
626 CRYPTODEV_OP_TYPE_ENCRYPT);
629 static_always_inline int
630 cryptodev_raw_enq_linked_alg_dec (vlib_main_t *vm,
631 vnet_crypto_async_frame_t *frame)
633 return cryptodev_frame_linked_algs_enqueue (vm, frame,
634 CRYPTODEV_OP_TYPE_DECRYPT);
638 cryptodev_register_raw_hdl (vlib_main_t *vm, u32 eidx)
640 cryptodev_main_t *cmt = &cryptodev_main;
641 cryptodev_engine_thread_t *cet;
642 cryptodev_inst_t *cinst;
643 struct rte_cryptodev_info info;
644 struct rte_cryptodev_sym_capability_idx cap_auth_idx;
645 struct rte_cryptodev_sym_capability_idx cap_cipher_idx;
646 struct rte_cryptodev_sym_capability_idx cap_aead_idx;
647 u32 support_raw_api = 1, max_ctx_size = 0;
648 clib_error_t *error = 0;
651 vec_foreach (cinst, cmt->cryptodev_inst)
654 rte_cryptodev_info_get (cinst->dev_id, &info);
655 if (!(info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))
661 ctx_size = rte_cryptodev_get_raw_dp_ctx_size (cinst->dev_id);
662 max_ctx_size = clib_max (ctx_size, max_ctx_size);
665 if (!support_raw_api)
666 return cryptodev_register_cop_hdl (vm, eidx);
668 vec_foreach (cet, cmt->per_thread_data)
670 u32 thread_id = cet - cmt->per_thread_data;
671 u32 numa = vlib_get_main_by_index (thread_id)->numa_node;
672 u8 *name = format (0, "cache_cache_ring_%u_%u", numa, thread_id);
674 cet->aad_buf = rte_zmalloc_socket (
675 0, CRYPTODEV_NB_CRYPTO_OPS * CRYPTODEV_MAX_AAD_SIZE,
676 CLIB_CACHE_LINE_BYTES, numa);
677 if (cet->aad_buf == 0)
679 error = clib_error_return (0, "Failed to alloc aad buf");
682 cet->aad_phy_addr = rte_malloc_virt2iova (cet->aad_buf);
685 rte_zmalloc_socket (0, max_ctx_size, CLIB_CACHE_LINE_BYTES, numa);
688 error = clib_error_return (0, "Failed to alloc raw dp ctx");
694 #define _(a, b, c, d, e, f, g) \
695 cap_aead_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; \
696 cap_aead_idx.algo.aead = RTE_CRYPTO_##b##_##c; \
697 if (cryptodev_check_cap_support (&cap_aead_idx, g, e, f)) \
699 vnet_crypto_register_enqueue_handler ( \
700 vm, eidx, VNET_CRYPTO_OP_##a##_TAG##e##_AAD##f##_ENC, \
701 cryptodev_raw_enq_aead_aad_##f##_enc); \
702 vnet_crypto_register_enqueue_handler ( \
703 vm, eidx, VNET_CRYPTO_OP_##a##_TAG##e##_AAD##f##_DEC, \
704 cryptodev_raw_enq_aead_aad_##f##_dec); \
707 foreach_vnet_aead_crypto_conversion
710 #define _(a, b, c, d, e) \
711 cap_auth_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; \
712 cap_auth_idx.algo.auth = RTE_CRYPTO_AUTH_##d##_HMAC; \
713 cap_cipher_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; \
714 cap_cipher_idx.algo.cipher = RTE_CRYPTO_CIPHER_##b; \
715 if (cryptodev_check_cap_support (&cap_cipher_idx, c, -1, -1) && \
716 cryptodev_check_cap_support (&cap_auth_idx, -1, e, -1)) \
718 vnet_crypto_register_enqueue_handler ( \
719 vm, eidx, VNET_CRYPTO_OP_##a##_##d##_TAG##e##_ENC, \
720 cryptodev_raw_enq_linked_alg_enc); \
721 vnet_crypto_register_enqueue_handler ( \
722 vm, eidx, VNET_CRYPTO_OP_##a##_##d##_TAG##e##_DEC, \
723 cryptodev_raw_enq_linked_alg_dec); \
726 foreach_cryptodev_link_async_alg
730 vnet_crypto_register_dequeue_handler (vm, eidx, cryptodev_raw_dequeue);