From: Martin Kaiser <martin@kaiser.cx> To: Herbert Xu <herbert@gondor.apana.org.au>, PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>, NXP Linux Team <linux-imx@nxp.com> Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser <martin@kaiser.cx> Subject: [PATCH 2/6] hwrng: imx-rngc - use automatic seeding Date: Tue, 28 Jan 2020 12:00:58 +0100 [thread overview] Message-ID: <20200128110102.11522-3-martin@kaiser.cx> (raw) In-Reply-To: <20200128110102.11522-1-martin@kaiser.cx> The rngc requires a new seed for its prng after generating 2^20 160-bit words of random data. At the moment, we seed the prng only once during initalisation. Set the rngc to auto seed mode so that it kicks off the internal reseeding operation when a new seed is required. Keep the manual calculation of the initial seed when the device is probed and switch to automatic seeding afterwards. Signed-off-by: Martin Kaiser <martin@kaiser.cx> --- drivers/char/hw_random/imx-rngc.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c index 0576801944fd..903894518c8d 100644 --- a/drivers/char/hw_random/imx-rngc.c +++ b/drivers/char/hw_random/imx-rngc.c @@ -31,6 +31,7 @@ #define RNGC_CTRL_MASK_ERROR 0x00000040 #define RNGC_CTRL_MASK_DONE 0x00000020 +#define RNGC_CTRL_AUTO_SEED 0x00000010 #define RNGC_STATUS_ERROR 0x00010000 #define RNGC_STATUS_FIFO_LEVEL_MASK 0x00000f00 @@ -167,7 +168,7 @@ static irqreturn_t imx_rngc_irq(int irq, void *priv) static int imx_rngc_init(struct hwrng *rng) { struct imx_rngc *rngc = container_of(rng, struct imx_rngc, rng); - u32 cmd; + u32 cmd, ctrl; int ret; /* clear error */ @@ -192,7 +193,18 @@ static int imx_rngc_init(struct hwrng *rng) } while (rngc->err_reg == RNGC_ERROR_STATUS_STAT_ERR); - return rngc->err_reg ? -EIO : 0; + if (rngc->err_reg) + return -EIO; + + /* + * enable automatic seeding, the rngc creates a new seed automatically + * after serving 2^20 random 160-bit words + */ + ctrl = readl(rngc->base + RNGC_CONTROL); + ctrl |= RNGC_CTRL_AUTO_SEED; + writel(ctrl, rngc->base + RNGC_CONTROL); + + return 0; } static int imx_rngc_probe(struct platform_device *pdev) -- 2.20.1
WARNING: multiple messages have this Message-ID (diff)
From: Martin Kaiser <martin@kaiser.cx> To: Herbert Xu <herbert@gondor.apana.org.au>, PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>, NXP Linux Team <linux-imx@nxp.com> Cc: Martin Kaiser <martin@kaiser.cx>, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/6] hwrng: imx-rngc - use automatic seeding Date: Tue, 28 Jan 2020 12:00:58 +0100 [thread overview] Message-ID: <20200128110102.11522-3-martin@kaiser.cx> (raw) In-Reply-To: <20200128110102.11522-1-martin@kaiser.cx> The rngc requires a new seed for its prng after generating 2^20 160-bit words of random data. At the moment, we seed the prng only once during initalisation. Set the rngc to auto seed mode so that it kicks off the internal reseeding operation when a new seed is required. Keep the manual calculation of the initial seed when the device is probed and switch to automatic seeding afterwards. Signed-off-by: Martin Kaiser <martin@kaiser.cx> --- drivers/char/hw_random/imx-rngc.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c index 0576801944fd..903894518c8d 100644 --- a/drivers/char/hw_random/imx-rngc.c +++ b/drivers/char/hw_random/imx-rngc.c @@ -31,6 +31,7 @@ #define RNGC_CTRL_MASK_ERROR 0x00000040 #define RNGC_CTRL_MASK_DONE 0x00000020 +#define RNGC_CTRL_AUTO_SEED 0x00000010 #define RNGC_STATUS_ERROR 0x00010000 #define RNGC_STATUS_FIFO_LEVEL_MASK 0x00000f00 @@ -167,7 +168,7 @@ static irqreturn_t imx_rngc_irq(int irq, void *priv) static int imx_rngc_init(struct hwrng *rng) { struct imx_rngc *rngc = container_of(rng, struct imx_rngc, rng); - u32 cmd; + u32 cmd, ctrl; int ret; /* clear error */ @@ -192,7 +193,18 @@ static int imx_rngc_init(struct hwrng *rng) } while (rngc->err_reg == RNGC_ERROR_STATUS_STAT_ERR); - return rngc->err_reg ? -EIO : 0; + if (rngc->err_reg) + return -EIO; + + /* + * enable automatic seeding, the rngc creates a new seed automatically + * after serving 2^20 random 160-bit words + */ + ctrl = readl(rngc->base + RNGC_CONTROL); + ctrl |= RNGC_CTRL_AUTO_SEED; + writel(ctrl, rngc->base + RNGC_CONTROL); + + return 0; } static int imx_rngc_probe(struct platform_device *pdev) -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-01-28 11:43 UTC|newest] Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-01-28 11:00 [PATCH 0/6] imx-rngc - several small fixes Martin Kaiser 2020-01-28 11:00 ` Martin Kaiser 2020-01-28 11:00 ` [PATCH 1/6] hwrng: imx-rngc - fix an error path Martin Kaiser 2020-01-28 11:00 ` Martin Kaiser 2020-02-12 16:22 ` PrasannaKumar Muralidharan 2020-02-12 16:22 ` PrasannaKumar Muralidharan 2020-01-28 11:00 ` Martin Kaiser [this message] 2020-01-28 11:00 ` [PATCH 2/6] hwrng: imx-rngc - use automatic seeding Martin Kaiser 2020-02-12 16:24 ` PrasannaKumar Muralidharan 2020-02-12 16:24 ` PrasannaKumar Muralidharan 2020-01-28 11:00 ` [PATCH 3/6] hwrng: imx-rngc - use devres for registration Martin Kaiser 2020-01-28 11:00 ` Martin Kaiser 2020-02-12 16:13 ` PrasannaKumar Muralidharan 2020-02-12 16:13 ` PrasannaKumar Muralidharan 2020-02-17 9:35 ` Martin Kaiser 2020-02-17 9:35 ` Martin Kaiser 2020-01-28 11:01 ` [PATCH 4/6] hwrng: imx-rngc - (trivial) simplify error prints Martin Kaiser 2020-01-28 11:01 ` Martin Kaiser 2020-02-12 16:24 ` PrasannaKumar Muralidharan 2020-02-12 16:24 ` PrasannaKumar Muralidharan 2020-01-28 11:01 ` [PATCH 5/6] hwrng: imx-rngc - check the rng type Martin Kaiser 2020-01-28 11:01 ` Martin Kaiser 2020-02-12 16:23 ` PrasannaKumar Muralidharan 2020-02-12 16:23 ` PrasannaKumar Muralidharan 2020-01-28 11:01 ` [PATCH 6/6] hwrng: imx-rngc - simplify interrupt mask/unmask Martin Kaiser 2020-01-28 11:01 ` Martin Kaiser 2020-03-05 20:58 ` [PATCH v2 0/5] imx-rngc - several small fixes Martin Kaiser 2020-03-05 20:58 ` Martin Kaiser 2020-03-05 20:58 ` [PATCH v2 1/5] hwrng: imx-rngc - fix an error path Martin Kaiser 2020-03-05 20:58 ` Martin Kaiser 2020-03-05 20:58 ` [PATCH v2 2/5] hwrng: imx-rngc - use automatic seeding Martin Kaiser 2020-03-05 20:58 ` Martin Kaiser 2020-03-05 20:58 ` [PATCH v2 3/5] hwrng: imx-rngc - (trivial) simplify error prints Martin Kaiser 2020-03-05 20:58 ` Martin Kaiser 2020-03-05 20:58 ` [PATCH v2 4/5] hwrng: imx-rngc - check the rng type Martin Kaiser 2020-03-05 20:58 ` Martin Kaiser 2020-03-05 20:58 ` [PATCH v2 5/5] hwrng: imx-rngc - simplify interrupt mask/unmask Martin Kaiser 2020-03-05 20:58 ` Martin Kaiser 2020-03-12 12:39 ` [PATCH v2 0/5] imx-rngc - several small fixes Herbert Xu 2020-03-12 12:39 ` Herbert Xu
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=20200128110102.11522-3-martin@kaiser.cx \ --to=martin@kaiser.cx \ --cc=herbert@gondor.apana.org.au \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-crypto@vger.kernel.org \ --cc=linux-imx@nxp.com \ --cc=linux-kernel@vger.kernel.org \ --cc=prasannatsmkumar@gmail.com \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.