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: 13364595 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A128C6FA8F for ; Thu, 24 Aug 2023 19:24:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4lqJjAqOk+8RiX3WrYHZCSn8YaGp02/lokmOXe8xvi0=; b=U7seFq+Zvw8zj0 YfMLFe0z1np65ASjC1fPa1fmXSXTOt1is2oa5Zmyn4P6ve79RIHXh4TebtJvca/jJjsRuAk8KWsrA nKL4VVORdC7oB2YxWSM5QIP79bJ5xmH2O7iGzvpTFz/IK7HjzLnidp4A+1Wu2w78DM03fiAtqJNcy O05lPrHkrIAqTRCSXJJ2Kkm2BtfZThPeXWq+S2S0EqPPeRCHru3yVsqROqwgHa8DSeWRXhzM4r4Cp l6stkc6Gk6Gzf8hQ0TF+YEZWF1JyBKGMmLnN1+CywK0L6pcsSreqZ6jPIkcP+6KXLU/fX6StkfSJr f+kbB4KHE8Rom2zenazA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZFwC-003ew6-1b; Thu, 24 Aug 2023 19:24:12 +0000 Received: from viti.kaiser.cx ([2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZFvt-003er2-0J for linux-arm-kernel@lists.infradead.org; Thu, 24 Aug 2023 19:23:55 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_122353_276796_CBCC67DF X-CRM114-Status: GOOD ( 12.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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)