Skip to contentSkip to conversation

crypto: caam - fix i.MX6SX entropy delay value

PATCH Superseded Fabio Estevam 3 participants 4 messages Apr 19, 2022 – Apr 20, 2022 1 message not in the archive

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 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

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 v3:
- Add a needs_extended_entropy_delay() function
- Assign the 'ent_delay' inside the the RNG initialization area. (Horia)
- Change the terminology as per Horia's explanation.

 drivers/crypto/caam/ctrl.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/crypto/caam/ctrl.c +18 -0
index ca0361b2dbb0..5b989a842ee9 100644
@@ -609,6 +609,13 @@ static bool check_version(struct fsl_mc_version *mc_version, u32 major,
 }
 #endif
 
+static bool needs_extended_entropy_delay(void)
+{
+	if (of_machine_is_compatible("fsl,imx6sx"))
+		return true;
+	return false;
+}
+
 /* Probe routine for CAAM top (controller) level */
 static int caam_probe(struct platform_device *pdev)
 {
@@ -855,6 +862,8 @@ static int caam_probe(struct platform_device *pdev)
 			 * Also, if a handle was instantiated, do not change
 			 * the TRNG parameters.
 			 */
+			if (needs_extended_entropy_delay())
+				ent_delay = 12000;
 			if (!(ctrlpriv->rng4_sh_init || inst_handles)) {
 				dev_info(dev,
 					 "Entropy delay = %u\n",
@@ -871,6 +880,15 @@ static int caam_probe(struct platform_device *pdev)
 			 */
 			ret = instantiate_rng(dev, inst_handles,
 					      gen_sk);
+			/*
+			 * Entropy delay is determined via TRNG characterization.
+			 * TRNG characterization 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 (needs_extended_entropy_delay())
+				break;
 			if (ret == -EAGAIN)
 				/*
 				 * if here, the loop will rerun,
Signature · 1 line
2.25.1
maintainer Reviewed-by on v4 1/1
#1 lore raw
Quoted 10 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

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

Quoted 7 lines

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")

Thanks,
Horia

A message that is not in the archive (sent off-list or not yet received): VI1PR04MB5342FB22BDAF3163C7C8ECD9E7F59@VI1PR04MB5342.eurprd04.prod.outlook.com

#3 lore raw
Quoted 67 lines

-----Original Message-----
From: Fabio Estevam <[email protected]>
Sent: Tuesday, April 19, 2022 5:15 PM
To: [email protected]
Cc: Horia Geanta <[email protected]>; Gaurav Jain <[email protected]>; Varun Sethi <[email protected]>; linux- [email protected]; Fabio Estevam <[email protected]>; [email protected]
Subject: [EXT] [PATCH v4] crypto: caam - fix i.MX6SX entropy delay value

Caution: EXT Email

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

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://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch
work.ozlabs.org%2Fproject%2Fuboot%2Fpatch%2F20220415111049.2565744- 1- gaurav.jain%40nxp.com%2F&amp;data=05%7C01%7Cgaurav.jain%40nxp.co m%7C9016fe4b6bb8402de08f08da21fa0703%7C686ea1d3bc2b4c6fa92cd99c5c 301635%7C0%7C0%7C637859655100732358%7CUnknown%7CTWFpbGZsb3d8 eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3 D%7C3000%7C%7C%7C&amp;sdata=wglpvZBmQUKn7sLRx5xpdwdgFMOc6LE qIMqUU0h4UZE%3D&amp;reserved=0

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

---
Changes since v3:
- Add a needs_extended_entropy_delay() function
- Assign the 'ent_delay' inside the the RNG initialization area. (Horia)
- Change the terminology as per Horia's explanation.

 drivers/crypto/caam/ctrl.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/crypto/caam/ctrl.c index renamed from drivers/crypto/caam/ctrl.c +0 -0

ca0361b2dbb0..5b989a842ee9 100644

drivers/crypto/caam/ctrl.c +7 -0
@@ -609,6 +609,13 @@ static bool check_version(struct fsl_mc_version
 *mc_version, u32 major,  }  #endif
 
+static bool needs_extended_entropy_delay(void)
+{
+       if (of_machine_is_compatible("fsl,imx6sx"))
+               return true;
+       return false;
+}
+
 /* Probe routine for CAAM top (controller) level */  static int

caam_probe(struct platform_device *pdev) { @@ -855,6 +862,8 @@ static int caam_probe(struct platform_device *pdev)
* Also, if a handle was instantiated, do not change
* the TRNG parameters.
*/

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

Quoted 3 lines
drivers/crypto/caam/ctrl.c +2 -0
+                       if (needs_extended_entropy_delay())
+                               ent_delay = 12000;
                        if (!(ctrlpriv->rng4_sh_init || inst_handles)) {

Please note if TRNG state handles are already instantiated e.g. by U-Boot bootloader, It is assumed that entropy is set correctly and kick_trng() will be skipped Kindly pick the U-Boot changes as detailed in commit message.

Quoted 6 lines
                                dev_info(dev,
                                         "Entropy delay = %u\n", @@ -871,6 +880,15 @@ static
int caam_probe(struct platform_device *pdev)
                         */
                        ret = instantiate_rng(dev, inst_handles,
                                              gen_sk);

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

Quoted 8 lines
drivers/crypto/caam/ctrl.c +8 -0
+                       /*
+                        * Entropy delay is determined via TRNG characterization.
+                        * TRNG characterization 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 (needs_extended_entropy_delay())

There is nothing like extended entropy delay and function name seems to be incorrect, The software test were run offline across ranges of temperature, voltage and process to determine the correct entropy delay. However, value of 12000 is determined by running said test across voltage and temperature only for iMX6SX.

Quoted 6 lines
+                               break;
                        if (ret == -EAGAIN)
                                /*
                                 * if here, the loop will rerun,

--
2.25.1

#4 lore raw

Hi Vabhav,

Quoted 2 lines · Vabhav Sharma

There is nothing like extended entropy delay and function name seems to be incorrect, The software test were run offline across ranges of temperature, voltage and process to determine the correct entropy delay. However, value of 12000 is determined by running said test across voltage and temperature only for iMX6SX.

Ok, I did as you suggested and sent a v5.

Just realized that I forgot to add you on Cc. Sorry about that.

Thanks