crypto/cnxk: add more info on command timeout
[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                 /* Application may not setup all queue pair */
105                 if (roc_cpt->lf[qp_id] == NULL)
106                         continue;
107
108                 roc_cpt_iq_enable(roc_cpt->lf[qp_id]);
109         }
110
111         return 0;
112 }
113
114 void
115 cnxk_cpt_dev_stop(struct rte_cryptodev *dev)
116 {
117         struct cnxk_cpt_vf *vf = dev->data->dev_private;
118         struct roc_cpt *roc_cpt = &vf->cpt;
119         uint16_t nb_lf = roc_cpt->nb_lf;
120         uint16_t qp_id;
121
122         for (qp_id = 0; qp_id < nb_lf; qp_id++) {
123                 if (roc_cpt->lf[qp_id] == NULL)
124                         continue;
125
126                 roc_cpt_iq_disable(roc_cpt->lf[qp_id]);
127         }
128 }
129
130 int
131 cnxk_cpt_dev_close(struct rte_cryptodev *dev)
132 {
133         struct cnxk_cpt_vf *vf = dev->data->dev_private;
134         uint16_t i;
135         int ret;
136
137         for (i = 0; i < dev->data->nb_queue_pairs; i++) {
138                 ret = cnxk_cpt_queue_pair_release(dev, i);
139                 if (ret < 0) {
140                         plt_err("Could not release queue pair %u", i);
141                         return ret;
142                 }
143         }
144
145         if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
146                 roc_ae_fpm_put();
147                 roc_ae_ec_grp_put();
148         }
149
150         roc_cpt_dev_clear(&vf->cpt);
151
152         return 0;
153 }
154
155 void
156 cnxk_cpt_dev_info_get(struct rte_cryptodev *dev,
157                       struct rte_cryptodev_info *info)
158 {
159         struct cnxk_cpt_vf *vf = dev->data->dev_private;
160         struct roc_cpt *roc_cpt = &vf->cpt;
161
162         info->max_nb_queue_pairs =
163                 RTE_MIN(roc_cpt->nb_lf_avail, vf->max_qps_limit);
164         plt_cpt_dbg("max_nb_queue_pairs %u", info->max_nb_queue_pairs);
165
166         info->feature_flags = cnxk_cpt_default_ff_get();
167         info->capabilities = cnxk_crypto_capabilities_get(vf);
168         info->sym.max_nb_sessions = 0;
169         info->min_mbuf_headroom_req = CNXK_CPT_MIN_HEADROOM_REQ;
170         info->min_mbuf_tailroom_req = CNXK_CPT_MIN_TAILROOM_REQ;
171 }
172
173 static void
174 qp_memzone_name_get(char *name, int size, int dev_id, int qp_id)
175 {
176         snprintf(name, size, "cnxk_cpt_pq_mem_%u:%u", dev_id, qp_id);
177 }
178
179 static int
180 cnxk_cpt_metabuf_mempool_create(const struct rte_cryptodev *dev,
181                                 struct cnxk_cpt_qp *qp, uint8_t qp_id,
182                                 uint32_t nb_elements)
183 {
184         char mempool_name[RTE_MEMPOOL_NAMESIZE];
185         struct cpt_qp_meta_info *meta_info;
186         int lcore_cnt = rte_lcore_count();
187         struct rte_mempool *pool;
188         int mb_pool_sz, mlen = 8;
189         uint32_t cache_sz;
190
191         if (dev->feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) {
192                 /* Get meta len */
193                 mlen = cnxk_cpt_get_mlen();
194         }
195
196         if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
197
198                 /* Get meta len required for asymmetric operations */
199                 mlen = RTE_MAX(mlen, cnxk_cpt_asym_get_mlen());
200         }
201
202         mb_pool_sz = nb_elements;
203         cache_sz = RTE_MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, nb_elements / 1.5);
204
205         /* For poll mode, core that enqueues and core that dequeues can be
206          * different. For event mode, all cores are allowed to use same crypto
207          * queue pair.
208          */
209
210         mb_pool_sz += (RTE_MAX(2, lcore_cnt) * cache_sz);
211
212         /* Allocate mempool */
213
214         snprintf(mempool_name, RTE_MEMPOOL_NAMESIZE, "cnxk_cpt_mb_%u:%u",
215                  dev->data->dev_id, qp_id);
216
217         pool = rte_mempool_create(mempool_name, mb_pool_sz, mlen, cache_sz, 0,
218                                   NULL, NULL, NULL, NULL, rte_socket_id(), 0);
219
220         if (pool == NULL) {
221                 plt_err("Could not create mempool for metabuf");
222                 return rte_errno;
223         }
224
225         meta_info = &qp->meta_info;
226
227         meta_info->pool = pool;
228         meta_info->mlen = mlen;
229
230         return 0;
231 }
232
233 static void
234 cnxk_cpt_metabuf_mempool_destroy(struct cnxk_cpt_qp *qp)
235 {
236         struct cpt_qp_meta_info *meta_info = &qp->meta_info;
237
238         rte_mempool_free(meta_info->pool);
239
240         meta_info->pool = NULL;
241         meta_info->mlen = 0;
242 }
243
244 static struct cnxk_cpt_qp *
245 cnxk_cpt_qp_create(const struct rte_cryptodev *dev, uint16_t qp_id,
246                    uint32_t iq_len)
247 {
248         const struct rte_memzone *pq_mem;
249         char name[RTE_MEMZONE_NAMESIZE];
250         struct cnxk_cpt_qp *qp;
251         uint32_t len;
252         uint8_t *va;
253         int ret;
254
255         /* Allocate queue pair */
256         qp = rte_zmalloc_socket("CNXK Crypto PMD Queue Pair", sizeof(*qp),
257                                 ROC_ALIGN, 0);
258         if (qp == NULL) {
259                 plt_err("Could not allocate queue pair");
260                 return NULL;
261         }
262
263         /* For pending queue */
264         len = iq_len * sizeof(struct cpt_inflight_req);
265
266         qp_memzone_name_get(name, RTE_MEMZONE_NAMESIZE, dev->data->dev_id,
267                             qp_id);
268
269         pq_mem = rte_memzone_reserve_aligned(name, len, rte_socket_id(),
270                                              RTE_MEMZONE_SIZE_HINT_ONLY |
271                                                      RTE_MEMZONE_256MB,
272                                              RTE_CACHE_LINE_SIZE);
273         if (pq_mem == NULL) {
274                 plt_err("Could not allocate reserved memzone");
275                 goto qp_free;
276         }
277
278         va = pq_mem->addr;
279
280         memset(va, 0, len);
281
282         ret = cnxk_cpt_metabuf_mempool_create(dev, qp, qp_id, iq_len);
283         if (ret) {
284                 plt_err("Could not create mempool for metabuf");
285                 goto pq_mem_free;
286         }
287
288         /* Initialize pending queue */
289         qp->pend_q.req_queue = pq_mem->addr;
290         qp->pend_q.head = 0;
291         qp->pend_q.tail = 0;
292
293         return qp;
294
295 pq_mem_free:
296         rte_memzone_free(pq_mem);
297 qp_free:
298         rte_free(qp);
299         return NULL;
300 }
301
302 static int
303 cnxk_cpt_qp_destroy(const struct rte_cryptodev *dev, struct cnxk_cpt_qp *qp)
304 {
305         const struct rte_memzone *pq_mem;
306         char name[RTE_MEMZONE_NAMESIZE];
307         int ret;
308
309         cnxk_cpt_metabuf_mempool_destroy(qp);
310
311         qp_memzone_name_get(name, RTE_MEMZONE_NAMESIZE, dev->data->dev_id,
312                             qp->lf.lf_id);
313
314         pq_mem = rte_memzone_lookup(name);
315
316         ret = rte_memzone_free(pq_mem);
317         if (ret)
318                 return ret;
319
320         rte_free(qp);
321
322         return 0;
323 }
324
325 int
326 cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id)
327 {
328         struct cnxk_cpt_qp *qp = dev->data->queue_pairs[qp_id];
329         struct cnxk_cpt_vf *vf = dev->data->dev_private;
330         struct roc_cpt *roc_cpt = &vf->cpt;
331         struct roc_cpt_lf *lf;
332         int ret;
333
334         if (qp == NULL)
335                 return -EINVAL;
336
337         lf = roc_cpt->lf[qp_id];
338         if (lf == NULL)
339                 return -ENOTSUP;
340
341         roc_cpt_lf_fini(lf);
342
343         ret = cnxk_cpt_qp_destroy(dev, qp);
344         if (ret) {
345                 plt_err("Could not destroy queue pair %d", qp_id);
346                 return ret;
347         }
348
349         roc_cpt->lf[qp_id] = NULL;
350         dev->data->queue_pairs[qp_id] = NULL;
351
352         return 0;
353 }
354
355 int
356 cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
357                           const struct rte_cryptodev_qp_conf *conf,
358                           int socket_id __rte_unused)
359 {
360         struct cnxk_cpt_vf *vf = dev->data->dev_private;
361         struct roc_cpt *roc_cpt = &vf->cpt;
362         struct rte_pci_device *pci_dev;
363         struct cnxk_cpt_qp *qp;
364         int ret;
365
366         if (dev->data->queue_pairs[qp_id] != NULL)
367                 cnxk_cpt_queue_pair_release(dev, qp_id);
368
369         pci_dev = RTE_DEV_TO_PCI(dev->device);
370
371         if (pci_dev->mem_resource[2].addr == NULL) {
372                 plt_err("Invalid PCI mem address");
373                 return -EIO;
374         }
375
376         qp = cnxk_cpt_qp_create(dev, qp_id, conf->nb_descriptors);
377         if (qp == NULL) {
378                 plt_err("Could not create queue pair %d", qp_id);
379                 return -ENOMEM;
380         }
381
382         qp->lf.lf_id = qp_id;
383         qp->lf.nb_desc = conf->nb_descriptors;
384
385         ret = roc_cpt_lf_init(roc_cpt, &qp->lf);
386         if (ret < 0) {
387                 plt_err("Could not initialize queue pair %d", qp_id);
388                 ret = -EINVAL;
389                 goto exit;
390         }
391
392         qp->pend_q.pq_mask = qp->lf.nb_desc - 1;
393
394         roc_cpt->lf[qp_id] = &qp->lf;
395
396         ret = roc_cpt_lmtline_init(roc_cpt, &qp->lmtline, qp_id);
397         if (ret < 0) {
398                 roc_cpt->lf[qp_id] = NULL;
399                 plt_err("Could not init lmtline for queue pair %d", qp_id);
400                 goto exit;
401         }
402
403         qp->sess_mp = conf->mp_session;
404         qp->sess_mp_priv = conf->mp_session_private;
405         dev->data->queue_pairs[qp_id] = qp;
406
407         return 0;
408
409 exit:
410         cnxk_cpt_qp_destroy(dev, qp);
411         return ret;
412 }
413
414 unsigned int
415 cnxk_cpt_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
416 {
417         return sizeof(struct cnxk_se_sess);
418 }
419
420 static int
421 cnxk_sess_fill(struct rte_crypto_sym_xform *xform, struct cnxk_se_sess *sess)
422 {
423         struct rte_crypto_sym_xform *aead_xfrm = NULL;
424         struct rte_crypto_sym_xform *c_xfrm = NULL;
425         struct rte_crypto_sym_xform *a_xfrm = NULL;
426         bool ciph_then_auth = false;
427
428         if (xform == NULL)
429                 return -EINVAL;
430
431         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
432                 c_xfrm = xform;
433                 a_xfrm = xform->next;
434                 ciph_then_auth = true;
435         } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
436                 c_xfrm = xform->next;
437                 a_xfrm = xform;
438                 ciph_then_auth = false;
439         } else {
440                 aead_xfrm = xform;
441         }
442
443         if (c_xfrm != NULL && c_xfrm->type != RTE_CRYPTO_SYM_XFORM_CIPHER) {
444                 plt_dp_err("Invalid type in cipher xform");
445                 return -EINVAL;
446         }
447
448         if (a_xfrm != NULL && a_xfrm->type != RTE_CRYPTO_SYM_XFORM_AUTH) {
449                 plt_dp_err("Invalid type in auth xform");
450                 return -EINVAL;
451         }
452
453         if (aead_xfrm != NULL && aead_xfrm->type != RTE_CRYPTO_SYM_XFORM_AEAD) {
454                 plt_dp_err("Invalid type in AEAD xform");
455                 return -EINVAL;
456         }
457
458         if ((c_xfrm == NULL || c_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_NULL) &&
459             a_xfrm != NULL && a_xfrm->auth.algo == RTE_CRYPTO_AUTH_NULL &&
460             a_xfrm->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
461                 plt_dp_err("Null cipher + null auth verify is not supported");
462                 return -ENOTSUP;
463         }
464
465         /* Cipher only */
466         if (c_xfrm != NULL &&
467             (a_xfrm == NULL || a_xfrm->auth.algo == RTE_CRYPTO_AUTH_NULL)) {
468                 if (fill_sess_cipher(c_xfrm, sess))
469                         return -ENOTSUP;
470                 else
471                         return 0;
472         }
473
474         /* Auth only */
475         if (a_xfrm != NULL &&
476             (c_xfrm == NULL || c_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_NULL)) {
477                 if (fill_sess_auth(a_xfrm, sess))
478                         return -ENOTSUP;
479                 else
480                         return 0;
481         }
482
483         /* AEAD */
484         if (aead_xfrm != NULL) {
485                 if (fill_sess_aead(aead_xfrm, sess))
486                         return -ENOTSUP;
487                 else
488                         return 0;
489         }
490
491         /* Chained ops */
492         if (c_xfrm == NULL || a_xfrm == NULL) {
493                 plt_dp_err("Invalid xforms");
494                 return -EINVAL;
495         }
496
497         if (c_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC &&
498             a_xfrm->auth.algo == RTE_CRYPTO_AUTH_SHA1) {
499                 plt_dp_err("3DES-CBC + SHA1 is not supported");
500                 return -ENOTSUP;
501         }
502
503         /* Cipher then auth */
504         if (ciph_then_auth) {
505                 if (fill_sess_cipher(c_xfrm, sess))
506                         return -ENOTSUP;
507                 if (fill_sess_auth(a_xfrm, sess))
508                         return -ENOTSUP;
509                 else
510                         return 0;
511         }
512
513         /* else */
514
515         if (c_xfrm->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
516                 switch (a_xfrm->auth.algo) {
517                 case RTE_CRYPTO_AUTH_SHA1_HMAC:
518                         switch (c_xfrm->cipher.algo) {
519                         case RTE_CRYPTO_CIPHER_AES_CBC:
520                                 break;
521                         default:
522                                 return -ENOTSUP;
523                         }
524                         break;
525                 default:
526                         return -ENOTSUP;
527                 }
528         }
529
530         if (fill_sess_auth(a_xfrm, sess))
531                 return -ENOTSUP;
532         if (fill_sess_cipher(c_xfrm, sess))
533                 return -ENOTSUP;
534         else
535                 return 0;
536 }
537
538 static uint64_t
539 cnxk_cpt_inst_w7_get(struct cnxk_se_sess *sess, struct roc_cpt *roc_cpt)
540 {
541         union cpt_inst_w7 inst_w7;
542
543         inst_w7.s.cptr = (uint64_t)&sess->roc_se_ctx.se_ctx;
544
545         /* Set the engine group */
546         if (sess->zsk_flag || sess->chacha_poly)
547                 inst_w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_SE];
548         else
549                 inst_w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_IE];
550
551         return inst_w7.u64;
552 }
553
554 int
555 sym_session_configure(struct roc_cpt *roc_cpt, int driver_id,
556                       struct rte_crypto_sym_xform *xform,
557                       struct rte_cryptodev_sym_session *sess,
558                       struct rte_mempool *pool)
559 {
560         struct cnxk_se_sess *sess_priv;
561         void *priv;
562         int ret;
563
564         if (unlikely(rte_mempool_get(pool, &priv))) {
565                 plt_dp_err("Could not allocate session private data");
566                 return -ENOMEM;
567         }
568
569         memset(priv, 0, sizeof(struct cnxk_se_sess));
570
571         sess_priv = priv;
572
573         ret = cnxk_sess_fill(xform, sess_priv);
574         if (ret)
575                 goto priv_put;
576
577         if ((sess_priv->roc_se_ctx.fc_type == ROC_SE_HASH_HMAC) &&
578             cpt_mac_len_verify(&xform->auth)) {
579                 plt_dp_err("MAC length is not supported");
580                 if (sess_priv->roc_se_ctx.auth_key != NULL) {
581                         plt_free(sess_priv->roc_se_ctx.auth_key);
582                         sess_priv->roc_se_ctx.auth_key = NULL;
583                 }
584
585                 ret = -ENOTSUP;
586                 goto priv_put;
587         }
588
589         sess_priv->cpt_inst_w7 = cnxk_cpt_inst_w7_get(sess_priv, roc_cpt);
590
591         set_sym_session_private_data(sess, driver_id, sess_priv);
592
593         return 0;
594
595 priv_put:
596         rte_mempool_put(pool, priv);
597
598         return ret;
599 }
600
601 int
602 cnxk_cpt_sym_session_configure(struct rte_cryptodev *dev,
603                                struct rte_crypto_sym_xform *xform,
604                                struct rte_cryptodev_sym_session *sess,
605                                struct rte_mempool *pool)
606 {
607         struct cnxk_cpt_vf *vf = dev->data->dev_private;
608         struct roc_cpt *roc_cpt = &vf->cpt;
609         uint8_t driver_id;
610
611         driver_id = dev->driver_id;
612
613         return sym_session_configure(roc_cpt, driver_id, xform, sess, pool);
614 }
615
616 void
617 sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess)
618 {
619         void *priv = get_sym_session_private_data(sess, driver_id);
620         struct cnxk_se_sess *sess_priv;
621         struct rte_mempool *pool;
622
623         if (priv == NULL)
624                 return;
625
626         sess_priv = priv;
627
628         if (sess_priv->roc_se_ctx.auth_key != NULL)
629                 plt_free(sess_priv->roc_se_ctx.auth_key);
630
631         memset(priv, 0, cnxk_cpt_sym_session_get_size(NULL));
632
633         pool = rte_mempool_from_obj(priv);
634
635         set_sym_session_private_data(sess, driver_id, NULL);
636
637         rte_mempool_put(pool, priv);
638 }
639
640 void
641 cnxk_cpt_sym_session_clear(struct rte_cryptodev *dev,
642                            struct rte_cryptodev_sym_session *sess)
643 {
644         return sym_session_clear(dev->driver_id, sess);
645 }
646
647 unsigned int
648 cnxk_ae_session_size_get(struct rte_cryptodev *dev __rte_unused)
649 {
650         return sizeof(struct cnxk_ae_sess);
651 }
652
653 void
654 cnxk_ae_session_clear(struct rte_cryptodev *dev,
655                       struct rte_cryptodev_asym_session *sess)
656 {
657         struct rte_mempool *sess_mp;
658         struct cnxk_ae_sess *priv;
659
660         priv = get_asym_session_private_data(sess, dev->driver_id);
661         if (priv == NULL)
662                 return;
663
664         /* Free resources allocated in session_cfg */
665         cnxk_ae_free_session_parameters(priv);
666
667         /* Reset and free object back to pool */
668         memset(priv, 0, cnxk_ae_session_size_get(dev));
669         sess_mp = rte_mempool_from_obj(priv);
670         set_asym_session_private_data(sess, dev->driver_id, NULL);
671         rte_mempool_put(sess_mp, priv);
672 }
673
674 int
675 cnxk_ae_session_cfg(struct rte_cryptodev *dev,
676                     struct rte_crypto_asym_xform *xform,
677                     struct rte_cryptodev_asym_session *sess,
678                     struct rte_mempool *pool)
679 {
680         struct cnxk_cpt_vf *vf = dev->data->dev_private;
681         struct roc_cpt *roc_cpt = &vf->cpt;
682         struct cnxk_ae_sess *priv;
683         union cpt_inst_w7 w7;
684         int ret;
685
686         if (rte_mempool_get(pool, (void **)&priv))
687                 return -ENOMEM;
688
689         memset(priv, 0, sizeof(struct cnxk_ae_sess));
690
691         ret = cnxk_ae_fill_session_parameters(priv, xform);
692         if (ret) {
693                 rte_mempool_put(pool, priv);
694                 return ret;
695         }
696
697         w7.u64 = 0;
698         w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_AE];
699         priv->cpt_inst_w7 = w7.u64;
700         priv->cnxk_fpm_iova = vf->cnxk_fpm_iova;
701         priv->ec_grp = vf->ec_grp;
702         set_asym_session_private_data(sess, dev->driver_id, priv);
703
704         return 0;
705 }
706
707 void
708 cnxk_cpt_dump_on_err(struct cnxk_cpt_qp *qp)
709 {
710         struct pending_queue *pend_q = &qp->pend_q;
711         uint64_t inflight, enq_ptr, deq_ptr, insts;
712         union cpt_lf_q_inst_ptr inst_ptr;
713         union cpt_lf_inprog lf_inprog;
714
715         plt_print("Lcore ID: %d, LF/QP ID: %d", rte_lcore_id(), qp->lf.lf_id);
716         plt_print("");
717         plt_print("S/w pending queue:");
718         plt_print("\tHead: %"PRIu64"", pend_q->head);
719         plt_print("\tTail: %"PRIu64"", pend_q->tail);
720         plt_print("\tMask: 0x%"PRIx64"", pend_q->pq_mask);
721         plt_print("\tInflight count: %"PRIu64"",
722                   pending_queue_infl_cnt(pend_q->head, pend_q->tail,
723                                          pend_q->pq_mask));
724
725         plt_print("");
726         plt_print("H/w pending queue:");
727
728         lf_inprog.u = plt_read64(qp->lf.rbase + CPT_LF_INPROG);
729         inflight = lf_inprog.s.inflight;
730         plt_print("\tInflight in engines: %"PRIu64"", inflight);
731
732         inst_ptr.u = plt_read64(qp->lf.rbase + CPT_LF_Q_INST_PTR);
733
734         enq_ptr = inst_ptr.s.nq_ptr;
735         deq_ptr = inst_ptr.s.dq_ptr;
736
737         if (enq_ptr >= deq_ptr)
738                 insts = enq_ptr - deq_ptr;
739         else
740                 insts = (enq_ptr + pend_q->pq_mask + 1 + 320 + 40) - deq_ptr;
741
742         plt_print("\tNQ ptr: 0x%"PRIx64"", enq_ptr);
743         plt_print("\tDQ ptr: 0x%"PRIx64"", deq_ptr);
744         plt_print("Insts waiting in CPT: %"PRIu64"", insts);
745
746         plt_print("");
747         roc_cpt_afs_print(qp->lf.roc_cpt);
748 }