LCOV - code coverage report
Current view: top level - drivers/crypto/cnxk - cn20k_cryptodev_ops.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 745 0.0 %
Date: 2025-07-01 21:32:37 Functions: 0 33 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 423 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2025 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <cryptodev_pmd.h>
       6                 :            : #include <eal_export.h>
       7                 :            : #include <ethdev_driver.h>
       8                 :            : #include <rte_cryptodev.h>
       9                 :            : #include <rte_hexdump.h>
      10                 :            : #include <rte_vect.h>
      11                 :            : 
      12                 :            : #include "hw/nix.h"
      13                 :            : #include "hw/npa.h"
      14                 :            : #include "hw/tim.h"
      15                 :            : #include "roc_cpt.h"
      16                 :            : #include "roc_idev.h"
      17                 :            : #include "roc_mbox.h"
      18                 :            : #include "roc_sso.h"
      19                 :            : #include "roc_sso_dp.h"
      20                 :            : #include "roc_tim.h"
      21                 :            : 
      22                 :            : #include "cn20k_cryptodev.h"
      23                 :            : #include "cn20k_cryptodev_event_dp.h"
      24                 :            : #include "cn20k_cryptodev_ops.h"
      25                 :            : #include "cn20k_cryptodev_sec.h"
      26                 :            : #include "cn20k_eventdev.h"
      27                 :            : #include "cn20k_ipsec_la_ops.h"
      28                 :            : #include "cn20k_tls_ops.h"
      29                 :            : #include "cnxk_ae.h"
      30                 :            : #include "cnxk_cryptodev.h"
      31                 :            : #include "cnxk_cryptodev_ops.h"
      32                 :            : #include "cnxk_eventdev.h"
      33                 :            : #include "cnxk_se.h"
      34                 :            : 
      35                 :            : #include "rte_pmd_cnxk_crypto.h"
      36                 :            : 
      37                 :            : /* Holds information required to send crypto operations in one burst */
      38                 :            : struct ops_burst {
      39                 :            :         struct rte_crypto_op *op[CN20K_CPT_PKTS_PER_LOOP];
      40                 :            :         uint64_t w2[CN20K_CPT_PKTS_PER_LOOP];
      41                 :            :         struct cn20k_sso_hws *ws;
      42                 :            :         struct cnxk_cpt_qp *qp;
      43                 :            :         uint16_t nb_ops;
      44                 :            : };
      45                 :            : 
      46                 :            : /* Holds information required to send vector of operations */
      47                 :            : struct vec_request {
      48                 :            :         struct cpt_inflight_req *req;
      49                 :            :         struct rte_event_vector *vec;
      50                 :            :         union cpt_inst_w7 w7;
      51                 :            :         uint64_t w2;
      52                 :            : };
      53                 :            : 
      54                 :            : static inline struct cnxk_se_sess *
      55                 :          0 : cn20k_cpt_sym_temp_sess_create(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op)
      56                 :            : {
      57                 :            :         struct rte_crypto_sym_op *sym_op = op->sym;
      58                 :            :         struct rte_cryptodev_sym_session *sess;
      59                 :            :         struct cnxk_se_sess *priv;
      60                 :            :         int ret;
      61                 :            : 
      62                 :            :         /* Create temporary session */
      63   [ #  #  #  # ]:          0 :         if (rte_mempool_get(qp->sess_mp, (void **)&sess) < 0)
      64                 :            :                 return NULL;
      65                 :            : 
      66                 :          0 :         ret = sym_session_configure(qp->lf.roc_cpt, sym_op->xform, sess, true);
      67         [ #  # ]:          0 :         if (ret) {
      68         [ #  # ]:          0 :                 rte_mempool_put(qp->sess_mp, (void *)sess);
      69                 :          0 :                 goto sess_put;
      70                 :            :         }
      71                 :            : 
      72                 :          0 :         priv = (void *)sess;
      73                 :          0 :         sym_op->session = sess;
      74                 :            : 
      75                 :          0 :         return priv;
      76                 :            : 
      77                 :            : sess_put:
      78         [ #  # ]:          0 :         rte_mempool_put(qp->sess_mp, sess);
      79                 :          0 :         return NULL;
      80                 :            : }
      81                 :            : 
      82                 :            : static inline struct cnxk_ae_sess *
      83                 :          0 : cn20k_cpt_asym_temp_sess_create(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op)
      84                 :            : {
      85                 :            :         struct rte_crypto_asym_op *asym_op = op->asym;
      86                 :          0 :         struct roc_cpt *roc_cpt = qp->lf.roc_cpt;
      87                 :            :         struct rte_cryptodev_asym_session *sess;
      88                 :            :         struct cnxk_ae_sess *priv;
      89                 :            :         struct cnxk_cpt_vf *vf;
      90                 :            :         union cpt_inst_w7 w7;
      91                 :            :         struct hw_ctx_s *hwc;
      92                 :            : 
      93                 :            :         /* Create temporary session */
      94   [ #  #  #  # ]:          0 :         if (rte_mempool_get(qp->sess_mp, (void **)&sess) < 0)
      95                 :            :                 return NULL;
      96                 :            : 
      97                 :          0 :         priv = (struct cnxk_ae_sess *)sess;
      98                 :          0 :         if (cnxk_ae_fill_session_parameters(priv, asym_op->xform))
      99                 :          0 :                 goto sess_put;
     100                 :            : 
     101         [ #  # ]:          0 :         priv->lf = &qp->lf;
     102                 :            : 
     103         [ #  # ]:          0 :         if (roc_errata_cpt_hang_on_mixed_ctx_val()) {
     104                 :            :                 hwc = &priv->hw_ctx;
     105                 :          0 :                 hwc->w0.s.aop_valid = 1;
     106                 :          0 :                 hwc->w0.s.ctx_hdr_size = 0;
     107                 :          0 :                 hwc->w0.s.ctx_size = 1;
     108                 :          0 :                 hwc->w0.s.ctx_push_size = 1;
     109                 :            : 
     110                 :            :                 w7.s.ctx_val = 1;
     111                 :            :                 w7.s.cptr = (uint64_t)hwc;
     112                 :            :         }
     113                 :            : 
     114                 :          0 :         w7.u64 = 0;
     115                 :          0 :         w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_AE];
     116                 :            : 
     117                 :          0 :         vf = container_of(roc_cpt, struct cnxk_cpt_vf, cpt);
     118                 :          0 :         priv->cpt_inst_w7 = w7.u64;
     119                 :          0 :         priv->cnxk_fpm_iova = vf->cnxk_fpm_iova;
     120                 :          0 :         priv->ec_grp = vf->ec_grp;
     121                 :            : 
     122                 :          0 :         asym_op->session = sess;
     123                 :            : 
     124                 :          0 :         return priv;
     125                 :            : 
     126                 :            : sess_put:
     127         [ #  # ]:          0 :         rte_mempool_put(qp->sess_mp, sess);
     128                 :          0 :         return NULL;
     129                 :            : }
     130                 :            : 
     131                 :            : static __rte_always_inline int __rte_hot
     132                 :            : cpt_sec_ipsec_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
     133                 :            :                         struct cn20k_sec_session *sess, struct cpt_inst_s *inst,
     134                 :            :                         struct cpt_inflight_req *infl_req)
     135                 :            : {
     136                 :            :         struct rte_crypto_sym_op *sym_op = op->sym;
     137                 :            :         int ret;
     138                 :            : 
     139   [ #  #  #  # ]:          0 :         if (unlikely(sym_op->m_dst && sym_op->m_dst != sym_op->m_src)) {
     140                 :          0 :                 plt_dp_err("Out of place is not supported");
     141                 :          0 :                 return -ENOTSUP;
     142                 :            :         }
     143                 :            : 
     144         [ #  # ]:          0 :         if (sess->ipsec.is_outbound)
     145                 :            :                 ret = process_outb_sa(&qp->lf, op, sess, &qp->meta_info, infl_req, inst);
     146                 :            :         else
     147                 :            :                 ret = process_inb_sa(op, sess, inst, &qp->meta_info, infl_req);
     148                 :            : 
     149                 :            :         return ret;
     150                 :            : }
     151                 :            : 
     152                 :            : static __rte_always_inline int __rte_hot
     153                 :            : cpt_sec_tls_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
     154                 :            :                       struct cn20k_sec_session *sess, struct cpt_inst_s *inst,
     155                 :            :                       struct cpt_inflight_req *infl_req)
     156                 :            : {
     157         [ #  # ]:          0 :         if (sess->tls_opt.is_write)
     158                 :          0 :                 return process_tls_write(&qp->lf, op, sess, &qp->meta_info, infl_req, inst);
     159                 :            :         else
     160                 :          0 :                 return process_tls_read(op, sess, &qp->meta_info, infl_req, inst);
     161                 :            : }
     162                 :            : 
     163                 :            : static __rte_always_inline int __rte_hot
     164                 :            : cpt_sec_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op, struct cn20k_sec_session *sess,
     165                 :            :                   struct cpt_inst_s *inst, struct cpt_inflight_req *infl_req)
     166                 :            : {
     167                 :            : 
     168                 :          0 :         if (sess->proto == RTE_SECURITY_PROTOCOL_IPSEC)
     169                 :            :                 return cpt_sec_ipsec_inst_fill(qp, op, sess, &inst[0], infl_req);
     170         [ #  # ]:          0 :         else if (sess->proto == RTE_SECURITY_PROTOCOL_TLS_RECORD)
     171                 :            :                 return cpt_sec_tls_inst_fill(qp, op, sess, &inst[0], infl_req);
     172                 :            : 
     173                 :            :         return 0;
     174                 :            : }
     175                 :            : 
     176                 :            : static inline int
     177                 :          0 : cn20k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[], struct cpt_inst_s inst[],
     178                 :            :                     struct cpt_inflight_req *infl_req)
     179                 :            : {
     180                 :            :         struct cn20k_sec_session *sec_sess;
     181                 :            :         struct rte_crypto_asym_op *asym_op;
     182                 :            :         struct rte_crypto_sym_op *sym_op;
     183                 :            :         struct cnxk_ae_sess *ae_sess;
     184                 :            :         struct cnxk_se_sess *sess;
     185                 :            :         struct rte_crypto_op *op;
     186                 :            :         uint64_t w7;
     187                 :            :         int ret;
     188                 :            : 
     189                 :            :         const union cpt_res_s res = {
     190                 :            :                 .cn20k.compcode = CPT_COMP_NOT_DONE,
     191                 :            :         };
     192                 :            : 
     193                 :          0 :         op = ops[0];
     194                 :            : 
     195                 :          0 :         inst[0].w0.u64 = 0;
     196                 :          0 :         inst[0].w2.u64 = 0;
     197                 :          0 :         inst[0].w3.u64 = 0;
     198                 :            : 
     199                 :            :         sym_op = op->sym;
     200                 :            : 
     201         [ #  # ]:          0 :         if (op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
     202         [ #  # ]:          0 :                 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
     203         [ #  # ]:          0 :                         sec_sess = (struct cn20k_sec_session *)sym_op->session;
     204                 :            :                         ret = cpt_sec_inst_fill(qp, op, sec_sess, &inst[0], infl_req);
     205         [ #  # ]:          0 :                         if (unlikely(ret))
     206                 :            :                                 return 0;
     207                 :          0 :                         w7 = sec_sess->inst.w7;
     208         [ #  # ]:          0 :                 } else if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
     209         [ #  # ]:          0 :                         sess = (struct cnxk_se_sess *)(sym_op->session);
     210                 :            :                         ret = cpt_sym_inst_fill(qp, op, sess, infl_req, &inst[0], true);
     211         [ #  # ]:          0 :                         if (unlikely(ret))
     212                 :            :                                 return 0;
     213                 :          0 :                         w7 = sess->cpt_inst_w7;
     214                 :            :                 } else {
     215                 :          0 :                         sess = cn20k_cpt_sym_temp_sess_create(qp, op);
     216         [ #  # ]:          0 :                         if (unlikely(sess == NULL)) {
     217                 :          0 :                                 plt_dp_err("Could not create temp session");
     218                 :          0 :                                 return 0;
     219                 :            :                         }
     220                 :            : 
     221                 :            :                         ret = cpt_sym_inst_fill(qp, op, sess, infl_req, &inst[0], true);
     222         [ #  # ]:          0 :                         if (unlikely(ret)) {
     223                 :          0 :                                 sym_session_clear(op->sym->session, true);
     224         [ #  # ]:          0 :                                 rte_mempool_put(qp->sess_mp, op->sym->session);
     225                 :          0 :                                 return 0;
     226                 :            :                         }
     227                 :          0 :                         w7 = sess->cpt_inst_w7;
     228                 :            :                 }
     229         [ #  # ]:          0 :         } else if (op->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
     230         [ #  # ]:          0 :                 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
     231                 :            :                         asym_op = op->asym;
     232         [ #  # ]:          0 :                         ae_sess = (struct cnxk_ae_sess *)asym_op->session;
     233                 :            :                         ret = cnxk_ae_enqueue(qp, op, infl_req, &inst[0], ae_sess);
     234         [ #  # ]:          0 :                         if (unlikely(ret))
     235                 :            :                                 return 0;
     236                 :          0 :                         w7 = ae_sess->cpt_inst_w7;
     237                 :            :                 } else {
     238                 :          0 :                         ae_sess = cn20k_cpt_asym_temp_sess_create(qp, op);
     239         [ #  # ]:          0 :                         if (unlikely(ae_sess == NULL)) {
     240                 :          0 :                                 plt_dp_err("Could not create temp session");
     241                 :          0 :                                 return 0;
     242                 :            :                         }
     243                 :            : 
     244                 :            :                         ret = cnxk_ae_enqueue(qp, op, infl_req, &inst[0], ae_sess);
     245         [ #  # ]:          0 :                         if (unlikely(ret)) {
     246                 :          0 :                                 cnxk_ae_session_clear(NULL,
     247                 :            :                                                       (struct rte_cryptodev_asym_session *)ae_sess);
     248         [ #  # ]:          0 :                                 rte_mempool_put(qp->sess_mp, ae_sess);
     249                 :          0 :                                 return 0;
     250                 :            :                         }
     251                 :          0 :                         w7 = ae_sess->cpt_inst_w7;
     252                 :            :                 }
     253                 :            : 
     254                 :            :         } else {
     255                 :          0 :                 plt_dp_err("Unsupported op type");
     256                 :          0 :                 return 0;
     257                 :            :         }
     258                 :            : 
     259                 :          0 :         inst[0].res_addr = (uint64_t)&infl_req->res;
     260                 :          0 :         rte_atomic_store_explicit((RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]),
     261                 :            :                                 res.u64[0], rte_memory_order_relaxed);
     262                 :          0 :         infl_req->cop = op;
     263                 :            : 
     264                 :          0 :         inst[0].w7.u64 = w7;
     265                 :            : 
     266                 :            : #ifdef CPT_INST_DEBUG_ENABLE
     267                 :            :         infl_req->dptr = (uint8_t *)inst[0].dptr;
     268                 :            :         infl_req->rptr = (uint8_t *)inst[0].rptr;
     269                 :            :         infl_req->scatter_sz = inst[0].w6.s.scatter_sz;
     270                 :            :         infl_req->opcode_major = inst[0].w4.s.opcode_major;
     271                 :            : 
     272                 :            :         rte_hexdump(rte_log_get_stream(), "cptr", (void *)(uint64_t)inst[0].w7.s.cptr, 128);
     273                 :            :         plt_err("major opcode:%d", inst[0].w4.s.opcode_major);
     274                 :            :         plt_err("minor opcode:%d", inst[0].w4.s.opcode_minor);
     275                 :            :         plt_err("param1:%d", inst[0].w4.s.param1);
     276                 :            :         plt_err("param2:%d", inst[0].w4.s.param2);
     277                 :            :         plt_err("dlen:%d", inst[0].w4.s.dlen);
     278                 :            : 
     279                 :            :         cnxk_cpt_request_data_sgv2_mode_dump((void *)inst[0].dptr, 1, inst[0].w5.s.gather_sz);
     280                 :            :         cnxk_cpt_request_data_sgv2_mode_dump((void *)inst[0].rptr, 0, inst[0].w6.s.scatter_sz);
     281                 :            : #endif
     282                 :            : 
     283                 :          0 :         return 1;
     284                 :            : }
     285                 :            : 
     286                 :            : static uint16_t
     287                 :          0 : cn20k_cpt_enqueue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
     288                 :            : {
     289                 :            :         struct cpt_inflight_req *infl_req;
     290                 :            :         uint64_t head, lmt_base, io_addr;
     291                 :            :         uint16_t nb_allowed, count = 0;
     292                 :            :         struct cnxk_cpt_qp *qp = qptr;
     293                 :            :         struct pending_queue *pend_q;
     294                 :            :         struct cpt_inst_s *inst;
     295                 :            :         union cpt_fc_write_s fc;
     296                 :            :         uint64_t *fc_addr;
     297                 :            :         uint16_t lmt_id;
     298                 :            :         int ret, i;
     299                 :            : 
     300                 :            :         pend_q = &qp->pend_q;
     301                 :            : 
     302                 :          0 :         const uint64_t pq_mask = pend_q->pq_mask;
     303                 :            : 
     304                 :          0 :         head = pend_q->head;
     305         [ #  # ]:          0 :         nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
     306                 :          0 :         nb_ops = RTE_MIN(nb_ops, nb_allowed);
     307                 :            : 
     308         [ #  # ]:          0 :         if (unlikely(nb_ops == 0))
     309                 :            :                 return 0;
     310                 :            : 
     311                 :          0 :         lmt_base = qp->lmtline.lmt_base;
     312                 :            :         io_addr = qp->lmtline.io_addr;
     313                 :          0 :         fc_addr = qp->lmtline.fc_addr;
     314                 :            : 
     315                 :          0 :         const uint32_t fc_thresh = qp->lmtline.fc_thresh;
     316                 :            : 
     317                 :            :         ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
     318                 :          0 :         inst = (struct cpt_inst_s *)lmt_base;
     319                 :            : 
     320                 :          0 : again:
     321                 :            :         fc.u64[0] =
     322                 :          0 :                 rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
     323         [ #  # ]:          0 :         if (unlikely(fc.s.qsize > fc_thresh)) {
     324                 :            :                 i = 0;
     325                 :          0 :                 goto pend_q_commit;
     326                 :            :         }
     327                 :            : 
     328         [ #  # ]:          0 :         for (i = 0; i < RTE_MIN(CN20K_CPT_PKTS_PER_LOOP, nb_ops); i++) {
     329                 :          0 :                 infl_req = &pend_q->req_queue[head];
     330                 :          0 :                 infl_req->op_flags = 0;
     331                 :            : 
     332                 :          0 :                 ret = cn20k_cpt_fill_inst(qp, ops + i, &inst[i], infl_req);
     333         [ #  # ]:          0 :                 if (unlikely(ret != 1)) {
     334                 :          0 :                         plt_dp_err("Could not process op: %p", ops + i);
     335         [ #  # ]:          0 :                         if (i == 0)
     336                 :          0 :                                 goto pend_q_commit;
     337                 :            :                         break;
     338                 :            :                 }
     339                 :            : 
     340                 :            :                 pending_queue_advance(&head, pq_mask);
     341                 :            :         }
     342                 :            : 
     343                 :            :         cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
     344                 :            : 
     345   [ #  #  #  # ]:          0 :         if (nb_ops - i > 0 && i == CN20K_CPT_PKTS_PER_LOOP) {
     346                 :          0 :                 nb_ops -= CN20K_CPT_PKTS_PER_LOOP;
     347                 :          0 :                 ops += CN20K_CPT_PKTS_PER_LOOP;
     348                 :          0 :                 count += CN20K_CPT_PKTS_PER_LOOP;
     349                 :          0 :                 goto again;
     350                 :            :         }
     351                 :            : 
     352                 :          0 : pend_q_commit:
     353                 :            :         rte_atomic_thread_fence(rte_memory_order_release);
     354                 :            : 
     355                 :          0 :         pend_q->head = head;
     356                 :          0 :         pend_q->time_out = rte_get_timer_cycles() + DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
     357                 :            : 
     358                 :          0 :         return count + i;
     359                 :            : }
     360                 :            : 
     361                 :            : static int
     362                 :          0 : cn20k_cpt_crypto_adapter_ev_mdata_set(struct rte_cryptodev *dev __rte_unused, void *sess,
     363                 :            :                                       enum rte_crypto_op_type op_type,
     364                 :            :                                       enum rte_crypto_op_sess_type sess_type, void *mdata)
     365                 :            : {
     366                 :            :         union rte_event_crypto_metadata *ec_mdata = mdata;
     367                 :            :         struct rte_event *rsp_info;
     368                 :            :         struct cnxk_cpt_qp *qp;
     369                 :            :         uint64_t w2, tag_type;
     370                 :            :         uint8_t cdev_id;
     371                 :            :         int16_t qp_id;
     372                 :            : 
     373                 :            :         /* Get queue pair */
     374                 :          0 :         cdev_id = ec_mdata->request_info.cdev_id;
     375                 :          0 :         qp_id = ec_mdata->request_info.queue_pair_id;
     376                 :          0 :         qp = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id];
     377                 :            : 
     378         [ #  # ]:          0 :         if (!qp->ca.enabled)
     379                 :            :                 return -EINVAL;
     380                 :            : 
     381                 :            :         /* Prepare w2 */
     382         [ #  # ]:          0 :         tag_type = qp->ca.vector_sz ? RTE_EVENT_TYPE_CRYPTODEV_VECTOR : RTE_EVENT_TYPE_CRYPTODEV;
     383                 :            :         rsp_info = &ec_mdata->response_info;
     384                 :          0 :         w2 = CNXK_CPT_INST_W2((tag_type << 28) | (rsp_info->sub_event_type << 20) |
     385                 :            :                                       rsp_info->flow_id,
     386                 :            :                               rsp_info->sched_type, rsp_info->queue_id, 0);
     387                 :            : 
     388                 :            :         /* Set meta according to session type */
     389         [ #  # ]:          0 :         if (op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
     390         [ #  # ]:          0 :                 if (sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
     391                 :            :                         struct cn20k_sec_session *sec_sess = (struct cn20k_sec_session *)sess;
     392                 :            : 
     393                 :          0 :                         sec_sess->qp = qp;
     394                 :          0 :                         sec_sess->inst.w2 = w2;
     395         [ #  # ]:          0 :                 } else if (sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
     396                 :            :                         struct cnxk_se_sess *priv;
     397                 :            : 
     398                 :            :                         priv = (struct cnxk_se_sess *)sess;
     399                 :          0 :                         priv->qp = qp;
     400                 :          0 :                         priv->cpt_inst_w2 = w2;
     401                 :            :                 } else
     402                 :            :                         return -EINVAL;
     403         [ #  # ]:          0 :         } else if (op_type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
     404         [ #  # ]:          0 :                 if (sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
     405                 :            :                         struct cnxk_ae_sess *priv;
     406                 :            : 
     407                 :            :                         priv = (struct cnxk_ae_sess *)sess;
     408                 :          0 :                         priv->qp = qp;
     409                 :          0 :                         priv->cpt_inst_w2 = w2;
     410                 :            :                 } else
     411                 :            :                         return -EINVAL;
     412                 :            :         } else
     413                 :            :                 return -EINVAL;
     414                 :            : 
     415                 :            :         return 0;
     416                 :            : }
     417                 :            : 
     418                 :            : static inline int
     419                 :          0 : cn20k_ca_meta_info_extract(struct rte_crypto_op *op, struct cnxk_cpt_qp **qp, uint64_t *w2)
     420                 :            : {
     421         [ #  # ]:          0 :         if (op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
     422         [ #  # ]:          0 :                 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
     423                 :            :                         struct cn20k_sec_session *sec_sess;
     424                 :            : 
     425                 :          0 :                         sec_sess = (struct cn20k_sec_session *)op->sym->session;
     426                 :            : 
     427                 :          0 :                         *qp = sec_sess->qp;
     428                 :          0 :                         *w2 = sec_sess->inst.w2;
     429         [ #  # ]:          0 :                 } else if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
     430                 :            :                         struct cnxk_se_sess *priv;
     431                 :            : 
     432                 :          0 :                         priv = (struct cnxk_se_sess *)op->sym->session;
     433                 :          0 :                         *qp = priv->qp;
     434                 :          0 :                         *w2 = priv->cpt_inst_w2;
     435                 :            :                 } else {
     436                 :            :                         union rte_event_crypto_metadata *ec_mdata;
     437                 :            :                         struct rte_event *rsp_info;
     438                 :            :                         uint8_t cdev_id;
     439                 :            :                         uint16_t qp_id;
     440                 :            : 
     441         [ #  # ]:          0 :                         if (unlikely(op->private_data_offset == 0))
     442                 :            :                                 return -EINVAL;
     443                 :          0 :                         ec_mdata = (union rte_event_crypto_metadata *)((uint8_t *)op +
     444                 :          0 :                                                                        op->private_data_offset);
     445                 :            :                         rsp_info = &ec_mdata->response_info;
     446                 :          0 :                         cdev_id = ec_mdata->request_info.cdev_id;
     447                 :          0 :                         qp_id = ec_mdata->request_info.queue_pair_id;
     448                 :          0 :                         *qp = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id];
     449                 :          0 :                         *w2 = CNXK_CPT_INST_W2((RTE_EVENT_TYPE_CRYPTODEV << 28) | rsp_info->flow_id,
     450                 :            :                                                rsp_info->sched_type, rsp_info->queue_id, 0);
     451                 :            :                 }
     452         [ #  # ]:          0 :         } else if (op->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
     453         [ #  # ]:          0 :                 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
     454                 :            :                         struct cnxk_ae_sess *priv;
     455                 :            : 
     456                 :          0 :                         priv = (struct cnxk_ae_sess *)op->asym->session;
     457                 :          0 :                         *qp = priv->qp;
     458                 :          0 :                         *w2 = priv->cpt_inst_w2;
     459                 :            :                 } else {
     460                 :            :                         union rte_event_crypto_metadata *ec_mdata;
     461                 :            :                         struct rte_event *rsp_info;
     462                 :            :                         uint8_t cdev_id;
     463                 :            :                         uint16_t qp_id;
     464                 :            : 
     465         [ #  # ]:          0 :                         if (unlikely(op->private_data_offset == 0))
     466                 :            :                                 return -EINVAL;
     467                 :          0 :                         ec_mdata = (union rte_event_crypto_metadata *)((uint8_t *)op +
     468                 :          0 :                                                                        op->private_data_offset);
     469                 :            :                         rsp_info = &ec_mdata->response_info;
     470                 :          0 :                         cdev_id = ec_mdata->request_info.cdev_id;
     471                 :          0 :                         qp_id = ec_mdata->request_info.queue_pair_id;
     472                 :          0 :                         *qp = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id];
     473                 :          0 :                         *w2 = CNXK_CPT_INST_W2((RTE_EVENT_TYPE_CRYPTODEV << 28) | rsp_info->flow_id,
     474                 :            :                                                rsp_info->sched_type, rsp_info->queue_id, 0);
     475                 :            :                 }
     476                 :            :         } else
     477                 :            :                 return -EINVAL;
     478                 :            : 
     479                 :            :         return 0;
     480                 :            : }
     481                 :            : 
     482                 :            : static inline void
     483                 :          0 : cn20k_cpt_vec_inst_fill(struct vec_request *vec_req, struct cpt_inst_s *inst,
     484                 :            :                         struct cnxk_cpt_qp *qp, union cpt_inst_w7 w7)
     485                 :            : {
     486                 :            :         const union cpt_res_s res = {.cn20k.compcode = CPT_COMP_NOT_DONE};
     487                 :          0 :         struct cpt_inflight_req *infl_req = vec_req->req;
     488                 :            : 
     489                 :            :         const union cpt_inst_w4 w4 = {
     490                 :            :                 .s.opcode_major = ROC_SE_MAJOR_OP_MISC,
     491                 :            :                 .s.opcode_minor = ROC_SE_MISC_MINOR_OP_PASSTHROUGH,
     492                 :            :                 .s.param1 = 1,
     493                 :            :                 .s.param2 = 1,
     494                 :            :                 .s.dlen = 0,
     495                 :            :         };
     496                 :            : 
     497                 :          0 :         w7.s.egrp = ROC_CPT_DFLT_ENG_GRP_SE;
     498                 :            : 
     499                 :          0 :         infl_req->vec = vec_req->vec;
     500                 :          0 :         infl_req->qp = qp;
     501                 :            : 
     502                 :          0 :         inst->res_addr = (uint64_t)&infl_req->res;
     503                 :          0 :         rte_atomic_store_explicit((RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), res.u64[0],
     504                 :            :                                   rte_memory_order_relaxed);
     505                 :            : 
     506                 :          0 :         inst->w0.u64 = 0;
     507                 :          0 :         inst->w2.u64 = vec_req->w2;
     508                 :          0 :         inst->w3.u64 = CNXK_CPT_INST_W3(1, infl_req);
     509                 :          0 :         inst->w4.u64 = w4.u64;
     510                 :          0 :         inst->w5.u64 = 0;
     511                 :          0 :         inst->w6.u64 = 0;
     512                 :          0 :         inst->w7.u64 = w7.u64;
     513                 :          0 : }
     514                 :            : 
     515                 :            : static void
     516                 :          0 : cn20k_cpt_vec_pkt_submission_timeout_handle(void)
     517                 :            : {
     518                 :          0 :         plt_dp_err("Vector packet submission timedout");
     519                 :          0 :         abort();
     520                 :            : }
     521                 :            : 
     522                 :            : static inline void
     523                 :          0 : cn20k_cpt_vec_submit(struct vec_request vec_tbl[], uint16_t vec_tbl_len, struct cnxk_cpt_qp *qp)
     524                 :            : {
     525                 :            :         uint64_t lmt_base, lmt_id, io_addr;
     526                 :            :         union cpt_fc_write_s fc;
     527                 :            :         struct cpt_inst_s *inst;
     528                 :            :         uint16_t burst_size;
     529                 :            :         uint64_t *fc_addr;
     530                 :            :         int i;
     531                 :            : 
     532         [ #  # ]:          0 :         if (vec_tbl_len == 0)
     533                 :            :                 return;
     534                 :            : 
     535                 :          0 :         const uint32_t fc_thresh = qp->lmtline.fc_thresh;
     536                 :            :         /*
     537                 :            :          * Use 10 mins timeout for the poll. It is not possible to recover from partial submission
     538                 :            :          * of vector packet. Actual packets for processing are submitted to CPT prior to this
     539                 :            :          * routine. Hence, any failure for submission of vector packet would indicate an
     540                 :            :          * unrecoverable error for the application.
     541                 :            :          */
     542                 :          0 :         const uint64_t timeout = rte_get_timer_cycles() + 10 * 60 * rte_get_timer_hz();
     543                 :            : 
     544                 :          0 :         lmt_base = qp->lmtline.lmt_base;
     545                 :            :         io_addr = qp->lmtline.io_addr;
     546                 :          0 :         fc_addr = qp->lmtline.fc_addr;
     547                 :            :         ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
     548                 :          0 :         inst = (struct cpt_inst_s *)lmt_base;
     549                 :            : 
     550                 :          0 : again:
     551                 :          0 :         burst_size = RTE_MIN(CN20K_PKTS_PER_STEORL, vec_tbl_len);
     552         [ #  # ]:          0 :         for (i = 0; i < burst_size; i++)
     553                 :          0 :                 cn20k_cpt_vec_inst_fill(&vec_tbl[i], &inst[i], qp, vec_tbl[0].w7);
     554                 :            : 
     555                 :            :         do {
     556                 :          0 :                 fc.u64[0] = rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr,
     557                 :            :                                                      rte_memory_order_relaxed);
     558         [ #  # ]:          0 :                 if (likely(fc.s.qsize < fc_thresh))
     559                 :            :                         break;
     560         [ #  # ]:          0 :                 if (unlikely(rte_get_timer_cycles() > timeout))
     561                 :          0 :                         cn20k_cpt_vec_pkt_submission_timeout_handle();
     562                 :            :         } while (true);
     563                 :            : 
     564                 :            :         cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
     565                 :            : 
     566                 :          0 :         vec_tbl_len -= i;
     567                 :            : 
     568         [ #  # ]:          0 :         if (vec_tbl_len > 0) {
     569                 :          0 :                 vec_tbl += i;
     570                 :          0 :                 goto again;
     571                 :            :         }
     572                 :            : }
     573                 :            : 
     574                 :            : static inline int
     575                 :          0 : ca_lmtst_vec_submit(struct ops_burst *burst, struct vec_request vec_tbl[], uint16_t *vec_tbl_len)
     576                 :            : {
     577                 :            :         struct cpt_inflight_req *infl_reqs[CN20K_CPT_PKTS_PER_LOOP];
     578                 :          0 :         uint16_t lmt_id, len = *vec_tbl_len;
     579                 :            :         struct cpt_inst_s *inst, *inst_base;
     580                 :            :         struct cpt_inflight_req *infl_req;
     581                 :            :         struct rte_event_vector *vec;
     582                 :            :         uint64_t lmt_base, io_addr;
     583                 :            :         union cpt_fc_write_s fc;
     584                 :            :         struct cnxk_cpt_qp *qp;
     585                 :            :         uint64_t *fc_addr;
     586                 :            :         int ret, i, vi;
     587                 :            : 
     588                 :          0 :         qp = burst->qp;
     589                 :            : 
     590                 :          0 :         lmt_base = qp->lmtline.lmt_base;
     591                 :            :         io_addr = qp->lmtline.io_addr;
     592                 :          0 :         fc_addr = qp->lmtline.fc_addr;
     593                 :            : 
     594                 :          0 :         const uint32_t fc_thresh = qp->lmtline.fc_thresh;
     595                 :            : 
     596                 :            :         ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
     597                 :          0 :         inst_base = (struct cpt_inst_s *)lmt_base;
     598                 :            : 
     599                 :            : #ifdef CNXK_CRYPTODEV_DEBUG
     600                 :            :         if (unlikely(!qp->ca.enabled)) {
     601                 :            :                 rte_errno = EINVAL;
     602                 :            :                 return 0;
     603                 :            :         }
     604                 :            : #endif
     605                 :            : 
     606                 :            :         /* Perform fc check before putting packets into vectors */
     607                 :            :         fc.u64[0] =
     608                 :          0 :                 rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
     609         [ #  # ]:          0 :         if (unlikely(fc.s.qsize > fc_thresh)) {
     610                 :          0 :                 rte_errno = EAGAIN;
     611                 :          0 :                 return 0;
     612                 :            :         }
     613                 :            : 
     614   [ #  #  #  # ]:          0 :         if (unlikely(rte_mempool_get_bulk(qp->ca.req_mp, (void **)infl_reqs, burst->nb_ops))) {
     615                 :          0 :                 rte_errno = ENOMEM;
     616                 :          0 :                 return 0;
     617                 :            :         }
     618                 :            : 
     619         [ #  # ]:          0 :         for (i = 0; i < burst->nb_ops; i++) {
     620                 :          0 :                 inst = &inst_base[i];
     621                 :          0 :                 infl_req = infl_reqs[i];
     622                 :          0 :                 infl_req->op_flags = 0;
     623                 :            : 
     624                 :          0 :                 ret = cn20k_cpt_fill_inst(qp, &burst->op[i], inst, infl_req);
     625         [ #  # ]:          0 :                 if (unlikely(ret != 1)) {
     626                 :          0 :                         plt_cpt_dbg("Could not process op: %p", burst->op[i]);
     627         [ #  # ]:          0 :                         if (i != 0)
     628                 :          0 :                                 goto submit;
     629                 :            :                         else
     630                 :          0 :                                 goto put;
     631                 :            :                 }
     632                 :            : 
     633                 :          0 :                 infl_req->res.cn20k.compcode = CPT_COMP_NOT_DONE;
     634                 :          0 :                 infl_req->qp = qp;
     635                 :          0 :                 inst->w3.u64 = 0x1;
     636                 :            : 
     637                 :            :                 /* Lookup for existing vector by w2 */
     638         [ #  # ]:          0 :                 for (vi = len - 1; vi >= 0; vi--) {
     639         [ #  # ]:          0 :                         if (vec_tbl[vi].w2 != burst->w2[i])
     640                 :          0 :                                 continue;
     641                 :          0 :                         vec = vec_tbl[vi].vec;
     642         [ #  # ]:          0 :                         if (unlikely(vec->nb_elem == qp->ca.vector_sz))
     643                 :          0 :                                 continue;
     644                 :          0 :                         vec->ptrs[vec->nb_elem++] = infl_req;
     645                 :          0 :                         goto next_op; /* continue outer loop */
     646                 :            :                 }
     647                 :            : 
     648                 :            :                 /* No available vectors found, allocate a new one */
     649   [ #  #  #  # ]:          0 :                 if (unlikely(rte_mempool_get(qp->ca.vector_mp, (void **)&vec_tbl[len].vec))) {
     650                 :          0 :                         rte_errno = ENOMEM;
     651         [ #  # ]:          0 :                         if (i != 0)
     652                 :          0 :                                 goto submit;
     653                 :            :                         else
     654                 :          0 :                                 goto put;
     655                 :            :                 }
     656                 :            :                 /* Also preallocate in-flight request, that will be used to
     657                 :            :                  * submit misc passthrough instruction
     658                 :            :                  */
     659   [ #  #  #  # ]:          0 :                 if (unlikely(rte_mempool_get(qp->ca.req_mp, (void **)&vec_tbl[len].req))) {
     660         [ #  # ]:          0 :                         rte_mempool_put(qp->ca.vector_mp, vec_tbl[len].vec);
     661                 :          0 :                         rte_errno = ENOMEM;
     662         [ #  # ]:          0 :                         if (i != 0)
     663                 :          0 :                                 goto submit;
     664                 :            :                         else
     665                 :          0 :                                 goto put;
     666                 :            :                 }
     667                 :          0 :                 vec_tbl[len].w2 = burst->w2[i];
     668                 :          0 :                 vec_tbl[len].vec->ptrs[0] = infl_req;
     669                 :          0 :                 vec_tbl[len].vec->nb_elem = 1;
     670                 :          0 :                 len++;
     671                 :            : 
     672                 :          0 : next_op:;
     673                 :            :         }
     674                 :            : 
     675                 :            :         /* Submit operations in burst */
     676                 :          0 : submit:
     677         [ #  # ]:          0 :         if (CNXK_TT_FROM_TAG(burst->ws->gw_rdata) == SSO_TT_ORDERED)
     678                 :          0 :                 roc_sso_hws_head_wait(burst->ws->base);
     679                 :            : 
     680                 :            :         cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
     681                 :            : 
     682                 :            :         /* Store w7 of last successfully filled instruction */
     683                 :          0 :         inst = &inst_base[2 * (i - 1)];
     684                 :          0 :         vec_tbl[0].w7 = inst->w7;
     685                 :            : 
     686                 :          0 : put:
     687         [ #  # ]:          0 :         if (i != burst->nb_ops)
     688         [ #  # ]:          0 :                 rte_mempool_put_bulk(qp->ca.req_mp, (void *)&infl_reqs[i], burst->nb_ops - i);
     689                 :            : 
     690                 :          0 :         *vec_tbl_len = len;
     691                 :            : 
     692                 :          0 :         return i;
     693                 :            : }
     694                 :            : 
     695                 :            : static inline uint16_t
     696                 :          0 : ca_lmtst_burst_submit(struct ops_burst *burst)
     697                 :            : {
     698                 :            :         struct cpt_inflight_req *infl_reqs[CN20K_CPT_PKTS_PER_LOOP];
     699                 :            :         struct cpt_inst_s *inst, *inst_base;
     700                 :            :         struct cpt_inflight_req *infl_req;
     701                 :            :         uint64_t lmt_base, io_addr;
     702                 :            :         union cpt_fc_write_s fc;
     703                 :            :         struct cnxk_cpt_qp *qp;
     704                 :            :         uint64_t *fc_addr;
     705                 :            :         uint16_t lmt_id;
     706                 :            :         int ret, i, j;
     707                 :            : 
     708                 :          0 :         qp = burst->qp;
     709                 :            : 
     710                 :          0 :         lmt_base = qp->lmtline.lmt_base;
     711                 :            :         io_addr = qp->lmtline.io_addr;
     712                 :          0 :         fc_addr = qp->lmtline.fc_addr;
     713                 :            : 
     714                 :          0 :         const uint32_t fc_thresh = qp->lmtline.fc_thresh;
     715                 :            : 
     716                 :            :         ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
     717                 :          0 :         inst_base = (struct cpt_inst_s *)lmt_base;
     718                 :            : 
     719                 :            : #ifdef CNXK_CRYPTODEV_DEBUG
     720                 :            :         if (unlikely(!qp->ca.enabled)) {
     721                 :            :                 rte_errno = EINVAL;
     722                 :            :                 return 0;
     723                 :            :         }
     724                 :            : #endif
     725                 :            : 
     726   [ #  #  #  # ]:          0 :         if (unlikely(rte_mempool_get_bulk(qp->ca.req_mp, (void **)infl_reqs, burst->nb_ops))) {
     727                 :          0 :                 rte_errno = ENOMEM;
     728                 :          0 :                 return 0;
     729                 :            :         }
     730                 :            : 
     731         [ #  # ]:          0 :         for (i = 0; i < burst->nb_ops; i++) {
     732                 :          0 :                 inst = &inst_base[i];
     733                 :          0 :                 infl_req = infl_reqs[i];
     734                 :          0 :                 infl_req->op_flags = 0;
     735                 :            : 
     736                 :          0 :                 ret = cn20k_cpt_fill_inst(qp, &burst->op[i], inst, infl_req);
     737         [ #  # ]:          0 :                 if (unlikely(ret != 1)) {
     738                 :            :                         plt_dp_dbg("Could not process op: %p", burst->op[i]);
     739         [ #  # ]:          0 :                         if (i != 0)
     740                 :          0 :                                 goto submit;
     741                 :            :                         else
     742                 :          0 :                                 goto put;
     743                 :            :                 }
     744                 :            : 
     745                 :          0 :                 infl_req->res.cn20k.compcode = CPT_COMP_NOT_DONE;
     746                 :          0 :                 infl_req->qp = qp;
     747                 :          0 :                 inst->w0.u64 = 0;
     748                 :          0 :                 inst->res_addr = (uint64_t)&infl_req->res;
     749                 :          0 :                 inst->w2.u64 = burst->w2[i];
     750                 :          0 :                 inst->w3.u64 = CNXK_CPT_INST_W3(1, infl_req);
     751                 :            :         }
     752                 :            : 
     753                 :            :         fc.u64[0] =
     754                 :          0 :                 rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
     755         [ #  # ]:          0 :         if (unlikely(fc.s.qsize > fc_thresh)) {
     756                 :          0 :                 rte_errno = EAGAIN;
     757         [ #  # ]:          0 :                 for (j = 0; j < i; j++) {
     758                 :          0 :                         infl_req = infl_reqs[j];
     759         [ #  # ]:          0 :                         if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
     760         [ #  # ]:          0 :                                 rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
     761                 :            :                 }
     762                 :            :                 i = 0;
     763                 :          0 :                 goto put;
     764                 :            :         }
     765                 :            : 
     766                 :          0 : submit:
     767         [ #  # ]:          0 :         if (CNXK_TT_FROM_TAG(burst->ws->gw_rdata) == SSO_TT_ORDERED)
     768                 :          0 :                 roc_sso_hws_head_wait(burst->ws->base);
     769                 :            : 
     770                 :            :         cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
     771                 :            : 
     772                 :          0 : put:
     773         [ #  # ]:          0 :         if (unlikely(i != burst->nb_ops))
     774         [ #  # ]:          0 :                 rte_mempool_put_bulk(qp->ca.req_mp, (void *)&infl_reqs[i], burst->nb_ops - i);
     775                 :            : 
     776                 :          0 :         return i;
     777                 :            : }
     778                 :            : 
     779                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cpt_crypto_adapter_enqueue)
     780                 :            : uint16_t __rte_hot
     781                 :          0 : cn20k_cpt_crypto_adapter_enqueue(void *ws, struct rte_event ev[], uint16_t nb_events)
     782                 :          0 : {
     783                 :          0 :         uint16_t submitted, count = 0, vec_tbl_len = 0;
     784                 :          0 :         struct vec_request vec_tbl[nb_events];
     785                 :            :         struct rte_crypto_op *op;
     786                 :            :         struct ops_burst burst;
     787                 :            :         struct cnxk_cpt_qp *qp;
     788                 :            :         bool is_vector = false;
     789                 :            :         uint64_t w2;
     790                 :            :         int ret, i;
     791                 :            : 
     792                 :          0 :         burst.ws = ws;
     793                 :          0 :         burst.qp = NULL;
     794                 :          0 :         burst.nb_ops = 0;
     795                 :            : 
     796         [ #  # ]:          0 :         for (i = 0; i < nb_events; i++) {
     797                 :          0 :                 op = ev[i].event_ptr;
     798                 :          0 :                 ret = cn20k_ca_meta_info_extract(op, &qp, &w2);
     799         [ #  # ]:          0 :                 if (unlikely(ret)) {
     800                 :          0 :                         rte_errno = EINVAL;
     801                 :          0 :                         goto vec_submit;
     802                 :            :                 }
     803                 :            : 
     804                 :            :                 /* Queue pair change check */
     805         [ #  # ]:          0 :                 if (qp != burst.qp) {
     806         [ #  # ]:          0 :                         if (burst.nb_ops) {
     807         [ #  # ]:          0 :                                 if (is_vector) {
     808                 :          0 :                                         submitted =
     809                 :          0 :                                                 ca_lmtst_vec_submit(&burst, vec_tbl, &vec_tbl_len);
     810                 :            :                                         /*
     811                 :            :                                          * Vector submission is required on qp change, but not in
     812                 :            :                                          * other cases, since we could send several vectors per
     813                 :            :                                          * lmtst instruction only for same qp
     814                 :            :                                          */
     815                 :          0 :                                         cn20k_cpt_vec_submit(vec_tbl, vec_tbl_len, burst.qp);
     816                 :          0 :                                         vec_tbl_len = 0;
     817                 :            :                                 } else {
     818                 :          0 :                                         submitted = ca_lmtst_burst_submit(&burst);
     819                 :            :                                 }
     820                 :          0 :                                 count += submitted;
     821         [ #  # ]:          0 :                                 if (unlikely(submitted != burst.nb_ops))
     822                 :          0 :                                         goto vec_submit;
     823                 :          0 :                                 burst.nb_ops = 0;
     824                 :            :                         }
     825                 :          0 :                         is_vector = qp->ca.vector_sz;
     826                 :          0 :                         burst.qp = qp;
     827                 :            :                 }
     828                 :          0 :                 burst.w2[burst.nb_ops] = w2;
     829                 :          0 :                 burst.op[burst.nb_ops] = op;
     830                 :            : 
     831                 :            :                 /* Max nb_ops per burst check */
     832         [ #  # ]:          0 :                 if (++burst.nb_ops == CN20K_CPT_PKTS_PER_LOOP) {
     833         [ #  # ]:          0 :                         if (is_vector)
     834                 :          0 :                                 submitted = ca_lmtst_vec_submit(&burst, vec_tbl, &vec_tbl_len);
     835                 :            :                         else
     836                 :          0 :                                 submitted = ca_lmtst_burst_submit(&burst);
     837                 :          0 :                         count += submitted;
     838         [ #  # ]:          0 :                         if (unlikely(submitted != burst.nb_ops))
     839                 :          0 :                                 goto vec_submit;
     840                 :          0 :                         burst.nb_ops = 0;
     841                 :            :                 }
     842                 :            :         }
     843                 :            :         /* Submit the rest of crypto operations */
     844         [ #  # ]:          0 :         if (burst.nb_ops) {
     845         [ #  # ]:          0 :                 if (is_vector)
     846                 :          0 :                         count += ca_lmtst_vec_submit(&burst, vec_tbl, &vec_tbl_len);
     847                 :            :                 else
     848                 :          0 :                         count += ca_lmtst_burst_submit(&burst);
     849                 :            :         }
     850                 :            : 
     851                 :          0 : vec_submit:
     852                 :          0 :         cn20k_cpt_vec_submit(vec_tbl, vec_tbl_len, burst.qp);
     853                 :          0 :         return count;
     854                 :            : }
     855                 :            : 
     856                 :            : static inline void
     857                 :          0 : cn20k_cpt_ipsec_post_process(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res)
     858                 :            : {
     859                 :          0 :         struct rte_mbuf *mbuf = cop->sym->m_src;
     860                 :          0 :         const uint16_t m_len = res->rlen;
     861                 :            : 
     862   [ #  #  #  #  :          0 :         switch (res->uc_compcode) {
                   #  # ]
     863                 :          0 :         case ROC_IE_OW_UCC_SUCCESS_PKT_IP_BADCSUM:
     864                 :          0 :                 mbuf->ol_flags &= ~RTE_MBUF_F_RX_IP_CKSUM_GOOD;
     865                 :          0 :                 mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
     866                 :          0 :                 break;
     867                 :          0 :         case ROC_IE_OW_UCC_SUCCESS_PKT_L4_GOODCSUM:
     868                 :          0 :                 mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD | RTE_MBUF_F_RX_IP_CKSUM_GOOD;
     869                 :          0 :                 break;
     870                 :          0 :         case ROC_IE_OW_UCC_SUCCESS_PKT_L4_BADCSUM:
     871                 :          0 :                 mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD | RTE_MBUF_F_RX_IP_CKSUM_GOOD;
     872                 :          0 :                 break;
     873                 :            :         case ROC_IE_OW_UCC_SUCCESS_PKT_IP_GOODCSUM:
     874                 :            :                 break;
     875                 :          0 :         case ROC_IE_OW_UCC_SUCCESS_SA_SOFTEXP_FIRST:
     876                 :            :         case ROC_IE_OW_UCC_SUCCESS_SA_SOFTEXP_AGAIN:
     877                 :          0 :                 cop->aux_flags = RTE_CRYPTO_OP_AUX_FLAGS_IPSEC_SOFT_EXPIRY;
     878                 :          0 :                 break;
     879                 :          0 :         default:
     880                 :          0 :                 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
     881                 :          0 :                 cop->aux_flags = res->uc_compcode;
     882                 :          0 :                 return;
     883                 :            :         }
     884                 :            : 
     885         [ #  # ]:          0 :         if (mbuf->next == NULL)
     886                 :          0 :                 mbuf->data_len = m_len;
     887                 :            : 
     888                 :          0 :         mbuf->pkt_len = m_len;
     889                 :            : }
     890                 :            : 
     891                 :            : static inline void
     892                 :          0 : cn20k_cpt_tls12_trim_mac(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res, uint8_t mac_len)
     893                 :            : {
     894                 :            :         struct rte_mbuf *mac_prev_seg = NULL, *mac_seg = NULL, *seg;
     895                 :            :         uint32_t pad_len, trim_len, mac_offset, pad_offset;
     896                 :          0 :         struct rte_mbuf *mbuf = cop->sym->m_src;
     897                 :          0 :         uint16_t m_len = res->rlen;
     898                 :            :         uint32_t i, nb_segs = 1;
     899                 :            :         uint8_t pad_res = 0;
     900                 :            :         uint8_t pad_val;
     901                 :            : 
     902                 :          0 :         pad_val = ((res->spi >> 16) & 0xff);
     903                 :          0 :         pad_len = pad_val + 1;
     904                 :          0 :         trim_len = pad_len + mac_len;
     905                 :          0 :         mac_offset = m_len - trim_len;
     906                 :          0 :         pad_offset = mac_offset + mac_len;
     907                 :            : 
     908                 :            :         /* Handle Direct Mode */
     909         [ #  # ]:          0 :         if (mbuf->next == NULL) {
     910                 :          0 :                 uint8_t *ptr = rte_pktmbuf_mtod_offset(mbuf, uint8_t *, pad_offset);
     911                 :            : 
     912         [ #  # ]:          0 :                 for (i = 0; i < pad_len; i++)
     913                 :          0 :                         pad_res |= ptr[i] ^ pad_val;
     914                 :            : 
     915         [ #  # ]:          0 :                 if (pad_res) {
     916                 :          0 :                         cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
     917                 :          0 :                         cop->aux_flags = res->uc_compcode;
     918                 :            :                 }
     919                 :          0 :                 mbuf->pkt_len = m_len - trim_len;
     920                 :          0 :                 mbuf->data_len = m_len - trim_len;
     921                 :            : 
     922                 :          0 :                 return;
     923                 :            :         }
     924                 :            : 
     925                 :            :         /* Handle SG mode */
     926                 :            :         seg = mbuf;
     927         [ #  # ]:          0 :         while (mac_offset >= seg->data_len) {
     928                 :          0 :                 mac_offset -= seg->data_len;
     929                 :            :                 mac_prev_seg = seg;
     930                 :          0 :                 seg = seg->next;
     931                 :          0 :                 nb_segs++;
     932                 :            :         }
     933                 :            :         mac_seg = seg;
     934                 :            : 
     935                 :          0 :         pad_offset = mac_offset + mac_len;
     936         [ #  # ]:          0 :         while (pad_offset >= seg->data_len) {
     937                 :          0 :                 pad_offset -= seg->data_len;
     938                 :          0 :                 seg = seg->next;
     939                 :            :         }
     940                 :            : 
     941         [ #  # ]:          0 :         while (pad_len != 0) {
     942                 :          0 :                 uint8_t *ptr = rte_pktmbuf_mtod_offset(seg, uint8_t *, pad_offset);
     943                 :          0 :                 uint8_t len = RTE_MIN(seg->data_len - pad_offset, pad_len);
     944                 :            : 
     945         [ #  # ]:          0 :                 for (i = 0; i < len; i++)
     946                 :          0 :                         pad_res |= ptr[i] ^ pad_val;
     947                 :            : 
     948                 :            :                 pad_offset = 0;
     949                 :          0 :                 pad_len -= len;
     950                 :          0 :                 seg = seg->next;
     951                 :            :         }
     952                 :            : 
     953         [ #  # ]:          0 :         if (pad_res) {
     954                 :          0 :                 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
     955                 :          0 :                 cop->aux_flags = res->uc_compcode;
     956                 :            :         }
     957                 :            : 
     958                 :          0 :         mbuf->pkt_len = m_len - trim_len;
     959         [ #  # ]:          0 :         if (mac_offset) {
     960                 :          0 :                 rte_pktmbuf_free(mac_seg->next);
     961                 :          0 :                 mac_seg->next = NULL;
     962                 :          0 :                 mac_seg->data_len = mac_offset;
     963                 :          0 :                 mbuf->nb_segs = nb_segs;
     964                 :            :         } else {
     965                 :          0 :                 rte_pktmbuf_free(mac_seg);
     966                 :          0 :                 mac_prev_seg->next = NULL;
     967                 :          0 :                 mbuf->nb_segs = nb_segs - 1;
     968                 :            :         }
     969                 :            : }
     970                 :            : 
     971                 :            : /* TLS-1.3:
     972                 :            :  * Read from last until a non-zero value is encountered.
     973                 :            :  * Return the non zero value as the content type.
     974                 :            :  * Remove the MAC and content type and padding bytes.
     975                 :            :  */
     976                 :            : static inline void
     977                 :          0 : cn20k_cpt_tls13_trim_mac(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res)
     978                 :            : {
     979                 :          0 :         struct rte_mbuf *mbuf = cop->sym->m_src;
     980                 :            :         struct rte_mbuf *seg = mbuf;
     981                 :          0 :         uint16_t m_len = res->rlen;
     982                 :            :         uint8_t *ptr, type = 0x0;
     983                 :            :         int len, i, nb_segs = 1;
     984                 :            : 
     985         [ #  # ]:          0 :         while (m_len && !type) {
     986                 :          0 :                 len = m_len;
     987                 :            :                 seg = mbuf;
     988                 :            : 
     989                 :            :                 /* get the last seg */
     990         [ #  # ]:          0 :                 while (len > seg->data_len) {
     991                 :          0 :                         len -= seg->data_len;
     992                 :          0 :                         seg = seg->next;
     993                 :          0 :                         nb_segs++;
     994                 :            :                 }
     995                 :            : 
     996                 :            :                 /* walkthrough from last until a non zero value is found */
     997                 :          0 :                 ptr = rte_pktmbuf_mtod(seg, uint8_t *);
     998                 :            :                 i = len;
     999   [ #  #  #  # ]:          0 :                 while (i && (ptr[--i] == 0))
    1000                 :            :                         ;
    1001                 :            : 
    1002                 :          0 :                 type = ptr[i];
    1003                 :          0 :                 m_len -= len;
    1004                 :            :         }
    1005                 :            : 
    1006         [ #  # ]:          0 :         if (type) {
    1007                 :          0 :                 cop->param1.tls_record.content_type = type;
    1008                 :          0 :                 mbuf->pkt_len = m_len + i;
    1009                 :          0 :                 mbuf->nb_segs = nb_segs;
    1010                 :          0 :                 seg->data_len = i;
    1011                 :          0 :                 rte_pktmbuf_free(seg->next);
    1012                 :          0 :                 seg->next = NULL;
    1013                 :            :         } else {
    1014                 :          0 :                 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
    1015                 :            :         }
    1016                 :          0 : }
    1017                 :            : 
    1018                 :            : static inline void
    1019                 :          0 : cn20k_cpt_tls_post_process(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res,
    1020                 :            :                            struct cn20k_sec_session *sess)
    1021                 :            : {
    1022                 :          0 :         struct cn20k_tls_opt tls_opt = sess->tls_opt;
    1023                 :          0 :         struct rte_mbuf *mbuf = cop->sym->m_src;
    1024                 :          0 :         uint16_t m_len = res->rlen;
    1025                 :            : 
    1026         [ #  # ]:          0 :         if (!res->uc_compcode) {
    1027         [ #  # ]:          0 :                 if (mbuf->next == NULL)
    1028                 :          0 :                         mbuf->data_len = m_len;
    1029                 :          0 :                 mbuf->pkt_len = m_len;
    1030                 :          0 :                 cop->param1.tls_record.content_type = (res->spi >> 24) & 0xff;
    1031                 :          0 :                 return;
    1032                 :            :         }
    1033                 :            : 
    1034                 :            :         /* Any error other than post process */
    1035         [ #  # ]:          0 :         if (res->uc_compcode != ROC_SE_ERR_SSL_POST_PROCESS) {
    1036                 :          0 :                 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
    1037                 :          0 :                 cop->aux_flags = res->uc_compcode;
    1038                 :          0 :                 plt_err("crypto op failed with UC compcode: 0x%x", res->uc_compcode);
    1039                 :          0 :                 return;
    1040                 :            :         }
    1041                 :            : 
    1042                 :            :         /* Extra padding scenario: Verify padding. Remove padding and MAC */
    1043         [ #  # ]:          0 :         if (tls_opt.tls_ver != RTE_SECURITY_VERSION_TLS_1_3)
    1044                 :          0 :                 cn20k_cpt_tls12_trim_mac(cop, res, (uint8_t)tls_opt.mac_len);
    1045                 :            :         else
    1046                 :          0 :                 cn20k_cpt_tls13_trim_mac(cop, res);
    1047                 :            : }
    1048                 :            : 
    1049                 :            : static inline void
    1050                 :          0 : cn20k_cpt_sec_post_process(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res)
    1051                 :            : {
    1052                 :            :         struct rte_crypto_sym_op *sym_op = cop->sym;
    1053                 :            :         struct cn20k_sec_session *sess;
    1054                 :            : 
    1055                 :          0 :         sess = sym_op->session;
    1056         [ #  # ]:          0 :         if (sess->proto == RTE_SECURITY_PROTOCOL_IPSEC)
    1057                 :          0 :                 cn20k_cpt_ipsec_post_process(cop, res);
    1058         [ #  # ]:          0 :         else if (sess->proto == RTE_SECURITY_PROTOCOL_TLS_RECORD)
    1059                 :          0 :                 cn20k_cpt_tls_post_process(cop, res, sess);
    1060                 :          0 : }
    1061                 :            : 
    1062                 :            : static inline void
    1063                 :          0 : cn20k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp, struct rte_crypto_op *cop,
    1064                 :            :                                struct cpt_inflight_req *infl_req, struct cpt_cn20k_res_s *res)
    1065                 :            : {
    1066                 :          0 :         const uint8_t uc_compcode = res->uc_compcode;
    1067                 :          0 :         const uint8_t compcode = res->compcode;
    1068                 :            : 
    1069                 :          0 :         cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
    1070                 :            : 
    1071         [ #  # ]:          0 :         if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
    1072                 :            :             cop->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
    1073         [ #  # ]:          0 :                 if (likely(compcode == CPT_COMP_GOOD || compcode == CPT_COMP_WARN)) {
    1074                 :            :                         /* Success with additional info */
    1075                 :          0 :                         cn20k_cpt_sec_post_process(cop, res);
    1076                 :            :                 } else {
    1077                 :          0 :                         cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
    1078                 :          0 :                         plt_dp_info("HW completion code 0x%x", res->compcode);
    1079         [ #  # ]:          0 :                         if (compcode == CPT_COMP_GOOD) {
    1080                 :          0 :                                 plt_dp_info("Request failed with microcode error");
    1081                 :          0 :                                 plt_dp_info("MC completion code 0x%x", uc_compcode);
    1082                 :            :                         }
    1083                 :            :                 }
    1084                 :            : 
    1085                 :          0 :                 return;
    1086         [ #  # ]:          0 :         } else if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC &&
    1087                 :            :                    cop->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
    1088                 :            :                 struct cnxk_ae_sess *sess;
    1089                 :            : 
    1090                 :          0 :                 sess = (struct cnxk_ae_sess *)cop->asym->session;
    1091         [ #  # ]:          0 :                 if (sess->xfrm_type == RTE_CRYPTO_ASYM_XFORM_ECDH &&
    1092         [ #  # ]:          0 :                     cop->asym->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY) {
    1093         [ #  # ]:          0 :                         if (likely(compcode == CPT_COMP_GOOD)) {
    1094         [ #  # ]:          0 :                                 if (uc_compcode == ROC_AE_ERR_ECC_POINT_NOT_ON_CURVE) {
    1095                 :          0 :                                         cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
    1096                 :          0 :                                         return;
    1097         [ #  # ]:          0 :                                 } else if (uc_compcode == ROC_AE_ERR_ECC_PAI) {
    1098                 :            :                                         cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
    1099                 :            :                                         return;
    1100                 :            :                                 }
    1101                 :            :                         }
    1102                 :            :                 }
    1103                 :            :         }
    1104                 :            : 
    1105         [ #  # ]:          0 :         if (likely(compcode == CPT_COMP_GOOD)) {
    1106                 :            : #ifdef CPT_INST_DEBUG_ENABLE
    1107                 :            :                 cnxk_cpt_request_data_sgv2_mode_dump(infl_req->rptr, 0, infl_req->scatter_sz);
    1108                 :            : #endif
    1109                 :            : 
    1110         [ #  # ]:          0 :                 if (unlikely(uc_compcode)) {
    1111         [ #  # ]:          0 :                         if (uc_compcode == ROC_SE_ERR_GC_ICV_MISCOMPARE)
    1112                 :          0 :                                 cop->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
    1113                 :            :                         else
    1114                 :          0 :                                 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
    1115                 :            : 
    1116                 :          0 :                         plt_dp_info("Request failed with microcode error");
    1117                 :          0 :                         plt_dp_info("MC completion code 0x%x", res->uc_compcode);
    1118                 :          0 :                         cop->aux_flags = uc_compcode;
    1119                 :          0 :                         goto temp_sess_free;
    1120                 :            :                 }
    1121                 :            : 
    1122         [ #  # ]:          0 :                 if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
    1123                 :            :                         /* Verify authentication data if required */
    1124         [ #  # ]:          0 :                         if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_AUTH_VERIFY)) {
    1125                 :          0 :                                 uintptr_t *rsp = infl_req->mdata;
    1126                 :            : 
    1127         [ #  # ]:          0 :                                 compl_auth_verify(cop, (uint8_t *)rsp[0], rsp[1]);
    1128                 :            :                         }
    1129         [ #  # ]:          0 :                 } else if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
    1130                 :            :                         struct rte_crypto_asym_op *op = cop->asym;
    1131                 :          0 :                         uintptr_t *mdata = infl_req->mdata;
    1132                 :          0 :                         struct cnxk_ae_sess *sess = (struct cnxk_ae_sess *)op->session;
    1133                 :            : 
    1134   [ #  #  #  #  :          0 :                         cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
             #  #  #  # ]
    1135                 :            :                 }
    1136                 :            :         } else {
    1137                 :          0 :                 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
    1138                 :          0 :                 plt_dp_info("HW completion code 0x%x", res->compcode);
    1139                 :            : 
    1140   [ #  #  #  # ]:          0 :                 switch (compcode) {
    1141                 :          0 :                 case CPT_COMP_INSTERR:
    1142                 :          0 :                         plt_dp_err("Request failed with instruction error");
    1143                 :          0 :                         break;
    1144                 :          0 :                 case CPT_COMP_FAULT:
    1145                 :          0 :                         plt_dp_err("Request failed with DMA fault");
    1146                 :          0 :                         break;
    1147                 :          0 :                 case CPT_COMP_HWERR:
    1148                 :          0 :                         plt_dp_err("Request failed with hardware error");
    1149                 :          0 :                         break;
    1150                 :          0 :                 default:
    1151                 :          0 :                         plt_dp_err("Request failed with unknown completion code");
    1152                 :            :                 }
    1153                 :            :         }
    1154                 :            : 
    1155                 :          0 : temp_sess_free:
    1156         [ #  # ]:          0 :         if (unlikely(cop->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
    1157         [ #  # ]:          0 :                 if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
    1158                 :          0 :                         sym_session_clear(cop->sym->session, true);
    1159         [ #  # ]:          0 :                         rte_mempool_put(qp->sess_mp, cop->sym->session);
    1160                 :          0 :                         cop->sym->session = NULL;
    1161                 :            :                 }
    1162         [ #  # ]:          0 :                 if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
    1163                 :          0 :                         cnxk_ae_session_clear(NULL, cop->asym->session);
    1164         [ #  # ]:          0 :                         rte_mempool_put(qp->sess_mp, cop->asym->session);
    1165                 :          0 :                         cop->asym->session = NULL;
    1166                 :            :                 }
    1167                 :            :         }
    1168                 :            : }
    1169                 :            : 
    1170                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cpt_crypto_adapter_dequeue)
    1171                 :            : uintptr_t
    1172                 :          0 : cn20k_cpt_crypto_adapter_dequeue(uintptr_t get_work1)
    1173                 :            : {
    1174                 :            :         struct cpt_inflight_req *infl_req;
    1175                 :            :         struct rte_crypto_op *cop;
    1176                 :            :         struct cnxk_cpt_qp *qp;
    1177                 :            :         union cpt_res_s res;
    1178                 :            : 
    1179                 :          0 :         infl_req = (struct cpt_inflight_req *)(get_work1);
    1180                 :          0 :         cop = infl_req->cop;
    1181                 :          0 :         qp = infl_req->qp;
    1182                 :            : 
    1183                 :          0 :         res.u64[0] = rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]),
    1184                 :            :                                               rte_memory_order_relaxed);
    1185                 :            : 
    1186                 :          0 :         cn20k_cpt_dequeue_post_process(qp, infl_req->cop, infl_req, &res.cn20k);
    1187                 :            : 
    1188         [ #  # ]:          0 :         if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
    1189         [ #  # ]:          0 :                 rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
    1190                 :            : 
    1191         [ #  # ]:          0 :         rte_mempool_put(qp->ca.req_mp, infl_req);
    1192                 :          0 :         return (uintptr_t)cop;
    1193                 :            : }
    1194                 :            : 
    1195                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cpt_crypto_adapter_vector_dequeue)
    1196                 :            : uintptr_t
    1197                 :          0 : cn20k_cpt_crypto_adapter_vector_dequeue(uintptr_t get_work1)
    1198                 :            : {
    1199                 :            :         struct cpt_inflight_req *infl_req, *vec_infl_req;
    1200                 :            :         struct rte_mempool *meta_mp, *req_mp;
    1201                 :            :         struct rte_event_vector *vec;
    1202                 :            :         struct rte_crypto_op *cop;
    1203                 :            :         struct cnxk_cpt_qp *qp;
    1204                 :            :         union cpt_res_s res;
    1205                 :            :         int i;
    1206                 :            : 
    1207                 :          0 :         vec_infl_req = (struct cpt_inflight_req *)(get_work1);
    1208                 :            : 
    1209                 :          0 :         vec = vec_infl_req->vec;
    1210                 :          0 :         qp = vec_infl_req->qp;
    1211                 :          0 :         meta_mp = qp->meta_info.pool;
    1212                 :          0 :         req_mp = qp->ca.req_mp;
    1213                 :            : 
    1214                 :            : #ifdef CNXK_CRYPTODEV_DEBUG
    1215                 :            :         res.u64[0] = rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)(&vec_infl_req->res.u64[0]),
    1216                 :            :                                               rte_memory_order_relaxed);
    1217                 :            :         PLT_ASSERT(res.cn20k.compcode == CPT_COMP_GOOD);
    1218                 :            :         PLT_ASSERT(res.cn20k.uc_compcode == 0);
    1219                 :            : #endif
    1220                 :            : 
    1221         [ #  # ]:          0 :         for (i = 0; i < vec->nb_elem; i++) {
    1222                 :          0 :                 infl_req = vec->ptrs[i];
    1223                 :          0 :                 cop = infl_req->cop;
    1224                 :            : 
    1225                 :          0 :                 res.u64[0] = rte_atomic_load_explicit(
    1226                 :            :                         (RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), rte_memory_order_relaxed);
    1227                 :          0 :                 cn20k_cpt_dequeue_post_process(qp, cop, infl_req, &res.cn20k);
    1228                 :            : 
    1229                 :          0 :                 vec->ptrs[i] = cop;
    1230         [ #  # ]:          0 :                 if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
    1231         [ #  # ]:          0 :                         rte_mempool_put(meta_mp, infl_req->mdata);
    1232                 :            : 
    1233                 :          0 :                 rte_mempool_put(req_mp, infl_req);
    1234                 :            :         }
    1235                 :            : 
    1236                 :          0 :         rte_mempool_put(req_mp, vec_infl_req);
    1237                 :            : 
    1238                 :          0 :         return (uintptr_t)vec;
    1239                 :            : }
    1240                 :            : 
    1241                 :            : static uint16_t
    1242                 :          0 : cn20k_cpt_dequeue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
    1243                 :            : {
    1244                 :            :         struct cpt_inflight_req *infl_req;
    1245                 :            :         struct cnxk_cpt_qp *qp = qptr;
    1246                 :            :         struct pending_queue *pend_q;
    1247                 :            :         uint64_t infl_cnt, pq_tail;
    1248                 :            :         struct rte_crypto_op *cop;
    1249                 :            :         union cpt_res_s res;
    1250                 :            :         int i;
    1251                 :            : 
    1252                 :            :         pend_q = &qp->pend_q;
    1253                 :            : 
    1254                 :          0 :         const uint64_t pq_mask = pend_q->pq_mask;
    1255                 :            : 
    1256                 :          0 :         pq_tail = pend_q->tail;
    1257                 :          0 :         infl_cnt = pending_queue_infl_cnt(pend_q->head, pq_tail, pq_mask);
    1258                 :          0 :         nb_ops = RTE_MIN(nb_ops, infl_cnt);
    1259                 :            : 
    1260                 :            :         /* Ensure infl_cnt isn't read before data lands */
    1261                 :            :         rte_atomic_thread_fence(rte_memory_order_acquire);
    1262                 :            : 
    1263         [ #  # ]:          0 :         for (i = 0; i < nb_ops; i++) {
    1264                 :          0 :                 infl_req = &pend_q->req_queue[pq_tail];
    1265                 :            : 
    1266                 :          0 :                 res.u64[0] = rte_atomic_load_explicit(
    1267                 :            :                         (RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), rte_memory_order_relaxed);
    1268                 :            : 
    1269         [ #  # ]:          0 :                 if (unlikely(res.cn20k.compcode == CPT_COMP_NOT_DONE)) {
    1270         [ #  # ]:          0 :                         if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
    1271                 :          0 :                                 plt_err("Request timed out");
    1272                 :          0 :                                 cnxk_cpt_dump_on_err(qp);
    1273                 :          0 :                                 pend_q->time_out = rte_get_timer_cycles() +
    1274                 :          0 :                                                    DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
    1275                 :            :                         }
    1276                 :            :                         break;
    1277                 :            :                 }
    1278                 :            : 
    1279                 :            :                 pending_queue_advance(&pq_tail, pq_mask);
    1280                 :            : 
    1281                 :          0 :                 cop = infl_req->cop;
    1282                 :            : 
    1283                 :          0 :                 ops[i] = cop;
    1284                 :            : 
    1285                 :          0 :                 cn20k_cpt_dequeue_post_process(qp, cop, infl_req, &res.cn20k);
    1286                 :            : 
    1287         [ #  # ]:          0 :                 if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
    1288         [ #  # ]:          0 :                         rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
    1289                 :            :         }
    1290                 :            : 
    1291                 :          0 :         pend_q->tail = pq_tail;
    1292                 :            : 
    1293                 :          0 :         return i;
    1294                 :            : }
    1295                 :            : 
    1296                 :            : void
    1297                 :          0 : cn20k_cpt_set_enqdeq_fns(struct rte_cryptodev *dev)
    1298                 :            : {
    1299                 :          0 :         dev->enqueue_burst = cn20k_cpt_enqueue_burst;
    1300                 :          0 :         dev->dequeue_burst = cn20k_cpt_dequeue_burst;
    1301                 :            : 
    1302                 :            :         rte_mb();
    1303                 :          0 : }
    1304                 :            : 
    1305                 :            : static void
    1306                 :          0 : cn20k_cpt_dev_info_get(struct rte_cryptodev *dev, struct rte_cryptodev_info *info)
    1307                 :            : {
    1308         [ #  # ]:          0 :         if (info != NULL) {
    1309                 :          0 :                 cnxk_cpt_dev_info_get(dev, info);
    1310                 :          0 :                 info->driver_id = cn20k_cryptodev_driver_id;
    1311                 :            :         }
    1312                 :          0 : }
    1313                 :            : 
    1314                 :            : static inline int
    1315                 :          0 : cn20k_cpt_raw_fill_inst(struct cnxk_iov *iov, struct cnxk_cpt_qp *qp,
    1316                 :            :                         struct cnxk_sym_dp_ctx *dp_ctx, struct cpt_inst_s inst[],
    1317                 :            :                         struct cpt_inflight_req *infl_req, void *opaque)
    1318                 :            : {
    1319                 :            :         struct cnxk_se_sess *sess;
    1320                 :            :         int ret;
    1321                 :            : 
    1322                 :            :         const union cpt_res_s res = {
    1323                 :            :                 .cn20k.compcode = CPT_COMP_NOT_DONE,
    1324                 :            :         };
    1325                 :            : 
    1326                 :          0 :         inst[0].w0.u64 = 0;
    1327                 :          0 :         inst[0].w2.u64 = 0;
    1328                 :          0 :         inst[0].w3.u64 = 0;
    1329                 :            : 
    1330                 :          0 :         sess = dp_ctx->sess;
    1331                 :            : 
    1332   [ #  #  #  #  :          0 :         switch (sess->dp_thr_type) {
                      # ]
    1333                 :          0 :         case CPT_DP_THREAD_TYPE_PT:
    1334                 :          0 :                 ret = fill_raw_passthrough_params(iov, inst);
    1335                 :          0 :                 break;
    1336         [ #  # ]:          0 :         case CPT_DP_THREAD_TYPE_FC_CHAIN:
    1337                 :            :                 ret = fill_raw_fc_params(iov, sess, &qp->meta_info, infl_req, &inst[0], false,
    1338                 :            :                                          false, true);
    1339                 :          0 :                 break;
    1340         [ #  # ]:          0 :         case CPT_DP_THREAD_TYPE_FC_AEAD:
    1341                 :            :                 ret = fill_raw_fc_params(iov, sess, &qp->meta_info, infl_req, &inst[0], false, true,
    1342                 :            :                                          true);
    1343                 :          0 :                 break;
    1344         [ #  # ]:          0 :         case CPT_DP_THREAD_AUTH_ONLY:
    1345                 :            :                 ret = fill_raw_digest_params(iov, sess, &qp->meta_info, infl_req, &inst[0], true);
    1346                 :          0 :                 break;
    1347                 :            :         default:
    1348                 :            :                 ret = -EINVAL;
    1349                 :            :         }
    1350                 :            : 
    1351         [ #  # ]:          0 :         if (unlikely(ret))
    1352                 :            :                 return 0;
    1353                 :            : 
    1354                 :          0 :         inst[0].res_addr = (uint64_t)&infl_req->res;
    1355                 :          0 :         rte_atomic_store_explicit((RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), res.u64[0],
    1356                 :            :                         rte_memory_order_relaxed);
    1357                 :          0 :         infl_req->opaque = opaque;
    1358                 :            : 
    1359                 :          0 :         inst[0].w7.u64 = sess->cpt_inst_w7;
    1360                 :            : 
    1361                 :          0 :         return 1;
    1362                 :            : }
    1363                 :            : 
    1364                 :            : static uint32_t
    1365                 :          0 : cn20k_cpt_raw_enqueue_burst(void *qpair, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
    1366                 :            :                             union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status)
    1367                 :            : {
    1368                 :          0 :         uint16_t lmt_id, nb_allowed, nb_ops = vec->num;
    1369                 :            :         struct cpt_inflight_req *infl_req;
    1370                 :            :         uint64_t lmt_base, io_addr, head;
    1371                 :            :         struct cnxk_cpt_qp *qp = qpair;
    1372                 :            :         struct cnxk_sym_dp_ctx *dp_ctx;
    1373                 :            :         struct pending_queue *pend_q;
    1374                 :            :         uint32_t count = 0, index;
    1375                 :            :         union cpt_fc_write_s fc;
    1376                 :            :         struct cpt_inst_s *inst;
    1377                 :            :         uint64_t *fc_addr;
    1378                 :            :         int ret, i;
    1379                 :            : 
    1380                 :            :         pend_q = &qp->pend_q;
    1381                 :          0 :         const uint64_t pq_mask = pend_q->pq_mask;
    1382                 :            : 
    1383                 :          0 :         head = pend_q->head;
    1384         [ #  # ]:          0 :         nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
    1385                 :          0 :         nb_ops = RTE_MIN(nb_ops, nb_allowed);
    1386                 :            : 
    1387         [ #  # ]:          0 :         if (unlikely(nb_ops == 0))
    1388                 :            :                 return 0;
    1389                 :            : 
    1390                 :          0 :         lmt_base = qp->lmtline.lmt_base;
    1391                 :            :         io_addr = qp->lmtline.io_addr;
    1392                 :          0 :         fc_addr = qp->lmtline.fc_addr;
    1393                 :            : 
    1394                 :          0 :         const uint32_t fc_thresh = qp->lmtline.fc_thresh;
    1395                 :            : 
    1396                 :            :         ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
    1397                 :          0 :         inst = (struct cpt_inst_s *)lmt_base;
    1398                 :            : 
    1399                 :            :         dp_ctx = (struct cnxk_sym_dp_ctx *)drv_ctx;
    1400                 :          0 : again:
    1401                 :            :         fc.u64[0] =
    1402                 :          0 :                 rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
    1403         [ #  # ]:          0 :         if (unlikely(fc.s.qsize > fc_thresh)) {
    1404                 :            :                 i = 0;
    1405                 :          0 :                 goto pend_q_commit;
    1406                 :            :         }
    1407                 :            : 
    1408         [ #  # ]:          0 :         for (i = 0; i < RTE_MIN(CN20K_CPT_PKTS_PER_LOOP, nb_ops); i++) {
    1409                 :            :                 struct cnxk_iov iov;
    1410                 :            : 
    1411                 :          0 :                 index = count + i;
    1412                 :          0 :                 infl_req = &pend_q->req_queue[head];
    1413                 :          0 :                 infl_req->op_flags = 0;
    1414                 :            : 
    1415                 :          0 :                 cnxk_raw_burst_to_iov(vec, &ofs, index, &iov);
    1416                 :          0 :                 ret = cn20k_cpt_raw_fill_inst(&iov, qp, dp_ctx, &inst[i], infl_req,
    1417                 :          0 :                                               user_data[index]);
    1418         [ #  # ]:          0 :                 if (unlikely(ret != 1)) {
    1419                 :          0 :                         plt_dp_err("Could not process vec: %d", index);
    1420         [ #  # ]:          0 :                         if (i == 0 && count == 0)
    1421                 :          0 :                                 return -1;
    1422         [ #  # ]:          0 :                         else if (i == 0)
    1423                 :          0 :                                 goto pend_q_commit;
    1424                 :            :                         else
    1425                 :            :                                 break;
    1426                 :            :                 }
    1427                 :            :                 pending_queue_advance(&head, pq_mask);
    1428                 :            :         }
    1429                 :            : 
    1430                 :            :         cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
    1431                 :            : 
    1432   [ #  #  #  # ]:          0 :         if (nb_ops - i > 0 && i == CN20K_CPT_PKTS_PER_LOOP) {
    1433                 :          0 :                 nb_ops -= i;
    1434                 :          0 :                 count += i;
    1435                 :          0 :                 goto again;
    1436                 :            :         }
    1437                 :            : 
    1438                 :          0 : pend_q_commit:
    1439                 :            :         rte_atomic_thread_fence(rte_memory_order_release);
    1440                 :            : 
    1441                 :          0 :         pend_q->head = head;
    1442                 :          0 :         pend_q->time_out = rte_get_timer_cycles() + DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
    1443                 :            : 
    1444                 :          0 :         *enqueue_status = 1;
    1445                 :          0 :         return count + i;
    1446                 :            : }
    1447                 :            : 
    1448                 :            : static int
    1449                 :          0 : cn20k_cpt_raw_enqueue(void *qpair, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
    1450                 :            :                       uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
    1451                 :            :                       struct rte_crypto_va_iova_ptr *iv, struct rte_crypto_va_iova_ptr *digest,
    1452                 :            :                       struct rte_crypto_va_iova_ptr *aad_or_auth_iv, void *user_data)
    1453                 :            : {
    1454                 :            :         struct cpt_inflight_req *infl_req;
    1455                 :            :         uint64_t lmt_base, io_addr, head;
    1456                 :            :         struct cnxk_cpt_qp *qp = qpair;
    1457                 :            :         struct cnxk_sym_dp_ctx *dp_ctx;
    1458                 :            :         uint16_t lmt_id, nb_allowed;
    1459                 :            :         struct cpt_inst_s *inst;
    1460                 :            :         union cpt_fc_write_s fc;
    1461                 :            :         struct cnxk_iov iov;
    1462                 :            :         uint64_t *fc_addr;
    1463                 :            :         int ret, i = 1;
    1464                 :            : 
    1465                 :            :         struct pending_queue *pend_q = &qp->pend_q;
    1466                 :          0 :         const uint64_t pq_mask = pend_q->pq_mask;
    1467                 :          0 :         const uint32_t fc_thresh = qp->lmtline.fc_thresh;
    1468                 :            : 
    1469                 :          0 :         head = pend_q->head;
    1470         [ #  # ]:          0 :         nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
    1471                 :            : 
    1472         [ #  # ]:          0 :         if (unlikely(nb_allowed == 0))
    1473                 :            :                 return -1;
    1474                 :            : 
    1475                 :            :         cnxk_raw_to_iov(data_vec, n_data_vecs, &ofs, iv, digest, aad_or_auth_iv, &iov);
    1476                 :            : 
    1477                 :          0 :         lmt_base = qp->lmtline.lmt_base;
    1478                 :            :         io_addr = qp->lmtline.io_addr;
    1479                 :          0 :         fc_addr = qp->lmtline.fc_addr;
    1480                 :            : 
    1481                 :            :         ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
    1482                 :          0 :         inst = (struct cpt_inst_s *)lmt_base;
    1483                 :            : 
    1484                 :            :         fc.u64[0] =
    1485                 :          0 :                 rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
    1486         [ #  # ]:          0 :         if (unlikely(fc.s.qsize > fc_thresh))
    1487                 :            :                 return -1;
    1488                 :            : 
    1489                 :            :         dp_ctx = (struct cnxk_sym_dp_ctx *)drv_ctx;
    1490                 :          0 :         infl_req = &pend_q->req_queue[head];
    1491                 :          0 :         infl_req->op_flags = 0;
    1492                 :            : 
    1493                 :          0 :         ret = cn20k_cpt_raw_fill_inst(&iov, qp, dp_ctx, &inst[0], infl_req, user_data);
    1494         [ #  # ]:          0 :         if (unlikely(ret != 1)) {
    1495                 :          0 :                 plt_dp_err("Could not process vec");
    1496                 :          0 :                 return -1;
    1497                 :            :         }
    1498                 :            : 
    1499                 :            :         pending_queue_advance(&head, pq_mask);
    1500                 :            : 
    1501                 :            :         cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
    1502                 :            : 
    1503                 :          0 :         pend_q->head = head;
    1504                 :          0 :         pend_q->time_out = rte_get_timer_cycles() + DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
    1505                 :            : 
    1506                 :          0 :         return 1;
    1507                 :            : }
    1508                 :            : 
    1509                 :            : static inline int
    1510                 :          0 : cn20k_cpt_raw_dequeue_post_process(struct cpt_cn20k_res_s *res)
    1511                 :            : {
    1512                 :          0 :         const uint8_t uc_compcode = res->uc_compcode;
    1513                 :          0 :         const uint8_t compcode = res->compcode;
    1514                 :            :         int ret = 1;
    1515                 :            : 
    1516         [ #  # ]:          0 :         if (likely(compcode == CPT_COMP_GOOD)) {
    1517         [ #  # ]:          0 :                 if (unlikely(uc_compcode))
    1518                 :          0 :                         plt_dp_info("Request failed with microcode error: 0x%x", res->uc_compcode);
    1519                 :            :                 else
    1520                 :            :                         ret = 0;
    1521                 :            :         }
    1522                 :            : 
    1523                 :          0 :         return ret;
    1524                 :            : }
    1525                 :            : 
    1526                 :            : static uint32_t
    1527                 :          0 : cn20k_cpt_sym_raw_dequeue_burst(void *qptr, uint8_t *drv_ctx,
    1528                 :            :                                 rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
    1529                 :            :                                 uint32_t max_nb_to_dequeue,
    1530                 :            :                                 rte_cryptodev_raw_post_dequeue_t post_dequeue, void **out_user_data,
    1531                 :            :                                 uint8_t is_user_data_array, uint32_t *n_success,
    1532                 :            :                                 int *dequeue_status)
    1533                 :            : {
    1534                 :            :         struct cpt_inflight_req *infl_req;
    1535                 :            :         struct cnxk_cpt_qp *qp = qptr;
    1536                 :            :         struct pending_queue *pend_q;
    1537                 :            :         uint64_t infl_cnt, pq_tail;
    1538                 :            :         union cpt_res_s res;
    1539                 :            :         int is_op_success;
    1540                 :            :         uint16_t nb_ops;
    1541                 :            :         void *opaque;
    1542                 :            :         int i = 0;
    1543                 :            : 
    1544                 :            :         pend_q = &qp->pend_q;
    1545                 :            : 
    1546                 :          0 :         const uint64_t pq_mask = pend_q->pq_mask;
    1547                 :            : 
    1548                 :            :         RTE_SET_USED(drv_ctx);
    1549                 :          0 :         pq_tail = pend_q->tail;
    1550         [ #  # ]:          0 :         infl_cnt = pending_queue_infl_cnt(pend_q->head, pq_tail, pq_mask);
    1551                 :            : 
    1552                 :            :         /* Ensure infl_cnt isn't read before data lands */
    1553                 :            :         rte_atomic_thread_fence(rte_memory_order_acquire);
    1554                 :            : 
    1555                 :          0 :         infl_req = &pend_q->req_queue[pq_tail];
    1556                 :            : 
    1557                 :          0 :         opaque = infl_req->opaque;
    1558         [ #  # ]:          0 :         if (get_dequeue_count)
    1559                 :          0 :                 nb_ops = get_dequeue_count(opaque);
    1560                 :            :         else
    1561                 :          0 :                 nb_ops = max_nb_to_dequeue;
    1562                 :          0 :         nb_ops = RTE_MIN(nb_ops, infl_cnt);
    1563                 :            : 
    1564         [ #  # ]:          0 :         for (i = 0; i < nb_ops; i++) {
    1565                 :            :                 is_op_success = 0;
    1566                 :          0 :                 infl_req = &pend_q->req_queue[pq_tail];
    1567                 :            : 
    1568                 :          0 :                 res.u64[0] = rte_atomic_load_explicit(
    1569                 :            :                         (RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), rte_memory_order_relaxed);
    1570                 :            : 
    1571         [ #  # ]:          0 :                 if (unlikely(res.cn20k.compcode == CPT_COMP_NOT_DONE)) {
    1572         [ #  # ]:          0 :                         if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
    1573                 :          0 :                                 plt_err("Request timed out");
    1574                 :          0 :                                 cnxk_cpt_dump_on_err(qp);
    1575                 :          0 :                                 pend_q->time_out = rte_get_timer_cycles() +
    1576                 :          0 :                                                    DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
    1577                 :            :                         }
    1578                 :            :                         break;
    1579                 :            :                 }
    1580                 :            : 
    1581                 :            :                 pending_queue_advance(&pq_tail, pq_mask);
    1582                 :            : 
    1583         [ #  # ]:          0 :                 if (!cn20k_cpt_raw_dequeue_post_process(&res.cn20k)) {
    1584                 :            :                         is_op_success = 1;
    1585                 :          0 :                         *n_success += 1;
    1586                 :            :                 }
    1587                 :            : 
    1588         [ #  # ]:          0 :                 if (is_user_data_array) {
    1589                 :          0 :                         out_user_data[i] = infl_req->opaque;
    1590                 :          0 :                         post_dequeue(out_user_data[i], i, is_op_success);
    1591                 :            :                 } else {
    1592         [ #  # ]:          0 :                         if (i == 0)
    1593                 :          0 :                                 out_user_data[0] = opaque;
    1594                 :          0 :                         post_dequeue(out_user_data[0], i, is_op_success);
    1595                 :            :                 }
    1596                 :            : 
    1597         [ #  # ]:          0 :                 if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
    1598         [ #  # ]:          0 :                         rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
    1599                 :            :         }
    1600                 :            : 
    1601                 :          0 :         pend_q->tail = pq_tail;
    1602                 :          0 :         *dequeue_status = 1;
    1603                 :            : 
    1604                 :          0 :         return i;
    1605                 :            : }
    1606                 :            : 
    1607                 :            : static void *
    1608                 :          0 : cn20k_cpt_sym_raw_dequeue(void *qptr, uint8_t *drv_ctx, int *dequeue_status,
    1609                 :            :                           enum rte_crypto_op_status *op_status)
    1610                 :            : {
    1611                 :            :         struct cpt_inflight_req *infl_req;
    1612                 :            :         struct cnxk_cpt_qp *qp = qptr;
    1613                 :            :         struct pending_queue *pend_q;
    1614                 :            :         uint64_t pq_tail;
    1615                 :            :         union cpt_res_s res;
    1616                 :            :         void *opaque = NULL;
    1617                 :            : 
    1618                 :            :         pend_q = &qp->pend_q;
    1619                 :            : 
    1620                 :            :         const uint64_t pq_mask = pend_q->pq_mask;
    1621                 :            : 
    1622                 :            :         RTE_SET_USED(drv_ctx);
    1623                 :            : 
    1624         [ #  # ]:          0 :         pq_tail = pend_q->tail;
    1625                 :            : 
    1626                 :            :         rte_atomic_thread_fence(rte_memory_order_acquire);
    1627                 :            : 
    1628                 :          0 :         infl_req = &pend_q->req_queue[pq_tail];
    1629                 :            : 
    1630                 :          0 :         res.u64[0] = rte_atomic_load_explicit(
    1631                 :            :                         (RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), rte_memory_order_relaxed);
    1632                 :            : 
    1633         [ #  # ]:          0 :         if (unlikely(res.cn20k.compcode == CPT_COMP_NOT_DONE)) {
    1634         [ #  # ]:          0 :                 if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
    1635                 :          0 :                         plt_err("Request timed out");
    1636                 :          0 :                         cnxk_cpt_dump_on_err(qp);
    1637                 :          0 :                         pend_q->time_out = rte_get_timer_cycles() +
    1638                 :          0 :                                            DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
    1639                 :            :                 }
    1640                 :          0 :                 goto exit;
    1641                 :            :         }
    1642                 :            : 
    1643                 :            :         pending_queue_advance(&pq_tail, pq_mask);
    1644                 :            : 
    1645                 :          0 :         opaque = infl_req->opaque;
    1646                 :            : 
    1647         [ #  # ]:          0 :         if (!cn20k_cpt_raw_dequeue_post_process(&res.cn20k))
    1648                 :          0 :                 *op_status = RTE_CRYPTO_OP_STATUS_SUCCESS;
    1649                 :            :         else
    1650                 :          0 :                 *op_status = RTE_CRYPTO_OP_STATUS_ERROR;
    1651                 :            : 
    1652         [ #  # ]:          0 :         if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
    1653         [ #  # ]:          0 :                 rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
    1654                 :            : 
    1655                 :          0 :         *dequeue_status = 1;
    1656                 :          0 : exit:
    1657                 :          0 :         return opaque;
    1658                 :            : }
    1659                 :            : 
    1660                 :            : static int
    1661                 :          0 : cn20k_sym_get_raw_dp_ctx_size(struct rte_cryptodev *dev __rte_unused)
    1662                 :            : {
    1663                 :          0 :         return sizeof(struct cnxk_sym_dp_ctx);
    1664                 :            : }
    1665                 :            : 
    1666                 :            : static int
    1667                 :          0 : cn20k_sym_configure_raw_dp_ctx(struct rte_cryptodev *dev, uint16_t qp_id,
    1668                 :            :                                struct rte_crypto_raw_dp_ctx *raw_dp_ctx,
    1669                 :            :                                enum rte_crypto_op_sess_type sess_type,
    1670                 :            :                                union rte_cryptodev_session_ctx session_ctx, uint8_t is_update)
    1671                 :            : {
    1672                 :          0 :         struct cnxk_se_sess *sess = (struct cnxk_se_sess *)session_ctx.crypto_sess;
    1673                 :            :         struct cnxk_sym_dp_ctx *dp_ctx;
    1674                 :            : 
    1675         [ #  # ]:          0 :         if (sess_type != RTE_CRYPTO_OP_WITH_SESSION)
    1676                 :            :                 return -ENOTSUP;
    1677                 :            : 
    1678         [ #  # ]:          0 :         if (sess == NULL)
    1679                 :            :                 return -EINVAL;
    1680                 :            : 
    1681                 :          0 :         if ((sess->dp_thr_type == CPT_DP_THREAD_TYPE_PDCP) ||
    1682                 :            :             (sess->dp_thr_type == CPT_DP_THREAD_TYPE_PDCP_CHAIN) ||
    1683         [ #  # ]:          0 :             (sess->dp_thr_type == CPT_DP_THREAD_TYPE_KASUMI) ||
    1684                 :            :             (sess->dp_thr_type == CPT_DP_THREAD_TYPE_SM))
    1685                 :            :                 return -ENOTSUP;
    1686                 :            : 
    1687         [ #  # ]:          0 :         if ((sess->dp_thr_type == CPT_DP_THREAD_AUTH_ONLY) &&
    1688         [ #  # ]:          0 :             ((sess->roc_se_ctx.fc_type == ROC_SE_KASUMI) ||
    1689                 :            :              (sess->roc_se_ctx.fc_type == ROC_SE_PDCP)))
    1690                 :            :                 return -ENOTSUP;
    1691                 :            : 
    1692         [ #  # ]:          0 :         if (sess->roc_se_ctx.hash_type == ROC_SE_SHA1_TYPE)
    1693                 :            :                 return -ENOTSUP;
    1694                 :            : 
    1695                 :            :         dp_ctx = (struct cnxk_sym_dp_ctx *)raw_dp_ctx->drv_ctx_data;
    1696                 :          0 :         dp_ctx->sess = sess;
    1697                 :            : 
    1698         [ #  # ]:          0 :         if (!is_update) {
    1699                 :          0 :                 raw_dp_ctx->qp_data = (struct cnxk_cpt_qp *)dev->data->queue_pairs[qp_id];
    1700                 :          0 :                 raw_dp_ctx->dequeue = cn20k_cpt_sym_raw_dequeue;
    1701                 :          0 :                 raw_dp_ctx->dequeue_burst = cn20k_cpt_sym_raw_dequeue_burst;
    1702                 :          0 :                 raw_dp_ctx->enqueue = cn20k_cpt_raw_enqueue;
    1703                 :          0 :                 raw_dp_ctx->enqueue_burst = cn20k_cpt_raw_enqueue_burst;
    1704                 :            :         }
    1705                 :            : 
    1706                 :            :         return 0;
    1707                 :            : }
    1708                 :            : 
    1709                 :            : #if defined(RTE_ARCH_ARM64)
    1710                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cryptodev_sec_inb_rx_inject)
    1711                 :            : uint16_t __rte_hot
    1712                 :            : cn20k_cryptodev_sec_inb_rx_inject(void *dev, struct rte_mbuf **pkts,
    1713                 :            :                                   struct rte_security_session **sess, uint16_t nb_pkts)
    1714                 :            : {
    1715                 :            :         uint64_t lmt_base, io_addr, u64_0, u64_1, l2_len, pf_func;
    1716                 :            :         uint64x2_t inst_01, inst_23, inst_45, inst_67;
    1717                 :            :         struct cn20k_sec_session *sec_sess;
    1718                 :            :         struct rte_cryptodev *cdev = dev;
    1719                 :            :         union cpt_res_s *hw_res = NULL;
    1720                 :            :         uint16_t lmt_id, count = 0;
    1721                 :            :         struct cpt_inst_s *inst;
    1722                 :            :         union cpt_fc_write_s fc;
    1723                 :            :         struct cnxk_cpt_vf *vf;
    1724                 :            :         struct rte_mbuf *m;
    1725                 :            :         uint64_t u64_dptr;
    1726                 :            :         uint64_t *fc_addr;
    1727                 :            :         int i;
    1728                 :            : 
    1729                 :            :         vf = cdev->data->dev_private;
    1730                 :            : 
    1731                 :            :         lmt_base = vf->rx_inj_lmtline.lmt_base;
    1732                 :            :         io_addr = vf->rx_inj_lmtline.io_addr;
    1733                 :            :         fc_addr = vf->rx_inj_lmtline.fc_addr;
    1734                 :            : 
    1735                 :            :         ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
    1736                 :            :         pf_func = vf->rx_inj_sso_pf_func;
    1737                 :            : 
    1738                 :            :         const uint32_t fc_thresh = vf->rx_inj_lmtline.fc_thresh;
    1739                 :            : 
    1740                 :            : again:
    1741                 :            :         fc.u64[0] =
    1742                 :            :                 rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
    1743                 :            :         inst = (struct cpt_inst_s *)lmt_base;
    1744                 :            : 
    1745                 :            :         i = 0;
    1746                 :            : 
    1747                 :            :         if (unlikely(fc.s.qsize > fc_thresh))
    1748                 :            :                 goto exit;
    1749                 :            : 
    1750                 :            :         for (; i < RTE_MIN(CN20K_CPT_PKTS_PER_LOOP, nb_pkts); i++) {
    1751                 :            : 
    1752                 :            :                 m = pkts[i];
    1753                 :            :                 sec_sess = (struct cn20k_sec_session *)sess[i];
    1754                 :            : 
    1755                 :            :                 if (unlikely(rte_pktmbuf_headroom(m) < 32)) {
    1756                 :            :                         plt_dp_err("No space for CPT res_s");
    1757                 :            :                         break;
    1758                 :            :                 }
    1759                 :            : 
    1760                 :            :                 l2_len = m->l2_len;
    1761                 :            : 
    1762                 :            :                 *rte_security_dynfield(m) = (uint64_t)sec_sess->userdata;
    1763                 :            : 
    1764                 :            :                 hw_res = rte_pktmbuf_mtod(m, void *);
    1765                 :            :                 hw_res = RTE_PTR_SUB(hw_res, 32);
    1766                 :            :                 hw_res = RTE_PTR_ALIGN_CEIL(hw_res, 16);
    1767                 :            : 
    1768                 :            :                 /* Prepare CPT instruction */
    1769                 :            :                 if (m->nb_segs > 1) {
    1770                 :            :                         struct rte_mbuf *last = rte_pktmbuf_lastseg(m);
    1771                 :            :                         uintptr_t dptr, rxphdr, wqe_hdr;
    1772                 :            :                         uint16_t i;
    1773                 :            : 
    1774                 :            :                         if ((m->nb_segs > CNXK_CPT_MAX_SG_SEGS) ||
    1775                 :            :                             (rte_pktmbuf_tailroom(m) < CNXK_CPT_MIN_TAILROOM_REQ))
    1776                 :            :                                 goto exit;
    1777                 :            : 
    1778                 :            :                         wqe_hdr = rte_pktmbuf_mtod_offset(last, uintptr_t, last->data_len);
    1779                 :            :                         wqe_hdr += BIT_ULL(7);
    1780                 :            :                         wqe_hdr = (wqe_hdr - 1) & ~(BIT_ULL(7) - 1);
    1781                 :            : 
    1782                 :            :                         /* Pointer to WQE header */
    1783                 :            :                         *(uint64_t *)(m + 1) = wqe_hdr;
    1784                 :            : 
    1785                 :            :                         /* Reserve SG list after end of last mbuf data location. */
    1786                 :            :                         rxphdr = wqe_hdr + 8;
    1787                 :            :                         dptr = rxphdr + 7 * 8;
    1788                 :            : 
    1789                 :            :                         /* Prepare Multiseg SG list */
    1790                 :            :                         i = fill_sg2_comp_from_pkt((struct roc_sg2list_comp *)dptr, 0, m);
    1791                 :            :                         u64_dptr = dptr | ((uint64_t)(i) << 60);
    1792                 :            :                 } else {
    1793                 :            :                         struct roc_sg2list_comp *sg2;
    1794                 :            :                         uintptr_t dptr, wqe_hdr;
    1795                 :            : 
    1796                 :            :                         /* Reserve space for WQE, NIX_RX_PARSE_S and SG_S.
    1797                 :            :                          * Populate SG_S with num segs and seg length
    1798                 :            :                          */
    1799                 :            :                         wqe_hdr = (uintptr_t)(m + 1);
    1800                 :            :                         *(uint64_t *)(m + 1) = wqe_hdr;
    1801                 :            : 
    1802                 :            :                         sg2 = (struct roc_sg2list_comp *)(wqe_hdr + 8 * 8);
    1803                 :            :                         sg2->u.s.len[0] = rte_pktmbuf_pkt_len(m);
    1804                 :            :                         sg2->u.s.valid_segs = 1;
    1805                 :            : 
    1806                 :            :                         dptr = (uint64_t)rte_pktmbuf_iova(m);
    1807                 :            :                         u64_dptr = dptr;
    1808                 :            :                 }
    1809                 :            : 
    1810                 :            :                 /* Word 0 and 1 */
    1811                 :            :                 inst_01 = vdupq_n_u64(0);
    1812                 :            :                 u64_0 = pf_func << 48 | *(vf->rx_chan_base + m->port) << 4 | (l2_len - 2) << 24 |
    1813                 :            :                         l2_len << 16;
    1814                 :            :                 inst_01 = vsetq_lane_u64(u64_0, inst_01, 0);
    1815                 :            :                 inst_01 = vsetq_lane_u64((uint64_t)hw_res, inst_01, 1);
    1816                 :            :                 vst1q_u64(&inst->w0.u64, inst_01);
    1817                 :            : 
    1818                 :            :                 /* Word 2 and 3 */
    1819                 :            :                 inst_23 = vdupq_n_u64(0);
    1820                 :            :                 u64_1 = (((uint64_t)m + sizeof(struct rte_mbuf)) >> 3) << 3 | 1;
    1821                 :            :                 inst_23 = vsetq_lane_u64(u64_1, inst_23, 1);
    1822                 :            :                 vst1q_u64(&inst->w2.u64, inst_23);
    1823                 :            : 
    1824                 :            :                 /* Word 4 and 5 */
    1825                 :            :                 inst_45 = vdupq_n_u64(0);
    1826                 :            :                 u64_0 = sec_sess->inst.w4 | (rte_pktmbuf_pkt_len(m));
    1827                 :            :                 inst_45 = vsetq_lane_u64(u64_0, inst_45, 0);
    1828                 :            :                 inst_45 = vsetq_lane_u64(u64_dptr, inst_45, 1);
    1829                 :            :                 vst1q_u64(&inst->w4.u64, inst_45);
    1830                 :            : 
    1831                 :            :                 /* Word 6 and 7 */
    1832                 :            :                 inst_67 = vdupq_n_u64(0);
    1833                 :            :                 u64_1 = sec_sess->inst.w7;
    1834                 :            :                 inst_67 = vsetq_lane_u64(u64_1, inst_67, 1);
    1835                 :            :                 vst1q_u64(&inst->w6.u64, inst_67);
    1836                 :            : 
    1837                 :            :                 inst++;
    1838                 :            :         }
    1839                 :            : 
    1840                 :            :         cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
    1841                 :            : 
    1842                 :            :         if (nb_pkts - i > 0 && i == CN20K_CPT_PKTS_PER_LOOP) {
    1843                 :            :                 nb_pkts -= CN20K_CPT_PKTS_PER_LOOP;
    1844                 :            :                 pkts += CN20K_CPT_PKTS_PER_LOOP;
    1845                 :            :                 count += CN20K_CPT_PKTS_PER_LOOP;
    1846                 :            :                 sess += CN20K_CPT_PKTS_PER_LOOP;
    1847                 :            :                 goto again;
    1848                 :            :         }
    1849                 :            : 
    1850                 :            : exit:
    1851                 :            :         return count + i;
    1852                 :            : }
    1853                 :            : #else
    1854                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cryptodev_sec_inb_rx_inject)
    1855                 :            : uint16_t __rte_hot
    1856                 :          0 : cn20k_cryptodev_sec_inb_rx_inject(void *dev, struct rte_mbuf **pkts,
    1857                 :            :                                   struct rte_security_session **sess, uint16_t nb_pkts)
    1858                 :            : {
    1859                 :            :         RTE_SET_USED(dev);
    1860                 :            :         RTE_SET_USED(pkts);
    1861                 :            :         RTE_SET_USED(sess);
    1862                 :            :         RTE_SET_USED(nb_pkts);
    1863                 :          0 :         return 0;
    1864                 :            : }
    1865                 :            : #endif
    1866                 :            : 
    1867                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cryptodev_sec_rx_inject_configure)
    1868                 :            : int
    1869                 :          0 : cn20k_cryptodev_sec_rx_inject_configure(void *device, uint16_t port_id, bool enable)
    1870                 :            : {
    1871                 :            :         struct rte_cryptodev *crypto_dev = device;
    1872                 :            :         struct rte_eth_dev *eth_dev;
    1873                 :            :         int ret;
    1874                 :            : 
    1875         [ #  # ]:          0 :         if (!rte_eth_dev_is_valid_port(port_id))
    1876                 :            :                 return -EINVAL;
    1877                 :            : 
    1878         [ #  # ]:          0 :         if (!(crypto_dev->feature_flags & RTE_CRYPTODEV_FF_SECURITY_RX_INJECT))
    1879                 :            :                 return -ENOTSUP;
    1880                 :            : 
    1881                 :            :         eth_dev = &rte_eth_devices[port_id];
    1882                 :            : 
    1883                 :          0 :         ret = strncmp(eth_dev->device->driver->name, "net_cn20k", 8);
    1884         [ #  # ]:          0 :         if (ret)
    1885                 :            :                 return -ENOTSUP;
    1886                 :            : 
    1887                 :          0 :         roc_idev_nix_rx_inject_set(port_id, enable);
    1888                 :            : 
    1889                 :          0 :         return 0;
    1890                 :            : }
    1891                 :            : 
    1892                 :            : struct rte_cryptodev_ops cn20k_cpt_ops = {
    1893                 :            :         /* Device control ops */
    1894                 :            :         .dev_configure = cnxk_cpt_dev_config,
    1895                 :            :         .dev_start = cnxk_cpt_dev_start,
    1896                 :            :         .dev_stop = cnxk_cpt_dev_stop,
    1897                 :            :         .dev_close = cnxk_cpt_dev_close,
    1898                 :            :         .dev_infos_get = cn20k_cpt_dev_info_get,
    1899                 :            : 
    1900                 :            :         .stats_get = NULL,
    1901                 :            :         .stats_reset = NULL,
    1902                 :            :         .queue_pair_setup = cnxk_cpt_queue_pair_setup,
    1903                 :            :         .queue_pair_release = cnxk_cpt_queue_pair_release,
    1904                 :            :         .queue_pair_reset = cnxk_cpt_queue_pair_reset,
    1905                 :            : 
    1906                 :            :         /* Symmetric crypto ops */
    1907                 :            :         .sym_session_get_size = cnxk_cpt_sym_session_get_size,
    1908                 :            :         .sym_session_configure = cnxk_cpt_sym_session_configure,
    1909                 :            :         .sym_session_clear = cnxk_cpt_sym_session_clear,
    1910                 :            : 
    1911                 :            :         /* Asymmetric crypto ops */
    1912                 :            :         .asym_session_get_size = cnxk_ae_session_size_get,
    1913                 :            :         .asym_session_configure = cnxk_ae_session_cfg,
    1914                 :            :         .asym_session_clear = cnxk_ae_session_clear,
    1915                 :            : 
    1916                 :            :         /* Event crypto ops */
    1917                 :            :         .session_ev_mdata_set = cn20k_cpt_crypto_adapter_ev_mdata_set,
    1918                 :            :         .queue_pair_event_error_query = cnxk_cpt_queue_pair_event_error_query,
    1919                 :            : 
    1920                 :            :         /* Raw data-path API related operations */
    1921                 :            :         .sym_get_raw_dp_ctx_size = cn20k_sym_get_raw_dp_ctx_size,
    1922                 :            :         .sym_configure_raw_dp_ctx = cn20k_sym_configure_raw_dp_ctx,
    1923                 :            : };

Generated by: LCOV version 1.14