From patchwork Tue Dec 5 12:35:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukasz Stelmach X-Patchwork-Id: 10092811 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 BAB586035E for ; Tue, 5 Dec 2017 12:36:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE42D29510 for ; Tue, 5 Dec 2017 12:36:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1C9F29566; Tue, 5 Dec 2017 12:36:33 +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=unavailable 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 36CE729510 for ; Tue, 5 Dec 2017 12:36:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752835AbdLEMgR (ORCPT ); Tue, 5 Dec 2017 07:36:17 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:59150 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752711AbdLEMgG (ORCPT ); Tue, 5 Dec 2017 07:36:06 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20171205123604euoutp0179f9ce001c36dff2be7ad25d574890ff~9ZiZQhUjX2888228882euoutp01g; Tue, 5 Dec 2017 12:36:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20171205123604euoutp0179f9ce001c36dff2be7ad25d574890ff~9ZiZQhUjX2888228882euoutp01g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1512477364; bh=HDC9V5TEi4CaLM8BVwmLMysgMtNR2KjRAxpRwq6qYSE=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=VdYtnfFaapRU2GWM2xCrg/fRualyCFfW1hBCpZbYN14lao1fkTseaWUo0mlfBoxD4 OcchRXMrgnX/TCtNpzmXAGTnj2ZzjIC6ShDiTIybPFJvJZzc3ZPwku/i7Hb3iq4Kvk XT/mDPEqxDwYhwW2Sfh8pOhvRrqfApY/RLYwMiyk= Received: from eusmges1.samsung.com (unknown [203.254.199.239]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20171205123603eucas1p1c5c0c300a953daba6d1da58930a97889~9ZiYoBT5W0086700867eucas1p1l; Tue, 5 Dec 2017 12:36:03 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1.samsung.com (EUCPMTA) with SMTP id 30.5A.12576.3B2962A5; Tue, 5 Dec 2017 12:36:03 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20171205123603eucas1p177cceb022e3a5c0a9d13ca437c05b669~9ZiX3QlGt1465914659eucas1p1Q; Tue, 5 Dec 2017 12:36:03 +0000 (GMT) X-AuditID: cbfec7ef-f79ee6d000003120-31-5a2692b3def5 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id AA.F5.20118.3B2962A5; Tue, 5 Dec 2017 12:36:03 +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 <0P0H00JZLN02HSB0@eusync3.samsung.com>; Tue, 05 Dec 2017 12:36:03 +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?= , m.szyprowski@samsung.com, b.zolnierkie@samsung.com Subject: [PATCH 2/3] crypto: exynos - Improve performance of PRNG Date: Tue, 05 Dec 2017 13:35:57 +0100 Message-id: <20171205123558.31087-3-l.stelmach@samsung.com> X-Mailer: git-send-email 2.11.0 In-reply-to: <20171205123558.31087-1-l.stelmach@samsung.com> Organization: Samsung R&D Institute Poland X-Brightmail-Tracker: H4sIAAAAAAAAA01SbUhTYRjlvffu7ioub5vYg0nSQFEjTerHTS0UFo2K9IcE7k8tvUzRqeyq pCKsUtNNms7EZeYHljpLV0tFDCXncILITMW0aFohiQVGFmZ+lPNq+e+8zznn+Ti8FC7uFPhR qRnZrCZDmS4lPYme4TXn8RfGIMWJeksI89xkETB1ziKC0S/5M4ZPX3DG6XwmZGZtbYiZc61h zGRfHcmYnAMY02F/L2SK++1Cpnq0g4jxkn+fmsLkXeZZTN7zKlBubS8j5Xe72pF8xXoknlR4 Riez6am5rCb87DXPlIaZWkGWVnLjs7FeqEWN3jrkQQF9CvRFmwIe+8K4y0LqkCclplsQzC82 4fxjBcFIwzC252g13kH/VDOTVuQmRPRB+FXlInSIonA6AOwTae4yTodA90uLkNf/QFDpMu80 IulYMDweEbgJH7ofg69j/QTvyIGx+ne4G0u2RQurozuYoAOh1VFO8sOiYHru5u5GAdBX8nrn Bg86GprGTDsabzoUnt56Q7gHAP2HBFfPkJA3yKDNXIF4LIElR9du3R8mq/S7BgOCoYbVXeIe guamGB5HwUZ7JclvegCMPTW4+2SgRVBaIuYlchiYf0jwOBYspd8w/vztnoNlv1E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39st7Lo11f7YckDgwXf/pxJPmDNx13tXxDqzbnFq5alt3JU5IqrQ7O22i3JZuv9lM FgzzE3dN+tuz++3taU+uK7EUZyQaajEXFScCAP0Cr6uUAgAA X-CMS-MailID: 20171205123603eucas1p177cceb022e3a5c0a9d13ca437c05b669 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20171205123603eucas1p177cceb022e3a5c0a9d13ca437c05b669 X-RootMTR: 20171205123603eucas1p177cceb022e3a5c0a9d13ca437c05b669 References: <20171205123558.31087-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. Remove unnecessary invocation of cpu_relax(). Signed-off-by: Ɓukasz Stelmach --- drivers/crypto/exynos-rng.c | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/drivers/crypto/exynos-rng.c b/drivers/crypto/exynos-rng.c index 894ef93ef5ec..002e9d2a83cc 100644 --- a/drivers/crypto/exynos-rng.c +++ b/drivers/crypto/exynos-rng.c @@ -130,34 +130,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). @@ -171,6 +143,8 @@ static int exynos_rng_get_random(struct exynos_rng_dev *rng, { int retry = EXYNOS_RNG_WAIT_RETRIES; + *read = min_t(size_t, dlen, EXYNOS_RNG_SEED_SIZE); + if (rng->type == EXYNOS_PRNG_TYPE4) { exynos_rng_writel(rng, EXYNOS_RNG_CONTROL_START, EXYNOS_RNG_CONTROL); @@ -180,8 +154,8 @@ static int exynos_rng_get_random(struct exynos_rng_dev *rng, } while (!(exynos_rng_readl(rng, - EXYNOS_RNG_STATUS) & EXYNOS_RNG_STATUS_RNG_DONE) && --retry) - cpu_relax(); + EXYNOS_RNG_STATUS) & EXYNOS_RNG_STATUS_RNG_DONE) && + --retry); if (!retry) return -ETIMEDOUT; @@ -189,7 +163,7 @@ 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); + memcpy_fromio(dst, rng->mem + EXYNOS_RNG_OUT_BASE, *read); return 0; }