X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fcommon%2Fcpt%2Fcpt_ucode.h;h=ee6d49aae77beac3c911e63746b2487240da2922;hb=753a7c08e2d4dbc4dc6709d48f30db9e691c3bc4;hp=c69896d537aa548e24769bb8dbef34cff1335d64;hpb=6045c06a870e31600c698a7ea1830a274f601fb1;p=dpdk.git diff --git a/drivers/common/cpt/cpt_ucode.h b/drivers/common/cpt/cpt_ucode.h index c69896d537..ee6d49aae7 100644 --- a/drivers/common/cpt/cpt_ucode.h +++ b/drivers/common/cpt/cpt_ucode.h @@ -489,7 +489,6 @@ cpt_digest_gen_prep(uint32_t flags, vq_cmd_word0_t vq_cmd_w0; void *c_vaddr, *m_vaddr; uint64_t c_dma, m_dma; - opcode_info_t opcode; ctx = params->ctx_buf.vaddr; meta_p = ¶ms->meta_buf; @@ -524,31 +523,27 @@ cpt_digest_gen_prep(uint32_t flags, data_len = AUTH_DLEN(d_lens); /*GP op header */ - vq_cmd_w0.u64 = 0; + vq_cmd_w0.s.opcode.minor = 0; vq_cmd_w0.s.param2 = ((uint16_t)hash_type << 8); if (ctx->hmac) { - opcode.s.major = CPT_MAJOR_OP_HMAC | CPT_DMA_MODE; + vq_cmd_w0.s.opcode.major = CPT_MAJOR_OP_HMAC | CPT_DMA_MODE; vq_cmd_w0.s.param1 = key_len; - vq_cmd_w0.s.dlen = data_len + ROUNDUP8(key_len); + vq_cmd_w0.s.dlen = data_len + RTE_ALIGN_CEIL(key_len, 8); } else { - opcode.s.major = CPT_MAJOR_OP_HASH | CPT_DMA_MODE; + vq_cmd_w0.s.opcode.major = CPT_MAJOR_OP_HASH | CPT_DMA_MODE; vq_cmd_w0.s.param1 = 0; vq_cmd_w0.s.dlen = data_len; } - opcode.s.minor = 0; - /* Null auth only case enters the if */ if (unlikely(!hash_type && !ctx->enc_cipher)) { - opcode.s.major = CPT_MAJOR_OP_MISC; + vq_cmd_w0.s.opcode.major = CPT_MAJOR_OP_MISC; /* Minor op is passthrough */ - opcode.s.minor = 0x03; + vq_cmd_w0.s.opcode.minor = 0x03; /* Send out completion code only */ vq_cmd_w0.s.param2 = 0x1; } - vq_cmd_w0.s.opcode = opcode.flags; - /* DPTR has SG list */ in_buffer = m_vaddr; dptr_dma = m_dma; @@ -569,7 +564,8 @@ cpt_digest_gen_prep(uint32_t flags, uint64_t k_dma = params->ctx_buf.dma_addr + offsetof(struct cpt_ctx, auth_key); /* Key */ - i = fill_sg_comp(gather_comp, i, k_dma, ROUNDUP8(key_len)); + i = fill_sg_comp(gather_comp, i, k_dma, + RTE_ALIGN_CEIL(key_len, 8)); } /* input data */ @@ -677,7 +673,6 @@ cpt_enc_hmac_prep(uint32_t flags, vq_cmd_word0_t vq_cmd_w0; void *c_vaddr; uint64_t c_dma; - opcode_info_t opcode; meta_p = &fc_params->meta_buf; m_vaddr = meta_p->vaddr; @@ -756,8 +751,10 @@ cpt_enc_hmac_prep(uint32_t flags, } /* Encryption */ - opcode.s.major = CPT_MAJOR_OP_FC; - opcode.s.minor = 0; + vq_cmd_w0.s.opcode.major = CPT_MAJOR_OP_FC; + vq_cmd_w0.s.opcode.minor = CPT_FC_MINOR_OP_ENCRYPT; + vq_cmd_w0.s.opcode.minor |= (cpt_ctx->auth_enc << + CPT_HMAC_FIRST_BIT_POS); if (hash_type == GMAC_TYPE) { encr_offset = 0; @@ -768,10 +765,12 @@ cpt_enc_hmac_prep(uint32_t flags, enc_dlen = encr_data_len + encr_offset; if (unlikely(encr_data_len & 0xf)) { if ((cipher_type == DES3_CBC) || (cipher_type == DES3_ECB)) - enc_dlen = ROUNDUP8(encr_data_len) + encr_offset; + enc_dlen = RTE_ALIGN_CEIL(encr_data_len, 8) + + encr_offset; else if (likely((cipher_type == AES_CBC) || (cipher_type == AES_ECB))) - enc_dlen = ROUNDUP16(encr_data_len) + encr_offset; + enc_dlen = RTE_ALIGN_CEIL(encr_data_len, 8) + + encr_offset; } if (unlikely(auth_dlen > enc_dlen)) { @@ -782,8 +781,10 @@ cpt_enc_hmac_prep(uint32_t flags, outputlen = enc_dlen + mac_len; } + if (cpt_ctx->auth_enc != 0) + outputlen = enc_dlen; + /* GP op header */ - vq_cmd_w0.u64 = 0; vq_cmd_w0.s.param1 = encr_data_len; vq_cmd_w0.s.param2 = auth_data_len; /* @@ -814,8 +815,6 @@ cpt_enc_hmac_prep(uint32_t flags, vq_cmd_w0.s.dlen = inputlen + OFF_CTRL_LEN; - vq_cmd_w0.s.opcode = opcode.flags; - if (likely(iv_len)) { uint64_t *dest = (uint64_t *)((uint8_t *)offset_vaddr + OFF_CTRL_LEN); @@ -844,9 +843,7 @@ cpt_enc_hmac_prep(uint32_t flags, m_vaddr = (uint8_t *)m_vaddr + size; m_dma += size; - opcode.s.major |= CPT_DMA_MODE; - - vq_cmd_w0.s.opcode = opcode.flags; + vq_cmd_w0.s.opcode.major |= CPT_DMA_MODE; if (likely(iv_len)) { uint64_t *dest = (uint64_t *)((uint8_t *)offset_vaddr @@ -1038,7 +1035,6 @@ cpt_dec_hmac_prep(uint32_t flags, uint32_t passthrough_len = 0; void *m_vaddr, *offset_vaddr; uint64_t m_dma, offset_dma; - opcode_info_t opcode; vq_cmd_word0_t vq_cmd_w0; void *c_vaddr; uint64_t c_dma; @@ -1120,8 +1116,10 @@ cpt_dec_hmac_prep(uint32_t flags, m_dma += size; /* Decryption */ - opcode.s.major = CPT_MAJOR_OP_FC; - opcode.s.minor = 1; + vq_cmd_w0.s.opcode.major = CPT_MAJOR_OP_FC; + vq_cmd_w0.s.opcode.minor = CPT_FC_MINOR_OP_DECRYPT; + vq_cmd_w0.s.opcode.minor |= (cpt_ctx->dec_auth << + CPT_HMAC_FIRST_BIT_POS); if (hash_type == GMAC_TYPE) { encr_offset = 0; @@ -1139,7 +1137,9 @@ cpt_dec_hmac_prep(uint32_t flags, outputlen = enc_dlen; } - vq_cmd_w0.u64 = 0; + if (cpt_ctx->dec_auth != 0) + outputlen = inputlen = enc_dlen; + vq_cmd_w0.s.param1 = encr_data_len; vq_cmd_w0.s.param2 = auth_data_len; @@ -1176,8 +1176,6 @@ cpt_dec_hmac_prep(uint32_t flags, vq_cmd_w0.s.dlen = inputlen + OFF_CTRL_LEN; - vq_cmd_w0.s.opcode = opcode.flags; - if (likely(iv_len)) { uint64_t *dest = (uint64_t *)((uint8_t *)offset_vaddr + OFF_CTRL_LEN); @@ -1207,9 +1205,7 @@ cpt_dec_hmac_prep(uint32_t flags, m_vaddr = (uint8_t *)m_vaddr + size; m_dma += size; - opcode.s.major |= CPT_DMA_MODE; - - vq_cmd_w0.s.opcode = opcode.flags; + vq_cmd_w0.s.opcode.major |= CPT_DMA_MODE; if (likely(iv_len)) { uint64_t *dest = (uint64_t *)((uint8_t *)offset_vaddr + @@ -1417,7 +1413,6 @@ cpt_zuc_snow3g_enc_prep(uint32_t req_flags, uint64_t *offset_vaddr, offset_dma; uint32_t *iv_s, iv[4]; vq_cmd_word0_t vq_cmd_w0; - opcode_info_t opcode; buf_p = ¶ms->meta_buf; m_vaddr = buf_p->vaddr; @@ -1451,11 +1446,11 @@ cpt_zuc_snow3g_enc_prep(uint32_t req_flags, m_vaddr = (uint8_t *)m_vaddr + size; m_dma += size; - opcode.s.major = CPT_MAJOR_OP_ZUC_SNOW3G; + vq_cmd_w0.s.opcode.major = CPT_MAJOR_OP_ZUC_SNOW3G; /* indicates CPTR ctx, operation type, KEY & IV mode from DPTR */ - opcode.s.minor = ((1 << 7) | (snow3g << 5) | (0 << 4) | + vq_cmd_w0.s.opcode.minor = ((1 << 7) | (snow3g << 5) | (0 << 4) | (0 << 3) | (flags & 0x7)); if (flags == 0x1) { @@ -1518,7 +1513,6 @@ cpt_zuc_snow3g_enc_prep(uint32_t req_flags, /* * GP op header, lengths are expected in bits. */ - vq_cmd_w0.u64 = 0; vq_cmd_w0.s.param1 = encr_data_len; vq_cmd_w0.s.param2 = auth_data_len; @@ -1551,8 +1545,6 @@ cpt_zuc_snow3g_enc_prep(uint32_t req_flags, vq_cmd_w0.s.dlen = inputlen + OFF_CTRL_LEN; - vq_cmd_w0.s.opcode = opcode.flags; - if (likely(iv_len)) { uint32_t *iv_d = (uint32_t *)((uint8_t *)offset_vaddr + OFF_CTRL_LEN); @@ -1575,9 +1567,7 @@ cpt_zuc_snow3g_enc_prep(uint32_t req_flags, m_vaddr = (uint8_t *)m_vaddr + OFF_CTRL_LEN + iv_len; m_dma += OFF_CTRL_LEN + iv_len; - opcode.s.major |= CPT_DMA_MODE; - - vq_cmd_w0.s.opcode = opcode.flags; + vq_cmd_w0.s.opcode.major |= CPT_DMA_MODE; /* DPTR has SG list */ in_buffer = m_vaddr; @@ -1729,7 +1719,6 @@ cpt_zuc_snow3g_dec_prep(uint32_t req_flags, uint64_t *offset_vaddr, offset_dma; uint32_t *iv_s, iv[4], j; vq_cmd_word0_t vq_cmd_w0; - opcode_info_t opcode; buf_p = ¶ms->meta_buf; m_vaddr = buf_p->vaddr; @@ -1768,11 +1757,12 @@ cpt_zuc_snow3g_dec_prep(uint32_t req_flags, m_vaddr = (uint8_t *)m_vaddr + size; m_dma += size; - opcode.s.major = CPT_MAJOR_OP_ZUC_SNOW3G; + vq_cmd_w0.u64 = 0; + vq_cmd_w0.s.opcode.major = CPT_MAJOR_OP_ZUC_SNOW3G; /* indicates CPTR ctx, operation type, KEY & IV mode from DPTR */ - opcode.s.minor = ((1 << 7) | (snow3g << 5) | (0 << 4) | + vq_cmd_w0.s.opcode.minor = ((1 << 7) | (snow3g << 5) | (0 << 4) | (0 << 3) | (flags & 0x7)); /* consider iv len */ @@ -1801,7 +1791,6 @@ cpt_zuc_snow3g_dec_prep(uint32_t req_flags, /* * GP op header, lengths are expected in bits. */ - vq_cmd_w0.u64 = 0; vq_cmd_w0.s.param1 = encr_data_len; /* @@ -1833,8 +1822,6 @@ cpt_zuc_snow3g_dec_prep(uint32_t req_flags, vq_cmd_w0.s.dlen = inputlen + OFF_CTRL_LEN; - vq_cmd_w0.s.opcode = opcode.flags; - if (likely(iv_len)) { uint32_t *iv_d = (uint32_t *)((uint8_t *)offset_vaddr + OFF_CTRL_LEN); @@ -1858,9 +1845,7 @@ cpt_zuc_snow3g_dec_prep(uint32_t req_flags, m_vaddr = (uint8_t *)m_vaddr + OFF_CTRL_LEN + iv_len; m_dma += OFF_CTRL_LEN + iv_len; - opcode.s.major |= CPT_DMA_MODE; - - vq_cmd_w0.s.opcode = opcode.flags; + vq_cmd_w0.s.opcode.major |= CPT_DMA_MODE; /* DPTR has SG list */ in_buffer = m_vaddr; @@ -1987,7 +1972,6 @@ cpt_kasumi_enc_prep(uint32_t req_flags, uint64_t m_dma, c_dma; uint64_t *offset_vaddr, offset_dma; vq_cmd_word0_t vq_cmd_w0; - opcode_info_t opcode; uint8_t *in_buffer; uint32_t g_size_bytes, s_size_bytes; uint64_t dptr_dma, rptr_dma; @@ -2037,19 +2021,17 @@ cpt_kasumi_enc_prep(uint32_t req_flags, m_vaddr = (uint8_t *)m_vaddr + size; m_dma += size; - opcode.s.major = CPT_MAJOR_OP_KASUMI | CPT_DMA_MODE; + vq_cmd_w0.s.opcode.major = CPT_MAJOR_OP_KASUMI | CPT_DMA_MODE; /* indicates ECB/CBC, direction, ctx from cptr, iv from dptr */ - opcode.s.minor = ((1 << 6) | (cpt_ctx->k_ecb << 5) | + vq_cmd_w0.s.opcode.minor = ((1 << 6) | (cpt_ctx->k_ecb << 5) | (dir << 4) | (0 << 3) | (flags & 0x7)); /* * GP op header, lengths are expected in bits. */ - vq_cmd_w0.u64 = 0; vq_cmd_w0.s.param1 = encr_data_len; vq_cmd_w0.s.param2 = auth_data_len; - vq_cmd_w0.s.opcode = opcode.flags; /* consider iv len */ if (flags == 0x0) { @@ -2223,7 +2205,6 @@ cpt_kasumi_dec_prep(uint64_t d_offs, uint64_t m_dma, c_dma; uint64_t *offset_vaddr, offset_dma; vq_cmd_word0_t vq_cmd_w0; - opcode_info_t opcode; uint8_t *in_buffer; uint32_t g_size_bytes, s_size_bytes; uint64_t dptr_dma, rptr_dma; @@ -2262,18 +2243,17 @@ cpt_kasumi_dec_prep(uint64_t d_offs, m_vaddr = (uint8_t *)m_vaddr + size; m_dma += size; - opcode.s.major = CPT_MAJOR_OP_KASUMI | CPT_DMA_MODE; + vq_cmd_w0.u64 = 0; + vq_cmd_w0.s.opcode.major = CPT_MAJOR_OP_KASUMI | CPT_DMA_MODE; /* indicates ECB/CBC, direction, ctx from cptr, iv from dptr */ - opcode.s.minor = ((1 << 6) | (cpt_ctx->k_ecb << 5) | + vq_cmd_w0.s.opcode.minor = ((1 << 6) | (cpt_ctx->k_ecb << 5) | (dir << 4) | (0 << 3) | (flags & 0x7)); /* * GP op header, lengths are expected in bits. */ - vq_cmd_w0.u64 = 0; vq_cmd_w0.s.param1 = encr_data_len; - vq_cmd_w0.s.opcode = opcode.flags; /* consider iv len */ encr_offset += iv_len; @@ -2596,6 +2576,7 @@ fill_sess_cipher(struct rte_crypto_sym_xform *xform, struct cpt_sess_misc *sess) { struct rte_crypto_cipher_xform *c_form; + struct cpt_ctx *ctx = SESS_PRIV(sess); cipher_type_t enc_type = 0; /* NULL Cipher type */ uint32_t cipher_key_len = 0; uint8_t zsk_flag = 0, aes_ctr = 0, is_null = 0; @@ -2604,9 +2585,14 @@ fill_sess_cipher(struct rte_crypto_sym_xform *xform, if (c_form->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) sess->cpt_op |= CPT_OP_CIPHER_ENCRYPT; - else if (c_form->op == RTE_CRYPTO_CIPHER_OP_DECRYPT) + else if (c_form->op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { sess->cpt_op |= CPT_OP_CIPHER_DECRYPT; - else { + if (xform->next != NULL && + xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) { + /* Perform decryption followed by auth verify */ + ctx->dec_auth = 1; + } + } else { CPT_LOG_DP_ERR("Unknown cipher operation\n"); return -1; } @@ -2697,10 +2683,18 @@ static __rte_always_inline int fill_sess_auth(struct rte_crypto_sym_xform *xform, struct cpt_sess_misc *sess) { + struct cpt_ctx *ctx = SESS_PRIV(sess); struct rte_crypto_auth_xform *a_form; auth_type_t auth_type = 0; /* NULL Auth type */ uint8_t zsk_flag = 0, aes_gcm = 0, is_null = 0; + if (xform->next != NULL && + xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER && + xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { + /* Perform auth followed by encryption */ + ctx->auth_enc = 1; + } + a_form = &xform->auth; if (a_form->op == RTE_CRYPTO_AUTH_OP_VERIFY) @@ -3023,6 +3017,7 @@ fill_fc_params(struct rte_crypto_op *cop, { uint32_t space = 0; struct rte_crypto_sym_op *sym_op = cop->sym; + struct cpt_ctx *ctx = SESS_PRIV(sess_misc); void *mdata = NULL; uintptr_t *op; uint32_t mc_hash_off; @@ -3150,9 +3145,10 @@ fill_fc_params(struct rte_crypto_op *cop, m = m_src; /* hmac immediately following data is best case */ - if (unlikely(rte_pktmbuf_mtod(m, uint8_t *) + + if (!ctx->dec_auth && !ctx->auth_enc && + (unlikely(rte_pktmbuf_mtod(m, uint8_t *) + mc_hash_off != - (uint8_t *)sym_op->auth.digest.data)) { + (uint8_t *)sym_op->auth.digest.data))) { flags |= VALID_MAC_BUF; fc_params.mac_buf.size = sess_misc->mac_len; @@ -3167,7 +3163,9 @@ fill_fc_params(struct rte_crypto_op *cop, fc_params.ctx_buf.vaddr = SESS_PRIV(sess_misc); fc_params.ctx_buf.dma_addr = sess_misc->ctx_dma_addr; - if (unlikely(sess_misc->is_null || sess_misc->cpt_op == CPT_OP_DECODE)) + if (!ctx->dec_auth && + unlikely(sess_misc->is_null || + sess_misc->cpt_op == CPT_OP_DECODE)) inplace = 0; if (likely(!m_dst && inplace)) {