Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4962570rwl; Sun, 8 Jan 2023 06:20:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXu3pEfUPxGQVK4Skiit/yQF96MjDHcN6elCdBnrTqg/5Dmgmar97q//bOyc/hH3E0n/O+ud X-Received: by 2002:a17:907:8b89:b0:7c1:6f86:eeb with SMTP id tb9-20020a1709078b8900b007c16f860eebmr49668372ejc.7.1673187636468; Sun, 08 Jan 2023 06:20:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673187636; cv=none; d=google.com; s=arc-20160816; b=L8njAeaErNeGpTkpyFDq8Q1YUCBs3XmjAy3IeBN/rj8+An7YICulXwXTymVhrNuNpX NI+Hue+yqxRaI/9zN1pWD8ufDNrf9n8C442hNAgPVQNmb58OAHIHVMh2EcEmYu7xjQzQ b1Yw5n0H3rgJzl2LHCV7zsPrvVf6c/GGZoL5y0HnecJffLJFYb29d5LczWCehx4FqFe8 Qq5C4FY2voT4x65dnqEwGYhjk6rbTn9kENm9uR704J1cEdpYA5ecd+uTpuQ17ly/KTBo yF2BhOpHsST/AarglnSYkzYPlgy1NmR4jmpIqnf0SIR73zEUmCCqKDdHXa6TYFoZb23B 86Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=eswmvnbMw8rDJPBSsLdDwNJGt6GuZuWM96xQpsVWekY=; b=c1bqTbM0tzR5lwARKeJmrpYFw7aqZNWeIwSprQl6rjeWq74HiV0QyqhXGikRm6bd7u 98NpGPuU7VTRZn2JmguKgbAzg5bz68qNLPW0NLK9d2PG/L5wKpJhF0AYKGnGiqIlpUPJ FOksuuyTa5ogkO33iX5Xn2f1ikhzHv1cwWnvwlo1ynJwcz9DUFZ7W8UexGm6lKGbBdQ+ YJ6K0O+j6jp3WRVq9lXF/gcTiXzgcCOLouv2/9KgNwKzqcYQ/gAjDqocTNcitZCCfC5u 3vBE/aQwXhoMj+g8RJOunV6TGyR0vJyvwMzBId6eRXew85f558ltnMZccvTQ7ZODxs8f 6BjQ== 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 qb21-20020a1709077e9500b007c0d9525ba4si6995545ejc.877.2023.01.08.06.20.06; Sun, 08 Jan 2023 06:20:36 -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 S233196AbjAHONP convert rfc822-to-8bit (ORCPT + 99 others); Sun, 8 Jan 2023 09:13:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbjAHONO (ORCPT ); Sun, 8 Jan 2023 09:13:14 -0500 Received: from fd01.gateway.ufhost.com (fd01.gateway.ufhost.com [61.152.239.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D475DFBA; Sun, 8 Jan 2023 06:13:09 -0800 (PST) Received: from EXMBX165.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX165", Issuer "EXMBX165" (not verified)) by fd01.gateway.ufhost.com (Postfix) with ESMTP id E0DCB24DC94; Sun, 8 Jan 2023 22:13:05 +0800 (CST) Received: from EXMBX168.cuchost.com (172.16.6.78) by EXMBX165.cuchost.com (172.16.6.75) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Sun, 8 Jan 2023 22:13:05 +0800 Received: from EXMBX168.cuchost.com ([fe80::3c2d:dee5:4938:3fc4]) by EXMBX168.cuchost.com ([fe80::3c2d:dee5:4938:3fc4%16]) with mapi id 15.00.1497.044; Sun, 8 Jan 2023 22:13:05 +0800 From: JiaJie Ho To: Herbert Xu 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 Thread-Topic: [PATCH v2 2/3] hwrng: starfive - Add TRNG driver for StarFive SoC Thread-Index: AQHZGoveBWEVWeSp5UqGtlmGFQKs8K6QmY4AgAQHL+A= Date: Sun, 8 Jan 2023 14:13:05 +0000 Message-ID: <75798088d1cd41dd94dafe67179761d9@EXMBX168.cuchost.com> References: <20221228071103.91797-1-jiajie.ho@starfivetech.com> <20221228071103.91797-3-jiajie.ho@starfivetech.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [172.16.6.8] x-yovoleruleagent: yovoleflag Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,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 > -----Original Message----- > From: Herbert Xu > Sent: 6 January, 2023 4:39 PM > To: JiaJie 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 > > 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. > I'll fix this in next version. > > +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. > Will fix this too. > > +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. I'll add this in the next version. Thanks for reviewing this patch. Best regards, Jia Jie