Re: [PATCH v1 1/3] drivers: rng: add check status bit feature

From: Martin Kaiser
Date: Wed Jul 26 2023 - 07:54:52 EST


Hi Alexey,

Alexey Romanov (AVRomanov@xxxxxxxxxxxxxx) wrote:

> > > +static int meson_rng_wait_status(void __iomem *cfg_addr, int bit)
> > > +{
> > > + u32 status;
> > > + u32 cnt = 0;
> > > +
> > > + do {
> > > + status = readl_relaxed(cfg_addr) & BIT(bit);
> > > + cpu_relax();
> > > + } while (status && (cnt++ < RETRY_CNT));
> > > +

> > Could you use readl_relaxed_poll_timeout here instead of open coding the
> > loop?

> At first I also thought about this API. But later I came to the
> conclusion that it is inappropriate here:

> 1. We can't call rng_read from an atomic context.

Agreed. A hwrng read function may sleep (an example for this is
exynos_trng_do_read). But this doesn't prevent us from using
readl_relaxed_poll_timeout.

> 2. RNG for me looks like a very lightweight primitive to me that
> should work quiclky.

> But, now I looked again at the API and realized that we can use
> readl_relaxed_poll_timeout_atomic() instead of
> readl_relaxed_poll_timeout(). What do you think?

Ok, if you know that your rng hardware won't need much time to set the
bit that you're checking, you may use readl_relaxed_poll_timeout_atomic.

stm32_rtc_set_alarm does something similar.

Best regards,
Martin