Remove spl*() calls from the bus/ infrastructure, replacing them with
authorMatthew Dillon <dillon@dragonflybsd.org>
Thu, 2 Jun 2005 20:41:05 +0000 (20:41 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Thu, 2 Jun 2005 20:41:05 +0000 (20:41 +0000)
critical sections.  Remove splusb() from everywhere, replacing it with
critical sections.

44 files changed:
sys/bus/cam/cam_periph.c
sys/bus/cam/cam_xpt.c
sys/bus/cam/scsi/scsi_cd.c
sys/bus/cam/scsi/scsi_ch.c
sys/bus/cam/scsi/scsi_da.c
sys/bus/cam/scsi/scsi_low.c
sys/bus/cam/scsi/scsi_low.h
sys/bus/cam/scsi/scsi_pass.c
sys/bus/cam/scsi/scsi_pt.c
sys/bus/cam/scsi/scsi_sa.c
sys/bus/cam/scsi/scsi_ses.c
sys/bus/cam/scsi/scsi_targ_bh.c
sys/bus/cam/scsi/scsi_target.c
sys/bus/firewire/firewire.c
sys/bus/firewire/firewirereg.h
sys/bus/firewire/fwdev.c
sys/bus/firewire/fwmem.c
sys/bus/firewire/fwohci.c
sys/bus/firewire/fwohci_pci.c
sys/bus/iicbus/iiconf.c
sys/bus/ppbus/ppbconf.c
sys/bus/smbus/smbconf.c
sys/bus/usb/ehci.c
sys/bus/usb/ohci.c
sys/bus/usb/uhci.c
sys/bus/usb/usb.c
sys/bus/usb/usb_ethersubr.c
sys/bus/usb/usb_mem.c
sys/bus/usb/usbdi.c
sys/bus/usb/usbdi.h
sys/bus/usb/usbdi_util.c
sys/bus/usb/usbdivar.h
sys/dev/disk/sbp/sbp.c
sys/dev/sound/usb/uaudio.c
sys/dev/usbmisc/ucom/ucom.c
sys/dev/usbmisc/udbp/udbp.c
sys/dev/usbmisc/ufm/ufm.c
sys/dev/usbmisc/ugen/ugen.c
sys/dev/usbmisc/uhid/uhid.c
sys/dev/usbmisc/ukbd/ukbd.c
sys/dev/usbmisc/ulpt/ulpt.c
sys/dev/usbmisc/ums/ums.c
sys/dev/usbmisc/urio/urio.c
sys/dev/usbmisc/uscanner/uscanner.c

index 0c66b59..f8b599a 100644 (file)
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/cam_periph.c,v 1.24.2.3 2003/01/25 19:04:40 dillon Exp $
- * $DragonFly: src/sys/bus/cam/cam_periph.c,v 1.10 2005/05/28 01:16:30 swildner Exp $
+ * $DragonFly: src/sys/bus/cam/cam_periph.c,v 1.11 2005/06/02 20:40:29 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -42,6 +42,8 @@
 #include <vm/vm.h>
 #include <vm/vm_extern.h>
 
+#include <sys/thread2.h>
+
 #include "cam.h"
 #include "cam_ccb.h"
 #include "cam_xpt_periph.h"
@@ -79,7 +81,6 @@ cam_periph_alloc(periph_ctor_t *periph_ctor,
        lun_id_t        lun_id;
        cam_status      status;
        u_int           init_level;
-       int s;
 
        init_level = 0;
        /*
@@ -139,7 +140,7 @@ cam_periph_alloc(periph_ctor_t *periph_ctor,
        if (status != CAM_REQ_CMP)
                goto failure;
 
-       s = splsoftcam();
+       crit_enter();
        cur_periph = TAILQ_FIRST(&(*p_drv)->units);
        while (cur_periph != NULL
            && cur_periph->unit_number < periph->unit_number)
@@ -152,7 +153,7 @@ cam_periph_alloc(periph_ctor_t *periph_ctor,
                (*p_drv)->generation++;
        }
 
-       splx(s);
+       crit_exit();
 
        init_level++;
 
@@ -167,9 +168,9 @@ failure:
                /* Initialized successfully */
                break;
        case 3:
-               s = splsoftcam();
+               crit_enter();
                TAILQ_REMOVE(&(*p_drv)->units, periph, unit_links);
-               splx(s);
+               crit_exit();
                xpt_remove_periph(periph);
        case 2:
                xpt_free_path(periph->path);
@@ -194,21 +195,20 @@ cam_periph_find(struct cam_path *path, char *name)
 {
        struct periph_driver **p_drv;
        struct cam_periph *periph;
-       int s;
 
        SET_FOREACH(p_drv, periphdriver_set) {
                if (name != NULL && (strcmp((*p_drv)->driver_name, name) != 0))
                        continue;
 
-               s = splsoftcam();
+               crit_enter();
                for (periph = TAILQ_FIRST(&(*p_drv)->units); periph != NULL;
                     periph = TAILQ_NEXT(periph, unit_links)) {
                        if (xpt_path_comp(periph->path, path) == 0) {
-                               splx(s);
+                               crit_exit();
                                return(periph);
                        }
                }
-               splx(s);
+               crit_exit();
                if (name != NULL)
                        return(NULL);
        }
@@ -218,14 +218,12 @@ cam_periph_find(struct cam_path *path, char *name)
 cam_status
 cam_periph_acquire(struct cam_periph *periph)
 {
-       int s;
-
        if (periph == NULL)
                return(CAM_REQ_CMP_ERR);
 
-       s = splsoftcam();
+       crit_enter();
        periph->refcount++;
-       splx(s);
+       crit_exit();
 
        return(CAM_REQ_CMP);
 }
@@ -233,18 +231,15 @@ cam_periph_acquire(struct cam_periph *periph)
 void
 cam_periph_release(struct cam_periph *periph)
 {
-       int s;
-
        if (periph == NULL)
                return;
 
-       s = splsoftcam();
+       crit_enter();
        if ((--periph->refcount == 0)
         && (periph->flags & CAM_PERIPH_INVALID)) {
                camperiphfree(periph);
        }
-       splx(s);
-
+       crit_exit();
 }
 
 /*
@@ -261,11 +256,10 @@ camperiphnextunit(struct periph_driver *p_drv, u_int newunit, int wired,
 {
        struct  cam_periph *periph;
        char    *periph_name, *strval;
-       int     s;
        int     i, val, dunit;
        const char *dname;
 
-       s = splsoftcam();
+       crit_enter();
        periph_name = p_drv->driver_name;
        for (;;newunit++) {
 
@@ -309,7 +303,7 @@ camperiphnextunit(struct periph_driver *p_drv, u_int newunit, int wired,
                if (i == -1)
                        break;
        }
-       splx(s);
+       crit_exit();
        return (newunit);
 }
 
@@ -366,14 +360,12 @@ camperiphunit(struct periph_driver *p_drv, path_id_t pathid,
 void
 cam_periph_invalidate(struct cam_periph *periph)
 {
-       int s;
-
-       s = splsoftcam();
        /*
         * We only call this routine the first time a peripheral is
-        * invalidated.  The oninvalidate() routine is always called at
-        * splsoftcam().
+        * invalidated.  The oninvalidate() routine is always called in
+        * a critical section.
         */
+       crit_enter();
        if (((periph->flags & CAM_PERIPH_INVALID) == 0)
         && (periph->periph_oninval != NULL))
                periph->periph_oninval(periph);
@@ -385,13 +377,12 @@ cam_periph_invalidate(struct cam_periph *periph)
                camperiphfree(periph);
        else if (periph->refcount < 0)
                printf("cam_invalidate_periph: refcount < 0!!\n");
-       splx(s);
+       crit_exit();
 }
 
 static void
 camperiphfree(struct cam_periph *periph)
 {
-       int s;
        struct periph_driver **p_drv;
 
        SET_FOREACH(p_drv, periphdriver_set) {
@@ -408,10 +399,10 @@ camperiphfree(struct cam_periph *periph)
        if (periph->periph_dtor != NULL)
                periph->periph_dtor(periph);
        
-       s = splsoftcam();
+       crit_enter();
        TAILQ_REMOVE(&(*p_drv)->units, periph, unit_links);
        (*p_drv)->generation++;
-       splx(s);
+       crit_exit();
 
        xpt_remove_periph(periph);
 
@@ -691,11 +682,10 @@ union ccb *
 cam_periph_getccb(struct cam_periph *periph, u_int32_t priority)
 {
        struct ccb_hdr *ccb_h;
-       int s;
 
        CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering cdgetccb\n"));
 
-       s = splsoftcam();
+       crit_enter();
        
        while (periph->ccb_list.slh_first == NULL) {
                if (periph->immediate_priority > priority)
@@ -709,21 +699,18 @@ cam_periph_getccb(struct cam_periph *periph, u_int32_t priority)
 
        ccb_h = periph->ccb_list.slh_first;
        SLIST_REMOVE_HEAD(&periph->ccb_list, periph_links.sle);
-       splx(s);
+       crit_exit();
        return ((union ccb *)ccb_h);
 }
 
 void
 cam_periph_ccbwait(union ccb *ccb)
 {
-       int s;
-
-       s = splsoftcam();
+       crit_enter();
        if ((ccb->ccb_h.pinfo.index != CAM_UNQUEUED_INDEX)
         || ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG))
                tsleep(&ccb->ccb_h.cbfcnp, 0, "cbwait", 0);
-
-       splx(s);
+       crit_exit();
 }
 
 int
index 5b6b3c3..b6b9493 100644 (file)
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/cam_xpt.c,v 1.80.2.18 2002/12/09 17:31:55 gibbs Exp $
- * $DragonFly: src/sys/bus/cam/cam_xpt.c,v 1.23 2005/03/15 20:42:12 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/cam_xpt.c,v 1.24 2005/06/02 20:40:29 dillon Exp $
  */
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1126,7 +1126,7 @@ xptioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
         * we never return a status of CAM_GDEVLIST_LIST_CHANGED.  It is
         * (or rather should be) impossible for the device peripheral driver
         * list to change since we look at the whole thing in one pass, and
-        * we do it with splcam protection.
+        * we do it within a critical section.
         * 
         */
        case CAMGETPASSTHRU: {
@@ -1138,14 +1138,14 @@ xptioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
                int cur_generation;
                int base_periph_found;
                int splbreaknum;
-               int s;
 
                ccb = (union ccb *)addr;
                unit = ccb->cgdl.unit_number;
                name = ccb->cgdl.periph_name;
                /*
-                * Every 100 devices, we want to drop our spl protection to
-                * give the software interrupt handler a chance to run.
+                * Every 100 devices, we want to call splz() to check for
+                * and allow the software interrupt handler a chance to run.
+                *
                 * Most systems won't run into this check, but this should
                 * avoid starvation in the software interrupt handler in
                 * large systems.
@@ -1166,7 +1166,7 @@ xptioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
                }
 
                /* Keep the list from changing while we traverse it */
-               s = splcam();
+               crit_enter();
 ptstartover:
                cur_generation = xsoftc.generation;
 
@@ -1177,7 +1177,7 @@ ptstartover:
                }
 
                if (*p_drv == NULL) {
-                       splx(s);
+                       crit_exit();
                        ccb->ccb_h.status = CAM_REQ_CMP_ERR;
                        ccb->cgdl.status = CAM_GDEVLIST_ERROR;
                        *ccb->cgdl.periph_name = '\0';
@@ -1199,8 +1199,7 @@ ptstartover:
                        if (periph->unit_number == unit) {
                                break;
                        } else if (--splbreaknum == 0) {
-                               splx(s);
-                               s = splcam();
+                               splz();
                                splbreaknum = 100;
                                if (cur_generation != xsoftc.generation)
                                       goto ptstartover;
@@ -1289,7 +1288,7 @@ ptstartover:
                                       "your kernel config file\n");
                        }
                }
-               splx(s);
+               crit_exit();
                break;
                }
        default:
@@ -1402,22 +1401,19 @@ xpt_add_periph(struct cam_periph *periph)
        status = CAM_REQ_CMP;
 
        if (device != NULL) {
-               int s;
-
                /*
                 * Make room for this peripheral
                 * so it will fit in the queue
                 * when it's scheduled to run
                 */
-               s = splsoftcam();
+               crit_enter();
                status = camq_resize(&device->drvq,
                                     device->drvq.array_size + 1);
 
                device->generation++;
 
                SLIST_INSERT_HEAD(periph_head, periph, periph_links);
-
-               splx(s);
+               crit_exit();
        }
 
        xsoftc.generation++;
@@ -1433,20 +1429,18 @@ xpt_remove_periph(struct cam_periph *periph)
        device = periph->path->device;
 
        if (device != NULL) {
-               int s;
                struct periph_list *periph_head;
 
                periph_head = &device->periphs;
                
                /* Release the slot for this peripheral */
-               s = splsoftcam();
+               crit_enter();
                camq_resize(&device->drvq, device->drvq.array_size - 1);
 
                device->generation++;
 
                SLIST_REMOVE(periph_head, periph, cam_periph, periph_links);
-
-               splx(s);
+               crit_exit();
        }
 
        xsoftc.generation++;
@@ -1456,7 +1450,6 @@ xpt_remove_periph(struct cam_periph *periph)
 void
 xpt_announce_periph(struct cam_periph *periph, char *announce_string)
 {
-       int s;
        u_int mb;
        struct cam_path *path;
        struct ccb_trans_settings cts;
@@ -1466,7 +1459,7 @@ xpt_announce_periph(struct cam_periph *periph, char *announce_string)
         * To ensure that this is printed in one piece,
         * mask out CAM interrupts.
         */
-       s = splsoftcam();
+       crit_enter();
        printf("%s%d at %s%d bus %d target %d lun %d\n",
               periph->periph_name, periph->unit_number,
               path->bus->sim->sim_name,
@@ -1553,7 +1546,7 @@ xpt_announce_periph(struct cam_periph *periph, char *announce_string)
        if (announce_string != NULL)
                printf("%s%d: %s\n", periph->periph_name,
                       periph->unit_number, announce_string);
-       splx(s);
+       crit_exit();
 }
 
 
@@ -2757,13 +2750,12 @@ xptsetasyncbusfunc(struct cam_eb *bus, void *arg)
 void
 xpt_action(union ccb *start_ccb)
 {
-       int iopl;
-
        CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("xpt_action\n"));
 
        start_ccb->ccb_h.status = CAM_REQ_INPROG;
 
-       iopl = splsoftcam();
+       crit_enter();
+
        switch (start_ccb->ccb_h.func_code) {
        case XPT_SCSI_IO:
        {
@@ -2814,18 +2806,15 @@ xpt_action(union ccb *start_ccb)
        case XPT_ENG_EXEC:
        {
                struct cam_path *path;
-               int s;
                int runq;
 
                path = start_ccb->ccb_h.path;
-               s = splsoftcam();
 
                cam_ccbq_insert_ccb(&path->device->ccbq, start_ccb);
                if (path->device->qfrozen_cnt == 0)
                        runq = xpt_schedule_dev_sendq(path->bus, path->device);
                else
                        runq = 0;
-               splx(s);
                if (runq != 0)
                        xpt_run_dev_sendq(path->bus);
                break;
@@ -2857,7 +2846,6 @@ xpt_action(union ccb *start_ccb)
        case XPT_ABORT:
        {
                union ccb* abort_ccb;
-               int s;                          
 
                abort_ccb = start_ccb->cab.abort_ccb;
                if (XPT_FC_IS_DEV_QUEUED(abort_ccb)) {
@@ -2870,9 +2858,7 @@ xpt_action(union ccb *start_ccb)
                                abort_ccb->ccb_h.status =
                                    CAM_REQ_ABORTED|CAM_DEV_QFRZN;
                                xpt_freeze_devq(abort_ccb->ccb_h.path, 1);
-                               s = splcam();
                                xpt_done(abort_ccb);
-                               splx(s);
                                start_ccb->ccb_h.status = CAM_REQ_CMP;
                                break;
                        }
@@ -2935,10 +2921,8 @@ xpt_action(union ccb *start_ccb)
        case XPT_GDEV_TYPE:
        {
                struct cam_ed *dev;
-               int s;
 
                dev = start_ccb->ccb_h.path->device;
-               s = splcam();
                if ((dev->flags & CAM_DEV_UNCONFIGURED) != 0) {
                        start_ccb->ccb_h.status = CAM_DEV_NOT_THERE;
                } else {
@@ -2957,16 +2941,13 @@ xpt_action(union ccb *start_ccb)
                                bcopy(dev->serial_num, cgd->serial_num,
                                      dev->serial_num_len);
                }
-               splx(s);
                break; 
        }
        case XPT_GDEV_STATS:
        {
                struct cam_ed *dev;
-               int s;
 
                dev = start_ccb->ccb_h.path->device;
-               s = splcam();
                if ((dev->flags & CAM_DEV_UNCONFIGURED) != 0) {
                        start_ccb->ccb_h.status = CAM_DEV_NOT_THERE;
                } else {
@@ -2989,7 +2970,6 @@ xpt_action(union ccb *start_ccb)
                                cgds->last_reset = bus->last_reset;
                        cgds->ccb_h.status = CAM_REQ_CMP;
                }
-               splx(s);
                break;
        }
        case XPT_GDEVLIST:
@@ -2998,7 +2978,6 @@ xpt_action(union ccb *start_ccb)
                struct periph_list      *periph_head;
                struct ccb_getdevlist   *cgdl;
                int                     i;
-               int                     s;
                struct cam_ed           *device;
                int                     found;
 
@@ -3008,7 +2987,6 @@ xpt_action(union ccb *start_ccb)
                /*
                 * Don't want anyone mucking with our data.
                 */
-               s = splcam();
                device = start_ccb->ccb_h.path->device;
                periph_head = &device->periphs;
                cgdl = &start_ccb->cgdl;
@@ -3022,7 +3000,6 @@ xpt_action(union ccb *start_ccb)
                if ((cgdl->index != 0) && 
                    (cgdl->generation != device->generation)) {
                        cgdl->status = CAM_GDEVLIST_LIST_CHANGED;
-                       splx(s);
                        break;
                }
 
@@ -3043,7 +3020,6 @@ xpt_action(union ccb *start_ccb)
                }
                if (found == 0) {
                        cgdl->status = CAM_GDEVLIST_ERROR;
-                       splx(s);
                        break;
                }
 
@@ -3055,13 +3031,11 @@ xpt_action(union ccb *start_ccb)
                cgdl->index++;
                cgdl->generation = device->generation;
 
-               splx(s);
                cgdl->ccb_h.status = CAM_REQ_CMP;
                break;
        }
        case XPT_DEV_MATCH:
        {
-               int s;
                dev_pos_type position_type;
                struct ccb_dev_match *cdm;
                int ret;
@@ -3071,7 +3045,6 @@ xpt_action(union ccb *start_ccb)
                /*
                 * Prevent EDT changes while we traverse it.
                 */
-               s = splcam();
                /*
                 * There are two ways of getting at information in the EDT.
                 * The first way is via the primary EDT tree.  It starts
@@ -3119,8 +3092,6 @@ xpt_action(union ccb *start_ccb)
                        break;
                }
 
-               splx(s);
-
                if (cdm->status == CAM_DEV_MATCH_ERROR)
                        start_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
                else
@@ -3134,7 +3105,6 @@ xpt_action(union ccb *start_ccb)
                struct async_node *cur_entry;
                struct async_list *async_head;
                u_int32_t added;
-               int s;
 
                csa = &start_ccb->csa;
                added = csa->event_enable;
@@ -3144,7 +3114,6 @@ xpt_action(union ccb *start_ccb)
                 * If there is already an entry for us, simply
                 * update it.
                 */
-               s = splcam();
                cur_entry = SLIST_FIRST(async_head);
                while (cur_entry != NULL) {
                        if ((cur_entry->callback_arg == csa->callback_arg)
@@ -3191,7 +3160,6 @@ xpt_action(union ccb *start_ccb)
                         */
                        xpt_for_all_busses(xptsetasyncbusfunc, cur_entry);
                }
-               splx(s);
                start_ccb->ccb_h.status = CAM_REQ_CMP;
                break;
        }
@@ -3199,7 +3167,6 @@ xpt_action(union ccb *start_ccb)
        {
                struct ccb_relsim *crs;
                struct cam_ed *dev;
-               int s;
 
                crs = &start_ccb->crs;
                dev = crs->ccb_h.path->device;
@@ -3209,8 +3176,6 @@ xpt_action(union ccb *start_ccb)
                        break;
                }
 
-               s = splcam();
-
                if ((crs->release_flags & RELSIM_ADJUST_OPENINGS) != 0) {
 
                        if ((dev->inq_data.flags & SID_CmdQue) != 0) {
@@ -3282,7 +3247,6 @@ xpt_action(union ccb *start_ccb)
                                start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
                        }
                }
-               splx(s);
                
                if ((start_ccb->ccb_h.flags & CAM_DEV_QFREEZE) == 0) {
 
@@ -3303,9 +3267,6 @@ xpt_action(union ccb *start_ccb)
                break;
        case XPT_DEBUG: {
 #ifdef CAMDEBUG
-               int s;
-               
-               s = splcam();
 #ifdef CAM_DEBUG_DELAY
                cam_debug_delay = CAM_DEBUG_DELAY;
 #endif
@@ -3332,7 +3293,6 @@ xpt_action(union ccb *start_ccb)
                        cam_dpath = NULL;
                        start_ccb->ccb_h.status = CAM_REQ_CMP;
                }
-               splx(s);
 #else /* !CAMDEBUG */
                start_ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
 #endif /* CAMDEBUG */
@@ -3351,13 +3311,12 @@ xpt_action(union ccb *start_ccb)
                start_ccb->ccb_h.status = CAM_PROVIDE_FAIL;
                break;
        }
-       splx(iopl);
+       crit_exit();
 }
 
 void
 xpt_polled_action(union ccb *start_ccb)
 {
-       int       s;
        u_int32_t timeout;
        struct    cam_sim *sim; 
        struct    cam_devq *devq;
@@ -3368,7 +3327,7 @@ xpt_polled_action(union ccb *start_ccb)
        devq = sim->devq;
        dev = start_ccb->ccb_h.path->device;
 
-       s = splcam();
+       crit_enter();
 
        /*
         * Steal an opening so that no other queued requests
@@ -3411,7 +3370,7 @@ xpt_polled_action(union ccb *start_ccb)
        } else {
                start_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
        }
-       splx(s);
+       crit_exit();
 }
        
 /*
@@ -3422,12 +3381,11 @@ void
 xpt_schedule(struct cam_periph *perph, u_int32_t new_priority)
 {
        struct cam_ed *device;
-       int s;
        int runq;
 
        CAM_DEBUG(perph->path, CAM_DEBUG_TRACE, ("xpt_schedule\n"));
        device = perph->path->device;
-       s = splsoftcam();
+       crit_enter();
        if (periph_is_queued(perph)) {
                /* Simply reorder based on new priority */
                CAM_DEBUG(perph->path, CAM_DEBUG_SUBTRACE,
@@ -3447,7 +3405,7 @@ xpt_schedule(struct cam_periph *perph, u_int32_t new_priority)
                camq_insert(&device->drvq, &perph->pinfo);
                runq = xpt_schedule_dev_allocq(perph->path->bus, device);
        }
-       splx(s);
+       crit_exit();
        if (runq != 0) {
                CAM_DEBUG(perph->path, CAM_DEBUG_SUBTRACE,
                          ("   calling xpt_run_devq\n"));
@@ -3462,8 +3420,7 @@ xpt_schedule(struct cam_periph *perph, u_int32_t new_priority)
  * return 1 meaning the device queue should be run. If we
  * were already queued, implying someone else has already
  * started the queue, return 0 so the caller doesn't attempt
- * to run the queue.  Must be run at either splsoftcam
- * (or splcam since that encompases splsoftcam).
+ * to run the queue.  Must be run in a critical section.
  */
 static int
 xpt_schedule_dev(struct camq *queue, cam_pinfo *pinfo,
@@ -3507,7 +3464,6 @@ static void
 xpt_run_dev_allocq(struct cam_eb *bus)
 {
        struct  cam_devq *devq;
-       int     s;
 
        CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_run_dev_allocq\n"));
        devq = bus->sim->devq;
@@ -3520,7 +3476,7 @@ xpt_run_dev_allocq(struct cam_eb *bus)
                         devq->alloc_openings,
                         devq->alloc_active));
 
-       s = splsoftcam();
+       crit_enter();
        devq->alloc_queue.qfrozen_cnt++;
        while ((devq->alloc_queue.entries > 0)
            && (devq->alloc_openings > 0)
@@ -3550,7 +3506,7 @@ xpt_run_dev_allocq(struct cam_eb *bus)
                        devq->alloc_openings--;
                        devq->alloc_active++;
                        drv = (struct cam_periph*)camq_remove(drvq, CAMQ_HEAD);
-                       splx(s);
+                       crit_exit();
                        xpt_setup_ccb(&work_ccb->ccb_h, drv->path,
                                      drv->pinfo.priority);
                        CAM_DEBUG_PRINT(CAM_DEBUG_XPT,
@@ -3570,7 +3526,7 @@ xpt_run_dev_allocq(struct cam_eb *bus)
                }
        
                /* Raise IPL for possible insertion and test at top of loop */
-               s = splsoftcam();
+               crit_enter();
 
                if (drvq->entries > 0) {
                        /* We have more work.  Attempt to reschedule */
@@ -3578,34 +3534,28 @@ xpt_run_dev_allocq(struct cam_eb *bus)
                }
        }
        devq->alloc_queue.qfrozen_cnt--;
-       splx(s);
+       crit_exit();
 }
 
 static void
 xpt_run_dev_sendq(struct cam_eb *bus)
 {
        struct  cam_devq *devq;
-       int     s;
 
        CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_run_dev_sendq\n"));
        
        devq = bus->sim->devq;
 
-       s = splcam();
+       crit_enter();
        devq->send_queue.qfrozen_cnt++;
-       splx(s);
-       s = splsoftcam();
        while ((devq->send_queue.entries > 0)
            && (devq->send_openings > 0)) {
                struct  cam_ed_qinfo *qinfo;
                struct  cam_ed *device;
                union ccb *work_ccb;
                struct  cam_sim *sim;
-               int     ospl;
 
-               ospl = splcam();
                if (devq->send_queue.qfrozen_cnt > 1) {
-                       splx(ospl);
                        break;
                }
 
@@ -3618,7 +3568,6 @@ xpt_run_dev_sendq(struct cam_eb *bus)
                 * to run it.
                 */
                if (device->qfrozen_cnt > 0) {
-                       splx(ospl);
                        continue;
                }
 
@@ -3628,7 +3577,6 @@ xpt_run_dev_sendq(struct cam_eb *bus)
                work_ccb = cam_ccbq_peek_ccb(&device->ccbq, CAMQ_HEAD);
                if (work_ccb == NULL) {
                        printf("device on run queue with no ccbs???\n");
-                       splx(ospl);
                        continue;
                }
 
@@ -3646,7 +3594,6 @@ xpt_run_dev_sendq(struct cam_eb *bus)
                                                   &work_ccb->ccb_h, 
                                                   xpt_links.stqe);
 
-                               splx(ospl);
                                continue;
                        } else {
                                /*
@@ -3660,7 +3607,6 @@ xpt_run_dev_sendq(struct cam_eb *bus)
                cam_ccbq_remove_ccb(&device->ccbq, work_ccb);
 
                cam_ccbq_send_ccb(&device->ccbq, work_ccb);
-               splx(ospl);
 
                devq->send_openings--;
                devq->send_active++;            
@@ -3673,12 +3619,8 @@ xpt_run_dev_sendq(struct cam_eb *bus)
                         * The client wants to freeze the queue
                         * after this CCB is sent.
                         */
-                       ospl = splcam();
                        device->qfrozen_cnt++;
-                       splx(ospl);
                }
-               
-               splx(s);
 
                /* In Target mode, the peripheral driver knows best... */
                if (work_ccb->ccb_h.func_code == XPT_SCSI_IO) {
@@ -3702,16 +3644,11 @@ xpt_run_dev_sendq(struct cam_eb *bus)
                sim = work_ccb->ccb_h.path->bus->sim;
                (*(sim->sim_action))(sim, work_ccb);
 
-               ospl = splcam();
                devq->active_dev = NULL;
-               splx(ospl);
                /* Raise IPL for possible insertion and test at top of loop */
-               s = splsoftcam();
        }
-       splx(s);
-       s = splcam();
        devq->send_queue.qfrozen_cnt--;
-       splx(s);
+       crit_exit();
 }
 
 /*
@@ -3781,7 +3718,6 @@ xpt_compile_path(struct cam_path *new_path, struct cam_periph *perph,
        struct       cam_et *target;
        struct       cam_ed *device;
        cam_status   status;
-       int          s;
 
        status = CAM_REQ_CMP;   /* Completed without error */
        target = NULL;          /* Wildcarded */
@@ -3791,7 +3727,7 @@ xpt_compile_path(struct cam_path *new_path, struct cam_periph *perph,
         * We will potentially modify the EDT, so block interrupts
         * that may attempt to create cam paths.
         */
-       s = splcam();
+       crit_enter();
        bus = xpt_find_bus(path_id);
        if (bus == NULL) {
                status = CAM_PATH_INVALID;
@@ -3825,7 +3761,7 @@ xpt_compile_path(struct cam_path *new_path, struct cam_periph *perph,
                        }
                }
        }
-       splx(s);
+       crit_exit();
 
        /*
         * Only touch the user's data if we are successful.
@@ -3988,7 +3924,6 @@ xpt_path_periph(struct cam_path *path)
 void
 xpt_release_ccb(union ccb *free_ccb)
 {
-       int      s;
        struct   cam_path *path;
        struct   cam_ed *device;
        struct   cam_eb *bus;
@@ -3997,7 +3932,7 @@ xpt_release_ccb(union ccb *free_ccb)
        path = free_ccb->ccb_h.path;
        device = path->device;
        bus = path->bus;
-       s = splsoftcam();
+       crit_enter();
        cam_ccbq_release_opening(&device->ccbq);
        if (xpt_ccb_count > xpt_max_ccbs) {
                xpt_free_ccb(free_ccb);
@@ -4012,7 +3947,7 @@ xpt_release_ccb(union ccb *free_ccb)
         && (device->drvq.entries > 0)) {
                xpt_schedule_dev_allocq(bus, device);
        }
-       splx(s);
+       crit_exit();
        if (dev_allocq_is_runnable(bus->sim->devq))
                xpt_run_dev_allocq(bus);
 }
@@ -4034,7 +3969,6 @@ xpt_bus_register(struct cam_sim *sim, u_int32_t bus)
        struct cam_eb *new_bus;
        struct cam_eb *old_bus;
        struct ccb_pathinq cpi;
-       int s;
 
        sim->bus_id = bus;
        new_bus = malloc(sizeof(*new_bus), M_DEVBUF, M_INTWAIT);
@@ -4052,7 +3986,7 @@ xpt_bus_register(struct cam_sim *sim, u_int32_t bus)
        new_bus->flags = 0;
        new_bus->refcount = 1;  /* Held until a bus_deregister event */
        new_bus->generation = 0;
-       s = splcam();
+       crit_enter();
        old_bus = TAILQ_FIRST(&xpt_busses);
        while (old_bus != NULL
            && old_bus->path_id < new_bus->path_id)
@@ -4062,7 +3996,7 @@ xpt_bus_register(struct cam_sim *sim, u_int32_t bus)
        else
                TAILQ_INSERT_TAIL(&xpt_busses, new_bus, links);
        bus_generation++;
-       splx(s);
+       crit_exit();
 
        /* Notify interested parties */
        if (sim->path_id != CAM_XPT_PATH_ID) {
@@ -4195,7 +4129,6 @@ xpt_async(u_int32_t async_code, struct cam_path *path, void *async_arg)
        struct cam_eb *bus;
        struct cam_et *target, *next_target;
        struct cam_ed *device, *next_device;
-       int s;
 
        CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_async\n"));
 
@@ -4206,7 +4139,7 @@ xpt_async(u_int32_t async_code, struct cam_path *path, void *async_arg)
         * deferred events with a call to xpt_async. Ensure async
         * notifications are serialized by blocking cam interrupts.
         */
-       s = splcam();
+       crit_enter();
 
        bus = path->bus;
 
@@ -4257,7 +4190,7 @@ xpt_async(u_int32_t async_code, struct cam_path *path, void *async_arg)
        if (bus != xpt_periph->path->bus)
                xpt_async_bcast(&xpt_periph->path->device->asyncs, async_code,
                                path, async_arg);
-       splx(s);
+       crit_exit();
 }
 
 static void
@@ -4361,10 +4294,9 @@ xpt_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
 u_int32_t
 xpt_freeze_devq(struct cam_path *path, u_int count)
 {
-       int s;
        struct ccb_hdr *ccbh;
 
-       s = splcam();
+       crit_enter();
        path->device->qfrozen_cnt += count;
 
        /*
@@ -4376,14 +4308,14 @@ xpt_freeze_devq(struct cam_path *path, u_int count)
         * freezes the queue.  To completly close the
         * hole, controller drives must check to see
         * if a ccb's status is still CAM_REQ_INPROG
-        * under spl protection just before they queue
+        * under critical section protection just before they queue
         * the CCB.  See ahc_action/ahc_freeze_devq for
         * an example.
         */
        ccbh = TAILQ_LAST(&path->device->ccbq.active_ccbs, ccb_hdr_tailq);
        if (ccbh && ccbh->status == CAM_REQ_INPROG)
                ccbh->status = CAM_REQUEUE_REQ;
-       splx(s);
+       crit_exit();
        return (path->device->qfrozen_cnt);
 }
 
@@ -4431,11 +4363,9 @@ static void
 xpt_release_devq_device(struct cam_ed *dev, u_int count, int run_queue)
 {
        int     rundevq;
-       int     s0, s1;
 
        rundevq = 0;
-       s0 = splsoftcam();
-       s1 = splcam();
+       crit_enter();
 
        if (dev->qfrozen_cnt > 0) {
 
@@ -4470,22 +4400,20 @@ xpt_release_devq_device(struct cam_ed *dev, u_int count, int run_queue)
                        }
                }
        }
-       splx(s1);
        if (rundevq != 0)
                xpt_run_dev_sendq(dev->target->bus);
-       splx(s0);
+       crit_exit();
 }
 
 void
 xpt_release_simq(struct cam_sim *sim, int run_queue)
 {
-       int     s;
        struct  camq *sendq;
 
        sendq = &(sim->devq->send_queue);
-       s = splcam();
-       if (sendq->qfrozen_cnt > 0) {
+       crit_enter();
 
+       if (sendq->qfrozen_cnt > 0) {
                sendq->qfrozen_cnt--;
                if (sendq->qfrozen_cnt == 0) {
                        struct cam_eb *bus;
@@ -4500,7 +4428,7 @@ xpt_release_simq(struct cam_sim *sim, int run_queue)
                                sim->flags &= ~CAM_SIM_REL_TIMEOUT_PENDING;
                        }
                        bus = xpt_find_bus(sim->path_id);
-                       splx(s);
+                       crit_exit();
 
                        if (run_queue) {
                                /*
@@ -4509,18 +4437,18 @@ xpt_release_simq(struct cam_sim *sim, int run_queue)
                                xpt_run_dev_sendq(bus);
                        }
                        xpt_release_bus(bus);
-               } else
-                       splx(s);
-       } else
-               splx(s);
+               } else {
+                       crit_exit();
+               }
+       } else {
+               crit_exit();
+       }
 }
 
 void
 xpt_done(union ccb *done_ccb)
 {
-       int s;
-
-       s = splcam();
+       crit_enter();
 
        CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("xpt_done\n"));
        if ((done_ccb->ccb_h.func_code & XPT_FC_QUEUED) != 0) {
@@ -4543,7 +4471,7 @@ xpt_done(union ccb *done_ccb)
                        break;
                }
        }
-       splx(s);
+       crit_exit();
 }
 
 union ccb *
@@ -4576,9 +4504,8 @@ static union ccb *
 xpt_get_ccb(struct cam_ed *device)
 {
        union ccb *new_ccb;
-       int s;
 
-       s = splsoftcam();
+       crit_enter();
        if ((new_ccb = (union ccb *)ccb_freeq.slh_first) == NULL) {
                new_ccb = malloc(sizeof(*new_ccb), M_DEVBUF, M_INTWAIT);
                SLIST_INSERT_HEAD(&ccb_freeq, &new_ccb->ccb_h,
@@ -4587,7 +4514,7 @@ xpt_get_ccb(struct cam_ed *device)
        }
        cam_ccbq_take_opening(&device->ccbq);
        SLIST_REMOVE_HEAD(&ccb_freeq, xpt_links.sle);
-       splx(s);
+       crit_exit();
        return (new_ccb);
 }
 
@@ -4788,13 +4715,13 @@ xpt_release_device(struct cam_eb *bus, struct cam_et *target,
 static u_int32_t
 xpt_dev_ccbq_resize(struct cam_path *path, int newopenings)
 {
-       int     s;
        int     diff;
        int     result;
        struct  cam_ed *dev;
 
        dev = path->device;
-       s = splsoftcam();
+
+       crit_enter();
 
        diff = newopenings - (dev->ccbq.dev_active + dev->ccbq.dev_openings);
        result = cam_ccbq_resize(&dev->ccbq, newopenings);
@@ -4803,7 +4730,7 @@ xpt_dev_ccbq_resize(struct cam_path *path, int newopenings)
        }
        /* Adjust the global limit */
        xpt_max_ccbs += diff;
-       splx(s);
+       crit_exit();
        return (result);
 }
 
@@ -4978,7 +4905,7 @@ xpt_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
                if (request_ccb->ccb_h.status != CAM_REQ_CMP) {
                        struct cam_ed *device;
                        struct cam_et *target;
-                       int s, phl;
+                       int phl;
 
                        /*
                         * If we already probed lun 0 successfully, or
@@ -4995,14 +4922,14 @@ xpt_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
                         * path in the request ccb.
                         */
                        phl = 0;
-                       s = splcam();
+                       crit_enter();
                        device = TAILQ_FIRST(&target->ed_entries);
                        if (device != NULL) {
                                phl = device->quirk->quirks & CAM_QUIRK_HILUNS;
                                if (device->lun_id == 0)
                                        device = TAILQ_NEXT(device, links);
                        }
-                       splx(s);
+                       crit_exit();
                        if ((lun_id != 0) || (device != NULL)) {
                                if (lun_id < (CAM_SCSI2_MAXLUN-1) || phl)
                                        lun_id++;
@@ -5112,7 +5039,6 @@ xpt_scan_lun(struct cam_periph *periph, struct cam_path *path,
        cam_status status;
        struct cam_path *new_path;
        struct cam_periph *old_periph;
-       int s;
        
        CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
                  ("xpt_scan_lun\n"));
@@ -5163,7 +5089,7 @@ xpt_scan_lun(struct cam_periph *periph, struct cam_path *path,
                request_ccb->crcn.flags = flags;
        }
 
-       s = splsoftcam();
+       crit_enter();
        if ((old_periph = cam_periph_find(path, "probe")) != NULL) {
                probe_softc *softc;
 
@@ -5185,7 +5111,7 @@ xpt_scan_lun(struct cam_periph *periph, struct cam_path *path,
                        xpt_done(request_ccb);
                }
        }
-       splx(s);
+       crit_exit();
 }
 
 static void
@@ -6244,16 +6170,15 @@ swi_cambio(void *arg)
 static void
 camisr(cam_isrq_t *queue)
 {
-       int     s;
        struct  ccb_hdr *ccb_h;
 
-       s = splcam();
+       crit_enter();
        while ((ccb_h = TAILQ_FIRST(queue)) != NULL) {
                int     runq;
 
                TAILQ_REMOVE(queue, ccb_h, sim_links.tqe);
                ccb_h->pinfo.index = CAM_UNQUEUED_INDEX;
-               splx(s);
+               splz();
 
                CAM_DEBUG(ccb_h->path, CAM_DEBUG_TRACE,
                          ("camisr\n"));
@@ -6291,12 +6216,10 @@ camisr(cam_isrq_t *queue)
 
                        dev = ccb_h->path->device;
 
-                       s = splcam();
                        cam_ccbq_ccb_done(&dev->ccbq, (union ccb *)ccb_h);
 
                        ccb_h->path->bus->sim->devq->send_active--;
                        ccb_h->path->bus->sim->devq->send_openings++;
-                       splx(s);
                        
                        if ((dev->flags & CAM_DEV_REL_ON_COMPLETE) != 0
                         || ((dev->flags & CAM_DEV_REL_ON_QUEUE_EMPTY) != 0
@@ -6336,9 +6259,6 @@ camisr(cam_isrq_t *queue)
 
                /* Call the peripheral driver's callback */
                (*ccb_h->cbfcnp)(ccb_h->path->periph, (union ccb *)ccb_h);
-
-               /* Raise IPL for while test */
-               s = splcam();
        }
-       splx(s);
+       crit_exit();
 }
index 3e63d0d..869c840 100644 (file)
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_cd.c,v 1.31.2.16 2003/10/21 22:26:11 thomas Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_cd.c,v 1.17 2004/09/18 19:40:24 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_cd.c,v 1.18 2005/06/02 20:40:31 dillon Exp $
  */
 /*
  * Portions of this driver taken from the original FreeBSD cd driver.
@@ -65,6 +65,7 @@
 #include <sys/taskqueue.h>
 #include <sys/proc.h>
 #include <sys/buf2.h>
+#include <sys/thread2.h>
 
 #include "../cam.h"
 #include "../cam_ccb.h"
@@ -402,7 +403,6 @@ cdinit(void)
 static void
 cdoninvalidate(struct cam_periph *periph)
 {
-       int s;
        struct cd_softc *softc;
        struct buf *q_bp;
        struct ccb_setasync csa;
@@ -423,11 +423,11 @@ cdoninvalidate(struct cam_periph *periph)
        softc->flags |= CD_FLAG_INVALID;
 
        /*
-        * Although the oninvalidate() routines are always called at
-        * splsoftcam, we need to be at splbio() here to keep the buffer
-        * queue from being modified while we traverse it.
+        * Although the oninvalidate() routines are always while in a
+        * critical section, we need to be in a critical section here to
+        * keep the buffer queue from being modified while we traverse it.
         */
-       s = splbio();
+       crit_enter();
 
        /*
         * Return all queued I/O with ENXIO.
@@ -441,7 +441,7 @@ cdoninvalidate(struct cam_periph *periph)
                q_bp->b_flags |= B_ERROR;
                biodone(q_bp);
        }
-       splx(s);
+       crit_exit();
 
        /*
         * If this device is part of a changer, and it was scheduled
@@ -460,7 +460,6 @@ static void
 cdcleanup(struct cam_periph *periph)
 {
        struct cd_softc *softc;
-       int s;
 
        softc = (struct cd_softc *)periph->softc;
 
@@ -473,7 +472,7 @@ cdcleanup(struct cam_periph *periph)
                printf("can't remove sysctl context\n");
        }
 
-       s = splsoftcam();
+       crit_enter();
        /*
         * In the queued, non-active case, the device in question
         * has already been removed from the changer run queue.  Since this
@@ -546,7 +545,7 @@ cdcleanup(struct cam_periph *periph)
                disk_destroy(&softc->disk);
        }
        free(softc, M_DEVBUF);
-       splx(s);
+       crit_exit();
 }
 
 static void
@@ -591,10 +590,9 @@ cdasync(void *callback_arg, u_int32_t code,
        {
                struct cd_softc *softc;
                struct ccb_hdr *ccbh;
-               int s;
 
                softc = (struct cd_softc *)periph->softc;
-               s = splsoftcam();
+               crit_enter();
                /*
                 * Don't fail on the expected unit attention
                 * that will occur.
@@ -603,7 +601,7 @@ cdasync(void *callback_arg, u_int32_t code,
                for (ccbh = LIST_FIRST(&softc->pending_ccbs);
                     ccbh != NULL; ccbh = LIST_NEXT(ccbh, periph_links.le))
                        ccbh->ccb_state |= CD_CCB_RETRY_UA;
-               splx(s);
+               crit_exit();
                /* FALLTHROUGH */
        }
        default:
@@ -1010,7 +1008,6 @@ cdopen(dev_t dev, int flags, int fmt, struct thread *td)
        struct cam_periph *periph;
        struct cd_softc *softc;
        int unit, error;
-       int s;
 
        unit = dkunit(dev);
        periph = cam_extend_get(cdperiphs, unit);
@@ -1021,20 +1018,20 @@ cdopen(dev_t dev, int flags, int fmt, struct thread *td)
        softc = (struct cd_softc *)periph->softc;
 
        /*
-        * Grab splsoftcam and hold it until we lock the peripheral.
+        * Grab a critical section and hold it until we lock the peripheral.
         */
-       s = splsoftcam();
+       crit_enter();
        if (softc->flags & CD_FLAG_INVALID) {
-               splx(s);
+               crit_exit();
                return(ENXIO);
        }
 
        if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
-               splx(s);
+               crit_exit();
                return (error);
        }
 
-       splx(s);
+       crit_exit();
 
        if (cam_periph_acquire(periph) != CAM_REQ_CMP)
                return(ENXIO);
@@ -1110,9 +1107,8 @@ static void
 cdshorttimeout(void *arg)
 {
        struct cdchanger *changer;
-       int s;
 
-       s = splsoftcam();
+       crit_enter();
 
        changer = (struct cdchanger *)arg;
 
@@ -1128,8 +1124,7 @@ cdshorttimeout(void *arg)
                changer->flags |= CHANGER_MANUAL_CALL;
                cdrunchangerqueue(changer);
        }
-
-       splx(s);
+       crit_exit();
 }
 
 /*
@@ -1139,9 +1134,8 @@ static void
 cdschedule(struct cam_periph *periph, int priority)
 {
        struct cd_softc *softc;
-       int s;
 
-       s = splsoftcam();
+       crit_enter();
 
        softc = (struct cd_softc *)periph->softc;
 
@@ -1178,11 +1172,10 @@ cdschedule(struct cam_periph *periph, int priority)
                        cdrunchangerqueue(softc->changer);
                }
        } else if ((softc->flags & CD_FLAG_ACTIVE)
-               && ((softc->flags & CD_FLAG_SCHED_ON_COMP) == 0))
+               && ((softc->flags & CD_FLAG_SCHED_ON_COMP) == 0)) {
                xpt_schedule(periph, priority);
-
-       splx(s);
-
+       }
+       crit_exit();
 }
 
 static void
@@ -1191,9 +1184,8 @@ cdrunchangerqueue(void *arg)
        struct cd_softc *softc;
        struct cdchanger *changer;
        int called_from_timeout;
-       int s;
 
-       s = splsoftcam();
+       crit_enter();
 
        changer = (struct cdchanger *)arg;
 
@@ -1213,7 +1205,7 @@ cdrunchangerqueue(void *arg)
 
        /* nothing to do if the queue is empty */
        if (changer->devq.entries <= 0) {
-               splx(s);
+               crit_exit();
                return;
        }
 
@@ -1233,7 +1225,7 @@ cdrunchangerqueue(void *arg)
                                        cdrunchangerqueue, changer);
                                changer->flags |= CHANGER_TIMEOUT_SCHED;
                        }
-                       splx(s);
+                       crit_exit();
                        return;
                }
 
@@ -1291,16 +1283,15 @@ cdrunchangerqueue(void *arg)
         */
        changer->flags |= CHANGER_NEED_TIMEOUT;
 
-       splx(s);
+       crit_exit();
 }
 
 static void
 cdchangerschedule(struct cd_softc *softc)
 {
        struct cdchanger *changer;
-       int s;
 
-       s = splsoftcam();
+       crit_enter();
 
        changer = softc->changer;
 
@@ -1370,7 +1361,7 @@ cdchangerschedule(struct cd_softc *softc)
                changer->flags &= ~CHANGER_NEED_TIMEOUT;
 
        }
-       splx(s);
+       crit_exit();
 }
 
 static int
@@ -1399,13 +1390,11 @@ static union ccb *
 cdgetccb(struct cam_periph *periph, u_int32_t priority)
 {
        struct cd_softc *softc;
-       int s;
 
        softc = (struct cd_softc *)periph->softc;
 
        if (softc->flags & CD_FLAG_CHANGER) {
-
-               s = splsoftcam();
+               crit_enter();
 
                /*
                 * This should work the first time this device is woken up,
@@ -1431,12 +1420,11 @@ cdgetccb(struct cam_periph *periph, u_int32_t priority)
                        } else
                                tsleep(&softc->changer, 0, "cgticb", 0);
                }
-               splx(s);
+               crit_exit();
        }
        return(cam_periph_getccb(periph, priority));
 }
 
-
 /*
  * Actually translate the requested transfer into one the physical driver
  * can understand.  The transfer is described by a buf and will include
@@ -1448,7 +1436,6 @@ cdstrategy(struct buf *bp)
        struct cam_periph *periph;
        struct cd_softc *softc;
        u_int  unit, part;
-       int    s;
 
        unit = dkunit(bp->b_dev);
        part = dkpart(bp->b_dev);
@@ -1467,13 +1454,13 @@ cdstrategy(struct buf *bp)
         * after we are in the queue.  Otherwise, we might not properly
         * clean up one of the buffers.
         */
-       s = splbio();
+       crit_enter();
        
        /*
         * If the device has been made invalid, error out
         */
        if ((softc->flags & CD_FLAG_INVALID)) {
-               splx(s);
+               crit_exit();
                bp->b_error = ENXIO;
                goto bad;
        }
@@ -1487,7 +1474,7 @@ cdstrategy(struct buf *bp)
 
                error = cdcheckmedia(periph);
                if (error != 0) {
-                       splx(s);
+                       crit_exit();
                        bp->b_error = error;
                        goto bad;
                }
@@ -1498,7 +1485,7 @@ cdstrategy(struct buf *bp)
         */
        bufqdisksort(&softc->buf_queue, bp);
 
-       splx(s);
+       crit_exit();
        
        /*
         * Schedule ourselves for performing the work.  We do things
@@ -1527,7 +1514,6 @@ cdstart(struct cam_periph *periph, union ccb *start_ccb)
        struct buf *bp;
        struct ccb_scsiio *csio;
        struct scsi_read_capacity_data *rcap;
-       int s;
 
        softc = (struct cd_softc *)periph->softc;
 
@@ -1536,9 +1522,7 @@ cdstart(struct cam_periph *periph, union ccb *start_ccb)
        switch (softc->state) {
        case CD_STATE_NORMAL:
        {
-               int oldspl;
-
-               s = splbio();
+               crit_enter();
                bp = bufq_first(&softc->buf_queue);
                if (periph->immediate_priority <= periph->pinfo.priority) {
                        start_ccb->ccb_h.ccb_state = CD_CCB_WAITING;
@@ -1546,10 +1530,10 @@ cdstart(struct cam_periph *periph, union ccb *start_ccb)
                        SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
                                          periph_links.sle);
                        periph->immediate_priority = CAM_PRIORITY_NONE;
-                       splx(s);
+                       crit_exit();
                        wakeup(&periph->ccb_list);
                } else if (bp == NULL) {
-                       splx(s);
+                       crit_exit();
                        xpt_release_ccb(start_ccb);
                } else {
                        bufq_remove(&softc->buf_queue, bp);
@@ -1578,10 +1562,8 @@ cdstart(struct cam_periph *periph, union ccb *start_ccb)
                         * Block out any asyncronous callbacks
                         * while we touch the pending ccb list.
                         */
-                       oldspl = splcam();
                        LIST_INSERT_HEAD(&softc->pending_ccbs,
                                         &start_ccb->ccb_h, periph_links.le);
-                       splx(oldspl);
 
                        /* We expect a unit attention from this device */
                        if ((softc->flags & CD_FLAG_RETRY_UA) != 0) {
@@ -1591,7 +1573,7 @@ cdstart(struct cam_periph *periph, union ccb *start_ccb)
 
                        start_ccb->ccb_h.ccb_bp = bp;
                        bp = bufq_first(&softc->buf_queue);
-                       splx(s);
+                       crit_exit();
 
                        xpt_action(start_ccb);
                }
@@ -1637,7 +1619,6 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
        {
                struct buf      *bp;
                int             error;
-               int             oldspl;
 
                bp = (struct buf *)done_ccb->ccb_h.ccb_bp;
                error = 0;
@@ -1663,12 +1644,11 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
                }
 
                if (error != 0) {
-                       int s;
                        struct buf *q_bp;
 
                        xpt_print_path(periph->path);
                        printf("cddone: got error %#x back\n", error);
-                       s = splbio();
+                       crit_enter();
                        while ((q_bp = bufq_first(&softc->buf_queue)) != NULL) {
                                bufq_remove(&softc->buf_queue, q_bp);
                                q_bp->b_resid = q_bp->b_bcount;
@@ -1676,7 +1656,7 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
                                q_bp->b_flags |= B_ERROR;
                                biodone(q_bp);
                        }
-                       splx(s);
+                       crit_exit();
                        bp->b_resid = bp->b_bcount;
                        bp->b_error = error;
                        bp->b_flags |= B_ERROR;
@@ -1699,9 +1679,9 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
                 * Block out any asyncronous callbacks
                 * while we touch the pending ccb list.
                 */
-               oldspl = splcam();
+               crit_enter();
                LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
-               splx(oldspl);
+               crit_exit();
 
                if (softc->flags & CD_FLAG_CHANGER)
                        cdchangerschedule(softc);
index f29d608..5811e1b 100644 (file)
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_ch.c,v 1.20.2.2 2000/10/31 08:09:49 dwmalone Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_ch.c,v 1.10 2004/05/19 22:52:38 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_ch.c,v 1.11 2005/06/02 20:40:31 dillon Exp $
  */
 /*
  * Derived from the NetBSD SCSI changer driver.
@@ -82,6 +82,7 @@
 #include <sys/chio.h>
 #include <sys/errno.h>
 #include <sys/devicestat.h>
+#include <sys/thread2.h>
 
 #include "../cam.h"
 #include "../cam_ccb.h"
@@ -426,7 +427,6 @@ chopen(dev_t dev, int flags, int fmt, struct thread *td)
        struct cam_periph *periph;
        struct ch_softc *softc;
        int unit, error;
-       int s;
 
        unit = CHUNIT(dev);
        periph = cam_extend_get(chperiphs, unit);
@@ -436,18 +436,18 @@ chopen(dev_t dev, int flags, int fmt, struct thread *td)
 
        softc = (struct ch_softc *)periph->softc;
 
-       s = splsoftcam();
+       crit_enter();
        if (softc->flags & CH_FLAG_INVALID) {
-               splx(s);
+               crit_exit();
                return(ENXIO);
        }
 
        if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
-               splx(s);
+               crit_exit();
                return (error);
        }
        
-       splx(s);
+       crit_exit();
 
        if ((softc->flags & CH_FLAG_OPEN) == 0) {
                if (cam_periph_acquire(periph) != CAM_REQ_CMP)
@@ -501,24 +501,22 @@ static void
 chstart(struct cam_periph *periph, union ccb *start_ccb)
 {
        struct ch_softc *softc;
-       int s;
 
        softc = (struct ch_softc *)periph->softc;
 
        switch (softc->state) {
        case CH_STATE_NORMAL:
        {
-               s = splbio();
+               crit_enter();
                if (periph->immediate_priority <= periph->pinfo.priority){
                        start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
 
                        SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
                                          periph_links.sle);
                        periph->immediate_priority = CAM_PRIORITY_NONE;
-                       splx(s);
                        wakeup(&periph->ccb_list);
-               } else
-                       splx(s);
+               }
+               crit_exit();
                break;
        }
        case CH_STATE_PROBE:
index f0d92d0..c3f7b7c 100644 (file)
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_da.c,v 1.42.2.46 2003/10/21 22:18:19 thomas Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_da.c,v 1.22 2005/04/25 15:14:54 joerg Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_da.c,v 1.23 2005/06/02 20:40:31 dillon Exp $
  */
 
 #ifdef _KERNEL
@@ -54,6 +54,7 @@
 #include <sys/proc.h>
 #endif
 #include <sys/buf2.h>
+#include <sys/thread2.h>
 
 #include <machine/md_var.h>
 
@@ -526,7 +527,6 @@ daopen(dev_t dev, int flags, int fmt, struct thread *td)
        int unit;
        int part;
        int error;
-       int s;
 
        unit = dkunit(dev);
        part = dkpart(dev);
@@ -548,13 +548,13 @@ daopen(dev_t dev, int flags, int fmt, struct thread *td)
                return(ENXIO);
        softc->flags |= DA_FLAG_OPEN;
 
-       s = splsoftcam();
+       crit_enter();
        if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
                /* Invalidate our pack information. */
                disk_invalidate(&softc->disk);
                softc->flags &= ~DA_FLAG_PACK_INVALID;
        }
-       splx(s);
+       crit_exit();
 
        /* Do a read capacity */
        {
@@ -740,7 +740,6 @@ dastrategy(struct buf *bp)
        struct da_softc *softc;
        u_int  unit;
        u_int  part;
-       int    s;
        
        unit = dkunit(bp->b_dev);
        part = dkpart(bp->b_dev);
@@ -762,13 +761,13 @@ dastrategy(struct buf *bp)
         * after we are in the queue.  Otherwise, we might not properly
         * clean up one of the buffers.
         */
-       s = splbio();
+       crit_enter();
        
        /*
         * If the device has been made invalid, error out
         */
        if ((softc->flags & DA_FLAG_PACK_INVALID)) {
-               splx(s);
+               crit_exit();
                bp->b_error = ENXIO;
                goto bad;
        }
@@ -778,7 +777,7 @@ dastrategy(struct buf *bp)
         */
        bufqdisksort(&softc->buf_queue, bp);
 
-       splx(s);
+       crit_exit();
        
        /*
         * Schedule ourselves for performing the work.
@@ -1011,7 +1010,6 @@ dainit(void)
 static void
 daoninvalidate(struct cam_periph *periph)
 {
-       int s;
        struct da_softc *softc;
        struct buf *q_bp;
        struct ccb_setasync csa;
@@ -1032,11 +1030,10 @@ daoninvalidate(struct cam_periph *periph)
        softc->flags |= DA_FLAG_PACK_INVALID;
 
        /*
-        * Although the oninvalidate() routines are always called at
-        * splsoftcam, we need to be at splbio() here to keep the buffer
-        * queue from being modified while we traverse it.
+        * Use a critical section to keep the buffer queue from being
+        * modified while we traverse it.
         */
-       s = splbio();
+       crit_enter();
 
        /*
         * Return all queued I/O with ENXIO.
@@ -1050,7 +1047,7 @@ daoninvalidate(struct cam_periph *periph)
                q_bp->b_flags |= B_ERROR;
                biodone(q_bp);
        }
-       splx(s);
+       crit_exit();
 
        SLIST_REMOVE(&softc_list, softc, da_softc, links);
 
@@ -1125,10 +1122,9 @@ daasync(void *callback_arg, u_int32_t code,
        {
                struct da_softc *softc;
                struct ccb_hdr *ccbh;
-               int s;
 
                softc = (struct da_softc *)periph->softc;
-               s = splsoftcam();
+               crit_enter();
                /*
                 * Don't fail on the expected unit attention
                 * that will occur.
@@ -1137,7 +1133,7 @@ daasync(void *callback_arg, u_int32_t code,
                for (ccbh = LIST_FIRST(&softc->pending_ccbs);
                     ccbh != NULL; ccbh = LIST_NEXT(ccbh, periph_links.le))
                        ccbh->ccb_state |= DA_CCB_RETRY_UA;
-               splx(s);
+               crit_exit();
                /* FALLTHROUGH*/
        }
        default:
@@ -1214,7 +1210,6 @@ dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
 static cam_status
 daregister(struct cam_periph *periph, void *arg)
 {
-       int s;
        struct da_softc *softc;
        struct ccb_setasync csa;
        struct ccb_pathinq cpi;
@@ -1298,9 +1293,9 @@ daregister(struct cam_periph *periph, void *arg)
         * Block our timeout handler while we
         * add this softc to the dev list.
         */
-       s = splsoftclock();
+       crit_enter();
        SLIST_INSERT_HEAD(&softc_list, softc, links);
-       splx(s);
+       crit_exit();
 
        /*
         * The DA driver supports a blocksize, but
@@ -1358,12 +1353,11 @@ dastart(struct cam_periph *periph, union ccb *start_ccb)
        {
                /* Pull a buffer from the queue and get going on it */          
                struct buf *bp;
-               int s;
 
                /*
                 * See if there is a buf with work for us to do..
                 */
-               s = splbio();
+               crit_enter();
                bp = bufq_first(&softc->buf_queue);
                if (periph->immediate_priority <= periph->pinfo.priority) {
                        CAM_DEBUG_PRINT(CAM_DEBUG_SUBTRACE,
@@ -1372,13 +1366,12 @@ dastart(struct cam_periph *periph, union ccb *start_ccb)
                        SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
                                          periph_links.sle);
                        periph->immediate_priority = CAM_PRIORITY_NONE;
-                       splx(s);
+                       crit_exit();
                        wakeup(&periph->ccb_list);
                } else if (bp == NULL) {
-                       splx(s);
+                       crit_exit();
                        xpt_release_ccb(start_ccb);
                } else {
-                       int oldspl;
                        u_int8_t tag_code;
 
                        bufq_remove(&softc->buf_queue, bp);
@@ -1412,10 +1405,8 @@ dastart(struct cam_periph *periph, union ccb *start_ccb)
                         * Block out any asyncronous callbacks
                         * while we touch the pending ccb list.
                         */
-                       oldspl = splcam();
                        LIST_INSERT_HEAD(&softc->pending_ccbs,
                                         &start_ccb->ccb_h, periph_links.le);
-                       splx(oldspl);
 
                        /* We expect a unit attention from this device */
                        if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
@@ -1425,7 +1416,7 @@ dastart(struct cam_periph *periph, union ccb *start_ccb)
 
                        start_ccb->ccb_h.ccb_bp = bp;
                        bp = bufq_first(&softc->buf_queue);
-                       splx(s);
+                       crit_exit();
 
                        xpt_action(start_ccb);
                }
@@ -1516,12 +1507,10 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
        case DA_CCB_BUFFER_IO:
        {
                struct buf *bp;
-               int    oldspl;
 
                bp = (struct buf *)done_ccb->ccb_h.ccb_bp;
                if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
                        int error;
-                       int s;
                        int sf;
                        
                        if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
@@ -1542,7 +1531,7 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
                        if (error != 0) {
                                struct buf *q_bp;
 
-                               s = splbio();
+                               crit_enter();
 
                                if (error == ENXIO) {
                                        /*
@@ -1570,7 +1559,7 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
                                        q_bp->b_flags |= B_ERROR;
                                        biodone(q_bp);
                                }
-                               splx(s);
+                               crit_exit();
                                bp->b_error = error;
                                bp->b_resid = bp->b_bcount;
                                bp->b_flags |= B_ERROR;
@@ -1596,9 +1585,9 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
                 * Block out any asyncronous callbacks
                 * while we touch the pending ccb list.
                 */
-               oldspl = splcam();
+               crit_enter();
                LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
-               splx(oldspl);
+               crit_exit();
 
                if (softc->device_stats.busy_count == 0)
                        softc->flags |= DA_FLAG_WENT_IDLE;
@@ -1870,12 +1859,11 @@ static void
 dasendorderedtag(void *arg)
 {
        struct da_softc *softc;
-       int s;
 
        for (softc = SLIST_FIRST(&softc_list);
             softc != NULL;
             softc = SLIST_NEXT(softc, links)) {
-               s = splsoftcam();
+               crit_enter();
                if ((softc->ordered_tag_count == 0) 
                 && ((softc->flags & DA_FLAG_WENT_IDLE) == 0)) {
                        softc->flags |= DA_FLAG_NEED_OTAG;
@@ -1884,7 +1872,7 @@ dasendorderedtag(void *arg)
                        softc->flags &= ~DA_FLAG_WENT_IDLE;
 
                softc->ordered_tag_count = 0;
-               splx(s);
+               crit_exit();
        }
        /* Queue us up again */
        callout_reset(&dasendorderedtag_ch,
index 5ca2a15..61d8e32 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * $FreeBSD: src/sys/cam/scsi/scsi_low.c,v 1.1.2.5 2003/08/09 06:18:30 non Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_low.c,v 1.12 2005/05/28 01:16:30 swildner Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_low.c,v 1.13 2005/06/02 20:40:31 dillon Exp $
  * $NetBSD: scsi_low.c,v 1.24.10.8 2001/06/26 07:39:44 honda Exp $
  */
 
@@ -70,6 +70,7 @@
 #include <sys/malloc.h>
 #include <sys/queue.h>
 #include <sys/systm.h>
+#include <sys/thread2.h>
 
 #include <bus/cam/cam.h>
 #include <bus/cam/cam_ccb.h>
@@ -457,7 +458,7 @@ scsi_low_scsi_action_cam(sim, ccb)
        struct lun_info *li;
        struct slccb *cb;
        u_int lun, flags, msg, target;
-       int s, rv;
+       int rv;
 
        target = (u_int) (ccb->ccb_h.target_id);
        lun = (u_int) ccb->ccb_h.target_lun;
@@ -496,7 +497,7 @@ scsi_low_scsi_action_cam(sim, ccb)
                else
                        flags = CCB_SCSIIO;
 
-               s = SCSI_LOW_SPLSCSI();
+               crit_enter();
                li = scsi_low_alloc_li(ti, lun, 1);
 
                if (ti->ti_setup_msg != 0)
@@ -512,7 +513,7 @@ scsi_low_scsi_action_cam(sim, ccb)
                        scsi_low_test_abort(slp, ti, li);
                }
 #endif /* SCSI_LOW_DEBUG */
-               splx(s);
+               crit_exit();
                break;
 
        case XPT_EN_LUN:                /* Enable LUN as a target */
@@ -535,10 +536,10 @@ scsi_low_scsi_action_cam(sim, ccb)
                }
 #endif /* SCSI_LOW_DIAGNOSTIC */
 
-               s = SCSI_LOW_SPLSCSI();
+               crit_enter();
                cb = scsi_low_find_ccb(slp, target, lun, ccb->cab.abort_ccb);
                rv = scsi_low_abort_ccb(slp, cb);
-               splx(s);
+               crit_exit();
 
                if (rv == 0)
                        ccb->ccb_h.status = CAM_REQ_CMP;
@@ -565,7 +566,7 @@ scsi_low_scsi_action_cam(sim, ccb)
                if (lun == CAM_LUN_WILDCARD)
                        lun = 0;
 
-               s = SCSI_LOW_SPLSCSI();
+               crit_enter();
                if ((cts->valid & (CCB_TRANS_BUS_WIDTH_VALID |
                                   CCB_TRANS_SYNC_RATE_VALID |
                                   CCB_TRANS_SYNC_OFFSET_VALID)) != 0)
@@ -615,7 +616,7 @@ scsi_low_scsi_action_cam(sim, ccb)
                        if ((slp->sl_show_result & SHOW_CALCF_RES) != 0)
                                scsi_low_calcf_show(li);
                }
-               splx(s);
+               crit_exit();
 
                ccb->ccb_h.status = CAM_REQ_CMP;
                xpt_done(ccb);
@@ -640,7 +641,7 @@ scsi_low_scsi_action_cam(sim, ccb)
                if (lun == CAM_LUN_WILDCARD)
                        lun = 0;
 
-               s = SCSI_LOW_SPLSCSI();
+               crit_enter();
                li = scsi_low_alloc_li(ti, lun, 1);
 #ifdef CAM_NEW_TRAN_CODE
                if (li != NULL && cts->type == CTS_TYPE_CURRENT_SETTINGS) {
@@ -746,7 +747,7 @@ scsi_low_scsi_action_cam(sim, ccb)
                ccb->ccb_h.status = CAM_REQ_CMP;
 #endif
 settings_out:
-               splx(s);
+               crit_exit();
                xpt_done(ccb);
                break;
        }
@@ -758,9 +759,9 @@ settings_out:
        }
 
        case XPT_RESET_BUS:             /* Reset the specified SCSI bus */
-               s = SCSI_LOW_SPLSCSI();
+               crit_enter();
                scsi_low_restart(slp, SCSI_LOW_RESTART_HARD, NULL);
-               splx(s);
+               crit_exit();
                ccb->ccb_h.status = CAM_REQ_CMP;
                xpt_done(ccb);
                break;
@@ -799,10 +800,10 @@ settings_out:
                else
                        flags = CCB_NORETRY | CCB_URGENT;
 
-               s = SCSI_LOW_SPLSCSI();
+               crit_enter();
                li = scsi_low_alloc_li(ti, lun, 1);
                scsi_low_enqueue(slp, ti, li, cb, flags, msg);
-               splx(s);
+               crit_exit();
                break;
 
        case XPT_PATH_INQ: {            /* Path routing inquiry */
@@ -1059,15 +1060,13 @@ int
 scsi_low_deactivate(slp)
        struct scsi_low_softc *slp;
 {
-       int s;
-
-       s = SCSI_LOW_SPLSCSI();
+       crit_enter();
        slp->sl_flags |= HW_INACTIVE;
        (*slp->sl_osdep_fp->scsi_low_osdep_timeout)
                (slp, SCSI_LOW_TIMEOUT_CH_IO, SCSI_LOW_TIMEOUT_STOP);
        (*slp->sl_osdep_fp->scsi_low_osdep_timeout)
                (slp, SCSI_LOW_TIMEOUT_CH_ENGAGE, SCSI_LOW_TIMEOUT_STOP);
-       splx(s);
+       crit_exit();
        return 0;
 }
 
@@ -1075,21 +1074,21 @@ int
 scsi_low_activate(slp)
        struct scsi_low_softc *slp;
 {
-       int error, s;
+       int error;
 
-       s = SCSI_LOW_SPLSCSI();
+       crit_enter();
        slp->sl_flags &= ~HW_INACTIVE;
        if ((error = scsi_low_restart(slp, SCSI_LOW_RESTART_HARD, NULL)) != 0)
        {
                slp->sl_flags |= HW_INACTIVE;
-               splx(s);
+               crit_exit();
                return error;
        }
 
        slp->sl_timeout_count = 0;
        (*slp->sl_osdep_fp->scsi_low_osdep_timeout)
                (slp, SCSI_LOW_TIMEOUT_CH_IO, SCSI_LOW_TIMEOUT_START);
-       splx(s);
+       crit_exit();
        return 0;
 }
 
@@ -1158,7 +1157,8 @@ scsi_low_engage(arg)
        void *arg;
 {
        struct scsi_low_softc *slp = arg;
-       int s = SCSI_LOW_SPLSCSI();
+
+       crit_enter();
 
        switch (slp->sl_rstep)
        {
@@ -1178,7 +1178,7 @@ scsi_low_engage(arg)
        case 2:
                break;
        }
-       splx(s);
+       crit_exit();
 }
 
 static int
@@ -1368,13 +1368,12 @@ scsi_low_timeout(arg)
        void *arg;
 {
        struct scsi_low_softc *slp = arg;
-       int s;
 
-       s = SCSI_LOW_SPLSCSI();
+       crit_enter();
        (void) scsi_low_timeout_check(slp);
        (*slp->sl_osdep_fp->scsi_low_osdep_timeout)
                (slp, SCSI_LOW_TIMEOUT_CH_IO, SCSI_LOW_TIMEOUT_START);
-       splx(s);
+       crit_exit();
 }
 
 static int
@@ -1551,7 +1550,7 @@ scsi_low_attach(slp, openings, ntargs, nluns, targsize, lunsize)
 {
        struct targ_info *ti;
        struct lun_info *li;
-       int s, i, nccb, rv;
+       int i, nccb, rv;
 
        slp->sl_osdep_fp = &scsi_low_osdep_funcs_cam;
 
@@ -1598,11 +1597,11 @@ scsi_low_attach(slp, openings, ntargs, nluns, targsize, lunsize)
        callout_init(&slp->sl_si.timeout_ch);
        callout_init(&slp->sl_si.engage_ch);
 
-       s = SCSI_LOW_SPLSCSI();
+       crit_enter();
        rv = (*slp->sl_osdep_fp->scsi_low_osdep_attach) (slp);
        if (rv != 0)
        {
-               splx(s);
+               crit_exit();
                printf("%s: scsi_low_attach: osdep attach failed\n",
                        slp->sl_xname);
                return EINVAL;
@@ -1612,7 +1611,7 @@ scsi_low_attach(slp, openings, ntargs, nluns, targsize, lunsize)
        SCSI_LOW_DELAY(1000);   /* wait for 1ms */
        if (scsi_low_init(slp, SCSI_LOW_RESTART_HARD) != 0)
        {
-               splx(s);
+               crit_exit();
                printf("%s: scsi_low_attach: initialization failed\n",
                        slp->sl_xname);
                return EINVAL;
@@ -1634,7 +1633,7 @@ scsi_low_attach(slp, openings, ntargs, nluns, targsize, lunsize)
 
        /* call os depend attach done*/
        (*slp->sl_osdep_fp->scsi_low_osdep_world_start) (slp);
-       splx(s);
+       crit_exit();
        return 0;
 }
 
@@ -1642,12 +1641,12 @@ int
 scsi_low_dettach(slp)
        struct scsi_low_softc *slp;
 {
-       int s, rv;
+       int rv;
 
-       s = SCSI_LOW_SPLSCSI();
+       crit_enter();
        if (scsi_low_is_busy(slp) != 0)
        {
-               splx(s);
+               crit_exit();
                return EBUSY;
        }
 
@@ -1656,13 +1655,13 @@ scsi_low_dettach(slp)
        rv = (*slp->sl_osdep_fp->scsi_low_osdep_dettach) (slp);
        if (rv != 0)
        {
-               splx(s);
+               crit_exit();
                return EBUSY;
        }
 
        scsi_low_free_ti(slp);
        LIST_REMOVE(slp, sl_chain);
-       splx(s);
+       crit_exit();
        return 0;
 }
 
index 43c2abd..3dec8f5 100644 (file)
@@ -1,5 +1,5 @@
 /*     $FreeBSD: src/sys/cam/scsi/scsi_low.h,v 1.1.2.4 2001/07/22 00:21:41 non Exp $   */
-/*     $DragonFly: src/sys/bus/cam/scsi/scsi_low.h,v 1.7 2004/09/17 02:38:10 joerg Exp $       */
+/*     $DragonFly: src/sys/bus/cam/scsi/scsi_low.h,v 1.8 2005/06/02 20:40:31 dillon Exp $      */
 /*     $NecBSD: scsi_low.h,v 1.24.10.5 2001/06/26 07:31:46 honda Exp $ */
 /*     $NetBSD$        */
 
@@ -60,7 +60,6 @@
 #undef MSG_IDENTIFY
 #define        SCSI_LOW_DEBUGGER(dev)  Debugger((dev))
 #define        SCSI_LOW_DELAY(mu)      DELAY((mu))
-#define        SCSI_LOW_SPLSCSI        splcam
 #define        SCSI_LOW_BZERO(pt, size)        bzero((pt), (size))
 
 typedef        struct scsi_sense_data scsi_low_osdep_sense_data_t;
index b268aac..1e73fc2 100644 (file)
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_pass.c,v 1.19 2000/01/17 06:27:37 mjacob Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_pass.c,v 1.12 2004/05/19 22:52:38 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_pass.c,v 1.13 2005/06/02 20:40:31 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -43,6 +43,7 @@
 #include <sys/devicestat.h>
 #include <sys/proc.h>
 #include <sys/buf2.h>
+#include <sys/thread2.h>
 
 #include "../cam.h"
 #include "../cam_ccb.h"
@@ -178,7 +179,6 @@ passinit(void)
 static void
 passoninvalidate(struct cam_periph *periph)
 {
-       int s;
        struct pass_softc *softc;
        struct buf *q_bp;
        struct ccb_setasync csa;
@@ -199,11 +199,10 @@ passoninvalidate(struct cam_periph *periph)
        softc->flags |= PASS_FLAG_INVALID;
 
        /*
-        * Although the oninvalidate() routines are always called at
-        * splsoftcam, we need to be at splbio() here to keep the buffer
+        * We need to be in a critical section here to keep the buffer
         * queue from being modified while we traverse it.
         */
-       s = splbio();
+       crit_enter();
 
        /*
         * Return all queued I/O with ENXIO.
@@ -217,7 +216,7 @@ passoninvalidate(struct cam_periph *periph)
                q_bp->b_flags |= B_ERROR;
                biodone(q_bp);
        }
-       splx(s);
+       crit_exit();
 
        if (bootverbose) {
                xpt_print_path(periph->path);
@@ -351,7 +350,6 @@ passopen(dev_t dev, int flags, int fmt, struct thread *td)
        struct cam_periph *periph;
        struct pass_softc *softc;
        int unit, error;
-       int s;
 
        error = 0; /* default to no error */
 
@@ -366,9 +364,9 @@ passopen(dev_t dev, int flags, int fmt, struct thread *td)
 
        softc = (struct pass_softc *)periph->softc;
 
-       s = splsoftcam();
+       crit_enter();
        if (softc->flags & PASS_FLAG_INVALID) {
-               splx(s);
+               crit_exit();
                return(ENXIO);
        }
 
@@ -376,7 +374,7 @@ passopen(dev_t dev, int flags, int fmt, struct thread *td)
         * Don't allow access when we're running at a high securelvel.
         */
        if (securelevel > 1) {
-               splx(s);
+               crit_exit();
                return(EPERM);
        }
 
@@ -384,7 +382,7 @@ passopen(dev_t dev, int flags, int fmt, struct thread *td)
         * Only allow read-write access.
         */
        if (((flags & FWRITE) == 0) || ((flags & FREAD) == 0)) {
-               splx(s);
+               crit_exit();
                return(EPERM);
        }
 
@@ -394,16 +392,16 @@ passopen(dev_t dev, int flags, int fmt, struct thread *td)
        if ((flags & O_NONBLOCK) != 0) {
                xpt_print_path(periph->path);
                printf("can't do nonblocking accesss\n");
-               splx(s);
+               crit_exit();
                return(EINVAL);
        }
 
        if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
-               splx(s);
+               crit_exit();
                return (error);
        }
 
-       splx(s);
+       crit_exit();
 
        if ((softc->flags & PASS_FLAG_OPEN) == 0) {
                if (cam_periph_acquire(periph) != CAM_REQ_CMP)
@@ -455,7 +453,6 @@ passstrategy(struct buf *bp)
        struct cam_periph *periph;
        struct pass_softc *softc;
        u_int  unit;
-       int    s;
 
        /*
         * The read/write interface for the passthrough driver doesn't
@@ -490,11 +487,9 @@ passstrategy(struct buf *bp)
         * after we are in the queue.  Otherwise, we might not properly
         * clean up one of the buffers.
         */
-       s = splbio();
-       
+       crit_enter();
        bufq_insert_tail(&softc->buf_queue, bp);
-
-       splx(s);
+       crit_exit();
        
        /*
         * Schedule ourselves for performing the work.
@@ -517,7 +512,6 @@ static void
 passstart(struct cam_periph *periph, union ccb *start_ccb)
 {
        struct pass_softc *softc;
-       int s;
 
        softc = (struct pass_softc *)periph->softc;
 
@@ -526,17 +520,17 @@ passstart(struct cam_periph *periph, union ccb *start_ccb)
        {
                struct buf *bp;
 
-               s = splbio();
+               crit_enter();
                bp = bufq_first(&softc->buf_queue);
                if (periph->immediate_priority <= periph->pinfo.priority) {
                        start_ccb->ccb_h.ccb_type = PASS_CCB_WAITING;                   
                        SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
                                          periph_links.sle);
                        periph->immediate_priority = CAM_PRIORITY_NONE;
-                       splx(s);
+                       crit_exit();
                        wakeup(&periph->ccb_list);
                } else if (bp == NULL) {
-                       splx(s);
+                       crit_exit();
                        xpt_release_ccb(start_ccb);
                } else {
 
@@ -557,7 +551,7 @@ passstart(struct cam_periph *periph, union ccb *start_ccb)
                        bp->b_resid = bp->b_bcount;
                        biodone(bp);
                        bp = bufq_first(&softc->buf_queue);
-                       splx(s);
+                       crit_exit();
   
                        xpt_action(start_ccb);
 
index 1caa81b..f7ec350 100644 (file)
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_pt.c,v 1.17 2000/01/17 06:27:37 mjacob Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_pt.c,v 1.11 2004/05/19 22:52:38 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_pt.c,v 1.12 2005/06/02 20:40:31 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -40,6 +40,7 @@
 #include <sys/conf.h>
 #include <sys/ptio.h>
 #include <sys/buf2.h>
+#include <sys/thread2.h>
 
 #include "../cam.h"
 #include "../cam_ccb.h"
@@ -152,7 +153,6 @@ ptopen(dev_t dev, int flags, int fmt, struct thread *td)
        struct pt_softc *softc;
        int unit;
        int error;
-       int s;
 
        unit = minor(dev);
        periph = cam_extend_get(ptperiphs, unit);
@@ -161,9 +161,9 @@ ptopen(dev_t dev, int flags, int fmt, struct thread *td)
 
        softc = (struct pt_softc *)periph->softc;
 
-       s = splsoftcam();
+       crit_enter();
        if (softc->flags & PT_FLAG_DEVICE_INVALID) {
-               splx(s);
+               crit_exit();
                return(ENXIO);
        }
 
@@ -171,11 +171,11 @@ ptopen(dev_t dev, int flags, int fmt, struct thread *td)
            ("ptopen: dev=%s (unit %d)\n", devtoname(dev), unit));
 
        if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
-               splx(s);
+               crit_exit();
                return (error); /* error code from tsleep */
        }
 
-       splx(s);
+       crit_exit();
 
        if ((softc->flags & PT_FLAG_OPEN) == 0) {
                if (cam_periph_acquire(periph) != CAM_REQ_CMP)
@@ -224,7 +224,6 @@ ptstrategy(struct buf *bp)
        struct cam_periph *periph;
        struct pt_softc *softc;
        u_int  unit;
-       int    s;
        
        unit = minor(bp->b_dev);
        periph = cam_extend_get(ptperiphs, unit);
@@ -239,13 +238,13 @@ ptstrategy(struct buf *bp)
         * after we are in the queue.  Otherwise, we might not properly
         * clean up one of the buffers.
         */
-       s = splbio();
+       crit_enter();
        
        /*
         * If the device has been made invalid, error out
         */
        if ((softc->flags & PT_FLAG_DEVICE_INVALID)) {
-               splx(s);
+               crit_exit();
                bp->b_error = ENXIO;
                goto bad;
        }
@@ -255,7 +254,7 @@ ptstrategy(struct buf *bp)
         */
        bufq_insert_tail(&softc->buf_queue, bp);
 
-       splx(s);
+       crit_exit();
        
        /*
         * Schedule ourselves for performing the work.
@@ -377,7 +376,6 @@ ptctor(struct cam_periph *periph, void *arg)
 static void
 ptoninvalidate(struct cam_periph *periph)
 {
-       int s;
        struct pt_softc *softc;
        struct buf *q_bp;
        struct ccb_setasync csa;
@@ -398,11 +396,10 @@ ptoninvalidate(struct cam_periph *periph)
        softc->flags |= PT_FLAG_DEVICE_INVALID;
 
        /*
-        * Although the oninvalidate() routines are always called at
-        * splsoftcam, we need to be at splbio() here to keep the buffer
+        * We need to be in a critical section here to keep the buffer
         * queue from being modified while we traverse it.
         */
-       s = splbio();
+       crit_enter();
 
        /*
         * Return all queued I/O with ENXIO.
@@ -417,7 +414,7 @@ ptoninvalidate(struct cam_periph *periph)
                biodone(q_bp);
        }
 
-       splx(s);
+       crit_exit();
 
        xpt_print_path(periph->path);
        printf("lost device\n");
@@ -477,10 +474,9 @@ ptasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
        {
                struct pt_softc *softc;
                struct ccb_hdr *ccbh;
-               int s;
 
                softc = (struct pt_softc *)periph->softc;
-               s = splsoftcam();
+               crit_enter();
                /*
                 * Don't fail on the expected unit attention
                 * that will occur.
@@ -489,7 +485,7 @@ ptasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
                for (ccbh = LIST_FIRST(&softc->pending_ccbs);
                     ccbh != NULL; ccbh = LIST_NEXT(ccbh, periph_links.le))
                        ccbh->ccb_state |= PT_CCB_RETRY_UA;
-               splx(s);
+               crit_exit();
                /* FALLTHROUGH */
        }
        default:
@@ -503,14 +499,13 @@ ptstart(struct cam_periph *periph, union ccb *start_ccb)
 {
        struct pt_softc *softc;
        struct buf *bp;
-       int s;
 
        softc = (struct pt_softc *)periph->softc;
 
        /*
         * See if there is a buf with work for us to do..
         */
-       s = splbio();
+       crit_enter();
        bp = bufq_first(&softc->buf_queue);
        if (periph->immediate_priority <= periph->pinfo.priority) {
                CAM_DEBUG_PRINT(CAM_DEBUG_SUBTRACE,
@@ -519,14 +514,12 @@ ptstart(struct cam_periph *periph, union ccb *start_ccb)
                SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
                                  periph_links.sle);
                periph->immediate_priority = CAM_PRIORITY_NONE;
-               splx(s);
+               crit_exit();
                wakeup(&periph->ccb_list);
        } else if (bp == NULL) {
-               splx(s);
+               crit_exit();
                xpt_release_ccb(start_ccb);
        } else {
-               int oldspl;
-
                bufq_remove(&softc->buf_queue, bp);
 
                devstat_start_transaction(&softc->device_stats);
@@ -548,14 +541,12 @@ ptstart(struct cam_periph *periph, union ccb *start_ccb)
                 * Block out any asyncronous callbacks
                 * while we touch the pending ccb list.
                 */
-               oldspl = splcam();
                LIST_INSERT_HEAD(&softc->pending_ccbs, &start_ccb->ccb_h,
                                 periph_links.le);
-               splx(oldspl);
 
                start_ccb->ccb_h.ccb_bp = bp;
                bp = bufq_first(&softc->buf_queue);
-               splx(s);
+               crit_exit();
 
                xpt_action(start_ccb);
                
@@ -579,12 +570,10 @@ ptdone(struct cam_periph *periph, union ccb *done_ccb)
        case PT_CCB_BUFFER_IO_UA:
        {
                struct buf *bp;
-               int    oldspl;
 
                bp = (struct buf *)done_ccb->ccb_h.ccb_bp;
                if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
                        int error;
-                       int s;
                        int sf;
                        
                        if ((csio->ccb_h.ccb_state & PT_CCB_RETRY_UA) != 0)
@@ -604,7 +593,7 @@ ptdone(struct cam_periph *periph, union ccb *done_ccb)
                        if (error != 0) {
                                struct buf *q_bp;
 
-                               s = splbio();
+                               crit_enter();
 
                                if (error == ENXIO) {
                                        /*
@@ -629,7 +618,7 @@ ptdone(struct cam_periph *periph, union ccb *done_ccb)
                                        q_bp->b_flags |= B_ERROR;
                                        biodone(q_bp);
                                }
-                               splx(s);
+                               crit_exit();
                                bp->b_error = error;
                                bp->b_resid = bp->b_bcount;
                                bp->b_flags |= B_ERROR;
@@ -657,9 +646,9 @@ ptdone(struct cam_periph *periph, union ccb *done_ccb)
                 * Block out any asyncronous callbacks
                 * while we touch the pending ccb list.
                 */
-               oldspl = splcam();
+               crit_enter();
                LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
-               splx(oldspl);
+               crit_exit();
 
                devstat_end_transaction_buf(&softc->device_stats, bp);
                biodone(bp);
@@ -715,16 +704,14 @@ ptioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
                break;
        case PTIOCSETTIMEOUT:
        {
-               int s;
-
                if (*(int *)addr < 1) {
                        error = EINVAL;
                        break;
                }
 
-               s = splsoftcam();
+               crit_enter();
                softc->io_timeout = *(int *)addr * 1000;
-               splx(s);
+               crit_exit();
 
                break;
        }
index a4e1ce0..817ab20 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * $FreeBSD: src/sys/cam/scsi/scsi_sa.c,v 1.45.2.13 2002/12/17 17:08:50 trhodes Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_sa.c,v 1.12 2004/05/19 22:52:38 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_sa.c,v 1.13 2005/06/02 20:40:31 dillon Exp $
  *
  * Implementation of SCSI Sequential Access Peripheral driver for CAM.
  *
@@ -46,6 +46,7 @@
 #ifdef _KERNEL
 #include <sys/proc.h>
 #include <sys/buf2.h>
+#include <sys/thread2.h>
 #endif
 #include <sys/devicestat.h>
 #include <machine/limits.h>
@@ -454,24 +455,23 @@ saopen(dev_t dev, int flags, int fmt, struct thread *td)
        int mode;
        int density;
        int error;
-       int s;
 
        unit = SAUNIT(dev);
        mode = SAMODE(dev);
        density = SADENSITY(dev);
 
-       s = splsoftcam();
+       crit_enter();
        periph = cam_extend_get(saperiphs, unit);
        if (periph == NULL) {
-               (void) splx(s);
+               crit_exit();
                return (ENXIO); 
        }
        softc = (struct sa_softc *)periph->softc;
        if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
-               splx(s);
+               crit_exit();
                return (error);
        }
-       splx(s);
+       crit_exit();
 
        CAM_DEBUG(periph->path, CAM_DEBUG_TRACE|CAM_DEBUG_INFO,
            ("saopen(%d): dev=0x%x softc=0x%x\n", unit, unit, softc->flags));
@@ -666,7 +666,6 @@ sastrategy(struct buf *bp)
        struct cam_periph *periph;
        struct sa_softc *softc;
        u_int  unit;
-       int    s;
        
        if (SA_IS_CTRL(bp->b_dev)) {
                bp->b_error = EINVAL;
@@ -680,21 +679,21 @@ sastrategy(struct buf *bp)
        }
        softc = (struct sa_softc *)periph->softc;
 
-       s = splsoftcam();
+       crit_enter();
 
        if (softc->flags & SA_FLAG_INVALID) {
-               splx(s);
+               crit_exit();
                bp->b_error = ENXIO;
                goto bad;
        }
 
        if (softc->flags & SA_FLAG_TAPE_FROZEN) {
-               splx(s);
+               crit_exit();
                bp->b_error = EPERM;
                goto bad;
        }
 
-       splx(s);
+       crit_exit();
 
        /*
         * If it's a null transfer, return immediatly
@@ -740,7 +739,7 @@ sastrategy(struct buf *bp)
         * after we are in the queue.  Otherwise, we might not properly
         * clean up one of the buffers.
         */
-       s = splbio();
+       crit_enter();
        
        /*
         * Place it at the end of the queue.
@@ -753,7 +752,7 @@ sastrategy(struct buf *bp)
             (softc->flags & SA_FLAG_FIXED)?  "fixed" : "variable",
             (bp->b_flags & B_READ)? "read" : "write", softc->queue_count));
 
-       splx(s);
+       crit_exit();
        
        /*
         * Schedule ourselves for performing the work.
@@ -779,7 +778,6 @@ saioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
        struct sa_softc *softc;
        scsi_space_code spaceop;
        int didlockperiph = 0;
-       int s;
        int unit;
        int mode;
        int density;
@@ -820,15 +818,16 @@ saioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
                         * other thread that has this device open to do
                         * an MTIOCERRSTAT that would clear latched status.
                         */
-                       s = splsoftcam();
+                       crit_enter();
                        if ((periph->flags & CAM_PERIPH_LOCKED) == 0) {
                                error = cam_periph_lock(periph, PCATCH);
                                if (error != 0) {
-                                       splx(s);
+                                       crit_exit();
                                        return (error);
                                }
                                didlockperiph = 1;
                        }
+                       crit_exit();
                        break;
 
                case MTIOCSETEOTMODEL:
@@ -840,13 +839,14 @@ saioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
                         * than at open time because we are sharing writable
                         * access to data structures.
                         */
-                       s = splsoftcam();
+                       crit_enter();
                        error = cam_periph_lock(periph, PCATCH);
                        if (error != 0) {
-                               splx(s);
+                               crit_exit();
                                return (error);
                        }
                        didlockperiph = 1;
+                       crit_exit();
                        break;
 
                default:
@@ -1308,7 +1308,6 @@ saoninvalidate(struct cam_periph *periph)
        struct sa_softc *softc;
        struct buf *q_bp;
        struct ccb_setasync csa;
-       int s;
 
        softc = (struct sa_softc *)periph->softc;
 
@@ -1326,11 +1325,10 @@ saoninvalidate(struct cam_periph *periph)
        softc->flags |= SA_FLAG_INVALID;
 
        /*
-        * Although the oninvalidate() routines are always called at
-        * splsoftcam, we need to be at splbio() here to keep the buffer
+        * We need to be in a critical section here to keep the buffer
         * queue from being modified while we traverse it.
         */
-       s = splbio();
+       crit_enter();
 
        /*
         * Return all queued I/O with ENXIO.
@@ -1345,7 +1343,7 @@ saoninvalidate(struct cam_periph *periph)
                biodone(q_bp);
        }
        softc->queue_count = 0;
-       splx(s);
+       crit_exit();
 
        xpt_print_path(periph->path);
        printf("lost device\n");
@@ -1536,12 +1534,11 @@ sastart(struct cam_periph *periph, union ccb *start_ccb)
        {
                /* Pull a buffer from the queue and get going on it */          
                struct buf *bp;
-               int s;
 
                /*
                 * See if there is a buf with work for us to do..
                 */
-               s = splbio();
+               crit_enter();
                bp = bufq_first(&softc->buf_queue);
                if (periph->immediate_priority <= periph->pinfo.priority) {
                        CAM_DEBUG_PRINT(CAM_DEBUG_SUBTRACE,
@@ -1550,10 +1547,10 @@ sastart(struct cam_periph *periph, union ccb *start_ccb)
                        SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
                                          periph_links.sle);
                        periph->immediate_priority = CAM_PRIORITY_NONE;
-                       splx(s);
+                       crit_exit();
                        wakeup(&periph->ccb_list);
                } else if (bp == NULL) {
-                       splx(s);
+                       crit_exit();
                        xpt_release_ccb(start_ccb);
                } else if ((softc->flags & SA_FLAG_ERR_PENDING) != 0) {
                        struct buf *done_bp;
@@ -1596,7 +1593,7 @@ again:
                            "%d more buffers queued up\n",
                            (softc->flags & SA_FLAG_ERR_PENDING),
                            (bp != NULL)? "not " : " ", softc->queue_count));
-                       splx(s);
+                       crit_exit();
                        xpt_release_ccb(start_ccb);
                        biodone(done_bp);
                } else {
@@ -1617,7 +1614,7 @@ again:
                                        xpt_print_path(periph->path);
                                        printf("zero blocksize for "
                                            "FIXED length writes?\n");
-                                       splx(s);
+                                       crit_exit();
                                        biodone(bp);
                                        break;
                                }
@@ -1660,7 +1657,7 @@ again:
                        Set_CCB_Type(start_ccb, SA_CCB_BUFFER_IO);
                        start_ccb->ccb_h.ccb_bp = bp;
                        bp = bufq_first(&softc->buf_queue);
-                       splx(s);
+                       crit_exit();
                        xpt_action(start_ccb);
                }
                
@@ -1705,7 +1702,6 @@ sadone(struct cam_periph *periph, union ccb *done_ccb)
                }
 
                if (error == EIO) {
-                       int s;                  
                        struct buf *q_bp;
 
                        /*
@@ -1719,7 +1715,7 @@ sadone(struct cam_periph *periph, union ccb *done_ccb)
                         *
                         */
 
-                       s = splbio();
+                       crit_enter();
                        softc->flags |= SA_FLAG_TAPE_FROZEN;
                        while ((q_bp = bufq_first(&softc->buf_queue)) != NULL) {
                                bufq_remove(&softc->buf_queue, q_bp);
@@ -1728,7 +1724,7 @@ sadone(struct cam_periph *periph, union ccb *done_ccb)
                                q_bp->b_flags |= B_ERROR;
                                biodone(q_bp);
                        }
-                       splx(s);
+                       crit_exit();
                }
                if (error != 0) {
                        bp->b_resid = bp->b_bcount;
index 6f9224f..1578209 100644 (file)
@@ -1,5 +1,5 @@
 /* $FreeBSD: src/sys/cam/scsi/scsi_ses.c,v 1.8.2.2 2000/08/08 23:19:21 mjacob Exp $ */
-/* $DragonFly: src/sys/bus/cam/scsi/scsi_ses.c,v 1.11 2004/05/19 22:52:38 dillon Exp $ */
+/* $DragonFly: src/sys/bus/cam/scsi/scsi_ses.c,v 1.12 2005/06/02 20:40:31 dillon Exp $ */
 /*
  * Copyright (c) 2000 Matthew Jacob
  * All rights reserved.
@@ -38,6 +38,7 @@
 #include <sys/buf.h>
 #include <sys/errno.h>
 #include <sys/devicestat.h>
+#include <sys/thread2.h>
 #include <machine/stdarg.h>
 
 #include "../cam.h"
@@ -423,19 +424,19 @@ sesopen(dev_t dev, int flags, int fmt, struct thread *td)
 {
        struct cam_periph *periph;
        struct ses_softc *softc;
-       int error, s;
+       int error;
 
-       s = splsoftcam();
+       crit_enter();
        periph = cam_extend_get(sesperiphs, SESUNIT(dev));
        if (periph == NULL) {
-               splx(s);
+               crit_exit();
                return (ENXIO);
        }
        if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
-               splx(s);
+               crit_exit();
                return (error);
        }
-       splx(s);
+       crit_exit();
 
        if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
                cam_periph_unlock(periph);
@@ -504,13 +505,13 @@ sesclose(dev_t dev, int flag, int fmt, struct thread *td)
 static void
 sesstart(struct cam_periph *p, union ccb *sccb)
 {
-       int s = splbio();
+       crit_enter();
        if (p->immediate_priority <= p->pinfo.priority) {
                SLIST_INSERT_HEAD(&p->ccb_list, &sccb->ccb_h, periph_links.sle);
                p->immediate_priority = CAM_PRIORITY_NONE;
                wakeup(&p->ccb_list);
        }
-       splx(s);
+       crit_exit();
 }
 
 static void
index a28104f..5faa566 100644 (file)
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_targ_bh.c,v 1.4.2.6 2003/11/14 11:31:25 simokawa Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_targ_bh.c,v 1.8 2004/03/15 02:27:56 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_targ_bh.c,v 1.9 2005/06/02 20:40:31 dillon Exp $
  */
 #include <sys/param.h>
 #include <sys/queue.h>
@@ -439,27 +439,26 @@ targbhstart(struct cam_periph *periph, union ccb *start_ccb)
        struct targbh_cmd_desc *desc;
        struct ccb_scsiio *csio;
        ccb_flags flags;
-       int    s;
 
        softc = (struct targbh_softc *)periph->softc;
        
-       s = splbio();
+       crit_enter();
        ccbh = TAILQ_FIRST(&softc->work_queue);
        if (periph->immediate_priority <= periph->pinfo.priority) {
                start_ccb->ccb_h.ccb_type = TARGBH_CCB_WAITING;                 
                SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
                                  periph_links.sle);
                periph->immediate_priority = CAM_PRIORITY_NONE;
-               splx(s);
+               crit_exit();
                wakeup(&periph->ccb_list);
        } else if (ccbh == NULL) {
-               splx(s);
+               crit_exit();
                xpt_release_ccb(start_ccb);     
        } else {
                TAILQ_REMOVE(&softc->work_queue, ccbh, periph_links.tqe);
                TAILQ_INSERT_HEAD(&softc->pending_queue, ccbh,
                                  periph_links.tqe);
-               splx(s);        
+               crit_exit();
                atio = (struct ccb_accept_tio*)ccbh;
                desc = (struct targbh_cmd_desc *)atio->ccb_h.ccb_descr;
 
@@ -506,9 +505,9 @@ targbhstart(struct cam_periph *periph, union ccb *start_ccb)
                CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
                          ("Sending a CTIO\n"));
                xpt_action(start_ccb);
-               s = splbio();
+               crit_enter();
                ccbh = TAILQ_FIRST(&softc->work_queue);
-               splx(s);
+               crit_exit();
        }
        if (ccbh != NULL)
                xpt_schedule(periph, /*priority*/1);
index eee4d1b..63990ce 100644 (file)
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_target.c,v 1.22.2.7 2003/02/18 22:07:10 njl Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_target.c,v 1.10 2005/03/15 20:42:14 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_target.c,v 1.11 2005/06/02 20:40:31 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -38,6 +38,7 @@
 #include <sys/poll.h>
 #include <sys/vnode.h>
 #include <sys/devicestat.h>
+#include <sys/thread2.h>
 
 #include "../cam.h"
 #include "../cam_ccb.h"
@@ -288,14 +289,14 @@ static int
 targpoll(dev_t dev, int poll_events, struct proc *p)
 {
        struct targ_softc *softc;
-       int     revents, s;
+       int     revents;
 
        softc = (struct targ_softc *)dev->si_drv1;
 
        /* Poll for write() is always ok. */
        revents = poll_events & (POLLOUT | POLLWRNORM);
        if ((poll_events & (POLLIN | POLLRDNORM)) != 0) {
-               s = splsoftcam();
+               crit_enter();
                /* Poll for read() depends on user and abort queues. */
                if (!TAILQ_EMPTY(&softc->user_ccb_queue) ||
                    !TAILQ_EMPTY(&softc->abort_queue)) {
@@ -304,7 +305,7 @@ targpoll(dev_t dev, int poll_events, struct proc *p)
                /* Only sleep if the user didn't poll for write. */
                if (revents == 0)
                        selrecord(p, &softc->read_select);
-               splx(s);
+               crit_exit();
        }
 
        return (revents);
@@ -314,14 +315,13 @@ static int
 targkqfilter(dev_t dev, struct knote *kn)
 {
        struct  targ_softc *softc;
-       int     s;
 
        softc = (struct targ_softc *)dev->si_drv1;
        kn->kn_hook = (caddr_t)softc;
        kn->kn_fop = &targread_filtops;
-       s = splsoftcam();
+       crit_enter();
        SLIST_INSERT_HEAD(&softc->read_select.si_note, kn, kn_selnext);
-       splx(s);
+       crit_exit();
        return (0);
 }
 
@@ -329,12 +329,11 @@ static void
 targreadfiltdetach(struct knote *kn)
 {
        struct  targ_softc *softc;
-       int     s;
 
        softc = (struct targ_softc *)kn->kn_hook;
-       s = splsoftcam();
+       crit_enter();
        SLIST_REMOVE(&softc->read_select.si_note, kn, knote, kn_selnext);
-       splx(s);
+       crit_exit();
 }
 
 /* Notify the user's kqueue when the user queue or abort queue gets a CCB */
@@ -342,13 +341,13 @@ static int
 targreadfilt(struct knote *kn, long hint)
 {
        struct targ_softc *softc;
-       int     retval, s;
+       int     retval;
 
        softc = (struct targ_softc *)kn->kn_hook;
-       s = splsoftcam();
+       crit_enter();
        retval = !TAILQ_EMPTY(&softc->user_ccb_queue) ||
                 !TAILQ_EMPTY(&softc->abort_queue);
-       splx(s);
+       crit_exit();
        return (retval);
 }
 
@@ -451,7 +450,6 @@ static cam_status
 targdisable(struct targ_softc *softc)
 {
        cam_status status;
-       int s;
 
        if ((softc->state & TARG_STATE_LUN_ENABLED) == 0)
                return (CAM_REQ_CMP);
@@ -459,9 +457,9 @@ targdisable(struct targ_softc *softc)
        CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("targdisable\n"));
 
        /* Abort any ccbs pending on the controller */
-       s = splcam();
+       crit_enter();
        abort_all_pending(softc);
-       splx(s);
+       crit_exit();
 
        /* Disable this lun */
        status = targendislun(softc->path, /*enable*/0,
@@ -523,7 +521,7 @@ targwrite(dev_t dev, struct uio *uio, int ioflag)
        union ccb *user_ccb;
        struct targ_softc *softc;
        struct targ_cmd_descr *descr;
-       int write_len, error, s;
+       int write_len, error;
        int func_code, priority;
 
        softc = (struct targ_softc *)dev->si_drv1;
@@ -555,11 +553,11 @@ targwrite(dev_t dev, struct uio *uio, int ioflag)
                        CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
                                  ("Sent ATIO/INOT (%p)\n", user_ccb));
                        xpt_action(ccb);
-                       s = splsoftcam();
+                       crit_enter();
                        TAILQ_INSERT_TAIL(&softc->pending_ccb_queue,
                                          &ccb->ccb_h,
                                          periph_links.tqe);
-                       splx(s);
+                       crit_exit();
                        break;
                default:
                        if ((func_code & XPT_FC_QUEUED) != 0) {
@@ -570,10 +568,10 @@ targwrite(dev_t dev, struct uio *uio, int ioflag)
                                descr->user_ccb = user_ccb;
                                descr->priority = priority;
                                descr->func_code = func_code;
-                               s = splsoftcam();
+                               crit_enter();
                                TAILQ_INSERT_TAIL(&softc->work_queue,
                                                  descr, tqe);
-                               splx(s);
+                               crit_exit();
                                xpt_schedule(softc->periph, priority);
                        } else {
                                CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
@@ -613,20 +611,20 @@ targstart(struct cam_periph *periph, union ccb *start_ccb)
 {
        struct targ_softc *softc;
        struct targ_cmd_descr *descr, *next_descr;
-       int s, error;
+       int error;
 
        softc = (struct targ_softc *)periph->softc;
        CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("targstart %p\n", start_ccb));
 
-       s = splsoftcam();
+       crit_enter();
        descr = TAILQ_FIRST(&softc->work_queue);
        if (descr == NULL) {
-               splx(s);
+               crit_exit();
                xpt_release_ccb(start_ccb);
        } else {
                TAILQ_REMOVE(&softc->work_queue, descr, tqe);
                next_descr = TAILQ_FIRST(&softc->work_queue);
-               splx(s);
+               crit_exit();
 
                /* Initiate a transaction using the descr and supplied CCB */
                error = targusermerge(softc, descr, start_ccb);
@@ -638,9 +636,9 @@ targstart(struct cam_periph *periph, union ccb *start_ccb)
                        xpt_release_ccb(start_ccb);
                        suword(&descr->user_ccb->ccb_h.status,
                               CAM_REQ_CMP_ERR);
-                       s = splsoftcam();
+                       crit_enter();
                        TAILQ_INSERT_TAIL(&softc->abort_queue, descr, tqe);
-                       splx(s);
+                       crit_exit();
                        notify_user(softc);
                }
 
@@ -684,7 +682,7 @@ targusermerge(struct targ_softc *softc, struct targ_cmd_descr *descr,
                int s;
 
                cab = (struct ccb_abort *)ccb;
-               s = splsoftcam();
+               crit_enter();
                TAILQ_FOREACH(ccb_h, &softc->pending_ccb_queue,
                    periph_links.tqe) {
                        struct targ_cmd_descr *ab_descr;
@@ -698,7 +696,7 @@ targusermerge(struct targ_softc *softc, struct targ_cmd_descr *descr,
                                break;
                        }
                }
-               splx(s);
+               crit_exit();
                /* CCB not found, set appropriate status */
                if (ccb_h == NULL) {
                        k_ccbh->status = CAM_PATH_INVALID;
@@ -766,19 +764,17 @@ targsendccb(struct targ_softc *softc, union ccb *ccb,
         */
        CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("sendccb %p\n", ccb));
        if (XPT_FC_IS_QUEUED(ccb)) {
-               int s;
-
-               s = splsoftcam();
+               crit_enter();
                TAILQ_INSERT_TAIL(&softc->pending_ccb_queue, ccb_h,
                                  periph_links.tqe);
-               splx(s);
+               crit_exit();
        }
        xpt_action(ccb);
 
        return (0);
 }
 
-/* Completion routine for CCBs (called at splsoftcam) */
+/* Completion routine for CCBs (called in a critical section) */
 static void
 targdone(struct cam_periph *periph, union ccb *done_ccb)
 {
@@ -826,7 +822,7 @@ targread(dev_t dev, struct uio *uio, int ioflag)
        struct ccb_queue  *user_queue;
        struct ccb_hdr    *ccb_h;
        union  ccb        *user_ccb;
-       int                read_len, error, s;
+       int                read_len, error;
 
        error = 0;
        read_len = 0;
@@ -836,7 +832,7 @@ targread(dev_t dev, struct uio *uio, int ioflag)
        CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("targread\n"));
 
        /* If no data is available, wait or return immediately */
-       s = splsoftcam();
+       crit_enter();
        ccb_h = TAILQ_FIRST(user_queue);
        user_descr = TAILQ_FIRST(abort_queue);
        while (ccb_h == NULL && user_descr == NULL) {
@@ -848,12 +844,12 @@ targread(dev_t dev, struct uio *uio, int ioflag)
                                if (error == ERESTART) {
                                        continue;
                                } else {
-                                       splx(s);
+                                       crit_exit();
                                        goto read_fail;
                                }
                        }
                } else {
-                       splx(s);
+                       crit_exit();
                        return (EAGAIN);
                }
        }
@@ -865,7 +861,7 @@ targread(dev_t dev, struct uio *uio, int ioflag)
                if (uio->uio_resid < sizeof(user_ccb))
                        break;
                TAILQ_REMOVE(user_queue, ccb_h, periph_links.tqe);
-               splx(s);
+               crit_exit();
                descr = (struct targ_cmd_descr *)ccb_h->targ_descr;
                user_ccb = descr->user_ccb;
                CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
@@ -878,7 +874,7 @@ targread(dev_t dev, struct uio *uio, int ioflag)
                        goto read_fail;
                read_len += sizeof(user_ccb);
 
-               s = splsoftcam();
+               crit_enter();
                ccb_h = TAILQ_FIRST(user_queue);
        }
 
@@ -887,7 +883,7 @@ targread(dev_t dev, struct uio *uio, int ioflag)
                if (uio->uio_resid < sizeof(user_ccb))
                        break;
                TAILQ_REMOVE(abort_queue, user_descr, tqe);
-               splx(s);
+               crit_exit();
                user_ccb = user_descr->user_ccb;
                CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH,
                          ("targread aborted descr %p (%p)\n",
@@ -898,10 +894,10 @@ targread(dev_t dev, struct uio *uio, int ioflag)
                        goto read_fail;
                read_len += sizeof(user_ccb);
 
-               s = splsoftcam();
+               crit_enter();
                user_descr = TAILQ_FIRST(abort_queue);
        }
-       splx(s);
+       crit_exit();
 
        /*
         * If we've successfully read some amount of data, don't report an
index 33c9c2f..b60c7ef 100644 (file)
@@ -32,7 +32,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  * 
  * $FreeBSD: src/sys/dev/firewire/firewire.c,v 1.68 2004/01/08 14:58:09 simokawa Exp $
- * $DragonFly: src/sys/bus/firewire/firewire.c,v 1.10 2005/02/17 13:59:35 joerg Exp $
+ * $DragonFly: src/sys/bus/firewire/firewire.c,v 1.11 2005/06/02 20:40:33 dillon Exp $
  *
  */
 
@@ -44,6 +44,7 @@
 #include <sys/malloc.h>
 #include <sys/conf.h>
 #include <sys/sysctl.h>
+#include <sys/thread2.h>
 
 #if defined(__DragonFly__) || __FreeBSD_version < 500000
 #include <machine/clock.h>     /* for DELAY() */
@@ -159,13 +160,12 @@ struct fw_device *
 fw_noderesolve_nodeid(struct firewire_comm *fc, int dst)
 {
        struct fw_device *fwdev;
-       int s;
 
-       s = splfw();
+       crit_enter();
        STAILQ_FOREACH(fwdev, &fc->devices, link)
                if (fwdev->dst == dst && fwdev->status != FWDEVINVAL)
                        break;
-       splx(s);
+       crit_exit();
 
        return fwdev;
 }
@@ -177,13 +177,12 @@ struct fw_device *
 fw_noderesolve_eui64(struct firewire_comm *fc, struct fw_eui64 *eui)
 {
        struct fw_device *fwdev;
-       int s;
 
-       s = splfw();
+       crit_enter();
        STAILQ_FOREACH(fwdev, &fc->devices, link)
                if (FW_EUI64_EQUAL(fwdev->eui, *eui))
                        break;
-       splx(s);
+       crit_exit();
 
        if(fwdev == NULL) return NULL;
        if(fwdev->status == FWDEVINVAL) return NULL;
@@ -293,7 +292,7 @@ static void
 fw_asystart(struct fw_xfer *xfer)
 {
        struct firewire_comm *fc = xfer->fc;
-       int s;
+
        if(xfer->retry++ >= fc->max_asyretry){
                device_printf(fc->bdev, "max_asyretry exceeded\n");
                xfer->resp = EBUSY;
@@ -310,11 +309,11 @@ fw_asystart(struct fw_xfer *xfer)
                return;
        }
 #endif
-       s = splfw();
+       crit_enter();
        xfer->state = FWXF_INQ;
        STAILQ_INSERT_TAIL(&xfer->q->q, xfer, link);
        xfer->q->queued ++;
-       splx(s);
+       crit_exit();
        /* XXX just queue for mbuf */
        if (xfer->mbuf == NULL)
                xfer->q->start(fc);
@@ -341,7 +340,7 @@ firewire_xfer_timeout(struct firewire_comm *fc)
        struct tlabel *tl;
        struct timeval tv;
        struct timeval split_timeout;
-       int i, s;
+       int i;
 
        split_timeout.tv_sec = 0;
        split_timeout.tv_usec = 200 * 1000;      /* 200 msec */
@@ -349,7 +348,7 @@ firewire_xfer_timeout(struct firewire_comm *fc)
        microtime(&tv);
        timevalsub(&tv, &split_timeout);
 
-       s = splfw();
+       crit_enter();
        for (i = 0; i < 0x40; i ++) {
                while ((tl = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
                        xfer = tl->xfer;
@@ -367,7 +366,7 @@ firewire_xfer_timeout(struct firewire_comm *fc)
                        fw_xfer_done(xfer);
                }
        }
-       splx(s);
+       crit_exit();
 }
 
 #define WATCHDOC_HZ 10
@@ -885,9 +884,8 @@ fw_bindremove(struct firewire_comm *fc, struct fw_bind *fwb)
        struct fw_xfer *xfer, *next;
 #endif
        struct fw_bind *tfw;
-       int s;
 
-       s = splfw();
+       crit_enter();
        STAILQ_FOREACH(tfw, &fc->binds, fclist)
                if (tfw == fwb) {
                        STAILQ_REMOVE(&fc->binds, fwb, fw_bind, fclist);
@@ -895,7 +893,7 @@ fw_bindremove(struct firewire_comm *fc, struct fw_bind *fwb)
                }
 
        printf("%s: no such bind\n", __func__);
-       splx(s);
+       crit_exit();
        return (1);
 found:
 #if 0
@@ -907,7 +905,7 @@ found:
        STAILQ_INIT(&fwb->xferlist);
 #endif
 
-       splx(s);
+       crit_exit();
        return 0;
 }
 
@@ -918,19 +916,17 @@ static void
 fw_tl_free(struct firewire_comm *fc, struct fw_xfer *xfer)
 {
        struct tlabel *tl;
-       int s = splfw();
 
+       crit_enter();
        for( tl = STAILQ_FIRST(&fc->tlabels[xfer->tl]); tl != NULL;
                tl = STAILQ_NEXT(tl, link)){
                if(tl->xfer == xfer){
                        STAILQ_REMOVE(&fc->tlabels[xfer->tl], tl, tlabel, link);
                        free(tl, M_FW);
-                       splx(s);
-                       return;
+                       break;
                }
        }
-       splx(s);
-       return;
+       crit_exit();
 }
 
 /*
@@ -941,13 +937,14 @@ fw_tl2xfer(struct firewire_comm *fc, int node, int tlabel)
 {
        struct fw_xfer *xfer;
        struct tlabel *tl;
-       int s = splfw();
+
+       crit_enter();
 
        for( tl = STAILQ_FIRST(&fc->tlabels[tlabel]); tl != NULL;
                tl = STAILQ_NEXT(tl, link)){
                if(tl->xfer->send.hdr.mode.hdr.dst == node){
                        xfer = tl->xfer;
-                       splx(s);
+                       crit_exit();
                        if (firewire_debug > 2)
                                printf("fw_tl2xfer: found tl=%d\n", tlabel);
                        return(xfer);
@@ -955,7 +952,7 @@ fw_tl2xfer(struct firewire_comm *fc, int node, int tlabel)
        }
        if (firewire_debug > 1)
                printf("fw_tl2xfer: not found tl=%d\n", tlabel);
-       splx(s);
+       crit_exit();
        return(NULL);
 }
 
@@ -1022,15 +1019,13 @@ fw_xfer_done(struct fw_xfer *xfer)
 void
 fw_xfer_unload(struct fw_xfer* xfer)
 {
-       int s;
-
        if(xfer == NULL ) return;
        if(xfer->state == FWXF_INQ){
                printf("fw_xfer_free FWXF_INQ\n");
-               s = splfw();
+               crit_enter();
                STAILQ_REMOVE(&xfer->q->q, xfer, fw_xfer, link);
                xfer->q->queued --;
-               splx(s);
+               crit_exit();
        }
        if (xfer->fc != NULL) {
 #if 1
@@ -1263,10 +1258,9 @@ void fw_sidrcv(struct firewire_comm* fc, u_int32_t *sid, u_int len)
 static void
 fw_bus_probe(struct firewire_comm *fc)
 {
-       int s;
        struct fw_device *fwdev;
 
-       s = splfw();
+       crit_enter();
        fc->status = FWBUSEXPLORE;
        fc->retry_count = 0;
 
@@ -1282,7 +1276,7 @@ fw_bus_probe(struct firewire_comm *fc)
        fc->ongodev = NULL;
        fc->ongoeui.hi = 0xffffffff; fc->ongoeui.lo = 0xffffffff;
        fw_bus_explore(fc);
-       splx(s);
+       crit_exit();
 }
 
 /*
@@ -1672,10 +1666,9 @@ fw_get_tlabel(struct firewire_comm *fc, struct fw_xfer *xfer)
 {
        u_int i;
        struct tlabel *tl, *tmptl;
-       int s;
        static u_int32_t label = 0;
 
-       s = splfw();
+       crit_enter();
        for( i = 0 ; i < 0x40 ; i ++){
                label = (label + 1) & 0x3f;
                for(tmptl = STAILQ_FIRST(&fc->tlabels[label]);
@@ -1688,14 +1681,14 @@ fw_get_tlabel(struct firewire_comm *fc, struct fw_xfer *xfer)
                        tl = malloc(sizeof(struct tlabel), M_FW, M_WAITOK);
                        tl->xfer = xfer;
                        STAILQ_INSERT_TAIL(&fc->tlabels[label], tl, link);
-                       splx(s);
+                       crit_exit();
                        if (firewire_debug > 1)
                                printf("fw_get_tlabel: dst=%d tl=%d\n",
                                    xfer->send.hdr.mode.hdr.dst, label);
                        return(label);
                }
        }
-       splx(s);
+       crit_exit();
 
        printf("fw_get_tlabel: no free tlabel\n");
        return(-1);
@@ -1763,7 +1756,7 @@ fw_rcv(struct fw_rcv_buf *rb)
 {
        struct fw_pkt *fp, *resfp;
        struct fw_bind *bind;
-       int tcode, s;
+       int tcode;
        int i, len, oldstate;
 #if 0
        {
@@ -1889,13 +1882,15 @@ fw_rcv(struct fw_rcv_buf *rb)
                        len += rb->vec[i].iov_len;
                switch(bind->act_type){
                case FWACT_XFER:
-                       /* splfw()?? */
+                       crit_enter();
                        rb->xfer = STAILQ_FIRST(&bind->xferlist);
                        if (rb->xfer == NULL) {
                                printf("Discard a packet for this bind.\n");
+                               crit_exit();
                                goto err;
                        }
                        STAILQ_REMOVE_HEAD(&bind->xferlist, link);
+                       crit_exit();
                        fw_rcv_copy(rb);
                        rb->xfer->act.hand(rb->xfer);
                        return;
@@ -1909,18 +1904,20 @@ fw_rcv(struct fw_rcv_buf *rb)
                                        rb->fc->ir[bind->sub]->queued);
                                goto err;
                        }
+                       crit_enter();
                        rb->xfer = STAILQ_FIRST(&bind->xferlist);
                        if (rb->xfer == NULL) {
                                printf("Discard packet for this bind\n");
                                goto err;
                        }
                        STAILQ_REMOVE_HEAD(&bind->xferlist, link);
+                       crit_exit();
                        fw_rcv_copy(rb);
-                       s = splfw();
+                       crit_enter();
                        rb->fc->ir[bind->sub]->queued++;
                        STAILQ_INSERT_TAIL(&rb->fc->ir[bind->sub]->q,
                            rb->xfer, link);
-                       splx(s);
+                       crit_exit();
 
                        wakeup((caddr_t)rb->fc->ir[bind->sub]);
 
@@ -1951,10 +1948,10 @@ fw_rcv(struct fw_rcv_buf *rb)
                                                vec[0].iov_len);
                if (rb->xfer == NULL) goto err;
                fw_rcv_copy(rb)
-               s = splfw();
+               crit_enter();
                xferq->queued++;
                STAILQ_INSERT_TAIL(&xferq->q, rb->xfer, link);
-               splx(s);
+               crit_exit();
                sc = device_get_softc(rb->fc->bdev);
 #if defined(__DragonFly__) || __FreeBSD_version < 500000
                if (&xferq->rsel.si_pid != 0)
index 4bb806b..73f3a57 100644 (file)
@@ -32,7 +32,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  * 
  * $FreeBSD: src/sys/dev/firewire/firewirereg.h,v 1.33 2004/01/06 14:30:46 simokawa Exp $
- * $DragonFly: src/sys/bus/firewire/firewirereg.h,v 1.7 2004/02/05 17:51:43 joerg Exp $
+ * $DragonFly: src/sys/bus/firewire/firewirereg.h,v 1.8 2005/06/02 20:40:33 dillon Exp $
  *
  */
 
@@ -47,8 +47,6 @@ typedef       struct proc fw_proc;
 #include <sys/select.h>
 #include <sys/uio.h>
 
-#define        splfw splimp
-
 struct fw_device{
        u_int16_t dst;
        struct fw_eui64 eui;
index e8d09f3..4055688 100644 (file)
@@ -32,7 +32,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  * 
  * $FreeBSD: src/sys/dev/firewire/fwdev.c,v 1.36 2004/01/22 14:41:17 simokawa Exp $
- * $DragonFly: src/sys/bus/firewire/fwdev.c,v 1.9 2004/05/19 22:52:38 dillon Exp $
+ * $DragonFly: src/sys/bus/firewire/fwdev.c,v 1.10 2005/06/02 20:40:33 dillon Exp $
  *
  */
 
@@ -56,6 +56,7 @@
 #include <machine/bus.h>
 
 #include <sys/ioccom.h>
+#include <sys/thread2.h>
 
 #ifdef __DragonFly__
 #include "firewire.h"
@@ -285,7 +286,7 @@ fw_read (dev_t dev, struct uio *uio, int ioflag)
        struct firewire_softc *sc;
        struct fw_xferq *ir;
        struct fw_xfer *xfer;
-       int err = 0, s, slept = 0;
+       int err = 0, slept = 0;
        int unit = DEV2UNIT(dev);
        struct fw_pkt *fp;
 
@@ -304,9 +305,9 @@ readloop:
                /* iso bulkxfer */
                ir->stproc = STAILQ_FIRST(&ir->stvalid);
                if (ir->stproc != NULL) {
-                       s = splfw();
+                       crit_enter();
                        STAILQ_REMOVE_HEAD(&ir->stvalid, link);
-                       splx(s);
+                       crit_exit();
                        ir->queued = 0;
                }
        }
@@ -325,10 +326,10 @@ readloop:
        } else if(xfer != NULL) {
 #if 0 /* XXX broken */
                /* per packet mode or FWACT_CH bind?*/
-               s = splfw();
+               crit_enter();
                ir->queued --;
                STAILQ_REMOVE_HEAD(&ir->q, link);
-               splx(s);
+               crit_exit();
                fp = &xfer->recv.hdr;
                if (sc->fc->irx_post != NULL)
                        sc->fc->irx_post(sc->fc, fp->mode.ld);
@@ -351,9 +352,9 @@ readloop:
                        fp->mode.stream.len + sizeof(u_int32_t), uio);
                ir->queued ++;
                if(ir->queued >= ir->bnpacket){
-                       s = splfw();
+                       crit_enter();
                        STAILQ_INSERT_TAIL(&ir->stfree, ir->stproc, link);
-                       splx(s);
+                       crit_exit();
                        sc->fc->irx_enable(sc->fc, ir->dmach);
                        ir->stproc = NULL;
                }
@@ -371,7 +372,7 @@ fw_write (dev_t dev, struct uio *uio, int ioflag)
        int err = 0;
        struct firewire_softc *sc;
        int unit = DEV2UNIT(dev);
-       int s, slept = 0;
+       int slept = 0;
        struct fw_pkt *fp;
        struct firewire_comm *fc;
        struct fw_xferq *it;
@@ -388,9 +389,9 @@ isoloop:
        if (it->stproc == NULL) {
                it->stproc = STAILQ_FIRST(&it->stfree);
                if (it->stproc != NULL) {
-                       s = splfw();
+                       crit_enter();
                        STAILQ_REMOVE_HEAD(&it->stfree, link);
-                       splx(s);
+                       crit_exit();
                        it->queued = 0;
                } else if (slept == 0) {
                        slept = 1;
@@ -413,9 +414,9 @@ isoloop:
                                fp->mode.stream.len, uio);
        it->queued ++;
        if (it->queued >= it->bnpacket) {
-               s = splfw();
+               crit_enter();
                STAILQ_INSERT_TAIL(&it->stvalid, it->stproc, link);
-               splx(s);
+               crit_exit();
                it->stproc = NULL;
                err = sc->fc->itx_enable(sc->fc, it->dmach);
        }
@@ -435,7 +436,7 @@ fw_ioctl (dev_t dev, u_long cmd, caddr_t data, int flag, fw_proc *td)
        struct firewire_comm *fc;
        struct fw_drv1 *d;
        int unit = DEV2UNIT(dev);
-       int s, i, len, err = 0;
+       int i, len, err = 0;
        struct fw_device *fwdev;
        struct fw_bind *fwb;
        struct fw_xferq *ir, *it;
@@ -645,11 +646,11 @@ out:
                }
                xfer->fc = sc->fc;
 
-               s = splfw();
+               crit_enter();
                /* XXX broken. need multiple xfer */
                STAILQ_INIT(&fwb->xferlist);
                STAILQ_INSERT_TAIL(&fwb->xferlist, xfer, link);
-               splx(s);
+               crit_exit();
                err = fw_bindadd(sc->fc, fwb);
                break;
        case FW_GDEVLST:
index 50894d9..331c91d 100644 (file)
@@ -31,7 +31,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * 
- * $DragonFly: src/sys/bus/firewire/fwmem.c,v 1.6 2005/02/17 13:59:35 joerg Exp $
+ * $DragonFly: src/sys/bus/firewire/fwmem.c,v 1.7 2005/06/02 20:40:33 dillon Exp $
  */
 
 #ifndef __DragonFly__
@@ -60,6 +60,7 @@ __FBSDID("$FreeBSD: src/sys/dev/firewire/fwmem.c,v 1.26 2004/01/05 14:21:18 simo
 #include <sys/mman.h>
 #include <sys/ioccom.h>
 #include <sys/fcntl.h>
+#include <sys/thread2.h>
 
 #ifdef __DragonFly__
 #include "firewire.h"
@@ -345,7 +346,7 @@ fwmem_strategy(struct bio *bp)
        struct fw_device *fwdev;
        struct fw_xfer *xfer;
        dev_t dev;
-       int unit, err=0, s, iolen;
+       int unit, err=0, iolen;
 
        dev = bp->bio_dev;
        /* XXX check request length */
@@ -353,7 +354,7 @@ fwmem_strategy(struct bio *bp)
         unit = DEV2UNIT(dev);
        sc = devclass_get_softc(firewire_devclass, unit);
 
-       s = splfw();
+       crit_enter();
        fms = (struct fwmem_softc *)dev->si_drv1;
        fwdev = fw_noderesolve_eui64(sc->fc, &fms->eui);
        if (fwdev == NULL) {
@@ -395,7 +396,7 @@ fwmem_strategy(struct bio *bp)
        /* XXX */
        bp->bio_resid = bp->bio_bcount - iolen;
 error:
-       splx(s);
+       crit_exit();
        if (err != 0) {
                if (fwmem_debug)
                        printf("%s: err=%d\n", __func__, err);
index 3086d25..ceef3ce 100644 (file)
@@ -33,7 +33,7 @@
  * 
  * $FreeBSD: src/sys/dev/firewire/fwohci.c,v 1.72 2004/01/22 14:41:17 simokawa Exp $
  * $FreeBSD: src/sys/dev/firewire/fwohci.c,v 1.1.2.19 2003/05/01 06:24:37 simokawa Exp $
- * $DragonFly: src/sys/bus/firewire/fwohci.c,v 1.8 2004/06/02 14:42:48 eirikn Exp $
+ * $DragonFly: src/sys/bus/firewire/fwohci.c,v 1.9 2005/06/02 20:40:33 dillon Exp $
  */
 
 #define ATRQ_CH 0
@@ -52,6 +52,7 @@
 #include <sys/kernel.h>
 #include <sys/conf.h>
 #include <sys/endian.h>
+#include <sys/thread2.h>
 
 #include <machine/bus.h>
 
@@ -840,7 +841,7 @@ fwohci_execute_db2(void *arg, bus_dma_segment_t *segs, int nseg,
 static void
 fwohci_start(struct fwohci_softc *sc, struct fwohci_dbch *dbch)
 {
-       int i, s;
+       int i;
        int tcode, hdr_len, pl_off;
        int fsegment = -1;
        u_int32_t off;
@@ -864,7 +865,7 @@ fwohci_start(struct fwohci_softc *sc, struct fwohci_dbch *dbch)
        if (dbch->flags & FWOHCI_DBCH_FULL)
                return;
 
-       s = splfw();
+       crit_enter();
        db_tr = dbch->top;
 txloop:
        xfer = STAILQ_FIRST(&dbch->xferq.q);
@@ -1011,7 +1012,7 @@ kick:
        }
 
        dbch->top = db_tr;
-       splx(s);
+       crit_exit();
        return;
 }
 
@@ -1034,7 +1035,7 @@ fwohci_start_ats(struct firewire_comm *fc)
 void
 fwohci_txd(struct fwohci_softc *sc, struct fwohci_dbch *dbch)
 {
-       int s, ch, err = 0;
+       int ch, err = 0;
        struct fwohcidb_tr *tr;
        struct fwohcidb *db;
        struct fw_xfer *xfer;
@@ -1052,7 +1053,7 @@ fwohci_txd(struct fwohci_softc *sc, struct fwohci_dbch *dbch)
        }else{
                return;
        }
-       s = splfw();
+       crit_enter();
        tr = dbch->bottom;
        packets = 0;
        fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_POSTREAD);
@@ -1166,7 +1167,7 @@ out:
                dbch->flags &= ~FWOHCI_DBCH_FULL;
                fwohci_start(sc, dbch);
        }
-       splx(s);
+       crit_exit();
 }
 
 static void
@@ -1491,7 +1492,7 @@ fwohci_itxbuf_enable(struct firewire_comm *fc, int dmach)
        int err = 0;
        unsigned short tag, ich;
        struct fwohci_dbch *dbch;
-       int cycle_match, cycle_now, s, ldesc;
+       int cycle_match, cycle_now, ldesc;
        u_int32_t stat;
        struct fw_bulkxfer *first, *chunk, *prev;
        struct fw_xferq *it;
@@ -1513,7 +1514,7 @@ fwohci_itxbuf_enable(struct firewire_comm *fc, int dmach)
                return err;
 
        ldesc = dbch->ndesc - 1;
-       s = splfw();
+       crit_enter();
        prev = STAILQ_LAST(&it->stdma, fw_bulkxfer, link);
        while  ((chunk = STAILQ_FIRST(&it->stvalid)) != NULL) {
                struct fwohcidb *db;
@@ -1542,7 +1543,7 @@ fwohci_itxbuf_enable(struct firewire_comm *fc, int dmach)
        }
        fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREWRITE);
        fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREREAD);
-       splx(s);
+       crit_exit();
        stat = OREAD(sc, OHCI_ITCTL(dmach));
        if (firewire_debug && (stat & OHCI_CNTL_CYCMATCH_S))
                printf("stat 0x%x\n", stat);
@@ -1606,7 +1607,7 @@ static int
 fwohci_irx_enable(struct firewire_comm *fc, int dmach)
 {
        struct fwohci_softc *sc = (struct fwohci_softc *)fc;
-       int err = 0, s, ldesc;
+       int err = 0, ldesc;
        unsigned short tag, ich;
        u_int32_t stat;
        struct fwohci_dbch *dbch;
@@ -1640,7 +1641,7 @@ fwohci_irx_enable(struct firewire_comm *fc, int dmach)
        }
 
        ldesc = dbch->ndesc - 1;
-       s = splfw();
+       crit_enter();
        prev = STAILQ_LAST(&ir->stdma, fw_bulkxfer, link);
        while  ((chunk = STAILQ_FIRST(&ir->stfree)) != NULL) {
                struct fwohcidb *db;
@@ -1670,7 +1671,7 @@ fwohci_irx_enable(struct firewire_comm *fc, int dmach)
        }
        fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREWRITE);
        fwdma_sync_multiseg_all(dbch->am, BUS_DMASYNC_PREREAD);
-       splx(s);
+       crit_exit();
        stat = OREAD(sc, OHCI_IRCTL(dmach));
        if (stat & OHCI_CNTL_DMA_ACTIVE)
                return 0;
@@ -2067,7 +2068,6 @@ again:
 void
 fwohci_poll(struct firewire_comm *fc, int quick, int count)
 {
-       int s;
        u_int32_t stat;
        struct fwohci_softc *sc;
 
@@ -2085,9 +2085,9 @@ fwohci_poll(struct firewire_comm *fc, int quick, int count)
                if (stat == 0 || stat == 0xffffffff)
                        return;
        }
-       s = splfw();
+       crit_enter();
        fwohci_intr_body(sc, stat, count);
-       splx(s);
+       crit_exit();
 }
 
 static void
@@ -2115,11 +2115,11 @@ fwohci_tbuf_update(struct fwohci_softc *sc, int dmach)
        struct fw_bulkxfer *chunk;
        struct fw_xferq *it;
        u_int32_t stat, count;
-       int s, w=0, ldesc;
+       int w=0, ldesc;
 
        it = fc->it[dmach];
        ldesc = sc->it[dmach].ndesc - 1;
-       s = splfw(); /* unnecessary ? */
+       crit_enter();   /* unnecessary? */
        fwdma_sync_multiseg_all(sc->it[dmach].am, BUS_DMASYNC_POSTREAD);
        if (firewire_debug)
                dump_db(sc, ITX_CH + dmach);
@@ -2148,7 +2148,7 @@ fwohci_tbuf_update(struct fwohci_softc *sc, int dmach)
                STAILQ_INSERT_TAIL(&it->stfree, chunk, link);
                w++;
        }
-       splx(s);
+       crit_exit();
        if (w)
                wakeup(it);
 }
@@ -2161,14 +2161,14 @@ fwohci_rbuf_update(struct fwohci_softc *sc, int dmach)
        struct fw_bulkxfer *chunk;
        struct fw_xferq *ir;
        u_int32_t stat;
-       int s, w=0, ldesc;
+       int w=0, ldesc;
 
        ir = fc->ir[dmach];
        ldesc = sc->ir[dmach].ndesc - 1;
 #if 0
        dump_db(sc, dmach);
 #endif
-       s = splfw();
+       crit_enter();
        fwdma_sync_multiseg_all(sc->ir[dmach].am, BUS_DMASYNC_POSTREAD);
        while ((chunk = STAILQ_FIRST(&ir->stdma)) != NULL) {
                db_tr = (struct fwohcidb_tr *)chunk->end;
@@ -2203,7 +2203,7 @@ fwohci_rbuf_update(struct fwohci_softc *sc, int dmach)
                }
                w++;
        }
-       splx(s);
+       crit_exit();
        if (w) {
                if (ir->flag & FWXFERQ_HANDLER) 
                        ir->hand(ir);
@@ -2692,7 +2692,6 @@ fwohci_arcv(struct fwohci_softc *sc, struct fwohci_dbch *dbch, int count)
        u_int32_t stat, off, status;
        u_int spd;
        int len, plen, hlen, pcnt, offset;
-       int s;
        caddr_t buf;
        int resCount;
 
@@ -2704,7 +2703,7 @@ fwohci_arcv(struct fwohci_softc *sc, struct fwohci_dbch *dbch, int count)
                return;
        }
 
-       s = splfw();
+       crit_enter();
        db_tr = dbch->top;
        pcnt = 0;
        /* XXX we cannot handle a packet which lies in more than two buf */
@@ -2896,5 +2895,5 @@ out:
        if (pcnt < 1)
                printf("fwohci_arcv: no packets\n");
 #endif
-       splx(s);
+       crit_exit();
 }
index 5c1e666..d6a9ceb 100644 (file)
@@ -32,7 +32,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  * 
  * $FreeBSD: src/sys/dev/firewire/fwohci_pci.c,v 1.38 2004/01/23 17:37:09 simokawa Exp $
- * $DragonFly: src/sys/bus/firewire/fwohci_pci.c,v 1.17 2005/05/24 20:58:45 dillon Exp $
+ * $DragonFly: src/sys/bus/firewire/fwohci_pci.c,v 1.18 2005/06/02 20:40:33 dillon Exp $
  */
 
 #define BOUNCE_BUFFER_TEST     0
@@ -52,6 +52,7 @@
 #include <sys/mutex.h>
 #endif
 #include <machine/resource.h>
+#include <sys/thread2.h>
 
 #if defined(__DragonFly__) || __FreeBSD_version < 500000
 #include <machine/clock.h>             /* for DELAY() */
@@ -386,11 +387,8 @@ static int
 fwohci_pci_detach(device_t self)
 {
        fwohci_softc_t *sc = device_get_softc(self);
-       int s;
-
-
-       s = splfw();
 
+       crit_enter();
        if (sc->bsr)
                fwohci_stop(sc, self);
 
@@ -431,7 +429,7 @@ fwohci_pci_detach(device_t self)
        }
 
        fwohci_detach(sc, self);
-       splx(s);
+       crit_exit();
 
        return 0;
 }
@@ -480,7 +478,7 @@ fwohci_pci_add_child(device_t dev, int order, const char *name, int unit)
 {
        struct fwohci_softc *sc;
        device_t child;
-       int s, err = 0;
+       int err = 0;
 
        sc = (struct fwohci_softc *)device_get_softc(dev);
        child = device_add_child(dev, name, unit);
@@ -504,9 +502,9 @@ fwohci_pci_add_child(device_t dev, int order, const char *name, int unit)
         * interrupt is disabled during the boot process.
         */
        DELAY(250); /* 2 cycles */
-       s = splfw();
+       crit_enter();
        fwohci_poll((void *)sc, 0, -1);
-       splx(s);
+       crit_exit();
 
        return (child);
 }
index 55aed6e..956c5c5 100644 (file)
@@ -24,7 +24,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/iicbus/iiconf.c,v 1.10 1999/12/03 08:41:02 mdodd Exp $
- * $DragonFly: src/sys/bus/iicbus/iiconf.c,v 1.4 2003/08/07 21:16:45 dillon Exp $
+ * $DragonFly: src/sys/bus/iicbus/iiconf.c,v 1.5 2005/06/02 20:40:36 dillon Exp $
  *
  */
 #include <sys/param.h>
@@ -33,6 +33,7 @@
 #include <sys/malloc.h>
 #include <sys/module.h>
 #include <sys/bus.h>
+#include <sys/thread2.h>
 
 #include "iiconf.h"
 #include "iicbus.h"
@@ -102,7 +103,7 @@ int
 iicbus_request_bus(device_t bus, device_t dev, int how)
 {
        struct iicbus_softc *sc = (struct iicbus_softc *)device_get_softc(bus);
-       int s, error = 0;
+       int error = 0;
 
        /* first, ask the underlying layers if the request is ok */
        do {
@@ -113,15 +114,13 @@ iicbus_request_bus(device_t bus, device_t dev, int how)
        } while (error == EWOULDBLOCK);
 
        while (!error) {
-               s = splhigh();  
+               crit_enter();
                if (sc->owner && sc->owner != dev) {
-                       splx(s);
-
+                       crit_exit();
                        error = iicbus_poll(sc, how);
                } else {
                        sc->owner = dev;
-
-                       splx(s);
+                       crit_exit();
                        return (0);
                }
 
@@ -143,7 +142,7 @@ int
 iicbus_release_bus(device_t bus, device_t dev)
 {
        struct iicbus_softc *sc = (struct iicbus_softc *)device_get_softc(bus);
-       int s, error;
+       int error;
 
        /* first, ask the underlying layers if the release is ok */
        error = IICBUS_CALLBACK(device_get_parent(bus), IIC_RELEASE_BUS, NULL);
@@ -151,14 +150,13 @@ iicbus_release_bus(device_t bus, device_t dev)
        if (error)
                return (error);
 
-       s = splhigh();
+       crit_enter();
        if (sc->owner != dev) {
-               splx(s);
+               crit_exit();
                return (EACCES);
        }
-
        sc->owner = 0;
-       splx(s);
+       crit_exit();
 
        /* wakeup waiting processes */
        wakeup(sc);
index 85e84fe..889ad6d 100644 (file)
@@ -24,7 +24,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ppbus/ppbconf.c,v 1.17.2.1 2000/05/24 00:20:57 n_hibma Exp $
- * $DragonFly: src/sys/bus/ppbus/ppbconf.c,v 1.6 2005/05/24 20:58:53 dillon Exp $
+ * $DragonFly: src/sys/bus/ppbus/ppbconf.c,v 1.7 2005/06/02 20:40:37 dillon Exp $
  *
  */
 #include "opt_ppb_1284.h"
@@ -35,6 +35,7 @@
 #include <sys/module.h>
 #include <sys/bus.h>
 #include <sys/malloc.h>
+#include <sys/thread2.h>
 
 #include "ppbconf.h"
 #include "ppb_1284.h"
@@ -457,15 +458,14 @@ ppbus_teardown_intr(device_t bus, device_t child, struct resource *r, void *ih)
 int
 ppb_request_bus(device_t bus, device_t dev, int how)
 {
-       int s, error = 0;
+       int error = 0;
        struct ppb_data *ppb = DEVTOSOFTC(bus);
        struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(dev);
 
        while (!error) {
-               s = splhigh();  
+               crit_enter();
                if (ppb->ppb_owner) {
-                       splx(s);
-
+                       crit_exit();
                        switch (how) {
                        case (PPB_WAIT | PPB_INTR):
                                error = tsleep(ppb, PCATCH, "ppbreq", 0);
@@ -492,7 +492,7 @@ ppb_request_bus(device_t bus, device_t dev, int how)
                        if (ppbdev->ctx.valid)
                                ppb_set_mode(bus, ppbdev->ctx.mode);
 
-                       splx(s);
+                       crit_exit();
                        return (0);
                }
        }
@@ -508,7 +508,7 @@ ppb_request_bus(device_t bus, device_t dev, int how)
 int
 ppb_release_bus(device_t bus, device_t dev)
 {
-       int s, error;
+       int error;
        struct ppb_data *ppb = DEVTOSOFTC(bus);
        struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(dev);
 
@@ -518,14 +518,13 @@ ppb_release_bus(device_t bus, device_t dev)
                                               ppbdev->intr_cookie)))
                        return (error);
 
-       s = splhigh();
+       crit_enter();
        if (ppb->ppb_owner != dev) {
-               splx(s);
+               crit_exit();
                return (EACCES);
        }
-
        ppb->ppb_owner = 0;
-       splx(s);
+       crit_exit();
 
        /* save the context of the device */
        ppbdev->ctx.mode = ppb_get_mode(bus);
index 2c4d6ad..9b9c548 100644 (file)
@@ -24,7 +24,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/smbus/smbconf.c,v 1.9 1999/12/03 08:41:08 mdodd Exp $
- * $DragonFly: src/sys/bus/smbus/smbconf.c,v 1.4 2003/08/07 21:16:47 dillon Exp $
+ * $DragonFly: src/sys/bus/smbus/smbconf.c,v 1.5 2005/06/02 20:40:38 dillon Exp $
  *
  */
 #include <sys/param.h>
@@ -33,6 +33,7 @@
 #include <sys/malloc.h>
 #include <sys/module.h>
 #include <sys/bus.h>
+#include <sys/thread2.h>
 
 #include "smbconf.h"
 #include "smbus.h"
@@ -130,7 +131,7 @@ int
 smbus_request_bus(device_t bus, device_t dev, int how)
 {
        struct smbus_softc *sc = (struct smbus_softc *)device_get_softc(bus);
-       int s, error = 0;
+       int error = 0;
 
        /* first, ask the underlying layers if the request is ok */
        do {
@@ -141,15 +142,13 @@ smbus_request_bus(device_t bus, device_t dev, int how)
        } while (error == EWOULDBLOCK);
 
        while (!error) {
-               s = splhigh();  
+               crit_enter();
                if (sc->owner && sc->owner != dev) {
-                       splx(s);
-
+                       crit_exit();
                        error = smbus_poll(sc, how);
                } else {
                        sc->owner = dev;
-
-                       splx(s);
+                       crit_exit();
                        return (0);
                }
 
@@ -171,7 +170,7 @@ int
 smbus_release_bus(device_t bus, device_t dev)
 {
        struct smbus_softc *sc = (struct smbus_softc *)device_get_softc(bus);
-       int s, error;
+       int error;
 
        /* first, ask the underlying layers if the release is ok */
        error = SMBUS_CALLBACK(device_get_parent(bus), SMB_RELEASE_BUS, NULL);
@@ -179,14 +178,13 @@ smbus_release_bus(device_t bus, device_t dev)
        if (error)
                return (error);
 
-       s = splhigh();
+       crit_enter();
        if (sc->owner != dev) {
-               splx(s);
+               crit_exit();
                return (EACCES);
        }
-
        sc->owner = 0;
-       splx(s);
+       crit_exit();
 
        /* wakeup waiting processes */
        wakeup(sc);
index 3617e1a..5268527 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $NetBSD: ehci.c,v 1.67 2004/07/06 04:18:05 mycroft Exp $
  * $FreeBSD: src/sys/dev/usb/ehci.c,v 1.5 2003/11/10 00:20:52 joe Exp $
- * $DragonFly: src/sys/bus/usb/ehci.c,v 1.6 2004/07/08 03:47:09 dillon Exp $
+ * $DragonFly: src/sys/bus/usb/ehci.c,v 1.7 2005/06/02 20:40:40 dillon Exp $
  */
 
 /*
@@ -89,6 +89,7 @@
 #include <sys/proc.h>
 #include <sys/queue.h>
 #include <sys/sysctl.h>
+#include <sys/thread2.h>
 
 #include <machine/bus.h>
 #include <machine/endian.h>
@@ -718,9 +719,9 @@ ehci_idone(struct ehci_xfer *ex)
        DPRINTFN(/*12*/2, ("ehci_idone: ex=%p\n", ex));
 #ifdef DIAGNOSTIC
        {
-               int s = splhigh();
+               crit_enter();
                if (ex->isdone) {
-                       splx(s);
+                       crit_exit();
 #ifdef USB_DEBUG
                        printf("ehci_idone: ex is done!\n   ");
                        ehci_dump_exfer(ex);
@@ -730,7 +731,7 @@ ehci_idone(struct ehci_xfer *ex)
                        return;
                }
                ex->isdone = 1;
-               splx(s);
+               crit_exit();
        }
 #endif
 
@@ -920,14 +921,14 @@ ehci_power(int why, void *v)
 {
        ehci_softc_t *sc = v;
        //u_int32_t ctl;
-       int s;
 
 #ifdef USB_DEBUG
        DPRINTF(("ehci_power: sc=%p, why=%d\n", sc, why));
        ehci_dump_regs(sc);
 #endif
 
-       s = splhardusb();
+       crit_enter();
+
        switch (why) {
        case PWR_SUSPEND:
        case PWR_STANDBY:
@@ -979,7 +980,7 @@ OOO
        case PWR_SOFTRESUME:
                break;
        }
-       splx(s);
+       crit_exit();
 }
 #endif
 
@@ -1226,7 +1227,6 @@ ehci_open(usbd_pipe_handle pipe)
        struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
        ehci_soft_qh_t *sqh;
        usbd_status err;
-       int s;
        int speed, naks;
 
        DPRINTFN(1, ("ehci_open: pipe=%p, addr=%d, endpt=%d (%d)\n",
@@ -1297,15 +1297,15 @@ ehci_open(usbd_pipe_handle pipe)
                if (err)
                        goto bad1;
                pipe->methods = &ehci_device_ctrl_methods;
-               s = splusb();
+               crit_enter();
                ehci_add_qh(sqh, sc->sc_async_head);
-               splx(s);
+               crit_exit();
                break;
        case UE_BULK:
                pipe->methods = &ehci_device_bulk_methods;
-               s = splusb();
+               crit_enter();
                ehci_add_qh(sqh, sc->sc_async_head);
-               splx(s);
+               crit_exit();
                break;
        case UE_INTERRUPT:
                pipe->methods = &ehci_device_intr_methods;
@@ -1325,13 +1325,11 @@ ehci_open(usbd_pipe_handle pipe)
 }
 
 /*
- * Add an ED to the schedule.  Called at splusb().
+ * Add an ED to the schedule.  Called while in a critical section. 
  */
 void
 ehci_add_qh(ehci_soft_qh_t *sqh, ehci_soft_qh_t *head)
 {
-       SPLUSBCHECK;
-
        sqh->next = head->next;
        sqh->qh.qh_link = head->qh.qh_link;
        head->next = sqh;
@@ -1346,14 +1344,13 @@ ehci_add_qh(ehci_soft_qh_t *sqh, ehci_soft_qh_t *head)
 }
 
 /*
- * Remove an ED from the schedule.  Called at splusb().
+ * Remove an ED from the schedule.  Called while in a critical section.
  */
 void
 ehci_rem_qh(ehci_softc_t *sc, ehci_soft_qh_t *sqh, ehci_soft_qh_t *head)
 {
        ehci_soft_qh_t *p;
 
-       SPLUSBCHECK;
        /* XXX */
        for (p = head; p != NULL && p->next != sqh; p = p->next)
                ;
@@ -1386,7 +1383,7 @@ ehci_set_qh_qtd(ehci_soft_qh_t *sqh, ehci_soft_qtd_t *sqtd)
 void
 ehci_sync_hc(ehci_softc_t *sc)
 {
-       int s, error;
+       int error;
 
        if (sc->sc_dying) {
                DPRINTFN(2,("ehci_sync_hc: dying\n"));
@@ -1395,7 +1392,7 @@ ehci_sync_hc(ehci_softc_t *sc)
        DPRINTFN(2,("ehci_sync_hc: enter\n"));
        /* get doorbell */
        lockmgr(&sc->sc_doorbell_lock, LK_EXCLUSIVE, NULL, NULL);
-       s = splhardusb();
+       crit_enter();
        /* ask for doorbell */
        EOWRITE4(sc, EHCI_USBCMD, EOREAD4(sc, EHCI_USBCMD) | EHCI_CMD_IAAD);
        DPRINTFN(1,("ehci_sync_hc: cmd=0x%08x sts=0x%08x\n",
@@ -1403,7 +1400,7 @@ ehci_sync_hc(ehci_softc_t *sc)
        error = tsleep(&sc->sc_async_head, 0, "ehcidi", hz); /* bell wait */
        DPRINTFN(1,("ehci_sync_hc: cmd=0x%08x sts=0x%08x\n",
                    EOREAD4(sc, EHCI_USBCMD), EOREAD4(sc, EHCI_USBSTS)));
-       splx(s);
+       crit_exit();
        /* release doorbell */
        lockmgr(&sc->sc_doorbell_lock, LK_RELEASE, NULL, NULL);
 #ifdef DIAGNOSTIC
@@ -1531,7 +1528,7 @@ ehci_root_ctrl_start(usbd_xfer_handle xfer)
        usb_device_request_t *req;
        void *buf = NULL;
        int port, i;
-       int s, len, value, index, l, totlen = 0;
+       int len, value, index, l, totlen = 0;
        usb_port_status_t ps;
        usb_hub_descriptor_t hubd;
        usbd_status err;
@@ -1904,9 +1901,9 @@ ehci_root_ctrl_start(usbd_xfer_handle xfer)
        err = USBD_NORMAL_COMPLETION;
  ret:
        xfer->status = err;
-       s = splusb();
+       crit_enter();
        usb_transfer_complete(xfer);
-       splx(s);
+       crit_exit();
        return (USBD_IN_PROGRESS);
 }
 
@@ -1991,16 +1988,14 @@ ehci_root_intr_start(usbd_xfer_handle xfer)
 Static void
 ehci_root_intr_abort(usbd_xfer_handle xfer)
 {
-       int s;
-
        if (xfer->pipe->intrxfer == xfer) {
                DPRINTF(("ehci_root_intr_abort: remove\n"));
                xfer->pipe->intrxfer = NULL;
        }
        xfer->status = USBD_CANCELLED;
-       s = splusb();
+       crit_enter();
        usb_transfer_complete(xfer);
-       splx(s);
+       crit_exit();
 }
 
 /* Close the root pipe. */
@@ -2069,7 +2064,6 @@ ehci_alloc_sqtd(ehci_softc_t *sc)
        usbd_status err;
        int i, offs;
        usb_dma_t dma;
-       int s;
 
        if (sc->sc_freeqtds == NULL) {
                DPRINTFN(2, ("ehci_alloc_sqtd: allocating chunk\n"));
@@ -2081,7 +2075,7 @@ ehci_alloc_sqtd(ehci_softc_t *sc)
 #endif
                if (err)
                        return (NULL);
-               s = splusb();
+               crit_enter();
                for(i = 0; i < EHCI_SQTD_CHUNK; i++) {
                        offs = i * EHCI_SQTD_SIZE;
                        sqtd = KERNADDR(&dma, offs);
@@ -2089,16 +2083,16 @@ ehci_alloc_sqtd(ehci_softc_t *sc)
                        sqtd->nextqtd = sc->sc_freeqtds;
                        sc->sc_freeqtds = sqtd;
                }
-               splx(s);
+               crit_exit();
        }
 
-       s = splusb();
+       crit_enter();
        sqtd = sc->sc_freeqtds;
        sc->sc_freeqtds = sqtd->nextqtd;
        memset(&sqtd->qtd, 0, sizeof(ehci_qtd_t));
        sqtd->nextqtd = NULL;
        sqtd->xfer = NULL;
-       splx(s);
+       crit_exit();
 
        return (sqtd);
 }
@@ -2106,12 +2100,10 @@ ehci_alloc_sqtd(ehci_softc_t *sc)
 void
 ehci_free_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd)
 {
-       int s;
-
-       s = splusb();
+       crit_enter();
        sqtd->nextqtd = sc->sc_freeqtds;
        sc->sc_freeqtds = sqtd;
-       splx(s);
+       crit_exit();
 }
 
 usbd_status
@@ -2291,18 +2283,17 @@ ehci_close_pipe(usbd_pipe_handle pipe, ehci_soft_qh_t *head)
        struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
        ehci_softc_t *sc = (ehci_softc_t *)pipe->device->bus;
        ehci_soft_qh_t *sqh = epipe->sqh;
-       int s;
 
-       s = splusb();
+       crit_enter();
        ehci_rem_qh(sc, sqh, head);
-       splx(s);
+       crit_exit();
        ehci_free_sqh(sc, epipe->sqh);
 }
 
 /*
  * Abort a device request.
- * If this routine is called at splusb() it guarantees that the request
- * will be removed from the hardware scheduling and that the callback
+ * If this routine is called from a critical section it guarantees that the
+ * request will be removed from the hardware scheduling and that the callback
  * for it will be called with USBD_CANCELLED status.
  * It's impossible to guarantee that the requested transfer will not
  * have happened since the hardware runs concurrently.
@@ -2320,18 +2311,17 @@ ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
        ehci_soft_qtd_t *sqtd;
        ehci_physaddr_t cur;
        u_int32_t qhstatus;
-       int s;
        int hit;
 
        DPRINTF(("ehci_abort_xfer: xfer=%p pipe=%p\n", xfer, epipe));
 
        if (sc->sc_dying) {
                /* If we're dying, just do the software part. */
-               s = splusb();
+               crit_enter();
                xfer->status = status;  /* make software ignore it */
                usb_uncallout(xfer->timeout_handle, ehci_timeout, xfer);
                usb_transfer_complete(xfer);
-               splx(s);
+               crit_exit();
                return;
        }
 
@@ -2341,7 +2331,7 @@ ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
        /*
         * Step 1: Make interrupt routine and hardware ignore xfer.
         */
-       s = splusb();
+       crit_enter();
        xfer->status = status;  /* make software ignore it */
        usb_uncallout(xfer->timeout_handle, ehci_timeout, xfer);
        qhstatus = sqh->qh.qh_qtd.qtd_status;
@@ -2351,7 +2341,7 @@ ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
                if (sqtd == exfer->sqtdend)
                        break;
        }
-       splx(s);
+       crit_exit();
 
        /*
         * Step 2: Wait until we know hardware has finished any possible
@@ -2359,7 +2349,7 @@ ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
         * has run.
         */
        ehci_sync_hc(sc);
-       s = splusb();
+       crit_enter();
 #ifdef USB_USE_SOFTINTR
        sc->sc_softwake = 1;
 #endif /* USB_USE_SOFTINTR */
@@ -2367,7 +2357,7 @@ ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
 #ifdef USB_USE_SOFTINTR
        tsleep(&sc->sc_softwake, 0, "ehciab", 0);
 #endif /* USB_USE_SOFTINTR */
-       splx(s);
+       crit_exit();
 
        /*
         * Step 3: Remove any vestiges of the xfer from the hardware.
@@ -2376,7 +2366,7 @@ ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
         * the TDs of this xfer we check if the hardware points to
         * any of them.
         */
-       s = splusb();           /* XXX why? */
+       crit_enter();           /* XXX why? */
        cur = EHCI_LINK_ADDR(le32toh(sqh->qh.qh_curqtd));
        hit = 0;
        for (sqtd = exfer->sqtdstart; ; sqtd = sqtd->nextqtd) {
@@ -2402,7 +2392,7 @@ ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
 #endif
        usb_transfer_complete(xfer);
 
-       splx(s);
+       crit_exit();
 #undef exfer
 }
 
@@ -2433,13 +2423,11 @@ void
 ehci_timeout_task(void *addr)
 {
        usbd_xfer_handle xfer = addr;
-       int s;
 
        DPRINTF(("ehci_timeout_task: xfer=%p\n", xfer));
-
-       s = splusb();
+       crit_enter();
        ehci_abort_xfer(xfer, USBD_TIMEOUT);
-       splx(s);
+       crit_exit();
 }
 
 /************************/
@@ -2540,7 +2528,6 @@ ehci_device_request(usbd_xfer_handle xfer)
        int isread;
        int len;
        usbd_status err;
-       int s;
 
        isread = req->bmRequestType & UT_READ;
        len = UGETW(req->wLength);
@@ -2640,7 +2627,7 @@ ehci_device_request(usbd_xfer_handle xfer)
 #endif
 
        /* Insert qTD in QH list. */
-       s = splusb();
+       crit_enter();
        ehci_set_qh_qtd(sqh, setup);
        if (xfer->timeout && !sc->sc_bus.use_polling) {
                 usb_callout(xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
@@ -2648,7 +2635,7 @@ ehci_device_request(usbd_xfer_handle xfer)
        }
        ehci_add_intr_list(sc, exfer);
        xfer->status = USBD_IN_PROGRESS;
-       splx(s);
+       crit_exit();
 
 #ifdef USB_DEBUG
        if (ehcidebug > 10) {
@@ -2703,7 +2690,6 @@ ehci_device_bulk_start(usbd_xfer_handle xfer)
        ehci_soft_qh_t *sqh;
        usbd_status err;
        int len, isread, endpt;
-       int s;
 
        DPRINTFN(2, ("ehci_device_bulk_transfer: xfer=%p len=%d flags=%d\n",
                     xfer, xfer->length, xfer->flags));
@@ -2750,7 +2736,7 @@ ehci_device_bulk_start(usbd_xfer_handle xfer)
        exfer->isdone = 0;
 #endif
 
-       s = splusb();
+       crit_enter();
        ehci_set_qh_qtd(sqh, data);
        if (xfer->timeout && !sc->sc_bus.use_polling) {
                usb_callout(xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
@@ -2758,7 +2744,7 @@ ehci_device_bulk_start(usbd_xfer_handle xfer)
        }
        ehci_add_intr_list(sc, exfer);
        xfer->status = USBD_IN_PROGRESS;
-       splx(s);
+       crit_exit();
 
 #ifdef USB_DEBUG
        if (ehcidebug > 10) {
index 6e3d458..fcc2565 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $NetBSD: ohci.c,v 1.138 2003/02/08 03:32:50 ichiro Exp $
  * $FreeBSD: src/sys/dev/usb/ohci.c,v 1.141 2003/12/22 15:40:10 shiba Exp $
- * $DragonFly: src/sys/bus/usb/ohci.c,v 1.9 2004/07/08 03:25:00 dillon Exp $
+ * $DragonFly: src/sys/bus/usb/ohci.c,v 1.10 2005/06/02 20:40:40 dillon Exp $
  */
 /* Also, already ported:
  *     $NetBSD: ohci.c,v 1.140 2003/05/13 04:42:00 gson Exp $
@@ -76,6 +76,8 @@
 #include <sys/queue.h>
 #include <sys/sysctl.h>
 
+#include <sys/thread2.h>
+
 #include <machine/bus.h>
 #include <machine/endian.h>
 
@@ -448,7 +450,6 @@ ohci_alloc_std(ohci_softc_t *sc)
        usbd_status err;
        int i, offs;
        usb_dma_t dma;
-       int s;
 
        if (sc->sc_freetds == NULL) {
                DPRINTFN(2, ("ohci_alloc_std: allocating chunk\n"));
@@ -456,7 +457,7 @@ ohci_alloc_std(ohci_softc_t *sc)
                          OHCI_TD_ALIGN, &dma);
                if (err)
                        return (NULL);
-               s = splusb();
+               crit_enter();
                for(i = 0; i < OHCI_STD_CHUNK; i++) {
                        offs = i * OHCI_STD_SIZE;
                        std = KERNADDR(&dma, offs);
@@ -464,17 +465,17 @@ ohci_alloc_std(ohci_softc_t *sc)
                        std->nexttd = sc->sc_freetds;
                        sc->sc_freetds = std;
                }
-               splx(s);
+               crit_exit();
        }
 
-       s = splusb();
+       crit_enter();
        std = sc->sc_freetds;
        sc->sc_freetds = std->nexttd;
        memset(&std->td, 0, sizeof(ohci_td_t));
        std->nexttd = NULL;
        std->xfer = NULL;
        ohci_hash_add_td(sc, std);
-       splx(s);
+       crit_exit();
 
        return (std);
 }
@@ -482,13 +483,11 @@ ohci_alloc_std(ohci_softc_t *sc)
 void
 ohci_free_std(ohci_softc_t *sc, ohci_soft_td_t *std)
 {
-       int s;
-
-       s = splusb();
+       crit_enter();
        ohci_hash_rem_td(sc, std);
        std->nexttd = sc->sc_freetds;
        sc->sc_freetds = std;
-       splx(s);
+       crit_exit();
 }
 
 usbd_status
@@ -635,7 +634,7 @@ ohci_alloc_sitd(ohci_softc_t *sc)
 {
        ohci_soft_itd_t *sitd;
        usbd_status err;
-       int i, s, offs;
+       int i, offs;
        usb_dma_t dma;
 
        if (sc->sc_freeitds == NULL) {
@@ -644,7 +643,7 @@ ohci_alloc_sitd(ohci_softc_t *sc)
                          OHCI_ITD_ALIGN, &dma);
                if (err)
                        return (NULL);
-               s = splusb();
+               crit_enter();
                for(i = 0; i < OHCI_SITD_CHUNK; i++) {
                        offs = i * OHCI_SITD_SIZE;
                        sitd = KERNADDR(&dma, offs);
@@ -652,17 +651,17 @@ ohci_alloc_sitd(ohci_softc_t *sc)
                        sitd->nextitd = sc->sc_freeitds;
                        sc->sc_freeitds = sitd;
                }
-               splx(s);
+               crit_exit();
        }
 
-       s = splusb();
+       crit_enter();
        sitd = sc->sc_freeitds;
        sc->sc_freeitds = sitd->nextitd;
        memset(&sitd->itd, 0, sizeof(ohci_itd_t));
        sitd->nextitd = NULL;
        sitd->xfer = NULL;
        ohci_hash_add_itd(sc, sitd);
-       splx(s);
+       crit_exit();
 
 #ifdef DIAGNOSTIC
        sitd->isdone = 0;
@@ -674,8 +673,6 @@ ohci_alloc_sitd(ohci_softc_t *sc)
 void
 ohci_free_sitd(ohci_softc_t *sc, ohci_soft_itd_t *sitd)
 {
-       int s;
-
        DPRINTFN(10,("ohci_free_sitd: sitd=%p\n", sitd));
 
 #ifdef DIAGNOSTIC
@@ -687,11 +684,11 @@ ohci_free_sitd(ohci_softc_t *sc, ohci_soft_itd_t *sitd)
        sitd->isdone = 0;
 #endif
 
-       s = splusb();
+       crit_enter();
        ohci_hash_rem_itd(sc, sitd);
        sitd->nextitd = sc->sc_freeitds;
        sc->sc_freeitds = sitd;
-       splx(s);
+       crit_exit();
 }
 
 usbd_status
@@ -1039,14 +1036,13 @@ ohci_power(int why, void *v)
 {
        ohci_softc_t *sc = v;
        u_int32_t ctl;
-       int s;
 
 #ifdef USB_DEBUG
        DPRINTF(("ohci_power: sc=%p, why=%d\n", sc, why));
        ohci_dumpregs(sc);
 #endif
 
-       s = splhardusb();
+       crit_enter();
        if (why != PWR_RESUME) {
                sc->sc_bus.use_polling++;
                ctl = OREAD4(sc, OHCI_CONTROL) & ~OHCI_HCFS_MASK;
@@ -1084,7 +1080,7 @@ ohci_power(int why, void *v)
                sc->sc_control = sc->sc_intre = 0;
                sc->sc_bus.use_polling--;
        }
-       splx(s);
+       crit_exit();
 }
 
 #ifdef USB_DEBUG
@@ -1272,11 +1268,10 @@ void
 ohci_rhsc_enable(void *v_sc)
 {
        ohci_softc_t *sc = v_sc;
-       int s;
 
-       s = splhardusb();
+       crit_enter();
        ohci_rhsc_able(sc, 1);
-       splx(s);
+       crit_exit();
 }
 
 #ifdef USB_DEBUG
@@ -1345,18 +1340,18 @@ ohci_softintr(void *v)
        ohci_soft_td_t  *std,  *sdone,  *stdnext;
        usbd_xfer_handle xfer;
        struct ohci_pipe *opipe;
-       int len, cc, s;
+       int len, cc;
 
        DPRINTFN(10,("ohci_softintr: enter\n"));
 
        sc->sc_bus.intr_context++;
 
-       s = splhardusb();
+       crit_enter();
        sdone = sc->sc_sdone;
        sc->sc_sdone = NULL;
        sidone = sc->sc_sidone;
        sc->sc_sidone = NULL;
-       splx(s);
+       crit_exit();
 
        DPRINTFN(10,("ohci_softintr: sdone=%p sidone=%p\n", sdone, sidone));
 
@@ -1405,9 +1400,9 @@ ohci_softintr(void *v)
                if (cc == OHCI_CC_NO_ERROR) {
                        if (std->flags & OHCI_CALL_DONE) {
                                xfer->status = USBD_NORMAL_COMPLETION;
-                               s = splusb();
+                               crit_enter();
                                usb_transfer_complete(xfer);
-                               splx(s);
+                               crit_exit();
                        }
                        ohci_free_std(sc, std);
                } else {
@@ -1446,9 +1441,9 @@ ohci_softintr(void *v)
                                xfer->status = USBD_STALLED;
                        else
                                xfer->status = USBD_IOERROR;
-                       s = splusb();
+                       crit_enter();
                        usb_transfer_complete(xfer);
-                       splx(s);
+                       crit_exit();
                }
        }
 
@@ -1494,16 +1489,16 @@ ohci_softintr(void *v)
                                /* XXX update frlengths with actual length */
                                /* XXX xfer->actlen = actlen; */
                                xfer->status = USBD_NORMAL_COMPLETION;
-                               s = splusb();
+                               crit_enter();
                                usb_transfer_complete(xfer);
-                               splx(s);
+                               crit_exit();
                        }
                } else {
                        /* XXX Do more */
                        xfer->status = USBD_IOERROR;
-                       s = splusb();
+                       crit_enter();
                        usb_transfer_complete(xfer);
-                       splx(s);
+                       crit_exit();
                }
        }
 
@@ -1698,7 +1693,6 @@ ohci_device_request(usbd_xfer_handle xfer)
        int isread;
        int len;
        usbd_status err;
-       int s;
 
        isread = req->bmRequestType & UT_READ;
        len = UGETW(req->wLength);
@@ -1783,7 +1777,7 @@ ohci_device_request(usbd_xfer_handle xfer)
 #endif
 
        /* Insert ED in schedule */
-       s = splusb();
+       crit_enter();
        sed->ed.ed_tailp = htole32(tail->physaddr);
        opipe->tail.td = tail;
        OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_CLF);
@@ -1791,7 +1785,7 @@ ohci_device_request(usbd_xfer_handle xfer)
                usb_callout(xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
                            ohci_timeout, xfer);
        }
-       splx(s);
+       crit_exit();
 
 #ifdef USB_DEBUG
        if (ohcidebug > 20) {
@@ -1818,14 +1812,13 @@ ohci_device_request(usbd_xfer_handle xfer)
 }
 
 /*
- * Add an ED to the schedule.  Called at splusb().
+ * Add an ED to the schedule.  Called from a critical section.
  */
 void
 ohci_add_ed(ohci_soft_ed_t *sed, ohci_soft_ed_t *head)
 {
        DPRINTFN(8,("ohci_add_ed: sed=%p head=%p\n", sed, head));
 
-       SPLUSBCHECK;
        sed->next = head->next;
        sed->ed.ed_nexted = head->ed.ed_nexted;
        head->next = sed;
@@ -1833,14 +1826,13 @@ ohci_add_ed(ohci_soft_ed_t *sed, ohci_soft_ed_t *head)
 }
 
 /*
- * Remove an ED from the schedule.  Called at splusb().
+ * Remove an ED from the schedule.  Called from a critical section.
  */
 void
 ohci_rem_ed(ohci_soft_ed_t *sed, ohci_soft_ed_t *head)
 {
        ohci_soft_ed_t *p;
 
-       SPLUSBCHECK;
 
        /* XXX */
        for (p = head; p != NULL && p->next != sed; p = p->next)
@@ -1862,23 +1854,23 @@ ohci_rem_ed(ohci_soft_ed_t *sed, ohci_soft_ed_t *head)
  */
 
 #define HASH(a) (((a) >> 4) % OHCI_HASH_SIZE)
-/* Called at splusb() */
+/*
+ * Called from a critical section 
+ */
 void
 ohci_hash_add_td(ohci_softc_t *sc, ohci_soft_td_t *std)
 {
        int h = HASH(std->physaddr);
 
-       SPLUSBCHECK;
-
        LIST_INSERT_HEAD(&sc->sc_hash_tds[h], std, hnext);
 }
 
-/* Called at splusb() */
+/*
+ * Called from a critical section 
+ */
 void
 ohci_hash_rem_td(ohci_softc_t *sc, ohci_soft_td_t *std)
 {
-       SPLUSBCHECK;
-
        LIST_REMOVE(std, hnext);
 }
 
@@ -1906,26 +1898,26 @@ ohci_hash_find_td(ohci_softc_t *sc, ohci_physaddr_t a)
        return (NULL);
 }
 
-/* Called at splusb() */
+/*
+ * Called from a critical section 
+ */
 void
 ohci_hash_add_itd(ohci_softc_t *sc, ohci_soft_itd_t *sitd)
 {
        int h = HASH(sitd->physaddr);
 
-       SPLUSBCHECK;
-
        DPRINTFN(10,("ohci_hash_add_itd: sitd=%p physaddr=0x%08lx\n",
                    sitd, (u_long)sitd->physaddr));
 
        LIST_INSERT_HEAD(&sc->sc_hash_itds[h], sitd, hnext);
 }
 
-/* Called at splusb() */
+/*
+ * Called from a critical section 
+ */
 void
 ohci_hash_rem_itd(ohci_softc_t *sc, ohci_soft_itd_t *sitd)
 {
-       SPLUSBCHECK;
-
        DPRINTFN(10,("ohci_hash_rem_itd: sitd=%p physaddr=0x%08lx\n",
                    sitd, (u_long)sitd->physaddr));
 
@@ -1969,13 +1961,12 @@ void
 ohci_timeout_task(void *addr)
 {
        usbd_xfer_handle xfer = addr;
-       int s;
 
        DPRINTF(("ohci_timeout_task: xfer=%p\n", xfer));
 
-       s = splusb();
+       crit_enter();
        ohci_abort_xfer(xfer, USBD_TIMEOUT);
-       splx(s);
+       crit_exit();
 }
 
 #ifdef USB_DEBUG
@@ -2072,7 +2063,6 @@ ohci_open(usbd_pipe_handle pipe)
        ohci_physaddr_t tdphys;
        u_int32_t fmt;
        usbd_status err;
-       int s;
        int ival;
 
        DPRINTFN(1, ("ohci_open: pipe=%p, addr=%d, endpt=%d (%d)\n",
@@ -2136,9 +2126,9 @@ ohci_open(usbd_pipe_handle pipe)
                                  0, &opipe->u.ctl.reqdma);
                        if (err)
                                goto bad;
-                       s = splusb();
+                       crit_enter();
                        ohci_add_ed(sed, sc->sc_ctrl_head);
-                       splx(s);
+                       crit_exit();
                        break;
                case UE_INTERRUPT:
                        pipe->methods = &ohci_device_intr_methods;
@@ -2151,9 +2141,9 @@ ohci_open(usbd_pipe_handle pipe)
                        return (ohci_setup_isoc(pipe));
                case UE_BULK:
                        pipe->methods = &ohci_device_bulk_methods;
-                       s = splusb();
+                       crit_enter();
                        ohci_add_ed(sed, sc->sc_bulk_head);
-                       splx(s);
+                       crit_exit();
                        break;
                }
        }
@@ -2180,9 +2170,8 @@ ohci_close_pipe(usbd_pipe_handle pipe, ohci_soft_ed_t *head)
        struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
        ohci_softc_t *sc = (ohci_softc_t *)pipe->device->bus;
        ohci_soft_ed_t *sed = opipe->sed;
-       int s;
 
-       s = splusb();
+       crit_enter();
 #ifdef DIAGNOSTIC
        sed->ed.ed_flags |= htole32(OHCI_ED_SKIP);
        if ((le32toh(sed->ed.ed_tailp) & OHCI_HEADMASK) !=
@@ -2211,15 +2200,15 @@ ohci_close_pipe(usbd_pipe_handle pipe, ohci_soft_ed_t *head)
        ohci_rem_ed(sed, head);
        /* Make sure the host controller is not touching this ED */
        usb_delay_ms(&sc->sc_bus, 1);
-       splx(s);
+       crit_exit();
        ohci_free_sed(sc, opipe->sed);
 }
 
 /*
  * Abort a device request.
- * If this routine is called at splusb() it guarantees that the request
- * will be removed from the hardware scheduling and that the callback
- * for it will be called with USBD_CANCELLED status.
+ * If this routine is called from a critical section it guarantees that
+ * the request will be removed from the hardware scheduling and that 
+ * the callback for it will be called with USBD_CANCELLED status.
  * It's impossible to guarantee that the requested transfer will not
  * have happened since the hardware runs concurrently.
  * If the transaction has already happened we rely on the ordinary
@@ -2233,17 +2222,17 @@ ohci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
        ohci_soft_ed_t *sed = opipe->sed;
        ohci_soft_td_t *p, *n;
        ohci_physaddr_t headp;
-       int s, hit;
+       int hit;
 
        DPRINTF(("ohci_abort_xfer: xfer=%p pipe=%p sed=%p\n", xfer, opipe,sed));
 
        if (sc->sc_dying) {
                /* If we're dying, just do the software part. */
-               s = splusb();
+               crit_enter();
                xfer->status = status;  /* make software ignore it */
                usb_uncallout(xfer->timeout_handle, ohci_timeout, xfer);
                usb_transfer_complete(xfer);
-               splx(s);
+               crit_exit();
        }
 
        if (xfer->device->bus->intr_context /* || !curproc REMOVED DFly */)
@@ -2252,10 +2241,10 @@ ohci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
        /*
         * Step 1: Make interrupt routine and hardware ignore xfer.
         */
-       s = splusb();
+       crit_enter();
        xfer->status = status;  /* make software ignore it */
        usb_uncallout(xfer->timeout_handle, ohci_timeout, xfer);
-       splx(s);
+       crit_exit();
        DPRINTFN(1,("ohci_abort_xfer: stop ed=%p\n", sed));
        sed->ed.ed_flags |= htole32(OHCI_ED_SKIP); /* force hardware skip */
 
@@ -2265,7 +2254,7 @@ ohci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
         * has run.
         */
        usb_delay_ms(opipe->pipe.device->bus, 20); /* Hardware finishes in 1ms */
-       s = splusb();
+       crit_enter();
 #ifdef USB_USE_SOFTINTR
        sc->sc_softwake = 1;
 #endif /* USB_USE_SOFTINTR */
@@ -2273,7 +2262,7 @@ ohci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
 #ifdef USB_USE_SOFTINTR
        tsleep(&sc->sc_softwake, 0, "ohciab", 0);
 #endif /* USB_USE_SOFTINTR */
-       splx(s);
+       crit_exit();
 
        /*
         * Step 3: Remove any vestiges of the xfer from the hardware.
@@ -2282,11 +2271,11 @@ ohci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
         * the TDs of this xfer we check if the hardware points to
         * any of them.
         */
-       s = splusb();           /* XXX why? */
+       crit_enter();
        p = xfer->hcpriv;
 #ifdef DIAGNOSTIC
        if (p == NULL) {
-               splx(s);
+               crit_exit();
                printf("ohci_abort_xfer: hcpriv is NULL\n");
                return;
        }
@@ -2324,7 +2313,7 @@ ohci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
         */
        usb_transfer_complete(xfer);
 
-       splx(s);
+       crit_exit();
 }
 
 /*
@@ -2428,7 +2417,7 @@ ohci_root_ctrl_start(usbd_xfer_handle xfer)
        usb_device_request_t *req;
        void *buf = NULL;
        int port, i;
-       int s, len, value, index, l, totlen = 0;
+       int len, value, index, l, totlen = 0;
        usb_port_status_t ps;
        usb_hub_descriptor_t hubd;
        usbd_status err;
@@ -2722,9 +2711,9 @@ ohci_root_ctrl_start(usbd_xfer_handle xfer)
        err = USBD_NORMAL_COMPLETION;
  ret:
        xfer->status = err;
-       s = splusb();
+       crit_enter();
        usb_transfer_complete(xfer);
-       splx(s);
+       crit_exit();
        return (USBD_IN_PROGRESS);
 }
 
@@ -2775,16 +2764,14 @@ ohci_root_intr_start(usbd_xfer_handle xfer)
 Static void
 ohci_root_intr_abort(usbd_xfer_handle xfer)
 {
-       int s;
-
        if (xfer->pipe->intrxfer == xfer) {
                DPRINTF(("ohci_root_intr_abort: remove\n"));
                xfer->pipe->intrxfer = NULL;
        }
        xfer->status = USBD_CANCELLED;
-       s = splusb();
+       crit_enter();
        usb_transfer_complete(xfer);
-       splx(s);
+       crit_exit();
 }
 
 /* Close the root pipe. */
@@ -2898,7 +2885,7 @@ ohci_device_bulk_start(usbd_xfer_handle xfer)
        int addr = dev->address;
        ohci_soft_td_t *data, *tail, *tdp;
        ohci_soft_ed_t *sed;
-       int s, len, isread, endpt;
+       int len, isread, endpt;
        usbd_status err;
 
        if (sc->sc_dying)
@@ -2959,7 +2946,7 @@ ohci_device_bulk_start(usbd_xfer_handle xfer)
 #endif
 
        /* Insert ED in schedule */
-       s = splusb();
+       crit_enter();
        for (tdp = data; tdp != tail; tdp = tdp->nexttd) {
                tdp->xfer = xfer;
        }
@@ -2983,7 +2970,7 @@ ohci_device_bulk_start(usbd_xfer_handle xfer)
        }
 #endif
 
-       splx(s);
+       crit_exit();
 
        return (USBD_IN_PROGRESS);
 }
@@ -3034,7 +3021,6 @@ ohci_device_intr_start(usbd_xfer_handle xfer)
        ohci_soft_ed_t *sed = opipe->sed;
        ohci_soft_td_t *data, *tail;
        int len;
-       int s;
 
        if (sc->sc_dying)
                return (USBD_IOERROR);
@@ -3079,7 +3065,7 @@ ohci_device_intr_start(usbd_xfer_handle xfer)
 #endif
 
        /* Insert ED in schedule */
-       s = splusb();
+       crit_enter();
        sed->ed.ed_tailp = htole32(tail->physaddr);
        opipe->tail.td = tail;
        sed->ed.ed_flags &= htole32(~OHCI_ED_SKIP);
@@ -3098,7 +3084,7 @@ ohci_device_intr_start(usbd_xfer_handle xfer)
                ohci_dump_tds(data);
        }
 #endif
-       splx(s);
+       crit_exit();
 
        return (USBD_IN_PROGRESS);
 }
@@ -3124,11 +3110,10 @@ ohci_device_intr_close(usbd_pipe_handle pipe)
        int pos = opipe->u.intr.pos;
        int j;
        ohci_soft_ed_t *p, *sed = opipe->sed;
-       int s;
 
        DPRINTFN(1,("ohci_device_intr_close: pipe=%p nslots=%d pos=%d\n",
                    pipe, nslots, pos));
-       s = splusb();
+       crit_enter();
        sed->ed.ed_flags |= htole32(OHCI_ED_SKIP);
        if ((le32toh(sed->ed.ed_tailp) & OHCI_HEADMASK) !=
            (le32toh(sed->ed.ed_headp) & OHCI_HEADMASK))
@@ -3148,7 +3133,7 @@ ohci_device_intr_close(usbd_pipe_handle pipe)
 #endif
        p->next = sed->next;
        p->ed.ed_nexted = sed->ed.ed_nexted;
-       splx(s);
+       crit_exit();
 
        for (j = 0; j < nslots; j++)
                --sc->sc_bws[(pos * nslots + j) % OHCI_NO_INTRS];
@@ -3160,7 +3145,7 @@ ohci_device_intr_close(usbd_pipe_handle pipe)
 Static usbd_status
 ohci_device_setintr(ohci_softc_t *sc, struct ohci_pipe *opipe, int ival)
 {
-       int i, j, s, best;
+       int i, j, best;
        u_int npoll, slow, shigh, nslots;
        u_int bestbw, bw;
        ohci_soft_ed_t *hsed, *sed = opipe->sed;
@@ -3202,13 +3187,13 @@ ohci_device_setintr(ohci_softc_t *sc, struct ohci_pipe *opipe, int ival)
        DPRINTFN(2, ("ohci_setintr: best=%d(%d..%d) bestbw=%d\n",
                     best, slow, shigh, bestbw));
 
-       s = splusb();
+       crit_enter();
        hsed = sc->sc_eds[best];
        sed->next = hsed->next;
        sed->ed.ed_nexted = hsed->ed.ed_nexted;
        hsed->next = sed;
        hsed->ed.ed_nexted = htole32(sed->physaddr);
-       splx(s);
+       crit_exit();
 
        for (j = 0; j < nslots; j++)
                ++sc->sc_bws[(best * nslots + j) % OHCI_NO_INTRS];
@@ -3259,7 +3244,6 @@ ohci_device_isoc_enter(usbd_xfer_handle xfer)
        ohci_soft_itd_t *sitd, *nsitd;
        ohci_physaddr_t buf, offs, noffs, bp0, tdphys;
        int i, ncur, nframes;
-       int s;
 
        DPRINTFN(1,("ohci_device_isoc_enter: used=%d next=%d xfer=%p "
                    "nframes=%d\n",
@@ -3372,11 +3356,11 @@ ohci_device_isoc_enter(usbd_xfer_handle xfer)
        }
 #endif
 
-       s = splusb();
+       crit_enter();
        sed->ed.ed_tailp = htole32(nsitd->physaddr);
        opipe->tail.itd = nsitd;
        sed->ed.ed_flags &= htole32(~OHCI_ED_SKIP);
-       splx(s);
+       crit_exit();
 
 #ifdef USB_DEBUG
        if (ohcidebug > 5) {
@@ -3395,7 +3379,6 @@ ohci_device_isoc_start(usbd_xfer_handle xfer)
        struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->pipe;
        ohci_softc_t *sc = (ohci_softc_t *)opipe->pipe.device->bus;
        ohci_soft_ed_t *sed;
-       int s;
 
        DPRINTFN(5,("ohci_device_isoc_start: xfer=%p\n", xfer));
 
@@ -3409,10 +3392,10 @@ ohci_device_isoc_start(usbd_xfer_handle xfer)
 
        /* XXX anything to do? */
 
-       s = splusb();
+       crit_enter();
        sed = opipe->sed;  /*  Turn off ED skip-bit to start processing */
        sed->ed.ed_flags &= htole32(~OHCI_ED_SKIP);    /* ED's ITD list.*/
-       splx(s);
+       crit_exit();
 
        return (USBD_IN_PROGRESS);
 }
@@ -3424,9 +3407,9 @@ ohci_device_isoc_abort(usbd_xfer_handle xfer)
        ohci_softc_t *sc = (ohci_softc_t *)opipe->pipe.device->bus;
        ohci_soft_ed_t *sed;
        ohci_soft_itd_t *sitd, *tmp_sitd;
-       int s,undone,num_sitds;
+       int undone,num_sitds;
 
-       s = splusb();
+       crit_enter();
        opipe->aborting = 1;
 
        DPRINTFN(1,("ohci_device_isoc_abort: xfer=%p\n", xfer));
@@ -3434,7 +3417,7 @@ ohci_device_isoc_abort(usbd_xfer_handle xfer)
        /* Transfer is already done. */
        if (xfer->status != USBD_NOT_STARTED &&
            xfer->status != USBD_IN_PROGRESS) {
-               splx(s);
+               crit_exit();
                printf("ohci_device_isoc_abort: early return\n");
                return;
        }
@@ -3449,7 +3432,7 @@ ohci_device_isoc_abort(usbd_xfer_handle xfer)
        sitd = xfer->hcpriv;
 #ifdef DIAGNOSTIC
        if (sitd == NULL) {
-               splx(s);
+               crit_exit();
                printf("ohci_device_isoc_abort: hcpriv==0\n");
                return;
        }
@@ -3462,7 +3445,7 @@ ohci_device_isoc_abort(usbd_xfer_handle xfer)
 #endif
        }
 
-       splx(s);
+       crit_exit();
 
        /*
         * Each sitd has up to OHCI_ITD_NOFFSET transfers, each can
@@ -3486,8 +3469,7 @@ ohci_device_isoc_abort(usbd_xfer_handle xfer)
                }
        } while( undone != 0 );
 
-
-       s = splusb();
+       crit_enter();
 
        /* Run callback. */
        usb_transfer_complete(xfer);
@@ -3503,7 +3485,7 @@ ohci_device_isoc_abort(usbd_xfer_handle xfer)
 
        sed->ed.ed_flags &= htole32(~OHCI_ED_SKIP); /* remove hardware skip */
 
-       splx(s);
+       crit_exit();
 }
 
 void
@@ -3534,14 +3516,13 @@ ohci_setup_isoc(usbd_pipe_handle pipe)
        struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
        ohci_softc_t *sc = (ohci_softc_t *)pipe->device->bus;
        struct iso *iso = &opipe->u.iso;
-       int s;
 
        iso->next = -1;
        iso->inuse = 0;
 
-       s = splusb();
+       crit_enter();
        ohci_add_ed(opipe->sed, sc->sc_isoc_head);
-       splx(s);
+       crit_exit();
 
        return (USBD_NORMAL_COMPLETION);
 }
index bb885fd..6d2f280 100644 (file)
@@ -2,7 +2,7 @@
  * $NetBSD: uhci.c,v 1.80 2000/01/19 01:16:38 augustss Exp $
  * $NetBSD: uhci.c,v 1.170 2003/02/19 01:35:04 augustss Exp $
  * $FreeBSD: src/sys/dev/usb/uhci.c,v 1.149 2003/11/10 00:08:41 joe Exp $
- * $DragonFly: src/sys/bus/usb/uhci.c,v 1.11 2004/12/05 04:24:42 drhodus Exp $
+ * $DragonFly: src/sys/bus/usb/uhci.c,v 1.12 2005/06/02 20:40:40 dillon Exp $
  */
 
 /*     Also already incorporated from NetBSD:
@@ -79,6 +79,7 @@
 #include <sys/proc.h>
 #include <sys/queue.h>
 #include <sys/sysctl.h>
+#include <sys/thread2.h>
 
 #include <machine/bus.h>
 #include <machine/endian.h>
@@ -690,9 +691,8 @@ uhci_power(int why, void *v)
 {
        uhci_softc_t *sc = v;
        int cmd;
-       int s;
 
-       s = splhardusb();
+       crit_enter();
        cmd = UREAD2(sc, UHCI_CMD);
 
        DPRINTF(("uhci_power: sc=%p, why=%d (was %d), cmd=0x%x\n",
@@ -752,7 +752,7 @@ uhci_power(int why, void *v)
                        uhci_dumpregs(sc);
 #endif
        }
-       splx(s);
+       crit_exit();
 }
 
 #ifdef USB_DEBUG
@@ -952,7 +952,6 @@ uhci_poll_hub(void *addr)
        usbd_xfer_handle xfer = addr;
        usbd_pipe_handle pipe = xfer->pipe;
        uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
-       int s;
        u_char *p;
 
        DPRINTFN(20, ("uhci_poll_hub\n"));
@@ -971,11 +970,11 @@ uhci_poll_hub(void *addr)
 
        xfer->actlen = 1;
        xfer->status = USBD_NORMAL_COMPLETION;
-       s = splusb();
+       crit_enter();
        xfer->device->bus->intr_context++;
        usb_transfer_complete(xfer);
        xfer->device->bus->intr_context--;
-       splx(s);
+       crit_exit();
 }
 
 void
@@ -1020,14 +1019,12 @@ uhci_rem_loop(uhci_softc_t *sc) {
        }
 }
 
-/* Add high speed control QH, called at splusb(). */
+/* Add high speed control QH, called from a critical section. */
 void
 uhci_add_hs_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
 {
        uhci_soft_qh_t *eqh;
 
-       SPLUSBCHECK;
-
        DPRINTFN(10, ("uhci_add_ctrl: sqh=%p\n", sqh));
        eqh = sc->sc_hctl_end;
        sqh->hlink       = eqh->hlink;
@@ -1040,14 +1037,12 @@ uhci_add_hs_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
 #endif
 }
 
-/* Remove high speed control QH, called at splusb(). */
+/* Remove high speed control QH, called from a critical section. */
 void
 uhci_remove_hs_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
 {
        uhci_soft_qh_t *pqh;
 
-       SPLUSBCHECK;
-
        DPRINTFN(10, ("uhci_remove_hs_ctrl: sqh=%p\n", sqh));
 #ifdef UHCI_CTL_LOOP
        uhci_rem_loop(sc);
@@ -1073,14 +1068,12 @@ uhci_remove_hs_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
                sc->sc_hctl_end = pqh;
 }
 
-/* Add low speed control QH, called at splusb(). */
+/* Add low speed control QH, called from a critical section. */
 void
 uhci_add_ls_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
 {
        uhci_soft_qh_t *eqh;
 
-       SPLUSBCHECK;
-
        DPRINTFN(10, ("uhci_add_ls_ctrl: sqh=%p\n", sqh));
        eqh = sc->sc_lctl_end;
        sqh->hlink = eqh->hlink;
@@ -1090,14 +1083,12 @@ uhci_add_ls_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
        sc->sc_lctl_end = sqh;
 }
 
-/* Remove low speed control QH, called at splusb(). */
+/* Remove low speed control QH, called from a critical section. */
 void
 uhci_remove_ls_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
 {
        uhci_soft_qh_t *pqh;
 
-       SPLUSBCHECK;
-
        DPRINTFN(10, ("uhci_remove_ls_ctrl: sqh=%p\n", sqh));
        /* See comment in uhci_remove_hs_ctrl() */
        if (!(sqh->qh.qh_elink & htole32(UHCI_PTR_T))) {
@@ -1112,14 +1103,12 @@ uhci_remove_ls_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
                sc->sc_lctl_end = pqh;
 }
 
-/* Add bulk QH, called at splusb(). */
+/* Add bulk QH, called from a critical section. */
 void
 uhci_add_bulk(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
 {
        uhci_soft_qh_t *eqh;
 
-       SPLUSBCHECK;
-
        DPRINTFN(10, ("uhci_add_bulk: sqh=%p\n", sqh));
        eqh = sc->sc_bulk_end;
        sqh->hlink = eqh->hlink;
@@ -1130,14 +1119,12 @@ uhci_add_bulk(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
        uhci_add_loop(sc);
 }
 
-/* Remove bulk QH, called at splusb(). */
+/* Remove bulk QH, called from a critical section. */
 void
 uhci_remove_bulk(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
 {
        uhci_soft_qh_t *pqh;
 
-       SPLUSBCHECK;
-
        DPRINTFN(10, ("uhci_remove_bulk: sqh=%p\n", sqh));
        uhci_rem_loop(sc);
        /* See comment in uhci_remove_hs_ctrl() */
@@ -1358,7 +1345,7 @@ done:
        uhci_idone(ii);
 }
 
-/* Called at splusb() */
+/* Called from a critical section. */
 void
 uhci_idone(uhci_intr_info_t *ii)
 {
@@ -1371,9 +1358,9 @@ uhci_idone(uhci_intr_info_t *ii)
        DPRINTFN(12, ("uhci_idone: ii=%p\n", ii));
 #ifdef DIAGNOSTIC
        {
-               int s = splhigh();
+               crit_enter();
                if (ii->isdone) {
-                       splx(s);
+                       crit_exit();
 #ifdef USB_DEBUG
                        printf("uhci_idone: ii is done!\n   ");
                        uhci_dump_ii(ii);
@@ -1383,7 +1370,7 @@ uhci_idone(uhci_intr_info_t *ii)
                        return;
                }
                ii->isdone = 1;
-               splx(s);
+               crit_exit();
        }
 #endif
 
@@ -1511,13 +1498,12 @@ void
 uhci_timeout_task(void *addr)
 {
        usbd_xfer_handle xfer = addr;
-       int s;
 
        DPRINTF(("uhci_timeout_task: xfer=%p\n", xfer));
 
-       s = splusb();
+       crit_enter();
        uhci_abort_xfer(xfer, USBD_TIMEOUT);
-       splx(s);
+       crit_exit();
 }
 
 /*
@@ -1584,11 +1570,11 @@ uhci_reset(uhci_softc_t *sc)
 usbd_status
 uhci_run(uhci_softc_t *sc, int run)
 {
-       int s, n, running;
+       int n, running;
        u_int16_t cmd;
 
        run = run != 0;
-       s = splhardusb();
+       crit_enter();
        DPRINTF(("uhci_run: setting run=%d\n", run));
        cmd = UREAD2(sc, UHCI_CMD);
        if (run)
@@ -1600,14 +1586,14 @@ uhci_run(uhci_softc_t *sc, int run)
                running = !(UREAD2(sc, UHCI_STS) & UHCI_STS_HCH);
                /* return when we've entered the state we want */
                if (run == running) {
-                       splx(s);
+                       crit_exit();
                        DPRINTF(("uhci_run: done cmd=0x%x sts=0x%x\n",
                                 UREAD2(sc, UHCI_CMD), UREAD2(sc, UHCI_STS)));
                        return (USBD_NORMAL_COMPLETION);
                }
                usb_delay_ms(&sc->sc_bus, 1);
        }
-       splx(s);
+       crit_exit();
        printf("%s: cannot %s\n", USBDEVNAME(sc->sc_bus.bdev),
               run ? "start" : "stop");
        return (USBD_IOERROR);
@@ -1825,7 +1811,6 @@ uhci_device_bulk_start(usbd_xfer_handle xfer)
        uhci_soft_qh_t *sqh;
        usbd_status err;
        int len, isread, endpt;
-       int s;
 
        DPRINTFN(3, ("uhci_device_bulk_start: xfer=%p len=%d flags=%d ii=%p\n",
                     xfer, xfer->length, xfer->flags, ii));
@@ -1873,7 +1858,7 @@ uhci_device_bulk_start(usbd_xfer_handle xfer)
        sqh->elink = data;
        sqh->qh.qh_elink = htole32(data->physaddr | UHCI_PTR_TD);
 
-       s = splusb();
+       crit_enter();
        uhci_add_bulk(sc, sqh);
        uhci_add_intr_info(sc, ii);
 
@@ -1882,7 +1867,7 @@ uhci_device_bulk_start(usbd_xfer_handle xfer)
                            uhci_timeout, ii);
        }
        xfer->status = USBD_IN_PROGRESS;
-       splx(s);
+       crit_exit();
 
 #ifdef USB_DEBUG
        if (uhcidebug > 10) {
@@ -1907,9 +1892,9 @@ uhci_device_bulk_abort(usbd_xfer_handle xfer)
 
 /*
  * Abort a device request.
- * If this routine is called at splusb() it guarantees that the request
- * will be removed from the hardware scheduling and that the callback
- * for it will be called with USBD_CANCELLED status.
+ * If this routine is called from a critical section.  It guarentees that
+ * the request will be removed from the hardware scheduling and that 
+ * the callback for it will be called with USBD_CANCELLED status.
  * It's impossible to guarantee that the requested transfer will not
  * have happened since the hardware runs concurrently.
  * If the transaction has already happened we rely on the ordinary
@@ -1922,17 +1907,16 @@ uhci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
        struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
        uhci_softc_t *sc = (uhci_softc_t *)upipe->pipe.device->bus;
        uhci_soft_td_t *std;
-       int s;
 
        DPRINTFN(1,("uhci_abort_xfer: xfer=%p, status=%d\n", xfer, status));
 
        if (sc->sc_dying) {
                /* If we're dying, just do the software part. */
-               s = splusb();
+               crit_enter();
                xfer->status = status;  /* make software ignore it */
                usb_uncallout(xfer->timeout_handle, uhci_timeout, xfer);
                usb_transfer_complete(xfer);
-               splx(s);
+               crit_exit();
                return;
        }
 
@@ -1942,13 +1926,13 @@ uhci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
        /*
         * Step 1: Make interrupt routine and hardware ignore xfer.
         */
-       s = splusb();
+       crit_enter();
        xfer->status = status;  /* make software ignore it */
        usb_uncallout(xfer->timeout_handle, uhci_timeout, ii);
        DPRINTFN(1,("uhci_abort_xfer: stop ii=%p\n", ii));
        for (std = ii->stdstart; std != NULL; std = std->link.std)
                std->td.td_status &= htole32(~(UHCI_TD_ACTIVE | UHCI_TD_IOC));
-       splx(s);
+       crit_exit();
 
        /*
         * Step 2: Wait until we know hardware has finished any possible
@@ -1956,7 +1940,7 @@ uhci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
         * has run.
         */
        usb_delay_ms(upipe->pipe.device->bus, 2); /* Hardware finishes in 1ms */
-       s = splusb();
+       crit_enter();
 #ifdef USB_USE_SOFTINTR
        sc->sc_softwake = 1;
 #endif /* USB_USE_SOFTINTR */
@@ -1965,7 +1949,7 @@ uhci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
        DPRINTFN(1,("uhci_abort_xfer: tsleep\n"));
        tsleep(&sc->sc_softwake, 0, "uhciab", 0);
 #endif /* USB_USE_SOFTINTR */
-       splx(s);
+       crit_exit();
 
        /*
         * Step 3: Execute callback.
@@ -1974,12 +1958,12 @@ uhci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
 
        DPRINTFN(1,("uhci_abort_xfer: callback\n"));
 
-       s = splusb();
+       crit_enter();
 #ifdef DIAGNOSTIC
        ii->isdone = 1;
 #endif
        usb_transfer_complete(xfer);
-       splx(s);
+       crit_exit();
 }
 
 /* Close a device bulk pipe. */
@@ -2061,7 +2045,7 @@ uhci_device_intr_start(usbd_xfer_handle xfer)
        uhci_soft_qh_t *sqh;
        usbd_status err;
        int isread, endpt;
-       int i, s;
+       int i;
 
        if (sc->sc_dying)
                return (USBD_IOERROR);
@@ -2095,7 +2079,7 @@ uhci_device_intr_start(usbd_xfer_handle xfer)
        }
 #endif
 
-       s = splusb();
+       crit_enter();
        /* Set up interrupt info. */
        ii->xfer = xfer;
        ii->stdstart = data;
@@ -2116,7 +2100,7 @@ uhci_device_intr_start(usbd_xfer_handle xfer)
        }
        uhci_add_intr_info(sc, ii);
        xfer->status = USBD_IN_PROGRESS;
-       splx(s);
+       crit_exit();
 
 #ifdef USB_DEBUG
        if (uhcidebug > 10) {
@@ -2162,14 +2146,13 @@ uhci_device_intr_close(usbd_pipe_handle pipe)
        struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
        uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
        int i, npoll;
-       int s;
 
        /* Unlink descriptors from controller data structures. */
        npoll = upipe->u.intr.npoll;
-       s = splusb();
+       crit_enter();
        for (i = 0; i < npoll; i++)
                uhci_remove_intr(sc, upipe->u.intr.qhs[i]);
-       splx(s);
+       crit_exit();
 
        /*
         * We now have to wait for any activity on the physical
@@ -2200,7 +2183,6 @@ uhci_device_request(usbd_xfer_handle xfer)
        u_int32_t ls;
        usbd_status err;
        int isread;
-       int s;
 
        DPRINTFN(3,("uhci_device_control type=0x%02x, request=0x%02x, "
                    "wValue=0x%04x, wIndex=0x%04x len=%d, addr=%d, endpt=%d\n",
@@ -2270,7 +2252,7 @@ uhci_device_request(usbd_xfer_handle xfer)
        sqh->elink = setup;
        sqh->qh.qh_elink = htole32(setup->physaddr | UHCI_PTR_TD);
 
-       s = splusb();
+       crit_enter();
        if (dev->speed == USB_SPEED_LOW)
                uhci_add_ls_ctrl(sc, sqh);
        else
@@ -2308,7 +2290,7 @@ uhci_device_request(usbd_xfer_handle xfer)
                            uhci_timeout, ii);
        }
        xfer->status = USBD_IN_PROGRESS;
-       splx(s);
+       crit_exit();
 
        return (USBD_NORMAL_COMPLETION);
 }
@@ -2348,7 +2330,7 @@ uhci_device_isoc_enter(usbd_xfer_handle xfer)
        struct iso *iso = &upipe->u.iso;
        uhci_soft_td_t *std;
        u_int32_t buf, len, status;
-       int s, i, next, nframes;
+       int i, next, nframes;
 
        DPRINTFN(5,("uhci_device_isoc_enter: used=%d next=%d xfer=%p "
                    "nframes=%d\n",
@@ -2383,7 +2365,7 @@ uhci_device_isoc_enter(usbd_xfer_handle xfer)
                                     UHCI_TD_ACTIVE |
                                     UHCI_TD_IOS);
        nframes = xfer->nframes;
-       s = splusb();
+       crit_enter();
        for (i = 0; i < nframes; i++) {
                std = iso->stds[next];
                if (++next >= UHCI_VFRAMELIST_COUNT)
@@ -2406,7 +2388,7 @@ uhci_device_isoc_enter(usbd_xfer_handle xfer)
        iso->next = next;
        iso->inuse += xfer->nframes;
 
-       splx(s);
+       crit_exit();
 }
 
 usbd_status
@@ -2416,7 +2398,7 @@ uhci_device_isoc_start(usbd_xfer_handle xfer)
        uhci_softc_t *sc = (uhci_softc_t *)upipe->pipe.device->bus;
        uhci_intr_info_t *ii = &UXFER(xfer)->iinfo;
        uhci_soft_td_t *end;
-       int s, i;
+       int i;
 
        DPRINTFN(5,("uhci_device_isoc_start: xfer=%p\n", xfer));
 
@@ -2441,7 +2423,7 @@ uhci_device_isoc_start(usbd_xfer_handle xfer)
        }
 #endif
 
-       s = splusb();
+       crit_enter();
 
        /* Set up interrupt info. */
        ii->xfer = xfer;
@@ -2454,7 +2436,7 @@ uhci_device_isoc_start(usbd_xfer_handle xfer)
 #endif
        uhci_add_intr_info(sc, ii);
 
-       splx(s);
+       crit_exit();
 
        return (USBD_IN_PROGRESS);
 }
@@ -2465,14 +2447,14 @@ uhci_device_isoc_abort(usbd_xfer_handle xfer)
        struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
        uhci_soft_td_t **stds = upipe->u.iso.stds;
        uhci_soft_td_t *std;
-       int i, n, s, nframes, maxlen, len;
+       int i, n, nframes, maxlen, len;
 
-       s = splusb();
+       crit_enter();
 
        /* Transfer is already done. */
        if (xfer->status != USBD_NOT_STARTED &&
            xfer->status != USBD_IN_PROGRESS) {
-               splx(s);
+               crit_exit();
                return;
        }
 
@@ -2502,7 +2484,7 @@ uhci_device_isoc_abort(usbd_xfer_handle xfer)
        /* Run callback and remove from interrupt list. */
        usb_transfer_complete(xfer);
 
-       splx(s);
+       crit_exit();
 }
 
 void
@@ -2513,7 +2495,7 @@ uhci_device_isoc_close(usbd_pipe_handle pipe)
        uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
        uhci_soft_td_t *std, *vstd;
        struct iso *iso;
-       int i, s;
+       int i;
 
        /*
         * Make sure all TDs are marked as inactive.
@@ -2527,7 +2509,7 @@ uhci_device_isoc_close(usbd_pipe_handle pipe)
                iso->stds[i]->td.td_status &= htole32(~UHCI_TD_ACTIVE);
        usb_delay_ms(&sc->sc_bus, 2); /* wait for completion */
 
-       s = splusb();
+       crit_enter();
        for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
                std = iso->stds[i];
                for (vstd = sc->sc_vframes[i].htd;
@@ -2537,14 +2519,14 @@ uhci_device_isoc_close(usbd_pipe_handle pipe)
                if (vstd == NULL) {
                        /*panic*/
                        printf("uhci_device_isoc_close: %p not found\n", std);
-                       splx(s);
+                       crit_exit();
                        return;
                }
                vstd->link = std->link;
                vstd->td.td_link = std->td.td_link;
                uhci_free_std(sc, std);
        }
-       splx(s);
+       crit_exit();
 
        free(iso->stds, M_USBHC);
 }
@@ -2561,7 +2543,7 @@ uhci_setup_isoc(usbd_pipe_handle pipe)
        uhci_soft_td_t *std, *vstd;
        u_int32_t token;
        struct iso *iso;
-       int i, s;
+       int i;
 
        iso = &upipe->u.iso;
        iso->stds = malloc(UHCI_VFRAMELIST_COUNT * sizeof (uhci_soft_td_t *),
@@ -2581,7 +2563,7 @@ uhci_setup_isoc(usbd_pipe_handle pipe)
        }
 
        /* Insert TDs into schedule. */
-       s = splusb();
+       crit_enter();
        for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
                std = iso->stds[i];
                vstd = sc->sc_vframes[i].htd;
@@ -2590,7 +2572,7 @@ uhci_setup_isoc(usbd_pipe_handle pipe)
                vstd->link.std = std;
                vstd->td.td_link = htole32(std->physaddr | UHCI_PTR_TD);
        }
-       splx(s);
+       crit_exit();
 
        iso->next = -1;
        iso->inuse = 0;
@@ -2809,7 +2791,7 @@ usbd_status
 uhci_device_setintr(uhci_softc_t *sc, struct uhci_pipe *upipe, int ival)
 {
        uhci_soft_qh_t *sqh;
-       int i, npoll, s;
+       int i, npoll;
        u_int bestbw, bw, bestoffs, offs;
 
        DPRINTFN(2, ("uhci_device_setintr: pipe=%p\n", upipe));
@@ -2850,11 +2832,11 @@ uhci_device_setintr(uhci_softc_t *sc, struct uhci_pipe *upipe, int ival)
        }
 #undef MOD
 
-       s = splusb();
+       crit_enter();
        /* Enter QHs into the controller data structures. */
        for(i = 0; i < npoll; i++)
                uhci_add_intr(sc, upipe->u.intr.qhs[i]);
-       splx(s);
+       crit_exit();
 
        DPRINTFN(5, ("uhci_device_setintr: returns %p\n", upipe));
        return (USBD_NORMAL_COMPLETION);
@@ -3138,7 +3120,7 @@ uhci_root_ctrl_start(usbd_xfer_handle xfer)
        usb_device_request_t *req;
        void *buf = NULL;
        int port, x;
-       int s, len, value, index, status, change, l, totlen = 0;
+       int len, value, index, status, change, l, totlen = 0;
        usb_port_status_t ps;
        usbd_status err;
 
@@ -3448,9 +3430,9 @@ uhci_root_ctrl_start(usbd_xfer_handle xfer)
        err = USBD_NORMAL_COMPLETION;
  ret:
        xfer->status = err;
-       s = splusb();
+       crit_enter();
        usb_transfer_complete(xfer);
-       splx(s);
+       crit_exit();
        return (USBD_IN_PROGRESS);
 }
 
index bf914c9..9041f64 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $NetBSD: usb.c,v 1.68 2002/02/20 20:30:12 christos Exp $
  * $FreeBSD: src/sys/dev/usb/usb.c,v 1.95 2003/11/09 23:54:21 joe Exp $
- * $DragonFly: src/sys/bus/usb/usb.c,v 1.14 2004/05/19 22:52:39 dillon Exp $
+ * $DragonFly: src/sys/bus/usb/usb.c,v 1.15 2005/06/02 20:40:40 dillon Exp $
  */
 
 /* Also already merged from NetBSD:
@@ -82,6 +82,7 @@
 #include <sys/vnode.h>
 #include <sys/signalvar.h>
 #include <sys/sysctl.h>
+#include <sys/thread2.h>
 
 #include "usb.h"
 #include "usbdi.h"
@@ -363,9 +364,7 @@ usb_create_event_thread(void *arg)
 void
 usb_add_task(usbd_device_handle dev, struct usb_task *task)
 {
-       int s;
-
-       s = splusb();
+       crit_enter();
        if (!task->onqueue) {
                DPRINTFN(2,("usb_add_task: task=%p\n", task));
                TAILQ_INSERT_TAIL(&usb_all_tasks, task, next);
@@ -374,20 +373,18 @@ usb_add_task(usbd_device_handle dev, struct usb_task *task)
                DPRINTFN(3,("usb_add_task: task=%p on q\n", task));
        }
        wakeup(&usb_all_tasks);
-       splx(s);
+       crit_exit();
 }
 
 void
 usb_rem_task(usbd_device_handle dev, struct usb_task *task)
 {
-       int s;
-
-       s = splusb();
+       crit_enter();
        if (task->onqueue) {
                TAILQ_REMOVE(&usb_all_tasks, task, next);
                task->onqueue = 0;
        }
-       splx(s);
+       crit_exit();
 }
 
 void
@@ -439,7 +436,6 @@ void
 usb_task_thread(void *arg)
 {
        struct usb_task *task;
-       int s;
 
 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
        mtx_lock(&Giant);
@@ -447,7 +443,7 @@ usb_task_thread(void *arg)
 
        DPRINTF(("usb_task_thread: start\n"));
 
-       s = splusb();
+       crit_enter();
        for (;;) {
                task = TAILQ_FIRST(&usb_all_tasks);
                if (task == NULL) {
@@ -458,9 +454,9 @@ usb_task_thread(void *arg)
                if (task != NULL) {
                        TAILQ_REMOVE(&usb_all_tasks, task, next);
                        task->onqueue = 0;
-                       splx(s);
+                       crit_exit();
                        task->fun(task->arg);
-                       s = splusb();
+                       crit_enter();
                }
        }
 }
@@ -504,7 +500,7 @@ usbread(dev_t dev, struct uio *uio, int flag)
 {
        struct usb_event ue;
        int unit = USBUNIT(dev);
-       int s, error, n;
+       int error, n;
 
        if (unit != USB_DEV_MINOR)
                return (ENODEV);
@@ -513,7 +509,7 @@ usbread(dev_t dev, struct uio *uio, int flag)
                return (EINVAL);
 
        error = 0;
-       s = splusb();
+       crit_enter();
        for (;;) {
                n = usb_get_next_event(&ue);
                if (n != 0)
@@ -526,7 +522,7 @@ usbread(dev_t dev, struct uio *uio, int flag)
                if (error)
                        break;
        }
-       splx(s);
+       crit_exit();
        if (!error)
                error = uiomove((void *)&ue, uio->uio_resid, uio);
 
@@ -671,19 +667,19 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p)
 int
 usbpoll(dev_t dev, int events, usb_proc_ptr p)
 {
-       int revents, mask, s;
+       int revents, mask;
        int unit = USBUNIT(dev);
 
        if (unit == USB_DEV_MINOR) {
                revents = 0;
                mask = POLLIN | POLLRDNORM;
 
-               s = splusb();
+               crit_enter();
                if (events & mask && usb_nevents > 0)
                        revents |= events & mask;
                if (revents == 0 && events & mask)
                        selrecord(p, &usb_selevent);
-               splx(s);
+               crit_exit();
 
                return (revents);
        } else {
@@ -701,11 +697,6 @@ usb_discover(void *v)
 {
        struct usb_softc *sc = v;
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
-       /* splxxx should be changed to mutexes for preemption safety some day */
-       int s;
-#endif
-
        DPRINTFN(2,("usb_discover\n"));
 #ifdef USB_DEBUG
        if (usb_noexplore > 1)
@@ -718,20 +709,20 @@ usb_discover(void *v)
         * from the event thread for the controller.
         */
 #if defined(__FreeBSD__) || defined(__DragonFly__)
-       s = splusb();
+       crit_enter();
 #endif
        while (sc->sc_bus->needs_explore && !sc->sc_dying) {
                sc->sc_bus->needs_explore = 0;
 #if defined(__FreeBSD__) || defined(__DragonFly__)
-               splx(s);
+               crit_exit();
 #endif
                sc->sc_bus->root_hub->hub->explore(sc->sc_bus->root_hub);
 #if defined(__FreeBSD__) || defined(__DragonFly__)
-               s = splusb();
+               crit_enter();
 #endif
        }
 #if defined(__FreeBSD__) || defined(__DragonFly__)
-       splx(s);
+       crit_exit();
 #endif
 }
 
@@ -743,7 +734,7 @@ usb_needs_explore(usbd_device_handle dev)
        wakeup(&dev->bus->needs_explore);
 }
 
-/* Called at splusb() */
+/* Called from a critical section */
 int
 usb_get_next_event(struct usb_event *ue)
 {
@@ -792,7 +783,6 @@ usb_add_event(int type, struct usb_event *uep)
        struct usb_event_q *ueq;
        struct usb_event ue;
        struct timeval thetime;
-       int s;
 
        ueq = malloc(sizeof *ueq, M_USBDEV, M_INTWAIT);
        ueq->ue = *uep;
@@ -800,7 +790,7 @@ usb_add_event(int type, struct usb_event *uep)
        microtime(&thetime);
        TIMEVAL_TO_TIMESPEC(&thetime, &ueq->ue.ue_time);
 
-       s = splusb();
+       crit_enter();
        if (USB_EVENT_IS_DETACH(type)) {
                struct usb_event_q *ueqi, *ueqi_next;
 
@@ -829,7 +819,7 @@ usb_add_event(int type, struct usb_event *uep)
                psignal(usb_async_proc, SIGIO);
                PROC_UNLOCK(usb_async_proc);
        }
-       splx(s);
+       crit_exit();
 }
 
 void
index 2db40d7..1b4dc29 100644 (file)
  *
  *
  * $FreeBSD: src/sys/dev/usb/usb_ethersubr.c,v 1.17 2003/11/14 11:09:45 johan Exp $
- * $DragonFly: src/sys/bus/usb/usb_ethersubr.c,v 1.12 2005/02/16 22:50:28 joerg Exp $
+ * $DragonFly: src/sys/bus/usb/usb_ethersubr.c,v 1.13 2005/06/02 20:40:40 dillon Exp $
  */
 
 /*
- * Callbacks in the USB code operate at splusb() (actually splbio()
- * in FreeBSD). However adding packets to the input queues has to be
- * done at splimp(). It is conceivable that this arrangement could
- * trigger a condition where the splimp() is ignored and the input
- * queues could get trampled in spite of our best effors to prevent
- * it. To work around this, we implement a special input queue for
- * USB ethernet adapter drivers. Rather than passing the frames directly
- * to ether_input(), we pass them here, then schedule a soft interrupt
- * to hand them to ether_input() later, outside of the USB interrupt
- * context.
+ * Callbacks in the USB code operate in a critical section.
+ *
+ * It is conceivable that this arrangement could trigger a condition
+ * where the input queues could get trampled in spite of our best effors
+ * to prevent it. To work around this, we implement a special input queue
+ * for USB ethernet adapter drivers. Rather than passing the frames directly
+ * to ether_input(), we pass them here, then schedule a soft interrupt to
+ * hand them to ether_input() later, outside of the USB interrupt context.
  *
  * It's questional as to whether this code should be expanded to
  * handle other kinds of devices, or handle USB transfer callbacks
@@ -79,14 +77,11 @@ Static int usbintr(struct netmsg *msg)
 {
        struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet;
        struct ifnet *ifp;
-       int s;
-
-       s = splimp();
 
+       crit_enter();
        ifp = m->m_pkthdr.rcvif;
        (*ifp->if_input)(ifp, m);
-
-       splx(s);
+       crit_exit();
 
        lwkt_replymsg(&msg->nm_lmsg, 0);
        return EASYNC;
@@ -102,11 +97,14 @@ usb_register_netisr(void)
 }
 
 /*
- * Must be called at splusb() (actually splbio()). This should be
- * the case when called from a transfer callback routine.
+ * Must be called from a critical section.  This should be the case when
+ * called from a transfer callback routine.  Don't trust it, though.
  */
 void
 usb_ether_input(struct mbuf *m)
 {
+       crit_enter();
        netisr_queue(NETISR_USB, m);
+       crit_exit();
 }
+
index e6d97fd..c670087 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $NetBSD: usb_mem.c,v 1.26 2003/02/01 06:23:40 thorpej Exp $
  * $FreeBSD: src/sys/dev/usb/usb_mem.c,v 1.5 2003/10/04 22:13:21 joe Exp $
- * $DragonFly: src/sys/bus/usb/usb_mem.c,v 1.4 2004/05/13 17:24:49 dillon Exp $
+ * $DragonFly: src/sys/bus/usb/usb_mem.c,v 1.5 2005/06/02 20:40:40 dillon Exp $
  */
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -66,6 +66,7 @@
 #ifdef DIAGNOSTIC
 #include <sys/proc.h>
 #endif
+#include <sys/thread2.h>
 
 #include <bus/usb/usb.h>
 #include <bus/usb/usbdi.h>
@@ -125,25 +126,24 @@ usb_block_allocmem(bus_dma_tag_t tag, size_t size, size_t align,
                   usb_dma_block_t **dmap)
 {
         usb_dma_block_t *p;
-       int s;
 
        DPRINTFN(5, ("usb_block_allocmem: size=%lu align=%lu\n",
                     (u_long)size, (u_long)align));
 
-       s = splusb();
+       crit_enter();
        /* First check the free list. */
        for (p = LIST_FIRST(&usb_blk_freelist); p; p = LIST_NEXT(p, next)) {
                if (p->tag == tag && p->size >= size && p->align >= align) {
                        LIST_REMOVE(p, next);
                        usb_blk_nfree--;
-                       splx(s);
+                       crit_exit();
                        *dmap = p;
                        DPRINTFN(6,("usb_block_allocmem: free list size=%lu\n",
                                    (u_long)p->size));
                        return (USBD_NORMAL_COMPLETION);
                }
        }
-       splx(s);
+       crit_exit();
 
        DPRINTFN(6, ("usb_block_allocmem: no free\n"));
        p = malloc(sizeof *p, M_USB, M_INTWAIT);
@@ -199,13 +199,11 @@ free:
 Static void
 usb_block_freemem(usb_dma_block_t *p)
 {
-       int s;
-
        DPRINTFN(6, ("usb_block_freemem: size=%lu\n", (u_long)p->size));
-       s = splusb();
+       crit_enter();
        LIST_INSERT_HEAD(&usb_blk_freelist, p, next);
        usb_blk_nfree++;
-       splx(s);
+       crit_exit();
 }
 
 usbd_status
@@ -216,7 +214,6 @@ usb_allocmem(usbd_bus_handle bus, size_t size, size_t align, usb_dma_t *p)
        struct usb_frag_dma *f;
        usb_dma_block_t *b;
        int i;
-       int s;
 
        /* compat w/ Net/OpenBSD */
        if (align == 0)
@@ -235,7 +232,7 @@ usb_allocmem(usbd_bus_handle bus, size_t size, size_t align, usb_dma_t *p)
                return (err);
        }
 
-       s = splusb();
+       crit_enter();
        /* Check for free fragments. */
        for (f = LIST_FIRST(&usb_frag_freelist); f; f = LIST_NEXT(f, next))
                if (f->block->tag == tag)
@@ -244,7 +241,7 @@ usb_allocmem(usbd_bus_handle bus, size_t size, size_t align, usb_dma_t *p)
                DPRINTFN(1, ("usb_allocmem: adding fragments\n"));
                err = usb_block_allocmem(tag, USB_MEM_BLOCK, USB_MEM_SMALL,&b);
                if (err) {
-                       splx(s);
+                       crit_exit();
                        return (err);
                }
                b->fullblock = 0;
@@ -264,7 +261,7 @@ usb_allocmem(usbd_bus_handle bus, size_t size, size_t align, usb_dma_t *p)
        p->offs = f->offs;
        p->len = USB_MEM_SMALL;
        LIST_REMOVE(f, next);
-       splx(s);
+       crit_exit();
        DPRINTFN(5, ("usb_allocmem: use frag=%p size=%d\n", f, (int)size));
        return (USBD_NORMAL_COMPLETION);
 }
@@ -273,7 +270,6 @@ void
 usb_freemem(usbd_bus_handle bus, usb_dma_t *p)
 {
        struct usb_frag_dma *f;
-       int s;
 
        if (p->block->fullblock) {
                DPRINTFN(1, ("usb_freemem: large free\n"));
@@ -283,8 +279,8 @@ usb_freemem(usbd_bus_handle bus, usb_dma_t *p)
        f = KERNADDR(p, 0);
        f->block = p->block;
        f->offs = p->offs;
-       s = splusb();
+       crit_enter();
        LIST_INSERT_HEAD(&usb_frag_freelist, f, next);
-       splx(s);
+       crit_exit();
        DPRINTFN(5, ("usb_freemem: frag=%p\n", f));
 }
index a2c18c2..50277f0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $NetBSD: usbdi.c,v 1.103 2002/09/27 15:37:38 provos Exp $
  * $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.84 2003/11/09 23:56:19 joe Exp $
- * $DragonFly: src/sys/bus/usb/usbdi.c,v 1.8 2004/02/11 15:17:26 joerg Exp $
+ * $DragonFly: src/sys/bus/usb/usbdi.c,v 1.9 2005/06/02 20:40:40 dillon Exp $
  */
 
 /*
@@ -55,6 +55,7 @@
 #endif
 #include <sys/malloc.h>
 #include <sys/proc.h>
+#include <sys/thread2.h>
 
 #include <machine/bus.h>
 
@@ -285,7 +286,6 @@ usbd_transfer(usbd_xfer_handle xfer)
        usb_dma_t *dmap = &xfer->dmabuf;
        usbd_status err;
        u_int size;
-       int s;
 
        DPRINTFN(5,("usbd_transfer: xfer=%p, flags=%d, pipe=%p, running=%d\n",
                    xfer, xfer->flags, pipe, pipe->running));
@@ -336,13 +336,13 @@ usbd_transfer(usbd_xfer_handle xfer)
        /* Sync transfer, wait for completion. */
        if (err != USBD_IN_PROGRESS)
                return (err);
-       s = splusb();
+       crit_enter();
        if (!xfer->done) {
                if (pipe->device->bus->use_polling)
                        panic("usbd_transfer: not done\n");
                tsleep(xfer, 0, "usbsyn", 0);
        }
-       splx(s);
+       crit_exit();
        return (xfer->status);
 }
 
@@ -537,7 +537,6 @@ usbd_status
 usbd_abort_pipe(usbd_pipe_handle pipe)
 {
        usbd_status err;
-       int s;
 
 #ifdef DIAGNOSTIC
        if (pipe == NULL) {
@@ -545,9 +544,9 @@ usbd_abort_pipe(usbd_pipe_handle pipe)
                return (USBD_NORMAL_COMPLETION);
        }
 #endif
-       s = splusb();
+       crit_enter();
        err = usbd_ar_pipe(pipe);
-       splx(s);
+       crit_exit();
        return (err);
 }
 
@@ -727,14 +726,12 @@ usbd_get_interface(usbd_interface_handle iface, u_int8_t *aiface)
 
 /*** Internal routines ***/
 
-/* Dequeue all pipe operations, called at splusb(). */
+/* Dequeue all pipe operations, called from a critical section. */
 Static usbd_status
 usbd_ar_pipe(usbd_pipe_handle pipe)
 {
        usbd_xfer_handle xfer;
 
-       SPLUSBCHECK;
-
        DPRINTFN(2,("usbd_ar_pipe: pipe=%p\n", pipe));
 #ifdef USB_DEBUG
        if (usbdebug > 5)
@@ -753,7 +750,7 @@ usbd_ar_pipe(usbd_pipe_handle pipe)
        return (USBD_NORMAL_COMPLETION);
 }
 
-/* Called at splusb() */
+/* Called from a critical section. */
 void
 usb_transfer_complete(usbd_xfer_handle xfer)
 {
@@ -762,8 +759,6 @@ usb_transfer_complete(usbd_xfer_handle xfer)
        int repeat = pipe->repeat;
        int polling;
 
-       SPLUSBCHECK;
-
        DPRINTFN(5, ("usb_transfer_complete: pipe=%p xfer=%p status=%d "
                     "actlen=%d\n", pipe, xfer, xfer->status, xfer->actlen));
 #ifdef DIAGNOSTIC
@@ -862,7 +857,6 @@ usb_insert_transfer(usbd_xfer_handle xfer)
 {
        usbd_pipe_handle pipe = xfer->pipe;
        usbd_status err;
-       int s;
 
        DPRINTFN(5,("usb_insert_transfer: pipe=%p running=%d timeout=%d\n",
                    pipe, pipe->running, xfer->timeout));
@@ -874,7 +868,7 @@ usb_insert_transfer(usbd_xfer_handle xfer)
        }
        xfer->busy_free = XFER_ONQU;
 #endif
-       s = splusb();
+       crit_enter();
        SIMPLEQ_INSERT_TAIL(&pipe->queue, xfer, next);
        if (pipe->running)
                err = USBD_IN_PROGRESS;
@@ -882,19 +876,17 @@ usb_insert_transfer(usbd_xfer_handle xfer)
                pipe->running = 1;
                err = USBD_NORMAL_COMPLETION;
        }
-       splx(s);
+       crit_exit();
        return (err);
 }
 
-/* Called at splusb() */
+/* Called from a critical section. */
 void
 usbd_start_next(usbd_pipe_handle pipe)
 {
        usbd_xfer_handle xfer;
        usbd_status err;
 
-       SPLUSBCHECK;
-
 #ifdef DIAGNOSTIC
        if (pipe == NULL) {
                printf("usbd_start_next: pipe == NULL\n");
index 25db3c1..d714b3e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $NetBSD: usbdi.h,v 1.62 2002/07/11 21:14:35 augustss Exp $
  * $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.48 2003/07/14 20:31:03 joe Exp $
- * $DragonFly: src/sys/bus/usb/usbdi.h,v 1.4 2004/02/11 15:17:26 joerg Exp $
+ * $DragonFly: src/sys/bus/usb/usbdi.h,v 1.5 2005/06/02 20:40:40 dillon Exp $
  */
 
 /*
@@ -271,15 +271,3 @@ struct usb_attach_arg {
 int usbd_driver_load(module_t mod, int what, void *arg);
 #endif
 
-/* XXX Perhaps USB should have its own levels? */
-#ifdef USB_USE_SOFTINTR
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
-#define splusb splsoftnet
-#else
-#define        splusb splsoftclock
-#endif /* __HAVE_GENERIC_SOFT_INTERRUPTS */
-#else
-#define splusb splbio
-#endif /* USB_USE_SOFTINTR */
-#define splhardusb splbio
-#define IPL_USB IPL_BIO
index 05418c2..dc1b5c3 100644 (file)
@@ -2,7 +2,7 @@
  * $NetBSD: usbdi_util.c,v 1.24 1999/11/17 23:00:50 augustss Exp $
  * $NetBSD: usbdi_util.c,v 1.36 2001/11/13 06:24:57 lukem Exp $
  * $FreeBSD: src/sys/dev/usb/usbdi_util.c,v 1.31 2003/08/24 17:55:55 obrien Exp $
- * $DragonFly: src/sys/bus/usb/usbdi_util.c,v 1.7 2004/03/12 03:43:06 dillon Exp $
+ * $DragonFly: src/sys/bus/usb/usbdi_util.c,v 1.8 2005/06/02 20:40:40 dillon Exp $
  */
 
 /*
@@ -52,6 +52,7 @@
 #elif defined(__FreeBSD__) || defined(__DragonFly__)
 #include <sys/bus.h>
 #endif
+#include <sys/thread2.h>
 
 #include "usb.h"
 #include "usbhid.h"
@@ -420,19 +421,19 @@ usbd_bulk_transfer(usbd_xfer_handle xfer, usbd_pipe_handle pipe,
                   u_int32_t *size, char *lbl)
 {
        usbd_status err;
-       int s, error;
+       int error;
 
        usbd_setup_xfer(xfer, pipe, 0, buf, *size,
                        flags, timeout, usbd_bulk_transfer_cb);
        DPRINTFN(1, ("usbd_bulk_transfer: start transfer %d bytes\n", *size));
-       s = splusb();           /* don't want callback until tsleep() */
+       crit_enter();
        err = usbd_transfer(xfer);
        if (err != USBD_IN_PROGRESS) {
-               splx(s);
+               crit_exit();
                return (err);
        }
        error = tsleep((caddr_t)xfer, PCATCH, lbl, 0);
-       splx(s);
+       crit_exit();
        if (error) {
                DPRINTF(("usbd_bulk_transfer: tsleep=%d\n", error));
                usbd_abort_pipe(pipe);
@@ -462,19 +463,19 @@ usbd_intr_transfer(usbd_xfer_handle xfer, usbd_pipe_handle pipe,
                   u_int32_t *size, char *lbl)
 {
        usbd_status err;
-       int s, error;
+       int error;
 
        usbd_setup_xfer(xfer, pipe, 0, buf, *size,
                        flags, timeout, usbd_intr_transfer_cb);
        DPRINTFN(1, ("usbd_intr_transfer: start transfer %d bytes\n", *size));
-       s = splusb();           /* don't want callback until tsleep() */
+       crit_enter();           /* don't want callback until tsleep() */
        err = usbd_transfer(xfer);
        if (err != USBD_IN_PROGRESS) {
-               splx(s);
+               crit_exit();
                return (err);
        }
        error = tsleep(xfer, PCATCH, lbl, 0);
-       splx(s);
+       crit_exit();
        if (error) {
                DPRINTF(("usbd_intr_transfer: tsleep=%d\n", error));
                usbd_abort_pipe(pipe);
index 576917c..82cbfdd 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $NetBSD: usbdivar.h,v 1.70 2002/07/11 21:14:36 augustss Exp $
  * $FreeBSD: src/sys/dev/usb/usbdivar.h,v 1.40 2003/07/15 22:42:37 jmg Exp $
- * $DragonFly: src/sys/bus/usb/usbdivar.h,v 1.4 2004/02/11 15:17:26 joerg Exp $
+ * $DragonFly: src/sys/bus/usb/usbdivar.h,v 1.5 2005/06/02 20:40:40 dillon Exp $
  */
 
 /*
@@ -261,20 +261,6 @@ void               usb_disconnect_port(struct usbd_port *up, device_ptr_t);
 void           usb_needs_explore(usbd_device_handle);
 void           usb_schedsoftintr(struct usbd_bus *);
 
-/*
- * XXX This check is extremely bogus. Bad Bad Bad.
- */
-#if defined(DIAGNOSTIC) && 0
-#define SPLUSBCHECK \
-       do { int _s = splusb(), _su = splusb(); \
-             if (!cold && _s != _su) printf("SPLUSBCHECK failed 0x%x!=0x%x, %s:%d\n", \
-                                  _s, _su, __FILE__, __LINE__); \
-            splx(_s); \
-        } while (0)
-#else
-#define SPLUSBCHECK
-#endif
-
 /* Locator stuff. */
 
 #if defined(__NetBSD__)
index 9d7d5a4..33d19b6 100644 (file)
@@ -32,7 +32,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  * 
  * $FreeBSD: src/sys/dev/firewire/sbp.c,v 1.74 2004/01/08 14:58:09 simokawa Exp $
- * $DragonFly: src/sys/dev/disk/sbp/sbp.c,v 1.13 2005/02/17 13:59:35 joerg Exp $
+ * $DragonFly: src/sys/dev/disk/sbp/sbp.c,v 1.14 2005/06/02 20:40:42 dillon Exp $
  *
  */
 
@@ -53,6 +53,7 @@
 #if defined(__DragonFly__) || __FreeBSD_version < 500106
 #include <sys/devicestat.h>    /* for struct devstat */
 #endif
+#include <sys/thread2.h>
 
 #ifdef __DragonFly__
 #include <bus/cam/cam.h>
@@ -850,7 +851,6 @@ END_DEBUG
 #if NEED_RESPONSE
 static void
 sbp_loginres_callback(struct fw_xfer *xfer){
-       int s;
        struct sbp_dev *sdev;
        sdev = (struct sbp_dev *)xfer->sc;
 SBP_DEBUG(1)
@@ -858,9 +858,9 @@ SBP_DEBUG(1)
        printf("sbp_loginres_callback\n");
 END_DEBUG
        /* recycle */
-       s = splfw();
+       crit_enter();
        STAILQ_INSERT_TAIL(&sdev->target->sbp->fwb.xferlist, xfer, link);
-       splx(s);
+       crit_exit();
        return;
 }
 #endif
@@ -869,13 +869,12 @@ static __inline void
 sbp_xfer_free(struct fw_xfer *xfer)
 {
        struct sbp_dev *sdev;
-       int s;
 
        sdev = (struct sbp_dev *)xfer->sc;
        fw_xfer_unload(xfer);
-       s = splfw();
+       crit_enter();
        STAILQ_INSERT_TAIL(&sdev->target->xferlist, xfer, link);
-       splx(s);
+       crit_exit();
 }
 
 static void
@@ -1248,21 +1247,21 @@ sbp_write_cmd(struct sbp_dev *sdev, int tcode, int offset)
        struct fw_xfer *xfer;
        struct fw_pkt *fp;
        struct sbp_target *target;
-       int s, new = 0;
+       int new = 0;
 
        target = sdev->target;
-       s = splfw();
+       crit_enter();
        xfer = STAILQ_FIRST(&target->xferlist);
        if (xfer == NULL) {
                if (target->n_xfer > 5 /* XXX */) {
                        printf("sbp: no more xfer for this target\n");
-                       splx(s);
+                       crit_exit();
                        return(NULL);
                }
                xfer = fw_xfer_alloc_buf(M_SBP, 8, 0);
                if(xfer == NULL){
                        printf("sbp: fw_xfer_alloc_buf failed\n");
-                       splx(s);
+                       crit_exit();
                        return NULL;
                }
                target->n_xfer ++;
@@ -1272,7 +1271,7 @@ sbp_write_cmd(struct sbp_dev *sdev, int tcode, int offset)
        } else {
                STAILQ_REMOVE_HEAD(&target->xferlist, link);
        }
-       splx(s);
+       crit_exit();
 
        microtime(&xfer->tv);
 
@@ -1308,23 +1307,23 @@ sbp_mgm_orb(struct sbp_dev *sdev, int func, struct sbp_ocb *aocb)
        struct fw_pkt *fp;
        struct sbp_ocb *ocb;
        struct sbp_target *target;
-       int s, nid;
+       int nid;
 
        target = sdev->target;
        nid = target->sbp->fd.fc->nodeid | FWLOCALBUS;
 
-       s = splfw();
+       crit_enter();
        if (func == ORB_FUN_RUNQUEUE) {
                ocb = STAILQ_FIRST(&target->mgm_ocb_queue);
                if (target->mgm_ocb_cur != NULL || ocb == NULL) {
-                       splx(s);
+                       crit_exit();
                        return;
                }
                STAILQ_REMOVE_HEAD(&target->mgm_ocb_queue, ocb);
                goto start;
        }
        if ((ocb = sbp_get_ocb(sdev)) == NULL) {
-               splx(s);
+               crit_exit();
                /* XXX */
                return;
        }
@@ -1366,12 +1365,12 @@ END_DEBUG
        if (target->mgm_ocb_cur != NULL) {
                /* there is a standing ORB */
                STAILQ_INSERT_TAIL(&sdev->target->mgm_ocb_queue, ocb, ocb);
-               splx(s);
+               crit_exit();
                return;
        }
 start:
        target->mgm_ocb_cur = ocb;
-       splx(s);
+       crit_exit();
 
        callout_reset(&target->mgm_ocb_timeout, 5*hz,
                                sbp_mgm_timeout, (caddr_t)ocb);
@@ -1845,11 +1844,9 @@ done0:
 static void
 sbp