mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] hwrng: imx-rngc - adjust the timeouts
@ 2023-09-12 14:31 Martin Kaiser
  2023-09-12 14:31 ` [PATCH 1/2] hwrng: imx-rngc - reasonable timeout for selftest Martin Kaiser
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Martin Kaiser @ 2023-09-12 14:31 UTC (permalink / raw)
  To: Herbert Xu; +Cc: linux-crypto, linux-arm-kernel, linux-kernel, 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(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] hwrng: imx-rngc - reasonable timeout for selftest
  2023-09-12 14:31 [PATCH 0/2] hwrng: imx-rngc - adjust the timeouts Martin Kaiser
@ 2023-09-12 14:31 ` Martin Kaiser
  2023-09-12 14:31 ` [PATCH 2/2] hwrng: imx-rngc - reasonable timeout for initial seed Martin Kaiser
  2023-09-20  5:20 ` [PATCH 0/2] hwrng: imx-rngc - adjust the timeouts Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Martin Kaiser @ 2023-09-12 14:31 UTC (permalink / raw)
  To: Herbert Xu; +Cc: linux-crypto, linux-arm-kernel, linux-kernel, Martin Kaiser

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.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/char/hw_random/imx-rngc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
index e4b385b01b11..127c292dfbbf 100644
--- a/drivers/char/hw_random/imx-rngc.c
+++ b/drivers/char/hw_random/imx-rngc.c
@@ -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;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] hwrng: imx-rngc - reasonable timeout for initial seed
  2023-09-12 14:31 [PATCH 0/2] hwrng: imx-rngc - adjust the timeouts Martin Kaiser
  2023-09-12 14:31 ` [PATCH 1/2] hwrng: imx-rngc - reasonable timeout for selftest Martin Kaiser
@ 2023-09-12 14:31 ` Martin Kaiser
  2023-09-20  5:20 ` [PATCH 0/2] hwrng: imx-rngc - adjust the timeouts Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Martin Kaiser @ 2023-09-12 14:31 UTC (permalink / raw)
  To: Herbert Xu; +Cc: linux-crypto, linux-arm-kernel, linux-kernel, 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.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/char/hw_random/imx-rngc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
index 127c292dfbbf..118a72acb99b 100644
--- a/drivers/char/hw_random/imx-rngc.c
+++ b/drivers/char/hw_random/imx-rngc.c
@@ -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;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] hwrng: imx-rngc - adjust the timeouts
  2023-09-12 14:31 [PATCH 0/2] hwrng: imx-rngc - adjust the timeouts Martin Kaiser
  2023-09-12 14:31 ` [PATCH 1/2] hwrng: imx-rngc - reasonable timeout for selftest Martin Kaiser
  2023-09-12 14:31 ` [PATCH 2/2] hwrng: imx-rngc - reasonable timeout for initial seed Martin Kaiser
@ 2023-09-20  5:20 ` Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2023-09-20  5:20 UTC (permalink / raw)
  To: Martin Kaiser; +Cc: linux-crypto, linux-arm-kernel, linux-kernel

On Tue, Sep 12, 2023 at 04:31:16PM +0200, Martin Kaiser wrote:
> 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(-)
> 
> -- 
> 2.39.2

All applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-20  5:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-12 14:31 [PATCH 0/2] hwrng: imx-rngc - adjust the timeouts Martin Kaiser
2023-09-12 14:31 ` [PATCH 1/2] hwrng: imx-rngc - reasonable timeout for selftest Martin Kaiser
2023-09-12 14:31 ` [PATCH 2/2] hwrng: imx-rngc - reasonable timeout for initial seed Martin Kaiser
2023-09-20  5:20 ` [PATCH 0/2] hwrng: imx-rngc - adjust the timeouts Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®