diff mbox series

[v3] rng: Add Turris Mox rTWM RNG driver

Message ID 20240207150017.666213-1-resch.max@gmail.com
State Superseded
Delegated to: Stefan Roese
Headers show
Series [v3] rng: Add Turris Mox rTWM RNG driver | expand

Commit Message

Max Resch Feb. 7, 2024, 3 p.m. UTC
A RNG driver for Armada 3720 boards running the Turris Mox rWTM firmware
from CZ.NIC in the secure processor.

Signed-off-by: Max Resch <resch.max@gmail.com>
---

Changes in v3:
 - More meaningful variable names in accordance with review

Changes in v2:
 - Removed ring buffer implementation

 drivers/rng/turris_rwtm_rng.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

Comments

Stefan Roese Feb. 8, 2024, 5:42 a.m. UTC | #1
Hi Max,

On 2/7/24 16:00, Max Resch wrote:
> A RNG driver for Armada 3720 boards running the Turris Mox rWTM firmware
> from CZ.NIC in the secure processor.
> 
> Signed-off-by: Max Resch <resch.max@gmail.com>
> ---
> 
> Changes in v3:
>   - More meaningful variable names in accordance with review
> 
> Changes in v2:
>   - Removed ring buffer implementation
> 
>   drivers/rng/turris_rwtm_rng.c | 18 +++++++++---------
>   1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/rng/turris_rwtm_rng.c b/drivers/rng/turris_rwtm_rng.c
> index 143fe0b47f..ec2cb0bca3 100644
> --- a/drivers/rng/turris_rwtm_rng.c
> +++ b/drivers/rng/turris_rwtm_rng.c
> @@ -41,18 +41,19 @@ static int turris_rwtm_rng_fill_entropy(phys_addr_t entropy, size_t size)
>   
>   static int turris_rwtm_rng_random_read(struct udevice *dev, void *data, size_t count)
>   {
> -	phys_addr_t p;
> +	struct turris_rwtm_rng_priv *priv = dev_get_priv(dev);
> +	phys_addr_t phys;

You've now just sent the update v2->v3. As v2 is not applied yet
this is not the way to do it. Please squash this patch into the v2
one a send this as v3 or even better v4 now.

Thanks,
Stefan

>   	size_t size;
>   	int ret;
>   
> -	p = ((struct turris_rwtm_rng_priv *)dev_get_priv(dev))->buffer;
> +	phys = priv->buffer;
>   
>   	while (count) {
>   		size = min_t(size_t, RNG_BUFFER_SIZE, count);
>   
> -		ret = turris_rwtm_rng_fill_entropy(p, size);
> +		ret = turris_rwtm_rng_fill_entropy(phys, size);
>   
> -		memcpy(data, (void *)p, size);
> +		memcpy(data, (void *)phys, size);
>   		count -= size;
>   		data = (u8 *)data + size;
>   	}
> @@ -62,7 +63,7 @@ static int turris_rwtm_rng_random_read(struct udevice *dev, void *data, size_t c
>   
>   static int turris_rwtm_rng_probe(struct udevice *dev)
>   {
> -	struct turris_rwtm_rng_priv *priv;
> +	struct turris_rwtm_rng_priv *priv = dev_get_priv(dev);
>   	u32 args[] = { 0 };
>   	int ret;
>   
> @@ -76,7 +77,6 @@ static int turris_rwtm_rng_probe(struct udevice *dev)
>   		return ret;
>   
>   	/* entropy buffer */
> -	priv = (struct turris_rwtm_rng_priv *)dev_get_priv(dev);
>   	priv->buffer = 0;
>   
>   	/* buffer address need to be aligned */
> @@ -89,10 +89,10 @@ static int turris_rwtm_rng_probe(struct udevice *dev)
>   
>   static int turris_rwtm_rng_remove(struct udevice *dev)
>   {
> -	phys_addr_t p;
> +	struct turris_rwtm_rng_priv *priv = dev_get_priv(dev);
> +	phys_addr_t phys = priv->buffer;
>   
> -	p = ((struct turris_rwtm_rng_priv *)dev_get_priv(dev))->buffer;
> -	dma_free_coherent((void *)p);
> +	dma_free_coherent((void *)phys);
>   
>   	return 0;
>   }

Viele Grüße,
Stefan Roese
diff mbox series

Patch

diff --git a/drivers/rng/turris_rwtm_rng.c b/drivers/rng/turris_rwtm_rng.c
index 143fe0b47f..ec2cb0bca3 100644
--- a/drivers/rng/turris_rwtm_rng.c
+++ b/drivers/rng/turris_rwtm_rng.c
@@ -41,18 +41,19 @@  static int turris_rwtm_rng_fill_entropy(phys_addr_t entropy, size_t size)
 
 static int turris_rwtm_rng_random_read(struct udevice *dev, void *data, size_t count)
 {
-	phys_addr_t p;
+	struct turris_rwtm_rng_priv *priv = dev_get_priv(dev);
+	phys_addr_t phys;
 	size_t size;
 	int ret;
 
-	p = ((struct turris_rwtm_rng_priv *)dev_get_priv(dev))->buffer;
+	phys = priv->buffer;
 
 	while (count) {
 		size = min_t(size_t, RNG_BUFFER_SIZE, count);
 
-		ret = turris_rwtm_rng_fill_entropy(p, size);
+		ret = turris_rwtm_rng_fill_entropy(phys, size);
 
-		memcpy(data, (void *)p, size);
+		memcpy(data, (void *)phys, size);
 		count -= size;
 		data = (u8 *)data + size;
 	}
@@ -62,7 +63,7 @@  static int turris_rwtm_rng_random_read(struct udevice *dev, void *data, size_t c
 
 static int turris_rwtm_rng_probe(struct udevice *dev)
 {
-	struct turris_rwtm_rng_priv *priv;
+	struct turris_rwtm_rng_priv *priv = dev_get_priv(dev);
 	u32 args[] = { 0 };
 	int ret;
 
@@ -76,7 +77,6 @@  static int turris_rwtm_rng_probe(struct udevice *dev)
 		return ret;
 
 	/* entropy buffer */
-	priv = (struct turris_rwtm_rng_priv *)dev_get_priv(dev);
 	priv->buffer = 0;
 
 	/* buffer address need to be aligned */
@@ -89,10 +89,10 @@  static int turris_rwtm_rng_probe(struct udevice *dev)
 
 static int turris_rwtm_rng_remove(struct udevice *dev)
 {
-	phys_addr_t p;
+	struct turris_rwtm_rng_priv *priv = dev_get_priv(dev);
+	phys_addr_t phys = priv->buffer;
 
-	p = ((struct turris_rwtm_rng_priv *)dev_get_priv(dev))->buffer;
-	dma_free_coherent((void *)p);
+	dma_free_coherent((void *)phys);
 
 	return 0;
 }