2020-06-21 19:32:32

by Corentin LABBE

[permalink] [raw]
Subject: [PATCH v3 14/14] crypto: sun8i-ce: Add support for the TRNG

This patch had support for the TRNG present in the CE.
Note that according to the algorithm ID, 2 version of the TRNG exists,
the first present in H3/H5/R40/A64 and the second present in H6.
This patch adds support for both, but only the second is working
reliabily accoridng to rngtest.

Signed-off-by: Corentin Labbe <[email protected]>
---
drivers/crypto/allwinner/Kconfig | 8 ++
drivers/crypto/allwinner/sun8i-ce/Makefile | 1 +
.../crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 18 +++
.../crypto/allwinner/sun8i-ce/sun8i-ce-trng.c | 124 ++++++++++++++++++
drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 18 +++
5 files changed, 169 insertions(+)
create mode 100644 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c

diff --git a/drivers/crypto/allwinner/Kconfig b/drivers/crypto/allwinner/Kconfig
index 223a5823867c..6aec31f7d2be 100644
--- a/drivers/crypto/allwinner/Kconfig
+++ b/drivers/crypto/allwinner/Kconfig
@@ -87,6 +87,14 @@ config CRYPTO_DEV_SUN8I_CE_PRNG
Select this option if you want to provide kernel-side support for
the Pseudo-Random Number Generator found in the Crypto Engine.

+config CRYPTO_DEV_SUN8I_CE_TRNG
+ bool "Support for Allwinner Crypto Engine TRNG"
+ depends on CRYPTO_DEV_SUN8I_CE
+ select HW_RANDOM
+ help
+ Select this option if you want to provide kernel-side support for
+ the True Random Number Generator found in the Crypto Engine.
+
config CRYPTO_DEV_SUN8I_SS
tristate "Support for Allwinner Security System cryptographic offloader"
select CRYPTO_SKCIPHER
diff --git a/drivers/crypto/allwinner/sun8i-ce/Makefile b/drivers/crypto/allwinner/sun8i-ce/Makefile
index c0ea81da2c7d..0842eb2d9408 100644
--- a/drivers/crypto/allwinner/sun8i-ce/Makefile
+++ b/drivers/crypto/allwinner/sun8i-ce/Makefile
@@ -2,3 +2,4 @@ obj-$(CONFIG_CRYPTO_DEV_SUN8I_CE) += sun8i-ce.o
sun8i-ce-y += sun8i-ce-core.o sun8i-ce-cipher.o
sun8i-ce-$(CONFIG_CRYPTO_DEV_SUN8I_CE_HASH) += sun8i-ce-hash.o
sun8i-ce-$(CONFIG_CRYPTO_DEV_SUN8I_CE_PRNG) += sun8i-ce-prng.o
+sun8i-ce-$(CONFIG_CRYPTO_DEV_SUN8I_CE_TRNG) += sun8i-ce-trng.o
diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c
index 33790fee2c81..f1d6f34ea20e 100644
--- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c
@@ -47,6 +47,7 @@ static const struct ce_variant ce_h3_variant = {
},
.esr = ESR_H3,
.prng = CE_ALG_PRNG,
+ .trng = CE_ID_NOTSUPP,
};

static const struct ce_variant ce_h5_variant = {
@@ -63,6 +64,7 @@ static const struct ce_variant ce_h5_variant = {
},
.esr = ESR_H5,
.prng = CE_ALG_PRNG,
+ .trng = CE_ID_NOTSUPP,
};

static const struct ce_variant ce_h6_variant = {
@@ -76,6 +78,7 @@ static const struct ce_variant ce_h6_variant = {
.cipher_t_dlen_in_bytes = true,
.hash_t_dlen_in_bits = true,
.prng_t_dlen_in_bytes = true,
+ .trng_t_dlen_in_bytes = true,
.ce_clks = {
{ "bus", 0, 200000000 },
{ "mod", 300000000, 0 },
@@ -83,6 +86,7 @@ static const struct ce_variant ce_h6_variant = {
},
.esr = ESR_H6,
.prng = CE_ALG_PRNG_V2,
+ .trng = CE_ALG_TRNG_V2,
};

static const struct ce_variant ce_a64_variant = {
@@ -99,6 +103,7 @@ static const struct ce_variant ce_a64_variant = {
},
.esr = ESR_A64,
.prng = CE_ALG_PRNG,
+ .trng = CE_ID_NOTSUPP,
};

static const struct ce_variant ce_r40_variant = {
@@ -115,6 +120,7 @@ static const struct ce_variant ce_r40_variant = {
},
.esr = ESR_R40,
.prng = CE_ALG_PRNG,
+ .trng = CE_ID_NOTSUPP,
};

/*
@@ -582,6 +588,10 @@ static int sun8i_ce_dbgfs_read(struct seq_file *seq, void *v)
break;
}
}
+#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_TRNG
+ seq_printf(seq, "HWRNG %lu %lu\n",
+ ce->hwrng_stat_req, ce->hwrng_stat_bytes);
+#endif
return 0;
}

@@ -932,6 +942,10 @@ static int sun8i_ce_probe(struct platform_device *pdev)
if (err < 0)
goto error_alg;

+#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_TRNG
+ sun8i_ce_hwrng_register(ce);
+#endif
+
v = readl(ce->base + CE_CTR);
v >>= CE_DIE_ID_SHIFT;
v &= CE_DIE_ID_MASK;
@@ -961,6 +975,10 @@ static int sun8i_ce_remove(struct platform_device *pdev)
{
struct sun8i_ce_dev *ce = platform_get_drvdata(pdev);

+#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_TRNG
+ sun8i_ce_hwrng_unregister(ce);
+#endif
+
sun8i_ce_unregister_algs(ce);

#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c
new file mode 100644
index 000000000000..b8bab377906d
--- /dev/null
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * sun8i-ce-trng.c - hardware cryptographic offloader for
+ * Allwinner H3/A64/H5/H2+/H6/R40 SoC
+ *
+ * Copyright (C) 2015-2020 Corentin Labbe <[email protected]>
+ *
+ * This file handle the TRNG
+ *
+ * You could find a link for the datasheet in Documentation/arm/sunxi/README
+ */
+#include "sun8i-ce.h"
+#include <linux/pm_runtime.h>
+#include <linux/hw_random.h>
+/*
+ * Note that according to the algorithm ID, 2 versions of the TRNG exists,
+ * The first present in H3/H5/R40/A64 and the second present in H6.
+ * This file adds support for both, but only the second is working
+ * reliabily according to rngtest.
+ **/
+
+int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)
+{
+ struct sun8i_ce_dev *ce;
+ dma_addr_t dma_dst;
+ int err = 0;
+ int flow = 3;
+ unsigned int todo;
+ struct sun8i_ce_flow *chan;
+ struct ce_task *cet;
+ u32 common;
+ void *d;
+
+ ce = container_of(rng, struct sun8i_ce_dev, trng);
+
+ /* round the data length to a multiple of 32*/
+ todo = max + 32;
+ todo -= todo % 32;
+
+ d = kzalloc(todo, GFP_KERNEL | GFP_DMA);
+ if (!d)
+ return -ENOMEM;
+
+#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
+ ce->hwrng_stat_req++;
+ ce->hwrng_stat_bytes += todo;
+#endif
+
+ dma_dst = dma_map_single(ce->dev, d, todo, DMA_FROM_DEVICE);
+ if (dma_mapping_error(ce->dev, dma_dst)) {
+ dev_err(ce->dev, "Cannot DMA MAP DST\n");
+ err = -EFAULT;
+ goto err_dst;
+ }
+
+ err = pm_runtime_get_sync(ce->dev);
+ if (err < 0)
+ goto err_pm;
+
+ mutex_lock(&ce->rnglock);
+ chan = &ce->chanlist[flow];
+
+ cet = &chan->tl[0];
+ memset(cet, 0, sizeof(struct ce_task));
+
+ cet->t_id = cpu_to_le32(flow);
+ common = ce->variant->trng | CE_COMM_INT;
+ cet->t_common_ctl = cpu_to_le32(common);
+
+ /* recent CE (H6) need length in bytes, in word otherwise */
+ if (ce->variant->trng_t_dlen_in_bytes)
+ cet->t_dlen = cpu_to_le32(todo);
+ else
+ cet->t_dlen = cpu_to_le32(todo / 4);
+
+ cet->t_sym_ctl = 0;
+ cet->t_asym_ctl = 0;
+
+ cet->t_dst[0].addr = cpu_to_le32(dma_dst);
+ cet->t_dst[0].len = cpu_to_le32(todo / 4);
+ ce->chanlist[flow].timeout = todo;
+
+ err = sun8i_ce_run_task(ce, 3, "TRNG");
+ mutex_unlock(&ce->rnglock);
+
+ pm_runtime_put(ce->dev);
+
+err_pm:
+ dma_unmap_single(ce->dev, dma_dst, todo, DMA_FROM_DEVICE);
+
+ if (!err) {
+ memcpy(data, d, max);
+ err = max;
+ }
+ memzero_explicit(d, todo);
+err_dst:
+ kfree(d);
+ return err;
+}
+
+int sun8i_ce_hwrng_register(struct sun8i_ce_dev *ce)
+{
+ int ret;
+
+ if (ce->variant->trng == CE_ID_NOTSUPP) {
+ dev_info(ce->dev, "TRNG not supported\n");
+ return 0;
+ }
+ ce->trng.name = "sun8i Crypto Engine TRNG";
+ ce->trng.read = sun8i_ce_trng_read;
+ ce->trng.quality = 1000;
+
+ ret = hwrng_register(&ce->trng);
+ if (ret)
+ dev_err(ce->dev, "Fail to register the TRNG\n");
+ return ret;
+}
+
+void sun8i_ce_hwrng_unregister(struct sun8i_ce_dev *ce)
+{
+ if (ce->variant->trng == CE_ID_NOTSUPP)
+ return;
+ hwrng_unregister(&ce->trng);
+}
diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h
index 2ef0c3814367..746e56c254d4 100644
--- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h
@@ -12,6 +12,7 @@
#include <linux/atomic.h>
#include <linux/debugfs.h>
#include <linux/crypto.h>
+#include <linux/hw_random.h>
#include <crypto/internal/hash.h>
#include <crypto/md5.h>
#include <crypto/rng.h>
@@ -55,7 +56,9 @@
#define CE_ALG_SHA256 19
#define CE_ALG_SHA384 20
#define CE_ALG_SHA512 21
+#define CE_ALG_TRNG 48
#define CE_ALG_PRNG 49
+#define CE_ALG_TRNG_V2 0x1c
#define CE_ALG_PRNG_V2 0x1d

/* Used in ce_variant */
@@ -129,9 +132,12 @@ struct ce_clock {
* bits or words
* @prng_t_dlen_in_bytes: Does the request size for PRNG is in
* bytes or words
+ * @trng_t_dlen_in_bytes: Does the request size for TRNG is in
+ * bytes or words
* @ce_clks: list of clocks needed by this variant
* @esr: The type of error register
* @prng: The CE_ALG_XXX value for the PRNG
+ * @trng: The CE_ALG_XXX value for the TRNG
*/
struct ce_variant {
char alg_cipher[CE_ID_CIPHER_MAX];
@@ -140,9 +146,11 @@ struct ce_variant {
bool cipher_t_dlen_in_bytes;
bool hash_t_dlen_in_bits;
bool prng_t_dlen_in_bytes;
+ bool trng_t_dlen_in_bytes;
struct ce_clock ce_clks[CE_MAX_CLOCKS];
int esr;
char prng;
+ char trng;
};

struct sginfo {
@@ -218,6 +226,13 @@ struct sun8i_ce_dev {
struct dentry *dbgfs_dir;
struct dentry *dbgfs_stats;
#endif
+#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_TRNG
+ struct hwrng trng;
+#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
+ unsigned long hwrng_stat_req;
+ unsigned long hwrng_stat_bytes;
+#endif
+#endif
};

/*
@@ -349,3 +364,6 @@ int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 *src,
int sun8i_ce_prng_seed(struct crypto_rng *tfm, const u8 *seed, unsigned int slen);
void sun8i_ce_prng_exit(struct crypto_tfm *tfm);
int sun8i_ce_prng_init(struct crypto_tfm *tfm);
+
+int sun8i_ce_hwrng_register(struct sun8i_ce_dev *ce);
+void sun8i_ce_hwrng_unregister(struct sun8i_ce_dev *ce);
--
2.26.2


2020-06-21 22:27:26

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v3 14/14] crypto: sun8i-ce: Add support for the TRNG

Hi Corentin,

I love your patch! Perhaps something to improve:

[auto build test WARNING on sunxi/sunxi/for-next]
[also build test WARNING on cryptodev/master crypto/master v5.8-rc1]
[cannot apply to next-20200621]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Corentin-Labbe/crypto-allwinner-add-xRNG-and-hashes/20200622-033401
base: https://git.kernel.org/pub/scm/linux/kernel/git/sunxi/linux.git sunxi/for-next
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sh

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c:22:5: warning: no previous prototype for 'sun8i_ce_trng_read' [-Wmissing-prototypes]
22 | int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)
| ^~~~~~~~~~~~~~~~~~
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c: In function 'sun8i_ce_hwrng_register':
>> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c:105:24: warning: comparison is always false due to limited range of data type [-Wtype-limits]
105 | if (ce->variant->trng == CE_ID_NOTSUPP) {
| ^~
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c: In function 'sun8i_ce_hwrng_unregister':
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c:121:24: warning: comparison is always false due to limited range of data type [-Wtype-limits]
121 | if (ce->variant->trng == CE_ID_NOTSUPP)
| ^~

vim +/sun8i_ce_trng_read +22 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c

> 22 int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)
23 {
24 struct sun8i_ce_dev *ce;
25 dma_addr_t dma_dst;
26 int err = 0;
27 int flow = 3;
28 unsigned int todo;
29 struct sun8i_ce_flow *chan;
30 struct ce_task *cet;
31 u32 common;
32 void *d;
33
34 ce = container_of(rng, struct sun8i_ce_dev, trng);
35
36 /* round the data length to a multiple of 32*/
37 todo = max + 32;
38 todo -= todo % 32;
39
40 d = kzalloc(todo, GFP_KERNEL | GFP_DMA);
41 if (!d)
42 return -ENOMEM;
43
44 #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
45 ce->hwrng_stat_req++;
46 ce->hwrng_stat_bytes += todo;
47 #endif
48
49 dma_dst = dma_map_single(ce->dev, d, todo, DMA_FROM_DEVICE);
50 if (dma_mapping_error(ce->dev, dma_dst)) {
51 dev_err(ce->dev, "Cannot DMA MAP DST\n");
52 err = -EFAULT;
53 goto err_dst;
54 }
55
56 err = pm_runtime_get_sync(ce->dev);
57 if (err < 0)
58 goto err_pm;
59
60 mutex_lock(&ce->rnglock);
61 chan = &ce->chanlist[flow];
62
63 cet = &chan->tl[0];
64 memset(cet, 0, sizeof(struct ce_task));
65
66 cet->t_id = cpu_to_le32(flow);
67 common = ce->variant->trng | CE_COMM_INT;
68 cet->t_common_ctl = cpu_to_le32(common);
69
70 /* recent CE (H6) need length in bytes, in word otherwise */
71 if (ce->variant->trng_t_dlen_in_bytes)
72 cet->t_dlen = cpu_to_le32(todo);
73 else
74 cet->t_dlen = cpu_to_le32(todo / 4);
75
76 cet->t_sym_ctl = 0;
77 cet->t_asym_ctl = 0;
78
79 cet->t_dst[0].addr = cpu_to_le32(dma_dst);
80 cet->t_dst[0].len = cpu_to_le32(todo / 4);
81 ce->chanlist[flow].timeout = todo;
82
83 err = sun8i_ce_run_task(ce, 3, "TRNG");
84 mutex_unlock(&ce->rnglock);
85
86 pm_runtime_put(ce->dev);
87
88 err_pm:
89 dma_unmap_single(ce->dev, dma_dst, todo, DMA_FROM_DEVICE);
90
91 if (!err) {
92 memcpy(data, d, max);
93 err = max;
94 }
95 memzero_explicit(d, todo);
96 err_dst:
97 kfree(d);
98 return err;
99 }
100
101 int sun8i_ce_hwrng_register(struct sun8i_ce_dev *ce)
102 {
103 int ret;
104
> 105 if (ce->variant->trng == CE_ID_NOTSUPP) {
106 dev_info(ce->dev, "TRNG not supported\n");
107 return 0;
108 }
109 ce->trng.name = "sun8i Crypto Engine TRNG";
110 ce->trng.read = sun8i_ce_trng_read;
111 ce->trng.quality = 1000;
112
113 ret = hwrng_register(&ce->trng);
114 if (ret)
115 dev_err(ce->dev, "Fail to register the TRNG\n");
116 return ret;
117 }
118

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (5.01 kB)
.config.gz (53.62 kB)
Download all attachments

2020-06-22 00:38:02

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v3 14/14] crypto: sun8i-ce: Add support for the TRNG

Hi Corentin,

I love your patch! Perhaps something to improve:

[auto build test WARNING on sunxi/sunxi/for-next]
[also build test WARNING on cryptodev/master crypto/master v5.8-rc2]
[cannot apply to next-20200621]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Corentin-Labbe/crypto-allwinner-add-xRNG-and-hashes/20200622-033401
base: https://git.kernel.org/pub/scm/linux/kernel/git/sunxi/linux.git sunxi/for-next
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project ef455a55bcf2cfea04a99c361b182ad18b7f03f1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c:22:5: warning: no previous prototype for function 'sun8i_ce_trng_read' [-Wmissing-prototypes]
int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)
^
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c:22:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)
^
static
>> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c:105:24: warning: result of comparison of constant 255 with expression of type 'const char' is always false [-Wtautological-constant-out-of-range-compare]
if (ce->variant->trng == CE_ID_NOTSUPP) {
~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c:121:24: warning: result of comparison of constant 255 with expression of type 'const char' is always false [-Wtautological-constant-out-of-range-compare]
if (ce->variant->trng == CE_ID_NOTSUPP)
~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~
3 warnings generated.

vim +/sun8i_ce_trng_read +22 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c

> 22 int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)
23 {
24 struct sun8i_ce_dev *ce;
25 dma_addr_t dma_dst;
26 int err = 0;
27 int flow = 3;
28 unsigned int todo;
29 struct sun8i_ce_flow *chan;
30 struct ce_task *cet;
31 u32 common;
32 void *d;
33
34 ce = container_of(rng, struct sun8i_ce_dev, trng);
35
36 /* round the data length to a multiple of 32*/
37 todo = max + 32;
38 todo -= todo % 32;
39
40 d = kzalloc(todo, GFP_KERNEL | GFP_DMA);
41 if (!d)
42 return -ENOMEM;
43
44 #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
45 ce->hwrng_stat_req++;
46 ce->hwrng_stat_bytes += todo;
47 #endif
48
49 dma_dst = dma_map_single(ce->dev, d, todo, DMA_FROM_DEVICE);
50 if (dma_mapping_error(ce->dev, dma_dst)) {
51 dev_err(ce->dev, "Cannot DMA MAP DST\n");
52 err = -EFAULT;
53 goto err_dst;
54 }
55
56 err = pm_runtime_get_sync(ce->dev);
57 if (err < 0)
58 goto err_pm;
59
60 mutex_lock(&ce->rnglock);
61 chan = &ce->chanlist[flow];
62
63 cet = &chan->tl[0];
64 memset(cet, 0, sizeof(struct ce_task));
65
66 cet->t_id = cpu_to_le32(flow);
67 common = ce->variant->trng | CE_COMM_INT;
68 cet->t_common_ctl = cpu_to_le32(common);
69
70 /* recent CE (H6) need length in bytes, in word otherwise */
71 if (ce->variant->trng_t_dlen_in_bytes)
72 cet->t_dlen = cpu_to_le32(todo);
73 else
74 cet->t_dlen = cpu_to_le32(todo / 4);
75
76 cet->t_sym_ctl = 0;
77 cet->t_asym_ctl = 0;
78
79 cet->t_dst[0].addr = cpu_to_le32(dma_dst);
80 cet->t_dst[0].len = cpu_to_le32(todo / 4);
81 ce->chanlist[flow].timeout = todo;
82
83 err = sun8i_ce_run_task(ce, 3, "TRNG");
84 mutex_unlock(&ce->rnglock);
85
86 pm_runtime_put(ce->dev);
87
88 err_pm:
89 dma_unmap_single(ce->dev, dma_dst, todo, DMA_FROM_DEVICE);
90
91 if (!err) {
92 memcpy(data, d, max);
93 err = max;
94 }
95 memzero_explicit(d, todo);
96 err_dst:
97 kfree(d);
98 return err;
99 }
100
101 int sun8i_ce_hwrng_register(struct sun8i_ce_dev *ce)
102 {
103 int ret;
104
> 105 if (ce->variant->trng == CE_ID_NOTSUPP) {
106 dev_info(ce->dev, "TRNG not supported\n");
107 return 0;
108 }
109 ce->trng.name = "sun8i Crypto Engine TRNG";
110 ce->trng.read = sun8i_ce_trng_read;
111 ce->trng.quality = 1000;
112
113 ret = hwrng_register(&ce->trng);
114 if (ret)
115 dev_err(ce->dev, "Fail to register the TRNG\n");
116 return ret;
117 }
118

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (5.38 kB)
.config.gz (72.30 kB)
Download all attachments