common/mlx5: fix default devargs initialization
[dpdk.git] / drivers / crypto / octeontx / otx_cryptodev_ops.c
index 2fe04eb..ddb1266 100644 (file)
@@ -5,7 +5,7 @@
 #include <rte_alarm.h>
 #include <rte_bus_pci.h>
 #include <rte_cryptodev.h>
-#include <rte_cryptodev_pmd.h>
+#include <cryptodev_pmd.h>
 #include <rte_eventdev.h>
 #include <rte_event_crypto_adapter.h>
 #include <rte_errno.h>
@@ -292,6 +292,11 @@ sym_session_configure(int driver_id, struct rte_crypto_sym_xform *xform,
        if ((GET_SESS_FC_TYPE(misc) == HASH_HMAC) &&
                        cpt_mac_len_verify(&temp_xform->auth)) {
                CPT_LOG_ERR("MAC length is not supported");
+               struct cpt_ctx *ctx = SESS_PRIV(misc);
+               if (ctx->auth_key != NULL) {
+                       rte_free(ctx->auth_key);
+                       ctx->auth_key = NULL;
+               }
                ret = -ENOTSUP;
                goto priv_put;
        }
@@ -320,11 +325,18 @@ static void
 sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess)
 {
        void *priv = get_sym_session_private_data(sess, driver_id);
+       struct cpt_sess_misc *misc;
        struct rte_mempool *pool;
+       struct cpt_ctx *ctx;
 
        if (priv == NULL)
                return;
 
+       misc = priv;
+       ctx = SESS_PRIV(misc);
+
+       rte_free(ctx->auth_key);
+
        memset(priv, 0, cpt_get_session_size());
 
        pool = rte_mempool_from_obj(priv);
@@ -362,35 +374,24 @@ otx_cpt_asym_session_size_get(struct rte_cryptodev *dev __rte_unused)
 }
 
 static int
-otx_cpt_asym_session_cfg(struct rte_cryptodev *dev,
+otx_cpt_asym_session_cfg(struct rte_cryptodev *dev __rte_unused,
                         struct rte_crypto_asym_xform *xform __rte_unused,
-                        struct rte_cryptodev_asym_session *sess,
-                        struct rte_mempool *pool)
+                        struct rte_cryptodev_asym_session *sess)
 {
-       struct cpt_asym_sess_misc *priv;
+       struct cpt_asym_sess_misc *priv = (struct cpt_asym_sess_misc *)
+                       sess->sess_private_data;
        int ret;
 
        CPT_PMD_INIT_FUNC_TRACE();
 
-       if (rte_mempool_get(pool, (void **)&priv)) {
-               CPT_LOG_ERR("Could not allocate session private data");
-               return -ENOMEM;
-       }
-
-       memset(priv, 0, sizeof(struct cpt_asym_sess_misc));
-
        ret = cpt_fill_asym_session_parameters(priv, xform);
        if (ret) {
                CPT_LOG_ERR("Could not configure session parameters");
-
-               /* Return session to mempool */
-               rte_mempool_put(pool, priv);
                return ret;
        }
 
        priv->cpt_inst_w7 = 0;
 
-       set_asym_session_private_data(sess, dev->driver_id, priv);
        return 0;
 }
 
@@ -399,11 +400,10 @@ otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
                           struct rte_cryptodev_asym_session *sess)
 {
        struct cpt_asym_sess_misc *priv;
-       struct rte_mempool *sess_mp;
 
        CPT_PMD_INIT_FUNC_TRACE();
 
-       priv = get_asym_session_private_data(sess, dev->driver_id);
+       priv = (struct cpt_asym_sess_misc *) sess->sess_private_data;
 
        if (priv == NULL)
                return;
@@ -411,23 +411,14 @@ otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
        /* Free resources allocated during session configure */
        cpt_free_asym_session_parameters(priv);
        memset(priv, 0, otx_cpt_asym_session_size_get(dev));
-       sess_mp = rte_mempool_from_obj(priv);
-       set_asym_session_private_data(sess, dev->driver_id, NULL);
-       rte_mempool_put(sess_mp, priv);
 }
 
 static __rte_always_inline void * __rte_hot
 otx_cpt_request_enqueue(struct cpt_instance *instance,
-                       struct pending_queue *pqueue,
                        void *req, uint64_t cpt_inst_w7)
 {
        struct cpt_request_info *user_req = (struct cpt_request_info *)req;
 
-       if (unlikely(pqueue->pending_count >= DEFAULT_CMD_QLEN)) {
-               rte_errno = EAGAIN;
-               return NULL;
-       }
-
        fill_cpt_inst(instance, req, cpt_inst_w7);
 
        CPT_LOG_DP_DEBUG("req: %p op: %p ", req, user_req->op);
@@ -447,8 +438,7 @@ otx_cpt_request_enqueue(struct cpt_instance *instance,
 
 static __rte_always_inline void * __rte_hot
 otx_cpt_enq_single_asym(struct cpt_instance *instance,
-                       struct rte_crypto_op *op,
-                       struct pending_queue *pqueue)
+                       struct rte_crypto_op *op)
 {
        struct cpt_qp_meta_info *minfo = &instance->meta_info;
        struct rte_crypto_asym_op *asym_op = op->asym;
@@ -465,8 +455,8 @@ otx_cpt_enq_single_asym(struct cpt_instance *instance,
                return NULL;
        }
 
-       sess = get_asym_session_private_data(asym_op->session,
-                                            otx_cryptodev_driver_id);
+       sess = (struct cpt_asym_sess_misc *)
+                       asym_op->session->sess_private_data;
 
        /* Store phys_addr of the mdata to meta_buf */
        params.meta_buf = rte_mempool_virt2iova(mdata);
@@ -512,8 +502,7 @@ otx_cpt_enq_single_asym(struct cpt_instance *instance,
                goto req_fail;
        }
 
-       req = otx_cpt_request_enqueue(instance, pqueue, params.req,
-                                     sess->cpt_inst_w7);
+       req = otx_cpt_request_enqueue(instance, params.req, sess->cpt_inst_w7);
        if (unlikely(req == NULL)) {
                CPT_LOG_DP_ERR("Could not enqueue crypto req");
                goto req_fail;
@@ -529,8 +518,7 @@ req_fail:
 
 static __rte_always_inline void * __rte_hot
 otx_cpt_enq_single_sym(struct cpt_instance *instance,
-                      struct rte_crypto_op *op,
-                      struct pending_queue *pqueue)
+                      struct rte_crypto_op *op)
 {
        struct cpt_sess_misc *sess;
        struct rte_crypto_sym_op *sym_op = op->sym;
@@ -554,14 +542,13 @@ otx_cpt_enq_single_sym(struct cpt_instance *instance,
                                         &mdata, (void **)&prep_req);
 
        if (unlikely(ret)) {
-               CPT_LOG_DP_ERR("prep cryto req : op %p, cpt_op 0x%x "
+               CPT_LOG_DP_ERR("prep crypto req : op %p, cpt_op 0x%x "
                               "ret 0x%x", op, (unsigned int)cpt_op, ret);
                return NULL;
        }
 
        /* Enqueue prepared instruction to h/w */
-       req = otx_cpt_request_enqueue(instance, pqueue, prep_req,
-                                     sess->cpt_inst_w7);
+       req = otx_cpt_request_enqueue(instance, prep_req, sess->cpt_inst_w7);
        if (unlikely(req == NULL))
                /* Buffer allocated for request preparation need to be freed */
                free_op_meta(mdata, instance->meta_info.pool);
@@ -571,8 +558,7 @@ otx_cpt_enq_single_sym(struct cpt_instance *instance,
 
 static __rte_always_inline void * __rte_hot
 otx_cpt_enq_single_sym_sessless(struct cpt_instance *instance,
-                               struct rte_crypto_op *op,
-                               struct pending_queue *pend_q)
+                               struct rte_crypto_op *op)
 {
        const int driver_id = otx_cryptodev_driver_id;
        struct rte_crypto_sym_op *sym_op = op->sym;
@@ -594,8 +580,8 @@ otx_cpt_enq_single_sym_sessless(struct cpt_instance *instance,
 
        sym_op->session = sess;
 
-       req = otx_cpt_enq_single_sym(instance, op, pend_q);
-
+       /* Enqueue op with the tmp session set */
+       req = otx_cpt_enq_single_sym(instance, op);
        if (unlikely(req == NULL))
                goto priv_put;
 
@@ -614,22 +600,20 @@ sess_put:
 static __rte_always_inline void *__rte_hot
 otx_cpt_enq_single(struct cpt_instance *inst,
                   struct rte_crypto_op *op,
-                  struct pending_queue *pqueue,
                   const uint8_t op_type)
 {
        /* Check for the type */
 
        if (op_type == OP_TYPE_SYM) {
                if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
-                       return otx_cpt_enq_single_sym(inst, op, pqueue);
+                       return otx_cpt_enq_single_sym(inst, op);
                else
-                       return otx_cpt_enq_single_sym_sessless(inst, op,
-                                                              pqueue);
+                       return otx_cpt_enq_single_sym_sessless(inst, op);
        }
 
        if (op_type == OP_TYPE_ASYM) {
                if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
-                       return otx_cpt_enq_single_asym(inst, op, pqueue);
+                       return otx_cpt_enq_single_asym(inst, op);
        }
 
        /* Should not reach here */
@@ -642,30 +626,33 @@ otx_cpt_pkt_enqueue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops,
                    const uint8_t op_type)
 {
        struct cpt_instance *instance = (struct cpt_instance *)qptr;
-       uint16_t count;
+       uint16_t count, free_slots;
        void *req;
        struct cpt_vf *cptvf = (struct cpt_vf *)instance;
        struct pending_queue *pqueue = &cptvf->pqueue;
 
-       count = DEFAULT_CMD_QLEN - pqueue->pending_count;
-       if (nb_ops > count)
-               nb_ops = count;
+       free_slots = pending_queue_free_slots(pqueue, DEFAULT_CMD_QLEN,
+                               DEFAULT_CMD_QRSVD_SLOTS);
+       if (nb_ops > free_slots)
+               nb_ops = free_slots;
 
        count = 0;
        while (likely(count < nb_ops)) {
 
                /* Enqueue single op */
-               req = otx_cpt_enq_single(instance, ops[count], pqueue, op_type);
+               req = otx_cpt_enq_single(instance, ops[count], op_type);
 
                if (unlikely(req == NULL))
                        break;
 
-               pqueue->req_queue[pqueue->enq_tail] = (uintptr_t)req;
-               MOD_INC(pqueue->enq_tail, DEFAULT_CMD_QLEN);
-               pqueue->pending_count += 1;
+               pending_queue_push(pqueue, req, count, DEFAULT_CMD_QLEN);
                count++;
        }
-       otx_cpt_ring_dbell(instance, count);
+
+       if (likely(count)) {
+               pending_queue_commit(pqueue, count, DEFAULT_CMD_QLEN);
+               otx_cpt_ring_dbell(instance, count);
+       }
        return count;
 }
 
@@ -743,8 +730,7 @@ otx_crypto_adapter_enqueue(void *port, struct rte_crypto_op *op)
 
        op_type = op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC ? OP_TYPE_SYM :
                                                             OP_TYPE_ASYM;
-       req = otx_cpt_enq_single(instance, op,
-                                &((struct cpt_vf *)instance)->pqueue, op_type);
+       req = otx_cpt_enq_single(instance, op, op_type);
        if (unlikely(req == NULL))
                return 0;
 
@@ -850,8 +836,7 @@ otx_cpt_asym_post_process(struct rte_crypto_op *cop,
        struct rte_crypto_asym_op *op = cop->asym;
        struct cpt_asym_sess_misc *sess;
 
-       sess = get_asym_session_private_data(op->session,
-                                            otx_cryptodev_driver_id);
+       sess = (struct cpt_asym_sess_misc *) op->session->sess_private_data;
 
        switch (sess->xfrm_type) {
        case RTE_CRYPTO_ASYM_XFORM_RSA:
@@ -958,17 +943,16 @@ otx_cpt_pkt_dequeue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops,
        int nb_completed;
        struct pending_queue *pqueue = &cptvf->pqueue;
 
-       pcount = pqueue->pending_count;
+       pcount = pending_queue_level(pqueue, DEFAULT_CMD_QLEN);
+
+       /* Ensure pcount isn't read before data lands */
+       rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
+
        count = (nb_ops > pcount) ? pcount : nb_ops;
 
        for (i = 0; i < count; i++) {
-               user_req = (struct cpt_request_info *)
-                               pqueue->req_queue[pqueue->deq_head];
-
-               if (likely((i+1) < count)) {
-                       rte_prefetch_non_temporal(
-                               (void *)pqueue->req_queue[i+1]);
-               }
+               pending_queue_peek(pqueue, (void **) &user_req,
+                       DEFAULT_CMD_QLEN, i + 1 < count);
 
                ret = check_nb_command_id(user_req, instance);
 
@@ -984,8 +968,7 @@ otx_cpt_pkt_dequeue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops,
                CPT_LOG_DP_DEBUG("Request %p Op %p completed with code %d",
                                 user_req, user_req->op, ret);
 
-               MOD_INC(pqueue->deq_head, DEFAULT_CMD_QLEN);
-               pqueue->pending_count -= 1;
+               pending_queue_pop(pqueue, DEFAULT_CMD_QLEN);
        }
 
        nb_completed = i;