Received: by 10.223.185.116 with SMTP id b49csp2000065wrg; Thu, 15 Feb 2018 05:06:50 -0800 (PST) X-Google-Smtp-Source: AH8x224bJSQxRUBs7g/Phs+jXPiimePhZLNRdzxh0mZbhgknYnpFX4yc8dvFnF+3djaxVthiHnrR X-Received: by 10.99.130.72 with SMTP id w69mr2161895pgd.368.1518700010687; Thu, 15 Feb 2018 05:06:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518700010; cv=none; d=google.com; s=arc-20160816; b=COtCTtucLu7Ob+fybUccMoquH0gS1WasF6rJexsuSEFukphVfGRLCmKmWXqrB83vOs ju1jx8X4e/Ei6/6lzbhE+8e1rXdw+hiumlPp5Tjd3AW71HDOZe0hzvnH6ZnhgV1HeN9s RNPP9EuTjH5OjPdeTl0CwVkoJ90eeNXuvgCpXtB09hgP78eM5t9W94ekFMVuhAnaBPeW 7XtDAB79QwajlCENDz0RP6pW5Q2dVz2qXjmnnIfi1TU5GyqdSUOzUIc/e+HjHh8Df1Nm b2BG9508ZLQIovq5E/PO9vPI+6+lhXbjISByntUb78SCI6Nq0t6dkLhrFZj2Dv44gpI9 jjaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=P5GtPZLkD+IfQTqviWVbl7tAqg+3waZ4rz0wxgbJCpc=; b=O7Qn69x79xeB5a0KxxmFVDHqt+8Pt8H/iNR2klEQrVdsY0nbDuZCNkjXFlpIf/EYBH jutjhOt1Iapu4f8ddxqtG7PZYuWvVM8oYdaST13PneTKOt3J02x7/NTJVg8tx/8jOYIO N7EQej2aaDF8fxNFI2Drr27WiXrFtQkMsz6i66NH/2LeA6QrU/YkoBmIt+e90m/2FkXc nHtyRBcNhzTS18RJkw/7XXTz28EJ0dhA0rGi9d6NcwjtSnFZkntHlVMxLKh4QJRub+Kn 85PSKzqyiXDXfmOSuKgSXeeKGSM8drJ66v+rrU30B7YcA8mBJrxT1N42dg3+pHaLg/Ol oNfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 62si2252964pgd.45.2018.02.15.05.06.36; Thu, 15 Feb 2018 05:06:50 -0800 (PST) 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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032752AbeBONFI (ORCPT + 99 others); Thu, 15 Feb 2018 08:05:08 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:61663 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030843AbeBOND4 (ORCPT ); Thu, 15 Feb 2018 08:03:56 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w1FCxBqG008490; Thu, 15 Feb 2018 14:03:29 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2g1q32925d-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 15 Feb 2018 14:03:29 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id B2F0231; Thu, 15 Feb 2018 13:03:28 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 906614E31; Thu, 15 Feb 2018 13:03:28 +0000 (GMT) Received: from SAFEX1HUBCAS23.st.com (10.75.90.47) by SAFEX1HUBCAS21.st.com (10.75.90.44) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 15 Feb 2018 14:03:28 +0100 Received: from localhost (10.201.23.65) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 15 Feb 2018 14:03:27 +0100 From: Lionel Debieve To: Matt Mackall , Herbert Xu , Arnd Bergmann , Greg Kroah-Hartman , Maxime Coquelin , Alexandre Torgue , Rob Herring , , , CC: Benjamin Gaignard , Ludovic Barre Subject: [PATCH Resend 5/5] hwrng: stm32 - rework read timeout calculation Date: Thu, 15 Feb 2018 14:03:12 +0100 Message-ID: <20180215130312.23612-6-lionel.debieve@st.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180215130312.23612-1-lionel.debieve@st.com> References: <20180215130312.23612-1-lionel.debieve@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.201.23.65] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-02-15_05:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Increase timeout delay to support longer timing linked to rng initialization. Measurement is based on timer instead of instructions per iteration which is not powerful on all targets. Signed-off-by: Lionel Debieve --- drivers/char/hw_random/stm32-rng.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/char/hw_random/stm32-rng.c b/drivers/char/hw_random/stm32-rng.c index 709a8d061be3..0d2328da3b76 100644 --- a/drivers/char/hw_random/stm32-rng.c +++ b/drivers/char/hw_random/stm32-rng.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -35,15 +36,6 @@ #define RNG_DR 0x08 -/* - * It takes 40 cycles @ 48MHz to generate each random number (e.g. <1us). - * At the time of writing STM32 parts max out at ~200MHz meaning a timeout - * of 500 leaves us a very comfortable margin for error. The loop to which - * the timeout applies takes at least 4 instructions per iteration so the - * timeout is enough to take us up to multi-GHz parts! - */ -#define RNG_TIMEOUT 500 - struct stm32_rng_private { struct hwrng rng; void __iomem *base; @@ -63,13 +55,16 @@ static int stm32_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) while (max > sizeof(u32)) { sr = readl_relaxed(priv->base + RNG_SR); + /* Manage timeout which is based on timer and take */ + /* care of initial delay time when enabling rng */ if (!sr && wait) { - unsigned int timeout = RNG_TIMEOUT; - - do { - cpu_relax(); - sr = readl_relaxed(priv->base + RNG_SR); - } while (!sr && --timeout); + retval = readl_relaxed_poll_timeout_atomic(priv->base + + RNG_SR, + sr, sr, + 10, 50000); + if (retval) + dev_err((struct device *)priv->rng.priv, + "%s: timeout %x!\n", __func__, sr); } /* If error detected or data not ready... */ -- 2.15.1