From patchwork Fri Mar 5 07:01:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?= X-Patchwork-Id: 12117877 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=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 660E8C433E0 for ; Fri, 5 Mar 2021 07:04:07 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA52364D74 for ; Fri, 5 Mar 2021 07:04:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA52364D74 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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:To:From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4Hl7FvI994v/QJAbN1AagATEQu9TtVYHwOxOW/MEHLQ=; b=qc0SZKE+SZqd4PzQ+1FzNF5QL YJtJp+6WmH3Q9kAY8VRNjJqGlMHLwE10SX+awDCOaoiZxpzIwBiGeik8XVA7NEN8MxSKE7NGg0Eha ZdDc0i4dTsTkYaDoveZtdv+fY4/urTohLydnbMJyxBHyb5ek4ps0iS4LPLM0tVeWGTqVjeBfxDKVi DSBgzmgImdoB507b++WoYjJnOLFXL8430Sv2OsYS2JBojZkVa3/Y/6mW1bdBj+alizHek0RZCyQVZ Dlka+9Nu4cGc0bGyZ8WLEmvvTqL5fbAMS/1gQTZ9wYRAOBe0gMoq1t99R+PPCFE3jXF1WXLJsTix8 lmIZ3O49g==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lI4Ti-00DWww-Li; Fri, 05 Mar 2021 07:02:26 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lI4Sw-00DWOJ-07; Fri, 05 Mar 2021 07:01:40 +0000 Received: by mail-wr1-x436.google.com with SMTP id b18so892463wrn.6; Thu, 04 Mar 2021 23:01:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=z1XetKjHCD1nkGlnf/Dumzc1flLXCFdZJxrK1LQl/AU=; b=AncSwcHaKNhaUNvGU/ZDEHzZwdWwZWWSSJWgBASMhdDbzmmsxO75PY9Pgdp41K5p2Z wzwndus7xmuAK+ZSgL9pgoir6UA5gN5ehlvu61j6E1vLwWMbdnRI8wlCKnC5UFwRaG43 aWhpqDD2D4eRB6FIZVf/XWj/QJFJCSNp8/5PrssVOEA1caVP/AgmadhAMHq7fgiy29nU Ef2sEf7BTBJ8E01fhP2dEyRNzOQ5qKTDClCiqgEMlozwcdsb5ycQx/57+jwEnjOycDvp DKTeNcjPujRu8+hUncggvndEGaccke+9+og1uIpQJTGeB9wvQ9WLGWr84A3uQotAjgME HfCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z1XetKjHCD1nkGlnf/Dumzc1flLXCFdZJxrK1LQl/AU=; b=MZxYlwQmQJNtA54uiZqCsRteM0CmonVilPtLfUP7fZyWwCryOGTEpG+Gmn/9j8goyk B6I9o3EXtJxvJvduqfoXhwjewkj0tlEHSnq41iFS2S044a9HHijf28Uc/TG8tzaAsCRm mBCggFAd8k5rvGVDY1jg3tBjTa7LfJjMDRqG3U1OUSsKBADe2RJCk/7JoYoy4jPGxvDq nd3YPj3TvjLf7RFiNvwdp/LmK6q+hVpBLAu4pZsQwQZJglm8Mw8HDR7AS6LSKDAZCbu4 1oAdErBJUgrqjnpjRuVXvzl3OixSNFfvnRVsExfJIJ1UvE3dIzaa1HAt76RkhD9fdogH iyTA== X-Gm-Message-State: AOAM530gGqhqRk5gNh7bLhhRcCDAap+T36AJ/3fXW9aG1TMMKDID4PJd 1+G/5BIr6R/1RtUNksRRcaM= X-Google-Smtp-Source: ABdhPJyBljkf3jOAJ6LZyQb5bqYgFgIUFjzoDgfhnXSg5I23sThciOmq9Cxh/hEeu1Jt4qFsUfpbZA== X-Received: by 2002:adf:a418:: with SMTP id d24mr7554007wra.187.1614927697667; Thu, 04 Mar 2021 23:01:37 -0800 (PST) Received: from skynet.lan (170.red-88-1-105.dynamicip.rima-tde.net. [88.1.105.170]) by smtp.gmail.com with ESMTPSA id y18sm2799220wrq.61.2021.03.04.23.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 23:01:37 -0800 (PST) From: =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?= To: Matt Mackall , Herbert Xu , Rob Herring , Nicolas Saenz Julienne , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Philipp Zabel , =?utf-8?q?=C3=81lvaro_Fern=C3=A1nde?= =?utf-8?q?z_Rojas?= , Lee Jones , Bjorn Andersson , Alexandru Ardelean , Rikard Falkeborn , Tian Tao , Stefan Wahren , linux-crypto@vger.kernel.org, devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 3/3] hwrng: bcm2835: add reset support Date: Fri, 5 Mar 2021 08:01:32 +0100 Message-Id: <20210305070132.2986-4-noltari@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210305070132.2986-1-noltari@gmail.com> References: <20210305070132.2986-1-noltari@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210305_070138_403697_158170D4 X-CRM114-Status: GOOD ( 16.04 ) 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 BCM6368 devices need to reset the IPSEC controller in order to generate true random numbers. This is what BCM6368 produces without a reset: root@OpenWrt:/# cat /dev/hwrng | rngtest -c 1000 rngtest 6.10 Copyright (c) 2004 by Henrique de Moraes Holschuh This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. rngtest: starting FIPS tests... rngtest: bits received from input: 20000032 rngtest: FIPS 140-2 successes: 0 rngtest: FIPS 140-2 failures: 1000 rngtest: FIPS 140-2(2001-10-10) Monobit: 2 rngtest: FIPS 140-2(2001-10-10) Poker: 1000 rngtest: FIPS 140-2(2001-10-10) Runs: 1000 rngtest: FIPS 140-2(2001-10-10) Long run: 30 rngtest: FIPS 140-2(2001-10-10) Continuous run: 0 rngtest: input channel speed: (min=37.253; avg=320.827; max=635.783)Mibits/s rngtest: FIPS tests speed: (min=12.141; avg=15.034; max=16.428)Mibits/s rngtest: Program run time: 1336176 microseconds Signed-off-by: Álvaro Fernández Rojas Reviewed-by: Philipp Zabel Acked-by: Florian Fainelli --- v6: fix commit description. v5: remove reset_control_rearm(). v4: add reset_control_rearm(). v3: no changes. v2: no changes. drivers/char/hw_random/bcm2835-rng.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index be5be395b341..e7dd457e9b22 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -13,6 +13,7 @@ #include #include #include +#include #define RNG_CTRL 0x0 #define RNG_STATUS 0x4 @@ -32,6 +33,7 @@ struct bcm2835_rng_priv { void __iomem *base; bool mask_interrupts; struct clk *clk; + struct reset_control *reset; }; static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) @@ -92,6 +94,10 @@ static int bcm2835_rng_init(struct hwrng *rng) if (ret) return ret; + ret = reset_control_reset(priv->reset); + if (ret) + return ret; + if (priv->mask_interrupts) { /* mask the interrupt */ val = rng_readl(priv, RNG_INT_MASK); @@ -156,6 +162,10 @@ static int bcm2835_rng_probe(struct platform_device *pdev) if (IS_ERR(priv->clk)) return PTR_ERR(priv->clk); + priv->reset = devm_reset_control_get_optional_exclusive(dev, NULL); + if (IS_ERR(priv->reset)) + return PTR_ERR(priv->reset); + priv->rng.name = pdev->name; priv->rng.init = bcm2835_rng_init; priv->rng.read = bcm2835_rng_read;