From: Romain Perier <romain.perier@free-electrons.com>
To: dsaxena@plexity.net, mpm@selenic.com,
Herbert Xu <herbert@gondor.apana.org.au>
Cc: Gregory Clement <gregory.clement@free-electrons.com>,
Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
Romain Perier <romain.perier@free-electrons.com>,
Nadav Haklai <nadavh@marvell.com>, Omri Itach <omrii@marvell.com>,
Shadi Ammouri <shadi@marvell.com>,
Yahuda Yitschak <yehuday@marvell.com>,
Hanna Hawa <hannah@marvell.com>,
Neta Zur Hershkovits <neta@marvell.com>,
Igal Liberman <igall@marvell.com>,
Marcin Wojtas <mw@semihalf.com>,
linux-crypto@vger.kernel.org
Subject: [PATCH v2 3/8] hwrng: omap - Switch to non-obsolete read API implementation
Date: Wed, 7 Sep 2016 17:57:38 +0200 [thread overview]
Message-ID: <20160907155743.6403-4-romain.perier@free-electrons.com> (raw)
In-Reply-To: <20160907155743.6403-1-romain.perier@free-electrons.com>
The ".data_present" and ".data_read" operations are marked as
OBSOLETE in the hwrng API. We have to use the ".read" operation instead.
It makes the driver simpler and removes the need to do a busy loop to
wait until enough data is generated by the IP. We simplify this step by
only checking the status of the engine, if there is data, we copy the
data to the output buffer and the amout of copied data is returned to the
caller, otherwise zero is returned. The hwrng core will re-call the read
operation as many times as required until enough data has been copied.
Signed-off-by: Romain Perier <romain.perier@free-electrons.com>
---
drivers/char/hw_random/omap-rng.c | 39 ++++++++++++---------------------------
1 file changed, 12 insertions(+), 27 deletions(-)
diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
index 01d4be2..d47b24d 100644
--- a/drivers/char/hw_random/omap-rng.c
+++ b/drivers/char/hw_random/omap-rng.c
@@ -140,41 +140,27 @@ static inline void omap_rng_write(struct omap_rng_dev *priv, u16 reg,
__raw_writel(val, priv->base + priv->pdata->regs[reg]);
}
-static int omap_rng_data_present(struct hwrng *rng, int wait)
+
+static int omap_rng_do_read(struct hwrng *rng, void *data, size_t max,
+ bool wait)
{
struct omap_rng_dev *priv;
- int data, i;
priv = (struct omap_rng_dev *)rng->priv;
- for (i = 0; i < 20; i++) {
- data = priv->pdata->data_present(priv);
- if (data || !wait)
- break;
- /* RNG produces data fast enough (2+ MBit/sec, even
- * during "rngtest" loads, that these delays don't
- * seem to trigger. We *could* use the RNG IRQ, but
- * that'd be higher overhead ... so why bother?
- */
- udelay(10);
- }
- return data;
-}
-
-static int omap_rng_data_read(struct hwrng *rng, u32 *data)
-{
- struct omap_rng_dev *priv;
- u32 data_size, i;
+ if (max < priv->pdata->data_size)
+ return 0;
- priv = (struct omap_rng_dev *)rng->priv;
- data_size = priv->pdata->data_size;
+ if (!priv->pdata->data_present(priv))
+ return 0;
- for (i = 0; i < data_size / sizeof(u32); i++)
- data[i] = omap_rng_read(priv, RNG_OUTPUT_L_REG + i);
+ memcpy_fromio(data, priv->base + priv->pdata->regs[RNG_OUTPUT_L_REG],
+ priv->pdata->data_size);
if (priv->pdata->regs[RNG_INTACK_REG])
omap_rng_write(priv, RNG_INTACK_REG, RNG_REG_INTACK_RDY_MASK);
- return data_size;
+
+ return priv->pdata->data_size;
}
static int omap_rng_init(struct hwrng *rng)
@@ -195,8 +181,7 @@ static void omap_rng_cleanup(struct hwrng *rng)
static struct hwrng omap_rng_ops = {
.name = "omap",
- .data_present = omap_rng_data_present,
- .data_read = omap_rng_data_read,
+ .read = omap_rng_do_read,
.init = omap_rng_init,
.cleanup = omap_rng_cleanup,
};
--
2.9.3
next prev parent reply other threads:[~2016-09-07 15:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-07 15:57 [PATCH v2 0/8] Add support for SafeXcel IP-76 to OMAP RNG Romain Perier
2016-09-07 15:57 ` [PATCH v2 1/8] dt-bindings: Add vendor prefix for INSIDE Secure Romain Perier
2016-09-07 15:57 ` [PATCH v2 2/8] dt-bindings: omap-rng: Document SafeXcel IP-76 device variant Romain Perier
2016-09-07 15:57 ` Romain Perier [this message]
2016-09-13 9:48 ` [PATCH v2 3/8] hwrng: omap - Switch to non-obsolete read API implementation Herbert Xu
2016-09-16 10:11 ` Romain Perier
2016-09-07 15:57 ` [PATCH v2 4/8] hwrng: omap - Remove global definition of hwrng Romain Perier
2016-09-07 15:57 ` [PATCH v2 5/8] hwrng: omap - Add support for 128-bit output of data Romain Perier
2016-09-07 15:57 ` [PATCH v2 6/8] hwrng: omap - Don't prefix the probe message with OMAP Romain Perier
2016-09-07 15:57 ` [PATCH v2 7/8] hwrng: omap - Add device variant for SafeXcel IP-76 found in Armada 8K Romain Perier
2016-09-07 15:57 ` [PATCH v2 8/8] arm64: dts: marvell: add TRNG description for Armada 8K CP Romain Perier
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=20160907155743.6403-4-romain.perier@free-electrons.com \
--to=romain.perier@free-electrons.com \
--cc=dsaxena@plexity.net \
--cc=gregory.clement@free-electrons.com \
--cc=hannah@marvell.com \
--cc=herbert@gondor.apana.org.au \
--cc=igall@marvell.com \
--cc=linux-crypto@vger.kernel.org \
--cc=mpm@selenic.com \
--cc=mw@semihalf.com \
--cc=nadavh@marvell.com \
--cc=neta@marvell.com \
--cc=omrii@marvell.com \
--cc=shadi@marvell.com \
--cc=thomas.petazzoni@free-electrons.com \
--cc=yehuday@marvell.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: 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