hwrng: bcm2835: add reset support
Subsystems (5)
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
@@ -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
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
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
@@ -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
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.
Signed-off-by Álvaro Fernández Rojas <[email protected]>
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
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.
Signed-off-by Álvaro Fernández Rojas <[email protected]>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?
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
Signed-off-by Álvaro Fernández Rojas <[email protected]>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.
PATCH 2/2 hwrng: bcm2835: add reset support
In reply to Álvaro Fernández RojasBCM6368 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
@@ -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
v4 cover hwrng: bcm2835: add reset support
In reply to Álvaro Fernández Rojasv4: 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
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
@@ -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
PATCH v4 2/2 hwrng: bcm2835: add reset support
In reply to Álvaro Fernández RojasBCM6368 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
@@ -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
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
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_rearmshould 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
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_rearmshould 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
v3 cover hwrng: bcm2835: add reset support
In reply to Álvaro Fernández RojasSome 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
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
@@ -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
Rob Herring
maintainerRe: [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.
Signed-off-by Álvaro Fernández Rojas <[email protected]>---
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.
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.
Signed-off-by Álvaro Fernández Rojas <[email protected]>---
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.
Re: [PATCH v3 1/2] dt-bindings: rng: bcm2835: document reset support
In reply to Álvaro Fernández RojasHi Alvaro,
Quoted 18 lines · Álvaro Fernández Rojas
Some devices may need to perform a reset before using the RNG, such as the BCM6368.
Signed-off-by Álvaro Fernández Rojas <[email protected]>---
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@@ -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_clk18>;
clock-names = "ipsec";Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml +2
-0+ + resets = <&periph_rst 4>;
Quoted 1 line
};
Regards,
Nicolas
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.
Signed-off-by Álvaro Fernández Rojas <[email protected]>---
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@@ -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
-0additionalProperties: falseI 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: + - resetsI 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
-0clocks = <&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
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.
Signed-off-by Álvaro Fernández Rojas <[email protected]>---
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@@ -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):
makedt_binding_checkDT_SCHEMA_FILES=Documentation/devicetree/bindings/rng/brcm,bcm2835.yamlQuoted 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: + - resetsI 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
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.
Signed-off-by Álvaro Fernández Rojas <[email protected]>---
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@@ -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
-0additionalProperties: falseI 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):
makedt_binding_checkDT_SCHEMA_FILES=Documentation/devicetree/bindings/rng/brcm,bcm2835.yamlQuoted 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: + - resetsI 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.
Re: [PATCH v3 1/2] dt-bindings: rng: bcm2835: document reset support
In reply to Nicolas Saenz JulienneQuoted 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.
Signed-off-by Álvaro Fernández Rojas <[email protected]>---
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@@ -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
-0additionalProperties: falseI 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: + - resetsI 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
PATCH v3 2/2 hwrng: bcm2835: add reset support
In reply to Álvaro Fernández RojasBCM6368 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
@@ -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
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 pipeSigned-off-by Álvaro Fernández Rojas <[email protected]>---
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@@ -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