From patchwork Mon Jul 16 05:50:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinod Koul X-Patchwork-Id: 141968 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2013071ljj; Sun, 15 Jul 2018 22:51:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfDs5aQRxLQ3JMhBXsADF3GEJN/CQ44hDvNaG2dD+2PaEPNXBLZCUCQFJl9ou0chpLKVWvG X-Received: by 2002:a17:902:7482:: with SMTP id h2-v6mr15640431pll.185.1531720274159; Sun, 15 Jul 2018 22:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531720274; cv=none; d=google.com; s=arc-20160816; b=ORbpi+5JKxy0X4aKjFFRTli5Mq2Xih9XUCLZa67NtpsrL/mVZpclODJRryKPT5Rbhc GS3OQwU+JjA58ZyXsEP0M7rwRHKcXvNTfrqzBwn9AJ/xTePi4pscV4Xw644E+luRam+M 5yZ0TVbLgnttZLFTWizWUq4651nV/mCj0xdlOPTkbHJINPjhMAD3azl91SXveGwcKJtX fiNXDzD/VzYkjnhS78OecGcegH5SZM57DArDYdw0ETX6KCSmIeleIVlb5nDLP09ouYez HVMaRWQGLRFyhKUm/buwr270drC5B3q+U6HUoObrY9mb7nRCXDsR7H3pThsp4lKia1tB 0l+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=emdmglhhwUFISV9A8xk4dSxjG8+El3fT7Hgv/n1Jgrs=; b=Gq+wLKLVpCtW/DCq6xsI6SqRJ4UQh8IpiKlwzsAgQAzvZ/1GjQcd+/qukDWVMe8Mh0 BCDINvRdnSRMeZv52sbsQ6Yo2+TOUNMLwweXO15J4juFMQoBtvOsu4Q090FzuTCC5T/a aEccAGN3+92fiSZCB6X6kfClejujb3GA/sLf2Tlec9FXKzYjDRe5fmKCqW+JC5f+FWeb riRor/h5UJdpwihn4GdkneMvrmL8XEJqcENOslx1zICU5lkwKZVuqZCFsH+83/uulsVB pFJc0VWLb9M15zyzvqzDs5SxWhusvetY+iQCFW7Dgu92pgXp+tKzxf+MoqcoQ6IiHttT /69g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=default header.b=yiA0f10E; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a20-v6si6589657pls.237.2018.07.15.22.51.13; Sun, 15 Jul 2018 22:51:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=default header.b=yiA0f10E; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727182AbeGPGQx (ORCPT + 13 others); Mon, 16 Jul 2018 02:16:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:37114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726811AbeGPGQx (ORCPT ); Mon, 16 Jul 2018 02:16:53 -0400 Received: from localhost.localdomain (unknown [122.178.242.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3C8BF208DB; Mon, 16 Jul 2018 05:51:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1531720271; bh=6+OBQNvRg3jErPCKQ+HAePMkltPA+PT3CAaXbXhfc24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yiA0f10EU7rBHVJWS4gRZkT/2O7IvuVuAz1aZ2oQVMQXj9Q4BYWv7v0PD2XkA2QIH LUf8gnaeWhT+7jS5KjaeJctKcM/vHHzpSbN0cGXHe2sTqQ3pIcW/VcGEF9r9tBhmSB 7YuNiKuSwsYpRGs/Hw48DCvEoMw6K+UY5iR2/9yU= From: Vinod Koul To: linux-crypto@vger.kernel.org Cc: Bjorn Andersson , Matt Mackall , Herbert Xu , linux-arm-msm@vger.kernel.org, Stephen Boyd , Timur Tabi , Jeffrey Hugo , Vinod Koul Subject: [PATCH v6 1/6] hwrng: remove msm hw_random driver Date: Mon, 16 Jul 2018 11:20:22 +0530 Message-Id: <20180716055027.3048-2-vkoul@kernel.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180716055027.3048-1-vkoul@kernel.org> References: <20180716055027.3048-1-vkoul@kernel.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This driver is for a psedo-rng so should not be added in hwrng. Remove it so that it's replacement can be added. Signed-off-by: Vinod Koul --- drivers/char/hw_random/Kconfig | 13 --- drivers/char/hw_random/Makefile | 1 - drivers/char/hw_random/msm-rng.c | 183 --------------------------------------- 3 files changed, 197 deletions(-) delete mode 100644 drivers/char/hw_random/msm-rng.c -- 2.14.4 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index c34b257d852d..dac895dc01b9 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig @@ -307,19 +307,6 @@ config HW_RANDOM_HISI If unsure, say Y. -config HW_RANDOM_MSM - tristate "Qualcomm SoCs Random Number Generator support" - depends on HW_RANDOM && ARCH_QCOM - default HW_RANDOM - ---help--- - This driver provides kernel-side support for the Random Number - Generator hardware found on Qualcomm SoCs. - - To compile this driver as a module, choose M here. the - module will be called msm-rng. - - If unsure, say Y. - config HW_RANDOM_ST tristate "ST Microelectronics HW Random Number Generator support" depends on HW_RANDOM && ARCH_STI diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile index 533e913c93d1..e35ec3ce3a20 100644 --- a/drivers/char/hw_random/Makefile +++ b/drivers/char/hw_random/Makefile @@ -29,7 +29,6 @@ obj-$(CONFIG_HW_RANDOM_POWERNV) += powernv-rng.o obj-$(CONFIG_HW_RANDOM_HISI) += hisi-rng.o obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o obj-$(CONFIG_HW_RANDOM_IPROC_RNG200) += iproc-rng200.o -obj-$(CONFIG_HW_RANDOM_MSM) += msm-rng.o obj-$(CONFIG_HW_RANDOM_ST) += st-rng.o obj-$(CONFIG_HW_RANDOM_XGENE) += xgene-rng.o obj-$(CONFIG_HW_RANDOM_STM32) += stm32-rng.o diff --git a/drivers/char/hw_random/msm-rng.c b/drivers/char/hw_random/msm-rng.c deleted file mode 100644 index 841fee845ec9..000000000000 --- a/drivers/char/hw_random/msm-rng.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 and - * only version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -#include -#include -#include -#include -#include -#include -#include - -/* Device specific register offsets */ -#define PRNG_DATA_OUT 0x0000 -#define PRNG_STATUS 0x0004 -#define PRNG_LFSR_CFG 0x0100 -#define PRNG_CONFIG 0x0104 - -/* Device specific register masks and config values */ -#define PRNG_LFSR_CFG_MASK 0x0000ffff -#define PRNG_LFSR_CFG_CLOCKS 0x0000dddd -#define PRNG_CONFIG_HW_ENABLE BIT(1) -#define PRNG_STATUS_DATA_AVAIL BIT(0) - -#define MAX_HW_FIFO_DEPTH 16 -#define MAX_HW_FIFO_SIZE (MAX_HW_FIFO_DEPTH * 4) -#define WORD_SZ 4 - -struct msm_rng { - void __iomem *base; - struct clk *clk; - struct hwrng hwrng; -}; - -#define to_msm_rng(p) container_of(p, struct msm_rng, hwrng) - -static int msm_rng_enable(struct hwrng *hwrng, int enable) -{ - struct msm_rng *rng = to_msm_rng(hwrng); - u32 val; - int ret; - - ret = clk_prepare_enable(rng->clk); - if (ret) - return ret; - - if (enable) { - /* Enable PRNG only if it is not already enabled */ - val = readl_relaxed(rng->base + PRNG_CONFIG); - if (val & PRNG_CONFIG_HW_ENABLE) - goto already_enabled; - - val = readl_relaxed(rng->base + PRNG_LFSR_CFG); - val &= ~PRNG_LFSR_CFG_MASK; - val |= PRNG_LFSR_CFG_CLOCKS; - writel(val, rng->base + PRNG_LFSR_CFG); - - val = readl_relaxed(rng->base + PRNG_CONFIG); - val |= PRNG_CONFIG_HW_ENABLE; - writel(val, rng->base + PRNG_CONFIG); - } else { - val = readl_relaxed(rng->base + PRNG_CONFIG); - val &= ~PRNG_CONFIG_HW_ENABLE; - writel(val, rng->base + PRNG_CONFIG); - } - -already_enabled: - clk_disable_unprepare(rng->clk); - return 0; -} - -static int msm_rng_read(struct hwrng *hwrng, void *data, size_t max, bool wait) -{ - struct msm_rng *rng = to_msm_rng(hwrng); - size_t currsize = 0; - u32 *retdata = data; - size_t maxsize; - int ret; - u32 val; - - /* calculate max size bytes to transfer back to caller */ - maxsize = min_t(size_t, MAX_HW_FIFO_SIZE, max); - - ret = clk_prepare_enable(rng->clk); - if (ret) - return ret; - - /* read random data from hardware */ - do { - val = readl_relaxed(rng->base + PRNG_STATUS); - if (!(val & PRNG_STATUS_DATA_AVAIL)) - break; - - val = readl_relaxed(rng->base + PRNG_DATA_OUT); - if (!val) - break; - - *retdata++ = val; - currsize += WORD_SZ; - - /* make sure we stay on 32bit boundary */ - if ((maxsize - currsize) < WORD_SZ) - break; - } while (currsize < maxsize); - - clk_disable_unprepare(rng->clk); - - return currsize; -} - -static int msm_rng_init(struct hwrng *hwrng) -{ - return msm_rng_enable(hwrng, 1); -} - -static void msm_rng_cleanup(struct hwrng *hwrng) -{ - msm_rng_enable(hwrng, 0); -} - -static int msm_rng_probe(struct platform_device *pdev) -{ - struct resource *res; - struct msm_rng *rng; - int ret; - - rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL); - if (!rng) - return -ENOMEM; - - platform_set_drvdata(pdev, rng); - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - rng->base = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(rng->base)) - return PTR_ERR(rng->base); - - rng->clk = devm_clk_get(&pdev->dev, "core"); - if (IS_ERR(rng->clk)) - return PTR_ERR(rng->clk); - - rng->hwrng.name = KBUILD_MODNAME, - rng->hwrng.init = msm_rng_init, - rng->hwrng.cleanup = msm_rng_cleanup, - rng->hwrng.read = msm_rng_read, - - ret = devm_hwrng_register(&pdev->dev, &rng->hwrng); - if (ret) { - dev_err(&pdev->dev, "failed to register hwrng\n"); - return ret; - } - - return 0; -} - -static const struct of_device_id msm_rng_of_match[] = { - { .compatible = "qcom,prng", }, - {} -}; -MODULE_DEVICE_TABLE(of, msm_rng_of_match); - -static struct platform_driver msm_rng_driver = { - .probe = msm_rng_probe, - .driver = { - .name = KBUILD_MODNAME, - .of_match_table = of_match_ptr(msm_rng_of_match), - } -}; -module_platform_driver(msm_rng_driver); - -MODULE_ALIAS("platform:" KBUILD_MODNAME); -MODULE_AUTHOR("The Linux Foundation"); -MODULE_DESCRIPTION("Qualcomm MSM random number generator driver"); -MODULE_LICENSE("GPL v2"); From patchwork Mon Jul 16 05:50:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinod Koul X-Patchwork-Id: 141969 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2013095ljj; Sun, 15 Jul 2018 22:51:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdRfvU0wm6RD0AUUEeV40kQ/VTsfvWriWPgupatmfHAZSgFzaMI+zQUWmJfUhkY2Vlwvl66 X-Received: by 2002:a62:5dd7:: with SMTP id n84-v6mr16818412pfj.68.1531720275997; Sun, 15 Jul 2018 22:51:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531720275; cv=none; d=google.com; s=arc-20160816; b=Er51XL/HyTeSqa34XTCo0JT16d3r6KdX3r9/LvefD3Vg1RbvS6VX6tRku0jC8QqukT WFMYbPD9cdUObxWwoLVU6M5xsP5l+DR4JoZb7b3Q8dPR0Wfl7bRwIlRAhBZxWZLNn92B kVBn+L+hnZ7KqOv4/Bz9SJfn2odUrsPT67BBkMYQkTyYqO2Vvy353RYHmKgI3rE/a6y2 hCncIyxcjLUKHryYnYD+PX1Ivggh5hxy7qfiI0zG4hTo+wv3CRI69GbDZc1Mlcinfqt2 THMAsZhCdQDwGdn4Gls8Vw6OFzpsakdSMHxItetYS6USXu0bXy1MpLtosHNJiPj+D265 Us6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=VDtlY5teeUsBlNIHzZg7zEORLOlW6ZrScPDvyHxT9/0=; b=C0O1exljCDKVvLSzGftLrg3J3ceBO45klP0k8moETMmUt/vQYnotHVXJpDvRhmRyiH kviiX+FJWuFSmmW9qpF2UTgqYC9IlCJBffYt+YZ91FCk7yUS+zH09AIQv6ZY24B6G2Fa Lac/mge9pM2i/L5gi39rjSd1arfFxVEU7yElXxGy+uH/WH623Nf9uJEFFTyiJcPs1lvD yT4S2nX3sPLWVTD5vOryF4T1DOjRUZPcWp0B1Z7uNz4Wdk3oljT18gmnrLkfIr7NKd8F GxCnT2DvrX/oWLiUCWQ6U18I4mi3OdNxKeL9BRyrrHWl0hdHtREQL75aRr+QM8fEDca0 fUTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=default header.b=qc+hDD49; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a20-v6si6589657pls.237.2018.07.15.22.51.15; Sun, 15 Jul 2018 22:51:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=default header.b=qc+hDD49; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727419AbeGPGQz (ORCPT + 13 others); Mon, 16 Jul 2018 02:16:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:37140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726811AbeGPGQz (ORCPT ); Mon, 16 Jul 2018 02:16:55 -0400 Received: from localhost.localdomain (unknown [122.178.242.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 42B462086E; Mon, 16 Jul 2018 05:51:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1531720274; bh=Y6e/3n+guSDc62R6uIPH9agVkOQjWphtXjwR8dgS8bw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qc+hDD49vs7g+rZ2vJzBrbfdJxJnx5eRw0SolsG6kTtSkdkVs5IkzHa7RJlBZEBXw YTFMUmn4kC0naj/mZE3I0mpjPtOL3um9iKG0qIZ7uaotCH+PWjcRTGvMD369Yfsx0K AmAC1t6IQ10FIsDbnoWk4CK5BP65/mxJkUkX4iBg= From: Vinod Koul To: linux-crypto@vger.kernel.org Cc: Bjorn Andersson , Matt Mackall , Herbert Xu , linux-arm-msm@vger.kernel.org, Stephen Boyd , Timur Tabi , Jeffrey Hugo , Vinod Koul Subject: [PATCH v6 2/6] dt-bindings: crypto: Move prng binding to crypto Date: Mon, 16 Jul 2018 11:20:23 +0530 Message-Id: <20180716055027.3048-3-vkoul@kernel.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180716055027.3048-1-vkoul@kernel.org> References: <20180716055027.3048-1-vkoul@kernel.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Now that we are adding new driver for prng in crypto, move the binding as well. Signed-off-by: Vinod Koul --- Documentation/devicetree/bindings/{rng => crypto}/qcom,prng.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Documentation/devicetree/bindings/{rng => crypto}/qcom,prng.txt (100%) -- 2.14.4 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/Documentation/devicetree/bindings/rng/qcom,prng.txt b/Documentation/devicetree/bindings/crypto/qcom,prng.txt similarity index 100% rename from Documentation/devicetree/bindings/rng/qcom,prng.txt rename to Documentation/devicetree/bindings/crypto/qcom,prng.txt From patchwork Mon Jul 16 05:50:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinod Koul X-Patchwork-Id: 141970 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2013120ljj; Sun, 15 Jul 2018 22:51:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdIFvq1K1lfW1SofJaMHHRasjBT1zD5oQKN1fNhWRVI9vE/igqQnMrB5306KBFPwOfz++gH X-Received: by 2002:a17:902:b785:: with SMTP id e5-v6mr15454011pls.339.1531720278994; Sun, 15 Jul 2018 22:51:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531720278; cv=none; d=google.com; s=arc-20160816; b=H2K2Hc64N6Kfwq1Rj5axzaaC8ZUA8F6ERPKX8bjLVDFDnMUYUMlKnb4LbUfmU490nM yTWuvk8wTLx7I/35PiPv3nl4puhLwM2QNK+JEhPh4JUFCrUW+0mlNHQfpdJRhubMm6bw 4+7Fpm8cAwdd8ue4cwA3eU6PMWYDXcLfUje6mHHNjByPc2i3fTXnDrNpua7nrM+1iEph 3n4vv9cZ7gS0H8UsUYZLnZIWwKx7g3HUQ7V1EPgjViDtq9al+BeoemFJPD5Zhg2uto0T 3C9Wd/v/lNrIr8M4DHHcLsP+EdGDr2yznir/ClUuwQp4N0Npp1ogGvCq8buiwRvFJW3s n5BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=r9mclRqjz3/NwHtgLgeEb71uMNHsnZHyscMR4ha6zgI=; b=avbOYlAdoHlw1XN31QV/XWP/gcqQ1QAVkSqXC/4efbcEOI5sezyM3SIFICFaHVHjJV zevNNLL+HpTrpqzAYECViaxK1yqbVZBIYpSLsHIp0eVvJSTivwg4Zmo6d5wQpDjprJ8e qpob1uzgKiB36w0cd40MTM5NbaP75dCd5E/IZsWcFnwPjobZU+RyUrZMzwhdOHkhafZR O6F9fdo1s/wSuct2oT1ZLOBNewG9npjr+4lZYvLB/yVl+g3msQJ69H1byVjojn7BbTHF 2wbU47H4Ha1TdGIMc+hAY0ht0F2IuQ7Acy2Hg0dZwcyaQZVwkXnL6qVBCrkPAiJbv0Ov 2Khw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=default header.b=fXHCKY4w; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a20-v6si6589657pls.237.2018.07.15.22.51.18; Sun, 15 Jul 2018 22:51:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=default header.b=fXHCKY4w; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727522AbeGPGQ6 (ORCPT + 13 others); Mon, 16 Jul 2018 02:16:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:37170 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726811AbeGPGQ6 (ORCPT ); Mon, 16 Jul 2018 02:16:58 -0400 Received: from localhost.localdomain (unknown [122.178.242.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1E415208B2; Mon, 16 Jul 2018 05:51:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1531720277; bh=cVhnTy+GOkDADBJaMAPJLYiKAtJxnaWFEiLlxUa9SmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fXHCKY4wF4DTql+RBFkbsOsvPs7usP0hiL551GchErFfed8/EuOFs/zY3lv2e/UMh Dd4+U4z+hxVK/fDIgawv0I52+Lrlb4QQca0SIYRSVSVzBJlS0wy+DA5tboPajYHhGh G2g+qzXwyzwzVHBRJ6pK6xIVvp9FQ+fEqAHdzE/4= From: Vinod Koul To: linux-crypto@vger.kernel.org Cc: Bjorn Andersson , Matt Mackall , Herbert Xu , linux-arm-msm@vger.kernel.org, Stephen Boyd , Timur Tabi , Jeffrey Hugo , Vinod Koul Subject: [PATCH v6 3/6] crypto: Add Qcom prng driver Date: Mon, 16 Jul 2018 11:20:24 +0530 Message-Id: <20180716055027.3048-4-vkoul@kernel.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180716055027.3048-1-vkoul@kernel.org> References: <20180716055027.3048-1-vkoul@kernel.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This ports the Qcom prng from older hw_random driver. No change of functionality and move from hw_random to crypto APIs is done. Reviewed-by: Linus Walleij Signed-off-by: Vinod Koul --- drivers/crypto/Kconfig | 11 +++ drivers/crypto/Makefile | 1 + drivers/crypto/qcom-rng.c | 208 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 220 insertions(+) create mode 100644 drivers/crypto/qcom-rng.c -- 2.14.4 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index 43cccf6aff61..4156f9e8e397 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -585,6 +585,17 @@ config CRYPTO_DEV_QCE hardware. To compile this driver as a module, choose M here. The module will be called qcrypto. +config CRYPTO_DEV_QCOM_RNG + tristate "Qualcomm Random Number Generator Driver" + depends on ARCH_QCOM || COMPILE_TEST + select CRYPTO_RNG + help + This driver provides support for the Random Number + Generator hardware found on Qualcomm SoCs. + + To compile this driver as a module, choose M here. The + module will be called qcom-rng. If unsure, say N. + config CRYPTO_DEV_VMX bool "Support for VMX cryptographic acceleration instructions" depends on PPC64 && VSX diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile index 7ae87b4f6c8d..3602875c4f80 100644 --- a/drivers/crypto/Makefile +++ b/drivers/crypto/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_CRYPTO_DEV_PICOXCELL) += picoxcell_crypto.o obj-$(CONFIG_CRYPTO_DEV_PPC4XX) += amcc/ obj-$(CONFIG_CRYPTO_DEV_QAT) += qat/ obj-$(CONFIG_CRYPTO_DEV_QCE) += qce/ +obj-$(CONFIG_CRYPTO_DEV_QCOM_RNG) += qcom-rng.o obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rockchip/ obj-$(CONFIG_CRYPTO_DEV_S5P) += s5p-sss.o obj-$(CONFIG_CRYPTO_DEV_SAHARA) += sahara.o diff --git a/drivers/crypto/qcom-rng.c b/drivers/crypto/qcom-rng.c new file mode 100644 index 000000000000..e921382099d7 --- /dev/null +++ b/drivers/crypto/qcom-rng.c @@ -0,0 +1,208 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2017-18 Linaro Limited +// +// Based on msm-rng.c and downstream driver + +#include +#include +#include +#include +#include +#include + +/* Device specific register offsets */ +#define PRNG_DATA_OUT 0x0000 +#define PRNG_STATUS 0x0004 +#define PRNG_LFSR_CFG 0x0100 +#define PRNG_CONFIG 0x0104 + +/* Device specific register masks and config values */ +#define PRNG_LFSR_CFG_MASK 0x0000ffff +#define PRNG_LFSR_CFG_CLOCKS 0x0000dddd +#define PRNG_CONFIG_HW_ENABLE BIT(1) +#define PRNG_STATUS_DATA_AVAIL BIT(0) + +#define WORD_SZ 4 + +struct qcom_rng { + struct mutex lock; + void __iomem *base; + struct clk *clk; +}; + +struct qcom_rng_ctx { + struct qcom_rng *rng; +}; + +static struct qcom_rng *qcom_rng_dev; + +static int qcom_rng_read(struct qcom_rng *rng, u8 *data, unsigned int max) +{ + unsigned int currsize = 0; + u32 val; + + /* read random data from hardware */ + do { + val = readl_relaxed(rng->base + PRNG_STATUS); + if (!(val & PRNG_STATUS_DATA_AVAIL)) + break; + + val = readl_relaxed(rng->base + PRNG_DATA_OUT); + if (!val) + break; + + if ((max - currsize) >= WORD_SZ) { + memcpy(data, &val, WORD_SZ); + data += WORD_SZ; + currsize += WORD_SZ; + } else { + /* copy only remaining bytes */ + memcpy(data, &val, max - currsize); + break; + } + } while (currsize < max); + + return currsize; +} + +static int qcom_rng_generate(struct crypto_rng *tfm, + const u8 *src, unsigned int slen, + u8 *dstn, unsigned int dlen) +{ + struct qcom_rng_ctx *ctx = crypto_rng_ctx(tfm); + struct qcom_rng *rng = ctx->rng; + int ret; + + ret = clk_prepare_enable(rng->clk); + if (ret) + return ret; + + mutex_lock(&rng->lock); + + ret = qcom_rng_read(rng, dstn, dlen); + + mutex_unlock(&rng->lock); + clk_disable_unprepare(rng->clk); + + return 0; +} + +static int qcom_rng_seed(struct crypto_rng *tfm, const u8 *seed, + unsigned int slen) +{ + return 0; +} + +static int qcom_rng_enable(struct qcom_rng *rng) +{ + u32 val; + int ret; + + ret = clk_prepare_enable(rng->clk); + if (ret) + return ret; + + /* Enable PRNG only if it is not already enabled */ + val = readl_relaxed(rng->base + PRNG_CONFIG); + if (val & PRNG_CONFIG_HW_ENABLE) + goto already_enabled; + + val = readl_relaxed(rng->base + PRNG_LFSR_CFG); + val &= ~PRNG_LFSR_CFG_MASK; + val |= PRNG_LFSR_CFG_CLOCKS; + writel(val, rng->base + PRNG_LFSR_CFG); + + val = readl_relaxed(rng->base + PRNG_CONFIG); + val |= PRNG_CONFIG_HW_ENABLE; + writel(val, rng->base + PRNG_CONFIG); + +already_enabled: + clk_disable_unprepare(rng->clk); + + return 0; +} + +static int qcom_rng_init(struct crypto_tfm *tfm) +{ + struct qcom_rng_ctx *ctx = crypto_tfm_ctx(tfm); + + ctx->rng = qcom_rng_dev; + + return qcom_rng_enable(ctx->rng); +} + +static struct rng_alg qcom_rng_alg = { + .generate = qcom_rng_generate, + .seed = qcom_rng_seed, + .seedsize = 0, + .base = { + .cra_name = "stdrng", + .cra_driver_name = "qcom-rng", + .cra_flags = CRYPTO_ALG_TYPE_RNG, + .cra_priority = 300, + .cra_ctxsize = sizeof(struct qcom_rng_ctx), + .cra_module = THIS_MODULE, + .cra_init = qcom_rng_init, + } +}; + +static int qcom_rng_probe(struct platform_device *pdev) +{ + struct resource *res; + struct qcom_rng *rng; + int ret; + + rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL); + if (!rng) + return -ENOMEM; + + platform_set_drvdata(pdev, rng); + mutex_init(&rng->lock); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + rng->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(rng->base)) + return PTR_ERR(rng->base); + + rng->clk = devm_clk_get(&pdev->dev, "core"); + if (IS_ERR(rng->clk)) + return PTR_ERR(rng->clk); + + qcom_rng_dev = rng; + ret = crypto_register_rng(&qcom_rng_alg); + if (ret) { + dev_err(&pdev->dev, "Register crypto rng failed: %d\n", ret); + qcom_rng_dev = NULL; + } + + return ret; +} + +static int qcom_rng_remove(struct platform_device *pdev) +{ + crypto_unregister_rng(&qcom_rng_alg); + + qcom_rng_dev = NULL; + + return 0; +} + +static const struct of_device_id qcom_rng_of_match[] = { + { .compatible = "qcom,prng" }, + {} +}; +MODULE_DEVICE_TABLE(of, qcom_rng_of_match); + +static struct platform_driver qcom_rng_driver = { + .probe = qcom_rng_probe, + .remove = qcom_rng_remove, + .driver = { + .name = KBUILD_MODNAME, + .of_match_table = of_match_ptr(qcom_rng_of_match), + } +}; +module_platform_driver(qcom_rng_driver); + +MODULE_ALIAS("platform:" KBUILD_MODNAME); +MODULE_DESCRIPTION("Qualcomm random number generator driver"); +MODULE_LICENSE("GPL v2"); From patchwork Mon Jul 16 05:50:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinod Koul X-Patchwork-Id: 141972 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2013186ljj; Sun, 15 Jul 2018 22:51:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpftMOz2YpqialAUhM+Onw+QGxGuHuUk9ErCvORFdvkBkFG/Dnbk9su6IhLTecwG7EPmltzd X-Received: by 2002:a62:1603:: with SMTP id 3-v6mr612119pfw.245.1531720284455; Sun, 15 Jul 2018 22:51:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531720284; cv=none; d=google.com; s=arc-20160816; b=qgAnjj78CKgzMz+l5WEzRgEXqJIcu4vgYSvkPgmXihB0k2yHVuL4SalSRkFVo3KoR9 Eau5Z6CN3XQR5r4EukduRCtfia6LplD4lIQqTPQoq3TzQ2vKBgPTlydr4BbThuNfsea7 xO8YiQe5B4uGajpfDybuLnxEF5CxZEwXBV5Hs+rgvdbTlAu8f8Wwkks/d4RNAQEk9NYP 8ok4qRM2b7OWHkuJ8qPCQ8nJWCc8mcGaXRXb/YJEbxWvx2uu7WawclunhRuS1np/3z/h nGFARS7Bbj6YMAsW1GGDgSK6dEYa6m3S5ZRTVRU4njd30KPaIhnNRBC5HVqLe1NCEnrB OutQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=MfdC0goG16COzhpyCoxsPpOb4DMrB0oefmbFNAiUpNA=; b=ueFXRDhr8K2RLAvnb9EwdDP+aEcz2HDwllxHSnOHEV/bCDXhMeoxIRoUQHksUCkXQU TZJ8a3qjLJhH1x5N5nyync21xjOhZ9M6UHebwilsH5IsEdNIc1AdNHA7fkT5/nfh2xvi Qc7qfSePNkIC11sDdsr5HcxZm6W9zBynuxcOkssxYckUkdxF7YDlJWZ28vokkN1r5dyA Hxy9Nc+cqeiD2z3GpfB2OgTpKUB0vMSl7dRuixABluAeJyA+z2p00GBK7MEBpZyrcByR GnZarQVWqXARCk95FHpAdEcKVwqU/MHhbgFRsYR3se9h3PUiCCst9qC0Ytnus87xU0s4 Zz4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=default header.b=VYns+j2t; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a20-v6si6589657pls.237.2018.07.15.22.51.24; Sun, 15 Jul 2018 22:51:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=default header.b=VYns+j2t; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727616AbeGPGRE (ORCPT + 13 others); Mon, 16 Jul 2018 02:17:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:37214 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726811AbeGPGRE (ORCPT ); Mon, 16 Jul 2018 02:17:04 -0400 Received: from localhost.localdomain (unknown [122.178.242.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B73DB208DB; Mon, 16 Jul 2018 05:51:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1531720283; bh=OCd2g3/jbI7ACjQAqu6Un7n6IMFJQYto2K/y7juv+9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VYns+j2t2H/kI/mbBXK1JWJrrWEScajSRvmO8y7d3+52BbKvC/n1oY9Cw7gb42Nkr hxQC78MIw37HD//VM428s6G/jCNlbAr4lG3eeRhm4Fs4YuZDbpEPK7j0wiLBcpD0OS hMUc2eJPj1jOO3ggUZ0/o9NdtNVQGyO+6tmfWaYk= From: Vinod Koul To: linux-crypto@vger.kernel.org Cc: Bjorn Andersson , Matt Mackall , Herbert Xu , linux-arm-msm@vger.kernel.org, Stephen Boyd , Timur Tabi , Jeffrey Hugo , Vinod Koul Subject: [PATCH v6 5/6] crypto: qcom: Add support for prng-ee Date: Mon, 16 Jul 2018 11:20:26 +0530 Message-Id: <20180716055027.3048-6-vkoul@kernel.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180716055027.3048-1-vkoul@kernel.org> References: <20180716055027.3048-1-vkoul@kernel.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Qcom 8996 and later chips features multiple Execution Environments (EE) and secure world is typically responsible for configuring the prng. Add driver data for qcom,prng as 0 and qcom,prng-ee as 1 and use that to skip initialization routine. Signed-off-by: Vinod Koul --- drivers/crypto/qcom-rng.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- 2.14.4 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/crypto/qcom-rng.c b/drivers/crypto/qcom-rng.c index e921382099d7..80544326e310 100644 --- a/drivers/crypto/qcom-rng.c +++ b/drivers/crypto/qcom-rng.c @@ -28,6 +28,7 @@ struct qcom_rng { struct mutex lock; void __iomem *base; struct clk *clk; + unsigned int skip_init; }; struct qcom_rng_ctx { @@ -128,7 +129,10 @@ static int qcom_rng_init(struct crypto_tfm *tfm) ctx->rng = qcom_rng_dev; - return qcom_rng_enable(ctx->rng); + if (!ctx->rng->skip_init) + return qcom_rng_enable(ctx->rng); + + return 0; } static struct rng_alg qcom_rng_alg = { @@ -168,6 +172,8 @@ static int qcom_rng_probe(struct platform_device *pdev) if (IS_ERR(rng->clk)) return PTR_ERR(rng->clk); + rng->skip_init = (unsigned long)device_get_match_data(&pdev->dev); + qcom_rng_dev = rng; ret = crypto_register_rng(&qcom_rng_alg); if (ret) { @@ -188,7 +194,8 @@ static int qcom_rng_remove(struct platform_device *pdev) } static const struct of_device_id qcom_rng_of_match[] = { - { .compatible = "qcom,prng" }, + { .compatible = "qcom,prng", .data = (void *)0}, + { .compatible = "qcom,prng-ee", .data = (void *)1}, {} }; MODULE_DEVICE_TABLE(of, qcom_rng_of_match);