Skip to contentSkip to conversation

rng: Add Turris Mox rTWM RNG driver

PATCH Superseded Max Resch 2 participants 2 messages Feb 7, 2024 – Feb 8, 2024

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Max Resch

author
#0 lore raw

PATCH v3 1/1 rng: Add Turris Mox rTWM RNG driver

A RNG driver for Armada 3720 boards running the Turris Mox rWTM firmware from CZ.NIC in the secure processor.

---

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(-)
drivers/rng/turris_rwtm_rng.c +9 -9
index 143fe0b47f..ec2cb0bca3 100644
@@ -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;
 }
Signature · 1 line
2.43.0
#1 lore raw

Hi Max,

Quoted 20 lines · Max Resch

A RNG driver for Armada 3720 boards running the Turris Mox rWTM firmware from CZ.NIC in the secure processor.

---

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(-)
drivers/rng/turris_rwtm_rng.c +0 -0
index 143fe0b47f..ec2cb0bca3 100644

drivers/rng/turris_rwtm_rng.c static int turris_rwtm_rng_fill_entropy(phys_addr_t entropy, size_t size) · line 45

Quoted 6 lines
drivers/rng/turris_rwtm_rng.c +2 -1
@@ -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

Quoted 38 lines
drivers/rng/turris_rwtm_rng.c +4 -5
  	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)
  {

drivers/rng/turris_rwtm_rng.c static int turris_rwtm_rng_probe(struct udevice *dev) · line 98

Quoted 10 lines
drivers/rng/turris_rwtm_rng.c +3 -3
-	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

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]