Skip to content

Commit

Permalink
Revert "hwrng: bcm2835 - sleep more intelligently"
Browse files Browse the repository at this point in the history
This reverts commit 6a825ed.
  • Loading branch information
popcornmix committed Feb 6, 2024
1 parent e0f11a6 commit eb1ea3e
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions drivers/char/hw_random/bcm2835-rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <linux/printk.h>
#include <linux/clk.h>
#include <linux/reset.h>
#include <linux/delay.h>

#define RNG_CTRL 0x0
#define RNG_STATUS 0x4
Expand All @@ -28,9 +27,6 @@

#define RNG_INT_OFF 0x1

#define RNG_FIFO_WORDS 4
#define RNG_US_PER_WORD 34 /* Tuned for throughput */

struct bcm2835_rng_priv {
struct hwrng rng;
void __iomem *base;
Expand Down Expand Up @@ -67,23 +63,19 @@ static inline void rng_writel(struct bcm2835_rng_priv *priv, u32 val,
static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
bool wait)
{
u32 retries = 1000000/(RNG_FIFO_WORDS * RNG_US_PER_WORD);
struct bcm2835_rng_priv *priv = to_rng_priv(rng);
u32 max_words = max / sizeof(u32);
u32 num_words, count;

num_words = rng_readl(priv, RNG_STATUS) >> 24;

while (!num_words) {
if (!wait || !retries)
while ((rng_readl(priv, RNG_STATUS) >> 24) == 0) {
if (!wait)
return 0;
retries--;
usleep_range((u32)RNG_US_PER_WORD,
(u32)RNG_US_PER_WORD * RNG_FIFO_WORDS);
num_words = rng_readl(priv, RNG_STATUS) >> 24;
hwrng_msleep(rng, 1000);
}

num_words = min(num_words, max_words);
num_words = rng_readl(priv, RNG_STATUS) >> 24;
if (num_words > max_words)
num_words = max_words;

for (count = 0; count < num_words; count++)
((u32 *)buf)[count] = rng_readl(priv, RNG_DATA);
Expand Down

0 comments on commit eb1ea3e

Please sign in to comment.