Skip to contentSkip to conversation

crypto: Add Qcom PRNG support

PATCH In review Vinod Koul 4 participants 13 messages Jul 9, 2018 – Jul 16, 2018

Subsystems (4)
lore
Share & tools
lore

Vinod Koul

author
#0 lore raw

v5 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 v5:
- Update ACPI check and use generic driver data API

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                          | 229 +++++++++++++++++++++
 7 files changed, 244 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.c
Signature · 1 line
2.14.4
author
#1 lore raw

PATCH v5 1/6 hwrng: remove msm hw_random driver

This driver is for a psedo-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
index c34b257d852d..dac895dc01b9 100644
@@ -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
index 533e913c93d1..e35ec3ce3a20 100644
@@ -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
author
#2 lore raw

PATCH v5 2/6 dt-bindings: crypto: Move prng binding to crypto

In reply to Vinod Koul

Now 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
similarity index 100%
rename from Documentation/devicetree/bindings/rng/qcom,prng.txt
rename to Documentation/devicetree/bindings/crypto/qcom,prng.txt
Signature · 1 line
2.14.4
author
#3 lore raw

PATCH v5 3/6 crypto: Add Qcom prng driver

In reply to Vinod Koul

This 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
index 43cccf6aff61..b8d9e71e550a 100644
@@ -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
index 7ae87b4f6c8d..3602875c4f80 100644
@@ -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
Reviewed-by on v5 3/6
#4 lore raw

Re: [PATCH v5 3/6] crypto: Add Qcom prng driver

Quoted 6 lines · Vinod Koul

This ports the Qcom prng from older hw_random driver.

No change of functionality and move from hw_random to crypto APIs is done.

FWIW:

drivers/crypto/Kconfig config CRYPTO_DEV_QCE · line 589

Quoted 2 lines
drivers/crypto/Kconfig +2 -0
+config CRYPTO_DEV_QCOM_RNG
+       tristate "Qualcomm Randon Number Generator Driver"

Random speling error.

Quoted 1 line

+#include <linux/of_device.h>

Do you need this? It seems like a platform device fair and square.

Yours,
Linus Walleij

author
#5 lore raw

Re: [PATCH v5 3/6] crypto: Add Qcom prng driver

Quoted 11 lines · Linus Walleij
Quoted 6 lines · Vinod Koul

This ports the Qcom prng from older hw_random driver.

No change of functionality and move from hw_random to crypto APIs is done.

FWIW:

Thanks

Quoted 4 lines

drivers/crypto/Kconfig config CRYPTO_DEV_QCE · line 589

Quoted 2 lines
drivers/crypto/Kconfig +2 -0
+config CRYPTO_DEV_QCOM_RNG
+       tristate "Qualcomm Randon Number Generator Driver"

Random speling error.

Will fix, thanks for pointing

Quoted 3 lines
Quoted 1 line

+#include <linux/of_device.h>

Do you need this? It seems like a platform device fair and square.

It was required for of_device_get_match_data() but then the change is in subsequent patch, I should move that

Signature · 1 line
~Vinod
author
#6 lore raw

Re: [PATCH v5 3/6] crypto: Add Qcom prng driver

Quoted 9 lines · Vinod
Quoted 5 lines · Linus Walleij
Quoted 1 line · Vinod Koul

+#include <linux/of_device.h>

Do you need this? It seems like a platform device fair and square.

It was required for of_device_get_match_data() but then the change is in subsequent patch, I should move that

And I need of.h here for of_match_ptr. Added that and removed of_device.h.

Signature · 1 line
~Vinod
author
#7 lore raw

PATCH v5 4/6 dt-bindings: crypto: Add new compatible qcom,prng-ee

In reply to Vinod Koul

Later 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
index 8e5853c2879b..7ee0e9eac973 100644
@@ -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
author
#8 lore raw

PATCH v5 5/6 crypto: qcom: Add support for prng-ee

In reply to Vinod Koul

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.

---
 drivers/crypto/qcom-rng.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/crypto/qcom-rng.c +9 -2
index 53e1d276e05e..f1bd86acaf9d 100644
@@ -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
author
#9 lore raw

PATCH v5 6/6 crypto: qcom: Add ACPI support

In reply to Vinod Koul

From: 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.

[port to crypto API]
---
 drivers/crypto/qcom-rng.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/crypto/qcom-rng.c +18 -4
index f1bd86acaf9d..8118d4cd93b2 100644
@@ -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,13 +169,17 @@ 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 clk already on, so skip clk_get */
+	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 = (unsigned long)device_get_match_data(&pdev->dev);
 	qcom_rng_dev = rng;
+
 	ret = crypto_register_rng(&qcom_rng_alg);
 	if (ret) {
 		dev_err(&pdev->dev, "Register crypto rng failed: %d\n", ret);
@@ -193,6 +198,14 @@ 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", .driver_data = 1 },
+	{}
+};
+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 +219,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
Tested-by on v5 6/6
#10 lore raw

Re: [PATCH v5 6/6] crypto: qcom: Add ACPI support

Quoted 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.

[port to crypto API]
Quoted 62 lines
---
  drivers/crypto/qcom-rng.c | 22 ++++++++++++++++++----
  1 file changed, 18 insertions(+), 4 deletions(-)
drivers/crypto/qcom-rng.c +18 -4
index f1bd86acaf9d..8118d4cd93b2 100644
@@ -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,13 +169,17 @@ 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 clk already on, so skip clk_get */
+	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 = (unsigned long)device_get_match_data(&pdev->dev);
  	qcom_rng_dev = rng;
+
  	ret = crypto_register_rng(&qcom_rng_alg);
  	if (ret) {
  		dev_err(&pdev->dev, "Register crypto rng failed: %d\n", ret);
@@ -193,6 +198,14 @@ 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", .driver_data = 1 },
+	{}
+};
+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 +219,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.
#11 lore raw

Re: [PATCH v5 6/6] crypto: qcom: Add ACPI support

Quoted 8 lines · Jeffrey Hugo
Quoted 8 lines

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.

Quoted 5 lines
Quoted 3 lines
[port to crypto API]

Thanks, Jeff. I appreciate it.

author
#12 lore raw

Re: [PATCH v5 6/6] crypto: qcom: Add ACPI support

In reply to Jeffrey Hugo
Quoted 10 lines · Jeffrey Hugo
Quoted 9 lines · Vinod Koul

From: 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.

Quoted 5 lines
Quoted 3 lines
[port to crypto API]

Thanks Jeffrey.

Signature · 1 line
~Vinod