From patchwork Tue Dec 12 16:36:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukasz Stelmach X-Patchwork-Id: 10107843 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 B450B602B3 for ; Tue, 12 Dec 2017 16:36:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A67222947F for ; Tue, 12 Dec 2017 16:36:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B1EB294D2; Tue, 12 Dec 2017 16:36:25 +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 3219A2947F for ; Tue, 12 Dec 2017 16:36:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752515AbdLLQgW (ORCPT ); Tue, 12 Dec 2017 11:36:22 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:57949 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751729AbdLLQgP (ORCPT ); Tue, 12 Dec 2017 11:36:15 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20171212163612euoutp0164cf3740b86b6ae0af8a388110bb8db5~-mVD5urrl1961919619euoutp01D; Tue, 12 Dec 2017 16:36:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20171212163612euoutp0164cf3740b86b6ae0af8a388110bb8db5~-mVD5urrl1961919619euoutp01D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1513096572; bh=8AISgKlPXJERwI01KihYeQp2eyyO6i/EB9zWSbXsbnc=; h=From:To:Cc:Subject:Date:In-reply-to:In-reply-to:References:From; b=nM2xbs0CtXFOeWuDoZBNk2q2aczu6YkAnHTcgwwKRs5FJcOlpA30Z2dZ2HRnlUYdP voMOP8blLXLhSNYb8RAfnM0nC0SVl3+OfdFhuhubYgK22Idejezv71qZn8gMylnx0Q F0jz+HCJoa/BlhcZMZuTelOoZCdG3lFHAB/BkRSI= Received: from eusmges5.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20171212163612eucas1p1286f23cf0c474530eb664436d1ec4cd9~-mVDKmsls2475124751eucas1p1d; Tue, 12 Dec 2017 16:36:12 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges5.samsung.com (EUCPMTA) with SMTP id BC.B0.12743.B75003A5; Tue, 12 Dec 2017 16:36:11 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20171212163611eucas1p2bb80c67eb0e0a8411abcc1f65242c362~-mVCe3pOi0378803788eucas1p2C; Tue, 12 Dec 2017 16:36:11 +0000 (GMT) X-AuditID: cbfec7f5-f79d06d0000031c7-6a-5a30057b2cb4 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id A1.ED.18832.B75003A5; Tue, 12 Dec 2017 16:36:11 +0000 (GMT) MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset="UTF-8" Received: from localhost ([106.116.147.110]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P0U00HGJWSBJS90@eusync3.samsung.com>; Tue, 12 Dec 2017 16:36:11 +0000 (GMT) From: =?UTF-8?q?=C5=81ukasz=20Stelmach?= To: Krzysztof Kozlowski , robh+dt@kernel.org, Stephan Mueller , Herbert Xu , "David S . Miller" , Kukjin Kim , linux-crypto@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?=C5=81ukasz=20Stelmach?= , Marek Szyprowski , Bartlomiej Zolnierkiewicz Subject: [PATCH v3 2/4] crypto: exynos - Improve performance of PRNG Date: Tue, 12 Dec 2017 17:36:05 +0100 Message-id: <20171212163607.2985-3-l.stelmach@samsung.com> X-Mailer: git-send-email 2.11.0 In-reply-to: <20171212163607.2985-1-l.stelmach@samsung.com> In-reply-to: <20171211140623.7673-1-l.stelmach@samsung.com> Organization: Samsung R&D Institute Poland X-Brightmail-Tracker: H4sIAAAAAAAAA02Sa0hTYRzGec85OztOZ6d56Y+OjIFCUl4g66QZGiH7KH3K+cGGnqbp1Ha8 ZH4xSXMKLk1LRNQhmg515WWJpuQFpxku01CzDBHBFBEv5YySdjxKfnt4n+f/e//vw0vhsh6R F5WUmsHqUtUpClJCWEb3Jy/mioJUQXnrwczrKrOIqbE9JpiSNTljWF7HGZvtlZiZH2pGzPfF fYyZ7q0hmSrbAMa0jXwTMwX9I2KmcqKNiHBRbs/MYMqulnlMaXnnq+ww6UllaZcJKXc6zkaT Ksm1BDYlKYvVBV6/I0ncHuxC6YWuD1b0beI8ZHQuRk4U0JfAPGbHBe0JHxfNZDGSUDK6EcHu vgnjDRm9g+CzPeR4oKPEiIRQE4K5hgWCN6T0abA/W3RoisJpHxj5lMwf4/R56O4zi4X8LoL2 N50i3iDpSDA0jol4w50ewGC5rPKQivPUQcs4yZPc6JtQVOHNDxC0L2zv1uPCZaGwtDCNhI18 oLdw6hDqRIfB7kE7dqz11ickr0/R/tCaP0vwfKANYugusx9uCg7+eFWMwHGDNWuXWNBy0BcN Ykd5BMN1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G dP0Zxh9sak4cD19u/nh9v/VHQfVWoavXzqnuktvSvo0tYo+kTeo83cKkTeeUch8t+P+i3LVi a9jFR1s21yw1vP6BdfPrPVP8V0/PyWOY5nrI1WRj3MMbS6uvXjlfdeDoyudMM3YfTJ2SeDyR LXYH2wOG73cPzWgP3jXB1Y9bbo2kiXmpzuNd95VYijMSDbWYi4oTAUSqUsGsAgAA X-CMS-MailID: 20171212163611eucas1p2bb80c67eb0e0a8411abcc1f65242c362 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20171212163611eucas1p2bb80c67eb0e0a8411abcc1f65242c362 X-RootMTR: 20171212163611eucas1p2bb80c67eb0e0a8411abcc1f65242c362 References: <20171212163607.2985-1-l.stelmach@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use memcpy_fromio() instead of custom exynos_rng_copy_random() function to retrieve generated numbers from the registers of PRNG. Signed-off-by: Ɓukasz Stelmach Reviewed-by: Krzysztof Kozlowski --- drivers/crypto/exynos-rng.c | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/drivers/crypto/exynos-rng.c b/drivers/crypto/exynos-rng.c index 825c09619eb8..dcdd444d0b3b 100644 --- a/drivers/crypto/exynos-rng.c +++ b/drivers/crypto/exynos-rng.c @@ -131,34 +131,6 @@ static int exynos_rng_set_seed(struct exynos_rng_dev *rng, } /* - * Read from output registers and put the data under 'dst' array, - * up to dlen bytes. - * - * Returns number of bytes actually stored in 'dst' (dlen - * or EXYNOS_RNG_SEED_SIZE). - */ -static unsigned int exynos_rng_copy_random(struct exynos_rng_dev *rng, - u8 *dst, unsigned int dlen) -{ - unsigned int cnt = 0; - int i, j; - u32 val; - - for (j = 0; j < EXYNOS_RNG_SEED_REGS; j++) { - val = exynos_rng_readl(rng, EXYNOS_RNG_OUT(j)); - - for (i = 0; i < 4; i++) { - dst[cnt] = val & 0xff; - val >>= 8; - if (++cnt >= dlen) - return cnt; - } - } - - return cnt; -} - -/* * Start the engine and poll for finish. Then read from output registers * filling the 'dst' buffer up to 'dlen' bytes or up to size of generated * random data (EXYNOS_RNG_SEED_SIZE). @@ -190,7 +162,8 @@ static int exynos_rng_get_random(struct exynos_rng_dev *rng, /* Clear status bit */ exynos_rng_writel(rng, EXYNOS_RNG_STATUS_RNG_DONE, EXYNOS_RNG_STATUS); - *read = exynos_rng_copy_random(rng, dst, dlen); + *read = min_t(size_t, dlen, EXYNOS_RNG_SEED_SIZE); + memcpy_fromio(dst, rng->mem + EXYNOS_RNG_OUT_BASE, *read); return 0; }