Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp560900pxb; Thu, 21 Apr 2022 05:50:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgSh8pe4aV/lyKVo3IRCjhTApeMJKtx0EY5F4wpbZ//qbYWLjolVf/bezPsTIklqdxDx9e X-Received: by 2002:a17:90b:4c4e:b0:1d2:9f85:66b2 with SMTP id np14-20020a17090b4c4e00b001d29f8566b2mr10410233pjb.128.1650545436745; Thu, 21 Apr 2022 05:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650545436; cv=none; d=google.com; s=arc-20160816; b=D3YwNB7u9P3/eL+03oyxplRDZTzZzDJYwcTE3fTqzhpKdUuJ4v9FjuNeI2kyFBICEv DvC7nXuGKjrCEtYMFjroxiJKQBQ/Ecsb7kbfD2hYewDZqabXxdBaFYobs2CjvB4jVq/z x4kHx7wusxWqJ8JC+JswjfX+/zoHGbnDmxtART+OSiln+aAFtKN5y2Ri9dGG+pfSaTs1 k930U91SBBFC50VRA49pSNN3bMlSdBSCLnA8JMNg/3WO9v63/peXYtE70wKWEiOTk+zs K5Ytj3VAHT0vqZ/tpwbCJul3FpHXXP4HLjNoilDGNy8+1yiHmLnNmF+EImMn3V7Lrt5D lKTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3vowEc/UcKrf0koZfGRpVEA6e8Y7oEc/jUqdJ2tAL84=; b=NfUrNfww6K1YOrMcNRN9XdpdCk2/HUw0374kjIJe8N6f8RcDLxIJUkYyGv9IpIfn52 14xaTrbRFnYKs6XrfC63/IrwbN8RYFPiLEe7LAMY3nEDLKERt4FDB+2xW9uasJfd5d39 fwUw1Yk+2xPY5k4L4yA0oLjYmhOOswCq0Up5vTlogrgNqrXZy8ZGcTN8tzASXNMho5H1 34dJXfK9acMqXooal87fHb2fCX+PLPVj6w7XV2eck9N2O5TWw5gF6PxGDifcr0zghmip AchHRsZsxKUXMh3N/AwarrxiQ3Tx4crbvqoCN5VbEqyz26wudwCom+onG1iI8jCGXAm/ YCeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jcyJFLN7; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb8-20020a17090ae7c800b001d2c6c93948si5998868pjb.80.2022.04.21.05.50.21; Thu, 21 Apr 2022 05:50:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jcyJFLN7; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378383AbiDTMJH (ORCPT + 99 others); Wed, 20 Apr 2022 08:09:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378390AbiDTMJG (ORCPT ); Wed, 20 Apr 2022 08:09:06 -0400 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CA5436B5E; Wed, 20 Apr 2022 05:06:16 -0700 (PDT) Received: by mail-oi1-x22b.google.com with SMTP id q129so1780876oif.4; Wed, 20 Apr 2022 05:06:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3vowEc/UcKrf0koZfGRpVEA6e8Y7oEc/jUqdJ2tAL84=; b=jcyJFLN7iLtNwhQplscp/7lkiD3lUsBJYoMNER1K9C8tMZVQBnOjD9ZHTDGFenS3iw KRHuFRotqrp3XdXYb8yNkWqZ4rgUAk7HPBm1X3knRHXgqhuSvp9sY/gpeZq2Dly2JDZe 6g0bQbPRv+vQfwV86livDx9BGKlLkj9bM15OZhXZiwUXDoiDccf7v3JAJ2L8x+uk5vtS DsnUvuCalpEopSXZeqm34KQfpljHx1H1xqOjb7u9aklTn0b7xroirqjbUSX3IZA9YIjY eSWJ++j+eNdJV0TRcYsmVGvoLuHusCJ3Eoho1V0kPHL4eLUW/IVjmlUjIfMEMKeBybk9 gzZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3vowEc/UcKrf0koZfGRpVEA6e8Y7oEc/jUqdJ2tAL84=; b=VCZo7wsioP6AIGKD3Yn0JuxqKiKrJCaAir1+fED4+Q6rn8rAmg4Isvs58Ch9RW6mCk bfvheB/u62uFIJmB/V7UWlp5LLsPMN4KmHZyQrOumvhcEVmAfBv449u6vIMkBtJwIkmD +HyHuaPf9zN8yi4GTxVwmQNB6uMDmy4ksZeSRXCHoUpr0ZqseSEIowM2IeOHCtEWCQrQ gIH69EyhVs6qfFZ333BO1gCFbtE5wgG397WKjswSYc5uwMXWec516ZbFrTDz7LZie1/2 ItT6ClNT5tPu+A/5pvo7ZQh/jznRezCzmu1cZKlko1wKgL3erLyPyQ78/GHI6YKu8LI+ Vm7Q== X-Gm-Message-State: AOAM530ttWcPZHHDmv2koN2/suiZsyqiHyqoayrWeDG0PNc9XC3+M087 dNZVEPwSyQp5M1mj8I6tc6w= X-Received: by 2002:a05:6808:128c:b0:2da:3751:7639 with SMTP id a12-20020a056808128c00b002da37517639mr1552321oiw.294.1650456375325; Wed, 20 Apr 2022 05:06:15 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:485:4b69:3ce1:a87b:51c0:189d]) by smtp.gmail.com with ESMTPSA id o19-20020a4a9593000000b0032176119e65sm6530117ooi.34.2022.04.20.05.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 05:06:14 -0700 (PDT) From: Fabio Estevam To: herbert@gondor.apana.org.au Cc: horia.geanta@nxp.com, gaurav.jain@nxp.com, V.Sethi@nxp.com, linux-crypto@vger.kernel.org, Fabio Estevam , stable@vger.kernel.org Subject: [PATCH v5] crypto: caam - fix i.MX6SX entropy delay value Date: Wed, 20 Apr 2022 09:06:01 -0300 Message-Id: <20220420120601.1015362-1-festevam@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Fabio Estevam 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/20220415111049.2565744-1-gaurav.jain@nxp.com/ As explained in the U-Boot patch: "RNG self tests are run to determine the correct entropy delay. Such tests are executed with different voltages and temperatures to identify the worst case value for the entropy delay. For i.MX6SX, it was determined that after adding a margin value of 1000 the minimum entropy delay should be at least 12000." Cc: Fixes: 358ba762d9f1 ("crypto: caam - enable prediction resistance in HRWNG") Signed-off-by: Fabio Estevam Reviewed-by: Horia Geantă --- Changes since v4: - Change the function name to needs_entropy_delay_adjustment() - Vabhav - Improve the commit log by adding the explanation from the U-Boot patch - Vabhav drivers/crypto/caam/ctrl.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index ca0361b2dbb0..f87aa2169e5f 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -609,6 +609,13 @@ static bool check_version(struct fsl_mc_version *mc_version, u32 major, } #endif +static bool needs_entropy_delay_adjustment(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_entropy_delay_adjustment()) + 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_entropy_delay_adjustment()) + break; if (ret == -EAGAIN) /* * if here, the loop will rerun, -- 2.25.1