Skip to contentSkip to conversation

hwrng: imx-rngc - adjust the timeouts

PATCH In review Martin Kaiser 2 participants 4 messages Sep 12, 2023 – Sep 20, 2023

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

cover hwrng: imx-rngc - adjust the timeouts

Set the timeouts for selftest and initial seed to approx. three times the maximum possible duration.

This replaces the series "hwrng: imx-rngc - use polling instead of interrupt".

Martin Kaiser (2):
hwrng: imx-rngc - reasonable timeout for selftest
hwrng: imx-rngc - reasonable timeout for initial seed

 drivers/char/hw_random/imx-rngc.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/2 hwrng: imx-rngc - reasonable timeout for selftest

Set a more reasonable timeout for the rngc selftest.

According to the reference manual, "The self test takes approximately 29,000 cycles to complete." The lowest possible frequency of the rngc peripheral clock is 33.25MHz, the selftest would then take about 872us.

2.5ms should be enough for the selftest timeout.

---
 drivers/char/hw_random/imx-rngc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/hw_random/imx-rngc.c +3 -1
index e4b385b01b11..127c292dfbbf 100644
@@ -53,6 +53,7 @@
 
 #define RNGC_TIMEOUT  3000 /* 3 sec */
 
+#define RNGC_SELFTEST_TIMEOUT 2500 /* us */
 
 static bool self_test = true;
 module_param(self_test, bool, 0);
@@ -110,7 +111,8 @@ static int imx_rngc_self_test(struct imx_rngc *rngc)
 	cmd = readl(rngc->base + RNGC_COMMAND);
 	writel(cmd | RNGC_CMD_SELF_TEST, rngc->base + RNGC_COMMAND);
 
-	ret = wait_for_completion_timeout(&rngc->rng_op_done, msecs_to_jiffies(RNGC_TIMEOUT));
+	ret = wait_for_completion_timeout(&rngc->rng_op_done,
+					  usecs_to_jiffies(RNGC_SELFTEST_TIMEOUT));
 	imx_rngc_irq_mask_clear(rngc);
 	if (!ret)
 		return -ETIMEDOUT;
Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/2 hwrng: imx-rngc - reasonable timeout for initial seed

In reply to Martin Kaiser

Set a more reasonable timeout for calculating the initial seed.

The reference manuals says that "The initial seed takes approximately 2,000,000 clock cycles." The rngc peripheral clock runs at >= 33.25MHz, so seeding takes at most 60ms.

A timeout of 200ms is more appropriate than the current value of 3 seconds.

---
 drivers/char/hw_random/imx-rngc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/hw_random/imx-rngc.c +3 -3
index 127c292dfbbf..118a72acb99b 100644
@@ -51,9 +51,8 @@
 
 #define RNGC_ERROR_STATUS_STAT_ERR	0x00000008
 
-#define RNGC_TIMEOUT  3000 /* 3 sec */
-
 #define RNGC_SELFTEST_TIMEOUT 2500 /* us */
+#define RNGC_SEED_TIMEOUT      200 /* ms */
 
 static bool self_test = true;
 module_param(self_test, bool, 0);
@@ -184,7 +183,8 @@ static int imx_rngc_init(struct hwrng *rng)
 		cmd = readl(rngc->base + RNGC_COMMAND);
 		writel(cmd | RNGC_CMD_SEED, rngc->base + RNGC_COMMAND);
 
-		ret = wait_for_completion_timeout(&rngc->rng_op_done, msecs_to_jiffies(RNGC_TIMEOUT));
+		ret = wait_for_completion_timeout(&rngc->rng_op_done,
+						  msecs_to_jiffies(RNGC_SEED_TIMEOUT));
 		if (!ret) {
 			ret = -ETIMEDOUT;
 			goto err;
Signature · 1 line
2.39.2
maintainer
#3 lore raw
In reply to Martin Kaiser
Quoted 14 lines · Martin Kaiser

Set the timeouts for selftest and initial seed to approx. three times the maximum possible duration.

This replaces the series "hwrng: imx-rngc - use polling instead of interrupt".

Martin Kaiser (2):
hwrng: imx-rngc - reasonable timeout for selftest
hwrng: imx-rngc - reasonable timeout for initial seed

 drivers/char/hw_random/imx-rngc.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.39.2

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