crypto/cnxk: fix KASUMI input length
[dpdk.git] / drivers / crypto / cnxk / cn10k_ipsec.c
index 1d567bf..27df1dc 100644 (file)
@@ -3,7 +3,7 @@
  */
 
 #include <rte_malloc.h>
-#include <rte_cryptodev.h>
+#include <cryptodev_pmd.h>
 #include <rte_esp.h>
 #include <rte_ip.h>
 #include <rte_security.h>
 
 #include "roc_api.h"
 
-static int
-ipsec_xform_aead_verify(struct rte_security_ipsec_xform *ipsec_xfrm,
-                       struct rte_crypto_sym_xform *crypto_xfrm)
-{
-       if (ipsec_xfrm->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
-           crypto_xfrm->aead.op != RTE_CRYPTO_AEAD_OP_ENCRYPT)
-               return -EINVAL;
-
-       if (ipsec_xfrm->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS &&
-           crypto_xfrm->aead.op != RTE_CRYPTO_AEAD_OP_DECRYPT)
-               return -EINVAL;
-
-       if (crypto_xfrm->aead.algo == RTE_CRYPTO_AEAD_AES_GCM) {
-               switch (crypto_xfrm->aead.key.length) {
-               case ROC_CPT_AES128_KEY_LEN:
-               case ROC_CPT_AES192_KEY_LEN:
-               case ROC_CPT_AES256_KEY_LEN:
-                       break;
-               default:
-                       return -EINVAL;
-               }
-               return 0;
-       }
-
-       return -ENOTSUP;
-}
-
-static int
-cn10k_ipsec_xform_verify(struct rte_security_ipsec_xform *ipsec_xfrm,
-                        struct rte_crypto_sym_xform *crypto_xfrm)
-{
-       if ((ipsec_xfrm->direction != RTE_SECURITY_IPSEC_SA_DIR_INGRESS) &&
-           (ipsec_xfrm->direction != RTE_SECURITY_IPSEC_SA_DIR_EGRESS))
-               return -EINVAL;
-
-       if ((ipsec_xfrm->proto != RTE_SECURITY_IPSEC_SA_PROTO_ESP) &&
-           (ipsec_xfrm->proto != RTE_SECURITY_IPSEC_SA_PROTO_AH))
-               return -EINVAL;
-
-       if ((ipsec_xfrm->mode != RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT) &&
-           (ipsec_xfrm->mode != RTE_SECURITY_IPSEC_SA_MODE_TUNNEL))
-               return -EINVAL;
-
-       if ((ipsec_xfrm->tunnel.type != RTE_SECURITY_IPSEC_TUNNEL_IPV4) &&
-           (ipsec_xfrm->tunnel.type != RTE_SECURITY_IPSEC_TUNNEL_IPV6))
-               return -EINVAL;
-
-       if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AEAD)
-               return ipsec_xform_aead_verify(ipsec_xfrm, crypto_xfrm);
-
-       return -ENOTSUP;
-}
-
 static uint64_t
 ipsec_cpt_inst_w7_get(struct roc_cpt *roc_cpt, void *sa)
 {
@@ -90,6 +37,7 @@ cn10k_ipsec_outb_sa_create(struct roc_cpt *roc_cpt,
                           struct rte_crypto_sym_xform *crypto_xfrm,
                           struct rte_security_session *sec_sess)
 {
+       union roc_ot_ipsec_outb_param1 param1;
        struct roc_ot_ipsec_outb_sa *out_sa;
        struct cnxk_ipsec_outb_rlens rlens;
        struct cn10k_sec_session *sess;
@@ -110,19 +58,53 @@ cn10k_ipsec_outb_sa_create(struct roc_cpt *roc_cpt,
 
        sa->inst.w7 = ipsec_cpt_inst_w7_get(roc_cpt, sa);
 
+#ifdef LA_IPSEC_DEBUG
+       /* Use IV from application in debug mode */
+       if (ipsec_xfrm->options.iv_gen_disable == 1) {
+               out_sa->w2.s.iv_src = ROC_IE_OT_SA_IV_SRC_FROM_SA;
+               if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
+                       sa->iv_offset = crypto_xfrm->aead.iv.offset;
+                       sa->iv_length = crypto_xfrm->aead.iv.length;
+               }
+       }
+#else
+       if (ipsec_xfrm->options.iv_gen_disable != 0) {
+               plt_err("Application provided IV not supported");
+               return -ENOTSUP;
+       }
+#endif
+
        /* Get Rlen calculation data */
        ret = cnxk_ipsec_outb_rlens_get(&rlens, ipsec_xfrm, crypto_xfrm);
        if (ret)
                return ret;
 
-       sa->partial_len = rlens.partial_len;
-       sa->roundup_byte = rlens.roundup_byte;
-       sa->roundup_len = rlens.roundup_len;
+       sa->max_extended_len = rlens.max_extended_len;
 
        /* pre-populate CPT INST word 4 */
        inst_w4.u64 = 0;
        inst_w4.s.opcode_major = ROC_IE_OT_MAJOR_OP_PROCESS_OUTBOUND_IPSEC;
-       inst_w4.s.param1 = 0;
+
+       param1.u16 = 0;
+
+       /* Disable IP checksum computation by default */
+       param1.s.ip_csum_disable = ROC_IE_OT_SA_INNER_PKT_IP_CSUM_DISABLE;
+
+       if (ipsec_xfrm->options.ip_csum_enable) {
+               param1.s.ip_csum_disable =
+                       ROC_IE_OT_SA_INNER_PKT_IP_CSUM_ENABLE;
+       }
+
+       /* Disable L4 checksum computation by default */
+       param1.s.l4_csum_disable = ROC_IE_OT_SA_INNER_PKT_L4_CSUM_DISABLE;
+
+       if (ipsec_xfrm->options.l4_csum_enable) {
+               param1.s.l4_csum_disable =
+                       ROC_IE_OT_SA_INNER_PKT_L4_CSUM_ENABLE;
+       }
+
+       inst_w4.s.param1 = param1.u16;
+
        sa->inst.w4 = inst_w4.u64;
 
        return 0;
@@ -134,6 +116,7 @@ cn10k_ipsec_inb_sa_create(struct roc_cpt *roc_cpt,
                          struct rte_crypto_sym_xform *crypto_xfrm,
                          struct rte_security_session *sec_sess)
 {
+       union roc_ot_ipsec_inb_param1 param1;
        struct roc_ot_ipsec_inb_sa *in_sa;
        struct cn10k_sec_session *sess;
        struct cn10k_ipsec_sa *sa;
@@ -160,8 +143,29 @@ cn10k_ipsec_inb_sa_create(struct roc_cpt *roc_cpt,
        inst_w4.u64 = 0;
        inst_w4.s.opcode_major = ROC_IE_OT_MAJOR_OP_PROCESS_INBOUND_IPSEC;
 
-       /* Disable checksum verification for now */
-       inst_w4.s.param1 = 7;
+       param1.u16 = 0;
+
+       /* Disable IP checksum verification by default */
+       param1.s.ip_csum_disable = ROC_IE_OT_SA_INNER_PKT_IP_CSUM_DISABLE;
+
+       if (ipsec_xfrm->options.ip_csum_enable) {
+               param1.s.ip_csum_disable =
+                       ROC_IE_OT_SA_INNER_PKT_IP_CSUM_ENABLE;
+               sa->ip_csum_enable = true;
+       }
+
+       /* Disable L4 checksum verification by default */
+       param1.s.l4_csum_disable = ROC_IE_OT_SA_INNER_PKT_L4_CSUM_DISABLE;
+
+       if (ipsec_xfrm->options.l4_csum_enable) {
+               param1.s.l4_csum_disable =
+                       ROC_IE_OT_SA_INNER_PKT_L4_CSUM_ENABLE;
+       }
+
+       param1.s.esp_trailer_disable = 1;
+
+       inst_w4.s.param1 = param1.u16;
+
        sa->inst.w4 = inst_w4.u64;
 
        return 0;
@@ -186,7 +190,7 @@ cn10k_ipsec_session_create(void *dev,
                return -EPERM;
        }
 
-       ret = cn10k_ipsec_xform_verify(ipsec_xfrm, crypto_xfrm);
+       ret = cnxk_ipsec_xform_verify(ipsec_xfrm, crypto_xfrm);
        if (ret)
                return ret;
 
@@ -209,9 +213,6 @@ cn10k_sec_session_create(void *device, struct rte_security_session_conf *conf,
        if (conf->action_type != RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL)
                return -EINVAL;
 
-       if (rte_security_dynfield_register() < 0)
-               return -ENOTSUP;
-
        if (rte_mempool_get(mempool, (void **)&priv)) {
                plt_err("Could not allocate security session private data");
                return -ENOMEM;
@@ -219,8 +220,6 @@ cn10k_sec_session_create(void *device, struct rte_security_session_conf *conf,
 
        set_sec_session_private_data(sess, priv);
 
-       priv->userdata = conf->userdata;
-
        if (conf->protocol != RTE_SECURITY_PROTOCOL_IPSEC) {
                ret = -ENOTSUP;
                goto mempool_put;