aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÁlvaro Fernández Rojas <noltari@gmail.com>2021-02-22 21:34:39 +0100
committerÁlvaro Fernández Rojas <noltari@gmail.com>2021-02-22 21:37:56 +0100
commit626add3394f8ce3cfcb36a1afef25815e541ce46 (patch)
tree9a4108454ab4789815e3a041f88c3adc92983ae1
parent567a88e4b99f9e1b647588de0319357e688ce016 (diff)
downloadupstream-626add3394f8ce3cfcb36a1afef25815e541ce46.tar.gz
upstream-626add3394f8ce3cfcb36a1afef25815e541ce46.tar.bz2
upstream-626add3394f8ce3cfcb36a1afef25815e541ce46.zip
bmips: bcm6368: fix bcm2835-rng
IPSEC needs a reset before using its HW RNG. Otherwise, the numbers generated won't be random at all. Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
-rw-r--r--target/linux/bmips/dts/bcm6368.dtsi2
-rw-r--r--target/linux/bmips/patches-5.10/207-hwrng-bcm2835-add-reset-support.patch74
2 files changed, 76 insertions, 0 deletions
diff --git a/target/linux/bmips/dts/bcm6368.dtsi b/target/linux/bmips/dts/bcm6368.dtsi
index e428a214ee..babd8c7385 100644
--- a/target/linux/bmips/dts/bcm6368.dtsi
+++ b/target/linux/bmips/dts/bcm6368.dtsi
@@ -460,6 +460,8 @@
clocks = <&periph_clk BCM6368_CLK_IPSEC>;
clock-names = "ipsec";
+
+ resets = <&periph_rst BCM6368_RST_IPSEC>;
};
};
diff --git a/target/linux/bmips/patches-5.10/207-hwrng-bcm2835-add-reset-support.patch b/target/linux/bmips/patches-5.10/207-hwrng-bcm2835-add-reset-support.patch
new file mode 100644
index 0000000000..1da0e952a8
--- /dev/null
+++ b/target/linux/bmips/patches-5.10/207-hwrng-bcm2835-add-reset-support.patch
@@ -0,0 +1,74 @@
+From 846cd2c9eee7a99de29c743911cc047fdd56db02 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= <noltari@gmail.com>
+Date: Mon, 22 Feb 2021 20:41:04 +0100
+Subject: [PATCH] hwrng: bcm2835: add reset support
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+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
+
+Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
+---
+ drivers/char/hw_random/bcm2835-rng.c | 10 ++++++++++
+ 1 file changed, 10 insertions(+)
+
+--- 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
+ 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 plat
+ 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;