Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1795261pxb; Thu, 4 Mar 2021 23:02:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQSn7YBLHNpII74WBCigXsQCg4zJG87LugayxYoUsE6Jcr1/CG6A9LIOzrQC/SZhurfWUZ X-Received: by 2002:a5d:9641:: with SMTP id d1mr6865635ios.123.1614927727382; Thu, 04 Mar 2021 23:02:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614927727; cv=none; d=google.com; s=arc-20160816; b=JiJ0GMeZYbq7uFSd/WHBCrdP6HQB0ITBlMX26wDSH1fMfmJaUhl29SXBNc0NBnEu4W Hz0VqmKWROQfeoTodDm6RxIT9G7tI8zvOgIfqk5YzA/G+qWQ5o7BGho75xvqC8LEuw92 u0VzV/ZX+4oYXJOqW9AtBce1B7QeCarcwiwQ5JjXO70O56lMsezy5FJ7gTNhOzIEHrf3 cghplnP94K0iVbXQcgSIoHDkYRMVJdVAfQDjLqLryGnlY1cjOflk+4+kFXsqCWhUp6t3 35gkT/DiLhjBetRW7y0/pZtrhR6A4bH2QMUqbjA8fg74YgwFafzeCsEIwTl5FmYwrX5g NwRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=z1XetKjHCD1nkGlnf/Dumzc1flLXCFdZJxrK1LQl/AU=; b=DiZsfEw8w8XYUfm2Xl9u4RSnwlrPZF1jkYY2RAv8FAm/ePIRIp2zl/l/P6vFiiLqmQ aGAzeYueFQgUdyUzuttyJTY22FBs8NGUFMNG8WDdFXIiW67Hw0riS7+M1/p9Z3yqMRM8 0kjUTp68f06qnVFMpUbWgtlqZ9EFqNfOIUAysu5KIpNhelYYCUHowdNGpoHks6gH3iFt +cu2UiEPxyn28me7JQC67554U97L6J7yO9d9ZL6Ez4/cMdxAKTQ3Kew9GKxphR3H9o9Y pNIpPA5qNsJfAQCUdhvLjNd/afa0F7WKIkDLrX253t/Kp/bOZbGwXOdQW7B2cjPi0Deo 9Lxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AncSwcHa; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r28si1538285jao.125.2021.03.04.23.01.53; Thu, 04 Mar 2021 23:02:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AncSwcHa; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229580AbhCEHBn (ORCPT + 99 others); Fri, 5 Mar 2021 02:01:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbhCEHBk (ORCPT ); Fri, 5 Mar 2021 02:01:40 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E84D2C06175F; Thu, 4 Mar 2021 23:01:38 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id a18so864075wrc.13; Thu, 04 Mar 2021 23:01:38 -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=p0uoQAvdPN9JRx+DS/OjnN3+7/PPPzT+NM9zB3Fk/M2hpYnSdajhn/jAlIvDiG+kzR 1qCOStgFpa3SiUrw5qABEdjd63k0nvXD8qoKnxhmq5Oa1ba6pS/sl9Lc6hVk/hOpiP2u wy6y69hS0nXovj44x0VEu2+OWAxpOO49aPMlf/8v9RYDZv2PSRJAr3fC0uCM3YedtWSH uZy+wnRG3UYI1c8Jmn6B+PTSISPeTgLIOlb3waqni5TGVNvTEdILNsJcgpWANSFToRmt M2fD+cHAEAyZuaEp2kclH2qaKYBIjJDButc3JIhujEiJ0o3r8tEkXacmlC53wsv7mjII KqKw== X-Gm-Message-State: AOAM531E8UUhL+6xNL9a01qwckyioIcq7mYw1Z7pQI4tiGZTcoe4iNQD nm+PttChRp0Un/QKG8o3fY0= 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=20Fern=C3=A1ndez=20Rojas?= 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=20Fern=C3=A1ndez=20Rojas?= , 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.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 --- 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; -- 2.20.1