Skip to contentSkip to conversation

hwrng: bcm2835: add reset support

PATCH New Álvaro Fernández Rojas 7 participants 24 messages Feb 22, 2021 – Mar 4, 2021

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

PATCH 1/1 hwrng: bcm2835: add reset support

BCM6368 devices need to reset the 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
cat: write error: Broken pipe

---
 drivers/char/hw_random/bcm2835-rng.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/char/hw_random/bcm2835-rng.c +10 -0
index 1a7c43b43c6b..1b93a896d8e8 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)
@@ -94,6 +96,10 @@ static int bcm2835_rng_init(struct hwrng *rng)
 			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);
@@ -159,6 +165,10 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
 	if (PTR_ERR(priv->clk) == -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 
+	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
#1 lore raw

cover hwrng: bcm2835: add reset support

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

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

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

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

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

---
v2: document reset support.

 Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +5 -0
index c147900f9041..dba70764b7d0 100644
@@ -31,6 +31,9 @@ properties:
   interrupts:
     maxItems: 1
 
+  resets:
+    maxItems: 1
+
 required:
   - compatible
   - reg
@@ -58,4 +61,6 @@ examples:
 
         clocks = <&periph_clk 18>;
         clock-names = "ipsec";
+
+        resets = <&periph_rst 4>;
     };
Signature · 1 line
2.20.1
#3 lore raw

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

Quoted 4 lines · Álvaro Fernández Rojas

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

Since the reset is unique to the 6368, you may want to make the property mandatory for the 6368 compatible string and optional otherwise.

Signature · 1 line
Florian
#4 lore raw

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

Quoted 11 lines · Florian Fainelli
Quoted 4 lines · Álvaro Fernández Rojas

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

Since the reset is unique to the 6368, you may want to make the property mandatory for the 6368 compatible string and optional otherwise.

Perhaps the reset could be done at an earlier boot stage as well and then the reset would even be optional on 6368?

#5 lore raw

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

Hello Scott,

Quoted 7 lines · Scott Branden
Quoted 6 lines · Florian Fainelli
Quoted 3 lines · Álvaro Fernández Rojas

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

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Since the reset is unique to the 6368, you may want to make the property mandatory for the 6368 compatible string and optional otherwise.

Perhaps the reset could be done at an earlier boot stage as well and then the reset would even be optional on 6368?

No, this isn't possible on bmips, which is device tree only. However, it's how is done in bcm63xx, which is why it wasn't needed before.

Best regards,
Álvaro.

#6 lore raw

PATCH 2/2 hwrng: bcm2835: add reset support

In reply to Álvaro Fernández Rojas

BCM6368 devices need to reset the 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

---
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 1a7c43b43c6b..1b93a896d8e8 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)
@@ -94,6 +96,10 @@ static int bcm2835_rng_init(struct hwrng *rng)
 			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);
@@ -159,6 +165,10 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
 	if (PTR_ERR(priv->clk) == -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 
+	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
#7 lore raw

v4 cover hwrng: bcm2835: add reset support

In reply to Álvaro Fernández Rojas

v4: fix documentation, add reset_control_rearm().
v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

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

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

PATCH v4 1/2 dt-bindings: rng: bcm2835: document reset support

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

---
v4: pass dt_binding_check.
v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

 .../devicetree/bindings/rng/brcm,bcm2835.yaml      | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +14 -0
index c147900f9041..9a74b5af1dbd 100644
@@ -31,12 +31,24 @@ properties:
   interrupts:
     maxItems: 1
 
+  resets:
+    maxItems: 1
+
 required:
   - compatible
   - reg
 
 additionalProperties: false
 
+if:
+  properties:
+    compatible:
+      enum:
+        - brcm,bcm6368-rng
+then:
+  required:
+    - resets
+
 examples:
   - |
     rng@7e104000 {
@@ -58,4 +70,6 @@ examples:
 
         clocks = <&periph_clk 18>;
         clock-names = "ipsec";
+
+        resets = <&periph_rst 4>;
     };
Signature · 1 line
2.20.1
#9 lore raw

PATCH v4 2/2 hwrng: bcm2835: add reset support

In reply to Álvaro Fernández Rojas

BCM6368 devices need to reset the 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

---
v4: add reset_control_rearm().
v3: no changes.
v2: no changes.

 drivers/char/hw_random/bcm2835-rng.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/char/hw_random/bcm2835-rng.c +12 -0
index 1a7c43b43c6b..92658edaff22 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)
@@ -94,6 +96,10 @@ static int bcm2835_rng_init(struct hwrng *rng)
 			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);
@@ -115,6 +121,8 @@ static void bcm2835_rng_cleanup(struct hwrng *rng)
 	/* disable rng hardware */
 	rng_writel(priv, 0, RNG_CTRL);
 
+	reset_control_rearm(priv->reset);
+
 	if (!IS_ERR(priv->clk))
 		clk_disable_unprepare(priv->clk);
 }
@@ -159,6 +167,10 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
 	if (PTR_ERR(priv->clk) == -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 
+	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
#10 lore raw

Hi Álvaro,

On Wed, 2021-02-24 at 09:22 +0100, Álvaro Fernández Rojas wrote:
[...]

Quoted 10 lines
drivers/char/hw_random/bcm2835-rng.c +2 -0
@@ -115,6 +121,8 @@ static void bcm2835_rng_cleanup(struct hwrng *rng)
 	/* disable rng hardware */
 	rng_writel(priv, 0, RNG_CTRL);
 
+	reset_control_rearm(priv->reset);
+
 	if (!IS_ERR(priv->clk))
 		clk_disable_unprepare(priv->clk);
 }

drivers/char/hw_random/bcm2835-rng.c static int bcm2835_rng_probe(struct platform_device *pdev) · line 176

Quoted 10 lines
drivers/char/hw_random/bcm2835-rng.c +4 -0
@@ -159,6 +167,10 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
 	if (PTR_ERR(priv->clk) == -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 
+	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;

That doesn't seem right. reset_control_rearm() doesn't do anything if the reset control is exclusive. Either the reset control should be requested as shared, or the _rearm should be removed.

regards
Philipp

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#11 lore raw

Hi Philipp,

Quoted 19 lines · Philipp Zabel

Hi Álvaro,

On Wed, 2021-02-24 at 09:22 +0100, Álvaro Fernández Rojas wrote:
[...]

Quoted 13 lines
drivers/char/hw_random/bcm2835-rng.c +2 -0
@@ -115,6 +121,8 @@ static void bcm2835_rng_cleanup(struct hwrng *rng)
 	/* disable rng hardware */
 	rng_writel(priv, 0, RNG_CTRL);
 
+	reset_control_rearm(priv->reset);
+
 	if (!IS_ERR(priv->clk))
 		clk_disable_unprepare(priv->clk);
 }
@@ -159,6 +167,10 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
 	if (PTR_ERR(priv->clk) == -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 
Quoted 11 lines

drivers/char/hw_random/bcm2835-rng.c static int bcm2835_rng_probe(struct platform_device *pdev) · line 176

Quoted 7 lines
drivers/char/hw_random/bcm2835-rng.c +4 -0
+	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;

That doesn't seem right. reset_control_rearm() doesn't do anything if the reset control is exclusive. Either the reset control should be requested as shared, or the _rearm should be removed.

In only added reset_control_rearm() because Florian requested it…
I think it’s not needed, so we can use v3, since it was the only change between v3 and v4...

Quoted 3 lines

regards
Philipp

Best regards,
Álvaro.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#12 lore raw
Quoted 33 lines · Álvaro Fernández Rojas

Hi Philipp,

Quoted 19 lines · Philipp Zabel

Hi Álvaro,

On Wed, 2021-02-24 at 09:22 +0100, Álvaro Fernández Rojas wrote:
[...]

Quoted 13 lines
drivers/char/hw_random/bcm2835-rng.c +2 -0
@@ -115,6 +121,8 @@ static void bcm2835_rng_cleanup(struct hwrng *rng)
 	/* disable rng hardware */
 	rng_writel(priv, 0, RNG_CTRL);
 
+	reset_control_rearm(priv->reset);
+
 	if (!IS_ERR(priv->clk))
 		clk_disable_unprepare(priv->clk);
 }
@@ -159,6 +167,10 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
 	if (PTR_ERR(priv->clk) == -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 
Quoted 11 lines

drivers/char/hw_random/bcm2835-rng.c static int bcm2835_rng_probe(struct platform_device *pdev) · line 176

Quoted 7 lines
drivers/char/hw_random/bcm2835-rng.c +4 -0
+	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;

That doesn't seem right. reset_control_rearm() doesn't do anything if the reset control is exclusive. Either the reset control should be requested as shared, or the _rearm should be removed.

Quoted 2 lines

In only added reset_control_rearm() because Florian requested it…
I think it’s not needed, so we can use v3, since it was the only change between v3 and v4...

Not the first time I am confused by the reset API not sure if I will ever get it one day, so apologies for suggesting something incorrect here.

Signature · 1 line
Florian
#13 lore raw

v3 cover hwrng: bcm2835: add reset support

In reply to Álvaro Fernández Rojas

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

v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

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

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

PATCH v3 1/2 dt-bindings: rng: bcm2835: document reset support

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

---
v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

 .../devicetree/bindings/rng/brcm,bcm2835.yaml   | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +17 -0
index c147900f9041..11c23e1f6988 100644
@@ -37,6 +37,21 @@ required:
 
 additionalProperties: false
 
+if:
+  properties:
+    compatible:
+      enum:
+        - brcm,bcm6368-rng
+then:
+  properties:
+    resets:
+      maxItems: 1
+  required:
+    - resets
+else:
+  properties:
+    resets: false
+
 examples:
   - |
     rng@7e104000 {
@@ -58,4 +73,6 @@ examples:
 
         clocks = <&periph_clk 18>;
         clock-names = "ipsec";
+
+        resets = <&periph_rst 4>;
     };
Signature · 1 line
2.20.1
maintainer
#15 lore raw

Re: [PATCH v3 1/2] dt-bindings: rng: bcm2835: document reset support

Quoted 11 lines · Álvaro Fernández Rojas

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

---
v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

 .../devicetree/bindings/rng/brcm,bcm2835.yaml   | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/rng/brcm,bcm2835.example.dt.yaml: rng@10004180: 'resets' does not match any of the regexes: 'pinctrl-[0-9]+'
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml

See https://patchwork.ozlabs.org/patch/1443582

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

#16 lore raw

Re: [PATCH v3 1/2] dt-bindings: rng: bcm2835: document reset support

Hi Rob,

Quoted 15 lines · Rob Herring
Quoted 11 lines · Álvaro Fernández Rojas

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

---
v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

.../devicetree/bindings/rng/brcm,bcm2835.yaml | 17 +++++++++++++++++

1 file changed, 17 insertions(+)
Quoted 7 lines

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/rng/brcm,bcm2835.example.dt.yaml: rng@10004180: 'resets' does not match any of the regexes: 'pinctrl-[0-9]+'
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml

I don’t get what’s wrong here...

Quoted 6 lines

See https://patchwork.ozlabs.org/patch/1443582

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

Quoted 8 lines

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

Best regards,
Álvaro.

#17 lore raw

Re: [PATCH v3 1/2] dt-bindings: rng: bcm2835: document reset support

In reply to Álvaro Fernández Rojas

Hi Alvaro,

Quoted 18 lines · Álvaro Fernández Rojas

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

---
 v3: make resets required if brcm,bcm6368-rng.
 v2: document reset support.

 .../devicetree/bindings/rng/brcm,bcm2835.yaml | 17 +++++++++++++++++

 1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +0 -0
index c147900f9041..11c23e1f6988 100644
@@ -37,6 +37,21 @@ required:

Quoted 1 line

 additionalProperties: false

I can't claim I fully understand all the meta stuff in shemas, so I generally just follow the patterns already available out there. That said, shoudln't this be at the end, just before the examples? Maybe the cause of that odd warning you got there?

Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml required: · line 50

Quoted 11 lines
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +11 -0
+if:
+  properties:
+    compatible:
+      enum:
+        - brcm,bcm6368-rng
+then:
+  properties:
+    resets:
+      maxItems: 1
+  required:
+    - resets

I belive you can't really make a property required when the bindings for 'brcm,bcm6368-rng' were already defined. This will break the schema for those otherwise correct devicetrees.

Quoted 14 lines
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +4 -0
+else:
+  properties:
+    resets: false
+

 examples:
   - |
     rng@7e104000 {

Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +0 -0
@@ -58,4 +73,6 @@ examples:

         clocks = <&periph_clk 18>;
         clock-names = "ipsec";

Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +2 -0
+
+        resets = <&periph_rst 4>;
Quoted 1 line

     };

Regards,
Nicolas

#18 lore raw

Re: [PATCH v3 1/2] dt-bindings: rng: bcm2835: document reset support

Quoted 25 lines · Nicolas Saenz Julienne

Hi Alvaro,

Quoted 18 lines · Álvaro Fernández Rojas

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

---
v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

 .../devicetree/bindings/rng/brcm,bcm2835.yaml   | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +0 -0
index c147900f9041..11c23e1f6988 100644
@@ -37,6 +37,21 @@ required:
 
 
Quoted 4 lines

Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml required: · line 38

Quoted 1 line
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +0 -0
 additionalProperties: false

I can't claim I fully understand all the meta stuff in shemas, so I generally just follow the patterns already available out there.

Well, that makes two of us :).

Quoted 1 line

That said, shoudln't this be at the end, just before the examples?

I don’t know but I can move it there ¯\_(ツ)_/¯

Quoted 2 lines

Maybe the cause of that odd warning
you got there?

Which odd warning?
I don’t get any warnings when running (or at least warnings related to rig, because I get warnings related to other yamls):
make dt_binding_check DT_SCHEMA_FILES=Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml

Quoted 16 lines

Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml required: · line 50

Quoted 12 lines
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +11 -0
+if:
+  properties:
+    compatible:
+      enum:
+        - brcm,bcm6368-rng
+then:
+  properties:
+    resets:
+      maxItems: 1
+  required:
+    - resets

I belive you can't really make a property required when the bindings for 'brcm,bcm6368-rng' were already defined. This will break the schema for those otherwise correct devicetrees.

Why not?
Wouldn’t just be required for brcm,bcm6368-rng?

Anyway, I can omit this, since it would be the same for clocks and those aren’t required either.

Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +4 -0
+else:
+  properties:
+    resets: false
+
 examples:
   - |
     rng@7e104000 {
@@ -58,4 +73,6 @@ examples:
 
 
Quoted 8 lines
Quoted 5 lines
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +2 -0
         clocks = <&periph_clk 18>;
         clock-names = "ipsec";
+
+        resets = <&periph_rst 4>;
     };

Regards,
Nicolas

Best regards,
Álvaro.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#19 lore raw

Re: [PATCH v3 1/2] dt-bindings: rng: bcm2835: document reset support

Quoted 30 lines · Álvaro Fernández Rojas
Quoted 25 lines · Nicolas Saenz Julienne

Hi Alvaro,

Quoted 19 lines · Álvaro Fernández Rojas

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

---
 v3: make resets required if brcm,bcm6368-rng.
 v2: document reset support.

 .../devicetree/bindings/rng/brcm,bcm2835.yaml | 17 +++++++++++++++++

 1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +0 -0
index c147900f9041..11c23e1f6988 100644
@@ -37,6 +37,21 @@ required:

Quoted 4 lines
Quoted 1 line

 additionalProperties: false

I can't claim I fully understand all the meta stuff in shemas, so I generally just follow the patterns already available out there.

Quoted 5 lines

Well, that makes two of us :).

Quoted 1 line

That said, shoudln't this be at the end, just before the examples?

I don’t know but I can move it there ¯\_(ツ)_/¯

Yes please do. See commit 7f464532b05 ("dt-bindings: Add missing 'additionalProperties: false'") which expands on why it is needed, and why it should be at the end.

Quoted 4 lines
Quoted 2 lines

Maybe the cause of that odd warning
you got there?

Which odd warning?

The one pointed out by Rob Herring's script, which I can reproduce too BTW. On the other hand I can't really tell what's wrong right away.

Quoted 20 lines

I don’t get any warnings when running (or at least warnings related to rig, because I get warnings related to other yamls):
make dt_binding_check DT_SCHEMA_FILES=Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml

Quoted 16 lines

Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml required: · line 50

Quoted 12 lines
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +11 -0
+if:
+  properties:
+    compatible:
+      enum:
+        - brcm,bcm6368-rng
+then:
+  properties:
+    resets:
+      maxItems: 1
+  required:
+    - resets

I belive you can't really make a property required when the bindings for 'brcm,bcm6368-rng' were already defined. This will break the schema for those otherwise correct devicetrees.

Quoted 2 lines

Why not?
Wouldn’t just be required for brcm,bcm6368-rng?

Well, do all 'brcm,bcm6368-rng' users absolutely need the reset controller? If so, the original binding is wrong, which should be mentioned and a 'Fixes:' tag should be added to the commit message. Otherwise, the requirement is optional.

Regards,
Nicolas

#20 lore raw

Re: [PATCH v3 1/2] dt-bindings: rng: bcm2835: document reset support

Hi Nicolas,

Quoted 43 lines · Nicolas Saenz Julienne
Quoted 30 lines · Álvaro Fernández Rojas
Quoted 25 lines · Nicolas Saenz Julienne

Hi Alvaro,

Quoted 19 lines · Álvaro Fernández Rojas

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

---
v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

 .../devicetree/bindings/rng/brcm,bcm2835.yaml   | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +0 -0
index c147900f9041..11c23e1f6988 100644
@@ -37,6 +37,21 @@ required:
 
 
 
Quoted 4 lines

Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml required: · line 38

Quoted 1 line
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +0 -0
 additionalProperties: false

I can't claim I fully understand all the meta stuff in shemas, so I generally just follow the patterns already available out there.

Quoted 5 lines

Well, that makes two of us :).

Quoted 1 line

That said, shoudln't this be at the end, just before the examples?

I don’t know but I can move it there ¯\_(ツ)_/¯

Yes please do. See commit 7f464532b05 ("dt-bindings: Add missing 'additionalProperties: false'") which expands on why it is needed, and why it should be at the end.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Maybe the cause of that odd warning
you got there?

Which odd warning?

The one pointed out by Rob Herring's script, which I can reproduce too BTW. On the other hand I can't really tell what's wrong right away.

Well, I can’t reproduce that locally and I don’t know what’s wrong either, I think that the best option is to remove the full if block.

Quoted 21 lines
Quoted 21 lines

I don’t get any warnings when running (or at least warnings related to rig, because I get warnings related to other yamls):
make dt_binding_check DT_SCHEMA_FILES=Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml

Quoted 16 lines

Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml required: · line 50

Quoted 12 lines
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +11 -0
+if:
+  properties:
+    compatible:
+      enum:
+        - brcm,bcm6368-rng
+then:
+  properties:
+    resets:
+      maxItems: 1
+  required:
+    - resets

I belive you can't really make a property required when the bindings for 'brcm,bcm6368-rng' were already defined. This will break the schema for those otherwise correct devicetrees.

Quoted 6 lines
Quoted 2 lines

Why not?
Wouldn’t just be required for brcm,bcm6368-rng?

Well, do all 'brcm,bcm6368-rng' users absolutely need the reset controller? If so, the original binding is wrong, which should be mentioned and a 'Fixes:' tag should be added to the commit message. Otherwise, the requirement is optional.

I’m not sure about this...

Quoted 3 lines

Regards,
Nicolas

Best regards,
Álvaro.

#21 lore raw

Re: [PATCH v3 1/2] dt-bindings: rng: bcm2835: document reset support

In reply to Nicolas Saenz Julienne
Quoted 22 lines · Nicolas Saenz Julienne

Hi Alvaro,

Quoted 18 lines · Álvaro Fernández Rojas

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

---
v3: make resets required if brcm,bcm6368-rng.
v2: document reset support.

 .../devicetree/bindings/rng/brcm,bcm2835.yaml   | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +0 -0
index c147900f9041..11c23e1f6988 100644
@@ -37,6 +37,21 @@ required:
 
 
Quoted 6 lines

Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml required: · line 38

Quoted 1 line
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +0 -0
 additionalProperties: false

I can't claim I fully understand all the meta stuff in shemas, so I generally just follow the patterns already available out there. That said, shoudln't this be at the end, just before the examples? Maybe the cause of that odd warning you got there?

Yes, 'resets' needs to be defined under 'properties' as additionalProperties can't 'see' into if/then schemas. The top level needs to define everything and then if/then schema just add additional constraints.

Quoted 16 lines

Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml required: · line 50

Quoted 12 lines
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +11 -0
+if:
+  properties:
+    compatible:
+      enum:
+        - brcm,bcm6368-rng
+then:
+  properties:
+    resets:
+      maxItems: 1
+  required:
+    - resets

I belive you can't really make a property required when the bindings for 'brcm,bcm6368-rng' were already defined. This will break the schema for those otherwise correct devicetrees.

Right, unless not having the property meant the device never would have worked.

Rob

#22 lore raw

PATCH v3 2/2 hwrng: bcm2835: add reset support

In reply to Álvaro Fernández Rojas

BCM6368 devices need to reset the 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
cat: write error: Broken pipe

---
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 1a7c43b43c6b..1b93a896d8e8 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)
@@ -94,6 +96,10 @@ static int bcm2835_rng_init(struct hwrng *rng)
 			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);
@@ -159,6 +165,10 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
 	if (PTR_ERR(priv->clk) == -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 
+	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
#23 lore raw
Quoted 50 lines · Álvaro Fernández Rojas

BCM6368 devices need to reset the 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
cat: write error: Broken pipe

---
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 +2 -0
index 1a7c43b43c6b..1b93a896d8e8 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)

drivers/char/hw_random/bcm2835-rng.c static int bcm2835_rng_init(struct hwrng *rng) · line 101

Quoted 6 lines
drivers/char/hw_random/bcm2835-rng.c +3 -0
@@ -94,6 +96,10 @@ static int bcm2835_rng_init(struct hwrng *rng)
 			return ret;
 	}
 
+	ret = reset_control_reset(priv->reset);
+	if (ret)
+		return ret;

For symmetry, the remove path should call reset_control_rearm(), assuming that .reset() is what you want and not .deassert()/assert().

Signature · 1 line
Florian