summaryrefslogtreecommitdiffstats
path: root/drivers/crypto/caam/ctrl.c
diff options
context:
space:
mode:
authorAlex Porosanu <alexandru.porosanu@freescale.com>2013-09-09 17:56:32 +0200
committerHerbert Xu <herbert@gondor.apana.org.au>2013-09-13 13:43:55 +0200
commitb1f996e0b3b00c98f0ac8ffef1a6572cbc735bbc (patch)
tree8f6ecb80263398bef489cc6f7a555230fbcc0531 /drivers/crypto/caam/ctrl.c
parentcrypto: caam - split RNG4 instantiation function (diff)
downloadlinux-b1f996e0b3b00c98f0ac8ffef1a6572cbc735bbc.tar.xz
linux-b1f996e0b3b00c98f0ac8ffef1a6572cbc735bbc.zip
crypto: caam - uninstantiate RNG state handle 0 if instantiated by caam driver
If the caam driver module instantiates the RNG state handle 0, then upon the removal of the module, the RNG state handle is left initialized. This patch takes care of reverting the state of the handle back to its previous uninstantatied state. Signed-off-by: Alex Porosanu <alexandru.porosanu@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/caam/ctrl.c')
-rw-r--r--drivers/crypto/caam/ctrl.c57
1 files changed, 51 insertions, 6 deletions
diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 3ad032f570ae..9e9215ac130e 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -44,6 +44,17 @@ static void build_instantiation_desc(u32 *desc)
append_jump(desc, JUMP_CLASS_CLASS1 | JUMP_TYPE_HALT);
}
+/* Descriptor for deinstantiation of State Handle 0 of the RNG block. */
+static void build_deinstantiation_desc(u32 *desc)
+{
+ init_job_desc(desc, 0);
+
+ /* Uninstantiate State Handle 0 */
+ append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
+ OP_ALG_AS_INITFINAL);
+
+ append_jump(desc, JUMP_CLASS_CLASS1 | JUMP_TYPE_HALT);
+}
/*
* run_descriptor_deco0 - runs a descriptor on DECO0, under direct control of
@@ -59,7 +70,7 @@ static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc)
struct caam_full __iomem *topregs;
unsigned int timeout = 100000;
u32 deco_dbg_reg, flags;
- int i, ret = 0;
+ int i;
/* Set the bit to request direct access to DECO0 */
topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
@@ -102,11 +113,6 @@ static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc)
cpu_relax();
} while ((deco_dbg_reg & DESC_DBG_DECO_STAT_VALID) && --timeout);
- if (!timeout) {
- dev_err(ctrldev, "failed to instantiate RNG\n");
- ret = -EIO;
- }
-
/* Mark the DECO as free */
clrbits32(&topregs->ctrl.deco_rq, DECORR_RQD0ENABLE);
@@ -146,6 +152,39 @@ static int instantiate_rng(struct device *ctrldev)
return ret;
}
+/*
+ * deinstantiate_rng - builds and executes a descriptor on DECO0,
+ * which deinitializes the RNG block.
+ * @ctrldev - pointer to device
+ *
+ * Return: - 0 if no error occurred
+ * - -ENOMEM if there isn't enough memory to allocate the descriptor
+ * - -ENODEV if DECO0 couldn't be acquired
+ * - -EAGAIN if an error occurred when executing the descriptor
+ */
+static int deinstantiate_rng(struct device *ctrldev)
+{
+ u32 *desc;
+ int i, ret = 0;
+
+ desc = kmalloc(CAAM_CMD_SZ * 3, GFP_KERNEL);
+ if (!desc)
+ return -ENOMEM;
+
+ /* Create the descriptor for deinstantating RNG State Handle 0 */
+ build_deinstantiation_desc(desc);
+
+ /* Try to run it through DECO0 */
+ ret = run_descriptor_deco0(ctrldev, desc);
+
+ if (ret)
+ dev_err(ctrldev, "failed to deinstantiate RNG\n");
+
+ kfree(desc);
+
+ return ret;
+}
+
static int caam_remove(struct platform_device *pdev)
{
struct device *ctrldev;
@@ -165,6 +204,10 @@ static int caam_remove(struct platform_device *pdev)
irq_dispose_mapping(jrpriv->irq);
}
+ /* De-initialize RNG if it was initialized by this driver. */
+ if (ctrlpriv->rng4_init)
+ deinstantiate_rng(ctrldev);
+
/* Shut down debug views */
#ifdef CONFIG_DEBUG_FS
debugfs_remove_recursive(ctrlpriv->dfs_root);
@@ -384,6 +427,8 @@ static int caam_probe(struct platform_device *pdev)
return ret;
}
+ ctrlpriv->rng4_init = 1;
+
/* Enable RDB bit so that RNG works faster */
setbits32(&topregs->ctrl.scfgr, SCFGR_RDBENABLE);
}