Skip to contentSkip to conversation

hwrng: mtk - wait long enough for the next word

PATCH New Ryan Brue 1 participant 1 message Oct 26

Subsystems (4)
lore
Share & tools
lore

Ryan Brue

author
#0 lore raw

PATCH 1/1 hwrng: mtk - wait long enough for the next word

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.

---
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(-)
drivers/char/hw_random/mtk-rng.c +1 -1
index 1f9793010e6c..8e3c99e5db3b 100644
@@ -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,

Signature · 1 line
Ryan Brue <[email protected]>