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(+)
--
2.20.1
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
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
---
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 1a7c43b43c6b..1b93a896d8e8 100644
--- a/drivers/char/hw_random/bcm2835-rng.c
+++ b/drivers/char/hw_random/bcm2835-rng.c
@@ -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;
--
2.20.1
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]>
---
v2: document reset support.
Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml b/Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml
index c147900f9041..dba70764b7d0 100644
--- a/Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml
+++ b/Documentation/devicetree/bindings/rng/brcm,bcm2835.yaml
@@ -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>;
};
--
2.20.1
On 2/23/2021 8:01 AM, Álvaro Fernández Rojas wrote:
> 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.
--
Florian
On 2021-02-23 8:36 a.m., Florian Fainelli wrote:
>
>
> On 2/23/2021 8:01 AM, Álvaro Fernández Rojas wrote:
>> 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?
Hello Scott,
El 23/02/2021 a las 18:17, Scott Branden escribió:
> On 2021-02-23 8:36 a.m., Florian Fainelli wrote:
>>
>>
>> On 2/23/2021 8:01 AM, Álvaro Fernández Rojas wrote:
>>> 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?
>
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.
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(+)
--
2.20.1
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
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
---
v4: add reset_control_rearm().
v3: no changes.
v2: no changes.
drivers/char/hw_random/bcm2835-rng.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c
index 1a7c43b43c6b..92658edaff22 100644
--- a/drivers/char/hw_random/bcm2835-rng.c
+++ b/drivers/char/hw_random/bcm2835-rng.c
@@ -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;
--
2.20.1
Hi Álvaro,
On Wed, 2021-02-24 at 09:22 +0100, Álvaro Fernández Rojas wrote:
[...]
> @@ -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;
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
Hi Philipp,
> El 3 mar 2021, a las 14:52, Philipp Zabel <[email protected]> escribió:
>
> Hi Álvaro,
>
> On Wed, 2021-02-24 at 09:22 +0100, Álvaro Fernández Rojas wrote:
> [...]
>> @@ -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;
>
> 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...
>
> regards
> Philipp
Best regards,
Álvaro.