From patchwork Thu Aug 24 19:20:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 13364583 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4AE4C7EE2C for ; Thu, 24 Aug 2023 19:24:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243174AbjHXTYI (ORCPT ); Thu, 24 Aug 2023 15:24:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242991AbjHXTXv (ORCPT ); Thu, 24 Aug 2023 15:23:51 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF95A1BE5; Thu, 24 Aug 2023 12:23:48 -0700 (PDT) Received: from dslb-188-097-211-187.188.097.pools.vodafone-ip.de ([188.97.211.187] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1qZFvi-00036P-8z; Thu, 24 Aug 2023 21:23:42 +0200 From: Martin Kaiser To: Herbert Xu Cc: Alexander Stein , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH v2 1/6] hwrng: imx-rngc - reasonable timeout for selftest Date: Thu, 24 Aug 2023 21:20:54 +0200 Message-Id: <20230824192059.1569591-2-martin@kaiser.cx> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230824192059.1569591-1-martin@kaiser.cx> References: <20230824192059.1569591-1-martin@kaiser.cx> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Set a more reasonable timeout for the rngc selftest. According to the reference manual, "The self test takes approximately 29,000 cycles to complete." With the rngc peripheral clock running at 66.5 MHz, this would be 436us. Let's use 1.5ms insteaf of 3sec for the timeout. Signed-off-by: Martin Kaiser --- v2: - adjust timeouts before we switch to polling drivers/char/hw_random/imx-rngc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c index e4b385b01b11..6024c923b67d 100644 --- a/drivers/char/hw_random/imx-rngc.c +++ b/drivers/char/hw_random/imx-rngc.c @@ -53,6 +53,7 @@ #define RNGC_TIMEOUT 3000 /* 3 sec */ +#define RNGC_SELFTEST_TIMEOUT 1500 /* us */ static bool self_test = true; module_param(self_test, bool, 0); @@ -110,7 +111,8 @@ static int imx_rngc_self_test(struct imx_rngc *rngc) cmd = readl(rngc->base + RNGC_COMMAND); writel(cmd | RNGC_CMD_SELF_TEST, rngc->base + RNGC_COMMAND); - ret = wait_for_completion_timeout(&rngc->rng_op_done, msecs_to_jiffies(RNGC_TIMEOUT)); + ret = wait_for_completion_timeout(&rngc->rng_op_done, + usecs_to_jiffies(RNGC_SELFTEST_TIMEOUT)); imx_rngc_irq_mask_clear(rngc); if (!ret) return -ETIMEDOUT; From patchwork Thu Aug 24 19:20:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 13364585 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30025C88CB9 for ; Thu, 24 Aug 2023 19:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243171AbjHXTYI (ORCPT ); Thu, 24 Aug 2023 15:24:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243164AbjHXTXv (ORCPT ); Thu, 24 Aug 2023 15:23:51 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFB731BEB; Thu, 24 Aug 2023 12:23:48 -0700 (PDT) Received: from dslb-188-097-211-187.188.097.pools.vodafone-ip.de ([188.97.211.187] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1qZFvj-00036P-5D; Thu, 24 Aug 2023 21:23:43 +0200 From: Martin Kaiser To: Herbert Xu Cc: Alexander Stein , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH v2 2/6] hwrng: imx-rngc - reasonable timeout for initial seed Date: Thu, 24 Aug 2023 21:20:55 +0200 Message-Id: <20230824192059.1569591-3-martin@kaiser.cx> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230824192059.1569591-1-martin@kaiser.cx> References: <20230824192059.1569591-1-martin@kaiser.cx> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Set a more reasonable timeout for calculating the initial seed. The reference manuals says that "The initial seed takes approximately 2,000,000 clock cycles." If the rngc peripheral clock runs at 66.5MHz, this is approx. 30ms. A timeout of 100ms is more appropriate that the current value of 3 seconds. We define the timeout in us to simplify the transition to readl_poll_timeout. Signed-off-by: Martin Kaiser --- v2: - adjust timeouts before we switch to polling drivers/char/hw_random/imx-rngc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c index 6024c923b67d..8ff3d46674fd 100644 --- a/drivers/char/hw_random/imx-rngc.c +++ b/drivers/char/hw_random/imx-rngc.c @@ -51,9 +51,8 @@ #define RNGC_ERROR_STATUS_STAT_ERR 0x00000008 -#define RNGC_TIMEOUT 3000 /* 3 sec */ - -#define RNGC_SELFTEST_TIMEOUT 1500 /* us */ +#define RNGC_SELFTEST_TIMEOUT 1500 /* us */ +#define RNGC_SEED_TIMEOUT 100000 /* us */ static bool self_test = true; module_param(self_test, bool, 0); @@ -184,7 +183,8 @@ static int imx_rngc_init(struct hwrng *rng) cmd = readl(rngc->base + RNGC_COMMAND); writel(cmd | RNGC_CMD_SEED, rngc->base + RNGC_COMMAND); - ret = wait_for_completion_timeout(&rngc->rng_op_done, msecs_to_jiffies(RNGC_TIMEOUT)); + ret = wait_for_completion_timeout(&rngc->rng_op_done, + usecs_to_jiffies(RNGC_SEED_TIMEOUT)); if (!ret) { ret = -ETIMEDOUT; goto err; From patchwork Thu Aug 24 19:20:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 13364586 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 442E0C88CB2 for ; Thu, 24 Aug 2023 19:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243166AbjHXTYI (ORCPT ); Thu, 24 Aug 2023 15:24:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243158AbjHXTXv (ORCPT ); Thu, 24 Aug 2023 15:23:51 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFBBF1BEC; Thu, 24 Aug 2023 12:23:48 -0700 (PDT) Received: from dslb-188-097-211-187.188.097.pools.vodafone-ip.de ([188.97.211.187] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1qZFvj-00036P-Ud; Thu, 24 Aug 2023 21:23:44 +0200 From: Martin Kaiser To: Herbert Xu Cc: Alexander Stein , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH v2 3/6] hwrng: imx-rngc - use polling to detect end of self test Date: Thu, 24 Aug 2023 21:20:56 +0200 Message-Id: <20230824192059.1569591-4-martin@kaiser.cx> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230824192059.1569591-1-martin@kaiser.cx> References: <20230824192059.1569591-1-martin@kaiser.cx> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use polling to detect the end of the rngc self test. This is much simpler than using an interrupt and a completion. The selftest should take approx. 450us. Keep the overhead to a minimum by polling every 500us. (We've already lowered the timeout to 1.5ms.) Signed-off-by: Martin Kaiser --- v2: - use shorter timeout and polling interval drivers/char/hw_random/imx-rngc.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c index 8ff3d46674fd..09523936d2af 100644 --- a/drivers/char/hw_random/imx-rngc.c +++ b/drivers/char/hw_random/imx-rngc.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #define RNGC_VER_ID 0x0000 @@ -101,22 +102,19 @@ static inline void imx_rngc_irq_unmask(struct imx_rngc *rngc) static int imx_rngc_self_test(struct imx_rngc *rngc) { - u32 cmd; + u32 cmd, status; int ret; - imx_rngc_irq_unmask(rngc); - /* run self test */ cmd = readl(rngc->base + RNGC_COMMAND); writel(cmd | RNGC_CMD_SELF_TEST, rngc->base + RNGC_COMMAND); - ret = wait_for_completion_timeout(&rngc->rng_op_done, - usecs_to_jiffies(RNGC_SELFTEST_TIMEOUT)); - imx_rngc_irq_mask_clear(rngc); - if (!ret) - return -ETIMEDOUT; + ret = readl_poll_timeout(rngc->base + RNGC_STATUS, status, + status & RNGC_STATUS_ST_DONE, 500, RNGC_SELFTEST_TIMEOUT); + if (ret < 0) + return ret; - return rngc->err_reg ? -EIO : 0; + return readl(rngc->base + RNGC_ERROR) ? -EIO : 0; } static int imx_rngc_read(struct hwrng *rng, void *data, size_t max, bool wait) From patchwork Thu Aug 24 19:20:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 13364584 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0BC6C71153 for ; Thu, 24 Aug 2023 19:24:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243178AbjHXTYJ (ORCPT ); Thu, 24 Aug 2023 15:24:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243061AbjHXTXv (ORCPT ); Thu, 24 Aug 2023 15:23:51 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF8DD1BE2; Thu, 24 Aug 2023 12:23:48 -0700 (PDT) Received: from dslb-188-097-211-187.188.097.pools.vodafone-ip.de ([188.97.211.187] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1qZFvk-00036P-Nc; Thu, 24 Aug 2023 21:23:44 +0200 From: Martin Kaiser To: Herbert Xu Cc: Alexander Stein , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH v2 4/6] hwrng: imx-rngc - read status register for error checks Date: Thu, 24 Aug 2023 21:20:57 +0200 Message-Id: <20230824192059.1569591-5-martin@kaiser.cx> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230824192059.1569591-1-martin@kaiser.cx> References: <20230824192059.1569591-1-martin@kaiser.cx> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The error bit in the status register of the imx-rngc is set for any kind of error. Details about the error can be read from the bits in the error status register. In the imx_rngc_self_test function, we just need the info if there was an error or not. We can check the status register, there's no need to read the error status register. Signed-off-by: Martin Kaiser --- drivers/char/hw_random/imx-rngc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c index 09523936d2af..c2582673427d 100644 --- a/drivers/char/hw_random/imx-rngc.c +++ b/drivers/char/hw_random/imx-rngc.c @@ -114,7 +114,7 @@ static int imx_rngc_self_test(struct imx_rngc *rngc) if (ret < 0) return ret; - return readl(rngc->base + RNGC_ERROR) ? -EIO : 0; + return (status & RNGC_STATUS_ERROR) ? -EIO : 0; } static int imx_rngc_read(struct hwrng *rng, void *data, size_t max, bool wait) From patchwork Thu Aug 24 19:20:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 13364587 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93D41EE49A6 for ; Thu, 24 Aug 2023 19:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243181AbjHXTYJ (ORCPT ); Thu, 24 Aug 2023 15:24:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234088AbjHXTXu (ORCPT ); Thu, 24 Aug 2023 15:23:50 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF1951BDF; Thu, 24 Aug 2023 12:23:48 -0700 (PDT) Received: from dslb-188-097-211-187.188.097.pools.vodafone-ip.de ([188.97.211.187] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1qZFvl-00036P-Io; Thu, 24 Aug 2023 21:23:45 +0200 From: Martin Kaiser To: Herbert Xu Cc: Alexander Stein , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH v2 5/6] hwrng: imx-rngc - use polling for initial seed Date: Thu, 24 Aug 2023 21:20:58 +0200 Message-Id: <20230824192059.1569591-6-martin@kaiser.cx> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230824192059.1569591-1-martin@kaiser.cx> References: <20230824192059.1569591-1-martin@kaiser.cx> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use polling instead of interrupt + completion to wait until the initial seed was calculated. This should take about 30ms. Call readl_poll_timeout and set the poll interval to the recommended maximum of 20ms. readl_poll_timeout uses usleep_range, this is based on a hrtimer. The task will we put to sleep while waiting, this does not burn CPU cycles by waiting in the foreground. Signed-off-by: Martin Kaiser --- v2: - use shorter timeout and polling interval - readl_poll_timeout does not wait in the foreground drivers/char/hw_random/imx-rngc.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c index c2582673427d..3a3f0f923bed 100644 --- a/drivers/char/hw_random/imx-rngc.c +++ b/drivers/char/hw_random/imx-rngc.c @@ -166,34 +166,29 @@ static irqreturn_t imx_rngc_irq(int irq, void *priv) static int imx_rngc_init(struct hwrng *rng) { struct imx_rngc *rngc = container_of(rng, struct imx_rngc, rng); - u32 cmd, ctrl; + u32 cmd, ctrl, status, err_reg; int ret; /* clear error */ cmd = readl(rngc->base + RNGC_COMMAND); writel(cmd | RNGC_CMD_CLR_ERR, rngc->base + RNGC_COMMAND); - imx_rngc_irq_unmask(rngc); - /* create seed, repeat while there is some statistical error */ do { /* seed creation */ cmd = readl(rngc->base + RNGC_COMMAND); writel(cmd | RNGC_CMD_SEED, rngc->base + RNGC_COMMAND); - ret = wait_for_completion_timeout(&rngc->rng_op_done, - usecs_to_jiffies(RNGC_SEED_TIMEOUT)); - if (!ret) { - ret = -ETIMEDOUT; - goto err; - } + ret = readl_poll_timeout(rngc->base + RNGC_STATUS, status, + status & RNGC_STATUS_SEED_DONE, 20000, RNGC_SEED_TIMEOUT); + if (ret < 0) + return ret; - } while (rngc->err_reg == RNGC_ERROR_STATUS_STAT_ERR); + err_reg = readl(rngc->base + RNGC_ERROR); + } while (err_reg == RNGC_ERROR_STATUS_STAT_ERR); - if (rngc->err_reg) { - ret = -EIO; - goto err; - } + if (err_reg) + return -EIO; /* * enable automatic seeding, the rngc creates a new seed automatically @@ -209,10 +204,6 @@ static int imx_rngc_init(struct hwrng *rng) * we mask the interrupt ourselves if we return an error */ return 0; - -err: - imx_rngc_irq_mask_clear(rngc); - return ret; } static void imx_rngc_cleanup(struct hwrng *rng) From patchwork Thu Aug 24 19:20:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 13364588 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66719EE4993 for ; Thu, 24 Aug 2023 19:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243164AbjHXTYJ (ORCPT ); Thu, 24 Aug 2023 15:24:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243165AbjHXTXv (ORCPT ); Thu, 24 Aug 2023 15:23:51 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFA361BE9; Thu, 24 Aug 2023 12:23:48 -0700 (PDT) Received: from dslb-188-097-211-187.188.097.pools.vodafone-ip.de ([188.97.211.187] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1qZFvm-00036P-E7; Thu, 24 Aug 2023 21:23:46 +0200 From: Martin Kaiser To: Herbert Xu Cc: Alexander Stein , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH v2 6/6] hwrng: imx-rngc - remove interrupt handler Date: Thu, 24 Aug 2023 21:20:59 +0200 Message-Id: <20230824192059.1569591-7-martin@kaiser.cx> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230824192059.1569591-1-martin@kaiser.cx> References: <20230824192059.1569591-1-martin@kaiser.cx> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Remove the interrupt handler and the code for its installation and cleanup. We use readl_poll_timeout now for the selftest and the initial seed. There are no more users of the interrupt. Signed-off-by: Martin Kaiser --- v2: - separate commit for removing irq code drivers/char/hw_random/imx-rngc.c | 55 ------------------------------- 1 file changed, 55 deletions(-) diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c index 3a3f0f923bed..7fe09c59ce19 100644 --- a/drivers/char/hw_random/imx-rngc.c +++ b/drivers/char/hw_random/imx-rngc.c @@ -63,12 +63,6 @@ struct imx_rngc { struct clk *clk; void __iomem *base; struct hwrng rng; - struct completion rng_op_done; - /* - * err_reg is written only by the irq handler and read only - * when interrupts are masked, we need no spinlock - */ - u32 err_reg; }; @@ -91,15 +85,6 @@ static inline void imx_rngc_irq_mask_clear(struct imx_rngc *rngc) writel(cmd, rngc->base + RNGC_COMMAND); } -static inline void imx_rngc_irq_unmask(struct imx_rngc *rngc) -{ - u32 ctrl; - - ctrl = readl(rngc->base + RNGC_CONTROL); - ctrl &= ~(RNGC_CTRL_MASK_DONE | RNGC_CTRL_MASK_ERROR); - writel(ctrl, rngc->base + RNGC_CONTROL); -} - static int imx_rngc_self_test(struct imx_rngc *rngc) { u32 cmd, status; @@ -143,26 +128,6 @@ static int imx_rngc_read(struct hwrng *rng, void *data, size_t max, bool wait) return retval ? retval : -EIO; } -static irqreturn_t imx_rngc_irq(int irq, void *priv) -{ - struct imx_rngc *rngc = (struct imx_rngc *)priv; - u32 status; - - /* - * clearing the interrupt will also clear the error register - * read error and status before clearing - */ - status = readl(rngc->base + RNGC_STATUS); - rngc->err_reg = readl(rngc->base + RNGC_ERROR); - - imx_rngc_irq_mask_clear(rngc); - - if (status & (RNGC_STATUS_SEED_DONE | RNGC_STATUS_ST_DONE)) - complete(&rngc->rng_op_done); - - return IRQ_HANDLED; -} - static int imx_rngc_init(struct hwrng *rng) { struct imx_rngc *rngc = container_of(rng, struct imx_rngc, rng); @@ -198,21 +163,9 @@ static int imx_rngc_init(struct hwrng *rng) ctrl |= RNGC_CTRL_AUTO_SEED; writel(ctrl, rngc->base + RNGC_CONTROL); - /* - * if initialisation was successful, we keep the interrupt - * unmasked until imx_rngc_cleanup is called - * we mask the interrupt ourselves if we return an error - */ return 0; } -static void imx_rngc_cleanup(struct hwrng *rng) -{ - struct imx_rngc *rngc = container_of(rng, struct imx_rngc, rng); - - imx_rngc_irq_mask_clear(rngc); -} - static int __init imx_rngc_probe(struct platform_device *pdev) { struct imx_rngc *rngc; @@ -246,12 +199,9 @@ static int __init imx_rngc_probe(struct platform_device *pdev) if (rng_type != RNGC_TYPE_RNGC && rng_type != RNGC_TYPE_RNGB) return -ENODEV; - init_completion(&rngc->rng_op_done); - rngc->rng.name = pdev->name; rngc->rng.init = imx_rngc_init; rngc->rng.read = imx_rngc_read; - rngc->rng.cleanup = imx_rngc_cleanup; rngc->rng.quality = 19; rngc->dev = &pdev->dev; @@ -259,11 +209,6 @@ static int __init imx_rngc_probe(struct platform_device *pdev) imx_rngc_irq_mask_clear(rngc); - ret = devm_request_irq(&pdev->dev, - irq, imx_rngc_irq, 0, pdev->name, (void *)rngc); - if (ret) - return dev_err_probe(&pdev->dev, ret, "Can't get interrupt working.\n"); - if (self_test) { ret = imx_rngc_self_test(rngc); if (ret)