diff options
author | Gary R Hook <gary.hook@amd.com> | 2016-07-26 19:10:31 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2016-08-09 18:47:17 +0800 |
commit | 084935b208f6507ef5214fd67052a67a700bc6cf (patch) | |
tree | 5b617289cb4807fd950c9028f8c18a26f2949f3c | |
parent | 4b394a232df78414442778b02ca4a388d947d059 (diff) |
crypto: ccp - Add support for the RNG in a version 5 CCP
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.c | 13 | ||||
-rw-r--r-- | drivers/crypto/ccp/ccp-dev-v5.c | 7 | ||||
-rw-r--r-- | drivers/crypto/ccp/ccp-dev.c | 23 | ||||
-rw-r--r-- | drivers/crypto/ccp/ccp-dev.h | 2 |
4 files changed, 36 insertions, 9 deletions
diff --git a/drivers/crypto/ccp/ccp-dev-v3.c b/drivers/crypto/ccp/ccp-dev-v3.c index ff2d2a4de16a..578522d8f22e 100644 --- a/drivers/crypto/ccp/ccp-dev-v3.c +++ b/drivers/crypto/ccp/ccp-dev-v3.c @@ -432,14 +432,9 @@ static int ccp_init(struct ccp_device *ccp) dev_dbg(dev, "Registering device...\n"); ccp_add_device(ccp); - /* Register the RNG */ - ccp->hwrng.name = ccp->rngname; - ccp->hwrng.read = ccp_trng_read; - ret = hwrng_register(&ccp->hwrng); - if (ret) { - dev_err(dev, "error registering hwrng (%d)\n", ret); + ret = ccp_register_rng(ccp); + if (ret) goto e_kthread; - } /* Register the DMA engine support */ ret = ccp_dmaengine_register(ccp); @@ -449,7 +444,7 @@ static int ccp_init(struct ccp_device *ccp) return 0; e_hwrng: - hwrng_unregister(&ccp->hwrng); + ccp_unregister_rng(ccp); e_kthread: for (i = 0; i < ccp->cmd_q_count; i++) @@ -475,7 +470,7 @@ static void ccp_destroy(struct ccp_device *ccp) ccp_dmaengine_unregister(ccp); /* Unregister the RNG */ - hwrng_unregister(&ccp->hwrng); + ccp_unregister_rng(ccp); /* Remove this device from the list of available units */ ccp_del_device(ccp); diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c index 16dad9633754..ddce2205e5fa 100644 --- a/drivers/crypto/ccp/ccp-dev-v5.c +++ b/drivers/crypto/ccp/ccp-dev-v5.c @@ -828,6 +828,10 @@ static int ccp5_init(struct ccp_device *ccp) /* Put this on the unit list to make it available */ ccp_add_device(ccp); + ret = ccp_register_rng(ccp); + if (ret) + goto e_kthread; + return 0; e_kthread: @@ -852,6 +856,9 @@ static void ccp5_destroy(struct ccp_device *ccp) struct ccp_cmd *cmd; unsigned int i; + /* Unregister the RNG */ + ccp_unregister_rng(ccp); + /* Remove this device from the list of available units first */ ccp_del_device(ccp); diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c index 6b44730ef9d6..38a98d879f82 100644 --- a/drivers/crypto/ccp/ccp-dev.c +++ b/drivers/crypto/ccp/ccp-dev.c @@ -119,6 +119,29 @@ void ccp_del_device(struct ccp_device *ccp) write_unlock_irqrestore(&ccp_unit_lock, flags); } + + +int ccp_register_rng(struct ccp_device *ccp) +{ + int ret = 0; + + dev_dbg(ccp->dev, "Registering RNG...\n"); + /* Register an RNG */ + ccp->hwrng.name = ccp->rngname; + ccp->hwrng.read = ccp_trng_read; + ret = hwrng_register(&ccp->hwrng); + if (ret) + dev_err(ccp->dev, "error registering hwrng (%d)\n", ret); + + return ret; +} + +void ccp_unregister_rng(struct ccp_device *ccp) +{ + if (ccp->hwrng.name) + hwrng_unregister(&ccp->hwrng); +} + static struct ccp_device *ccp_get_device(void) { unsigned long flags; diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h index 5ff4a73e3bd4..d04bd61ed845 100644 --- a/drivers/crypto/ccp/ccp-dev.h +++ b/drivers/crypto/ccp/ccp-dev.h @@ -601,6 +601,8 @@ int ccp_trng_read(struct hwrng *rng, void *data, size_t max, bool wait); int ccp_run_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd); +int ccp_register_rng(struct ccp_device *ccp); +void ccp_unregister_rng(struct ccp_device *ccp); int ccp_dmaengine_register(struct ccp_device *ccp); void ccp_dmaengine_unregister(struct ccp_device *ccp); |