Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2037545rwl; Fri, 6 Jan 2023 00:40:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXsffkDYAFQTbe9ieKs/B0bvZCMlbbj2JlTupJNPsT/uhY0EZ+ZS/ktYmcdOAzLRZ7H5kcbG X-Received: by 2002:aa7:d7c2:0:b0:472:cee9:bbd3 with SMTP id e2-20020aa7d7c2000000b00472cee9bbd3mr48607012eds.27.1672994435610; Fri, 06 Jan 2023 00:40:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672994435; cv=none; d=google.com; s=arc-20160816; b=dumfhrgFKiXsa5beUTtc5nJHHeGMRSX45kgA8YQ6KeYxG3kQSHjZXQ0VzXcSn4R39P W7EMnq41AZTJELgeIkn0ZAMWJnXVjQpLHm86VAtryqY+fQMgEXeN8xbHZeoLpOoPyw6V Z4SOPhGSMX/Ltz3Pax+5rnJ17wJj3VqrCOz8Zgbqe+W1oQ5Pe1yZlH/4XpnjV8HQCVng kmi91BNWU8mN9e0wM0K/lQNDmW1iuG0JdCJKjuDAF5pOU3X6dmI2cgE1QxcdKjqhrqNC ppz++zMFv/K1SSsLOjEtkKZ/ksRoObtbNqGKkJpbBTA/m3zb1foVwpjLNPb9921sEtEh Bzyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=9qNuTJqgk0EMlx2MaeJmA+6o5k8b9qEf18HUvxMo/jE=; b=L7MdHLwKl5ltI7MfmWBtm1vWrk8y08NauhjqtXWT7FWomQcZtNEuaUyjhcQS26oyJI /d8JMs2Oabjcsa6+au9FOSOXEVTDI4cp/IKehOUxMCtWgdHo7VQerSvwmRsEUI2UszaY BVaLF3vpNxQcquCB2pNbUwEfHNDmrl0kfzzGYtl3k9ZAUm3Xy71HYRpxkFR4Ora2g56n 5hX9ufDd6ZmidAmCJKVrN5J729ZmAe6cw3Z0mVFq72Tam+NNLZwHCoBcGECJynw5xV1d ul/SszwUVSYJ9mt1OWdVQLrNTfIB7TOPLsvXmLmml90PMa6lT2XTq6ssdwvXuAnJtU++ HVkA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020a05640205ca00b00483a725a827si1072538edx.412.2023.01.06.00.40.10; Fri, 06 Jan 2023 00:40:35 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230344AbjAFIkI (ORCPT + 99 others); Fri, 6 Jan 2023 03:40:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjAFIjv (ORCPT ); Fri, 6 Jan 2023 03:39:51 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 054F7F30; Fri, 6 Jan 2023 00:39:49 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1pDiG4-00EV7i-2e; Fri, 06 Jan 2023 16:39:25 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 06 Jan 2023 16:39:24 +0800 Date: Fri, 6 Jan 2023 16:39:24 +0800 From: Herbert Xu To: Jia Jie Ho Cc: Olivia Mackall , Rob Herring , Krzysztof Kozlowski , Emil Renner Berthing , Conor Dooley , linux-crypto@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v2 2/3] hwrng: starfive - Add TRNG driver for StarFive SoC Message-ID: References: <20221228071103.91797-1-jiajie.ho@starfivetech.com> <20221228071103.91797-3-jiajie.ho@starfivetech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221228071103.91797-3-jiajie.ho@starfivetech.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 On Wed, Dec 28, 2022 at 03:11:02PM +0800, Jia Jie Ho wrote: > > +static int starfive_trng_cmd(struct starfive_trng *trng, u32 cmd) > +{ > + int ret; > + > + ret = starfive_trng_wait_idle(trng); > + if (ret) > + return -ETIMEDOUT; > + > + switch (cmd) { > + case STARFIVE_CTRL_EXEC_NOP: > + writel(cmd, trng->base + STARFIVE_CTRL); > + break; > + case STARFIVE_CTRL_GENE_RANDNUM: > + reinit_completion(&trng->random_done); > + writel(cmd, trng->base + STARFIVE_CTRL); > + ret = wait_for_completion_timeout(&trng->random_done, 3000); Please don't use a constant jiffies value, because it may vary in length. Instead use a constant millisecond value and convert it to jiffies. > +static irqreturn_t starfive_trng_irq(int irq, void *priv) > +{ > + u32 status; > + struct starfive_trng *trng = (struct starfive_trng *)priv; > + > + status = readl(trng->base + STARFIVE_ISTAT); > + if (status & STARFIVE_ISTAT_RAND_RDY) { > + writel(STARFIVE_ISTAT_RAND_RDY, trng->base + STARFIVE_ISTAT); > + complete(&trng->random_done); > + } > + > + if (status & STARFIVE_ISTAT_SEED_DONE) { > + writel(STARFIVE_ISTAT_SEED_DONE, trng->base + STARFIVE_ISTAT); > + complete(&trng->reseed_done); > + } > + > + if (status & STARFIVE_ISTAT_LFSR_LOCKUP) { > + writel(STARFIVE_ISTAT_LFSR_LOCKUP, trng->base + STARFIVE_ISTAT); > + starfive_trng_cmd(trng, STARFIVE_CTRL_EXEC_RANDRESEED); You should not sleep in an IRQ handler. > +static int starfive_trng_read(struct hwrng *rng, void *buf, size_t max, bool wait) You should respect the wait argument and not do polling/sleeping if it is false. Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt