linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fabio Estevam <festevam@gmail.com>
To: herbert@gondor.apana.org.au
Cc: horia.geanta@nxp.com, andrei.botila@nxp.com,
	andrew.smirnov@gmail.com, fredrik.yhlen@endian.se, hs@denx.de,
	linux-crypto@vger.kernel.org, Fabio Estevam <festevam@denx.de>
Subject: [PATCH] crypto: caam - enable prediction resistance conditionally
Date: Tue, 11 Jan 2022 09:41:04 -0300	[thread overview]
Message-ID: <20220111124104.2379295-1-festevam@gmail.com> (raw)

From: Fabio Estevam <festevam@denx.de>

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

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
hwrng: no data available
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
hwrng: no data available

OP_ALG_PR_ON is enabled unconditionally, which may cause the problem
on i.MX devices.

Fix the problem by only enabling OP_ALG_PR_ON on platforms that have
Management Complex support.

Fixes: 358ba762d9f1 ("crypto: caam - enable prediction resistance in HRWNG")
Signed-off-by: Fabio Estevam <festevam@denx.de>
---
 drivers/crypto/caam/caamrng.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index 77d048dfe5d0..3514fe5de2a5 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -63,12 +63,19 @@ static void caam_rng_done(struct device *jrdev, u32 *desc, u32 err,
 	complete(jctx->done);
 }
 
-static u32 *caam_init_desc(u32 *desc, dma_addr_t dst_dma)
+static u32 *caam_init_desc(struct device *jrdev, u32 *desc, dma_addr_t dst_dma)
 {
+	struct caam_drv_private *priv = dev_get_drvdata(jrdev->parent);
+
 	init_job_desc(desc, 0);	/* + 1 cmd_sz */
 	/* Generate random bytes: + 1 cmd_sz */
-	append_operation(desc, OP_ALG_ALGSEL_RNG | OP_TYPE_CLASS1_ALG |
-			 OP_ALG_PR_ON);
+
+	if (priv->mc_en)
+		append_operation(desc, OP_ALG_ALGSEL_RNG | OP_TYPE_CLASS1_ALG |
+				  OP_ALG_PR_ON);
+	else
+		append_operation(desc, OP_ALG_ALGSEL_RNG | OP_TYPE_CLASS1_ALG);
+
 	/* Store bytes: + 1 cmd_sz + caam_ptr_sz  */
 	append_fifo_store(desc, dst_dma,
 			  CAAM_RNG_MAX_FIFO_STORE_SIZE, FIFOST_TYPE_RNGSTORE);
@@ -101,7 +108,7 @@ static int caam_rng_read_one(struct device *jrdev,
 
 	init_completion(done);
 	err = caam_jr_enqueue(jrdev,
-			      caam_init_desc(desc, dst_dma),
+			      caam_init_desc(jrdev, desc, dst_dma),
 			      caam_rng_done, &jctx);
 	if (err == -EINPROGRESS) {
 		wait_for_completion(done);
-- 
2.25.1


             reply	other threads:[~2022-01-11 12:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11 12:41 Fabio Estevam [this message]
2022-01-11 18:21 ` [PATCH] crypto: caam - enable prediction resistance conditionally Andrey Smirnov
2022-01-11 18:34   ` Fabio Estevam
2022-01-11 19:05     ` Andrey Smirnov
2022-01-28  6:23 ` Herbert Xu
2022-01-28  7:44   ` Horia Geantă
2022-01-28 11:35     ` Fabio Estevam
2022-01-31  0:20     ` Herbert Xu
2022-03-22 13:19     ` Fabio Estevam
2022-03-22 13:56       ` [EXT] " Varun Sethi
2022-04-14 14:53         ` Fabio Estevam
     [not found]           ` <AM9PR04MB82119651D9FC652BD982646DE8EF9@AM9PR04MB8211.eurprd04.prod.outlook.com>
2022-04-16 12:24             ` Fabio Estevam
2022-04-16 13:28               ` Fabio Estevam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220111124104.2379295-1-festevam@gmail.com \
    --to=festevam@gmail.com \
    --cc=andrei.botila@nxp.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=festevam@denx.de \
    --cc=fredrik.yhlen@endian.se \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=hs@denx.de \
    --cc=linux-crypto@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).