* [PATCH v2 0/3] hwrng: add support for Xiphera XIP8001B
@ 2020-08-20 10:51 Atte Tommiska
2020-08-20 10:51 ` [PATCH v2 1/3] dt-bindings: vendor-prefixes: Add Xiphera vendor prefix Atte Tommiska
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Atte Tommiska @ 2020-08-20 10:51 UTC (permalink / raw)
To: Matt Mackall, Herbert Xu, Rob Herring, Arnd Bergmann,
Greg Kroah-Hartman, linux-crypto, devicetree, linux-kernel
Cc: Atte Tommiska
This patchset introduces a linux driver for Xiphera's XIP8001B IP.
The IP is an FPGA-based TRNG which can be used in various FPGA families.
The IP is in use in multiple customer projects and in Xiphera's own products.
v2: fixed the 'make dt_binding_check' errors in the devicetree schema.
Atte Tommiska (3):
dt-bindings: vendor-prefixes: Add Xiphera vendor prefix
dt-bindings: rng: add bindings for Xiphera XIP8001B hwnrg
hwrng: xiphera-trng: add support for XIP8001B hwrng
.../bindings/rng/xiphera,xip8001b-trng.yaml | 33 ++++
.../devicetree/bindings/vendor-prefixes.yaml | 2 +
drivers/char/hw_random/Kconfig | 10 ++
drivers/char/hw_random/Makefile | 1 +
drivers/char/hw_random/xiphera-trng.c | 151 ++++++++++++++++++
5 files changed, 197 insertions(+)
create mode 100644 Documentation/devicetree/bindings/rng/xiphera,xip8001b-trng.yaml
create mode 100644 drivers/char/hw_random/xiphera-trng.c
base-commit: bc752d2f345bf55d71b3422a6a24890ea03168dc
--
2.28.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/3] dt-bindings: vendor-prefixes: Add Xiphera vendor prefix
2020-08-20 10:51 [PATCH v2 0/3] hwrng: add support for Xiphera XIP8001B Atte Tommiska
@ 2020-08-20 10:51 ` Atte Tommiska
2020-08-25 22:31 ` Rob Herring
2020-08-20 10:51 ` [PATCH v2 2/3] dt-bindings: rng: add bindings for Xiphera XIP8001B hwnrg Atte Tommiska
2020-08-20 10:51 ` [PATCH v2 3/3] hwrng: xiphera-trng: add support for XIP8001B hwrng Atte Tommiska
2 siblings, 1 reply; 8+ messages in thread
From: Atte Tommiska @ 2020-08-20 10:51 UTC (permalink / raw)
To: Matt Mackall, Herbert Xu, Rob Herring, Arnd Bergmann,
Greg Kroah-Hartman, linux-crypto, devicetree, linux-kernel
Cc: Atte Tommiska
Xiphera is an FPGA-based cryptographic solutions provider based in
Finland.
Website of the company: https://xiphera.com/
Signed-off-by: Atte Tommiska <atte.tommiska@xiphera.com>
---
Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index 2baee2c817c1..28ae913682b5 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -1174,6 +1174,8 @@ patternProperties:
description: Shenzhen Xingbangda Display Technology Co., Ltd
"^xinpeng,.*":
description: Shenzhen Xinpeng Technology Co., Ltd
+ "^xiphera,.*":
+ description: Xiphera Ltd.
"^xlnx,.*":
description: Xilinx
"^xnano,.*":
--
2.28.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/3] dt-bindings: rng: add bindings for Xiphera XIP8001B hwnrg
2020-08-20 10:51 [PATCH v2 0/3] hwrng: add support for Xiphera XIP8001B Atte Tommiska
2020-08-20 10:51 ` [PATCH v2 1/3] dt-bindings: vendor-prefixes: Add Xiphera vendor prefix Atte Tommiska
@ 2020-08-20 10:51 ` Atte Tommiska
2020-08-25 22:31 ` Rob Herring
2020-08-20 10:51 ` [PATCH v2 3/3] hwrng: xiphera-trng: add support for XIP8001B hwrng Atte Tommiska
2 siblings, 1 reply; 8+ messages in thread
From: Atte Tommiska @ 2020-08-20 10:51 UTC (permalink / raw)
To: Matt Mackall, Herbert Xu, Rob Herring, Arnd Bergmann,
Greg Kroah-Hartman, linux-crypto, devicetree, linux-kernel
Cc: Atte Tommiska
Document the device tree bindings of Xiphera's XIP8001B-trng IP.
Signed-off-by: Atte Tommiska <atte.tommiska@xiphera.com>
---
.../bindings/rng/xiphera,xip8001b-trng.yaml | 33 +++++++++++++++++++
1 file changed, 33 insertions(+)
create mode 100644 Documentation/devicetree/bindings/rng/xiphera,xip8001b-trng.yaml
diff --git a/Documentation/devicetree/bindings/rng/xiphera,xip8001b-trng.yaml b/Documentation/devicetree/bindings/rng/xiphera,xip8001b-trng.yaml
new file mode 100644
index 000000000000..1e17e55762f1
--- /dev/null
+++ b/Documentation/devicetree/bindings/rng/xiphera,xip8001b-trng.yaml
@@ -0,0 +1,33 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rng/xiphera,xip8001b-trng.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Xiphera XIP8001B-trng bindings
+
+maintainers:
+ - Atte Tommiska <atte.tommiska@xiphera.com>
+
+description: |
+ Xiphera FPGA-based true random number generator intellectual property core.
+
+properties:
+ compatible:
+ const: xiphera,xip8001b-trng
+
+ reg:
+ maxItems: 1
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ rng@43c00000 {
+ compatible = "xiphera,xip8001b-trng";
+ reg = <0x43c00000 0x10000>;
+ };
--
2.28.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/3] hwrng: xiphera-trng: add support for XIP8001B hwrng
2020-08-20 10:51 [PATCH v2 0/3] hwrng: add support for Xiphera XIP8001B Atte Tommiska
2020-08-20 10:51 ` [PATCH v2 1/3] dt-bindings: vendor-prefixes: Add Xiphera vendor prefix Atte Tommiska
2020-08-20 10:51 ` [PATCH v2 2/3] dt-bindings: rng: add bindings for Xiphera XIP8001B hwnrg Atte Tommiska
@ 2020-08-20 10:51 ` Atte Tommiska
2020-08-20 15:03 ` kernel test robot
2020-08-20 15:03 ` [PATCH] hwrng: xiphera-trng: fix platform_no_drv_owner.cocci warnings kernel test robot
2 siblings, 2 replies; 8+ messages in thread
From: Atte Tommiska @ 2020-08-20 10:51 UTC (permalink / raw)
To: Matt Mackall, Herbert Xu, Rob Herring, Arnd Bergmann,
Greg Kroah-Hartman, linux-crypto, devicetree, linux-kernel
Cc: Atte Tommiska
Xiphera XIP8001B is an FPGA-based True Random Number Generator
Intellectual Property (IP) Core which can be instantiated in
multiple FPGA families. This driver adds Linux support for it through
the hwrng interface.
Signed-off-by: Atte Tommiska <atte.tommiska@xiphera.com>
---
drivers/char/hw_random/Kconfig | 10 ++
drivers/char/hw_random/Makefile | 1 +
drivers/char/hw_random/xiphera-trng.c | 151 ++++++++++++++++++++++++++
3 files changed, 162 insertions(+)
create mode 100644 drivers/char/hw_random/xiphera-trng.c
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index f976a49e1fb5..007d765a9253 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -512,6 +512,16 @@ config HW_RANDOM_CCTRNG
will be called cctrng.
If unsure, say 'N'.
+config HW_RANDOM_XIPHERA
+ tristate "Xiphera FPGA based True Random Number Generator support"
+ depends on HAS_IOMEM
+ help
+ This driver provides kernel-side support for Xiphera True Random
+ Number Generator Intellectual Property Core.
+
+ To compile this driver as a module, choose M here: the
+ module will be called xiphera-trng.
+
endif # HW_RANDOM
config UML_RANDOM
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index 26ae06844f09..dfdcac81e384 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -44,3 +44,4 @@ obj-$(CONFIG_HW_RANDOM_KEYSTONE) += ks-sa-rng.o
obj-$(CONFIG_HW_RANDOM_OPTEE) += optee-rng.o
obj-$(CONFIG_HW_RANDOM_NPCM) += npcm-rng.o
obj-$(CONFIG_HW_RANDOM_CCTRNG) += cctrng.o
+obj-$(CONFIG_HW_RANDOM_XIPHERA) += xiphera-trng.o
diff --git a/drivers/char/hw_random/xiphera-trng.c b/drivers/char/hw_random/xiphera-trng.c
new file mode 100644
index 000000000000..2f082eb8e8a5
--- /dev/null
+++ b/drivers/char/hw_random/xiphera-trng.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2020 Xiphera Ltd. */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/hw_random.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+
+#define CONTROL_REG 0x00000000
+#define STATUS_REG 0x00000004
+#define RAND_REG 0x00000000
+
+#define HOST_TO_TRNG_RESET 0x00000001
+#define HOST_TO_TRNG_RELEASE_RESET 0x00000002
+#define HOST_TO_TRNG_ENABLE 0x80000000
+#define HOST_TO_TRNG_ZEROIZE 0x80000004
+#define HOST_TO_TRNG_ACK_ZEROIZE 0x80000008
+#define HOST_TO_TRNG_READ 0x8000000F
+
+/* trng statuses */
+#define TRNG_ACK_RESET 0x000000AC
+#define TRNG_SUCCESSFUL_STARTUP 0x00000057
+#define TRNG_FAILED_STARTUP 0x000000FA
+#define TRNG_NEW_RAND_AVAILABLE 0x000000ED
+
+struct xiphera_trng {
+ void __iomem *mem;
+ struct hwrng rng;
+};
+
+static int xiphera_trng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
+{
+ struct xiphera_trng *trng = container_of(rng, struct xiphera_trng, rng);
+ int ret = 0;
+
+ while (max >= sizeof(u32)) {
+ /* check for data */
+ if (readl(trng->mem + STATUS_REG) == TRNG_NEW_RAND_AVAILABLE) {
+ *(u32 *)buf = readl(trng->mem + RAND_REG);
+ /*
+ * Inform the trng of the read
+ * and re-enable it to produce a new random number
+ */
+ writel(HOST_TO_TRNG_READ, trng->mem + CONTROL_REG);
+ writel(HOST_TO_TRNG_ENABLE, trng->mem + CONTROL_REG);
+ ret += sizeof(u32);
+ buf += sizeof(u32);
+ max -= sizeof(u32);
+ } else {
+ break;
+ }
+ }
+ return ret;
+}
+
+static int xiphera_trng_probe(struct platform_device *pdev)
+{
+ int ret;
+ struct xiphera_trng *trng;
+ struct device *dev = &pdev->dev;
+ struct resource *res;
+
+ trng = devm_kzalloc(dev, sizeof(*trng), GFP_KERNEL);
+ if (!trng)
+ return -ENOMEM;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ trng->mem = devm_ioremap_resource(dev, res);
+ if (IS_ERR(trng->mem))
+ return PTR_ERR(trng->mem);
+
+ /*
+ * the trng needs to be reset first which might not happen in time,
+ * hence we incorporate a small delay to ensure proper behaviour
+ */
+ writel(HOST_TO_TRNG_RESET, trng->mem + CONTROL_REG);
+ usleep_range(100, 200);
+
+ if (readl(trng->mem + STATUS_REG) != TRNG_ACK_RESET) {
+ /*
+ * there is a small chance the trng is just not ready yet,
+ * so we try one more time. If the second time fails, we give up
+ */
+ usleep_range(100, 200);
+ if (readl(trng->mem + STATUS_REG) != TRNG_ACK_RESET) {
+ dev_err(dev, "failed to reset the trng ip\n");
+ return -ENODEV;
+ }
+ }
+
+ /*
+ * once again, to ensure proper behaviour we sleep
+ * for a while after zeroizing the trng
+ */
+ writel(HOST_TO_TRNG_RELEASE_RESET, trng->mem + CONTROL_REG);
+ writel(HOST_TO_TRNG_ENABLE, trng->mem + CONTROL_REG);
+ writel(HOST_TO_TRNG_ZEROIZE, trng->mem + CONTROL_REG);
+ msleep(20);
+
+ if (readl(trng->mem + STATUS_REG) != TRNG_SUCCESSFUL_STARTUP) {
+ /* diagnose the reason for the failure */
+ if (readl(trng->mem + STATUS_REG) == TRNG_FAILED_STARTUP) {
+ dev_err(dev, "trng ip startup-tests failed\n");
+ return -ENODEV;
+ }
+ dev_err(dev, "startup-tests yielded no response\n");
+ return -ENODEV;
+ }
+
+ writel(HOST_TO_TRNG_ACK_ZEROIZE, trng->mem + CONTROL_REG);
+
+ trng->rng.name = pdev->name;
+ trng->rng.read = xiphera_trng_read;
+ trng->rng.quality = 900;
+
+ ret = devm_hwrng_register(dev, &trng->rng);
+ if (ret) {
+ dev_err(dev, "failed to register rng device: %d\n", ret);
+ return ret;
+ }
+
+ platform_set_drvdata(pdev, trng);
+
+ return 0;
+}
+
+static const struct of_device_id xiphera_trng_of_match[] = {
+ { .compatible = "xiphera,xip8001b-trng", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, xiphera_trng_of_match);
+
+static struct platform_driver xiphera_trng_driver = {
+ .driver = {
+ .name = "xiphera-trng",
+ .owner = THIS_MODULE,
+ .of_match_table = xiphera_trng_of_match,
+ },
+ .probe = xiphera_trng_probe,
+};
+
+module_platform_driver(xiphera_trng_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Atte Tommiska");
+MODULE_DESCRIPTION("Xiphera FPGA-based true random number generator driver");
--
2.28.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 3/3] hwrng: xiphera-trng: add support for XIP8001B hwrng
2020-08-20 10:51 ` [PATCH v2 3/3] hwrng: xiphera-trng: add support for XIP8001B hwrng Atte Tommiska
@ 2020-08-20 15:03 ` kernel test robot
2020-08-20 15:03 ` [PATCH] hwrng: xiphera-trng: fix platform_no_drv_owner.cocci warnings kernel test robot
1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2020-08-20 15:03 UTC (permalink / raw)
To: Atte Tommiska, Matt Mackall, Herbert Xu, Rob Herring,
Arnd Bergmann, Greg Kroah-Hartman, linux-crypto, devicetree,
linux-kernel
Cc: kbuild-all, Atte Tommiska
[-- Attachment #1: Type: text/plain, Size: 832 bytes --]
Hi Atte,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on bc752d2f345bf55d71b3422a6a24890ea03168dc]
url: https://github.com/0day-ci/linux/commits/Atte-Tommiska/hwrng-add-support-for-Xiphera-XIP8001B/20200820-190349
base: bc752d2f345bf55d71b3422a6a24890ea03168dc
config: riscv-randconfig-c003-20200820 (attached as .config)
compiler: riscv32-linux-gcc (GCC) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
coccinelle warnings: (new ones prefixed by >>)
>> drivers/char/hw_random/xiphera-trng.c:141:3-8: No need to set .owner here. The core will do it.
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 27296 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] hwrng: xiphera-trng: fix platform_no_drv_owner.cocci warnings
2020-08-20 10:51 ` [PATCH v2 3/3] hwrng: xiphera-trng: add support for XIP8001B hwrng Atte Tommiska
2020-08-20 15:03 ` kernel test robot
@ 2020-08-20 15:03 ` kernel test robot
1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2020-08-20 15:03 UTC (permalink / raw)
To: Atte Tommiska, Matt Mackall, Herbert Xu, Rob Herring,
Arnd Bergmann, Greg Kroah-Hartman, linux-crypto, devicetree,
linux-kernel
Cc: kbuild-all, Atte Tommiska
From: kernel test robot <lkp@intel.com>
drivers/char/hw_random/xiphera-trng.c:141:3-8: No need to set .owner here. The core will do it.
Remove .owner field if calls are used which set it automatically
Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci
CC: Atte Tommiska <atte.tommiska@xiphera.com>
Signed-off-by: kernel test robot <lkp@intel.com>
---
url: https://github.com/0day-ci/linux/commits/Atte-Tommiska/hwrng-add-support-for-Xiphera-XIP8001B/20200820-190349
base: bc752d2f345bf55d71b3422a6a24890ea03168dc
xiphera-trng.c | 1 -
1 file changed, 1 deletion(-)
--- a/drivers/char/hw_random/xiphera-trng.c
+++ b/drivers/char/hw_random/xiphera-trng.c
@@ -138,7 +138,6 @@ MODULE_DEVICE_TABLE(of, xiphera_trng_of_
static struct platform_driver xiphera_trng_driver = {
.driver = {
.name = "xiphera-trng",
- .owner = THIS_MODULE,
.of_match_table = xiphera_trng_of_match,
},
.probe = xiphera_trng_probe,
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/3] dt-bindings: vendor-prefixes: Add Xiphera vendor prefix
2020-08-20 10:51 ` [PATCH v2 1/3] dt-bindings: vendor-prefixes: Add Xiphera vendor prefix Atte Tommiska
@ 2020-08-25 22:31 ` Rob Herring
0 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2020-08-25 22:31 UTC (permalink / raw)
To: Atte Tommiska
Cc: Arnd Bergmann, linux-kernel, Matt Mackall, Herbert Xu,
Rob Herring, linux-crypto, devicetree, Greg Kroah-Hartman
On Thu, 20 Aug 2020 13:51:20 +0300, Atte Tommiska wrote:
> Xiphera is an FPGA-based cryptographic solutions provider based in
> Finland.
> Website of the company: https://xiphera.com/
>
> Signed-off-by: Atte Tommiska <atte.tommiska@xiphera.com>
> ---
> Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
> 1 file changed, 2 insertions(+)
>
Acked-by: Rob Herring <robh@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/3] dt-bindings: rng: add bindings for Xiphera XIP8001B hwnrg
2020-08-20 10:51 ` [PATCH v2 2/3] dt-bindings: rng: add bindings for Xiphera XIP8001B hwnrg Atte Tommiska
@ 2020-08-25 22:31 ` Rob Herring
0 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2020-08-25 22:31 UTC (permalink / raw)
To: Atte Tommiska
Cc: Matt Mackall, Herbert Xu, Arnd Bergmann, Greg Kroah-Hartman,
linux-crypto, devicetree, linux-kernel
On Thu, Aug 20, 2020 at 01:51:21PM +0300, Atte Tommiska wrote:
> Document the device tree bindings of Xiphera's XIP8001B-trng IP.
typo in the subject. Otherwise,
Reviewed-by: Rob Herring <robh@kernel.org>
>
> Signed-off-by: Atte Tommiska <atte.tommiska@xiphera.com>
> ---
> .../bindings/rng/xiphera,xip8001b-trng.yaml | 33 +++++++++++++++++++
> 1 file changed, 33 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/rng/xiphera,xip8001b-trng.yaml
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-08-25 22:31 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-20 10:51 [PATCH v2 0/3] hwrng: add support for Xiphera XIP8001B Atte Tommiska
2020-08-20 10:51 ` [PATCH v2 1/3] dt-bindings: vendor-prefixes: Add Xiphera vendor prefix Atte Tommiska
2020-08-25 22:31 ` Rob Herring
2020-08-20 10:51 ` [PATCH v2 2/3] dt-bindings: rng: add bindings for Xiphera XIP8001B hwnrg Atte Tommiska
2020-08-25 22:31 ` Rob Herring
2020-08-20 10:51 ` [PATCH v2 3/3] hwrng: xiphera-trng: add support for XIP8001B hwrng Atte Tommiska
2020-08-20 15:03 ` kernel test robot
2020-08-20 15:03 ` [PATCH] hwrng: xiphera-trng: fix platform_no_drv_owner.cocci warnings kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).