diff options
Diffstat (limited to 'target/linux/layerscape/patches-4.9/804-crypto-support-layerscape.patch')
-rw-r--r-- | target/linux/layerscape/patches-4.9/804-crypto-support-layerscape.patch | 1247 |
1 files changed, 858 insertions, 389 deletions
diff --git a/target/linux/layerscape/patches-4.9/804-crypto-support-layerscape.patch b/target/linux/layerscape/patches-4.9/804-crypto-support-layerscape.patch index a143ad566b..56a3dc01c4 100644 --- a/target/linux/layerscape/patches-4.9/804-crypto-support-layerscape.patch +++ b/target/linux/layerscape/patches-4.9/804-crypto-support-layerscape.patch @@ -1,7 +1,7 @@ -From a3310d64d7cb1ba0f9279e77d21f13a75fa66ab5 Mon Sep 17 00:00:00 2001 +From 2a0aa9bd187f6f5693982a8f79665585af772237 Mon Sep 17 00:00:00 2001 From: Yangbo Lu <yangbo.lu@nxp.com> -Date: Wed, 17 Jan 2018 15:29:23 +0800 -Subject: [PATCH 16/30] crypto: support layerscape +Date: Thu, 5 Jul 2018 17:29:41 +0800 +Subject: [PATCH 16/32] crypto: support layerscape MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @@ -27,66 +27,67 @@ Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Laura Abbott <labbott@redhat.com> Signed-off-by: Horia Geantă <horia.geanta@nxp.com> -Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +Singed-off-by: Yangbo Lu <yangbo.lu@nxp.com> --- - crypto/Kconfig | 30 + - crypto/Makefile | 4 + - crypto/acompress.c | 169 + - crypto/algboss.c | 12 +- - crypto/crypto_user.c | 19 + - crypto/scompress.c | 356 ++ - crypto/tcrypt.c | 17 +- - crypto/testmgr.c | 1708 +++--- - crypto/testmgr.h | 1125 ++-- - crypto/tls.c | 607 +++ - drivers/crypto/caam/Kconfig | 77 +- - drivers/crypto/caam/Makefile | 16 +- - drivers/crypto/caam/caamalg.c | 2171 ++------ - drivers/crypto/caam/caamalg_desc.c | 1961 +++++++ - drivers/crypto/caam/caamalg_desc.h | 127 + - drivers/crypto/caam/caamalg_qi.c | 2929 ++++++++++ - drivers/crypto/caam/caamalg_qi2.c | 5920 +++++++++++++++++++++ - drivers/crypto/caam/caamalg_qi2.h | 281 + - drivers/crypto/caam/caamhash.c | 550 +- - drivers/crypto/caam/caamhash_desc.c | 108 + - drivers/crypto/caam/caamhash_desc.h | 49 + - drivers/crypto/caam/caampkc.c | 471 +- - drivers/crypto/caam/caampkc.h | 58 + - drivers/crypto/caam/caamrng.c | 16 +- - drivers/crypto/caam/compat.h | 1 + - drivers/crypto/caam/ctrl.c | 358 +- - drivers/crypto/caam/ctrl.h | 2 + - drivers/crypto/caam/desc.h | 84 +- - drivers/crypto/caam/desc_constr.h | 180 +- - drivers/crypto/caam/dpseci.c | 859 +++ - drivers/crypto/caam/dpseci.h | 395 ++ - drivers/crypto/caam/dpseci_cmd.h | 261 + - drivers/crypto/caam/error.c | 127 +- - drivers/crypto/caam/error.h | 10 +- - drivers/crypto/caam/intern.h | 31 +- - drivers/crypto/caam/jr.c | 72 +- - drivers/crypto/caam/jr.h | 2 + - drivers/crypto/caam/key_gen.c | 32 +- - drivers/crypto/caam/key_gen.h | 36 +- - drivers/crypto/caam/pdb.h | 62 + - drivers/crypto/caam/pkc_desc.c | 36 + - drivers/crypto/caam/qi.c | 797 +++ - drivers/crypto/caam/qi.h | 204 + - drivers/crypto/caam/regs.h | 63 +- - drivers/crypto/caam/sg_sw_qm.h | 126 + - drivers/crypto/caam/sg_sw_qm2.h | 81 + - drivers/crypto/caam/sg_sw_sec4.h | 60 +- - drivers/net/wireless/rsi/rsi_91x_usb.c | 2 +- - drivers/staging/wilc1000/linux_wlan.c | 2 +- - drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 2 +- - include/crypto/acompress.h | 269 + - include/crypto/internal/acompress.h | 81 + - include/crypto/internal/scompress.h | 136 + - include/linux/crypto.h | 3 + - include/uapi/linux/cryptouser.h | 5 + - scripts/spelling.txt | 3 + - sound/soc/amd/acp-pcm-dma.c | 2 +- - 57 files changed, 19177 insertions(+), 3988 deletions(-) + crypto/Kconfig | 30 + + crypto/Makefile | 4 + + crypto/acompress.c | 169 + + crypto/algboss.c | 12 +- + crypto/crypto_user.c | 19 + + crypto/scompress.c | 356 + + crypto/tcrypt.c | 17 +- + crypto/testmgr.c | 1708 ++--- + crypto/testmgr.h | 1125 ++-- + crypto/tls.c | 607 ++ + drivers/crypto/caam/Kconfig | 77 +- + drivers/crypto/caam/Makefile | 16 +- + drivers/crypto/caam/caamalg.c | 2185 ++---- + drivers/crypto/caam/caamalg_desc.c | 1961 ++++++ + drivers/crypto/caam/caamalg_desc.h | 127 + + drivers/crypto/caam/caamalg_qi.c | 3321 +++++++++ + drivers/crypto/caam/caamalg_qi2.c | 5938 +++++++++++++++++ + drivers/crypto/caam/caamalg_qi2.h | 283 + + drivers/crypto/caam/caamhash.c | 555 +- + drivers/crypto/caam/caamhash_desc.c | 108 + + drivers/crypto/caam/caamhash_desc.h | 49 + + drivers/crypto/caam/caampkc.c | 471 +- + drivers/crypto/caam/caampkc.h | 58 + + drivers/crypto/caam/caamrng.c | 16 +- + drivers/crypto/caam/compat.h | 1 + + drivers/crypto/caam/ctrl.c | 358 +- + drivers/crypto/caam/ctrl.h | 2 + + drivers/crypto/caam/desc.h | 84 +- + drivers/crypto/caam/desc_constr.h | 180 +- + drivers/crypto/caam/dpseci.c | 858 +++ + drivers/crypto/caam/dpseci.h | 395 ++ + drivers/crypto/caam/dpseci_cmd.h | 261 + + drivers/crypto/caam/error.c | 127 +- + drivers/crypto/caam/error.h | 10 +- + drivers/crypto/caam/intern.h | 31 +- + drivers/crypto/caam/jr.c | 72 +- + drivers/crypto/caam/jr.h | 2 + + drivers/crypto/caam/key_gen.c | 32 +- + drivers/crypto/caam/key_gen.h | 36 +- + drivers/crypto/caam/pdb.h | 62 + + drivers/crypto/caam/pkc_desc.c | 36 + + drivers/crypto/caam/qi.c | 804 +++ + drivers/crypto/caam/qi.h | 204 + + drivers/crypto/caam/regs.h | 63 +- + drivers/crypto/caam/sg_sw_qm.h | 126 + + drivers/crypto/caam/sg_sw_qm2.h | 81 + + drivers/crypto/caam/sg_sw_sec4.h | 60 +- + drivers/crypto/talitos.c | 8 + + drivers/net/wireless/rsi/rsi_91x_usb.c | 2 +- + drivers/staging/wilc1000/linux_wlan.c | 2 +- + .../staging/wilc1000/wilc_wfi_cfgoperations.c | 2 +- + include/crypto/acompress.h | 269 + + include/crypto/internal/acompress.h | 81 + + include/crypto/internal/scompress.h | 136 + + include/linux/crypto.h | 3 + + include/uapi/linux/cryptouser.h | 5 + + scripts/spelling.txt | 3 + + sound/soc/amd/acp-pcm-dma.c | 2 +- + 58 files changed, 19620 insertions(+), 3990 deletions(-) create mode 100644 crypto/acompress.c create mode 100644 crypto/scompress.c create mode 100644 crypto/tls.c @@ -7200,7 +7201,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> bool rfc3686; bool geniv; }; -@@ -163,302 +96,70 @@ struct caam_aead_alg { +@@ -163,302 +96,71 @@ struct caam_aead_alg { bool registered; }; @@ -7270,6 +7271,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> - unsigned int enckeylen; - unsigned int split_key_len; - unsigned int split_key_pad_len; ++ enum dma_data_direction dir; + struct device *jrdev; + struct alginfo adata; + struct alginfo cdata; @@ -7432,7 +7434,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_aead_null_encap(desc, &ctx->adata, ctx->authsize, + ctrlpriv->era); + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); /* * Job Descriptor and Shared Descriptors @@ -7529,11 +7531,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_aead_null_decap(desc, &ctx->adata, ctx->authsize, + ctrlpriv->era); + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); return 0; } -@@ -470,11 +171,12 @@ static int aead_set_sh_desc(struct crypt +@@ -470,11 +172,12 @@ static int aead_set_sh_desc(struct crypt unsigned int ivsize = crypto_aead_ivsize(aead); struct caam_ctx *ctx = crypto_aead_ctx(aead); struct device *jrdev = ctx->jrdev; @@ -7550,7 +7552,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> OP_ALG_AAI_CTR_MOD128); const bool is_rfc3686 = alg->caam.rfc3686; -@@ -482,7 +184,7 @@ static int aead_set_sh_desc(struct crypt +@@ -482,7 +185,7 @@ static int aead_set_sh_desc(struct crypt return 0; /* NULL encryption / decryption */ @@ -7559,7 +7561,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> return aead_null_set_sh_desc(aead); /* -@@ -497,8 +199,14 @@ static int aead_set_sh_desc(struct crypt +@@ -497,8 +200,14 @@ static int aead_set_sh_desc(struct crypt * RFC3686 specific: * CONTEXT1[255:128] = {NONCE, IV, COUNTER} */ @@ -7575,7 +7577,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> if (alg->caam.geniv) goto skip_enc; -@@ -507,146 +215,64 @@ static int aead_set_sh_desc(struct crypt +@@ -507,146 +216,64 @@ static int aead_set_sh_desc(struct crypt * Job Descriptor and Shared Descriptors * must all fit into the 64-word Descriptor h/w Buffer */ @@ -7660,7 +7662,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + ctx->authsize, is_rfc3686, nonce, ctx1_iv_off, + false, ctrlpriv->era); + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); skip_enc: /* @@ -7760,11 +7762,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + ctx->authsize, alg->caam.geniv, is_rfc3686, + nonce, ctx1_iv_off, false, ctrlpriv->era); + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); if (!alg->caam.geniv) goto skip_givenc; -@@ -655,107 +281,32 @@ skip_enc: +@@ -655,107 +282,32 @@ skip_enc: * Job Descriptor and Shared Descriptors * must all fit into the 64-word Descriptor h/w Buffer */ @@ -7890,11 +7892,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + ctx->authsize, is_rfc3686, nonce, + ctx1_iv_off, false, ctrlpriv->era); + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); skip_givenc: return 0; -@@ -776,12 +327,12 @@ static int gcm_set_sh_desc(struct crypto +@@ -776,12 +328,12 @@ static int gcm_set_sh_desc(struct crypto { struct caam_ctx *ctx = crypto_aead_ctx(aead); struct device *jrdev = ctx->jrdev; @@ -7911,7 +7913,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> return 0; /* -@@ -789,175 +340,35 @@ static int gcm_set_sh_desc(struct crypto +@@ -789,175 +341,35 @@ static int gcm_set_sh_desc(struct crypto * Job Descriptor and Shared Descriptor * must fit into the 64-word Descriptor h/w Buffer */ @@ -8012,7 +8014,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> -#endif + cnstr_shdsc_gcm_encap(desc, &ctx->cdata, ivsize, ctx->authsize, false); + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); /* * Job Descriptor and Shared Descriptors @@ -8103,11 +8105,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> -#endif + cnstr_shdsc_gcm_decap(desc, &ctx->cdata, ivsize, ctx->authsize, false); + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); return 0; } -@@ -976,11 +387,12 @@ static int rfc4106_set_sh_desc(struct cr +@@ -976,11 +388,12 @@ static int rfc4106_set_sh_desc(struct cr { struct caam_ctx *ctx = crypto_aead_ctx(aead); struct device *jrdev = ctx->jrdev; @@ -8123,7 +8125,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> return 0; /* -@@ -988,148 +400,37 @@ static int rfc4106_set_sh_desc(struct cr +@@ -988,148 +401,37 @@ static int rfc4106_set_sh_desc(struct cr * Job Descriptor and Shared Descriptor * must fit into the 64-word Descriptor h/w Buffer */ @@ -8205,7 +8207,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_rfc4106_encap(desc, &ctx->cdata, ivsize, ctx->authsize, + false); + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); /* * Job Descriptor and Shared Descriptors @@ -8290,11 +8292,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_rfc4106_decap(desc, &ctx->cdata, ivsize, ctx->authsize, + false); + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); return 0; } -@@ -1149,12 +450,12 @@ static int rfc4543_set_sh_desc(struct cr +@@ -1149,12 +451,12 @@ static int rfc4543_set_sh_desc(struct cr { struct caam_ctx *ctx = crypto_aead_ctx(aead); struct device *jrdev = ctx->jrdev; @@ -8311,7 +8313,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> return 0; /* -@@ -1162,151 +463,37 @@ static int rfc4543_set_sh_desc(struct cr +@@ -1162,151 +464,37 @@ static int rfc4543_set_sh_desc(struct cr * Job Descriptor and Shared Descriptor * must fit into the 64-word Descriptor h/w Buffer */ @@ -8392,7 +8394,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_rfc4543_encap(desc, &ctx->cdata, ivsize, ctx->authsize, + false); + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); /* * Job Descriptor and Shared Descriptors @@ -8481,11 +8483,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_rfc4543_decap(desc, &ctx->cdata, ivsize, ctx->authsize, + false); + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); return 0; } -@@ -1322,74 +509,67 @@ static int rfc4543_setauthsize(struct cr +@@ -1322,74 +510,67 @@ static int rfc4543_setauthsize(struct cr return 0; } @@ -8547,7 +8549,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + keys.enckeylen); + dma_sync_single_for_device(jrdev, ctx->key_dma, + ctx->adata.keylen_pad + -+ keys.enckeylen, DMA_TO_DEVICE); ++ keys.enckeylen, ctx->dir); + goto skip_split_key; + } + @@ -8569,7 +8571,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> - } + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen); + dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->adata.keylen_pad + -+ keys.enckeylen, DMA_TO_DEVICE); ++ keys.enckeylen, ctx->dir); #ifdef DEBUG print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ", DUMP_PREFIX_ADDRESS, 16, 4, ctx->key, @@ -8592,7 +8594,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> badkey: crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN); return -EINVAL; -@@ -1400,7 +580,6 @@ static int gcm_setkey(struct crypto_aead +@@ -1400,7 +581,6 @@ static int gcm_setkey(struct crypto_aead { struct caam_ctx *ctx = crypto_aead_ctx(aead); struct device *jrdev = ctx->jrdev; @@ -8600,7 +8602,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> #ifdef DEBUG print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ", -@@ -1408,21 +587,10 @@ static int gcm_setkey(struct crypto_aead +@@ -1408,21 +588,10 @@ static int gcm_setkey(struct crypto_aead #endif memcpy(ctx->key, key, keylen); @@ -8611,7 +8613,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> - return -ENOMEM; - } - ctx->enckeylen = keylen; -+ dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, DMA_TO_DEVICE); ++ dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, ctx->dir); + ctx->cdata.keylen = keylen; - ret = gcm_set_sh_desc(aead); @@ -8625,7 +8627,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> } static int rfc4106_setkey(struct crypto_aead *aead, -@@ -1430,7 +598,6 @@ static int rfc4106_setkey(struct crypto_ +@@ -1430,7 +599,6 @@ static int rfc4106_setkey(struct crypto_ { struct caam_ctx *ctx = crypto_aead_ctx(aead); struct device *jrdev = ctx->jrdev; @@ -8633,7 +8635,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> if (keylen < 4) return -EINVAL; -@@ -1446,22 +613,10 @@ static int rfc4106_setkey(struct crypto_ +@@ -1446,22 +614,10 @@ static int rfc4106_setkey(struct crypto_ * The last four bytes of the key material are used as the salt value * in the nonce. Update the AES key length. */ @@ -8655,12 +8657,12 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> - return ret; + ctx->cdata.keylen = keylen - 4; + dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen, -+ DMA_TO_DEVICE); ++ ctx->dir); + return rfc4106_set_sh_desc(aead); } static int rfc4543_setkey(struct crypto_aead *aead, -@@ -1469,7 +624,6 @@ static int rfc4543_setkey(struct crypto_ +@@ -1469,7 +625,6 @@ static int rfc4543_setkey(struct crypto_ { struct caam_ctx *ctx = crypto_aead_ctx(aead); struct device *jrdev = ctx->jrdev; @@ -8668,7 +8670,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> if (keylen < 4) return -EINVAL; -@@ -1485,43 +639,28 @@ static int rfc4543_setkey(struct crypto_ +@@ -1485,43 +640,28 @@ static int rfc4543_setkey(struct crypto_ * The last four bytes of the key material are used as the salt value * in the nonce. Update the AES key length. */ @@ -8690,7 +8692,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> - return ret; + ctx->cdata.keylen = keylen - 4; + dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen, -+ DMA_TO_DEVICE); ++ ctx->dir); + return rfc4543_set_sh_desc(aead); } @@ -8719,7 +8721,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> #ifdef DEBUG print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ", DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); -@@ -1544,215 +683,33 @@ static int ablkcipher_setkey(struct cryp +@@ -1544,215 +684,33 @@ static int ablkcipher_setkey(struct cryp keylen -= CTR_RFC3686_NONCE_SIZE; } @@ -8766,11 +8768,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> - /* Load iv */ - append_seq_load(desc, crt->ivsize, LDST_SRCDST_BYTE_CONTEXT | - LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT)); -+ cnstr_shdsc_ablkcipher_encap(desc, &ctx->cdata, ivsize, is_rfc3686, -+ ctx1_iv_off); -+ dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); - +- - /* Load counter into CONTEXT1 reg */ - if (is_rfc3686) - append_load_imm_be32(desc, 1, LDST_IMM | LDST_CLASS_1_CCB | @@ -8784,7 +8782,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> - - /* Perform operation */ - ablkcipher_append_src_dst(desc); -- ++ cnstr_shdsc_ablkcipher_encap(desc, &ctx->cdata, ivsize, is_rfc3686, ++ ctx1_iv_off); ++ dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, ++ desc_bytes(desc), ctx->dir); + - ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc, - desc_bytes(desc), - DMA_TO_DEVICE); @@ -8803,7 +8805,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_ablkcipher_decap(desc, &ctx->cdata, ivsize, is_rfc3686, + ctx1_iv_off); + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); - init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX); - /* Skip if already shared */ @@ -8870,7 +8872,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_ablkcipher_givencap(desc, &ctx->cdata, ivsize, is_rfc3686, + ctx1_iv_off); + dma_sync_single_for_device(jrdev, ctx->sh_desc_givenc_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); - init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX); - /* Skip if already shared */ @@ -8952,7 +8954,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> } static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, -@@ -1760,8 +717,7 @@ static int xts_ablkcipher_setkey(struct +@@ -1760,8 +718,7 @@ static int xts_ablkcipher_setkey(struct { struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); struct device *jrdev = ctx->jrdev; @@ -8962,7 +8964,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) { crypto_ablkcipher_set_flags(ablkcipher, -@@ -1771,126 +727,38 @@ static int xts_ablkcipher_setkey(struct +@@ -1771,126 +728,38 @@ static int xts_ablkcipher_setkey(struct } memcpy(ctx->key, key, keylen); @@ -9024,7 +9026,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> -#endif + cnstr_shdsc_xts_ablkcipher_encap(desc, &ctx->cdata); + dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); /* xts_ablkcipher_decrypt shared descriptor */ desc = ctx->sh_desc_dec; @@ -9075,7 +9077,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> -#endif + cnstr_shdsc_xts_ablkcipher_decap(desc, &ctx->cdata); + dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); return 0; } @@ -9102,7 +9104,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> int sec4_sg_bytes; dma_addr_t sec4_sg_dma; struct sec4_sg_entry *sec4_sg; -@@ -1899,12 +767,12 @@ struct aead_edesc { +@@ -1899,12 +768,12 @@ struct aead_edesc { /* * ablkcipher_edesc - s/w-extended ablkcipher descriptor @@ -9118,7 +9120,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> * @hw_desc: the h/w job descriptor followed by any referenced link tables */ struct ablkcipher_edesc { -@@ -1924,10 +792,11 @@ static void caam_unmap(struct device *de +@@ -1924,10 +793,11 @@ static void caam_unmap(struct device *de int sec4_sg_bytes) { if (dst != src) { @@ -9133,7 +9135,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> } if (iv_dma) -@@ -2021,8 +890,7 @@ static void ablkcipher_encrypt_done(stru +@@ -2021,8 +891,7 @@ static void ablkcipher_encrypt_done(stru dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); #endif @@ -9143,7 +9145,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> if (err) caam_jr_strstatus(jrdev, err); -@@ -2031,10 +899,10 @@ static void ablkcipher_encrypt_done(stru +@@ -2031,10 +900,10 @@ static void ablkcipher_encrypt_done(stru print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ", DUMP_PREFIX_ADDRESS, 16, 4, req->info, edesc->src_nents > 1 ? 100 : ivsize, 1); @@ -9157,7 +9159,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> ablkcipher_unmap(jrdev, edesc, req); -@@ -2062,8 +930,7 @@ static void ablkcipher_decrypt_done(stru +@@ -2062,8 +931,7 @@ static void ablkcipher_decrypt_done(stru dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); #endif @@ -9167,7 +9169,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> if (err) caam_jr_strstatus(jrdev, err); -@@ -2071,10 +938,10 @@ static void ablkcipher_decrypt_done(stru +@@ -2071,10 +939,10 @@ static void ablkcipher_decrypt_done(stru print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ", DUMP_PREFIX_ADDRESS, 16, 4, req->info, ivsize, 1); @@ -9181,7 +9183,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> ablkcipher_unmap(jrdev, edesc, req); -@@ -2114,7 +981,7 @@ static void init_aead_job(struct aead_re +@@ -2114,7 +982,7 @@ static void init_aead_job(struct aead_re init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE); if (all_contig) { @@ -9190,7 +9192,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> in_options = 0; } else { src_dma = edesc->sec4_sg_dma; -@@ -2129,7 +996,7 @@ static void init_aead_job(struct aead_re +@@ -2129,7 +997,7 @@ static void init_aead_job(struct aead_re out_options = in_options; if (unlikely(req->src != req->dst)) { @@ -9199,7 +9201,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> dst_dma = sg_dma_address(req->dst); } else { dst_dma = edesc->sec4_sg_dma + -@@ -2147,9 +1014,6 @@ static void init_aead_job(struct aead_re +@@ -2147,9 +1015,6 @@ static void init_aead_job(struct aead_re append_seq_out_ptr(desc, dst_dma, req->assoclen + req->cryptlen - authsize, out_options); @@ -9209,7 +9211,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> } static void init_gcm_job(struct aead_request *req, -@@ -2164,6 +1028,7 @@ static void init_gcm_job(struct aead_req +@@ -2164,6 +1029,7 @@ static void init_gcm_job(struct aead_req unsigned int last; init_aead_job(req, edesc, all_contig, encrypt); @@ -9217,7 +9219,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> /* BUG This should not be specific to generic GCM. */ last = 0; -@@ -2175,7 +1040,7 @@ static void init_gcm_job(struct aead_req +@@ -2175,7 +1041,7 @@ static void init_gcm_job(struct aead_req FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1 | 12 | last); /* Append Salt */ if (!generic_gcm) @@ -9226,7 +9228,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> /* Append IV */ append_data(desc, req->iv, ivsize); /* End of blank commands */ -@@ -2190,7 +1055,8 @@ static void init_authenc_job(struct aead +@@ -2190,7 +1056,8 @@ static void init_authenc_job(struct aead struct caam_aead_alg, aead); unsigned int ivsize = crypto_aead_ivsize(aead); struct caam_ctx *ctx = crypto_aead_ctx(aead); @@ -9236,7 +9238,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> OP_ALG_AAI_CTR_MOD128); const bool is_rfc3686 = alg->caam.rfc3686; u32 *desc = edesc->hw_desc; -@@ -2213,6 +1079,15 @@ static void init_authenc_job(struct aead +@@ -2213,6 +1080,15 @@ static void init_authenc_job(struct aead init_aead_job(req, edesc, all_contig, encrypt); @@ -9252,7 +9254,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> if (ivsize && ((is_rfc3686 && encrypt) || !alg->caam.geniv)) append_load_as_imm(desc, req->iv, ivsize, LDST_CLASS_1_CCB | -@@ -2236,16 +1111,15 @@ static void init_ablkcipher_job(u32 *sh_ +@@ -2236,16 +1112,15 @@ static void init_ablkcipher_job(u32 *sh_ int len, sec4_sg_index = 0; #ifdef DEBUG @@ -9274,7 +9276,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> len = desc_len(sh_desc); init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE); -@@ -2261,7 +1135,7 @@ static void init_ablkcipher_job(u32 *sh_ +@@ -2261,7 +1136,7 @@ static void init_ablkcipher_job(u32 *sh_ append_seq_in_ptr(desc, src_dma, req->nbytes + ivsize, in_options); if (likely(req->src == req->dst)) { @@ -9283,7 +9285,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> dst_dma = sg_dma_address(req->src); } else { dst_dma = edesc->sec4_sg_dma + -@@ -2269,7 +1143,7 @@ static void init_ablkcipher_job(u32 *sh_ +@@ -2269,7 +1144,7 @@ static void init_ablkcipher_job(u32 *sh_ out_options = LDST_SGF; } } else { @@ -9292,7 +9294,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> dst_dma = sg_dma_address(req->dst); } else { dst_dma = edesc->sec4_sg_dma + -@@ -2296,20 +1170,18 @@ static void init_ablkcipher_giv_job(u32 +@@ -2296,20 +1171,18 @@ static void init_ablkcipher_giv_job(u32 int len, sec4_sg_index = 0; #ifdef DEBUG @@ -9317,7 +9319,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> src_dma = sg_dma_address(req->src); in_options = 0; } else { -@@ -2340,87 +1212,100 @@ static struct aead_edesc *aead_edesc_all +@@ -2340,87 +1213,100 @@ static struct aead_edesc *aead_edesc_all struct crypto_aead *aead = crypto_aead_reqtfm(req); struct caam_ctx *ctx = crypto_aead_ctx(aead); struct device *jrdev = ctx->jrdev; @@ -9473,7 +9475,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> edesc->sec4_sg + sec4_sg_index, 0); } -@@ -2573,13 +1458,9 @@ static int aead_decrypt(struct aead_requ +@@ -2573,13 +1459,9 @@ static int aead_decrypt(struct aead_requ u32 *desc; int ret = 0; @@ -9490,7 +9492,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> /* allocate extended descriptor */ edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN, -@@ -2619,51 +1500,80 @@ static struct ablkcipher_edesc *ablkciph +@@ -2619,51 +1501,80 @@ static struct ablkcipher_edesc *ablkciph struct device *jrdev = ctx->jrdev; gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? GFP_KERNEL : GFP_ATOMIC; @@ -9594,7 +9596,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> return ERR_PTR(-ENOMEM); } -@@ -2673,23 +1583,24 @@ static struct ablkcipher_edesc *ablkciph +@@ -2673,23 +1584,24 @@ static struct ablkcipher_edesc *ablkciph edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) + desc_bytes; @@ -9626,7 +9628,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> return ERR_PTR(-ENOMEM); } -@@ -2701,7 +1612,7 @@ static struct ablkcipher_edesc *ablkciph +@@ -2701,7 +1613,7 @@ static struct ablkcipher_edesc *ablkciph sec4_sg_bytes, 1); #endif @@ -9635,7 +9637,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> return edesc; } -@@ -2792,30 +1703,54 @@ static struct ablkcipher_edesc *ablkciph +@@ -2792,30 +1704,54 @@ static struct ablkcipher_edesc *ablkciph struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); struct device *jrdev = ctx->jrdev; @@ -9706,7 +9708,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> } /* -@@ -2825,21 +1760,29 @@ static struct ablkcipher_edesc *ablkciph +@@ -2825,21 +1761,29 @@ static struct ablkcipher_edesc *ablkciph iv_dma = dma_map_single(jrdev, greq->giv, ivsize, DMA_TO_DEVICE); if (dma_mapping_error(jrdev, iv_dma)) { dev_err(jrdev, "unable to map IV\n"); @@ -9742,7 +9744,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> return ERR_PTR(-ENOMEM); } -@@ -2849,24 +1792,24 @@ static struct ablkcipher_edesc *ablkciph +@@ -2849,24 +1793,24 @@ static struct ablkcipher_edesc *ablkciph edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) + desc_bytes; @@ -9777,7 +9779,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> return ERR_PTR(-ENOMEM); } edesc->iv_dma = iv_dma; -@@ -2878,7 +1821,7 @@ static struct ablkcipher_edesc *ablkciph +@@ -2878,7 +1822,7 @@ static struct ablkcipher_edesc *ablkciph sec4_sg_bytes, 1); #endif @@ -9786,7 +9788,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> return edesc; } -@@ -2889,7 +1832,7 @@ static int ablkcipher_givencrypt(struct +@@ -2889,7 +1833,7 @@ static int ablkcipher_givencrypt(struct struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); struct device *jrdev = ctx->jrdev; @@ -9795,7 +9797,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> u32 *desc; int ret = 0; -@@ -2933,7 +1876,6 @@ struct caam_alg_template { +@@ -2933,7 +1877,6 @@ struct caam_alg_template { } template_u; u32 class1_alg_type; u32 class2_alg_type; @@ -9803,7 +9805,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }; static struct caam_alg_template driver_algs[] = { -@@ -3118,7 +2060,6 @@ static struct caam_aead_alg driver_aeads +@@ -3118,7 +2061,6 @@ static struct caam_aead_alg driver_aeads .caam = { .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9811,7 +9813,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3140,7 +2081,6 @@ static struct caam_aead_alg driver_aeads +@@ -3140,7 +2082,6 @@ static struct caam_aead_alg driver_aeads .caam = { .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9819,7 +9821,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3162,7 +2102,6 @@ static struct caam_aead_alg driver_aeads +@@ -3162,7 +2103,6 @@ static struct caam_aead_alg driver_aeads .caam = { .class2_alg_type = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9827,7 +9829,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3184,7 +2123,6 @@ static struct caam_aead_alg driver_aeads +@@ -3184,7 +2124,6 @@ static struct caam_aead_alg driver_aeads .caam = { .class2_alg_type = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9835,7 +9837,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3206,7 +2144,6 @@ static struct caam_aead_alg driver_aeads +@@ -3206,7 +2145,6 @@ static struct caam_aead_alg driver_aeads .caam = { .class2_alg_type = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9843,7 +9845,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3228,7 +2165,6 @@ static struct caam_aead_alg driver_aeads +@@ -3228,7 +2166,6 @@ static struct caam_aead_alg driver_aeads .caam = { .class2_alg_type = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9851,7 +9853,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3250,7 +2186,6 @@ static struct caam_aead_alg driver_aeads +@@ -3250,7 +2187,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9859,7 +9861,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3273,7 +2208,6 @@ static struct caam_aead_alg driver_aeads +@@ -3273,7 +2209,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9867,7 +9869,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3296,7 +2230,6 @@ static struct caam_aead_alg driver_aeads +@@ -3296,7 +2231,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9875,7 +9877,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3319,7 +2252,6 @@ static struct caam_aead_alg driver_aeads +@@ -3319,7 +2253,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9883,7 +9885,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3342,7 +2274,6 @@ static struct caam_aead_alg driver_aeads +@@ -3342,7 +2275,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9891,7 +9893,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3365,7 +2296,6 @@ static struct caam_aead_alg driver_aeads +@@ -3365,7 +2297,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9899,7 +9901,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3388,7 +2318,6 @@ static struct caam_aead_alg driver_aeads +@@ -3388,7 +2319,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9907,7 +9909,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3411,7 +2340,6 @@ static struct caam_aead_alg driver_aeads +@@ -3411,7 +2341,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9915,7 +9917,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3434,7 +2362,6 @@ static struct caam_aead_alg driver_aeads +@@ -3434,7 +2363,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9923,7 +9925,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3457,7 +2384,6 @@ static struct caam_aead_alg driver_aeads +@@ -3457,7 +2385,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9931,7 +9933,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3480,7 +2406,6 @@ static struct caam_aead_alg driver_aeads +@@ -3480,7 +2407,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9939,7 +9941,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3503,7 +2428,6 @@ static struct caam_aead_alg driver_aeads +@@ -3503,7 +2429,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9947,7 +9949,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3526,7 +2450,6 @@ static struct caam_aead_alg driver_aeads +@@ -3526,7 +2451,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9955,7 +9957,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> } }, { -@@ -3549,7 +2472,6 @@ static struct caam_aead_alg driver_aeads +@@ -3549,7 +2473,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9963,7 +9965,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, } }, -@@ -3573,7 +2495,6 @@ static struct caam_aead_alg driver_aeads +@@ -3573,7 +2496,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9971,7 +9973,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3597,7 +2518,6 @@ static struct caam_aead_alg driver_aeads +@@ -3597,7 +2519,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9979,7 +9981,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3621,7 +2541,6 @@ static struct caam_aead_alg driver_aeads +@@ -3621,7 +2542,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9987,7 +9989,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3645,7 +2564,6 @@ static struct caam_aead_alg driver_aeads +@@ -3645,7 +2565,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC_PRECOMP, @@ -9995,7 +9997,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3669,7 +2587,6 @@ static struct caam_aead_alg driver_aeads +@@ -3669,7 +2588,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10003,7 +10005,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3693,7 +2610,6 @@ static struct caam_aead_alg driver_aeads +@@ -3693,7 +2611,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10011,7 +10013,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3717,7 +2633,6 @@ static struct caam_aead_alg driver_aeads +@@ -3717,7 +2634,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10019,7 +10021,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3741,7 +2656,6 @@ static struct caam_aead_alg driver_aeads +@@ -3741,7 +2657,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10027,7 +10029,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3765,7 +2679,6 @@ static struct caam_aead_alg driver_aeads +@@ -3765,7 +2680,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10035,7 +10037,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3789,7 +2702,6 @@ static struct caam_aead_alg driver_aeads +@@ -3789,7 +2703,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10043,7 +10045,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3812,7 +2724,6 @@ static struct caam_aead_alg driver_aeads +@@ -3812,7 +2725,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10051,7 +10053,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3835,7 +2746,6 @@ static struct caam_aead_alg driver_aeads +@@ -3835,7 +2747,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10059,7 +10061,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3858,7 +2768,6 @@ static struct caam_aead_alg driver_aeads +@@ -3858,7 +2769,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10067,7 +10069,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3881,7 +2790,6 @@ static struct caam_aead_alg driver_aeads +@@ -3881,7 +2791,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10075,7 +10077,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3904,7 +2812,6 @@ static struct caam_aead_alg driver_aeads +@@ -3904,7 +2813,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10083,7 +10085,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3927,7 +2834,6 @@ static struct caam_aead_alg driver_aeads +@@ -3927,7 +2835,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10091,7 +10093,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3950,7 +2856,6 @@ static struct caam_aead_alg driver_aeads +@@ -3950,7 +2857,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10099,7 +10101,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -3973,7 +2878,6 @@ static struct caam_aead_alg driver_aeads +@@ -3973,7 +2879,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10107,7 +10109,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -3996,7 +2900,6 @@ static struct caam_aead_alg driver_aeads +@@ -3996,7 +2901,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10115,7 +10117,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -4019,7 +2922,6 @@ static struct caam_aead_alg driver_aeads +@@ -4019,7 +2923,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10123,7 +10125,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -4042,7 +2944,6 @@ static struct caam_aead_alg driver_aeads +@@ -4042,7 +2945,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10131,7 +10133,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, }, { -@@ -4065,7 +2966,6 @@ static struct caam_aead_alg driver_aeads +@@ -4065,7 +2967,6 @@ static struct caam_aead_alg driver_aeads .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .class2_alg_type = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10139,7 +10141,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .geniv = true, }, }, -@@ -4090,7 +2990,6 @@ static struct caam_aead_alg driver_aeads +@@ -4090,7 +2991,6 @@ static struct caam_aead_alg driver_aeads OP_ALG_AAI_CTR_MOD128, .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10147,7 +10149,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .rfc3686 = true, }, }, -@@ -4115,7 +3014,6 @@ static struct caam_aead_alg driver_aeads +@@ -4115,7 +3015,6 @@ static struct caam_aead_alg driver_aeads OP_ALG_AAI_CTR_MOD128, .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10155,7 +10157,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .rfc3686 = true, .geniv = true, }, -@@ -4141,7 +3039,6 @@ static struct caam_aead_alg driver_aeads +@@ -4141,7 +3040,6 @@ static struct caam_aead_alg driver_aeads OP_ALG_AAI_CTR_MOD128, .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10163,7 +10165,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .rfc3686 = true, }, }, -@@ -4166,7 +3063,6 @@ static struct caam_aead_alg driver_aeads +@@ -4166,7 +3064,6 @@ static struct caam_aead_alg driver_aeads OP_ALG_AAI_CTR_MOD128, .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10171,7 +10173,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .rfc3686 = true, .geniv = true, }, -@@ -4192,7 +3088,6 @@ static struct caam_aead_alg driver_aeads +@@ -4192,7 +3089,6 @@ static struct caam_aead_alg driver_aeads OP_ALG_AAI_CTR_MOD128, .class2_alg_type = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10179,7 +10181,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .rfc3686 = true, }, }, -@@ -4217,7 +3112,6 @@ static struct caam_aead_alg driver_aeads +@@ -4217,7 +3113,6 @@ static struct caam_aead_alg driver_aeads OP_ALG_AAI_CTR_MOD128, .class2_alg_type = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10187,7 +10189,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .rfc3686 = true, .geniv = true, }, -@@ -4243,7 +3137,6 @@ static struct caam_aead_alg driver_aeads +@@ -4243,7 +3138,6 @@ static struct caam_aead_alg driver_aeads OP_ALG_AAI_CTR_MOD128, .class2_alg_type = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10195,7 +10197,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .rfc3686 = true, }, }, -@@ -4268,7 +3161,6 @@ static struct caam_aead_alg driver_aeads +@@ -4268,7 +3162,6 @@ static struct caam_aead_alg driver_aeads OP_ALG_AAI_CTR_MOD128, .class2_alg_type = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10203,7 +10205,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .rfc3686 = true, .geniv = true, }, -@@ -4294,7 +3186,6 @@ static struct caam_aead_alg driver_aeads +@@ -4294,7 +3187,6 @@ static struct caam_aead_alg driver_aeads OP_ALG_AAI_CTR_MOD128, .class2_alg_type = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10211,7 +10213,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .rfc3686 = true, }, }, -@@ -4319,7 +3210,6 @@ static struct caam_aead_alg driver_aeads +@@ -4319,7 +3211,6 @@ static struct caam_aead_alg driver_aeads OP_ALG_AAI_CTR_MOD128, .class2_alg_type = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10219,7 +10221,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .rfc3686 = true, .geniv = true, }, -@@ -4345,7 +3235,6 @@ static struct caam_aead_alg driver_aeads +@@ -4345,7 +3236,6 @@ static struct caam_aead_alg driver_aeads OP_ALG_AAI_CTR_MOD128, .class2_alg_type = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10227,7 +10229,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .rfc3686 = true, }, }, -@@ -4370,7 +3259,6 @@ static struct caam_aead_alg driver_aeads +@@ -4370,7 +3260,6 @@ static struct caam_aead_alg driver_aeads OP_ALG_AAI_CTR_MOD128, .class2_alg_type = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC_PRECOMP, @@ -10235,11 +10237,16 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> .rfc3686 = true, .geniv = true, }, -@@ -4385,16 +3273,34 @@ struct caam_crypto_alg { +@@ -4383,18 +3272,44 @@ struct caam_crypto_alg { + struct caam_alg_entry caam; + }; - static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam) +-static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam) ++static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam, ++ bool uses_dkp) { + dma_addr_t dma_addr; ++ struct caam_drv_private *priv; + ctx->jrdev = caam_jr_alloc(); if (IS_ERR(ctx->jrdev)) { @@ -10247,10 +10254,16 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> return PTR_ERR(ctx->jrdev); } ++ priv = dev_get_drvdata(ctx->jrdev->parent); ++ if (priv->era >= 6 && uses_dkp) ++ ctx->dir = DMA_BIDIRECTIONAL; ++ else ++ ctx->dir = DMA_TO_DEVICE; ++ + dma_addr = dma_map_single_attrs(ctx->jrdev, ctx->sh_desc_enc, + offsetof(struct caam_ctx, + sh_desc_enc_dma), -+ DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC); ++ ctx->dir, DMA_ATTR_SKIP_CPU_SYNC); + if (dma_mapping_error(ctx->jrdev, dma_addr)) { + dev_err(ctx->jrdev, "unable to map key, shared descriptors\n"); + caam_jr_free(ctx->jrdev); @@ -10273,7 +10286,23 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> return 0; } -@@ -4421,25 +3327,9 @@ static int caam_aead_init(struct crypto_ +@@ -4406,7 +3321,7 @@ static int caam_cra_init(struct crypto_t + container_of(alg, struct caam_crypto_alg, crypto_alg); + struct caam_ctx *ctx = crypto_tfm_ctx(tfm); + +- return caam_init_common(ctx, &caam_alg->caam); ++ return caam_init_common(ctx, &caam_alg->caam, false); + } + + static int caam_aead_init(struct crypto_aead *tfm) +@@ -4416,30 +3331,15 @@ static int caam_aead_init(struct crypto_ + container_of(alg, struct caam_aead_alg, aead); + struct caam_ctx *ctx = crypto_aead_ctx(tfm); + +- return caam_init_common(ctx, &caam_alg->caam); ++ return caam_init_common(ctx, &caam_alg->caam, ++ alg->setkey == aead_setkey); + } static void caam_exit_common(struct caam_ctx *ctx) { @@ -10298,11 +10327,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> - + dma_unmap_single_attrs(ctx->jrdev, ctx->sh_desc_enc_dma, + offsetof(struct caam_ctx, sh_desc_enc_dma), -+ DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC); ++ ctx->dir, DMA_ATTR_SKIP_CPU_SYNC); caam_jr_free(ctx->jrdev); } -@@ -4515,7 +3405,6 @@ static struct caam_crypto_alg *caam_alg_ +@@ -4515,7 +3415,6 @@ static struct caam_crypto_alg *caam_alg_ t_alg->caam.class1_alg_type = template->class1_alg_type; t_alg->caam.class2_alg_type = template->class2_alg_type; @@ -11206,10 +11235,10 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + /* VSOL = payloadlen + icvlen + padlen */ + append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, 4); + -+#ifdef __LITTLE_ENDIAN -+ append_moveb(desc, MOVE_WAITCOMP | -+ MOVE_SRC_MATH0 | MOVE_DEST_MATH0 | 8); -+#endif ++ if (caam_little_end) ++ append_moveb(desc, MOVE_WAITCOMP | ++ MOVE_SRC_MATH0 | MOVE_DEST_MATH0 | 8); ++ + /* update Len field */ + append_math_sub(desc, REG0, REG0, REG2, 8); + @@ -11259,15 +11288,15 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + * SEQ OUT PTR command, Output Pointer (2 words) and + * Output Length into math registers. + */ -+#ifdef __LITTLE_ENDIAN -+ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_DESCBUF | -+ MOVE_DEST_MATH0 | (55 * 4 << MOVE_OFFSET_SHIFT) | -+ 20); -+#else -+ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_DESCBUF | -+ MOVE_DEST_MATH0 | (54 * 4 << MOVE_OFFSET_SHIFT) | -+ 20); -+#endif ++ if (caam_little_end) ++ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_DESCBUF | ++ MOVE_DEST_MATH0 | ++ (55 * 4 << MOVE_OFFSET_SHIFT) | 20); ++ else ++ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_DESCBUF | ++ MOVE_DEST_MATH0 | ++ (54 * 4 << MOVE_OFFSET_SHIFT) | 20); ++ + /* Transform SEQ OUT PTR command in SEQ IN PTR command */ + append_math_and_imm_u32(desc, REG0, REG0, IMM, + ~(CMD_SEQ_IN_PTR ^ CMD_SEQ_OUT_PTR)); @@ -11278,15 +11307,15 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + (4 << LDST_OFFSET_SHIFT)); + append_jump(desc, JUMP_TEST_ALL | JUMP_COND_CALM | 1); + /* Move the updated fields back to the Job Descriptor */ -+#ifdef __LITTLE_ENDIAN -+ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH0 | -+ MOVE_DEST_DESCBUF | (55 * 4 << MOVE_OFFSET_SHIFT) | -+ 24); -+#else -+ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH0 | -+ MOVE_DEST_DESCBUF | (54 * 4 << MOVE_OFFSET_SHIFT) | -+ 24); -+#endif ++ if (caam_little_end) ++ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH0 | ++ MOVE_DEST_DESCBUF | ++ (55 * 4 << MOVE_OFFSET_SHIFT) | 24); ++ else ++ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH0 | ++ MOVE_DEST_DESCBUF | ++ (54 * 4 << MOVE_OFFSET_SHIFT) | 24); ++ + /* + * Read the new SEQ IN PTR command, Input Pointer, Input Length + * and then jump back to the next command from the @@ -11298,15 +11327,15 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + * Move the SEQ OUT PTR command, Output Pointer (1 word) and + * Output Length into math registers. + */ -+#ifdef __LITTLE_ENDIAN -+ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_DESCBUF | -+ MOVE_DEST_MATH0 | (54 * 4 << MOVE_OFFSET_SHIFT) | -+ 12); -+#else -+ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_DESCBUF | -+ MOVE_DEST_MATH0 | (53 * 4 << MOVE_OFFSET_SHIFT) | -+ 12); -+#endif ++ if (caam_little_end) ++ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_DESCBUF | ++ MOVE_DEST_MATH0 | ++ (54 * 4 << MOVE_OFFSET_SHIFT) | 12); ++ else ++ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_DESCBUF | ++ MOVE_DEST_MATH0 | ++ (53 * 4 << MOVE_OFFSET_SHIFT) | 12); ++ + /* Transform SEQ OUT PTR command in SEQ IN PTR command */ + append_math_and_imm_u64(desc, REG0, REG0, IMM, + ~(((u64)(CMD_SEQ_IN_PTR ^ @@ -11318,15 +11347,15 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + (4 << LDST_OFFSET_SHIFT)); + append_jump(desc, JUMP_TEST_ALL | JUMP_COND_CALM | 1); + /* Move the updated fields back to the Job Descriptor */ -+#ifdef __LITTLE_ENDIAN -+ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH0 | -+ MOVE_DEST_DESCBUF | (54 * 4 << MOVE_OFFSET_SHIFT) | -+ 16); -+#else -+ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH0 | -+ MOVE_DEST_DESCBUF | (53 * 4 << MOVE_OFFSET_SHIFT) | -+ 16); -+#endif ++ if (caam_little_end) ++ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH0 | ++ MOVE_DEST_DESCBUF | ++ (54 * 4 << MOVE_OFFSET_SHIFT) | 16); ++ else ++ append_move(desc, MOVE_WAITCOMP | MOVE_SRC_MATH0 | ++ MOVE_DEST_DESCBUF | ++ (53 * 4 << MOVE_OFFSET_SHIFT) | 16); ++ + /* + * Read the new SEQ IN PTR command, Input Pointer, Input Length + * and then jump back to the next command from the @@ -12406,7 +12435,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +#endif /* _CAAMALG_DESC_H_ */ --- /dev/null +++ b/drivers/crypto/caam/caamalg_qi.c -@@ -0,0 +1,2929 @@ +@@ -0,0 +1,3321 @@ +/* + * Freescale FSL CAAM support for crypto API over QI backend. + * Based on caamalg.c @@ -12462,6 +12491,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + u32 sh_desc_givenc[DESC_MAX_USED_LEN]; + u8 key[CAAM_MAX_KEY_SIZE]; + dma_addr_t key_dma; ++ enum dma_data_direction dir; + struct alginfo adata; + struct alginfo cdata; + unsigned int authsize; @@ -12640,7 +12670,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + keys.enckeylen); + dma_sync_single_for_device(jrdev, ctx->key_dma, + ctx->adata.keylen_pad + -+ keys.enckeylen, DMA_TO_DEVICE); ++ keys.enckeylen, ctx->dir); + goto skip_split_key; + } + @@ -12653,7 +12683,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + /* postpend encryption key to auth split key */ + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen); + dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->adata.keylen_pad + -+ keys.enckeylen, DMA_TO_DEVICE); ++ keys.enckeylen, ctx->dir); +#ifdef DEBUG + print_hex_dump(KERN_ERR, "ctx.key@" __stringify(__LINE__)": ", + DUMP_PREFIX_ADDRESS, 16, 4, ctx->key, @@ -12796,7 +12826,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + keys.enckeylen); + dma_sync_single_for_device(jrdev, ctx->key_dma, + ctx->adata.keylen_pad + -+ keys.enckeylen, DMA_TO_DEVICE); ++ keys.enckeylen, ctx->dir); + goto skip_split_key; + } + @@ -12809,7 +12839,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + /* postpend encryption key to auth split key */ + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen); + dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->adata.keylen_pad + -+ keys.enckeylen, DMA_TO_DEVICE); ++ keys.enckeylen, ctx->dir); + +#ifdef DEBUG + dev_err(jrdev, "split keylen %d split keylen padded %d\n", @@ -12851,6 +12881,309 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + return -EINVAL; +} + ++static int gcm_set_sh_desc(struct crypto_aead *aead) ++{ ++ struct caam_ctx *ctx = crypto_aead_ctx(aead); ++ unsigned int ivsize = crypto_aead_ivsize(aead); ++ int rem_bytes = CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN - ++ ctx->cdata.keylen; ++ ++ if (!ctx->cdata.keylen || !ctx->authsize) ++ return 0; ++ ++ /* ++ * Job Descriptor and Shared Descriptor ++ * must fit into the 64-word Descriptor h/w Buffer ++ */ ++ if (rem_bytes >= DESC_QI_GCM_ENC_LEN) { ++ ctx->cdata.key_inline = true; ++ ctx->cdata.key_virt = ctx->key; ++ } else { ++ ctx->cdata.key_inline = false; ++ ctx->cdata.key_dma = ctx->key_dma; ++ } ++ ++ cnstr_shdsc_gcm_encap(ctx->sh_desc_enc, &ctx->cdata, ivsize, ++ ctx->authsize, true); ++ ++ /* ++ * Job Descriptor and Shared Descriptor ++ * must fit into the 64-word Descriptor h/w Buffer ++ */ ++ if (rem_bytes >= DESC_QI_GCM_DEC_LEN) { ++ ctx->cdata.key_inline = true; ++ ctx->cdata.key_virt = ctx->key; ++ } else { ++ ctx->cdata.key_inline = false; ++ ctx->cdata.key_dma = ctx->key_dma; ++ } ++ ++ cnstr_shdsc_gcm_decap(ctx->sh_desc_dec, &ctx->cdata, ivsize, ++ ctx->authsize, true); ++ ++ return 0; ++} ++ ++static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize) ++{ ++ struct caam_ctx *ctx = crypto_aead_ctx(authenc); ++ ++ ctx->authsize = authsize; ++ gcm_set_sh_desc(authenc); ++ ++ return 0; ++} ++ ++static int gcm_setkey(struct crypto_aead *aead, ++ const u8 *key, unsigned int keylen) ++{ ++ struct caam_ctx *ctx = crypto_aead_ctx(aead); ++ struct device *jrdev = ctx->jrdev; ++ int ret; ++ ++#ifdef DEBUG ++ print_hex_dump(KERN_ERR, "key in @" __stringify(__LINE__)": ", ++ DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); ++#endif ++ ++ memcpy(ctx->key, key, keylen); ++ dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, ctx->dir); ++ ctx->cdata.keylen = keylen; ++ ++ ret = gcm_set_sh_desc(aead); ++ if (ret) ++ return ret; ++ ++ /* Now update the driver contexts with the new shared descriptor */ ++ if (ctx->drv_ctx[ENCRYPT]) { ++ ret = caam_drv_ctx_update(ctx->drv_ctx[ENCRYPT], ++ ctx->sh_desc_enc); ++ if (ret) { ++ dev_err(jrdev, "driver enc context update failed\n"); ++ return ret; ++ } ++ } ++ ++ if (ctx->drv_ctx[DECRYPT]) { ++ ret = caam_drv_ctx_update(ctx->drv_ctx[DECRYPT], ++ ctx->sh_desc_dec); ++ if (ret) { ++ dev_err(jrdev, "driver dec context update failed\n"); ++ return ret; ++ } ++ } ++ ++ return 0; ++} ++ ++static int rfc4106_set_sh_desc(struct crypto_aead *aead) ++{ ++ struct caam_ctx *ctx = crypto_aead_ctx(aead); ++ unsigned int ivsize = crypto_aead_ivsize(aead); ++ int rem_bytes = CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN - ++ ctx->cdata.keylen; ++ ++ if (!ctx->cdata.keylen || !ctx->authsize) ++ return 0; ++ ++ ctx->cdata.key_virt = ctx->key; ++ ++ /* ++ * Job Descriptor and Shared Descriptor ++ * must fit into the 64-word Descriptor h/w Buffer ++ */ ++ if (rem_bytes >= DESC_QI_RFC4106_ENC_LEN) { ++ ctx->cdata.key_inline = true; ++ } else { ++ ctx->cdata.key_inline = false; ++ ctx->cdata.key_dma = ctx->key_dma; ++ } ++ ++ cnstr_shdsc_rfc4106_encap(ctx->sh_desc_enc, &ctx->cdata, ivsize, ++ ctx->authsize, true); ++ ++ /* ++ * Job Descriptor and Shared Descriptor ++ * must fit into the 64-word Descriptor h/w Buffer ++ */ ++ if (rem_bytes >= DESC_QI_RFC4106_DEC_LEN) { ++ ctx->cdata.key_inline = true; ++ } else { ++ ctx->cdata.key_inline = false; ++ ctx->cdata.key_dma = ctx->key_dma; ++ } ++ ++ cnstr_shdsc_rfc4106_decap(ctx->sh_desc_dec, &ctx->cdata, ivsize, ++ ctx->authsize, true); ++ ++ return 0; ++} ++ ++static int rfc4106_setauthsize(struct crypto_aead *authenc, ++ unsigned int authsize) ++{ ++ struct caam_ctx *ctx = crypto_aead_ctx(authenc); ++ ++ ctx->authsize = authsize; ++ rfc4106_set_sh_desc(authenc); ++ ++ return 0; ++} ++ ++static int rfc4106_setkey(struct crypto_aead *aead, ++ const u8 *key, unsigned int keylen) ++{ ++ struct caam_ctx *ctx = crypto_aead_ctx(aead); ++ struct device *jrdev = ctx->jrdev; ++ int ret; ++ ++ if (keylen < 4) ++ return -EINVAL; ++ ++#ifdef DEBUG ++ print_hex_dump(KERN_ERR, "key in @" __stringify(__LINE__)": ", ++ DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); ++#endif ++ ++ memcpy(ctx->key, key, keylen); ++ /* ++ * The last four bytes of the key material are used as the salt value ++ * in the nonce. Update the AES key length. ++ */ ++ ctx->cdata.keylen = keylen - 4; ++ dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen, ++ ctx->dir); ++ ++ ret = rfc4106_set_sh_desc(aead); ++ if (ret) ++ return ret; ++ ++ /* Now update the driver contexts with the new shared descriptor */ ++ if (ctx->drv_ctx[ENCRYPT]) { ++ ret = caam_drv_ctx_update(ctx->drv_ctx[ENCRYPT], ++ ctx->sh_desc_enc); ++ if (ret) { ++ dev_err(jrdev, "driver enc context update failed\n"); ++ return ret; ++ } ++ } ++ ++ if (ctx->drv_ctx[DECRYPT]) { ++ ret = caam_drv_ctx_update(ctx->drv_ctx[DECRYPT], ++ ctx->sh_desc_dec); ++ if (ret) { ++ dev_err(jrdev, "driver dec context update failed\n"); ++ return ret; ++ } ++ } ++ ++ return 0; ++} ++ ++static int rfc4543_set_sh_desc(struct crypto_aead *aead) ++{ ++ struct caam_ctx *ctx = crypto_aead_ctx(aead); ++ unsigned int ivsize = crypto_aead_ivsize(aead); ++ int rem_bytes = CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN - ++ ctx->cdata.keylen; ++ ++ if (!ctx->cdata.keylen || !ctx->authsize) ++ return 0; ++ ++ ctx->cdata.key_virt = ctx->key; ++ ++ /* ++ * Job Descriptor and Shared Descriptor ++ * must fit into the 64-word Descriptor h/w Buffer ++ */ ++ if (rem_bytes >= DESC_QI_RFC4543_ENC_LEN) { ++ ctx->cdata.key_inline = true; ++ } else { ++ ctx->cdata.key_inline = false; ++ ctx->cdata.key_dma = ctx->key_dma; ++ } ++ ++ cnstr_shdsc_rfc4543_encap(ctx->sh_desc_enc, &ctx->cdata, ivsize, ++ ctx->authsize, true); ++ ++ /* ++ * Job Descriptor and Shared Descriptor ++ * must fit into the 64-word Descriptor h/w Buffer ++ */ ++ if (rem_bytes >= DESC_QI_RFC4543_DEC_LEN) { ++ ctx->cdata.key_inline = true; ++ } else { ++ ctx->cdata.key_inline = false; ++ ctx->cdata.key_dma = ctx->key_dma; ++ } ++ ++ cnstr_shdsc_rfc4543_decap(ctx->sh_desc_dec, &ctx->cdata, ivsize, ++ ctx->authsize, true); ++ ++ return 0; ++} ++ ++static int rfc4543_setauthsize(struct crypto_aead *authenc, ++ unsigned int authsize) ++{ ++ struct caam_ctx *ctx = crypto_aead_ctx(authenc); ++ ++ ctx->authsize = authsize; ++ rfc4543_set_sh_desc(authenc); ++ ++ return 0; ++} ++ ++static int rfc4543_setkey(struct crypto_aead *aead, ++ const u8 *key, unsigned int keylen) ++{ ++ struct caam_ctx *ctx = crypto_aead_ctx(aead); ++ struct device *jrdev = ctx->jrdev; ++ int ret; ++ ++ if (keylen < 4) ++ return -EINVAL; ++ ++#ifdef DEBUG ++ print_hex_dump(KERN_ERR, "key in @" __stringify(__LINE__)": ", ++ DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); ++#endif ++ ++ memcpy(ctx->key, key, keylen); ++ /* ++ * The last four bytes of the key material are used as the salt value ++ * in the nonce. Update the AES key length. ++ */ ++ ctx->cdata.keylen = keylen - 4; ++ dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen, ++ ctx->dir); ++ ++ ret = rfc4543_set_sh_desc(aead); ++ if (ret) ++ return ret; ++ ++ /* Now update the driver contexts with the new shared descriptor */ ++ if (ctx->drv_ctx[ENCRYPT]) { ++ ret = caam_drv_ctx_update(ctx->drv_ctx[ENCRYPT], ++ ctx->sh_desc_enc); ++ if (ret) { ++ dev_err(jrdev, "driver enc context update failed\n"); ++ return ret; ++ } ++ } ++ ++ if (ctx->drv_ctx[DECRYPT]) { ++ ret = caam_drv_ctx_update(ctx->drv_ctx[DECRYPT], ++ ctx->sh_desc_dec); ++ if (ret) { ++ dev_err(jrdev, "driver dec context update failed\n"); ++ return ret; ++ } ++ } ++ ++ return 0; ++} ++ +static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, + const u8 *key, unsigned int keylen) +{ @@ -13169,8 +13502,18 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + qidev = caam_ctx->qidev; + + if (unlikely(status)) { ++ u32 ssrc = status & JRSTA_SSRC_MASK; ++ u8 err_id = status & JRSTA_CCBERR_ERRID_MASK; ++ + caam_jr_strstatus(qidev, status); -+ ecode = -EIO; ++ /* ++ * verify hw auth check passed else return -EBADMSG ++ */ ++ if (ssrc == JRSTA_SSRC_CCB_ERROR && ++ err_id == JRSTA_CCBERR_ERRID_ICVCHK) ++ ecode = -EBADMSG; ++ else ++ ecode = -EIO; + } + + edesc = container_of(drv_req, typeof(*edesc), drv_req); @@ -13414,6 +13757,22 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + return aead_crypt(req, false); +} + ++static int ipsec_gcm_encrypt(struct aead_request *req) ++{ ++ if (req->assoclen < 8) ++ return -EINVAL; ++ ++ return aead_crypt(req, true); ++} ++ ++static int ipsec_gcm_decrypt(struct aead_request *req) ++{ ++ if (req->assoclen < 8) ++ return -EINVAL; ++ ++ return aead_crypt(req, false); ++} ++ +static void tls_done(struct caam_drv_req *drv_req, u32 status) +{ + struct device *qidev; @@ -14168,6 +14527,61 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +}; + +static struct caam_aead_alg driver_aeads[] = { ++ { ++ .aead = { ++ .base = { ++ .cra_name = "rfc4106(gcm(aes))", ++ .cra_driver_name = "rfc4106-gcm-aes-caam-qi", ++ .cra_blocksize = 1, ++ }, ++ .setkey = rfc4106_setkey, ++ .setauthsize = rfc4106_setauthsize, ++ .encrypt = ipsec_gcm_encrypt, ++ .decrypt = ipsec_gcm_decrypt, ++ .ivsize = 8, ++ .maxauthsize = AES_BLOCK_SIZE, ++ }, ++ .caam = { ++ .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM, ++ }, ++ }, ++ { ++ .aead = { ++ .base = { ++ .cra_name = "rfc4543(gcm(aes))", ++ .cra_driver_name = "rfc4543-gcm-aes-caam-qi", ++ .cra_blocksize = 1, ++ }, ++ .setkey = rfc4543_setkey, ++ .setauthsize = rfc4543_setauthsize, ++ .encrypt = ipsec_gcm_encrypt, ++ .decrypt = ipsec_gcm_decrypt, ++ .ivsize = 8, ++ .maxauthsize = AES_BLOCK_SIZE, ++ }, ++ .caam = { ++ .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM, ++ }, ++ }, ++ /* Galois Counter Mode */ ++ { ++ .aead = { ++ .base = { ++ .cra_name = "gcm(aes)", ++ .cra_driver_name = "gcm-aes-caam-qi", ++ .cra_blocksize = 1, ++ }, ++ .setkey = gcm_setkey, ++ .setauthsize = gcm_setauthsize, ++ .encrypt = aead_encrypt, ++ .decrypt = aead_decrypt, ++ .ivsize = 12, ++ .maxauthsize = AES_BLOCK_SIZE, ++ }, ++ .caam = { ++ .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM, ++ } ++ }, + /* single-pass ipsec_esp descriptor */ + { + .aead = { @@ -15006,7 +15420,8 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + struct caam_alg_entry caam; +}; + -+static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam) ++static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam, ++ bool uses_dkp) +{ + struct caam_drv_private *priv; + /* Digest sizes for MD5, SHA1, SHA-224, SHA-256, SHA-384, SHA-512 */ @@ -15030,8 +15445,14 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + return PTR_ERR(ctx->jrdev); + } + ++ priv = dev_get_drvdata(ctx->jrdev->parent); ++ if (priv->era >= 6 && uses_dkp) ++ ctx->dir = DMA_BIDIRECTIONAL; ++ else ++ ctx->dir = DMA_TO_DEVICE; ++ + ctx->key_dma = dma_map_single(ctx->jrdev, ctx->key, sizeof(ctx->key), -+ DMA_TO_DEVICE); ++ ctx->dir); + if (dma_mapping_error(ctx->jrdev, ctx->key_dma)) { + dev_err(ctx->jrdev, "unable to map key\n"); + caam_jr_free(ctx->jrdev); @@ -15058,7 +15479,6 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + ctx->authsize = 0; + } + -+ priv = dev_get_drvdata(ctx->jrdev->parent); + ctx->qidev = priv->qidev; + + spin_lock_init(&ctx->lock); @@ -15076,7 +15496,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + crypto_alg); + struct caam_ctx *ctx = crypto_tfm_ctx(tfm); + -+ return caam_init_common(ctx, &caam_alg->caam); ++ return caam_init_common(ctx, &caam_alg->caam, false); +} + +static int caam_aead_init(struct crypto_aead *tfm) @@ -15086,7 +15506,9 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + aead); + struct caam_ctx *ctx = crypto_aead_ctx(tfm); + -+ return caam_init_common(ctx, &caam_alg->caam); ++ return caam_init_common(ctx, &caam_alg->caam, ++ (alg->setkey == aead_setkey) || ++ (alg->setkey == tls_setkey)); +} + +static void caam_exit_common(struct caam_ctx *ctx) @@ -15095,8 +15517,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + caam_drv_ctx_rel(ctx->drv_ctx[DECRYPT]); + caam_drv_ctx_rel(ctx->drv_ctx[GIVENCRYPT]); + -+ dma_unmap_single(ctx->jrdev, ctx->key_dma, sizeof(ctx->key), -+ DMA_TO_DEVICE); ++ dma_unmap_single(ctx->jrdev, ctx->key_dma, sizeof(ctx->key), ctx->dir); + + caam_jr_free(ctx->jrdev); +} @@ -15338,7 +15759,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +MODULE_AUTHOR("Freescale Semiconductor"); --- /dev/null +++ b/drivers/crypto/caam/caamalg_qi2.c -@@ -0,0 +1,5920 @@ +@@ -0,0 +1,5938 @@ +/* + * Copyright 2015-2016 Freescale Semiconductor Inc. + * Copyright 2017 NXP @@ -15373,6 +15794,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + * POSSIBILITY OF SUCH DAMAGE. + */ + ++#include <linux/fsl/mc.h> +#include "compat.h" +#include "regs.h" +#include "caamalg_qi2.h" @@ -15384,7 +15806,6 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +#include "key_gen.h" +#include "caamalg_desc.h" +#include "caamhash_desc.h" -+#include "../../../drivers/staging/fsl-mc/include/mc.h" +#include "../../../drivers/staging/fsl-mc/include/dpaa2-io.h" +#include "../../../drivers/staging/fsl-mc/include/dpaa2-fd.h" + @@ -15432,6 +15853,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + * @key: virtual address of the key(s): [authentication key], encryption key + * @flc_dma: I/O virtual addresses of the Flow Contexts + * @key_dma: I/O virtual address of the key ++ * @dir: DMA direction for mapping key and Flow Contexts + * @dev: dpseci device + * @adata: authentication algorithm details + * @cdata: encryption algorithm details @@ -15442,6 +15864,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + u8 key[CAAM_MAX_KEY_SIZE]; + dma_addr_t flc_dma[NUM_OP]; + dma_addr_t key_dma; ++ enum dma_data_direction dir; + struct device *dev; + struct alginfo adata; + struct alginfo cdata; @@ -15604,10 +16027,10 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + ivsize, ctx->authsize, is_rfc3686, nonce, + ctx1_iv_off, true, priv->sec_attr.era); + -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + /* aead_decrypt shared descriptor */ + if (desc_inline_query(DESC_QI_AEAD_DEC_LEN + @@ -15635,10 +16058,10 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + ivsize, ctx->authsize, alg->caam.geniv, + is_rfc3686, nonce, ctx1_iv_off, true, + priv->sec_attr.era); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + return 0; +} @@ -15702,7 +16125,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + memcpy(ctx->key, keys.authkey, keys.authkeylen); + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen); + dma_sync_single_for_device(dev, ctx->key_dma, ctx->adata.keylen_pad + -+ keys.enckeylen, DMA_BIDIRECTIONAL); ++ keys.enckeylen, ctx->dir); +#ifdef DEBUG + print_hex_dump(KERN_ERR, "ctx.key@" __stringify(__LINE__)": ", + DUMP_PREFIX_ADDRESS, 16, 4, ctx->key, @@ -15843,7 +16266,8 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + edesc->dst_nents = dst_nents; + edesc->iv_dma = iv_dma; + -+ edesc->assoclen_dma = dma_map_single(dev, &req->assoclen, 4, ++ edesc->assoclen = cpu_to_caam32(req->assoclen); ++ edesc->assoclen_dma = dma_map_single(dev, &edesc->assoclen, 4, + DMA_TO_DEVICE); + if (dma_mapping_error(dev, edesc->assoclen_dma)) { + dev_err(dev, "unable to map assoclen\n"); @@ -16135,10 +16559,10 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_tls_encap(desc, &ctx->cdata, &ctx->adata, + assoclen, ivsize, ctx->authsize, blocksize, + priv->sec_attr.era); -+ flc->flc[1] = desc_len(desc); ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + /* + * TLS 1.0 decrypt shared descriptor @@ -16152,10 +16576,10 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + desc = flc->sh_desc; + cnstr_shdsc_tls_decap(desc, &ctx->cdata, &ctx->adata, assoclen, ivsize, + ctx->authsize, blocksize, priv->sec_attr.era); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + return 0; +} @@ -16188,7 +16612,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + memcpy(ctx->key, keys.authkey, keys.authkeylen); + memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen); + dma_sync_single_for_device(dev, ctx->key_dma, ctx->adata.keylen_pad + -+ keys.enckeylen, DMA_BIDIRECTIONAL); ++ keys.enckeylen, ctx->dir); +#ifdef DEBUG + print_hex_dump(KERN_ERR, "ctx.key@" __stringify(__LINE__)": ", + DUMP_PREFIX_ADDRESS, 16, 4, ctx->key, @@ -16242,10 +16666,10 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + flc = &ctx->flc[ENCRYPT]; + desc = flc->sh_desc; + cnstr_shdsc_gcm_encap(desc, &ctx->cdata, ivsize, ctx->authsize, true); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + /* + * Job Descriptor and Shared Descriptors @@ -16262,10 +16686,10 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + flc = &ctx->flc[DECRYPT]; + desc = flc->sh_desc; + cnstr_shdsc_gcm_decap(desc, &ctx->cdata, ivsize, ctx->authsize, true); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + return 0; +} @@ -16292,8 +16716,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +#endif + + memcpy(ctx->key, key, keylen); -+ dma_sync_single_for_device(dev, ctx->key_dma, keylen, -+ DMA_BIDIRECTIONAL); ++ dma_sync_single_for_device(dev, ctx->key_dma, keylen, ctx->dir); + ctx->cdata.keylen = keylen; + + return gcm_set_sh_desc(aead); @@ -16330,10 +16753,10 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + desc = flc->sh_desc; + cnstr_shdsc_rfc4106_encap(desc, &ctx->cdata, ivsize, ctx->authsize, + true); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + /* + * Job Descriptor and Shared Descriptors @@ -16350,10 +16773,10 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + desc = flc->sh_desc; + cnstr_shdsc_rfc4106_decap(desc, &ctx->cdata, ivsize, ctx->authsize, + true); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + return 0; +} @@ -16390,7 +16813,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + */ + ctx->cdata.keylen = keylen - 4; + dma_sync_single_for_device(dev, ctx->key_dma, ctx->cdata.keylen, -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + return rfc4106_set_sh_desc(aead); +} @@ -16426,10 +16849,10 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + desc = flc->sh_desc; + cnstr_shdsc_rfc4543_encap(desc, &ctx->cdata, ivsize, ctx->authsize, + true); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + /* + * Job Descriptor and Shared Descriptors @@ -16446,10 +16869,10 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + desc = flc->sh_desc; + cnstr_shdsc_rfc4543_decap(desc, &ctx->cdata, ivsize, ctx->authsize, + true); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + return 0; +} @@ -16486,7 +16909,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + */ + ctx->cdata.keylen = keylen - 4; + dma_sync_single_for_device(dev, ctx->key_dma, ctx->cdata.keylen, -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + return rfc4543_set_sh_desc(aead); +} @@ -16537,30 +16960,30 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + desc = flc->sh_desc; + cnstr_shdsc_ablkcipher_encap(desc, &ctx->cdata, ivsize, + is_rfc3686, ctx1_iv_off); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + /* ablkcipher_decrypt shared descriptor */ + flc = &ctx->flc[DECRYPT]; + desc = flc->sh_desc; + cnstr_shdsc_ablkcipher_decap(desc, &ctx->cdata, ivsize, + is_rfc3686, ctx1_iv_off); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + /* ablkcipher_givencrypt shared descriptor */ + flc = &ctx->flc[GIVENCRYPT]; + desc = flc->sh_desc; + cnstr_shdsc_ablkcipher_givencap(desc, &ctx->cdata, + ivsize, is_rfc3686, ctx1_iv_off); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[GIVENCRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + return 0; +} @@ -16588,19 +17011,19 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + flc = &ctx->flc[ENCRYPT]; + desc = flc->sh_desc; + cnstr_shdsc_xts_ablkcipher_encap(desc, &ctx->cdata); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[ENCRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + /* xts_ablkcipher_decrypt shared descriptor */ + flc = &ctx->flc[DECRYPT]; + desc = flc->sh_desc; + cnstr_shdsc_xts_ablkcipher_decap(desc, &ctx->cdata); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(dev, ctx->flc_dma[DECRYPT], + sizeof(flc->flc) + desc_bytes(desc), -+ DMA_BIDIRECTIONAL); ++ ctx->dir); + + return 0; +} @@ -17324,7 +17747,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + struct caam_alg_entry caam; +}; + -+static int caam_cra_init(struct crypto_tfm *tfm) ++static int caam_cra_init(struct crypto_tfm *tfm, bool uses_dkp) +{ + struct crypto_alg *alg = tfm->__crt_alg; + struct caam_crypto_alg *caam_alg = container_of(alg, typeof(*caam_alg), @@ -17340,11 +17763,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + caam_alg->caam.class2_alg_type; + + ctx->dev = caam_alg->caam.dev; ++ ctx->dir = uses_dkp ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE; + + dma_addr = dma_map_single_attrs(ctx->dev, ctx->flc, + offsetof(struct caam_ctx, flc_dma), -+ DMA_BIDIRECTIONAL, -+ DMA_ATTR_SKIP_CPU_SYNC); ++ ctx->dir, DMA_ATTR_SKIP_CPU_SYNC); + if (dma_mapping_error(ctx->dev, dma_addr)) { + dev_err(ctx->dev, "unable to map key, shared descriptors\n"); + return -ENOMEM; @@ -17363,20 +17786,24 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + crypto_ablkcipher_crt(__crypto_ablkcipher_cast(tfm)); + + ablkcipher_tfm->reqsize = sizeof(struct caam_request); -+ return caam_cra_init(tfm); ++ return caam_cra_init(tfm, false); +} + +static int caam_cra_init_aead(struct crypto_aead *tfm) +{ ++ struct aead_alg *alg = crypto_aead_alg(tfm); ++ + crypto_aead_set_reqsize(tfm, sizeof(struct caam_request)); -+ return caam_cra_init(crypto_aead_tfm(tfm)); ++ return caam_cra_init(crypto_aead_tfm(tfm), ++ (alg->setkey == aead_setkey) || ++ (alg->setkey == tls_setkey)); +} + +static void caam_exit_common(struct caam_ctx *ctx) +{ + dma_unmap_single_attrs(ctx->dev, ctx->flc_dma[0], -+ offsetof(struct caam_ctx, flc_dma), -+ DMA_BIDIRECTIONAL, DMA_ATTR_SKIP_CPU_SYNC); ++ offsetof(struct caam_ctx, flc_dma), ctx->dir, ++ DMA_ATTR_SKIP_CPU_SYNC); +} + +static void caam_cra_exit(struct crypto_tfm *tfm) @@ -18891,7 +19318,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + desc = flc->sh_desc; + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_UPDATE, ctx->ctx_len, + ctx->ctx_len, true, priv->sec_attr.era); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(ctx->dev, ctx->flc_dma[UPDATE], + desc_bytes(desc), DMA_BIDIRECTIONAL); +#ifdef DEBUG @@ -18905,7 +19332,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + desc = flc->sh_desc; + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_INIT, ctx->ctx_len, + ctx->ctx_len, false, priv->sec_attr.era); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(ctx->dev, ctx->flc_dma[UPDATE_FIRST], + desc_bytes(desc), DMA_BIDIRECTIONAL); +#ifdef DEBUG @@ -18919,7 +19346,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + desc = flc->sh_desc; + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_FINALIZE, digestsize, + ctx->ctx_len, true, priv->sec_attr.era); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(ctx->dev, ctx->flc_dma[FINALIZE], + desc_bytes(desc), DMA_BIDIRECTIONAL); +#ifdef DEBUG @@ -18933,7 +19360,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + desc = flc->sh_desc; + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_INITFINAL, digestsize, + ctx->ctx_len, false, priv->sec_attr.era); -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + dma_sync_single_for_device(ctx->dev, ctx->flc_dma[DIGEST], + desc_bytes(desc), DMA_BIDIRECTIONAL); +#ifdef DEBUG @@ -18994,7 +19421,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + append_seq_store(desc, digestsize, LDST_CLASS_2_CCB | + LDST_SRCDST_BYTE_CONTEXT); + -+ flc->flc[1] = desc_len(desc); /* SDL */ ++ flc->flc[1] = cpu_to_caam32(desc_len(desc)); /* SDL */ + flc_dma = dma_map_single(ctx->dev, flc, sizeof(flc->flc) + + desc_bytes(desc), DMA_TO_DEVICE); + if (dma_mapping_error(ctx->dev, flc_dma)) { @@ -20412,6 +20839,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + template->name); + snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", + template->driver_name); ++ t_alg->ahash_alg.setkey = NULL; + } + alg->cra_module = THIS_MODULE; + alg->cra_init = caam_hash_cra_init; @@ -20456,8 +20884,15 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + /* Register notification callbacks */ + err = dpaa2_io_service_register(NULL, nctx); + if (unlikely(err)) { -+ dev_err(dev, "notification register failed\n"); ++ dev_dbg(dev, "No affine DPIO for cpu %d\n", cpu); + nctx->cb = NULL; ++ /* ++ * If no affine DPIO for this core, there's probably ++ * none available for next cores either. Signal we want ++ * to retry later, in case the DPIO devices weren't ++ * probed yet. ++ */ ++ err = -EPROBE_DEFER; + goto err; + } + @@ -20935,7 +21370,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + /* Obtain a MC portal */ + err = fsl_mc_portal_allocate(dpseci_dev, 0, &priv->mc_io); + if (err) { -+ dev_err(dev, "MC portal allocation failed\n"); ++ if (err == -ENXIO) ++ err = -EPROBE_DEFER; ++ else ++ dev_err(dev, "MC portal allocation failed\n"); ++ + goto err_dma_mask; + } + @@ -21204,7 +21643,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + memset(&fd, 0, sizeof(fd)); + dpaa2_fd_set_format(&fd, dpaa2_fd_list); + dpaa2_fd_set_addr(&fd, req->fd_flt_dma); -+ dpaa2_fd_set_len(&fd, req->fd_flt[1].len); ++ dpaa2_fd_set_len(&fd, dpaa2_fl_get_len(&req->fd_flt[1])); + dpaa2_fd_set_flc(&fd, req->flc_dma); + + /* @@ -21261,7 +21700,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +module_fsl_mc_driver(dpaa2_caam_driver); --- /dev/null +++ b/drivers/crypto/caam/caamalg_qi2.h -@@ -0,0 +1,281 @@ +@@ -0,0 +1,283 @@ +/* + * Copyright 2015-2016 Freescale Semiconductor Inc. + * Copyright 2017 NXP @@ -21418,6 +21857,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + * @iv_dma: dma address of iv for checking continuity and link table + * @qm_sg_bytes: length of dma mapped h/w link table + * @qm_sg_dma: bus physical mapped address of h/w link table ++ * @assoclen: associated data length, in CAAM endianness + * @assoclen_dma: bus physical mapped address of req->assoclen + * @sgt: the h/w link table + */ @@ -21427,6 +21867,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + dma_addr_t iv_dma; + int qm_sg_bytes; + dma_addr_t qm_sg_dma; ++ unsigned int assoclen; + dma_addr_t assoclen_dma; +#define CAAM_QI_MAX_AEAD_SG \ + ((CAAM_QI_MEMCACHE_SIZE - offsetof(struct aead_edesc, sgt)) / \ @@ -21568,7 +22009,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> #define DESC_HASH_MAX_USED_BYTES (DESC_AHASH_FINAL_LEN + \ CAAM_MAX_HASH_KEY_SIZE) #define DESC_HASH_MAX_USED_LEN (DESC_HASH_MAX_USED_BYTES / CAAM_CMD_SZ) -@@ -103,20 +96,14 @@ struct caam_hash_ctx { +@@ -103,20 +96,15 @@ struct caam_hash_ctx { u32 sh_desc_update_first[DESC_HASH_MAX_USED_LEN] ____cacheline_aligned; u32 sh_desc_fin[DESC_HASH_MAX_USED_LEN] ____cacheline_aligned; u32 sh_desc_digest[DESC_HASH_MAX_USED_LEN] ____cacheline_aligned; @@ -21578,6 +22019,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> dma_addr_t sh_desc_fin_dma; dma_addr_t sh_desc_digest_dma; - dma_addr_t sh_desc_finup_dma; ++ enum dma_data_direction dir; struct device *jrdev; - u32 alg_type; - u32 alg_op; @@ -21590,7 +22032,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }; /* ahash state */ -@@ -143,6 +130,31 @@ struct caam_export_state { +@@ -143,6 +131,31 @@ struct caam_export_state { int (*finup)(struct ahash_request *req); }; @@ -21622,7 +22064,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> /* Common job descriptor seq in/out ptr routines */ /* Map state->caam_ctx, and append seq_out_ptr command that points to it */ -@@ -175,40 +187,31 @@ static inline dma_addr_t map_seq_out_ptr +@@ -175,40 +188,31 @@ static inline dma_addr_t map_seq_out_ptr return dst_dma; } @@ -21680,7 +22122,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> struct caam_hash_state *state, int ctx_len, struct sec4_sg_entry *sec4_sg, u32 flag) { -@@ -224,124 +227,22 @@ static inline int ctx_map_to_sec4_sg(u32 +@@ -224,124 +228,22 @@ static inline int ctx_map_to_sec4_sg(u32 return 0; } @@ -21807,11 +22249,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_UPDATE, ctx->ctx_len, + ctx->ctx_len, true, ctrlpriv->era); + dma_sync_single_for_device(jrdev, ctx->sh_desc_update_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); #ifdef DEBUG print_hex_dump(KERN_ERR, "ahash update shdesc@"__stringify(__LINE__)": ", -@@ -350,17 +251,10 @@ static int ahash_set_sh_desc(struct cryp +@@ -350,17 +252,10 @@ static int ahash_set_sh_desc(struct cryp /* ahash_update_first shared descriptor */ desc = ctx->sh_desc_update_first; @@ -21829,11 +22271,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_INIT, ctx->ctx_len, + ctx->ctx_len, false, ctrlpriv->era); + dma_sync_single_for_device(jrdev, ctx->sh_desc_update_first_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); #ifdef DEBUG print_hex_dump(KERN_ERR, "ahash update first shdesc@"__stringify(__LINE__)": ", -@@ -369,53 +263,22 @@ static int ahash_set_sh_desc(struct cryp +@@ -369,53 +264,22 @@ static int ahash_set_sh_desc(struct cryp /* ahash_final shared descriptor */ desc = ctx->sh_desc_fin; @@ -21850,7 +22292,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_FINALIZE, digestsize, + ctx->ctx_len, true, ctrlpriv->era); + dma_sync_single_for_device(jrdev, ctx->sh_desc_fin_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); #ifdef DEBUG print_hex_dump(KERN_ERR, "ahash final shdesc@"__stringify(__LINE__)": ", DUMP_PREFIX_ADDRESS, 16, 4, desc, @@ -21891,11 +22333,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + cnstr_shdsc_ahash(desc, &ctx->adata, OP_ALG_AS_INITFINAL, digestsize, + ctx->ctx_len, false, ctrlpriv->era); + dma_sync_single_for_device(jrdev, ctx->sh_desc_digest_dma, -+ desc_bytes(desc), DMA_TO_DEVICE); ++ desc_bytes(desc), ctx->dir); #ifdef DEBUG print_hex_dump(KERN_ERR, "ahash digest shdesc@"__stringify(__LINE__)": ", -@@ -426,14 +289,6 @@ static int ahash_set_sh_desc(struct cryp +@@ -426,14 +290,6 @@ static int ahash_set_sh_desc(struct cryp return 0; } @@ -21910,7 +22352,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> /* Digest hash size if it is too large */ static int hash_digest_key(struct caam_hash_ctx *ctx, const u8 *key_in, u32 *keylen, u8 *key_out, u32 digestsize) -@@ -469,7 +324,7 @@ static int hash_digest_key(struct caam_h +@@ -469,7 +325,7 @@ static int hash_digest_key(struct caam_h } /* Job descriptor to perform unkeyed hash on key_in */ @@ -21919,7 +22361,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> OP_ALG_AS_INITFINAL); append_seq_in_ptr(desc, src_dma, *keylen, 0); append_seq_fifo_load(desc, *keylen, FIFOLD_CLASS_CLASS2 | -@@ -513,12 +368,10 @@ static int hash_digest_key(struct caam_h +@@ -513,12 +369,10 @@ static int hash_digest_key(struct caam_h static int ahash_setkey(struct crypto_ahash *ahash, const u8 *key, unsigned int keylen) { @@ -21933,7 +22375,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> int ret; u8 *hashed_key = NULL; -@@ -539,43 +392,29 @@ static int ahash_setkey(struct crypto_ah +@@ -539,43 +393,29 @@ static int ahash_setkey(struct crypto_ah key = hashed_key; } @@ -21995,7 +22437,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> bad_free_key: kfree(hashed_key); crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN); -@@ -604,6 +443,8 @@ static inline void ahash_unmap(struct de +@@ -604,6 +444,8 @@ static inline void ahash_unmap(struct de struct ahash_edesc *edesc, struct ahash_request *req, int dst_len) { @@ -22004,7 +22446,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> if (edesc->src_nents) dma_unmap_sg(dev, req->src, edesc->src_nents, DMA_TO_DEVICE); if (edesc->dst_dma) -@@ -612,6 +453,12 @@ static inline void ahash_unmap(struct de +@@ -612,6 +454,12 @@ static inline void ahash_unmap(struct de if (edesc->sec4_sg_bytes) dma_unmap_single(dev, edesc->sec4_sg_dma, edesc->sec4_sg_bytes, DMA_TO_DEVICE); @@ -22017,7 +22459,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> } static inline void ahash_unmap_ctx(struct device *dev, -@@ -643,8 +490,7 @@ static void ahash_done(struct device *jr +@@ -643,8 +491,7 @@ static void ahash_done(struct device *jr dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); #endif @@ -22027,7 +22469,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> if (err) caam_jr_strstatus(jrdev, err); -@@ -671,19 +517,19 @@ static void ahash_done_bi(struct device +@@ -671,19 +518,19 @@ static void ahash_done_bi(struct device struct ahash_edesc *edesc; struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); @@ -22050,7 +22492,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> kfree(edesc); #ifdef DEBUG -@@ -713,8 +559,7 @@ static void ahash_done_ctx_src(struct de +@@ -713,8 +560,7 @@ static void ahash_done_ctx_src(struct de dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); #endif @@ -22060,7 +22502,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> if (err) caam_jr_strstatus(jrdev, err); -@@ -741,19 +586,19 @@ static void ahash_done_ctx_dst(struct de +@@ -741,19 +587,19 @@ static void ahash_done_ctx_dst(struct de struct ahash_edesc *edesc; struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); @@ -22083,7 +22525,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> kfree(edesc); #ifdef DEBUG -@@ -835,13 +680,12 @@ static int ahash_update_ctx(struct ahash +@@ -835,13 +681,12 @@ static int ahash_update_ctx(struct ahash struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); struct caam_hash_state *state = ahash_request_ctx(req); struct device *jrdev = ctx->jrdev; @@ -22103,7 +22545,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> int in_len = *buflen + req->nbytes, to_hash; u32 *desc; int src_nents, mapped_nents, sec4_sg_bytes, sec4_sg_src_index; -@@ -890,15 +734,14 @@ static int ahash_update_ctx(struct ahash +@@ -890,15 +735,14 @@ static int ahash_update_ctx(struct ahash edesc->src_nents = src_nents; edesc->sec4_sg_bytes = sec4_sg_bytes; @@ -22123,7 +22565,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> if (mapped_nents) { sg_to_sec4_sg_last(req->src, mapped_nents, -@@ -909,12 +752,10 @@ static int ahash_update_ctx(struct ahash +@@ -909,12 +753,10 @@ static int ahash_update_ctx(struct ahash to_hash - *buflen, *next_buflen, 0); } else { @@ -22138,7 +22580,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> desc = edesc->hw_desc; edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg, -@@ -969,12 +810,9 @@ static int ahash_final_ctx(struct ahash_ +@@ -969,12 +811,9 @@ static int ahash_final_ctx(struct ahash_ struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); struct caam_hash_state *state = ahash_request_ctx(req); struct device *jrdev = ctx->jrdev; @@ -22154,7 +22596,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> u32 *desc; int sec4_sg_bytes, sec4_sg_src_index; int digestsize = crypto_ahash_digestsize(ahash); -@@ -994,18 +832,17 @@ static int ahash_final_ctx(struct ahash_ +@@ -994,18 +833,17 @@ static int ahash_final_ctx(struct ahash_ desc = edesc->hw_desc; edesc->sec4_sg_bytes = sec4_sg_bytes; @@ -22179,7 +22621,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg, sec4_sg_bytes, DMA_TO_DEVICE); -@@ -1048,12 +885,9 @@ static int ahash_finup_ctx(struct ahash_ +@@ -1048,12 +886,9 @@ static int ahash_finup_ctx(struct ahash_ struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); struct caam_hash_state *state = ahash_request_ctx(req); struct device *jrdev = ctx->jrdev; @@ -22195,7 +22637,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> u32 *desc; int sec4_sg_src_index; int src_nents, mapped_nents; -@@ -1082,7 +916,7 @@ static int ahash_finup_ctx(struct ahash_ +@@ -1082,7 +917,7 @@ static int ahash_finup_ctx(struct ahash_ /* allocate space for base edesc and hw desc commands, link tables */ edesc = ahash_edesc_alloc(ctx, sec4_sg_src_index + mapped_nents, @@ -22204,7 +22646,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> flags); if (!edesc) { dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE); -@@ -1093,14 +927,14 @@ static int ahash_finup_ctx(struct ahash_ +@@ -1093,14 +928,14 @@ static int ahash_finup_ctx(struct ahash_ edesc->src_nents = src_nents; @@ -22223,7 +22665,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> ret = ahash_edesc_add_src(ctx, edesc, req, mapped_nents, sec4_sg_src_index, ctx->ctx_len + buflen, -@@ -1136,15 +970,18 @@ static int ahash_digest(struct ahash_req +@@ -1136,15 +971,18 @@ static int ahash_digest(struct ahash_req { struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); @@ -22244,7 +22686,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> src_nents = sg_nents_for_len(req->src, req->nbytes); if (src_nents < 0) { dev_err(jrdev, "Invalid number of src SG.\n"); -@@ -1215,10 +1052,10 @@ static int ahash_final_no_ctx(struct aha +@@ -1215,10 +1053,10 @@ static int ahash_final_no_ctx(struct aha struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); struct caam_hash_state *state = ahash_request_ctx(req); struct device *jrdev = ctx->jrdev; @@ -22259,7 +22701,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> u32 *desc; int digestsize = crypto_ahash_digestsize(ahash); struct ahash_edesc *edesc; -@@ -1246,7 +1083,6 @@ static int ahash_final_no_ctx(struct aha +@@ -1246,7 +1084,6 @@ static int ahash_final_no_ctx(struct aha dev_err(jrdev, "unable to map dst\n"); goto unmap; } @@ -22267,7 +22709,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> #ifdef DEBUG print_hex_dump(KERN_ERR, "jobdesc@"__stringify(__LINE__)": ", -@@ -1276,13 +1112,12 @@ static int ahash_update_no_ctx(struct ah +@@ -1276,13 +1113,12 @@ static int ahash_update_no_ctx(struct ah struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); struct caam_hash_state *state = ahash_request_ctx(req); struct device *jrdev = ctx->jrdev; @@ -22287,7 +22729,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> int in_len = *buflen + req->nbytes, to_hash; int sec4_sg_bytes, src_nents, mapped_nents; struct ahash_edesc *edesc; -@@ -1329,10 +1164,11 @@ static int ahash_update_no_ctx(struct ah +@@ -1329,10 +1165,11 @@ static int ahash_update_no_ctx(struct ah edesc->src_nents = src_nents; edesc->sec4_sg_bytes = sec4_sg_bytes; @@ -22302,7 +22744,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> sg_to_sec4_sg_last(req->src, mapped_nents, edesc->sec4_sg + 1, 0); -@@ -1342,8 +1178,6 @@ static int ahash_update_no_ctx(struct ah +@@ -1342,8 +1179,6 @@ static int ahash_update_no_ctx(struct ah *next_buflen, 0); } @@ -22311,7 +22753,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> desc = edesc->hw_desc; edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg, -@@ -1403,12 +1237,9 @@ static int ahash_finup_no_ctx(struct aha +@@ -1403,12 +1238,9 @@ static int ahash_finup_no_ctx(struct aha struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); struct caam_hash_state *state = ahash_request_ctx(req); struct device *jrdev = ctx->jrdev; @@ -22327,7 +22769,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> u32 *desc; int sec4_sg_bytes, sec4_sg_src_index, src_nents, mapped_nents; int digestsize = crypto_ahash_digestsize(ahash); -@@ -1450,9 +1281,9 @@ static int ahash_finup_no_ctx(struct aha +@@ -1450,9 +1282,9 @@ static int ahash_finup_no_ctx(struct aha edesc->src_nents = src_nents; edesc->sec4_sg_bytes = sec4_sg_bytes; @@ -22340,7 +22782,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> ret = ahash_edesc_add_src(ctx, edesc, req, mapped_nents, 1, buflen, req->nbytes); -@@ -1496,11 +1327,10 @@ static int ahash_update_first(struct aha +@@ -1496,11 +1328,10 @@ static int ahash_update_first(struct aha struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); struct caam_hash_state *state = ahash_request_ctx(req); struct device *jrdev = ctx->jrdev; @@ -22356,7 +22798,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> int to_hash; u32 *desc; int src_nents, mapped_nents; -@@ -1545,7 +1375,6 @@ static int ahash_update_first(struct aha +@@ -1545,7 +1376,6 @@ static int ahash_update_first(struct aha } edesc->src_nents = src_nents; @@ -22364,7 +22806,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> ret = ahash_edesc_add_src(ctx, edesc, req, mapped_nents, 0, 0, to_hash); -@@ -1582,6 +1411,7 @@ static int ahash_update_first(struct aha +@@ -1582,6 +1412,7 @@ static int ahash_update_first(struct aha state->final = ahash_final_no_ctx; scatterwalk_map_and_copy(next_buf, req->src, 0, req->nbytes, 0); @@ -22372,7 +22814,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> } #ifdef DEBUG print_hex_dump(KERN_ERR, "next buf@"__stringify(__LINE__)": ", -@@ -1688,7 +1518,6 @@ struct caam_hash_template { +@@ -1688,7 +1519,6 @@ struct caam_hash_template { unsigned int blocksize; struct ahash_alg template_ahash; u32 alg_type; @@ -22380,7 +22822,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }; /* ahash descriptors */ -@@ -1714,7 +1543,6 @@ static struct caam_hash_template driver_ +@@ -1714,7 +1544,6 @@ static struct caam_hash_template driver_ }, }, .alg_type = OP_ALG_ALGSEL_SHA1, @@ -22388,7 +22830,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, { .name = "sha224", .driver_name = "sha224-caam", -@@ -1736,7 +1564,6 @@ static struct caam_hash_template driver_ +@@ -1736,7 +1565,6 @@ static struct caam_hash_template driver_ }, }, .alg_type = OP_ALG_ALGSEL_SHA224, @@ -22396,7 +22838,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, { .name = "sha256", .driver_name = "sha256-caam", -@@ -1758,7 +1585,6 @@ static struct caam_hash_template driver_ +@@ -1758,7 +1586,6 @@ static struct caam_hash_template driver_ }, }, .alg_type = OP_ALG_ALGSEL_SHA256, @@ -22404,7 +22846,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, { .name = "sha384", .driver_name = "sha384-caam", -@@ -1780,7 +1606,6 @@ static struct caam_hash_template driver_ +@@ -1780,7 +1607,6 @@ static struct caam_hash_template driver_ }, }, .alg_type = OP_ALG_ALGSEL_SHA384, @@ -22412,7 +22854,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, { .name = "sha512", .driver_name = "sha512-caam", -@@ -1802,7 +1627,6 @@ static struct caam_hash_template driver_ +@@ -1802,7 +1628,6 @@ static struct caam_hash_template driver_ }, }, .alg_type = OP_ALG_ALGSEL_SHA512, @@ -22420,7 +22862,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> }, { .name = "md5", .driver_name = "md5-caam", -@@ -1824,14 +1648,12 @@ static struct caam_hash_template driver_ +@@ -1824,14 +1649,12 @@ static struct caam_hash_template driver_ }, }, .alg_type = OP_ALG_ALGSEL_MD5, @@ -22435,23 +22877,27 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> struct ahash_alg ahash_alg; }; -@@ -1853,6 +1675,7 @@ static int caam_hash_cra_init(struct cry +@@ -1853,6 +1676,8 @@ static int caam_hash_cra_init(struct cry HASH_MSG_LEN + SHA256_DIGEST_SIZE, HASH_MSG_LEN + 64, HASH_MSG_LEN + SHA512_DIGEST_SIZE }; + dma_addr_t dma_addr; ++ struct caam_drv_private *priv; /* * Get a Job ring from Job Ring driver to ensure in-order -@@ -1863,11 +1686,31 @@ static int caam_hash_cra_init(struct cry +@@ -1863,11 +1688,34 @@ static int caam_hash_cra_init(struct cry pr_err("Job Ring Device allocation for transform failed\n"); return PTR_ERR(ctx->jrdev); } + ++ priv = dev_get_drvdata(ctx->jrdev->parent); ++ ctx->dir = priv->era >= 6 ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE; ++ + dma_addr = dma_map_single_attrs(ctx->jrdev, ctx->sh_desc_update, + offsetof(struct caam_hash_ctx, + sh_desc_update_dma), -+ DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC); ++ ctx->dir, DMA_ATTR_SKIP_CPU_SYNC); + if (dma_mapping_error(ctx->jrdev, dma_addr)) { + dev_err(ctx->jrdev, "unable to map shared descriptors\n"); + caam_jr_free(ctx->jrdev); @@ -22478,7 +22924,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> OP_ALG_ALGSEL_SHIFT]; crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), -@@ -1879,30 +1722,10 @@ static void caam_hash_cra_exit(struct cr +@@ -1879,30 +1727,10 @@ static void caam_hash_cra_exit(struct cr { struct caam_hash_ctx *ctx = crypto_tfm_ctx(tfm); @@ -22509,11 +22955,11 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + dma_unmap_single_attrs(ctx->jrdev, ctx->sh_desc_update_dma, + offsetof(struct caam_hash_ctx, + sh_desc_update_dma), -+ DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC); ++ ctx->dir, DMA_ATTR_SKIP_CPU_SYNC); caam_jr_free(ctx->jrdev); } -@@ -1961,7 +1784,6 @@ caam_hash_alloc(struct caam_hash_templat +@@ -1961,7 +1789,6 @@ caam_hash_alloc(struct caam_hash_templat alg->cra_type = &crypto_ahash_type; t_alg->alg_type = template->alg_type; @@ -24571,7 +25017,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +#endif /* DESC_CONSTR_H */ --- /dev/null +++ b/drivers/crypto/caam/dpseci.c -@@ -0,0 +1,859 @@ +@@ -0,0 +1,858 @@ +/* + * Copyright 2013-2016 Freescale Semiconductor Inc. + * Copyright 2017 NXP @@ -24606,8 +25052,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + * POSSIBILITY OF SUCH DAMAGE. + */ + -+#include "../../../drivers/staging/fsl-mc/include/mc-sys.h" -+#include "../../../drivers/staging/fsl-mc/include/mc-cmd.h" ++#include <linux/fsl/mc.h> +#include "../../../drivers/staging/fsl-mc/include/dpopr.h" +#include "dpseci.h" +#include "dpseci_cmd.h" @@ -24631,7 +25076,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpseci_id, + u16 *token) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_open *cmd_params; + int err; + @@ -24662,7 +25107,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + */ +int dpseci_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLOSE, + cmd_flags, @@ -24695,7 +25140,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_create(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags, + const struct dpseci_cfg *cfg, u32 *obj_id) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_create *cmd_params; + int i, err; + @@ -24735,7 +25180,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_destroy(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags, + u32 object_id) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_destroy *cmd_params; + + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DESTROY, @@ -24757,7 +25202,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + */ +int dpseci_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_ENABLE, + cmd_flags, @@ -24775,7 +25220,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + */ +int dpseci_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DISABLE, + cmd_flags, @@ -24796,7 +25241,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_is_enabled(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + int *en) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_rsp_is_enabled *rsp_params; + int err; + @@ -24823,7 +25268,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + */ +int dpseci_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_RESET, + cmd_flags, @@ -24845,7 +25290,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_get_irq_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + u8 irq_index, u8 *en) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_irq_enable *cmd_params; + struct dpseci_rsp_get_irq_enable *rsp_params; + int err; @@ -24883,7 +25328,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_set_irq_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + u8 irq_index, u8 en) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_irq_enable *cmd_params; + + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_IRQ_ENABLE, @@ -24912,7 +25357,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_get_irq_mask(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + u8 irq_index, u32 *mask) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_irq_mask *cmd_params; + int err; + @@ -24949,7 +25394,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_set_irq_mask(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + u8 irq_index, u32 mask) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_irq_mask *cmd_params; + + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_IRQ_MASK, @@ -24977,7 +25422,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_get_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + u8 irq_index, u32 *status) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_irq_status *cmd_params; + int err; + @@ -25011,7 +25456,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_clear_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + u8 irq_index, u32 status) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_irq_status *cmd_params; + + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLEAR_IRQ_STATUS, @@ -25036,7 +25481,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + struct dpseci_attr *attr) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_rsp_get_attributes *rsp_params; + int err; + @@ -25071,7 +25516,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_set_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + u8 queue, const struct dpseci_rx_queue_cfg *cfg) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_queue *cmd_params; + + cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE, @@ -25104,7 +25549,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + u8 queue, struct dpseci_rx_queue_attr *attr) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_queue *cmd_params; + int err; + @@ -25142,7 +25587,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + u8 queue, struct dpseci_tx_queue_attr *attr) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_queue *cmd_params; + struct dpseci_rsp_get_tx_queue *rsp_params; + int err; @@ -25175,7 +25620,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_get_sec_attr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + struct dpseci_sec_attr *attr) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_rsp_get_sec_attr *rsp_params; + int err; + @@ -25220,7 +25665,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_get_sec_counters(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, + struct dpseci_sec_counters *counters) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_rsp_get_sec_counters *rsp_params; + int err; + @@ -25256,7 +25701,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags, + u16 *major_ver, u16 *minor_ver) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_rsp_get_api_version *rsp_params; + int err; + @@ -25288,7 +25733,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_set_opr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u8 index, + u8 options, struct opr_cfg *cfg) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_opr *cmd_params; + + cmd.header = mc_encode_cmd_header( @@ -25321,7 +25766,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_get_opr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u8 index, + struct opr_cfg *cfg, struct opr_qry *qry) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_opr *cmd_params; + struct dpseci_rsp_get_opr *rsp_params; + int err; @@ -25370,7 +25815,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_set_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags, + u16 token, const struct dpseci_congestion_notification_cfg *cfg) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_congestion_notification *cmd_params; + + cmd.header = mc_encode_cmd_header( @@ -25405,7 +25850,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +int dpseci_get_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags, + u16 token, struct dpseci_congestion_notification_cfg *cfg) +{ -+ struct mc_command cmd = { 0 }; ++ struct fsl_mc_command cmd = { 0 }; + struct dpseci_cmd_congestion_notification *rsp_params; + int err; + @@ -26735,7 +27180,7 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> +} --- /dev/null +++ b/drivers/crypto/caam/qi.c -@@ -0,0 +1,797 @@ +@@ -0,0 +1,804 @@ +/* + * CAAM/SEC 4.x QI transport/backend driver + * Queue Interface backend functionality @@ -27314,8 +27759,15 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> + return qman_cb_dqrr_stop; + + fd = &dqrr->fd; -+ if (unlikely(fd->status)) -+ dev_err(qidev, "Error: %#x in CAAM response FD\n", fd->status); ++ if (unlikely(fd->status)) { ++ u32 ssrc = fd->status & JRSTA_SSRC_MASK; ++ u8 err_id = fd->status & JRSTA_CCBERR_ERRID_MASK; ++ ++ if (ssrc != JRSTA_SSRC_CCB_ERROR || ++ err_id != JRSTA_CCBERR_ERRID_ICVCHK) ++ dev_err(qidev, "Error: %#x in CAAM response FD\n", ++ fd->status); ++ } + + if (unlikely(fd->format != fd->format)) { + dev_err(qidev, "Non-compound FD from CAAM\n"); @@ -28162,6 +28614,23 @@ Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> - return sg_nents; -} +#endif /* _SG_SW_SEC4_H_ */ +--- a/drivers/crypto/talitos.c ++++ b/drivers/crypto/talitos.c +@@ -1241,6 +1241,14 @@ static int ipsec_esp(struct talitos_edes + ret = talitos_sg_map_ext(dev, areq->src, cryptlen, edesc, &desc->ptr[4], + sg_count, areq->assoclen, tbl_off, elen); + ++ /* ++ * In case of SEC 2.x+, cipher in len must include only the ciphertext, ++ * while extent is used for ICV len. ++ */ ++ if ((edesc->desc.hdr & DESC_HDR_TYPE_IPSEC_ESP) && ++ (desc->hdr & DESC_HDR_MODE1_MDEU_CICV)) ++ desc->ptr[4].len = cpu_to_be16(cryptlen); ++ + if (ret > 1) { + tbl_off += ret; + sync_needed = true; --- a/drivers/net/wireless/rsi/rsi_91x_usb.c +++ b/drivers/net/wireless/rsi/rsi_91x_usb.c @@ -516,7 +516,7 @@ err: |