crypto/cnxk: support lookaside IPsec AES-CTR
[dpdk.git] / drivers / crypto / cnxk / cn10k_cryptodev_ops.c
index c25c8e6..1905ea3 100644 (file)
@@ -49,11 +49,11 @@ sess_put:
 }
 
 static __rte_always_inline int __rte_hot
-cpt_sec_inst_fill(struct rte_crypto_op *op, struct cn10k_sec_session *sess,
+cpt_sec_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
+                 struct cn10k_sec_session *sess,
                  struct cpt_inflight_req *infl_req, struct cpt_inst_s *inst)
 {
        struct rte_crypto_sym_op *sym_op = op->sym;
-       union roc_ot_ipsec_sa_word2 *w2;
        struct cn10k_ipsec_sa *sa;
        int ret;
 
@@ -68,10 +68,9 @@ cpt_sec_inst_fill(struct rte_crypto_op *op, struct cn10k_sec_session *sess,
        }
 
        sa = &sess->sa;
-       w2 = (union roc_ot_ipsec_sa_word2 *)&sa->in_sa.w2;
 
-       if (w2->s.dir == ROC_IE_SA_DIR_OUTBOUND)
-               ret = process_outb_sa(op, sa, inst);
+       if (sa->is_outbound)
+               ret = process_outb_sa(&qp->lf, op, sa, inst);
        else {
                infl_req->op_flags |= CPT_OP_FLAGS_IPSEC_DIR_INBOUND;
                ret = process_inb_sa(op, sa, inst);
@@ -112,6 +111,10 @@ cn10k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[],
        uint64_t w7;
        int ret;
 
+       const union cpt_res_s res = {
+               .cn10k.compcode = CPT_COMP_NOT_DONE,
+       };
+
        op = ops[0];
 
        inst[0].w0.u64 = 0;
@@ -124,7 +127,7 @@ cn10k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[],
                if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
                        sec_sess = get_sec_session_private_data(
                                sym_op->sec_session);
-                       ret = cpt_sec_inst_fill(op, sec_sess, infl_req,
+                       ret = cpt_sec_inst_fill(qp, op, sec_sess, infl_req,
                                                &inst[0]);
                        if (unlikely(ret))
                                return 0;
@@ -175,7 +178,7 @@ cn10k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[],
        }
 
        inst[0].res_addr = (uint64_t)&infl_req->res;
-       infl_req->res.cn10k.compcode = CPT_COMP_NOT_DONE;
+       __atomic_store_n(&infl_req->res.u64[0], res.u64[0], __ATOMIC_RELAXED);
        infl_req->cop = op;
 
        inst[0].w7.u64 = w7;
@@ -196,11 +199,15 @@ cn10k_cpt_enqueue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
        struct pending_queue *pend_q;
        struct cpt_inst_s *inst;
        uint16_t lmt_id;
+       uint64_t head;
        int ret, i;
 
        pend_q = &qp->pend_q;
 
-       nb_allowed = qp->lf.nb_desc - pend_q->pending_count;
+       const uint64_t pq_mask = pend_q->pq_mask;
+
+       head = pend_q->head;
+       nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
        nb_ops = RTE_MIN(nb_ops, nb_allowed);
 
        if (unlikely(nb_ops == 0))
@@ -214,18 +221,18 @@ cn10k_cpt_enqueue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
 
 again:
        for (i = 0; i < RTE_MIN(PKTS_PER_LOOP, nb_ops); i++) {
-               infl_req = &pend_q->req_queue[pend_q->enq_tail];
+               infl_req = &pend_q->req_queue[head];
                infl_req->op_flags = 0;
 
                ret = cn10k_cpt_fill_inst(qp, ops + i, &inst[2 * i], infl_req);
                if (unlikely(ret != 1)) {
                        plt_dp_err("Could not process op: %p", ops + i);
                        if (i == 0)
-                               goto update_pending;
+                               goto pend_q_commit;
                        break;
                }
 
-               MOD_INC(pend_q->enq_tail, qp->lf.nb_desc);
+               pending_queue_advance(&head, pq_mask);
        }
 
        if (i > PKTS_PER_STEORL) {
@@ -251,9 +258,10 @@ again:
                goto again;
        }
 
-update_pending:
-       pend_q->pending_count += count + i;
+pend_q_commit:
+       rte_atomic_thread_fence(__ATOMIC_RELEASE);
 
+       pend_q->head = head;
        pend_q->time_out = rte_get_timer_cycles() +
                           DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
 
@@ -368,20 +376,20 @@ cn10k_cpt_sec_ucc_process(struct rte_crypto_op *cop,
        switch (uc_compcode) {
        case ROC_IE_OT_UCC_SUCCESS:
                if (sa->ip_csum_enable)
-                       mbuf->ol_flags |= PKT_RX_IP_CKSUM_GOOD;
+                       mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
                break;
        case ROC_IE_OT_UCC_SUCCESS_PKT_IP_BADCSUM:
-               mbuf->ol_flags |= PKT_RX_IP_CKSUM_BAD;
+               mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
                break;
        case ROC_IE_OT_UCC_SUCCESS_PKT_L4_GOODCSUM:
-               mbuf->ol_flags |= PKT_RX_L4_CKSUM_GOOD;
+               mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
                if (sa->ip_csum_enable)
-                       mbuf->ol_flags |= PKT_RX_IP_CKSUM_GOOD;
+                       mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
                break;
        case ROC_IE_OT_UCC_SUCCESS_PKT_L4_BADCSUM:
-               mbuf->ol_flags |= PKT_RX_L4_CKSUM_BAD;
+               mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
                if (sa->ip_csum_enable)
-                       mbuf->ol_flags |= PKT_RX_IP_CKSUM_GOOD;
+                       mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
                break;
        default:
                break;
@@ -391,9 +399,9 @@ cn10k_cpt_sec_ucc_process(struct rte_crypto_op *cop,
 static inline void
 cn10k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp,
                               struct rte_crypto_op *cop,
-                              struct cpt_inflight_req *infl_req)
+                              struct cpt_inflight_req *infl_req,
+                              struct cpt_cn10k_res_s *res)
 {
-       struct cpt_cn10k_res_s *res = (struct cpt_cn10k_res_s *)&infl_req->res;
        const uint8_t uc_compcode = res->uc_compcode;
        const uint8_t compcode = res->compcode;
        unsigned int sz;
@@ -491,12 +499,15 @@ cn10k_cpt_crypto_adapter_dequeue(uintptr_t get_work1)
        struct cpt_inflight_req *infl_req;
        struct rte_crypto_op *cop;
        struct cnxk_cpt_qp *qp;
+       union cpt_res_s res;
 
        infl_req = (struct cpt_inflight_req *)(get_work1);
        cop = infl_req->cop;
        qp = infl_req->qp;
 
-       cn10k_cpt_dequeue_post_process(qp, infl_req->cop, infl_req);
+       res.u64[0] = __atomic_load_n(&infl_req->res.u64[0], __ATOMIC_RELAXED);
+
+       cn10k_cpt_dequeue_post_process(qp, infl_req->cop, infl_req, &res.cn10k);
 
        if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
                rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
@@ -511,26 +522,33 @@ cn10k_cpt_dequeue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
        struct cpt_inflight_req *infl_req;
        struct cnxk_cpt_qp *qp = qptr;
        struct pending_queue *pend_q;
-       struct cpt_cn10k_res_s *res;
+       uint64_t infl_cnt, pq_tail;
        struct rte_crypto_op *cop;
-       int i, nb_pending;
+       union cpt_res_s res;
+       int i;
 
        pend_q = &qp->pend_q;
 
-       nb_pending = pend_q->pending_count;
+       const uint64_t pq_mask = pend_q->pq_mask;
+
+       pq_tail = pend_q->tail;
+       infl_cnt = pending_queue_infl_cnt(pend_q->head, pq_tail, pq_mask);
+       nb_ops = RTE_MIN(nb_ops, infl_cnt);
 
-       if (nb_ops > nb_pending)
-               nb_ops = nb_pending;
+       /* Ensure infl_cnt isn't read before data lands */
+       rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
 
        for (i = 0; i < nb_ops; i++) {
-               infl_req = &pend_q->req_queue[pend_q->deq_head];
+               infl_req = &pend_q->req_queue[pq_tail];
 
-               res = (struct cpt_cn10k_res_s *)&infl_req->res;
+               res.u64[0] = __atomic_load_n(&infl_req->res.u64[0],
+                                            __ATOMIC_RELAXED);
 
-               if (unlikely(res->compcode == CPT_COMP_NOT_DONE)) {
+               if (unlikely(res.cn10k.compcode == CPT_COMP_NOT_DONE)) {
                        if (unlikely(rte_get_timer_cycles() >
                                     pend_q->time_out)) {
                                plt_err("Request timed out");
+                               cnxk_cpt_dump_on_err(qp);
                                pend_q->time_out = rte_get_timer_cycles() +
                                                   DEFAULT_COMMAND_TIMEOUT *
                                                           rte_get_timer_hz();
@@ -538,19 +556,19 @@ cn10k_cpt_dequeue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
                        break;
                }
 
-               MOD_INC(pend_q->deq_head, qp->lf.nb_desc);
+               pending_queue_advance(&pq_tail, pq_mask);
 
                cop = infl_req->cop;
 
                ops[i] = cop;
 
-               cn10k_cpt_dequeue_post_process(qp, cop, infl_req);
+               cn10k_cpt_dequeue_post_process(qp, cop, infl_req, &res.cn10k);
 
                if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
                        rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
        }
 
-       pend_q->pending_count -= i;
+       pend_q->tail = pq_tail;
 
        return i;
 }