RE: [PATCH] crypto: caam - Check for CAAM block presence before registering with crypto layer

2014-03-21 Thread yashpal.du...@freescale.com
Reviewed by: Yashpal Dutta 

-Original Message-
From: linux-crypto-ow...@vger.kernel.org 
[mailto:linux-crypto-ow...@vger.kernel.org] On Behalf Of Ruchika Gupta
Sent: Friday, March 21, 2014 12:14 PM
To: linux-crypto@vger.kernel.org
Cc: herb...@gondor.apana.org.au
Subject: [PATCH] crypto: caam - Check for CAAM block presence before 
registering with crypto layer

The layer which registers with the crypto API should check for the presence of
the CAAM device it is going to use.  If the platform's device tree doesn't have
the required CAAM node, the layer should return an error and not register the
algorithms with crypto API layer.

Signed-off-by: Ruchika Gupta 
---
 drivers/crypto/caam/caamalg.c  | 27 +++
 drivers/crypto/caam/caamhash.c | 26 ++
 drivers/crypto/caam/caamrng.c  | 26 ++
 3 files changed, 79 insertions(+)

diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index b71f2fd..4335e38 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -2164,8 +2164,35 @@ static struct caam_crypto_alg *caam_alg_alloc(struct 
caam_alg_template
 
 static int __init caam_algapi_init(void)
 {
+   struct device_node *dev_node;
+   struct platform_device *pdev;
+   struct device *ctrldev;
+   void *priv;
int i = 0, err = 0;
 
+   dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
+   if (!dev_node) {
+   dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
+   if (!dev_node)
+   return -ENODEV;
+   }
+
+   pdev = of_find_device_by_node(dev_node);
+   if (!pdev)
+   return -ENODEV;
+
+   ctrldev = &pdev->dev;
+   priv = dev_get_drvdata(ctrldev);
+   of_node_put(dev_node);
+
+   /*
+* If priv is NULL, it's probably because the caam driver wasn't
+* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
+*/
+   if (!priv)
+   return -ENODEV;
+
+
INIT_LIST_HEAD(&alg_list);
 
/* register crypto algorithms the device supports */
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 0378328..5592fec 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -1797,8 +1797,34 @@ caam_hash_alloc(struct caam_hash_template *template,
 
 static int __init caam_algapi_hash_init(void)
 {
+   struct device_node *dev_node;
+   struct platform_device *pdev;
+   struct device *ctrldev;
+   void *priv;
int i = 0, err = 0;
 
+   dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
+   if (!dev_node) {
+   dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
+   if (!dev_node)
+   return -ENODEV;
+   }
+
+   pdev = of_find_device_by_node(dev_node);
+   if (!pdev)
+   return -ENODEV;
+
+   ctrldev = &pdev->dev;
+   priv = dev_get_drvdata(ctrldev);
+   of_node_put(dev_node);
+
+   /*
+* If priv is NULL, it's probably because the caam driver wasn't
+* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
+*/
+   if (!priv)
+   return -ENODEV;
+
INIT_LIST_HEAD(&hash_list);
 
/* register crypto algorithms the device supports */
diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index 403d8d5..7c9803b 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -281,6 +281,32 @@ static void __exit caam_rng_exit(void)
 static int __init caam_rng_init(void)
 {
struct device *dev;
+   struct device_node *dev_node;
+   struct platform_device *pdev;
+   struct device *ctrldev;
+   void *priv;
+
+   dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
+   if (!dev_node) {
+   dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
+   if (!dev_node)
+   return -ENODEV;
+   }
+
+   pdev = of_find_device_by_node(dev_node);
+   if (!pdev)
+   return -ENODEV;
+
+   ctrldev = &pdev->dev;
+   priv = dev_get_drvdata(ctrldev);
+   of_node_put(dev_node);
+
+   /*
+* If priv is NULL, it's probably because the caam driver wasn't
+* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
+*/
+   if (!priv)
+   return -ENODEV;
 
dev = caam_jr_alloc();
if (IS_ERR(dev)) {
-- 
1.8.1.4


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.ker

RE: [PATCH v3] crypto: caam - power management support for caam job-ring

2014-03-22 Thread yashpal.du...@freescale.com
I tried to reduce the patch to smallest possible size which resulted in current 
patch. 

I didn’t find a way to compress or break it further to limit of stable tree 
patch expectations.

Yash
-Original Message-
From: Ben Hutchings [mailto:b...@decadent.org.uk] 
Sent: Saturday, March 22, 2014 9:54 PM
To: Dutta Yashpal-B05456
Cc: linux-crypto@vger.kernel.org; Geanta Neag Horia Ioan-B05471; Garg 
Vakul-B16394; Gupta Ruchika-R66431; sta...@vger.kernel.org
Subject: Re: [PATCH v3] crypto: caam - power management support for caam 
job-ring

On Fri, 2014-03-21 at 00:35 +0545, Yashpal Dutta wrote:
> Job ring is suspended gracefully and resume afresh.
> 
> Both Sleep (where device will remain powered-on) and Deep-sleep (where 
> device will be powered-down are handled gracefully. Persistance 
> sessions are not supported across deep-sleep.
> 
> Cc: sta...@vger.kernel.org
> Signed-off-by: Yashpal Dutta 
> ---
>  drivers/crypto/caam/intern.h |   2 +
>  drivers/crypto/caam/jr.c | 257 
> +++
>  2 files changed, 190 insertions(+), 69 deletions(-)
[...]

This is too big for stable; is a simpler fix possible?

Ben.

--
Ben Hutchings
I'm not a reverse psychological virus.  Please don't copy me into your sig.
N�r��yb�X��ǧv�^�)޺{.n�+{�r����ܨ}���Ơz�&j:+v���zZ+��+zf���h���~i���z��w���?�&�)ߢf