kernel: bump 4.14 to 4.14.114
[openwrt/openwrt.git] / target / linux / apm821xx / patches-4.14 / 020-0022-crypto-crypto4xx-simplify-sa-and-state-context-acqui.patch
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
5 acquisition
6
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.
9
10 There's no need to setup any dma coherent memory anymore and
11 much of the support code can be removed.
12
13 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
14 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
15 ---
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(-)
20
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
24 }
25
26 /* Create SA */
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);
30
31 rc = crypto4xx_alloc_sa(ctx, SA_AES128_LEN + (keylen-16) / 4);
32 if (rc)
33 return rc;
34
35 - if (ctx->state_record_dma_addr == 0) {
36 - rc = crypto4xx_alloc_state_record(ctx);
37 - if (rc) {
38 - crypto4xx_free_sa(ctx);
39 - return rc;
40 - }
41 - }
42 /* Setup SA */
43 sa = ctx->sa_in;
44
45 @@ -204,8 +197,8 @@ int crypto4xx_setkey_rfc3686(struct cryp
46 if (rc)
47 return rc;
48
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]);
53
54 return 0;
55 }
56 @@ -214,7 +207,7 @@ int crypto4xx_rfc3686_encrypt(struct abl
57 {
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],
61 + ctx->iv_nonce,
62 cpu_to_le32p((u32 *) req->info),
63 cpu_to_le32p((u32 *) (req->info + 4)),
64 cpu_to_le32(1) };
65 @@ -228,7 +221,7 @@ int crypto4xx_rfc3686_decrypt(struct abl
66 {
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],
70 + ctx->iv_nonce,
71 cpu_to_le32p((u32 *) req->info),
72 cpu_to_le32p((u32 *) (req->info + 4)),
73 cpu_to_le32(1) };
74 @@ -255,21 +248,13 @@ static int crypto4xx_hash_alg_init(struc
75 ctx->dev = my_alg->dev;
76
77 /* Create SA */
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);
81
82 rc = crypto4xx_alloc_sa(ctx, sa_len);
83 if (rc)
84 return rc;
85
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);
90 - return -ENOMEM;
91 - }
92 - }
93 -
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
100
101 int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size)
102 {
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)
107 return -ENOMEM;
108
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);
115 + kfree(ctx->sa_in);
116 + ctx->sa_in = NULL;
117 return -ENOMEM;
118 }
119
120 - memset(ctx->sa_in, 0, size * 4);
121 - memset(ctx->sa_out, 0, size * 4);
122 ctx->sa_len = size;
123
124 return 0;
125 @@ -152,40 +148,13 @@ int crypto4xx_alloc_sa(struct crypto4xx_
126
127 void crypto4xx_free_sa(struct crypto4xx_ctx *ctx)
128 {
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);
135 -
136 - ctx->sa_in_dma_addr = 0;
137 - ctx->sa_out_dma_addr = 0;
138 + kfree(ctx->sa_in);
139 + ctx->sa_in = NULL;
140 + kfree(ctx->sa_out);
141 + ctx->sa_out = NULL;
142 ctx->sa_len = 0;
143 }
144
145 -u32 crypto4xx_alloc_state_record(struct crypto4xx_ctx *ctx)
146 -{
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)
151 - return -ENOMEM;
152 - memset(ctx->state_record, 0, sizeof(struct sa_state_record));
153 -
154 - return 0;
155 -}
156 -
157 -static void crypto4xx_free_state_record(struct crypto4xx_ctx *ctx)
158 -{
159 - if (ctx->state_record != NULL)
160 - dma_free_coherent(ctx->dev->core_dev->device,
161 - sizeof(struct sa_state_record),
162 - ctx->state_record,
163 - ctx->state_record_dma_addr);
164 - ctx->state_record_dma_addr = 0;
165 -}
166 -
167 /**
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;
172 ctx->sa_in = NULL;
173 ctx->sa_out = NULL;
174 - ctx->sa_in_dma_addr = 0;
175 - ctx->sa_out_dma_addr = 0;
176 ctx->sa_len = 0;
177
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);
181
182 crypto4xx_free_sa(ctx);
183 - crypto4xx_free_state_record(ctx);
184 }
185
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;
198 + __le32 iv_nonce;
199 u32 sa_len;
200 };
201
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,