Skip to contentSkip to conversation

crypto: caam - fix i.MX6SX entropy delay value

PATCH Superseded Fabio Estevam 2 participants 2 messages Apr 18, 2022 – Apr 19, 2022

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 crypto: caam - fix i.MX6SX entropy delay value

From: Fabio Estevam <[email protected]>

Since commit 358ba762d9f1 ("crypto: caam - enable prediction resistance in HRWNG") the following CAAM errors can be seen on i.MX6SX:

caam_jr 2101000.jr: 20003c5b: CCB: desc idx 60: RNG: Hardware error
hwrng: no data available
caam_jr 2101000.jr: 20003c5b: CCB: desc idx 60: RNG: Hardware error

This error is due to an incorrect entropy delay for i.MX6SX.

Fix it by increasing the minimum entropy delay for i.MX6SX as done in U-Boot:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Fixes 358ba762d9f1 ("crypto: caam - enable prediction resistance in HRWNG")

---
Changes since v2:
- Added Fixes tag. (Horia)

Change since v1:
- Align the fix with U-Boot.

 drivers/crypto/caam/ctrl.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/crypto/caam/ctrl.c +11 -0
index ca0361b2dbb0..c515c20442d5 100644
@@ -648,6 +648,8 @@ static int caam_probe(struct platform_device *pdev)
 			return ret;
 	}
 
+	if (of_machine_is_compatible("fsl,imx6sx"))
+		ent_delay = 12000;
 
 	/* Get configuration properties from device tree */
 	/* First, get register page */
@@ -871,6 +873,15 @@ static int caam_probe(struct platform_device *pdev)
 			 */
 			ret = instantiate_rng(dev, inst_handles,
 					      gen_sk);
+			/*
+			 * Entropy delay is calculated via self-test method.
+			 * Self-test is run across different voltages and
+			 * temperatures.
+			 * If worst case value for ent_dly is identified,
+			 * the loop can be skipped for that platform.
+			 */
+			if (of_machine_is_compatible("fsl,imx6sx"))
+				break;
 			if (ret == -EAGAIN)
 				/*
 				 * if here, the loop will rerun,
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 32 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

Since commit 358ba762d9f1 ("crypto: caam - enable prediction resistance in HRWNG") the following CAAM errors can be seen on i.MX6SX:

caam_jr 2101000.jr: 20003c5b: CCB: desc idx 60: RNG: Hardware error
hwrng: no data available
caam_jr 2101000.jr: 20003c5b: CCB: desc idx 60: RNG: Hardware error

This error is due to an incorrect entropy delay for i.MX6SX.

Fix it by increasing the minimum entropy delay for i.MX6SX as done in U-Boot:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Fixes 358ba762d9f1 ("crypto: caam - enable prediction resistance in HRWNG")

---
Changes since v2:
- Added Fixes tag. (Horia)

Change since v1:
- Align the fix with U-Boot.

 drivers/crypto/caam/ctrl.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/crypto/caam/ctrl.c +0 -0
index ca0361b2dbb0..c515c20442d5 100644

drivers/crypto/caam/ctrl.c static int caam_probe(struct platform_device *pdev) · line 653

Quoted 6 lines
drivers/crypto/caam/ctrl.c +2 -0
@@ -648,6 +648,8 @@ static int caam_probe(struct platform_device *pdev)
 			return ret;
 	}
 
+	if (of_machine_is_compatible("fsl,imx6sx"))
+		ent_delay = 12000;
 

This looks rather randomly placed in the probe() function. I'd suggest moving it into the RNG initialization area. Another benefit would be calling of_machine_is_compatible() only once.

drivers/crypto/caam/ctrl.c static int caam_probe(struct platform_device *pdev) · line 879

Quoted 10 lines
drivers/crypto/caam/ctrl.c +4 -0
 	/* Get configuration properties from device tree */
 	/* First, get register page */
@@ -871,6 +873,15 @@ static int caam_probe(struct platform_device *pdev)
 			 */
 			ret = instantiate_rng(dev, inst_handles,
 					      gen_sk);
+			/*
+			 * Entropy delay is calculated via self-test method.
+			 * Self-test is run across different voltages and
+			 * temperatures.

A clarification wrt. terminology:
-"self-tests" refer to HW checks done when initializing the RNG (instantiating the RNG state handle), they are statistical tests to check the quality of the entropy
-"TRNG characterization" is the offline process of determining the entropy delay values that are "suitable" - i.e. allowing TRNG to work correctly across ranges of temperature, voltage and clock frequency

drivers/crypto/caam/ctrl.c static int caam_probe(struct platform_device *pdev) · line 887

Quoted 8 lines
drivers/crypto/caam/ctrl.c +5 -0
+			 * If worst case value for ent_dly is identified,
+			 * the loop can be skipped for that platform.
+			 */
+			if (of_machine_is_compatible("fsl,imx6sx"))
+				break;
 			if (ret == -EAGAIN)
 				/*
 				 * if here, the loop will rerun,

Thanks,
Horia