mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] hwrng: histb: fix the FIFO batch timeout
@ 2026-11-03  4:13 David Yang
  2026-11-03  4:13 ` [PATCH 1/2] hwrng: histb: wait for a batch of words David Yang
  2026-11-03  4:14 ` [PATCH 2/2] hwrng: histb: use device messages David Yang
  0 siblings, 2 replies; 3+ messages in thread
From: David Yang @ 2026-11-03  4:13 UTC (permalink / raw)
  To: linux-crypto
  Cc: David Yang, Olivia Mackall, Herbert Xu, Takashi Sakamoto,
	Danilo Krummrich, Uwe Kleine-König (The Capable Hub),
	Bjorn Helgaas, linux-kernel

The poll timeout in histb_rng_wait() was derived for a single word, while
the device feeds the FIFO in batches. Fix the timeout, and print with
dev_*() so that the messages name the device.

David Yang (2):
  hwrng: histb: wait for a batch of words
  hwrng: histb: use device messages

 drivers/char/hw_random/histb-rng.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

-- 
2.53.0


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

* [PATCH 1/2] hwrng: histb: wait for a batch of words
  2026-11-03  4:13 [PATCH 0/2] hwrng: histb: fix the FIFO batch timeout David Yang
@ 2026-11-03  4:13 ` David Yang
  2026-11-03  4:14 ` [PATCH 2/2] hwrng: histb: use device messages David Yang
  1 sibling, 0 replies; 3+ messages in thread
From: David Yang @ 2026-11-03  4:13 UTC (permalink / raw)
  To: linux-crypto
  Cc: David Yang, Olivia Mackall, Herbert Xu, Takashi Sakamoto,
	Danilo Krummrich, Uwe Kleine-König (The Capable Hub),
	Bjorn Helgaas, linux-kernel

The old figures were per-word, taken from a streaming average: ~16ms at
depth 255 is one word out of a batch every ~64ms, and ~1ms at depth 1 is
the 1ms poll granularity of the read path. The device fills the FIFO
with 4 words in one go, every ~200us per unit of post-process depth, so
at the depth of 144 this driver programs a batch lands every ~30ms and
an empty queue waits that long for a single word. The 30ms per-word
timeout falls inside that, so wait 500ms instead, which also covers the
restart after rewriting the control word.

Fixes: a2216e187471 ("crypto: hisilicon/trng - add support for HiSTB TRNG")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/char/hw_random/histb-rng.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/char/hw_random/histb-rng.c b/drivers/char/hw_random/histb-rng.c
index 445b80beed62..d435d4ab9aa7 100644
--- a/drivers/char/hw_random/histb-rng.c
+++ b/drivers/char/hw_random/histb-rng.c
@@ -26,16 +26,21 @@ struct histb_rng_priv {
 };
 
 /*
- * Observed:
- * depth = 1 -> ~1ms
- * depth = 255 -> ~16ms
+ * Observed: the FIFO fills with 4 words at a time, roughly every 200us per
+ * unit of post-process depth, i.e. one batch per:
+ * depth = 144 -> ~30ms
+ * depth = 255 -> ~52ms
+ * Rewriting the control word delays the first batch by up to 300ms.
  */
+#define BATCH_TIMEOUT_US	(500 * USEC_PER_MSEC)
+
 static int histb_rng_wait(void __iomem *base)
 {
 	u32 val;
 
 	return readl_relaxed_poll_timeout(base + RNG_STAT, val,
-					  val & DATA_COUNT, 1000, 30 * 1000);
+					  val & DATA_COUNT, 1000,
+					  BATCH_TIMEOUT_US);
 }
 
 static void histb_rng_init(void __iomem *base, unsigned int depth)
-- 
2.53.0


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

* [PATCH 2/2] hwrng: histb: use device messages
  2026-11-03  4:13 [PATCH 0/2] hwrng: histb: fix the FIFO batch timeout David Yang
  2026-11-03  4:13 ` [PATCH 1/2] hwrng: histb: wait for a batch of words David Yang
@ 2026-11-03  4:14 ` David Yang
  1 sibling, 0 replies; 3+ messages in thread
From: David Yang @ 2026-11-03  4:14 UTC (permalink / raw)
  To: linux-crypto
  Cc: David Yang, Olivia Mackall, Herbert Xu, Takashi Sakamoto,
	Danilo Krummrich, Uwe Kleine-König (The Capable Hub),
	Bjorn Helgaas, linux-kernel

pr_*() prints without saying which device the message came from. Print
with dev_*() instead and adjust error messages.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/char/hw_random/histb-rng.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/char/hw_random/histb-rng.c b/drivers/char/hw_random/histb-rng.c
index d435d4ab9aa7..d28cc84e8367 100644
--- a/drivers/char/hw_random/histb-rng.c
+++ b/drivers/char/hw_random/histb-rng.c
@@ -22,6 +22,7 @@
 
 struct histb_rng_priv {
 	struct hwrng rng;
+	struct device *dev;
 	void __iomem *base;
 };
 
@@ -71,8 +72,9 @@ static int histb_rng_read(struct hwrng *rng, void *data, size_t max, bool wait)
 			if (!wait)
 				return i;
 			if (histb_rng_wait(base)) {
-				pr_err("failed to generate random number, generated %d\n",
-				       i);
+				dev_err(priv->dev,
+					"RNG timeout, generated %d of %zu bytes\n",
+					i, max);
 				return i ? i : -ETIMEDOUT;
 			}
 		}
@@ -142,6 +144,7 @@ static int histb_rng_probe(struct platform_device *pdev)
 	}
 
 	priv->base = base;
+	priv->dev = dev;
 	priv->rng.name = pdev->name;
 	priv->rng.read = histb_rng_read;
 	ret = devm_hwrng_register(dev, &priv->rng);
-- 
2.53.0


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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03  4:13 [PATCH 0/2] hwrng: histb: fix the FIFO batch timeout David Yang
2026-11-03  4:13 ` [PATCH 1/2] hwrng: histb: wait for a batch of words David Yang
2026-11-03  4:14 ` [PATCH 2/2] hwrng: histb: use device messages David Yang

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®