linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i.MX31: mxc-rnga: implement waiting for data in driver
@ 2012-02-21 12:13 Michael Thalmeier
  2012-02-21 13:29 ` Fabio Estevam
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Thalmeier @ 2012-02-21 12:13 UTC (permalink / raw)
  To: Matt Mackall, Sascha Hauer
  Cc: michael, Michael Thalmeier, linux-kernel, linux-arm-kernel

mxc_rnga_data_present dit not use the wait parameter which caused a build
warning about initialization from incompatible pointer type.

Apart from this warning it is cleaner to implement the interface as intendet
and wait in the driver until data is available or a timeout has occured.

Signed-off-by: Michael Thalmeier <michael.thalmeier@hale.at>
---
 drivers/char/hw_random/mxc-rnga.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/char/hw_random/mxc-rnga.c b/drivers/char/hw_random/mxc-rnga.c
index 187c6be..39fb446 100644
--- a/drivers/char/hw_random/mxc-rnga.c
+++ b/drivers/char/hw_random/mxc-rnga.c
@@ -25,6 +25,7 @@
 #include <linux/platform_device.h>
 #include <linux/hw_random.h>
 #include <linux/io.h>
+#include <linux/delay.h>
 
 /* RNGA Registers */
 #define RNGA_CONTROL			0x00
@@ -60,14 +61,19 @@
 
 static struct platform_device *rng_dev;
 
-static int mxc_rnga_data_present(struct hwrng *rng)
+static int mxc_rnga_data_present(struct hwrng *rng, int wait)
 {
-	int level;
+	int level, i;
 	void __iomem *rng_base = (void __iomem *)rng->priv;
 
-	/* how many random numbers is in FIFO? [0-16] */
-	level = ((__raw_readl(rng_base + RNGA_STATUS) &
-			RNGA_STATUS_LEVEL_MASK) >> 8);
+	for (i = 0; i < 20; i++) {
+		/* how many random numbers is in FIFO? [0-16] */
+		level = ((__raw_readl(rng_base + RNGA_STATUS) &
+				RNGA_STATUS_LEVEL_MASK) >> 8);
+		if (level || !wait)
+			break;
+		udelay(10);
+	}
 
 	return level > 0 ? 1 : 0;
 }
-- 
1.7.7.6



--
Scanned by MailScanner.


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

* Re: [PATCH] i.MX31: mxc-rnga: implement waiting for data in driver
  2012-02-21 12:13 [PATCH] i.MX31: mxc-rnga: implement waiting for data in driver Michael Thalmeier
@ 2012-02-21 13:29 ` Fabio Estevam
  2012-02-21 14:39   ` Michael Thalmeier
  0 siblings, 1 reply; 4+ messages in thread
From: Fabio Estevam @ 2012-02-21 13:29 UTC (permalink / raw)
  To: Michael Thalmeier
  Cc: Matt Mackall, Sascha Hauer, linux-arm-kernel, michael, linux-kernel

On Tue, Feb 21, 2012 at 10:13 AM, Michael Thalmeier
<michael.thalmeier@hale.at> wrote:

> -static int mxc_rnga_data_present(struct hwrng *rng)
> +static int mxc_rnga_data_present(struct hwrng *rng, int wait)

This looks good, but ...

>  {
> -       int level;
> +       int level, i;
>        void __iomem *rng_base = (void __iomem *)rng->priv;
>
> -       /* how many random numbers is in FIFO? [0-16] */
> -       level = ((__raw_readl(rng_base + RNGA_STATUS) &
> -                       RNGA_STATUS_LEVEL_MASK) >> 8);
> +       for (i = 0; i < 20; i++) {

Why the magic "20" here?

It would be better to add a proper timeout mechanism instead, such as
time_after(jiffies, timeout)

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

* Re: [PATCH] i.MX31: mxc-rnga: implement waiting for data in driver
  2012-02-21 13:29 ` Fabio Estevam
@ 2012-02-21 14:39   ` Michael Thalmeier
  2012-02-23 13:37     ` Arnd Bergmann
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Thalmeier @ 2012-02-21 14:39 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: Matt Mackall, Sascha Hauer, linux-arm-kernel, michael, linux-kernel

On 2012-02-21 14:29, Fabio Estevam wrote:

> On Tue, Feb 21, 2012 at 10:13 AM, Michael Thalmeier
> <michael.thalmeier@hale.at> wrote:
> 
>> -static int mxc_rnga_data_present(struct hwrng *rng)
>> +static int mxc_rnga_data_present(struct hwrng *rng, int wait)
> 
> This looks good, but ...
> 
>>  {
>> -       int level;
>> +       int level, i;
>>        void __iomem *rng_base = (void __iomem *)rng->priv;
>>
>> -       /* how many random numbers is in FIFO? [0-16] */
>> -       level = ((__raw_readl(rng_base + RNGA_STATUS) &
>> -                       RNGA_STATUS_LEVEL_MASK) >> 8);
>> +       for (i = 0; i < 20; i++) {
> 
> Why the magic "20" here?
> 
> It would be better to add a proper timeout mechanism instead, such as
> time_after(jiffies, timeout)
> 


I am absolutely with you.
The point is only that this is the behaviour of nearly all hw_random
drivers, and I basically just copied it over into this driver.


--
Scanned by MailScanner.


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

* Re: [PATCH] i.MX31: mxc-rnga: implement waiting for data in driver
  2012-02-21 14:39   ` Michael Thalmeier
@ 2012-02-23 13:37     ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2012-02-23 13:37 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Michael Thalmeier, Fabio Estevam, michael, Sascha Hauer,
	linux-kernel, Matt Mackall

On Tuesday 21 February 2012, Michael Thalmeier wrote:
> On 2012-02-21 14:29, Fabio Estevam wrote:
> 
> > On Tue, Feb 21, 2012 at 10:13 AM, Michael Thalmeier
> > <michael.thalmeier@hale.at> wrote:
> > 
> >> -static int mxc_rnga_data_present(struct hwrng *rng)
> >> +static int mxc_rnga_data_present(struct hwrng *rng, int wait)
> > 
> > This looks good, but ...
> > 
> >>  {
> >> -       int level;
> >> +       int level, i;
> >>        void __iomem *rng_base = (void __iomem *)rng->priv;
> >>
> >> -       /* how many random numbers is in FIFO? [0-16] */
> >> -       level = ((__raw_readl(rng_base + RNGA_STATUS) &
> >> -                       RNGA_STATUS_LEVEL_MASK) >> 8);
> >> +       for (i = 0; i < 20; i++) {
> > 
> > Why the magic "20" here?
> > 
> > It would be better to add a proper timeout mechanism instead, such as
> > time_after(jiffies, timeout)
> > 
> I am absolutely with you.
> The point is only that this is the behaviour of nearly all hw_random
> drivers, and I basically just copied it over into this driver.

Hmm, I guess they are all wrong then ;-)

It would be nice to move the retry loop into common code where it
would be easier to change.

Note that comparing jiffies is not going to help here because the
maximum delay in the loop is less than a jiffy.

	Arnd

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

end of thread, other threads:[~2012-02-23 13:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-21 12:13 [PATCH] i.MX31: mxc-rnga: implement waiting for data in driver Michael Thalmeier
2012-02-21 13:29 ` Fabio Estevam
2012-02-21 14:39   ` Michael Thalmeier
2012-02-23 13:37     ` Arnd Bergmann

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).