net/tap: set BPF syscall ID for RISC-V
[dpdk.git] / drivers / crypto / cnxk / cn10k_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_event_crypto_adapter.h>
8 #include <rte_ip.h>
9
10 #include "cn10k_cryptodev.h"
11 #include "cn10k_cryptodev_ops.h"
12 #include "cn10k_ipsec_la_ops.h"
13 #include "cn10k_ipsec.h"
14 #include "cnxk_ae.h"
15 #include "cnxk_cryptodev.h"
16 #include "cnxk_cryptodev_ops.h"
17 #include "cnxk_se.h"
18
19 #include "roc_api.h"
20
21 static inline struct cnxk_se_sess *
22 cn10k_cpt_sym_temp_sess_create(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op)
23 {
24         const int driver_id = cn10k_cryptodev_driver_id;
25         struct rte_crypto_sym_op *sym_op = op->sym;
26         struct rte_cryptodev_sym_session *sess;
27         struct cnxk_se_sess *priv;
28         int ret;
29
30         /* Create temporary session */
31         sess = rte_cryptodev_sym_session_create(qp->sess_mp);
32         if (sess == NULL)
33                 return NULL;
34
35         ret = sym_session_configure(qp->lf.roc_cpt, driver_id, sym_op->xform,
36                                     sess, qp->sess_mp_priv);
37         if (ret)
38                 goto sess_put;
39
40         priv = get_sym_session_private_data(sess, driver_id);
41
42         sym_op->session = sess;
43
44         return priv;
45
46 sess_put:
47         rte_mempool_put(qp->sess_mp, sess);
48         return NULL;
49 }
50
51 static __rte_always_inline int __rte_hot
52 cpt_sec_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
53                   struct cn10k_sec_session *sess, struct cpt_inst_s *inst)
54 {
55         struct rte_crypto_sym_op *sym_op = op->sym;
56         struct cn10k_ipsec_sa *sa;
57         int ret;
58
59         if (unlikely(sym_op->m_dst && sym_op->m_dst != sym_op->m_src)) {
60                 plt_dp_err("Out of place is not supported");
61                 return -ENOTSUP;
62         }
63
64         if (unlikely(!rte_pktmbuf_is_contiguous(sym_op->m_src))) {
65                 plt_dp_err("Scatter Gather mode is not supported");
66                 return -ENOTSUP;
67         }
68
69         sa = &sess->sa;
70
71         if (sa->is_outbound)
72                 ret = process_outb_sa(&qp->lf, op, sa, inst);
73         else
74                 ret = process_inb_sa(op, sa, inst);
75
76         return ret;
77 }
78
79 static __rte_always_inline int __rte_hot
80 cpt_sym_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
81                   struct cnxk_se_sess *sess, struct cpt_inflight_req *infl_req,
82                   struct cpt_inst_s *inst)
83 {
84         uint64_t cpt_op;
85         int ret;
86
87         cpt_op = sess->cpt_op;
88
89         if (cpt_op & ROC_SE_OP_CIPHER_MASK)
90                 ret = fill_fc_params(op, sess, &qp->meta_info, infl_req, inst);
91         else
92                 ret = fill_digest_params(op, sess, &qp->meta_info, infl_req,
93                                          inst);
94
95         return ret;
96 }
97
98 static inline int
99 cn10k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[],
100                     struct cpt_inst_s inst[], struct cpt_inflight_req *infl_req)
101 {
102         struct cn10k_sec_session *sec_sess;
103         struct rte_crypto_asym_op *asym_op;
104         struct rte_crypto_sym_op *sym_op;
105         struct cnxk_ae_sess *ae_sess;
106         struct cnxk_se_sess *sess;
107         struct rte_crypto_op *op;
108         uint64_t w7;
109         int ret;
110
111         const union cpt_res_s res = {
112                 .cn10k.compcode = CPT_COMP_NOT_DONE,
113         };
114
115         op = ops[0];
116
117         inst[0].w0.u64 = 0;
118         inst[0].w2.u64 = 0;
119         inst[0].w3.u64 = 0;
120
121         sym_op = op->sym;
122
123         if (op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
124                 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
125                         sec_sess = get_sec_session_private_data(
126                                 sym_op->sec_session);
127                         ret = cpt_sec_inst_fill(qp, op, sec_sess, &inst[0]);
128                         if (unlikely(ret))
129                                 return 0;
130                         w7 = sec_sess->sa.inst.w7;
131                 } else if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
132                         sess = get_sym_session_private_data(
133                                 sym_op->session, cn10k_cryptodev_driver_id);
134                         ret = cpt_sym_inst_fill(qp, op, sess, infl_req,
135                                                 &inst[0]);
136                         if (unlikely(ret))
137                                 return 0;
138                         w7 = sess->cpt_inst_w7;
139                 } else {
140                         sess = cn10k_cpt_sym_temp_sess_create(qp, op);
141                         if (unlikely(sess == NULL)) {
142                                 plt_dp_err("Could not create temp session");
143                                 return 0;
144                         }
145
146                         ret = cpt_sym_inst_fill(qp, op, sess, infl_req,
147                                                 &inst[0]);
148                         if (unlikely(ret)) {
149                                 sym_session_clear(cn10k_cryptodev_driver_id,
150                                                   op->sym->session);
151                                 rte_mempool_put(qp->sess_mp, op->sym->session);
152                                 return 0;
153                         }
154                         w7 = sess->cpt_inst_w7;
155                 }
156         } else if (op->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
157
158                 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
159                         asym_op = op->asym;
160                         ae_sess = (struct cnxk_ae_sess *)
161                                         asym_op->session->sess_private_data;
162                         ret = cnxk_ae_enqueue(qp, op, infl_req, &inst[0],
163                                               ae_sess);
164                         if (unlikely(ret))
165                                 return 0;
166                         w7 = ae_sess->cpt_inst_w7;
167                 } else {
168                         plt_dp_err("Not supported Asym op without session");
169                         return 0;
170                 }
171         } else {
172                 plt_dp_err("Unsupported op type");
173                 return 0;
174         }
175
176         inst[0].res_addr = (uint64_t)&infl_req->res;
177         __atomic_store_n(&infl_req->res.u64[0], res.u64[0], __ATOMIC_RELAXED);
178         infl_req->cop = op;
179
180         inst[0].w7.u64 = w7;
181
182         return 1;
183 }
184
185 #define PKTS_PER_LOOP   32
186 #define PKTS_PER_STEORL 16
187
188 static uint16_t
189 cn10k_cpt_enqueue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
190 {
191         uint64_t lmt_base, lmt_arg, io_addr;
192         struct cpt_inflight_req *infl_req;
193         uint16_t nb_allowed, count = 0;
194         struct cnxk_cpt_qp *qp = qptr;
195         struct pending_queue *pend_q;
196         struct cpt_inst_s *inst;
197         uint16_t lmt_id;
198         uint64_t head;
199         int ret, i;
200
201         pend_q = &qp->pend_q;
202
203         const uint64_t pq_mask = pend_q->pq_mask;
204
205         head = pend_q->head;
206         nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
207         nb_ops = RTE_MIN(nb_ops, nb_allowed);
208
209         if (unlikely(nb_ops == 0))
210                 return 0;
211
212         lmt_base = qp->lmtline.lmt_base;
213         io_addr = qp->lmtline.io_addr;
214
215         ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
216         inst = (struct cpt_inst_s *)lmt_base;
217
218 again:
219         for (i = 0; i < RTE_MIN(PKTS_PER_LOOP, nb_ops); i++) {
220                 infl_req = &pend_q->req_queue[head];
221                 infl_req->op_flags = 0;
222
223                 ret = cn10k_cpt_fill_inst(qp, ops + i, &inst[2 * i], infl_req);
224                 if (unlikely(ret != 1)) {
225                         plt_dp_err("Could not process op: %p", ops + i);
226                         if (i == 0)
227                                 goto pend_q_commit;
228                         break;
229                 }
230
231                 pending_queue_advance(&head, pq_mask);
232         }
233
234         if (i > PKTS_PER_STEORL) {
235                 lmt_arg = ROC_CN10K_CPT_LMT_ARG | (PKTS_PER_STEORL - 1) << 12 |
236                           (uint64_t)lmt_id;
237                 roc_lmt_submit_steorl(lmt_arg, io_addr);
238                 lmt_arg = ROC_CN10K_CPT_LMT_ARG |
239                           (i - PKTS_PER_STEORL - 1) << 12 |
240                           (uint64_t)(lmt_id + PKTS_PER_STEORL);
241                 roc_lmt_submit_steorl(lmt_arg, io_addr);
242         } else {
243                 lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - 1) << 12 |
244                           (uint64_t)lmt_id;
245                 roc_lmt_submit_steorl(lmt_arg, io_addr);
246         }
247
248         rte_io_wmb();
249
250         if (nb_ops - i > 0 && i == PKTS_PER_LOOP) {
251                 nb_ops -= i;
252                 ops += i;
253                 count += i;
254                 goto again;
255         }
256
257 pend_q_commit:
258         rte_atomic_thread_fence(__ATOMIC_RELEASE);
259
260         pend_q->head = head;
261         pend_q->time_out = rte_get_timer_cycles() +
262                            DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
263
264         return count + i;
265 }
266
267 static int
268 cn10k_cpt_crypto_adapter_ev_mdata_set(struct rte_cryptodev *dev __rte_unused,
269                                       void *sess,
270                                       enum rte_crypto_op_type op_type,
271                                       enum rte_crypto_op_sess_type sess_type,
272                                       void *mdata)
273 {
274         union rte_event_crypto_metadata *ec_mdata = mdata;
275         struct rte_event *rsp_info;
276         struct cnxk_cpt_qp *qp;
277         uint8_t cdev_id;
278         int16_t qp_id;
279         uint64_t w2;
280
281         /* Get queue pair */
282         cdev_id = ec_mdata->request_info.cdev_id;
283         qp_id = ec_mdata->request_info.queue_pair_id;
284         qp = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id];
285
286         /* Prepare w2 */
287         rsp_info = &ec_mdata->response_info;
288         w2 = CNXK_CPT_INST_W2(
289                 (RTE_EVENT_TYPE_CRYPTODEV << 28) | rsp_info->flow_id,
290                 rsp_info->sched_type, rsp_info->queue_id, 0);
291
292         /* Set meta according to session type */
293         if (op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
294                 if (sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
295                         struct cn10k_sec_session *priv;
296                         struct cn10k_ipsec_sa *sa;
297
298                         priv = get_sec_session_private_data(sess);
299                         sa = &priv->sa;
300                         sa->qp = qp;
301                         sa->inst.w2 = w2;
302                 } else if (sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
303                         struct cnxk_se_sess *priv;
304
305                         priv = get_sym_session_private_data(
306                                 sess, cn10k_cryptodev_driver_id);
307                         priv->qp = qp;
308                         priv->cpt_inst_w2 = w2;
309                 } else
310                         return -EINVAL;
311         } else if (op_type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
312                 if (sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
313                         struct rte_cryptodev_asym_session *asym_sess = sess;
314                         struct cnxk_ae_sess *priv;
315
316                         priv = (struct cnxk_ae_sess *)asym_sess->sess_private_data;
317                         priv->qp = qp;
318                         priv->cpt_inst_w2 = w2;
319                 } else
320                         return -EINVAL;
321         } else
322                 return -EINVAL;
323
324         return 0;
325 }
326
327 static inline int
328 cn10k_ca_meta_info_extract(struct rte_crypto_op *op,
329                          struct cnxk_cpt_qp **qp, uint64_t *w2)
330 {
331         if (op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
332                 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
333                         struct cn10k_sec_session *priv;
334                         struct cn10k_ipsec_sa *sa;
335
336                         priv = get_sec_session_private_data(op->sym->sec_session);
337                         sa = &priv->sa;
338                         *qp = sa->qp;
339                         *w2 = sa->inst.w2;
340                 } else if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
341                         struct cnxk_se_sess *priv;
342
343                         priv = get_sym_session_private_data(
344                                 op->sym->session, cn10k_cryptodev_driver_id);
345                         *qp = priv->qp;
346                         *w2 = priv->cpt_inst_w2;
347                 } else {
348                         union rte_event_crypto_metadata *ec_mdata;
349                         struct rte_event *rsp_info;
350                         uint8_t cdev_id;
351                         uint16_t qp_id;
352
353                         ec_mdata = (union rte_event_crypto_metadata *)
354                                 ((uint8_t *)op + op->private_data_offset);
355                         if (!ec_mdata)
356                                 return -EINVAL;
357                         rsp_info = &ec_mdata->response_info;
358                         cdev_id = ec_mdata->request_info.cdev_id;
359                         qp_id = ec_mdata->request_info.queue_pair_id;
360                         *qp = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id];
361                         *w2 = CNXK_CPT_INST_W2(
362                                 (RTE_EVENT_TYPE_CRYPTODEV << 28) | rsp_info->flow_id,
363                                 rsp_info->sched_type, rsp_info->queue_id, 0);
364                 }
365         } else if (op->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
366                 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
367                         struct rte_cryptodev_asym_session *asym_sess;
368                         struct cnxk_ae_sess *priv;
369
370                         asym_sess = op->asym->session;
371                         priv = (struct cnxk_ae_sess *)asym_sess->sess_private_data;
372                         *qp = priv->qp;
373                         *w2 = priv->cpt_inst_w2;
374                 } else
375                         return -EINVAL;
376         } else
377                 return -EINVAL;
378
379         return 0;
380 }
381
382 uint16_t
383 cn10k_cpt_crypto_adapter_enqueue(uintptr_t base, struct rte_crypto_op *op)
384 {
385         struct cpt_inflight_req *infl_req;
386         uint64_t lmt_base, lmt_arg, w2;
387         struct cpt_inst_s *inst;
388         struct cnxk_cpt_qp *qp;
389         uint16_t lmt_id;
390         int ret;
391
392         ret = cn10k_ca_meta_info_extract(op, &qp, &w2);
393         if (unlikely(ret)) {
394                 rte_errno = EINVAL;
395                 return 0;
396         }
397
398         if (unlikely(!qp->ca.enabled)) {
399                 rte_errno = EINVAL;
400                 return 0;
401         }
402
403         if (unlikely(rte_mempool_get(qp->ca.req_mp, (void **)&infl_req))) {
404                 rte_errno = ENOMEM;
405                 return 0;
406         }
407         infl_req->op_flags = 0;
408
409         lmt_base = qp->lmtline.lmt_base;
410         ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
411         inst = (struct cpt_inst_s *)lmt_base;
412
413         ret = cn10k_cpt_fill_inst(qp, &op, inst, infl_req);
414         if (unlikely(ret != 1)) {
415                 plt_dp_err("Could not process op: %p", op);
416                 rte_mempool_put(qp->ca.req_mp, infl_req);
417                 return 0;
418         }
419
420         infl_req->cop = op;
421         infl_req->res.cn10k.compcode = CPT_COMP_NOT_DONE;
422         infl_req->qp = qp;
423         inst->w0.u64 = 0;
424         inst->res_addr = (uint64_t)&infl_req->res;
425         inst->w2.u64 = w2;
426         inst->w3.u64 = CNXK_CPT_INST_W3(1, infl_req);
427
428         if (roc_cpt_is_iq_full(&qp->lf)) {
429                 rte_mempool_put(qp->ca.req_mp, infl_req);
430                 rte_errno = EAGAIN;
431                 return 0;
432         }
433
434         if (inst->w2.s.tt == RTE_SCHED_TYPE_ORDERED)
435                 roc_sso_hws_head_wait(base);
436
437         lmt_arg = ROC_CN10K_CPT_LMT_ARG | (uint64_t)lmt_id;
438         roc_lmt_submit_steorl(lmt_arg, qp->lmtline.io_addr);
439
440         rte_io_wmb();
441
442         return 1;
443 }
444
445 static inline void
446 cn10k_cpt_sec_post_process(struct rte_crypto_op *cop,
447                            struct cpt_cn10k_res_s *res)
448 {
449         struct rte_mbuf *mbuf = cop->sym->m_src;
450         const uint16_t m_len = res->rlen;
451
452         mbuf->data_len = m_len;
453         mbuf->pkt_len = m_len;
454
455         switch (res->uc_compcode) {
456         case ROC_IE_OT_UCC_SUCCESS:
457                 break;
458         case ROC_IE_OT_UCC_SUCCESS_PKT_IP_BADCSUM:
459                 mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
460                 break;
461         case ROC_IE_OT_UCC_SUCCESS_PKT_L4_GOODCSUM:
462                 mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD |
463                                   RTE_MBUF_F_RX_IP_CKSUM_GOOD;
464                 break;
465         case ROC_IE_OT_UCC_SUCCESS_PKT_L4_BADCSUM:
466                 mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD |
467                                   RTE_MBUF_F_RX_IP_CKSUM_GOOD;
468                 break;
469         case ROC_IE_OT_UCC_SUCCESS_PKT_IP_GOODCSUM:
470                 mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
471                 break;
472         case ROC_IE_OT_UCC_SUCCESS_SA_SOFTEXP_FIRST:
473                 cop->aux_flags = RTE_CRYPTO_OP_AUX_FLAGS_IPSEC_SOFT_EXPIRY;
474                 break;
475         default:
476                 plt_dp_err("Success with unknown microcode completion code");
477                 break;
478         }
479 }
480
481 static inline void
482 cn10k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp,
483                                struct rte_crypto_op *cop,
484                                struct cpt_inflight_req *infl_req,
485                                struct cpt_cn10k_res_s *res)
486 {
487         const uint8_t uc_compcode = res->uc_compcode;
488         const uint8_t compcode = res->compcode;
489         unsigned int sz;
490
491         cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
492
493         if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
494             cop->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
495                 if (likely(compcode == CPT_COMP_WARN)) {
496                         /* Success with additional info */
497                         cn10k_cpt_sec_post_process(cop, res);
498                 } else {
499                         cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
500                         plt_dp_info("HW completion code 0x%x", res->compcode);
501                         if (compcode == CPT_COMP_GOOD) {
502                                 plt_dp_info(
503                                         "Request failed with microcode error");
504                                 plt_dp_info("MC completion code 0x%x",
505                                             uc_compcode);
506                         }
507                 }
508
509                 return;
510         }
511
512         if (likely(compcode == CPT_COMP_GOOD || compcode == CPT_COMP_WARN)) {
513                 if (unlikely(uc_compcode)) {
514                         if (uc_compcode == ROC_SE_ERR_GC_ICV_MISCOMPARE)
515                                 cop->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
516                         else
517                                 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
518
519                         plt_dp_info("Request failed with microcode error");
520                         plt_dp_info("MC completion code 0x%x",
521                                     res->uc_compcode);
522                         goto temp_sess_free;
523                 }
524
525                 if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
526                         /* Verify authentication data if required */
527                         if (unlikely(infl_req->op_flags &
528                                      CPT_OP_FLAGS_AUTH_VERIFY)) {
529                                 uintptr_t *rsp = infl_req->mdata;
530                                 compl_auth_verify(cop, (uint8_t *)rsp[0],
531                                                   rsp[1]);
532                         }
533                 } else if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
534                         struct rte_crypto_asym_op *op = cop->asym;
535                         uintptr_t *mdata = infl_req->mdata;
536                         struct cnxk_ae_sess *sess;
537
538                         sess = (struct cnxk_ae_sess *)
539                                         op->session->sess_private_data;
540
541                         cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
542                 }
543         } else {
544                 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
545                 plt_dp_info("HW completion code 0x%x", res->compcode);
546
547                 switch (compcode) {
548                 case CPT_COMP_INSTERR:
549                         plt_dp_err("Request failed with instruction error");
550                         break;
551                 case CPT_COMP_FAULT:
552                         plt_dp_err("Request failed with DMA fault");
553                         break;
554                 case CPT_COMP_HWERR:
555                         plt_dp_err("Request failed with hardware error");
556                         break;
557                 default:
558                         plt_dp_err(
559                                 "Request failed with unknown completion code");
560                 }
561         }
562
563 temp_sess_free:
564         if (unlikely(cop->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
565                 if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
566                         sym_session_clear(cn10k_cryptodev_driver_id,
567                                           cop->sym->session);
568                         sz = rte_cryptodev_sym_get_existing_header_session_size(
569                                 cop->sym->session);
570                         memset(cop->sym->session, 0, sz);
571                         rte_mempool_put(qp->sess_mp, cop->sym->session);
572                         cop->sym->session = NULL;
573                 }
574         }
575 }
576
577 uintptr_t
578 cn10k_cpt_crypto_adapter_dequeue(uintptr_t get_work1)
579 {
580         struct cpt_inflight_req *infl_req;
581         struct rte_crypto_op *cop;
582         struct cnxk_cpt_qp *qp;
583         union cpt_res_s res;
584
585         infl_req = (struct cpt_inflight_req *)(get_work1);
586         cop = infl_req->cop;
587         qp = infl_req->qp;
588
589         res.u64[0] = __atomic_load_n(&infl_req->res.u64[0], __ATOMIC_RELAXED);
590
591         cn10k_cpt_dequeue_post_process(qp, infl_req->cop, infl_req, &res.cn10k);
592
593         if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
594                 rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
595
596         rte_mempool_put(qp->ca.req_mp, infl_req);
597         return (uintptr_t)cop;
598 }
599
600 static uint16_t
601 cn10k_cpt_dequeue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
602 {
603         struct cpt_inflight_req *infl_req;
604         struct cnxk_cpt_qp *qp = qptr;
605         struct pending_queue *pend_q;
606         uint64_t infl_cnt, pq_tail;
607         struct rte_crypto_op *cop;
608         union cpt_res_s res;
609         int i;
610
611         pend_q = &qp->pend_q;
612
613         const uint64_t pq_mask = pend_q->pq_mask;
614
615         pq_tail = pend_q->tail;
616         infl_cnt = pending_queue_infl_cnt(pend_q->head, pq_tail, pq_mask);
617         nb_ops = RTE_MIN(nb_ops, infl_cnt);
618
619         /* Ensure infl_cnt isn't read before data lands */
620         rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
621
622         for (i = 0; i < nb_ops; i++) {
623                 infl_req = &pend_q->req_queue[pq_tail];
624
625                 res.u64[0] = __atomic_load_n(&infl_req->res.u64[0],
626                                              __ATOMIC_RELAXED);
627
628                 if (unlikely(res.cn10k.compcode == CPT_COMP_NOT_DONE)) {
629                         if (unlikely(rte_get_timer_cycles() >
630                                      pend_q->time_out)) {
631                                 plt_err("Request timed out");
632                                 cnxk_cpt_dump_on_err(qp);
633                                 pend_q->time_out = rte_get_timer_cycles() +
634                                                    DEFAULT_COMMAND_TIMEOUT *
635                                                            rte_get_timer_hz();
636                         }
637                         break;
638                 }
639
640                 pending_queue_advance(&pq_tail, pq_mask);
641
642                 cop = infl_req->cop;
643
644                 ops[i] = cop;
645
646                 cn10k_cpt_dequeue_post_process(qp, cop, infl_req, &res.cn10k);
647
648                 if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
649                         rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
650         }
651
652         pend_q->tail = pq_tail;
653
654         return i;
655 }
656
657 void
658 cn10k_cpt_set_enqdeq_fns(struct rte_cryptodev *dev)
659 {
660         dev->enqueue_burst = cn10k_cpt_enqueue_burst;
661         dev->dequeue_burst = cn10k_cpt_dequeue_burst;
662
663         rte_mb();
664 }
665
666 static void
667 cn10k_cpt_dev_info_get(struct rte_cryptodev *dev,
668                        struct rte_cryptodev_info *info)
669 {
670         if (info != NULL) {
671                 cnxk_cpt_dev_info_get(dev, info);
672                 info->driver_id = cn10k_cryptodev_driver_id;
673         }
674 }
675
676 struct rte_cryptodev_ops cn10k_cpt_ops = {
677         /* Device control ops */
678         .dev_configure = cnxk_cpt_dev_config,
679         .dev_start = cnxk_cpt_dev_start,
680         .dev_stop = cnxk_cpt_dev_stop,
681         .dev_close = cnxk_cpt_dev_close,
682         .dev_infos_get = cn10k_cpt_dev_info_get,
683
684         .stats_get = NULL,
685         .stats_reset = NULL,
686         .queue_pair_setup = cnxk_cpt_queue_pair_setup,
687         .queue_pair_release = cnxk_cpt_queue_pair_release,
688
689         /* Symmetric crypto ops */
690         .sym_session_get_size = cnxk_cpt_sym_session_get_size,
691         .sym_session_configure = cnxk_cpt_sym_session_configure,
692         .sym_session_clear = cnxk_cpt_sym_session_clear,
693
694         /* Asymmetric crypto ops */
695         .asym_session_get_size = cnxk_ae_session_size_get,
696         .asym_session_configure = cnxk_ae_session_cfg,
697         .asym_session_clear = cnxk_ae_session_clear,
698
699         /* Event crypto ops */
700         .session_ev_mdata_set = cn10k_cpt_crypto_adapter_ev_mdata_set,
701 };