crypto: Add Qcom PRNG support
Subsystems (4)
v4 cover crypto: Add Qcom PRNG support
This series removes the hwrng qcom driver and replaces it with crypto qcom driver and then adds support for Execution Environment (EE) found in v2 version of the hardware and ACPI support for these
Changes in v4:
- Use memcpy for data copy
- Fix trailing bytes copy
- Fix ACPI ID table name
Timur Tabi (1):
crypto: qcom: Add ACPI support
Vinod Koul (5):
hwrng: remove msm hw_random driver
dt-bindings: crypto: Move prng binding to crypto
crypto: Add Qcom prng driver
dt-bindings: crypto: Add new compatible qcom,prng-ee
crypto: qcom: Add support for prng-ee
.../bindings/{rng => crypto}/qcom,prng.txt | 4 +-
drivers/char/hw_random/Kconfig | 13 --
drivers/char/hw_random/Makefile | 1 -
drivers/char/hw_random/msm-rng.c | 183 ----------------
drivers/crypto/Kconfig | 11 +
drivers/crypto/Makefile | 1 +
drivers/crypto/qcom-rng.c | 237 +++++++++++++++++++++
7 files changed, 252 insertions(+), 198 deletions(-)
rename Documentation/devicetree/bindings/{rng => crypto}/qcom,prng.txt (73%)
delete mode 100644 drivers/char/hw_random/msm-rng.c
create mode 100644 drivers/crypto/qcom-rng.cSignature · 1 line
2.14.4
PATCH v4 1/6 hwrng: remove msm hw_random driver
This driver is for a pseudo-rng so should not be added in hwrng. Remove it so that it's replacement can be added.
--- 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
drivers/char/hw_random/Kconfig +0 -13
@@ -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
drivers/char/hw_random/Makefile +0 -1
@@ -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
drivers/char/hw_random/msm-rng.c deleted +0 -183
183 lines not on this page · raw message
Signature · 1 line
2.14.4
PATCH v4 2/6 dt-bindings: crypto: Move prng binding to crypto
In reply to Vinod KoulNow that we are adding new driver for prng in crypto, move the binding as well.
---
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%)Documentation/devicetree/bindings/crypto/qcom,prng.txt renamed from Documentation/devicetree/bindings/rng/qcom,prng.txt +0 -0
Signature · 1 line
2.14.4
PATCH v4 3/6 crypto: Add Qcom prng driver
In reply to Vinod KoulThis ports the Qcom prng from older hw_random driver.
No change of functionality and move from hw_random to crypto APIs is done.
--- 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
drivers/crypto/Kconfig +11 -0
@@ -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 Randon 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
drivers/crypto/Makefile +1 -0
@@ -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
drivers/crypto/qcom-rng.c new file +208 -0
208 lines not on this page · raw message
Signature · 1 line
2.14.4
PATCH v4 4/6 dt-bindings: crypto: Add new compatible qcom,prng-ee
In reply to Vinod KoulLater qcom chips support v2 of the prng, which exposes an EE (Execution Environment) for OS to use so add new compatible qcom,prng-ee for this.
--- Documentation/devicetree/bindings/crypto/qcom,prng.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/crypto/qcom,prng.txt +3 -1
@@ -2,7 +2,9 @@ Qualcomm MSM pseudo random number generator. Required properties: -- compatible : should be "qcom,prng" +- compatible : should be "qcom,prng" for 8916 etc + : should be "qcom,prng-ee" for 8996 and later using EE + (Execution Environment) slice of prng - reg : specifies base physical address and size of the registers map - clocks : phandle to clock-controller plus clock-specifier pair - clock-names : "core" clocks all registers, FIFO and circuits in PRNG IP block
Signature · 1 line
2.14.4
PATCH v4 5/6 crypto: qcom: Add support for prng-ee
In reply to Vinod KoulQcom 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.
--- drivers/crypto/qcom-rng.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/crypto/qcom-rng.c +9 -2
@@ -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 )of_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);
Signature · 1 line
2.14.4
PATCH v4 6/6 crypto: qcom: Add ACPI support
In reply to Vinod KoulFrom: Timur Tabi <[email protected]>
Add support for probing on ACPI systems, with ACPI HID QCOM8160.
On ACPI systems, clocks are always enabled, the PRNG should already be enabled, and the register region is read-only. The driver only verifies that the hardware is already enabled never tries to disable or configure it.
--- drivers/crypto/qcom-rng.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)
drivers/crypto/qcom-rng.c +26 -4
@@ -4,6 +4,7 @@// Based on msm-rng.c and downstream driver #include <crypto/internal/rng.h> +#include <linux/acpi.h> #include <linux/clk.h> #include <linux/crypto.h> #include <linux/module.h>
@@ -168,11 +169,21 @@ static int qcom_rng_probe(struct platform_device *pdev)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->skip_init = (unsigned long )of_device_get_match_data (&pdev->dev); +/* +* ACPI systems have v2 hardware. The clocks are always enabled, +* and we should skip init +*/ +if (has_acpi_companion (&pdev->dev)) { + rng->skip_init =1 ; + }else { + rng->clk =devm_clk_get (&pdev->dev,"core" ); +if (IS_ERR (rng->clk)) +return PTR_ERR (rng->clk); + + rng->skip_init = + (unsigned long )of_device_get_match_data (&pdev->dev); + } qcom_rng_dev = rng; ret =crypto_register_rng (&qcom_rng_alg);
@@ -193,6 +204,16 @@ static int qcom_rng_remove(struct platform_device *pdev)return 0 ; } +#if IS_ENABLED (CONFIG_ACPI ) +static const struct acpi_device_id qcom_rng_acpi_match[] = { + { + .id ="QCOM8160" , + }, + {} +}; +MODULE_DEVICE_TABLE (acpi, qcom_rng_acpi_match); +#endif +static const struct of_device_id qcom_rng_of_match[] = { { .compatible ="qcom,prng" , .data = (void *)0 }, { .compatible ="qcom,prng-ee" , .data = (void *)1 },
@@ -206,6 +227,7 @@ static struct platform_driver qcom_rng_driver = { .driver = { .name = KBUILD_MODNAME, .of_match_table = of_match_ptr(qcom_rng_of_match), + .acpi_match_table = ACPI_PTR(qcom_rng_acpi_match), } };module_platform_driver (qcom_rng_driver);
Signature · 1 line
2.14.4
Re: [PATCH v4 6/6] crypto: qcom: Add ACPI support
drivers/crypto/qcom-rng.c static int qcom_rng_probe(struct platform_device *pdev) · line 186
Quoted 10 lines · Vinod Koul
drivers/crypto/qcom-rng.c +10
-0+if (has_acpi_companion (&pdev->dev)) { + rng->skip_init =1 ; + }else { + rng->clk =devm_clk_get (&pdev->dev,"core" ); +if (IS_ERR (rng->clk)) +return PTR_ERR (rng->clk); + + rng->skip_init = + (unsigned long )of_device_get_match_data (&pdev->dev); + }
There is a device_get_match_data() function, if you want to be consistent between ACPI and DT.
Re: [PATCH v4 6/6] crypto: qcom: Add ACPI support
Quoted 14 lines · Timur Tabi
drivers/crypto/qcom-rng.c static int qcom_rng_probe(struct platform_device *pdev) · line 186
Quoted 10 lines · Vinod Koul
drivers/crypto/qcom-rng.c +10
-0+if (has_acpi_companion (&pdev->dev)) { + rng->skip_init =1 ; + }else { + rng->clk =devm_clk_get (&pdev->dev,"core" ); +if (IS_ERR (rng->clk)) +return PTR_ERR (rng->clk); + + rng->skip_init = + (unsigned long )of_device_get_match_data (&pdev->dev); + }There is a
device_get_match_data()function, if you want to be consistent between ACPI and DT.
Yes we can add driver data in ACPI ID as well so code can be:
if (!has_acpi_companion(&pdev->dev)) {
rng->clk = devm_clk_get(&pdev->dev, "core");
if (IS_ERR(rng->clk))
return PTR_ERR(rng->clk);
}
rng->skip_init = device_get_match_data(&pdev->dev);Looks much neater.
I will wait for feedback on other patches before updating this.
Meanwhile any word from testing on ACPI systems?
Thanks
Signature · 1 line
~Vinod
Re: [PATCH v4 6/6] crypto: qcom: Add ACPI support
Quoted 1 line · Vinod
Meanwhile any word from testing on ACPI systems?
Jeff Hugo is handling that for me. Since it's a whole new API, he's had to start over.
Re: [PATCH v4 6/6] crypto: qcom: Add ACPI support
Quoted 5 lines · Timur Tabi
Quoted 1 line · Vinod
Meanwhile any word from testing on ACPI systems?
Jeff Hugo is handling that for me. Since it's a whole new API, he's had to start over.
Okay great, I have already been thru the hoops, so please do ping me if you folks have questions.
Thanks
Signature · 1 line
~Vinod
Re: [PATCH v4 6/6] crypto: qcom: Add ACPI support
In reply to VinodQuoted 10 lines · Vinod
Yes we can add driver data in ACPI ID as well so code can be:
if (!has_acpi_companion(&pdev->dev)) { rng->clk = devm_clk_get(&pdev->dev, "core"); if (IS_ERR(rng->clk)) return PTR_ERR(rng->clk); } rng->skip_init = device_get_match_data(&pdev->dev);Looks much neater.
Yeah, I like it.
Quoted 1 line
I will wait for feedback on other patches before updating this.
Jeff said it works, so I guess v5 will be good to go.
Re: [PATCH v4 6/6] crypto: qcom: Add ACPI support
Quoted 10 lines · Timur Tabi
Quoted 9 lines · Vinod
Yes we can add driver data in ACPI ID as well so code can be:
if (!has_acpi_companion(&pdev->dev)) { rng->clk = devm_clk_get(&pdev->dev, "core"); if (IS_ERR(rng->clk)) return PTR_ERR(rng->clk); } rng->skip_init = device_get_match_data(&pdev->dev);
Quoted 7 lines
Quoted 1 line
Looks much neater.
Yeah, I like it.
Quoted 1 line
I will wait for feedback on other patches before updating this.
Jeff said it works, so I guess v5 will be good to go.
Yes posting that right now. It would be great if you folks can test again on ACPI systems
Thanks
Signature · 1 line
~Vinod
Re: [PATCH v4 6/6] crypto: qcom: Add ACPI support
Quoted 15 lines · Vinod
Quoted 14 lines · Timur Tabi
Quoted 10 lines · Vinod
Yes we can add driver data in ACPI ID as well so code can be:
if (!has_acpi_companion(&pdev->dev)) { rng->clk = devm_clk_get(&pdev->dev, "core"); if (IS_ERR(rng->clk)) return PTR_ERR(rng->clk); } rng->skip_init = device_get_match_data(&pdev->dev);Looks much neater.
Yeah, I like it.
Quoted 9 lines
Quoted 3 lines
Quoted 1 line
I will wait for feedback on other patches before updating this.
Jeff said it works, so I guess v5 will be good to go.
Yes posting that right now. It would be great if you folks can test again on ACPI systems
Thanks
I might need a day, but I'll get to it.
Signature · 4 lines
Jeffrey Hugo Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH v4 6/6] crypto: qcom: Add ACPI support
In reply to Vinod KoulQuoted 4 lines · Vinod Koul
From: Timur Tabi <[email protected]>
Add support for probing on ACPI systems, with ACPI HID QCOM8160.
Quoted 8 lines
On ACPI systems, clocks are always enabled, the PRNG should already be enabled, and the register region is read-only. The driver only verifies that the hardware is already enabled never tries to disable or configure it.
Signed-off-by Timur Tabi <[email protected]>[port to crypto API]Signed-off-by Vinod Koul <[email protected]>
Quoted 68 lines
--- drivers/crypto/qcom-rng.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)drivers/crypto/qcom-rng.c +26
-4@@ -4,6 +4,7 @@// Based on msm-rng.c and downstream driver #include <crypto/internal/rng.h> +#include <linux/acpi.h> #include <linux/clk.h> #include <linux/crypto.h> #include <linux/module.h> @@ -168,11 +169,21 @@ static int qcom_rng_probe(struct platform_device *pdev)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->skip_init = (unsigned long )of_device_get_match_data (&pdev->dev); +/* +* ACPI systems have v2 hardware. The clocks are always enabled, +* and we should skip init +*/ +if (has_acpi_companion (&pdev->dev)) { + rng->skip_init =1 ; + }else { + rng->clk =devm_clk_get (&pdev->dev,"core" ); +if (IS_ERR (rng->clk)) +return PTR_ERR (rng->clk); + + rng->skip_init = + (unsigned long )of_device_get_match_data (&pdev->dev); + } qcom_rng_dev = rng; ret =crypto_register_rng (&qcom_rng_alg);@@ -193,6 +204,16 @@ static int qcom_rng_remove(struct platform_device *pdev)return 0 ; } +#if IS_ENABLED (CONFIG_ACPI ) +static const struct acpi_device_id qcom_rng_acpi_match[] = { + { + .id ="QCOM8160" , + }, + {} +}; +MODULE_DEVICE_TABLE (acpi, qcom_rng_acpi_match); +#endif +static const struct of_device_id qcom_rng_of_match[] = { { .compatible ="qcom,prng" , .data = (void *)0 }, { .compatible ="qcom,prng-ee" , .data = (void *)1 },@@ -206,6 +227,7 @@ static struct platform_driver qcom_rng_driver = { .driver = { .name = KBUILD_MODNAME, .of_match_table = of_match_ptr(qcom_rng_of_match), + .acpi_match_table = ACPI_PTR(qcom_rng_acpi_match), } };module_platform_driver (qcom_rng_driver);
Signature · 4 lines
Jeffrey Hugo Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.