From patchwork Thu Mar 19 16:12:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 197966 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E303C4332D for ; Thu, 19 Mar 2020 16:13:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF9E620663 for ; Thu, 19 Mar 2020 16:13:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hLyAnhV8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728312AbgCSQND (ORCPT ); Thu, 19 Mar 2020 12:13:03 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:35593 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728270AbgCSQNC (ORCPT ); Thu, 19 Mar 2020 12:13:02 -0400 Received: by mail-pl1-f196.google.com with SMTP id g6so1264493plt.2; Thu, 19 Mar 2020 09:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ikmpOAjYjiZjMcu6wx7gyB/EupCQsqCMEG2y7EaS2d8=; b=hLyAnhV8iUaz9L6OvG4yok1R9WrlsS20bncuv83nVZ0kwXAVT7JnagX+1FyleeKQU3 NPLybW8AU7TVFaYcq2++OvmSE/f2/tbpQWSYu8DjrtD2DVyd1MSqSf1/TVXr9aQH5nU9 ryKrm8YfUnkr0OMad3Aqis1hRx8iAh0EpKPdj8D9F8uHkp9jwortazkfG3IEVxxtPKYM E1Fmz8D952rthLm6jx/RakoFuw/k+/duzDj2LrVsNN0jhmx7lVy2fFufDdGVPXb6NM4U Xj/XM1L8AxosM/7hfoYLw/k8SuEo4TPfBXO4+D3Zeslu6JOLckeEQb3BqRPTqmpwus8V i3Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ikmpOAjYjiZjMcu6wx7gyB/EupCQsqCMEG2y7EaS2d8=; b=si7N8iqWAIkDMmukhTbRNuxcgd3zOGeyyifBdDVAzwzZWti2xwg097/LWqHZd9hsao gEnWuclXl7RMnxfuesLr8ZUS8itiJUOefDL+KMMV37jYsid5jlTc9tWoj2IZ7cyS80tf jiC7uDuS07ynQ5HWey5v17d2w5URoot+L4qMjlhMvXVFOPmzqQu9hT3+M6SBrEkAM98T wIzRXSLSLegydn/qTeI2/iR5VSMOkSbWIl+JQ28xKqc4p1orxNZrav/F8M73YO2fNOEo uUSr2JI6MCiFGBEyTy7bywv09464TL/211slnFOxwgNZvX28AlFT9IhG1jyX771AczqP kPLg== X-Gm-Message-State: ANhLgQ1CbMSHaJcHVvD8LguQMn7TOdWAakn8D3EiOe0jY0vnUXKN1ZFo fJCdA0zrwufEVaTh+X/TXtDXRJG4 X-Google-Smtp-Source: ADFU+vueUOzYFERasM0E8oI12/jKiVh9SgetVEDam1juhfHfTlJhmNbYo5OAkg3dcBk6a+CiQBYrqA== X-Received: by 2002:a17:902:a588:: with SMTP id az8mr4030968plb.163.1584634380181; Thu, 19 Mar 2020 09:13:00 -0700 (PDT) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id x189sm3000078pfb.1.2020.03.19.09.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2020 09:12:58 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant?= =?utf-8?b?xIM=?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v9 3/9] crypto: caam - drop global context pointer and init_done Date: Thu, 19 Mar 2020 09:12:27 -0700 Message-Id: <20200319161233.8134-4-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200319161233.8134-1-andrew.smirnov@gmail.com> References: <20200319161233.8134-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Leverage devres to get rid of code storing global context as well as init_done flag. Original code also has a circular deallocation dependency where unregister_algs() -> caam_rng_exit() -> caam_jr_free() chain would only happen if all of JRs were freed. Fix this by moving caam_rng_exit() outside of unregister_algs() and doing it specifically for JR that instantiated HWRNG. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-imx@nxp.com --- drivers/crypto/caam/caamrng.c | 67 +++++++++++++++++------------------ drivers/crypto/caam/intern.h | 7 ++-- drivers/crypto/caam/jr.c | 13 ++++--- 3 files changed, 44 insertions(+), 43 deletions(-) diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c index 69a02ac5de54..753625f2b2c0 100644 --- a/drivers/crypto/caam/caamrng.c +++ b/drivers/crypto/caam/caamrng.c @@ -70,6 +70,7 @@ struct buf_data { /* rng per-device context */ struct caam_rng_ctx { + struct hwrng rng; struct device *jrdev; dma_addr_t sh_desc_dma; u32 sh_desc[DESC_RNG_LEN]; @@ -78,13 +79,10 @@ struct caam_rng_ctx { struct buf_data bufs[2]; }; -static struct caam_rng_ctx *rng_ctx; - -/* - * Variable used to avoid double free of resources in case - * algorithm registration was unsuccessful - */ -static bool init_done; +static struct caam_rng_ctx *to_caam_rng_ctx(struct hwrng *r) +{ + return (struct caam_rng_ctx *)r->priv; +} static inline void rng_unmap_buf(struct device *jrdev, struct buf_data *bd) { @@ -143,7 +141,7 @@ static inline int submit_job(struct caam_rng_ctx *ctx, int to_current) static int caam_read(struct hwrng *rng, void *data, size_t max, bool wait) { - struct caam_rng_ctx *ctx = rng_ctx; + struct caam_rng_ctx *ctx = to_caam_rng_ctx(rng); struct buf_data *bd = &ctx->bufs[ctx->current_buf]; int next_buf_idx, copied_idx; int err; @@ -246,17 +244,18 @@ static inline int rng_create_job_desc(struct caam_rng_ctx *ctx, int buf_id) static void caam_cleanup(struct hwrng *rng) { + struct caam_rng_ctx *ctx = to_caam_rng_ctx(rng); int i; struct buf_data *bd; for (i = 0; i < 2; i++) { - bd = &rng_ctx->bufs[i]; + bd = &ctx->bufs[i]; if (atomic_read(&bd->empty) == BUF_PENDING) wait_for_completion(&bd->filled); } - rng_unmap_ctx(rng_ctx); - caam_jr_free(rng_ctx->jrdev); + rng_unmap_ctx(ctx); + caam_jr_free(ctx->jrdev); } static int caam_init_buf(struct caam_rng_ctx *ctx, int buf_id) @@ -277,7 +276,7 @@ static int caam_init_buf(struct caam_rng_ctx *ctx, int buf_id) static int caam_init(struct hwrng *rng) { - struct caam_rng_ctx *ctx = rng_ctx; + struct caam_rng_ctx *ctx = to_caam_rng_ctx(rng); int err; ctx->jrdev = caam_jr_alloc(); @@ -309,28 +308,19 @@ static int caam_init(struct hwrng *rng) return err; } -static struct hwrng caam_rng = { - .name = "rng-caam", - .init = caam_init, - .cleanup = caam_cleanup, - .read = caam_read, -}; +int caam_rng_init(struct device *ctrldev); -void caam_rng_exit(void) +void caam_rng_exit(struct device *ctrldev) { - if (!init_done) - return; - - hwrng_unregister(&caam_rng); - kfree(rng_ctx); + devres_release_group(ctrldev, caam_rng_init); } int caam_rng_init(struct device *ctrldev) { + struct caam_rng_ctx *ctx; u32 rng_inst; struct caam_drv_private *priv = dev_get_drvdata(ctrldev); - int err; - init_done = false; + int ret; /* Check for an instantiated RNG before registration */ if (priv->era < 10) @@ -342,18 +332,27 @@ int caam_rng_init(struct device *ctrldev) if (!rng_inst) return 0; - rng_ctx = kmalloc(sizeof(*rng_ctx), GFP_DMA | GFP_KERNEL); - if (!rng_ctx) + if (!devres_open_group(ctrldev, caam_rng_init, GFP_KERNEL)) + return -ENOMEM; + + ctx = devm_kzalloc(ctrldev, sizeof(*ctx), GFP_DMA | GFP_KERNEL); + if (!ctx) return -ENOMEM; + ctx->rng.name = "rng-caam"; + ctx->rng.init = caam_init; + ctx->rng.cleanup = caam_cleanup; + ctx->rng.read = caam_read; + ctx->rng.priv = (unsigned long)ctx; + dev_info(ctrldev, "registering rng-caam\n"); - err = hwrng_register(&caam_rng); - if (!err) { - init_done = true; - return err; + ret = devm_hwrng_register(ctrldev, &ctx->rng); + if (ret) { + caam_rng_exit(ctrldev); + return ret; } - kfree(rng_ctx); - return err; + devres_close_group(ctrldev, caam_rng_init); + return 0; } diff --git a/drivers/crypto/caam/intern.h b/drivers/crypto/caam/intern.h index 230ea88184f5..402d6a362e8c 100644 --- a/drivers/crypto/caam/intern.h +++ b/drivers/crypto/caam/intern.h @@ -47,6 +47,7 @@ struct caam_drv_private_jr { struct caam_job_ring __iomem *rregs; /* JobR's register space */ struct tasklet_struct irqtask; int irq; /* One per queue */ + bool hwrng; /* Number of scatterlist crypt transforms active on the JobR */ atomic_t tfm_count ____cacheline_aligned; @@ -163,7 +164,7 @@ static inline void caam_pkc_exit(void) #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API int caam_rng_init(struct device *dev); -void caam_rng_exit(void); +void caam_rng_exit(struct device *dev); #else @@ -172,9 +173,7 @@ static inline int caam_rng_init(struct device *dev) return 0; } -static inline void caam_rng_exit(void) -{ -} +static inline void caam_rng_exit(struct device *dev) {} #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API */ diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index 88aff2aefd5d..4af22e7ceb4f 100644 --- a/drivers/crypto/caam/jr.c +++ b/drivers/crypto/caam/jr.c @@ -27,7 +27,8 @@ static struct jr_driver_data driver_data; static DEFINE_MUTEX(algs_lock); static unsigned int active_devs; -static void register_algs(struct device *dev) +static void register_algs(struct caam_drv_private_jr *jrpriv, + struct device *dev) { mutex_lock(&algs_lock); @@ -37,7 +38,7 @@ static void register_algs(struct device *dev) caam_algapi_init(dev); caam_algapi_hash_init(dev); caam_pkc_init(dev); - caam_rng_init(dev); + jrpriv->hwrng = !caam_rng_init(dev); caam_qi_algapi_init(dev); algs_unlock: @@ -53,7 +54,6 @@ static void unregister_algs(void) caam_qi_algapi_exit(); - caam_rng_exit(); caam_pkc_exit(); caam_algapi_hash_exit(); caam_algapi_exit(); @@ -135,6 +135,9 @@ static int caam_jr_remove(struct platform_device *pdev) jrdev = &pdev->dev; jrpriv = dev_get_drvdata(jrdev); + if (jrpriv->hwrng) + caam_rng_exit(jrdev->parent); + /* * Return EBUSY if job ring already allocated. */ @@ -514,7 +517,7 @@ static int caam_jr_probe(struct platform_device *pdev) int error; jrdev = &pdev->dev; - jrpriv = devm_kmalloc(jrdev, sizeof(*jrpriv), GFP_KERNEL); + jrpriv = devm_kzalloc(jrdev, sizeof(*jrpriv), GFP_KERNEL); if (!jrpriv) return -ENOMEM; @@ -590,7 +593,7 @@ static int caam_jr_probe(struct platform_device *pdev) atomic_set(&jrpriv->tfm_count, 0); - register_algs(jrdev->parent); + register_algs(jrpriv, jrdev->parent); return 0; } From patchwork Thu Mar 19 16:12:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 197969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBD8CC4332B for ; Thu, 19 Mar 2020 16:13:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B105820663 for ; Thu, 19 Mar 2020 16:13:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k1Po56HI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728094AbgCSQNH (ORCPT ); Thu, 19 Mar 2020 12:13:07 -0400 Received: from mail-pj1-f65.google.com ([209.85.216.65]:38417 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728352AbgCSQNG (ORCPT ); Thu, 19 Mar 2020 12:13:06 -0400 Received: by mail-pj1-f65.google.com with SMTP id m15so1207780pje.3; Thu, 19 Mar 2020 09:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LCAGbzjQfd4JlaOjjKxUHcbjmkgk4JwloTjciGBlv28=; b=k1Po56HIE5oa4MTwiqOPUWFcpcwLNDu4cqdhSntXEMuAjPT3beaaDGNTHuwUlFI/w2 kCJfOkOakXmPOiBKp8k84V24ALWAHYUSEjU+Kb9esxMIXKEM56Is8hOgJRWFmHHHIYFt O95e8d6Wprbe5LAPMArHpOiazgMrDOgBxdNdOhdG5Ra+6eyn4cLkf44EdpcnxGVx2M7B /H8HrwK3MAApWRKAMhXmq+W0VESWhZg4Oe7nuqIY/P+B0kyFC7xDqRTGTxG6fvw+4l7c dskXAEbxinPW1Cr1RB8IyKjYE/0esCSDuC1BIQ0fGJwrcLgTXje+FVXUGMnK/qyWOxmB UbzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LCAGbzjQfd4JlaOjjKxUHcbjmkgk4JwloTjciGBlv28=; b=SazoUGCNpR5aBWqkVZeWEdB99u9HSdeWI3HcYvoR9CHly7FyXHfXpmD/5mqq2N895B ocUjolFxHQvkdhBh5+tYKBA/WeifOMuEDgHs4r/tUsOJ0hxbDbYM4S24EH9Xdr2DcDk8 xLWvd6Af/T5NmopwAotjSOaZ+Nm4ssfC/37tl9ZoamMpk3zyTekPDSrrve0o/ZIdsbiV 85JFFIR1UlbdHbgCv8ncTL54ammhMuOsAvOBcMCPsDy//tqJ/rcXmbYuFZPehRdAWZ5k 3hCEyveDBaOUgutkOVMZcwTeHVa+gEpXt489h1hjgxSnF/3DdStoJmUDUN/XaF71QrFM JIKA== X-Gm-Message-State: ANhLgQ14QnnjACCi8fopaCV2hRJP3+p64f7yRN9p98gE6A3XQmpJjyPu 2iFS5fCWQrpn4qc7p8SKhNKWFnhb X-Google-Smtp-Source: ADFU+vuOBTTg0DRV+kx/4nBnO86lbNIGtDuRvm6CAZ8PoJpE2YxRAmUt0jwPeGB5bdsNxL+z1tuZrQ== X-Received: by 2002:a17:902:463:: with SMTP id 90mr4300514ple.213.1584634384883; Thu, 19 Mar 2020 09:13:04 -0700 (PDT) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id x189sm3000078pfb.1.2020.03.19.09.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2020 09:13:03 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , =?utf-8?q?Horia_Geant=C4=83?= , Chris Healy , Lucas Stach , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v9 5/9] crypto: caam - check if RNG job failed Date: Thu, 19 Mar 2020 09:12:29 -0700 Message-Id: <20200319161233.8134-6-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200319161233.8134-1-andrew.smirnov@gmail.com> References: <20200319161233.8134-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org We shouldn't stay silent if RNG job fails. Add appropriate code to check for that case and propagate error code up appropriately. Signed-off-by: Andrey Smirnov Reviewed-by: Horia Geantă Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-imx@nxp.com --- drivers/crypto/caam/caamrng.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c index e64f2d77fa03..d0027d31e840 100644 --- a/drivers/crypto/caam/caamrng.c +++ b/drivers/crypto/caam/caamrng.c @@ -44,6 +44,11 @@ struct caam_rng_ctx { struct kfifo fifo; }; +struct caam_rng_job_ctx { + struct completion *done; + int *err; +}; + static struct caam_rng_ctx *to_caam_rng_ctx(struct hwrng *r) { return (struct caam_rng_ctx *)r->priv; @@ -52,12 +57,12 @@ static struct caam_rng_ctx *to_caam_rng_ctx(struct hwrng *r) static void caam_rng_done(struct device *jrdev, u32 *desc, u32 err, void *context) { - struct completion *done = context; + struct caam_rng_job_ctx *jctx = context; if (err) - caam_jr_strstatus(jrdev, err); + *jctx->err = caam_jr_strstatus(jrdev, err); - complete(done); + complete(jctx->done); } static u32 *caam_init_desc(u32 *desc, dma_addr_t dst_dma, int len) @@ -80,7 +85,11 @@ static int caam_rng_read_one(struct device *jrdev, struct completion *done) { dma_addr_t dst_dma; - int err; + int err, ret = 0; + struct caam_rng_job_ctx jctx = { + .done = done, + .err = &ret, + }; len = min_t(int, len, CAAM_RNG_MAX_FIFO_STORE_SIZE); @@ -93,7 +102,7 @@ static int caam_rng_read_one(struct device *jrdev, init_completion(done); err = caam_jr_enqueue(jrdev, caam_init_desc(desc, dst_dma, len), - caam_rng_done, done); + caam_rng_done, &jctx); if (err == -EINPROGRESS) { wait_for_completion(done); err = 0; @@ -101,7 +110,7 @@ static int caam_rng_read_one(struct device *jrdev, dma_unmap_single(jrdev, dst_dma, len, DMA_FROM_DEVICE); - return err ?: len; + return err ?: (ret ?: len); } static void caam_rng_fill_async(struct caam_rng_ctx *ctx) From patchwork Thu Mar 19 16:12:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 197967 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23498C4332B for ; Thu, 19 Mar 2020 16:13:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DDEF620663 for ; Thu, 19 Mar 2020 16:13:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DrcNObS3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728389AbgCSQNM (ORCPT ); Thu, 19 Mar 2020 12:13:12 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34394 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728377AbgCSQNL (ORCPT ); Thu, 19 Mar 2020 12:13:11 -0400 Received: by mail-pg1-f195.google.com with SMTP id t3so1531488pgn.1; Thu, 19 Mar 2020 09:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rqGhDfe/l3VrM3s9b0bpdG7gXHo9u6mXfCQLIUi04fc=; b=DrcNObS3h0a19UBO/Bk1ikFhx7Dv3h9vWztSpmnOZN/O3xQWtIJoFwvZ4WbxzZ+pFx 8sODoDvo1dIvuS0Rqqe0ca3BBLXbdrw5ZBX8XQofn/BGHIDBrITtsNSJ/N2Wp430FdYw HQ5j2ShSiRNswdlouMwx9Op1wj0RgUT9Mq+3gKOh3RL1Lz5YuV/epWbWFuY8qUdSRQVP 3c/VOJxeEgVNM64gLlSiE3GQ0eO6V7d6oeRikoUYAL6TfkAr25bSjp+sIO6rIn8Zj9b4 IrNt/ucSV0f9BgVF1R3fgQ5vQxR2B9v3hIi1UxXnZZ8wt7yUtGMgruEvzDGbYhiUIbMK PKvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rqGhDfe/l3VrM3s9b0bpdG7gXHo9u6mXfCQLIUi04fc=; b=XWT5nWVyK90xhOw7RiXyFjCKfTOX5p91CrYeQFdi8YI4BfLg+sPZ1eHsXF7d+9tM7n T2MUoPvpyBrROXYwdg9XHpLrzk3gWHEBrBReLpqdbl4GNo3Whd8hjSpEZg/2UZhfSqVX yqZHRI6dS3scNsqQP5/hwwPJ3BqZVFu111MKLuDLznOA55jtNHx2f2F6nobPOsBTkLvx yBpysV4yQDNoL9hWT2UFui8Rvc8YP0hFleZCXo3fXM9tROsgqWd5SPPjuzWDLE3Oym3v SvZPL2jYQEVwVIlE1cQpFKX2EEj413H6vfig8YtqZNXAj9zzS1Cm52T40whs/J7u1Hix AF2A== X-Gm-Message-State: ANhLgQ1QXYBKnDg0RcfnpSrRiLHcqU2jue5hEvhFC++fnfJSBrqgPeHo w17AJTujLu1ht97JpibRNbKZKTtd X-Google-Smtp-Source: ADFU+vs9RaTqIxpnTGtHvbkTOm5DPCfnXe1NVnZlOwDsjQFhfpB1jVnTisyuxGjygQettlYTFkd40w== X-Received: by 2002:a65:53c5:: with SMTP id z5mr4339151pgr.0.1584634389164; Thu, 19 Mar 2020 09:13:09 -0700 (PDT) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id x189sm3000078pfb.1.2020.03.19.09.13.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2020 09:13:08 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrei Botila , Laurentiu Tudor , =?utf-8?q?Horia_Geant=C4=83?= , Chris Healy , Lucas Stach , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v9 7/9] bus: fsl-mc: add api to retrieve mc version Date: Thu, 19 Mar 2020 09:12:31 -0700 Message-Id: <20200319161233.8134-8-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200319161233.8134-1-andrew.smirnov@gmail.com> References: <20200319161233.8134-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Andrei Botila Add a new api that returns Management Complex firmware version and make the required structure public. The api's first user will be the caam driver for setting prediction resistance bits. Signed-off-by: Andrei Botila Acked-by: Laurentiu Tudor Reviewed-by: Horia Geantă Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-imx@nxp.com --- drivers/bus/fsl-mc/fsl-mc-bus.c | 33 +++++++++++++++++---------------- include/linux/fsl/mc.h | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 16 deletions(-) -- 2.21.0 diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c index c78d10ea641f..40526da5c6a6 100644 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c @@ -26,6 +26,8 @@ */ #define FSL_MC_DEFAULT_DMA_MASK (~0ULL) +static struct fsl_mc_version mc_version; + /** * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device * @root_mc_bus_dev: fsl-mc device representing the root DPRC @@ -54,20 +56,6 @@ struct fsl_mc_addr_translation_range { phys_addr_t start_phys_addr; }; -/** - * struct mc_version - * @major: Major version number: incremented on API compatibility changes - * @minor: Minor version number: incremented on API additions (that are - * backward compatible); reset when major version is incremented - * @revision: Internal revision number: incremented on implementation changes - * and/or bug fixes that have no impact on API - */ -struct mc_version { - u32 major; - u32 minor; - u32 revision; -}; - /** * fsl_mc_bus_match - device to driver matching callback * @dev: the fsl-mc device to match against @@ -338,7 +326,7 @@ EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister); */ static int mc_get_version(struct fsl_mc_io *mc_io, u32 cmd_flags, - struct mc_version *mc_ver_info) + struct fsl_mc_version *mc_ver_info) { struct fsl_mc_command cmd = { 0 }; struct dpmng_rsp_get_version *rsp_params; @@ -363,6 +351,20 @@ static int mc_get_version(struct fsl_mc_io *mc_io, return 0; } +/** + * fsl_mc_get_version - function to retrieve the MC f/w version information + * + * Return: mc version when called after fsl-mc-bus probe; NULL otherwise. + */ +struct fsl_mc_version *fsl_mc_get_version(void) +{ + if (mc_version.major) + return &mc_version; + + return NULL; +} +EXPORT_SYMBOL_GPL(fsl_mc_get_version); + /** * fsl_mc_get_root_dprc - function to traverse to the root dprc */ @@ -862,7 +864,6 @@ static int fsl_mc_bus_probe(struct platform_device *pdev) int container_id; phys_addr_t mc_portal_phys_addr; u32 mc_portal_size; - struct mc_version mc_version; struct resource res; mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL); diff --git a/include/linux/fsl/mc.h b/include/linux/fsl/mc.h index 54d9436600c7..2b5f8366dbe1 100644 --- a/include/linux/fsl/mc.h +++ b/include/linux/fsl/mc.h @@ -381,6 +381,22 @@ int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver, void fsl_mc_driver_unregister(struct fsl_mc_driver *driver); +/** + * struct fsl_mc_version + * @major: Major version number: incremented on API compatibility changes + * @minor: Minor version number: incremented on API additions (that are + * backward compatible); reset when major version is incremented + * @revision: Internal revision number: incremented on implementation changes + * and/or bug fixes that have no impact on API + */ +struct fsl_mc_version { + u32 major; + u32 minor; + u32 revision; +}; + +struct fsl_mc_version *fsl_mc_get_version(void); + int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev, u16 mc_io_flags, struct fsl_mc_io **new_mc_io); From patchwork Thu Mar 19 16:12:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 197968 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77250C4332B for ; Thu, 19 Mar 2020 16:13:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 38F4420663 for ; Thu, 19 Mar 2020 16:13:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sXSjf7Ls" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728377AbgCSQNO (ORCPT ); Thu, 19 Mar 2020 12:13:14 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40871 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728401AbgCSQNN (ORCPT ); Thu, 19 Mar 2020 12:13:13 -0400 Received: by mail-pg1-f195.google.com with SMTP id t24so1514455pgj.7; Thu, 19 Mar 2020 09:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FiKO51yZRWULjDGY5wnf3hkkAgzr8tUWTiT1ZM0mT7M=; b=sXSjf7Ls9veGacD+TgWAvUyp4l6bSZQWsv40elLUsK/p6d2GPxxYnVHIm8qD+N9bKb inzU9pBZaLjMxpup6GpU3HUgElOxvqgHZLt+wSrgPSXTfL+dHabo6+Sljr5V4xBsgB7b 8yMeWRp+7LyfvafKf0aYcUElJxyD59RWkNVTKbpQRcIP2CMC8ghIlv/RaBKjM4mmX7NC 0MURSwEoV0/NaVWyoHZRInI/AzyPdNuWs/geLRyeeVC6FJBdjtogdDyi88Dva9Zf2Bor 6Fr9dBHeWOy9UAXLLTok37ovobgd6gsRXMnnTqpBgCtpBfaew+ckPJlGSKkuz8lGCizQ sguA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FiKO51yZRWULjDGY5wnf3hkkAgzr8tUWTiT1ZM0mT7M=; b=lDHXKyhj6C6zLKwCnBvztvHr2ZWeJkz7OMXWfQ/V6KqgJvXgBUnBwECa9u3g4jxD5T ujhIOS5dS+sqgcY8C19lWTGEaOqIToqjwlVaJMXRPbB2JP4OjNi/hUK7kWVswJQh9X5d 5WZgWHII7QhlxQNH9cNo5tpDtGnMcIiGT2lxTeDohEyu8vM1JJzmUQLGSb/qC2rZrzzJ KRzF4wGeV1/hE0bbJQmE8eMCQQC2Qa06lofgWu1VtFZivMKVbkPc20qR59QtdilHhqxV RrmqUsrq+RqHqYyEDWuRGqdPeeAjJDz5MamCh9HoSm520go3gxuxgMxm9HoChoBPOqMZ lC+g== X-Gm-Message-State: ANhLgQ2kEfCTkoJZ2EJDuylkKyqaWLeDVSJblDorjOhmcunzbbaBsacO YwB1ewR2HCNH2T3cgREgcGfgTN2d X-Google-Smtp-Source: ADFU+vve9/tAQCBZDnCNxNc+GvI2Nw6y00elRzQwhkQO4JlhOWEQSHN+lj0uJzC0t+Z4CHfeF7NJMw== X-Received: by 2002:a65:6810:: with SMTP id l16mr4226864pgt.248.1584634391389; Thu, 19 Mar 2020 09:13:11 -0700 (PDT) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id x189sm3000078pfb.1.2020.03.19.09.13.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2020 09:13:10 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Andrei Botila , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v9 8/9] crypto: caam - enable prediction resistance in HRWNG Date: Thu, 19 Mar 2020 09:12:32 -0700 Message-Id: <20200319161233.8134-9-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200319161233.8134-1-andrew.smirnov@gmail.com> References: <20200319161233.8134-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instantiate CAAM RNG with prediction resistance enabled to improve its quality (with PR on DRNG is forced to reseed from TRNG every time random data is generated). Management Complex firmware with version lower than 10.20.0 doesn't provide prediction resistance support. Consider this and only instantiate rng when mc f/w version is lower. Signed-off-by: Andrey Smirnov Signed-off-by: Andrei Botila Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-imx@nxp.com --- drivers/crypto/caam/Kconfig | 1 + drivers/crypto/caam/caamrng.c | 3 +- drivers/crypto/caam/ctrl.c | 73 ++++++++++++++++++++++++++++------- drivers/crypto/caam/desc.h | 2 + drivers/crypto/caam/regs.h | 4 +- 5 files changed, 68 insertions(+), 15 deletions(-) diff --git a/drivers/crypto/caam/Kconfig b/drivers/crypto/caam/Kconfig index 64f82263b20e..a62f228be6da 100644 --- a/drivers/crypto/caam/Kconfig +++ b/drivers/crypto/caam/Kconfig @@ -13,6 +13,7 @@ config CRYPTO_DEV_FSL_CAAM depends on FSL_SOC || ARCH_MXC || ARCH_LAYERSCAPE select SOC_BUS select CRYPTO_DEV_FSL_CAAM_COMMON + imply FSL_MC_BUS help Enables the driver module for Freescale's Cryptographic Accelerator and Assurance Module (CAAM), also known as the SEC version 4 (SEC4). diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c index d0027d31e840..988bfddbadc6 100644 --- a/drivers/crypto/caam/caamrng.c +++ b/drivers/crypto/caam/caamrng.c @@ -69,7 +69,8 @@ static u32 *caam_init_desc(u32 *desc, dma_addr_t dst_dma, int len) { 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); + append_operation(desc, OP_ALG_ALGSEL_RNG | OP_TYPE_CLASS1_ALG | + OP_ALG_PR_ON); /* Store bytes: + 1 cmd_sz + caam_ptr_sz */ append_fifo_store(desc, dst_dma, len, FIFOST_TYPE_RNGSTORE); diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index b278471f4013..4fcdd262e581 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "compat.h" #include "regs.h" @@ -36,7 +37,8 @@ static void build_instantiation_desc(u32 *desc, int handle, int do_sk) init_job_desc(desc, 0); op_flags = OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG | - (handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INIT; + (handle << OP_ALG_AAI_SHIFT) | OP_ALG_AS_INIT | + OP_ALG_PR_ON; /* INIT RNG in non-test mode */ append_operation(desc, op_flags); @@ -278,12 +280,25 @@ static int instantiate_rng(struct device *ctrldev, int state_handle_mask, return -ENOMEM; for (sh_idx = 0; sh_idx < RNG4_MAX_HANDLES; sh_idx++) { + const u32 rdsta_if = RDSTA_IF0 << sh_idx; + const u32 rdsta_pr = RDSTA_PR0 << sh_idx; + const u32 rdsta_mask = rdsta_if | rdsta_pr; /* * If the corresponding bit is set, this state handle * was initialized by somebody else, so it's left alone. */ - if ((1 << sh_idx) & state_handle_mask) - continue; + if (rdsta_if & state_handle_mask) { + if (rdsta_pr & state_handle_mask) + continue; + + dev_info(ctrldev, + "RNG4 SH%d was previously instantiated without prediction resistance. Tearing it down\n", + sh_idx); + + ret = deinstantiate_rng(ctrldev, rdsta_if); + if (ret) + break; + } /* Create the descriptor for instantiating RNG State Handle */ build_instantiation_desc(desc, sh_idx, gen_sk); @@ -303,9 +318,9 @@ static int instantiate_rng(struct device *ctrldev, int state_handle_mask, if (ret) break; - rdsta_val = rd_reg32(&ctrl->r4tst[0].rdsta) & RDSTA_IFMASK; + rdsta_val = rd_reg32(&ctrl->r4tst[0].rdsta) & RDSTA_MASK; if ((status && status != JRSTA_SSRC_JUMP_HALT_CC) || - !(rdsta_val & (1 << sh_idx))) { + (rdsta_val & rdsta_mask) != rdsta_mask) { ret = -EAGAIN; break; } @@ -564,6 +579,26 @@ static void caam_remove_debugfs(void *root) } #endif +#ifdef CONFIG_FSL_MC_BUS +static bool check_version(struct fsl_mc_version *mc_version, u32 major, + u32 minor, u32 revision) +{ + if (mc_version->major > major) + return true; + + if (mc_version->major == major) { + if (mc_version->minor > minor) + return true; + + if (mc_version->minor == minor && + mc_version->revision > revision) + return true; + } + + return false; +} +#endif + /* Probe routine for CAAM top (controller) level */ static int caam_probe(struct platform_device *pdev) { @@ -582,6 +617,7 @@ static int caam_probe(struct platform_device *pdev) u8 rng_vid; int pg_size; int BLOCK_OFFSET = 0; + bool pr_support = false; ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL); if (!ctrlpriv) @@ -667,6 +703,21 @@ static int caam_probe(struct platform_device *pdev) /* Get the IRQ of the controller (for security violations only) */ ctrlpriv->secvio_irq = irq_of_parse_and_map(nprop, 0); + np = of_find_compatible_node(NULL, NULL, "fsl,qoriq-mc"); + ctrlpriv->mc_en = !!np; + of_node_put(np); + +#ifdef CONFIG_FSL_MC_BUS + if (ctrlpriv->mc_en) { + struct fsl_mc_version *mc_version; + + mc_version = fsl_mc_get_version(); + if (mc_version) + pr_support = check_version(mc_version, 10, 20, 0); + else + return -EPROBE_DEFER; + } +#endif /* * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel, @@ -674,10 +725,6 @@ static int caam_probe(struct platform_device *pdev) * In case of SoCs with Management Complex, MC f/w performs * the configuration. */ - np = of_find_compatible_node(NULL, NULL, "fsl,qoriq-mc"); - ctrlpriv->mc_en = !!np; - of_node_put(np); - if (!ctrlpriv->mc_en) clrsetbits_32(&ctrl->mcr, MCFGR_AWCACHE_MASK, MCFGR_AWCACHE_CACH | MCFGR_AWCACHE_BUFF | @@ -784,7 +831,7 @@ static int caam_probe(struct platform_device *pdev) * already instantiated, do RNG instantiation * In case of SoCs with Management Complex, RNG is managed by MC f/w. */ - if (!ctrlpriv->mc_en && rng_vid >= 4) { + if (!(ctrlpriv->mc_en && pr_support) && rng_vid >= 4) { ctrlpriv->rng4_sh_init = rd_reg32(&ctrl->r4tst[0].rdsta); /* @@ -794,11 +841,11 @@ static int caam_probe(struct platform_device *pdev) * to regenerate these keys before the next POR. */ gen_sk = ctrlpriv->rng4_sh_init & RDSTA_SKVN ? 0 : 1; - ctrlpriv->rng4_sh_init &= RDSTA_IFMASK; + ctrlpriv->rng4_sh_init &= RDSTA_MASK; do { int inst_handles = rd_reg32(&ctrl->r4tst[0].rdsta) & - RDSTA_IFMASK; + RDSTA_MASK; /* * If either SH were instantiated by somebody else * (e.g. u-boot) then it is assumed that the entropy @@ -838,7 +885,7 @@ static int caam_probe(struct platform_device *pdev) * Set handles init'ed by this module as the complement of the * already initialized ones */ - ctrlpriv->rng4_sh_init = ~ctrlpriv->rng4_sh_init & RDSTA_IFMASK; + ctrlpriv->rng4_sh_init = ~ctrlpriv->rng4_sh_init & RDSTA_MASK; /* Enable RDB bit so that RNG works faster */ clrsetbits_32(&ctrl->scfgr, 0, SCFGR_RDBENABLE); diff --git a/drivers/crypto/caam/desc.h b/drivers/crypto/caam/desc.h index 4b6854bf896a..e796d3cb9be8 100644 --- a/drivers/crypto/caam/desc.h +++ b/drivers/crypto/caam/desc.h @@ -1254,6 +1254,8 @@ #define OP_ALG_ICV_OFF (0 << OP_ALG_ICV_SHIFT) #define OP_ALG_ICV_ON (1 << OP_ALG_ICV_SHIFT) +#define OP_ALG_PR_ON BIT(1) + #define OP_ALG_DIR_SHIFT 0 #define OP_ALG_DIR_MASK 1 #define OP_ALG_DECRYPT 0 diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h index c191e8fd0fa7..0f810bc13b2b 100644 --- a/drivers/crypto/caam/regs.h +++ b/drivers/crypto/caam/regs.h @@ -524,9 +524,11 @@ struct rng4tst { u32 rsvd1[40]; #define RDSTA_SKVT 0x80000000 #define RDSTA_SKVN 0x40000000 +#define RDSTA_PR0 BIT(4) +#define RDSTA_PR1 BIT(5) #define RDSTA_IF0 0x00000001 #define RDSTA_IF1 0x00000002 -#define RDSTA_IFMASK (RDSTA_IF1 | RDSTA_IF0) +#define RDSTA_MASK (RDSTA_PR1 | RDSTA_PR0 | RDSTA_IF1 | RDSTA_IF0) u32 rdsta; u32 rsvd2[15]; };