crypto/dpaa_sec: support null cipher and null auth
[dpdk.git] / drivers / crypto / dpaa_sec / dpaa_sec.c
index 17c1756..2e18cce 100644 (file)
@@ -15,7 +15,9 @@
 #include <rte_cryptodev_pmd.h>
 #include <rte_crypto.h>
 #include <rte_cryptodev.h>
+#ifdef RTE_LIBRTE_SECURITY
 #include <rte_security_driver.h>
+#endif
 #include <rte_cycles.h>
 #include <rte_dev.h>
 #include <rte_kvargs.h>
 
 #include <fsl_usd.h>
 #include <fsl_qman.h>
-#include <of.h>
+#include <dpaa_of.h>
 
 /* RTA header files */
-#include <hw/desc/common.h>
-#include <hw/desc/algo.h>
-#include <hw/desc/ipsec.h>
-#include <hw/desc/pdcp.h>
+#include <desc/common.h>
+#include <desc/algo.h>
+#include <desc/ipsec.h>
+#include <desc/pdcp.h>
 
 #include <rte_dpaa_bus.h>
 #include <dpaa_sec.h>
@@ -242,43 +244,6 @@ dpaa_sec_init_tx(struct qman_fq *fq)
        return ret;
 }
 
-static inline int is_cipher_only(dpaa_sec_session *ses)
-{
-       return ((ses->cipher_alg != RTE_CRYPTO_CIPHER_NULL) &&
-               (ses->auth_alg == RTE_CRYPTO_AUTH_NULL));
-}
-
-static inline int is_auth_only(dpaa_sec_session *ses)
-{
-       return ((ses->cipher_alg == RTE_CRYPTO_CIPHER_NULL) &&
-               (ses->auth_alg != RTE_CRYPTO_AUTH_NULL));
-}
-
-static inline int is_aead(dpaa_sec_session *ses)
-{
-       return ((ses->cipher_alg == 0) &&
-               (ses->auth_alg == 0) &&
-               (ses->aead_alg != 0));
-}
-
-static inline int is_auth_cipher(dpaa_sec_session *ses)
-{
-       return ((ses->cipher_alg != RTE_CRYPTO_CIPHER_NULL) &&
-               (ses->auth_alg != RTE_CRYPTO_AUTH_NULL) &&
-               (ses->proto_alg != RTE_SECURITY_PROTOCOL_PDCP) &&
-               (ses->proto_alg != RTE_SECURITY_PROTOCOL_IPSEC));
-}
-
-static inline int is_proto_ipsec(dpaa_sec_session *ses)
-{
-       return (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC);
-}
-
-static inline int is_proto_pdcp(dpaa_sec_session *ses)
-{
-       return (ses->proto_alg == RTE_SECURITY_PROTOCOL_PDCP);
-}
-
 static inline int is_encode(dpaa_sec_session *ses)
 {
        return ses->dir == DIR_ENC;
@@ -289,102 +254,7 @@ static inline int is_decode(dpaa_sec_session *ses)
        return ses->dir == DIR_DEC;
 }
 
-static inline void
-caam_auth_alg(dpaa_sec_session *ses, struct alginfo *alginfo_a)
-{
-       switch (ses->auth_alg) {
-       case RTE_CRYPTO_AUTH_NULL:
-               alginfo_a->algtype =
-                       (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
-                       OP_PCL_IPSEC_HMAC_NULL : 0;
-               ses->digest_length = 0;
-               break;
-       case RTE_CRYPTO_AUTH_MD5_HMAC:
-               alginfo_a->algtype =
-                       (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
-                       OP_PCL_IPSEC_HMAC_MD5_96 : OP_ALG_ALGSEL_MD5;
-               alginfo_a->algmode = OP_ALG_AAI_HMAC;
-               break;
-       case RTE_CRYPTO_AUTH_SHA1_HMAC:
-               alginfo_a->algtype =
-                       (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
-                       OP_PCL_IPSEC_HMAC_SHA1_96 : OP_ALG_ALGSEL_SHA1;
-               alginfo_a->algmode = OP_ALG_AAI_HMAC;
-               break;
-       case RTE_CRYPTO_AUTH_SHA224_HMAC:
-               alginfo_a->algtype =
-                       (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
-                       OP_PCL_IPSEC_HMAC_SHA1_160 : OP_ALG_ALGSEL_SHA224;
-               alginfo_a->algmode = OP_ALG_AAI_HMAC;
-               break;
-       case RTE_CRYPTO_AUTH_SHA256_HMAC:
-               alginfo_a->algtype =
-                       (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
-                       OP_PCL_IPSEC_HMAC_SHA2_256_128 : OP_ALG_ALGSEL_SHA256;
-               alginfo_a->algmode = OP_ALG_AAI_HMAC;
-               break;
-       case RTE_CRYPTO_AUTH_SHA384_HMAC:
-               alginfo_a->algtype =
-                       (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
-                       OP_PCL_IPSEC_HMAC_SHA2_384_192 : OP_ALG_ALGSEL_SHA384;
-               alginfo_a->algmode = OP_ALG_AAI_HMAC;
-               break;
-       case RTE_CRYPTO_AUTH_SHA512_HMAC:
-               alginfo_a->algtype =
-                       (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
-                       OP_PCL_IPSEC_HMAC_SHA2_512_256 : OP_ALG_ALGSEL_SHA512;
-               alginfo_a->algmode = OP_ALG_AAI_HMAC;
-               break;
-       default:
-               DPAA_SEC_ERR("unsupported auth alg %u", ses->auth_alg);
-       }
-}
-
-static inline void
-caam_cipher_alg(dpaa_sec_session *ses, struct alginfo *alginfo_c)
-{
-       switch (ses->cipher_alg) {
-       case RTE_CRYPTO_CIPHER_NULL:
-               alginfo_c->algtype =
-                       (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
-                       OP_PCL_IPSEC_NULL : 0;
-               break;
-       case RTE_CRYPTO_CIPHER_AES_CBC:
-               alginfo_c->algtype =
-                       (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
-                       OP_PCL_IPSEC_AES_CBC : OP_ALG_ALGSEL_AES;
-               alginfo_c->algmode = OP_ALG_AAI_CBC;
-               break;
-       case RTE_CRYPTO_CIPHER_3DES_CBC:
-               alginfo_c->algtype =
-                       (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
-                       OP_PCL_IPSEC_3DES : OP_ALG_ALGSEL_3DES;
-               alginfo_c->algmode = OP_ALG_AAI_CBC;
-               break;
-       case RTE_CRYPTO_CIPHER_AES_CTR:
-               alginfo_c->algtype =
-                       (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
-                       OP_PCL_IPSEC_AES_CTR : OP_ALG_ALGSEL_AES;
-               alginfo_c->algmode = OP_ALG_AAI_CTR;
-               break;
-       default:
-               DPAA_SEC_ERR("unsupported cipher alg %d", ses->cipher_alg);
-       }
-}
-
-static inline void
-caam_aead_alg(dpaa_sec_session *ses, struct alginfo *alginfo)
-{
-       switch (ses->aead_alg) {
-       case RTE_CRYPTO_AEAD_AES_GCM:
-               alginfo->algtype = OP_ALG_ALGSEL_AES;
-               alginfo->algmode = OP_ALG_AAI_GCM;
-               break;
-       default:
-               DPAA_SEC_ERR("unsupported AEAD alg %d", ses->aead_alg);
-       }
-}
-
+#ifdef RTE_LIBRTE_SECURITY
 static int
 dpaa_sec_prep_pdcp_cdb(dpaa_sec_session *ses)
 {
@@ -399,58 +269,24 @@ dpaa_sec_prep_pdcp_cdb(dpaa_sec_session *ses)
        int swap = true;
 #endif
 
-       switch (ses->cipher_alg) {
-       case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
-               cipherdata.algtype = PDCP_CIPHER_TYPE_SNOW;
-               break;
-       case RTE_CRYPTO_CIPHER_ZUC_EEA3:
-               cipherdata.algtype = PDCP_CIPHER_TYPE_ZUC;
-               break;
-       case RTE_CRYPTO_CIPHER_AES_CTR:
-               cipherdata.algtype = PDCP_CIPHER_TYPE_AES;
-               break;
-       case RTE_CRYPTO_CIPHER_NULL:
-               cipherdata.algtype = PDCP_CIPHER_TYPE_NULL;
-               break;
-       default:
-               DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
-                             ses->cipher_alg);
-               return -1;
-       }
-
        cipherdata.key = (size_t)ses->cipher_key.data;
        cipherdata.keylen = ses->cipher_key.length;
        cipherdata.key_enc_flags = 0;
        cipherdata.key_type = RTA_DATA_IMM;
+       cipherdata.algtype = ses->cipher_key.alg;
+       cipherdata.algmode = ses->cipher_key.algmode;
 
        cdb->sh_desc[0] = cipherdata.keylen;
        cdb->sh_desc[1] = 0;
        cdb->sh_desc[2] = 0;
 
        if (ses->auth_alg) {
-               switch (ses->auth_alg) {
-               case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
-                       authdata.algtype = PDCP_AUTH_TYPE_SNOW;
-                       break;
-               case RTE_CRYPTO_AUTH_ZUC_EIA3:
-                       authdata.algtype = PDCP_AUTH_TYPE_ZUC;
-                       break;
-               case RTE_CRYPTO_AUTH_AES_CMAC:
-                       authdata.algtype = PDCP_AUTH_TYPE_AES;
-                       break;
-               case RTE_CRYPTO_AUTH_NULL:
-                       authdata.algtype = PDCP_AUTH_TYPE_NULL;
-                       break;
-               default:
-                       DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
-                                     ses->auth_alg);
-                       return -1;
-               }
-
                authdata.key = (size_t)ses->auth_key.data;
                authdata.keylen = ses->auth_key.length;
                authdata.key_enc_flags = 0;
                authdata.key_type = RTA_DATA_IMM;
+               authdata.algtype = ses->auth_key.alg;
+               authdata.algmode = ses->auth_key.algmode;
 
                p_authdata = &authdata;
 
@@ -522,7 +358,6 @@ dpaa_sec_prep_pdcp_cdb(dpaa_sec_session *ses)
                                        ses->pdcp.hfn_threshold,
                                        &cipherdata, p_authdata, 0);
        }
-
        return shared_desc_len;
 }
 
@@ -540,27 +375,19 @@ dpaa_sec_prep_ipsec_cdb(dpaa_sec_session *ses)
        int swap = true;
 #endif
 
-       caam_cipher_alg(ses, &cipherdata);
-       if (cipherdata.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
-               DPAA_SEC_ERR("not supported cipher alg");
-               return -ENOTSUP;
-       }
-
        cipherdata.key = (size_t)ses->cipher_key.data;
        cipherdata.keylen = ses->cipher_key.length;
        cipherdata.key_enc_flags = 0;
        cipherdata.key_type = RTA_DATA_IMM;
-
-       caam_auth_alg(ses, &authdata);
-       if (authdata.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
-               DPAA_SEC_ERR("not supported auth alg");
-               return -ENOTSUP;
-       }
+       cipherdata.algtype = ses->cipher_key.alg;
+       cipherdata.algmode = ses->cipher_key.algmode;
 
        authdata.key = (size_t)ses->auth_key.data;
        authdata.keylen = ses->auth_key.length;
        authdata.key_enc_flags = 0;
        authdata.key_type = RTA_DATA_IMM;
+       authdata.algtype = ses->auth_key.alg;
+       authdata.algmode = ses->auth_key.algmode;
 
        cdb->sh_desc[0] = cipherdata.keylen;
        cdb->sh_desc[1] = authdata.keylen;
@@ -607,7 +434,7 @@ dpaa_sec_prep_ipsec_cdb(dpaa_sec_session *ses)
        }
        return shared_desc_len;
 }
-
+#endif
 /* prepare command block of the session */
 static int
 dpaa_sec_prep_cdb(dpaa_sec_session *ses)
@@ -624,46 +451,92 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
 
        memset(cdb, 0, sizeof(struct sec_cdb));
 
-       if (is_proto_ipsec(ses)) {
+       switch (ses->ctxt) {
+#ifdef RTE_LIBRTE_SECURITY
+       case DPAA_SEC_IPSEC:
                shared_desc_len = dpaa_sec_prep_ipsec_cdb(ses);
-       } else if (is_proto_pdcp(ses)) {
+               break;
+       case DPAA_SEC_PDCP:
                shared_desc_len = dpaa_sec_prep_pdcp_cdb(ses);
-       } else if (is_cipher_only(ses)) {
-               caam_cipher_alg(ses, &alginfo_c);
-               if (alginfo_c.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
-                       DPAA_SEC_ERR("not supported cipher alg");
-                       return -ENOTSUP;
-               }
-
+               break;
+#endif
+       case DPAA_SEC_CIPHER:
                alginfo_c.key = (size_t)ses->cipher_key.data;
                alginfo_c.keylen = ses->cipher_key.length;
                alginfo_c.key_enc_flags = 0;
                alginfo_c.key_type = RTA_DATA_IMM;
+               alginfo_c.algtype = ses->cipher_key.alg;
+               alginfo_c.algmode = ses->cipher_key.algmode;
 
-               shared_desc_len = cnstr_shdsc_blkcipher(
-                                               cdb->sh_desc, true,
-                                               swap, SHR_NEVER, &alginfo_c,
-                                               NULL,
-                                               ses->iv.length,
-                                               ses->dir);
-       } else if (is_auth_only(ses)) {
-               caam_auth_alg(ses, &alginfo_a);
-               if (alginfo_a.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
-                       DPAA_SEC_ERR("not supported auth alg");
+               switch (ses->cipher_alg) {
+               case RTE_CRYPTO_CIPHER_AES_CBC:
+               case RTE_CRYPTO_CIPHER_3DES_CBC:
+               case RTE_CRYPTO_CIPHER_AES_CTR:
+               case RTE_CRYPTO_CIPHER_3DES_CTR:
+                       shared_desc_len = cnstr_shdsc_blkcipher(
+                                       cdb->sh_desc, true,
+                                       swap, SHR_NEVER, &alginfo_c,
+                                       NULL,
+                                       ses->iv.length,
+                                       ses->dir);
+                       break;
+               case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
+                       shared_desc_len = cnstr_shdsc_snow_f8(
+                                       cdb->sh_desc, true, swap,
+                                       &alginfo_c,
+                                       ses->dir);
+                       break;
+               case RTE_CRYPTO_CIPHER_ZUC_EEA3:
+                       shared_desc_len = cnstr_shdsc_zuce(
+                                       cdb->sh_desc, true, swap,
+                                       &alginfo_c,
+                                       ses->dir);
+                       break;
+               default:
+                       DPAA_SEC_ERR("unsupported cipher alg %d",
+                                    ses->cipher_alg);
                        return -ENOTSUP;
                }
-
+               break;
+       case DPAA_SEC_AUTH:
                alginfo_a.key = (size_t)ses->auth_key.data;
                alginfo_a.keylen = ses->auth_key.length;
                alginfo_a.key_enc_flags = 0;
                alginfo_a.key_type = RTA_DATA_IMM;
-
-               shared_desc_len = cnstr_shdsc_hmac(cdb->sh_desc, true,
-                                                  swap, SHR_NEVER, &alginfo_a,
-                                                  !ses->dir,
-                                                  ses->digest_length);
-       } else if (is_aead(ses)) {
-               caam_aead_alg(ses, &alginfo);
+               alginfo_a.algtype = ses->auth_key.alg;
+               alginfo_a.algmode = ses->auth_key.algmode;
+               switch (ses->auth_alg) {
+               case RTE_CRYPTO_AUTH_MD5_HMAC:
+               case RTE_CRYPTO_AUTH_SHA1_HMAC:
+               case RTE_CRYPTO_AUTH_SHA224_HMAC:
+               case RTE_CRYPTO_AUTH_SHA256_HMAC:
+               case RTE_CRYPTO_AUTH_SHA384_HMAC:
+               case RTE_CRYPTO_AUTH_SHA512_HMAC:
+                       shared_desc_len = cnstr_shdsc_hmac(
+                                               cdb->sh_desc, true,
+                                               swap, SHR_NEVER, &alginfo_a,
+                                               !ses->dir,
+                                               ses->digest_length);
+                       break;
+               case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
+                       shared_desc_len = cnstr_shdsc_snow_f9(
+                                               cdb->sh_desc, true, swap,
+                                               &alginfo_a,
+                                               !ses->dir,
+                                               ses->digest_length);
+                       break;
+               case RTE_CRYPTO_AUTH_ZUC_EIA3:
+                       shared_desc_len = cnstr_shdsc_zuca(
+                                               cdb->sh_desc, true, swap,
+                                               &alginfo_a,
+                                               !ses->dir,
+                                               ses->digest_length);
+                       break;
+               default:
+                       DPAA_SEC_ERR("unsupported auth alg %u", ses->auth_alg);
+               }
+               break;
+       case DPAA_SEC_AEAD:
                if (alginfo.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
                        DPAA_SEC_ERR("not supported aead alg");
                        return -ENOTSUP;
@@ -672,6 +545,8 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
                alginfo.keylen = ses->aead_key.length;
                alginfo.key_enc_flags = 0;
                alginfo.key_type = RTA_DATA_IMM;
+               alginfo.algtype = ses->aead_key.alg;
+               alginfo.algmode = ses->aead_key.algmode;
 
                if (ses->dir == DIR_ENC)
                        shared_desc_len = cnstr_shdsc_gcm_encap(
@@ -685,28 +560,21 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
                                        &alginfo,
                                        ses->iv.length,
                                        ses->digest_length);
-       } else {
-               caam_cipher_alg(ses, &alginfo_c);
-               if (alginfo_c.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
-                       DPAA_SEC_ERR("not supported cipher alg");
-                       return -ENOTSUP;
-               }
-
+               break;
+       case DPAA_SEC_CIPHER_HASH:
                alginfo_c.key = (size_t)ses->cipher_key.data;
                alginfo_c.keylen = ses->cipher_key.length;
                alginfo_c.key_enc_flags = 0;
                alginfo_c.key_type = RTA_DATA_IMM;
-
-               caam_auth_alg(ses, &alginfo_a);
-               if (alginfo_a.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
-                       DPAA_SEC_ERR("not supported auth alg");
-                       return -ENOTSUP;
-               }
+               alginfo_c.algtype = ses->cipher_key.alg;
+               alginfo_c.algmode = ses->cipher_key.algmode;
 
                alginfo_a.key = (size_t)ses->auth_key.data;
                alginfo_a.keylen = ses->auth_key.length;
                alginfo_a.key_enc_flags = 0;
                alginfo_a.key_type = RTA_DATA_IMM;
+               alginfo_a.algtype = ses->auth_key.alg;
+               alginfo_a.algmode = ses->auth_key.algmode;
 
                cdb->sh_desc[0] = alginfo_c.keylen;
                cdb->sh_desc[1] = alginfo_a.keylen;
@@ -741,8 +609,13 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
                 */
                shared_desc_len = cnstr_shdsc_authenc(cdb->sh_desc,
                                true, swap, SHR_SERIAL, &alginfo_c, &alginfo_a,
-                               ses->iv.length, 0,
+                               ses->iv.length,
                                ses->digest_length, ses->dir);
+               break;
+       case DPAA_SEC_HASH_CIPHER:
+       default:
+               DPAA_SEC_ERR("error: Unsupported session");
+               return -ENOTSUP;
        }
 
        if (shared_desc_len < 0) {
@@ -848,6 +721,21 @@ build_auth_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
        struct qm_sg_entry *sg, *out_sg, *in_sg;
        phys_addr_t start_addr;
        uint8_t *old_digest, extra_segs;
+       int data_len, data_offset;
+
+       data_len = sym->auth.data.length;
+       data_offset = sym->auth.data.offset;
+
+       if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
+           ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
+               if ((data_len & 7) || (data_offset & 7)) {
+                       DPAA_SEC_ERR("AUTH: len/offset must be full bytes");
+                       return NULL;
+               }
+
+               data_len = data_len >> 3;
+               data_offset = data_offset >> 3;
+       }
 
        if (is_decode(ses))
                extra_segs = 3;
@@ -878,23 +766,52 @@ build_auth_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
        /* need to extend the input to a compound frame */
        in_sg->extension = 1;
        in_sg->final = 1;
-       in_sg->length = sym->auth.data.length;
+       in_sg->length = data_len;
        qm_sg_entry_set64(in_sg, dpaa_mem_vtop(&cf->sg[2]));
 
        /* 1st seg */
        sg = in_sg + 1;
-       qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
-       sg->length = mbuf->data_len - sym->auth.data.offset;
-       sg->offset = sym->auth.data.offset;
 
-       /* Successive segs */
-       mbuf = mbuf->next;
-       while (mbuf) {
+       if (ses->iv.length) {
+               uint8_t *iv_ptr;
+
+               iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
+                                                  ses->iv.offset);
+
+               if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
+                       iv_ptr = conv_to_snow_f9_iv(iv_ptr);
+                       sg->length = 12;
+               } else if (ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
+                       iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
+                       sg->length = 8;
+               } else {
+                       sg->length = ses->iv.length;
+               }
+               qm_sg_entry_set64(sg, dpaa_mem_vtop(iv_ptr));
+               in_sg->length += sg->length;
                cpu_to_hw_sg(sg);
                sg++;
-               qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
-               sg->length = mbuf->data_len;
-               mbuf = mbuf->next;
+       }
+
+       qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
+       sg->offset = data_offset;
+
+       if (data_len <= (mbuf->data_len - data_offset)) {
+               sg->length = data_len;
+       } else {
+               sg->length = mbuf->data_len - data_offset;
+
+               /* remaining i/p segs */
+               while ((data_len = data_len - sg->length) &&
+                      (mbuf = mbuf->next)) {
+                       cpu_to_hw_sg(sg);
+                       sg++;
+                       qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
+                       if (data_len > mbuf->data_len)
+                               sg->length = mbuf->data_len;
+                       else
+                               sg->length = data_len;
+               }
        }
 
        if (is_decode(ses)) {
@@ -907,9 +824,6 @@ build_auth_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
                qm_sg_entry_set64(sg, start_addr);
                sg->length = ses->digest_length;
                in_sg->length += ses->digest_length;
-       } else {
-               /* Digest calculation case */
-               sg->length -= ses->digest_length;
        }
        sg->final = 1;
        cpu_to_hw_sg(sg);
@@ -933,9 +847,24 @@ build_auth_only(struct rte_crypto_op *op, dpaa_sec_session *ses)
        struct rte_mbuf *mbuf = sym->m_src;
        struct dpaa_sec_job *cf;
        struct dpaa_sec_op_ctx *ctx;
-       struct qm_sg_entry *sg;
+       struct qm_sg_entry *sg, *in_sg;
        rte_iova_t start_addr;
        uint8_t *old_digest;
+       int data_len, data_offset;
+
+       data_len = sym->auth.data.length;
+       data_offset = sym->auth.data.offset;
+
+       if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
+           ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
+               if ((data_len & 7) || (data_offset & 7)) {
+                       DPAA_SEC_ERR("AUTH: len/offset must be full bytes");
+                       return NULL;
+               }
+
+               data_len = data_len >> 3;
+               data_offset = data_offset >> 3;
+       }
 
        ctx = dpaa_sec_alloc_ctx(ses, 4);
        if (!ctx)
@@ -953,36 +882,55 @@ build_auth_only(struct rte_crypto_op *op, dpaa_sec_session *ses)
        cpu_to_hw_sg(sg);
 
        /* input */
-       sg = &cf->sg[1];
-       if (is_decode(ses)) {
-               /* need to extend the input to a compound frame */
-               sg->extension = 1;
-               qm_sg_entry_set64(sg, dpaa_mem_vtop(&cf->sg[2]));
-               sg->length = sym->auth.data.length + ses->digest_length;
-               sg->final = 1;
+       in_sg = &cf->sg[1];
+       /* need to extend the input to a compound frame */
+       in_sg->extension = 1;
+       in_sg->final = 1;
+       in_sg->length = data_len;
+       qm_sg_entry_set64(in_sg, dpaa_mem_vtop(&cf->sg[2]));
+       sg = &cf->sg[2];
+
+       if (ses->iv.length) {
+               uint8_t *iv_ptr;
+
+               iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
+                                                  ses->iv.offset);
+
+               if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
+                       iv_ptr = conv_to_snow_f9_iv(iv_ptr);
+                       sg->length = 12;
+               } else if (ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
+                       iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
+                       sg->length = 8;
+               } else {
+                       sg->length = ses->iv.length;
+               }
+               qm_sg_entry_set64(sg, dpaa_mem_vtop(iv_ptr));
+               in_sg->length += sg->length;
                cpu_to_hw_sg(sg);
+               sg++;
+       }
+
+       qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
+       sg->offset = data_offset;
+       sg->length = data_len;
 
-               sg = &cf->sg[2];
+       if (is_decode(ses)) {
+               /* Digest verification case */
+               cpu_to_hw_sg(sg);
                /* hash result or digest, save digest first */
                rte_memcpy(old_digest, sym->auth.digest.data,
-                          ses->digest_length);
-               qm_sg_entry_set64(sg, start_addr + sym->auth.data.offset);
-               sg->length = sym->auth.data.length;
-               cpu_to_hw_sg(sg);
-
+                               ses->digest_length);
                /* let's check digest by hw */
                start_addr = dpaa_mem_vtop(old_digest);
                sg++;
                qm_sg_entry_set64(sg, start_addr);
                sg->length = ses->digest_length;
-               sg->final = 1;
-               cpu_to_hw_sg(sg);
-       } else {
-               qm_sg_entry_set64(sg, start_addr + sym->auth.data.offset);
-               sg->length = sym->auth.data.length;
-               sg->final = 1;
-               cpu_to_hw_sg(sg);
+               in_sg->length += ses->digest_length;
        }
+       sg->final = 1;
+       cpu_to_hw_sg(sg);
+       cpu_to_hw_sg(in_sg);
 
        return cf;
 }
@@ -998,6 +946,21 @@ build_cipher_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
        uint8_t req_segs;
        uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
                        ses->iv.offset);
+       int data_len, data_offset;
+
+       data_len = sym->cipher.data.length;
+       data_offset = sym->cipher.data.offset;
+
+       if (ses->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
+               ses->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
+               if ((data_len & 7) || (data_offset & 7)) {
+                       DPAA_SEC_ERR("CIPHER: len/offset must be full bytes");
+                       return NULL;
+               }
+
+               data_len = data_len >> 3;
+               data_offset = data_offset >> 3;
+       }
 
        if (sym->m_dst) {
                mbuf = sym->m_dst;
@@ -1006,7 +969,6 @@ build_cipher_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
                mbuf = sym->m_src;
                req_segs = mbuf->nb_segs * 2 + 3;
        }
-
        if (mbuf->nb_segs > MAX_SG_ENTRIES) {
                DPAA_SEC_DP_ERR("Cipher: Max sec segs supported is %d",
                                MAX_SG_ENTRIES);
@@ -1023,15 +985,15 @@ build_cipher_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
        /* output */
        out_sg = &cf->sg[0];
        out_sg->extension = 1;
-       out_sg->length = sym->cipher.data.length;
+       out_sg->length = data_len;
        qm_sg_entry_set64(out_sg, dpaa_mem_vtop(&cf->sg[2]));
        cpu_to_hw_sg(out_sg);
 
        /* 1st seg */
        sg = &cf->sg[2];
        qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
-       sg->length = mbuf->data_len - sym->cipher.data.offset;
-       sg->offset = sym->cipher.data.offset;
+       sg->length = mbuf->data_len - data_offset;
+       sg->offset = data_offset;
 
        /* Successive segs */
        mbuf = mbuf->next;
@@ -1050,7 +1012,7 @@ build_cipher_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
        in_sg = &cf->sg[1];
        in_sg->extension = 1;
        in_sg->final = 1;
-       in_sg->length = sym->cipher.data.length + ses->iv.length;
+       in_sg->length = data_len + ses->iv.length;
 
        sg++;
        qm_sg_entry_set64(in_sg, dpaa_mem_vtop(sg));
@@ -1064,8 +1026,8 @@ build_cipher_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
        /* 1st seg */
        sg++;
        qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
-       sg->length = mbuf->data_len - sym->cipher.data.offset;
-       sg->offset = sym->cipher.data.offset;
+       sg->length = mbuf->data_len - data_offset;
+       sg->offset = data_offset;
 
        /* Successive segs */
        mbuf = mbuf->next;
@@ -1092,6 +1054,21 @@ build_cipher_only(struct rte_crypto_op *op, dpaa_sec_session *ses)
        rte_iova_t src_start_addr, dst_start_addr;
        uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
                        ses->iv.offset);
+       int data_len, data_offset;
+
+       data_len = sym->cipher.data.length;
+       data_offset = sym->cipher.data.offset;
+
+       if (ses->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
+               ses->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
+               if ((data_len & 7) || (data_offset & 7)) {
+                       DPAA_SEC_ERR("CIPHER: len/offset must be full bytes");
+                       return NULL;
+               }
+
+               data_len = data_len >> 3;
+               data_offset = data_offset >> 3;
+       }
 
        ctx = dpaa_sec_alloc_ctx(ses, 4);
        if (!ctx)
@@ -1109,8 +1086,8 @@ build_cipher_only(struct rte_crypto_op *op, dpaa_sec_session *ses)
 
        /* output */
        sg = &cf->sg[0];
-       qm_sg_entry_set64(sg, dst_start_addr + sym->cipher.data.offset);
-       sg->length = sym->cipher.data.length + ses->iv.length;
+       qm_sg_entry_set64(sg, dst_start_addr + data_offset);
+       sg->length = data_len + ses->iv.length;
        cpu_to_hw_sg(sg);
 
        /* input */
@@ -1119,7 +1096,7 @@ build_cipher_only(struct rte_crypto_op *op, dpaa_sec_session *ses)
        /* need to extend the input to a compound frame */
        sg->extension = 1;
        sg->final = 1;
-       sg->length = sym->cipher.data.length + ses->iv.length;
+       sg->length = data_len + ses->iv.length;
        qm_sg_entry_set64(sg, dpaa_mem_vtop(&cf->sg[2]));
        cpu_to_hw_sg(sg);
 
@@ -1129,8 +1106,8 @@ build_cipher_only(struct rte_crypto_op *op, dpaa_sec_session *ses)
        cpu_to_hw_sg(sg);
 
        sg++;
-       qm_sg_entry_set64(sg, src_start_addr + sym->cipher.data.offset);
-       sg->length = sym->cipher.data.length;
+       qm_sg_entry_set64(sg, src_start_addr + data_offset);
+       sg->length = data_len;
        sg->final = 1;
        cpu_to_hw_sg(sg);
 
@@ -1179,10 +1156,9 @@ build_cipher_auth_gcm_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
        out_sg = &cf->sg[0];
        out_sg->extension = 1;
        if (is_encode(ses))
-               out_sg->length = sym->aead.data.length + ses->auth_only_len
-                                               + ses->digest_length;
+               out_sg->length = sym->aead.data.length + ses->digest_length;
        else
-               out_sg->length = sym->aead.data.length + ses->auth_only_len;
+               out_sg->length = sym->aead.data.length;
 
        /* output sg entries */
        sg = &cf->sg[2];
@@ -1191,9 +1167,8 @@ build_cipher_auth_gcm_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
 
        /* 1st seg */
        qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
-       sg->length = mbuf->data_len - sym->aead.data.offset +
-                                       ses->auth_only_len;
-       sg->offset = sym->aead.data.offset - ses->auth_only_len;
+       sg->length = mbuf->data_len - sym->aead.data.offset;
+       sg->offset = sym->aead.data.offset;
 
        /* Successive segs */
        mbuf = mbuf->next;
@@ -1366,8 +1341,8 @@ build_cipher_auth_gcm(struct rte_crypto_op *op, dpaa_sec_session *ses)
        sg++;
        qm_sg_entry_set64(&cf->sg[0], dpaa_mem_vtop(sg));
        qm_sg_entry_set64(sg,
-               dst_start_addr + sym->aead.data.offset - ses->auth_only_len);
-       sg->length = sym->aead.data.length + ses->auth_only_len;
+               dst_start_addr + sym->aead.data.offset);
+       sg->length = sym->aead.data.length;
        length = sg->length;
        if (is_encode(ses)) {
                cpu_to_hw_sg(sg);
@@ -1609,6 +1584,7 @@ build_cipher_auth(struct rte_crypto_op *op, dpaa_sec_session *ses)
        return cf;
 }
 
+#ifdef RTE_LIBRTE_SECURITY
 static inline struct dpaa_sec_job *
 build_proto(struct rte_crypto_op *op, dpaa_sec_session *ses)
 {
@@ -1740,6 +1716,7 @@ build_proto_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
 
        return cf;
 }
+#endif
 
 static uint16_t
 dpaa_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
@@ -1754,7 +1731,8 @@ dpaa_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
        struct rte_crypto_op *op;
        struct dpaa_sec_job *cf;
        dpaa_sec_session *ses;
-       uint32_t auth_only_len, index, flags[DPAA_SEC_BURST] = {0};
+       uint16_t auth_hdr_len, auth_tail_len;
+       uint32_t index, flags[DPAA_SEC_BURST] = {0};
        struct qman_fq *inq[DPAA_SEC_BURST];
 
        while (nb_ops) {
@@ -1781,11 +1759,13 @@ dpaa_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
                                                        op->sym->session,
                                                        cryptodev_driver_id);
                                break;
+#ifdef RTE_LIBRTE_SECURITY
                        case RTE_CRYPTO_OP_SECURITY_SESSION:
                                ses = (dpaa_sec_session *)
                                        get_sec_session_private_data(
                                                        op->sym->sec_session);
                                break;
+#endif
                        default:
                                DPAA_SEC_DP_ERR(
                                        "sessionless crypto op not supported");
@@ -1793,6 +1773,14 @@ dpaa_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
                                nb_ops = loop;
                                goto send_pkts;
                        }
+
+                       if (!ses) {
+                               DPAA_SEC_DP_ERR("session not available");
+                               frames_to_send = loop;
+                               nb_ops = loop;
+                               goto send_pkts;
+                       }
+
                        if (unlikely(!ses->qp[rte_lcore_id() % MAX_DPAA_CORES])) {
                                if (dpaa_sec_attach_sess_q(qp, ses)) {
                                        frames_to_send = loop;
@@ -1810,43 +1798,75 @@ dpaa_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
                                goto send_pkts;
                        }
 
-                       auth_only_len = op->sym->auth.data.length -
+                       auth_hdr_len = op->sym->auth.data.length -
                                                op->sym->cipher.data.length;
+                       auth_tail_len = 0;
+
                        if (rte_pktmbuf_is_contiguous(op->sym->m_src) &&
                                  ((op->sym->m_dst == NULL) ||
                                   rte_pktmbuf_is_contiguous(op->sym->m_dst))) {
-                               if (is_proto_ipsec(ses)) {
+                               switch (ses->ctxt) {
+#ifdef RTE_LIBRTE_SECURITY
+                               case DPAA_SEC_PDCP:
+                               case DPAA_SEC_IPSEC:
                                        cf = build_proto(op, ses);
-                               } else if (is_proto_pdcp(ses)) {
-                                       cf = build_proto(op, ses);
-                               } else if (is_auth_only(ses)) {
+                                       break;
+#endif
+                               case DPAA_SEC_AUTH:
                                        cf = build_auth_only(op, ses);
-                               } else if (is_cipher_only(ses)) {
+                                       break;
+                               case DPAA_SEC_CIPHER:
                                        cf = build_cipher_only(op, ses);
-                               } else if (is_aead(ses)) {
+                                       break;
+                               case DPAA_SEC_AEAD:
                                        cf = build_cipher_auth_gcm(op, ses);
-                                       auth_only_len = ses->auth_only_len;
-                               } else if (is_auth_cipher(ses)) {
+                                       auth_hdr_len = ses->auth_only_len;
+                                       break;
+                               case DPAA_SEC_CIPHER_HASH:
+                                       auth_hdr_len =
+                                               op->sym->cipher.data.offset
+                                               - op->sym->auth.data.offset;
+                                       auth_tail_len =
+                                               op->sym->auth.data.length
+                                               - op->sym->cipher.data.length
+                                               - auth_hdr_len;
                                        cf = build_cipher_auth(op, ses);
-                               } else {
+                                       break;
+                               default:
                                        DPAA_SEC_DP_ERR("not supported ops");
                                        frames_to_send = loop;
                                        nb_ops = loop;
                                        goto send_pkts;
                                }
                        } else {
-                               if (is_proto_pdcp(ses) || is_proto_ipsec(ses)) {
+                               switch (ses->ctxt) {
+#ifdef RTE_LIBRTE_SECURITY
+                               case DPAA_SEC_PDCP:
+                               case DPAA_SEC_IPSEC:
                                        cf = build_proto_sg(op, ses);
-                               } else if (is_auth_only(ses)) {
+                                       break;
+#endif
+                               case DPAA_SEC_AUTH:
                                        cf = build_auth_only_sg(op, ses);
-                               } else if (is_cipher_only(ses)) {
+                                       break;
+                               case DPAA_SEC_CIPHER:
                                        cf = build_cipher_only_sg(op, ses);
-                               } else if (is_aead(ses)) {
+                                       break;
+                               case DPAA_SEC_AEAD:
                                        cf = build_cipher_auth_gcm_sg(op, ses);
-                                       auth_only_len = ses->auth_only_len;
-                               } else if (is_auth_cipher(ses)) {
+                                       auth_hdr_len = ses->auth_only_len;
+                                       break;
+                               case DPAA_SEC_CIPHER_HASH:
+                                       auth_hdr_len =
+                                               op->sym->cipher.data.offset
+                                               - op->sym->auth.data.offset;
+                                       auth_tail_len =
+                                               op->sym->auth.data.length
+                                               - op->sym->cipher.data.length
+                                               - auth_hdr_len;
                                        cf = build_cipher_auth_sg(op, ses);
-                               } else {
+                                       break;
+                               default:
                                        DPAA_SEC_DP_ERR("not supported ops");
                                        frames_to_send = loop;
                                        nb_ops = loop;
@@ -1866,27 +1886,31 @@ dpaa_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
                        qm_fd_addr_set64(fd, dpaa_mem_vtop(cf->sg));
                        fd->_format1 = qm_fd_compound;
                        fd->length29 = 2 * sizeof(struct qm_sg_entry);
+
                        /* Auth_only_len is set as 0 in descriptor and it is
                         * overwritten here in the fd.cmd which will update
                         * the DPOVRD reg.
                         */
-                       if (auth_only_len)
-                               fd->cmd = 0x80000000 | auth_only_len;
+                       if (auth_hdr_len || auth_tail_len) {
+                               fd->cmd = 0x80000000;
+                               fd->cmd |=
+                                       ((auth_tail_len << 16) | auth_hdr_len);
+                       }
 
+#ifdef RTE_LIBRTE_SECURITY
                        /* In case of PDCP, per packet HFN is stored in
                         * mbuf priv after sym_op.
                         */
-                       if (is_proto_pdcp(ses) && ses->pdcp.hfn_ovd) {
+                       if ((ses->ctxt == DPAA_SEC_PDCP) && ses->pdcp.hfn_ovd) {
                                fd->cmd = 0x80000000 |
                                        *((uint32_t *)((uint8_t *)op +
                                        ses->pdcp.hfn_ovd_offset));
-                               DPAA_SEC_DP_DEBUG("Per packet HFN: %x, ovd:%u,%u\n",
+                               DPAA_SEC_DP_DEBUG("Per packet HFN: %x, ovd:%u\n",
                                        *((uint32_t *)((uint8_t *)op +
                                        ses->pdcp.hfn_ovd_offset)),
-                                       ses->pdcp.hfn_ovd,
-                                       is_proto_pdcp(ses));
+                                       ses->pdcp.hfn_ovd);
                        }
-
+#endif
                }
 send_pkts:
                loop = 0;
@@ -2013,6 +2037,7 @@ dpaa_sec_cipher_init(struct rte_cryptodev *dev __rte_unused,
                     struct rte_crypto_sym_xform *xform,
                     dpaa_sec_session *session)
 {
+       session->ctxt = DPAA_SEC_CIPHER;
        session->cipher_alg = xform->cipher.algo;
        session->iv.length = xform->cipher.iv.length;
        session->iv.offset = xform->cipher.iv.offset;
@@ -2026,6 +2051,31 @@ dpaa_sec_cipher_init(struct rte_cryptodev *dev __rte_unused,
 
        memcpy(session->cipher_key.data, xform->cipher.key.data,
               xform->cipher.key.length);
+       switch (xform->cipher.algo) {
+       case RTE_CRYPTO_CIPHER_AES_CBC:
+               session->cipher_key.alg = OP_ALG_ALGSEL_AES;
+               session->cipher_key.algmode = OP_ALG_AAI_CBC;
+               break;
+       case RTE_CRYPTO_CIPHER_3DES_CBC:
+               session->cipher_key.alg = OP_ALG_ALGSEL_3DES;
+               session->cipher_key.algmode = OP_ALG_AAI_CBC;
+               break;
+       case RTE_CRYPTO_CIPHER_AES_CTR:
+               session->cipher_key.alg = OP_ALG_ALGSEL_AES;
+               session->cipher_key.algmode = OP_ALG_AAI_CTR;
+               break;
+       case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
+               session->cipher_key.alg = OP_ALG_ALGSEL_SNOW_F8;
+               break;
+       case RTE_CRYPTO_CIPHER_ZUC_EEA3:
+               session->cipher_key.alg = OP_ALG_ALGSEL_ZUCE;
+               break;
+       default:
+               DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
+                             xform->cipher.algo);
+               rte_free(session->cipher_key.data);
+               return -1;
+       }
        session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
                        DIR_ENC : DIR_DEC;
 
@@ -2037,6 +2087,7 @@ dpaa_sec_auth_init(struct rte_cryptodev *dev __rte_unused,
                   struct rte_crypto_sym_xform *xform,
                   dpaa_sec_session *session)
 {
+       session->ctxt = DPAA_SEC_AUTH;
        session->auth_alg = xform->auth.algo;
        session->auth_key.data = rte_zmalloc(NULL, xform->auth.key.length,
                                             RTE_CACHE_LINE_SIZE);
@@ -2046,21 +2097,173 @@ dpaa_sec_auth_init(struct rte_cryptodev *dev __rte_unused,
        }
        session->auth_key.length = xform->auth.key.length;
        session->digest_length = xform->auth.digest_length;
+       if (session->cipher_alg == RTE_CRYPTO_CIPHER_NULL) {
+               session->iv.offset = xform->auth.iv.offset;
+               session->iv.length = xform->auth.iv.length;
+       }
 
        memcpy(session->auth_key.data, xform->auth.key.data,
               xform->auth.key.length);
+
+       switch (xform->auth.algo) {
+       case RTE_CRYPTO_AUTH_SHA1_HMAC:
+               session->auth_key.alg = OP_ALG_ALGSEL_SHA1;
+               session->auth_key.algmode = OP_ALG_AAI_HMAC;
+               break;
+       case RTE_CRYPTO_AUTH_MD5_HMAC:
+               session->auth_key.alg = OP_ALG_ALGSEL_MD5;
+               session->auth_key.algmode = OP_ALG_AAI_HMAC;
+               break;
+       case RTE_CRYPTO_AUTH_SHA224_HMAC:
+               session->auth_key.alg = OP_ALG_ALGSEL_SHA224;
+               session->auth_key.algmode = OP_ALG_AAI_HMAC;
+               break;
+       case RTE_CRYPTO_AUTH_SHA256_HMAC:
+               session->auth_key.alg = OP_ALG_ALGSEL_SHA256;
+               session->auth_key.algmode = OP_ALG_AAI_HMAC;
+               break;
+       case RTE_CRYPTO_AUTH_SHA384_HMAC:
+               session->auth_key.alg = OP_ALG_ALGSEL_SHA384;
+               session->auth_key.algmode = OP_ALG_AAI_HMAC;
+               break;
+       case RTE_CRYPTO_AUTH_SHA512_HMAC:
+               session->auth_key.alg = OP_ALG_ALGSEL_SHA512;
+               session->auth_key.algmode = OP_ALG_AAI_HMAC;
+               break;
+       case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
+               session->auth_key.alg = OP_ALG_ALGSEL_SNOW_F9;
+               session->auth_key.algmode = OP_ALG_AAI_F9;
+               break;
+       case RTE_CRYPTO_AUTH_ZUC_EIA3:
+               session->auth_key.alg = OP_ALG_ALGSEL_ZUCA;
+               session->auth_key.algmode = OP_ALG_AAI_F9;
+               break;
+       default:
+               DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
+                             xform->auth.algo);
+               rte_free(session->auth_key.data);
+               return -1;
+       }
+
        session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
                        DIR_ENC : DIR_DEC;
 
        return 0;
 }
 
+static int
+dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
+                  struct rte_crypto_sym_xform *xform,
+                  dpaa_sec_session *session)
+{
+
+       struct rte_crypto_cipher_xform *cipher_xform;
+       struct rte_crypto_auth_xform *auth_xform;
+
+       session->ctxt = DPAA_SEC_CIPHER_HASH;
+       if (session->auth_cipher_text) {
+               cipher_xform = &xform->cipher;
+               auth_xform = &xform->next->auth;
+       } else {
+               cipher_xform = &xform->next->cipher;
+               auth_xform = &xform->auth;
+       }
+
+       /* Set IV parameters */
+       session->iv.offset = cipher_xform->iv.offset;
+       session->iv.length = cipher_xform->iv.length;
+
+       session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
+                                              RTE_CACHE_LINE_SIZE);
+       if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
+               DPAA_SEC_ERR("No Memory for cipher key");
+               return -1;
+       }
+       session->cipher_key.length = cipher_xform->key.length;
+       session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
+                                            RTE_CACHE_LINE_SIZE);
+       if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
+               DPAA_SEC_ERR("No Memory for auth key");
+               rte_free(session->cipher_key.data);
+               return -ENOMEM;
+       }
+       session->auth_key.length = auth_xform->key.length;
+       memcpy(session->cipher_key.data, cipher_xform->key.data,
+              cipher_xform->key.length);
+       memcpy(session->auth_key.data, auth_xform->key.data,
+              auth_xform->key.length);
+
+       session->digest_length = auth_xform->digest_length;
+       session->auth_alg = auth_xform->algo;
+
+       switch (auth_xform->algo) {
+       case RTE_CRYPTO_AUTH_SHA1_HMAC:
+               session->auth_key.alg = OP_ALG_ALGSEL_SHA1;
+               session->auth_key.algmode = OP_ALG_AAI_HMAC;
+               break;
+       case RTE_CRYPTO_AUTH_MD5_HMAC:
+               session->auth_key.alg = OP_ALG_ALGSEL_MD5;
+               session->auth_key.algmode = OP_ALG_AAI_HMAC;
+               break;
+       case RTE_CRYPTO_AUTH_SHA224_HMAC:
+               session->auth_key.alg = OP_ALG_ALGSEL_SHA224;
+               session->auth_key.algmode = OP_ALG_AAI_HMAC;
+               break;
+       case RTE_CRYPTO_AUTH_SHA256_HMAC:
+               session->auth_key.alg = OP_ALG_ALGSEL_SHA256;
+               session->auth_key.algmode = OP_ALG_AAI_HMAC;
+               break;
+       case RTE_CRYPTO_AUTH_SHA384_HMAC:
+               session->auth_key.alg = OP_ALG_ALGSEL_SHA384;
+               session->auth_key.algmode = OP_ALG_AAI_HMAC;
+               break;
+       case RTE_CRYPTO_AUTH_SHA512_HMAC:
+               session->auth_key.alg = OP_ALG_ALGSEL_SHA512;
+               session->auth_key.algmode = OP_ALG_AAI_HMAC;
+               break;
+       default:
+               DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
+                             auth_xform->algo);
+               goto error_out;
+       }
+
+       session->cipher_alg = cipher_xform->algo;
+
+       switch (cipher_xform->algo) {
+       case RTE_CRYPTO_CIPHER_AES_CBC:
+               session->cipher_key.alg = OP_ALG_ALGSEL_AES;
+               session->cipher_key.algmode = OP_ALG_AAI_CBC;
+               break;
+       case RTE_CRYPTO_CIPHER_3DES_CBC:
+               session->cipher_key.alg = OP_ALG_ALGSEL_3DES;
+               session->cipher_key.algmode = OP_ALG_AAI_CBC;
+               break;
+       case RTE_CRYPTO_CIPHER_AES_CTR:
+               session->cipher_key.alg = OP_ALG_ALGSEL_AES;
+               session->cipher_key.algmode = OP_ALG_AAI_CTR;
+               break;
+       default:
+               DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
+                             cipher_xform->algo);
+               goto error_out;
+       }
+       session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
+                               DIR_ENC : DIR_DEC;
+       return 0;
+
+error_out:
+       rte_free(session->cipher_key.data);
+       rte_free(session->auth_key.data);
+       return -1;
+}
+
 static int
 dpaa_sec_aead_init(struct rte_cryptodev *dev __rte_unused,
                   struct rte_crypto_sym_xform *xform,
                   dpaa_sec_session *session)
 {
        session->aead_alg = xform->aead.algo;
+       session->ctxt = DPAA_SEC_AEAD;
        session->iv.length = xform->aead.iv.length;
        session->iv.offset = xform->aead.iv.offset;
        session->auth_only_len = xform->aead.aad_length;
@@ -2075,6 +2278,18 @@ dpaa_sec_aead_init(struct rte_cryptodev *dev __rte_unused,
 
        memcpy(session->aead_key.data, xform->aead.key.data,
               xform->aead.key.length);
+
+       switch (session->aead_alg) {
+       case RTE_CRYPTO_AEAD_AES_GCM:
+               session->aead_key.alg = OP_ALG_ALGSEL_AES;
+               session->aead_key.algmode = OP_ALG_AAI_GCM;
+               break;
+       default:
+               DPAA_SEC_ERR("unsupported AEAD alg %d", session->aead_alg);
+               rte_free(session->aead_key.data);
+               return -ENOMEM;
+       }
+
        session->dir = (xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
                        DIR_ENC : DIR_DEC;
 
@@ -2147,6 +2362,7 @@ dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
        struct dpaa_sec_dev_private *internals = dev->data->dev_private;
        dpaa_sec_session *session = sess;
        uint32_t i;
+       int ret;
 
        PMD_INIT_FUNC_TRACE();
 
@@ -2162,31 +2378,42 @@ dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
        /* Cipher Only */
        if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
                session->auth_alg = RTE_CRYPTO_AUTH_NULL;
-               dpaa_sec_cipher_init(dev, xform, session);
+               ret = dpaa_sec_cipher_init(dev, xform, session);
 
        /* Authentication Only */
        } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
                   xform->next == NULL) {
                session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
-               dpaa_sec_auth_init(dev, xform, session);
+               session->ctxt = DPAA_SEC_AUTH;
+               ret = dpaa_sec_auth_init(dev, xform, session);
 
        /* Cipher then Authenticate */
        } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
                   xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
                if (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
-                       dpaa_sec_cipher_init(dev, xform, session);
-                       dpaa_sec_auth_init(dev, xform->next, session);
+                       session->auth_cipher_text = 1;
+                       if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
+                               ret = dpaa_sec_auth_init(dev, xform, session);
+                       else if (xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL)
+                               ret = dpaa_sec_cipher_init(dev, xform, session);
+                       else
+                               ret = dpaa_sec_chain_init(dev, xform, session);
                } else {
                        DPAA_SEC_ERR("Not supported: Auth then Cipher");
                        return -EINVAL;
                }
-
        /* Authenticate then Cipher */
        } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
                   xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
                if (xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
-                       dpaa_sec_auth_init(dev, xform, session);
-                       dpaa_sec_cipher_init(dev, xform->next, session);
+                       session->auth_cipher_text = 0;
+                       if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL)
+                               ret = dpaa_sec_cipher_init(dev, xform, session);
+                       else if (xform->next->cipher.algo
+                                       == RTE_CRYPTO_CIPHER_NULL)
+                               ret = dpaa_sec_auth_init(dev, xform, session);
+                       else
+                               ret = dpaa_sec_chain_init(dev, xform, session);
                } else {
                        DPAA_SEC_ERR("Not supported: Auth then Cipher");
                        return -EINVAL;
@@ -2195,12 +2422,17 @@ dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
        /* AEAD operation for AES-GCM kind of Algorithms */
        } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
                   xform->next == NULL) {
-               dpaa_sec_aead_init(dev, xform, session);
+               ret = dpaa_sec_aead_init(dev, xform, session);
 
        } else {
                DPAA_SEC_ERR("Invalid crypto type");
                return -EINVAL;
        }
+       if (ret) {
+               DPAA_SEC_ERR("unable to init session");
+               goto err1;
+       }
+
        rte_spinlock_lock(&internals->lock);
        for (i = 0; i < MAX_DPAA_CORES; i++) {
                session->inq[i] = dpaa_sec_attach_rxq(internals);
@@ -2289,6 +2521,7 @@ dpaa_sec_sym_session_clear(struct rte_cryptodev *dev,
        }
 }
 
+#ifdef RTE_LIBRTE_SECURITY
 static int
 dpaa_sec_set_ipsec_session(__rte_unused struct rte_cryptodev *dev,
                           struct rte_security_session_conf *conf,
@@ -2314,6 +2547,7 @@ dpaa_sec_set_ipsec_session(__rte_unused struct rte_cryptodev *dev,
                        cipher_xform = &conf->crypto_xform->next->cipher;
        }
        session->proto_alg = conf->protocol;
+       session->ctxt = DPAA_SEC_IPSEC;
 
        if (cipher_xform && cipher_xform->algo != RTE_CRYPTO_CIPHER_NULL) {
                session->cipher_key.data = rte_zmalloc(NULL,
@@ -2329,9 +2563,20 @@ dpaa_sec_set_ipsec_session(__rte_unused struct rte_cryptodev *dev,
                session->cipher_key.length = cipher_xform->key.length;
 
                switch (cipher_xform->algo) {
+               case RTE_CRYPTO_CIPHER_NULL:
+                       session->cipher_key.alg = OP_PCL_IPSEC_NULL;
+                       break;
                case RTE_CRYPTO_CIPHER_AES_CBC:
+                       session->cipher_key.alg = OP_PCL_IPSEC_AES_CBC;
+                       session->cipher_key.algmode = OP_ALG_AAI_CBC;
+                       break;
                case RTE_CRYPTO_CIPHER_3DES_CBC:
+                       session->cipher_key.alg = OP_PCL_IPSEC_3DES;
+                       session->cipher_key.algmode = OP_ALG_AAI_CBC;
+                       break;
                case RTE_CRYPTO_CIPHER_AES_CTR:
+                       session->cipher_key.alg = OP_PCL_IPSEC_AES_CTR;
+                       session->cipher_key.algmode = OP_ALG_AAI_CTR;
                        break;
                default:
                        DPAA_SEC_ERR("Crypto: Unsupported Cipher alg %u",
@@ -2360,12 +2605,33 @@ dpaa_sec_set_ipsec_session(__rte_unused struct rte_cryptodev *dev,
                session->auth_key.length = auth_xform->key.length;
 
                switch (auth_xform->algo) {
-               case RTE_CRYPTO_AUTH_SHA1_HMAC:
+               case RTE_CRYPTO_AUTH_NULL:
+                       session->auth_key.alg = OP_PCL_IPSEC_HMAC_NULL;
+                       session->digest_length = 0;
+                       break;
                case RTE_CRYPTO_AUTH_MD5_HMAC:
+                       session->auth_key.alg = OP_PCL_IPSEC_HMAC_MD5_96;
+                       session->auth_key.algmode = OP_ALG_AAI_HMAC;
+                       break;
+               case RTE_CRYPTO_AUTH_SHA1_HMAC:
+                       session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA1_96;
+                       session->auth_key.algmode = OP_ALG_AAI_HMAC;
+                       break;
+               case RTE_CRYPTO_AUTH_SHA224_HMAC:
+                       session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA1_160;
+                       session->auth_key.algmode = OP_ALG_AAI_HMAC;
+                       break;
                case RTE_CRYPTO_AUTH_SHA256_HMAC:
+                       session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_256_128;
+                       session->auth_key.algmode = OP_ALG_AAI_HMAC;
+                       break;
                case RTE_CRYPTO_AUTH_SHA384_HMAC:
+                       session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_384_192;
+                       session->auth_key.algmode = OP_ALG_AAI_HMAC;
+                       break;
                case RTE_CRYPTO_AUTH_SHA512_HMAC:
-               case RTE_CRYPTO_AUTH_AES_CMAC:
+                       session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_512_256;
+                       session->auth_key.algmode = OP_ALG_AAI_HMAC;
                        break;
                default:
                        DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
@@ -2506,7 +2772,28 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
        }
 
        session->proto_alg = conf->protocol;
+       session->ctxt = DPAA_SEC_PDCP;
+
        if (cipher_xform) {
+               switch (cipher_xform->algo) {
+               case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
+                       session->cipher_key.alg = PDCP_CIPHER_TYPE_SNOW;
+                       break;
+               case RTE_CRYPTO_CIPHER_ZUC_EEA3:
+                       session->cipher_key.alg = PDCP_CIPHER_TYPE_ZUC;
+                       break;
+               case RTE_CRYPTO_CIPHER_AES_CTR:
+                       session->cipher_key.alg = PDCP_CIPHER_TYPE_AES;
+                       break;
+               case RTE_CRYPTO_CIPHER_NULL:
+                       session->cipher_key.alg = PDCP_CIPHER_TYPE_NULL;
+                       break;
+               default:
+                       DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
+                                     session->cipher_alg);
+                       return -1;
+               }
+
                session->cipher_key.data = rte_zmalloc(NULL,
                                               cipher_xform->key.length,
                                               RTE_CACHE_LINE_SIZE);
@@ -2538,6 +2825,25 @@ dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
        }
 
        if (auth_xform) {
+               switch (auth_xform->algo) {
+               case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
+                       session->auth_key.alg = PDCP_AUTH_TYPE_SNOW;
+                       break;
+               case RTE_CRYPTO_AUTH_ZUC_EIA3:
+                       session->auth_key.alg = PDCP_AUTH_TYPE_ZUC;
+                       break;
+               case RTE_CRYPTO_AUTH_AES_CMAC:
+                       session->auth_key.alg = PDCP_AUTH_TYPE_AES;
+                       break;
+               case RTE_CRYPTO_AUTH_NULL:
+                       session->auth_key.alg = PDCP_AUTH_TYPE_NULL;
+                       break;
+               default:
+                       DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
+                                     session->auth_alg);
+                       rte_free(session->cipher_key.data);
+                       return -1;
+               }
                session->auth_key.data = rte_zmalloc(NULL,
                                                     auth_xform->key.length,
                                                     RTE_CACHE_LINE_SIZE);
@@ -2639,7 +2945,7 @@ dpaa_sec_security_session_destroy(void *dev __rte_unused,
        }
        return 0;
 }
-
+#endif
 static int
 dpaa_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
                       struct rte_cryptodev_config *config __rte_unused)
@@ -2885,6 +3191,7 @@ static struct rte_cryptodev_ops crypto_ops = {
        .sym_session_clear        = dpaa_sec_sym_session_clear
 };
 
+#ifdef RTE_LIBRTE_SECURITY
 static const struct rte_security_capability *
 dpaa_sec_capabilities_get(void *device __rte_unused)
 {
@@ -2899,7 +3206,7 @@ static const struct rte_security_ops dpaa_sec_security_ops = {
        .set_pkt_metadata = NULL,
        .capabilities_get = dpaa_sec_capabilities_get
 };
-
+#endif
 static int
 dpaa_sec_uninit(struct rte_cryptodev *dev)
 {
@@ -2923,7 +3230,9 @@ static int
 dpaa_sec_dev_init(struct rte_cryptodev *cryptodev)
 {
        struct dpaa_sec_dev_private *internals;
+#ifdef RTE_LIBRTE_SECURITY
        struct rte_security_ctx *security_instance;
+#endif
        struct dpaa_sec_qp *qp;
        uint32_t i, flags;
        int ret;
@@ -2958,7 +3267,7 @@ dpaa_sec_dev_init(struct rte_cryptodev *cryptodev)
                DPAA_SEC_WARN("Device already init by primary process");
                return 0;
        }
-
+#ifdef RTE_LIBRTE_SECURITY
        /* Initialize security_ctx only for primary process*/
        security_instance = rte_malloc("rte_security_instances_ops",
                                sizeof(struct rte_security_ctx), 0);
@@ -2968,7 +3277,7 @@ dpaa_sec_dev_init(struct rte_cryptodev *cryptodev)
        security_instance->ops = &dpaa_sec_security_ops;
        security_instance->sess_cnt = 0;
        cryptodev->security_ctx = security_instance;
-
+#endif
        rte_spinlock_init(&internals->lock);
        for (i = 0; i < internals->max_nb_queue_pairs; i++) {
                /* init qman fq for queue pair */
@@ -3050,6 +3359,14 @@ cryptodev_dpaa_sec_probe(struct rte_dpaa_driver *dpaa_drv __rte_unused,
                }
        }
 
+       if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
+               retval = rte_dpaa_portal_init((void *)1);
+               if (retval) {
+                       DPAA_SEC_ERR("Unable to initialize portal");
+                       return retval;
+               }
+       }
+
        /* Invoke PMD device initialization function */
        retval = dpaa_sec_dev_init(cryptodev);
        if (retval == 0)