From patchwork Fri May 27 10:10:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yendapally Reddy Dhananjaya Reddy X-Patchwork-Id: 9138021 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8EE326075C for ; Fri, 27 May 2016 10:11:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8197328093 for ; Fri, 27 May 2016 10:11:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75F392818B; Fri, 27 May 2016 10:11:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B7E628093 for ; Fri, 27 May 2016 10:11:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755725AbcE0KLP (ORCPT ); Fri, 27 May 2016 06:11:15 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:32848 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755648AbcE0KLN (ORCPT ); Fri, 27 May 2016 06:11:13 -0400 Received: by mail-pf0-f182.google.com with SMTP id b124so40578744pfb.0 for ; Fri, 27 May 2016 03:11:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fOxwxRHE6TrKMV4E2N2Mm2pjv2YCvlQxczgBm+JGZfQ=; b=R2if96ocOHyJHJ4VwmSuDkEUDETDc3SiZZ2ooiDgFO56S1qKzjv1Nm8RvBAXlQ8oQh 8YdfOrnarPWj7PUkL67kTlM1MqjKU4z4d02fA4FFyYjZ8E+34KmYZnQ3FbKvElZBw5/T 6G4hXX0JnwkeLUcgjUPCGmRhBL7jvMPsnHLsg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fOxwxRHE6TrKMV4E2N2Mm2pjv2YCvlQxczgBm+JGZfQ=; b=Nnm5Mou6lwsRueWmuDncA196U90TNjdAEYSzoIJtNsSRdX1LKHLmb6YyZBfeNXIuZa QLZ1UQIVBVPsJhBPhNu/BpZ/Bo1H23LgOWmLAHyf2tAUx8ftTWalC2Cnfkk+oZsyQ02r by2VbDexa6PZUAk3MtXlZtGX1SqC6MpCNmcy2T2qgOQ31uP05kUomVjlMqGwAFdAkcQG BQw7JgYkrYCSMzzGjkk3y+m/RqU4vD9JC31ILg/wxCEWAr2Togt6oIdpQZER9lY+C/k9 SpMd+ljMDcwWLRxTxCfpwTRUacktuiYEvV+faabEbNBRB/hJ3ppZv8GmhDszGrvXJzf2 8HuA== X-Gm-Message-State: ALyK8tIEMsycy4EyctH9WXyIb6WoC1uJK47BnYRHh1W7uOsEcE+9YGf1S4kxCXM4FbYuqMZp X-Received: by 10.98.157.146 with SMTP id a18mr21225421pfk.117.1464343872066; Fri, 27 May 2016 03:11:12 -0700 (PDT) Received: from xl-rtp-02.rtp.broadcom.com ([216.31.219.19]) by smtp.gmail.com with ESMTPSA id j65sm12418628pfj.44.2016.05.27.03.11.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 May 2016 03:11:11 -0700 (PDT) From: Yendapally Reddy Dhananjaya Reddy To: Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Stephen Warren , Lee Jones , Eric Anholt , Russell King , Ray Jui , Scott Branden , Jon Mason , Matt Mackall , Herbert Xu , Daniel Thompson , Kieran Bingham , Pankaj Dev , Richard Weinberger , noltari@gmail.com, Joshua Henderson Cc: devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-crypto@vger.kernel.org, Yendapally Reddy Dhananjaya Reddy Subject: [PATCH v2 4/4] hwrng: bcm2835: Read as much data as available Date: Fri, 27 May 2016 06:10:41 -0400 Message-Id: <1464343841-29504-5-git-send-email-yendapally.reddy@broadcom.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1464343841-29504-1-git-send-email-yendapally.reddy@broadcom.com> References: <1464343841-29504-1-git-send-email-yendapally.reddy@broadcom.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Read the requested number of data from the fifo Signed-off-by: Yendapally Reddy Dhananjaya Reddy Reviewed-by: Eric Anholt --- drivers/char/hw_random/bcm2835-rng.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index b1e8b78..75ca820 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -43,6 +43,8 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) { void __iomem *rng_base = (void __iomem *)rng->priv; + u32 max_words = max / sizeof(u32); + u32 num_words, count; while ((__raw_readl(rng_base + RNG_STATUS) >> 24) == 0) { if (!wait) @@ -50,8 +52,14 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, cpu_relax(); } - *(u32 *)buf = __raw_readl(rng_base + RNG_DATA); - return sizeof(u32); + num_words = readl(rng_base + RNG_STATUS) >> 24; + if (num_words > max_words) + num_words = max_words; + + for (count = 0; count < num_words; count++) + ((u32 *)buf)[count] = readl(rng_base + RNG_DATA); + + return num_words * sizeof(u32); } static struct hwrng bcm2835_rng_ops = {