30c30
< __FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_da.c 166861 2007-02-21 07:45:02Z n_hibma $");
---
> __FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_da.c 168752 2007-04-15 08:49:19Z scottl $");
39a40,41
> #include <sys/lock.h>
> #include <sys/mutex.h>
63a66
> #include <cam/cam_sim.h>
135a139
> struct callout sendordered_c;
554,555d557
< static SLIST_HEAD(,da_softc) softc_list;
<
563d564
< int s;
565d565
< s = splsoftcam();
568d567
< splx(s);
571d569
< unit = periph->unit_number;
572a571,582
> if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
> return(ENXIO);
> }
>
> cam_periph_lock(periph);
> if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
> cam_periph_unlock(periph);
> cam_periph_release(periph);
> return (error);
> }
>
> unit = periph->unit_number;
573a584
> softc->flags |= DA_FLAG_OPEN;
579,585d589
< if ((error = cam_periph_lock(periph, PRIBIO|PCATCH)) != 0)
< return (error); /* error code from tsleep */
<
< if (cam_periph_acquire(periph) != CAM_REQ_CMP)
< return(ENXIO);
< softc->flags |= DA_FLAG_OPEN;
<
590d593
< splx(s);
612a616
> cam_periph_unhold(periph);
622c626
< int error;
---
> int error;
628,631c632,636
< softc = (struct da_softc *)periph->softc;
<
< if ((error = cam_periph_lock(periph, PRIBIO)) != 0) {
< return (error); /* error code from tsleep */
---
> cam_periph_lock(periph);
> if ((error = cam_periph_hold(periph, PRIBIO)) != 0) {
> cam_periph_unlock(periph);
> cam_periph_release(periph);
> return (error);
633a639,640
> softc = (struct da_softc *)periph->softc;
>
694a702
> cam_periph_unhold(periph);
710d717
< int s;
717a725,727
>
> cam_periph_lock(periph);
>
730d739
< s = splbio();
736c745
< splx(s);
---
> cam_periph_unlock(periph);
746,747d754
< splx(s);
<
751a759
> cam_periph_unlock(periph);
775a784
> periph->flags |= CAM_PERIPH_POLLED;
800a810
> periph->flags |= CAM_PERIPH_POLLED;
804c814
< }
---
> }
842a853
> periph->flags &= ~CAM_PERIPH_POLLED;
852,853d862
< SLIST_INIT(&softc_list);
<
879,885d887
< /*
< * Schedule a periodic event to occasionally send an
< * ordered tag to a device.
< */
< timeout(dasendorderedtag, NULL,
< (DA_DEFAULT_TIMEOUT * hz) / DA_ORDEREDTAG_INTERVAL);
<
896d897
< int s;
916,922d916
< * 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.
< */
< s = splbio();
<
< /*
928d921
< splx(s);
930,931d922
< SLIST_REMOVE(&softc_list, softc, da_softc, links);
<
951a943,950
>
> /*
> * XXX Gotta drop the periph lock so that the drain can complete with
> * deadlocking on the lock. Hopefully dropping here is safe.
> */
> cam_periph_unlock(periph);
> callout_drain(&softc->sendordered_c);
> cam_periph_lock(periph);
965a965
> struct cam_sim *sim;
981a982
> sim = xpt_path_sim(cgd->ccb_h.path);
999d999
< int s;
1002d1001
< s = splsoftcam();
1010d1008
< splx(s);
1027c1025,1026
< softc = (struct da_softc *)periph->softc;
---
> if (cam_periph_acquire(periph) != CAM_REQ_CMP)
> return;
1028a1028
> softc = (struct da_softc *)periph->softc;
1040a1041
> cam_periph_release(periph);
1053a1055
> cam_periph_release(periph);
1091d1092
< int s;
1181,1188d1181
< * Block our timeout handler while we
< * add this softc to the dev list.
< */
< s = splsoftclock();
< SLIST_INSERT_HEAD(&softc_list, softc, links);
< splx(s);
<
< /*
1191a1185
> mtx_unlock(periph->sim->mtx);
1201c1195
< softc->disk->d_flags = DISKFLAG_NEEDSGIANT;
---
> softc->disk->d_flags = 0;
1204a1199
> mtx_lock(periph->sim->mtx);
1219a1215
>
1221,1222c1217,1219
< * Lock this peripheral until we are setup.
< * This first call can't block
---
> * Take an exclusive refcount on the periph while dastart is called
> * to finish the probe. The reference will be dropped in dadone at
> * the end of probe.
1224c1221
< (void)cam_periph_lock(periph, PRIBIO);
---
> (void)cam_periph_hold(periph, PRIBIO);
1226a1224,1232
> /*
> * Schedule a periodic event to occasionally send an
> * ordered tag to a device.
> */
> callout_init_mtx(&softc->sendordered_c, periph->sim->mtx, 0);
> callout_reset(&softc->sendordered_c,
> (DA_DEFAULT_TIMEOUT * hz) / DA_ORDEREDTAG_INTERVAL,
> dasendorderedtag, softc);
>
1237d1242
<
1243d1247
< int s;
1248d1251
< s = splbio();
1257d1259
< splx(s);
1260d1261
< splx(s);
1263d1263
< int oldspl;
1310d1309
< oldspl = splcam();
1314d1312
< splx(oldspl);
1324d1321
< splx(s);
1449d1445
< int oldspl;
1454d1449
< int s;
1472,1473d1466
< s = splbio();
<
1494d1486
< splx(s);
1522d1513
< oldspl = splcam();
1527d1517
< splx(oldspl);
1713c1703
< cam_periph_unlock(periph);
---
> cam_periph_unhold(periph);
1836c1826,1828
< M_WAITOK);
---
> M_NOWAIT);
> if (rcap == NULL)
> return (ENOMEM);
1962,1974c1954
< struct da_softc *softc;
< int s;
< if (da_send_ordered) {
< for (softc = SLIST_FIRST(&softc_list);
< softc != NULL;
< softc = SLIST_NEXT(softc, links)) {
< s = splsoftcam();
< if ((softc->ordered_tag_count == 0)
< && ((softc->flags & DA_FLAG_WENT_IDLE) == 0)) {
< softc->flags |= DA_FLAG_NEED_OTAG;
< }
< if (softc->outstanding_cmds > 0)
< softc->flags &= ~DA_FLAG_WENT_IDLE;
---
> struct da_softc *softc = arg;
1976,1977c1956,1959
< softc->ordered_tag_count = 0;
< splx(s);
---
> if (da_send_ordered) {
> if ((softc->ordered_tag_count == 0)
> && ((softc->flags & DA_FLAG_WENT_IDLE) == 0)) {
> softc->flags |= DA_FLAG_NEED_OTAG;
1979,1981c1961,1964
< /* Queue us up again */
< timeout(dasendorderedtag, NULL,
< (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL);
---
> if (softc->outstanding_cmds > 0)
> softc->flags &= ~DA_FLAG_WENT_IDLE;
>
> softc->ordered_tag_count = 0;
1982a1966,1969
> /* Queue us up again */
> callout_reset(&softc->sendordered_c,
> (DA_DEFAULT_TIMEOUT * hz) / DA_ORDEREDTAG_INTERVAL,
> dasendorderedtag, softc);
< __FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_da.c 166861 2007-02-21 07:45:02Z n_hibma $");
---
> __FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_da.c 168752 2007-04-15 08:49:19Z scottl $");
39a40,41
> #include <sys/lock.h>
> #include <sys/mutex.h>
63a66
> #include <cam/cam_sim.h>
135a139
> struct callout sendordered_c;
554,555d557
< static SLIST_HEAD(,da_softc) softc_list;
<
563d564
< int s;
565d565
< s = splsoftcam();
568d567
< splx(s);
571d569
< unit = periph->unit_number;
572a571,582
> if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
> return(ENXIO);
> }
>
> cam_periph_lock(periph);
> if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
> cam_periph_unlock(periph);
> cam_periph_release(periph);
> return (error);
> }
>
> unit = periph->unit_number;
573a584
> softc->flags |= DA_FLAG_OPEN;
579,585d589
< if ((error = cam_periph_lock(periph, PRIBIO|PCATCH)) != 0)
< return (error); /* error code from tsleep */
<
< if (cam_periph_acquire(periph) != CAM_REQ_CMP)
< return(ENXIO);
< softc->flags |= DA_FLAG_OPEN;
<
590d593
< splx(s);
612a616
> cam_periph_unhold(periph);
622c626
< int error;
---
> int error;
628,631c632,636
< softc = (struct da_softc *)periph->softc;
<
< if ((error = cam_periph_lock(periph, PRIBIO)) != 0) {
< return (error); /* error code from tsleep */
---
> cam_periph_lock(periph);
> if ((error = cam_periph_hold(periph, PRIBIO)) != 0) {
> cam_periph_unlock(periph);
> cam_periph_release(periph);
> return (error);
633a639,640
> softc = (struct da_softc *)periph->softc;
>
694a702
> cam_periph_unhold(periph);
710d717
< int s;
717a725,727
>
> cam_periph_lock(periph);
>
730d739
< s = splbio();
736c745
< splx(s);
---
> cam_periph_unlock(periph);
746,747d754
< splx(s);
<
751a759
> cam_periph_unlock(periph);
775a784
> periph->flags |= CAM_PERIPH_POLLED;
800a810
> periph->flags |= CAM_PERIPH_POLLED;
804c814
< }
---
> }
842a853
> periph->flags &= ~CAM_PERIPH_POLLED;
852,853d862
< SLIST_INIT(&softc_list);
<
879,885d887
< /*
< * Schedule a periodic event to occasionally send an
< * ordered tag to a device.
< */
< timeout(dasendorderedtag, NULL,
< (DA_DEFAULT_TIMEOUT * hz) / DA_ORDEREDTAG_INTERVAL);
<
896d897
< int s;
916,922d916
< * 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.
< */
< s = splbio();
<
< /*
928d921
< splx(s);
930,931d922
< SLIST_REMOVE(&softc_list, softc, da_softc, links);
<
951a943,950
>
> /*
> * XXX Gotta drop the periph lock so that the drain can complete with
> * deadlocking on the lock. Hopefully dropping here is safe.
> */
> cam_periph_unlock(periph);
> callout_drain(&softc->sendordered_c);
> cam_periph_lock(periph);
965a965
> struct cam_sim *sim;
981a982
> sim = xpt_path_sim(cgd->ccb_h.path);
999d999
< int s;
1002d1001
< s = splsoftcam();
1010d1008
< splx(s);
1027c1025,1026
< softc = (struct da_softc *)periph->softc;
---
> if (cam_periph_acquire(periph) != CAM_REQ_CMP)
> return;
1028a1028
> softc = (struct da_softc *)periph->softc;
1040a1041
> cam_periph_release(periph);
1053a1055
> cam_periph_release(periph);
1091d1092
< int s;
1181,1188d1181
< * Block our timeout handler while we
< * add this softc to the dev list.
< */
< s = splsoftclock();
< SLIST_INSERT_HEAD(&softc_list, softc, links);
< splx(s);
<
< /*
1191a1185
> mtx_unlock(periph->sim->mtx);
1201c1195
< softc->disk->d_flags = DISKFLAG_NEEDSGIANT;
---
> softc->disk->d_flags = 0;
1204a1199
> mtx_lock(periph->sim->mtx);
1219a1215
>
1221,1222c1217,1219
< * Lock this peripheral until we are setup.
< * This first call can't block
---
> * Take an exclusive refcount on the periph while dastart is called
> * to finish the probe. The reference will be dropped in dadone at
> * the end of probe.
1224c1221
< (void)cam_periph_lock(periph, PRIBIO);
---
> (void)cam_periph_hold(periph, PRIBIO);
1226a1224,1232
> /*
> * Schedule a periodic event to occasionally send an
> * ordered tag to a device.
> */
> callout_init_mtx(&softc->sendordered_c, periph->sim->mtx, 0);
> callout_reset(&softc->sendordered_c,
> (DA_DEFAULT_TIMEOUT * hz) / DA_ORDEREDTAG_INTERVAL,
> dasendorderedtag, softc);
>
1237d1242
<
1243d1247
< int s;
1248d1251
< s = splbio();
1257d1259
< splx(s);
1260d1261
< splx(s);
1263d1263
< int oldspl;
1310d1309
< oldspl = splcam();
1314d1312
< splx(oldspl);
1324d1321
< splx(s);
1449d1445
< int oldspl;
1454d1449
< int s;
1472,1473d1466
< s = splbio();
<
1494d1486
< splx(s);
1522d1513
< oldspl = splcam();
1527d1517
< splx(oldspl);
1713c1703
< cam_periph_unlock(periph);
---
> cam_periph_unhold(periph);
1836c1826,1828
< M_WAITOK);
---
> M_NOWAIT);
> if (rcap == NULL)
> return (ENOMEM);
1962,1974c1954
< struct da_softc *softc;
< int s;
< if (da_send_ordered) {
< for (softc = SLIST_FIRST(&softc_list);
< softc != NULL;
< softc = SLIST_NEXT(softc, links)) {
< s = splsoftcam();
< if ((softc->ordered_tag_count == 0)
< && ((softc->flags & DA_FLAG_WENT_IDLE) == 0)) {
< softc->flags |= DA_FLAG_NEED_OTAG;
< }
< if (softc->outstanding_cmds > 0)
< softc->flags &= ~DA_FLAG_WENT_IDLE;
---
> struct da_softc *softc = arg;
1976,1977c1956,1959
< softc->ordered_tag_count = 0;
< splx(s);
---
> if (da_send_ordered) {
> if ((softc->ordered_tag_count == 0)
> && ((softc->flags & DA_FLAG_WENT_IDLE) == 0)) {
> softc->flags |= DA_FLAG_NEED_OTAG;
1979,1981c1961,1964
< /* Queue us up again */
< timeout(dasendorderedtag, NULL,
< (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL);
---
> if (softc->outstanding_cmds > 0)
> softc->flags &= ~DA_FLAG_WENT_IDLE;
>
> softc->ordered_tag_count = 0;
1982a1966,1969
> /* Queue us up again */
> callout_reset(&softc->sendordered_c,
> (DA_DEFAULT_TIMEOUT * hz) / DA_ORDEREDTAG_INTERVAL,
> dasendorderedtag, softc);