summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJason Wright <jason@cvs.openbsd.org>2001-06-29 16:19:16 +0000
committerJason Wright <jason@cvs.openbsd.org>2001-06-29 16:19:16 +0000
commit23702d89ae57f40ec0e03e5f7a94452779051f16 (patch)
treee319a78cb656cec42ce23e1836007545beb09bf6 /sys
parentf98361d3757240c0162d33a191a612b8d4db5bed (diff)
allocate contexts during attach since we can't mess with them during
interrupts (the space allocation is wasteful, but more data will be moved into the allocation soon).
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/pci/ubsec.c49
-rw-r--r--sys/dev/pci/ubsecvar.h21
2 files changed, 48 insertions, 22 deletions
diff --git a/sys/dev/pci/ubsec.c b/sys/dev/pci/ubsec.c
index a4dbc6f8ba8..ed967ce847b 100644
--- a/sys/dev/pci/ubsec.c
+++ b/sys/dev/pci/ubsec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ubsec.c,v 1.62 2001/06/23 22:02:55 angelos Exp $ */
+/* $OpenBSD: ubsec.c,v 1.63 2001/06/29 16:19:15 jason Exp $ */
/*
* Copyright (c) 2000 Jason L. Wright (jason@thought.net)
@@ -131,8 +131,9 @@ ubsec_attach(parent, self, aux)
pci_chipset_tag_t pc = pa->pa_pc;
pci_intr_handle_t ih;
const char *intrstr = NULL;
+ struct ubsec_dma *dmap;
bus_size_t iosize;
- u_int32_t cmd;
+ u_int32_t cmd, i;
SIMPLEQ_INIT(&sc->sc_queue);
SIMPLEQ_INIT(&sc->sc_qchip);
@@ -192,6 +193,15 @@ ubsec_attach(parent, self, aux)
return;
}
+ SIMPLEQ_INIT(&sc->sc_dma);
+ dmap = sc->sc_dmaa;
+ for (i = 0; i < UBS_MAX_NQUEUE; i++, dmap++) {
+ if (ubsec_dma_malloc(sc, MAX(sizeof(struct ubsec_pktctx_long),
+ sizeof(struct ubsec_pktctx)), &dmap->d_ctx, 0))
+ break;
+ SIMPLEQ_INSERT_TAIL(&sc->sc_dma, dmap, d_next);
+ }
+
crypto_register(sc->sc_cid, CRYPTO_3DES_CBC, 0, 0,
ubsec_newsession, ubsec_freesession, ubsec_process);
crypto_register(sc->sc_cid, CRYPTO_DES_CBC, 0, 0, NULL, NULL, NULL);
@@ -579,6 +589,7 @@ ubsec_process(crp)
int16_t coffset;
struct ubsec_session *ses;
struct ubsec_pktctx ctx;
+ struct ubsec_dma *dmap = NULL;
if (crp == NULL || crp->crp_callback == NULL)
return (EINVAL);
@@ -595,6 +606,13 @@ ubsec_process(crp)
err = ENOMEM;
goto errout;
}
+ if (SIMPLEQ_EMPTY(&sc->sc_dma)) {
+ splx(s);
+ err = ENOMEM;
+ goto errout;
+ }
+ dmap = SIMPLEQ_FIRST(&sc->sc_dma);
+ SIMPLEQ_REMOVE_HEAD(&sc->sc_dma, dmap, d_next);
splx(s);
q = (struct ubsec_q *)malloc(sizeof(struct ubsec_q),
@@ -607,6 +625,7 @@ ubsec_process(crp)
bzero(&ctx, sizeof(ctx));
q->q_sesn = UBSEC_SESSION(crp->crp_sid);
+ q->q_dma = dmap;
ses = &sc->sc_sessions[q->q_sesn];
if (crp->crp_flags & CRYPTO_F_IMBUF) {
@@ -985,17 +1004,12 @@ ubsec_process(crp)
#endif
}
- if (ubsec_dma_malloc(sc, MAX(sizeof(struct ubsec_pktctx_long),
- sizeof(struct ubsec_pktctx)), &q->q_ctx_dma, 0)) {
- err = ENOMEM;
- goto errout;
- }
- q->q_mcr->mcr_cmdctxp = q->q_ctx_dma.dma_paddr;
+ q->q_mcr->mcr_cmdctxp = dmap->d_ctx.dma_paddr;
if (sc->sc_flags & UBS_FLAGS_LONGCTX) {
struct ubsec_pktctx_long *ctxl;
- ctxl = (struct ubsec_pktctx_long *)q->q_ctx_dma.dma_vaddr;
+ ctxl = (struct ubsec_pktctx_long *)dmap->d_ctx.dma_vaddr;
/* transform small context into long context */
ctxl->pc_len = sizeof(struct ubsec_pktctx_long);
@@ -1011,8 +1025,9 @@ ubsec_process(crp)
ctxl->pc_iv[0] = ctx.pc_iv[0];
ctxl->pc_iv[1] = ctx.pc_iv[1];
} else
- bcopy(&ctx, q->q_ctx_dma.dma_vaddr, sizeof(struct ubsec_pktctx));
- bus_dmamap_sync(sc->sc_dmat, q->q_ctx_dma.dma_map, BUS_DMASYNC_PREREAD);
+ bcopy(&ctx, dmap->d_ctx.dma_vaddr,
+ sizeof(struct ubsec_pktctx));
+ bus_dmamap_sync(sc->sc_dmat, dmap->d_ctx.dma_map, BUS_DMASYNC_PREREAD);
s = splnet();
SIMPLEQ_INSERT_TAIL(&sc->sc_queue, q, q_next);
@@ -1025,8 +1040,11 @@ errout:
if (q != NULL) {
if (q->q_mcr != NULL)
free(q->q_mcr, M_DEVBUF);
- if (q->q_ctx_dma.dma_map != NULL)
- ubsec_dma_free(sc, &q->q_ctx_dma);
+ if (dmap != NULL) {
+ s = splnet();
+ SIMPLEQ_INSERT_TAIL(&sc->sc_dma, dmap, d_next);
+ splx(s);
+ }
if ((q->q_dst_m != NULL) && (q->q_src_m != q->q_dst_m))
m_freem(q->q_dst_m);
free(q, M_DEVBUF);
@@ -1043,9 +1061,10 @@ ubsec_callback(sc, q)
{
struct cryptop *crp = (struct cryptop *)q->q_crp;
struct cryptodesc *crd;
+ struct ubsec_dma *dmap = q->q_dma;
- bus_dmamap_sync(sc->sc_dmat, q->q_ctx_dma.dma_map, BUS_DMASYNC_POSTREAD);
- ubsec_dma_free(sc, &q->q_ctx_dma);
+ bus_dmamap_sync(sc->sc_dmat, dmap->d_ctx.dma_map, BUS_DMASYNC_POSTREAD);
+ SIMPLEQ_INSERT_TAIL(&sc->sc_dma, dmap, d_next);
if ((crp->crp_flags & CRYPTO_F_IMBUF) && (q->q_src_m != q->q_dst_m)) {
m_freem(q->q_src_m);
diff --git a/sys/dev/pci/ubsecvar.h b/sys/dev/pci/ubsecvar.h
index 253b3fb8e90..d75eda9a2fb 100644
--- a/sys/dev/pci/ubsecvar.h
+++ b/sys/dev/pci/ubsecvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ubsecvar.h,v 1.19 2001/06/08 01:59:32 jason Exp $ */
+/* $OpenBSD: ubsecvar.h,v 1.20 2001/06/29 16:19:15 jason Exp $ */
/*
* Copyright (c) 2000 Theo de Raadt
@@ -27,6 +27,11 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/* Maximum queue length */
+#ifndef UBS_MAX_NQUEUE
+#define UBS_MAX_NQUEUE 60
+#endif
+
struct ubsec_dma_alloc {
u_int32_t dma_paddr;
caddr_t dma_vaddr;
@@ -49,6 +54,11 @@ struct ubsec_q2_rng {
};
#define UBSEC_RNG_BUFSIZ 16 /* measured in 32bit words */
+struct ubsec_dma {
+ SIMPLEQ_ENTRY(ubsec_dma) d_next;
+ struct ubsec_dma_alloc d_ctx;
+};
+
struct ubsec_softc {
struct device sc_dv; /* generic device */
void *sc_ih; /* interrupt handler cookie */
@@ -69,6 +79,8 @@ struct ubsec_softc {
struct timeout sc_rngto; /* rng timeout */
int sc_rnghz; /* rng poll time */
struct ubsec_q2_rng sc_rng;
+ struct ubsec_dma sc_dmaa[UBS_MAX_NQUEUE];
+ SIMPLEQ_HEAD(,ubsec_dma) sc_dma;
};
#define UBS_FLAGS_KEY 0x01 /* has key accelerator */
@@ -80,7 +92,7 @@ struct ubsec_q {
struct ubsec_mcr *q_mcr;
struct ubsec_pktbuf q_srcpkt[MAX_SCATTER-1];
struct ubsec_pktbuf q_dstpkt[MAX_SCATTER-1];
- struct ubsec_dma_alloc q_ctx_dma;
+ struct ubsec_dma *q_dma;
struct mbuf *q_src_m, *q_dst_m;
struct uio *q_src_io, *q_dst_io;
@@ -105,8 +117,3 @@ struct ubsec_session {
u_int32_t ses_hmouter[5]; /* hmac outer state */
u_int32_t ses_iv[2]; /* [3]DES iv */
};
-
-/* Maximum queue length */
-#ifndef UBS_MAX_NQUEUE
-#define UBS_MAX_NQUEUE 60
-#endif