crypto/cnxk: add max queue pairs limit option
[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 =
154                 RTE_MIN(roc_cpt->nb_lf_avail, vf->max_qps_limit);
155         plt_cpt_dbg("max_nb_queue_pairs %u", info->max_nb_queue_pairs);
156
157         info->feature_flags = cnxk_cpt_default_ff_get();
158         info->capabilities = cnxk_crypto_capabilities_get(vf);
159         info->sym.max_nb_sessions = 0;
160         info->min_mbuf_headroom_req = CNXK_CPT_MIN_HEADROOM_REQ;
161         info->min_mbuf_tailroom_req = CNXK_CPT_MIN_TAILROOM_REQ;
162 }
163
164 static void
165 qp_memzone_name_get(char *name, int size, int dev_id, int qp_id)
166 {
167         snprintf(name, size, "cnxk_cpt_pq_mem_%u:%u", dev_id, qp_id);
168 }
169
170 static int
171 cnxk_cpt_metabuf_mempool_create(const struct rte_cryptodev *dev,
172                                 struct cnxk_cpt_qp *qp, uint8_t qp_id,
173                                 uint32_t nb_elements)
174 {
175         char mempool_name[RTE_MEMPOOL_NAMESIZE];
176         struct cpt_qp_meta_info *meta_info;
177         struct rte_mempool *pool;
178         uint32_t cache_sz;
179         int mlen = 8;
180
181         if (dev->feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) {
182                 /* Get meta len */
183                 mlen = cnxk_cpt_get_mlen();
184         }
185
186         if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
187
188                 /* Get meta len required for asymmetric operations */
189                 mlen = RTE_MAX(mlen, cnxk_cpt_asym_get_mlen());
190         }
191
192         cache_sz = RTE_MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, nb_elements / 1.5);
193
194         /* Allocate mempool */
195
196         snprintf(mempool_name, RTE_MEMPOOL_NAMESIZE, "cnxk_cpt_mb_%u:%u",
197                  dev->data->dev_id, qp_id);
198
199         pool = rte_mempool_create(mempool_name, nb_elements, mlen, cache_sz, 0,
200                                   NULL, NULL, NULL, NULL, rte_socket_id(), 0);
201
202         if (pool == NULL) {
203                 plt_err("Could not create mempool for metabuf");
204                 return rte_errno;
205         }
206
207         meta_info = &qp->meta_info;
208
209         meta_info->pool = pool;
210         meta_info->mlen = mlen;
211
212         return 0;
213 }
214
215 static void
216 cnxk_cpt_metabuf_mempool_destroy(struct cnxk_cpt_qp *qp)
217 {
218         struct cpt_qp_meta_info *meta_info = &qp->meta_info;
219
220         rte_mempool_free(meta_info->pool);
221
222         meta_info->pool = NULL;
223         meta_info->mlen = 0;
224 }
225
226 static struct cnxk_cpt_qp *
227 cnxk_cpt_qp_create(const struct rte_cryptodev *dev, uint16_t qp_id,
228                    uint32_t iq_len)
229 {
230         const struct rte_memzone *pq_mem;
231         char name[RTE_MEMZONE_NAMESIZE];
232         struct cnxk_cpt_qp *qp;
233         uint32_t len;
234         uint8_t *va;
235         int ret;
236
237         /* Allocate queue pair */
238         qp = rte_zmalloc_socket("CNXK Crypto PMD Queue Pair", sizeof(*qp),
239                                 ROC_ALIGN, 0);
240         if (qp == NULL) {
241                 plt_err("Could not allocate queue pair");
242                 return NULL;
243         }
244
245         /* For pending queue */
246         len = iq_len * sizeof(struct cpt_inflight_req);
247
248         qp_memzone_name_get(name, RTE_MEMZONE_NAMESIZE, dev->data->dev_id,
249                             qp_id);
250
251         pq_mem = rte_memzone_reserve_aligned(name, len, rte_socket_id(),
252                                              RTE_MEMZONE_SIZE_HINT_ONLY |
253                                                      RTE_MEMZONE_256MB,
254                                              RTE_CACHE_LINE_SIZE);
255         if (pq_mem == NULL) {
256                 plt_err("Could not allocate reserved memzone");
257                 goto qp_free;
258         }
259
260         va = pq_mem->addr;
261
262         memset(va, 0, len);
263
264         ret = cnxk_cpt_metabuf_mempool_create(dev, qp, qp_id, iq_len);
265         if (ret) {
266                 plt_err("Could not create mempool for metabuf");
267                 goto pq_mem_free;
268         }
269
270         /* Initialize pending queue */
271         qp->pend_q.req_queue = pq_mem->addr;
272         qp->pend_q.enq_tail = 0;
273         qp->pend_q.deq_head = 0;
274         qp->pend_q.pending_count = 0;
275
276         return qp;
277
278 pq_mem_free:
279         rte_memzone_free(pq_mem);
280 qp_free:
281         rte_free(qp);
282         return NULL;
283 }
284
285 static int
286 cnxk_cpt_qp_destroy(const struct rte_cryptodev *dev, struct cnxk_cpt_qp *qp)
287 {
288         const struct rte_memzone *pq_mem;
289         char name[RTE_MEMZONE_NAMESIZE];
290         int ret;
291
292         cnxk_cpt_metabuf_mempool_destroy(qp);
293
294         qp_memzone_name_get(name, RTE_MEMZONE_NAMESIZE, dev->data->dev_id,
295                             qp->lf.lf_id);
296
297         pq_mem = rte_memzone_lookup(name);
298
299         ret = rte_memzone_free(pq_mem);
300         if (ret)
301                 return ret;
302
303         rte_free(qp);
304
305         return 0;
306 }
307
308 int
309 cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id)
310 {
311         struct cnxk_cpt_qp *qp = dev->data->queue_pairs[qp_id];
312         struct cnxk_cpt_vf *vf = dev->data->dev_private;
313         struct roc_cpt *roc_cpt = &vf->cpt;
314         struct roc_cpt_lf *lf;
315         int ret;
316
317         if (qp == NULL)
318                 return -EINVAL;
319
320         lf = roc_cpt->lf[qp_id];
321         if (lf == NULL)
322                 return -ENOTSUP;
323
324         roc_cpt_lf_fini(lf);
325
326         ret = cnxk_cpt_qp_destroy(dev, qp);
327         if (ret) {
328                 plt_err("Could not destroy queue pair %d", qp_id);
329                 return ret;
330         }
331
332         roc_cpt->lf[qp_id] = NULL;
333         dev->data->queue_pairs[qp_id] = NULL;
334
335         return 0;
336 }
337
338 int
339 cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
340                           const struct rte_cryptodev_qp_conf *conf,
341                           int socket_id __rte_unused)
342 {
343         struct cnxk_cpt_vf *vf = dev->data->dev_private;
344         struct roc_cpt *roc_cpt = &vf->cpt;
345         struct rte_pci_device *pci_dev;
346         struct cnxk_cpt_qp *qp;
347         int ret;
348
349         if (dev->data->queue_pairs[qp_id] != NULL)
350                 cnxk_cpt_queue_pair_release(dev, qp_id);
351
352         pci_dev = RTE_DEV_TO_PCI(dev->device);
353
354         if (pci_dev->mem_resource[2].addr == NULL) {
355                 plt_err("Invalid PCI mem address");
356                 return -EIO;
357         }
358
359         qp = cnxk_cpt_qp_create(dev, qp_id, conf->nb_descriptors);
360         if (qp == NULL) {
361                 plt_err("Could not create queue pair %d", qp_id);
362                 return -ENOMEM;
363         }
364
365         qp->lf.lf_id = qp_id;
366         qp->lf.nb_desc = conf->nb_descriptors;
367
368         ret = roc_cpt_lf_init(roc_cpt, &qp->lf);
369         if (ret < 0) {
370                 plt_err("Could not initialize queue pair %d", qp_id);
371                 ret = -EINVAL;
372                 goto exit;
373         }
374
375         roc_cpt->lf[qp_id] = &qp->lf;
376
377         ret = roc_cpt_lmtline_init(roc_cpt, &qp->lmtline, qp_id);
378         if (ret < 0) {
379                 roc_cpt->lf[qp_id] = NULL;
380                 plt_err("Could not init lmtline for queue pair %d", qp_id);
381                 goto exit;
382         }
383
384         qp->sess_mp = conf->mp_session;
385         qp->sess_mp_priv = conf->mp_session_private;
386         dev->data->queue_pairs[qp_id] = qp;
387
388         return 0;
389
390 exit:
391         cnxk_cpt_qp_destroy(dev, qp);
392         return ret;
393 }
394
395 unsigned int
396 cnxk_cpt_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
397 {
398         return sizeof(struct cnxk_se_sess);
399 }
400
401 static int
402 sym_xform_verify(struct rte_crypto_sym_xform *xform)
403 {
404         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
405             xform->auth.algo == RTE_CRYPTO_AUTH_NULL &&
406             xform->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY)
407                 return -ENOTSUP;
408
409         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL)
410                 return CNXK_CPT_CIPHER;
411
412         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH && xform->next == NULL)
413                 return CNXK_CPT_AUTH;
414
415         if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD && xform->next == NULL)
416                 return CNXK_CPT_AEAD;
417
418         if (xform->next == NULL)
419                 return -EIO;
420
421         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
422             xform->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC &&
423             xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
424             xform->next->auth.algo == RTE_CRYPTO_AUTH_SHA1)
425                 return -ENOTSUP;
426
427         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
428             xform->auth.algo == RTE_CRYPTO_AUTH_SHA1 &&
429             xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
430             xform->next->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC)
431                 return -ENOTSUP;
432
433         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
434             xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
435             xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
436             xform->next->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE)
437                 return CNXK_CPT_CIPHER_ENC_AUTH_GEN;
438
439         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
440             xform->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY &&
441             xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
442             xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT)
443                 return CNXK_CPT_AUTH_VRFY_CIPHER_DEC;
444
445         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
446             xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE &&
447             xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
448             xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
449                 switch (xform->auth.algo) {
450                 case RTE_CRYPTO_AUTH_SHA1_HMAC:
451                         switch (xform->next->cipher.algo) {
452                         case RTE_CRYPTO_CIPHER_AES_CBC:
453                                 return CNXK_CPT_AUTH_GEN_CIPHER_ENC;
454                         default:
455                                 return -ENOTSUP;
456                         }
457                 default:
458                         return -ENOTSUP;
459                 }
460         }
461
462         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
463             xform->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT &&
464             xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
465             xform->next->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
466                 switch (xform->cipher.algo) {
467                 case RTE_CRYPTO_CIPHER_AES_CBC:
468                         switch (xform->next->auth.algo) {
469                         case RTE_CRYPTO_AUTH_SHA1_HMAC:
470                                 return CNXK_CPT_CIPHER_DEC_AUTH_VRFY;
471                         default:
472                                 return -ENOTSUP;
473                         }
474                 default:
475                         return -ENOTSUP;
476                 }
477         }
478
479         return -ENOTSUP;
480 }
481
482 static uint64_t
483 cnxk_cpt_inst_w7_get(struct cnxk_se_sess *sess, struct roc_cpt *roc_cpt)
484 {
485         union cpt_inst_w7 inst_w7;
486
487         inst_w7.s.cptr = (uint64_t)&sess->roc_se_ctx.se_ctx;
488
489         /* Set the engine group */
490         if (sess->zsk_flag || sess->chacha_poly)
491                 inst_w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_SE];
492         else
493                 inst_w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_IE];
494
495         return inst_w7.u64;
496 }
497
498 int
499 sym_session_configure(struct roc_cpt *roc_cpt, int driver_id,
500                       struct rte_crypto_sym_xform *xform,
501                       struct rte_cryptodev_sym_session *sess,
502                       struct rte_mempool *pool)
503 {
504         struct cnxk_se_sess *sess_priv;
505         void *priv;
506         int ret;
507
508         ret = sym_xform_verify(xform);
509         if (unlikely(ret < 0))
510                 return ret;
511
512         if (unlikely(rte_mempool_get(pool, &priv))) {
513                 plt_dp_err("Could not allocate session private data");
514                 return -ENOMEM;
515         }
516
517         memset(priv, 0, sizeof(struct cnxk_se_sess));
518
519         sess_priv = priv;
520
521         switch (ret) {
522         case CNXK_CPT_CIPHER:
523                 ret = fill_sess_cipher(xform, sess_priv);
524                 break;
525         case CNXK_CPT_AUTH:
526                 if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC)
527                         ret = fill_sess_gmac(xform, sess_priv);
528                 else
529                         ret = fill_sess_auth(xform, sess_priv);
530                 break;
531         case CNXK_CPT_AEAD:
532                 ret = fill_sess_aead(xform, sess_priv);
533                 break;
534         case CNXK_CPT_CIPHER_ENC_AUTH_GEN:
535         case CNXK_CPT_CIPHER_DEC_AUTH_VRFY:
536                 ret = fill_sess_cipher(xform, sess_priv);
537                 if (ret < 0)
538                         break;
539                 ret = fill_sess_auth(xform->next, sess_priv);
540                 break;
541         case CNXK_CPT_AUTH_VRFY_CIPHER_DEC:
542         case CNXK_CPT_AUTH_GEN_CIPHER_ENC:
543                 ret = fill_sess_auth(xform, sess_priv);
544                 if (ret < 0)
545                         break;
546                 ret = fill_sess_cipher(xform->next, sess_priv);
547                 break;
548         default:
549                 ret = -1;
550         }
551
552         if (ret)
553                 goto priv_put;
554
555         if ((sess_priv->roc_se_ctx.fc_type == ROC_SE_HASH_HMAC) &&
556             cpt_mac_len_verify(&xform->auth)) {
557                 plt_dp_err("MAC length is not supported");
558                 if (sess_priv->roc_se_ctx.auth_key != NULL) {
559                         plt_free(sess_priv->roc_se_ctx.auth_key);
560                         sess_priv->roc_se_ctx.auth_key = NULL;
561                 }
562
563                 ret = -ENOTSUP;
564                 goto priv_put;
565         }
566
567         sess_priv->cpt_inst_w7 = cnxk_cpt_inst_w7_get(sess_priv, roc_cpt);
568
569         set_sym_session_private_data(sess, driver_id, sess_priv);
570
571         return 0;
572
573 priv_put:
574         rte_mempool_put(pool, priv);
575
576         return -ENOTSUP;
577 }
578
579 int
580 cnxk_cpt_sym_session_configure(struct rte_cryptodev *dev,
581                                struct rte_crypto_sym_xform *xform,
582                                struct rte_cryptodev_sym_session *sess,
583                                struct rte_mempool *pool)
584 {
585         struct cnxk_cpt_vf *vf = dev->data->dev_private;
586         struct roc_cpt *roc_cpt = &vf->cpt;
587         uint8_t driver_id;
588
589         driver_id = dev->driver_id;
590
591         return sym_session_configure(roc_cpt, driver_id, xform, sess, pool);
592 }
593
594 void
595 sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess)
596 {
597         void *priv = get_sym_session_private_data(sess, driver_id);
598         struct cnxk_se_sess *sess_priv;
599         struct rte_mempool *pool;
600
601         if (priv == NULL)
602                 return;
603
604         sess_priv = priv;
605
606         if (sess_priv->roc_se_ctx.auth_key != NULL)
607                 plt_free(sess_priv->roc_se_ctx.auth_key);
608
609         memset(priv, 0, cnxk_cpt_sym_session_get_size(NULL));
610
611         pool = rte_mempool_from_obj(priv);
612
613         set_sym_session_private_data(sess, driver_id, NULL);
614
615         rte_mempool_put(pool, priv);
616 }
617
618 void
619 cnxk_cpt_sym_session_clear(struct rte_cryptodev *dev,
620                            struct rte_cryptodev_sym_session *sess)
621 {
622         return sym_session_clear(dev->driver_id, sess);
623 }
624
625 unsigned int
626 cnxk_ae_session_size_get(struct rte_cryptodev *dev __rte_unused)
627 {
628         return sizeof(struct cnxk_ae_sess);
629 }
630
631 void
632 cnxk_ae_session_clear(struct rte_cryptodev *dev,
633                       struct rte_cryptodev_asym_session *sess)
634 {
635         struct rte_mempool *sess_mp;
636         struct cnxk_ae_sess *priv;
637
638         priv = get_asym_session_private_data(sess, dev->driver_id);
639         if (priv == NULL)
640                 return;
641
642         /* Free resources allocated in session_cfg */
643         cnxk_ae_free_session_parameters(priv);
644
645         /* Reset and free object back to pool */
646         memset(priv, 0, cnxk_ae_session_size_get(dev));
647         sess_mp = rte_mempool_from_obj(priv);
648         set_asym_session_private_data(sess, dev->driver_id, NULL);
649         rte_mempool_put(sess_mp, priv);
650 }
651
652 int
653 cnxk_ae_session_cfg(struct rte_cryptodev *dev,
654                     struct rte_crypto_asym_xform *xform,
655                     struct rte_cryptodev_asym_session *sess,
656                     struct rte_mempool *pool)
657 {
658         struct cnxk_cpt_vf *vf = dev->data->dev_private;
659         struct roc_cpt *roc_cpt = &vf->cpt;
660         struct cnxk_ae_sess *priv;
661         union cpt_inst_w7 w7;
662         int ret;
663
664         if (rte_mempool_get(pool, (void **)&priv))
665                 return -ENOMEM;
666
667         memset(priv, 0, sizeof(struct cnxk_ae_sess));
668
669         ret = cnxk_ae_fill_session_parameters(priv, xform);
670         if (ret) {
671                 rte_mempool_put(pool, priv);
672                 return ret;
673         }
674
675         w7.u64 = 0;
676         w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_AE];
677         priv->cpt_inst_w7 = w7.u64;
678         priv->cnxk_fpm_iova = vf->cnxk_fpm_iova;
679         priv->ec_grp = vf->ec_grp;
680         set_asym_session_private_data(sess, dev->driver_id, priv);
681
682         return 0;
683 }