replace hot attributes
[dpdk.git] / drivers / crypto / octeontx2 / otx2_cryptodev_ops.c
index 65101b0..0ae04c5 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <rte_cryptodev_pmd.h>
 #include <rte_errno.h>
+#include <rte_ethdev.h>
 
 #include "otx2_cryptodev.h"
 #include "otx2_cryptodev_capabilities.h"
@@ -13,6 +14,7 @@
 #include "otx2_cryptodev_mbox.h"
 #include "otx2_cryptodev_ops.h"
 #include "otx2_mbox.h"
+#include "otx2_sec_idev.h"
 
 #include "cpt_hw_types.h"
 #include "cpt_pmd_logs.h"
@@ -22,6 +24,8 @@
 
 #define METABUF_POOL_CACHE_SIZE        512
 
+static uint64_t otx2_fpm_iova[CPT_EC_ID_PMAX];
+
 /* Forward declarations */
 
 static int
@@ -125,6 +129,34 @@ otx2_cpt_metabuf_mempool_destroy(struct otx2_cpt_qp *qp)
        meta_info->sg_mlen = 0;
 }
 
+static int
+otx2_cpt_qp_inline_cfg(const struct rte_cryptodev *dev, struct otx2_cpt_qp *qp)
+{
+       static rte_atomic16_t port_offset = RTE_ATOMIC16_INIT(-1);
+       uint16_t port_id, nb_ethport = rte_eth_dev_count_avail();
+       int i, ret;
+
+       for (i = 0; i < nb_ethport; i++) {
+               port_id = rte_atomic16_add_return(&port_offset, 1) % nb_ethport;
+               if (otx2_eth_dev_is_sec_capable(&rte_eth_devices[port_id]))
+                       break;
+       }
+
+       if (i >= nb_ethport)
+               return 0;
+
+       ret = otx2_cpt_qp_ethdev_bind(dev, qp, port_id);
+       if (ret)
+               return ret;
+
+       /* Publish inline Tx QP to eth dev security */
+       ret = otx2_sec_idev_tx_cpt_qp_add(port_id, qp);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
 static struct otx2_cpt_qp *
 otx2_cpt_qp_create(const struct rte_cryptodev *dev, uint16_t qp_id,
                   uint8_t group)
@@ -216,8 +248,20 @@ otx2_cpt_qp_create(const struct rte_cryptodev *dev, uint16_t qp_id,
 
        qp->lf_nq_reg = qp->base + OTX2_CPT_LF_NQ(0);
 
+       ret = otx2_sec_idev_tx_cpt_qp_remove(qp);
+       if (ret && (ret != -ENOENT)) {
+               CPT_LOG_ERR("Could not delete inline configuration");
+               goto mempool_destroy;
+       }
+
        otx2_cpt_iq_disable(qp);
 
+       ret = otx2_cpt_qp_inline_cfg(dev, qp);
+       if (ret) {
+               CPT_LOG_ERR("Could not configure queue for inline IPsec");
+               goto mempool_destroy;
+       }
+
        ret = otx2_cpt_iq_enable(dev, qp, group, OTX2_CPT_QUEUE_HI_PRIO,
                                 size_div40);
        if (ret) {
@@ -243,6 +287,12 @@ otx2_cpt_qp_destroy(const struct rte_cryptodev *dev, struct otx2_cpt_qp *qp)
        char name[RTE_MEMZONE_NAMESIZE];
        int ret;
 
+       ret = otx2_sec_idev_tx_cpt_qp_remove(qp);
+       if (ret && (ret != -ENOENT)) {
+               CPT_LOG_ERR("Could not delete inline configuration");
+               return ret;
+       }
+
        otx2_cpt_iq_disable(qp);
 
        otx2_cpt_metabuf_mempool_destroy(qp);
@@ -345,7 +395,7 @@ sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess)
        rte_mempool_put(pool, priv);
 }
 
-static __rte_always_inline int32_t __hot
+static __rte_always_inline int32_t __rte_hot
 otx2_cpt_enqueue_req(const struct otx2_cpt_qp *qp,
                     struct pending_queue *pend_q,
                     struct cpt_request_info *req)
@@ -393,7 +443,7 @@ otx2_cpt_enqueue_req(const struct otx2_cpt_qp *qp,
        return 0;
 }
 
-static __rte_always_inline int32_t __hot
+static __rte_always_inline int32_t __rte_hot
 otx2_cpt_enqueue_asym(struct otx2_cpt_qp *qp,
                      struct rte_crypto_op *op,
                      struct pending_queue *pend_q)
@@ -440,6 +490,17 @@ otx2_cpt_enqueue_asym(struct otx2_cpt_qp *qp,
                if (unlikely(ret))
                        goto req_fail;
                break;
+       case RTE_CRYPTO_ASYM_XFORM_ECDSA:
+               ret = cpt_enqueue_ecdsa_op(op, &params, sess, otx2_fpm_iova);
+               if (unlikely(ret))
+                       goto req_fail;
+               break;
+       case RTE_CRYPTO_ASYM_XFORM_ECPM:
+               ret = cpt_ecpm_prep(&asym_op->ecpm, &params,
+                                   sess->ec_ctx.curveid);
+               if (unlikely(ret))
+                       goto req_fail;
+               break;
        default:
                op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
                ret = -EINVAL;
@@ -465,7 +526,7 @@ req_fail:
        return ret;
 }
 
-static __rte_always_inline int __hot
+static __rte_always_inline int __rte_hot
 otx2_cpt_enqueue_sym(struct otx2_cpt_qp *qp, struct rte_crypto_op *op,
                     struct pending_queue *pend_q)
 {
@@ -508,7 +569,7 @@ otx2_cpt_enqueue_sym(struct otx2_cpt_qp *qp, struct rte_crypto_op *op,
        return ret;
 }
 
-static __rte_always_inline int __hot
+static __rte_always_inline int __rte_hot
 otx2_cpt_enqueue_sym_sessless(struct otx2_cpt_qp *qp, struct rte_crypto_op *op,
                              struct pending_queue *pend_q)
 {
@@ -641,6 +702,36 @@ otx2_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req,
        }
 }
 
+static __rte_always_inline void
+otx2_cpt_asym_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa,
+                              struct cpt_request_info *req,
+                              struct cpt_asym_ec_ctx *ec)
+{
+       int prime_len = ec_grp[ec->curveid].prime.length;
+
+       if (ecdsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
+               return;
+
+       /* Separate out sign r and s components */
+       memcpy(ecdsa->r.data, req->rptr, prime_len);
+       memcpy(ecdsa->s.data, req->rptr + ROUNDUP8(prime_len), prime_len);
+       ecdsa->r.length = prime_len;
+       ecdsa->s.length = prime_len;
+}
+
+static __rte_always_inline void
+otx2_cpt_asym_dequeue_ecpm_op(struct rte_crypto_ecpm_op_param *ecpm,
+                            struct cpt_request_info *req,
+                            struct cpt_asym_ec_ctx *ec)
+{
+       int prime_len = ec_grp[ec->curveid].prime.length;
+
+       memcpy(ecpm->r.x.data, req->rptr, prime_len);
+       memcpy(ecpm->r.y.data, req->rptr + ROUNDUP8(prime_len), prime_len);
+       ecpm->r.x.length = prime_len;
+       ecpm->r.y.length = prime_len;
+}
+
 static void
 otx2_cpt_asym_post_process(struct rte_crypto_op *cop,
                           struct cpt_request_info *req)
@@ -660,6 +751,12 @@ otx2_cpt_asym_post_process(struct rte_crypto_op *cop,
                memcpy(op->modex.result.data, req->rptr,
                       op->modex.result.length);
                break;
+       case RTE_CRYPTO_ASYM_XFORM_ECDSA:
+               otx2_cpt_asym_dequeue_ecdsa_op(&op->ecdsa, req, &sess->ec_ctx);
+               break;
+       case RTE_CRYPTO_ASYM_XFORM_ECPM:
+               otx2_cpt_asym_dequeue_ecpm_op(&op->ecpm, req, &sess->ec_ctx);
+               break;
        default:
                CPT_LOG_DP_DEBUG("Invalid crypto xform type");
                cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
@@ -824,6 +921,13 @@ otx2_cpt_dev_config(struct rte_cryptodev *dev,
 
        dev->feature_flags &= ~conf->ff_disable;
 
+       if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
+               /* Initialize shared FPM table */
+               ret = cpt_fpm_init(otx2_fpm_iova);
+               if (ret)
+                       return ret;
+       }
+
        /* Unregister error interrupts */
        if (vf->err_intr_registered)
                otx2_cpt_err_intr_unregister(dev);
@@ -857,12 +961,20 @@ otx2_cpt_dev_config(struct rte_cryptodev *dev,
                goto queues_detach;
        }
 
+       ret = otx2_cpt_inline_init(dev);
+       if (ret) {
+               CPT_LOG_ERR("Could not enable inline IPsec");
+               goto intr_unregister;
+       }
+
        dev->enqueue_burst = otx2_cpt_enqueue_burst;
        dev->dequeue_burst = otx2_cpt_dequeue_burst;
 
        rte_mb();
        return 0;
 
+intr_unregister:
+       otx2_cpt_err_intr_unregister(dev);
 queues_detach:
        otx2_cpt_queues_detach(dev);
        return ret;
@@ -881,9 +993,10 @@ otx2_cpt_dev_start(struct rte_cryptodev *dev)
 static void
 otx2_cpt_dev_stop(struct rte_cryptodev *dev)
 {
-       RTE_SET_USED(dev);
-
        CPT_PMD_INIT_FUNC_TRACE();
+
+       if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)
+               cpt_fpm_clear();
 }
 
 static int
@@ -1091,7 +1204,6 @@ struct rte_cryptodev_ops otx2_cpt_ops = {
        .stats_reset = NULL,
        .queue_pair_setup = otx2_cpt_queue_pair_setup,
        .queue_pair_release = otx2_cpt_queue_pair_release,
-       .queue_pair_count = NULL,
 
        /* Symmetric crypto ops */
        .sym_session_get_size = otx2_cpt_sym_session_get_size,