Re: [linux-yocto] Revert "hwrng: bcm2835 - sleep more intelligently"

2023-12-04 Thread Bruce Ashfield
In message: [linux-yocto] Revert "hwrng: bcm2835 - sleep more intelligently"
on 04/12/2023 Kevin Hao wrote:

> From: Kevin Hao 
> 
> The SDK commit a9d5338d0643 ("hwrng: bcm2835 - sleep more
> intelligently") and stable commit 3c5c7f926a4b ("hwrng: bcm2835 - Fix
> hwrng throughput regression") are trying to fix the same issue with
> different implementation. The later approach is better. So revert
> the SDK changes.
> 
> Signed-off-by: Kevin Hao 
> ---
> Hi Bruce,
> 
> Please help me merge this into the following two branches:
>   v6.1/standard/bcm-2xxx-rpi
>   v6.1/standard/preempt-rt/bcm-2xxx-rpi

merged.

Bruce

> 
>  drivers/char/hw_random/bcm2835-rng.c | 19 +--
>  1 file changed, 5 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/char/hw_random/bcm2835-rng.c 
> b/drivers/char/hw_random/bcm2835-rng.c
> index b821fc12c80d..f46731a5dfe1 100644
> --- a/drivers/char/hw_random/bcm2835-rng.c
> +++ b/drivers/char/hw_random/bcm2835-rng.c
> @@ -14,7 +14,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  
>  #define RNG_CTRL 0x0
>  #define RNG_STATUS   0x4
> @@ -29,9 +28,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;
> @@ -68,24 +64,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 = 100/(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_yield(rng);
>   }
>  
> - 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);
> -- 
> 2.39.2
> 

> 
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#13368): 
https://lists.yoctoproject.org/g/linux-yocto/message/13368
Mute This Topic: https://lists.yoctoproject.org/mt/102969990/21656
Group Owner: linux-yocto+ow...@lists.yoctoproject.org
Unsubscribe: 
https://lists.yoctoproject.org/g/linux-yocto/leave/6687884/21656/624485779/xyzzy
 [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[linux-yocto] Revert "hwrng: bcm2835 - sleep more intelligently"

2023-12-04 Thread Kevin Hao
From: Kevin Hao 

The SDK commit a9d5338d0643 ("hwrng: bcm2835 - sleep more
intelligently") and stable commit 3c5c7f926a4b ("hwrng: bcm2835 - Fix
hwrng throughput regression") are trying to fix the same issue with
different implementation. The later approach is better. So revert
the SDK changes.

Signed-off-by: Kevin Hao 
---
Hi Bruce,

Please help me merge this into the following two branches:
  v6.1/standard/bcm-2xxx-rpi
  v6.1/standard/preempt-rt/bcm-2xxx-rpi

 drivers/char/hw_random/bcm2835-rng.c | 19 +--
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/char/hw_random/bcm2835-rng.c 
b/drivers/char/hw_random/bcm2835-rng.c
index b821fc12c80d..f46731a5dfe1 100644
--- a/drivers/char/hw_random/bcm2835-rng.c
+++ b/drivers/char/hw_random/bcm2835-rng.c
@@ -14,7 +14,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #define RNG_CTRL   0x0
 #define RNG_STATUS 0x4
@@ -29,9 +28,6 @@
 
 #define RNG_INT_OFF0x1
 
-#define RNG_FIFO_WORDS 4
-#define RNG_US_PER_WORD34 /* Tuned for throughput */
-
 struct bcm2835_rng_priv {
struct hwrng rng;
void __iomem *base;
@@ -68,24 +64,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 = 100/(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_yield(rng);
}
 
-   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);
-- 
2.39.2


-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#13359): 
https://lists.yoctoproject.org/g/linux-yocto/message/13359
Mute This Topic: https://lists.yoctoproject.org/mt/102969990/21656
Group Owner: linux-yocto+ow...@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-