summaryrefslogtreecommitdiff
path: root/target/linux/apm821xx/patches-4.14/020-0022-crypto-crypto4xx-simplify-sa-and-state-context-acqui.patch
diff options
context:
space:
mode:
authorChristian Lamparter <chunkeey@gmail.com>2018-01-07 21:27:50 +0100
committerMathias Kresin <dev@kresin.me>2018-01-12 08:00:04 +0100
commit780477d17c0e73e54397a0f3cebff08634e7231a (patch)
tree098826be0c3cbfb24fc1fc15219eed83d915e84a /target/linux/apm821xx/patches-4.14/020-0022-crypto-crypto4xx-simplify-sa-and-state-context-acqui.patch
parente4371779d2691553e6321e87d86212beaaa8b89d (diff)
downloadmtk-20170518-780477d17c0e73e54397a0f3cebff08634e7231a.zip
mtk-20170518-780477d17c0e73e54397a0f3cebff08634e7231a.tar.gz
mtk-20170518-780477d17c0e73e54397a0f3cebff08634e7231a.tar.bz2
apm821xx: backport crypto4xx patches from 4.15
This patch backports changes to crypto4xx in order to get the crypto4xx operational. Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Diffstat (limited to 'target/linux/apm821xx/patches-4.14/020-0022-crypto-crypto4xx-simplify-sa-and-state-context-acqui.patch')
-rw-r--r--target/linux/apm821xx/patches-4.14/020-0022-crypto-crypto4xx-simplify-sa-and-state-context-acqui.patch209
1 files changed, 209 insertions, 0 deletions
diff --git a/target/linux/apm821xx/patches-4.14/020-0022-crypto-crypto4xx-simplify-sa-and-state-context-acqui.patch b/target/linux/apm821xx/patches-4.14/020-0022-crypto-crypto4xx-simplify-sa-and-state-context-acqui.patch
new file mode 100644
index 0000000..06ab798
--- /dev/null
+++ b/target/linux/apm821xx/patches-4.14/020-0022-crypto-crypto4xx-simplify-sa-and-state-context-acqui.patch
@@ -0,0 +1,209 @@
+From 2f77690dcb96e525bc6b57bce4a0eaecaa2878d1 Mon Sep 17 00:00:00 2001
+From: Christian Lamparter <chunkeey@gmail.com>
+Date: Wed, 4 Oct 2017 01:00:14 +0200
+Subject: [PATCH 22/25] crypto: crypto4xx - simplify sa and state context
+ acquisition
+
+Thanks to the big overhaul of crypto4xx_build_pd(), the request-local
+sa_in, sa_out and state_record allocation can be simplified.
+
+There's no need to setup any dma coherent memory anymore and
+much of the support code can be removed.
+
+Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
+Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
+---
+ drivers/crypto/amcc/crypto4xx_alg.c | 27 +++++--------------
+ drivers/crypto/amcc/crypto4xx_core.c | 50 ++++++------------------------------
+ drivers/crypto/amcc/crypto4xx_core.h | 6 +----
+ 3 files changed, 15 insertions(+), 68 deletions(-)
+
+--- a/drivers/crypto/amcc/crypto4xx_alg.c
++++ b/drivers/crypto/amcc/crypto4xx_alg.c
+@@ -122,20 +122,13 @@ static int crypto4xx_setkey_aes(struct c
+ }
+
+ /* Create SA */
+- if (ctx->sa_in_dma_addr || ctx->sa_out_dma_addr)
++ if (ctx->sa_in || ctx->sa_out)
+ crypto4xx_free_sa(ctx);
+
+ rc = crypto4xx_alloc_sa(ctx, SA_AES128_LEN + (keylen-16) / 4);
+ if (rc)
+ return rc;
+
+- if (ctx->state_record_dma_addr == 0) {
+- rc = crypto4xx_alloc_state_record(ctx);
+- if (rc) {
+- crypto4xx_free_sa(ctx);
+- return rc;
+- }
+- }
+ /* Setup SA */
+ sa = ctx->sa_in;
+
+@@ -203,8 +196,8 @@ int crypto4xx_setkey_rfc3686(struct cryp
+ if (rc)
+ return rc;
+
+- crypto4xx_memcpy_to_le32(ctx->state_record->save_iv,
+- key + keylen - CTR_RFC3686_NONCE_SIZE, CTR_RFC3686_NONCE_SIZE);
++ ctx->iv_nonce = cpu_to_le32p((u32 *)&key[keylen -
++ CTR_RFC3686_NONCE_SIZE]);
+
+ return 0;
+ }
+@@ -213,7 +206,7 @@ int crypto4xx_rfc3686_encrypt(struct abl
+ {
+ struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ __le32 iv[AES_IV_SIZE / 4] = {
+- ctx->state_record->save_iv[0],
++ ctx->iv_nonce,
+ cpu_to_le32p((u32 *) req->info),
+ cpu_to_le32p((u32 *) (req->info + 4)),
+ cpu_to_le32(1) };
+@@ -227,7 +220,7 @@ int crypto4xx_rfc3686_decrypt(struct abl
+ {
+ struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
+ __le32 iv[AES_IV_SIZE / 4] = {
+- ctx->state_record->save_iv[0],
++ ctx->iv_nonce,
+ cpu_to_le32p((u32 *) req->info),
+ cpu_to_le32p((u32 *) (req->info + 4)),
+ cpu_to_le32(1) };
+@@ -254,21 +247,13 @@ static int crypto4xx_hash_alg_init(struc
+ ctx->dev = my_alg->dev;
+
+ /* Create SA */
+- if (ctx->sa_in_dma_addr || ctx->sa_out_dma_addr)
++ if (ctx->sa_in || ctx->sa_out)
+ crypto4xx_free_sa(ctx);
+
+ rc = crypto4xx_alloc_sa(ctx, sa_len);
+ if (rc)
+ return rc;
+
+- if (ctx->state_record_dma_addr == 0) {
+- crypto4xx_alloc_state_record(ctx);
+- if (!ctx->state_record_dma_addr) {
+- crypto4xx_free_sa(ctx);
+- return -ENOMEM;
+- }
+- }
+-
+ crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
+ sizeof(struct crypto4xx_ctx));
+ sa = (struct dynamic_sa_hash160 *)ctx->sa_in;
+--- a/drivers/crypto/amcc/crypto4xx_core.c
++++ b/drivers/crypto/amcc/crypto4xx_core.c
+@@ -130,21 +130,17 @@ static void crypto4xx_hw_init(struct cry
+
+ int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size)
+ {
+- ctx->sa_in = dma_alloc_coherent(ctx->dev->core_dev->device, size * 4,
+- &ctx->sa_in_dma_addr, GFP_ATOMIC);
++ ctx->sa_in = kzalloc(size * 4, GFP_ATOMIC);
+ if (ctx->sa_in == NULL)
+ return -ENOMEM;
+
+- ctx->sa_out = dma_alloc_coherent(ctx->dev->core_dev->device, size * 4,
+- &ctx->sa_out_dma_addr, GFP_ATOMIC);
++ ctx->sa_out = kzalloc(size * 4, GFP_ATOMIC);
+ if (ctx->sa_out == NULL) {
+- dma_free_coherent(ctx->dev->core_dev->device, size * 4,
+- ctx->sa_in, ctx->sa_in_dma_addr);
++ kfree(ctx->sa_in);
++ ctx->sa_in = NULL;
+ return -ENOMEM;
+ }
+
+- memset(ctx->sa_in, 0, size * 4);
+- memset(ctx->sa_out, 0, size * 4);
+ ctx->sa_len = size;
+
+ return 0;
+@@ -152,40 +148,13 @@ int crypto4xx_alloc_sa(struct crypto4xx_
+
+ void crypto4xx_free_sa(struct crypto4xx_ctx *ctx)
+ {
+- if (ctx->sa_in != NULL)
+- dma_free_coherent(ctx->dev->core_dev->device, ctx->sa_len * 4,
+- ctx->sa_in, ctx->sa_in_dma_addr);
+- if (ctx->sa_out != NULL)
+- dma_free_coherent(ctx->dev->core_dev->device, ctx->sa_len * 4,
+- ctx->sa_out, ctx->sa_out_dma_addr);
+-
+- ctx->sa_in_dma_addr = 0;
+- ctx->sa_out_dma_addr = 0;
++ kfree(ctx->sa_in);
++ ctx->sa_in = NULL;
++ kfree(ctx->sa_out);
++ ctx->sa_out = NULL;
+ ctx->sa_len = 0;
+ }
+
+-u32 crypto4xx_alloc_state_record(struct crypto4xx_ctx *ctx)
+-{
+- ctx->state_record = dma_alloc_coherent(ctx->dev->core_dev->device,
+- sizeof(struct sa_state_record),
+- &ctx->state_record_dma_addr, GFP_ATOMIC);
+- if (!ctx->state_record_dma_addr)
+- return -ENOMEM;
+- memset(ctx->state_record, 0, sizeof(struct sa_state_record));
+-
+- return 0;
+-}
+-
+-static void crypto4xx_free_state_record(struct crypto4xx_ctx *ctx)
+-{
+- if (ctx->state_record != NULL)
+- dma_free_coherent(ctx->dev->core_dev->device,
+- sizeof(struct sa_state_record),
+- ctx->state_record,
+- ctx->state_record_dma_addr);
+- ctx->state_record_dma_addr = 0;
+-}
+-
+ /**
+ * alloc memory for the gather ring
+ * no need to alloc buf for the ring
+@@ -883,8 +852,6 @@ static int crypto4xx_alg_init(struct cry
+ ctx->dev = amcc_alg->dev;
+ ctx->sa_in = NULL;
+ ctx->sa_out = NULL;
+- ctx->sa_in_dma_addr = 0;
+- ctx->sa_out_dma_addr = 0;
+ ctx->sa_len = 0;
+
+ switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
+@@ -905,7 +872,6 @@ static void crypto4xx_alg_exit(struct cr
+ struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm);
+
+ crypto4xx_free_sa(ctx);
+- crypto4xx_free_state_record(ctx);
+ }
+
+ int crypto4xx_register_alg(struct crypto4xx_device *sec_dev,
+--- a/drivers/crypto/amcc/crypto4xx_core.h
++++ b/drivers/crypto/amcc/crypto4xx_core.h
+@@ -122,11 +122,8 @@ struct crypto4xx_core_device {
+ struct crypto4xx_ctx {
+ struct crypto4xx_device *dev;
+ struct dynamic_sa_ctl *sa_in;
+- dma_addr_t sa_in_dma_addr;
+ struct dynamic_sa_ctl *sa_out;
+- dma_addr_t sa_out_dma_addr;
+- struct sa_state_record *state_record;
+- dma_addr_t state_record_dma_addr;
++ __le32 iv_nonce;
+ u32 sa_len;
+ };
+
+@@ -159,7 +156,6 @@ static inline struct crypto4xx_alg *cryp
+ int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size);
+ void crypto4xx_free_sa(struct crypto4xx_ctx *ctx);
+ void crypto4xx_free_ctx(struct crypto4xx_ctx *ctx);
+-u32 crypto4xx_alloc_state_record(struct crypto4xx_ctx *ctx);
+ int crypto4xx_build_pd(struct crypto_async_request *req,
+ struct crypto4xx_ctx *ctx,
+ struct scatterlist *src,