Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/opencrypto Consistently use a single CRYPTO_SESID2HID-li...



details:   https://anonhg.NetBSD.org/src/rev/3f25ecc2c8dc
branches:  trunk
changeset: 756804:3f25ecc2c8dc
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Mon Aug 02 19:59:35 2010 +0000

description:
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

diffstat:

 sys/opencrypto/crypto.c     |  49 +++++++++++++++++++++-----------------------
 sys/opencrypto/cryptodev.c  |  28 +++++++++++++-----------
 sys/opencrypto/cryptosoft.c |   6 ++--
 3 files changed, 41 insertions(+), 42 deletions(-)

diffs (258 lines):

diff -r c38e9141a5a9 -r 3f25ecc2c8dc sys/opencrypto/crypto.c
--- a/sys/opencrypto/crypto.c   Mon Aug 02 17:49:04 2010 +0000
+++ b/sys/opencrypto/crypto.c   Mon Aug 02 19:59:35 2010 +0000
@@ -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 <sys/cdefs.h>
-__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 <sys/param.h>
 #include <sys/reboot.h>
@@ -80,8 +80,6 @@
   #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 @@
        }
 
        /* Determine two IDs. */
-       hid = SESID2HID(sid);
+       hid = CRYPTO_SESID2HID(sid);
 
        if (hid >= crypto_drivers_num) {
                err = ENOENT;
@@ -712,14 +710,12 @@
 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 @@
                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 @@
                /*
                 * 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 @@
 
        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 @@
        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 @@
                         * 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 @@
                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 @@
                                         * 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 @@
                                 * 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 -r c38e9141a5a9 -r 3f25ecc2c8dc sys/opencrypto/cryptodev.c
--- a/sys/opencrypto/cryptodev.c        Mon Aug 02 17:49:04 2010 +0000
+++ b/sys/opencrypto/cryptodev.c        Mon Aug 02 19:59:35 2010 +0000
@@ -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 <sys/cdefs.h>
-__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 <sys/param.h>
 #include <sys/systm.h>
@@ -422,7 +422,8 @@
                        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 @@
        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 @@
                }
        }
 
-       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 @@
                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 @@
        }
 
        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 -r c38e9141a5a9 -r 3f25ecc2c8dc sys/opencrypto/cryptosoft.c
--- a/sys/opencrypto/cryptosoft.c       Mon Aug 02 17:49:04 2010 +0000
+++ b/sys/opencrypto/cryptosoft.c       Mon Aug 02 19:59:35 2010 +0000
@@ -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 <sys/cdefs.h>
-__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 <sys/param.h>
 #include <sys/systm.h>
@@ -1000,7 +1000,7 @@
        }
 
 done:
-       DPRINTF(("request %08x done\n", (uint32_t)crp));
+       DPRINTF(("request %p done\n", crp));
        crypto_done(crp);
        return 0;
 }



Home | Main Index | Thread Index | Old Index