From: Herbert Xu <herbert@gondor.apana.org.au>
To: Jia Jie Ho <jiajie.ho@starfivetech.com>
Cc: Olivia Mackall <olivia@selenic.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Emil Renner Berthing <kernel@esmil.dk>,
Conor Dooley <conor.dooley@microchip.com>,
linux-crypto@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org
Subject: Re: [PATCH v2 2/3] hwrng: starfive - Add TRNG driver for StarFive SoC
Date: Fri, 6 Jan 2023 16:39:24 +0800 [thread overview]
Message-ID: <Y7fePDme5E3yhPhQ@gondor.apana.org.au> (raw)
In-Reply-To: <20221228071103.91797-3-jiajie.ho@starfivetech.com>
On Wed, Dec 28, 2022 at 03:11:02PM +0800, Jia Jie Ho wrote:
>
> +static int starfive_trng_cmd(struct starfive_trng *trng, u32 cmd)
> +{
> + int ret;
> +
> + ret = starfive_trng_wait_idle(trng);
> + if (ret)
> + return -ETIMEDOUT;
> +
> + switch (cmd) {
> + case STARFIVE_CTRL_EXEC_NOP:
> + writel(cmd, trng->base + STARFIVE_CTRL);
> + break;
> + case STARFIVE_CTRL_GENE_RANDNUM:
> + reinit_completion(&trng->random_done);
> + writel(cmd, trng->base + STARFIVE_CTRL);
> + ret = wait_for_completion_timeout(&trng->random_done, 3000);
Please don't use a constant jiffies value, because it may vary
in length. Instead use a constant millisecond value and convert
it to jiffies.
> +static irqreturn_t starfive_trng_irq(int irq, void *priv)
> +{
> + u32 status;
> + struct starfive_trng *trng = (struct starfive_trng *)priv;
> +
> + status = readl(trng->base + STARFIVE_ISTAT);
> + if (status & STARFIVE_ISTAT_RAND_RDY) {
> + writel(STARFIVE_ISTAT_RAND_RDY, trng->base + STARFIVE_ISTAT);
> + complete(&trng->random_done);
> + }
> +
> + if (status & STARFIVE_ISTAT_SEED_DONE) {
> + writel(STARFIVE_ISTAT_SEED_DONE, trng->base + STARFIVE_ISTAT);
> + complete(&trng->reseed_done);
> + }
> +
> + if (status & STARFIVE_ISTAT_LFSR_LOCKUP) {
> + writel(STARFIVE_ISTAT_LFSR_LOCKUP, trng->base + STARFIVE_ISTAT);
> + starfive_trng_cmd(trng, STARFIVE_CTRL_EXEC_RANDRESEED);
You should not sleep in an IRQ handler.
> +static int starfive_trng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
You should respect the wait argument and not do polling/sleeping
if it is false.
Cheers,
--
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
next prev parent reply other threads:[~2023-01-06 8:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-28 7:11 [PATCH v2 0/3] hwrng: starfive - Add driver for TRNG module Jia Jie Ho
2022-12-28 7:11 ` [PATCH v2 1/3] dt-bindings: rng: Add StarFive " Jia Jie Ho
2022-12-28 7:11 ` [PATCH v2 2/3] hwrng: starfive - Add TRNG driver for StarFive SoC Jia Jie Ho
2023-01-06 8:39 ` Herbert Xu [this message]
2023-01-08 14:13 ` JiaJie Ho
2023-01-09 2:58 ` JiaJie Ho
2023-01-09 3:03 ` Herbert Xu
2023-01-09 3:41 ` JiaJie Ho
2023-01-09 4:00 ` Herbert Xu
2023-01-09 4:33 ` JiaJie Ho
2022-12-28 7:11 ` [PATCH v2 3/3] riscv: dts: starfive: Add TRNG node for VisionFive 2 Jia Jie Ho
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y7fePDme5E3yhPhQ@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=conor.dooley@microchip.com \
--cc=devicetree@vger.kernel.org \
--cc=jiajie.ho@starfivetech.com \
--cc=kernel@esmil.dk \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=olivia@selenic.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).