From 29d08b2e918d6e6913c0d7465605944bc0fcbc99 Mon Sep 17 00:00:00 2001 From: Alex Porosanu Date: Mon, 11 Aug 2014 11:40:17 +0300 Subject: crypto: caam - enable raw data instead of von Neumann data The sampling of the oscillator can be done in multiple modes for generating the entropy value. By default, this is set to von Neumann. This patch changes the sampling to raw data, since it has been discovered that the generated entropy has a better 'quality'. Signed-off-by: Alex Porosanu Signed-off-by: Herbert Xu (cherry picked from commit e5ffbfc182bc148f44840bdd3970ea4c8bf80c3c) Change-Id: Ib366aa7e0477b2793f648333f2798a5c7b59ec5f Reviewed-on: http://git.am.freescale.net:8181/23839 Reviewed-by: Matthew Weigel Tested-by: Matthew Weigel diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index e662376..dcf360c 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -361,8 +361,17 @@ static void kick_trng(struct device *dev, int ent_delay) wr_reg32(&r4tst->rtfrqmin, ent_delay >> 2); /* disable maximum frequency count */ wr_reg32(&r4tst->rtfrqmax, RTFRQMAX_DISABLE); + /* read the control register */ + val = rd_reg32(&r4tst->rtmctl); + /* + * select raw sampling in both entropy shifter + * and statistical checker + */ + setbits32(&val, RTMCTL_SAMP_MODE_RAW_ES_SC); /* put RNG4 into run mode */ - clrbits32(&r4tst->rtmctl, RTMCTL_PRGM); + clrbits32(&val, RTMCTL_PRGM); + /* write back the control register */ + wr_reg32(&r4tst->rtmctl, val); } /** diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h index 6b62a6c..928cb53 100644 --- a/drivers/crypto/caam/regs.h +++ b/drivers/crypto/caam/regs.h @@ -277,6 +277,16 @@ struct rngtst { /* RNG4 TRNG test registers */ struct rng4tst { #define RTMCTL_PRGM 0x00010000 /* 1 -> program mode, 0 -> run mode */ +#define RTMCTL_SAMP_MODE_VON_NEUMANN_ES_SC 0 /* use von Neumann data in + both entropy shifter and + statistical checker */ +#define RTMCTL_SAMP_MODE_RAW_ES_SC 1 /* use raw data in both + entropy shifter and + statistical checker */ +#define RTMCTL_SAMP_MODE_VON_NEUMANN_ES_RAW_SC 2 /* use von Neumann data in + entropy shifter, raw data + in statistical checker */ +#define RTMCTL_SAMP_MODE_INVALID 3 /* invalid combination */ u32 rtmctl; /* misc. control register */ u32 rtscmisc; /* statistical check misc. register */ u32 rtpkrrng; /* poker range register */ -- cgit v0.10.2