mediatek: Add support for Xiaomi Redmi Router AX6S
[openwrt/openwrt.git] / target / linux / layerscape / patches-5.4 / 804-crypto-0012-MLK-19053-crypto-caam-RNG4-TRNG-errata.patch
1 From e1a89cdf6fa6b04806eb24b939738bb89ab62914 Mon Sep 17 00:00:00 2001
2 From: Aymen Sghaier <aymen.sghaier@nxp.com>
3 Date: Thu, 13 Sep 2018 16:41:03 +0200
4 Subject: [PATCH] MLK-19053 crypto: caam - RNG4 TRNG errata
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 The TRNG as used in RNG4, used in CAAM has a documentation issue. The
10 effect is that it is possible that the entropy used to instantiate the
11 DRBG may be old entropy, rather than newly generated entropy. There is
12 proper programming guidance, but it is not in the documentation.
13
14 Signed-off-by: Aymen Sghaier <aymen.sghaier@nxp.com>
15 Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
16 (cherry picked from commit ea2b30c8171acf7624e3d44276737c3878ca900d)
17
18 -ported to RNG initialization in ctrl.c
19 -changed commit headline
20
21 Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
22 ---
23 drivers/crypto/caam/ctrl.c | 9 +++++++--
24 drivers/crypto/caam/regs.h | 3 ++-
25 2 files changed, 9 insertions(+), 3 deletions(-)
26
27 --- a/drivers/crypto/caam/ctrl.c
28 +++ b/drivers/crypto/caam/ctrl.c
29 @@ -339,7 +339,11 @@ static void kick_trng(struct platform_de
30 r4tst = &ctrl->r4tst[0];
31
32 /* put RNG4 into program mode */
33 - clrsetbits_32(&r4tst->rtmctl, 0, RTMCTL_PRGM);
34 + /* Setting both RTMCTL:PRGM and RTMCTL:TRNG_ACC causes TRNG to
35 + * properly invalidate the entropy in the entropy register and
36 + * force re-generation.
37 + */
38 + clrsetbits_32(&r4tst->rtmctl, 0, RTMCTL_PRGM | RTMCTL_ACC);
39
40 /*
41 * Performance-wise, it does not make sense to
42 @@ -369,7 +373,8 @@ start_rng:
43 * select raw sampling in both entropy shifter
44 * and statistical checker; ; put RNG4 into run mode
45 */
46 - clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM, RTMCTL_SAMP_MODE_RAW_ES_SC);
47 + clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM | RTMCTL_ACC,
48 + RTMCTL_SAMP_MODE_RAW_ES_SC);
49 }
50
51 static int caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl)
52 --- a/drivers/crypto/caam/regs.h
53 +++ b/drivers/crypto/caam/regs.h
54 @@ -495,7 +495,8 @@ struct rngtst {
55
56 /* RNG4 TRNG test registers */
57 struct rng4tst {
58 -#define RTMCTL_PRGM 0x00010000 /* 1 -> program mode, 0 -> run mode */
59 +#define RTMCTL_ACC BIT(5) /* TRNG access mode */
60 +#define RTMCTL_PRGM BIT(16) /* 1 -> program mode, 0 -> run mode */
61 #define RTMCTL_SAMP_MODE_VON_NEUMANN_ES_SC 0 /* use von Neumann data in
62 both entropy shifter and
63 statistical checker */