From bbc746ce721ddaf7f3022abaeb9a601711809ff5 Mon Sep 17 00:00:00 2001 From: jakllsch Date: Mon, 2 Aug 2010 19:59:35 +0000 Subject: [PATCH] Consistently use a single CRYPTO_SESID2HID-like macro. Improve CRYPTO_DEBUG printing a bit: print pointers with %p print unsigned with %u rather than %d use CRYPTO_SESID2LID instead of just casting to uint32_t --- sys/opencrypto/crypto.c | 49 +++++++++++++++++-------------------- sys/opencrypto/cryptodev.c | 28 +++++++++++---------- sys/opencrypto/cryptosoft.c | 6 ++--- 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/sys/opencrypto/crypto.c b/sys/opencrypto/crypto.c index 0cb21c9932ae..bc9707d098a7 100644 --- a/sys/opencrypto/crypto.c +++ b/sys/opencrypto/crypto.c @@ -1,4 +1,4 @@ -/* $NetBSD: crypto.c,v 1.34 2009/04/18 14:58:07 tsutsui Exp $ */ +/* $NetBSD: crypto.c,v 1.35 2010/08/02 19:59:35 jakllsch Exp $ */ /* $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $ */ /* $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */ @@ -53,7 +53,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.34 2009/04/18 14:58:07 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.35 2010/08/02 19:59:35 jakllsch Exp $"); #include #include @@ -80,8 +80,6 @@ kmutex_t crypto_mtx; #define unregister_swi(lvl, fn) softint_disestablish(softintr_cookie) #define setsoftcrypto(x) softint_schedule(x) -#define SESID2HID(sid) (((sid) >> 32) & 0xffffffff) - int crypto_ret_q_check(struct cryptop *); /* @@ -389,7 +387,7 @@ crypto_freesession(u_int64_t sid) } /* Determine two IDs. */ - hid = SESID2HID(sid); + hid = CRYPTO_SESID2HID(sid); if (hid >= crypto_drivers_num) { err = ENOENT; @@ -712,14 +710,12 @@ crypto_unblock(u_int32_t driverid, int what) int crypto_dispatch(struct cryptop *crp) { - u_int32_t hid = SESID2HID(crp->crp_sid); + u_int32_t hid = CRYPTO_SESID2HID(crp->crp_sid); int result; mutex_spin_enter(&crypto_mtx); - DPRINTF(("crypto_dispatch: crp %08x, reqid 0x%x, alg %d\n", - (uint32_t)crp, - crp->crp_reqid, - crp->crp_desc->crd_alg)); + DPRINTF(("crypto_dispatch: crp %p, reqid 0x%x, alg %d\n", + crp, crp->crp_reqid, crp->crp_desc->crd_alg)); cryptostats.cs_ops++; @@ -918,7 +914,7 @@ crypto_invoke(struct cryptop *crp, int hint) return 0; } - hid = SESID2HID(crp->crp_sid); + hid = CRYPTO_SESID2HID(crp->crp_sid); if (hid < crypto_drivers_num) { mutex_spin_enter(&crypto_mtx); if (crypto_drivers[hid].cc_flags & CRYPTOCAP_F_CLEANUP) @@ -953,7 +949,7 @@ crypto_invoke(struct cryptop *crp, int hint) /* * Invoke the driver to process the request. */ - DPRINTF(("calling process for %08x\n", (uint32_t)crp)); + DPRINTF(("calling process for %p\n", crp)); return (*process)(crypto_drivers[hid].cc_arg, crp, hint); } } @@ -968,8 +964,8 @@ crypto_freereq(struct cryptop *crp) if (crp == NULL) return; - DPRINTF(("crypto_freereq[%d]: crp %p\n", - (uint32_t)crp->crp_sid, crp)); + DPRINTF(("crypto_freereq[%u]: crp %p\n", + CRYPTO_SESID2LID(crp->crp_sid), crp)); /* sanity check */ if (crp->crp_flags & CRYPTO_F_ONRETQ) { @@ -1029,8 +1025,8 @@ crypto_done(struct cryptop *crp) if (crypto_timing) crypto_tstat(&cryptostats.cs_done, &crp->crp_tstamp); #endif - DPRINTF(("crypto_done[%d]: crp %08x\n", - (uint32_t)crp->crp_sid, (uint32_t)crp)); + DPRINTF(("crypto_done[%u]: crp %p\n", + CRYPTO_SESID2LID(crp->crp_sid), crp)); /* * Normal case; queue the callback for the thread. @@ -1077,18 +1073,18 @@ crypto_done(struct cryptop *crp) * This is an optimization to avoid * unecessary context switches. */ - DPRINTF(("crypto_done[%d]: crp %08x CRYPTO_F_USER\n", - (uint32_t)crp->crp_sid, (uint32_t)crp)); + DPRINTF(("crypto_done[%u]: crp %p CRYPTO_F_USER\n", + CRYPTO_SESID2LID(crp->crp_sid), crp)); } else { wasempty = TAILQ_EMPTY(&crp_ret_q); - DPRINTF(("crypto_done[%d]: queueing %08x\n", - (uint32_t)crp->crp_sid, (uint32_t)crp)); + DPRINTF(("crypto_done[%u]: queueing %p\n", + CRYPTO_SESID2LID(crp->crp_sid), crp)); crp->crp_flags |= CRYPTO_F_ONRETQ; TAILQ_INSERT_TAIL(&crp_ret_q, crp, crp_next); if (wasempty) { - DPRINTF(("crypto_done[%d]: waking cryptoret, crp %08x " \ - "hit empty queue\n.", - (uint32_t)crp->crp_sid, (uint32_t)crp)); + DPRINTF(("crypto_done[%u]: waking cryptoret, " + "crp %p hit empty queue\n.", + CRYPTO_SESID2LID(crp->crp_sid), crp)); cv_signal(&cryptoret_cv); } } @@ -1178,7 +1174,7 @@ cryptointr(void) submit = NULL; hint = 0; TAILQ_FOREACH_SAFE(crp, &crp_q, crp_next, cnext) { - u_int32_t hid = SESID2HID(crp->crp_sid); + u_int32_t hid = CRYPTO_SESID2HID(crp->crp_sid); cap = crypto_checkdriver(hid); if (cap == NULL || cap->cc_process == NULL) { /* Op needs to be migrated, process it. */ @@ -1196,7 +1192,8 @@ cryptointr(void) * better to just use a per-driver * queue instead. */ - if (SESID2HID(submit->crp_sid) == hid) + if (CRYPTO_SESID2HID(submit->crp_sid) + == hid) hint = CRYPTO_HINT_MORE; break; } else { @@ -1225,7 +1222,7 @@ cryptointr(void) * it at the end does not work. */ /* XXX validate sid again? */ - crypto_drivers[SESID2HID(submit->crp_sid)].cc_qblocked = 1; + crypto_drivers[CRYPTO_SESID2HID(submit->crp_sid)].cc_qblocked = 1; TAILQ_INSERT_HEAD(&crp_q, submit, crp_next); cryptostats.cs_blocks++; } diff --git a/sys/opencrypto/cryptodev.c b/sys/opencrypto/cryptodev.c index b7ef037a6fe0..e8e55a6c1679 100644 --- a/sys/opencrypto/cryptodev.c +++ b/sys/opencrypto/cryptodev.c @@ -1,4 +1,4 @@ -/* $NetBSD: cryptodev.c,v 1.52 2010/01/31 14:32:56 hubertf Exp $ */ +/* $NetBSD: cryptodev.c,v 1.53 2010/08/02 19:59:35 jakllsch Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */ /* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */ @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.52 2010/01/31 14:32:56 hubertf Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.53 2010/08/02 19:59:35 jakllsch Exp $"); #include #include @@ -422,7 +422,8 @@ cryptodev_op(struct csession *cse, struct crypt_op *cop, struct lwp *l) return EINVAL; } - DPRINTF(("cryptodev_op[%d]: iov_len %d\n", (uint32_t)cse->sid, iov_len)); + DPRINTF(("cryptodev_op[%u]: iov_len %d\n", + CRYPTO_SESID2LID(cse->sid), iov_len)); if ((cse->tcomp) && cop->dst_len) { if (iov_len < cop->dst_len) { /* Need larger iov to deal with decompress */ @@ -444,15 +445,17 @@ cryptodev_op(struct csession *cse, struct crypt_op *cop, struct lwp *l) cse->uio.uio_iov[0].iov_len = iov_len; cse->uio.uio_iov[0].iov_base = kmem_alloc(iov_len, KM_SLEEP); cse->uio.uio_resid = cse->uio.uio_iov[0].iov_len; - DPRINTF(("cryptodev_op[%d]: uio.iov_base %p malloced %d bytes\n", - (uint32_t)cse->sid, cse->uio.uio_iov[0].iov_base, iov_len)); + DPRINTF(("cryptodev_op[%u]: uio.iov_base %p malloced %d bytes\n", + CRYPTO_SESID2LID(cse->sid), + cse->uio.uio_iov[0].iov_base, iov_len)); crp = crypto_getreq((cse->tcomp != NULL) + (cse->txform != NULL) + (cse->thash != NULL)); if (crp == NULL) { error = ENOMEM; goto bail; } - DPRINTF(("cryptodev_op[%d]: crp %p\n", (uint32_t)cse->sid, crp)); + DPRINTF(("cryptodev_op[%u]: crp %p\n", + CRYPTO_SESID2LID(cse->sid), crp)); /* crds are always ordered tcomp, thash, then txform */ /* with optional missing links */ @@ -478,8 +481,8 @@ cryptodev_op(struct csession *cse, struct crypt_op *cop, struct lwp *l) } } - DPRINTF(("ocf[%d]: iov_len %d, cop->len %d\n", - (uint32_t)cse->sid, + DPRINTF(("ocf[%u]: iov_len %zu, cop->len %u\n", + CRYPTO_SESID2LID(cse->sid), cse->uio.uio_iov[0].iov_len, cop->len)); @@ -510,8 +513,8 @@ cryptodev_op(struct csession *cse, struct crypt_op *cop, struct lwp *l) crdc->crd_alg = cse->comp_alg; crdc->crd_key = NULL; crdc->crd_klen = 0; - DPRINTF(("cryptodev_op[%d]: crdc setup for comp_alg %d.\n", - (uint32_t)cse->sid, crdc->crd_alg)); + DPRINTF(("cryptodev_op[%u]: crdc setup for comp_alg %d.\n", + CRYPTO_SESID2LID(cse->sid), crdc->crd_alg)); } if (crda) { @@ -632,9 +635,8 @@ eagain: } while (!(crp->crp_flags & CRYPTO_F_DONE)) { - DPRINTF(("cryptodev_op[%d]: sleeping on cv %08x for crp %08x\n", - (uint32_t)cse->sid, (uint32_t)&crp->crp_cv, - (uint32_t)crp)); + DPRINTF(("cryptodev_op[%d]: sleeping on cv %p for crp %p\n", + (uint32_t)cse->sid, &crp->crp_cv, crp)); cv_wait(&crp->crp_cv, &crypto_mtx); /* XXX cv_wait_sig? */ } if (crp->crp_flags & CRYPTO_F_ONRETQ) { diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c index af5b3f3610e2..b306c4a2efbd 100644 --- a/sys/opencrypto/cryptosoft.c +++ b/sys/opencrypto/cryptosoft.c @@ -1,4 +1,4 @@ -/* $NetBSD: cryptosoft.c,v 1.25 2009/04/18 14:58:07 tsutsui Exp $ */ +/* $NetBSD: cryptosoft.c,v 1.26 2010/08/02 19:59:35 jakllsch Exp $ */ /* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */ @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.25 2009/04/18 14:58:07 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.26 2010/08/02 19:59:35 jakllsch Exp $"); #include #include @@ -1000,7 +1000,7 @@ swcr_process(void *arg, struct cryptop *crp, int hint) } done: - DPRINTF(("request %08x done\n", (uint32_t)crp)); + DPRINTF(("request %p done\n", crp)); crypto_done(crp); return 0; }