47cc15aaaff9510ab60a1cbe67ba71c0737420a8
[vpp.git] / src / plugins / dpdk / cryptodev / cryptodev_op_data_path.c
1
2 /*
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:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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  *------------------------------------------------------------------
17  */
18
19 #include <vlib/vlib.h>
20 #include <vnet/crypto/crypto.h>
21
22 #include <dpdk/buffer.h>
23 #include <dpdk/device/dpdk.h>
24 #include <dpdk/device/dpdk_priv.h>
25 #undef always_inline
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>
32
33 #include "cryptodev.h"
34
35 #if CLIB_DEBUG > 0
36 #define always_inline static inline
37 #else
38 #define always_inline static inline __attribute__ ((__always_inline__))
39 #endif
40
41 #define CRYPTODEV_AAD_OFFSET (offsetof (cryptodev_op_t, aad))
42
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)
50
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
54 #undef _
55 };
56
57 static_always_inline rte_iova_t
58 cryptodev_get_iova (clib_pmalloc_main_t *pm, enum rte_iova_mode mode,
59                     void *data)
60 {
61   u64 index;
62   if (mode == RTE_IOVA_VA)
63     return (rte_iova_t) pointer_to_uword (data);
64
65   index = clib_pmalloc_get_page_index (pm, data);
66   return pointer_to_uword (data) - pm->lookup_table[index];
67 }
68
69 static_always_inline void
70 cryptodev_validate_mbuf_chain (vlib_main_t *vm, struct rte_mbuf *mb,
71                                vlib_buffer_t *b)
72 {
73   struct rte_mbuf *first_mb = mb, *last_mb = mb; /**< last mbuf */
74   /* when input node is not dpdk, mbuf data len is not initialized, for
75    * single buffer it is not a problem since the data length is written
76    * into cryptodev operation. For chained buffer a reference data length
77    * has to be computed through vlib_buffer.
78    *
79    * even when input node is dpdk, it is possible chained vlib_buffers
80    * are updated (either added or removed a buffer) but not not mbuf fields.
81    * we have to re-link every mbuf in the chain.
82    */
83   u16 data_len = b->current_length +
84                  (b->data + b->current_data - rte_pktmbuf_mtod (mb, u8 *));
85
86   first_mb->nb_segs = 1;
87   first_mb->pkt_len = first_mb->data_len = data_len;
88
89   while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
90     {
91       b = vlib_get_buffer (vm, b->next_buffer);
92       mb = rte_mbuf_from_vlib_buffer (b);
93       if (PREDICT_FALSE ((b->flags & VLIB_BUFFER_EXT_HDR_VALID) == 0))
94         rte_pktmbuf_reset (mb);
95       last_mb->next = mb;
96       last_mb = mb;
97       mb->data_len = b->current_length;
98       mb->pkt_len = b->current_length;
99       mb->data_off = VLIB_BUFFER_PRE_DATA_SIZE + b->current_data;
100       first_mb->nb_segs++;
101       if (PREDICT_FALSE (b->ref_count > 1))
102         mb->pool =
103           dpdk_no_cache_mempool_by_buffer_pool_index[b->buffer_pool_index];
104     }
105 }
106
107 static_always_inline void
108 crypto_op_init (struct rte_mempool *mempool,
109                 void *_arg __attribute__ ((unused)), void *_obj,
110                 unsigned i __attribute__ ((unused)))
111 {
112   struct rte_crypto_op *op = _obj;
113
114   op->sess_type = RTE_CRYPTO_OP_WITH_SESSION;
115   op->type = RTE_CRYPTO_OP_TYPE_SYMMETRIC;
116   op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
117   op->phys_addr = rte_mempool_virt2iova (_obj);
118   op->mempool = mempool;
119 }
120
121 static_always_inline int
122 cryptodev_frame_linked_algs_enqueue (vlib_main_t *vm,
123                                      vnet_crypto_async_frame_t *frame,
124                                      cryptodev_op_type_t op_type)
125 {
126   cryptodev_main_t *cmt = &cryptodev_main;
127   clib_pmalloc_main_t *pm = vm->physmem_main.pmalloc_main;
128   cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
129   vnet_crypto_async_frame_elt_t *fe;
130   struct rte_cryptodev_sym_session *sess = 0;
131   cryptodev_op_t **cop;
132   u32 *bi;
133   u32 n_enqueue, n_elts;
134   u32 last_key_index = ~0;
135
136   if (PREDICT_FALSE (frame == 0 || frame->n_elts == 0))
137     return -1;
138   n_elts = frame->n_elts;
139
140   if (PREDICT_FALSE (CRYPTODEV_NB_CRYPTO_OPS - cet->inflight < n_elts))
141     {
142       cryptodev_mark_frame_err_status (frame,
143                                        VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
144       return -1;
145     }
146
147   if (PREDICT_FALSE (
148         rte_mempool_get_bulk (cet->cop_pool, (void **) cet->cops, n_elts) < 0))
149     {
150       cryptodev_mark_frame_err_status (frame,
151                                        VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
152       return -1;
153     }
154
155   cop = cet->cops;
156   fe = frame->elts;
157   bi = frame->buffer_indices;
158   cop[0]->frame = frame;
159   cop[0]->n_elts = n_elts;
160
161   while (n_elts)
162     {
163       vlib_buffer_t *b = vlib_get_buffer (vm, bi[0]);
164       struct rte_crypto_sym_op *sop = &cop[0]->sop;
165       i16 crypto_offset = fe->crypto_start_offset;
166       i16 integ_offset = fe->integ_start_offset;
167       u32 offset_diff = crypto_offset - integ_offset;
168
169       if (n_elts > 2)
170         {
171           CLIB_PREFETCH (cop[1], sizeof (*cop[1]), STORE);
172           CLIB_PREFETCH (cop[2], sizeof (*cop[2]), STORE);
173           clib_prefetch_load (&fe[1]);
174           clib_prefetch_load (&fe[2]);
175         }
176       if (last_key_index != fe->key_index)
177         {
178           cryptodev_key_t *key = vec_elt_at_index (cmt->keys, fe->key_index);
179           last_key_index = fe->key_index;
180
181           if (key->keys[vm->numa_node][op_type] == 0)
182             {
183               if (PREDICT_FALSE (
184                     cryptodev_session_create (vm, last_key_index, 0) < 0))
185                 {
186                   cryptodev_mark_frame_err_status (
187                     frame, VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
188                   return -1;
189                 }
190             }
191           sess = key->keys[vm->numa_node][op_type];
192         }
193
194       sop->m_src = rte_mbuf_from_vlib_buffer (b);
195       sop->m_src->data_off = VLIB_BUFFER_PRE_DATA_SIZE;
196       sop->m_dst = 0;
197       /* mbuf prepend happens in the tx, but vlib_buffer happens in the nodes,
198        * so we have to manually adjust mbuf data_off here so cryptodev can
199        * correctly compute the data pointer. The prepend here will be later
200        * rewritten by tx. */
201       if (PREDICT_TRUE (fe->integ_start_offset < 0))
202         {
203           sop->m_src->data_off += fe->integ_start_offset;
204           integ_offset = 0;
205           crypto_offset = offset_diff;
206         }
207       sop->session = sess;
208       sop->cipher.data.offset = crypto_offset;
209       sop->cipher.data.length = fe->crypto_total_length;
210       sop->auth.data.offset = integ_offset;
211       sop->auth.data.length = fe->crypto_total_length + fe->integ_length_adj;
212       sop->auth.digest.data = fe->digest;
213       sop->auth.digest.phys_addr =
214         cryptodev_get_iova (pm, cmt->iova_mode, fe->digest);
215       if (PREDICT_FALSE (fe->flags & VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS))
216         cryptodev_validate_mbuf_chain (vm, sop->m_src, b);
217       else
218         /* for input nodes that are not dpdk-input, it is possible the mbuf
219          * was updated before as one of the chained mbufs. Setting nb_segs
220          * to 1 here to prevent the cryptodev PMD to access potentially
221          * invalid m_src->next pointers.
222          */
223         sop->m_src->nb_segs = 1;
224       clib_memcpy_fast (cop[0]->iv, fe->iv, 16);
225       cop++;
226       bi++;
227       fe++;
228       n_elts--;
229     }
230
231   n_enqueue = rte_cryptodev_enqueue_burst (cet->cryptodev_id, cet->cryptodev_q,
232                                            (struct rte_crypto_op **) cet->cops,
233                                            frame->n_elts);
234   ASSERT (n_enqueue == frame->n_elts);
235   cet->inflight += n_enqueue;
236
237   return 0;
238 }
239
240 static_always_inline int
241 cryptodev_frame_aead_enqueue (vlib_main_t *vm,
242                               vnet_crypto_async_frame_t *frame,
243                               cryptodev_op_type_t op_type, u8 aad_len)
244 {
245   cryptodev_main_t *cmt = &cryptodev_main;
246   clib_pmalloc_main_t *pm = vm->physmem_main.pmalloc_main;
247   cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
248   vnet_crypto_async_frame_elt_t *fe;
249   struct rte_cryptodev_sym_session *sess = 0;
250   cryptodev_op_t **cop;
251   u32 *bi;
252   u32 n_enqueue = 0, n_elts;
253   u32 last_key_index = ~0;
254
255   if (PREDICT_FALSE (frame == 0 || frame->n_elts == 0))
256     return -1;
257   n_elts = frame->n_elts;
258
259   if (PREDICT_FALSE (CRYPTODEV_MAX_INFLIGHT - cet->inflight < n_elts))
260     {
261       cryptodev_mark_frame_err_status (frame,
262                                        VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
263       return -1;
264     }
265
266   if (PREDICT_FALSE (
267         rte_mempool_get_bulk (cet->cop_pool, (void **) cet->cops, n_elts) < 0))
268     {
269       cryptodev_mark_frame_err_status (frame,
270                                        VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
271       return -1;
272     }
273
274   cop = cet->cops;
275   fe = frame->elts;
276   bi = frame->buffer_indices;
277   cop[0]->frame = frame;
278   cop[0]->n_elts = n_elts;
279
280   while (n_elts)
281     {
282       vlib_buffer_t *b = vlib_get_buffer (vm, bi[0]);
283       struct rte_crypto_sym_op *sop = &cop[0]->sop;
284       u16 crypto_offset = fe->crypto_start_offset;
285
286       if (n_elts > 2)
287         {
288           CLIB_PREFETCH (cop[1], sizeof (*cop[1]), STORE);
289           CLIB_PREFETCH (cop[2], sizeof (*cop[2]), STORE);
290           clib_prefetch_load (&fe[1]);
291           clib_prefetch_load (&fe[2]);
292         }
293       if (last_key_index != fe->key_index)
294         {
295           cryptodev_key_t *key = vec_elt_at_index (cmt->keys, fe->key_index);
296
297           last_key_index = fe->key_index;
298           if (key->keys[vm->numa_node][op_type] == 0)
299             {
300               if (PREDICT_FALSE (cryptodev_session_create (vm, last_key_index,
301                                                            aad_len) < 0))
302                 {
303                   cryptodev_mark_frame_err_status (
304                     frame, VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
305                   return -1;
306                 }
307             }
308           else if (PREDICT_FALSE (
309                      key->keys[vm->numa_node][op_type]->opaque_data !=
310                      aad_len))
311             {
312               cryptodev_sess_handler (vm, VNET_CRYPTO_KEY_OP_DEL,
313                                       fe->key_index, aad_len);
314               if (PREDICT_FALSE (cryptodev_session_create (vm, last_key_index,
315                                                            aad_len) < 0))
316                 {
317                   cryptodev_mark_frame_err_status (
318                     frame, VNET_CRYPTO_OP_STATUS_FAIL_ENGINE_ERR);
319                   return -1;
320                 }
321             }
322
323           sess = key->keys[vm->numa_node][op_type];
324         }
325
326       sop->m_src = rte_mbuf_from_vlib_buffer (b);
327       sop->m_src->data_off = VLIB_BUFFER_PRE_DATA_SIZE;
328       sop->m_dst = 0;
329       /* mbuf prepend happens in the tx, but vlib_buffer happens in the nodes,
330        * so we have to manually adjust mbuf data_off here so cryptodev can
331        * correctly compute the data pointer. The prepend here will be later
332        * rewritten by tx. */
333       if (PREDICT_FALSE (fe->crypto_start_offset < 0))
334         {
335           rte_pktmbuf_prepend (sop->m_src, -fe->crypto_start_offset);
336           crypto_offset = 0;
337         }
338
339       sop->session = sess;
340       sop->aead.aad.data = cop[0]->aad;
341       sop->aead.aad.phys_addr = cop[0]->op.phys_addr + CRYPTODEV_AAD_OFFSET;
342       sop->aead.data.length = fe->crypto_total_length;
343       sop->aead.data.offset = crypto_offset;
344       sop->aead.digest.data = fe->tag;
345       sop->aead.digest.phys_addr =
346         cryptodev_get_iova (pm, cmt->iova_mode, fe->tag);
347       if (PREDICT_FALSE (fe->flags & VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS))
348         cryptodev_validate_mbuf_chain (vm, sop->m_src, b);
349       else
350         /* for input nodes that are not dpdk-input, it is possible the mbuf
351          * was updated before as one of the chained mbufs. Setting nb_segs
352          * to 1 here to prevent the cryptodev PMD to access potentially
353          * invalid m_src->next pointers.
354          */
355         sop->m_src->nb_segs = 1;
356       clib_memcpy_fast (cop[0]->iv, fe->iv, 12);
357       clib_memcpy_fast (cop[0]->aad, fe->aad, aad_len);
358       cop++;
359       bi++;
360       fe++;
361       n_elts--;
362     }
363
364   n_enqueue = rte_cryptodev_enqueue_burst (cet->cryptodev_id, cet->cryptodev_q,
365                                            (struct rte_crypto_op **) cet->cops,
366                                            frame->n_elts);
367   ASSERT (n_enqueue == frame->n_elts);
368   cet->inflight += n_enqueue;
369
370   return 0;
371 }
372
373 static_always_inline u16
374 cryptodev_ring_deq (struct rte_ring *r, cryptodev_op_t **cops)
375 {
376   u16 n, n_elts = 0;
377
378   n = rte_ring_dequeue_bulk_start (r, (void **) cops, 1, 0);
379   rte_ring_dequeue_finish (r, 0);
380   if (!n)
381     return 0;
382
383   n = cops[0]->n_elts;
384   if (rte_ring_count (r) < n)
385     return 0;
386
387   n_elts = rte_ring_sc_dequeue_bulk (r, (void **) cops, n, 0);
388   ASSERT (n_elts == n);
389
390   return n_elts;
391 }
392
393 static_always_inline vnet_crypto_async_frame_t *
394 cryptodev_frame_dequeue (vlib_main_t *vm, u32 *nb_elts_processed,
395                          u32 *enqueue_thread_idx)
396 {
397   cryptodev_main_t *cmt = &cryptodev_main;
398   cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index;
399   cryptodev_op_t **cop = cet->cops;
400   vnet_crypto_async_frame_elt_t *fe;
401   vnet_crypto_async_frame_t *frame;
402   u32 n_elts, n_completed_ops = rte_ring_count (cet->ring);
403   u32 ss0 = 0, ss1 = 0, ss2 = 0, ss3 = 0; /* sum of status */
404
405   if (cet->inflight)
406     {
407       n_elts = rte_cryptodev_dequeue_burst (
408         cet->cryptodev_id, cet->cryptodev_q,
409         (struct rte_crypto_op **) cet->cops, VNET_CRYPTO_FRAME_SIZE);
410
411       if (n_elts)
412         {
413           cet->inflight -= n_elts;
414           n_completed_ops += n_elts;
415
416           rte_ring_sp_enqueue_burst (cet->ring, (void **) cet->cops, n_elts,
417                                      NULL);
418         }
419     }
420
421   if (PREDICT_FALSE (n_completed_ops == 0))
422     return 0;
423
424   n_elts = cryptodev_ring_deq (cet->ring, cop);
425   if (!n_elts)
426     return 0;
427
428   frame = cop[0]->frame;
429   fe = frame->elts;
430
431   while (n_elts > 4)
432     {
433       ss0 |= fe[0].status = cryptodev_status_conversion[cop[0]->op.status];
434       ss1 |= fe[1].status = cryptodev_status_conversion[cop[1]->op.status];
435       ss2 |= fe[2].status = cryptodev_status_conversion[cop[2]->op.status];
436       ss3 |= fe[3].status = cryptodev_status_conversion[cop[3]->op.status];
437
438       cop += 4;
439       fe += 4;
440       n_elts -= 4;
441     }
442
443   while (n_elts)
444     {
445       ss0 |= fe[0].status = cryptodev_status_conversion[cop[0]->op.status];
446       fe++;
447       cop++;
448       n_elts--;
449     }
450
451   frame->state = (ss0 | ss1 | ss2 | ss3) == VNET_CRYPTO_OP_STATUS_COMPLETED ?
452                    VNET_CRYPTO_FRAME_STATE_SUCCESS :
453                    VNET_CRYPTO_FRAME_STATE_ELT_ERROR;
454
455   rte_mempool_put_bulk (cet->cop_pool, (void **) cet->cops, frame->n_elts);
456   *nb_elts_processed = frame->n_elts;
457   *enqueue_thread_idx = frame->enqueue_thread_index;
458   return frame;
459 }
460
461 static_always_inline int
462 cryptodev_enqueue_aead_aad_8_enc (vlib_main_t *vm,
463                                   vnet_crypto_async_frame_t *frame)
464 {
465   return cryptodev_frame_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_ENCRYPT,
466                                        8);
467 }
468 static_always_inline int
469 cryptodev_enqueue_aead_aad_12_enc (vlib_main_t *vm,
470                                    vnet_crypto_async_frame_t *frame)
471 {
472   return cryptodev_frame_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_ENCRYPT,
473                                        12);
474 }
475
476 static_always_inline int
477 cryptodev_enqueue_aead_aad_8_dec (vlib_main_t *vm,
478                                   vnet_crypto_async_frame_t *frame)
479 {
480   return cryptodev_frame_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_DECRYPT,
481                                        8);
482 }
483 static_always_inline int
484 cryptodev_enqueue_aead_aad_12_dec (vlib_main_t *vm,
485                                    vnet_crypto_async_frame_t *frame)
486 {
487   return cryptodev_frame_aead_enqueue (vm, frame, CRYPTODEV_OP_TYPE_DECRYPT,
488                                        12);
489 }
490
491 static_always_inline int
492 cryptodev_enqueue_linked_alg_enc (vlib_main_t *vm,
493                                   vnet_crypto_async_frame_t *frame)
494 {
495   return cryptodev_frame_linked_algs_enqueue (vm, frame,
496                                               CRYPTODEV_OP_TYPE_ENCRYPT);
497 }
498
499 static_always_inline int
500 cryptodev_enqueue_linked_alg_dec (vlib_main_t *vm,
501                                   vnet_crypto_async_frame_t *frame)
502 {
503   return cryptodev_frame_linked_algs_enqueue (vm, frame,
504                                               CRYPTODEV_OP_TYPE_DECRYPT);
505 }
506
507 clib_error_t *
508 cryptodev_register_cop_hdl (vlib_main_t *vm, u32 eidx)
509 {
510   cryptodev_main_t *cmt = &cryptodev_main;
511   cryptodev_engine_thread_t *cet;
512   struct rte_cryptodev_sym_capability_idx cap_auth_idx;
513   struct rte_cryptodev_sym_capability_idx cap_cipher_idx;
514   struct rte_cryptodev_sym_capability_idx cap_aead_idx;
515   u8 *name;
516   clib_error_t *error = 0;
517   u32 ref_cnt = 0;
518
519   vec_foreach (cet, cmt->per_thread_data)
520     {
521       u32 thread_index = cet - cmt->per_thread_data;
522       u32 numa = vlib_get_main_by_index (thread_index)->numa_node;
523       name = format (0, "vpp_cop_pool_%u_%u", numa, thread_index);
524       cet->cop_pool = rte_mempool_create (
525         (char *) name, CRYPTODEV_NB_CRYPTO_OPS, sizeof (cryptodev_op_t), 0,
526         sizeof (struct rte_crypto_op_pool_private), NULL, NULL, crypto_op_init,
527         NULL, vm->numa_node, 0);
528       if (!cet->cop_pool)
529         {
530           error = clib_error_return (
531             0, "Failed to create cryptodev op pool %s", name);
532
533           goto error_exit;
534         }
535       vec_free (name);
536
537       name = format (0, "frames_ring_%u_%u", numa, thread_index);
538       cet->ring =
539         rte_ring_create ((char *) name, CRYPTODEV_NB_CRYPTO_OPS, vm->numa_node,
540                          RING_F_SP_ENQ | RING_F_SC_DEQ);
541       if (!cet->ring)
542         {
543           error = clib_error_return (
544             0, "Failed to create cryptodev op pool %s", name);
545
546           goto error_exit;
547         }
548       vec_free (name);
549
550       vec_validate (cet->cops, VNET_CRYPTO_FRAME_SIZE - 1);
551     }
552
553 #define _(a, b, c, d, e, f, g)                                                \
554   cap_aead_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;                              \
555   cap_aead_idx.algo.aead = RTE_CRYPTO_##b##_##c;                              \
556   if (cryptodev_check_cap_support (&cap_aead_idx, g, e, f))                   \
557     {                                                                         \
558       vnet_crypto_register_enqueue_handler (                                  \
559         vm, eidx, VNET_CRYPTO_OP_##a##_TAG##e##_AAD##f##_ENC,                 \
560         cryptodev_enqueue_aead_aad_##f##_enc);                                \
561       vnet_crypto_register_enqueue_handler (                                  \
562         vm, eidx, VNET_CRYPTO_OP_##a##_TAG##e##_AAD##f##_DEC,                 \
563         cryptodev_enqueue_aead_aad_##f##_dec);                                \
564       ref_cnt++;                                                              \
565     }
566   foreach_vnet_aead_crypto_conversion
567 #undef _
568
569 #define _(a, b, c, d, e)                                                      \
570   cap_auth_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;                              \
571   cap_auth_idx.algo.auth = RTE_CRYPTO_AUTH_##d##_HMAC;                        \
572   cap_cipher_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;                          \
573   cap_cipher_idx.algo.cipher = RTE_CRYPTO_CIPHER_##b;                         \
574   if (cryptodev_check_cap_support (&cap_cipher_idx, c, -1, -1) &&             \
575       cryptodev_check_cap_support (&cap_auth_idx, -1, e, -1))                 \
576     {                                                                         \
577       vnet_crypto_register_enqueue_handler (                                  \
578         vm, eidx, VNET_CRYPTO_OP_##a##_##d##_TAG##e##_ENC,                    \
579         cryptodev_enqueue_linked_alg_enc);                                    \
580       vnet_crypto_register_enqueue_handler (                                  \
581         vm, eidx, VNET_CRYPTO_OP_##a##_##d##_TAG##e##_DEC,                    \
582         cryptodev_enqueue_linked_alg_dec);                                    \
583       ref_cnt++;                                                              \
584     }
585     foreach_cryptodev_link_async_alg
586 #undef _
587
588     if (ref_cnt)
589       vnet_crypto_register_dequeue_handler (vm, eidx, cryptodev_frame_dequeue);
590
591     return 0;
592
593 error_exit:
594   vec_foreach (cet, cmt->per_thread_data)
595     {
596       if (cet->ring)
597         rte_ring_free (cet->ring);
598
599       if (cet->cop_pool)
600         rte_mempool_free (cet->cop_pool);
601     }
602
603   return error;
604 }