cryptodev: expose driver interface as internal
[dpdk.git] / drivers / crypto / cnxk / cnxk_cryptodev_ops.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #include <rte_cryptodev.h>
6 #include <cryptodev_pmd.h>
7 #include <rte_errno.h>
8
9 #include "roc_cpt.h"
10
11 #include "cnxk_ae.h"
12 #include "cnxk_cryptodev.h"
13 #include "cnxk_cryptodev_ops.h"
14 #include "cnxk_cryptodev_capabilities.h"
15 #include "cnxk_se.h"
16
17 #define CNXK_CPT_MAX_ASYM_OP_NUM_PARAMS 5
18 #define CNXK_CPT_MAX_ASYM_OP_MOD_LEN    1024
19
20 static int
21 cnxk_cpt_get_mlen(void)
22 {
23         uint32_t len;
24
25         /* For MAC */
26         len = 2 * sizeof(uint64_t);
27         len += ROC_SE_MAX_MAC_LEN * sizeof(uint8_t);
28
29         len += ROC_SE_OFF_CTRL_LEN + ROC_CPT_AES_CBC_IV_LEN;
30         len += RTE_ALIGN_CEIL((ROC_SE_SG_LIST_HDR_SIZE +
31                                (RTE_ALIGN_CEIL(ROC_SE_MAX_SG_IN_OUT_CNT, 4) >>
32                                 2) * ROC_SE_SG_ENTRY_SIZE),
33                               8);
34
35         return len;
36 }
37
38 static int
39 cnxk_cpt_asym_get_mlen(void)
40 {
41         uint32_t len;
42
43         /* To hold RPTR */
44         len = sizeof(uint64_t);
45
46         /* Get meta len for asymmetric operations */
47         len += CNXK_CPT_MAX_ASYM_OP_NUM_PARAMS * CNXK_CPT_MAX_ASYM_OP_MOD_LEN;
48
49         return len;
50 }
51
52 int
53 cnxk_cpt_dev_config(struct rte_cryptodev *dev,
54                     struct rte_cryptodev_config *conf)
55 {
56         struct cnxk_cpt_vf *vf = dev->data->dev_private;
57         struct roc_cpt *roc_cpt = &vf->cpt;
58         uint16_t nb_lf_avail, nb_lf;
59         int ret;
60
61         dev->feature_flags = cnxk_cpt_default_ff_get() & ~conf->ff_disable;
62
63         nb_lf_avail = roc_cpt->nb_lf_avail;
64         nb_lf = conf->nb_queue_pairs;
65
66         if (nb_lf > nb_lf_avail)
67                 return -ENOTSUP;
68
69         ret = roc_cpt_dev_configure(roc_cpt, nb_lf);
70         if (ret) {
71                 plt_err("Could not configure device");
72                 return ret;
73         }
74
75         if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
76                 /* Initialize shared FPM table */
77                 ret = roc_ae_fpm_get(vf->cnxk_fpm_iova);
78                 if (ret) {
79                         plt_err("Could not get FPM table");
80                         return ret;
81                 }
82
83                 /* Init EC grp table */
84                 ret = roc_ae_ec_grp_get(vf->ec_grp);
85                 if (ret) {
86                         plt_err("Could not get EC grp table");
87                         roc_ae_fpm_put();
88                         return ret;
89                 }
90         }
91
92         return 0;
93 }
94
95 int
96 cnxk_cpt_dev_start(struct rte_cryptodev *dev)
97 {
98         struct cnxk_cpt_vf *vf = dev->data->dev_private;
99         struct roc_cpt *roc_cpt = &vf->cpt;
100         uint16_t nb_lf = roc_cpt->nb_lf;
101         uint16_t qp_id;
102
103         for (qp_id = 0; qp_id < nb_lf; qp_id++)
104                 roc_cpt_iq_enable(roc_cpt->lf[qp_id]);
105
106         return 0;
107 }
108
109 void
110 cnxk_cpt_dev_stop(struct rte_cryptodev *dev)
111 {
112         struct cnxk_cpt_vf *vf = dev->data->dev_private;
113         struct roc_cpt *roc_cpt = &vf->cpt;
114         uint16_t nb_lf = roc_cpt->nb_lf;
115         uint16_t qp_id;
116
117         for (qp_id = 0; qp_id < nb_lf; qp_id++)
118                 roc_cpt_iq_disable(roc_cpt->lf[qp_id]);
119 }
120
121 int
122 cnxk_cpt_dev_close(struct rte_cryptodev *dev)
123 {
124         struct cnxk_cpt_vf *vf = dev->data->dev_private;
125         uint16_t i;
126         int ret;
127
128         for (i = 0; i < dev->data->nb_queue_pairs; i++) {
129                 ret = cnxk_cpt_queue_pair_release(dev, i);
130                 if (ret < 0) {
131                         plt_err("Could not release queue pair %u", i);
132                         return ret;
133                 }
134         }
135
136         if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
137                 roc_ae_fpm_put();
138                 roc_ae_ec_grp_put();
139         }
140
141         roc_cpt_dev_clear(&vf->cpt);
142
143         return 0;
144 }
145
146 void
147 cnxk_cpt_dev_info_get(struct rte_cryptodev *dev,
148                       struct rte_cryptodev_info *info)
149 {
150         struct cnxk_cpt_vf *vf = dev->data->dev_private;
151         struct roc_cpt *roc_cpt = &vf->cpt;
152
153         info->max_nb_queue_pairs = roc_cpt->nb_lf_avail;
154         info->feature_flags = cnxk_cpt_default_ff_get();
155         info->capabilities = cnxk_crypto_capabilities_get(vf);
156         info->sym.max_nb_sessions = 0;
157         info->min_mbuf_headroom_req = CNXK_CPT_MIN_HEADROOM_REQ;
158         info->min_mbuf_tailroom_req = CNXK_CPT_MIN_TAILROOM_REQ;
159 }
160
161 static void
162 qp_memzone_name_get(char *name, int size, int dev_id, int qp_id)
163 {
164         snprintf(name, size, "cnxk_cpt_pq_mem_%u:%u", dev_id, qp_id);
165 }
166
167 static int
168 cnxk_cpt_metabuf_mempool_create(const struct rte_cryptodev *dev,
169                                 struct cnxk_cpt_qp *qp, uint8_t qp_id,
170                                 uint32_t nb_elements)
171 {
172         char mempool_name[RTE_MEMPOOL_NAMESIZE];
173         struct cpt_qp_meta_info *meta_info;
174         struct rte_mempool *pool;
175         uint32_t cache_sz;
176         int mlen = 8;
177
178         if (dev->feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) {
179                 /* Get meta len */
180                 mlen = cnxk_cpt_get_mlen();
181         }
182
183         if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
184
185                 /* Get meta len required for asymmetric operations */
186                 mlen = RTE_MAX(mlen, cnxk_cpt_asym_get_mlen());
187         }
188
189         cache_sz = RTE_MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, nb_elements / 1.5);
190
191         /* Allocate mempool */
192
193         snprintf(mempool_name, RTE_MEMPOOL_NAMESIZE, "cnxk_cpt_mb_%u:%u",
194                  dev->data->dev_id, qp_id);
195
196         pool = rte_mempool_create(mempool_name, nb_elements, mlen, cache_sz, 0,
197                                   NULL, NULL, NULL, NULL, rte_socket_id(), 0);
198
199         if (pool == NULL) {
200                 plt_err("Could not create mempool for metabuf");
201                 return rte_errno;
202         }
203
204         meta_info = &qp->meta_info;
205
206         meta_info->pool = pool;
207         meta_info->mlen = mlen;
208
209         return 0;
210 }
211
212 static void
213 cnxk_cpt_metabuf_mempool_destroy(struct cnxk_cpt_qp *qp)
214 {
215         struct cpt_qp_meta_info *meta_info = &qp->meta_info;
216
217         rte_mempool_free(meta_info->pool);
218
219         meta_info->pool = NULL;
220         meta_info->mlen = 0;
221 }
222
223 static struct cnxk_cpt_qp *
224 cnxk_cpt_qp_create(const struct rte_cryptodev *dev, uint16_t qp_id,
225                    uint32_t iq_len)
226 {
227         const struct rte_memzone *pq_mem;
228         char name[RTE_MEMZONE_NAMESIZE];
229         struct cnxk_cpt_qp *qp;
230         uint32_t len;
231         uint8_t *va;
232         int ret;
233
234         /* Allocate queue pair */
235         qp = rte_zmalloc_socket("CNXK Crypto PMD Queue Pair", sizeof(*qp),
236                                 ROC_ALIGN, 0);
237         if (qp == NULL) {
238                 plt_err("Could not allocate queue pair");
239                 return NULL;
240         }
241
242         /* For pending queue */
243         len = iq_len * sizeof(struct cpt_inflight_req);
244
245         qp_memzone_name_get(name, RTE_MEMZONE_NAMESIZE, dev->data->dev_id,
246                             qp_id);
247
248         pq_mem = rte_memzone_reserve_aligned(name, len, rte_socket_id(),
249                                              RTE_MEMZONE_SIZE_HINT_ONLY |
250                                                      RTE_MEMZONE_256MB,
251                                              RTE_CACHE_LINE_SIZE);
252         if (pq_mem == NULL) {
253                 plt_err("Could not allocate reserved memzone");
254                 goto qp_free;
255         }
256
257         va = pq_mem->addr;
258
259         memset(va, 0, len);
260
261         ret = cnxk_cpt_metabuf_mempool_create(dev, qp, qp_id, iq_len);
262         if (ret) {
263                 plt_err("Could not create mempool for metabuf");
264                 goto pq_mem_free;
265         }
266
267         /* Initialize pending queue */
268         qp->pend_q.req_queue = pq_mem->addr;
269         qp->pend_q.enq_tail = 0;
270         qp->pend_q.deq_head = 0;
271         qp->pend_q.pending_count = 0;
272
273         return qp;
274
275 pq_mem_free:
276         rte_memzone_free(pq_mem);
277 qp_free:
278         rte_free(qp);
279         return NULL;
280 }
281
282 static int
283 cnxk_cpt_qp_destroy(const struct rte_cryptodev *dev, struct cnxk_cpt_qp *qp)
284 {
285         const struct rte_memzone *pq_mem;
286         char name[RTE_MEMZONE_NAMESIZE];
287         int ret;
288
289         cnxk_cpt_metabuf_mempool_destroy(qp);
290
291         qp_memzone_name_get(name, RTE_MEMZONE_NAMESIZE, dev->data->dev_id,
292                             qp->lf.lf_id);
293
294         pq_mem = rte_memzone_lookup(name);
295
296         ret = rte_memzone_free(pq_mem);
297         if (ret)
298                 return ret;
299
300         rte_free(qp);
301
302         return 0;
303 }
304
305 int
306 cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id)
307 {
308         struct cnxk_cpt_qp *qp = dev->data->queue_pairs[qp_id];
309         struct cnxk_cpt_vf *vf = dev->data->dev_private;
310         struct roc_cpt *roc_cpt = &vf->cpt;
311         struct roc_cpt_lf *lf;
312         int ret;
313
314         if (qp == NULL)
315                 return -EINVAL;
316
317         lf = roc_cpt->lf[qp_id];
318         if (lf == NULL)
319                 return -ENOTSUP;
320
321         roc_cpt_lf_fini(lf);
322
323         ret = cnxk_cpt_qp_destroy(dev, qp);
324         if (ret) {
325                 plt_err("Could not destroy queue pair %d", qp_id);
326                 return ret;
327         }
328
329         roc_cpt->lf[qp_id] = NULL;
330         dev->data->queue_pairs[qp_id] = NULL;
331
332         return 0;
333 }
334
335 int
336 cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
337                           const struct rte_cryptodev_qp_conf *conf,
338                           int socket_id __rte_unused)
339 {
340         struct cnxk_cpt_vf *vf = dev->data->dev_private;
341         struct roc_cpt *roc_cpt = &vf->cpt;
342         struct rte_pci_device *pci_dev;
343         struct cnxk_cpt_qp *qp;
344         int ret;
345
346         if (dev->data->queue_pairs[qp_id] != NULL)
347                 cnxk_cpt_queue_pair_release(dev, qp_id);
348
349         pci_dev = RTE_DEV_TO_PCI(dev->device);
350
351         if (pci_dev->mem_resource[2].addr == NULL) {
352                 plt_err("Invalid PCI mem address");
353                 return -EIO;
354         }
355
356         qp = cnxk_cpt_qp_create(dev, qp_id, conf->nb_descriptors);
357         if (qp == NULL) {
358                 plt_err("Could not create queue pair %d", qp_id);
359                 return -ENOMEM;
360         }
361
362         qp->lf.lf_id = qp_id;
363         qp->lf.nb_desc = conf->nb_descriptors;
364
365         ret = roc_cpt_lf_init(roc_cpt, &qp->lf);
366         if (ret < 0) {
367                 plt_err("Could not initialize queue pair %d", qp_id);
368                 ret = -EINVAL;
369                 goto exit;
370         }
371
372         roc_cpt->lf[qp_id] = &qp->lf;
373
374         ret = roc_cpt_lmtline_init(roc_cpt, &qp->lmtline, qp_id);
375         if (ret < 0) {
376                 roc_cpt->lf[qp_id] = NULL;
377                 plt_err("Could not init lmtline for queue pair %d", qp_id);
378                 goto exit;
379         }
380
381         qp->sess_mp = conf->mp_session;
382         qp->sess_mp_priv = conf->mp_session_private;
383         dev->data->queue_pairs[qp_id] = qp;
384
385         return 0;
386
387 exit:
388         cnxk_cpt_qp_destroy(dev, qp);
389         return ret;
390 }
391
392 unsigned int
393 cnxk_cpt_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
394 {
395         return sizeof(struct cnxk_se_sess);
396 }
397
398 static int
399 sym_xform_verify(struct rte_crypto_sym_xform *xform)
400 {
401         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
402             xform->auth.algo == RTE_CRYPTO_AUTH_NULL &&
403             xform->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY)
404                 return -ENOTSUP;
405
406         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL)
407                 return CNXK_CPT_CIPHER;
408
409         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH && xform->next == NULL)
410                 return CNXK_CPT_AUTH;
411
412         if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD && xform->next == NULL)
413                 return CNXK_CPT_AEAD;
414
415         if (xform->next == NULL)
416                 return -EIO;
417
418         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
419             xform->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC &&
420             xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
421             xform->next->auth.algo == RTE_CRYPTO_AUTH_SHA1)
422                 return -ENOTSUP;
423
424         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
425             xform->auth.algo == RTE_CRYPTO_AUTH_SHA1 &&
426             xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
427             xform->next->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC)
428                 return -ENOTSUP;
429
430         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
431             xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
432             xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
433             xform->next->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE)
434                 return CNXK_CPT_CIPHER_ENC_AUTH_GEN;
435
436         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
437             xform->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY &&
438             xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
439             xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT)
440                 return CNXK_CPT_AUTH_VRFY_CIPHER_DEC;
441
442         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
443             xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE &&
444             xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
445             xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
446                 switch (xform->auth.algo) {
447                 case RTE_CRYPTO_AUTH_SHA1_HMAC:
448                         switch (xform->next->cipher.algo) {
449                         case RTE_CRYPTO_CIPHER_AES_CBC:
450                                 return CNXK_CPT_AUTH_GEN_CIPHER_ENC;
451                         default:
452                                 return -ENOTSUP;
453                         }
454                 default:
455                         return -ENOTSUP;
456                 }
457         }
458
459         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
460             xform->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT &&
461             xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
462             xform->next->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
463                 switch (xform->cipher.algo) {
464                 case RTE_CRYPTO_CIPHER_AES_CBC:
465                         switch (xform->next->auth.algo) {
466                         case RTE_CRYPTO_AUTH_SHA1_HMAC:
467                                 return CNXK_CPT_CIPHER_DEC_AUTH_VRFY;
468                         default:
469                                 return -ENOTSUP;
470                         }
471                 default:
472                         return -ENOTSUP;
473                 }
474         }
475
476         return -ENOTSUP;
477 }
478
479 static uint64_t
480 cnxk_cpt_inst_w7_get(struct cnxk_se_sess *sess, struct roc_cpt *roc_cpt)
481 {
482         union cpt_inst_w7 inst_w7;
483
484         inst_w7.s.cptr = (uint64_t)&sess->roc_se_ctx.se_ctx;
485
486         /* Set the engine group */
487         if (sess->zsk_flag || sess->chacha_poly)
488                 inst_w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_SE];
489         else
490                 inst_w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_IE];
491
492         return inst_w7.u64;
493 }
494
495 int
496 sym_session_configure(struct roc_cpt *roc_cpt, int driver_id,
497                       struct rte_crypto_sym_xform *xform,
498                       struct rte_cryptodev_sym_session *sess,
499                       struct rte_mempool *pool)
500 {
501         struct cnxk_se_sess *sess_priv;
502         void *priv;
503         int ret;
504
505         ret = sym_xform_verify(xform);
506         if (unlikely(ret < 0))
507                 return ret;
508
509         if (unlikely(rte_mempool_get(pool, &priv))) {
510                 plt_dp_err("Could not allocate session private data");
511                 return -ENOMEM;
512         }
513
514         memset(priv, 0, sizeof(struct cnxk_se_sess));
515
516         sess_priv = priv;
517
518         switch (ret) {
519         case CNXK_CPT_CIPHER:
520                 ret = fill_sess_cipher(xform, sess_priv);
521                 break;
522         case CNXK_CPT_AUTH:
523                 if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC)
524                         ret = fill_sess_gmac(xform, sess_priv);
525                 else
526                         ret = fill_sess_auth(xform, sess_priv);
527                 break;
528         case CNXK_CPT_AEAD:
529                 ret = fill_sess_aead(xform, sess_priv);
530                 break;
531         case CNXK_CPT_CIPHER_ENC_AUTH_GEN:
532         case CNXK_CPT_CIPHER_DEC_AUTH_VRFY:
533                 ret = fill_sess_cipher(xform, sess_priv);
534                 if (ret < 0)
535                         break;
536                 ret = fill_sess_auth(xform->next, sess_priv);
537                 break;
538         case CNXK_CPT_AUTH_VRFY_CIPHER_DEC:
539         case CNXK_CPT_AUTH_GEN_CIPHER_ENC:
540                 ret = fill_sess_auth(xform, sess_priv);
541                 if (ret < 0)
542                         break;
543                 ret = fill_sess_cipher(xform->next, sess_priv);
544                 break;
545         default:
546                 ret = -1;
547         }
548
549         if (ret)
550                 goto priv_put;
551
552         if ((sess_priv->roc_se_ctx.fc_type == ROC_SE_HASH_HMAC) &&
553             cpt_mac_len_verify(&xform->auth)) {
554                 plt_dp_err("MAC length is not supported");
555                 if (sess_priv->roc_se_ctx.auth_key != NULL) {
556                         plt_free(sess_priv->roc_se_ctx.auth_key);
557                         sess_priv->roc_se_ctx.auth_key = NULL;
558                 }
559
560                 ret = -ENOTSUP;
561                 goto priv_put;
562         }
563
564         sess_priv->cpt_inst_w7 = cnxk_cpt_inst_w7_get(sess_priv, roc_cpt);
565
566         set_sym_session_private_data(sess, driver_id, sess_priv);
567
568         return 0;
569
570 priv_put:
571         rte_mempool_put(pool, priv);
572
573         return -ENOTSUP;
574 }
575
576 int
577 cnxk_cpt_sym_session_configure(struct rte_cryptodev *dev,
578                                struct rte_crypto_sym_xform *xform,
579                                struct rte_cryptodev_sym_session *sess,
580                                struct rte_mempool *pool)
581 {
582         struct cnxk_cpt_vf *vf = dev->data->dev_private;
583         struct roc_cpt *roc_cpt = &vf->cpt;
584         uint8_t driver_id;
585
586         driver_id = dev->driver_id;
587
588         return sym_session_configure(roc_cpt, driver_id, xform, sess, pool);
589 }
590
591 void
592 sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess)
593 {
594         void *priv = get_sym_session_private_data(sess, driver_id);
595         struct cnxk_se_sess *sess_priv;
596         struct rte_mempool *pool;
597
598         if (priv == NULL)
599                 return;
600
601         sess_priv = priv;
602
603         if (sess_priv->roc_se_ctx.auth_key != NULL)
604                 plt_free(sess_priv->roc_se_ctx.auth_key);
605
606         memset(priv, 0, cnxk_cpt_sym_session_get_size(NULL));
607
608         pool = rte_mempool_from_obj(priv);
609
610         set_sym_session_private_data(sess, driver_id, NULL);
611
612         rte_mempool_put(pool, priv);
613 }
614
615 void
616 cnxk_cpt_sym_session_clear(struct rte_cryptodev *dev,
617                            struct rte_cryptodev_sym_session *sess)
618 {
619         return sym_session_clear(dev->driver_id, sess);
620 }
621
622 unsigned int
623 cnxk_ae_session_size_get(struct rte_cryptodev *dev __rte_unused)
624 {
625         return sizeof(struct cnxk_ae_sess);
626 }
627
628 void
629 cnxk_ae_session_clear(struct rte_cryptodev *dev,
630                       struct rte_cryptodev_asym_session *sess)
631 {
632         struct rte_mempool *sess_mp;
633         struct cnxk_ae_sess *priv;
634
635         priv = get_asym_session_private_data(sess, dev->driver_id);
636         if (priv == NULL)
637                 return;
638
639         /* Free resources allocated in session_cfg */
640         cnxk_ae_free_session_parameters(priv);
641
642         /* Reset and free object back to pool */
643         memset(priv, 0, cnxk_ae_session_size_get(dev));
644         sess_mp = rte_mempool_from_obj(priv);
645         set_asym_session_private_data(sess, dev->driver_id, NULL);
646         rte_mempool_put(sess_mp, priv);
647 }
648
649 int
650 cnxk_ae_session_cfg(struct rte_cryptodev *dev,
651                     struct rte_crypto_asym_xform *xform,
652                     struct rte_cryptodev_asym_session *sess,
653                     struct rte_mempool *pool)
654 {
655         struct cnxk_cpt_vf *vf = dev->data->dev_private;
656         struct roc_cpt *roc_cpt = &vf->cpt;
657         struct cnxk_ae_sess *priv;
658         union cpt_inst_w7 w7;
659         int ret;
660
661         if (rte_mempool_get(pool, (void **)&priv))
662                 return -ENOMEM;
663
664         memset(priv, 0, sizeof(struct cnxk_ae_sess));
665
666         ret = cnxk_ae_fill_session_parameters(priv, xform);
667         if (ret) {
668                 rte_mempool_put(pool, priv);
669                 return ret;
670         }
671
672         w7.u64 = 0;
673         w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_AE];
674         priv->cpt_inst_w7 = w7.u64;
675         priv->cnxk_fpm_iova = vf->cnxk_fpm_iova;
676         priv->ec_grp = vf->ec_grp;
677         set_asym_session_private_data(sess, dev->driver_id, priv);
678
679         return 0;
680 }