Skip to contentSkip to conversation

hwrng: bcm2835: add reset support

PATCH In review Álvaro Fernández Rojas 5 participants 11 messages Mar 5, 2021 – Mar 12, 2021

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v6 cover hwrng: bcm2835: add reset support

Some devices may need to perform a reset before using the RNG, such as the BCM6368.

v6: fix dt-bindings documentation, add patch makings clocks mandatory for
BCM6368.
v5: remove reset_control_rearm() and apply on latest herbert/cryptodev-2.6.git.
v4: fix documentation, add reset_control_rearm().
v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

Álvaro Fernández Rojas (3):
dt-bindings: rng: bcm2835: add clock constraints
dt-bindings: rng: bcm2835: document reset support
hwrng: bcm2835: add reset support

 .../devicetree/bindings/rng/brcm,bcm2835.yaml | 21 +++++++++++++++++++
 drivers/char/hw_random/bcm2835-rng.c          | 10 +++++++++
 2 files changed, 31 insertions(+)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v6 1/3 dt-bindings: rng: bcm2835: add clock constraints

brcm,bcm6368-rng controllers require enabling the IPSEC clock in order to get a functional RNG.

---
v6: add new patch making clocks mandatory for BCM6368.

 .../devicetree/bindings/rng/brcm,bcm2835.yaml          | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +10 -0
index c147900f9041..5174492e22f3 100644
@@ -35,6 +35,16 @@ required:
   - compatible
   - reg
 
+if:
+  properties:
+    compatible:
+      enum:
+        - brcm,bcm6368-rng
+then:
+  required:
+    - clocks
+    - clock-names
+
 additionalProperties: false
 
 examples:
Signature · 1 line
2.20.1
maintainer Reviewed-by on v6 1/3
#2 lore raw

Re: [PATCH v6 1/3] dt-bindings: rng: bcm2835: add clock constraints

Quoted 10 lines · Álvaro Fernández Rojas

brcm,bcm6368-rng controllers require enabling the IPSEC clock in order to get a functional RNG.

---
v6: add new patch making clocks mandatory for BCM6368.

 .../devicetree/bindings/rng/brcm,bcm2835.yaml          | 10 ++++++++++
 1 file changed, 10 insertions(+)
#4 lore raw

PATCH v6 2/3 dt-bindings: rng: bcm2835: document reset support

In reply to Álvaro Fernández Rojas

brcm,bcm6368-rng controllers require resetting the IPSEC clock in order to get a functional RNG.

---
v6: fix dt-bindings warnings.
v5: no changes.
v4: pass dt_binding_check.
v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

 .../devicetree/bindings/rng/brcm,bcm2835.yaml         | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +11 -0
index 5174492e22f3..6da674666d45 100644
@@ -28,6 +28,12 @@ properties:
   clock-names:
     const: ipsec
 
+  resets:
+    maxItems: 1
+
+  reset-names:
+    const: ipsec
+
   interrupts:
     maxItems: 1
 
@@ -44,6 +50,8 @@ then:
   required:
     - clocks
     - clock-names
+    - resets
+    - reset-names
 
 additionalProperties: false
 
@@ -68,4 +76,7 @@ examples:
 
         clocks = <&periph_clk 18>;
         clock-names = "ipsec";
+
+        resets = <&periph_rst 4>;
+        reset-names = "ipsec";
     };
Signature · 1 line
2.20.1
maintainer Reviewed-by on v6 2/3
#5 lore raw

Re: [PATCH v6 2/3] dt-bindings: rng: bcm2835: document reset support

Quoted 11 lines · Álvaro Fernández Rojas

brcm,bcm6368-rng controllers require resetting the IPSEC clock in order to get a functional RNG.

---
v6: fix dt-bindings warnings.
v5: no changes.
v4: pass dt_binding_check.
v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

Quoted 3 lines
 .../devicetree/bindings/rng/brcm,bcm2835.yaml         | 11 +++++++++++
 1 file changed, 11 insertions(+)
#7 lore raw

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

In reply to Á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: 20000032
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

---
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(+)
drivers/char/hw_random/bcm2835-rng.c +10 -0
index be5be395b341..e7dd457e9b22 100644
@@ -13,6 +13,7 @@
 #include <linux/platform_device.h>
 #include <linux/printk.h>
 #include <linux/clk.h>
+#include <linux/reset.h>
 
 #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;
Signature · 1 line
2.20.1
Reviewed-by on v6 3/3
#8 lore raw
Quoted 22 lines · Á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: 20000032
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

Quoted 1 line

regards
Philipp

Quoted 52 lines

---
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(+)
drivers/char/hw_random/bcm2835-rng.c +10 -0
index be5be395b341..e7dd457e9b22 100644
@@ -13,6 +13,7 @@
 #include <linux/platform_device.h>
 #include <linux/printk.h>
 #include <linux/clk.h>
+#include <linux/reset.h>
 
 #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;
Acked-by on v6 3/3
#9 lore raw
In reply to Álvaro Fernández Rojas
Quoted 22 lines · Á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: 20000032
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

Quoted 1 line
Signature · 1 line
Florian
maintainer
#10 lore raw
In reply to Álvaro Fernández Rojas
Quoted 10 lines · Álvaro Fernández Rojas

Some devices may need to perform a reset before using the RNG, such as the BCM6368.

v6: fix dt-bindings documentation, add patch makings clocks mandatory for
BCM6368.
v5: remove reset_control_rearm() and apply on latest herbert/cryptodev-2.6.git.
v4: fix documentation, add reset_control_rearm().
v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

Quoted 8 lines

Álvaro Fernández Rojas (3):
dt-bindings: rng: bcm2835: add clock constraints
dt-bindings: rng: bcm2835: document reset support
hwrng: bcm2835: add reset support

 .../devicetree/bindings/rng/brcm,bcm2835.yaml | 21 +++++++++++++++++++
 drivers/char/hw_random/bcm2835-rng.c          | 10 +++++++++
 2 files changed, 31 insertions(+)

All applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt