mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hwrng: mtk - wait long enough for the next word
@ 2026-10-26 18:47 Ryan Brue
  2026-11-12  9:56 ` Herbert Xu
  2026-11-12 10:03 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Ryan Brue @ 2026-10-26 18:47 UTC (permalink / raw)
  To: Sean Wang, Olivia Mackall, Herbert Xu, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: linux-crypto, linux-kernel, linux-arm-kernel, linux-mediatek, Ryan Brue

mtk_rng_wait_ready() gives the generator 60 us to produce the next
32-bit word. On MT8695 it takes longer: timed over 1421 waits, the
median was 82 us, the 99th percentile 92 us and the longest 225 us. So
most waits time out. A read that fails on its first word returns -EIO,
which a read from /dev/hwrng after a short idle period does more often
than not, and longer reads come back short.

Raise the timeout to 1 ms. Generators that are faster still return as
soon as the word is ready. On MT8695, 20 reads after idle periods all
succeeded, and a 256 KiB read returned in full at the same 63 KB/s.

Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
---
Found while bringing up mainline on the Amazon Fire TV Stick (3rd
generation, MT8695), whose RNG uses the mediatek,mt7623-rng compatible.
The board's devicetree is not upstream yet. The timings were taken with
a temporary print in mtk_rng_wait_ready().
---
 drivers/char/hw_random/mtk-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/hw_random/mtk-rng.c b/drivers/char/hw_random/mtk-rng.c
index 1f9793010e6c..8e3c99e5db3b 100644
--- a/drivers/char/hw_random/mtk-rng.c
+++ b/drivers/char/hw_random/mtk-rng.c
@@ -25,7 +25,7 @@
 #define RNG_AUTOSUSPEND_TIMEOUT		100
 
 #define USEC_POLL			2
-#define TIMEOUT_POLL			60
+#define TIMEOUT_POLL			1000
 
 #define RNG_CTRL			0x00
 #define RNG_EN				BIT(0)

---
base-commit: 178aff4cf425b3fc51ff09c571fa1bfbc1eb8ea4
change-id: 20261021-rbrue-sheldon-upstreaming-mtk-rng-timeout-ef2b4d517bbe

Best regards,
-- 
Ryan Brue <ryanbrue.dev@gmail.com>


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

end of thread, other threads:[~2026-11-12 10:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-26 18:47 [PATCH] hwrng: mtk - wait long enough for the next word Ryan Brue
2026-11-12  9:56 ` Herbert Xu
2026-11-12 10:03 ` 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®