1 From 2f77690dcb96e525bc6b57bce4a0eaecaa2878d1 Mon Sep 17 00:00:00 2001
2 From: Christian Lamparter <chunkeey@gmail.com>
3 Date: Wed, 4 Oct 2017 01:00:14 +0200
4 Subject: [PATCH 22/25] crypto: crypto4xx - simplify sa and state context
7 Thanks to the big overhaul of crypto4xx_build_pd(), the request-local
8 sa_in, sa_out and state_record allocation can be simplified.
10 There's no need to setup any dma coherent memory anymore and
11 much of the support code can be removed.
13 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
14 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
16 drivers/crypto/amcc/crypto4xx_alg.c | 27 +++++--------------
17 drivers/crypto/amcc/crypto4xx_core.c | 50 ++++++------------------------------
18 drivers/crypto/amcc/crypto4xx_core.h | 6 +----
19 3 files changed, 15 insertions(+), 68 deletions(-)
21 --- a/drivers/crypto/amcc/crypto4xx_alg.c
22 +++ b/drivers/crypto/amcc/crypto4xx_alg.c
23 @@ -122,20 +122,13 @@ static int crypto4xx_setkey_aes(struct c
27 - if (ctx->sa_in_dma_addr || ctx->sa_out_dma_addr)
28 + if (ctx->sa_in || ctx->sa_out)
29 crypto4xx_free_sa(ctx);
31 rc = crypto4xx_alloc_sa(ctx, SA_AES128_LEN + (keylen-16) / 4);
35 - if (ctx->state_record_dma_addr == 0) {
36 - rc = crypto4xx_alloc_state_record(ctx);
38 - crypto4xx_free_sa(ctx);
45 @@ -204,8 +197,8 @@ int crypto4xx_setkey_rfc3686(struct cryp
49 - crypto4xx_memcpy_to_le32(ctx->state_record->save_iv,
50 - key + keylen - CTR_RFC3686_NONCE_SIZE, CTR_RFC3686_NONCE_SIZE);
51 + ctx->iv_nonce = cpu_to_le32p((u32 *)&key[keylen -
52 + CTR_RFC3686_NONCE_SIZE]);
56 @@ -214,7 +207,7 @@ int crypto4xx_rfc3686_encrypt(struct abl
58 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
59 __le32 iv[AES_IV_SIZE / 4] = {
60 - ctx->state_record->save_iv[0],
62 cpu_to_le32p((u32 *) req->info),
63 cpu_to_le32p((u32 *) (req->info + 4)),
65 @@ -228,7 +221,7 @@ int crypto4xx_rfc3686_decrypt(struct abl
67 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
68 __le32 iv[AES_IV_SIZE / 4] = {
69 - ctx->state_record->save_iv[0],
71 cpu_to_le32p((u32 *) req->info),
72 cpu_to_le32p((u32 *) (req->info + 4)),
74 @@ -255,21 +248,13 @@ static int crypto4xx_hash_alg_init(struc
75 ctx->dev = my_alg->dev;
78 - if (ctx->sa_in_dma_addr || ctx->sa_out_dma_addr)
79 + if (ctx->sa_in || ctx->sa_out)
80 crypto4xx_free_sa(ctx);
82 rc = crypto4xx_alloc_sa(ctx, sa_len);
86 - if (ctx->state_record_dma_addr == 0) {
87 - crypto4xx_alloc_state_record(ctx);
88 - if (!ctx->state_record_dma_addr) {
89 - crypto4xx_free_sa(ctx);
94 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
95 sizeof(struct crypto4xx_ctx));
96 sa = (struct dynamic_sa_hash160 *)ctx->sa_in;
97 --- a/drivers/crypto/amcc/crypto4xx_core.c
98 +++ b/drivers/crypto/amcc/crypto4xx_core.c
99 @@ -130,21 +130,17 @@ static void crypto4xx_hw_init(struct cry
101 int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size)
103 - ctx->sa_in = dma_alloc_coherent(ctx->dev->core_dev->device, size * 4,
104 - &ctx->sa_in_dma_addr, GFP_ATOMIC);
105 + ctx->sa_in = kzalloc(size * 4, GFP_ATOMIC);
106 if (ctx->sa_in == NULL)
109 - ctx->sa_out = dma_alloc_coherent(ctx->dev->core_dev->device, size * 4,
110 - &ctx->sa_out_dma_addr, GFP_ATOMIC);
111 + ctx->sa_out = kzalloc(size * 4, GFP_ATOMIC);
112 if (ctx->sa_out == NULL) {
113 - dma_free_coherent(ctx->dev->core_dev->device, size * 4,
114 - ctx->sa_in, ctx->sa_in_dma_addr);
120 - memset(ctx->sa_in, 0, size * 4);
121 - memset(ctx->sa_out, 0, size * 4);
125 @@ -152,40 +148,13 @@ int crypto4xx_alloc_sa(struct crypto4xx_
127 void crypto4xx_free_sa(struct crypto4xx_ctx *ctx)
129 - if (ctx->sa_in != NULL)
130 - dma_free_coherent(ctx->dev->core_dev->device, ctx->sa_len * 4,
131 - ctx->sa_in, ctx->sa_in_dma_addr);
132 - if (ctx->sa_out != NULL)
133 - dma_free_coherent(ctx->dev->core_dev->device, ctx->sa_len * 4,
134 - ctx->sa_out, ctx->sa_out_dma_addr);
136 - ctx->sa_in_dma_addr = 0;
137 - ctx->sa_out_dma_addr = 0;
140 + kfree(ctx->sa_out);
141 + ctx->sa_out = NULL;
145 -u32 crypto4xx_alloc_state_record(struct crypto4xx_ctx *ctx)
147 - ctx->state_record = dma_alloc_coherent(ctx->dev->core_dev->device,
148 - sizeof(struct sa_state_record),
149 - &ctx->state_record_dma_addr, GFP_ATOMIC);
150 - if (!ctx->state_record_dma_addr)
152 - memset(ctx->state_record, 0, sizeof(struct sa_state_record));
157 -static void crypto4xx_free_state_record(struct crypto4xx_ctx *ctx)
159 - if (ctx->state_record != NULL)
160 - dma_free_coherent(ctx->dev->core_dev->device,
161 - sizeof(struct sa_state_record),
163 - ctx->state_record_dma_addr);
164 - ctx->state_record_dma_addr = 0;
168 * alloc memory for the gather ring
169 * no need to alloc buf for the ring
170 @@ -892,8 +861,6 @@ static int crypto4xx_alg_init(struct cry
171 ctx->dev = amcc_alg->dev;
174 - ctx->sa_in_dma_addr = 0;
175 - ctx->sa_out_dma_addr = 0;
178 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
179 @@ -914,7 +881,6 @@ static void crypto4xx_alg_exit(struct cr
180 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm);
182 crypto4xx_free_sa(ctx);
183 - crypto4xx_free_state_record(ctx);
186 int crypto4xx_register_alg(struct crypto4xx_device *sec_dev,
187 --- a/drivers/crypto/amcc/crypto4xx_core.h
188 +++ b/drivers/crypto/amcc/crypto4xx_core.h
189 @@ -122,11 +122,8 @@ struct crypto4xx_core_device {
190 struct crypto4xx_ctx {
191 struct crypto4xx_device *dev;
192 struct dynamic_sa_ctl *sa_in;
193 - dma_addr_t sa_in_dma_addr;
194 struct dynamic_sa_ctl *sa_out;
195 - dma_addr_t sa_out_dma_addr;
196 - struct sa_state_record *state_record;
197 - dma_addr_t state_record_dma_addr;
202 @@ -159,7 +156,6 @@ static inline struct crypto4xx_alg *cryp
203 int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size);
204 void crypto4xx_free_sa(struct crypto4xx_ctx *ctx);
205 void crypto4xx_free_ctx(struct crypto4xx_ctx *ctx);
206 -u32 crypto4xx_alloc_state_record(struct crypto4xx_ctx *ctx);
207 int crypto4xx_build_pd(struct crypto_async_request *req,
208 struct crypto4xx_ctx *ctx,
209 struct scatterlist *src,