From patchwork Wed Oct 7 12:23:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 54582 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id 7713422FF8 for ; Wed, 7 Oct 2015 12:26:02 +0000 (UTC) Received: by lbwr8 with SMTP id r8sf5970363lbw.0 for ; Wed, 07 Oct 2015 05:26:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=0VinWjgpyoRPSyMnquGPpIhYMWdHPU4ACKMQobcW1KY=; b=Vv/EmALLAiz/RL71FyTMZXNazYlJ1hZht8t16JE+ToJrKfm/PAzTQ66wGUu1vQQkBm wUxJnWdej+eIzAJUbsi3LGj1jfQ6S3pkIXT7DRWZDiYY8yle2nAd+CSS3Ixhq+vnDqIf ZveqCXkfxE0kFfB0yVLUJYzOa+CO1NfNkNQn85HMtwDyf0WwGukWrcreBdrNPQZzVp8v TjXZ3fQSwvpy7KmF1i09fMRHRQ9zityr7nosUD9ibqhiPoKjV7LlovDh01IqZB/yK6k8 DbzlGBI2iAS5mUwNIKQA2txBj7tJMWd06h9wXf/9KtX8drswOpFt9EXwne56gNG41TrV 6VLA== X-Gm-Message-State: ALoCoQnMhMjMxbkk6RGguWAVzR5Rrr2KkQQ8Vd+llIxbkwqCfSIRfNxqm1J0rYIWegxSkrkrY8Pj X-Received: by 10.195.12.234 with SMTP id et10mr178404wjd.2.1444220761233; Wed, 07 Oct 2015 05:26:01 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.21.229 with SMTP id 98ls53152lfv.97.gmail; Wed, 07 Oct 2015 05:26:01 -0700 (PDT) X-Received: by 10.25.42.148 with SMTP id q142mr269862lfq.67.1444220761051; Wed, 07 Oct 2015 05:26:01 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id l17si24953972lfg.72.2015.10.07.05.26.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Oct 2015 05:26:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbcao8 with SMTP id ao8so8929176lbc.3 for ; Wed, 07 Oct 2015 05:26:00 -0700 (PDT) X-Received: by 10.112.135.9 with SMTP id po9mr451620lbb.56.1444220760908; Wed, 07 Oct 2015 05:26:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2417380lbq; Wed, 7 Oct 2015 05:25:59 -0700 (PDT) X-Received: by 10.107.32.80 with SMTP id g77mr1404500iog.14.1444220759754; Wed, 07 Oct 2015 05:25:59 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 35si27206697ioq.87.2015.10.07.05.25.59; Wed, 07 Oct 2015 05:25:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753985AbbJGMZ6 (ORCPT + 30 others); Wed, 7 Oct 2015 08:25:58 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:37534 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752132AbbJGMZf (ORCPT ); Wed, 7 Oct 2015 08:25:35 -0400 Received: by wicfx3 with SMTP id fx3so25720627wic.0 for ; Wed, 07 Oct 2015 05:25:34 -0700 (PDT) X-Received: by 10.194.104.200 with SMTP id gg8mr970797wjb.144.1444220734511; Wed, 07 Oct 2015 05:25:34 -0700 (PDT) Received: from localhost.localdomain (host81-129-171-83.range81-129.btcentralplus.com. [81.129.171.83]) by smtp.gmail.com with ESMTPSA id jq10sm38925455wjc.40.2015.10.07.05.25.33 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Oct 2015 05:25:34 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: kernel@stlinux.com, herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org, pankaj.dev@st.com, daniel.thompson@linaro.org, linux@arm.linux.org.uk, Lee Jones Subject: [PATCH v2 2/3] hwrng: st: Use real-world device timings for timeout Date: Wed, 7 Oct 2015 13:23:28 +0100 Message-Id: <1444220609-31251-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444220609-31251-1-git-send-email-lee.jones@linaro.org> References: <1444220609-31251-1-git-send-email-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Samples are documented to be available every 0.667us, so in theory the 8 sample deep FIFO should take 5.336us to fill. However, during thorough testing, it became apparent that filling the FIFO actually takes closer to 12us. Also take into consideration that udelay() can behave oddly i.e. not delay for as long as requested. Suggested-by: Russell King : "IIRC, Linus recommends a x2 factor on delays, especially timeouts generated by these functions. Signed-off-by: Lee Jones --- drivers/char/hw_random/st-rng.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/char/hw_random/st-rng.c b/drivers/char/hw_random/st-rng.c index 8c8a435..17f0a09 100644 --- a/drivers/char/hw_random/st-rng.c +++ b/drivers/char/hw_random/st-rng.c @@ -32,8 +32,14 @@ #define ST_RNG_FIFO_SIZE 8 #define ST_RNG_SAMPLE_SIZE 2 /* 2 Byte (16bit) samples */ -/* Samples are available every 0.667us, which we round to 1us */ -#define ST_RNG_FILL_FIFO_TIMEOUT (1 * (ST_RNG_FIFO_SIZE / ST_RNG_SAMPLE_SIZE)) +/* + * Samples are documented to be available every 0.667us, so in theory + * the 4 sample deep FIFO should take 2.668us to fill. However, during + * thorough testing, it became apparent that filling the FIFO actually + * takes closer to 12us. We then multiply by 2 in order to account for + * the lack of udelay()'s reliability, suggested by Russell King. + */ +#define ST_RNG_FILL_FIFO_TIMEOUT (12 * 2) struct st_rng_data { void __iomem *base;