aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/inside-secure
diff options
context:
space:
mode:
authorAntoine Tenart <antoine.tenart@bootlin.com>2018-05-14 09:10:56 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2018-05-26 12:11:35 -0400
commit8ac1283e4aaa14ea7eeadb9afb7dcaa40145282f (patch)
tree1f6f0677843898a2fca0eb40c2a7ee142a645c31 /drivers/crypto/inside-secure
parent6182480637d98100056883e8191b4f69c5313847 (diff)
crypto: inside-secure - rework cipher functions for future AEAD support
This patch reworks the Inside Secure cipher functions, to remove all skcipher specific information and structure from all functions generic enough to be shared between skcipher and aead algorithms. This is a cosmetic only patch. Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/inside-secure')
-rw-r--r--drivers/crypto/inside-secure/safexcel_cipher.c236
1 files changed, 129 insertions, 107 deletions
diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/crypto/inside-secure/safexcel_cipher.c
index 9a51da28fb62..51f88f93ed99 100644
--- a/drivers/crypto/inside-secure/safexcel_cipher.c
+++ b/drivers/crypto/inside-secure/safexcel_cipher.c
@@ -38,18 +38,16 @@ struct safexcel_cipher_req {
38 bool needs_inv; 38 bool needs_inv;
39}; 39};
40 40
41static void safexcel_cipher_token(struct safexcel_cipher_ctx *ctx, 41static void safexcel_skcipher_token(struct safexcel_cipher_ctx *ctx, u8 *iv,
42 struct crypto_async_request *async, 42 struct safexcel_command_desc *cdesc,
43 struct safexcel_command_desc *cdesc, 43 u32 length)
44 u32 length)
45{ 44{
46 struct skcipher_request *req = skcipher_request_cast(async);
47 struct safexcel_token *token; 45 struct safexcel_token *token;
48 unsigned offset = 0; 46 unsigned offset = 0;
49 47
50 if (ctx->mode == CONTEXT_CONTROL_CRYPTO_MODE_CBC) { 48 if (ctx->mode == CONTEXT_CONTROL_CRYPTO_MODE_CBC) {
51 offset = AES_BLOCK_SIZE / sizeof(u32); 49 offset = AES_BLOCK_SIZE / sizeof(u32);
52 memcpy(cdesc->control_data.token, req->iv, AES_BLOCK_SIZE); 50 memcpy(cdesc->control_data.token, iv, AES_BLOCK_SIZE);
53 51
54 cdesc->control_data.options |= EIP197_OPTION_4_TOKEN_IV_CMD; 52 cdesc->control_data.options |= EIP197_OPTION_4_TOKEN_IV_CMD;
55 } 53 }
@@ -65,8 +63,8 @@ static void safexcel_cipher_token(struct safexcel_cipher_ctx *ctx,
65 EIP197_TOKEN_INS_TYPE_OUTPUT; 63 EIP197_TOKEN_INS_TYPE_OUTPUT;
66} 64}
67 65
68static int safexcel_aes_setkey(struct crypto_skcipher *ctfm, const u8 *key, 66static int safexcel_skcipher_aes_setkey(struct crypto_skcipher *ctfm,
69 unsigned int len) 67 const u8 *key, unsigned int len)
70{ 68{
71 struct crypto_tfm *tfm = crypto_skcipher_tfm(ctfm); 69 struct crypto_tfm *tfm = crypto_skcipher_tfm(ctfm);
72 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm); 70 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
@@ -100,11 +98,10 @@ static int safexcel_aes_setkey(struct crypto_skcipher *ctfm, const u8 *key,
100 98
101static int safexcel_context_control(struct safexcel_cipher_ctx *ctx, 99static int safexcel_context_control(struct safexcel_cipher_ctx *ctx,
102 struct crypto_async_request *async, 100 struct crypto_async_request *async,
101 struct safexcel_cipher_req *sreq,
103 struct safexcel_command_desc *cdesc) 102 struct safexcel_command_desc *cdesc)
104{ 103{
105 struct safexcel_crypto_priv *priv = ctx->priv; 104 struct safexcel_crypto_priv *priv = ctx->priv;
106 struct skcipher_request *req = skcipher_request_cast(async);
107 struct safexcel_cipher_req *sreq = skcipher_request_ctx(req);
108 int ctrl_size; 105 int ctrl_size;
109 106
110 if (sreq->direction == SAFEXCEL_ENCRYPT) 107 if (sreq->direction == SAFEXCEL_ENCRYPT)
@@ -140,9 +137,12 @@ static int safexcel_context_control(struct safexcel_cipher_ctx *ctx,
140 137
141static int safexcel_handle_req_result(struct safexcel_crypto_priv *priv, int ring, 138static int safexcel_handle_req_result(struct safexcel_crypto_priv *priv, int ring,
142 struct crypto_async_request *async, 139 struct crypto_async_request *async,
140 struct scatterlist *src,
141 struct scatterlist *dst,
142 unsigned int cryptlen,
143 struct safexcel_cipher_req *sreq,
143 bool *should_complete, int *ret) 144 bool *should_complete, int *ret)
144{ 145{
145 struct skcipher_request *req = skcipher_request_cast(async);
146 struct safexcel_result_desc *rdesc; 146 struct safexcel_result_desc *rdesc;
147 int ndesc = 0; 147 int ndesc = 0;
148 148
@@ -171,16 +171,16 @@ static int safexcel_handle_req_result(struct safexcel_crypto_priv *priv, int rin
171 safexcel_complete(priv, ring); 171 safexcel_complete(priv, ring);
172 spin_unlock_bh(&priv->ring[ring].egress_lock); 172 spin_unlock_bh(&priv->ring[ring].egress_lock);
173 173
174 if (req->src == req->dst) { 174 if (src == dst) {
175 dma_unmap_sg(priv->dev, req->src, 175 dma_unmap_sg(priv->dev, src,
176 sg_nents_for_len(req->src, req->cryptlen), 176 sg_nents_for_len(src, cryptlen),
177 DMA_BIDIRECTIONAL); 177 DMA_BIDIRECTIONAL);
178 } else { 178 } else {
179 dma_unmap_sg(priv->dev, req->src, 179 dma_unmap_sg(priv->dev, src,
180 sg_nents_for_len(req->src, req->cryptlen), 180 sg_nents_for_len(src, cryptlen),
181 DMA_TO_DEVICE); 181 DMA_TO_DEVICE);
182 dma_unmap_sg(priv->dev, req->dst, 182 dma_unmap_sg(priv->dev, dst,
183 sg_nents_for_len(req->dst, req->cryptlen), 183 sg_nents_for_len(dst, cryptlen),
184 DMA_FROM_DEVICE); 184 DMA_FROM_DEVICE);
185 } 185 }
186 186
@@ -189,39 +189,41 @@ static int safexcel_handle_req_result(struct safexcel_crypto_priv *priv, int rin
189 return ndesc; 189 return ndesc;
190} 190}
191 191
192static int safexcel_aes_send(struct crypto_async_request *async, 192static int safexcel_aes_send(struct crypto_async_request *base, int ring,
193 int ring, struct safexcel_request *request, 193 struct safexcel_request *request,
194 int *commands, int *results) 194 struct safexcel_cipher_req *sreq,
195 struct scatterlist *src, struct scatterlist *dst,
196 unsigned int cryptlen, u8 *iv, int *commands,
197 int *results)
195{ 198{
196 struct skcipher_request *req = skcipher_request_cast(async); 199 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(base->tfm);
197 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
198 struct safexcel_crypto_priv *priv = ctx->priv; 200 struct safexcel_crypto_priv *priv = ctx->priv;
199 struct safexcel_command_desc *cdesc; 201 struct safexcel_command_desc *cdesc;
200 struct safexcel_result_desc *rdesc; 202 struct safexcel_result_desc *rdesc;
201 struct scatterlist *sg; 203 struct scatterlist *sg;
202 int nr_src, nr_dst, n_cdesc = 0, n_rdesc = 0, queued = req->cryptlen; 204 int nr_src, nr_dst, n_cdesc = 0, n_rdesc = 0, queued = cryptlen;
203 int i, ret = 0; 205 int i, ret = 0;
204 206
205 if (req->src == req->dst) { 207 if (src == dst) {
206 nr_src = dma_map_sg(priv->dev, req->src, 208 nr_src = dma_map_sg(priv->dev, src,
207 sg_nents_for_len(req->src, req->cryptlen), 209 sg_nents_for_len(src, cryptlen),
208 DMA_BIDIRECTIONAL); 210 DMA_BIDIRECTIONAL);
209 nr_dst = nr_src; 211 nr_dst = nr_src;
210 if (!nr_src) 212 if (!nr_src)
211 return -EINVAL; 213 return -EINVAL;
212 } else { 214 } else {
213 nr_src = dma_map_sg(priv->dev, req->src, 215 nr_src = dma_map_sg(priv->dev, src,
214 sg_nents_for_len(req->src, req->cryptlen), 216 sg_nents_for_len(src, cryptlen),
215 DMA_TO_DEVICE); 217 DMA_TO_DEVICE);
216 if (!nr_src) 218 if (!nr_src)
217 return -EINVAL; 219 return -EINVAL;
218 220
219 nr_dst = dma_map_sg(priv->dev, req->dst, 221 nr_dst = dma_map_sg(priv->dev, dst,
220 sg_nents_for_len(req->dst, req->cryptlen), 222 sg_nents_for_len(dst, cryptlen),
221 DMA_FROM_DEVICE); 223 DMA_FROM_DEVICE);
222 if (!nr_dst) { 224 if (!nr_dst) {
223 dma_unmap_sg(priv->dev, req->src, 225 dma_unmap_sg(priv->dev, src,
224 sg_nents_for_len(req->src, req->cryptlen), 226 sg_nents_for_len(src, cryptlen),
225 DMA_TO_DEVICE); 227 DMA_TO_DEVICE);
226 return -EINVAL; 228 return -EINVAL;
227 } 229 }
@@ -232,7 +234,7 @@ static int safexcel_aes_send(struct crypto_async_request *async,
232 spin_lock_bh(&priv->ring[ring].egress_lock); 234 spin_lock_bh(&priv->ring[ring].egress_lock);
233 235
234 /* command descriptors */ 236 /* command descriptors */
235 for_each_sg(req->src, sg, nr_src, i) { 237 for_each_sg(src, sg, nr_src, i) {
236 int len = sg_dma_len(sg); 238 int len = sg_dma_len(sg);
237 239
238 /* Do not overflow the request */ 240 /* Do not overflow the request */
@@ -240,7 +242,7 @@ static int safexcel_aes_send(struct crypto_async_request *async,
240 len = queued; 242 len = queued;
241 243
242 cdesc = safexcel_add_cdesc(priv, ring, !n_cdesc, !(queued - len), 244 cdesc = safexcel_add_cdesc(priv, ring, !n_cdesc, !(queued - len),
243 sg_dma_address(sg), len, req->cryptlen, 245 sg_dma_address(sg), len, cryptlen,
244 ctx->base.ctxr_dma); 246 ctx->base.ctxr_dma);
245 if (IS_ERR(cdesc)) { 247 if (IS_ERR(cdesc)) {
246 /* No space left in the command descriptor ring */ 248 /* No space left in the command descriptor ring */
@@ -250,8 +252,8 @@ static int safexcel_aes_send(struct crypto_async_request *async,
250 n_cdesc++; 252 n_cdesc++;
251 253
252 if (n_cdesc == 1) { 254 if (n_cdesc == 1) {
253 safexcel_context_control(ctx, async, cdesc); 255 safexcel_context_control(ctx, base, sreq, cdesc);
254 safexcel_cipher_token(ctx, async, cdesc, req->cryptlen); 256 safexcel_skcipher_token(ctx, iv, cdesc, cryptlen);
255 } 257 }
256 258
257 queued -= len; 259 queued -= len;
@@ -260,7 +262,7 @@ static int safexcel_aes_send(struct crypto_async_request *async,
260 } 262 }
261 263
262 /* result descriptors */ 264 /* result descriptors */
263 for_each_sg(req->dst, sg, nr_dst, i) { 265 for_each_sg(dst, sg, nr_dst, i) {
264 bool first = !i, last = (i == nr_dst - 1); 266 bool first = !i, last = (i == nr_dst - 1);
265 u32 len = sg_dma_len(sg); 267 u32 len = sg_dma_len(sg);
266 268
@@ -276,7 +278,7 @@ static int safexcel_aes_send(struct crypto_async_request *async,
276 278
277 spin_unlock_bh(&priv->ring[ring].egress_lock); 279 spin_unlock_bh(&priv->ring[ring].egress_lock);
278 280
279 request->req = &req->base; 281 request->req = base;
280 282
281 *commands = n_cdesc; 283 *commands = n_cdesc;
282 *results = n_rdesc; 284 *results = n_rdesc;
@@ -291,16 +293,16 @@ cdesc_rollback:
291 293
292 spin_unlock_bh(&priv->ring[ring].egress_lock); 294 spin_unlock_bh(&priv->ring[ring].egress_lock);
293 295
294 if (req->src == req->dst) { 296 if (src == dst) {
295 dma_unmap_sg(priv->dev, req->src, 297 dma_unmap_sg(priv->dev, src,
296 sg_nents_for_len(req->src, req->cryptlen), 298 sg_nents_for_len(src, cryptlen),
297 DMA_BIDIRECTIONAL); 299 DMA_BIDIRECTIONAL);
298 } else { 300 } else {
299 dma_unmap_sg(priv->dev, req->src, 301 dma_unmap_sg(priv->dev, src,
300 sg_nents_for_len(req->src, req->cryptlen), 302 sg_nents_for_len(src, cryptlen),
301 DMA_TO_DEVICE); 303 DMA_TO_DEVICE);
302 dma_unmap_sg(priv->dev, req->dst, 304 dma_unmap_sg(priv->dev, dst,
303 sg_nents_for_len(req->dst, req->cryptlen), 305 sg_nents_for_len(dst, cryptlen),
304 DMA_FROM_DEVICE); 306 DMA_FROM_DEVICE);
305 } 307 }
306 308
@@ -309,11 +311,10 @@ cdesc_rollback:
309 311
310static int safexcel_handle_inv_result(struct safexcel_crypto_priv *priv, 312static int safexcel_handle_inv_result(struct safexcel_crypto_priv *priv,
311 int ring, 313 int ring,
312 struct crypto_async_request *async, 314 struct crypto_async_request *base,
313 bool *should_complete, int *ret) 315 bool *should_complete, int *ret)
314{ 316{
315 struct skcipher_request *req = skcipher_request_cast(async); 317 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(base->tfm);
316 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
317 struct safexcel_result_desc *rdesc; 318 struct safexcel_result_desc *rdesc;
318 int ndesc = 0, enq_ret; 319 int ndesc = 0, enq_ret;
319 320
@@ -354,7 +355,7 @@ static int safexcel_handle_inv_result(struct safexcel_crypto_priv *priv,
354 ctx->base.ring = ring; 355 ctx->base.ring = ring;
355 356
356 spin_lock_bh(&priv->ring[ring].queue_lock); 357 spin_lock_bh(&priv->ring[ring].queue_lock);
357 enq_ret = crypto_enqueue_request(&priv->ring[ring].queue, async); 358 enq_ret = crypto_enqueue_request(&priv->ring[ring].queue, base);
358 spin_unlock_bh(&priv->ring[ring].queue_lock); 359 spin_unlock_bh(&priv->ring[ring].queue_lock);
359 360
360 if (enq_ret != -EINPROGRESS) 361 if (enq_ret != -EINPROGRESS)
@@ -368,9 +369,10 @@ static int safexcel_handle_inv_result(struct safexcel_crypto_priv *priv,
368 return ndesc; 369 return ndesc;
369} 370}
370 371
371static int safexcel_handle_result(struct safexcel_crypto_priv *priv, int ring, 372static int safexcel_skcipher_handle_result(struct safexcel_crypto_priv *priv,
372 struct crypto_async_request *async, 373 int ring,
373 bool *should_complete, int *ret) 374 struct crypto_async_request *async,
375 bool *should_complete, int *ret)
374{ 376{
375 struct skcipher_request *req = skcipher_request_cast(async); 377 struct skcipher_request *req = skcipher_request_cast(async);
376 struct safexcel_cipher_req *sreq = skcipher_request_ctx(req); 378 struct safexcel_cipher_req *sreq = skcipher_request_ctx(req);
@@ -381,24 +383,24 @@ static int safexcel_handle_result(struct safexcel_crypto_priv *priv, int ring,
381 err = safexcel_handle_inv_result(priv, ring, async, 383 err = safexcel_handle_inv_result(priv, ring, async,
382 should_complete, ret); 384 should_complete, ret);
383 } else { 385 } else {
384 err = safexcel_handle_req_result(priv, ring, async, 386 err = safexcel_handle_req_result(priv, ring, async, req->src,
387 req->dst, req->cryptlen, sreq,
385 should_complete, ret); 388 should_complete, ret);
386 } 389 }
387 390
388 return err; 391 return err;
389} 392}
390 393
391static int safexcel_cipher_send_inv(struct crypto_async_request *async, 394static int safexcel_cipher_send_inv(struct crypto_async_request *base,
392 int ring, struct safexcel_request *request, 395 int ring, struct safexcel_request *request,
393 int *commands, int *results) 396 int *commands, int *results)
394{ 397{
395 struct skcipher_request *req = skcipher_request_cast(async); 398 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(base->tfm);
396 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
397 struct safexcel_crypto_priv *priv = ctx->priv; 399 struct safexcel_crypto_priv *priv = ctx->priv;
398 int ret; 400 int ret;
399 401
400 ret = safexcel_invalidate_cache(async, priv, 402 ret = safexcel_invalidate_cache(base, priv, ctx->base.ctxr_dma, ring,
401 ctx->base.ctxr_dma, ring, request); 403 request);
402 if (unlikely(ret)) 404 if (unlikely(ret))
403 return ret; 405 return ret;
404 406
@@ -408,9 +410,9 @@ static int safexcel_cipher_send_inv(struct crypto_async_request *async,
408 return 0; 410 return 0;
409} 411}
410 412
411static int safexcel_send(struct crypto_async_request *async, 413static int safexcel_skcipher_send(struct crypto_async_request *async, int ring,
412 int ring, struct safexcel_request *request, 414 struct safexcel_request *request,
413 int *commands, int *results) 415 int *commands, int *results)
414{ 416{
415 struct skcipher_request *req = skcipher_request_cast(async); 417 struct skcipher_request *req = skcipher_request_cast(async);
416 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(req->base.tfm); 418 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
@@ -421,59 +423,69 @@ static int safexcel_send(struct crypto_async_request *async,
421 BUG_ON(priv->version == EIP97 && sreq->needs_inv); 423 BUG_ON(priv->version == EIP97 && sreq->needs_inv);
422 424
423 if (sreq->needs_inv) 425 if (sreq->needs_inv)
424 ret = safexcel_cipher_send_inv(async, ring, request, 426 ret = safexcel_cipher_send_inv(async, ring, request, commands,
425 commands, results); 427 results);
426 else 428 else
427 ret = safexcel_aes_send(async, ring, request, 429 ret = safexcel_aes_send(async, ring, request, sreq, req->src,
430 req->dst, req->cryptlen, req->iv,
428 commands, results); 431 commands, results);
429 return ret; 432 return ret;
430} 433}
431 434
432static int safexcel_cipher_exit_inv(struct crypto_tfm *tfm) 435static int safexcel_cipher_exit_inv(struct crypto_tfm *tfm,
436 struct crypto_async_request *base,
437 struct safexcel_cipher_req *sreq,
438 struct safexcel_inv_result *result)
433{ 439{
434 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm); 440 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
435 struct safexcel_crypto_priv *priv = ctx->priv; 441 struct safexcel_crypto_priv *priv = ctx->priv;
436 EIP197_REQUEST_ON_STACK(req, skcipher, EIP197_SKCIPHER_REQ_SIZE);
437 struct safexcel_cipher_req *sreq = skcipher_request_ctx(req);
438 struct safexcel_inv_result result = {};
439 int ring = ctx->base.ring; 442 int ring = ctx->base.ring;
440 443
441 memset(req, 0, sizeof(struct skcipher_request)); 444 init_completion(&result->completion);
442 445
443 /* create invalidation request */ 446 ctx = crypto_tfm_ctx(base->tfm);
444 init_completion(&result.completion);
445 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
446 safexcel_inv_complete, &result);
447
448 skcipher_request_set_tfm(req, __crypto_skcipher_cast(tfm));
449 ctx = crypto_tfm_ctx(req->base.tfm);
450 ctx->base.exit_inv = true; 447 ctx->base.exit_inv = true;
451 sreq->needs_inv = true; 448 sreq->needs_inv = true;
452 449
453 spin_lock_bh(&priv->ring[ring].queue_lock); 450 spin_lock_bh(&priv->ring[ring].queue_lock);
454 crypto_enqueue_request(&priv->ring[ring].queue, &req->base); 451 crypto_enqueue_request(&priv->ring[ring].queue, base);
455 spin_unlock_bh(&priv->ring[ring].queue_lock); 452 spin_unlock_bh(&priv->ring[ring].queue_lock);
456 453
457 queue_work(priv->ring[ring].workqueue, 454 queue_work(priv->ring[ring].workqueue,
458 &priv->ring[ring].work_data.work); 455 &priv->ring[ring].work_data.work);
459 456
460 wait_for_completion(&result.completion); 457 wait_for_completion(&result->completion);
461 458
462 if (result.error) { 459 if (result->error) {
463 dev_warn(priv->dev, 460 dev_warn(priv->dev,
464 "cipher: sync: invalidate: completion error %d\n", 461 "cipher: sync: invalidate: completion error %d\n",
465 result.error); 462 result->error);
466 return result.error; 463 return result->error;
467 } 464 }
468 465
469 return 0; 466 return 0;
470} 467}
471 468
472static int safexcel_aes(struct skcipher_request *req, 469static int safexcel_skcipher_exit_inv(struct crypto_tfm *tfm)
473 enum safexcel_cipher_direction dir, u32 mode)
474{ 470{
475 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(req->base.tfm); 471 EIP197_REQUEST_ON_STACK(req, skcipher, EIP197_SKCIPHER_REQ_SIZE);
476 struct safexcel_cipher_req *sreq = skcipher_request_ctx(req); 472 struct safexcel_cipher_req *sreq = skcipher_request_ctx(req);
473 struct safexcel_inv_result result = {};
474
475 memset(req, 0, sizeof(struct skcipher_request));
476
477 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
478 safexcel_inv_complete, &result);
479 skcipher_request_set_tfm(req, __crypto_skcipher_cast(tfm));
480
481 return safexcel_cipher_exit_inv(tfm, &req->base, sreq, &result);
482}
483
484static int safexcel_aes(struct crypto_async_request *base,
485 struct safexcel_cipher_req *sreq,
486 enum safexcel_cipher_direction dir, u32 mode)
487{
488 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(base->tfm);
477 struct safexcel_crypto_priv *priv = ctx->priv; 489 struct safexcel_crypto_priv *priv = ctx->priv;
478 int ret, ring; 490 int ret, ring;
479 491
@@ -489,7 +501,7 @@ static int safexcel_aes(struct skcipher_request *req,
489 } else { 501 } else {
490 ctx->base.ring = safexcel_select_ring(priv); 502 ctx->base.ring = safexcel_select_ring(priv);
491 ctx->base.ctxr = dma_pool_zalloc(priv->context_pool, 503 ctx->base.ctxr = dma_pool_zalloc(priv->context_pool,
492 EIP197_GFP_FLAGS(req->base), 504 EIP197_GFP_FLAGS(*base),
493 &ctx->base.ctxr_dma); 505 &ctx->base.ctxr_dma);
494 if (!ctx->base.ctxr) 506 if (!ctx->base.ctxr)
495 return -ENOMEM; 507 return -ENOMEM;
@@ -498,7 +510,7 @@ static int safexcel_aes(struct skcipher_request *req,
498 ring = ctx->base.ring; 510 ring = ctx->base.ring;
499 511
500 spin_lock_bh(&priv->ring[ring].queue_lock); 512 spin_lock_bh(&priv->ring[ring].queue_lock);
501 ret = crypto_enqueue_request(&priv->ring[ring].queue, &req->base); 513 ret = crypto_enqueue_request(&priv->ring[ring].queue, base);
502 spin_unlock_bh(&priv->ring[ring].queue_lock); 514 spin_unlock_bh(&priv->ring[ring].queue_lock);
503 515
504 queue_work(priv->ring[ring].workqueue, 516 queue_work(priv->ring[ring].workqueue,
@@ -509,14 +521,14 @@ static int safexcel_aes(struct skcipher_request *req,
509 521
510static int safexcel_ecb_aes_encrypt(struct skcipher_request *req) 522static int safexcel_ecb_aes_encrypt(struct skcipher_request *req)
511{ 523{
512 return safexcel_aes(req, SAFEXCEL_ENCRYPT, 524 return safexcel_aes(&req->base, skcipher_request_ctx(req),
513 CONTEXT_CONTROL_CRYPTO_MODE_ECB); 525 SAFEXCEL_ENCRYPT, CONTEXT_CONTROL_CRYPTO_MODE_ECB);
514} 526}
515 527
516static int safexcel_ecb_aes_decrypt(struct skcipher_request *req) 528static int safexcel_ecb_aes_decrypt(struct skcipher_request *req)
517{ 529{
518 return safexcel_aes(req, SAFEXCEL_DECRYPT, 530 return safexcel_aes(&req->base, skcipher_request_ctx(req),
519 CONTEXT_CONTROL_CRYPTO_MODE_ECB); 531 SAFEXCEL_DECRYPT, CONTEXT_CONTROL_CRYPTO_MODE_ECB);
520} 532}
521 533
522static int safexcel_skcipher_cra_init(struct crypto_tfm *tfm) 534static int safexcel_skcipher_cra_init(struct crypto_tfm *tfm)
@@ -526,34 +538,44 @@ static int safexcel_skcipher_cra_init(struct crypto_tfm *tfm)
526 container_of(tfm->__crt_alg, struct safexcel_alg_template, 538 container_of(tfm->__crt_alg, struct safexcel_alg_template,
527 alg.skcipher.base); 539 alg.skcipher.base);
528 540
529 ctx->priv = tmpl->priv;
530 ctx->base.send = safexcel_send;
531 ctx->base.handle_result = safexcel_handle_result;
532
533 crypto_skcipher_set_reqsize(__crypto_skcipher_cast(tfm), 541 crypto_skcipher_set_reqsize(__crypto_skcipher_cast(tfm),
534 sizeof(struct safexcel_cipher_req)); 542 sizeof(struct safexcel_cipher_req));
535 543
544 ctx->priv = tmpl->priv;
545
546 ctx->base.send = safexcel_skcipher_send;
547 ctx->base.handle_result = safexcel_skcipher_handle_result;
536 return 0; 548 return 0;
537} 549}
538 550
539static void safexcel_skcipher_cra_exit(struct crypto_tfm *tfm) 551static int safexcel_cipher_cra_exit(struct crypto_tfm *tfm)
540{ 552{
541 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm); 553 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
542 struct safexcel_crypto_priv *priv = ctx->priv;
543 int ret;
544 554
545 memzero_explicit(ctx->key, 8 * sizeof(u32)); 555 memzero_explicit(ctx->key, 8 * sizeof(u32));
546 556
547 /* context not allocated, skip invalidation */ 557 /* context not allocated, skip invalidation */
548 if (!ctx->base.ctxr) 558 if (!ctx->base.ctxr)
549 return; 559 return -ENOMEM;
550 560
551 memzero_explicit(ctx->base.ctxr->data, 8 * sizeof(u32)); 561 memzero_explicit(ctx->base.ctxr->data, 8 * sizeof(u32));
562 return 0;
563}
564
565static void safexcel_skcipher_cra_exit(struct crypto_tfm *tfm)
566{
567 struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
568 struct safexcel_crypto_priv *priv = ctx->priv;
569 int ret;
570
571 if (safexcel_cipher_cra_exit(tfm))
572 return;
552 573
553 if (priv->version == EIP197) { 574 if (priv->version == EIP197) {
554 ret = safexcel_cipher_exit_inv(tfm); 575 ret = safexcel_skcipher_exit_inv(tfm);
555 if (ret) 576 if (ret)
556 dev_warn(priv->dev, "cipher: invalidation error %d\n", ret); 577 dev_warn(priv->dev, "skcipher: invalidation error %d\n",
578 ret);
557 } else { 579 } else {
558 dma_pool_free(priv->context_pool, ctx->base.ctxr, 580 dma_pool_free(priv->context_pool, ctx->base.ctxr,
559 ctx->base.ctxr_dma); 581 ctx->base.ctxr_dma);
@@ -563,7 +585,7 @@ static void safexcel_skcipher_cra_exit(struct crypto_tfm *tfm)
563struct safexcel_alg_template safexcel_alg_ecb_aes = { 585struct safexcel_alg_template safexcel_alg_ecb_aes = {
564 .type = SAFEXCEL_ALG_TYPE_SKCIPHER, 586 .type = SAFEXCEL_ALG_TYPE_SKCIPHER,
565 .alg.skcipher = { 587 .alg.skcipher = {
566 .setkey = safexcel_aes_setkey, 588 .setkey = safexcel_skcipher_aes_setkey,
567 .encrypt = safexcel_ecb_aes_encrypt, 589 .encrypt = safexcel_ecb_aes_encrypt,
568 .decrypt = safexcel_ecb_aes_decrypt, 590 .decrypt = safexcel_ecb_aes_decrypt,
569 .min_keysize = AES_MIN_KEY_SIZE, 591 .min_keysize = AES_MIN_KEY_SIZE,
@@ -586,20 +608,20 @@ struct safexcel_alg_template safexcel_alg_ecb_aes = {
586 608
587static int safexcel_cbc_aes_encrypt(struct skcipher_request *req) 609static int safexcel_cbc_aes_encrypt(struct skcipher_request *req)
588{ 610{
589 return safexcel_aes(req, SAFEXCEL_ENCRYPT, 611 return safexcel_aes(&req->base, skcipher_request_ctx(req),
590 CONTEXT_CONTROL_CRYPTO_MODE_CBC); 612 SAFEXCEL_ENCRYPT, CONTEXT_CONTROL_CRYPTO_MODE_CBC);
591} 613}
592 614
593static int safexcel_cbc_aes_decrypt(struct skcipher_request *req) 615static int safexcel_cbc_aes_decrypt(struct skcipher_request *req)
594{ 616{
595 return safexcel_aes(req, SAFEXCEL_DECRYPT, 617 return safexcel_aes(&req->base, skcipher_request_ctx(req),
596 CONTEXT_CONTROL_CRYPTO_MODE_CBC); 618 SAFEXCEL_DECRYPT, CONTEXT_CONTROL_CRYPTO_MODE_CBC);
597} 619}
598 620
599struct safexcel_alg_template safexcel_alg_cbc_aes = { 621struct safexcel_alg_template safexcel_alg_cbc_aes = {
600 .type = SAFEXCEL_ALG_TYPE_SKCIPHER, 622 .type = SAFEXCEL_ALG_TYPE_SKCIPHER,
601 .alg.skcipher = { 623 .alg.skcipher = {
602 .setkey = safexcel_aes_setkey, 624 .setkey = safexcel_skcipher_aes_setkey,
603 .encrypt = safexcel_cbc_aes_encrypt, 625 .encrypt = safexcel_cbc_aes_encrypt,
604 .decrypt = safexcel_cbc_aes_decrypt, 626 .decrypt = safexcel_cbc_aes_decrypt,
605 .min_keysize = AES_MIN_KEY_SIZE, 627 .min_keysize = AES_MIN_KEY_SIZE,