summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorsam <sam@FreeBSD.org>2003-03-11 22:47:06 +0000
committersam <sam@FreeBSD.org>2003-03-11 22:47:06 +0000
commit08b96bb1399a2789ebc9d72321d31751cec37e33 (patch)
treec4b232799e4ac8460f49b969f01ac7575565a38e /sys
parent0c3ac305c83bd43547194c4582f11b1918260bba (diff)
downloadFreeBSD-src-08b96bb1399a2789ebc9d72321d31751cec37e33.zip
FreeBSD-src-08b96bb1399a2789ebc9d72321d31751cec37e33.tar.gz
o add crypto driver glue for using the new rndtest driver/module; this is
conditional in each driver on foo_RNDTEST being defined_ o bring HIFN_DEBUG and UBSEC_DEBUG out to be visible options; they control the debugging printfs that are set with hw.foo.debug (e.g. hw.hifn.debug)
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/NOTES8
-rw-r--r--sys/conf/options7
-rw-r--r--sys/dev/hifn/hifn7751.c31
-rw-r--r--sys/dev/hifn/hifn7751var.h5
-rw-r--r--sys/dev/ubsec/ubsec.c37
-rw-r--r--sys/dev/ubsec/ubsecvar.h5
6 files changed, 82 insertions, 11 deletions
diff --git a/sys/conf/NOTES b/sys/conf/NOTES
index b0d8ba7..a5251f9 100644
--- a/sys/conf/NOTES
+++ b/sys/conf/NOTES
@@ -2152,9 +2152,15 @@ device fwe # Ethernet over Firewire (non-standard!)
device crypto # core crypto support
device cryptodev # /dev/crypto for access to h/w
+device rndtest # FIPS 140-2 entropy tester
+
device hifn # Hifn 7951, 7781, etc.
+options HIFN_DEBUG # enable debugging support: hw.hifn.debug
+options HIFN_RNDTEST # enable rndtest support
+
device ubsec # Broadcom 5501, 5601, 58xx
-device rndtest # FIPS 140-2 entropy tester
+options UBSEC_DEBUG # enable debugging support: hw.ubsec.debug
+options UBSEC_RNDTEST # enable rndtest support
#####################################################################
diff --git a/sys/conf/options b/sys/conf/options
index 49906f3..1024a5d 100644
--- a/sys/conf/options
+++ b/sys/conf/options
@@ -602,3 +602,10 @@ DEVICE_POLLING opt_global.h
# Mutex profiling
MUTEX_PROFILING opt_global.h
+# options for ubsec driver
+UBSEC_DEBUG opt_ubsec.h
+UBSEC_RNDTEST opt_ubsec.h
+
+# options for hifn driver
+HIFN_DEBUG opt_hifn.h
+HIFN_RNDTEST opt_hifn.h
diff --git a/sys/dev/hifn/hifn7751.c b/sys/dev/hifn/hifn7751.c
index cb58fe0..f7d60a4 100644
--- a/sys/dev/hifn/hifn7751.c
+++ b/sys/dev/hifn/hifn7751.c
@@ -41,11 +41,10 @@
*
*/
-#define HIFN_DEBUG
-
/*
* Driver for the Hifn 7751 encryption processor.
*/
+#include "opt_hifn.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -72,6 +71,10 @@
#include <pci/pcivar.h>
#include <pci/pcireg.h>
+
+#ifdef HIFN_RNDTEST
+#include <dev/rndtest/rndtest.h>
+#endif
#include <dev/hifn/hifn7751reg.h>
#include <dev/hifn/hifn7751var.h>
@@ -109,6 +112,9 @@ static devclass_t hifn_devclass;
DRIVER_MODULE(hifn, pci, hifn_driver, hifn_devclass, 0, 0);
MODULE_DEPEND(hifn, crypto, 1, 1, 1);
+#ifdef HIFN_RNDTEST
+MODULE_DEPEND(hifn, rndtest, 1, 1, 1);
+#endif
static void hifn_reset_board(struct hifn_softc *, int);
static void hifn_reset_puc(struct hifn_softc *);
@@ -230,6 +236,12 @@ hifn_partname(struct hifn_softc *sc)
return "Unknown-vendor unknown-part";
}
+static void
+default_harvest(struct rndtest_state *rsp, void *buf, u_int count)
+{
+ random_harvest(buf, count, count*NBBY, 0, RANDOM_PURE);
+}
+
/*
* Attach an interface that successfully probed.
*/
@@ -621,6 +633,15 @@ hifn_init_pubrng(struct hifn_softc *sc)
u_int32_t r;
int i;
+#ifdef HIFN_RNDTEST
+ sc->sc_rndtest = rndtest_attach(sc->sc_dev);
+ if (sc->sc_rndtest)
+ sc->sc_harvest = rndtest_harvest;
+ else
+ sc->sc_harvest = default_harvest;
+#else
+ sc->sc_harvest = default_harvest;
+#endif
if ((sc->sc_flags & HIFN_IS_7811) == 0) {
/* Reset 7951 public key/rng engine */
WRITE_REG_1(sc, HIFN_1_PUB_RESET,
@@ -705,7 +726,8 @@ hifn_rng(void *vsc)
if (sc->sc_rngfirst)
sc->sc_rngfirst = 0;
else
- random_harvest(num, RANDOM_BITS(2), RANDOM_PURE);
+ (*sc->sc_harvest)(sc->sc_rndtest,
+ num, sizeof (num));
}
} else {
num[0] = READ_REG_1(sc, HIFN_1_RNG_DATA);
@@ -714,7 +736,8 @@ hifn_rng(void *vsc)
if (sc->sc_rngfirst)
sc->sc_rngfirst = 0;
else
- random_harvest(num, RANDOM_BITS(1), RANDOM_PURE);
+ (*sc->sc_harvest)(sc->sc_rndtest,
+ num, sizeof (num[0]));
}
callout_reset(&sc->sc_rngto, sc->sc_rnghz, hifn_rng, sc);
diff --git a/sys/dev/hifn/hifn7751var.h b/sys/dev/hifn/hifn7751var.h
index e7ff4a3..9d58f5e 100644
--- a/sys/dev/hifn/hifn7751var.h
+++ b/sys/dev/hifn/hifn7751var.h
@@ -133,6 +133,8 @@ struct hifn_session {
#define HS_STATE_USED 1 /* allocated, but key not on card */
#define HS_STATE_KEY 2 /* allocated and key is on card */
+struct rndstate_test;
+
/*
* Holds data specific to a single HIFN board.
*/
@@ -171,6 +173,9 @@ struct hifn_softc {
struct callout sc_tickto; /* for managing DMA */
int sc_rngfirst;
int sc_rnghz; /* RNG polling frequency */
+ struct rndtest_state *sc_rndtest; /* RNG test state */
+ void (*sc_harvest)(struct rndtest_state *,
+ void *, u_int);
int sc_c_busy; /* command ring busy */
int sc_s_busy; /* source data ring busy */
int sc_d_busy; /* destination data ring busy */
diff --git a/sys/dev/ubsec/ubsec.c b/sys/dev/ubsec/ubsec.c
index 278f2bb..c091653 100644
--- a/sys/dev/ubsec/ubsec.c
+++ b/sys/dev/ubsec/ubsec.c
@@ -40,12 +40,12 @@
*
*/
-#define UBSEC_DEBUG
-
/*
* uBsec 5[56]01, 58xx hardware crypto accelerator
*/
+#include "opt_ubsec.h"
+
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
@@ -90,6 +90,9 @@
#define letoh16(x) le16toh(x)
#define letoh32(x) le32toh(x)
+#ifdef UBSEC_RNDTEST
+#include <dev/rndtest/rndtest.h>
+#endif
#include <dev/ubsec/ubsecreg.h>
#include <dev/ubsec/ubsecvar.h>
@@ -127,6 +130,9 @@ static devclass_t ubsec_devclass;
DRIVER_MODULE(ubsec, pci, ubsec_driver, ubsec_devclass, 0, 0);
MODULE_DEPEND(ubsec, crypto, 1, 1, 1);
+#ifdef UBSEC_RNDTEST
+MODULE_DEPEND(ubsec, rndtest, 1, 1, 1);
+#endif
static void ubsec_intr(void *);
static int ubsec_newsession(void *, u_int32_t *, struct cryptoini *);
@@ -231,6 +237,12 @@ ubsec_partname(struct ubsec_softc *sc)
return "Unknown-vendor unknown-part";
}
+static void
+default_harvest(struct rndtest_state *rsp, void *buf, u_int count)
+{
+ random_harvest(buf, count, count*NBBY, 0, RANDOM_PURE);
+}
+
static int
ubsec_attach(device_t dev)
{
@@ -405,6 +417,15 @@ ubsec_attach(device_t dev)
#ifndef UBSEC_NO_RNG
if (sc->sc_flags & UBS_FLAGS_RNG) {
sc->sc_statmask |= BS_STAT_MCR2_DONE;
+#ifdef UBSEC_RNDTEST
+ sc->sc_rndtest = rndtest_attach(dev);
+ if (sc->sc_rndtest)
+ sc->sc_harvest = rndtest_harvest;
+ else
+ sc->sc_harvest = default_harvest;
+#else
+ sc->sc_harvest = default_harvest;
+#endif
if (ubsec_dma_malloc(sc, sizeof(struct ubsec_mcr),
&sc->sc_rng.rng_q.q_mcr, 0))
@@ -477,6 +498,11 @@ ubsec_detach(device_t dev)
crypto_unregister_all(sc->sc_cid);
+#ifdef UBSEC_RNDTEST
+ if (sc->sc_rndtest)
+ rndtest_detach(sc->sc_rndtest);
+#endif
+
while (!SIMPLEQ_EMPTY(&sc->sc_freequeue)) {
struct ubsec_q *q;
@@ -1652,10 +1678,9 @@ ubsec_callback2(struct ubsec_softc *sc, struct ubsec_q2 *q)
struct ubsec_q2_rng *rng = (struct ubsec_q2_rng *)q;
ubsec_dma_sync(&rng->rng_buf, BUS_DMASYNC_POSTREAD);
- random_harvest(rng->rng_buf.dma_vaddr,
- UBSEC_RNG_BUFSIZ*sizeof (u_int32_t),
- UBSEC_RNG_BUFSIZ*sizeof (u_int32_t)*NBBY, 0,
- RANDOM_PURE);
+ (*sc->sc_harvest)(sc->sc_rndtest,
+ rng->rng_buf.dma_vaddr,
+ UBSEC_RNG_BUFSIZ*sizeof (u_int32_t));
rng->rng_used = 0;
callout_reset(&sc->sc_rngto, sc->sc_rnghz, ubsec_rng, sc);
break;
diff --git a/sys/dev/ubsec/ubsecvar.h b/sys/dev/ubsec/ubsecvar.h
index 588dec9..9c5b3dd 100644
--- a/sys/dev/ubsec/ubsecvar.h
+++ b/sys/dev/ubsec/ubsecvar.h
@@ -174,6 +174,8 @@ struct ubsec_q {
#define q_dst_segs q_dst.segs
#define q_dst_mapsize q_dst.mapsize
+struct rndstate_test;
+
struct ubsec_softc {
device_t sc_dev; /* device backpointer */
struct mtx sc_mtx; /* per-driver lock */
@@ -201,6 +203,9 @@ struct ubsec_softc {
struct callout sc_rngto; /* rng timeout */
int sc_rnghz; /* rng poll time */
struct ubsec_q2_rng sc_rng;
+ struct rndtest_state *sc_rndtest; /* RNG test state */
+ void (*sc_harvest)(struct rndtest_state *,
+ void *, u_int);
struct ubsec_dma sc_dmaa[UBS_MAX_NQUEUE];
struct ubsec_q *sc_queuea[UBS_MAX_NQUEUE];
SIMPLEQ_HEAD(,ubsec_q2) sc_q2free; /* free list */
OpenPOWER on IntegriCloud