]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ENGR00216259 caam: improve RNG4 initialization process
authorSteve Cornelius <steve.cornelius@freescale.com>
Thu, 9 Aug 2012 22:26:33 +0000 (15:26 -0700)
committerOliver Wendt <ow@karo-electronics.de>
Mon, 30 Sep 2013 12:12:40 +0000 (14:12 +0200)
Early versions of this driver used a set of entropy generation parameters
inherited from QorIQ devices. Those parameters were a hardcoded set
based upon internally-suggested values, and worked well on QorIQ. However,
for certain mx6 devices, oscillator values were found to be exceeding
the upper limit, and so RNG instantiation was failing in those cases.

This code improves initialization by (a) making sure the oscillator
divider is set to a known value, and (b) converting the parameter selection
to a symbolic compiler-generated form, instead of using embedded
magic number constants.

The calculation is now based on the definition of RNG4_ENT_CLOCKS_SAMPLE,
which defaults to 1600 unless overridden by something. The lower limit
is then set as /4, and the upper limit set to *8.

Tested-by: Minnick Michael-B21710 <b21710@freescale.com>
Signed-off-by: Steve Cornelius <steve.cornelius@freescale.com>
Signed-off-by: Jason Liu <r64343@freescale.com>
drivers/crypto/caam/ctrl.c
drivers/crypto/caam/intern.h
drivers/crypto/caam/regs.h

index f2c8595ccb9b1d3da9d1bca6d66c7db547292532..c47e25eee926e7b625d7b5cdfd007d0f3d3646c1 100644 (file)
@@ -163,14 +163,16 @@ static void kick_trng(struct platform_device *pdev)
 
        /* put RNG4 into program mode */
        setbits32(&r4tst->rtmctl, RTMCTL_PRGM);
-       /* 1600 clocks per sample */
+       /* Set clocks per sample to the default, and divider to zero */
        val = rd_reg32(&r4tst->rtsdctl);
-       val = (val & ~RTSDCTL_ENT_DLY_MASK) | (1600 << RTSDCTL_ENT_DLY_SHIFT);
+       val = ((val & ~RTSDCTL_ENT_DLY_MASK) |
+              (RNG4_ENT_CLOCKS_SAMPLE << RTSDCTL_ENT_DLY_SHIFT)) &
+              ~RTMCTL_OSC_DIV_MASK;
        wr_reg32(&r4tst->rtsdctl, val);
        /* min. freq. count */
-       wr_reg32(&r4tst->rtfrqmin, 400);
+       wr_reg32(&r4tst->rtfrqmin, RNG4_ENT_CLOCKS_SAMPLE / 4);
        /* max. freq. count */
-       wr_reg32(&r4tst->rtfrqmax, 6400);
+       wr_reg32(&r4tst->rtfrqmax, RNG4_ENT_CLOCKS_SAMPLE * 8);
        /* put RNG4 into run mode */
        clrbits32(&r4tst->rtmctl, RTMCTL_PRGM);
 }
index 18e7385fb2d8a56d47875a67f9ad1901e5b3ab53..1f818ffb831a81bde827f8518966c27fde37cba1 100644 (file)
@@ -12,6 +12,9 @@
 #define JOBR_UNASSIGNED 0
 #define JOBR_ASSIGNED 1
 
+/* Default clock/sample settings for an RNG4 entropy source */
+#define RNG4_ENT_CLOCKS_SAMPLE 1600
+
 /* Currently comes from Kconfig param as a ^2 (driver-required) */
 #define JOBR_DEPTH (1 << CONFIG_CRYPTO_DEV_FSL_CAAM_RINGSIZE)
 
index fd8a2a251b8a6b9d8452c58f649f041c446e2b85..04ae9d4167b03f8655fca02daa417188596c7c23 100644 (file)
@@ -297,6 +297,7 @@ struct rngtst {
 /* RNG4 TRNG test registers */
 struct rng4tst {
 #define RTMCTL_PRGM 0x00010000 /* 1 -> program mode, 0 -> run mode */
+#define RTMCTL_OSC_DIV_MASK 0xc        /* select oscillator divider value */
        u32 rtmctl;             /* misc. control register */
        u32 rtscmisc;           /* statistical check misc. register */
        u32 rtpkrrng;           /* poker range register */