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/vnet.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_cryptodev_pmd.h>
33 #include <rte_config.h>
36 #define always_inline static inline
38 #define always_inline static inline __attribute__ ((__always_inline__))
41 #define CRYPTODEV_NB_CRYPTO_OPS 1024
42 #define CRYPTODEV_MAX_INFLIGHT (CRYPTODEV_NB_CRYPTO_OPS - 1)
43 #define CRYPTODEV_AAD_MASK (CRYPTODEV_NB_CRYPTO_OPS - 1)
44 #define CRYPTODEV_DEQ_CACHE_SZ 32
45 #define CRYPTODEV_NB_SESSION 10240
46 #define CRYPTODEV_MAX_AAD_SIZE 16
47 #define CRYPTODEV_MAX_N_SGL 8 /**< maximum number of segments */
49 /* VNET_CRYPTO_ALGO, TYPE, DPDK_CRYPTO_ALGO, IV_LEN, TAG_LEN, AAD_LEN */
50 #define foreach_vnet_aead_crypto_conversion \
51 _(AES_128_GCM, AEAD, AES_GCM, 12, 16, 8) \
52 _(AES_128_GCM, AEAD, AES_GCM, 12, 16, 12) \
53 _(AES_192_GCM, AEAD, AES_GCM, 12, 16, 8) \
54 _(AES_192_GCM, AEAD, AES_GCM, 12, 16, 12) \
55 _(AES_256_GCM, AEAD, AES_GCM, 12, 16, 8) \
56 _(AES_256_GCM, AEAD, AES_GCM, 12, 16, 12)
59 * crypto (alg, cryptodev_alg), hash (alg, digest-size)
61 #define foreach_cryptodev_link_async_alg \
62 _ (AES_128_CBC, AES_CBC, SHA1, 12) \
63 _ (AES_192_CBC, AES_CBC, SHA1, 12) \
64 _ (AES_256_CBC, AES_CBC, SHA1, 12) \
65 _ (AES_128_CBC, AES_CBC, SHA224, 14) \
66 _ (AES_192_CBC, AES_CBC, SHA224, 14) \
67 _ (AES_256_CBC, AES_CBC, SHA224, 14) \
68 _ (AES_128_CBC, AES_CBC, SHA256, 16) \
69 _ (AES_192_CBC, AES_CBC, SHA256, 16) \
70 _ (AES_256_CBC, AES_CBC, SHA256, 16) \
71 _ (AES_128_CBC, AES_CBC, SHA384, 24) \
72 _ (AES_192_CBC, AES_CBC, SHA384, 24) \
73 _ (AES_256_CBC, AES_CBC, SHA384, 24) \
74 _ (AES_128_CBC, AES_CBC, SHA512, 32) \
75 _ (AES_192_CBC, AES_CBC, SHA512, 32) \
76 _ (AES_256_CBC, AES_CBC, SHA512, 32)
80 CRYPTODEV_OP_TYPE_ENCRYPT = 0,
81 CRYPTODEV_OP_TYPE_DECRYPT,
83 } cryptodev_op_type_t;
87 struct rte_cryptodev_sym_session *keys[CRYPTODEV_N_OP_TYPES];
94 u8 *dp_service_buffer;
100 struct rte_mempool *sess_pool;
101 struct rte_mempool *sess_priv_pool;
102 } cryptodev_numa_data_t;
106 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
107 vlib_buffer_t *b[VNET_CRYPTO_FRAME_SIZE];
108 struct rte_crypto_dp_service_ctx *dp_service;
109 struct rte_crypto_vec vec[CRYPTODEV_MAX_N_SGL];
110 struct rte_ring *cached_frame;
117 } cryptodev_engine_thread_t;
121 cryptodev_numa_data_t *per_numa_data;
122 cryptodev_key_t *keys;
123 cryptodev_engine_thread_t *per_thread_data;
124 enum rte_iova_mode iova_mode;
125 cryptodev_inst_t *cryptodev_inst;
126 clib_bitmap_t *active_cdev_inst_mask;
127 clib_spinlock_t tlock;
130 cryptodev_main_t cryptodev_main;
133 prepare_aead_xform (struct rte_crypto_sym_xform *xform,
134 cryptodev_op_type_t op_type,
135 const vnet_crypto_key_t * key, u32 aad_len)
137 struct rte_crypto_aead_xform *aead_xform = &xform->aead;
138 memset (xform, 0, sizeof (*xform));
139 xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
142 if (key->alg != VNET_CRYPTO_ALG_AES_128_GCM &&
143 key->alg != VNET_CRYPTO_ALG_AES_192_GCM &&
144 key->alg != VNET_CRYPTO_ALG_AES_256_GCM)
147 aead_xform->algo = RTE_CRYPTO_AEAD_AES_GCM;
148 aead_xform->op = (op_type == CRYPTODEV_OP_TYPE_ENCRYPT) ?
149 RTE_CRYPTO_AEAD_OP_ENCRYPT : RTE_CRYPTO_AEAD_OP_DECRYPT;
150 aead_xform->aad_length = aad_len;
151 aead_xform->digest_length = 16;
152 aead_xform->iv.offset = 0;
153 aead_xform->iv.length = 12;
154 aead_xform->key.data = key->data;
155 aead_xform->key.length = vec_len (key->data);
161 prepare_linked_xform (struct rte_crypto_sym_xform *xforms,
162 cryptodev_op_type_t op_type,
163 const vnet_crypto_key_t * key)
165 struct rte_crypto_sym_xform *xform_cipher, *xform_auth;
166 vnet_crypto_key_t *key_cipher, *key_auth;
167 enum rte_crypto_cipher_algorithm cipher_algo = ~0;
168 enum rte_crypto_auth_algorithm auth_algo = ~0;
171 key_cipher = vnet_crypto_get_key (key->index_crypto);
172 key_auth = vnet_crypto_get_key (key->index_integ);
173 if (!key_cipher || !key_auth)
176 if (op_type == CRYPTODEV_OP_TYPE_ENCRYPT)
178 xform_cipher = xforms;
179 xform_auth = xforms + 1;
180 xform_cipher->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
181 xform_auth->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
185 xform_cipher = xforms + 1;
187 xform_cipher->cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
188 xform_auth->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
191 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
192 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
193 xforms->next = xforms + 1;
195 switch (key->async_alg)
197 #define _(a, b, c, d) \
198 case VNET_CRYPTO_ALG_##a##_##c##_TAG##d:\
199 cipher_algo = RTE_CRYPTO_CIPHER_##b; \
200 auth_algo = RTE_CRYPTO_AUTH_##c##_HMAC; \
204 foreach_cryptodev_link_async_alg
210 xform_cipher->cipher.algo = cipher_algo;
211 xform_cipher->cipher.key.data = key_cipher->data;
212 xform_cipher->cipher.key.length = vec_len (key_cipher->data);
213 xform_cipher->cipher.iv.length = 16;
214 xform_cipher->cipher.iv.offset = 0;
216 xform_auth->auth.algo = auth_algo;
217 xform_auth->auth.digest_length = digest_len;
218 xform_auth->auth.key.data = key_auth->data;
219 xform_auth->auth.key.length = vec_len (key_auth->data);
225 cryptodev_session_create (vnet_crypto_key_t * const key,
226 struct rte_mempool *sess_priv_pool,
227 cryptodev_key_t * session_pair, u32 aad_len)
229 struct rte_crypto_sym_xform xforms_enc[2] = { {0} };
230 struct rte_crypto_sym_xform xforms_dec[2] = { {0} };
231 cryptodev_main_t *cmt = &cryptodev_main;
232 cryptodev_inst_t *dev_inst;
233 struct rte_cryptodev *cdev;
237 if (key->type == VNET_CRYPTO_KEY_TYPE_LINK)
238 ret = prepare_linked_xform (xforms_enc, CRYPTODEV_OP_TYPE_ENCRYPT, key);
240 ret = prepare_aead_xform (xforms_enc, CRYPTODEV_OP_TYPE_ENCRYPT, key,
245 if (key->type == VNET_CRYPTO_KEY_TYPE_LINK)
246 prepare_linked_xform (xforms_dec, CRYPTODEV_OP_TYPE_DECRYPT, key);
248 prepare_aead_xform (xforms_dec, CRYPTODEV_OP_TYPE_DECRYPT, key, aad_len);
250 vec_foreach (dev_inst, cmt->cryptodev_inst)
252 dev_id = dev_inst->dev_id;
253 cdev = rte_cryptodev_pmd_get_dev (dev_id);
255 /* if the session is already configured for the driver type, avoid
256 configuring it again to increase the session data's refcnt */
257 if (session_pair->keys[0]->sess_data[cdev->driver_id].data &&
258 session_pair->keys[1]->sess_data[cdev->driver_id].data)
261 ret = rte_cryptodev_sym_session_init (dev_id, session_pair->keys[0],
262 xforms_enc, sess_priv_pool);
263 ret = rte_cryptodev_sym_session_init (dev_id, session_pair->keys[1],
264 xforms_dec, sess_priv_pool);
268 session_pair->keys[0]->opaque_data = aad_len;
269 session_pair->keys[1]->opaque_data = aad_len;
275 cryptodev_session_del (struct rte_cryptodev_sym_session *sess)
282 n_devs = rte_cryptodev_count ();
284 for (i = 0; i < n_devs; i++)
285 rte_cryptodev_sym_session_clear (i, sess);
287 rte_cryptodev_sym_session_free (sess);
291 cryptodev_check_supported_vnet_alg (vnet_crypto_key_t * key)
293 vnet_crypto_alg_t alg;
294 if (key->type == VNET_CRYPTO_KEY_TYPE_LINK)
299 #define _(a, b, c, d, e, f) \
300 if (alg == VNET_CRYPTO_ALG_##a) \
303 foreach_vnet_aead_crypto_conversion
308 static_always_inline void
309 cryptodev_sess_handler (vlib_main_t * vm, vnet_crypto_key_op_t kop,
310 vnet_crypto_key_index_t idx, u32 aad_len)
312 cryptodev_main_t *cmt = &cryptodev_main;
313 cryptodev_numa_data_t *numa_data;
314 vnet_crypto_key_t *key = vnet_crypto_get_key (idx);
315 struct rte_mempool *sess_pool, *sess_priv_pool;
316 cryptodev_key_t *ckey = 0;
319 if (kop == VNET_CRYPTO_KEY_OP_DEL)
321 if (idx >= vec_len (cmt->keys))
324 ckey = pool_elt_at_index (cmt->keys, idx);
325 cryptodev_session_del (ckey->keys[0]);
326 cryptodev_session_del (ckey->keys[1]);
329 pool_put (cmt->keys, ckey);
332 else if (kop == VNET_CRYPTO_KEY_OP_MODIFY)
334 if (idx >= vec_len (cmt->keys))
337 ckey = pool_elt_at_index (cmt->keys, idx);
339 cryptodev_session_del (ckey->keys[0]);
340 cryptodev_session_del (ckey->keys[1]);
344 else /* create key */
345 pool_get_zero (cmt->keys, ckey);
347 /* do not create session for unsupported alg */
348 if (cryptodev_check_supported_vnet_alg (key))
351 numa_data = vec_elt_at_index (cmt->per_numa_data, vm->numa_node);
352 sess_pool = numa_data->sess_pool;
353 sess_priv_pool = numa_data->sess_priv_pool;
355 ckey->keys[0] = rte_cryptodev_sym_session_create (sess_pool);
362 ckey->keys[1] = rte_cryptodev_sym_session_create (sess_pool);
369 ret = cryptodev_session_create (key, sess_priv_pool, ckey, aad_len);
374 cryptodev_session_del (ckey->keys[0]);
375 cryptodev_session_del (ckey->keys[1]);
376 memset (ckey, 0, sizeof (*ckey));
377 pool_put (cmt->keys, ckey);
382 cryptodev_key_handler (vlib_main_t * vm, vnet_crypto_key_op_t kop,
383 vnet_crypto_key_index_t idx)
385 cryptodev_sess_handler (vm, kop, idx, 8);
388 static_always_inline void
389 cryptodev_mark_frame_err_status (vnet_crypto_async_frame_t * f,
390 vnet_crypto_op_status_t s)
392 u32 n_elts = f->n_elts, i;
394 for (i = 0; i < n_elts; i++)
395 f->elts[i].status = s;
396 f->state = VNET_CRYPTO_FRAME_STATE_NOT_PROCESSED;
399 static_always_inline int
400 cryptodev_frame_build_sgl (vlib_main_t * vm, enum rte_iova_mode iova_mode,
401 struct rte_crypto_vec *data_vec,
402 u16 * n_seg, vlib_buffer_t * b, u32 size)
404 struct rte_crypto_vec *vec = data_vec + 1;
405 if (vlib_buffer_chain_linearize (vm, b) > CRYPTODEV_MAX_N_SGL)
408 while ((b->flags & VLIB_BUFFER_NEXT_PRESENT) && size)
411 b = vlib_get_buffer (vm, b->next_buffer);
412 len = clib_min (b->current_length, size);
413 vec->base = (void *) vlib_buffer_get_current (b);
414 if (iova_mode == RTE_IOVA_VA)
415 vec->iova = pointer_to_uword (vec->base);
417 vec->iova = vlib_buffer_get_current_pa (vm, b);
430 static_always_inline u64
431 compute_ofs_linked_alg (vnet_crypto_async_frame_elt_t * fe, i16 * min_ofs,
434 union rte_crypto_sym_ofs ofs;
435 u32 crypto_end = fe->crypto_start_offset + fe->crypto_total_length;
436 u32 integ_end = fe->integ_start_offset + fe->crypto_total_length +
437 fe->integ_length_adj;
439 *min_ofs = clib_min (fe->crypto_start_offset, fe->integ_start_offset);
440 *max_end = clib_max (crypto_end, integ_end);
442 ofs.ofs.cipher.head = fe->crypto_start_offset - *min_ofs;
443 ofs.ofs.cipher.tail = *max_end - crypto_end;
444 ofs.ofs.auth.head = fe->integ_start_offset - *min_ofs;
445 ofs.ofs.auth.tail = *max_end - integ_end;
450 static_always_inline int
451 cryptodev_frame_linked_algs_enqueue (vlib_main_t * vm,
452 vnet_crypto_async_frame_t * frame,
453 cryptodev_op_type_t op_type)
455 cryptodev_main_t *cmt = &cryptodev_main;
456 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
457 vnet_crypto_async_frame_elt_t *fe;
458 struct rte_crypto_vec *vec;
459 struct rte_crypto_data iv_vec, digest_vec;
462 cryptodev_key_t *key;
464 union rte_crypto_sym_ofs cofs;
468 n_elts = frame->n_elts;
470 if (PREDICT_FALSE (CRYPTODEV_MAX_INFLIGHT - cet->inflight < n_elts))
472 cryptodev_mark_frame_err_status (frame,
473 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
477 vlib_get_buffers (vm, frame->buffer_indices, cet->b, frame->n_elts);
484 key = pool_elt_at_index (cmt->keys, fe->key_index);
485 last_key_index = fe->key_index;
488 (rte_cryptodev_dp_configure_service
489 (cet->cryptodev_id, cet->cryptodev_q, RTE_CRYPTO_DP_SYM_CHAIN,
490 RTE_CRYPTO_OP_WITH_SESSION,
491 (union rte_cryptodev_session_ctx) key->keys[op_type], cet->dp_service,
494 cryptodev_mark_frame_err_status (frame,
495 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
499 cofs.raw = compute_ofs_linked_alg (fe, &min_ofs, &max_end);
508 CLIB_PREFETCH (&fe[1], CLIB_CACHE_LINE_BYTES, LOAD);
509 CLIB_PREFETCH (&fe[2], CLIB_CACHE_LINE_BYTES, LOAD);
510 vlib_prefetch_buffer_header (b[1], LOAD);
511 vlib_prefetch_buffer_header (b[2], LOAD);
514 if (PREDICT_FALSE (last_key_index != fe->key_index))
516 cofs.raw = compute_ofs_linked_alg (fe, &min_ofs, &max_end);
518 key = pool_elt_at_index (cmt->keys, fe->key_index);
519 last_key_index = fe->key_index;
522 (rte_cryptodev_dp_configure_service
523 (cet->cryptodev_id, cet->cryptodev_q, RTE_CRYPTO_DP_SYM_CHAIN,
524 RTE_CRYPTO_OP_WITH_SESSION,
525 (union rte_cryptodev_session_ctx) key->keys[op_type],
526 cet->dp_service, 1) < 0))
528 cryptodev_mark_frame_err_status (frame,
529 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
534 vec->len = max_end - min_ofs;
535 if (cmt->iova_mode == RTE_IOVA_VA)
537 vec->base = (void *) (b[0]->data + min_ofs);
538 vec->iova = pointer_to_uword (b[0]->data) + min_ofs;
539 iv_vec.base = (void *) fe->iv;
540 iv_vec.iova = pointer_to_uword (fe->iv);
541 digest_vec.base = (void *) fe->tag;
542 digest_vec.iova = pointer_to_uword (fe->tag);
546 vec->base = (void *) (b[0]->data + min_ofs);
547 vec->iova = vlib_buffer_get_pa (vm, b[0]) + min_ofs;
548 iv_vec.base = (void *) fe->iv;
549 iv_vec.iova = vlib_physmem_get_pa (vm, fe->iv);
550 digest_vec.base = (void *) fe->tag;
551 digest_vec.iova = vlib_physmem_get_pa (vm, fe->digest);
554 if (PREDICT_FALSE (fe->flags & VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS))
556 vec->len = b[0]->current_data + b[0]->current_length - min_ofs;
557 if (cryptodev_frame_build_sgl
558 (vm, cmt->iova_mode, vec, &n_seg, b[0],
559 max_end - min_ofs - vec->len) < 0)
561 cryptodev_mark_frame_err_status (frame,
562 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
567 status = rte_cryptodev_dp_submit_single_job (cet->dp_service,
568 vec, n_seg, cofs, &iv_vec,
573 cryptodev_mark_frame_err_status (frame,
574 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
583 rte_cryptodev_dp_submit_done (cet->dp_service, frame->n_elts);
584 cet->inflight += frame->n_elts;
589 static_always_inline int
590 cryptodev_frame_gcm_enqueue (vlib_main_t * vm,
591 vnet_crypto_async_frame_t * frame,
592 cryptodev_op_type_t op_type, u8 aad_len)
594 cryptodev_main_t *cmt = &cryptodev_main;
595 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
596 vnet_crypto_async_frame_elt_t *fe;
599 cryptodev_key_t *key;
601 union rte_crypto_sym_ofs cofs;
602 struct rte_crypto_vec *vec;
603 struct rte_crypto_data iv_vec, digest_vec, aad_vec;
606 n_elts = frame->n_elts;
608 if (PREDICT_FALSE (CRYPTODEV_MAX_INFLIGHT - cet->inflight < n_elts))
610 cryptodev_mark_frame_err_status (frame,
611 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
615 vlib_get_buffers (vm, frame->buffer_indices, cet->b, frame->n_elts);
623 key = pool_elt_at_index (cmt->keys, fe->key_index);
624 last_key_index = fe->key_index;
625 sess_aad_len = (u8) key->keys[op_type]->opaque_data;
626 if (PREDICT_FALSE (sess_aad_len != aad_len))
627 cryptodev_sess_handler (vm, VNET_CRYPTO_KEY_OP_MODIFY,
628 fe->key_index, aad_len);
631 (rte_cryptodev_dp_configure_service
632 (cet->cryptodev_id, cet->cryptodev_q, RTE_CRYPTO_DP_SYM_AEAD,
633 RTE_CRYPTO_OP_WITH_SESSION,
634 (union rte_cryptodev_session_ctx) key->keys[op_type], cet->dp_service,
637 cryptodev_mark_frame_err_status (frame,
638 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
644 u32 aad_offset = ((cet->aad_index++) & CRYPTODEV_AAD_MASK) << 4;
650 CLIB_PREFETCH (&fe[1], CLIB_CACHE_LINE_BYTES, LOAD);
651 vlib_prefetch_buffer_header (b[1], LOAD);
654 if (last_key_index != fe->key_index)
656 key = pool_elt_at_index (cmt->keys, fe->key_index);
657 sess_aad_len = (u8) key->keys[op_type]->opaque_data;
658 if (PREDICT_FALSE (sess_aad_len != aad_len))
660 cryptodev_sess_handler (vm, VNET_CRYPTO_KEY_OP_MODIFY,
661 fe->key_index, aad_len);
663 last_key_index = fe->key_index;
666 (rte_cryptodev_dp_configure_service
667 (cet->cryptodev_id, cet->cryptodev_q, RTE_CRYPTO_DP_SYM_AEAD,
668 RTE_CRYPTO_OP_WITH_SESSION,
669 (union rte_cryptodev_session_ctx) key->keys[op_type],
670 cet->dp_service, 1) < 0))
672 cryptodev_mark_frame_err_status (frame,
673 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
678 if (cmt->iova_mode == RTE_IOVA_VA)
680 vec[0].base = (void *) (b[0]->data + fe->crypto_start_offset);
681 vec[0].iova = pointer_to_uword (vec[0].base);
682 vec[0].len = fe->crypto_total_length;
683 iv_vec.base = (void *) fe->iv;
684 iv_vec.iova = pointer_to_uword (fe->iv);
685 digest_vec.base = (void *) fe->tag;
686 digest_vec.iova = pointer_to_uword (fe->tag);
687 aad_vec.base = (void *) (cet->aad_buf + aad_offset);
688 aad_vec.iova = cet->aad_phy_addr + aad_offset;
692 vec[0].base = (void *) (b[0]->data + fe->crypto_start_offset);
694 vlib_buffer_get_pa (vm, b[0]) + fe->crypto_start_offset;
695 vec[0].len = fe->crypto_total_length;
696 iv_vec.base = (void *) fe->iv;
697 iv_vec.iova = vlib_physmem_get_pa (vm, fe->iv);
698 aad_vec.base = (void *) (cet->aad_buf + aad_offset);
699 aad_vec.iova = cet->aad_phy_addr + aad_offset;
700 digest_vec.base = (void *) fe->tag;
701 digest_vec.iova = vlib_physmem_get_pa (vm, fe->tag);
705 *(u64 *) (cet->aad_buf + aad_offset) = *(u64 *) fe->aad;
709 *(u64 *) (cet->aad_buf + aad_offset) = *(u64 *) fe->aad;
710 *(u32 *) (cet->aad_buf + aad_offset + 8) = *(u32 *) (fe->aad + 8);
713 if (PREDICT_FALSE (fe->flags & VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS))
715 vec[0].len = b[0]->current_data +
716 b[0]->current_length - fe->crypto_start_offset;
717 if (cryptodev_frame_build_sgl
718 (vm, cmt->iova_mode, vec, &n_seg, b[0],
719 fe->crypto_total_length - vec[0].len) < 0)
721 cryptodev_mark_frame_err_status (frame,
722 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
728 rte_cryptodev_dp_submit_single_job (cet->dp_service, vec, n_seg, cofs,
729 &iv_vec, &digest_vec, &aad_vec,
731 if (PREDICT_FALSE (status < 0))
733 cryptodev_mark_frame_err_status (frame,
734 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
742 rte_cryptodev_dp_submit_done (cet->dp_service, frame->n_elts);
743 cet->inflight += frame->n_elts;
749 cryptodev_get_frame_n_elts (void *frame)
751 vnet_crypto_async_frame_t *f = (vnet_crypto_async_frame_t *) frame;
756 cryptodev_post_dequeue (void *frame, u32 index, u8 is_op_success)
758 vnet_crypto_async_frame_t *f = (vnet_crypto_async_frame_t *) frame;
760 f->elts[index].status = is_op_success ? VNET_CRYPTO_OP_STATUS_COMPLETED :
761 VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC;
764 #define GET_RING_OBJ(r, pos, f) do { \
765 vnet_crypto_async_frame_t **ring = (void *)&r[1]; \
766 f = ring[(r->cons.head + pos) & r->mask]; \
769 static_always_inline vnet_crypto_async_frame_t *
770 cryptodev_frame_dequeue (vlib_main_t * vm, u32 * nb_elts_processed,
771 u32 * enqueue_thread_idx)
773 cryptodev_main_t *cmt = &cryptodev_main;
774 cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
775 vnet_crypto_async_frame_t *frame, *frame_ret = 0;
776 u32 n_deq, n_success;
777 u32 n_cached_frame = rte_ring_count (cet->cached_frame), n_room_left;
778 u8 no_job_to_deq = 0;
779 u16 inflight = cet->inflight;
781 n_room_left = CRYPTODEV_DEQ_CACHE_SZ - n_cached_frame - 1;
786 for (i = 0; i < n_cached_frame; i++)
788 vnet_crypto_async_frame_t *f;
792 GET_RING_OBJ (cet->cached_frame, i, f);
794 if (i < n_cached_frame - 2)
796 vnet_crypto_async_frame_t *f1, *f2;
797 GET_RING_OBJ (cet->cached_frame, i + 1, f1);
798 GET_RING_OBJ (cet->cached_frame, i + 2, f2);
799 CLIB_PREFETCH (f1, CLIB_CACHE_LINE_BYTES, LOAD);
800 CLIB_PREFETCH (f2, CLIB_CACHE_LINE_BYTES, LOAD);
803 n_left = f->state & 0x7f;
804 err = f->state & 0x80;
806 for (j = f->n_elts - n_left; j < f->n_elts && inflight; j++)
809 rte_cryptodev_dp_sym_dequeue_single_job (cet->dp_service,
813 f->elts[j].status = ret == 1 ? VNET_CRYPTO_OP_STATUS_COMPLETED :
814 VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR;
824 f->state = err ? VNET_CRYPTO_FRAME_STATE_ELT_ERROR :
825 VNET_CRYPTO_FRAME_STATE_SUCCESS;
829 f->state = f->n_elts - j;
836 /* to here f is not completed dequeued and no more job can be
839 f->state = f->n_elts - j;
847 rte_ring_sc_dequeue (cet->cached_frame, (void **) &frame_ret);
852 /* no point to dequeue further */
853 if (!inflight || no_job_to_deq || !n_room_left)
856 n_deq = rte_cryptodev_dp_sym_dequeue (cet->dp_service,
857 cryptodev_get_frame_n_elts,
858 cryptodev_post_dequeue,
859 (void **) &frame, 0, &n_success);
864 no_job_to_deq = n_deq < frame->n_elts;
865 /* we have to cache the frame */
866 if (frame_ret || n_cached_frame || no_job_to_deq)
868 frame->state = frame->n_elts - n_deq;
869 frame->state |= ((n_success < n_deq) << 7);
870 rte_ring_sp_enqueue (cet->cached_frame, (void *) frame);
875 frame->state = n_success == frame->n_elts ?
876 VNET_CRYPTO_FRAME_STATE_SUCCESS : VNET_CRYPTO_FRAME_STATE_ELT_ERROR;
880 /* see if we can dequeue more */
881 while (inflight && n_room_left && !no_job_to_deq)
883 n_deq = rte_cryptodev_dp_sym_dequeue (cet->dp_service,
884 cryptodev_get_frame_n_elts,
885 cryptodev_post_dequeue,
886 (void **) &frame, 0, &n_success);
890 no_job_to_deq = n_deq < frame->n_elts;
891 frame->state = frame->n_elts - n_deq;
892 frame->state |= ((n_success < n_deq) << 7);
893 rte_ring_sp_enqueue (cet->cached_frame, (void *) frame);
898 if (inflight < cet->inflight)
900 rte_cryptodev_dp_dequeue_done (cet->dp_service,
901 cet->inflight - inflight);
902 cet->inflight = inflight;
907 *nb_elts_processed = frame_ret->n_elts;
908 *enqueue_thread_idx = frame_ret->enqueue_thread_index;
915 static_always_inline int
916 cryptodev_enqueue_gcm_aad_8_enc (vlib_main_t * vm,
917 vnet_crypto_async_frame_t * frame)
919 return cryptodev_frame_gcm_enqueue (vm, frame,
920 CRYPTODEV_OP_TYPE_ENCRYPT, 8);
922 static_always_inline int
923 cryptodev_enqueue_gcm_aad_12_enc (vlib_main_t * vm,
924 vnet_crypto_async_frame_t * frame)
926 return cryptodev_frame_gcm_enqueue (vm, frame,
927 CRYPTODEV_OP_TYPE_ENCRYPT, 12);
930 static_always_inline int
931 cryptodev_enqueue_gcm_aad_8_dec (vlib_main_t * vm,
932 vnet_crypto_async_frame_t * frame)
934 return cryptodev_frame_gcm_enqueue (vm, frame,
935 CRYPTODEV_OP_TYPE_DECRYPT, 8);
937 static_always_inline int
938 cryptodev_enqueue_gcm_aad_12_dec (vlib_main_t * vm,
939 vnet_crypto_async_frame_t * frame)
941 return cryptodev_frame_gcm_enqueue (vm, frame,
942 CRYPTODEV_OP_TYPE_DECRYPT, 12);
945 static_always_inline int
946 cryptodev_enqueue_linked_alg_enc (vlib_main_t * vm,
947 vnet_crypto_async_frame_t * frame)
949 return cryptodev_frame_linked_algs_enqueue (vm, frame,
950 CRYPTODEV_OP_TYPE_ENCRYPT);
953 static_always_inline int
954 cryptodev_enqueue_linked_alg_dec (vlib_main_t * vm,
955 vnet_crypto_async_frame_t * frame)
957 return cryptodev_frame_linked_algs_enqueue (vm, frame,
958 CRYPTODEV_OP_TYPE_DECRYPT);
963 CRYPTODEV_RESOURCE_ASSIGN_AUTO = 0,
964 CRYPTODEV_RESOURCE_ASSIGN_UPDATE,
965 } cryptodev_resource_assign_op_t;
968 * assign a cryptodev resource to a worker.
969 * @param cet: the worker thread data
970 * @param cryptodev_inst_index: if op is "ASSIGN_AUTO" this param is ignored.
971 * @param op: the assignment method.
972 * @return: 0 if successfully, negative number otherwise.
974 static_always_inline int
975 cryptodev_assign_resource (cryptodev_engine_thread_t * cet,
976 u32 cryptodev_inst_index,
977 cryptodev_resource_assign_op_t op)
979 cryptodev_main_t *cmt = &cryptodev_main;
980 cryptodev_inst_t *cinst = 0;
983 /* assign resource is only allowed when no inflight op is in the queue */
989 case CRYPTODEV_RESOURCE_ASSIGN_AUTO:
990 if (clib_bitmap_count_set_bits (cmt->active_cdev_inst_mask) >=
991 vec_len (cmt->cryptodev_inst))
994 clib_spinlock_lock (&cmt->tlock);
995 idx = clib_bitmap_first_clear (cmt->active_cdev_inst_mask);
996 clib_bitmap_set (cmt->active_cdev_inst_mask, idx, 1);
997 cinst = vec_elt_at_index (cmt->cryptodev_inst, idx);
998 cet->cryptodev_id = cinst->dev_id;
999 cet->cryptodev_q = cinst->q_id;
1000 cet->dp_service = (struct rte_crypto_dp_service_ctx *)
1001 cinst->dp_service_buffer;
1002 clib_spinlock_unlock (&cmt->tlock);
1004 case CRYPTODEV_RESOURCE_ASSIGN_UPDATE:
1005 /* assigning a used cryptodev resource is not allowed */
1006 if (clib_bitmap_get (cmt->active_cdev_inst_mask, cryptodev_inst_index)
1009 vec_foreach_index (idx, cmt->cryptodev_inst)
1011 cinst = cmt->cryptodev_inst + idx;
1012 if (cinst->dev_id == cet->cryptodev_id &&
1013 cinst->q_id == cet->cryptodev_q)
1016 /* invalid existing worker resource assignment */
1017 if (idx == vec_len (cmt->cryptodev_inst))
1019 clib_spinlock_lock (&cmt->tlock);
1020 clib_bitmap_set_no_check (cmt->active_cdev_inst_mask, idx, 0);
1021 clib_bitmap_set_no_check (cmt->active_cdev_inst_mask,
1022 cryptodev_inst_index, 1);
1023 cinst = cmt->cryptodev_inst + cryptodev_inst_index;
1024 cet->cryptodev_id = cinst->dev_id;
1025 cet->cryptodev_q = cinst->q_id;
1026 cet->dp_service = (struct rte_crypto_dp_service_ctx *)
1027 cinst->dp_service_buffer;
1028 clib_spinlock_unlock (&cmt->tlock);
1037 format_cryptodev_inst (u8 * s, va_list * args)
1039 cryptodev_main_t *cmt = &cryptodev_main;
1040 u32 inst = va_arg (*args, u32);
1041 cryptodev_inst_t *cit = cmt->cryptodev_inst + inst;
1042 u32 thread_index = 0;
1043 struct rte_cryptodev_info info;
1045 rte_cryptodev_info_get (cit->dev_id, &info);
1046 s = format (s, "%-25s%-10u", info.device->name, cit->q_id);
1048 vec_foreach_index (thread_index, cmt->per_thread_data)
1050 cryptodev_engine_thread_t *cet = cmt->per_thread_data + thread_index;
1051 if (vlib_num_workers () > 0 && thread_index == 0)
1054 if (cet->cryptodev_id == cit->dev_id && cet->cryptodev_q == cit->q_id)
1056 s = format (s, "%u (%v)\n", thread_index,
1057 vlib_worker_threads[thread_index].name);
1062 if (thread_index == vec_len (cmt->per_thread_data))
1063 s = format (s, "%s\n", "free");
1068 static clib_error_t *
1069 cryptodev_show_assignment_fn (vlib_main_t * vm, unformat_input_t * input,
1070 vlib_cli_command_t * cmd)
1072 cryptodev_main_t *cmt = &cryptodev_main;
1075 vlib_cli_output (vm, "%-5s%-25s%-10s%s\n", "No.", "Name", "Queue-id",
1077 if (vec_len (cmt->cryptodev_inst) == 0)
1079 vlib_cli_output (vm, "(nil)\n");
1083 vec_foreach_index (inst, cmt->cryptodev_inst)
1084 vlib_cli_output (vm, "%-5u%U", inst, format_cryptodev_inst, inst);
1089 VLIB_CLI_COMMAND (show_cryptodev_assignment, static) = {
1090 .path = "show cryptodev assignment",
1091 .short_help = "show cryptodev assignment",
1092 .function = cryptodev_show_assignment_fn,
1095 static clib_error_t *
1096 cryptodev_set_assignment_fn (vlib_main_t * vm, unformat_input_t * input,
1097 vlib_cli_command_t * cmd)
1099 cryptodev_main_t *cmt = &cryptodev_main;
1100 cryptodev_engine_thread_t *cet;
1101 unformat_input_t _line_input, *line_input = &_line_input;
1102 u32 thread_index, inst_index;
1103 u32 thread_present = 0, inst_present = 0;
1104 clib_error_t *error = 0;
1107 /* Get a line of input. */
1108 if (!unformat_user (input, unformat_line_input, line_input))
1111 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1113 if (unformat (line_input, "thread %u", &thread_index))
1115 else if (unformat (line_input, "resource %u", &inst_index))
1119 error = clib_error_return (0, "unknown input `%U'",
1120 format_unformat_error, line_input);
1125 if (!thread_present || !inst_present)
1127 error = clib_error_return (0, "mandatory argument(s) missing");
1131 if (thread_index == 0 && vlib_num_workers () > 0)
1134 clib_error_return (0, "assign crypto resource for master thread");
1138 if (thread_index > vec_len (cmt->per_thread_data) ||
1139 inst_index > vec_len (cmt->cryptodev_inst))
1141 error = clib_error_return (0, "wrong thread id or resource id");
1145 cet = cmt->per_thread_data + thread_index;
1146 ret = cryptodev_assign_resource (cet, inst_index,
1147 CRYPTODEV_RESOURCE_ASSIGN_UPDATE);
1150 error = clib_error_return (0, "cryptodev_assign_resource returned %i",
1158 VLIB_CLI_COMMAND (set_cryptodev_assignment, static) = {
1159 .path = "set cryptodev assignment",
1160 .short_help = "set cryptodev assignment thread <thread_index> "
1161 "resource <inst_index>",
1162 .function = cryptodev_set_assignment_fn,
1166 check_cryptodev_alg_support (u32 dev_id)
1168 const struct rte_cryptodev_symmetric_capability *cap;
1169 struct rte_cryptodev_sym_capability_idx cap_idx;
1171 #define _(a, b, c, d, e, f) \
1172 cap_idx.type = RTE_CRYPTO_SYM_XFORM_##b; \
1173 cap_idx.algo.aead = RTE_CRYPTO_##b##_##c; \
1174 cap = rte_cryptodev_sym_capability_get (dev_id, &cap_idx); \
1176 return -RTE_CRYPTO_##b##_##c; \
1179 if (cap->aead.digest_size.min > e || cap->aead.digest_size.max < e) \
1180 return -RTE_CRYPTO_##b##_##c; \
1181 if (cap->aead.aad_size.min > f || cap->aead.aad_size.max < f) \
1182 return -RTE_CRYPTO_##b##_##c; \
1183 if (cap->aead.iv_size.min > d || cap->aead.iv_size.max < d) \
1184 return -RTE_CRYPTO_##b##_##c; \
1187 foreach_vnet_aead_crypto_conversion
1190 #define _(a, b, c, d) \
1191 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; \
1192 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_##b; \
1193 cap = rte_cryptodev_sym_capability_get (dev_id, &cap_idx); \
1195 return -RTE_CRYPTO_CIPHER_##b; \
1196 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; \
1197 cap_idx.algo.auth = RTE_CRYPTO_AUTH_##c##_HMAC; \
1198 cap = rte_cryptodev_sym_capability_get (dev_id, &cap_idx); \
1200 return -RTE_CRYPTO_AUTH_##c;
1202 foreach_cryptodev_link_async_alg
1208 cryptodev_count_queue (u32 numa)
1210 struct rte_cryptodev_info info;
1211 u32 n_cryptodev = rte_cryptodev_count ();
1214 for (i = 0; i < n_cryptodev; i++)
1216 rte_cryptodev_info_get (i, &info);
1217 if (rte_cryptodev_socket_id (i) != numa)
1219 clib_warning ("DPDK crypto resource %s is in different numa node "
1220 "as %u, ignored", info.device->name, numa);
1223 q_count += info.max_nb_queue_pairs;
1230 cryptodev_configure (vlib_main_t *vm, u32 cryptodev_id)
1232 struct rte_cryptodev_info info;
1233 struct rte_cryptodev *cdev;
1234 cryptodev_main_t *cmt = &cryptodev_main;
1235 cryptodev_numa_data_t *numa_data = vec_elt_at_index (cmt->per_numa_data,
1241 cdev = rte_cryptodev_pmd_get_dev (cryptodev_id);
1242 rte_cryptodev_info_get (cryptodev_id, &info);
1244 if (!(info.feature_flags & RTE_CRYPTODEV_FF_DATA_PLANE_SERVICE))
1247 ret = check_cryptodev_alg_support (cryptodev_id);
1253 /** If the device is already started, we reuse it, otherwise configure
1254 * both the device and queue pair.
1256 if (!cdev->data->dev_started)
1258 struct rte_cryptodev_config cfg;
1260 cfg.socket_id = vm->numa_node;
1261 cfg.nb_queue_pairs = info.max_nb_queue_pairs;
1263 rte_cryptodev_configure (cryptodev_id, &cfg);
1265 for (i = 0; i < info.max_nb_queue_pairs; i++)
1267 struct rte_cryptodev_qp_conf qp_cfg;
1269 qp_cfg.mp_session = numa_data->sess_pool;
1270 qp_cfg.mp_session_private = numa_data->sess_priv_pool;
1271 qp_cfg.nb_descriptors = CRYPTODEV_NB_CRYPTO_OPS;
1273 ret = rte_cryptodev_queue_pair_setup (cryptodev_id, i, &qp_cfg,
1278 if (i != info.max_nb_queue_pairs)
1281 /* start the device */
1282 rte_cryptodev_start (i);
1285 ret = rte_cryptodev_get_dp_service_ctx_data_size (cryptodev_id);
1290 for (i = 0; i < info.max_nb_queue_pairs; i++)
1292 cryptodev_inst_t *cdev_inst;
1293 vec_add2(cmt->cryptodev_inst, cdev_inst, 1);
1294 cdev_inst->desc = vec_new (char, strlen (info.device->name) + 10);
1295 cdev_inst->dev_id = cryptodev_id;
1296 cdev_inst->q_id = i;
1297 vec_validate_aligned(cdev_inst->dp_service_buffer, dp_size, 8);
1298 snprintf (cdev_inst->desc, strlen (info.device->name) + 9,
1299 "%s_q%u", info.device->name, i);
1306 cryptodev_cmp (void *v1, void *v2)
1308 cryptodev_inst_t *a1 = v1;
1309 cryptodev_inst_t *a2 = v2;
1311 if (a1->q_id > a2->q_id)
1313 if (a1->q_id < a2->q_id)
1319 cryptodev_probe (vlib_main_t *vm, u32 n_workers)
1321 cryptodev_main_t *cmt = &cryptodev_main;
1322 u32 n_queues = cryptodev_count_queue (vm->numa_node);
1326 if (n_queues < n_workers)
1329 for (i = 0; i < rte_cryptodev_count (); i++)
1331 ret = cryptodev_configure (vm, i);
1336 vec_sort_with_function(cmt->cryptodev_inst, cryptodev_cmp);
1338 /* if there is not enough device stop cryptodev */
1339 if (vec_len (cmt->cryptodev_inst) < n_workers)
1346 cryptodev_get_session_sz (vlib_main_t *vm, u32 n_workers)
1348 u32 sess_data_sz = 0, i;
1350 if (rte_cryptodev_count () == 0)
1353 for (i = 0; i < rte_cryptodev_count (); i++)
1355 u32 dev_sess_sz = rte_cryptodev_sym_get_private_session_size (i);
1357 sess_data_sz = dev_sess_sz > sess_data_sz ? dev_sess_sz : sess_data_sz;
1360 return sess_data_sz;
1364 dpdk_disable_cryptodev_engine (vlib_main_t * vm)
1366 cryptodev_main_t *cmt = &cryptodev_main;
1367 cryptodev_numa_data_t *numa_data;
1368 cryptodev_engine_thread_t *ptd;
1370 vec_validate (cmt->per_numa_data, vm->numa_node);
1371 numa_data = vec_elt_at_index (cmt->per_numa_data, vm->numa_node);
1373 if (numa_data->sess_pool)
1374 rte_mempool_free (numa_data->sess_pool);
1375 if (numa_data->sess_priv_pool)
1376 rte_mempool_free (numa_data->sess_priv_pool);
1378 vec_foreach (ptd, cmt->per_thread_data)
1381 rte_free (ptd->aad_buf);
1382 if (ptd->cached_frame)
1383 rte_ring_free (ptd->cached_frame);
1388 dpdk_cryptodev_init (vlib_main_t * vm)
1390 cryptodev_main_t *cmt = &cryptodev_main;
1391 vlib_thread_main_t *tm = vlib_get_thread_main ();
1392 cryptodev_engine_thread_t *ptd;
1393 cryptodev_numa_data_t *numa_data;
1394 struct rte_mempool *mp;
1395 u32 skip_master = vlib_num_workers () > 0;
1396 u32 n_workers = tm->n_vlib_mains - skip_master;
1397 u32 numa = vm->numa_node;
1402 clib_error_t *error;
1404 cmt->iova_mode = rte_eal_iova_mode ();
1406 sess_sz = cryptodev_get_session_sz(vm, n_workers);
1409 error = clib_error_return (0, "Not enough cryptodevs");
1413 vec_validate (cmt->per_numa_data, vm->numa_node);
1414 numa_data = vec_elt_at_index (cmt->per_numa_data, numa);
1416 /* create session pool for the numa node */
1417 name = format (0, "vcryptodev_sess_pool_%u%c", numa, 0);
1418 mp = rte_cryptodev_sym_session_pool_create ((char *) name,
1419 CRYPTODEV_NB_SESSION,
1423 error = clib_error_return (0, "Not enough memory for mp %s", name);
1428 numa_data->sess_pool = mp;
1430 /* create session private pool for the numa node */
1431 name = format (0, "cryptodev_sess_pool_%u%c", numa, 0);
1432 mp = rte_mempool_create ((char *) name, CRYPTODEV_NB_SESSION, sess_sz, 0,
1433 0, NULL, NULL, NULL, NULL, numa, 0);
1436 error = clib_error_return (0, "Not enough memory for mp %s", name);
1443 numa_data->sess_priv_pool = mp;
1445 /* probe all cryptodev devices and get queue info */
1446 if (cryptodev_probe (vm, n_workers) < 0)
1448 error = clib_error_return (0, "Failed to configure cryptodev");
1452 clib_bitmap_vec_validate (cmt->active_cdev_inst_mask, tm->n_vlib_mains);
1453 clib_spinlock_init (&cmt->tlock);
1455 vec_validate_aligned(cmt->per_thread_data, tm->n_vlib_mains - 1,
1456 CLIB_CACHE_LINE_BYTES);
1457 for (i = skip_master; i < tm->n_vlib_mains; i++)
1459 ptd = cmt->per_thread_data + i;
1460 cryptodev_assign_resource (ptd, 0, CRYPTODEV_RESOURCE_ASSIGN_AUTO);
1461 ptd->aad_buf = rte_zmalloc_socket (0, CRYPTODEV_NB_CRYPTO_OPS *
1462 CRYPTODEV_MAX_AAD_SIZE,
1463 CLIB_CACHE_LINE_BYTES,
1465 if (ptd->aad_buf == 0)
1467 error = clib_error_return (0, "Failed to alloc aad buf");
1471 ptd->aad_phy_addr = rte_malloc_virt2iova (ptd->aad_buf);
1473 name = format (0, "cache_frame_ring_%u%u", numa, i);
1474 ptd->cached_frame = rte_ring_create ((char *)name,
1475 CRYPTODEV_DEQ_CACHE_SZ, numa,
1476 RING_F_SC_DEQ | RING_F_SP_ENQ);
1478 if (ptd->cached_frame == 0)
1480 error = clib_error_return (0, "Failed to frame ring");
1486 /* register handler */
1487 eidx = vnet_crypto_register_engine (vm, "dpdk_cryptodev", 79,
1488 "DPDK Cryptodev Engine");
1490 #define _(a, b, c, d, e, f) \
1491 vnet_crypto_register_async_handler \
1492 (vm, eidx, VNET_CRYPTO_OP_##a##_TAG##e##_AAD##f##_ENC, \
1493 cryptodev_enqueue_gcm_aad_##f##_enc,\
1494 cryptodev_frame_dequeue); \
1495 vnet_crypto_register_async_handler \
1496 (vm, eidx, VNET_CRYPTO_OP_##a##_TAG##e##_AAD##f##_DEC, \
1497 cryptodev_enqueue_gcm_aad_##f##_dec, \
1498 cryptodev_frame_dequeue);
1500 foreach_vnet_aead_crypto_conversion
1503 #define _(a, b, c, d) \
1504 vnet_crypto_register_async_handler \
1505 (vm, eidx, VNET_CRYPTO_OP_##a##_##c##_TAG##d##_ENC, \
1506 cryptodev_enqueue_linked_alg_enc, \
1507 cryptodev_frame_dequeue); \
1508 vnet_crypto_register_async_handler \
1509 (vm, eidx, VNET_CRYPTO_OP_##a##_##c##_TAG##d##_DEC, \
1510 cryptodev_enqueue_linked_alg_dec, \
1511 cryptodev_frame_dequeue);
1513 foreach_cryptodev_link_async_alg
1516 vnet_crypto_register_key_handler (vm, eidx, cryptodev_key_handler);
1521 dpdk_disable_cryptodev_engine (vm);
1528 * fd.io coding-style-patch-verification: ON
1531 * eval: (c-set-style "gnu")