From patchwork Mon May 23 16:20:51 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: 9132123 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 599E5607D3 for ; Mon, 23 May 2016 16:22:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5104B28219 for ; Mon, 23 May 2016 16:22:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 454EA28238; Mon, 23 May 2016 16:22:37 +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 CE34B28219 for ; Mon, 23 May 2016 16:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754201AbcEWQVo (ORCPT ); Mon, 23 May 2016 12:21:44 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:35500 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754188AbcEWQVm (ORCPT ); Mon, 23 May 2016 12:21:42 -0400 Received: by mail-pf0-f177.google.com with SMTP id g64so13495367pfb.2 for ; Mon, 23 May 2016 09:21:41 -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=6dWilBhR7Zt5uU9iGx3D6DSwNxcVpG6jifaDq1rhgNE=; b=RVM+oozSHngXl9f09m1vfc7qSCOsYeWUX+h5FgAEAc34o5TnkSyrxafAMLMFTRkiqo Cy9/cxYo1kMbyLrXpjET2MW9ZJoZ3HbR0lpdcNkgH0n5F1b5j5mhHrvU6aZ3C6eERIcQ A6wvFUBkfuJzjssBHTx4ruyJbDXsK/E80v4CE= 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=6dWilBhR7Zt5uU9iGx3D6DSwNxcVpG6jifaDq1rhgNE=; b=B+DFPQVPUlnC8hbZo8xOXNdyzEn2k3YCnQokDjuG5v89V/yP5x4M9oNvjAge+UysNj eMO4mUWVVn4zOHTKQ6sgc4w0H2lBYTU+s7ZaQjR0X5lzSHEMV8G1YnOGLtNKjvA8xCmL QwXhnBEbAwezkO9po/Th1VmO4VsNE1GsssUuQA9ZhI7tZPt55L7ID5bggtXjEuujO+lq TD+5Amy/hCy28nYCAw0xnux89e1K1QIKuF69JrTPckZjzZ47Lp0PtvInp9Z1eMMR2anj K/YzF+0VgOB3WDfcframEXKmaT6VxN8IZnMsDrBw3sEWBPM/TSSjuKhL7ye8Cccu/uYH vArw== X-Gm-Message-State: ALyK8tKcH+rWpaRNFlSYnHXbNR2Gi+4fi/va022GHcR6w+8YtMJI/3snu3AIGw8pqi3afzww X-Received: by 10.98.35.93 with SMTP id j90mr10480483pfj.10.1464020500936; Mon, 23 May 2016 09:21:40 -0700 (PDT) Received: from xl-rtp-02.rtp.broadcom.com ([216.31.219.19]) by smtp.gmail.com with ESMTPSA id u65sm47782512pfa.9.2016.05.23.09.21.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 May 2016 09:21:39 -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 4/4] hwrng: bcm2835: Read as much data as available Date: Mon, 23 May 2016 12:20:51 -0400 Message-Id: <1464020451-16520-5-git-send-email-yendapally.reddy@broadcom.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1464020451-16520-1-git-send-email-yendapally.reddy@broadcom.com> References: <1464020451-16520-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..9bbdc07 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 = {