aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGary R Hook <gary.hook@amd.com>2016-07-26 20:10:02 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2016-08-09 06:47:09 -0400
commit8256e683113e659d9bf6bffdd227eeb1881ae9a7 (patch)
tree909ef28a95723e7cffab192109f3e7118bbbe694
parent58a690b701efc32ffd49722dd7b887154eb5a205 (diff)
crypto: ccp - Refactor code supporting the CCP's RNG
Make the RNG support code common (where possible) in preparation for adding a v5 device. Signed-off-by: Gary R Hook <gary.hook@amd.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/ccp/ccp-dev-v3.c51
-rw-r--r--drivers/crypto/ccp/ccp-dev.c28
-rw-r--r--drivers/crypto/ccp/ccp-dev.h1
3 files changed, 40 insertions, 40 deletions
diff --git a/drivers/crypto/ccp/ccp-dev-v3.c b/drivers/crypto/ccp/ccp-dev-v3.c
index 5b0659933b2b..373ac4fa4a47 100644
--- a/drivers/crypto/ccp/ccp-dev-v3.c
+++ b/drivers/crypto/ccp/ccp-dev-v3.c
@@ -307,35 +307,6 @@ static int ccp_perform_ecc(struct ccp_op *op)
307 return ccp_do_cmd(op, cr, ARRAY_SIZE(cr)); 307 return ccp_do_cmd(op, cr, ARRAY_SIZE(cr));
308} 308}
309 309
310static int ccp_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)
311{
312 struct ccp_device *ccp = container_of(rng, struct ccp_device, hwrng);
313 u32 trng_value;
314 int len = min_t(int, sizeof(trng_value), max);
315
316 /*
317 * Locking is provided by the caller so we can update device
318 * hwrng-related fields safely
319 */
320 trng_value = ioread32(ccp->io_regs + TRNG_OUT_REG);
321 if (!trng_value) {
322 /* Zero is returned if not data is available or if a
323 * bad-entropy error is present. Assume an error if
324 * we exceed TRNG_RETRIES reads of zero.
325 */
326 if (ccp->hwrng_retries++ > TRNG_RETRIES)
327 return -EIO;
328
329 return 0;
330 }
331
332 /* Reset the counter and save the rng value */
333 ccp->hwrng_retries = 0;
334 memcpy(data, &trng_value, len);
335
336 return len;
337}
338
339static int ccp_init(struct ccp_device *ccp) 310static int ccp_init(struct ccp_device *ccp)
340{ 311{
341 struct device *dev = ccp->dev; 312 struct device *dev = ccp->dev;
@@ -495,17 +466,6 @@ static void ccp_destroy(struct ccp_device *ccp)
495 /* Remove this device from the list of available units first */ 466 /* Remove this device from the list of available units first */
496 ccp_del_device(ccp); 467 ccp_del_device(ccp);
497 468
498 /* Unregister the DMA engine */
499 ccp_dmaengine_unregister(ccp);
500
501 /* Unregister the RNG */
502 hwrng_unregister(&ccp->hwrng);
503
504 /* Stop the queue kthreads */
505 for (i = 0; i < ccp->cmd_q_count; i++)
506 if (ccp->cmd_q[i].kthread)
507 kthread_stop(ccp->cmd_q[i].kthread);
508
509 /* Build queue interrupt mask (two interrupt masks per queue) */ 469 /* Build queue interrupt mask (two interrupt masks per queue) */
510 qim = 0; 470 qim = 0;
511 for (i = 0; i < ccp->cmd_q_count; i++) { 471 for (i = 0; i < ccp->cmd_q_count; i++) {
@@ -523,6 +483,17 @@ static void ccp_destroy(struct ccp_device *ccp)
523 } 483 }
524 iowrite32(qim, ccp->io_regs + IRQ_STATUS_REG); 484 iowrite32(qim, ccp->io_regs + IRQ_STATUS_REG);
525 485
486 /* Unregister the DMA engine */
487 ccp_dmaengine_unregister(ccp);
488
489 /* Unregister the RNG */
490 hwrng_unregister(&ccp->hwrng);
491
492 /* Stop the queue kthreads */
493 for (i = 0; i < ccp->cmd_q_count; i++)
494 if (ccp->cmd_q[i].kthread)
495 kthread_stop(ccp->cmd_q[i].kthread);
496
526 ccp->free_irq(ccp); 497 ccp->free_irq(ccp);
527 498
528 for (i = 0; i < ccp->cmd_q_count; i++) 499 for (i = 0; i < ccp->cmd_q_count; i++)
diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c
index 9c8cfbb6841f..6b44730ef9d6 100644
--- a/drivers/crypto/ccp/ccp-dev.c
+++ b/drivers/crypto/ccp/ccp-dev.c
@@ -409,6 +409,34 @@ struct ccp_device *ccp_alloc_struct(struct device *dev)
409 return ccp; 409 return ccp;
410} 410}
411 411
412int ccp_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)
413{
414 struct ccp_device *ccp = container_of(rng, struct ccp_device, hwrng);
415 u32 trng_value;
416 int len = min_t(int, sizeof(trng_value), max);
417
418 /* Locking is provided by the caller so we can update device
419 * hwrng-related fields safely
420 */
421 trng_value = ioread32(ccp->io_regs + TRNG_OUT_REG);
422 if (!trng_value) {
423 /* Zero is returned if not data is available or if a
424 * bad-entropy error is present. Assume an error if
425 * we exceed TRNG_RETRIES reads of zero.
426 */
427 if (ccp->hwrng_retries++ > TRNG_RETRIES)
428 return -EIO;
429
430 return 0;
431 }
432
433 /* Reset the counter and save the rng value */
434 ccp->hwrng_retries = 0;
435 memcpy(data, &trng_value, len);
436
437 return len;
438}
439
412#ifdef CONFIG_PM 440#ifdef CONFIG_PM
413bool ccp_queues_suspended(struct ccp_device *ccp) 441bool ccp_queues_suspended(struct ccp_device *ccp)
414{ 442{
diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
index 4e38a61fbe5d..0c44c5e049f5 100644
--- a/drivers/crypto/ccp/ccp-dev.h
+++ b/drivers/crypto/ccp/ccp-dev.h
@@ -440,6 +440,7 @@ void ccp_del_device(struct ccp_device *ccp);
440struct ccp_device *ccp_alloc_struct(struct device *dev); 440struct ccp_device *ccp_alloc_struct(struct device *dev);
441bool ccp_queues_suspended(struct ccp_device *ccp); 441bool ccp_queues_suspended(struct ccp_device *ccp);
442int ccp_cmd_queue_thread(void *data); 442int ccp_cmd_queue_thread(void *data);
443int ccp_trng_read(struct hwrng *rng, void *data, size_t max, bool wait);
443 444
444int ccp_run_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd); 445int ccp_run_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd);
445 446