Re: [PATCH v6 3/3] hwrng: bcm2835: add reset support

2021-03-08 Thread Florian Fainelli
On 3/4/21 11:01 PM, Álvaro Fernández Rojas wrote:
> BCM6368 devices need to reset the IPSEC controller in order to generate true
> random numbers.
> 
> This is what BCM6368 produces without a reset:
> root@OpenWrt:/# cat /dev/hwrng | rngtest -c 1000
> rngtest 6.10
> Copyright (c) 2004 by Henrique de Moraes Holschuh
> This is free software; see the source for copying conditions.  There is NO 
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> rngtest: starting FIPS tests...
> rngtest: bits received from input: 2032
> rngtest: FIPS 140-2 successes: 0
> rngtest: FIPS 140-2 failures: 1000
> rngtest: FIPS 140-2(2001-10-10) Monobit: 2
> rngtest: FIPS 140-2(2001-10-10) Poker: 1000
> rngtest: FIPS 140-2(2001-10-10) Runs: 1000
> rngtest: FIPS 140-2(2001-10-10) Long run: 30
> rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
> rngtest: input channel speed: (min=37.253; avg=320.827; max=635.783)Mibits/s
> rngtest: FIPS tests speed: (min=12.141; avg=15.034; max=16.428)Mibits/s
> rngtest: Program run time: 1336176 microseconds
> 
> Signed-off-by: Álvaro Fernández Rojas 

Acked-by: Florian Fainelli 
-- 
Florian


Re: [PATCH v6 3/3] hwrng: bcm2835: add reset support

2021-03-05 Thread Philipp Zabel
On Fri, 2021-03-05 at 08:01 +0100, Álvaro Fernández Rojas wrote:
> BCM6368 devices need to reset the IPSEC controller in order to generate true
> random numbers.
> 
> This is what BCM6368 produces without a reset:
> root@OpenWrt:/# cat /dev/hwrng | rngtest -c 1000
> rngtest 6.10
> Copyright (c) 2004 by Henrique de Moraes Holschuh
> This is free software; see the source for copying conditions.  There is NO 
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> rngtest: starting FIPS tests...
> rngtest: bits received from input: 2032
> rngtest: FIPS 140-2 successes: 0
> rngtest: FIPS 140-2 failures: 1000
> rngtest: FIPS 140-2(2001-10-10) Monobit: 2
> rngtest: FIPS 140-2(2001-10-10) Poker: 1000
> rngtest: FIPS 140-2(2001-10-10) Runs: 1000
> rngtest: FIPS 140-2(2001-10-10) Long run: 30
> rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
> rngtest: input channel speed: (min=37.253; avg=320.827; max=635.783)Mibits/s
> rngtest: FIPS tests speed: (min=12.141; avg=15.034; max=16.428)Mibits/s
> rngtest: Program run time: 1336176 microseconds
> 
> Signed-off-by: Álvaro Fernández Rojas 

Reviewed-by: Philipp Zabel 

regards
Philipp

> ---
>  v6: fix commit description.
>  v5: remove reset_control_rearm().
>  v4: add reset_control_rearm().
>  v3: no changes.
>  v2: no changes.
> 
>  drivers/char/hw_random/bcm2835-rng.c | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/char/hw_random/bcm2835-rng.c 
> b/drivers/char/hw_random/bcm2835-rng.c
> index be5be395b341..e7dd457e9b22 100644
> --- a/drivers/char/hw_random/bcm2835-rng.c
> +++ b/drivers/char/hw_random/bcm2835-rng.c
> @@ -13,6 +13,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #define RNG_CTRL 0x0
>  #define RNG_STATUS   0x4
> @@ -32,6 +33,7 @@ struct bcm2835_rng_priv {
>   void __iomem *base;
>   bool mask_interrupts;
>   struct clk *clk;
> + struct reset_control *reset;
>  };
>  
>  static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng)
> @@ -92,6 +94,10 @@ static int bcm2835_rng_init(struct hwrng *rng)
>   if (ret)
>   return ret;
>  
> + ret = reset_control_reset(priv->reset);
> + if (ret)
> + return ret;
> +
>   if (priv->mask_interrupts) {
>   /* mask the interrupt */
>   val = rng_readl(priv, RNG_INT_MASK);
> @@ -156,6 +162,10 @@ static int bcm2835_rng_probe(struct platform_device 
> *pdev)
>   if (IS_ERR(priv->clk))
>   return PTR_ERR(priv->clk);
>  
> + priv->reset = devm_reset_control_get_optional_exclusive(dev, NULL);
> + if (IS_ERR(priv->reset))
> + return PTR_ERR(priv->reset);
> +
>   priv->rng.name = pdev->name;
>   priv->rng.init = bcm2835_rng_init;
>   priv->rng.read = bcm2835_rng_read;


[PATCH v6 3/3] hwrng: bcm2835: add reset support

2021-03-04 Thread Álvaro Fernández Rojas
BCM6368 devices need to reset the IPSEC controller in order to generate true
random numbers.

This is what BCM6368 produces without a reset:
root@OpenWrt:/# cat /dev/hwrng | rngtest -c 1000
rngtest 6.10
Copyright (c) 2004 by Henrique de Moraes Holschuh
This is free software; see the source for copying conditions.  There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

rngtest: starting FIPS tests...
rngtest: bits received from input: 2032
rngtest: FIPS 140-2 successes: 0
rngtest: FIPS 140-2 failures: 1000
rngtest: FIPS 140-2(2001-10-10) Monobit: 2
rngtest: FIPS 140-2(2001-10-10) Poker: 1000
rngtest: FIPS 140-2(2001-10-10) Runs: 1000
rngtest: FIPS 140-2(2001-10-10) Long run: 30
rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
rngtest: input channel speed: (min=37.253; avg=320.827; max=635.783)Mibits/s
rngtest: FIPS tests speed: (min=12.141; avg=15.034; max=16.428)Mibits/s
rngtest: Program run time: 1336176 microseconds

Signed-off-by: Álvaro Fernández Rojas 
---
 v6: fix commit description.
 v5: remove reset_control_rearm().
 v4: add reset_control_rearm().
 v3: no changes.
 v2: no changes.

 drivers/char/hw_random/bcm2835-rng.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/char/hw_random/bcm2835-rng.c 
b/drivers/char/hw_random/bcm2835-rng.c
index be5be395b341..e7dd457e9b22 100644
--- a/drivers/char/hw_random/bcm2835-rng.c
+++ b/drivers/char/hw_random/bcm2835-rng.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define RNG_CTRL   0x0
 #define RNG_STATUS 0x4
@@ -32,6 +33,7 @@ struct bcm2835_rng_priv {
void __iomem *base;
bool mask_interrupts;
struct clk *clk;
+   struct reset_control *reset;
 };
 
 static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng)
@@ -92,6 +94,10 @@ static int bcm2835_rng_init(struct hwrng *rng)
if (ret)
return ret;
 
+   ret = reset_control_reset(priv->reset);
+   if (ret)
+   return ret;
+
if (priv->mask_interrupts) {
/* mask the interrupt */
val = rng_readl(priv, RNG_INT_MASK);
@@ -156,6 +162,10 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
if (IS_ERR(priv->clk))
return PTR_ERR(priv->clk);
 
+   priv->reset = devm_reset_control_get_optional_exclusive(dev, NULL);
+   if (IS_ERR(priv->reset))
+   return PTR_ERR(priv->reset);
+
priv->rng.name = pdev->name;
priv->rng.init = bcm2835_rng_init;
priv->rng.read = bcm2835_rng_read;
-- 
2.20.1